source: extensions/PHP_Optimisateur/index.php @ 8226

Last change on this file since 8226 was 8226, checked in by mistic100, 13 years ago
  • Corrections de bugs
  • Améliorations mineures
File size: 6.8 KB
RevLine 
[7988]1<?php
2/***************************************\
3|                       PHP OPTIMISATEUR                        |
[8195]4|                          Version 1.2                          |
[7988]5\***************************************/
6
[8226]7set_time_limit(7200);
[7988]8$TIME_START = microtime(true);
9
[7993]10include('files/functions.php');
[7991]11include('files/header.php');
[7988]12
13
[7991]14
15### DEMARRAGE ###
16// Fichier de configuration
17if (!file_exists('config.xml')) {
[7993]18        $Errors['ErrorFile'] = true;
19       
20} else {
21        // Configuration
22        extract(load_config());
[7988]23
[7993]24        // Afficher la configuration
[8195]25        include('files/display_config.php');
[7991]26
[7993]27        // Dossiers
28        if (!file_exists($DIRsource)) {
29                mkdir($DIRsource);
30        }
31        if (!file_exists($DIRsortie)) {
32                mkdir($DIRsortie);
33        }
34        if (is_dir_empty($DIRsource)) {
35                $Errors['ErrorFolderIn'] = true;
36        }
[8195]37        if (!is_dir_empty($DIRsortie) AND $silentORNOT == 'block') {
[7993]38                $Errors['ErrorFolderOut'] = true;
39        }
[8195]40        if (!file_exists('files\nconvert.exe')) {
41                $Errors['ErrorNconvert'] = true;
42        }
[7991]43}
44
[7993]45
[8195]46
[7993]47### ERREURS ###
48if (isset($Errors)) {
49        foreach ($Errors as $key => $null) {
[8195]50                echo '<div class="error">'.l10n($key).'</div>';
[7993]51        }
[8195]52        echo '<div class="link"><a href="index.php">&raquo; '.l10n('Back').'</a> <a href="setup.php">&raquo; '.l10n('Config').'</a></div>';
[7991]53}
[7988]54
55
[7991]56
57### EXECUTION ###
[7993]58if (isset($_GET['Process']) AND !isset($Errors)) {
[8195]59        // Si mode silencieux vidage automatique du dossier de sortie
60        if ($silentORNOT == 'erase') {
61                rrmdir($DIRsortie);
62                mkdir($DIRsortie);
63        }
[7991]64
[8195]65       
[7991]66        ### Supprimer les caractères spéciaux - dossiers & fichiers ###
[7993]67        // Les caractères '%' et '$' sont systématiquement échappés, ca génère des bugs dans les noms de fichiers
68        function recursive_delete_special_car($dir) {
69                $dir = rtrim($dir, '/');
70                $dh = opendir($dir);
71               
72                while (($file = readdir($dh)) !== false ) {
73                        if ($file !== '.' && $file !== '..') {
74                                $path = $dir.'/'.$file;
75                                $new_path = $dir.'/'.delete_special_car($file);
76                                rename($path, $new_path);
77                               
78                                if (is_dir($new_path)) {
79                                        recursive_delete_special_car($new_path);
[7991]80                                }
[7988]81                        }
82                }
[7993]83                closedir($dh);
[7988]84        }
85
[7993]86        recursive_delete_special_car($DIRsource);
[7988]87
[7993]88
[8195]89        ### Copyright & Options générales des conversion ###
[7994]90        $copyright = utf8_decode($copyright);
[8226]91        $copyCOLOR = hex2RGB(substr($copyCOLOR,1), true, ' ');
[7994]92       
[7991]93        if ($copyONhd) {
94                $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
95        } else {
96                $copyHD = null;
97        }
[7994]98       
[7991]99        if ($copyONnormal) {
100                $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
101        } else {
102                $copyNormal = null;
103        }
[8195]104       
105        $convOptions = '-ratio -rtype lanczos -rflag decr';
[7988]106
107
[7991]108        ### Plugins avant execution ###
109        foreach ($PluginsBefore as $name => $config) {
110                if ($config['active']) {
111                        include('plugins/'.$name.'.php');
112                }
[7988]113        }
114
115
[7991]116        ### Processus principal ###
117        // Tableau avec les fichiers source
118        $FilesSource = array();
119        recursive_readdir($DIRsource, 'FilesSource');
[8195]120       
[7991]121        // Tableau avec les fichiers de sortie
122        $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource);
[7988]123
[8195]124        // Boucle sur tous les fichiers
[7991]125        for ($i=0; $i<count($FilesSource); $i++) {
126                // Découpe le nom de fichier : dossier/fichier
127                preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches);
[8226]128                $FileFolder = $matches[1]; // dossier de sortie
129                $FileName = $matches[2]; // nom+ext fichier
[7991]130                       
131                // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
[8195]132                if (!file_exists($FileFolder.'/pwg_high') AND $DIRhighORNOT) {
133                        mkdir($FileFolder.'/pwg_high', 0777, true);
[7991]134                }
[8195]135                if (!file_exists($FileFolder.'/thumbnail')) {
136                        mkdir($FileFolder.'/thumbnail', 0777, true);
[7991]137                }
[8195]138               
139                // Informations sur le fichier
140                exec('files\nconvert.exe -info "'.$FilesSource[$i].'"', $FileInfos);
141                for ($m=0; $m<=5; $m++) {
142                        unset($FileInfos[$m]);
143                }
144                foreach ($FileInfos as $key) {
145                        $a = explode(':', $key);
146                        $FileInfos[trim($a[0])] = trim($a[1]);
147                }
[7991]148                       
149                // Plugins pendant l'execution
150                foreach ($PluginsProcess as $name => $config) {
151                        if ($config['active']) {
152                                include('plugins/'.$name.'.php');
153                        }
154                }
[7988]155               
[7991]156                // Compresse les fichiers dans le dossier de sortie
157                if (!isset($BlockNormal)) { 
[8195]158                        exec('files\nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$FileFolder.'/'.$FileName.'" -dpi 72 '.$convOptions.' -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"');
[7988]159                }
[7991]160                if (!isset($BlockThumbnail)) { 
[8226]161                        exec('files\nconvert.exe -q '.$Qthumbnail.' -out jpeg -o "'.$FileFolder.'/thumbnail/'.$prefixe_mini.$FileName.'" -dpi 72 '.$convOptions.' -resize '.$DIMthumbnail.' '.$DIMthumbnail.' -rmeta -rexifthumb "'.$FilesSource[$i].'"');
[7988]162                }
[8195]163                if (!isset($BlockHigh) AND $DIRhighORNOT) {
[7991]164                        if ($DIMhdORNOT) {
[8195]165                                exec('files\nconvert.exe -q '.$Qhd.' -out jpeg -o "'.$FileFolder.'/pwg_high/'.$FileName.'" -dpi '.$DPI.' '.$convOptions.' -resize '.$DIMhd.' '.$DIMhd.' '.$copyHD.' "'.$FilesSource[$i].'"');
[7991]166                        } else {
[8195]167                                copy($FilesSource[$i], $FileFolder.'/pwg_high/'.$FileName);
[7991]168                        }
169                }
170               
171                // Réinitialise les bloqueurs
[8195]172                unset($FileInfos);
[7991]173                unset($BlockNormal);
174                unset($BlockThumbnail);
175                unset($BlockHigh);
[7988]176        }
177
[8195]178       
179        ### Affichage des fichiers traités ###
180        echo '<div class="files">
181                <h2>'.l10n('Source files').'</h2>
182                <ul>';
183                        foreach ($FilesSource as $value) {
184                                echo '<li>'.$value.'</li>';
185                        }
186                echo '</ul>
187                <i>'.l10n('%d files', count($FilesSource)).'</i>
188        </div>';
[7988]189
[7991]190        unset($FilesSource);
191        unset($FilesSortie);
[7988]192
193
[7991]194        ### Supprime les dossiers vides et copie les fichiers index.php ###
195        $DirsSortie = array();
196        recursive_readdir($DIRsortie, 'DirsSortie', true);
[7988]197
[7991]198        foreach($DirsSortie as $dir) {
199                if (is_dir_empty($dir)) {
200                        rmdir($dir);
201                } else if ($indexORNOT) {
202                        copy('files/index.php', $dir.'/index.php');
203                }
[7988]204        }
205
[7991]206        unset($DirsSortie);
[7988]207
208
[7991]209        ### Plugins après execution ###
210        foreach ($PluginsAfter as $name => $config) {
211                if ($config['active']) {
212                        include('plugins/'.$name.'.php');
213                }
[7988]214        }
215
216
[8195]217        ### Message final ###
218        echo '<div class="finish">'.l10n('Finish %d seconds', intval((microtime(true)-$TIME_START))).'</div>
219        <div class="link"><a href="index.php">&raquo; '.l10n('Back').'</a> <a href="setup.php">&raquo; '.l10n('Config').'</a></div>';
[7988]220
[7991]221       
222       
[8195]223### READY ###
[7993]224} else if (!isset($Errors)) {
[8195]225        echo '<div class="finish">'.l10n('Ready').' <span id="loader" style="display:none;float:right;margin:-8px 0 -10px 0;"><img src="files/loader.gif" /></span></div>
226        <div class="link"><a href="index.php?Process=true" onClick="document.getElementById(\'loader\').style.display=\'block\';">&raquo; '.l10n('Launch').'</a> <a href="setup.php">&raquo; '.l10n('Config').'</a></div>';
[7988]227}
228
[8195]229
230
231### FIN ###
232echo '<div class="footer">
233        2010 - <a href="http://www.strangeplanet.fr">Damien Sorel</a> - <a href="http://fr.piwigo.org/forum/viewtopic.php?id=19117">Forum</a>
234</div>
235
236</body>
[7988]237</html>';
238?>
Note: See TracBrowser for help on using the repository browser.