]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GroupFavorited/groupfavoritedaction.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / plugins / GroupFavorited / groupfavoritedaction.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of popular notices
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Public
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 class GroupFavoritedAction extends ShowgroupAction
36 {
37     /**
38      * Title of the page
39      *
40      * @return string page title, with page number
41      */
42     function title()
43     {
44         if (!empty($this->group->fullname)) {
45             // @todo Create a core method to create this properly. i18n issue.
46             $base = $this->group->fullname . ' (' . $this->group->nickname . ')';
47         } else {
48             $base = $this->group->nickname;
49         }
50
51         if ($this->page == 1) {
52             // TRANS: %s is a group name.
53             return sprintf(_m('Popular posts in %s group'), $base);
54         } else {
55             // TRANS: %1$s is a group name, %2$s is a group number.
56             return sprintf(_m('Popular posts in %1$s group, page %2$d'),
57                            $base,
58                            $this->page);
59         }
60     }
61
62     /**
63      * Content area
64      *
65      * Shows the list of popular notices
66      *
67      * @return void
68      */
69     function showContent()
70     {
71         $groupId = intval($this->group->id);
72         $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
73         $cutoff = sprintf("fave.modified > '%s'",
74                           common_sql_date(time() - common_config('popular', 'cutoff')));
75
76         $qry = 'SELECT notice.*, '.
77           $weightexpr . ' as weight ' .
78           'FROM notice ' .
79           "JOIN group_inbox ON notice.id = group_inbox.notice_id " .
80           'JOIN fave ON notice.id = fave.notice_id ' .
81           "WHERE $cutoff AND group_id = $groupId " .
82           'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' .
83           'ORDER BY weight DESC';
84
85         $offset = ($this->page - 1) * NOTICES_PER_PAGE;
86         $limit  = NOTICES_PER_PAGE + 1;
87
88         if (common_config('db', 'type') == 'pgsql') {
89             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
90         } else {
91             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
92         }
93
94         $notice = Memcached_DataObject::cachedQuery('Notice',
95                                                     $qry,
96                                                     600);
97
98         $nl = new NoticeList($notice, $this);
99
100         $cnt = $nl->show();
101
102         if ($cnt == 0) {
103             //$this->showEmptyList();
104         }
105
106         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
107                           $this->page, 'groupfavorited',
108                           array('nickname' => $this->group->nickname));
109     }
110 }