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 oohEmbed.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/
48 class OembedproxyAction extends OembedAction
51 function handle($args)
53 // Trigger short error responses; not a human-readable web page.
54 StatusNet::setApi(true);
56 // We're not a general oEmbed proxy service; limit to valid sessions.
57 $token = $this->trimmed('token');
58 if (!$token || $token != common_session_token()) {
59 $this->clientError(_m('There was a problem with your session token. '.
60 'Try again, please.'));
63 $format = $this->arg('format');
64 if ($format && $format != 'json') {
65 throw new ClientException('Invalid format; only JSON supported.');
68 $url = $this->arg('url');
69 if (!common_valid_http_url($url)) {
70 throw new ClientException('Invalid URL.');
74 if ($this->arg('maxwidth')) {
75 $params['maxwidth'] = $this->arg('maxwidth');
77 if ($this->arg('maxheight')) {
78 $params['maxheight'] = $this->arg('maxheight');
81 $data = oEmbedHelper::getObject($url, $params);
83 $this->init_document('json');
84 print json_encode($data);