From 78215a8279ecc048bd6bbb6a4977ee58766928b6 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 2 Feb 2015 21:34:22 +0100 Subject: [PATCH 1/1] Add oEmbed support --- README.rst | 2 +- data/templates/display.htm | 2 + data/templates/oembed.htm | 7 +++ src/phorkie/Repository.php | 6 +++ www/oembed.php | 87 ++++++++++++++++++++++++++++++++++++++ www/www-header.php | 10 ++++- 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 data/templates/oembed.htm create mode 100644 www/oembed.php diff --git a/README.rst b/README.rst index 889f474..fc97dd7 100644 --- a/README.rst +++ b/README.rst @@ -22,7 +22,7 @@ Features - add new files - delete existing files - replace file with upload -- embedding of pastes in your blog +- embedding of pastes in your blog via oEmbed - multiple files in one paste - option to edit single files in a multi-file paste - syntax highlighting with GeSHi diff --git a/data/templates/display.htm b/data/templates/display.htm index 0e5f036..16e1b08 100644 --- a/data/templates/display.htm +++ b/data/templates/display.htm @@ -3,6 +3,8 @@ {% block meta %} + + {% if repo.getCloneURL(true) %} {% endif %} diff --git a/data/templates/oembed.htm b/data/templates/oembed.htm new file mode 100644 index 0000000..1a1eb7a --- /dev/null +++ b/data/templates/oembed.htm @@ -0,0 +1,7 @@ + + +
+{% for file in repo.getFiles %} + {% include 'embed-part-file.htm' %} +{% endfor %} +
diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index f9b248d..8cf5ff6 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -337,6 +337,12 @@ class Repository $link = $this->id . '/delete/confirm'; } else if ($type == 'embed') { $link = $this->id . '/embed'; + } else if ($type == 'oembed-json') { + $link = 'oembed.php?format=json&url=' + . urlencode($this->getLink('display', null, true)); + } else if ($type == 'oembed-xml') { + $link = 'oembed.php?format=xml&url=' + . urlencode($this->getLink('display', null, true)); } else if ($type == 'remotefork') { return 'web+fork:' . $this->getLink('display', null, true); } else if ($type == 'revision') { diff --git a/www/oembed.php b/www/oembed.php new file mode 100644 index 0000000..8672658 --- /dev/null +++ b/www/oembed.php @@ -0,0 +1,87 @@ +loadById($id); + +if ($format == 'json') { + $data = new \stdClass(); +} else { + $data = new \SimpleXMLElement( + '' + . '' + ); +} +$data->type = 'rich'; +$data->version = '1.0'; + +$data->provider_name = 'phorkie'; +$data->provider_url = Tools::fullUrl(); + +$data->title = $repo->getTitle(); +$author = $repo->getOwner(); +$data->author_name = $author['name']; +$data->cache_age = 86400; + +$data->width = $maxWidth; +$data->height = $maxHeight; + +$data->html = render('oembed', array('repo' => $repo), true); + +if ($format == 'json') { + header('Content-type: application/json'); + echo json_encode($data) . "\n"; +} else { + header('Content-type: text/xml'); + echo $data->asXML();; +} +?> diff --git a/www/www-header.php b/www/www-header.php index 833fb8a..859d797 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -91,7 +91,7 @@ if (!isset($noSecurityCheck) || $noSecurityCheck !== true) { require __DIR__ . '/www-security.php'; } -function render($tplname, $vars = array()) +function render($tplname, $vars = array(), $return = false) { $vars['baseurl'] = '/'; if (!empty($GLOBALS['phorkie']['cfg']['baseurl'])) { @@ -117,8 +117,14 @@ function render($tplname, $vars = array()) $vars['suggestSetupCheck'] = $GLOBALS['phorkie']['suggestSetupCheck']; $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm'); - echo $template->render($vars); + + if ($return) { + return $template->render($vars); + } else { + echo $template->render($vars); + } } + function redirect($target) { header('Location: ' . $target); -- 2.30.2