source: extensions/PHP_Optimisateur/index.php @ 8195

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