Remove depencies of library/common/curl : getUrl

This commit is contained in:
Michael RICOIS 2013-10-31 12:58:50 +00:00
parent fc18e6b97a
commit b04cce503e

View File

@ -1,14 +1,13 @@
<?php
require_once 'common/curl.php';
class BDF
{
protected $host = 'http://protectel.scrypto.fr';
protected $page = '/iBDF/RequeteLanceur.php';
protected $filetime = 8;
public function __construct(){}
// --------------------------------------------------------------------------- //
// enleveLiens
// --------------------------------------------------------------------------- //
@ -34,26 +33,29 @@ class BDF
$pos1 = $pos2;
}
}
return $contenu;
}
function bdf_loadpage($url)
{
$page = getUrl($url, '', '', '', false, '', '',15);
//Fichier non disponible
if($page['code']==408 || $page['code']==400){
try {
$client = new Zend_Http_Client($url);
$response = $client->request('GET');
if ( $response->isSuccessful() ) {
$output = $response->getBody();
} else {
$output = false;
}
} catch (Zend_Http_Client_Exception $e) {
$output = false;
//Ecriture du fichier sur le serveur en local
}else{
$body = $page['body'];
$output = $body;
}
$output = utf8_encode($output);
$output = preg_replace('/(.*)\<html/', '<html', $output);
$output = $this->bdf_removeblock($output);
$output = $this->removeTag('html', $output, true, false);
$output = $this->removeTag('head', $output, true, false);
@ -61,27 +63,27 @@ class BDF
$output = $this->removeTag('meta', $output, false, false);
$output = $this->removeTag('title', $output, true, true);
$output = $this->removeTag('script', $output, true, true);
//$output = changeLinkToLowerCase($output);
$output = $this->bdf_lien_siren($output);
$output = stripslashes($output);
return $output;
}
function bdf_removeblock($content)
{
$output = $content;
$output = $this->enleveLiens($output, '#nullepart');
$output = $this->enleveLiens($output, 'window.print');
$output = str_replace('/PROTECTEL/FIBEN20110207/',
$this->host.'/PROTECTEL/FIBEN20110207/', $output);
return $output;
}
function removeTag($balise, $content, $endOfTag = true, $removeContent = true)
{
if( $endOfTag )
@ -97,29 +99,29 @@ class BDF
}
return $output;
}
function changeLinkToLowerCase($content)
{
//$pattern = "/\< *[img][^\>]*[href] *= *[\"\']{0,1}([^\"\'\ >]*)/i";
$pattern = '/(\<img[^>].*?>)/ie';
$replace = "strtolower('\\1')";
$content = preg_replace($pattern,$replace,$content);
$pattern = '/(\<script[^>].*?>)/ie';
$replace = "strtolower('\\1')";
$content = preg_replace($pattern,$replace,$content);
$pattern = '/(\<link[^>].*?>)/ie';
$replace = "strtolower('\\1')";
$content = preg_replace($pattern,$replace,$content);
$pattern = '/(\<table[^>].*?>)/ie';
$replace = "strtolower('\\1')";
$content = preg_replace($pattern,$replace,$content);
return $content;
}
function bdf_lien_module($id, $service = 'fiben', $req = '', $rech = array() )
{
$func_module = 'bdf_modules_'.$service;
@ -131,7 +133,7 @@ class BDF
${$key} = $val;
}
}
//Paramètres URL
foreach($modules[$id]['params'] as $mparams => $fparams)
{
@ -144,7 +146,7 @@ class BDF
$func_params[] = ${$fparam};
}
}
$addParams = call_user_func_array(array($this,'bdf_param_'.$mparams), $func_params);
//Rassemblement de tout les paramètres
$params = array_merge($params, $addParams);
@ -158,51 +160,51 @@ class BDF
}
return $this->host.$this->page.'?'.$output;
}
function bdf_lien_siren($c)
{
$p = '/(width="160" class="clFond".*)([0-9]{3} [0-9]{3} [0-9]{3} [0-9]{5})/';
$r = '$1<a href="./?page=identite&siret=$2">$2</a>';
$c = preg_replace($p, $r, $c);
$p = '/(class="clGrasFond".*)([0-9]{3} [0-9]{3} [0-9]{3})/';
$r = '$1<a href="./?page=identite&siret=$2">$2</a>';
$c = preg_replace($p, $r, $c);
$p = '/(width="130" class="clFond".*)([0-9]{3} [0-9]{3} [0-9]{3})/';
$r = '$1<a href="./?page=identite&siret=$2">$2</a>';
$c = preg_replace($p, $r, $c);
$p = '/(class="clFond" width="80".*)([0-9]{3} [0-9]{3} [0-9]{3})/';
$r = '$1<a href="./?page=identite&siret=$2">$2</a>';
$c = preg_replace($p, $r, $c);
$p = '/(class="clTexte" width="184".*)([0-9]{3} [0-9]{3} [0-9]{3})/';
$r = '$1<a href="./?page=identite&siret=$2">$2</a>';
$c = preg_replace($p, $r, $c);
$p = '/(class="clFond" width="255".*)([0-9]{3} [0-9]{3} [0-9]{3})/';
$r = '$1<a href="./?page=identite&siret=$2">$2</a>';
$c = preg_replace($p, $r, $c);
$c = stripslashes($c);
return $c;
}
function bdf_lien_clebdf()
{
//Détection des clebdf
//Remplacement du lien
}
function bdf_lien_plusinfos()
{
}
function bdf_param_banque()
{
return array(
@ -210,7 +212,7 @@ class BDF
'Guichet' => '00001',
);
}
function bdf_param_utilisateur()
{
return array(
@ -218,73 +220,73 @@ class BDF
'MDP' => '', //$_SESSION['tabInfo']['password']
);
}
function bdf_param_profil()
{
return array(
'Profil' => 'Agence',
);
}
function bdf_param_service($service = 'FIBEN')
{
return array(
'Service' => strtoupper($service),
);
}
function bdf_param_req($req)
{
return array(
'Req' => $req,
);
}
function bdf_param_typeop($id)
{
return array(
'TypeOp' => $id,
);
}
function bdf_param_denom($denom)
{
return array(
'Denom' => $denom,
);
}
function bdf_param_type($type)
{
return array(
'Type' => $type,
);
}
function bdf_param_code($code)
{
return array(
'Code' => $code,
);
}
function bdf_param_rechet($rechet)
{
if(empty($rechet)) $output = 'N';
else $output = 'O';
return array(
'RechEt' => $output,
);
}
function bdf_param_ape($ape)
{
return array(
'APE' => $ape,
);
}
function bdf_modules_fiben()
{
return array(
@ -590,11 +592,11 @@ class BDF
),
'liste' => false,
),
);
}
function bdf_modules_fcc()
{
return array(
@ -621,9 +623,9 @@ class BDF
),
),
);
}
function bdf_modules_ficp()
{
return array(
@ -640,7 +642,7 @@ class BDF
),
);
}
function bdf_filetimeover($fichier)
{
$timeover = false;
@ -650,7 +652,7 @@ class BDF
if($now>$maxTime) $timeover = true;
return $timeover;
}
function displayModule($req, $module, $service, $listModules)
{
//Vérifier que le module existe
@ -663,16 +665,16 @@ class BDF
'rechet' => $rechet,
'ape' => $ape,
);
$url = $this->bdf_lien_module($module, $service, $req, $rech);
if($module=='07'){
$filename = false;
} else {
$c = Zend_Registry::get('config');
$filename = $c->profil->path->cache.'/bdf_'.$service.'_'.$req.'_'.$module.'.html';
}
//@todo : Ajouter timeover
$content = '';
if( $filename!==false && file_exists($filename) ) {
@ -688,5 +690,5 @@ class BDF
}
return false;
}
}