class_name = get_class($this); $this->load_msg(); $this->fetch_datas_cache(); if(!$this->hash){ $this->get_hash_from_form(); }else{ $var_name = $this->class_name."_hash"; global ${$var_name}; if(isset(${$var_name}) && is_array(${$var_name})){ array_shift(${$var_name}); } } } protected function fetch_datas_cache(){ if($this->id && ($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(){ if (!count($this->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 $cache_msg_file, $base_path; if(!$cache_msg_file || !is_array($cache_msg_file)){ $cache_msg_file=array(); } if(isset($cache_msg_file[$file])){ $this->msg=$cache_msg_file[$file]; } elseif(file_exists($file)){ $messages = new XMLlist($file); $messages->analyser(); if(is_array($messages->table)){ $this->msg = array_merge($this->msg, $messages->table); } //Gestion des substs $tokens = explode('/', $file); $file_name = array_pop($tokens); $file_lang = array_pop($tokens); $subst_file = $base_path."/cms/modules/common/substs/".$file_lang."/".$file_name; if(file_exists($subst_file)) { $subst_messages = new XMLlist($subst_file); $subst_messages->analyser(); if(is_array($subst_messages->table)){ $this->msg = array_merge($this->msg, $subst_messages->table); } } $cache_msg_file[$file]=$this->msg; return true; } else { return false; } } protected function format_text($text){ global $charset; return htmlentities($text,ENT_QUOTES,$charset); } public function get_hash(){ global $dbh; if(!$this->hash){ $this->hash = $this->generate_hash($this->class_name); $query = "insert into cms_hash set hash = '".$this->hash."'"; pmb_mysql_query($query,$dbh); } return $this->hash; } public function delete_hash(){ global $dbh; $query = "delete from cms_hash where hash = '".$this->hash."'"; $result = pmb_mysql_query($query,$dbh); if($result){ $this->hash = ""; } } protected function generate_hash($phrase=""){ global $dbh; $hash = md5($phrase.time()); $query = "select hash from cms_hash where hash = '".$hash."'"; $result = pmb_mysql_query($query,$dbh); if(pmb_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){ case CMS_DEBUG_MODE_DUMP : var_dump($elem); break; //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(isset($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){ if(!is_object($xml)){ $dom = new domDocument(); $dom->load($xml); $xml = $dom; } $default_language = $xml->getElementsByTagName("default_language")->item(0)->nodeValue; 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($datas=array()){ return array(); } public function get_ajax_link($args = array(), $action = 'ajax'){ 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=".$action.$request; } public function execute_ajax(){ global $dbh,$do; switch($do){ case "get_infopages" : $query = "select id_infopage,title_infopage from infopages where valid_infopage = 1 order by title_infopage"; $result = pmb_mysql_query($query,$dbh); $infopages = array(); if(pmb_mysql_num_rows($result)){ while($row = pmb_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 = pmb_mysql_query($query,$dbh); $pages = array(); $pages[0] = $this->msg["cms_module_menu_menu_entry_page_choice"]; if(pmb_mysql_num_rows($result)){ while($row = pmb_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 = pmb_mysql_query($query,$dbh); $vars = array(); if(pmb_mysql_num_rows($result)){ while($row = pmb_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(){ global $dbh; 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 = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ $obj = pmb_mysql_result($result,0,0); return $obj."_".$this->cadre_parent; } } } protected function fetch_managed_datas($type){ global $dbh; $this->managed_datas = ''; 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 = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ $datas = unserialize(pmb_mysql_result($result,0,0)); if(isset($datas[$type][$this->class_name])) { $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 = pmb_mysql_query($query,$dbh); if(pmb_mysql_num_rows($result)){ $this->managed_datas = unserialize(pmb_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