]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/redirecturl.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / actions / redirecturl.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Redirect to the given URL
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  URL
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  * Redirect to a given URL
39  *
40  * This is our internal low-budget URL-shortener
41  *
42  * @category  Action
43  * @package   StatusNet
44  * @author    Evan Prodromou <evan@status.net>
45  * @copyright 2010 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49
50 class RedirecturlAction extends Action
51 {
52     protected $id   = null;
53     protected $file = 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->id = $this->trimmed('id');
68         
69         if (empty($this->id)) {
70             throw new ClientException(_('No id parameter'));
71         }
72
73         $this->file = File::staticGet('id', $this->id);
74         
75         if (empty($this->file)) {
76             throw new ClientException(sprintf(_('No such file "%d"'),
77                                               $this->id),
78                                       404);
79         }
80
81         return true;
82     }
83
84     /**
85      * Handler method
86      *
87      * @param array $argarray is ignored since it's now passed in in prepare()
88      *
89      * @return void
90      */
91
92     function handle($argarray=null)
93     {
94         common_redirect($this->file->url, 307);
95         return;
96     }
97
98     /**
99      * Return true if read only.
100      *
101      * MAY override
102      *
103      * @param array $args other arguments
104      *
105      * @return boolean is read only action?
106      */
107
108     function isReadOnly($args)
109     {
110         return true;
111     }
112
113     /**
114      * Return last modified, if applicable.
115      *
116      * MAY override
117      *
118      * @return string last modified http header
119      */
120
121     function lastModified()
122     {
123         // For comparison with If-Last-Modified
124         // If not applicable, return null
125
126         return strtotime($this->file->modified);
127     }
128
129     /**
130      * Return etag, if applicable.
131      *
132      * MAY override
133      *
134      * @return string etag http header
135      */
136
137     function etag()
138     {
139         return 'W/"' . implode(':', array($this->arg('action'),
140                                           common_user_cache_hash(),
141                                           common_language(),
142                                           $this->file->id)) . '"';
143     }
144 }