コード例 #1
0
ファイル: metaweblog.php プロジェクト: nemein/openpsa
 function newMediaObject($message)
 {
     $args = $this->_params_to_args($message);
     if (count($args) != 4) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Invalid arguments.');
     }
     if ($args[0] != $this->_content_topic->guid) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Blog ID does not match this folder.');
     }
     if (!midcom::get('auth')->login($args[1], $args[2])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Authentication failed.');
     }
     midcom::get('auth')->initialize();
     if (count($args) < 3) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Invalid file data.');
     }
     if (!$args[3]['name']) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'No filename given.');
     }
     // Clean up possible path information
     $attachment_name = basename($args[3]['name']);
     $attachment = $this->_content_topic->get_attachment($attachment_name);
     if (!$attachment) {
         // Create new attachment
         $attachment = $this->_content_topic->create_attachment($attachment_name, $args[3]['name'], $args[3]['type']);
         if (!$attachment) {
             return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to create attachment: ' . midgard_connection::get_error_string());
         }
     }
     if (!$attachment->copy_from_memory($args[3]['bits'])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to store contents to attachment: ' . midgard_connection::get_error_string());
     }
     $attachment_array = array('url' => new XML_RPC_Value("{$GLOBALS['midcom_config']['midcom_site_url']}midcom-serveattachmentguid-{$attachment->guid}/{$attachment->name}", 'string'), 'guid' => new XML_RPC_Value($attachment->guid, 'string'));
     return new XML_RPC_Response(new XML_RPC_Value($attachment_array, 'struct'));
 }