Example #1
0
 /**
  * Traverse the child elements starting from the requested node id
  */
 private function _list_child_elements($id, $indent = '')
 {
     // If only nodes are to be listed use the appropriate NAP call
     if (!$this->list_leaves) {
         $this->_list_child_nodes($id, $indent);
         return;
     }
     $children = $this->_nap->list_child_elements($id);
     // Stop traversing the path if there are no children
     if (!$children || count($children) === 0) {
         return;
     }
     // Add ID property to the first unordered list ever called
     $element_id = '';
     if ($this->root_object_id) {
         $element_id = " id=\"{$this->root_object_id}\"";
         $this->root_object_id = null;
     }
     echo "{$indent}<ul class=\"{$this->css_list_style} node-{$id}\"{$element_id}>\n";
     $item_count = count($children);
     $item_counter = 0;
     // Draw each child element
     foreach ($children as $child) {
         $item_counter++;
         if ($child[MIDCOM_NAV_TYPE] === 'node') {
             $item = $this->_nap->get_node($child[MIDCOM_NAV_ID]);
         } else {
             $item = $this->_nap->get_leaf($child[MIDCOM_NAV_ID]);
         }
         $classes = $this->_get_css_classes($child, $item, $item_counter, $item_count);
         $this->_display_element($item, $indent, $classes);
     }
     echo "{$indent}</ul>\n";
 }
Example #2
0
 /**
  * Constructor
  *
  * @param midcom_db_topic $topic The current topic
  * @param midcom_service_indexer $indexer The indexer service
  */
 public function __construct($topic, midcom_services_indexer $indexer = null)
 {
     $this->_topic = $topic;
     $this->_l10n = midcom::get('i18n')->get_l10n($topic->component);
     if (null === $indexer) {
         $indexer = midcom::get('indexer');
     }
     $this->_indexer = $indexer;
     $nav = new midcom_helper_nav();
     $this->_node = $nav->get_node($this->_topic->id);
 }
Example #3
0
 /**
  * Tries to determine the topic GUID and component using NAPs reverse-lookup capabilities.
  *
  * If this fails, you have to set the members $topic_guid, $topic_url and
  * $component manually.
  */
 function _process_topic()
 {
     $nav = new midcom_helper_nav();
     $object = $nav->resolve_guid($this->source);
     if (!$object) {
         debug_add("Failed to resolve the topic, skipping autodetection.");
         return;
     }
     if ($object[MIDCOM_NAV_TYPE] == 'leaf') {
         $object = $nav->get_node($object[MIDCOM_NAV_NODEID]);
     }
     $this->topic_guid = $object[MIDCOM_NAV_GUID];
     $this->topic_url = $object[MIDCOM_NAV_FULLURL];
     $this->component = $object[MIDCOM_NAV_COMPONENT];
 }
Example #4
0
 /**
  * Indexes a wiki page.
  *
  * This function is usually called statically from various handlers.
  *
  * @param midcom_helper_datamanager2_datamanager &$dm The Datamanager encapsulating the event.
  * @param midcom_services_indexer &$indexer The indexer instance to use.
  * @param midcom_db_topic The topic which we are bound to. If this is not an object, the code
  *     tries to load a new topic instance from the database identified by this parameter.
  */
 function index(&$dm, &$indexer, $topic)
 {
     if (!is_object($topic)) {
         $topic = new midcom_db_topic($topic);
     }
     // Don't index directly, that would lose a reference due to limitations
     // of the index() method. Needs fixes there.
     $nav = new midcom_helper_nav();
     $node = $nav->get_node($topic->id);
     $document = $indexer->new_document($dm);
     $document->topic_guid = $topic->guid;
     $document->topic_url = $node[MIDCOM_NAV_FULLURL];
     $document->read_metadata_from_object($dm->storage->object);
     $document->component = $topic->component;
     $indexer->index($document);
 }
Example #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_search($handler_id, array $args, array &$data)
 {
     $this->_request_data['results'] = array();
     if (array_key_exists('query', $_GET)) {
         // Figure out where we are
         $nap = new midcom_helper_nav();
         $node = $nap->get_node($nap->get_current_node());
         // Instantiate indexer
         $indexer = midcom::get('indexer');
         // Add the search parameters
         $query = $_GET['query'];
         $query .= " AND __TOPIC_URL:\"{$node[MIDCOM_NAV_FULLURL]}*\"";
         $query .= " AND __COMPONENT:org.openpsa.documents";
         // TODO: Metadata support
         // Run the search
         $this->_request_data['results'] = $indexer->query($query, null);
     }
     $this->add_stylesheet(MIDCOM_STATIC_URL . "/org.openpsa.documents/layout.css");
     $this->_populate_toolbar();
 }
Example #6
0
 /**
  * Indexes an article.
  *
  * This function is usually called statically from various handlers.
  *
  * @param midcom_helper_datamanager2_datamanager &$dm The Datamanager encapsulating the event.
  * @param midcom_services_indexer &$indexer The indexer instance to use.
  * @param midcom_db_topic The topic which we are bound to. If this is not an object, the code
  *     tries to load a new topic instance from the database identified by this parameter.
  */
 function index(&$dm, &$indexer, $topic)
 {
     if (!is_object($topic)) {
         $tmp = new midcom_db_topic($topic);
         if (!$tmp || !$tmp->guid) {
             $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to load the topic referenced by {$topic} for indexing, this is fatal.");
             // This will exit.
         }
         $topic = $tmp;
     }
     // Don't index directly, that would loose a reference due to limitations
     // of the index() method. Needs fixes there.
     $nav = new midcom_helper_nav();
     $node = $nav->get_node($topic->id);
     $author = $_MIDCOM->auth->get_user($dm->storage->object->creator);
     $document = $indexer->new_document($dm);
     $document->topic_guid = $topic->guid;
     $document->component = $topic->component;
     $document->topic_url = $node[MIDCOM_NAV_FULLURL];
     $document->read_metadata_from_object($dm->storage->object);
     $indexer->index($document);
 }
