/** * DM2 creation callback, binds to the current content topic. */ private function _create_article($title) { $this->_article = new midcom_db_article(); $author = $this->_find_email_person($this->_request_data['from']); if (!$author) { debug_add("Author '{$this->_request_data['from']}' not found", MIDCOM_LOG_WARN); if ($this->_config->get('api_email_abort_authornotfound') !== false) { throw new midcom_error("Author '{$this->_request_data['from']}' not found"); } $this->_article->author = midcom_connection::get_user(); } else { // TODO: This code needs a bit of rethinking $author_user = midcom::get('auth')->get_user($author->guid); if (!$this->_content_topic->can_do('midgard:create', $author_user)) { throw new midcom_error('Author doesn\'t have posting privileges'); } $this->_article->author = $author->id; } //Default to first user in DB if author is not set if (!$this->_article->author) { $qb = midcom_db_person::new_query_builder(); $qb->add_constraint('username', '<>', ''); $qb->set_limit(1); $results = $qb->execute(); unset($qb); if (empty($results)) { //No users found throw new midcom_error('Cannot set any author for the article'); } $this->_article->author = $results[0]->id; } $resolver = new midcom_helper_reflector_nameresolver($this->_article); $this->_article->topic = $this->_content_topic->id; $this->_article->title = $title; $this->_article->allow_name_catenate = true; $this->_article->name = $resolver->generate_unique_name('title'); if (empty($this->_article->name)) { debug_add('Could not generate unique name for the new article from title, using timestamp', MIDCOM_LOG_INFO); $this->_article->name = time(); $resolver = new midcom_helper_reflector_nameresolver($this->_article); if (!$resolver->name_is_unique()) { throw new midcom_error('Failed to create unique name for the new article, aborting.'); } } if (!$this->_article->create()) { debug_print_r('Failed to create article:', $this->_article); throw new midcom_error('Failed to create a new article. Last Midgard error was: ' . midcom_connection::get_error_string()); } $this->_article->parameter('midcom.helper.datamanager2', 'schema_name', $this->_config->get('api_email_schema')); return true; }
/** * Populates the node toolbar depending on the user's rights. */ private function _populate_node_toolbar() { if ($this->_content_topic->can_do('midgard:create')) { foreach (array_keys($this->_request_data['schemadb']) as $name) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "create/{$name}/", MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get($this->_request_data['schemadb'][$name]->description)), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/new-text.png', MIDCOM_TOOLBAR_ACCESSKEY => 'n')); } } if ($this->_config->get('rss_subscription_enable')) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'feeds/subscribe/', MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('subscribe feeds', 'net.nemein.rss'), MIDCOM_TOOLBAR_ICON => 'net.nemein.rss/rss-16.png', MIDCOM_TOOLBAR_ENABLED => $this->_topic->can_do('midgard:create'))); $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'feeds/list/', MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('manage feeds', 'net.nemein.rss'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png', MIDCOM_TOOLBAR_ENABLED => $this->_topic->can_do('midgard:create'))); $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "feeds/fetch/all", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('refresh all feeds', 'net.nemein.rss'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_refresh.png', MIDCOM_TOOLBAR_ENABLED => $this->_topic->can_do('midgard:create'))); } if ($this->_config->get('enable_article_links') && $this->_content_topic->can_do('midgard:create')) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link')), MIDCOM_TOOLBAR_URL => "create/link/", MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png')); } if ($this->_topic->can_do('midgard:update') && $this->_topic->can_do('midcom:component_config')) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'config/', MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png')); } }
/** * Populates the node toolbar depending on the user's rights. */ private function _populate_node_toolbar() { if ($this->_content_topic->can_do('midgard:create')) { foreach (array_keys($this->_request_data['schemadb']) as $name) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "create/{$name}/", MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get($this->_request_data['schemadb'][$name]->description)), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/new-text.png', MIDCOM_TOOLBAR_ACCESSKEY => 'n')); } } if ($this->_config->get('enable_article_links') && $this->_content_topic->can_do('midgard:create')) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link')), MIDCOM_TOOLBAR_URL => "create/link/", MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png')); } if ($this->_topic->can_do('midgard:update') && $this->_topic->can_do('midcom:component_config')) { $this->_node_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'config/', MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png')); } }
/** * Handle actual article display * * @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_view($handler_id, array $args, array &$data) { if ($handler_id == 'view-raw') { midcom::get()->skip_page_style = true; } $this->_load_datamanager(); if ($this->_config->get('enable_ajax_editing')) { $this->_request_data['controller'] = midcom_helper_datamanager2_controller::create('ajax'); $this->_request_data['controller']->schemadb =& $this->_request_data['schemadb']; $this->_request_data['controller']->set_storage($this->_article); $this->_request_data['controller']->process_ajax(); } if ($this->_config->get('comments_enable')) { $comments_node = $this->_seek_comments(); if ($comments_node) { $this->_request_data['comments_url'] = $comments_node[MIDCOM_NAV_RELATIVEURL] . "comment/{$this->_article->guid}"; if ($this->_topic->can_do('midgard:update') && $this->_topic->can_do('net.nehmer.comments:moderation')) { net_nehmer_comments_viewer::add_head_elements(); } } // TODO: Should we tell admin to create a net.nehmer.comments folder? } $tmp = array(); $arg = $this->_article->name ? $this->_article->name : $this->_article->guid; if ($this->_config->get('view_in_url')) { $view_url = "view/{$arg}/"; } else { $view_url = "{$arg}/"; } $this->add_breadcrumb($view_url, $this->_article->title); $this->_prepare_request_data(); if ($this->_config->get('enable_article_links') && $this->_content_topic->can_do('midgard:create')) { $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_LABEL => sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link')), MIDCOM_TOOLBAR_URL => "create/link/?article={$this->_article->id}", MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/attach.png')); } $this->bind_view_to_object($this->_article, $this->_datamanager->schema->name); midcom::get('metadata')->set_request_metadata($this->_article->metadata->revised, $this->_article->guid); midcom::get('head')->set_pagetitle("{$this->_topic->extra}: {$this->_article->title}"); }
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]; }