예제 #1
0
 /**
  * Iterate over all articles and create index record using the datamanager indexer
  * method.
  */
 public function _on_reindex($topic, $config, &$indexer)
 {
     if (is_null($config->get('symlink_topic')) && !$config->get('disable_indexing')) {
         $qb = midcom::get('dbfactory')->new_query_builder('midcom_db_article');
         $qb->add_constraint('topic', '=', $topic->id);
         $result = $qb->execute();
         if ($result) {
             $schemadb = midcom_helper_datamanager2_schema::load_database($config->get('schemadb'));
             $datamanager = new midcom_helper_datamanager2_datamanager($schemadb);
             if (!$datamanager) {
                 debug_add('Warning, failed to create a datamanager instance with this schemapath:' . $config->get('schemadb'), MIDCOM_LOG_WARN);
                 continue;
             }
             foreach ($result as $article) {
                 if (!$datamanager->autoset_storage($article)) {
                     debug_add("Warning, failed to initialize datamanager for Article {$article->id}. Skipping it.", MIDCOM_LOG_WARN);
                     continue;
                 }
                 net_nehmer_blog_viewer::index($datamanager, $indexer, $topic);
             }
         }
     } elseif (is_null($config->get('symlink_topic')) && !$config->get('disable_search')) {
         debug_add("The topic {$topic->id} is is not to be indexed, skipping indexing.");
     } else {
         debug_add("The topic {$topic->id} is symlinked to another topic, skipping indexing.");
     }
     return true;
 }
예제 #2
0
 function editPost($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[1], $args[2])) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Authentication failed.');
     }
     midcom::get('auth')->initialize();
     try {
         $article = new midcom_db_article($args[0]);
     } catch (midcom_error $e) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Article not found: ' . $e->getMessage());
     }
     if (!$this->_datamanager->autoset_storage($article)) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to initialize DM2 for article: ' . midgard_connection::get_error_string());
     }
     foreach ($args[3] as $field => $value) {
         switch ($field) {
             case 'title':
                 $this->_datamanager->types['title']->value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
                 break;
             case 'mt_excerpt':
                 $this->_datamanager->types['abstract']->value = $value;
                 break;
             case 'description':
                 $this->_datamanager->types['content']->value = $value;
                 break;
             case 'link':
                 // TODO: We may have to bulletproof this a bit
                 $this->_datamanager->types['name']->value = str_replace('.html', '', basename($args[3]['link']));
                 break;
             case 'categories':
                 if (array_key_exists('categories', $this->_datamanager->types)) {
                     $this->_datamanager->types['categories']->selection = $value;
                     break;
                 }
             case 'http://www.georss.org/georss/':
                 if ($this->_positioning) {
                     foreach ($value as $feature => $val) {
                         switch ($feature) {
                             case 'point':
                                 $coordinates = explode(' ', $val);
                                 if (count($coordinates) != 2) {
                                     break;
                                 }
                                 $log = new org_routamc_positioning_log_dba();
                                 $log->date = $article->metadata->published;
                                 $log->latitude = (double) $coordinates[0];
                                 $log->longitude = (double) $coordinates[1];
                                 $log->accuracy = ORG_ROUTAMC_POSITIONING_ACCURACY_MANUAL;
                                 $log->create();
                                 break;
                         }
                         // TODO: Handle different relationshiptags as per http://georss.org/simple/
                     }
                 }
                 break;
         }
     }
     if (!$this->_datamanager->save()) {
         return new XML_RPC_Response(0, midcom_connection::get_error(), 'Failed to update article: ' . midgard_connection::get_error_string());
     }
     // TODO: Map the publish property to approval
     // Index the article
     $indexer = midcom::get('indexer');
     net_nehmer_blog_viewer::index($this->_datamanager, $indexer, $this->_content_topic);
     return new XML_RPC_Response(new XML_RPC_Value($article->guid, 'string'));
 }
예제 #3
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();
 }
예제 #4
0
파일: create.php 프로젝트: nemein/openpsa
 /**
  * Displays an article edit 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_create($handler_id, array $args, array &$data)
 {
     $this->_content_topic->require_do('midgard:create');
     $this->_schema = $args[0];
     if ($handler_id == 'createindex') {
         $this->_indexmode = true;
     }
     $data['controller'] = $this->get_controller('create');
     switch ($data['controller']->process_form()) {
         case 'save':
             // #809 should have taken care of this, but see same place in n.n.static
             if (strlen($this->_article->name) == 0) {
                 // Generate something to avoid empty "/" links in case of failures
                 $this->_article->name = time();
                 $this->_article->update();
             }
             // Index the article
             $indexer = midcom::get('indexer');
             net_nehmer_blog_viewer::index($data['controller']->datamanager, $indexer, $this->_content_topic);
             // *** FALL THROUGH ***
         // *** FALL THROUGH ***
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $this->_prepare_request_data();
     $title = sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$title}");
     $this->add_breadcrumb("create/{$this->_schema}/", sprintf($this->_l10n_midcom->get('create %s'), $this->_schemadb[$this->_schema]->description));
 }
예제 #5
0
파일: admin.php 프로젝트: nemein/openpsa
 /**
  * Displays an article edit 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_edit($handler_id, array $args, array &$data)
 {
     $this->_article = new midcom_db_article($args[0]);
     // Relocate for the correct content topic, let the true content topic take care of the ACL
     if ($this->_article->topic !== $this->_content_topic->id) {
         $nap = new midcom_helper_nav();
         $node = $nap->get_node($this->_article->topic);
         if ($node && isset($node[MIDCOM_NAV_FULLURL])) {
             return new midcom_response_relocate($node[MIDCOM_NAV_FULLURL] . "edit/{$args[0]}/");
         }
         throw new midcom_error_notfound("The article with GUID {$args[0]} was not found.");
     }
     $this->_article->require_do('midgard:update');
     $this->_load_controller();
     switch ($this->_controller->process_form()) {
         case 'save':
             // Reindex the article
             $indexer = midcom::get('indexer');
             net_nehmer_blog_viewer::index($this->_controller->datamanager, $indexer, $this->_content_topic);
             // *** FALL-THROUGH ***
         // *** FALL-THROUGH ***
         case 'cancel':
             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();
     $this->_view_toolbar->bind_to($this->_article);
     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->_update_breadcrumb_line($handler_id);
 }