Example #7
0
/**
 * Try to find a comments node (cache results)
 *
 * @access private
 */
function seek_comments(&$data)
{
    if ($data['config']->get('comments_topic')) {
        // We have a specified photostream here
        $comments_topic = new midcom_db_topic($data['config']->get('comments_topic'));
        if (!is_object($comments_topic) || !isset($comments_topic->guid) || empty($comments_topic->guid)) {
            return false;
        }
        // We got a topic. Make it a NAP node
        $nap = new midcom_helper_nav();
        $comments_node = $nap->get_node($comments_topic->id);
        return $comments_node;
    }
    // No comments topic specified, autoprobe
    $comments_node = midcom_helper_find_node_by_component('net.nehmer.comments');
    // Cache the data
    if ($_MIDCOM->auth->request_sudo($data['topic']->component)) {
        $data['topic']->set_parameter($data['topic']->component, 'comments_topic', $comments_node[MIDCOM_NAV_GUID]);
        $_MIDCOM->auth->drop_sudo();
    }
    return $comments_node;
}
Example #8
0
 /**
  *
  * @param mixed $handler_id The ID of the handler.
  * @param array &$data The local request data.
  */
 public function _show_delete($handler_id, array &$data)
 {
     $data['article'] =& $this->_article;
     $nap = new midcom_helper_nav();
     $node = $nap->get_node($this->_article->topic);
     $data['topic_url'] = $node[MIDCOM_NAV_FULLURL];
     $data['topic_name'] = $node[MIDCOM_NAV_NAME];
     $data['delete_url'] = "{$node[MIDCOM_NAV_FULLURL]}delete/{$this->_article->guid}/";
     midcom_show_style('admin-delete-link');
 }
