X-Git-Url: https://git.mxchange.org/?p=quix0rs-gnu-social.git;a=blobdiff_plain;f=lib%2Fmenu.php;h=f0f797fe3257b609fa771d630667624b5b2e5989;hp=281ef7797be7c4af1c9aa2179cbd4df59ebbaf13;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hpb=8884a5255fb90fda67b63fa0d4252d77176337e5 diff --git a/lib/menu.php b/lib/menu.php index 281ef7797b..f0f797fe32 100644 --- a/lib/menu.php +++ b/lib/menu.php @@ -56,7 +56,7 @@ class Menu extends Widget * * @param Action $action current action, used for output */ - function __construct($action=null) + function __construct(Action $action=null) { parent::__construct($action); @@ -94,17 +94,21 @@ class Menu extends Widget $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, $cls=null) + + function item($actionName, array $args, $label, $description, $id=null, $cls=null) { if (empty($id)) { $id = $this->menuItemID($actionName, $args); @@ -120,10 +124,16 @@ class Menu extends Widget $cls); } - function isCurrent($actionName, $args) + 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) { @@ -134,11 +144,11 @@ class Menu extends Widget return true; } - + function menuItemID($actionName, $args = null) { $id = sprintf('nav_%s', $actionName); - + if (!is_null($args)) { foreach ($args as $key => $value) { $id .= '_' . $key . '_' . $value; @@ -150,9 +160,12 @@ class Menu extends Widget function submenu($label, $menu) { - $this->action->elementStart('li'); - $this->action->element('h3', null, $label); - $menu->show(); - $this->action->elementEnd('li'); + if (Event::handle('StartSubMenu', array($this->action, $menu, $label))) { + $this->action->elementStart('li'); + $this->action->element('h3', null, $label); + $menu->show(); + $this->action->elementEnd('li'); + Event::handle('EndSubMenu', array($this->action, $menu, $label)); + } } }