Remove depencies of library/common/curl : getUrl

This commit is contained in:
Michael RICOIS 2013-10-30 15:58:16 +00:00
parent a60698181f
commit ad2984ee91
5 changed files with 194 additions and 192 deletions

View File

@ -700,9 +700,6 @@ class EvaluationController extends Zend_Controller_Action
if(!$user->checkModeEdition() or !$user->checkPerm('SCORECSF')) if(!$user->checkModeEdition() or !$user->checkPerm('SCORECSF'))
$this->render('error/perms', null, 'error'); $this->render('error/perms', null, 'error');
require_once 'Evaluation/DomDocument2.lib.php';
require_once 'common/curl.php';
define('CREDITSAFE_WS_URL', 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx'); define('CREDITSAFE_WS_URL', 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx');
define('CREDITSAFE_WS_URI', 'https://www.creditsafe.fr/getdata/service/'); define('CREDITSAFE_WS_URI', 'https://www.creditsafe.fr/getdata/service/');
define('CREDITSAFE_WS_USER', 'scores_decisions'); define('CREDITSAFE_WS_USER', 'scores_decisions');
@ -730,14 +727,17 @@ class EvaluationController extends Zend_Controller_Action
'</body>'. '</body>'.
'</xmlrequest>'; '</xmlrequest>';
$success = true;
$date = date('Ymd'); $date = date('Ymd');
$url = 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx/GetData?RequestXmlStr='.$req; $url = 'https://www.creditsafe.fr/getdata/service/CSFRServices.asmx/GetData?RequestXmlStr='.$req;
$referer = $cookie = '';
$page = getUrl($url, $cookie, '', $referer, false, '', '');
$referer = $url;
$file = APPLICATION_PATH.'/../../data/creditsafe/'.$this->siret.'.xml'; $file = APPLICATION_PATH.'/../../data/creditsafe/'.$this->siret.'.xml';
$xml = html_entity_decode($page['body'], ENT_QUOTES, 'UTF-8');
try {
$client = new Zend_Http_Client($url);
$client->setStream();
$response = $client->request('GET');
if ( $response->isSuccessful() ) {
$xml = html_entity_decode($response->getBody(), ENT_QUOTES, 'UTF-8');
$dom_object = new DOMDocument(); $dom_object = new DOMDocument();
$ws = new WsScores(); $ws = new WsScores();
if(!file_exists($file)) { if(!file_exists($file)) {
@ -800,6 +800,8 @@ class EvaluationController extends Zend_Controller_Action
$this->view->strCreditlimit = $strCreditlimit; $this->view->strCreditlimit = $strCreditlimit;
} }
} catch (Zend_Http_Client_Exception $e) {}
}
/** /**
* Commande de scoring partenaire creditsafe * Commande de scoring partenaire creditsafe

View File

@ -208,7 +208,6 @@ class LogoController extends Zend_Controller_Action
if ($request->isPost()){ if ($request->isPost()){
require_once 'common/curl.php';
$logoUrl = $request->getParam('url'); $logoUrl = $request->getParam('url');
$tabTmp = parse_url($logoUrl); $tabTmp = parse_url($logoUrl);
$hostUrl = $tabTmp['host']; $hostUrl = $tabTmp['host'];
@ -216,20 +215,23 @@ class LogoController extends Zend_Controller_Action
$tmp = explode('.', basename($pathUrl)); $tmp = explode('.', basename($pathUrl));
$ext = strtolower(end($tmp)); $ext = strtolower(end($tmp));
$page = getUrl($logoUrl, '', '', '', false, $hostUrl, '', 7);
$body = $page['body'];
$extAuthorized = array('jpeg', 'jpg', 'png', 'gif', 'bmp'); $extAuthorized = array('jpeg', 'jpg', 'png', 'gif', 'bmp');
//Vérification fichier est une image //Vérification fichier est une image
if ( in_array($ext, $extAuthorized ) ) if ( in_array($ext, $extAuthorized ) )
{ {
$name_file = $siren.'.'.$ext; $name_file = $siren.'.'.$ext;
$fp = fopen($this->pathLogo.'/'.$name_file, 'w');
fwrite($fp, $body); try {
fclose($fp); $client = new Zend_Http_Client($logoUrl);
$client->setStream();
$response = $client->request('GET');
if ( $response->isSuccessful()
&& copy($response->getStreamName(), $this->pathLogo.'/'.$name_file) ) {
$this->view->assign('image', $name_file); $this->view->assign('image', $name_file);
} }
} catch (Zend_Http_Client_Exception $e) {}
}
$this->view->assign('isPost', true); $this->view->assign('isPost', true);
} }
$this->view->assign('siren', $siren); $this->view->assign('siren', $siren);
@ -307,7 +309,7 @@ class LogoController extends Zend_Controller_Action
} }
} }
} else { } else {
saisie_getlogo($siren); $this->_getlogo($siren);
} }
} }
return $message; return $message;
@ -418,26 +420,28 @@ class LogoController extends Zend_Controller_Action
function _getlogo( $siren ) function _getlogo( $siren )
{ {
require_once 'common/curl.php';
$logoUrl = $_REQUEST['logoUrl']['url']; $logoUrl = $_REQUEST['logoUrl']['url'];
$tabTmp = parse_url($logoUrl);
$hostUrl = $tabTmp['host'];
$pathUrl = $tabTmp['path'];
$tmp = explode('.', basename($pathUrl));
$ext = strtolower(end($tmp));
$page = getUrl($logoUrl, '', '', '', false, $hostUrl, '', 7);
$body = $page['body'];
$extAuthorized = array('jpeg', 'jpg', 'png', 'gif', 'bmp'); $extAuthorized = array('jpeg', 'jpg', 'png', 'gif', 'bmp');
try {
$client = new Zend_Http_Client($pathUrl);
$client->setStream();
$response = $client->request('GET');
if ( $response->isSuccessful() ) {
$tmp = explode('.', basename($response->getStreamName()));
$ext = strtolower(end($tmp));
if ( !in_array($ext, $extAuthorized ) ) if ( !in_array($ext, $extAuthorized ) )
{ {
$tmp = explode('/', $page['header']['Content-Type']); $tmp = explode('/', $page['header']['Content-Type']);
$ext = trim ( str_replace('?', '',strtolower(end($tmp)) ) ); $ext = trim ( str_replace('?', '',strtolower(end($tmp)) ) );
} }
$name_file = $siren.'.'.$ext; $name_file = $siren.'.'.$ext;
$fp = @fopen($this->pathLogo.'/'.$name_file, 'w'); if( copy($response->getStreamName(), $this->pathLogo.'/'.$name_file) ) {
@fwrite($fp, $body);
@fclose($fp);
chmod($this->pathLogo.'/'.$name_file, 0755); chmod($this->pathLogo.'/'.$name_file, 0755);
} }
}
} catch (Zend_Http_Client_Exception $e) {}
}
} }

View File

@ -24,8 +24,6 @@ class TelechargementController extends Zend_Controller_Action
{ {
if (!is_dir($this->path)) mkdir($this->path); if (!is_dir($this->path)) mkdir($this->path);
require_once 'common/curl.php';
// Recuperation du nom du fichier // Recuperation du nom du fichier
if ($filename===null) { if ($filename===null) {
$tableau = explode('/', $url); $tableau = explode('/', $url);
@ -48,29 +46,23 @@ class TelechargementController extends Zend_Controller_Action
} }
// Recuperation du fichier sur le serveur // Recuperation du fichier sur le serveur
if (!file_exists($this->path.'/'.$file)) { if (file_exists($this->path.'/'.$file)) {
// On check si le fichier est present sur l'url
Zend_Registry::get('firebug')->info('URL : '.$url);
$url_tab = getUrl($url, '', '', '', false);
if ($url_tab['code'] == 408 ||
$url_tab['code'] == 400 ||
$url_tab['code'] == 404) {
// Fichier non disponible
Zend_Registry::get('firebug')->info('Fichier non disponible !');
return false;
} else {
// Ecriture du fichier sur le serveur en local
$body = $url_tab['body'];
Zend_Registry::get('firebug')->info('Taille fichier '.strlen($body));
if ( strlen($body) ) {
$fp = fopen($this->path.'/'.$file, 'w');
fwrite($fp, $body);
fclose($fp);
Zend_Registry::get('firebug')->info('Ecriture fichier : '.$this->path.'/'.$file);
}
}
}
return $file; return $file;
} else {
// On check si le fichier est present sur l'url
try {
$client = new Zend_Http_Client($url);
$client->setStream();
$response = $client->request('GET');
if ( $response->isSuccessful() && copy($response->getStreamName(), $this->path.'/'.$file) ) {
return $file;
} else {
return false;
}
} catch (Zend_Http_Client_Exception $e) {
return false;
}
}
} }
public function init() public function init()

View File

@ -156,14 +156,15 @@ class Scores_Google_Streetview
*/ */
public function getImg() public function getImg()
{ {
require_once 'common/curl.php';
$page = getUrl($this->url, '', '', '', false);
Zend_Registry::get('firebug')->info('URL = '.$this->url); Zend_Registry::get('firebug')->info('URL = '.$this->url);
if ( !in_array($page['code'], array(400, 408, 403)) ) { try {
$body = $page['body']; $client = new Zend_Http_Client($url);
file_put_contents($this->pathImg(), $body); $client->setStream();
$response = $client->request('GET');
if ( $response->isSuccessful() ) {
copy($response->getStreamName(), $this->pathImg());
} }
} catch (Zend_Http_Client_Exception $e) {}
} }
/** /**

View File

@ -38,27 +38,30 @@ class Logo
public function getFromUrl($siteWeb) public function getFromUrl($siteWeb)
{ {
$img = false; $img = false;
require_once 'common/curl.php';
if (substr($siteWeb,-1)!='/') $siteWeb.='/'; if (substr($siteWeb,-1)!='/') $siteWeb.='/';
$arrUrl = parse_url($siteWeb); try {
$page = getUrl($siteWeb, '', '', '', false, $arrUrl['host'], '', 3); $client = new Zend_Http_Client($url);
$body = $page['body']; $response = $client->request('GET');
if (preg_match('/<img(?:.*)src=(?:"|\')((?:.*)logo(?:.*)(?:gif|png|jpg|jpeg))/Ui', $body, $matches)) { $siteBody = $response->getBody();
} catch (Zend_Http_Client_Exception $e) {
}
if (preg_match('/<img(?:.*)src=(?:"|\')((?:.*)logo(?:.*)(?:gif|png|jpg|jpeg))/Ui', $siteBody, $matches)) {
$logo = trim(strtr($matches[1],'"\'',' ')); $logo = trim(strtr($matches[1],'"\'',' '));
$urlLogo = $siteWeb.$logo; $urlLogo = $siteWeb.$logo;
$tmp = explode('.', basename($logo)); $tmp = explode('.', basename($logo));
$ext = end($tmp); $ext = end($tmp);
$page = getUrl($urlLogo, '', '', $siteWeb, false, $arrUrl['host']); try {
if($page['code']!=400) $client = new Zend_Http_Client($url);
{ $client->setStream();
$body = $page['body']; $response = $client->request('GET');
if ( $response->isSuccessful() ) {
$img = $this->path.'/'.$this->siren.'.'.$ext; $img = $this->path.'/'.$this->siren.'.'.$ext;
$fp = fopen($img, 'a'); copy($response->getStreamName(), $img);
fwrite($fp, $body);
fclose($fp);
chmod($img, 0755); chmod($img, 0755);
} }
} catch (Zend_Http_Client_Exception $e) {}
} }
return $img; return $img;
} }