]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/attachment.php
change LACONICA to STATUSNET
[quix0rs-gnu-social.git] / actions / attachment.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show notice attachments
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  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/attachmentlist.php';
35
36 /**
37  * Show notice attachments
38  *
39  * @category Personal
40  * @package  StatusNet
41  * @author   Evan Prodromou <evan@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45
46 class AttachmentAction extends Action
47 {
48     /**
49      * Attachment object to show
50      */
51
52     var $attachment = null;
53
54     /**
55      * Load attributes based on database arguments
56      *
57      * Loads all the DB stuff
58      *
59      * @param array $args $_REQUEST array
60      *
61      * @return success flag
62      */
63
64     function prepare($args)
65     {
66         parent::prepare($args);
67
68         if ($id = $this->trimmed('attachment')) {
69             $this->attachment = File::staticGet($id);
70         }
71
72         if (empty($this->attachment)) {
73             $this->clientError(_('No such attachment.'), 404);
74             return false;
75         }
76         return true;
77     }
78
79     /**
80      * Is this action read-only?
81      *
82      * @return boolean true
83      */
84
85     function isReadOnly($args)
86     {
87         return true;
88     }
89
90     /**
91      * Title of the page
92      *
93      * @return string title of the page
94      */
95     function title()
96     {
97         $a = new Attachment($this->attachment);
98         return $a->title();
99     }
100
101     function extraHead()
102     {
103         $this->element('link',array('rel'=>'alternate',
104             'type'=>'application/json+oembed',
105             'href'=>common_local_url(
106                 'oembed',
107                 array(),
108                 array('format'=>'json', 'url'=>
109                     common_local_url('attachment',
110                         array('attachment' => $this->attachment->id)))),
111             'title'=>'oEmbed'),null);
112         $this->element('link',array('rel'=>'alternate',
113             'type'=>'text/xml+oembed',
114             'href'=>common_local_url(
115                 'oembed',
116                 array(),
117                 array('format'=>'xml','url'=>
118                     common_local_url('attachment',
119                         array('attachment' => $this->attachment->id)))),
120             'title'=>'oEmbed'),null);
121     }
122
123     /**
124      * Handle input
125      *
126      * Only handles get, so just show the page.
127      *
128      * @param array $args $_REQUEST data (unused)
129      *
130      * @return void
131      */
132
133     function handle($args)
134     {
135         parent::handle($args);
136
137         if (empty($this->attachment->filename)) {
138
139             // if it's not a local file, gtfo
140
141             common_redirect($this->attachment->url, 303);
142
143         } else {
144             $this->showPage();
145         }
146     }
147
148     /**
149      * Don't show local navigation
150      *
151      * @return void
152      */
153
154     function showLocalNavBlock()
155     {
156     }
157
158     /**
159      * Fill the content area of the page
160      *
161      * Shows a single notice list item.
162      *
163      * @return void
164      */
165
166     function showContent()
167     {
168         $ali = new Attachment($this->attachment, $this);
169         $cnt = $ali->show();
170     }
171
172     /**
173      * Don't show page notice
174      *
175      * @return void
176      */
177
178     function showPageNoticeBlock()
179     {
180     }
181
182     /**
183      * Show aside: this attachments appears in what notices
184      *
185      * @return void
186      */
187     function showSections() {
188         $ns = new AttachmentNoticeSection($this);
189         $ns->show();
190         $atcs = new AttachmentTagCloudSection($this);
191         $atcs->show();
192     }
193 }
194