2010-11-16 23:36:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* StatusNet-only extensions to the Twitter-like API
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Brion Vibber <brion@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Oembed proxy implementation
|
|
|
|
*
|
|
|
|
* This class provides an interface for our JS-side code to pull info on
|
|
|
|
* links from other sites, using either native oEmbed, our own custom
|
2011-09-30 20:51:23 +01:00
|
|
|
* handlers, or the noembed.com offsite proxy service as configured.
|
2010-11-16 23:36:53 +00:00
|
|
|
*
|
|
|
|
* @category oEmbed
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Brion Vibber <brion@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
class OembedproxyAction extends OembedAction
|
|
|
|
{
|
|
|
|
function handle($args)
|
|
|
|
{
|
2010-12-06 21:37:57 +00:00
|
|
|
// Trigger short error responses; not a human-readable web page.
|
2015-02-27 11:44:15 +00:00
|
|
|
GNUsocial::setApi(true);
|
2010-12-06 21:37:57 +00:00
|
|
|
|
2010-11-16 23:36:53 +00:00
|
|
|
// We're not a general oEmbed proxy service; limit to valid sessions.
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2011-04-24 18:28:26 +01:00
|
|
|
// TRANS: Client error displayed when the session token does not match or is not given.
|
2011-03-30 21:30:23 +01:00
|
|
|
$this->clientError(_m('There was a problem with your session token. '.
|
2010-11-16 23:36:53 +00:00
|
|
|
'Try again, please.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$format = $this->arg('format');
|
|
|
|
if ($format && $format != 'json') {
|
2011-04-24 18:28:26 +01:00
|
|
|
// TRANS: Client exception thrown when requesting a different format than JSON.
|
|
|
|
throw new ClientException(_m('Invalid format; only JSON supported.'));
|
2010-11-16 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$url = $this->arg('url');
|
|
|
|
if (!common_valid_http_url($url)) {
|
2011-04-24 18:28:26 +01:00
|
|
|
// TRANS: Client exception thrown when not providing a valid URL.
|
|
|
|
throw new ClientException(_m('Invalid URL.'));
|
2010-11-16 23:36:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
if ($this->arg('maxwidth')) {
|
|
|
|
$params['maxwidth'] = $this->arg('maxwidth');
|
|
|
|
}
|
|
|
|
if ($this->arg('maxheight')) {
|
|
|
|
$params['maxheight'] = $this->arg('maxheight');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = oEmbedHelper::getObject($url, $params);
|
|
|
|
|
|
|
|
$this->init_document('json');
|
|
|
|
print json_encode($data);
|
|
|
|
}
|
|
|
|
}
|