2011-04-29 07:48:31 +00:00
|
|
|
<?php
|
|
|
|
class Logo
|
|
|
|
{
|
|
|
|
protected $path = '';
|
|
|
|
protected $siren;
|
|
|
|
protected $isin = null;
|
|
|
|
protected $logoNom = '';
|
|
|
|
protected $logoSize = '';
|
2013-11-05 14:45:25 +00:00
|
|
|
|
2011-04-29 07:48:31 +00:00
|
|
|
public function __construct($siren, $isin = null)
|
|
|
|
{
|
2012-11-05 15:33:01 +00:00
|
|
|
$c = Zend_Registry::get('config');
|
2012-11-16 14:12:03 +00:00
|
|
|
$this->path = realpath($c->profil->path->data).'/logos';
|
2011-04-29 07:48:31 +00:00
|
|
|
$this->siren = $siren;
|
|
|
|
$this->isin = $isin;
|
|
|
|
}
|
2013-11-05 14:45:25 +00:00
|
|
|
|
2011-04-29 07:48:31 +00:00
|
|
|
public function affiche()
|
|
|
|
{
|
|
|
|
// Ne pas afficher le logo si il n'existe pas OU
|
|
|
|
// si le siren est à 0 OU si le siren est inférieur a 100
|
|
|
|
$logo = $this->exist($this->siren, $this->isin);
|
2011-05-10 08:35:50 +00:00
|
|
|
if ( $logo && (intval($this->siren)!=0 || intval($this->siren)>100) )
|
|
|
|
{
|
2011-04-29 07:48:31 +00:00
|
|
|
$tabTmp = @getimagesize($this->path.'/'.$logo);
|
|
|
|
$w = $tabTmp[0];
|
|
|
|
$h = $tabTmp[1];
|
|
|
|
if ($w > 350) {
|
2011-12-12 13:06:34 +00:00
|
|
|
$strSize = $this->redimage($this->path.'/'.$logo, 350, 150);
|
2011-04-29 07:48:31 +00:00
|
|
|
} else {
|
|
|
|
$strSize = '';
|
|
|
|
}
|
2011-05-10 08:35:50 +00:00
|
|
|
return '<img src="/fichier/logo/'.$logo.'" '.$strSize.'/>';
|
2011-04-29 07:48:31 +00:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2013-11-05 14:45:25 +00:00
|
|
|
|
2011-04-29 07:48:31 +00:00
|
|
|
public function getFromUrl($siteWeb)
|
|
|
|
{
|
|
|
|
$img = false;
|
|
|
|
if (substr($siteWeb,-1)!='/') $siteWeb.='/';
|
2013-11-05 14:45:25 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$client = new Zend_Http_Client($url);
|
|
|
|
$response = $client->request('GET');
|
|
|
|
$siteBody = $response->getBody();
|
|
|
|
} catch (Zend_Http_Client_Exception $e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('/<img(?:.*)src=(?:"|\')((?:.*)logo(?:.*)(?:gif|png|jpg|jpeg))/Ui', $siteBody, $matches)) {
|
2011-04-29 07:48:31 +00:00
|
|
|
$logo = trim(strtr($matches[1],'"\'',' '));
|
|
|
|
$urlLogo = $siteWeb.$logo;
|
|
|
|
$tmp = explode('.', basename($logo));
|
|
|
|
$ext = end($tmp);
|
2013-11-05 14:45:25 +00:00
|
|
|
try {
|
|
|
|
$client = new Zend_Http_Client($url);
|
|
|
|
$client->setStream();
|
|
|
|
$response = $client->request('GET');
|
|
|
|
if ( $response->isSuccessful() ) {
|
|
|
|
$img = $this->path.'/'.$this->siren.'.'.$ext;
|
|
|
|
copy($response->getStreamName(), $img);
|
|
|
|
chmod($img, 0755);
|
|
|
|
}
|
|
|
|
} catch (Zend_Http_Client_Exception $e) {}
|
2011-04-29 07:48:31 +00:00
|
|
|
}
|
|
|
|
return $img;
|
|
|
|
}
|
2013-11-05 14:45:25 +00:00
|
|
|
|
2011-04-29 07:48:31 +00:00
|
|
|
public function exist()
|
|
|
|
{
|
|
|
|
$img_ext = array('gif', 'png', 'jpg', 'jpeg');
|
|
|
|
$ext = '';
|
|
|
|
// Recherche le logo avec le siren
|
|
|
|
$locImg = $this->path.'/'.$this->siren;
|
|
|
|
foreach($img_ext as $extension){
|
|
|
|
if( file_exists($locImg.'.'.$extension) ) {
|
2011-05-10 08:35:50 +00:00
|
|
|
return $this->siren.'.'.$extension;
|
2011-04-29 07:48:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Recherche de logos avec le code isin
|
|
|
|
if(!empty($this->isin))
|
|
|
|
{
|
|
|
|
$locImg = $this->path.'/'.$this->isin;
|
|
|
|
foreach($img_ext as $extension) {
|
|
|
|
if( file_exists($locImg.'.'.$extension) ) {
|
2011-05-10 08:35:50 +00:00
|
|
|
return $this->isin.'.'.$extension;
|
2011-04-29 07:48:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-05 14:45:25 +00:00
|
|
|
|
|
|
|
|
2011-12-12 13:06:34 +00:00
|
|
|
function redimage($img_src,$dst_w,$dst_h) {
|
|
|
|
// Lit les dimensions de l'image
|
|
|
|
$size = getimagesize($img_src);
|
|
|
|
$src_w = $size[0]; $src_h = $size[1];
|
|
|
|
// Teste les dimensions tenant dans la zone
|
|
|
|
$test_h = round(($dst_w / $src_w) * $src_h);
|
|
|
|
$test_w = round(($dst_h / $src_h) * $src_w);
|
|
|
|
// Si Height final non précisé (0)
|
|
|
|
if(!$dst_h) $dst_h = $test_h;
|
|
|
|
// Sinon si Width final non précisé (0)
|
|
|
|
elseif(!$dst_w) $dst_w = $test_w;
|
|
|
|
// Sinon teste quel redimensionnement tient dans la zone
|
|
|
|
elseif($test_h>$dst_h) $dst_w = $test_w;
|
|
|
|
else $dst_h = $test_h;
|
2013-11-05 14:45:25 +00:00
|
|
|
|
2011-12-12 13:06:34 +00:00
|
|
|
// Affiche les dimensions optimales
|
|
|
|
return "width=".$dst_w." height=".$dst_h;
|
|
|
|
}
|
2013-11-05 14:45:25 +00:00
|
|
|
|
2011-04-29 07:48:31 +00:00
|
|
|
}
|