Beispiel #1
0
 /**
  * Returns all leaves for the current content topic.
  *
  * It will hide the index leaf from the NAP information unless we are in Autoindex
  * mode. The leaves' title are used as a description within NAP, and the toolbar will
  * contain edit and delete links.
  */
 public function get_leaves()
 {
     $leaves = array();
     if ($this->_config->get('hide_navigation')) {
         return $leaves;
     }
     // Get the required information with midgard_collector
     $qb = midcom_db_article::new_query_builder();
     $qb->add_constraint('up', '=', 0);
     // Check whether to include the linked articles to navigation list
     if (!$this->_config->get('enable_article_links')) {
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
     } else {
         // Get the linked articles as well
         $mc = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id);
         $mc->add_constraint('topic', '=', $this->_content_topic->id);
         $links = $mc->get_values('article');
         $qb->begin_group('OR');
         if (count($links) > 0) {
             $qb->add_constraint('id', 'IN', $links);
         }
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
         $qb->end_group();
     }
     $qb->add_constraint('metadata.navnoentry', '=', 0);
     $qb->add_constraint('name', '<>', '');
     // Unless in Auto-Index mode or the index article is hidden, we skip the index article.
     if (!$this->_config->get('autoindex') && !$this->_config->get('indexinnav')) {
         $qb->add_constraint('name', '<>', 'index');
     }
     $sort_order = 'ASC';
     $sort_property = $this->_config->get('sort_order');
     if (strpos($sort_property, 'reverse ') === 0) {
         $sort_order = 'DESC';
         $sort_property = substr($sort_property, strlen('reverse '));
     }
     if (strpos($sort_property, 'metadata.') === false) {
         $article = new midgard_article();
         if (!property_exists($article, $sort_property)) {
             $sort_property = 'metadata.' . $sort_property;
         }
     }
     $qb->add_order($sort_property, $sort_order);
     // Sort items with the same primary sort key by title.
     $qb->add_order('title');
     $articles = $qb->execute();
     foreach ($articles as $article) {
         $article_url = "{$article->name}/";
         if ($article->name == 'index') {
             $article_url = '';
         }
         $leaves[$article->id] = array(MIDCOM_NAV_URL => $article_url, MIDCOM_NAV_NAME => $article->title ? $article->title : $article->name, MIDCOM_NAV_GUID => $article->guid, MIDCOM_NAV_OBJECT => $article);
     }
     return $leaves;
 }
Beispiel #2
0
 /**
  * This helper function goes over the topic and loads all available objects for displaying
  * in the autoindex.
  *
  * It will populate the request data key 'create_urls' as well. See the view handler for
  * further details.
  *
  * The computed array has the following keys:
  *
  * - string name: The name of the object.
  * - string url: The full URL to the object.
  * - string size: The formatted size of the document. This is only populated for attachments.
  * - string desc: The object title/description.
  * - string type: The MIME Type of the object.
  * - string lastmod: The localized last modified date.
  *
  * @return Array Autoindex objects as outlined above
  */
 private function _load_autoindex_data()
 {
     $view = array();
     $datamanager = new midcom_helper_datamanager2_datamanager($this->_request_data['schemadb']);
     $qb = midcom_db_article::new_query_builder();
     $sort_order = 'ASC';
     $sort_property = $this->_config->get('sort_order');
     if (strpos($sort_property, 'reverse ') === 0) {
         $sort_order = 'DESC';
         $sort_property = substr($sort_property, strlen('reverse '));
     }
     if (strpos($sort_property, 'metadata.') === false) {
         $article = new midgard_article();
         if (!property_exists($article, $sort_property)) {
             $sort_property = 'metadata.' . $sort_property;
         }
     }
     $qb->add_order($sort_property, $sort_order);
     $qb->add_order('title');
     $qb->add_order('name');
     // Include the article links to the indexes if enabled
     if ($this->_config->get('enable_article_links')) {
         $mc = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id);
         $mc->add_constraint('topic', '=', $this->_content_topic->id);
         $links = $mc->get_values('article');
         $qb->begin_group('OR');
         if (count($links) > 0) {
             $qb->add_constraint('id', 'IN', $links);
         }
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
         $qb->end_group();
     } else {
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
     }
     $result = $qb->execute();
     foreach ($result as $article) {
         if (!$datamanager->autoset_storage($article)) {
             debug_add("The datamanager for article {$article->id} could not be initialized, skipping it.");
             debug_print_r('Object was:', $article);
             continue;
         }
         $this->_process_datamanager($datamanager, $article, $view);
     }
     return $view;
 }
Beispiel #3
0
 private function _load_index_article()
 {
     $qb = midcom_db_article::new_query_builder();
     $qb->add_constraint('name', '=', 'index');
     $qb->set_limit(1);
     // Include the article links to the indexes if enabled
     if ($this->_config->get('enable_article_links')) {
         $mc = net_nehmer_static_link_dba::new_collector('topic', $this->_content_topic->id);
         $mc->add_constraint('topic', '=', $this->_content_topic->id);
         $links = $mc->get_values('article');
         $qb->begin_group('OR');
         if (count($links) > 0) {
             $qb->add_constraint('id', 'IN', $links);
         }
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
         $qb->end_group();
     } else {
         $qb->add_constraint('topic', '=', $this->_content_topic->id);
     }
     $result = $qb->execute();
     if (empty($result)) {
         if ($this->_content_topic->can_do('midgard:create')) {
             // Check via non-ACLd QB that the topic really doesn't have index article before relocating
             $index_qb = midcom_db_article::new_query_builder();
             $index_qb->add_constraint('topic', '=', $this->_content_topic->id);
             $index_qb->add_constraint('name', '=', 'index');
             if ($index_qb->count_unchecked() == 0) {
                 $schemas = array_keys($this->_request_data['schemadb']);
                 midcom::get()->relocate("createindex/{$schemas[0]}/");
                 // This will exit.
             }
         }
         throw new midcom_error_forbidden('Directory index forbidden');
     }
     $this->_article = $result[0];
 }