source: extensions/PHP_Optimisateur/index.php @ 7993

Last change on this file since 7993 was 7993, checked in by mistic100, 13 years ago

gestion des langues, ajout de l'anglais, correction de bugs mineurs

File size: 5.8 KB
Line 
1<?php
2/***************************************\
3|                       PHP OPTIMISATEUR                        |
4|                          Version 1.1                          |
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        if (!$silentORNOT) {
26                include('files/display_config.php');
27        }
28
29        // Dossiers
30        if (!file_exists($DIRsource)) {
31                mkdir($DIRsource);
32        }
33        if (!file_exists($DIRsortie)) {
34                mkdir($DIRsortie);
35        }
36        if (is_dir_empty($DIRsource)) {
37                $Errors['ErrorFolderIn'] = true;
38        }
39        if ($silentORNOT) {
40                rrmdir($DIRsortie); // Si mode silencieux
41                mkdir($DIRsortie); // vidage automatique du dossier de sortie
42        } else if (!is_dir_empty($DIRsortie)) {
43                $Errors['ErrorFolderOut'] = true;
44        }
45}
46
47
48### ERREURS ###
49if (isset($Errors)) {
50        $i=0;
51        foreach ($Errors as $key => $null) {
52                // Dégueulasse les ternaires à la suite ! mais j'aime ça
53                echo '<div class="error">'.l10n($key).' '.(($i==0)?'<a href="index.php">'.l10n('Back').'</a> '.(($key!='ErrorFile')?'<a href="setup.php">'.l10n('Config').'</a></div>':'</div>'):'</div>');
54                $i++;
55        }
56}
57
58
59
60### EXECUTION ###
61if (isset($_GET['Process']) AND !isset($Errors)) {
62
63        ### Supprimer les caractères spéciaux - dossiers & fichiers ###
64        // Les caractères '%' et '$' sont systématiquement échappés, ca génère des bugs dans les noms de fichiers
65        function recursive_delete_special_car($dir) {
66                $dir = rtrim($dir, '/');
67                $dh = opendir($dir);
68               
69                while (($file = readdir($dh)) !== false ) {
70                        if ($file !== '.' && $file !== '..') {
71                                $path = $dir.'/'.$file;
72                                $new_path = $dir.'/'.delete_special_car($file);
73                                rename($path, $new_path);
74                               
75                                if (is_dir($new_path)) {
76                                        recursive_delete_special_car($new_path);
77                                }
78                        }
79                }
80                closedir($dh);
81        }
82
83        recursive_delete_special_car($DIRsource);
84
85
86        ### Copyright ###
87        if ($copyONhd) {
88                $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
89        } else {
90                $copyHD = null;
91        }
92        if ($copyONnormal) {
93                $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
94        } else {
95                $copyNormal = null;
96        }
97
98
99        ### Plugins avant execution ###
100        foreach ($PluginsBefore as $name => $config) {
101                if ($config['active']) {
102                        include('plugins/'.$name.'.php');
103                }
104        }
105
106
107        ### Processus principal ###
108
109        // Tableau avec les fichiers source
110        $FilesSource = array();
111        recursive_readdir($DIRsource, 'FilesSource');
112        // Tableau avec les fichiers de sortie
113        $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource);
114
115        for ($i=0; $i<count($FilesSource); $i++) {
116                // Découpe le nom de fichier : dossier/fichier
117                preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches);
118                # matches[1] = dossier sortie
119                # matches[2] = fichier.ext
120                       
121                // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
122                if (!file_exists($matches[1].'/pwg_high') AND $DIRhighORNOT) {
123                        mkdir($matches[1].'/pwg_high', 0777, true);
124                }
125                if (!file_exists($matches[1].'/thumbnail')) {
126                        mkdir($matches[1].'/thumbnail', 0777, true);
127                }
128                       
129                // Plugins pendant l'execution
130                foreach ($PluginsProcess as $name => $config) {
131                        if ($config['active']) {
132                                include('plugins/'.$name.'.php');
133                        }
134                }
135               
136                // Compresse les fichiers dans le dossier de sortie
137                if (!isset($BlockNormal)) { 
138                        exec('nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$matches[1].'/'.$matches[2].'" -dpi 72 -ratio -rtype lanczos -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"');
139                }
140                if (!isset($BlockThumbnail)) { 
141                        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].'"');
142                }
143                if ($DIRhighORNOT AND !isset($BlockHigh)) {
144                        if ($DIMhdORNOT) {
145                                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].'"');
146                        } else {
147                                copy($FilesSource[$i], $matches[1].'/pwg_high/'.$matches[2]);
148                        }
149                }
150               
151                // Réinitialise les bloqueurs
152                unset($BlockNormal);
153                unset($BlockThumbnail);
154                unset($BlockHigh);
155
156        }
157
158        if (!$silentORNOT) {
159                echo '<div class="files">
160                        <h2>'.l10n('Source files').'</h2>
161                        <ul>';
162                                foreach ($FilesSource as $value) {
163                                        echo '<li>'.$value.'</li>';
164                                }
165                        echo '</ul>
166                        <i>'.l10n('%d files', count($FilesSource)).'</i>
167                </div>';
168        }
169
170        unset($FilesSource);
171        unset($FilesSortie);
172
173
174        ### Supprime les dossiers vides et copie les fichiers index.php ###
175        // Tableau avec les dossiers de sortie
176        $DirsSortie = array();
177        recursive_readdir($DIRsortie, 'DirsSortie', true);
178
179        foreach($DirsSortie as $dir) {
180                if (is_dir_empty($dir)) {
181                        rmdir($dir);
182                } else if ($indexORNOT) {
183                        copy('files/index.php', $dir.'/index.php');
184                }
185        }
186
187        unset($DirsSortie);
188
189
190        ### Plugins après execution ###
191        foreach ($PluginsAfter as $name => $config) {
192                if ($config['active']) {
193                        include('plugins/'.$name.'.php');
194                }
195        }
196
197
198        echo '<div class="finish">'.l10n('Finish %d seconds', intval((microtime(true)-$TIME_START))).' <a href="index.php">'.l10n('Back').'</a> <a href="setup.php">'.l10n('Config').'</a></div>';
199
200       
201       
202} else if (!isset($Errors)) {
203        echo '<div class="finish">'.l10n('Ready').' <a href="index.php?Process=true">'.l10n('Launch').'</a> <a href="setup.php">'.l10n('Config').'</a></div>';
204}
205
206echo '</body>
207</html>';
208?>
Note: See TracBrowser for help on using the repository browser.