--- nfo/php/libs/net.php.pear/HTML/TreeMenu.php 2003/02/27 16:45:21 1.1
+++ nfo/php/libs/net.php.pear/HTML/TreeMenu.php 2004/07/07 02:21:09 1.2
@@ -33,8 +33,8 @@
// | Harald Radi |
// +-----------------------------------------------------------------------+
//
-// Id: TreeMenu.php,v 1.15 2003/02/21 18:19:39 richard Exp
-// $Id: TreeMenu.php,v 1.1 2003/02/27 16:45:21 joko Exp $
+// Id: TreeMenu.php,v 1.18 2003/12/20 13:10:59 richard Exp
+// $Id: TreeMenu.php,v 1.2 2004/07/07 02:21:09 joko Exp $
/**
* HTML_TreeMenu Class
@@ -101,7 +101,7 @@
* are Wolfram Kriesings' PEAR Tree class, and Richard Heyes' (me!)
* Tree class (available here: http://www.phpguru.org/). This
* method is intended to be used statically, eg:
- * $treeMenu = &HTML_TreeMenu::import($myTreeStructureObj);
+ * $treeMenu = &HTML_TreeMenu::createFromStructure($myTreeStructureObj);
*
* @param array $params An array of parameters that determine
* how the import happens. This can consist of:
@@ -172,7 +172,38 @@
break;
/**
- * Richard Heyes' (me!) Tree class
+ * Richard Heyes' (me!) second (array based) Tree class
+ */
+ case 'heyes_array':
+ // Need to create a HTML_TreeMenu object ?
+ if (!isset($params['treeMenu'])) {
+ $treeMenu = &new HTML_TreeMenu();
+ $parentID = 0;
+ } else {
+ $treeMenu = &$params['treeMenu'];
+ $parentID = $params['parentID'];
+ }
+
+ // Loop thru the trees nodes
+ foreach ($params['structure']->getChildren($parentID) as $nodeID) {
+ $data = $params['structure']->getData($nodeID);
+ $parentNode = &$treeMenu->addItem(new HTML_TreeNode(array_merge($params['nodeOptions'], $data)));
+
+ // Recurse ?
+ if ($params['structure']->hasChildren($nodeID)) {
+ $recurseParams['type'] = 'heyes_array';
+ $recurseParams['parentID'] = $nodeID;
+ $recurseParams['nodeOptions'] = $params['nodeOptions'];
+ $recurseParams['structure'] = &$params['structure'];
+ $recurseParams['treeMenu'] = &$parentNode;
+ HTML_TreeMenu::createFromStructure($recurseParams);
+ }
+ }
+
+ break;
+
+ /**
+ * Richard Heyes' (me!) original OO based Tree class
*/
case 'heyes':
default:
@@ -202,55 +233,55 @@
return $treeMenu;
}
-
- /**
+
+ /**
* Creates a treeMenu from XML. The structure of your XML should be
- * like so:
- *
- *
- *
- *
- *
- *
- *
- *
- *
- * Any of the options you can supply to the HTML_TreeNode constructor can be supplied as
- * attributes to the tag. If there are no subnodes for a particular node, you can
- * use the XML shortcut instead of . The $xml argument can
- * be either the XML as a string, or an pre-created XML_Tree object. Also, this method
- * REQUIRES my own Tree class to work (http://phpguru.org/tree.html). If this has not
- * been include()ed or require()ed this method will die().
- *
- * @param mixed $xml This can be either a string containing the XML, or an XML_Tree object
- * (the PEAR::XML_Tree package).
- * @return object The HTML_TreeMenu object
- */
- function createFromXML($xml)
- {
- if (!class_exists('Tree')) {
- die('Could not find Tree class');
- }
-
- // Supplied $xml is a string
- if (is_string($xml)) {
- require_once('XML/Tree.php');
- $xmlTree = &new XML_Tree();
- $xmlTree->getTreeFromString($xml);
-
- // Supplied $xml is an XML_Tree object
- } else {
- $xmlTree = $xml;
- }
-
- // Now process the XML_Tree object, setting the XML attributes
- // to be the tag data (with out the XML tag name or contents).
- $treeStructure = Tree::createFromXMLTree($xmlTree, true);
- $treeStructure->nodes->traverse(create_function('&$node', '$tagData = $node->getTag(); $node->setTag($tagData["attributes"]);'));
-
-
- return HTML_TreeMenu::createFromStructure(array('structure' => $treeStructure));
- }
+ * like so:
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * Any of the options you can supply to the HTML_TreeNode constructor can be supplied as
+ * attributes to the tag. If there are no subnodes for a particular node, you can
+ * use the XML shortcut instead of . The $xml argument can
+ * be either the XML as a string, or an pre-created XML_Tree object. Also, this method
+ * REQUIRES my own Tree class to work (http://phpguru.org/tree.html). If this has not
+ * been include()ed or require()ed this method will die().
+ *
+ * @param mixed $xml This can be either a string containing the XML, or an XML_Tree object
+ * (the PEAR::XML_Tree package).
+ * @return object The HTML_TreeMenu object
+ */
+ function createFromXML($xml)
+ {
+ if (!class_exists('Tree')) {
+ die('Could not find Tree class');
+ }
+
+ // Supplied $xml is a string
+ if (is_string($xml)) {
+ require_once('XML/Tree.php');
+ $xmlTree = &new XML_Tree();
+ $xmlTree->getTreeFromString($xml);
+
+ // Supplied $xml is an XML_Tree object
+ } else {
+ $xmlTree = $xml;
+ }
+
+ // Now process the XML_Tree object, setting the XML attributes
+ // to be the tag data (with out the XML tag name or contents).
+ $treeStructure = Tree::createFromXMLTree($xmlTree, true);
+ $treeStructure->nodes->traverse(create_function('&$node', '$tagData = $node->getTag(); $node->setTag($tagData["attributes"]);'));
+
+
+ return HTML_TreeMenu::createFromStructure(array('structure' => $treeStructure));
+ }
} // HTML_TreeMenu
@@ -349,7 +380,7 @@
* o link The link for the node, defaults to blank
* o icon The icon for the node, defaults to blank
* o expandedIcon The icon to show when the node is expanded
- * o class The CSS class for this node, defaults to blank
+ * o cssClass The CSS class for this node, defaults to blank
* o expanded The default expanded status of this node, defaults to false
* This doesn't affect non dynamic presentation types
* o linkTarget Target for the links. Defaults to linkTarget of the
@@ -546,6 +577,9 @@
* is achieved using cookies. Default is true.
* o noTopLevelImages - Whether to skip displaying the first level of images if
* there is multiple top level branches.
+ * o maxDepth - The maximum depth of indentation. Useful for ensuring
+ * deeply nested trees don't go way off to the right of your
+ * page etc. Defaults to no limit.
*
* And also a boolean for whether the entire tree is dynamic or not.
* This overrides any perNode dynamic settings.
@@ -561,6 +595,7 @@
// Defaults
$this->images = 'images';
+ $this->maxDepth = 0; // No limit
$this->linkTarget = '_self';
$this->defaultClass = '';
$this->usePersistence = true;
@@ -582,7 +617,7 @@
function toHTML()
{
static $count = 0;
- $menuObj = 'objTreeMenu_' . ++$count;
+ $menuObj = 'objTreeMenu_' . ++$count;
$html = "\n";
$html .= '