xml = $xml;} public function setXml($xml) { if(!empty($xml)) { $this->xml = $xml; } } public function get_array() { if($this->get_dom() === false){return false;} $this->xml_array = array(); $root_element = $this->xml_dom->firstChild; $this->xml_array[$root_element->tagName] = $this->node_2_array($root_element); return $this->xml_array; } private function node_2_array($dom_element) { if($dom_element->nodeType != XML_ELEMENT_NODE){return false;} $children = $dom_element->childNodes; foreach($children as $child) { if($child->nodeType != XML_ELEMENT_NODE){continue;} $prefix = ($child->prefix) ? $child->prefix.':' : ''; if(!is_array(@$result[$prefix.$child->nodeName])) { $subnode = false; foreach($children as $test_node) { if($child->nodeName == $test_node->nodeName && !$child->isSameNode($test_node)) { $subnode = true; break; } } } else { $subnode = true; } if ($subnode) { $result[$prefix.$child->nodeName][] = $this->node_2_array($child); } else { $result[$prefix.$child->nodeName] = $this->node_2_array($child); } } if (!is_array(@$result)) { if (function_exists('html_entity_decode')) $result['#text'] = html_entity_decode(htmlentities($dom_element->nodeValue)); else $result['#text'] = htmlentities($dom_element->nodeValue); } if ($dom_element->hasAttributes()) { foreach ($dom_element->attributes as $attrib) { $prefix = ($attrib->prefix) ? $attrib->prefix.':' : ''; if (function_exists('html_entity_encode')) $result["@".$prefix.$attrib->nodeName] = html_entity_encode(htmlentities($attrib->nodeValue)); else $result["@".$prefix.$attrib->nodeName] = htmlentities($attrib->nodeValue); } } return $result; } private function get_dom() { if(empty($this->xml)) { echo 'Aucun fichier XML trouvé.'; return false; } $this->xml_dom = @DOMDocument::load($this->xml); if($this->xml_dom) { return $this->xml_dom; } echo 'Données XML invalide'; //header('Location: '.$AEOS_REW.HOME_PAGE.'-E404.html'); } } // Renvoi le XML en ARRAY function lecture_xml($config) { $converter = new Xml2Array(); $converter->setXml($config); $xml_array = $converter->get_array(); return $xml_array; } // Renvoi le listing d'un dossier dans un ARRAY function listing_dossier($folder) { $dossier = opendir($folder); $i=0; while ($Fichier = readdir($dossier)) { if ($Fichier != "." && $Fichier != ".." && $Fichier != ".htaccess" && substr($Fichier, 0, 1) != '.') { $array[$i]=$Fichier; $i++; } } @natsort($array); return $array; closedir($dossier); } // Renvoi le listing du dossier PAGE en triant par ordre function listing_ordre($o = NULL) { $a = array(); $l = listing_dossier(DATA_PAGES); foreach ($l as &$p) { $m = lecture_xml(DATA_PAGES.$p); $a[$m['page']['ordre']['#text']] = $p; } switch($o) { case 1: krsort($a); break; case 0: default: ksort($a); break; } return $a; } // Enregistre une donnée dans un XML - Chemin, OldElement, NewElement /* function ecriture_xml($a, $b, $c) { $dom = new DomDocument; $dom->load($a); $xml = $dom->getElementsByTagName($b); //echo $xml->item(0)->nodeValue; $titre = $xml->item(0); $titre->nodeValue = stripslashes(utf8_encode($c)); //echo $dom->saveXML(); $dom->save($a); } */ function ecriture_xml($a, $b, $c, $d=FALSE) { $dom = new DomDocument('1.0','UTF-8'); $dom->load($a); $b = explode("/", $b); $i = 0; foreach($b as $element) { $crt = "dom".$i; $prec = ($i == 0)? "dom" : "dom".($i-1); if(substr($element, -1) == "]") { $d = explode("[", $element); $e = $d[0]; $f = intval(substr($d[1], 0, -1)); $$crt = $$prec->getElementsByTagName($e)->item($f); } else { $$crt = $$prec->getElementsByTagName($element)->item(0); } $i++; } $rep = $$crt->nodeValue = stripslashes($c); if($d) { $ocrt = $$crt; $ncrt=$$crt->parentNode->appendChild($dom->createElement($element)); $cdata=$dom->createCDATASection(stripslashes($c)); $ncrt->appendChild($cdata); $$crt->parentNode->replaceChild($ncrt, $ocrt); } $dom->save($a); } // Renvoi une donnée en STRING function donnee_xml($a, $b) { $dom = new DomDocument; $dom->load($a); $xml = $dom->getElementsByTagName($b); return $xml->item(0)->nodeValue; } function cleanName($a) { $b = array('"', '/', ',', '\\', '*', '?', '<', '>', '|', ':'); $c = str_replace($b, "", $a); return utf8_decode($c); } // Upload $fichier, le dézippe dans $dossier et affiche le message $page function upload_unzip($fichier, $dossier, $page) { $filename = $fichier["name"]; $source = $fichier["tmp_name"]; $type = $fichier["type"]; if ($type=="application/zip" || $type=="application/x-zip-compressed" || $type=="multipart/x-zip" || $type=="application/x-compressed" || $type=="application/octet-stream") { $target_path = $dossier.$filename; if(move_uploaded_file($source, $target_path)) { $nom = basename($filename, ".zip"); if (is_dir($dossier.$nom)==TRUE) { $e = 2; //echo "Ce ".$page." est déjà installé."; unlink($target_path); } else { $zip = new ZipArchive(); $x = $zip->open($target_path); if ($x === true) { $zip->extractTo($dossier.$nom); $zip->close(); unlink($target_path); } //Modification pour l'installation de module $contenu = lecture_xml($dossier.$nom."/config.xml"); rename ($dossier.$nom, $dossier.$contenu['configuration']['dossier']['#text']); // $e = 0; //echo "Votre ".$page." a bien été installé."; } } else {$e=1; //echo "Une erreur est survenue. Veuillez recommencer."; } } else {$e=3; //echo "Votre fichier n'est pas un zip."; } return $e; } // Inverse de nl2br by OverSu function br2nl($replace) { return preg_replace("//i", "", $replace); } //Merci à holger1 de php.net // Supprime un dossier function removeFolder($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") removeFolder($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } } // Vide un dossier function clearFolder($folder) { $dossier=opendir($folder); while ($fichier = readdir($dossier)) { if ($fichier != "." && $fichier != "..") { $Vidage= $folder.$fichier; unlink($Vidage); } } closedir($dossier); } // Génère un mot de passe de $nbr caractères function generer_mdp($nbr) { $str = ""; $chaine = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand((double)microtime()*1000); for($i=0; $i<$nbr; $i++) { $str .= $chaine[rand()%strlen($chaine)]; } return $str; } // Envoi un mail // Ajout du nom de l'expéditeur dans le champs 'FROM' (Optionnel) function sendMail($expediteur, $destinataire, $titre, $messageHTML, $name = null){ date("D, j M Y H:i:s"); $entete = ($name == null)? "From: ".$expediteur."\n" : "From: ".$name." <".$expediteur.">\n"; $entete .= "Cc: \n"; $entete .= "Reply-To: ".$expediteur." \n"; $entete .= "X-Mailer: PHP/" . phpversion() . "\n" ; $entete .= "Date: ". date("D, j M Y H:i:s"); mail($destinataire, $titre, $messageHTML, $entete); } // Retourne un boolean // Vérifie si une adresse est belle et bien au format mail. function checkMail($adresse) { $Syntaxe='#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#'; if(preg_match($Syntaxe,$adresse)) return true; else return false; } // Retourne STRING // Permet d'afficher le chemin complet du site SANS le fichier à la fin NI le slash. (Ex: http://www.domaine.com/dossier/) function getBaseScript() { $fullPath = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; $file = basename ($fullPath); $dir = dirname($fullPath); return $dir; } // Retourne STRING // Transforme une chaine en URL valide function valideURL($s) { $p = array("?","!","@","#","%","&","*","(",")","[","]","=","+"," ",";",":","'",".","_", "&"); $s = str_replace($p, "-", $s); $s = strip_tags($s); $m = array('@', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ'); $n = array('a', 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y'); while($k = strpos($s, '--')!==FALSE) $s = str_replace("--", "-", $s); $s = str_replace($m, $n, $s); return $s; } // Retrouve STRING // Retourne la valeur précédente d'un array function getValueArray($a, $b, $c) { $k = array_flip(array_keys($a)); $v = array_values($a); return $v[$k[$b]+$c]; } function showTooltip($a, $b) { $r=''; $r.=$a; $r.=''; $r.=''; $r.=$b; $r.=''; $r.=''; return $r; } // Retourne BOOLEAN // Retourne si il y a une nouvelle version - ou pas. function checkVersion() { $v = lecture_xml(AEOS_REAL_URL.'/demo/data/config.xml'); if($v['configuration']['version']['#text']==AEOS_VERSION) return FALSE; else return TRUE; } // Retourne STRING // Retourne STRING sécurisé function CA20($a) { //XSS strip_tags($a); $a = htmlspecialchars($a, ENT_QUOTES); //SQL Injection $a = htmlentities($a, ENT_QUOTES); if(get_magic_quotes_gpc()===1){$a = stripslashes($a);} return $a; } function checkInstall() { global $subdir; $config = $subdir."data/config.xml"; $install = $subdir."install/index.php"; if (!file_exists($config)) { if (!file_exists($install)) die("Fichier config.xml et script d'installation introuvable"); else header('Location: '.$install); } return TRUE; } ?>