]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/conversation.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / actions / conversation.php
1 <?php
2 /**
3  * Display a conversation in the browser
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  Laconica
9  * @author   Evan Prodromou <evan@controlyourself.ca>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://laconi.ca/
12  *
13  * Laconica - a distributed open-source microblogging tool
14  * Copyright (C) 2008, Controlez-Vous, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Conversation tree in the browser
36  *
37  * @category Action
38  * @package  Laconica
39  * @author   Evan Prodromou <evan@controlyourself.ca>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://laconi.ca/
42  */
43 class ConversationAction extends Action
44 {
45     var $id = null;
46     var $notices = null;
47     var $page = null;
48
49     /**
50      * Initialization.
51      *
52      * @param array $args Web and URL arguments
53      *
54      * @return boolean false if id not passed in
55      */
56
57     function prepare($args)
58     {
59         parent::prepare($args);
60         $this->id = $this->trimmed('id');
61         if (!$this->id) {
62             return false;
63         }
64         $this->notices = $this->getNotices();
65         $this->page = $this->trimmed('page');
66         if (empty($this->page)) {
67             $this->page = 1;
68         }
69         return true;
70     }
71
72     /**
73      * Get notices
74      *
75      * @param integer $limit max number of notices to return
76      *
77      * @return array notices
78      */
79
80     function getNotices($limit=0)
81     {
82         $qry = 'SELECT notice.*, '.
83           'FROM notice WHERE conversation = %d '.
84           'ORDER BY created ';
85
86         $offset = 0;
87         $limit  = NOTICES_PER_PAGE + 1;
88
89         if (common_config('db', 'type') == 'pgsql') {
90             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
91         } else {
92             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
93         }
94
95         return Notice::getStream(sprintf($qry, $this->id),
96                                  'notice:conversation:'.$this->id,
97                                  $offset, $limit);
98     }
99
100     function handle($args)
101     {
102         $this->showPage();
103     }
104
105     function title()
106     {
107         return _("Conversation");
108     }
109
110     function showContent()
111     {
112         // FIXME this needs to be a tree, not a list
113
114         $nl = new NoticeList($this->notices, $this);
115
116         $cnt = $nl->show();
117
118         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
119                           $this->page, 'conversation', array('id' => $this->id));
120     }
121
122 }
123