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 ' ]);
52+
53+ $ fileCache = $ cacheDir .DIRECTORY_SEPARATOR .md5 (serialize ($ params )).'.json ' ;
54+ if (!file_exists ($ fileCache )) {
55+ // File do not exists in cache, get it
56+ $ params ['callback ' ] = $ replaceClb ;
57+ if ($ key )
58+ $ params ['key ' ] = $ key ;
59+ $ url = $ urlApi .'? ' .http_build_query ($ params );
60+ $ content = file_get_contents ($ url );
61+ file_put_contents ($ fileCache , $ content );
62+ } else {
63+ $ content = file_get_contents ($ fileCache );
64+ }
65+
66+ // Send the json
67+ header ('Content-type: application/javascript ' );
68+ echo str_replace ($ replaceClb , $ clb , $ content );
0 commit comments