Example #9
0
 function getUsersBlogs($message)
 {
     $args = $this->_params_to_args($message);
     if (count($args) != 3) {
         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();
     $response = array();
     $topic = $this->_topic;
     if (!$topic->can_do('midgard:create')) {
         // Skip this blog, user cannot edit
         continue;
     }
     $nap = new midcom_helper_nav();
     $node = $nap->get_node($topic->id);
     if (!$node) {
         // This topic isn't on site
         continue;
     }
     $response_array = array('url' => new XML_RPC_Value($node[MIDCOM_NAV_FULLURL], 'string'), 'blogid' => new XML_RPC_Value($topic->guid, 'string'), 'blogName' => new XML_RPC_Value($node[MIDCOM_NAV_NAME], 'string'));
     $response[] = new XML_RPC_Value($response_array, 'struct');
     return new XML_RPC_Response(new XML_RPC_Value($response, 'array'));
 }
Example #10
0
if (!class_exists('org_openpsa_httplib')) {
    $singlep_uri = str_replace('midcom-exec-midcom/reindex.php', 'midcom-exec-midcom/reindex_singleprocess.php', $current_uri);
    throw new midcom_error("We need org.openpsa.httplib installed to use the granular reindex, use {$singlep_uri} to get the old way.");
}
debug_add('Disabling script abort through client.');
ignore_user_abort(true);
debug_add("Setting memory limit to configured value of {$GLOBALS['midcom_config']['midcom_max_memory']}");
ini_set('memory_limit', $GLOBALS['midcom_config']['midcom_max_memory']);
$start = microtime(true);
$nap = new midcom_helper_nav();
$nodes = array();
$nodeid = $nap->get_root_node();
$loader = midcom::get('componentloader');
$indexer = midcom::get('indexer');
// Use this to check that indexer is online (and hope the root topic isn't a gigantic wiki)
$root_node = $nap->get_node($nodeid);
$existing_documents = $indexer->query("__TOPIC_GUID:{$root_node[MIDCOM_NAV_OBJECT]->guid}");
if ($existing_documents === false) {
    $msg = "Query '__TOPIC_GUID:{$root_node[MIDCOM_NAV_OBJECT]->guid}' returned false, indicating problem with indexer";
    throw new midcom_error($msg);
}
unset($existing_documents, $root_node);
// Disable ob
while (@ob_end_flush()) {
}
echo "<pre>\n";
debug_dump_mem("Initial Memory Usage");
$reindex_topic_uri = str_replace('midcom-exec-midcom/reindex.php', 'midcom-exec-midcom/reindex_singlenode.php', $current_uri);
$http_client = new org_openpsa_httplib();
$http_client->set_param('timeout', 300);
if (isset($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) && !empty($_SERVER['PHP_AUTH_PW'])) {
Example #11
0
 /**
  * Handle a request.
  *
  * The URL of the component that is used to handle the request is obtained automatically.
  * If the handler hook returns false (i.e. handling failed), it will produce an error page.
  *
  * @param midcom_baseclasses_components_interface $handler The component's main handler class
  */
 public function run(midcom_baseclasses_components_interface $handler)
 {
     $result = $handler->handle();
     if (false === $result) {
         throw new midcom_error("Component " . $this->get_key(MIDCOM_CONTEXT_COMPONENT) . " failed to handle the request");
     } else {
         if (is_object($result) && $result instanceof midcom_response) {
             $result->send();
             //this will exit
         }
     }
     // Retrieve Metadata
     $nav = new midcom_helper_nav();
     if ($nav->get_current_leaf() === false) {
         $meta = $nav->get_node($nav->get_current_node());
     } else {
         $meta = $nav->get_leaf($nav->get_current_leaf());
     }
     if ($this->get_key(MIDCOM_CONTEXT_PERMALINKGUID) === null) {
         $this->set_key(MIDCOM_CONTEXT_PERMALINKGUID, $meta[MIDCOM_NAV_GUID]);
     }
     if ($this->get_key(MIDCOM_CONTEXT_PAGETITLE) == '') {
         $this->set_key(MIDCOM_CONTEXT_PAGETITLE, $meta[MIDCOM_NAV_NAME]);
     }
 }
Example #12
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_edit($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $this->_document = $this->_load_document($args[0]);
     $this->_document->require_do('midgard:update');
     $this->_load_edit_controller();
     if ($data['enable_versioning'] && !empty($_POST)) {
         $this->_backup_attachment();
     }
     switch ($this->_controller->process_form()) {
         case 'save':
             // TODO: Update the URL name?
             // Update the Index
             $indexer = new org_openpsa_documents_midcom_indexer($this->_topic);
             $indexer->index($this->_controller->datamanager);
             $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
             if ($this->_document->topic != $this->_topic->id) {
                 $nap = new midcom_helper_nav();
                 $node = $nap->get_node($this->_document->topic);
                 $prefix = $node[MIDCOM_NAV_ABSOLUTEURL];
             }
             return new midcom_response_relocate($prefix . "document/" . $this->_document->guid . "/");
         case 'cancel':
             return new midcom_response_relocate(midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . "document/" . $this->_document->guid . "/");
     }
     $this->_request_data['controller'] =& $this->_controller;
     midcom::get('head')->set_pagetitle(sprintf($this->_l10n_midcom->get('edit %s'), $this->_document->title));
     // Add toolbar items
     org_openpsa_helpers::dm2_savecancel($this);
     $this->bind_view_to_object($this->_document, $this->_controller->datamanager->schema->name);
     $this->_update_breadcrumb_line('edit');
 }
Example #13
0
 /**
  * Adds a simple search form and place holder for results.
  * Also adds static options to results.
  */
 function add_elements_to_form($attributes)
 {
     // Get url to search handler
     $nav = new midcom_helper_nav();
     $root_node = $nav->get_node($nav->get_root_node());
     if (empty($root_node)) {
         return;
     }
     $this->_handler_url = $root_node[MIDCOM_NAV_FULLURL] . 'midcom-exec-midcom.helper.datamanager2/chooser_handler.php';
     $this->widget_elements[] = HTML_QuickForm::createElement('hidden', "{$this->_element_id}_handler_url", $this->_handler_url, array('id' => "{$this->_element_id}_handler_url"));
     // Text input for the search box
     $search_input = HTML_QuickForm::createElement('text', "{$this->_element_id}_search_input", $this->_translate($this->_field['title']), array_merge($attributes, array('class' => 'shorttext chooser_widget_search_input', 'id' => "{$this->_element_id}_search_input", 'style' => "display: none;")));
     if ($this->default_search) {
         $search_input->setValue($this->default_search);
         $this->_js_widget_options['default_search'] = true;
     }
     $this->widget_elements[] = $search_input;
     if ($this->creation_mode_enabled) {
         $dialog_id = $this->_element_id . '_creation_dialog';
         $dialog_html = "<div class=\"chooser_widget_creation_dialog\" id=\"{$dialog_id}\">\n";
         $dialog_html .= "</div>\n";
         $button_html = "<div class=\"chooser_widget_create_button\" id=\"{$this->_element_id}_create_button\" style=\"display: none;\">\n";
         $button_html .= "</div>\n";
         $html = $button_html . $dialog_html;
         $this->widget_elements[] = HTML_QuickForm::createElement('static', "{$this->_element_id}_creation_dialog_holder", '', $html);
     }
     $this->_jscript .= '<script type="text/javascript">';
     $this->_jscript .= 'jQuery().ready(function(){';
     $script = "jQuery('#{$this->_element_id}_search_input').midcom_helper_datamanager2_widget_chooser_widget('{$this->_handler_url}',\n";
     $script .= json_encode($this->_js_widget_options);
     $script .= ");";
     $this->_jscript .= $script;
     $this->_static_items_html .= "<table class=\"widget_chooser_static_items_table\">\n";
     $this->_static_items_html .= "    <thead>\n";
     $this->_static_items_html .= "        <tr>\n";
     if (!empty($this->reflector_key) && !$this->result_headers) {
         $title = midcom::get('i18n')->get_string('Label', 'midcom');
         $this->_static_items_html .= "            <th class=\"label\">{$title}&nbsp;</th>\n";
     } else {
         foreach ($this->result_headers as $header_item) {
             $header_title = midcom::get('i18n')->get_string(midcom::get('i18n')->get_string($header_item['title'], $this->component), 'midcom');
             $this->_static_items_html .= "            <th class=\"{$header_item['name']}\">{$header_title}&nbsp;</th>\n";
         }
     }
     $title = midcom::get('i18n')->get_string('Selected', 'midcom.helper.datamanager2');
     $this->_static_items_html .= "            <th class=\"selected\">{$title}&nbsp;</th>\n";
     $this->_static_items_html .= "        </tr>\n";
     $this->_static_items_html .= "    </thead>\n";
     $this->_static_items_html .= "    <tbody>\n";
     $this->_add_items_to_form();
     $this->_static_items_html .= "    </tbody>\n";
     $this->_static_items_html .= "</table>\n";
     $this->widget_elements[] = HTML_QuickForm::createElement('static', "{$this->_element_id}_initscripts", '', $this->_jscript);
     $this->widget_elements[] = HTML_QuickForm::createElement('static', "{$this->_element_id}_noscript", '', $this->_static_items_html);
     $this->widget_elements[] = HTML_QuickForm::createElement('hidden', "{$this->_element_id}_selections", '');
     $this->_form->addGroup($this->widget_elements, $this->name, $this->_translate($this->_field['title']), '', array('class' => 'midcom_helper_datamanager2_widget_chooser'));
     if ($this->_field['required']) {
         $errmsg = sprintf($this->_l10n->get('field %s is required'), $this->_translate($this->_field['title']));
         /*
          * @todo: This only works because of a bug in quickform. When it doesn't find a name,
          * it takes the last one in the group element array, but forgets to prefix the group name,
          * allowing us to validate against a top-level POST key. This should be replaced by a more
          * solid implementation at some point
          */
         $this->_form->addGroupRule($this->name, array("{$this->_element_id}_nonexistant" => array(array($errmsg, 'required'))));
     }
 }
Example #14
0
 /**
  * Day view
  *
  * @param String $handler_id    Name of the request handler
  * @param array $args           Variable arguments
  * @param array &$data          Public request data, passed by reference
  */
 public function _handler_day($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $this->_generate_date($args);
     // Instantiate calendar widget
     $this->_calendar = new org_openpsa_widgets_calendar(date('Y', $this->_selected_time), date('m', $this->_selected_time), date('d', $this->_selected_time));
     $this->_calendar->type = org_openpsa_widgets_calendar::DAY;
     // Slots are 2 hours long
     $this->_calendar->calendar_slot_length = $this->_config->get('day_slot_length') * 60;
     $this->_calendar->start_hour = $this->_config->get('day_start_time');
     $this->_calendar->end_hour = $this->_config->get('day_end_time');
     $this->_calendar->column_width = 60;
     $this->_populate_toolbar('day');
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'month/' . $this->_get_datestring() . '/', MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('month view'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png'));
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => 'week/' . $this->_get_datestring() . '/', MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('week view'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png'));
     // Clicking a free slot should bring up 'new event' dialogue
     $nap = new midcom_helper_nav();
     $this_node = $nap->get_node($nap->get_current_node());
     if ($this->_root_event->can_do('midgard:create')) {
         $this->_calendar->reservation_div_options = array('onclick' => org_openpsa_calendar_interface::calendar_editevent_js('__GUID__', $this_node));
     }
     $this->_calendar->free_div_options = array('onclick' => org_openpsa_calendar_interface::calendar_newevent_js($this_node, '__START__', '__RESOURCE__'));
     // Populate contacts
     $this->_populate_calendar_contacts($this->_calendar->get_day_start(), $this->_calendar->get_day_end());
     $this->_request_data['calendar'] =& $this->_calendar;
     // Set the breadcrumb
     $this->add_breadcrumb('year/' . date('Y-01-01', $this->_selected_time) . '/', strftime('%Y', $this->_selected_time));
     $this->add_breadcrumb('month/' . date('Y-m-01', $this->_selected_time) . '/', strftime('%B', $this->_selected_time));
     $this->add_breadcrumb('day/' . date('Y-m-d', $this->_selected_time) . '/', strftime('%x', $this->_selected_time));
     midcom::get('head')->set_pagetitle(strftime("%x", $this->_selected_time));
 }
Example #15
0
 private function _get_navigation_data()
 {
     $ret = array();
     // Initialize the midcom_helper_nav or navigation access point
     $nap = new midcom_helper_nav();
     switch ((int) $this->_topic->get_parameter('midcom.helper.nav', 'navorder')) {
         case MIDCOM_NAVORDER_DEFAULT:
             $ret['nodes'] = array();
             $nodes = $nap->list_nodes($nap->get_current_node());
             foreach ($nodes as $id => $node_id) {
                 $node = $nap->get_node($node_id);
                 $node[MIDCOM_NAV_TYPE] = 'node';
                 $ret['nodes'][$id] = $node;
             }
             break;
         case MIDCOM_NAVORDER_TOPICSFIRST:
             // Sort the array to have the nodes first
             $ret = array('nodes' => array(), 'leaves' => array());
             // Fall through
         // Fall through
         case MIDCOM_NAVORDER_ARTICLESFIRST:
             // Sort the array to have the leaves first
             if (!isset($ret['leaves'])) {
                 $ret = array('leaves' => array(), 'nodes' => array());
             }
             // Get the nodes
             $nodes = $nap->list_nodes($nap->get_current_node());
             foreach ($nodes as $id => $node_id) {
                 $node = $nap->get_node($node_id);
                 $node[MIDCOM_NAV_TYPE] = 'node';
                 $ret['nodes'][$id] = $node;
             }
             // Get the leafs
             $leaves = $nap->list_leaves($nap->get_current_node());
             foreach ($leaves as $id => $leaf_id) {
                 $leaf = $nap->get_leaf($leaf_id);
                 $leaf[MIDCOM_NAV_TYPE] = 'leaf';
                 $ret['leaves'][$id] = $leaf;
             }
             break;
         case MIDCOM_NAVORDER_SCORE:
         default:
             $ret['mixed'] = array();
             // Get the navigation items
             $items = $nap->list_child_elements($nap->get_current_node());
             foreach ($items as $id => $item) {
                 if ($item[MIDCOM_NAV_TYPE] === 'node') {
                     $element = $nap->get_node($item[MIDCOM_NAV_ID]);
                 } else {
                     $element = $nap->get_leaf($item[MIDCOM_NAV_ID]);
                 }
                 // Store the type information
                 $element[MIDCOM_NAV_TYPE] = $item[MIDCOM_NAV_TYPE];
                 $ret['mixed'][] = $element;
             }
             break;
     }
     return $ret;
 }
Example #16
0
 /**
  * Indexes an article.
  *
  * @param midcom_helper_datamanager2_datamanager &$dm The Datamanager encapsulating the event.
  * @param midcom_services_indexer &$indexer The indexer instance to use.
  * @param midcom_db_topic The topic which we are bound to. If this is not an object, the code
  *     tries to load a new topic instance from the database identified by this parameter.
  */
 public static function index(&$dm, &$indexer, $topic)
 {
     $config = new midcom_helper_configuration($topic, 'net.nehmer.blog');
     if ($config->get('disable_indexing')) {
         return;
     }
     if (!is_object($topic)) {
         $topic = new midcom_db_topic($topic);
     }
     // Don't index directly, that would lose a reference due to limitations
     // of the index() method. Needs fixes there.
     $nav = new midcom_helper_nav();
     $node = $nav->get_node($topic->id);
     $document = $indexer->new_document($dm);
     $document->topic_guid = $topic->guid;
     $document->component = $topic->component;
     $document->topic_url = $node[MIDCOM_NAV_FULLURL];
     $document->read_metadata_from_object($dm->storage->object);
     $indexer->index($document);
 }
Example #17
0
 /**
  * Links to other wiki pages tagged with arbitrary tags
  */
 private function _run_macro_tagged($macro_content, $fulltag, $after)
 {
     if (!midcom::get('componentloader')->load_library('net.nemein.tag')) {
         // TODO: do something to explain that we can't load n.n.tag...
         return $fulltag;
     }
     $tags_exploded = explode(',', $macro_content);
     $tags = array();
     foreach ($tags_exploded as $tagname) {
         if (empty($tagname)) {
             continue;
         }
         $tag = net_nemein_tag_handler::resolve_tagname(trim($tagname));
         $tags[$tag] = $tag;
     }
     $classes = array('net_nemein_wiki_wikipage', 'midcom_db_article', 'midgard_article');
     $pages = net_nemein_tag_handler::get_objects_with_tags($tags, $classes, 'OR');
     if (!is_array($pages)) {
         // Failure in tag library
         return $fulltag;
     }
     $nap = new midcom_helper_nav();
     static $node_cache = array();
     $ret = "\n<ul class=\"tagged\">\n";
     usort($pages, array($this, '_code_sort_by_title'));
     foreach ($pages as $page) {
         if (!isset($node_cache[$page->topic])) {
             $node_cache[$page->topic] = $nap->get_node($page->topic);
         }
         $node =& $node_cache[$page->topic];
         if ($node[MIDCOM_NAV_COMPONENT] !== 'net.nemein.wiki') {
             // We only wish to link to wiki pages
             continue;
         }
         $url = $node[MIDCOM_NAV_FULLURL] . "{$page->name}/";
         $ret .= "    <li class=\"page\"><a href=\"{$url}\">{$page->title}</a></li>\n";
     }
     $ret .= "</ul>\n";
     return $ret . $after;
 }
Example #18
0
 /**
  * Indexes a product
  *
  * This function is usually called statically from various handlers.
  *
  * @param midcom_helper_datamanager2_datamanager &$dm The Datamanager encapsulating the event.
  * @param midcom_services_indexer &$indexer The indexer instance to use.
  * @param midcom_db_topic The topic which we are bound to. If this is not an object, the code
  *     tries to load a new topic instance from the database identified by this parameter.
  */
 public static function index(&$dm, &$indexer, $topic, $config = null)
 {
     if ($config == null) {
         $config = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config');
     }
     $object =& $dm->storage->object;
     if (!is_object($topic)) {
         $topic = new midcom_db_topic($topic);
     }
     // Don't index directly, that would lose a reference due to limitations
     // of the index() method. Needs fixes there.
     $document = $indexer->new_document($dm);
     if (midcom::get('dbfactory')->is_a($object, 'org_openpsa_products_product_dba')) {
         if ($config->get('enable_scheduling')) {
             // Check start/end for products
             if ($object->start != 0 && $object->start > time() || $object->end != 0 && $object->end < time()) {
                 // Not in market, remove from index
                 $indexer->delete($document->RI);
                 return;
             }
             // FIXME: add midcom at job or somesuch to reindex products after their end time (and start time if in the future)
         }
     }
     $document->topic_guid = $topic->guid;
     $document->component = $topic->component;
     $nav = new midcom_helper_nav();
     $node = $nav->get_node($topic->id);
     $document->topic_url = $node[MIDCOM_NAV_FULLURL];
     $document->read_metadata_from_object($object);
     $document->content = "{$dm->schema->name} {$dm->schema->description} {$document->content}";
     $indexer->index($document);
 }
Example #19
0
    /**
     * Adds a simple search form and place holder for results.
     * Also adds static options to results.
     */
    function add_elements_to_form($attributes)
    {
        // Get url to search handler
        $nav = new midcom_helper_nav();
        $root_node = $nav->get_node($nav->get_root_node());
        if (!$root_node || empty($root_node)) {
            return;
        }
        $handler_url = $root_node[MIDCOM_NAV_FULLURL] . 'midcom-exec-midcom.helper.datamanager2/autocomplete_handler.php';
        $selection = $this->_get_selection();
        $this->_widget_elements[] = HTML_QuickForm::createElement('hidden', "{$this->_element_id}_selection", json_encode($selection), array('id' => "{$this->_element_id}_selection"));
        $preset = '';
        if (!empty($selection)) {
            $identifier = $selection[0];
            if ($this->id_field == 'id') {
                $identifier = (int) $identifier;
            }
            try {
                $object = new $this->class($identifier);
                $preset = self::create_item_label($object, $this->result_headers, $this->get_label_for);
            } catch (midcom_error $e) {
                $e->log();
            }
        }
        // Text input for the search box
        $this->_widget_elements[] = HTML_QuickForm::createElement('text', "{$this->_element_id}_search_input", $this->_translate($this->_field['title']), array_merge($attributes, array('class' => 'shorttext autocomplete_input', 'id' => "{$this->_element_id}_search_input", 'value' => $preset)));
        $handler_options = json_encode(array('handler_url' => $handler_url, 'class' => $this->class, 'component' => $this->component, 'id_field' => $this->id_field, 'constraints' => $this->constraints, 'result_headers' => $this->result_headers, 'searchfields' => $this->searchfields, 'orders' => $this->orders, 'auto_wildcards' => $this->auto_wildcards));
        $script = <<<EOT
            var {$this->_element_id}_handler_options = {$handler_options}
        jQuery(document).ready(
        function()
        {
            jQuery('#{$this->_element_id}_search_input').autocomplete(
            {
                minLength: {$this->min_chars},
                source: midcom_helper_datamanager2_autocomplete.query,
                select: midcom_helper_datamanager2_autocomplete.select
            })
        });
EOT;
        if ($this->creation_mode_enabled) {
            $script .= <<<EOT
            jQuery(document).ready(
                function()
                {
                    midcom_helper_datamanager2_autocomplete.enable_creation_mode('{$this->_element_id}', '{$this->creation_handler}');
                });
EOT;
        }
        $script = '<script type="text/javascript">' . $script . '</script>';
        $this->_widget_elements[] = HTML_QuickForm::createElement('static', "{$this->_element_id}_initscript", '', $script);
        $this->_form->addGroup($this->_widget_elements, $this->name, $this->_translate($this->_field['title']), '', array('class' => 'midcom_helper_datamanager2_widget_autocomplete'));
        if ($this->_field['required']) {
            $errmsg = sprintf($this->_l10n->get('field %s is required'), $this->_translate($this->_field['title']));
            $this->_form->addGroupRule($this->name, array("{$this->_element_id}_selection" => array(array($errmsg, 'required'), array($errmsg, 'regex', '/\\[.+?\\]/'))));
        }
    }
Example #20
0
 /**
  * Adds a simple single-line text form element and place holder for tags.
  */
 function add_elements_to_form($attributes)
 {
     $attributes = array_merge($attributes, array('class' => "shorttext", 'id' => $this->_input_element_id));
     $this->widget_elements[] = HTML_QuickForm::createElement('text', "{$this->name}_input", $this->_translate($this->_field['title']), $attributes);
     // Get url to search handler
     $nav = new midcom_helper_nav();
     $root_node = $nav->get_node($nav->get_root_node());
     $this->_handler_url = $root_node[MIDCOM_NAV_FULLURL] . 'midcom-exec-midcom.helper.datamanager2/tags_handler.php';
     $this->_jscript .= '<script type="text/javascript">';
     $this->_jscript .= 'jQuery().ready(function(){';
     $script = "jQuery('#{$this->_input_element_id}').midcom_helper_datamanager2_widget_tags_widget('{$this->_handler_url}', {\n";
     foreach ($this->_js_widget_options as $key => $value) {
         $script .= "{$key}: {$value},\n";
     }
     $script .= "});";
     $this->_jscript .= $script;
     // Add existing selection
     $existing_elements = $this->_type->selection;
     $ee_script = '';
     foreach ($existing_elements as $key) {
         $data = $this->_get_key_data($key);
         $ee_script .= "jQuery('#{$this->_input_element_id}').midcom_helper_datamanager2_widget_tags_add_selection_item({$data});\n";
     }
     $this->_jscript .= $ee_script;
     $this->_jscript .= '});';
     $this->_jscript .= '</script>';
     $this->widget_elements[] = HTML_QuickForm::createElement('static', "{$this->name}_initscripts", '', $this->_jscript);
     $this->_form->addGroup($this->widget_elements, $this->name, $this->_translate($this->_field['title']), '', array('class' => 'midcom_helper_datamanager2_widget_tags'));
 }
Example #21
0
 /**
  * Shows the _Delete folder_ form.
  *
  * @param mixed $handler_id The ID of the handler.
  * @param array &$data The local request data.
  */
 public function _show_delete($handler_id, array &$data)
 {
     if (!empty($this->_topic->symlink)) {
         try {
             $topic = new midcom_db_topic($this->_topic->symlink);
             $data['symlink'] = '';
             $nap = new midcom_helper_nav();
             if ($node = $nap->get_node($topic)) {
                 $data['symlink'] = $node[MIDCOM_NAV_FULLURL];
             }
         } catch (midcom_error $e) {
             debug_add("Could not get target for symlinked topic #{$this->_topic->id}: " . $e->getMessage(), MIDCOM_LOG_ERROR);
         }
     }
     $data['title'] = $this->_topic->extra;
     if (!$data['title']) {
         $data['title'] = $this->_topic->name;
     }
     midcom_show_style('midcom-admin-show-delete-folder');
 }
Example #22
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_create($handler_id, array $args, array &$data)
 {
     $data['directory']->require_do('midgard:create');
     $this->_defaults = array('topic' => $this->_request_data['directory']->id, 'author' => midcom_connection::get_user(), 'orgOpenpsaAccesstype' => $this->_topic->get_parameter('org.openpsa.core', 'orgOpenpsaAccesstype'), 'orgOpenpsaOwnerWg' => $this->_topic->get_parameter('org.openpsa.core', 'orgOpenpsaOwnerWg'));
     $this->_load_create_controller();
     switch ($this->_controller->process_form()) {
         case 'save':
             /* Index the document */
             $indexer = new org_openpsa_documents_midcom_indexer($this->_topic);
             $indexer->index($this->_controller->datamanager);
             // Relocate to document view
             $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
             if ($this->_document->topic != $this->_topic->id) {
                 $nap = new midcom_helper_nav();
                 $node = $nap->get_node($this->_document->topic);
                 $prefix = $node[MIDCOM_NAV_ABSOLUTEURL];
             }
             return new midcom_response_relocate($prefix . "document/" . $this->_document->guid . "/");
         case 'cancel':
             return new midcom_response_relocate('');
     }
     $this->_request_data['controller'] =& $this->_controller;
     // Add toolbar items
     org_openpsa_helpers::dm2_savecancel($this);
     $this->add_breadcrumb("", $this->_l10n->get('create document'));
 }
Example #23
0
 /**
  * Displays the archive.
  *
  * @param mixed $handler_id The ID of the handler.
  * @param array &$data The local request data.
  */
 public function _show_list($handler_id, array &$data)
 {
     // FIXME: For some reason the config topic is lost between _handle and _show phases
     $this->_config->store_from_object($this->_topic, $this->_component);
     midcom_show_style('archive-list-start');
     if ($this->_articles) {
         $data['index_fulltext'] = $this->_config->get('index_fulltext');
         if ($this->_config->get('comments_enable')) {
             midcom::get('componentloader')->load_graceful('net.nehmer.comments');
             $data['comments_enable'] = true;
         }
         $total_count = count($this->_articles);
         $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
         foreach ($this->_articles as $article_counter => $article) {
             if (!$this->_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;
             }
             $data['article'] =& $article;
             $data['article_counter'] = $article_counter;
             $data['article_count'] = $total_count;
             $arg = $article->name ? $article->name : $article->guid;
             if ($this->_config->get('view_in_url')) {
                 $data['local_view_url'] = "{$prefix}view/{$arg}/";
             } else {
                 $data['local_view_url'] = "{$prefix}{$arg}/";
             }
             if ($this->_config->get('link_to_external_url') && !empty($article->url)) {
                 $data['view_url'] = $article->url;
             } else {
                 $data['view_url'] = $data['local_view_url'];
             }
             if ($article->topic === $this->_content_topic->id) {
                 $data['linked'] = false;
             } else {
                 $data['linked'] = true;
                 $nap = new midcom_helper_nav();
                 $data['node'] = $nap->get_node($article->topic);
             }
             midcom_show_style('archive-list-item');
         }
     } else {
         midcom_show_style('archive-list-empty');
     }
     midcom_show_style('archive-list-end');
 }
Example #24
0
 /**
  * Creates the tab view for all enabled positioning methods
  * Also adds static options to results.
  */
 function add_elements_to_form($attributes)
 {
     // Get url to geocode handler
     $nav = new midcom_helper_nav();
     $root_node = $nav->get_node($nav->get_root_node());
     $this->_handler_url = $root_node[MIDCOM_NAV_FULLURL] . 'midcom-exec-org.routamc.positioning/geocode.php';
     $html = "<div id=\"{$this->_element_id}\" class=\"midcom_helper_datamanager2_widget_position\"><!-- widget starts -->\n";
     $html .= "<input class=\"position_widget_id\" id=\"{$this->_element_id}_id\" name=\"{$this->_element_id}_id\" type=\"hidden\" value=\"{$this->_element_id}\" />";
     $html .= "<input class=\"position_widget_backend_url\" id=\"{$this->_element_id}_backend_url\" name=\"{$this->_element_id}_backend_url\" type=\"hidden\" value=\"{$this->_handler_url}\" />";
     $html .= "<input class=\"position_widget_backend_service\" id=\"{$this->_element_id}_backend_service\" name=\"{$this->_element_id}_backend_service\" type=\"hidden\" value=\"{$this->service}\" />";
     $html .= "    <ul>\n";
     foreach ($this->enabled_methods as $method) {
         $html .= "        <li><a href=\"#{$this->_element_id}_tab_content_{$method}\"><span>" . midcom::get('i18n')->get_string($method, 'org.routamc.positioning') . "</span></a></li>\n";
     }
     $html .= "    </ul>\n";
     $this->_widget_elements[] = HTML_QuickForm::createElement('static', "{$this->_element_id}_static_widget_start", '', $html);
     foreach ($this->enabled_methods as $method) {
         $function = "_add_{$method}_method_elements";
         $this->{$function}();
     }
     $html = "</div><!-- widget ends -->\n";
     $this->_widget_elements[] = HTML_QuickForm::createElement('static', "{$this->_element_id}_static_widget_end", '', $html);
     $this->_main_group = $this->_form->addGroup($this->_widget_elements, $this->name, $this->_translate($this->_field['title']), '');
 }
Example #25
0
}
$site_root = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPIC);
$host_prefix = midcom::get()->get_host_prefix();
$nap = new midcom_helper_nav();
$qb = midcom_db_topic::new_query_builder();
$qb->add_constraint('up', 'INTREE', $site_root->id);
$qb->begin_group('OR');
$qb->add_constraint('metadata.hidden', '=', 1);
$qb->add_constraint('metadata.navnoentry', '=', 1);
$qb->end_group();
$qb->add_order('name');
$topics = $qb->execute();
unset($qb);
echo "<h2>Topics</h2>\n";
foreach ($topics as $topic) {
    $node =& $nap->get_node($topic->id);
    $crumbs =& $nap->get_breadcrumb_data($node[MIDCOM_NAV_ID]);
    $n_crumbs = count($crumbs);
    $i = 0;
    render_breadcrumb($crumbs);
    echo " (<a href='{$host_prefix}__mfa/asgard/object/view/{$topic->guid}'>in Asgard</a>)<br/>\n";
}
echo "<h2>Articles</h2>\n";
$qb = midcom_db_article::new_query_builder();
$qb->add_constraint('topic', 'INTREE', $site_root->id);
$qb->begin_group('OR');
$qb->add_constraint('metadata.hidden', '=', 1);
$qb->add_constraint('metadata.navnoentry', '=', 1);
$qb->end_group();
$qb->add_order('name');
$articles = $qb->execute();
Example #26
0
 private function _prepare_send(&$data)
 {
     $nap = new midcom_helper_nav();
     $node = $nap->get_node($nap->get_current_node());
     $data['compose_url'] = $node[MIDCOM_NAV_RELATIVEURL] . 'message/compose/' . $data['message_obj']->guid;
     $data['batch_url_base_full'] = $node[MIDCOM_NAV_RELATIVEURL] . 'message/send_bg/' . $data['message_obj']->guid;
     debug_add("compose_url: {$data['compose_url']}");
     debug_add("batch_url base: {$data['batch_url_base_full']}");
     $de_backup = ini_get('display_errors');
     $le_backup = ini_get('log_errors');
     ini_set('log_errors', true);
     ini_set('display_errors', false);
     ob_start();
     midcom::get()->dynamic_load($data['compose_url']);
     $composed = ob_get_contents();
     ob_end_clean();
     ini_set('display_errors', $de_backup);
     ini_set('log_errors', $le_backup);
     //We force the content-type since the compositor might have set it to something else in compositor for preview purposes
     debug_add('Forcing content type: text/html');
     midcom::get('cache')->content->content_type('text/html');
     //PONDER: Should we leave these entirely for the methods to parse from the array ?
     $data['compose_subject'] = '';
     $data['compose_from'] = '';
     if (array_key_exists('subject', $data['message_array'])) {
         $data['compose_subject'] =& $data['message_array']['subject'];
     }
     if (array_key_exists('from', $data['message_array'])) {
         $data['compose_from'] =& $data['message_array']['from'];
     }
     //Get SMS/MMS settings from component configuration
     if ($smslib_api = $this->_config->get('smslib_api')) {
         $data['message_obj']->sms_lib_api = $smslib_api;
     }
     if ($smslib_uri = $this->_config->get('smslib_uri')) {
         $data['message_obj']->sms_lib_location = $smslib_uri;
     } else {
         if ($email2sms_address = $this->_config->get('email2sms_address')) {
             $data['message_obj']->sms_lib_location = $email2sms_address;
         }
     }
     if ($smslib_client_id = $this->_config->get('smslib_client_id')) {
         $data['message_obj']->sms_lib_client_id = $smslib_client_id;
     }
     if ($smslib_user = $this->_config->get('smslib_user')) {
         $data['message_obj']->sms_lib_user = $smslib_user;
     }
     if ($smslib_password = $this->_config->get('smslib_password')) {
         $data['message_obj']->sms_lib_password = $smslib_password;
     }
     if ($mail_send_backend = $this->_config->get('mail_send_backend')) {
         $data['message_array']['mail_send_backend'] = $mail_send_backend;
     }
     if ($bouncer_address = $this->_config->get('bouncer_address')) {
         $data['message_array']['bounce_detector_address'] = $bouncer_address;
     }
     if ($link_detector_address = $this->_config->get('linkdetector_address')) {
         $data['message_array']['link_detector_address'] = $link_detector_address;
     }
     if ($token_size = $this->_config->get('token_size')) {
         $data['message_obj']->token_size = $token_size;
     }
     return $composed;
 }
Example #27
0
<?php

$nap = new midcom_helper_nav();
$node = $nap->get_node($nap->get_current_node());
?>
<div class="sidebar">
<div class="area org_openpsa_helper_box">
    <h3><?php 
echo $data['l10n']->get('groups');
?>
</h3>
<?php 
$data['tree']->render();
?>
</div>
</div>

<div class="main">
    <?php 
midcom::get()->dynamic_load($node[MIDCOM_NAV_RELATIVEURL] . "mycontacts");
?>
</div>
Example #28
0
 private function _resolve_permalink_in_topic($topic, $guid)
 {
     // get the interface class
     // if we have a next-generation-one, use it to look up the required information
     // otherwise settle with a NAP scan
     // in any way, return in the same way as resolve_permalink itself.
     $component = $topic->component;
     if (!midcom::get('componentloader')->is_installed($component)) {
         return null;
     }
     $interface = midcom::get('componentloader')->get_interface_class($component);
     if ($interface === null) {
         debug_add("Failed to load the interface class for the component {$component} of the topic #{$topic->id}, cannot attempt to resolve the permalink here.", MIDCOM_LOG_WARN);
         debug_print_r('Passed topic was:', $topic);
         return null;
     }
     $result = $interface->resolve_permalink($topic, $guid);
     if ($result === null) {
         return null;
     }
     $nav = new midcom_helper_nav();
     $node = $nav->get_node($topic->id);
     if (!$node) {
         debug_add("Failed to load the NAP information of the topic #{$topic->id}, cannot attempt to resolve the permalink here.", MIDCOM_LOG_WARN);
         debug_print_r('Passed topic was:', $topic);
         return null;
     }
     return "{$node[MIDCOM_NAV_FULLURL]}{$result}";
 }
Example #29
0
 /**
  * This helper function returns the first instance of a given component on
  * the MidCOM site.
  *
  * @return array NAP array of the first component instance found
  */
 public static function find_node_by_component($component, $node_id = null, $nap = null)
 {
     static $cache = array();
     $cache_node = $node_id;
     if (is_null($cache_node)) {
         $cache_node = 0;
     }
     if (!isset($cache[$cache_node])) {
         $cache[$cache_node] = array();
     }
     if (array_key_exists($component, $cache[$cache_node])) {
         return $cache[$cache_node][$component];
     }
     if (is_null($nap)) {
         $nap = new midcom_helper_nav();
     }
     if (is_null($node_id)) {
         $node_id = $nap->get_root_node();
         $root_node = $nap->get_node($node_id);
         if ($root_node[MIDCOM_NAV_COMPONENT] == $component) {
             $cache[$cache_node][$component] = $root_node;
             return $root_node;
         }
     }
     // Otherwise, go with QB
     $qb = midcom_db_topic::new_query_builder();
     $qb->add_constraint('component', '=', $component);
     $qb->add_constraint('name', '<>', '');
     $qb->add_constraint('up', 'INTREE', $node_id);
     $qb->set_limit(1);
     $topics = $qb->execute();
     if (count($topics) == 0) {
         $cache[$cache_node][$component] = null;
         return null;
     }
     $node = $nap->get_node($topics[0]->id);
     $cache[$cache_node][$component] = $node;
     return $node;
 }
Example #30
0
 /**
  * Try to find the comments node (cache results)
  * @return object node which has the dataset comments
  * @access private
  */
 function _seek_comments()
 {
     $comments_node = false;
     if ($this->_config->get('comments_topic_id')) {
         $nap = new midcom_helper_nav();
         $comments_node = $nap->get_node($this->_config->get('comments_topic_id'));
     } else {
         // No comments topic specified, autoprobe
         $comments_node = midcom_helper_find_node_by_component('net.nehmer.comments');
     }
     return $comments_node;
 }