blob: 867265857b2b6f3f1aa8c6b61f401c552877e087 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<?php
namespace phorkie;
/**
* Embed a paste via oEmbed
*
* @link http://www.oembed.com/
*/
$reqWritePermissions = false;
require_once 'www-header.php';
if (!isset($_GET['url'])) {
header('HTTP/1.0 400 Bad Request');
echo "url parameter missing\n";
exit(1);
}
if (!isset($_GET['format'])) {
$format = 'json';
} else if ($_GET['format'] != 'json' && $_GET['format'] != 'xml') {
header('HTTP/1.0 400 Bad Request');
echo "Invalid format parameter\n";
exit(1);
} else {
$format = $_GET['format'];
}
if (!isset($_GET['maxwidth'])) {
$maxWidth = 900;
} else {
$maxWidth = (int) $_GET['maxwidth'];
if ($maxWidth <= 100) {
header('HTTP/1.0 400 Bad Request');
echo "maxwidth parameter too small\n";
exit(1);
}
}
if (!isset($_GET['maxheight'])) {
$maxHeight = 900;
} else {
$maxHeight = (int) $_GET['maxheight'];
if ($maxHeight <= 100) {
header('HTTP/1.0 400 Bad Request');
echo "maxheight parameter too small\n";
exit(1);
}
}
$parts = explode('/', $_GET['url']);
$id = end($parts);
$repo = new Repository();
$repo->loadById($id);
if ($format == 'json') {
$data = new \stdClass();
} else {
$data = new \SimpleXMLElement(
'<?xml version="1.0" encoding="utf-8" standalone="yes"?>'
. '<oembed/>'
);
}
$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();;
}
?>
|