Example #1
0
 private function _list_wiki_nodes($node, $prefix = '')
 {
     static $nap = null;
     if (is_null($nap)) {
         $nap = new midcom_helper_nav();
     }
     $nodes = array();
     if ($prefix == '') {
         // This is the root node
         $node_identifier = '';
         $nodes['/'] = $node;
     } else {
         $node_identifier = "{$prefix}{$node[MIDCOM_NAV_NAME]}";
         $nodes[$node_identifier] = $node;
     }
     $subnodes = $nap->list_nodes($node[MIDCOM_NAV_ID]);
     foreach ($subnodes as $node_id) {
         $subnode = $nap->get_node($node_id);
         if ($subnode[MIDCOM_NAV_COMPONENT] != 'net.nemein.wiki') {
             // This is not a wiki folder, skip
             continue;
         }
         $subnode_children = $this->_list_wiki_nodes($subnode, "{$node_identifier}/");
         $nodes = array_merge($nodes, $subnode_children);
     }
     return $nodes;
 }
Example #2
0
 private function _get_css_classes($child, $item, $item_counter, $item_count)
 {
     $classes = array();
     if ($child[MIDCOM_NAV_TYPE] === 'node') {
         // If the listing of nodes is set to false, skip this item and proceed to the next
         if ($this->list_nodes === false) {
             continue;
         }
         if ($item[MIDCOM_NAV_ID] === $this->_nap->get_current_node() && (!$this->_nap->get_current_leaf() || !$this->_nap->get_leaf($this->_nap->get_current_leaf()))) {
             $classes[] = $this->css_active;
         }
         if (in_array($item[MIDCOM_NAV_ID], $this->node_path, true)) {
             $classes[] = $this->css_selected;
         }
         if ($this->component_name_to_class) {
             $classes[] = str_replace('.', '_', $item[MIDCOM_NAV_COMPONENT]);
         }
     } else {
         // Place the corresponding css class for the currently active leaf)
         if ($item[MIDCOM_NAV_ID] === $this->_nap->get_current_leaf()) {
             $classes[] = $this->css_active;
             $classes[] = $this->css_selected;
         }
     }
     // Check if the URL name is supposed to be drawn
     if ($this->url_name_to_class) {
         $classes[] = str_replace('/', '', $item[MIDCOM_NAV_URL]);
     }
     if ($this->first_and_last_to_class) {
         if ($item_count == 1) {
             $classes[] = $this->css_first_last;
         } else {
             if ($item_counter == 1) {
                 $classes[] = $this->css_first;
             } else {
                 if ($item_counter == $item_count) {
                     $classes[] = $this->css_last;
                 }
             }
         }
     }
     if ($this->has_children_to_class) {
         if (!$this->list_leaves) {
             $children = $this->_nap->list_nodes($child[MIDCOM_NAV_ID]);
         } else {
             $children = $this->_nap->list_child_elements($child[MIDCOM_NAV_ID]);
         }
         if (is_array($children) && count($children) > 0) {
             $classes[] = $this->css_has_children;
         }
     }
     // Add information about the object's status
     if ($this->object_status_to_class && isset($item[MIDCOM_NAV_OBJECT]) && ($css_status_class = midcom::get('metadata')->get_object_classes($item[MIDCOM_NAV_OBJECT]))) {
         $classes[] = $css_status_class;
     }
     return implode(' ', $classes);
 }
