Example #1
0
 /**
  * Method for drawing the navigation.
  */
 public function draw()
 {
     if (!$this->root_id) {
         $this->root_id = $this->_nap->get_root_node();
     }
     if ($this->skip_levels !== 0) {
         if (!array_key_exists($this->skip_levels, $this->node_path)) {
             return;
         }
         $this->root_id = $this->node_path[$this->skip_levels];
     }
     if ($this->show_only_current) {
         $this->root_id = $this->_nap->get_current_node();
     }
     $this->_list_child_elements($this->root_id);
 }
Example #2
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 #3
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 #4
0
$language = midcom::get('i18n')->get_current_language();
if (isset($_REQUEST['language'])) {
    $language = $_REQUEST['language'];
}
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");
Example #5
0
 /**
  * This function resolves any GUID into a fully qualified URL which can be relocated
  * to. It operates in multiple phases:
  *
  * 1. Check, whether the GUID is already known by NAP. In case we have the corresponding
  *    node/leaf loaded, use its linking information directly.
  * 2. Look if we have a topic, in that case, we get the corresponding NAP node and use
  *    it to resolve the permalink. If that object is not retrievable, the lookup
  *    fails.
  * 3. We check whether the object in question has a topic as one of its ancestors. If yes,
  *    that topic and its corresponding component is used to lookup the GUID, which might
  *    fail.
  * 4. As a last resort we have to iterate over all NAP topics to do the resolving.
  *
  * @param string $guid The GUID to resolve.
  * @return string The full HTTP relocation'able URL to the GUID.
  */
 function resolve_permalink($guid)
 {
     // resolves a guid into a fully qualified url, uses some heuristics for that, mainly replaces
     // the nap permalink resolver, with the difference that it will be based on the
     // components permalink interface code.
     $nav = new midcom_helper_nav();
     // Step 1: Maybe NAP already knows the topic.
     $napobj = $nav->resolve_guid($guid);
     if ($napobj) {
         return $napobj[MIDCOM_NAV_FULLURL];
     }
     try {
         $object = midcom::get('dbfactory')->get_object_by_guid($guid);
     } catch (midcom_error $e) {
         debug_add("Failed to resolve the GUID {$guid}, this is most probably an access denied error.", MIDCOM_LOG_ERROR);
         debug_add('Last MidCOM error string: ' . $e->getMessage());
         return null;
     }
     $metadata = midcom_helper_metadata::retrieve($object);
     if (!$metadata->is_object_visible_onsite()) {
         return null;
     }
     if (is_a($object, 'midcom_db_topic')) {
         $napobj = $nav->get_node($object->id);
         if (!$napobj) {
             debug_add("Failed to retrieve the NAP object for topic {$object->id}.", MIDCOM_LOG_INFO);
             return null;
         }
         return $napobj[MIDCOM_NAV_FULLURL];
     }
     if (is_a($object, 'midcom_db_attachment')) {
         // Faster linking to attachments
         $parent = $object->get_parent();
         if (is_a($parent, 'midcom_db_topic') && $nav->is_node_in_tree($parent->id, $nav->get_root_node())) {
             $napobj = $nav->get_node($parent->id);
             return $napobj[MIDCOM_NAV_FULLURL] . $object->name;
         } else {
             return "{$GLOBALS['midcom_config']['midcom_site_url']}midcom-serveattachmentguid-{$object->guid}/{$object->name}";
         }
     }
     // Ok, unfortunately, this is not an immediate topic. We try to traverse
     // upwards in the object chain to find a topic.
     $topic = null;
     $parent = $object->get_parent();
     while ($parent) {
         if (is_a($parent, 'midcom_db_topic')) {
             // Verify that this topic is within the current sites tree, if it is not,
             // we ignore it. This might happen on symlink topics with static & co
             // which point to the outside f.x.
             if ($nav->is_node_in_tree($parent->id, $nav->get_root_node())) {
                 $topic = $parent;
                 break;
             }
         }
         $parent = $parent->get_parent();
     }
     if ($topic !== null) {
         $return_value = $this->_resolve_permalink_in_topic($topic, $guid);
         if ($return_value != null) {
             return $return_value;
         }
     }
     // Bad, this means a full scan,
     // We need to try every topic for the GUID.
     $topic_qb = midcom_db_topic::new_query_builder();
     $topic_qb->add_constraint('name', '<>', '');
     $topic_qb->add_constraint('up', 'INTREE', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPIC)->id);
     $topics = $topic_qb->execute();
     foreach ($topics as $topic) {
         $result = $this->_resolve_permalink_in_topic($topic, $guid);
         if ($result !== null) {
             return $result;
         }
     }
     // We were unable to find the GUID
     return null;
 }
Example #6
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 #7
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 #8
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'))));
     }
 }