Permalink
Browse files

Add embedlyUrl option for nmObject in embedLy filter

Add embedlyProxy.php file to set an exemple how to cache embedly responses
  • Loading branch information...
nyroDev committed Sep 26, 2011
1 parent 9c52b40 commit b12752ee7dcdb1836c2e497567f5ee52fbf0a7ae
Showing with 70 additions and 1 deletion.
  1. +68 −0 embedlyProxy.php
  2. +2 −1 js/jquery.nyroModal.filters.embedly.js
View
@@ -0,0 +1,68 @@
<?php
// Directory to cache the results (should be writable !)
$cacheDir = 'cache';
// Embed.ly API key
// If null, the one set in JavaScript will be used
// If not null, this key will replace the one set in JavaScript
$key = 'EMBED.LY API KEY';
// Referer to restrict the call from
$referers = array(
'*.nyrodev.com/*'
);
// Embed.ly API URL (change only if you know what you're doing)
$urlApi = 'http://api.embed.ly/1/oembed';
// Replace callback used for caching. (change only if you know what you're doing)
$replaceClb = 'DUMMYCALLBACK';
//--------------------------------------------------------------//
// Do not edit under this line ---------------------------------//
//--------------------------------------------------------------//
// Referers checks Start
$continue = false;
$httpReferer = $_SERVER['HTTP_REFERER'];
if ($httpReferer) {
foreach($referers as $referer) {
$referer = '`^'.str_replace(
array('.', '*'),
array('\\.', '.*'),
$referer).'$`i';
$continue = $continue || !!preg_match($referer, $httpReferer);
}
}
if (!$continue) {
header('HTTP/1.0 401 Unauthorized');
echo 'Unauthorized';
exit;
}
// Referers checks End
$params = $_GET;
$clb = $params['callback'];
unset($params['callback']);
$fileCache = $cacheDir.DIRECTORY_SEPARATOR.md5(serialize($params)).'.json';
if (!file_exists($fileCache)) {
// File do not exists in cache, get it
$params['callback'] = $replaceClb;
if ($key)
$params['key'] = $key;
$url = $urlApi.'?'.http_build_query($params);
$content = file_get_contents($url);
file_put_contents($fileCache, $content);
} else {
$content = file_get_contents($fileCache);
}
// Send the json
header('Content-type: application/javascript');
echo str_replace($replaceClb, $clb, $content);
@@ -10,6 +10,7 @@
*/
jQuery(function($, undefined) {
$.nmObj({
embedlyUrl: 'http://api.embed.ly/1/oembed',
embedly: {
key: undefined,
wmode: 'transparent',
@@ -42,7 +43,7 @@ jQuery(function($, undefined) {
var data = nm.embedly;
data.url = nm.opener.attr('href');
$.ajax({
url: 'http://api.embed.ly/1/oembed',
url: nm.embedlyUrl,
dataType: 'jsonp',
data: data,
success: function(data) {

0 comments on commit b12752e

Please sign in to comment.