]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LinkPreview/oembedproxyaction.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / plugins / LinkPreview / oembedproxyaction.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * StatusNet-only extensions to the Twitter-like API
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  * @package   StatusNet
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/
27  */
28
29 if (!defined('STATUSNET') && !defined('LACONICA')) {
30     exit(1);
31 }
32
33 /**
34  * Oembed proxy implementation
35  *
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.
39  *
40  * @category  oEmbed
41  * @package   StatusNet
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/
46  */
47
48 class OembedproxyAction extends OembedAction
49 {
50
51     function handle($args)
52     {
53         // Trigger short error responses; not a human-readable web page.
54         StatusNet::setApi(true);
55
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(_('There was a problem with your session token. '.
60                                  'Try again, please.'));
61         }
62
63         $format = $this->arg('format');
64         if ($format && $format != 'json') {
65             throw new ClientException('Invalid format; only JSON supported.');
66         }
67
68         $url = $this->arg('url');
69         if (!common_valid_http_url($url)) {
70             throw new ClientException('Invalid URL.');
71         }
72
73         $params = array();
74         if ($this->arg('maxwidth')) {
75             $params['maxwidth'] = $this->arg('maxwidth');
76         }
77         if ($this->arg('maxheight')) {
78             $params['maxheight'] = $this->arg('maxheight');
79         }
80
81         $data = oEmbedHelper::getObject($url, $params);
82
83         $this->init_document('json');
84         print json_encode($data);
85     }
86
87 }