From 5f6512c92f457e6a96327b053319f194391ef10a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 5 Apr 2011 17:49:45 -0400 Subject: [PATCH 1/5] Move streams nav to groups nav --- lib/defaultlocalnav.php | 6 ++-- lib/{streamsnav.php => groupsnav.php} | 43 +++++++++++++++++---------- 2 files changed, 31 insertions(+), 18 deletions(-) rename lib/{streamsnav.php => groupsnav.php} (62%) 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'); From 097d76b3d211c633a68802c506dbc97fdc49b5fb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 5 Apr 2011 18:14:48 -0400 Subject: [PATCH 2/5] Added tagsub to the left-hand menu --- plugins/TagSub/TagSub.php | 27 ++++++++++++ plugins/TagSub/TagSubPlugin.php | 25 +++++++++++ plugins/TagSub/tagsubmenu.php | 76 +++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 plugins/TagSub/tagsubmenu.php diff --git a/plugins/TagSub/TagSub.php b/plugins/TagSub/TagSub.php index a734b4fc5f..c2da072693 100644 --- a/plugins/TagSub/TagSub.php +++ b/plugins/TagSub/TagSub.php @@ -120,6 +120,7 @@ class TagSub extends Managed_DataObject $ts->profile_id = $profile->id; $ts->created = common_sql_now(); $ts->insert(); + self::blow('tagsub:by_profile:%d', $profile->id); return $ts; } @@ -135,6 +136,32 @@ class TagSub extends Managed_DataObject 'profile_id' => $profile->id)); if ($ts) { $ts->delete(); + self::blow('tagsub:by_profile:%d', $profile->id); } } + + static function forProfile(Profile $profile) + { + $tags = array(); + + $keypart = sprintf('tagsub:by_profile:%d', $profile->id); + $tagstring = self::cacheGet($keypart); + + if ($tagstring !== false) { + $tags = explode(',', $tagstring); + } else { + $tagsub = new TagSub(); + $tagsub->profile_id = $profile->id; + + if ($tagsub->find()) { + while ($tagsub->fetch()) { + $tags[] = $tagsub->tag; + } + } + + self::cacheSet($keypart, implode(',', $tags)); + } + + return $tags; + } } diff --git a/plugins/TagSub/TagSubPlugin.php b/plugins/TagSub/TagSubPlugin.php index 53a06ab5bf..13e525bb62 100644 --- a/plugins/TagSub/TagSubPlugin.php +++ b/plugins/TagSub/TagSubPlugin.php @@ -80,6 +80,7 @@ class TagSubPlugin extends Plugin case 'TagunsubAction': case 'TagsubsAction': case 'TagSubForm': + case 'TagSubMenu': case 'TagUnsubForm': include_once $dir.'/'.strtolower($cls).'.php'; return false; @@ -239,4 +240,28 @@ class TagSubPlugin extends Plugin } return true; } + + function onEndDefaultLocalNav($menu, $user) + { + $user = common_current_user(); + + $tags = TagSub::forProfile($user->getProfile()); + + if (!empty($tags)) { + $tagSubMenu = new TagSubMenu($menu->out, $user, $tags); + $menu->submenu(_m('Tags'), $tagSubMenu); + } + + foreach ($tags as $tag) { + $menu->out->menuItem(common_local_url('tag', + array('tag' => $tag)), + sprintf('#%s', $tag), + sprintf(_('Notices tagged with %s'), $tag), + $menu->actionName == 'tag' && $menu->action->arg('tag') == $tag, + 'nav_streams_tag_'.$tag); + } + + return true; + } + } diff --git a/plugins/TagSub/tagsubmenu.php b/plugins/TagSub/tagsubmenu.php new file mode 100644 index 0000000000..44770651d9 --- /dev/null +++ b/plugins/TagSub/tagsubmenu.php @@ -0,0 +1,76 @@ +. + * + * @category Menu + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * Class comment + * + * @category General + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class TagSubMenu extends Menu +{ + protected $user; + protected $tags; + + function __construct($out, $user, $tags) + { + parent::__construct($out); + $this->user = $user; + $this->tags = $tags; + } + + function show() + { + $this->out->elementStart('ul', array('class' => 'nav')); + + foreach ($tags as $tag) { + $this->out->menuItem(common_local_url('tag', + array('tag' => $tag)), + sprintf('#%s', $tag), + sprintf(_('Notices tagged with %s'), $tag), + $this->actionName == 'tag' && $this->action->arg('tag') == $tag, + 'nav_streams_tag_'.$tag); + } + + $this->out->elementEnd('ul'); + } + +} From 3377cd59ce84b85334ea3f057fcf6797c9ff38ec Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 5 Apr 2011 18:07:10 -0400 Subject: [PATCH 3/5] a hook for showing the default local nav --- EVENTS.txt | 8 ++++++++ lib/defaultlocalnav.php | 33 +++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/EVENTS.txt b/EVENTS.txt index 1494a9c890..b328785e7b 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1139,3 +1139,11 @@ StartNoticeWhoGets: Called at start of inbox delivery prep; plugins can schedule EndNoticeWhoGets: Called at end of inbox delivery prep; plugins can filter out profiles from receiving inbox delivery here. Be aware that output can be cached or used several times, so should remain idempotent. - $notice Notice - &$ni: in/out array mapping profile IDs to constants: NOTICE_INBOX_SOURCE_SUB etc + +StartDefaultLocalNav: When showing the default local nav +- $menu: the menu +- $user: current user + +EndDefaultLocalNav: When showing the default local nav +- $menu: the menu +- $user: current user diff --git a/lib/defaultlocalnav.php b/lib/defaultlocalnav.php index a61ebbb585..1201ae7468 100644 --- a/lib/defaultlocalnav.php +++ b/lib/defaultlocalnav.php @@ -48,25 +48,30 @@ class DefaultLocalNav extends Menu { function show() { - $this->action->elementStart('ul', array('id' => 'nav_local_default')); - $user = common_current_user(); - if (!empty($user)) { - $pn = new PersonalGroupNav($this->action); - // TRANS: Menu item in default local navigation panel. - $this->submenu(_m('MENU','Home'), $pn); - } + $this->action->elementStart('ul', array('id' => 'nav_local_default')); - $bn = new PublicGroupNav($this->action); - // TRANS: Menu item in default local navigation panel. - $this->submenu(_m('MENU','Public'), $bn); + if (Event::handle('StartDefaultLocalNav', array($this, $user))) { - if (!empty($user)) { - $sn = new GroupsNav($this->action, $user); - if ($sn->haveGroups()) { - $this->submenu(_m('MENU', 'Groups'), $sn); + if (!empty($user)) { + $pn = new PersonalGroupNav($this->action); + // TRANS: Menu item in default local navigation panel. + $this->submenu(_m('MENU','Home'), $pn); } + + $bn = new PublicGroupNav($this->action); + // TRANS: Menu item in default local navigation panel. + $this->submenu(_m('MENU','Public'), $bn); + + if (!empty($user)) { + $sn = new GroupsNav($this->action, $user); + if ($sn->haveGroups()) { + $this->submenu(_m('MENU', 'Groups'), $sn); + } + } + + Event::handle('EndDefaultLocalNav', array($this, $user)); } $this->action->elementEnd('ul'); From 1459443b2110039a085103ee33522c79840288d5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 5 Apr 2011 18:19:11 -0400 Subject: [PATCH 4/5] cut-and-paste error in TagSubMenu --- plugins/TagSub/TagSubPlugin.php | 9 --------- plugins/TagSub/tagsubmenu.php | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/plugins/TagSub/TagSubPlugin.php b/plugins/TagSub/TagSubPlugin.php index 13e525bb62..8fbb113362 100644 --- a/plugins/TagSub/TagSubPlugin.php +++ b/plugins/TagSub/TagSubPlugin.php @@ -252,15 +252,6 @@ class TagSubPlugin extends Plugin $menu->submenu(_m('Tags'), $tagSubMenu); } - foreach ($tags as $tag) { - $menu->out->menuItem(common_local_url('tag', - array('tag' => $tag)), - sprintf('#%s', $tag), - sprintf(_('Notices tagged with %s'), $tag), - $menu->actionName == 'tag' && $menu->action->arg('tag') == $tag, - 'nav_streams_tag_'.$tag); - } - return true; } diff --git a/plugins/TagSub/tagsubmenu.php b/plugins/TagSub/tagsubmenu.php index 44770651d9..e2ddf04ef9 100644 --- a/plugins/TagSub/tagsubmenu.php +++ b/plugins/TagSub/tagsubmenu.php @@ -61,7 +61,7 @@ class TagSubMenu extends Menu { $this->out->elementStart('ul', array('class' => 'nav')); - foreach ($tags as $tag) { + foreach ($this->tags as $tag) { $this->out->menuItem(common_local_url('tag', array('tag' => $tag)), sprintf('#%s', $tag), From b3e7dd70e25ffecddcb24e676bfc9ae328f16c70 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 5 Apr 2011 18:27:01 -0400 Subject: [PATCH 5/5] don't put bogus groups into the groups array --- classes/Profile.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/Profile.php b/classes/Profile.php index f7a94413b2..9f63980242 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -272,7 +272,10 @@ class Profile extends Memcached_DataObject $groups = array(); foreach ($ids as $id) { - $groups[] = User_group::staticGet('id', $id); + $group = User_group::staticGet('id', $id); + if (!empty($group)) { + $groups[] = $group; + } } return new ArrayWrapper($groups);