/** * 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; }
/** * 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; }