diff --git a/lib/defaultlocalnav.php b/lib/defaultlocalnav.php index f150407621..a61ebbb585 100644 --- a/lib/defaultlocalnav.php +++ b/lib/defaultlocalnav.php @@ -63,8 +63,10 @@ class DefaultLocalNav extends Menu $this->submenu(_m('MENU','Public'), $bn); if (!empty($user)) { - $sn = new StreamsNav($this->action); - $this->submenu(_m('MENU', 'Streams'), $sn); + $sn = new GroupsNav($this->action, $user); + if ($sn->haveGroups()) { + $this->submenu(_m('MENU', 'Groups'), $sn); + } } $this->action->elementEnd('ul'); diff --git a/lib/streamsnav.php b/lib/groupsnav.php similarity index 62% rename from lib/streamsnav.php rename to lib/groupsnav.php index 2051cc3484..1d2066f2e5 100644 --- a/lib/streamsnav.php +++ b/lib/groupsnav.php @@ -45,8 +45,23 @@ if (!defined('STATUSNET')) { * @link http://status.net/ */ -class StreamsNav extends Menu +class GroupsNav extends Menu { + protected $user; + protected $groups; + + function __construct($action, $user) + { + parent::__construct($action); + $this->user = $user; + $this->groups = $user->getGroups(); + } + + function haveGroups() + { + return (!empty($this->groups) && ($this->groups->N > 0)); + } + /** * Show the menu * @@ -54,28 +69,24 @@ class StreamsNav extends Menu */ function show() { - $user = common_current_user(); - - if (empty($user)) { - throw new ServerException('Cannot show personal group navigation without a current user.'); - } - $action = $this->actionName; $this->out->elementStart('ul', array('class' => 'nav')); - if (Event::handle('StartStreamsNav', array($this))) { - $group = $user->getGroups(); + if (Event::handle('StartGroupsNav', array($this))) { - while ($group->fetch()) { - $this->out->menuItem(($group->mainpage) ? $group->mainpage : common_local_url('showgroup', - array('nickname' => $group->nickname)), - $group->getBestName(), + while ($this->groups->fetch()) { + $this->out->menuItem(($this->groups->mainpage) ? + $this->groups->mainpage : + common_local_url('showgroup', + array('nickname' => $this->groups->nickname)), + $this->groups->getBestName(), '', - $action == 'showgroup' && $this->action->arg('nickname') == $group->nickname, - 'nav_timeline_group_'.$group->nickname); + $action == 'showgroup' && + $this->action->arg('nickname') == $this->groups->nickname, + 'nav_timeline_group_'.$this->groups->nickname); } - Event::handle('EndStreamsNav', array($this)); + Event::handle('EndGroupsNav', array($this)); } $this->out->elementEnd('ul');