true,
'exceptions'=>false,
'trace'=>true
);
function object2array($object, $indice)
{
if (is_object($object)) {
foreach ($object as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $object;
}
return $array[$indice];
}
function initXvfb()
{
echo "Xvfb start...
";
exec('ps -edf | grep Xvfb',$ret);
if (sizeof($ret) < 3 )
{
exec('Xvfb :1 -screen 0 1280x960x24 2> /dev/null &');
sleep(5);
}
}
function closeXvfb()
{
echo "Xvfb stop...
";
exec('killall -9 Xvfb 2> /dev/null');
}
function getUrlsIdsFromOriIndexing($soap, $namespace, $debutIDFiche = 1)
{
$fiches = array();
//caracteres a probleme pour les url
$interdit = array(' ', '(', ')');
$autorise = array('%20', '%28', '%29');
//recuperation des fiches
$fiches = $soap->searchXMLDocs(array( 'in0' => 'md-ori-oai-namespace:("'.$namespace.'")',
'in1' => $debutIDFiche,
'in2' => $debutIDFiche+100 ));
// s'il y a des fiches
if ( $fiches )
{
$fiches = object2array($fiches, 'out');
$fiches = object2array($fiches, 'results');
$fiches = object2array($fiches, 'SearchResult');
foreach( $fiches as $key => $value )
{
//recuperation de l'id pour nommer l'image
$ret[$key]['id'] = object2array($value, 'id');
$value = object2array($value, 'noticeContent');
$value = object2array($value, 'entry');
$value = object2array($value, 'value');
//critere de recherche en fonction des fiches
#LOM
if ( $namespace == 'http@//ltsc.ieee.org/xsd/LOM')
{
$debutUrl = stripos($value,"") + 14;
$finUrl = stripos($value,"");
//recuperation de l'url
$ret[$key]['url'] = substr($value,$debutUrl,$finUrl-$debutUrl);
//suppression des caracteres a probleme
$ret[$key]['url'] = str_replace($interdit, $autorise, $ret[$key]['url']);
}
#TEF
elseif ( $namespace == 'http@//www.abes.fr/abes/documents/tef')
{
$debutUrl = stripos($value,'') + 38;
$value = substr($value, $debutUrl);
$finUrl = stripos($value,"");
//recuperation de l'url
$ret[$key]['url'] = substr($value,0,$finUrl);
//suppression des caracteres a probleme
$ret[$key]['url'] = str_replace($interdit, $autorise, $ret[$key]['url']);
}
else
{
echo "Le format demande n'est pas defini
";
break;
}
}
return $ret;
}
else
return false;
}
function launchFirefox($url)
{
echo "Launch Iceweasel URL : ".$url."
";
exec('ps -edf | grep iceweasel',$ret);
if (sizeof($ret) < 3 )
{
exec('DISPLAY=:1 iceweasel '. $url .' > /dev/null &');
sleep(5);
}
}
function closeFirefox()
{
echo "Close Iceweasel...
";
exec('killall -9 iceweasel > /dev/null');
exec('pkill iceweasel > /dev/null');
//exec('rm /root/.mozilla/firefox/ -rf');
}
function shot($repDepot, $id, $url)
{
$valid = true;
//ouverture de l'url
$handle = fopen($url,'r');
//reponse du header
$httpHeader = get_headers($url,1);
// test si la ressource est OK
if ( substr($httpHeader[0],-2) == 'OK')
{
//ressource HTML
if ( substr($httpHeader['Content-Type'],0,9) == 'text/html' || substr($httpHeader['Content-Type'],0,8) == 'text/htm' )
{
initXvfb();
//lancement de firefox + screenshot + ferme firefox
launchFirefox($url);
//prend le screenshot
exec("DISPLAY=:1 import -window root -crop 978x730+0+120 /tmp/" . $id . ".png &");
closeFirefox();
closeXvfb();
}
//ressource PDF
elseif ( $httpHeader['Content-Type'] == 'application/pdf' )
{
exec("wget -q -O /tmp/oriPDF.pdf ".$url);
exec("gs -dNOPAUSE -sDEVICE=png256 -q -dBATCH -sOutputFile=/tmp/" . $id .".png /tmp/oriPDF.pdf");
exec("rm /tmp/oriPDF.pdf -rf");
}
//ressource IMG
elseif ( substr($httpHeader['Content-Type'],0,5) == 'image' )
{
/* exec("wget -O ". $repDepot ."oriIMG.png ".$url);
exec("mv ". $repDepot ."oriIMG.png " .$repDepot . $id .".png");
*/
$img = file_get_contents ($url);
// Ecriture du résultat dans le fichier
$fp = fopen ('/tmp/'. $id . '.png', 'wb');
fwrite($fp, $img);
fclose($fp);
}
//ressource indeterminée
else
{
echo "Impossible de déterminer le type ressource pour '.$id.'
";
$valid = false;
}
//pause pour laisser le temps d'ecriture sur le disque
sleep(1);
}
//test si SSOCAS
elseif ( substr($httpHeader['Set-Cookie'][1],0,3) == 'sso' )
{
echo 'La ressource ".$id." demande SSO-CAS
';
$valid = false;
}
else
{
echo 'La ressource ".$id." n est pas OK dans les headers
'; $valid = false;
}
return $valid;
}
function thumb150($repDepot, $id)
{
echo 'Genere thumb 150 ...
';
exec("cp /tmp/". $id .".png ". $repDepot. "thumb150-". $id .".png");
exec("mogrify -thumbnail 150 ". $repDepot. "thumb150-". $id .".png");
}
function thumb300($repDepot, $id)
{
echo 'Genere thumb 300 ...
';
exec("cp /tmp/". $id .".png ". $repDepot. "thumb300-". $id .".png");
exec("mogrify -thumbnail 300 ". $repDepot. "thumb300-". $id .".png");
}
//connexion au webservice
$soap = new SoapClient($wsdl, $options);
#######################################
# LOM
#######################################
$ficheID = 1;
// recuperation de l'id et de l'URL pour les fiches LOM
while ( $fiches = getUrlsIdsFromOriIndexing($soap, 'http@//ltsc.ieee.org/xsd/LOM', $ficheID) )
{
//recuperation de l'image
foreach ( $fiches as $key => $value )
{
echo '##############################
';
echo "#Ressource ".$value['id']."
##############################
";
//faut il faire un screenshot en 150 et 300 ?
if ( $thumb150 && $thumb300 )
{
if ( !file_exists($repDepot ."thumb150-".$value['id'] . ".png") && !file_exists($repDepot ."thumb300-".$value['id'] . ".png") )
{
//screenshot de la ressource
$valid = shot($repDepot, $value['id'],$value['url']);
if ( $valid )
{
//redimmensionne le screenshot en vignette
thumb150($repDepot, $value['id']);
thumb300($repDepot, $value['id']);
//suppression du screenshot
exec("rm /tmp/". $value['id'] .".png -f");
}
}
else
{
echo 'thumb150 et 300 Deja traite...
';
}
}
//faut il faire un screenshot en 150 ?
if ( $thumb150 )
{
if ( !file_exists($repDepot ."thumb150-".$value['id'] . ".png") )
{
//screenshot de la ressource
$valid = shot($repDepot, $value['id'],$value['url']);
if ( $valid )
{
//redimmensionne le screenshot en vignette 150
thumb150($repDepot, $value['id']);
//suppression du screenshot
exec("rm /tmp/". $value['id'] .".png -f");
}
}
else
{
echo 'thumb150 Deja traite...
';
}
}
//faut il faire un screenshot en 300 ?
if ( $thumb300 )
{
if ( !file_exists($repDepot ."thumb300-".$value['id'] . ".png") )
{
//screenshot de la ressource
$valid = shot($repDepot, $value['id'],$value['url']);
if ( $valid )
{
//redimmensionne le screenshot en vignette 300
thumb300($repDepot, $value['id']);
//suppression du screenshot
exec("rm /tmp/". $value['id'] .".png -f");
}
}
else
{
echo 'thumb300 Deja traite...
';
}
}
}
$ficheID = $ficheID + 100;
}
#######################################
# TEF
#######################################
$ficheID = 1;
// recuperation de l'id et de l'URL pour les fiches TEF
while ( $fiches = getUrlsIdsFromOriIndexing($soap, 'http@//www.abes.fr/abes/documents/tef', $ficheID) )
{
//recuperation de l'image
foreach ( $fiches as $key => $value )
{
echo '##############################
';
echo "#Ressource ".$value['id']."
##############################
";
//faut il faire un screenshot en 150 et 300 ?
if ( $thumb150 && $thumb300 )
{
if ( !file_exists($repDepot ."thumb150-".$value['id'] . ".png") && !file_exists($repDepot ."thumb300-".$value['id'] . ".png") )
{
//screenshot de la ressource
$valid = shot($repDepot, $value['id'],$value['url']);
if ( $valid )
{
//redimmensionne le screenshot en vignette
thumb150($repDepot, $value['id']);
thumb300($repDepot, $value['id']);
//suppression du screenshot
exec("rm /tmp/". $value['id'] .".png -f");
}
}
else
{
echo 'Deja traite...
';
}
}
//faut il faire un screenshot en 150 ?
if ( $thumb150 )
{
if ( !file_exists($repDepot ."thumb150-".$value['id'] . ".png") )
{
//screenshot de la ressource
$valid = shot($repDepot, $value['id'],$value['url']);
if ( $valid )
{
//redimmensionne le screenshot en vignette 150
thumb150($repDepot, $value['id']);
//suppression du screenshot
exec("rm /tmp/". $value['id'] .".png -f");
}
}
else
{
echo 'Deja traite...
';
}
}
//faut il faire un screenshot en 300 ?
if ( $thumb300 )
{
if ( !file_exists($repDepot ."thumb300-".$value['id'] . ".png") )
{
//screenshot de la ressource
$valid = shot($repDepot, $value['id'],$value['url']);
if ( $valid )
{
//redimmensionne le screenshot en vignette 300
thumb300($repDepot, $value['id']);
//suppression du screenshot
exec("rm /tmp/". $value['id'] .".png -f");
}
}
else
{
echo 'Deja traite...
';
}
}
}
$ficheID = $ficheID + 100;
}
?>