Beispiel #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;
 }
Beispiel #2
0
 /**
  * Can-Handle check against the article name. We have to do this explicitly
  * in can_handle already, otherwise we would hide all subtopics as the request switch
  * accepts all argument count matches unconditionally.
  *
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  * @return boolean True if the request can be handled, false otherwise.
  */
 public function _can_handle_view($handler_id, array $args, array &$data)
 {
     $qb = midcom_db_article::new_query_builder();
     net_nehmer_blog_viewer::article_qb_constraints($qb, $data, $handler_id);
     $qb->begin_group('OR');
     $qb->add_constraint('name', '=', $args[0]);
     $qb->add_constraint('guid', '=', $args[0]);
     $qb->end_group();
     $articles = $qb->execute();
     if (count($articles) > 0) {
         $this->_article = $articles[0];
     }
     if (!$this->_article) {
         return false;
         // This will 404
     }
     return true;
 }
Beispiel #3
0
 /**
  * Shows the archive. Depending on the selected handler various constraints are added to
  * the QB. See the add_*_constraint methods for details.
  *
  * @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_list($handler_id, array $args, array &$data)
 {
     // Get Articles, distinguish by handler.
     $qb = midcom_db_article::new_query_builder();
     net_nehmer_blog_viewer::article_qb_constraints($qb, $data, $handler_id);
     // Use helper functions to determine start/end
     switch ($handler_id) {
         case 'archive-year-category':
             if (!$this->_config->get('archive_years_enable')) {
                 throw new midcom_error_notfound('Year archive not allowed');
             }
             $data['category'] = trim(strip_tags($args[1]));
             $multiple_categories = true;
             if (isset($data['schemadb']['default']->fields['categories']) && array_key_exists('allow_multiple', $data['schemadb']['default']->fields['categories']['type_config']) && !$data['schemadb']['default']->fields['categories']['type_config']['allow_multiple']) {
                 $multiple_categories = false;
             }
             if ($multiple_categories) {
                 $qb->add_constraint('extra1', 'LIKE', "%|{$this->_request_data['category']}|%");
             } else {
                 $qb->add_constraint('extra1', '=', (string) $data['category']);
             }
         case 'archive-year':
             if (!$this->_config->get('archive_years_enable')) {
                 throw new midcom_error_notfound('Year archive not allowed');
             }
             $this->_set_startend_from_year($args[0]);
             break;
         case 'archive-month':
             $this->_set_startend_from_month($args[0], $args[1]);
             break;
         default:
             throw new midcom_error("The request handler {$handler_id} is not supported.");
     }
     $qb->add_constraint('metadata.published', '>=', $this->_start->format('Y-m-d H:i:s'));
     $qb->add_constraint('metadata.published', '<', $this->_end->format('Y-m-d H:i:s'));
     $qb->add_order('metadata.published', $this->_config->get('archive_item_order'));
     $this->_articles = $qb->execute();
     $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_request_data['schemadb']);
     // Move end date one day backwards for display purposes.
     $now = new DateTime();
     if ($now < $this->_end) {
         $this->_end = $now;
     } else {
         $this->_end->modify('-1 day');
     }
     $start = $this->_start->format($this->_l10n_midcom->get('short date'));
     $end = $this->_end->format($this->_l10n_midcom->get('short date'));
     $this->add_breadcrumb("archive/year/{$args[0]}/", "{$start} - {$end}");
     $this->_prepare_request_data();
     if ($this->_config->get('archive_in_navigation')) {
         $this->set_active_leaf($this->_topic->id . '_ARCHIVE');
     } else {
         $this->set_active_leaf($this->_topic->id . '_ARCHIVE_' . $args[0]);
     }
     midcom::get('metadata')->set_request_metadata(net_nehmer_blog_viewer::get_last_modified($this->_topic, $this->_content_topic), $this->_topic->guid);
     midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$start} - {$end}");
 }
Beispiel #4
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'));
 }
Beispiel #5
0
 /**
  * @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();
 }
Beispiel #6
0
 /**
  * Shows the autoindex list. Nothing to do in the handle phase except setting last modified
  * dates.
  *
  * @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_feed($handler_id, array $args, array &$data)
 {
     midcom::get('componentloader')->load_library('de.bitfolge.feedcreator');
     midcom::get('cache')->content->content_type("text/xml; charset=UTF-8");
     midcom::get()->header("Content-type: text/xml; charset=UTF-8");
     midcom::get()->skip_page_style = true;
     // Prepare control structures
     $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_request_data['schemadb']);
     // Get the articles,
     $qb = midcom_db_article::new_query_builder();
     net_nehmer_blog_viewer::article_qb_constraints($qb, $data, $handler_id);
     $qb->add_order('metadata.published', 'DESC');
     if ($handler_id == 'feed-category-rss2') {
         if (!in_array($args[0], $this->_request_data['categories'])) {
             // This is not a predefined category from configuration, check if site maintainer allows us to show it
             if (!$this->_config->get('categories_custom_enable')) {
                 throw new midcom_error('Custom category support is disabled');
             }
         }
         // TODO: Check for ".xml" suffix
         $this->_request_data['category'] = trim(strip_tags($args[0]));
         $multiple_categories = true;
         // TODO: check schema storage to get fieldname
         if (isset($this->_request_data['schemadb']['default']->fields['categories']) && array_key_exists('allow_multiple', $this->_request_data['schemadb']['default']->fields['categories']['type_config']) && !$this->_request_data['schemadb']['default']->fields['categories']['type_config']['allow_multiple']) {
             $multiple_categories = false;
         }
         debug_add("multiple_categories={$multiple_categories}");
         if ($multiple_categories) {
             $qb->add_constraint('extra1', 'LIKE', "%|{$this->_request_data['category']}|%");
         } else {
             $qb->add_constraint('extra1', '=', (string) $this->_request_data['category']);
         }
     }
     $qb->set_limit($this->_config->get('rss_count'));
     $this->_articles = $qb->execute();
     // Prepare the feed (this will also validate the handler_id)
     $this->_create_feed($handler_id);
     midcom::get('metadata')->set_request_metadata(net_nehmer_blog_viewer::get_last_modified($this->_topic, $this->_content_topic), $this->_topic->guid);
 }
Beispiel #7
0
 /**
  * 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));
 }
Beispiel #8
0
 /**
  * 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);
 }
Beispiel #9
0
 /**
  * Shows the autoindex list. Nothing to do in the handle phase except setting last modified
  * dates.
  *
  * @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_index($handler_id, array $args, array &$data)
 {
     if ($handler_id == 'ajax-latest') {
         midcom::get()->skip_page_style = true;
     }
     $this->_datamanager = new midcom_helper_datamanager2_datamanager($data['schemadb']);
     $qb = new org_openpsa_qbpager('midcom_db_article', 'net_nehmer_blog_index');
     $data['qb'] =& $qb;
     net_nehmer_blog_viewer::article_qb_constraints($qb, $data, $handler_id);
     // Set default page title
     $data['page_title'] = $this->_topic->extra;
     // Filter by categories
     if ($handler_id == 'index-category' || $handler_id == 'latest-category') {
         $data['category'] = trim(strip_tags($args[0]));
         if (!($constraint = $this->_process_category_constraint($qb))) {
             throw new midcom_error('Failed to process category constraint');
         }
     }
     $qb->add_order('metadata.published', 'DESC');
     switch ($handler_id) {
         case 'index':
         case 'index-category':
             $qb->results_per_page = $this->_config->get('index_entries');
             break;
         case 'latest':
         case 'ajax-latest':
             $qb->results_per_page = $args[0];
             break;
         case 'latest-category':
             $qb->results_per_page = $args[1];
             break;
         default:
             $qb->results_per_page = $this->_config->get('index_entries');
             break;
     }
     $this->_articles = $qb->execute();
     $this->_prepare_request_data();
     midcom::get('metadata')->set_request_metadata(net_nehmer_blog_viewer::get_last_modified($this->_topic, $this->_content_topic), $this->_topic->guid);
     if ($qb->get_current_page() > 1) {
         $this->add_breadcrumb(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX), sprintf(midcom::get('i18n')->get_string('page %s', 'org.openpsa.qbpager'), $qb->get_current_page()));
     }
 }