]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/favorited.php
Minor: Including formData()'s inreplyto in action check
[quix0rs-gnu-social.git] / actions / favorited.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/stream.php');
23
24 class FavoritedAction extends StreamAction
25 {
26
27     function handle($args)
28     {
29         parent::handle($args);
30
31         $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
32
33         common_show_header(_('Popular notices'),
34                            array($this, 'show_header'), null,
35                            array($this, 'show_top'));
36
37         $this->show_notices($page);
38
39         common_show_footer();
40     }
41
42     function show_top()
43     {
44         $instr = $this->get_instructions();
45         $output = common_markup_to_html($instr);
46         common_element_start('div', 'instructions');
47         common_raw($output);
48         common_element_end('div');
49         $this->public_views_menu();
50     }
51
52     function show_header()
53     {
54         return;
55     }
56
57     function get_instructions()
58     {
59         return _('Showing recently popular notices');
60     }
61
62     function show_notices($page)
63     {
64
65         $qry = 'SELECT notice.*, sum(exp(-(now() - fave.modified) / %s)) as weight ' .
66                 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
67                 'GROUP BY fave.notice_id ' .
68                 'ORDER BY weight DESC';
69
70         $offset = ($page - 1) * NOTICES_PER_PAGE;
71         $limit = NOTICES_PER_PAGE + 1;
72
73         if (common_config('db','type') == 'pgsql') {
74             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
75         } else {
76             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
77         }
78
79         # Figure out how to cache this query
80
81         $notice = new Notice;
82         $notice->query(sprintf($qry, common_config('popular', 'dropoff')));
83
84         common_element_start('ul', array('id' => 'notices'));
85
86         $cnt = 0;
87
88         while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
89             $cnt++;
90
91             if ($cnt > NOTICES_PER_PAGE) {
92                 break;
93             }
94
95             $item = new NoticeListItem($notice);
96             $item->show();
97         }
98
99         common_element_end('ul');
100
101         common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
102                           $page, 'favorited');
103     }
104
105 }