3 * StatusNet, the distributed open-source microblogging tool
5 * StatusNet-only extensions to the Twitter-like API
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.
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.
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/>.
23 * @author Brion Vibber <brion@status.net>
24 * @copyright 2010 StatusNet, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26 * @link http://status.net/
29 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 * Oembed proxy implementation
36 * This class provides an interface for our JS-side code to pull info on
37 * links from other sites, using either native oEmbed, our own custom
38 * handlers, or the noembed.com offsite proxy service as configured.
42 * @author Brion Vibber <brion@status.net>
43 * @copyright 2010 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
47 class OembedproxyAction extends OembedAction
49 function handle(array $args=array())
51 // Trigger short error responses; not a human-readable web page.
52 StatusNet::setApi(true);
54 // We're not a general oEmbed proxy service; limit to valid sessions.
55 $token = $this->trimmed('token');
56 if (!$token || $token != common_session_token()) {
57 // TRANS: Client error displayed when the session token does not match or is not given.
58 $this->clientError(_m('There was a problem with your session token. '.
59 'Try again, please.'));
62 $format = $this->arg('format');
63 if ($format && $format != 'json') {
64 // TRANS: Client exception thrown when requesting a different format than JSON.
65 throw new ClientException(_m('Invalid format; only JSON supported.'));
68 $url = $this->arg('url');
69 if (!common_valid_http_url($url)) {
70 // TRANS: Client exception thrown when not providing a valid URL.
71 throw new ClientException(_m('Invalid URL.'));
75 if ($this->arg('maxwidth')) {
76 $params['maxwidth'] = $this->arg('maxwidth');
78 if ($this->arg('maxheight')) {
79 $params['maxheight'] = $this->arg('maxheight');
82 $data = oEmbedHelper::getObject($url, $params);
84 $this->init_document('json');
85 print json_encode($data);