Skip to content
Newer
Older
100644 69 lines (55 sloc) 1.73 KB
b12752e @nyroDev Add embedlyUrl option for nmObject in embedLy filter
authored Sep 26, 2011
1 <?php
2
3 // Directory to cache the results (should be writable !)
4 $cacheDir = 'cache';
5
6 // Embed.ly API key
7 // If null, the one set in JavaScript will be used
8 // If not null, this key will replace the one set in JavaScript
9 $key = 'EMBED.LY API KEY';
10
11 // Referer to restrict the call from
12 $referers = array(
13 '*.nyrodev.com/*'
14 );
15
16 // Embed.ly API URL (change only if you know what you're doing)
17 $urlApi = 'http://api.embed.ly/1/oembed';
18
19 // Replace callback used for caching. (change only if you know what you're doing)
20 $replaceClb = 'DUMMYCALLBACK';
21
22
23 //--------------------------------------------------------------//
24 // Do not edit under this line ---------------------------------//
25 //--------------------------------------------------------------//
26
27
28 // Referers checks Start
29 $continue = false;
30 $httpReferer = $_SERVER['HTTP_REFERER'];
31 if ($httpReferer) {
32 foreach($referers as $referer) {
33 $referer = '`^'.str_replace(
34 array('.', '*'),
35 array('\\.', '.*'),
36 $referer).'$`i';
37 $continue = $continue || !!preg_match($referer, $httpReferer);
38 }
39 }
40
41 if (!$continue) {
42 header('HTTP/1.0 401 Unauthorized');
43 echo 'Unauthorized';
44 exit;
45 }
46 // Referers checks End
47
48 $params = $_GET;
49
50 $clb = $params['callback'];
51 unset($params['callback']);
29ef228 @nyroDev Update embedlyProxy in order to remove additionnal random parameter s…
authored Sep 27, 2011
52 unset($params['_']);
b12752e @nyroDev Add embedlyUrl option for nmObject in embedLy filter
authored Sep 26, 2011
53
54 $fileCache = $cacheDir.DIRECTORY_SEPARATOR.md5(serialize($params)).'.json';
55 if (!file_exists($fileCache)) {
56 // File do not exists in cache, get it
57 $params['callback'] = $replaceClb;
58 if ($key)
59 $params['key'] = $key;
60 $url = $urlApi.'?'.http_build_query($params);
61 $content = file_get_contents($url);
62 file_put_contents($fileCache, $content);
63 } else {
64 $content = file_get_contents($fileCache);
65 }
66
67 // Send the json
68 header('Content-type: application/javascript');
69 echo str_replace($replaceClb, $clb, $content);
Something went wrong with that request. Please try again.