]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/noticebyurl.php
Page with a list of notices that link to an URL
[quix0rs-gnu-social.git] / plugins / Bookmark / noticebyurl.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Notice stream of notices with a given attachment
7  * 
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Bookmark
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2010 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * List notices that contain/link to/use a given URL
39  *
40  * @category  Bookmark
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2010 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47
48 class NoticebyurlAction extends Action
49 {
50     protected $url     = null;
51     protected $file    = null;
52     protected $notices = null;
53     protected $page    = null;
54
55     /**
56      * For initializing members of the class.
57      *
58      * @param array $argarray misc. arguments
59      *
60      * @return boolean true
61      */
62
63     function prepare($argarray)
64     {
65         parent::prepare($argarray);
66         
67         $this->file = File::staticGet('id', $this->trimmed('id'));
68
69         if (empty($this->file)) {
70             throw new ClientException(_('Unknown URL'));
71         }
72
73         $pageArg = $this->trimmed('page');
74
75         $this->page = (empty($pageArg)) ? 1 : intval($pageArg);
76
77         $this->notices = $this->file->stream(($this->page - 1) * NOTICES_PER_PAGE,
78                                              NOTICES_PER_PAGE + 1);
79
80         return true;
81     }
82
83     function title()
84     {
85         if ($this->page == 1) {
86             return sprintf(_("Notices linking to %s"), $this->file->url);
87         } else {
88             return sprintf(_("Notices linking to %s, page %d"),
89                            $this->file->url,
90                            $this->page);
91         }
92     }
93
94     /**
95      * Handler method
96      *
97      * @param array $argarray is ignored since it's now passed in in prepare()
98      *
99      * @return void
100      */
101
102     function handle($argarray=null)
103     {
104         $this->showPage();
105     }
106
107     function showContent()
108     {
109         $nl = new NoticeList($this->notices, $this);
110
111         $nl->show();
112
113         $cnt = $nl->show();
114
115         $this->pagination($this->page > 1,
116                           $cnt > NOTICES_PER_PAGE,
117                           $this->page,
118                           'noticebyurl',
119                           array('id' => $this->file->id));
120     }
121
122     /**
123      * Return true if read only.
124      *
125      * MAY override
126      *
127      * @param array $args other arguments
128      *
129      * @return boolean is read only action?
130      */
131
132     function isReadOnly($args)
133     {
134         return true;
135     }
136
137     /**
138      * Return last modified, if applicable.
139      *
140      * MAY override
141      *
142      * @return string last modified http header
143      */
144     function lastModified()
145     {
146         // For comparison with If-Last-Modified
147         // If not applicable, return null
148         return null;
149     }
150
151     /**
152      * Return etag, if applicable.
153      *
154      * MAY override
155      *
156      * @return string etag http header
157      */
158
159     function etag()
160     {
161         return null;
162     }
163 }