class_name = get_class($this); $this->load_msg(); $this->fetch_datas_cache(); if(!$this->hash){ $this->get_hash_from_form(); } } protected function fetch_datas_cache(){ if($tmp=cms_cache::get_at_cms_cache($this)){ $this->restore($tmp); }else{ $this->fetch_datas(); cms_cache::set_at_cms_cache($this); } } protected function restore($cms_object){ foreach(get_object_vars($cms_object) as $propertieName=>$propertieValue){ $this->{$propertieName}=$propertieValue; } } public function serialize(){ global $charset; // //formulaire chargé en ajax donc en UTF-8 // if($charset!="utf-8"){ // $this->parameters = $this->utf8_decode($this->parameters); // } return serialize($this->parameters); } public function unserialize($parameters){ $this->parameters = unserialize($parameters); } protected function load_msg(){ global $lang; global $base_path; //on regarde si on doit intégrer des fichiers de messages de parents $parents = $this->get_parent_classes(); for($i=count($parents)-1 ; $i>=0 ; $i--){ if($parents[$i] != "cms_module_root"){ $parent = str_replace("cms_module_","",$parents[$i]); if(strpos($parent,"_") !== false){ $module_rep = substr($parent,0,strpos($parent,"_")); }else{ $module_rep = $parent; } //on regarde la langue par défaut du module $default_language = $this->get_default_language($module_rep); //si elle est différente de celle de l'interface, on l'intègre // la langue par défaut donne l'assurance d'avoir tous les messages... if($default_language != $lang){ $file = $base_path."/cms/modules/".$module_rep."/messages/".$default_language."/".$parents[$i].".xml"; $this->load_msg_file($file); } //on commence par charger les messages de la langue par défaut du module... $file = $base_path."/cms/modules/".$module_rep."/messages/".$lang."/".$parents[$i].".xml"; $this->load_msg_file($file); }else{ $file = $base_path."/cms/modules/common/messages/".$lang."/cms_module_root.xml"; $this->load_msg_file($file); } } $var = str_replace("cms_module_","",$this->class_name); if(strpos($var,"_") !== false){ $module_rep = substr($var,0,strpos($var,"_")); }else{ $module_rep = $var; } //on regarde la langue par défaut du module $default_language = $this->get_default_language($module_rep); //si elle est différente de celle de l'interface, on l'intègre // la langue par défaut donne l'assurance d'avoir tous les messages... if($default_language != $lang){ $file = $base_path."/cms/modules/".$module_rep."/messages/".$default_language."/".$this->class_name.".xml"; $this->load_msg_file($file); } $file = $base_path."/cms/modules/".$module_rep."/messages/".$lang."/".$this->class_name.".xml"; $this->load_msg_file($file); } protected function get_parent_classes(){ $parents = array(); $parent = get_parent_class($this->class_name); if($parent){ $parents[] =$parent; while($parent = get_parent_class($parent)){ $parents[] =$parent; } } return $parents; } protected function get_recurse_classes_parent($name,$parents=array()){ $parent = get_parent_class($name); $parents[]=$parent; if(get_parent_class($parent)!=""){ $parents = $this->get_recurse_classes_parent($parent,$parents); } return $parents; } protected function load_msg_file($file){ global $charset; global $cache_msg_file; if(!$cache_msg_file || !is_array($cache_msg_file)){ $cache_msg_file=array(); } if($cache_msg_file[$file]){ $this->msg=$cache_msg_file[$file]; }elseif(file_exists($file)){ @ini_set("zend.ze1_compatibility_mode", "0"); $dom = new domDocument(); $dom->load($file); $entries = $dom->getElementsByTagName('entry'); for($i=0 ; $i<$entries->length ; $i++){ if($entries->item($i)->hasAttributes()){ $attributes = $entries->item($i)->attributes; for($j=0 ; $j<$attributes->length ; $j++){ if($attributes->item($j)->nodeName == "code"){ //dom retourne de l'utf-8 à tous les coups... $this->msg[$attributes->item($j)->nodeValue] = $this->charset_normalize($entries->item($i)->nodeValue,"utf-8"); break; } } } } $cache_msg_file[$file]=$this->msg; @ini_set("zend.ze1_compatibility_mode", "1"); return true; }else{ return false; } } protected function format_text($text){ global $charset; return htmlentities($text,ENT_QUOTES,$charset); } public function get_hash(){ if(!$this->hash){ $this->hash = $this->generate_hash($this->class_name); } $query = "insert into cms_hash set hash = '".$this->hash."'"; mysql_query($query); return $this->hash; } public function delete_hash(){ $query = "delete from cms_hash where hash = '".$this->hash."'"; $result = mysql_query($query); if($result){ $this->hash = ""; } } protected function generate_hash($phrase=""){ $hash = md5($phrase.time()); $query = "select hash from cms_hash where hash = '".$hash."'"; $result = mysql_query($query); if(mysql_num_rows($result)){ $hash = $this->generate_hash($hash); } return $hash; } protected static function charset_normalize($elem,$input_charset){ global $charset; if(is_array($elem)){ foreach ($elem as $key =>$value){ $elem[$key] = self::charset_normalize($value,$input_charset); } }else{ //PMB dans un autre charset, on converti la chaine... $elem = self::clean_cp1252($elem, $input_charset); if($charset != $input_charset){ $elem = iconv($input_charset,$charset,$elem); } } return $elem; } public static function addslashes($elem){ if(is_array($elem) || is_object($elem)){ foreach ($elem as $key =>$value){ $elem[$key] = self::addslashes($value); } }else{ $elem = addslashes($elem); } return $elem; } public static function stripslashes($elem){ if(is_array($elem) || is_object($elem)){ foreach ($elem as $key =>$value){ $elem[$key] = self::stripslashes($value); } }else{ $elem = stripslashes($elem); } return $elem; } public static function debug($elem,$mode=""){ global $cms_debug_mode; if(!$mode){ global $cms_debug_mode; $mode = $cms_debug_mode; } switch ($mode){ //impression à l'écran case CMS_DEBUG_MODE_PHP : highlight_string(print_r($elem,true)); break; //renvoi dans la console case CMS_DEBUG_MODE_CONSOLE : print " "; break; case CMS_DEBUG_MODE_FILE : global $base_path; if(is_string($elem)){ file_put_contents($base_path."/temp/debug_portail.txt",date("r")." : ".$elem."\n",FILE_APPEND); }else{ file_put_contents($base_path."/temp/debug_portail.txt",date("r")." : ".print_r($elem,true)."\n",FILE_APPEND); } break; case CMS_DEBUG_MODE_OFF : default : // rien à faire... break; } } public function get_default_language($module){ global $base_path; //si c'est un module, on a déjà lu le manifest... if($this->manifest){ $default_language = $this->informations['default_language']; }else{ //sinon, le cas des common est à part, on sait que c'est en français... if($module == "common"){ $default_language = "fr_FR"; }else{ //sinon, on va chercher l'info dans le manifest du module... $default_language = self::get_module_default_language($base_path."/cms/modules/".$module."/manifest.xml"); } } return $default_language; } public static function get_module_default_language($xml){ @ini_set("zend.ze1_compatibility_mode", "0"); if(!is_object($xml)){ $dom = new domDocument(); $dom->load($xml); $xml = $dom; } $default_language = $xml->getElementsByTagName("default_language")->item(0)->nodeValue; @ini_set("zend.ze1_compatibility_mode", "1"); return $default_language; } public function set_cms_build_env($env){ $this->cms_build_env = $env; } public function get_module_folder(){ if(!$this->module_folder){ global $base_path; $var = str_replace("cms_module_","",$this->class_name); if(strpos($var,"_") !== false){ $module_rep = substr($var,0,strpos($var,"_")); }else{ $module_rep = $var; } $this->module_folder = $base_path."/cms/modules/".$module_rep."/"; } return $this->module_folder; } public function convert_utf8($str){ global $charset; if($charset != "utf-8"){ return iconv($charset,"utf-8",$str); } } public function get_headers(){ return array(); } public function get_ajax_link($args){ global $base_path; $request = ""; foreach($args as $key => $val){ $request.="&".$key."=".$val; } return $base_path."/ajax.php?module=cms&categ=module&elem=".$this->class_name."&id=".$this->id."&action=ajax".$request; } public function execute_ajax(){ global $do; switch($do){ case "get_infopages" : $query = "select id_infopage,title_infopage from infopages where valid_infopage = 1 order by title_infopage"; $result = mysql_query($query); $infopages = array(); if(mysql_num_rows($result)){ while($row = mysql_fetch_object($result)){ $infopages[$row->id_infopage]=$row->title_infopage; } } $response['content'] = json_encode($this->utf8_encode($infopages)); $response['content-type'] = "application/json"; break; case "get_pages" : $query = "select id_page,page_name from cms_pages order by page_name asc"; $result = mysql_query($query); $pages = array(); $pages[0] = $this->msg["cms_module_menu_menu_entry_page_choice"]; if(mysql_num_rows($result)){ while($row = mysql_fetch_object($result)){ $pages[$row->id_page]=$row->page_name; } } $response['content'] = json_encode($this->utf8_encode($pages)); $response['content-type'] = "application/json"; break; case 'get_page_vars' : global $page; $page+=0; $query = "select var_name,var_comment from cms_vars where var_num_page = ".$page; $result = mysql_query($query); $vars = array(); if(mysql_num_rows($result)){ while($row = mysql_fetch_object($result)){ $vars[] = array( 'name' => $row->var_name, 'comment' => $row->var_comment ); } } $response['content'] = json_encode($this->utf8_encode($vars)); $response['content-type'] = "application/json"; break; default : $response = array( 'content' => "", 'content-type' => "text/html" ); break; } return $response; } public function get_module_dom_id(){ if(method_exists($this,"get_dom_id")){ return $this->get_dom_id(); }else{ $query = "select cadre_object from cms_cadres where id_cadre = ".$this->cadre_parent; $result = mysql_query($query); if(mysql_num_rows($result)){ $obj = mysql_result($result,0,0); return $obj."_".$this->cadre_parent; } } } protected function fetch_managed_datas($type){ switch($type){ case "conditions" : case "datasources" : case "views" : if($this->module_class_name){ $query = "select managed_module_box from cms_managed_modules where managed_module_name = '".$this->module_class_name."'"; $result = mysql_query($query); if(mysql_num_rows($result)){ $datas = unserialize(mysql_result($result,0,0)); $this->managed_datas = $datas[$type][$this->class_name]; } } break; default : $query = "select managed_module_box from cms_managed_modules where managed_module_name = '".$this->class_name."'"; $result = mysql_query($query); if(mysql_num_rows($result)){ $this->managed_datas = unserialize(mysql_result($result,0,0)); } break; } } protected function get_managed_form_start($pvars=""){ global $base_path; $vars =""; $params =array( 'categ' => "manage" ); if($this->module_class_name){ $params['sub']= str_replace("cms_module_","",$this->module_class_name); $var = explode("_",$this->class_name); $params['quoi'] = $var[3]."s"; $params['elem'] = $this->class_name; }else { $params['sub']= str_replace("cms_module_","",$this->class_name); $params['quoi'] = "module"; } $params['action'] = "save_form"; foreach($params as $key=>$val){ if($vars!="") $vars .="&"; $vars.=$key."=".$val; } if($pvars){ foreach($pvars as $key=>$val){ if($vars!="") $vars .="&"; $vars.=$key."=".$val; } } return "
"; } protected function get_exported_datas(){ $infos = array( "id" => $this->id, "class" => $this->class_name, "hash" => $this->hash, "parameters" => $this->parameters ); $infos['selectors'] = array(); if(count($this->selectors)){ for($i=0 ; $i