示例#1
0
文件: admin.php 项目: nemein/openpsa
 /**
  * Displays an article delete confirmation view.
  *
  * Note, that the article for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation article
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     $this->_article = new midcom_db_article($args[0]);
     // Relocate to delete the link instead of the article itself
     if ($this->_article->topic !== $this->_content_topic->id) {
         return new midcom_response_relocate("delete/link/{$args[0]}/");
     }
     $this->_article->require_do('midgard:delete');
     $this->_load_datamanager();
     if (array_key_exists('net_nehmer_blog_deleteok', $_REQUEST)) {
         $title = $this->_article->title;
         // Deletion confirmed.
         if (!$this->_article->delete()) {
             throw new midcom_error("Failed to delete article {$args[0]}, last Midgard error was: " . midcom_connection::get_error_string());
         }
         // Delete all the links pointing to the article
         $qb = net_nehmer_blog_link_dba::new_query_builder();
         $qb->add_constraint('article', '=', $this->_article->id);
         $links = $qb->execute_unchecked();
         midcom::get('auth')->request_sudo('net.nehmer.blog');
         foreach ($links as $link) {
             $link->delete();
         }
         midcom::get('auth')->drop_sudo();
         // Update the index
         $indexer = midcom::get('indexer');
         $indexer->delete($this->_article->guid);
         // Show user interface message
         midcom::get('uimessages')->add($this->_l10n->get('net.nehmer.blog'), sprintf($this->_l10n->get('article %s deleted'), $title));
         // Delete ok, relocating to welcome.
         return new midcom_response_relocate('');
     }
     if (array_key_exists('net_nehmer_blog_deletecancel', $_REQUEST)) {
         midcom::get('uimessages')->add($this->_l10n->get('net.nehmer.blog'), $this->_l10n->get('delete cancelled'));
         // Redirect to view page.
         if ($this->_config->get('view_in_url')) {
             return new midcom_response_relocate("view/{$this->_article->name}/");
         } else {
             return new midcom_response_relocate("{$this->_article->name}/");
         }
     }
     $this->_prepare_request_data();
     midcom::get('metadata')->set_request_metadata($this->_article->metadata->revised, $this->_article->guid);
     $this->_view_toolbar->bind_to($this->_article);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$this->_article->title}");
     $this->_update_breadcrumb_line($handler_id);
 }
示例#2
0
文件: admin.php 项目: nemein/openpsa
 /**
  * Displays an article delete confirmation view.
  *
  * Note, that the article for non-index mode operation is automatically determined in the can_handle
  * phase.
  *
  * If create privileges apply, we relocate to the index creation article
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     $this->_article = new midcom_db_article($args[0]);
     // Relocate to delete the link instead of the article itself
     if ($this->_article->topic !== $this->_content_topic->id) {
         return new midcom_response_relocate("delete/link/{$args[0]}/");
     }
     $this->_article->require_do('midgard:delete');
     $this->_load_datamanager();
     if (array_key_exists('net_nehmer_static_deleteok', $_REQUEST)) {
         // Deletion confirmed.
         if (!$this->_article->delete()) {
             throw new midcom_error("Failed to delete article {$args[0]}, last Midgard error was: " . midcom_connection::get_error_string());
         }
         // Delete all the links pointing to the article
         $qb = net_nehmer_static_link_dba::new_query_builder();
         $qb->add_constraint('article', '=', $this->_article->id);
         $links = $qb->execute_unchecked();
         midcom::get('auth')->request_sudo('net.nehmer.static');
         foreach ($links as $link) {
             $link->delete();
         }
         midcom::get('auth')->drop_sudo();
         // Update the index
         $indexer = midcom::get('indexer');
         $indexer->delete($this->_article->guid);
         // Delete ok, relocating to welcome.
         return new midcom_response_relocate('');
     }
     if (array_key_exists('net_nehmer_static_deletecancel', $_REQUEST)) {
         // Redirect to view page.
         return new midcom_response_relocate("{$this->_article->name}/");
     }
     $this->_prepare_request_data();
     $this->bind_view_to_object($this->_article, $this->_datamanager->schema->name);
     midcom::get('style')->append_substyle('admin');
     midcom::get('metadata')->set_request_metadata($this->_article->metadata->revised, $this->_article->guid);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$this->_article->title}");
     $this->set_active_leaf($this->_article->id);
     $this->_update_breadcrumb_line($handler_id);
 }
示例#3
0
 function deletePost($message)
 {
     $args = $this->_params_to_args($message);
     if (count($args) != 5) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Invalid arguments.');
     }
     if (!midcom::get('auth')->login($args[2], $args[3])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Authentication failed.');
     }
     midcom::get('auth')->initialize();
     try {
         $article = new midcom_db_article($args[1]);
     } catch (midcom_error $e) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Article not found: ' . $e->getMessage());
     }
     if (!$article->delete()) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to delete article: ' . midgard_connection::get_error_string());
     }
     // Update the index
     $indexer = midcom::get('indexer');
     $indexer->delete($article->guid);
     return new XML_RPC_Response(new XML_RPC_Value(true, 'boolean'));
 }
示例#4
0
文件: email.php 项目: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_import($handler_id, array $args, array &$data)
 {
     if (!$this->_config->get('api_email_enable')) {
         throw new midcom_error('Email API is disabled');
     }
     if ($handler_id === 'api-email-basicauth') {
         midcom::get('auth')->require_valid_user('basic');
     }
     //Content-Type
     midcom::get()->skip_page_style = true;
     midcom::get('cache')->content->content_type('text/plain');
     if (!isset($this->_request_data['schemadb'][$this->_config->get('api_email_schema')])) {
         throw new midcom_error('Schema "' . $this->_config->get('api_email_schema') . '" not found in schemadb "' . $this->_config->get('schemadb') . '"');
     }
     $schema_instance =& $this->_request_data['schemadb'][$this->_config->get('api_email_schema')];
     // Parse email
     $this->_decode_email();
     $this->_parse_email_persons();
     midcom::get('auth')->request_sudo('net.nehmer.blog');
     // Create article
     $this->_create_article($this->_decoder->subject);
     // Load the article to DM2
     $this->_load_datamanager();
     // Find image and tag fields in schema
     foreach ($schema_instance->fields as $name => $field) {
         if (is_a($this->_datamanager->types[$name], 'midcom_helper_datamanager2_type_image')) {
             $this->_request_data['image_field'] = $name;
             continue;
         }
         if (is_a($this->_datamanager->types[$name], 'midcom_helper_datamanager2_type_tags')) {
             $data['tags_field'] = $name;
             continue;
         }
     }
     // Try to find tags in email content
     $content = $this->_decoder->body;
     $content_tags = '';
     midcom::get('componentloader')->load_graceful('net.nemein.tag');
     if (class_exists('net_nemein_tag_handler')) {
         // unconditionally tag
         debug_add("content before machine tag separation\n===\n{$content}\n===\n");
         $content_tags = net_nemein_tag_handler::separate_machine_tags_in_content($content);
         if (!empty($content_tags)) {
             debug_add("found machine tags string: {$content_tags}");
             net_nemein_tag_handler::tag_object($this->_article, net_nemein_tag_handler::string2tag_array($content_tags));
         }
         debug_add("content AFTER machine tag separation\n===\n{$content}\n===\n");
     }
     // Populate rest of the data
     $this->_datamanager->types['content']->value = $content;
     if (!empty($data['tags_field'])) {
         // if we have tags field put content_tags value there as well or they will get deleted!
         $this->_datamanager->types[$data['tags_field']]->value = $content_tags;
     }
     $body_switched = false;
     foreach ($this->_decoder->attachments as $att) {
         debug_add("processing attachment {$att['name']}");
         switch (true) {
             case strpos($att['mimetype'], 'image/') !== false:
                 $this->_add_image($att);
                 break;
             case strtolower($att['mimetype']) == 'text/plain':
                 if (!$body_switched) {
                     // Use first text/plain part as the content
                     $this->_datamanager->types['content']->value = $att['content'];
                     $body_switched = true;
                     break;
                 }
                 // Fall-through if not switching
             // Fall-through if not switching
             default:
                 $this->_add_attachment($att);
         }
     }
     if (!$this->_datamanager->save()) {
         // Remove the article, but get errstr first
         $errstr = midcom_connection::get_error_string();
         $this->_article->delete();
         throw new midcom_error('DM2 failed to save the article. Last Midgard error was: ' . $errstr);
     }
     // Index the article
     $indexer = midcom::get('indexer');
     net_nehmer_blog_viewer::index($this->_datamanager, $indexer, $this->_content_topic);
     if ($this->_config->get('api_email_autoapprove')) {
         $metadata = midcom_helper_metadata::retrieve($this->_article);
         if (!$metadata->force_approve()) {
             // Remove the article, but get errstr first
             $errstr = midcom_connection::get_error_string();
             $this->_article->delete();
             throw new midcom_error('Failed to force approval on article. Last Midgard error was: ' . $errstr);
         }
     }
     midcom::get('auth')->drop_sudo();
 }