Example #3
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 #4
0
        echo "failure.\n   Background processing failed, error: {$http_client->error}\n";
        echo "Url: " . $reindex_topic_uri . "?" . $post_string . "\n";
    } else {
        if (!preg_match("#(\n|\r\n)Reindex complete for node http.*\\s*</pre>\\s*\$#", $response)) {
            // Does not end with 'Reindex complete for node...'
            echo "failure.\n   Background reindex returned unexpected data:\n---\n{$response}\n---\n";
            echo "Url: " . $reindex_topic_uri . "?" . $post_string . "\n\n";
        } else {
            // Background reindex ok
            echo "OK.\n";
        }
    }
    flush();
    debug_dump_mem("Mem usage after {$node[MIDCOM_NAV_RELATIVEURL]}; {$node[MIDCOM_NAV_COMPONENT]}");
    // Retrieve all child nodes and append them to $nodes:
    $childs = $nap->list_nodes($nodeid);
    if ($childs === false) {
        throw new midcom_error("Failed to list the child nodes of {$nodeid}. Aborting.");
    }
    $nodes = array_merge($nodes, $childs);
    $nodeid = array_shift($nodes);
}
debug_add('Enabling script abort through client again.');
ignore_user_abort(false);
if ($ip_sudo) {
    midcom::get('auth')->drop_sudo();
}
//re-enable ob
ob_start();
?>
Example #5
0
 /**
  * Removes the folder from indexer if applicable.
  */
 private function _delete_topic_update_index()
 {
     if ($GLOBALS['midcom_config']['indexer_backend'] === false) {
         // Indexer is not configured.
         return;
     }
     debug_add("Dropping all NAP registered objects from the index.");
     // First we collect everything we have to delete, this might take a while
     // so we keep an eye on the script timeout.
     $guids = array();
     $nap = new midcom_helper_nav();
     $node_list = array($nap->get_current_node());
     while (count($node_list) > 0) {
         set_time_limit(30);
         // Add the node being processed.
         $nodeid = array_shift($node_list);
         debug_add("Processing node {$nodeid}");
         $node = $nap->get_node($nodeid);
         $guids[] = $node[MIDCOM_NAV_GUID];
         debug_add("Processing leaves of node {$nodeid}");
         $leaves = $nap->list_leaves($nodeid, true);
         debug_add('Got ' . count($leaves) . ' leaves.');
         foreach ($leaves as $leafid) {
             $leaf = $nap->get_leaf($leafid);
             $guids[] = $leaf[MIDCOM_NAV_GUID];
         }
         debug_add('Loading subnodes');
         $node_list = array_merge($node_list, $nap->list_nodes($nodeid, true));
         debug_print_r('Remaining node queue', $node_list);
     }
     debug_add('We have to delete ' . count($guids) . ' objects from the index.');
     // Now we go over the entire index and delete the corresponding objects.
     // We load all attachments of the corresponding objects as well, to have
     // them deleted too.
     //
     // Again we keep an eye on the script timeout.
     $indexer = midcom::get('indexer');
     foreach ($guids as $guid) {
         set_time_limit(60);
         try {
             $object = midcom::get('dbfactory')->get_object_by_guid($guid);
             $atts = $object->list_attachments();
             if ($atts) {
                 foreach ($atts as $attachment) {
                     debug_add("Deleting attachment {$attachment->id} from the index.");
                     $indexer->delete($attachment->guid);
                 }
             }
         } catch (midcom_error $e) {
             $e->log();
         }
         debug_add("Deleting guid {$guid} from the index.");
         $indexer->delete($guid);
     }
 }
Example #6
0
 /**
  * Get the URL where the topic links to
  *
  * @param array &$data   Request data
  * @return String containing redirection URL
  */
 public static function topic_links_to(&$data)
 {
     $config =& $data['config'];
     switch ($data['config']->get('redirection_type')) {
         case 'node':
             $nap = new midcom_helper_nav();
             $id = $data['config']->get('redirection_node');
             if (is_string($id)) {
                 try {
                     $topic = new midcom_db_topic($id);
                     $id = $topic->id;
                 } catch (midcom_error $e) {
                     $e->log();
                     break;
                 }
             }
             $node = $nap->get_node($id);
             // Node not found, fall through to configuration
             if (!$node) {
                 break;
             }
             return $node[MIDCOM_NAV_FULLURL];
         case 'subnode':
             $nap = new midcom_helper_nav();
             $nodes = $nap->list_nodes($nap->get_current_node());
             // Subnodes not found, fall through to configuration
             if (count($nodes) == 0) {
                 break;
             }
             // Redirect to first node
             $node = $nap->get_node($nodes[0]);
             return $node[MIDCOM_NAV_FULLURL];
         case 'permalink':
             $url = midcom::get('permalinks')->resolve_permalink($data['config']->get('redirection_guid'));
             if ($url) {
                 return $url;
             }
         case 'url':
             if ($data['config']->get('redirection_url') != '') {
                 $url = $data['config']->get('redirection_url');
                 // Support varying host prefixes
                 if (strpos($url, '__PREFIX__') !== false) {
                     $url = str_replace('__PREFIX__', midcom_connection::get_url('self'), $url);
                 }
                 return $url;
             }
             // Otherwise fall-through to config
     }
     $prefix = midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX);
     return "{$prefix}config/";
 }