Skip to content

Commit b12752e

Browse files
committed
Add embedlyUrl option for nmObject in embedLy filter
Add embedlyProxy.php file to set an exemple how to cache embedly responses
1 parent 9c52b40 commit b12752e

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

Diff for: embedlyProxy.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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);

Diff for: js/jquery.nyroModal.filters.embedly.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
jQuery(function($, undefined) {
1212
$.nmObj({
13+
embedlyUrl: 'http://api.embed.ly/1/oembed',
1314
embedly: {
1415
key: undefined,
1516
wmode: 'transparent',
@@ -42,7 +43,7 @@ jQuery(function($, undefined) {
4243
var data = nm.embedly;
4344
data.url = nm.opener.attr('href');
4445
$.ajax({
45-
url: 'http://api.embed.ly/1/oembed',
46+
url: nm.embedlyUrl,
4647
dataType: 'jsonp',
4748
data: data,
4849
success: function(data) {

0 commit comments

Comments
 (0)