93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
<?php
|
|
class Logo
|
|
{
|
|
protected $path = '';
|
|
protected $siren;
|
|
protected $isin = null;
|
|
protected $logoNom = '';
|
|
protected $logoSize = '';
|
|
|
|
public function __construct($siren, $isin = null)
|
|
{
|
|
$config = new Zend_Config_Ini(APPLICATION_PATH .
|
|
'/configs/configuration.ini', 'path');
|
|
$this->path = realpath($config->data).'/'.$config->logos;
|
|
$this->siren = $siren;
|
|
$this->isin = $isin;
|
|
}
|
|
|
|
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);
|
|
if ( $logo && (intval($this->siren)!=0 || intval($this->siren)>100) )
|
|
{
|
|
$tabTmp = @getimagesize($this->path.'/'.$logo);
|
|
$w = $tabTmp[0];
|
|
$h = $tabTmp[1];
|
|
if ($w > 350) {
|
|
$strSize = @redimage($this->path.'/'.$logo, 350, 150);
|
|
} else {
|
|
$strSize = '';
|
|
}
|
|
return '<img src="/fichier/logo/'.$logo.'" '.$strSize.'/>';
|
|
}
|
|
return '';
|
|
}
|
|
|
|
public function getFromUrl($siteWeb)
|
|
{
|
|
$img = false;
|
|
require_once 'common/curl.php';
|
|
if (substr($siteWeb,-1)!='/') $siteWeb.='/';
|
|
|
|
$arrUrl = parse_url($siteWeb);
|
|
$page = getUrl($siteWeb, '', '', '', false, $arrUrl['host'], '', 3);
|
|
$body = $page['body'];
|
|
if (preg_match('/<img(?:.*)src=(?:"|\')((?:.*)logo(?:.*)(?:gif|png|jpg|jpeg))/Ui', $body, $matches)) {
|
|
$logo = trim(strtr($matches[1],'"\'',' '));
|
|
$urlLogo = $siteWeb.$logo;
|
|
$tmp = explode('.', basename($logo));
|
|
$ext = end($tmp);
|
|
$page = getUrl($urlLogo, '', '', $siteWeb, false, $arrUrl['host']);
|
|
if($page['code']!=400)
|
|
{
|
|
$body = $page['body'];
|
|
$img = $this->path.'/'.$this->siren.'.'.$ext;
|
|
$fp = fopen($img, 'a');
|
|
fwrite($fp, $body);
|
|
fclose($fp);
|
|
chmod($img, 0755);
|
|
}
|
|
}
|
|
return $img;
|
|
}
|
|
|
|
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) ) {
|
|
return $this->siren.'.'.$extension;
|
|
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) ) {
|
|
return $this->isin.'.'.$extension;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} |