Check http request on server side + remove image source in html pages

This commit is contained in:
2015-08-29 16:18:22 +02:00
parent 3e69ae7199
commit 304c31d870
3 changed files with 21 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
<?php <?php
function getPage($sPath, $asVars) require_once 'settings.php';
function getPage($sPath, $asVars, $sType)
{ {
$bSavePage = Settings::DEBUG; $bSavePage = Settings::DEBUG;
if($bSavePage) if($bSavePage)
@@ -11,17 +13,30 @@ function getPage($sPath, $asVars)
} }
if(!$bSavePage || !file_exists($sFileName) || date('dmY', filemtime($sFileName))!=date('dmY')) if(!$bSavePage || !file_exists($sFileName) || date('dmY', filemtime($sFileName))!=date('dmY'))
{ {
$sPath = 'http://www.ugc.fr/'.$sPath.'?'.http_build_query($asVars); $sUrl = 'http://www.ugc.fr/'.$sPath.'?'.http_build_query($asVars);
$oCurl = curl_init(); $oCurl = curl_init();
curl_setopt($oCurl, CURLOPT_URL, $sPath); curl_setopt($oCurl, CURLOPT_URL, $sUrl);
curl_setopt($oCurl, CURLOPT_HEADER, false); curl_setopt($oCurl, CURLOPT_HEADER, false);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$sContent = curl_exec($oCurl); $sContent = curl_exec($oCurl);
curl_close($oCurl); curl_close($oCurl);
//Detect failed http request
if(strpos(str_replace(array("\r", "\n"), '', $sContent), '<title>Service Temporarily Unavailable</title>')) return getPage($sPath, $asVars, $sType);
if($bSavePage) file_put_contents($sFileName, $sContent); if($bSavePage) file_put_contents($sFileName, $sContent);
} }
return $bSavePage?file_get_contents($sFileName):$sContent; else $sContent = file_get_contents($sFileName);
//Remove scripting & image source (avoid http request)
if($sType=='html')
{
$sContent = preg_replace('/<script(.*)<\/script>/sU', '', $sContent);
$sContent = preg_replace('/<img src="(.*)"(.*)\/>/sU', '<img source="$1"$2/>', $sContent);
}
return $sContent;
} }
function setPageMime($sType='html') function setPageMime($sType='html')

View File

@@ -1,6 +1,5 @@
<?php <?php
require_once 'inc/settings.php';
require_once 'inc/functions.php'; require_once 'inc/functions.php';
$sAction = isset($_REQUEST['a'])?$_REQUEST['a']:''; $sAction = isset($_REQUEST['a'])?$_REQUEST['a']:'';
@@ -10,7 +9,7 @@ $sType = isset($_REQUEST['type'])?$_REQUEST['type']:'html';
switch($sAction) switch($sAction)
{ {
case 'get_page': case 'get_page':
$sResult = getPage($asData['path'], $asData['vars']); $sResult = getPage($asData['path'], $asData['vars'], $sType);
break; break;
case 'get_poster': case 'get_poster':
$sResult = getTrimImage($asData['id'], $asData['size'], $asData['url'], $sType); $sResult = getTrimImage($asData['id'], $asData['size'], $asData['url'], $sType);

View File

@@ -269,7 +269,7 @@ function Ugc()
oFilm.name($Film.find('.FilmTitle').text()); oFilm.name($Film.find('.FilmTitle').text());
//Poster //Poster
var sPosterUrl = $Film.find('.FilmThumbnail img').attr('src'); var sPosterUrl = $Film.find('.FilmThumbnail img').attr('source');
oFilm.poster(sPosterUrl); oFilm.poster(sPosterUrl);
oFilm.backgroundPoster(sPosterUrl.replace('152x217/FFFFFF', '274x410/EEEEE8')); oFilm.backgroundPoster(sPosterUrl.replace('152x217/FFFFFF', '274x410/EEEEE8'));