source: extensions/PHP_Optimisateur/index.php @ 7994

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

minor fix : bug with © symbol

File size: 5.9 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        $copyright = utf8_decode($copyright);
88       
89        if ($copyONhd) {
90                $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
91        } else {
92                $copyHD = null;
93        }
94       
95        if ($copyONnormal) {
96                $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"';
97        } else {
98                $copyNormal = null;
99        }
100
101
102        ### Plugins avant execution ###
103        foreach ($PluginsBefore as $name => $config) {
104                if ($config['active']) {
105                        include('plugins/'.$name.'.php');
106                }
107        }
108
109
110        ### Processus principal ###
111
112        // Tableau avec les fichiers source
113        $FilesSource = array();
114        recursive_readdir($DIRsource, 'FilesSource');
115        // Tableau avec les fichiers de sortie
116        $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource);
117
118        for ($i=0; $i<count($FilesSource); $i++) {
119                // Découpe le nom de fichier : dossier/fichier
120                preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches);
121                # matches[1] = dossier sortie
122                # matches[2] = fichier.ext
123                       
124                // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
125                if (!file_exists($matches[1].'/pwg_high') AND $DIRhighORNOT) {
126                        mkdir($matches[1].'/pwg_high', 0777, true);
127                }
128                if (!file_exists($matches[1].'/thumbnail')) {
129                        mkdir($matches[1].'/thumbnail', 0777, true);
130                }
131                       
132                // Plugins pendant l'execution
133                foreach ($PluginsProcess as $name => $config) {
134                        if ($config['active']) {
135                                include('plugins/'.$name.'.php');
136                        }
137                }
138               
139                // Compresse les fichiers dans le dossier de sortie
140                if (!isset($BlockNormal)) { 
141                        exec('nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$matches[1].'/'.$matches[2].'" -dpi 72 -ratio -rtype lanczos -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"');
142                }
143                if (!isset($BlockThumbnail)) { 
144                        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].'"');
145                }
146                if ($DIRhighORNOT AND !isset($BlockHigh)) {
147                        if ($DIMhdORNOT) {
148                                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].'"');
149                        } else {
150                                copy($FilesSource[$i], $matches[1].'/pwg_high/'.$matches[2]);
151                        }
152                }
153               
154                // Réinitialise les bloqueurs
155                unset($BlockNormal);
156                unset($BlockThumbnail);
157                unset($BlockHigh);
158
159        }
160
161        if (!$silentORNOT) {
162                echo '<div class="files">
163                        <h2>'.l10n('Source files').'</h2>
164                        <ul>';
165                                foreach ($FilesSource as $value) {
166                                        echo '<li>'.$value.'</li>';
167                                }
168                        echo '</ul>
169                        <i>'.l10n('%d files', count($FilesSource)).'</i>
170                </div>';
171        }
172
173        unset($FilesSource);
174        unset($FilesSortie);
175
176
177        ### Supprime les dossiers vides et copie les fichiers index.php ###
178        // Tableau avec les dossiers de sortie
179        $DirsSortie = array();
180        recursive_readdir($DIRsortie, 'DirsSortie', true);
181
182        foreach($DirsSortie as $dir) {
183                if (is_dir_empty($dir)) {
184                        rmdir($dir);
185                } else if ($indexORNOT) {
186                        copy('files/index.php', $dir.'/index.php');
187                }
188        }
189
190        unset($DirsSortie);
191
192
193        ### Plugins après execution ###
194        foreach ($PluginsAfter as $name => $config) {
195                if ($config['active']) {
196                        include('plugins/'.$name.'.php');
197                }
198        }
199
200
201        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>';
202
203       
204       
205} else if (!isset($Errors)) {
206        echo '<div class="finish">'.l10n('Ready').' <a href="index.php?Process=true">'.l10n('Launch').'</a> <a href="setup.php">'.l10n('Config').'</a></div>';
207}
208
209echo '</body>
210</html>';
211?>
Note: See TracBrowser for help on using the repository browser.