Index: trunk/lib/Nav.inc.php
===================================================================
--- trunk/lib/Nav.inc.php	(revision 180)
+++ 	(revision )
@@ -1,301 +1,0 @@
-<?php
-/**
- * Nav.inc.php
- * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
- *
- * The Nav class provides a system for working with navigation elements.
- * Currently it supports storing page titles and URLs for printing breadcrumbs
- * and titles, as well as setting page features such as hiding the page title on
- * some pages but not others.
- *
- * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.0
- */
-class Nav {
-
-    var $pages = array();
-    var $path_delimiter = ' / ';
-    var $features = array();
-    var $default_features = array(
-        'title' => true,
-        'path' => true,
-        'breadcrumbs' => true,
-        'chop_breadcrumbs' => 0,
-        'chop_breadcrumb_links' => 1,
-    );
-    var $last_crumb_format = '%s';
-
-    /**
-     * Constructor. Set default features to apply to all added pages.
-     */
-    function Nav($default_features=null)
-    {
-        if (isset($default_features) && is_array($default_features)) {
-            $this->default_features = array_merge($this->default_features, $default_features);
-        }
-        $this->features = $this->default_features;
-    }
-
-/********************************************************************
-* INPUT
-********************************************************************/
-
-    /**
-     * Add a page to the internal pages array. Pages must be added sequentially
-     * as they are to be printed. The root page must be added first, and the
-     * current page added last. Features can be specified for a page, but currently
-     * only the features for the current page can be set. Future versions of this
-     * class may have the ability to set features for each page specifically.
-     *
-     * @access  public
-     *
-     * @param   string  $title      The title of the page.
-     * @param   string  $url        The URL to the page. Leave blank (or null) if
-     *                              page is to not be linked.
-     * @param   array   $features   Set the features of the current page.
-     */
-    function addPage($title, $url=null, $features=null)
-    {
-        $this->pages[] = array(
-            'title'     => $title,
-            'url'       => $url,
-            'features'  => (isset($features) && is_array($features)) ? array_merge($this->default_features, $features) : $this->default_features
-        );
-    }
-
-    /**
-     * Set the features of the current page. Future versions of this class
-     * may have the ability to set features for a specific page. In that case
-     * some form of ID will need to be specified for each page.
-     *
-     * @param  array $feature   Array of feature keys and value to set.
-     *
-     * @return bool true on success, false on failure
-     */
-    function setFeature($features=null, $page_id=null)
-    {
-        $page_id = $this->_calculatePageID($page_id);
-
-        if (isset($features) && is_array($features) && isset($this->pages[sizeof($this->pages)-1]['features']) && is_array($this->pages[sizeof($this->pages)-1]['features'])) {
-            // Set features for specified page.
-            $this->pages[sizeof($this->pages)-1]['features'] = array_merge($this->pages[sizeof($this->pages)-1]['features'], $features);
-            // TODO: Store "current page" features.
-//             $this->pages[$page_id]['features'] = array_merge($this->pages[$page_id]['features'], $features);
-        }
-    }
-
-    /**
-     * Unsets all page variables and resets features to the default set.
-     *
-     * @access  public
-     */
-    function clearPath()
-    {
-        $this->pages = array();
-        $this->features = $this->default_features;
-    }
-
-/********************************************************************
-* OUTPUT
-********************************************************************/
-
-    /**
-     * Get the value of a feature for specified page_id or current page if page_id not specified (future use).
-     *
-     * @param  string $feature   Name of feature value to retreive.
-     * @param  mixed $page_id    Future use: ID of page.
-     *
-     * @return bool true on success, false on failure
-     */
-    function getFeature($feature, $page_id=null, $default=null)
-    {
-        $page_id = $this->_calculatePageID($page_id);
-
-        if (isset($this->pages[$page_id]['features'][$feature])) {
-            switch ($feature) {
-            case 'breadcrumbs' :
-                // No breadcrumbs if displayed quantity of crumbs is less than 1.
-                return $this->pages[$page_id]['features'][$feature] && ((sizeof($this->pages) - $this->getFeature('chop_breadcrumbs')) > 0);
-                break;
-            default :
-                return $this->pages[$page_id]['features'][$feature];
-            }
-        } else {
-            return $default;
-        }
-    }
-
-
-    /**
-     * Returns the title of current page.
-     *
-     * @access  public
-     *
-     * @return  mixed  Title of page (string) or false if title feature not set.
-     */
-    function getTitle($page_id=null)
-    {
-        $page_id = $this->_calculatePageID($page_id);
-
-        if ($this->getFeature('title', $page_id)) {
-            return oTxt($this->pages[$page_id]['title'], true);
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Prints the title of page returned by getTitle().
-     *
-     * @access  public
-     */
-    function printTitle($page_id=null)
-    {
-        echo $this->getTitle($page_id);
-    }
-
-    /**
-     * Returns the text path from root up to the current page, seperated by the
-     * path_delimeter.
-     *
-     * @access  public
-     *
-     * @return  mixed   Path (string) or false if path feature is not set.
-     */
-    function getPath($page_id=null)
-    {
-        $page_id = $this->_calculatePageID($page_id);
-
-        if ($this->getFeature('path', $page_id)) {
-            $path = '';
-            $pathmark = '';
-            foreach ($this->pages as $curr_id => $page) {
-                $path .= oTxt($pathmark . strip_tags($page['title']), true);
-                $pathmark = $this->path_delimiter;
-                if ($curr_id === $page_id) {
-                    // Reached requested page.
-                    return $path;
-                }
-            }
-            return $path;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Prints the path returned by getPath().
-     *
-     * @access  public
-     */
-    function printPath($page_id=null)
-    {
-        echo $this->getPath($page_id);
-    }
-
-    /**
-     * Returns the breadcrumbs from the root page to the current page.
-     * Breadcrumbs are the text path with pages titles linked to that page.
-     *
-     * @access  public
-     *
-     * @return  mixed   Breadcrumbs (string) or false if breadcrumbs feature not set.
-     */
-    function getBreadcrumbs($page_id=null)
-    {
-		$app =& App::getInstance();
-
-        $page_id = $this->_calculatePageID($page_id);
-
-        if ($this->getFeature('breadcrumbs')) {
-            $breadcrumbs = '';
-            $pathmark = '';
-            $crumb_count = sizeof($this->pages);
-            foreach ($this->pages as $curr_id => $page) {
-                if ($crumb_count <= $this->getFeature('chop_breadcrumbs')) {
-                    // Stop gathering crumbs.
-                    return $breadcrumbs;
-                }
-                if ($crumb_count <= 1) {
-                    // The last crumb.
-                    if (empty($page['url']) || $crumb_count <= $this->getFeature('chop_breadcrumb_links')) {
-                        // A crumb with no link.
-                        $breadcrumbs .= oTxt($pathmark, true) . sprintf($this->last_crumb_format, oTxt($page['title'], true));
-                    } else if ($crumb_count > $this->getFeature('chop_breadcrumb_links')) {
-                        // A normal linked crumb.
-                        $breadcrumbs .= oTxt($pathmark, true) . '<a href="' . $app->oHREF($page['url']) . '">' . sprintf($this->last_crumb_format, oTxt($page['title'], true)) . '</a>';
-                    }
-                } else {
-                    if (empty($page['url'])) {
-                        // A crumb with no link.
-                        $breadcrumbs .= oTxt($pathmark . $page['title'], true);
-                    } else {
-                        // A normal linked crumb.
-                        $breadcrumbs .= oTxt($pathmark, true) . '<a href="' . $app->oHREF($page['url']) . '">' . oTxt($page['title'], true) . '</a>';
-                    }
-                }
-                $pathmark = $this->path_delimiter;
-                $crumb_count--;
-
-                if ($curr_id === $page_id) {
-                    // Reached requested page.
-                    return $breadcrumbs;
-                }
-            }
-            return $breadcrumbs;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Prints the breadcrumbs returned by getBreadcrumbs().
-     *
-     * @access  public
-     */
-    function printBreadcrumbs($page_id=null)
-    {
-        echo $this->getBreadcrumbs($page_id);
-    }
-
-    /**
-     * Returns a string if the queried page is the current page. One use is to print
-     * CSS tags if the current page matches a link, such as:
-     * $nav->currentPage('mypage.php', ' id="current"');
-     *
-     * @access  public
-     *
-     * @param   mixed   $page   The URI of the page to query, with PREG express markup, if needed.
-     * @param   mixed   $return The value to return if the current page matches the page queried.
-     *
-     * @return  mixed   The value set for $return, TRUE by default.
-     */
-    function currentPage($page_uri, $return=true)
-    {
-        // $page_uri = str_replace('/', '\/', $page_uri);
-        if (preg_match('/^' . preg_quote(urldecode($page_uri), '/') . '/i', $_SERVER['PHP_SELF'])) {
-            return $return;
-        }
-    }
-
-    /**
-     * Returns the ID of the current page, or the adjusted ID for a given page ID.
-     *
-     * @access  private
-     * @return  string  The value of the current page id.
-     */
-    function _calculatePageID($page_id=null)
-    {
-        if (!isset($page_id)) {
-            return sizeof($this->pages) - 1;
-        } else if ($page_id < 0 && is_numeric($page_id)) {
-            return sizeof($this->pages) + intval($page_id);
-        } else {
-            return $page_id;
-        }
-    }
-
-}
-// End of class.
-
-?>
Index: trunk/lib/Navigation.inc.php
===================================================================
--- trunk/lib/Navigation.inc.php	(revision 184)
+++ trunk/lib/Navigation.inc.php	(revision 184)
@@ -0,0 +1,271 @@
+<?php
+/**
+ * Navigation.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
+ * The Nav class provides a system for working with navigation elements.
+ * It supports storing page titles and URLs for printing breadcrumbs
+ * and titles, as well as setting page params such as hiding the page title on
+ * some pages but not others, and storing vars like the page title itself.
+ * 
+ * Note: this class was renamed from "Nav" because of the change in API and to be more descriptive.
+ *
+ * @author  Quinn Comendant <quinn@strangecode.com>
+ * @version 2.0
+ */
+class Navigation {
+
+    // Configuration parameters for this object.
+    var $_params = array(        
+        'html_title' = true,
+        'body_title' = true,
+        'title' => true,
+        'path' => true,
+        'breadcrumbs' => true,
+        'chop_breadcrumbs' => 0,
+        'chop_breadcrumb_links' => 1,
+        'path_delimiter' => ' / ',
+        'last_crumb_format' => '%s',
+    );
+    var $pages = array();
+
+    /**
+     * Navigation constructor.
+     */
+    function Navigation($params=null)
+    {
+		$app =& App::getInstance();
+
+        if (isset($params) && is_array($params)) {
+            // Merge new parameters with old overriding only those passed.
+            $this->_params = array_merge($this->_params, $params);
+        }
+    }
+
+    /**
+     * Add a page to the internal pages array. Pages must be added sequentially
+     * as they are to be printed. The root page must be added first, and the
+     * current page added last. Vars can be specified for any page, but only vars
+     * from the "current" page will be accessed with Nav::get.
+     * 
+     * @access  public
+     * @param   string  $title      The title of the page.
+     * @param   string  $url        The URL to the page. Set to null to use PHP_SELF.
+     * @param   array   $vars       Additoinal page variables.
+     */
+    function add($title, $url=null, $vars=array())
+    {
+        $page = array(
+            'title' => $title,
+            'url' => is_null($url) ? $_SERVER['PHP_SELF'] : $url;
+        );
+        $this->pages[] = array_merge($page, $vars);
+    }
+
+    /**
+     * Set (or overwrite existing) parameters by passing an array of new parameters.
+     *
+     * @access public
+     * @param  array    $params     Array of parameters (key => val pairs).
+     */
+    function setParam($params)
+    {
+		$app =& App::getInstance();
+    
+        if (isset($params) && is_array($params)) {
+            // Merge new parameters with old overriding only those passed.
+            $this->_params = array_merge($this->_params, $params);
+        } else {
+            $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
+        }
+    }
+
+    /**
+     * Return the value of a parameter, if it exists.
+     *
+     * @access public
+     * @param string $param        Which parameter to return.
+     * @return mixed               Configured parameter value.
+     */
+    function getParam($param)
+    {
+		$app =& App::getInstance();
+    
+        if (isset($this->_params[$param])) {
+            return $this->_params[$param];
+        } else {
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            return null;
+        }
+    }
+
+    /**
+     * Unsets all pages.
+     *
+     * @access  public
+     */
+    function clear()
+    {
+        $this->pages = array();
+    }
+
+    /**
+     * Sets a variable into the current page.
+     *
+     * @access public
+     * @param mixed $key      Which value to set.
+     * @param mixed $val      Value to set variable to.
+     */
+    function set($key, $val)
+    {
+        // Set params of current page.
+        $curr_page =& $this->pages[sizeof($this->pages) - 1];
+        $curr_page[$key] = $val;
+    }
+
+    /**
+     * Returns a specified value from the current page.
+     *
+     * @access public
+     * @param mixed $key      Which value to return.
+     * @param mixed $default  Value to return if key not found in user_data.
+     * @return mixed          Value stored in session.
+     */
+    function get($key, $default='')
+    {
+        $curr_page =& $this->pages[sizeof($this->pages) - 1];
+        
+        switch ($key) {
+        case 'title' :
+            if ($this->getParam('title') && isset($curr_page['title'])) {
+                return $curr_page['title'];
+            }
+            break;
+
+        case 'head_title' :
+            if ($this->getParam('head_title') && $this->getParam('title') && isset($curr_page['head_title'])) {
+                return $curr_page['head_title'];
+            }
+            break;
+
+        case 'body_title' :
+            if (!$this->getParam('body_title') && $this->getParam('title') && isset($curr_page['body_title'])) {
+                return $curr_page['body_title'];
+            }
+            break;
+
+        case 'path' :
+            if ($this->getParam('path')) {
+                return $this->getPath();
+            }
+            break;
+
+        case 'breadcrumbs' :
+            if ($this->getParam('breadcrumbs')) {
+                return $this->getBreadcrumbs();
+            }
+            break;
+
+        default :
+            return isset($curr_page[$key]) ? $curr_page[$key] : $default;
+            break;
+        }
+
+        return $default;
+    }
+
+    /**
+     * Returns the text path from root up to the current page, seperated by the
+     * path_delimeter.
+     *
+     * @access  public
+     *
+     * @return  mixed   Path (string) or false if path param is not set.
+     */
+    function getPath()
+    {
+        if ($this->getParam('path')) {
+            $path = '';
+            $pathmark = '';
+            foreach ($this->pages as $page) {
+                $path .= oTxt($pathmark . strip_tags($page['title']), true);
+                $pathmark = $this->getParam('path_delimiter');
+            }
+            return $path;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Returns the breadcrumbs from the root page to the current page.
+     * Breadcrumbs are the text path with pages titles linked to that page.
+     *
+     * @access  public
+     *
+     * @return  mixed   Breadcrumbs (string) or false if breadcrumbs param not set.
+     */
+    function getBreadcrumbs()
+    {
+		$app =& App::getInstance();
+
+        if ($this->getParam('breadcrumbs')) {
+            $breadcrumbs = '';
+            $pathmark = '';
+            $crumb_count = sizeof($this->pages);
+            foreach ($this->pages as $page) {
+                if ($crumb_count <= $this->getParam('chop_breadcrumbs')) {
+                    // Stop gathering crumbs.
+                    return $breadcrumbs;
+                }
+                if ($crumb_count <= 1) {
+                    // The last crumb.
+                    if ('' == trim($page['url']) || $crumb_count <= $this->getParam('chop_breadcrumb_links')) {
+                        // A crumb with no link.
+                        $breadcrumbs .= oTxt($pathmark, true) . sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true));
+                    } else if ($crumb_count > $this->getParam('chop_breadcrumb_links')) {
+                        // A normal linked crumb.
+                        $breadcrumbs .= oTxt($pathmark, true) . '<a href="' . $app->oHREF($page['url']) . '">' . sprintf($this->getParam('last_crumb_format'), oTxt($page['title'], true)) . '</a>';
+                    }
+                } else {
+                    if ('' == trim($page['url'])) {
+                        // A crumb with no link.
+                        $breadcrumbs .= oTxt($pathmark . $page['title'], true);
+                    } else {
+                        // A normal linked crumb.
+                        $breadcrumbs .= oTxt($pathmark, true) . '<a href="' . $app->oHREF($page['url']) . '">' . oTxt($page['title'], true) . '</a>';
+                    }
+                }
+                $pathmark = $this->getParam('path_delimiter');
+                $crumb_count--;
+            }
+            return $breadcrumbs;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Returns a string if the queried page is the current page. One use is to print
+     * CSS tags if the current page matches a link, such as:
+     * $nav->currentPage('mypage.php', ' id="current"');
+     *
+     * @access  public
+     *
+     * @param   mixed   $page   The URI of the page to query, with PREG express markup, if needed.
+     * @param   mixed   $return The value to return if the current page matches the page queried.
+     *
+     * @return  mixed   The value set for $return, TRUE by default.
+     */
+    function currentPage($page_uri, $return=true)
+    {
+        // $page_uri = str_replace('/', '\/', $page_uri);
+        if (preg_match('/^' . preg_quote(urldecode($page_uri), '/') . '/i', $_SERVER['PHP_SELF'])) {
+            return $return;
+        }
+    }
+
+}
+// End of class.
+
+?>
