From 1459f10803a28aff73220ca3ed6618507a0bf330 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Sat, 10 Aug 2019 20:21:09 +0100 Subject: [PATCH] [GroupFavorited] Fix plugin --- DOCUMENTATION/DEVELOPERS/EVENTS.txt | 6 - lib/noticelist.php | 4 +- lib/peopletagnav.php | 2 +- .../GroupFavorited/GroupFavoritedPlugin.php | 84 +++++++------ .../GroupFavorited/actions/groupfavorited.php | 112 +++++++++--------- 5 files changed, 108 insertions(+), 100 deletions(-) diff --git a/DOCUMENTATION/DEVELOPERS/EVENTS.txt b/DOCUMENTATION/DEVELOPERS/EVENTS.txt index 005260dd1f..7433395f7c 100644 --- a/DOCUMENTATION/DEVELOPERS/EVENTS.txt +++ b/DOCUMENTATION/DEVELOPERS/EVENTS.txt @@ -229,12 +229,6 @@ StartPersonalGroupNav: beginning of personal group nav menu EndPersonalGroupNav: end of personal group nav menu (good place to add a menu item) - $action: action object being shown -StartGroupGroupNav: Showing the group nav menu -- $action: the current action - -EndGroupGroupNav: At the end of the group nav menu -- $action: the current action - StartEndHTML: just before the tag - $action: action object being shown diff --git a/lib/noticelist.php b/lib/noticelist.php index 727be89bc6..e7e4756da8 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -63,9 +63,9 @@ class NoticeList extends Widget /** * constructor * - * @param Notice $notice stream of notices from DB_DataObject + * @param mixed $notice stream of notices from DB_DataObject (may be a Notice but can also be something like an ArrayWrapper) */ - function __construct(Notice $notice, $out=null, array $prefs=array()) + function __construct($notice, $out = null, array $prefs = []) { parent::__construct($out); $this->notice = $notice; diff --git a/lib/peopletagnav.php b/lib/peopletagnav.php index c2e3d1f268..e586c30de5 100644 --- a/lib/peopletagnav.php +++ b/lib/peopletagnav.php @@ -101,7 +101,7 @@ class PeopletagNav extends Menu sprintf(_m('TOOLTIP','Lists by %s.'), $nickname), $action_name == 'peopletagsbyuser', 'nav_lists_by'); - Event::handle('EndGroupGroupNav', array($this)); + Event::handle('EndPeopletagGroupNav', array($this)); } $this->out->elementEnd('ul'); } diff --git a/plugins/GroupFavorited/GroupFavoritedPlugin.php b/plugins/GroupFavorited/GroupFavoritedPlugin.php index e42a4338e9..889f455902 100644 --- a/plugins/GroupFavorited/GroupFavoritedPlugin.php +++ b/plugins/GroupFavorited/GroupFavoritedPlugin.php @@ -1,61 +1,71 @@ . - */ +// This file is part of GNU social - https://www.gnu.org/software/social +// +// GNU social is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GNU social is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with GNU social. If not, see . /** - * @package GroupFavoritedPlugin - * @maintainer Brion Vibber + * The GroupFavorited plugin adds a menu item for popular notices in groups. + * + * @package GroupFavoritedPlugin + * @author Brion Vibber + * @author Diogo Cordeiro + * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET')) { exit(1); } +defined('GNUSOCIAL') || die(); class GroupFavoritedPlugin extends Plugin { - const PLUGIN_VERSION = '2.0.0'; + const PLUGIN_VERSION = '2.0.1'; /** * Hook for RouterInitialized event. * * @param URLMapper $m path-to-action mapper * @return boolean hook return + * @throws Exception */ - function onRouterInitialized(URLMapper $m) + public function onRouterInitialized(URLMapper $m) { - $m->connect('group/:nickname/favorited', - ['action' => 'groupfavorited'], - ['nickname' => '[a-zA-Z0-9]+']); + $m->connect( + 'group/:nickname/favorited', + ['action' => 'groupfavorited'], + ['nickname' => '[a-zA-Z0-9]+'] + ); return true; } - function onEndGroupGroupNav(Menu $nav) + public function onEndGroupActionsList(GroupProfileBlock $nav, User_group $group) { - $action_name = $nav->action->trimmed('action'); - $nickname = $nav->group->nickname; - $nav->out->menuItem(common_local_url('groupfavorited', array('nickname' => - $nickname)), - // TRANS: Menu item in the group navigation page. - _m('MENU', 'Popular'), - // TRANS: Tooltip for menu item in the group navigation page. - // TRANS: %s is the nickname of the group. - sprintf(_m('TOOLTIP','Popular notices in %s group'), $nickname), - $action_name == 'groupfavorited', - 'nav_group_group'); + $nav->out->elementStart('li', 'entity_popular'); + $nav->out->element( + 'a', + [ + 'href' => common_local_url( + 'groupfavorited', + ['nickname' => $group->nickname] + ), + // TRANS: Tooltip for menu item in the group navigation page. + // TRANS: %s is the nickname of the group. + 'title' => sprintf(_m('TOOLTIP', 'Popular notices in %s group'), $group->nickname) + ], + // TRANS: Menu item in the group navigation page. + _m('MENU', 'Popular') + ); + $nav->out->elementEnd('li'); } /** diff --git a/plugins/GroupFavorited/actions/groupfavorited.php b/plugins/GroupFavorited/actions/groupfavorited.php index dcbf7d0bc5..3799f3a2f6 100644 --- a/plugins/GroupFavorited/actions/groupfavorited.php +++ b/plugins/GroupFavorited/actions/groupfavorited.php @@ -1,36 +1,29 @@ . + /** - * StatusNet, the distributed open-source microblogging tool + * The GroupFavorited plugin adds a menu item for popular notices in groups. * - * List of popular notices - * - * PHP version 5 - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * @category Public - * @package StatusNet - * @author Zach Copley - * @author Evan Prodromou - * @copyright 2008-2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @package GroupFavoritedPlugin + * @author Brion Vibber + * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); class GroupFavoritedAction extends ShowgroupAction { @@ -38,8 +31,9 @@ class GroupFavoritedAction extends ShowgroupAction * Title of the page * * @return string page title, with page number + * @throws Exception */ - function title() + public function title() { $base = $this->group->getFancyName(); @@ -48,9 +42,11 @@ class GroupFavoritedAction extends ShowgroupAction return sprintf(_m('Popular posts in %s group'), $base); } else { // TRANS: %1$s is a group name, %2$s is a group number. - return sprintf(_m('Popular posts in %1$s group, page %2$d'), - $base, - $this->page); + return sprintf( + _m('Popular posts in %1$s group, page %2$d'), + $base, + $this->page + ); } } @@ -61,24 +57,26 @@ class GroupFavoritedAction extends ShowgroupAction * * @return void */ - function showContent() + public function showContent() { - $groupId = intval($this->group->id); + $groupId = (int)$this->group->id; $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff')); - $cutoff = sprintf("fave.modified > '%s'", - common_sql_date(time() - common_config('popular', 'cutoff'))); + $cutoff = sprintf( + "fave.modified > '%s'", + common_sql_date(time() - common_config('popular', 'cutoff')) + ); - $qry = 'SELECT notice.*, '. - $weightexpr . ' as weight ' . - 'FROM notice ' . - "JOIN group_inbox ON notice.id = group_inbox.notice_id " . - 'JOIN fave ON notice.id = fave.notice_id ' . - "WHERE $cutoff AND group_id = $groupId " . - 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' . - 'ORDER BY weight DESC'; + $qry = 'SELECT notice.*, ' . + $weightexpr . ' as weight ' . + 'FROM notice ' . + "JOIN group_inbox ON notice.id = group_inbox.notice_id " . + 'JOIN fave ON notice.id = fave.notice_id ' . + "WHERE $cutoff AND group_id = $groupId " . + 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' . + 'ORDER BY weight DESC'; $offset = ($this->page - 1) * NOTICES_PER_PAGE; - $limit = NOTICES_PER_PAGE + 1; + $limit = NOTICES_PER_PAGE + 1; if (common_config('db', 'type') == 'pgsql') { $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; @@ -86,20 +84,26 @@ class GroupFavoritedAction extends ShowgroupAction $qry .= ' LIMIT ' . $offset . ', ' . $limit; } - $notice = Memcached_DataObject::cachedQuery('Notice', - $qry, - 600); + $notice = Memcached_DataObject::cachedQuery( + 'Notice', + $qry, + 600 + ); $nl = new NoticeList($notice, $this); $cnt = $nl->show(); - if ($cnt == 0) { - //$this->showEmptyList(); - } + /*if ($cnt == 0) { + $this->showEmptyList(); + }*/ - $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, - $this->page, 'groupfavorited', - array('nickname' => $this->group->nickname)); + $this->pagination( + $this->page > 1, + $cnt > NOTICES_PER_PAGE, + $this->page, + 'groupfavorited', + array('nickname' => $this->group->nickname) + ); } }