Changeset 7991


Ignore:
Timestamp:
Dec 3, 2010, 11:50:00 PM (13 years ago)
Author:
mistic100
Message:

PHP Optimisateur :
configuration via formulaire
installation semi-automatique des plugins

Location:
extensions/PHP_Optimisateur
Files:
8 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/PHP_Optimisateur/files/functions.php

    r7988 r7991  
    22/***************************************\
    33|                       PHP OPTIMISATEUR                        |
    4 |                          Version 1.0                          |
     4|                          Version 1.1                          |
    55\***************************************/
    66
     
    1212        $replace = array ('e','E','a','A','i','I','u','U','o','O','c','C',',n','N','y','Y','_','');
    1313       
    14         if ($renameORNOT) {
    15                 return preg_replace($search, $replace, $string);
    16         } else {
    17                 return $string;
    18         }
     14        return preg_replace($search, $replace, $string);
    1915}
    2016
     
    4945        # si $dirs=true liste les dossiers plutot que les fichiers
    5046        global ${$array}; // Charge la tableau pour la sortie, déclaré à l'exterieur à cause de l'appel recursif de la fonction
    51         $dir = rtrim($dir, '/'); // on vire un eventuel slash mis par l'utilisateur de la fonction a droite du repertoire
     47        $dir = rtrim($dir, '/');
    5248
    5349        if (is_dir($dir)) {
     
    5652                exit;
    5753        }
    58         while (($file = readdir($dh)) !== false ) { //boucle pour parcourir le repertoire
     54        while (($file = readdir($dh)) !== false ) {
    5955                if ($file !== '.' && $file !== '..') {
    6056                        $path = $dir.'/'.$file;
    61                         if (is_dir($path)) { //si on tombe sur un sous-repertoire
     57                        if (is_dir($path)) {
    6258                                if($dirs) ${$array}[] = $path;
    63                                 recursive_readdir($path, $array, $dirs); // appel recursif pour lire a l'interieur de ce sous-repertoire
    64                         } else { // si il s'agit d'un fichier
     59                                recursive_readdir($path, $array, $dirs);
     60                        } else {
    6561                                if(!$dirs) ${$array}[] = $path;
    6662                        }
     
    6965        closedir($dh);
    7066}
     67
     68// Parse le fichier de configuration
     69function XMLParse($xml) {
     70        $content = array();
     71        foreach ($xml as $nom => $elem) {
     72                if (trim($elem) == '') {
     73                        $content[$nom] = XMLParse($elem->children());
     74                } else {
     75                        $content[$nom] = utf8_encode(utf8_decode($elem));
     76                }
     77        }
     78        return $content;
     79}
     80
     81// Crée le fichier de configuration
     82function XMLCreate($array, $level) {
     83        $content = null;
     84        foreach ($array as $nom => $elem) {
     85                if (is_array($elem)) {
     86                        for($i=0;$i<=$level;$i++) $content .= "\t";
     87                        $content .= '<'.$nom.'>'."\n";
     88                        $content .= XMLCreate($elem, $level+1);
     89                        for($i=0;$i<=$level;$i++) $content .= "\t";
     90                        $content .= '</'.$nom.'>'."\n";
     91                } else {
     92                        for($i=0;$i<=$level;$i++) $content .= "\t";
     93                        $content .= '<'.$nom.'>'.$elem.'</'.$nom.'>'."\n";
     94                }
     95        }
     96        return $content;
     97}
     98
     99// Convertit les booléens, entiers et flotants d'un tableau de 'string'
     100function array_settype($array) {
     101        foreach ($array as $key => $value) {
     102                if (is_array($value)) {
     103                        $array[$key] = array_settype($value);
     104                } else {
     105                        if ($value === 'true') {
     106                                $array[$key] = true;           
     107                        } else if ($value === 'false') {
     108                                $array[$key] = false;           
     109                        } else if (preg_match('#^([0-9]*)$#', $value)) {
     110                                settype($array[$key], 'int');           
     111                        } else if (preg_match('#^([0-9]*)(.|,)([0-9]*)$#', $value)) {
     112                                settype($array[$key], 'float');         
     113                        }
     114                }
     115        }
     116               
     117        return $array;
     118}
     119
     120// Booléen vers français ou texte
     121function bool_to_string($bool, $just_echo=0) {
     122        # $just_echo pour pouvoir afficher un booléen tel quel
     123        if (is_bool($bool)) {
     124                if ($bool) {
     125                        if ($just_echo) return 'true';
     126                        else return 'oui';
     127                } else {
     128                        if ($just_echo) return 'false';
     129                        else return 'non';
     130                }
     131        } else {
     132                return $bool;
     133        }
     134}
    71135?>
  • extensions/PHP_Optimisateur/files/style.css

    r7988 r7991  
    66
    77body {
    8         font-size:12px;
    9         font-family:Verdanna;
     8        font-size:13px;
     9        font-family:Calibri,sans-serif;
    1010        background:#eee;
    1111        color:#333;
     12        width:990px;
     13        margin:0 auto;
    1214}
    1315
    1416div {
    15         width:40%;
     17        width:450px;
    1618        margin:10px;
    1719        padding:10px;
    1820        border:1px dotted #333;
    1921        float:left;
     22}
     23
     24a {
     25        color:#EF9700;
     26        text-decoration:none;
     27        padding:0 10px;
     28        float:right;
     29        margin-bottom:1px;
     30}
     31a:hover {
     32        color:#555;
     33        border-bottom:1px dotted #555;
     34        margin-bottom:0;
    2035}
    2136
     
    3449}
    3550
    36 .title {
    37         width:80%;
     51div.title {
     52        float:none;
     53        width:902px;
    3854        padding:10px 30px;
    3955        font-weight:bold;
     
    5975        font-size:1.2em;
    6076}
     77
     78input {
     79        border:1px solid #888;
     80        -moz-border-radius:3px;
     81}
     82
     83b.new:after {
     84        content:' New !';
     85        color:#0ABF00;
     86        font-style:italic;
     87}
     88
     89span.title {
     90        font-weight:bold;
     91        text-decoration:underline;
     92        font-size:1.1em;
     93}
     94
     95td {
     96        width:50%;
     97}
     98tr td:first-child {
     99        text-align:right;
     100        padding-right:5px;
     101}
  • extensions/PHP_Optimisateur/index.php

    r7988 r7991  
    22/***************************************\
    33|                       PHP OPTIMISATEUR                        |
    4 |                          Version 1.0                          |
     4|                          Version 1.1                          |
    55\***************************************/
    66
     
    88$TIME_START = microtime(true);
    99
    10 echo '<?xml version="1.0" encoding="utf-8"?>
    11 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    12         "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    13 <html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
    14 <head>
    15         <link rel="stylesheet" type="text/css" media="screen" href="files/style.css" />
    16         <title>PHP Optimisateur 1.0</title>
    17 </head>
    18 <body>
    19 <div class="title">PHP Optimisateur 1.0</div>';
    20 
    21 include('config.php');
     10include('files/header.php');
    2211include('files/functions.php');
    2312
    2413
    25 ### Erreurs fatales ###
    26 if (!is_int($DIMhd) || !is_int($DIMnormal) || !is_int($DIMthumbnail) || !is_int($Qhd) || !is_int($Qnormal) || !is_int($Qthumbnail) ||
    27                 !is_bool($silentORNOT) || !is_bool($DIRhighORNOT) || !is_bool($DIMhdORNOT) || !is_bool($renameORNOT) || !is_bool($indexORNOT) || !is_string($prefixe_mini)) {
    28         die('<div class="error">Erreur fatale : Configuration incorrecte. <a href="index.php">Retour</a></div>');
    29 }
    30 
     14
     15### DEMARRAGE ###
     16// Fichier de configuration
     17if (!file_exists('config.xml')) {
     18        die('<div class="error">Erreur fatale : Fichier de configuration introuvable. <a href="index.php">Retour</a></div>');
     19}
     20
     21// Configuration
     22$config = simplexml_load_file('config.xml');
     23$config = XMLParse($config);
     24$config = array_settype($config);
     25extract($config);
     26
     27// Afficher la configuration
     28if (!$silentORNOT) {
     29        include('files/display_config.php');
     30}
     31
     32// Dossiers
     33if (!file_exists($DIRsource)) {
     34        mkdir($DIRsource);
     35}
     36if (!file_exists($DIRsortie)) {
     37        mkdir($DIRsortie);
     38}
    3139if (is_dir_empty($DIRsource)) {
    32         die('<div class="error">Erreur fatale : Dossier source vide. <a href="index.php">Retour</a></div>');
    33 }
    34 
     40        die('<div class="error">Erreur fatale : Dossier source vide. <a href="index.php">Retour</a> <a href="setup.php">Configurer</a></div>');
     41}
    3542if ($silentORNOT) {
    36         rrmdir($DIRsortie);
    37         mkdir($DIRsortie);
     43        rrmdir($DIRsortie); // Si mode silencieux
     44        mkdir($DIRsortie); // vidage automatique du dossier de sortie
    3845} else if (!is_dir_empty($DIRsortie)) {
    39         die('<div class="error">Erreur fatale : Dossier de sortie non vide. <a href="index.php">Retour</a></div>');
    40 }
    41 
    42 
    43 if (!$silentORNOT AND isset($_GET['Process'])) {
    44 ### Supprimer les caractères spéciaux - dossiers & fichiers ###
    45 function recursive_delete_special_car($dir) {
    46         $dir = rtrim($dir, '/');
    47         $dh = opendir($dir);
    48        
    49         while (($file = readdir($dh)) !== false ) { //boucle pour parcourir le repertoire
    50                 if ($file !== '.' && $file !== '..') {
    51                         $path = $dir.'/'.$file;
    52                         $new_path = $dir.'/'.delete_special_car($file);
    53                         rename($path, $new_path);
     46        die('<div class="error">Erreur fatale : Dossier de sortie non vide. <a href="index.php">Retour</a> <a href="setup.php">Configurer</a></div>');
     47}
     48
     49
     50
     51### EXECUTION ###
     52if (isset($_GET['Process'])) {
     53
     54        ### Supprimer les caractères spéciaux - dossiers & fichiers ###
     55        if ($renameORNOT) {
     56                function recursive_delete_special_car($dir) {
     57                        $dir = rtrim($dir, '/');
     58                        $dh = opendir($dir);
    5459                       
    55                         if (is_dir($new_path)) { //si on tombe sur un sous-repertoire
    56                                 recursive_delete_special_car($new_path); // appel recursif pour lire a l'interieur de ce sous-repertoire
     60                        while (($file = readdir($dh)) !== false ) {
     61                                if ($file !== '.' && $file !== '..') {
     62                                        $path = $dir.'/'.$file;
     63                                        $new_path = $dir.'/'.delete_special_car($file);
     64                                        rename($path, $new_path);
     65                                       
     66                                        if (is_dir($new_path)) {
     67                                                recursive_delete_special_car($new_path);
     68                                        }
     69                                }
    5770                        }
    58                 }
    59         }
    60         closedir($dh);
    61 }
    62 
    63 recursive_delete_special_car($DIRsource);
    64 
    65 
    66 
    67 ### Copyright ###
    68 if ($copyONhd) {
    69         $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
    70 } else {
    71         $copyHD = null;
    72 }
    73 if ($copyONnormal) {
    74         $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
    75 } else {
    76         $copyNormal = null;
    77 }
    78 
    79 
    80 
    81 ### Plugins avant execution ###
    82 foreach ($PluginsBefore as $name => $config) {
    83         if ($config['active']) {
    84                 include('plugins/'.$name.'.php');
    85         }
    86 }
    87 
    88 
    89 
    90 ### Processus principal ###
    91 
    92 // Tableau avec les fichiers source
    93 $FilesSource = array();
    94 recursive_readdir($DIRsource, 'FilesSource');
    95 // Tableau avec les fichiers de sortie
    96 $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource);
    97 
    98 for ($i=0; $i<count($FilesSource); $i++) {
    99         // Découpe le nom de fichier : dossier/fichier
    100         preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches);
    101         # matches[1] = dossier sortie
    102         # matches[2] = fichier.ext
    103                
    104         // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
    105         if (!file_exists($matches[1].'/pwg_high') AND $DIRhighORNOT) {
    106                 mkdir($matches[1].'/pwg_high', 0777, true);
    107         }
    108         if (!file_exists($matches[1].'/thumbnail')) {
    109                 mkdir($matches[1].'/thumbnail', 0777, true);
    110         }
    111                
    112         // Plugins pendant l'execution
    113         foreach ($PluginsProcess as $name => $config) {
     71                        closedir($dh);
     72                }
     73
     74                recursive_delete_special_car($DIRsource);
     75        }
     76
     77
     78        ### Copyright ###
     79        if ($copyONhd) {
     80                $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
     81        } else {
     82                $copyHD = null;
     83        }
     84        if ($copyONnormal) {
     85                $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
     86        } else {
     87                $copyNormal = null;
     88        }
     89
     90
     91        ### Plugins avant execution ###
     92        foreach ($PluginsBefore as $name => $config) {
    11493                if ($config['active']) {
    11594                        include('plugins/'.$name.'.php');
    11695                }
    11796        }
     97
     98
     99        ### Processus principal ###
     100
     101        // Tableau avec les fichiers source
     102        $FilesSource = array();
     103        recursive_readdir($DIRsource, 'FilesSource');
     104        // Tableau avec les fichiers de sortie
     105        $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource);
     106
     107        for ($i=0; $i<count($FilesSource); $i++) {
     108                // Découpe le nom de fichier : dossier/fichier
     109                preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches);
     110                # matches[1] = dossier sortie
     111                # matches[2] = fichier.ext
     112                       
     113                // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
     114                if (!file_exists($matches[1].'/pwg_high') AND $DIRhighORNOT) {
     115                        mkdir($matches[1].'/pwg_high', 0777, true);
     116                }
     117                if (!file_exists($matches[1].'/thumbnail')) {
     118                        mkdir($matches[1].'/thumbnail', 0777, true);
     119                }
     120                       
     121                // Plugins pendant l'execution
     122                foreach ($PluginsProcess as $name => $config) {
     123                        if ($config['active']) {
     124                                include('plugins/'.$name.'.php');
     125                        }
     126                }
     127               
     128                // Compresse les fichiers dans le dossier de sortie
     129                if (!isset($BlockNormal)) {
     130                        exec('nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$matches[1].'/'.$matches[2].'" -dpi 72 -ratio -rtype lanczos -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"');
     131                }
     132                if (!isset($BlockThumbnail)) {
     133                        exec('nconvert.exe -q '.$Qthumbnail.' -out jpeg -o "'.$matches[1].'/thumbnail/'.$prefixe_mini.$matches[2].'" -dpi 72 -ratio -rtype lanczos -rflag decr -resize '.$DIMthumbnail.' '.$DIMthumbnail.' -rmeta -rexifthumb   "'.$FilesSource[$i].'"');
     134                }
     135                if ($DIRhighORNOT AND !isset($BlockHigh)) {
     136                        if ($DIMhdORNOT) {
     137                                exec('nconvert.exe -q '.$Qhd.' -out jpeg -o "'.$matches[1].'/pwg_high/'.$matches[2].'" -dpi '.$DPI.' -ratio -rtype lanczos -rflag decr -resize '.$DIMhd.' '.$DIMhd.' '.$copyHD.' "'.$FilesSource[$i].'"');
     138                        } else {
     139                                copy($FilesSource[$i], $matches[1].'/pwg_high/'.$matches[2]);
     140                        }
     141                }
     142               
     143                // Réinitialise les bloqueurs
     144                unset($BlockNormal);
     145                unset($BlockThumbnail);
     146                unset($BlockHigh);
     147
     148        }
     149
     150        if (!$silentORNOT) {
     151                echo '<div class="files">
     152                        <h2>Fichiers source</h2>
     153                        <ul>';
     154                                foreach ($FilesSource as $value) {
     155                                        echo '<li>'.$value.'</li>';
     156                                }
     157                        echo '</ul>
     158                        <i>'.count($FilesSource).' fichiers</i>
     159                </div>';
     160        }
     161
     162        unset($FilesSource);
     163        unset($FilesSortie);
     164
     165
     166        ### Supprime les dossiers vides et copie les fichiers index.php ###
     167        // Tableau avec les dossiers de sortie
     168        $DirsSortie = array();
     169        recursive_readdir($DIRsortie, 'DirsSortie', true);
     170
     171        foreach($DirsSortie as $dir) {
     172                if (is_dir_empty($dir)) {
     173                        rmdir($dir);
     174                } else if ($indexORNOT) {
     175                        copy('files/index.php', $dir.'/index.php');
     176                }
     177        }
     178
     179        unset($DirsSortie);
     180
     181
     182        ### Plugins après execution ###
     183        foreach ($PluginsAfter as $name => $config) {
     184                if ($config['active']) {
     185                        include('plugins/'.$name.'.php');
     186                }
     187        }
     188
     189
     190        echo '<div class="finish">Opération terminée : '.intval((microtime(true)-$TIME_START)) .' secondes. <a href="index.php">Retour</a> <a href="setup.php">Configurer</a></div>';
     191
    118192       
    119         // Compresse les fichiers dans le dossier de sortie
    120         if (!isset($BlockNormal)) {
    121                 exec('nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$matches[1].'/'.$matches[2].'" -dpi 72 -ratio -rtype lanczos -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"');
    122         }
    123         if (!isset($BlockThumbnail)) {
    124                 exec('nconvert.exe -q '.$Qthumbnail.' -out jpeg -o "'.$matches[1].'/thumbnail/'.$prefixe_mini.$matches[2].'" -dpi 72 -ratio -rtype lanczos -rflag decr -resize '.$DIMthumbnail.' '.$DIMthumbnail.' -rmeta -rexifthumb   "'.$FilesSource[$i].'"');
    125         }
    126         if ($DIRhighORNOT AND !isset($BlockHigh)) {
    127                 if ($DIMhdORNOT) {
    128                         exec('nconvert.exe -q '.$Qhd.' -out jpeg -o "'.$matches[1].'/pwg_high/'.$matches[2].'" -dpi '.$DPI.' -ratio -rtype lanczos -rflag decr -resize '.$DIMhd.' '.$DIMhd.' '.$copyHD.' "'.$FilesSource[$i].'"');
    129                 } else {
    130                         copy($FilesSource[$i], $matches[1].'/pwg_high/'.$matches[2]);
    131                 }
    132         }
    133193       
    134         // Réinitialise les bloqueurs
    135         unset($BlockNormal);
    136         unset($BlockThumbnail);
    137         unset($BlockHigh);
    138 
    139 }
    140 
    141 if (!$silentORNOT) {
    142         echo '<div class="files">
    143                 <h2>Fichiers source</h2>
    144                 <ul>';
    145                         foreach ($FilesSource as $value) {
    146                                 echo '<li>'.$value.'</li>';
    147                         }
    148                 echo '</ul>
    149                 <i>'.count($FilesSource).' fichiers</i>
    150         </div>';
    151 }
    152 
    153 unset($FilesSource);
    154 unset($FilesSortie);
    155 
    156 
    157 
    158 ### Supprime les dossiers vides et copie les fichiers index.php ###
    159 // Tableau avec les dossiers de sortie
    160 $DirsSortie = array();
    161 recursive_readdir($DIRsortie, 'DirsSortie', true);
    162 
    163 foreach($DirsSortie as $dir) {
    164         if (is_dir_empty($dir)) {
    165                 rmdir($dir);
    166         } else if ($indexORNOT) {
    167                 copy('files/index.php', $dir.'/index.php');
    168         }
    169 }
    170 
    171 unset($DirsSortie);
    172 
    173 
    174 
    175 ### Plugins après execution ###
    176 foreach ($PluginsAfter as $name => $config) {
    177         if ($config['active']) {
    178                 include('plugins/'.$name.'.php');
    179         }
    180 }
    181 
    182 
    183 
    184 echo '<div class="finish">Opération terminée : '.intval((microtime(true)-$TIME_START)) .' secondes. <a href="index.php">Retour</a></div>';
    185 
    186194} else {
    187 
    188 echo '<div class="finish">Prêt à commencer. <a href="index.php?Process=true">Exécuter</a></div>';
    189 
     195        echo '<div class="finish">Prêt à commencer. <a href="index.php?Process=true">Exécuter</a> <a href="setup.php">Configurer</a></div>';
    190196}
    191197
  • extensions/PHP_Optimisateur/plugins/convert_pan.php

    r7988 r7991  
    77## Crée des images normales plus hautes pour les panoramas (utilisation des paMOOrama par exemple)
    88## Crée des miniatures rognées pour ne pas avoir de minuscules images
    9 
    10 # PluginsProcess => 'convert_pan' => array('active' => true, 'DIMpanorama' => 500, 'NAMEpanorama' => '_pan', 'RatioPanThumb' => 1.7)
    119
    1210$NAMEpanorama = $PluginsProcess['convert_pan']['NAMEpanorama']; // Suffixe des panoramas
  • extensions/PHP_Optimisateur/plugins/create_folders_alpha.php

    r7988 r7991  
    77## Crée une arborescence alphanumérique dans la dossier source
    88## Ne supporte pas une arborescence pré-existante
    9 
    10 # PluginsBefore => 'create_folders_alpha' => array('active' => true)
    119
    1210$handle = opendir($DIRsource);
  • extensions/PHP_Optimisateur/plugins/front2back_support.php

    r7988 r7991  
    88## Crée la version alternative hd dans 'pwg_high/verso'
    99## Supprime le suffixe et déplace aussi les fichiers du repertoire source
    10 
    11 # PluginsProcess => 'front2back_support' => array('active' => true, 'NAMEverso' => '_verso')
    1210
    1311$NAMEverso = $PluginsProcess['front2back_support']['NAMEverso']; // Suffixe des versions alternatives
  • extensions/PHP_Optimisateur/plugins/watermark.php

    r7988 r7991  
    77## Replace le texte de copyright par une image
    88## Dépend des valeurs de $copyONhd, $copyONnormal et $copyPOS
    9 
    10 # PluginsBefore => 'watermark' => array('active' => true, 'waterFILE' => 'logo.png', 'waterALPHA' => 50)
    119
    1210$waterFILE = $PluginsBefore['watermark']['waterFILE']; // Fichier à incruster
Note: See TracChangeset for help on using the changeset viewer.