diff --git a/QvitterPlugin.php b/QvitterPlugin.php index 1be1692..e32bc81 100644 --- a/QvitterPlugin.php +++ b/QvitterPlugin.php @@ -153,7 +153,10 @@ class QvitterPlugin extends Plugin { // route/reroute urls public function onRouterInitialized($m) { - + $m->connect('api/qvitter/oembed_notice/:id.:format', + array('action' => 'apiqvitteroembednotice', + 'id' => '[0-9]+', + 'format' => '(xml|json)')); $m->connect('api/qvitter/check_email.json', array('action' => 'ApiQvitterCheckEmail')); $m->connect('api/qvitter/:nickname/lists/:id/subscribers.json', diff --git a/actions/apiqvitteroembednotice.php b/actions/apiqvitteroembednotice.php new file mode 100644 index 0000000..2166e58 --- /dev/null +++ b/actions/apiqvitteroembednotice.php @@ -0,0 +1,128 @@ + \\\\_\ · + · \\) \____) · + · · + · · + · · + · Qvitter 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 three of the License or (at · + · your option) any later version. · + · · + · Qvitter is distributed in hope that it will be useful but WITHOUT ANY · + · WARRANTY; without even the implied warranty of MERCHANTABILTY 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 Qvitter. If not, see . · + · · + · Contact h@nnesmannerhe.im if you have any questions. · + · · + · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ + + +if (!defined('GNUSOCIAL')) { exit(1); } + +class ApiQvitterOembedNoticeAction extends ApiAction +{ + + var $id = null; + var $format = null; + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + */ + protected function prepare(array $args=array()) + { + parent::prepare($args); + + $this->id = $this->arg('id'); + $this->format = $this->arg('format'); + + return true; + } + + /** + * Handle the request + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + protected function handle() + { + parent::handle(); + + $notice = Notice::getKV('id',$this->id); + + if(!$notice instanceof Notice){ + // TRANS: Client error displayed in oEmbed action when notice not found. + // TRANS: %s is a notice. + $this->clientError(sprintf(_("Notice %s not found."),$this->id), 404); + } + $profile = $notice->getProfile(); + if (!$profile instanceof Profile) { + // TRANS: Server error displayed in oEmbed action when notice has not profile. + $this->serverError(_('Notice has no profile.'), 500); + } + $authorname = $profile->getFancyName(); + + $oembed=array(); + $oembed['version']='1.0'; + $oembed['provider_name']=common_config('site', 'name'); + $oembed['provider_url']=common_root_url(); + + // TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date. + $oembed['title'] = sprintf(_('%1$s\'s status on %2$s'), + $authorname, + common_exact_date($notice->created)); + $oembed['author_name']=$authorname; + $oembed['author_url']=$profile->profileurl; + $oembed['url']=$notice->getUrl(); + $oembed['html']=$notice->getRendered(); + + if($this->format == 'json') { + $this->initDocument('json'); + print json_encode($oembed); + $this->endDocument('json'); + } elseif ($this->format == 'xml') { + $this->initDocument('xml'); + $this->elementStart('oembed'); + foreach(array( + 'version', 'type', 'provider_name', + 'provider_url', 'title', 'author_name', + 'author_url', 'url', 'html' + ) as $key) { + if (isset($oembed[$key]) && $oembed[$key]!='') { + $this->element($key, null, $oembed[$key]); + } + } + $this->elementEnd('oembed'); + $this->endDocument('xml'); + } else { + $this->serverError(sprintf(_('Format %s not supported.'), $this->format), 501); + } + } +} diff --git a/actions/qvitter.php b/actions/qvitter.php index c3adfe8..20bfcf5 100644 --- a/actions/qvitter.php +++ b/actions/qvitter.php @@ -174,7 +174,23 @@ class QvitterAction extends ApiAction } } - + // oembed discovery for local notices + if(substr($_SERVER['REQUEST_URI'],0,8) == '/notice/' + && $this->arg('notice') + && array_key_exists('Oembed', StatusNet::getActivePlugins())) { + $notice = Notice::getKV('id', $this->arg('notice')); + if($notice instanceof Notice) { + if ($notice->isLocal()) { + try { + $notice_url = $notice->getUrl(); + print ''; + print ''; + } catch (Exception $e) { + // + } + } + } + } ?>