oembed discovery closer to spec (not working yet)

This commit is contained in:
Hannes Mannerheim 2016-01-20 20:56:50 +01:00
parent d614b9fca8
commit 11df93fcb5
2 changed files with 20 additions and 6 deletions

View File

@ -153,9 +153,8 @@ class QvitterPlugin extends Plugin {
// route/reroute urls
public function onRouterInitialized($m)
{
$m->connect('api/qvitter/oembed_notice/:id.:format',
$m->connect('services/oembed.:format',
array('action' => 'apiqvitteroembednotice',
'id' => '[0-9]+',
'format' => '(xml|json)'));
$m->connect('api/qvitter/check_email.json',
array('action' => 'ApiQvitterCheckEmail'));

View File

@ -43,9 +43,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
class ApiQvitterOembedNoticeAction extends ApiAction
{
var $id = null;
var $format = null;
var $url = null;
/**
* Take arguments for running
@ -58,8 +57,8 @@ class ApiQvitterOembedNoticeAction extends ApiAction
{
parent::prepare($args);
$this->id = $this->arg('id');
$this->format = $this->arg('format');
$this->url = $this->arg('url');
return true;
}
@ -75,7 +74,23 @@ class ApiQvitterOembedNoticeAction extends ApiAction
{
parent::handle();
$notice = Notice::getKV('id',$this->id);
$noticeurl = common_path('notice/', StatusNet::isHTTPS());
$instanceurl = common_path('', StatusNet::isHTTPS());
// remove protocol for the comparison below
$noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl);
$instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl);
$url_wo_protocol = preg_replace('(^https?://)', '', $this->url);
// find local notice
if(strpos($url_wo_protocol, $noticeurl_wo_protocol) === 0) {
$possible_notice_id = str_replace($noticeurl_wo_protocol,'',$url_wo_protocol);
if(ctype_digit($possible_notice_id)) {
$notice = Notice::getKV('id',$possible_notice_id);;
} else {
$this->clientError("Notice not found.", 404);
}
}
if(!$notice instanceof Notice){
// TRANS: Client error displayed in oEmbed action when notice not found.