Example #1
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_link = new net_nehmer_static_link_dba();
     $this->_link->topic = $this->_topic->id;
     if (!$this->_link->create()) {
         debug_print_r('We operated on this object:', $this->_link);
         throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     return $this->_link;
 }
Example #2
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;
 }
Example #3
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;
 }
Example #4
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];
 }
Example #5
0
 /**
  * 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);
 }