Téléverser les fichiers vers "lib"
This commit is contained in:
parent
205ffbf7ac
commit
2a489a5ff4
4 changed files with 319 additions and 0 deletions
259
lib/aeos.lib.php
Normal file
259
lib/aeos.lib.php
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
<?php
|
||||
// Listings des fonctions (librairie) utilisées sur AEOS
|
||||
// *****************************************************
|
||||
|
||||
/* Class qui permet la lecture des fichiers XML */
|
||||
class Xml2Array
|
||||
{
|
||||
private $xml_dom;
|
||||
private $xml_array;
|
||||
private $xml;
|
||||
|
||||
public function __construct($xml = '') {$this->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))
|
||||
{
|
||||
$result['#text'] = html_entity_decode(htmlentities($dom_element->nodeValue, ENT_COMPAT, 'UTF-8'), ENT_COMPAT,'ISO-8859-1');
|
||||
}
|
||||
|
||||
if ($dom_element->hasAttributes())
|
||||
{
|
||||
foreach ($dom_element->attributes as $attrib)
|
||||
{
|
||||
$prefix = ($attrib->prefix) ? $attrib->prefix.':' : '';
|
||||
$result["@".$prefix.$attrib->nodeName] = $attrib->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function get_dom()
|
||||
{
|
||||
if(empty($this->xml))
|
||||
{
|
||||
echo '<span class="erreur">Aucun fichier XML trouvé.</span>';
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->xml_dom = @DOMDocument::load($this->xml);
|
||||
|
||||
if($this->xml_dom)
|
||||
{
|
||||
return $this->xml_dom;
|
||||
}
|
||||
|
||||
echo '<span class="erreur">Données XML invalide</span>'; exit;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 != "..") {
|
||||
$array[$i]=$Fichier;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
@natsort($array);
|
||||
return $array;
|
||||
closedir($dossier);
|
||||
}
|
||||
|
||||
// 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 = utf8_encode($c);
|
||||
//echo $dom->saveXML();
|
||||
$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;
|
||||
}
|
||||
|
||||
// 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")
|
||||
{
|
||||
$target_path = $dossier.$filename;
|
||||
if(move_uploaded_file($source, $target_path))
|
||||
{
|
||||
$nom = basename($filename, ".zip");
|
||||
if (is_dir($dossier.$nom)==TRUE)
|
||||
{
|
||||
echo "<span class='erreur'>Ce ".$page." est déjà installé.</span>";
|
||||
unlink($target_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
$x = $zip->open($target_path);
|
||||
if ($x === true)
|
||||
{
|
||||
$zip->extractTo($dossier.$nom);
|
||||
$zip->close();
|
||||
unlink($target_path);
|
||||
}
|
||||
echo "<span class='valide'>Votre ".$page." a bien été installé.</span>";
|
||||
}
|
||||
}
|
||||
else {echo "<span class='erreur'>Une erreur est survenue. Veuillez recommencer.</span>";}
|
||||
}
|
||||
else {echo "<span class='erreur'>Votre fichier n'est pas un zip.</span>";}
|
||||
}
|
||||
|
||||
// Inverse de nl2br by OverSu
|
||||
function br2nl($replace) {
|
||||
return preg_replace("/<br\\s*?\/??>/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
|
||||
function sendMail($expediteur, $destinataire, $titre, $messageHTML){
|
||||
date("D, j M Y H:i:s");
|
||||
$entete = "From: ".$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;
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue