[GroupFavorited] Fix plugin

This commit is contained in:
Diogo Cordeiro 2019-08-10 20:21:09 +01:00
parent 0795a39459
commit 1459f10803
5 changed files with 108 additions and 100 deletions

View File

@ -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 </html> tag
- $action: action object being shown

View File

@ -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;

View File

@ -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');
}

View File

@ -1,61 +1,71 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* 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 <http://www.gnu.org/licenses/>.
*/
// 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 <http://www.gnu.org/licenses/>.
/**
* The GroupFavorited plugin adds a menu item for popular notices in groups.
*
* @package GroupFavoritedPlugin
* @maintainer Brion Vibber <brion@status.net>
* @author Brion Vibber <brion@status.net>
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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',
$m->connect(
'group/:nickname/favorited',
['action' => 'groupfavorited'],
['nickname' => '[a-zA-Z0-9]+']);
['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'),
$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.
sprintf(_m('TOOLTIP','Popular notices in %s group'), $nickname),
$action_name == 'groupfavorited',
'nav_group_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');
}
/**

View File

@ -1,36 +1,29 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* 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 <http://www.gnu.org/licenses/>.
*
* @category Public
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @author Evan Prodromou <evan@status.net>
* @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 <brion@status.net>
* @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'),
return sprintf(
_m('Popular posts in %1$s group, page %2$d'),
$base,
$this->page);
$this->page
);
}
}
@ -61,12 +57,14 @@ 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 ' .
@ -86,20 +84,26 @@ class GroupFavoritedAction extends ShowgroupAction
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
$notice = Memcached_DataObject::cachedQuery('Notice',
$notice = Memcached_DataObject::cachedQuery(
'Notice',
$qry,
600);
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)
);
}
}