diff options
-rw-r--r-- | actions/attachment.php | 12 | ||||
-rw-r--r-- | actions/oembed.php (renamed from actions/twitapioembed.php) | 61 | ||||
-rw-r--r-- | actions/shownotice.php | 12 | ||||
-rw-r--r-- | lib/router.php | 11 |
4 files changed, 61 insertions, 35 deletions
diff --git a/actions/attachment.php b/actions/attachment.php index c6a5d0d52..f42906fd8 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -103,18 +103,18 @@ class AttachmentAction extends Action $this->element('link',array('rel'=>'alternate', 'type'=>'application/json+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.json'), - array('url'=> + 'oembed', + array(), + array('format'=>'json', 'url'=> common_local_url('attachment', array('attachment' => $this->attachment->id)))), 'title'=>'oEmbed'),null); $this->element('link',array('rel'=>'alternate', 'type'=>'text/xml+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.xml'), - array('url'=> + 'oembed', + array(), + array('format'=>'xml','url'=> common_local_url('attachment', array('attachment' => $this->attachment->id)))), 'title'=>'oEmbed'),null); diff --git a/actions/twitapioembed.php b/actions/oembed.php index 3019e5878..3e46a7262 100644 --- a/actions/twitapioembed.php +++ b/actions/oembed.php @@ -31,8 +31,6 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/twitterapi.php'; - /** * Oembed provider implementation * @@ -46,17 +44,13 @@ require_once INSTALLDIR.'/lib/twitterapi.php'; * @link http://laconi.ca/ */ -class TwitapioembedAction extends TwitterapiAction +class OembedAction extends Action { - function oembed($args, $apidata) + function handle($args) { - parent::handle($args); - common_debug("in oembed api action"); - $this->auth_user = $apidata['user']; - $url = $args['url']; if( substr(strtolower($url),0,strlen(common_root_url())) == strtolower(common_root_url()) ){ $path = substr($url,strlen(common_root_url())); @@ -131,8 +125,7 @@ class TwitapioembedAction extends TwitterapiAction default: $this->serverError(_("$path not supported for oembed requests"), 501); } - - switch($apidata['content-type']){ + switch($args['format']){ case 'xml': $this->init_document('xml'); $this->elementStart('oembed'); @@ -151,12 +144,11 @@ class TwitapioembedAction extends TwitterapiAction if($oembed['thumbnail_url']) $this->element('thumbnail_url',null,$oembed['thumbnail_url']); if($oembed['thumbnail_width']) $this->element('thumbnail_width',null,$oembed['thumbnail_width']); if($oembed['thumbnail_height']) $this->element('thumbnail_height',null,$oembed['thumbnail_height']); - $this->elementEnd('oembed'); $this->end_document('xml'); break; - case 'json': + case 'json': case '': $this->init_document('json'); print(json_encode($oembed)); $this->end_document('json'); @@ -164,10 +156,51 @@ class TwitapioembedAction extends TwitterapiAction default: $this->serverError(_('content type ' . $apidata['content-type'] . ' not supported'), 501); } - }else{ $this->serverError(_('Only ' . common_root_url() . ' urls over plain http please'), 404); } } -} + function init_document($type) + { + switch ($type) { + case 'xml': + header('Content-Type: application/xml; charset=utf-8'); + $this->startXML(); + break; + case 'json': + header('Content-Type: application/json; charset=utf-8'); + + // Check for JSONP callback + $callback = $this->arg('callback'); + if ($callback) { + print $callback . '('; + } + break; + default: + $this->serverError(_('Not a supported data format.'), 501); + break; + } + } + + function end_document($type='xml') + { + switch ($type) { + case 'xml': + $this->endXML(); + break; + case 'json': + // Check for JSONP callback + $callback = $this->arg('callback'); + if ($callback) { + print ')'; + } + break; + default: + $this->serverError(_('Not a supported data format.'), 501); + break; + } + return; + } + +} diff --git a/actions/shownotice.php b/actions/shownotice.php index 4b179bc72..8f2ffd6b9 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -278,16 +278,16 @@ class ShownoticeAction extends OwnerDesignAction $this->element('link',array('rel'=>'alternate', 'type'=>'application/json+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.json'), - array('url'=>$this->notice->uri)), + 'oembed', + array(), + array('format'=>'json','url'=>$this->notice->uri)), 'title'=>'oEmbed'),null); $this->element('link',array('rel'=>'alternate', 'type'=>'text/xml+oembed', 'href'=>common_local_url( - 'api', - array('apiaction'=>'oembed','method'=>'oembed.xml'), - array('url'=>$this->notice->uri)), + 'oembed', + array(), + array('format'=>'xml','url'=>$this->notice->uri)), 'title'=>'oEmbed'),null); } } diff --git a/lib/router.php b/lib/router.php index f03cfcf6d..04c6dd414 100644 --- a/lib/router.php +++ b/lib/router.php @@ -117,15 +117,8 @@ class Router $m->connect('main/tagother/:id', array('action' => 'tagother')); - $m->connect('main/oembed.xml', - array('action' => 'api', - 'method' => 'oembed.xml', - 'apiaction' => 'oembed')); - - $m->connect('main/oembed.json', - array('action' => 'api', - 'method' => 'oembed.json', - 'apiaction' => 'oembed')); + $m->connect('main/oembed', + array('action' => 'oembed')); // these take a code |