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); }
/** * 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); } }
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; }
/** * 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]); } }
/** * This interface function is used to check whether a component can handle a given GUID * or not. A topic is provided which limits the "scope" of the search * accordingly. It can be safely assumed that the topic given is a valid topic in the * MidCOM content tree (it is checked through NAP). * * If the guid could be successfully resolved, a URL local to the given topic without a * leading slash must be returned (f.x. 'article/'), empty strings ('') are allowed * indicating root page access. If the GUID is invalid, null will be returned. * * This call is relayed to the component using the event handler _on_resolve_permalink(). * Before that it will deduce the active configuration for the given topic. * * The information you return with this call (if no-null) will be considered cacheable by * the content caching engine. Therefore you have to ensure that either the resolution * is stable or that you configure the content cache accordingly if you have a match. * The hard way is setting the no_cache flag in cases where you need full flexibility, but * this should be avoided for the sake of performance if somehow possible. The more * sophisticated alternative is therefore to selectively invalidate all GUIDs that have * their Permalink lookup affected. * * <b>Important Note:</b> * * Be aware that this is the only event handler at this time which has a real default * implementation: If you do not override the base class implementation, it will iterate * through all NAP leaves applicable to the node associated with the topic. If a match * is found, its local URL will be returned. This will not be terribly efficient, so * you are strongly encouraged to have some more efficient solution instead. Obviously, * if you override the function, you shouldn't call the base class implementation unless * you really need it. * * @param string $guid The permalink GUID that should be looked up. * @param midcom_db_topic $topic the Topic to look up. * @param midcom_helper_configuration $config The configuration used for the given topic. * @return string The local URL (without leading slashes) or null on failure. */ public function _on_resolve_permalink($topic, $config, $guid) { $nav = new midcom_helper_nav(); $leaves = $nav->list_leaves($topic->id); if (!$leaves) { return null; } foreach ($leaves as $leafid) { $leaf = $nav->get_leaf($leafid); if ($leaf[MIDCOM_NAV_GUID] == $guid) { return $leaf[MIDCOM_NAV_URL]; } } return null; }