From a32bfe7d87ae513ae5762db5cde628c87333b5aa Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 27 Aug 2016 15:24:25 +0200 Subject: [PATCH] TagCloud turned into plugin (performance issues on large installs) --- actions/all.php | 6 -- actions/attachment.php | 4 -- actions/public.php | 6 -- actions/showstream.php | 9 --- lib/groupaction.php | 5 -- lib/publicgroupnav.php | 7 -- lib/router.php | 6 -- plugins/TagCloud/TagCloudPlugin.php | 70 +++++++++++++++++++ .../TagCloud/actions}/publictagcloud.php | 0 .../lib}/attachmenttagcloudsection.php | 0 .../TagCloud/lib}/grouptagcloudsection.php | 0 .../TagCloud/lib}/inboxtagcloudsection.php | 0 .../TagCloud/lib}/personaltagcloudsection.php | 2 +- .../TagCloud/lib}/publictagcloudsection.php | 0 .../lib}/subpeopletagcloudsection.php | 0 .../subscriberspeopleselftagcloudsection.php | 0 .../lib}/subscriberspeopletagcloudsection.php | 0 ...subscriptionspeopleselftagcloudsection.php | 0 .../subscriptionspeopletagcloudsection.php | 0 .../TagCloud/lib}/tagcloudsection.php | 0 20 files changed, 71 insertions(+), 44 deletions(-) create mode 100644 plugins/TagCloud/TagCloudPlugin.php rename {actions => plugins/TagCloud/actions}/publictagcloud.php (100%) rename {lib => plugins/TagCloud/lib}/attachmenttagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/grouptagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/inboxtagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/personaltagcloudsection.php (97%) rename {lib => plugins/TagCloud/lib}/publictagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subpeopletagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriberspeopleselftagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriberspeopletagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriptionspeopleselftagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/subscriptionspeopletagcloudsection.php (100%) rename {lib => plugins/TagCloud/lib}/tagcloudsection.php (100%) diff --git a/actions/all.php b/actions/all.php index 19413076b5..84e4dd5305 100644 --- a/actions/all.php +++ b/actions/all.php @@ -170,12 +170,6 @@ class AllAction extends ShowstreamAction } $ibs->show(); } - // XXX: make this a little more convenient - - if (!common_config('performance', 'high')) { - $pop = new InboxTagCloudSection($this, $this->target); - $pop->show(); - } } } diff --git a/actions/attachment.php b/actions/attachment.php index 3ec837a511..3f2ae5c1ce 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -132,9 +132,5 @@ class AttachmentAction extends ManagedAction function showSections() { $ns = new AttachmentNoticeSection($this); $ns->show(); - if (!common_config('performance', 'high')) { - $atcs = new AttachmentTagCloudSection($this); - $atcs->show(); - } } } diff --git a/actions/public.php b/actions/public.php index 000f82cb93..a2958e8806 100644 --- a/actions/public.php +++ b/actions/public.php @@ -86,12 +86,6 @@ class PublicAction extends SitestreamAction $ibs->show(); } - $p = Profile::current(); - - if (!common_config('performance', 'high')) { - $cloud = new PublicTagCloudSection($this); - $cloud->show(); - } $feat = new FeaturedUsersSection($this); $feat->show(); } diff --git a/actions/showstream.php b/actions/showstream.php index 97b21b1286..1e70ecd3ac 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -251,15 +251,6 @@ class ShowstreamAction extends NoticestreamAction $this->elementEnd('div'); } - function showSections() - { - parent::showSections(); - if (!common_config('performance', 'high')) { - $cloud = new PersonalTagCloudSection($this->target, $this); - $cloud->show(); - } - } - function noticeFormOptions() { $options = parent::noticeFormOptions(); diff --git a/lib/groupaction.php b/lib/groupaction.php index 0886460737..31a0b8bc34 100644 --- a/lib/groupaction.php +++ b/lib/groupaction.php @@ -112,11 +112,6 @@ class GroupAction extends Action } $this->showAdmins(); - - if (!common_config('performance', 'high')) { - $cloud = new GroupTagCloudSection($this, $this->group); - $cloud->show(); - } } /** diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php index 620a61ddd9..ef342839d8 100644 --- a/lib/publicgroupnav.php +++ b/lib/publicgroupnav.php @@ -77,13 +77,6 @@ class PublicGroupNav extends Menu // TRANS: Menu item title in search group navigation panel. _('User groups'), $this->actionName == 'groups', 'nav_groups'); - if (!common_config('performance', 'high')) { - // TRANS: Menu item in search group navigation panel. - $this->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'), - // TRANS: Menu item title in search group navigation panel. - _('Recent tags'), $this->actionName == 'publictagcloud', 'nav_recent-tags'); - } - if (count(common_config('nickname', 'featured')) > 0) { // TRANS: Menu item in search group navigation panel. $this->out->menuItem(common_local_url('featured'), _m('MENU','Featured'), diff --git a/lib/router.php b/lib/router.php index b01c9a7677..cd464d841c 100644 --- a/lib/router.php +++ b/lib/router.php @@ -260,12 +260,6 @@ class Router array('action' => 'userbyid'), array('id' => '[0-9]+')); - if (!common_config('performance', 'high')) { - $m->connect('tags/', array('action' => 'publictagcloud')); - $m->connect('tag/', array('action' => 'publictagcloud')); - $m->connect('tags', array('action' => 'publictagcloud')); - $m->connect('tag', array('action' => 'publictagcloud')); - } $m->connect('tag/:tag/rss', array('action' => 'tagrss'), array('tag' => self::REGEX_TAG)); diff --git a/plugins/TagCloud/TagCloudPlugin.php b/plugins/TagCloud/TagCloudPlugin.php new file mode 100644 index 0000000000..c616be75fd --- /dev/null +++ b/plugins/TagCloud/TagCloudPlugin.php @@ -0,0 +1,70 @@ + + * @copyright 2016 Free Software Foundation, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://gnu.io/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class TagCloudPlugin extends Plugin { + + public function onRouterInitialized(URLMapper $m) + { + $m->connect('tags/', array('action' => 'publictagcloud')); + $m->connect('tag/', array('action' => 'publictagcloud')); + $m->connect('tags', array('action' => 'publictagcloud')); + $m->connect('tag', array('action' => 'publictagcloud')); + } + + public function onEndPublicGroupNav(Menu $menu) + { + // TRANS: Menu item in search group navigation panel. + $menu->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'), + // TRANS: Menu item title in search group navigation panel. + _('Recent tags'), $menu->actionName === 'publictagcloud', 'nav_recent-tags'); + } + + public function onEndShowSections(Action $action) + { + $cloud = null; + + switch (true) { + case $action instanceof AllAction: + $cloud = new InboxTagCloudSection($action, $action->getTarget()); + break; + case $action instanceof AttachmentAction: + $cloud = new AttachmentTagCloudSection($action); + break; + case $action instanceof PublicAction: + $cloud = new PublicTagCloudSection($action); + break; + case $action instanceof ShowstreamAction: + $cloud = new PersonalTagCloudSection($action, $action->getTarget()); + break; + case $action instanceof GroupAction: + $cloud = new GroupTagCloudSection($action, $action->getGroup()); + } + + if (!is_null($cloud)) { + $cloud->show(); + } + } + + public function onPluginVersion(array &$versions) + { + $versions[] = array('name' => 'TagCloud', + 'version' => GNUSOCIAL_VERSION, + 'author' => 'Mikael Nordfeldth', + 'homepage' => 'https://gnu.io/social', + 'description' => + // TRANS: Plugin description. + _m('Adds tag clouds to stream pages')); + return true; + } +} diff --git a/actions/publictagcloud.php b/plugins/TagCloud/actions/publictagcloud.php similarity index 100% rename from actions/publictagcloud.php rename to plugins/TagCloud/actions/publictagcloud.php diff --git a/lib/attachmenttagcloudsection.php b/plugins/TagCloud/lib/attachmenttagcloudsection.php similarity index 100% rename from lib/attachmenttagcloudsection.php rename to plugins/TagCloud/lib/attachmenttagcloudsection.php diff --git a/lib/grouptagcloudsection.php b/plugins/TagCloud/lib/grouptagcloudsection.php similarity index 100% rename from lib/grouptagcloudsection.php rename to plugins/TagCloud/lib/grouptagcloudsection.php diff --git a/lib/inboxtagcloudsection.php b/plugins/TagCloud/lib/inboxtagcloudsection.php similarity index 100% rename from lib/inboxtagcloudsection.php rename to plugins/TagCloud/lib/inboxtagcloudsection.php diff --git a/lib/personaltagcloudsection.php b/plugins/TagCloud/lib/personaltagcloudsection.php similarity index 97% rename from lib/personaltagcloudsection.php rename to plugins/TagCloud/lib/personaltagcloudsection.php index 46b4661e89..e46aa2d662 100644 --- a/lib/personaltagcloudsection.php +++ b/plugins/TagCloud/lib/personaltagcloudsection.php @@ -42,7 +42,7 @@ class PersonalTagCloudSection extends TagCloudSection { protected $profile = null; - function __construct(Profile $profile, HTMLOutputter $out=null) + function __construct(HTMLOutputter $out, Profile $profile) { parent::__construct($out); $this->profile = $profile; diff --git a/lib/publictagcloudsection.php b/plugins/TagCloud/lib/publictagcloudsection.php similarity index 100% rename from lib/publictagcloudsection.php rename to plugins/TagCloud/lib/publictagcloudsection.php diff --git a/lib/subpeopletagcloudsection.php b/plugins/TagCloud/lib/subpeopletagcloudsection.php similarity index 100% rename from lib/subpeopletagcloudsection.php rename to plugins/TagCloud/lib/subpeopletagcloudsection.php diff --git a/lib/subscriberspeopleselftagcloudsection.php b/plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php similarity index 100% rename from lib/subscriberspeopleselftagcloudsection.php rename to plugins/TagCloud/lib/subscriberspeopleselftagcloudsection.php diff --git a/lib/subscriberspeopletagcloudsection.php b/plugins/TagCloud/lib/subscriberspeopletagcloudsection.php similarity index 100% rename from lib/subscriberspeopletagcloudsection.php rename to plugins/TagCloud/lib/subscriberspeopletagcloudsection.php diff --git a/lib/subscriptionspeopleselftagcloudsection.php b/plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php similarity index 100% rename from lib/subscriptionspeopleselftagcloudsection.php rename to plugins/TagCloud/lib/subscriptionspeopleselftagcloudsection.php diff --git a/lib/subscriptionspeopletagcloudsection.php b/plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php similarity index 100% rename from lib/subscriptionspeopletagcloudsection.php rename to plugins/TagCloud/lib/subscriptionspeopletagcloudsection.php diff --git a/lib/tagcloudsection.php b/plugins/TagCloud/lib/tagcloudsection.php similarity index 100% rename from lib/tagcloudsection.php rename to plugins/TagCloud/lib/tagcloudsection.php -- 2.39.5