Documentation is available at _basicnav.php
- <?php
- /**
- * @package midcom
- * @author The Midgard Project, http://www.midgard-project.org
- * @version $Id: _basicnav.php,v 1.34.2.12 2005/11/21 14:52:30 bergius Exp $
- * @copyright The Midgard Project, http://www.midgard-project.org
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
- */
- /**
- * This class is the basic building stone of the Navigation Access Point
- * System of MidCOM.
- *
- * It is responsible for collecting the available
- * Information and for building the navigational Tree out of it. This
- * class is only the internal interface to the NAP System and is used by
- * midcom_helper_nav as a node cache. The framework should ensure that
- * only one class of this type is active at one time.
- *
- * Basicnav will give you a very abstract view of the content tree, modified
- * by the NAP classes of the components. You can retrieve a node/leaf tree
- * of the content, and for each element you can retrieve an URL name and a
- * long name for Navigation display.
- *
- * Leaves and Nodes are both indexed by Integer constants which are assigned
- * by the framework. The framework defines two starting points in this tree:
- * The root node and the "current" node. The current node defined through
- * the topic of the component that declared to be able to handle the request.
- *
- * The class will load the neccessary information on demand to minimize
- * database traffic.
- *
- * The interface functions should enable you to build any navigation tree you
- * desire. The public nav class will give you some of those high-level
- * functions.
- *
- * <b>Node data interchange format</b>
- *
- * Node NAP data consists of a simple key => value array with the following
- * keys required by the component:
- *
- * - MIDCOM_NAV_NAME => The Real (= displayable) name of the element
- * - MIDCOM_NAV_TOOLBAR => Toolbar data (see below)
- * - MIDCOM_META_CREATOR => Creator of the element (MidgardPerson)
- * - MIDCOM_META_CREATED => Creation date (UNIX Timestamp)
- * - MIDCOM_META_EDITOR => Last modifier of the element (MidgardPerson)
- * - MIDCOM_META_EDITED => Last modification date (UNIX Timestamp)
- *
- * Other keys delivered to NAP users include:
- *
- * - MIDCOM_NAV_URL => The URL name of the element, which is automatically
- * defined by NAP.
- *
- * <b>Leaf data interchaneg format</b>
- *
- * Basically for each leaf the usual meta information is returned:
- *
- * - MIDCOM_META_CREATOR => Creator of the element (MidgardPerson)
- * - MIDCOM_META_CREATED => Creation date (UNIX Timestamp)
- * - MIDCOM_META_EDITOR => Last modifier of the element (MidgardPerson)
- * - MIDCOM_META_EDITED => Last modification date (UNIX Timestamp)
- * - MIDCOM_NAV_GUID => Optional argument denoting the GUID of the referred element
- * - MIDCOM_NAV_TOOLBAR => Toolbar data (see below)
- *
- * MidCOM NAP has reduced the separation of Admin Mode and Site Mode NAP
- * Data. Both Site- and Administrative Mode data is now delivered to NAP
- * (and from there to the NAP user) in a single call. This is done by
- * creating two sub-arrays retrievable under the keys MIDCOM_NAV_SITE and
- * MIDCOM_NAV_ADMIN. Both of those arrays contain MIDCOM_NAV_URL and
- * MIDCOM_NAV_NAME values. For compatibility and ease of use the top-level
- * entries of MIDCOM_NAV_NAME and MIDCOM_NAV_URL are still existent and
- * in use. Therefore, three possible constellation exist:
- *
- * 1) Both Values present
- *
- * <pre>
- * MIDCOM_NAV_SITE => Array (MIDCOM_NAV_URL, MIDCOM_NAV_NAME),
- * MIDCOM_NAV_ADMIN => Array (MIDCOM_NAV_URL, MIDCOM_NAV_NAME),
- * [... all other tags ...]
- * </pre>
- *
- * The top-level entries MIDCOM_NAV_NAME and _URL will be automatically
- * popluated according to Admin- or non-Admin mode, so that the displaying
- * code for all standard-situations won't have to consider this difference.
- *
- * 2) One element omitted
- *
- * If any Element does have only one of those pairs (like a "Create New
- * Category"-Link for example), set the unavailable Array Entry to null:
- *
- * <pre>
- * MIDCOM_NAV_SITE => null,
- * MIDCOM_NAV_ADMIN => Array (MIDCOM_NAV_URL, MIDCOM_NAV_NAME),
- * [... all other tags ...]
- * </pre>
- *
- * Note, that if one of the elements is missing like outlined above, the
- * list-methods of NAP will not show them in the corresponding mode. The
- * element of the above example would only be included in the listings if
- * the system was running in Admin-Mode. Copying of the primary values will
- * still happen like in (1).
- *
- * 3) Compatibility syntax
- *
- * For ease-of-use and for backwards compatibility, you can deliver an old
- * style data like this:
- *
- * <pre>
- * MIDCOM_NAV_URL => "blah",
- * MIDCOM_NAV_NAME => "blubb",
- * [... all other tags ...]
- * </pre>
- *
- * The Datamanger will automatically transform (3) to the syntax described in
- * (1) by copying the values.
- *
- * <b>Important note:</b> The difference outlined above is only valid for leaves (read
- * "articles"), because the topic structure is essentially the same in both AIS
- * and live Site.
- *
- * <b>Toolbar Syntax</b>
- *
- * You can add toolbars to your NAP information, that can be used for simple on-site
- * editing. They are indexed using integers and consist of an
- * midcom_helper_toolbar::add_item() compatible array with one exception:
- * The URL is always realtive to the AIS topic welcome page, but see the example
- * (it assumes that the referenced l10n libraries are available, of course):
- *
- * <code>
- * $toolbar[0] = Array (
- * MIDCOM_TOOLBAR_URL => '',
- * MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create article'),
- * MIDCOM_TOOLBAR_HELPTEXT => null,
- * MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_new.png',
- * MIDCOM_TOOLBAR_ENABLED => true
- * );
- * $toolbar[100] = Array(
- * MIDCOM_TOOLBAR_URL => 'config.html',
- * MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'),
- * MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'),
- * MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png',
- * MIDCOM_TOOLBAR_ENABLED => true
- * );
- * </code>
- *
- * You can now use a similar in your leaf data and place further buttons between these two
- * using indexes like 50,51,52.
- *
- * <b>DEPRECATED INFORMATION</b>
- *
- * The key MIDCOM_NAV_VISIBLE is deprecated from MidCOM 2.4.0 on, visibility is taken into account
- * automatically. The key is set to true for all values now for backwards compatibility and will
- * be removed entirely in MidCOM 2.6.0
- *
- * @todo Bring the information from http://www.nathan-syntronics.de/midgard/midcom_fs-transition/nap-update.html somehow into this.
- * @package midcom
- */
- class midcom_helper__basicnav
- {
- /**#@+
- * NAP data variable.
- *
- * @access private
- */
- /**
- * The GUID of the MidCOM Root Content Topic
- *
- * @var int
- */
- var $_root;
- /**
- * The GUID of the currently active Navigation Node, determied by the active
- * MidCOM Topic or one of its uplinks, if the subtree in question is invisible.
- *
- * @var int
- */
- var $_current;
- /**
- * The GUID of the currently active leaf.
- *
- * @var int
- */
- var $_currentleaf;
- /**
- * This is the leaf cache. It is an array which contains elements indexed by
- * their leaf ID. The data is again stored in an accociative array:
- *
- * - MIDCOM_NAV_NODEID => ID of the parent node (int)
- * - MIDCOM_NAV_URL => URL name of the leaf (string)
- * - MIDCOM_NAV_NAME => Textual name of the leaf (string)
- * - MIDCOM_META_CREATOR => Creator of the element (MidgardPerson)
- * - MIDCOM_META_CREATED => Creation date (UNIX Timestamp)
- * - MIDCOM_META_EDITOR => Last modifier of the element (MidgardPerson)
- * - MIDCOM_META_EDITED => Last modification date (UNIX Timestamp)
- *
- * @todo Update the data structure documentation
- * @var Array
- */
- var $_leaves;
- /**
- * This is the node cache. It is an array which contains elements indexed by
- * their node ID. The data is again stored in an accociative array:
- *
- * - MIDCOM_NAV_NODEID => ID of the parent node (-1 for the root node) (int)
- * - MIDCOM_NAV_URL => URL name of the leaf (string)
- * - MIDCOM_NAV_NAME => Textual name of the leaf (string)
- * - MIDCOM_META_CREATOR => Creator of the element (MidgardPerson)
- * - MIDCOM_META_CREATED => Creation date (UNIX Timestamp)
- * - MIDCOM_META_EDITOR => Last modifier of the element (MidgardPerson)
- * - MIDCOM_META_EDITED => Last modification date (UNIX Timestamp)
- *
- * @todo Update the data structure documentation
- * @var Array
- */
- var $_nodes;
- /**
- * This map tracks all loaded GUIDs along with their NAP structures. This cache
- * is used by nav's resolve_guid function to short-circut already known GUIDs.
- *
- * @var Array
- */
- var $_guid_map = Array();
- /**
- * This array holds a list of all topics for which the leaves have been loaded.
- * If the id of the node is in this array, the leaves are available, otheriwise,
- * the leaves ahve to be loaded.
- *
- * @var Array
- */
- var $_loaded_leaves = Array();
- /**#@-*/
- /**#@+
- * Internal runtime state variable.
- *
- * @access private
- */
- /**
- * This is a reference to the systemwide component loader class.
- *
- * @var midcom_helper__componentloader
- */
- var $_loader;
- /**
- * This one is true, if the system is in content administration mode and therefore
- * working with a different topic. See Constructor Documentation for details.
- *
- * @var bool
- */
- var $_adminmode;
- /**
- * This is a temporary storage where _loadNode can return the last known good
- * node in case the current node not visible. It is evaluated by the
- * constructor.
- *
- * @var int
- */
- var $_lastgoodnode;
- /**
- * A reference to the NAP cache store
- *
- * @var midcom_services_cache_backend
- */
- var $_nap_cache = null;
- /**#@-*/
- /**
- * This helper object will construct a complete node data structure for a given topic,
- * without any dependant objects like subtopics or leaves. It does not do any visibility
- * checks, it just prepares the object for later processing.
- *
- * This code is NAP cache aware, if the resulting information is already in the NAP
- * cache, it is retrieved from there.
- *
- * @param int $id The ID of the topic for which the NAP information is requested.
- * @return Array NAP node data structure or NULL in case no NAP information is available for this topic.
- * @access private
- */
- function _get_node($id)
- {
- debug_push_class(__CLASS__, __FUNCTION__);
- debug_add("Trying to load NAP data for topic {$id}...");
- $this->_nap_cache->open();
- if ($this->_nap_cache->exists($id))
- {
- debug_add("Cache hit for the guid {$id}.");
- $nodedata = $this->_nap_cache->get($id);
- $this->_nap_cache->close();
- }
- else
- {
- debug_add("No cache hit for the guid {$id}.");
- $this->_nap_cache->close();
- $nodedata = $this->_get_node_from_database($id);
- $this->_nap_cache->put($id, $nodedata);
- debug_add("Added the guid {$id} to the cache.");
- }
- if (is_null($nodedata))
- {
- debug_add('We got NULL for this node, so we do not have any NAP information, returning null directly.');
- debug_pop();
- return null;
- }
- // Rewrite all host dependant URLs based on the relative URL within our topic tree.
- $midgard = mgd_get_midgard();
- $nodedata[MIDCOM_NAV_FULLURL] = "{$GLOBALS['midcom_config']['midcom_site_url']}{$nodedata[MIDCOM_NAV_RELATIVEURL]}";
- $nodedata[MIDCOM_NAV_ABSOLUTEURL] = substr($GLOBALS['midcom_config']['midcom_site_url'], strlen($GLOBALS['midcom']->get_host_name()))
- . "{$nodedata[MIDCOM_NAV_RELATIVEURL]}";
- $nodedata[MIDCOM_NAV_PERMALINK] = "{$GLOBALS['midcom_config']['midcom_site_url']}midcom-permalink-{$nodedata[MIDCOM_NAV_GUID]}";
- // In addition, kill the toolbar as this is cached information and thus not relevant for the current user.
- $nodedata[MIDCOM_NAV_TOOLBAR] = null;
- debug_print_r("Node structure to return:", $nodedata);
- debug_pop();
- return $nodedata;
- }
- /**
- * Reads a node data structure from the database, completes all defaults and
- * derived properties (like ViewerGroups).
- *
- * @param int $id The ID of the topic for which the NAP information is requested.
- * @return Array Node data structure or NULL in case no NAP information is available for this topic.
- * @access private
- */
- function _get_node_from_database($id)
- {
- debug_push_class(__CLASS__, __FUNCTION__);
- // Load the topic first.
- $topic = mgd_get_topic($id);
- if (! $topic)
- {
- $GLOBALS['midcom']->generate_error(MIDCOM_ERRCRIT,
- "Cannot load NAP information, aborting: Could not load the topic {$id} from the database ("
- . mgd_errstr() . ').');
- // This will exit().
- }
- debug_add("Trying to load NAP data for topic {$topic->name} (#{$topic->id})");
- // Retrieve a NAP instance
- $path = $topic->parameter('midcom', 'component');
- if ($path === false)
- {
- debug_print_r('Topic object dump:', $topic);
- $GLOBALS['midcom']->generate_error(MIDCOM_ERRCRIT,
- "Cannot load NAP information, aborting: The topic {$topic->id} does not have a component assigned.");
- // This will exit().
- }
- $nap =& $this->_loader->get_nap_class($path);
- if (! $nap->set_object($topic))
- {
- debug_print_r('Topic object dump:', $topic);
- $GLOBALS['midcom']->generate_error(MIDCOM_ERRCRIT,
- "Cannot load NAP information, aborting: Could not set the nap instance of {$path} to the topic {$topic->id}.");
- // This will exit().
- }
- // Get the node data and verify this is a node that actually has any relevant NAP
- // information. Internal components like AIS or the L10n editor, which don't have
- // a NAP interface yet return null here, to be exempt from any NAP processing.
- $nodedata = $nap->get_node();
- if (is_null($nodedata))
- {
- debug_add("The component {$path} did return null for the topic {$topic->id}, indicating no NAP information is available.");
- debug_pop();
- return null;
- }
- // Now complete the node data structure, we need a metadata object for this:
- $metadata =& midcom_helper_metadata::retrieve($topic);
- $nodedata[MIDCOM_NAV_URL] = $topic->name . '/';
- $nodedata[MIDCOM_NAV_NAME] = trim($nodedata[MIDCOM_NAV_NAME]) == '' ? $topic->name : $nodedata[MIDCOM_NAV_NAME];
- $nodedata[MIDCOM_NAV_GUID] = $topic->guid();
- $nodedata[MIDCOM_NAV_ID] = $topic->id;
- $nodedata[MIDCOM_NAV_TYPE] = 'node';
- $nodedata[MIDCOM_NAV_SCORE] = $topic->score;
- $nodedata[MIDCOM_NAV_COMPONENT] = $path;
- $nodedata[MIDCOM_NAV_SUBNODES] = null;
- $nodedata[MIDCOM_NAV_LEAVES] = null;
- if (! array_key_exists(MIDCOM_NAV_TOOLBAR, $nodedata))
- {
- $nodedata[MIDCOM_NAV_TOOLBAR] = null;
- }
- if ( ! array_key_exists(MIDCOM_NAV_NOENTRY, $nodedata)
- || $nodedata[MIDCOM_NAV_NOENTRY] == false)
- {
- $nodedata[MIDCOM_NAV_NOENTRY] = (bool) $metadata->get('nav_noentry');
- }
- if ($topic->id == $this->_root)
- {
- $nodedata[MIDCOM_NAV_NODEID] = -1;
- $nodedata[MIDCOM_NAV_RELATIVEURL] = '';
- }
- else
- {
- $nodedata[MIDCOM_NAV_NODEID] = $topic->up;
- $nodedata[MIDCOM_NAV_RELATIVEURL] = $this->_nodes[$nodedata[MIDCOM_NAV_NODEID]][MIDCOM_NAV_RELATIVEURL] . $nodedata[MIDCOM_NAV_URL];
- }
- $nodedata[MIDCOM_NAV_OBJECT] = $topic;
- // Collect Viewergroups
- // A topic can be viewed by all groups by default
- $nodedata[MIDCOM_NAV_VIEWERGROUPS] = null;
- $topic_viewers = $topic->listparameters("ViewerGroups");
- if ($topic_viewers)
- {
- $groups = Array();
- while ($topic_viewers->fetch())
- {
- if ($topic_viewers->name == 'all')
- {
- // There is an "all" value, everybody can access this topic for sure.
- debug_add("Got a viewer Group 'all', breaking out of the loop and leaving the topic readable for everybody.");
- break;
- }
- $groups[] = $topic_viewers->name; }
- $nodedata[MIDCOM_NAV_VIEWERGROUPS] = $groups;
- }
- // Temporary compatiblity value
- $nodedata[MIDCOM_NAV_VISIBLE] = true;
- debug_pop();
- return $nodedata;
- }
- /**
- * Return the list of leaves for a given node. This helper will construct complete leaf
- * data structures for each leaf found. It will first check the cache for the leaf structures,
- * and query the database only if the corresponding objects have not been found there.
- *
- * No visibility checks are made at this point.
- *
- * @param Array $node The node data structure for which to retrieve the leaves.
- * @return Array All leaves found for that node, in complete post processed leave data structures.
- * @access private
- */
- function _get_leaves($node)
- {
- debug_push_class(__CLASS__, __FUNCTION__);
- debug_add("Trying to load NAP leaf data for topic {$node[MIDCOM_NAV_OBJECT]->name} (#{$node[MIDCOM_NAV_OBJECT]->id})");
- $entry_name = "{$node[MIDCOM_NAV_ID]}-leaves";
- $this->_nap_cache->open();
- if ($this->_nap_cache->exists($entry_name))
- {
- $leaves = $this->_nap_cache->get($entry_name);
- }
- else
- {
- $leaves = null;
- }
- $this->_nap_cache->close();
- if (is_null($leaves))
- {
- // Appearantly, the leaves have not yet been loaded for this topic, so we have to do this now.
- // Afterwards we update the cache.
- debug_add('The leaves have not yet been loaded from the database, we do this now.');
- $leaves = $this->_get_leaves_from_database($node);
- $this->_write_leaves_to_cache($node, $leaves);
- }
- // Post process the leaves for URLs and the like. Don't forget NAV_ADMIN/NAV_SITE
- // Rewrite all host dependant URLs based on the relative URL within our topic tree.
- $this->_update_leaflist_urls($leaves);
- debug_print_r("We will return these leaves:", $leaves);
- debug_pop();
- return $leaves;
- }
- /**
- * This helper updates the URLs in the reference-passed leaf list.
- * FULLURL, ABSOLUTEURL and PERMALINK are built upon RELATIVEURL,
- * NAV_NAME and NAV_URL are populated based on the administration mode with either
- * NAV_ADMIN or NAV_SITE values.
- *
- * @param Array $leaves A reference to the list of leaves which has to be processed.
- * @access private
- */
- function _update_leaflist_urls(&$leaves)
- {
- debug_push_class(__CLASS__, __FUNCTION__);
- $fullprefix = "{$GLOBALS['midcom_config']['midcom_site_url']}";
- $absoluteprefix = substr($GLOBALS['midcom_config']['midcom_site_url'], strlen($GLOBALS['midcom']->get_host_name()));
- $permaprefix = "{$fullprefix}midcom-permalink-";
- if (! is_array($leaves))
- {
- echo "<pre>"; print_r($leaves); echo "</pre>";
- die ("wrong type");
- }
- foreach ($leaves as $id => $copy)
- {
- $leaves[$id][MIDCOM_NAV_FULLURL] = $fullprefix . $leaves[$id][MIDCOM_NAV_RELATIVEURL];
- $leaves[$id][MIDCOM_NAV_ABSOLUTEURL] = $absoluteprefix . $leaves[$id][MIDCOM_NAV_RELATIVEURL];
- if (is_null($leaves[$id][MIDCOM_NAV_GUID]))
- {
- $leaves[$id][MIDCOM_NAV_PERMALINK] = $leaves[$id][MIDCOM_NAV_FULLURL];
- }
- else
- {
- $leaves[$id][MIDCOM_NAV_PERMALINK] = $permaprefix . $leaves[$id][MIDCOM_NAV_GUID];
- }
- if ($this->_adminmode)
- {
- $leaves[$id][MIDCOM_NAV_URL] = $leaves[$id][MIDCOM_NAV_ADMIN][MIDCOM_NAV_URL];
- $leaves[$id][MIDCOM_NAV_NAME] = $leaves[$id][MIDCOM_NAV_ADMIN][MIDCOM_NAV_NAME];
- }
- else
- {
- $leaves[$id][MIDCOM_NAV_URL] = $leaves[$id][MIDCOM_NAV_SITE][MIDCOM_NAV_URL];
- $leaves[$id][MIDCOM_NAV_NAME] = $leaves[$id][MIDCOM_NAV_SITE][MIDCOM_NAV_NAME];
- }
- // In addition, kill the toolbar as this is cached information and thus not relevant for the current user.
- $leaves[$id][MIDCOM_NAV_TOOLBAR] = null;
- }
- debug_pop();
- }
- /**
- * Writes the leaves passed to this function to the cache, assigning them to the
- * specified node.
- *
- * The function will bail out on any critical error. Data inconsistencies will be
- * logged and overwritten silently otherwise.
- *
- * @param Array $node The node datastructure to which the leaves should be assigned.
- * @param Array $leaves The leaves to store in the cache.
- * @access private
- */
- function _write_leaves_to_cache($node, $leaves)
- {
- debug_push_class(__CLASS__, __FUNCTION__);
- debug_add('Writing ' . count ($leaves) . ' leaves to the cache.');
- // We need to update the node too, as it contains the leaf list for rapid access.
- $node_leaflist = array_keys($leaves);
- $this->_nap_cache->open(true);
- if (! $this->_nap_cache->exists($node[MIDCOM_NAV_ID]))
- {
- $this->_nap_cache->close();
- debug_add("NAP Caching Engine: Tried to update the topic {$node[MIDCOM_NAV_OBJECT]->name} (#{$node[MIDCOM_NAV_OBJECT]->id}) "
- . 'which was supposed to be in the cache already, but failed to load the object from the database. '
- . 'Aborting write_to_cache, this is a critical cache inconsistency.', MIDCOM_LOG_WARN);
- debug_pop();
- return;
- }
- // We load it again to get the cached structure, not the completed one from the
- // in-memory cache.
- $cached_node = $this->_nap_cache->get($node[MIDCOM_NAV_ID]);
- $cached_node[MIDCOM_NAV_LEAVES] = $node_leaflist;
- debug_print_r('Updating the Node structure in the cache to this:', $cached_node);
- $this->_nap_cache->put($node[MIDCOM_NAV_ID], $cached_node);
- $this->_nap_cache->put("{$node[MIDCOM_NAV_ID]}-leaves", $leaves);
- $this->_nap_cache->close();
- debug_pop();
- }
- /**
- * This helper is responsible for loading the leaves for a given node out of the
- * database. It will complete all default fields to provide full blown nap structures.
- * It will also build the base relative URLs which will later be completed by the
- * _get_leaves() interface functions.
- *
- * Important notes:
- * - The ViewerGroups property is copied from the parent topic, to ensure the same level of visibility.
- * - The IDs constructed for the leaves are the concatenation of the ID delivered by the component
- * and the topics' GUID.
- *
- * @param Array $node The node data structure for which to retrieve the leaves.
- * @return Array All leaves found for that node, in complete post processed leave data structures.
- * @access private
- */
- function _get_leaves_from_database($node)
- {
- debug_push_class(__CLASS__, __FUNCTION__);
- $topic = $node[MIDCOM_NAV_OBJECT];
- // Retrieve a NAP instance
- $nap =& $this->_loader->get_nap_class($node[MIDCOM_NAV_COMPONENT]);
- if (! $nap->set_object($topic))
- {
- debug_print_r('Topic object dump:', $topic);
- $GLOBALS['midcom']->generate_error(MIDCOM_ERRCRIT,
- "Cannot load NAP information, aborting: Could not set the nap instance of {$path} to the topic {$topic->id}.");
- // This will exit().
- }
- $leafdata = $nap->get_leaves();
- $leaves = Array();
- foreach ($leafdata as $id => $leaf)
- {
- // First, try to somehow gain both a GUID and a Leaf.
- if ( ! array_key_exists(MIDCOM_NAV_GUID, $leaf)
- && ! array_key_exists(MIDCOM_NAV_OBJECT, $leaf))
- {
- debug_add("Warning: The leaf {$id} of topic {$topic->id} does set neither a GUID nor an object.", MIDCOM_LOG_WARN);
- $leaf[MIDCOM_NAV_GUID] = null;
- $leaf[MIDCOM_NAV_OBJECT] = null;
- }
- else if (! array_key_exists(MIDCOM_NAV_GUID, $leaf))
- {
- $leaf[MIDCOM_NAV_GUID] = $leaf[MIDCOM_NAV_OBJECT]->guid();
- }
- else if (! array_key_exists(MIDCOM_NAV_OBJECT, $leaf))
- {
- $leaf[MIDCOM_NAV_OBJECT] = mgd_get_object_by_guid($leaf[MIDCOM_NAV_GUID]);
- }
- $leaf[MIDCOM_NAV_VIEWERGROUPS] = $node[MIDCOM_NAV_VIEWERGROUPS];
- // Now complete the actual leaf information
- // Score
- if (! array_key_exists(MIDCOM_NAV_SCORE, $leaf))
- {
- if ( ! is_null($leaf[MIDCOM_NAV_OBJECT])
- && array_key_exists('score', get_object_vars($leaf[MIDCOM_NAV_OBJECT])))
- {
- $leaf[MIDCOM_NAV_SCORE] = $leaf[MIDCOM_NAV_OBJECT]->score;
- }
- else
- {
- $leaf[MIDCOM_NAV_SCORE] = 0;
- }
- }
- // NAV_NOENTRY Flag
- if (! array_key_exists(MIDCOM_NAV_NOENTRY, $leaf))
- {
- $leaf[MIDCOM_NAV_NOENTRY] = false;
- }
- if ($leaf[MIDCOM_NAV_NOENTRY] == false)
- {
- $metadata =& midcom_helper_metadata::retrieve($leaf);
- if ($metadata)
- {
- $leaf[MIDCOM_NAV_NOENTRY] = (bool) $metadata->get('nav_noentry');
- }
- }
- // Complete the NAV_SITE and NAV_ADMIN fields if the old-style
- // root level URL/NAME parameters are set. This automatically overrides
- // any NAV_SITE/ADMIN settings.
- if ( array_key_exists(MIDCOM_NAV_NAME, $leaf)
- && array_key_exists(MIDCOM_NAV_URL, $leaf))
- {
- $leaf[MIDCOM_NAV_SITE][MIDCOM_NAV_URL] = $leaf[MIDCOM_NAV_URL];
- $leaf[MIDCOM_NAV_SITE][MIDCOM_NAV_NAME] = $leaf[MIDCOM_NAV_NAME];
- $leaf[MIDCOM_NAV_ADMIN][MIDCOM_NAV_URL] = $leaf[MIDCOM_NAV_URL];
- $leaf[MIDCOM_NAV_ADMIN][MIDCOM_NAV_NAME] = $leaf[MIDCOM_NAV_NAME];
- }
- // complete NAV_NAMES where neccessary
- if ( ! is_null($leaf[MIDCOM_NAV_SITE])
- && trim($leaf[MIDCOM_NAV_SITE][MIDCOM_NAV_NAME]) == '')
- {
- $leaf[MIDCOM_NAV_SITE][MIDCOM_NAV_NAME] = $leaf[MIDCOM_NAV_ADMIN][MIDCOM_NAV_URL];
- }
- if ( ! is_null($leaf[MIDCOM_NAV_ADMIN])
- && trim($leaf[MIDCOM_NAV_ADMIN][MIDCOM_NAV_NAME]) == '')
- {
- $leaf[MIDCOM_NAV_ADMIN][MIDCOM_NAV_NAME] = $leaf[MIDCOM_NAV_ADMIN][MIDCOM_NAV_URL];
- }
- // Toolbar
- if (! array_key_exists(