3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Redirect to the given URL
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Redirect to a given URL
40 * This is our internal low-budget URL-shortener
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/
50 class RedirecturlAction extends Action
53 protected $file = null;
56 * For initializing members of the class.
58 * @param array $argarray misc. arguments
60 * @return boolean true
62 function prepare($argarray)
64 parent::prepare($argarray);
66 $this->id = $this->trimmed('id');
68 if (empty($this->id)) {
69 // TRANS: Client exception thrown when no ID parameter was provided.
70 throw new ClientException(_('No id parameter.'));
73 $this->file = File::staticGet('id', $this->id);
75 if (empty($this->file)) {
76 // TRANS: Client exception thrown when an invalid ID parameter was provided for a file.
77 // TRANS: %d is the provided ID for which the file is not present (number).
78 throw new ClientException(sprintf(_('No such file "%d".'),
89 * @param array $argarray is ignored since it's now passed in in prepare()
93 function handle($argarray=null)
95 common_redirect($this->file->url, 307);
100 * Return true if read only.
104 * @param array $args other arguments
106 * @return boolean is read only action?
108 function isReadOnly($args)
114 * Return last modified, if applicable.
118 * @return string last modified http header
120 function lastModified()
122 // For comparison with If-Last-Modified
123 // If not applicable, return null
125 return strtotime($this->file->modified);
129 * Return etag, if applicable.
133 * @return string etag http header
137 return 'W/"' . implode(':', array($this->arg('action'),
138 common_user_cache_hash(),
140 $this->file->id)) . '"';