X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fmenu.php;h=b9dfb88c7327570bfb8dac300aaa84cb686cf5c3;hb=035aae2745e25d44ab9fe1b7bdffbcaa505ba970;hp=b9791d2359f1c388281cb5ea5d2d33f8694be6bb;hpb=c8d6a77d8ae64d527838ed6691e6eabff4aa12e2;p=quix0rs-gnu-social.git diff --git a/lib/menu.php b/lib/menu.php index b9791d2359..b9dfb88c73 100644 --- a/lib/menu.php +++ b/lib/menu.php @@ -49,23 +49,69 @@ class Menu extends Widget { var $action = null; var $actionName = null; + var $actionArgs = null; + /** * Construction * * @param Action $action current action, used for output */ - function __construct($action=null) + function __construct(Action $action=null) { parent::__construct($action); $this->action = $action; $this->actionName = $action->trimmed('action'); + + $rtargs = $action->returnToArgs(); + + $this->actionArgs = $rtargs[1]; + } + + function getItems() + { + return array(); + } + + function tag() + { + return null; + } + + function show() + { + $items = $this->getItems(); + $tag = $this->tag(); + + $attrs = array('class' => 'nav'); + + if (!is_null($tag)) { + $attrs['id'] = 'nav_' . $tag; + } + + if (Event::handle('StartNav', array($this, &$tag, &$items))) { + + $this->out->elementStart('ul', $attrs); + + foreach ($items as $item) { + assert(is_array($item)); + assert(count($item) == 5); + + list($actionName, $args, $label, $description, $id) = $item; + + $this->item($actionName, $args, $label, $description, $id); + } + + $this->out->elementEnd('ul'); + + Event::handle('EndNav', array($this, $tag, $items)); + } } - function item($actionName, $args, $label, $description, $id=null) + function item($actionName, array $args, $label, $description, $id=null, $cls=null) { if (empty($id)) { - $id = $this->menuItemID($actionName); + $id = $this->menuItemID($actionName, $args); } $url = common_local_url($actionName, $args); @@ -73,12 +119,50 @@ class Menu extends Widget $this->out->menuItem($url, $label, $description, - $actionName == $this->actionName, - $id); + $this->isCurrent($actionName, $args), + $id, + $cls); + } + + function isCurrent($actionName, array $args) + { + if ($actionName != $this->actionName) { + return false; + } elseif (!is_array($args)) { + /* + * No array, then the below loop doesn't need to run and + * 'return false' will never be reached. + */ + return true; + } + + foreach ($this->actionArgs as $k => $v) { + if (!array_key_exists($k, $args) || $args[$k] != $v) { + return false; + } + } + + return true; + } + + function menuItemID($actionName, $args = null) + { + $id = sprintf('nav_%s', $actionName); + + if (!is_null($args)) { + foreach ($args as $key => $value) { + $id .= '_' . $key . '_' . $value; + } + } + + return $id; } - function menuItemID($actionName) + function submenu($label, $menu) { - return sprintf('nav_%s', $actionName); + $this->action->elementStart('li'); + $this->action->element('h3', null, $label); + $menu->show(); + $this->action->elementEnd('li'); } }