Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters