function cache_thumb($id_site) { global $core; $theme=recup_donnee(SITES, "id_site", $id_site, "theme"); if(file_exists($path."cache/".$theme.".cache")) { if(time() - filemtime($path."cache/".$theme.".cache") >= $core->config['cache_max']) { $dirs = array_diff(scandir("media/themes/".$theme."/" ), Array( ".", ".." ) ); sort($dirs); @unlink($path."cache/".$theme.".cache"); $fp = fopen($path."cache/".$theme.".cache", 'x+'); if (flock($fp, LOCK_EX)) { // pose un verrou exclusif fwrite($fp,serialize($dirs)); flock($fp, LOCK_UN); fclose($fp); } else { echo $query." Ecriture du cache";return FALSE;} } else { $lines=file($path."cache/".$theme.".cache"); foreach ($lines as $line_num => $line) {$dirs=unserialize($line);} } } else { if(!is_dir("media/themes/".$theme)) {mkdir("media/themes/".$theme);} $dirs = array_diff(scandir("media/themes/".$theme."/" ), Array( ".", ".." ) ); sort($dirs); @unlink($path."cache/".$theme.".cache"); $fp = fopen($path."cache/".$theme.".cache", 'x+'); if (flock($fp, LOCK_EX)) { // pose un verrou exclusif fwrite($fp,serialize($dirs)); flock($fp, LOCK_UN); fclose($fp); } else { echo $query." Ecriture du cache";return FALSE;} } $nb=count($dirs); if($nb<1) {return "";} else { $num=mt_rand(0, $nb-1); return $core->config['url_images']."/media/themes/".$theme."/".$dirs[$num]; } } function cache_sql($nom,$emplacement,$page=1) { global $core; $db = new db($core->config['db_name']); if($page==0) {$page=1;} $req="SELECT contenu, UNIX_TIMESTAMP(date) AS temps FROM ".CACHE." WHERE nom LIKE '".$nom."' AND emplacement = '".$emplacement."' AND page='".$page."'"; $result = $db->query($req); $num = $db->num_rows($result); if($num>0) { $row=$db->get_object($result); if($row->temps>(time()-$core->config['cache_max'])) { $cache=true; $tab[1]=$row->contenu; } else {$cache=false;$tab[1]="";} } else { $req="INSERT INTO ".CACHE." SET contenu='',nom='".$nom."',emplacement= '".$emplacement."', page='".$page."'"; $db->query($req); $cache=false; $tab[1]=""; } $tab[0]=$cache; return $tab; } ?> function verif_get_post($type,$value) { global $core; switch ($type){ case 'num' : if(!is_numeric($value)) { $value=0; } break; case 'char' : $value=htmlspecialchars($value,ENT_QUOTES, 'UTF-8'); break; case 'char_base' : $value=addslashes($value); break; case 'mail' : $value=htmlspecialchars(trim($value),ENT_QUOTES, 'UTF-8'); if(!filter_var($value, FILTER_VALIDATE_EMAIL)) {$value=false;} break; case 'checkbox' : if(($value!=true)AND($value!=false)) {$value=false;} break; case 'password' : $value=md5($value); break; case 'date' : $Syntaxe='#^[0-3]{0,1}+[0-9]{1}\/[0-1]{0,1}+[0-9]{1}+\/[1-2]{1}+[0-9]{3}$#'; if(!preg_match($Syntaxe,$value)) { $value=false; } break; case 'file' : if(!preg_match('/(\.sh)|(\.php)|(\.php3)|(\.php4)|(\.php5)|(\.py)|(\.shtml)|(\.phtml)|(\.cgi)|(\.pl)|(\.htaccess)|(\.htpasswd)$/i',$value["name"])) { move_uploaded_file($value["tmp_name"], $core->config['url_tmp'].$value["name"]); $value=true; } else { $value=false; } break; default : $value=htmlspecialchars($value,ENT_QUOTES, 'UTF-8'); break; } return $value; } function get_nom($text){ $nom=trim($text); $sSearch = array ('/-/','/à|á|â|ä|ã|å/', '/À|Á|Â|Ä|Ã|Å/', '/è|é|ê|ë/', '/È|É|Ê|Ë/', '/ì|í|î|ï/', '/Ì|Í|Î|Ï/', '/ò|ó|ô|ö|ø/', '/Ò|Ó|Ô|Ö|Ø/', '/ù|ú|û|ü/', '/Ù|Ú|Û|Ü/', '/ÿ/', '/Ÿ/', '/ñ/', '/Ñ/', '/ç/', '/Ç/', '/[^a-z0-9]/i'); $sReplace = array ('_', 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'y', 'Y', 'n', 'N', 'c', 'C', '_'); $nom=preg_replace ($sSearch, $sReplace, $nom); $tab=array('"',"'","\\","&","{","(","[","-","|","`","@",")","]","=","}","+",":","/",";",",","?","!","<",">","%"," ","*",'$','-'); $nom=str_replace($tab,"_",$nom); $nom=str_replace("___","_",$nom); $nom=str_replace("__","_",$nom); $nom=strtolower($nom); return $nom; } function get_nom2($text){ $nom=trim($text); $sSearch = array ('/-/','/à|á|â|ä|ã|å/', '/À|Á|Â|Ä|Ã|Å/', '/è|é|ê|ë/', '/È|É|Ê|Ë/', '/ì|í|î|ï/', '/Ì|Í|Î|Ï/', '/ò|ó|ô|ö|ø/', '/Ò|Ó|Ô|Ö|Ø/', '/ù|ú|û|ü/', '/Ù|Ú|Û|Ü/', '/ÿ/', '/Ÿ/', '/ñ/', '/Ñ/', '/ç/', '/Ç/', '/[^a-z0-9]/i'); $sReplace = array ('_', 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'y', 'Y', 'n', 'N', 'c', 'C', '_'); $nom=preg_replace ($sSearch, $sReplace, $nom); $tab=array('"',"'","\\", "&", "&","{","(","[","-","|","`","@",")","]","=","}","+",":","/",";",",","?","!","<",">","%"," ","*",'$','-','_'); $nom=str_replace($tab,"-",$nom); $nom=str_replace("---","-",$nom); $nom=str_replace("--","-",$nom); $nom=strtolower($nom); return $nom; } function clean_str_soft($str){ $accents = array('à' => 'a', 'ä' => 'a', 'â' => 'a', 'é' => 'e', 'è' => 'e', 'ê' => 'e', 'ë' => 'e', 'ï' => 'i', 'î' => 'i', 'ö' => 'o', 'ô' => 'o', 'ü' => 'u', 'ç' => 'c'); $str = rtrim($str); $str = str_replace(array_keys($accents), array_values($accents), $str); $str = preg_replace('#[^a-zA-Z0-9\.]#si', '_', $str); return ($str); } function verif_rep($dir_name){ $size = strlen($dir_name); if ($dir_name{$size-1}=="/") { $dir_name = substr($dir_name,0,$size-1); } if (!is_dir($dir_name)) mkdir($dir_name,0775); } function hash_rep($rep,$nom_fichier) { $dir=''; for($i=0 ; $i<3 ; $i++) { $dir.= $nom_fichier{$i}."/"; verif_rep($rep.$dir); } return $dir; } function create_config_id_client() { global $core; if(isset($_SESSION['key_session'])) { //Initialisation de la fonction de cryptage $init_crypt=initialize_crypt(); //Récupération des données en session $key_sess=decode_crypt($_SESSION['key_session'],$init_crypt); if($key_sess!=false) { $core->config['id_client']=$key_sess[0]; $core->config['login']=$key_sess[1]; $connected="yes"; //$core->page['infos_client']=evalTemplate("tpl_infos_client.php","commun"); } else { $connected=""; //$err=-4; } } else { $connected=""; // $err=-4; } return $connected; } function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } ?> class verif_mobile { var $config; function verif_mobile() { $this->config=new StdClass(); $this->config->http_accepted = array( 'VND.WAP.WML' ); $this->config->agent_denied = array( 'OfficeLiveConnector', 'Swapper', ); $this->config->agent_accepted = array( 'airness', 'alcatel', 'amoi', 'android', //'asus', 'benq', //'bird', 'blackberry', 'cdm-', 'docomo', 'ericsson', //'eten', 'gigabyte', 'Google Wireless Transcoder', //'haier', 'Huawei', 'htc_', 'htc-', 'i-mate', 'i-mobile', 'ipaq', 'iphone', 'j-phone', 'kwc-', 'kddi', 'lenovo-', //'lg', 'lg-', 'lg/', 'lge-', 'midp', 'mitsu/', 'mot-', //'motor', 'motorola', 'nokia', //'nec', 'palm', 'panasonic', 'pantech', 'philips', //'ppc', 'pg-', 'portalmmm', 'qtek', 'sagem', 'samsung', 'sanyo', 'sch-', 'sec-', 'sendo', 'sgh-', 'sharp', 'sie-', 'siemens', 'sonyericsson', 'sph-', 'symbianos', 'treo', 'telit', 'toshiba', //'tsm', 'vk-', 'vodafone', 'wap2', //'wap', 'windows ce', 'wnd', 'wonu', 'zte-', ); $this->config->regex['http_accepted'] = '/(' . str_replace(',', '|', preg_quote(implode(',', $this->config->http_accepted), '/')) . ')/i'; $this->config->regex['agent_denied'] = '/(' . str_replace(',', '|', preg_quote(implode(',', $this->config->agent_denied), '/')) . ')/i'; $this->config->regex['agent_accepted'] = '/(' . str_replace(',', '|', preg_quote(implode(',', $this->config->agent_accepted), '/')) . ')/i'; } function check_http_accept($value = NULL) { return preg_match($this->config->regex['http_accepted'], $value); } function check_http_user_agent($value = NULL) { $status = false; if (!preg_match($this->config->regex['agent_denied'], $value)) { $status = preg_match($this->config->regex['agent_accepted'], $value); } return $status; } function redirect () { if ($this->check_http_accept($_SERVER['HTTP_ACCEPT'])) { return true; } if ($this->check_http_user_agent($_SERVER['HTTP_USER_AGENT'])) { return true; } return false; } } ?> global $prefix; // From object to array. function toArray($data) { if (is_object($data)) $data = get_object_vars($data); return is_array($data) ? array_map(__FUNCTION__, $data) : $data; } // From array to object. function toObject($data) { return is_array($data) ? (object) array_map(__FUNCTION__, $data) : $data; } class db { protected $host = 'localhost'; protected $user = ''; protected $pass = ''; protected $base; protected $connect_id = 0; protected $result_id = 0; protected $error; protected $query; public function __construct($base){ global $core; $this->host=$core->config['host']; $this->user=$core->config['user']; $this->pass=$core->config['password']; $this->base=$base; } // PRIVATE : connection à la DB function connect() { global $core; $host=$core->config['host']; $user=$core->config['user']; $pass=$core->config['password']; //=$core->config['dbname']; $this->connect_id = mysql_connect($host, $user, $pass); if ($this->connect_id) { if(mysql_select_db($this->base, $this->connect_id)){ mysql_query("SET NAMES UTF8"); return $this->connect_id; } else return FALSE; } else return FALSE; } // PRIVATE : connection à la DB function query($query,$cache=0,$path="") { global $core; if ( !$this->connect_id ) $this->connect($this->host,$this->user,$this->pass,$this->base); if($cache==0) { if ( $this->result_id = mysql_query($query, $this->connect_id) ) { $this->query = trim($query); return $this->result_id; } else { echo $query.$this->error= mysql_error(); return FALSE; } } else { $id_file=md5($query); if (!file_exists($path."cache/".$id_file.".sql") or (time() - filemtime($path."cache/".$id_file.".sql") >= $core->config['cache_max'])) { if ( $this->result_id = mysql_query($query, $this->connect_id) ) { $this->query = trim($query); $id=$this->result_id; } else { echo $query.$this->error= mysql_error(); return FALSE; } @unlink($path."cache/".$id_file.".sql"); $fp = fopen($path."cache/".$id_file.".sql", 'x+'); if (flock($fp, LOCK_EX)) { // pose un verrou exclusif while ($row = mysql_fetch_assoc($id)) {fwrite($fp, preg_replace("/\\r/"," ",preg_replace("/\\n/"," ",preg_replace("/\\r\\n/"," ",serialize($row))))."\r\n");} flock($fp, LOCK_UN); fclose($fp); } else { echo $query." Ecriture du cache";return FALSE;} } } } // PUBLIC : Dernier id inserer function last_insert_id() { return @mysql_insert_id(); } // PUBLIC : renvoi le nombre d'enregistrement affecté function num_rows($id="",$obj="",$cache=0){ if ($id=="") $id=$this->result_id; if($cache==1) { return count($obj); } else { if ( isset($id) ) { if ( preg_match('`^select`i',$this->query) ) { $i = mysql_num_rows($id); return $i; } if ( preg_match('`^(insert|update|delete)`i',$this->query) ) return mysql_affected_rows($id); } else { return count($this->records); } } } function get_object($id="") { if ($id=="") $id=$this->result_id; return @mysql_fetch_object($id); } function get_object_cache($query="",$path="") { $id_file=md5($query); $lines=file($path."cache/".$id_file.".sql"); foreach ($lines as $line_num => $line) {$php[]=unserialize($line);} return $php; } function get_array($query, $mode='BOTH') { /* switch($mode) { case 'NUMERIC' : $tab= @mysql_fetch_array($query, MYSQL_NUM); return $tab; break; case 'BOTH' : $tab= @mysql_fetch_array($query, MYSQL_BOTH); return $tab; break; case 'ASSOC' : default : $tab=@mysql_fetch_assoc($query); return $tab; break; } */ $i=0; while ($row = mysql_fetch_assoc($query)) { $tab[$i]=$row; $i++; } mysql_free_result($query); return $tab; } // PUBLIC : renvoi le msg d'erreur mysql function return_error() { return @mysql_error(); } // PUBLIC : ferme la connection; function close() { return @mysql_close($this->connect_id); } // PUBLIC : vide les resultat des requete function free_result() { return @mysql_free_result($this->connect_id); } } /* ***** Script pour se connecter : $maBD = new bd("base"); base est le nom de la base de donnée // executer une requete : $result = $maBD->query(SELECT * FROM ....); $row = $maBD->get_object($result); */ ?> function aff_pub($size, $random="random",$id_site) { global $core; $db = new db($core->config['db_name']); if($size==""){$size="bandeau";} if($id_site!=0) { $res=$db->query("SELECT * FROM ".SITES." WHERE id_site = '".$id_site."'"); if ($db->num_rows($res)>0) { $row=$db->get_object($res); $add_site=" theme ='".$row->theme."' "; } else {$add_site=" 1 ";} } else {$add_site=" 1 ";} if ($random=="random") { $res=$db->query("SELECT id_pubs FROM ".PUBS." WHERE taille = '".$size."' AND ".$add_site); $nb=$db->num_rows($res); if ($nb>0) { $tab=$db->get_array($res); $add_random=" AND id_pubs='".$tab[mt_rand(0,$nb-1)]['id_pubs']."'"; } } $pub=recup_donnee(PUBS, "taille",$size, "code",$add_site." ".$add_random." LIMIT 1 "); return $pub; } function aff_catcher($type="") { $inactive = 1*60; // 1 minute $session_life = time() - $_SESSION['catcher']; if($session_life > $inactive) { if ($type=="annonces") { //$pub=" "; } else { $pub=""; $_SESSION['catcher']=time(); } } else { $pub=""; } return $pub; } ?> function base64url_decode($base64url) { $base64 = strtr($base64url, '-_@', '=/+'); $plainText = base64_decode($base64); return ($plainText); } function base64url_encode($plainText) { $base64 = base64_encode($plainText); $base64url = strtr($base64, '=/+', '-_@'); return ($base64url); } function initialize_crypt() { $init_crypt['secret']=md5($_SERVER['REMOTE_ADDR'].session_id()); $init_crypt['iv'] = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); return $init_crypt; } function initialize_crypt_no_sess() { global $core; $init_crypt['secret']=md5($core->config['secret_no_sess']); $init_crypt['iv'] = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); return $init_crypt; } function decode_crypt($key,$init_crypt) { $data=base64url_decode($key); $result = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,$init_crypt['secret'],$data,MCRYPT_MODE_ECB,$init_crypt['iv']); if(strpos($result, '##')) { $tab = explode('##',$result); } else { $tab=false; } return $tab; } function encode_crypt($data,$init_crypt) { $key = base64url_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,$init_crypt['secret'],$data,MCRYPT_MODE_ECB,$init_crypt['iv'])); return $key; } ?> function aff_date($date, $court="") { global $core; $annee = substr($date, 0, 4); $mois = substr($date, 5, 2); $jour = substr($date, 8, 2); $heure = substr($date, 11, 2); $minute = substr($date, 14, 2); if($court =="1") { $date_aff= $jour."/".$mois."/".$annee; } else { $date_aff= $jour."/".$mois."/".$annee." à ".$heure."h".$minute; } return $date_aff; } function insert_date($date) { $tab = explode("/",$date); $date_insert=$tab[2]."-".$tab[1]."-".$tab[0]; return $date_insert; } /* TRONQUER LES TEXTES */ function tronque($chaine, $longueur = 120, $etc=1) { if (empty ($chaine)) { return ""; } elseif (strlen ($chaine) < $longueur) { return $chaine; } elseif (preg_match ("/(.{1,$longueur})\s./ms", $chaine, $match)) { if ($etc=="1") {return $match [1] . "..."; } else {return $match [1]; } } else { if ($etc=="1") {return substr ($chaine, 0, $longueur) . "...";} else {return substr ($chaine, 0, $longueur); } } } /* reloader une div */ function reload_div($fonction_php,$div,$params='',$script='') { if(@file_exists("class/config.php")){require_once ("class/config.php");} elseif(@file_exists("../class/config.php")){require_once ("../class/config.php");} set_text_site(); $tab=explode('##',urldecode($params)); $text=$fonction_php($tab); $objResponse = new xajaxResponse(); $objResponse->clear($div, "innerHTML"); if(is_array($text)) { $objResponse->assign($div,"innerHTML",$text[0]); $objResponse->script($text[1]); } else {$objResponse->assign($div,"innerHTML",$text);} if($script!="") {$objResponse->script(base64_decode($script));} return $objResponse; } /* AFFICHAGE DES MESSAGES D'ERREUR */ function affiche_msg_err($type,$err){ global $core; $db = new db($core->config['db_name']); $result=$db->query("SELECT text FROM ".TEXTES_INFO." WHERE num='$err' AND type='$type' AND lang='".$core->config['lang']."'"); if($db->num_rows($result)!=0) { $r = $db->get_object($result); $erreur = $r->text; } return $erreur; } function msg_err($err){ global $core; //Affichage des erreurs if(($err!='')&&($err!=0)) { $core->systeme['erreur']=affiche_msg_err('err',$err); if($err<0) {$core->page['err'].=evalTemplate("tpl_erreur.php","commun");} elseif($err>0) {$core->page['err'].=evalTemplate("tpl_message.php","commun");} } } // Pour appeler une page dans templates/ function evalTemplate($template,$add_path="") { global $core; if(($add_path!="")&&(substr($add_path,-1)!="/")) {$add_path=$add_path."/";} if ($add_path=="") { $add_path="templates/".$core->config['squelette_defaut']."/"; } if ((file_exists($core->config['path_site']."/templates/".$core->config['template']."/templates/".$template))) { $add_path="templates/".$core->config['template']."/"; } $return = file_get_contents($add_path."templates/".$template); $return = str_replace('"','\"',$return); $return = preg_replace('/\{'.'\$'.'(.*)\}/smiU','".'.'\$'.'$1."',$return); eval( "\$return = \"$return\";" ); // on va chercher toutes les images et on va vérifier qu'elles existent bien avec la langue actuelle, sinon, on affiche les images correspondantes à la langue par défaut $return=modif_image($return); return $return; } // Pour appeler une page html dans html/ function evalPageHtml($pageHtml) { global $core; $return = @file_get_contents("html/".$pageHtml); // si le fichier html n'existe pas dans la langue actuelle if(!$return) { // on ouvre le fichier html correspondant à la langue par défaut $tab_namefile = explode('_',$pageHtml); // reconstitution du nom du fichier avec l'extension correspondant au language par défaut for($i=0;$i<(sizeof($tab_namefile)-1);$i++) {$fichierHtml.=$tab_namefile[$i]."_";} $fichierHtml.=$core->config['lang_default'].".html"; $return = file_get_contents("html/".$fichierHtml); } $return = str_replace('"','\"',$return); $return = preg_replace('/\{'.'\$'.'(.*)\}/smiU','".'.'\$'.'$1."',$return); eval( "\$return = \"$return\";" ); modif_image($return); return $return; } // Pour traduire les JS/ function evalTemplateJS($template) { global $core; $return = file_get_contents("js/".$template); $return = str_replace('"','\"',$return); $return = str_replace('$','#dollar#',$return); $return = preg_replace('/\{'.'#dollar#'.'(.*)\}/smiU','".'.'\$'.'$1."',$return); eval( "\$return = \"$return\";" ); $return = str_replace('#dollar#','$',$return); return $return; } function set_text_site(){ global $core; $db = new db($core->config['db_name']); $req1="SELECT nom,text FROM ".TEXTES_SITE." WHERE lang='".$core->config['lang_default']."' ORDER BY nom"; $result1 = $db->query($req1); $nb1 = $db->num_rows($result1); if($nb1>0) { while($row1=$db->get_object($result1)) { $req="SELECT nom,text FROM ".TEXTES_SITE." WHERE lang='".$core->config['lang']."' AND nom LIKE '".$row1->nom."' LIMIT 1"; $result = $db->query($req); $nb = $db->num_rows($result); if($nb>0) { $row=$db->get_object($result); $core->text[$row->nom]=htmlspecialchars($row->text, ENT_QUOTES); } // si aucun texte de la langue en cours , on remplace par le texte de la langue par defaut else { $core->text[$row1->nom]=htmlspecialchars($row1->text, ENT_QUOTES); } } } } function set_text_page($page){ global $core; $db = new db($core->config['db_name']); $req1="SELECT nom,text FROM ".TEXTES_PAGE." WHERE lang LIKE'".$core->config['lang_default']."' AND page LIKE '$page' ORDER BY nom"; $result1 = $db->query($req1); $nb1 = $db->num_rows($result1); if($nb1>0) { while($row1=$db->get_object($result1)) { $req="SELECT nom,page,text FROM ".TEXTES_PAGE." WHERE lang LIKE'".$core->config['lang']."' AND page LIKE '$page' AND nom LIKE '".$row1->nom."' LIMIT 1"; $result = $db->query($req); $nb = $db->num_rows($result); if($nb>0) { $row=$db->get_object($result); $core->page[$row->page][$row->nom]=htmlspecialchars($row->text, ENT_QUOTES); } // si aucun texte de la langue en cours , on remplace par le texte de la langue par defaut else { $core->page[$row->page][$row1->nom]=htmlspecialchars($row1->text, ENT_QUOTES); } } } } function set_text_menu($zone,$style=''){ global $core; $db = new db($core->config['db_name']); $req="SELECT nom,text,url,rubrique,target FROM ".TEXTES_MENU." WHERE lang LIKE '".$core->config['lang']."' AND zone LIKE '$zone' AND level<='".$core->config['level']."' ORDER BY ordre"; $result = $db->query($req); $nb = $db->num_rows($result); if($nb>0) { $i=0; $core->page['menu']='
$text | "; } else { $constuction_tableau.="$text | "; } $i++; } $constuction_tableau.="
---|---|
$text | "; } else { $constuction_tableau.="$text | "; } $i++; } $constuction_tableau.="