4 * Embed a paste via oEmbed
6 * @link http://www.oembed.com/
8 $reqWritePermissions = false;
9 require_once 'www-header.php';
11 if (!isset($_GET['url'])) {
12 header('HTTP/1.0 400 Bad Request');
13 echo "url parameter missing\n";
17 if (!isset($_GET['format'])) {
19 } else if ($_GET['format'] != 'json' && $_GET['format'] != 'xml') {
20 header('HTTP/1.0 400 Bad Request');
21 echo "Invalid format parameter\n";
24 $format = $_GET['format'];
27 if (!isset($_GET['maxwidth'])) {
30 $maxWidth = (int) $_GET['maxwidth'];
31 if ($maxWidth <= 100) {
32 header('HTTP/1.0 400 Bad Request');
33 echo "maxwidth parameter too small\n";
38 if (!isset($_GET['maxheight'])) {
41 $maxHeight = (int) $_GET['maxheight'];
42 if ($maxHeight <= 100) {
43 header('HTTP/1.0 400 Bad Request');
44 echo "maxheight parameter too small\n";
50 $parts = explode('/', $_GET['url']);
53 $repo = new Repository();
56 if ($format == 'json') {
57 $data = new \stdClass();
59 $data = new \SimpleXMLElement(
60 '<?xml version="1.0" encoding="utf-8" standalone="yes"?>'
65 $data->version = '1.0';
67 $data->provider_name = 'phorkie';
68 $data->provider_url = Tools::fullUrl();
70 $data->title = $repo->getTitle();
71 $author = $repo->getOwner();
72 $data->author_name = $author['name'];
73 $data->cache_age = 86400;
75 $data->width = $maxWidth;
76 $data->height = $maxHeight;
78 $data->html = render('oembed', array('repo' => $repo), true);
80 if ($format == 'json') {
81 header('Content-type: application/json');
82 echo json_encode($data) . "\n";
84 header('Content-type: text/xml');