[7988] | 1 | <?php |
---|
| 2 | /***************************************\ |
---|
| 3 | | PHP OPTIMISATEUR | |
---|
[7991] | 4 | | Version 1.1 | |
---|
[7988] | 5 | \***************************************/ |
---|
| 6 | |
---|
| 7 | set_time_limit(3600); |
---|
| 8 | $TIME_START = microtime(true); |
---|
| 9 | |
---|
[7993] | 10 | include('files/functions.php'); |
---|
[7991] | 11 | include('files/header.php'); |
---|
[7988] | 12 | |
---|
| 13 | |
---|
[7991] | 14 | |
---|
| 15 | ### DEMARRAGE ### |
---|
| 16 | // Fichier de configuration |
---|
| 17 | if (!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 |
---|
| 25 | if (!$silentORNOT) { |
---|
| 26 | include('files/display_config.php'); |
---|
| 27 | } |
---|
[7991] | 28 | |
---|
[7993] | 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 | } |
---|
[7991] | 45 | } |
---|
| 46 | |
---|
[7993] | 47 | |
---|
| 48 | ### ERREURS ### |
---|
| 49 | if (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 | } |
---|
[7991] | 56 | } |
---|
[7988] | 57 | |
---|
| 58 | |
---|
[7991] | 59 | |
---|
| 60 | ### EXECUTION ### |
---|
[7993] | 61 | if (isset($_GET['Process']) AND !isset($Errors)) { |
---|
[7991] | 62 | |
---|
| 63 | ### Supprimer les caractères spéciaux - dossiers & fichiers ### |
---|
[7993] | 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); |
---|
[7991] | 77 | } |
---|
[7988] | 78 | } |
---|
| 79 | } |
---|
[7993] | 80 | closedir($dh); |
---|
[7988] | 81 | } |
---|
| 82 | |
---|
[7993] | 83 | recursive_delete_special_car($DIRsource); |
---|
[7988] | 84 | |
---|
[7993] | 85 | |
---|
[7991] | 86 | ### Copyright ### |
---|
[7994] | 87 | $copyright = utf8_decode($copyright); |
---|
| 88 | |
---|
[7991] | 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 | } |
---|
[7994] | 94 | |
---|
[7991] | 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 | } |
---|
[7988] | 100 | |
---|
| 101 | |
---|
[7991] | 102 | ### Plugins avant execution ### |
---|
| 103 | foreach ($PluginsBefore as $name => $config) { |
---|
| 104 | if ($config['active']) { |
---|
| 105 | include('plugins/'.$name.'.php'); |
---|
| 106 | } |
---|
[7988] | 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[7991] | 110 | ### Processus principal ### |
---|
[7988] | 111 | |
---|
[7991] | 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); |
---|
[7988] | 117 | |
---|
[7991] | 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 | } |
---|
[7988] | 138 | |
---|
[7991] | 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].'"'); |
---|
[7988] | 142 | } |
---|
[7991] | 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].'"'); |
---|
[7988] | 145 | } |
---|
[7991] | 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 | |
---|
[7988] | 159 | } |
---|
| 160 | |
---|
[7991] | 161 | if (!$silentORNOT) { |
---|
| 162 | echo '<div class="files"> |
---|
[7993] | 163 | <h2>'.l10n('Source files').'</h2> |
---|
[7991] | 164 | <ul>'; |
---|
| 165 | foreach ($FilesSource as $value) { |
---|
| 166 | echo '<li>'.$value.'</li>'; |
---|
| 167 | } |
---|
| 168 | echo '</ul> |
---|
[7993] | 169 | <i>'.l10n('%d files', count($FilesSource)).'</i> |
---|
[7991] | 170 | </div>'; |
---|
| 171 | } |
---|
[7988] | 172 | |
---|
[7991] | 173 | unset($FilesSource); |
---|
| 174 | unset($FilesSortie); |
---|
[7988] | 175 | |
---|
| 176 | |
---|
[7991] | 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); |
---|
[7988] | 181 | |
---|
[7991] | 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 | } |
---|
[7988] | 188 | } |
---|
| 189 | |
---|
[7991] | 190 | unset($DirsSortie); |
---|
[7988] | 191 | |
---|
| 192 | |
---|
[7991] | 193 | ### Plugins après execution ### |
---|
| 194 | foreach ($PluginsAfter as $name => $config) { |
---|
| 195 | if ($config['active']) { |
---|
| 196 | include('plugins/'.$name.'.php'); |
---|
| 197 | } |
---|
[7988] | 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
[7993] | 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>'; |
---|
[7988] | 202 | |
---|
[7991] | 203 | |
---|
| 204 | |
---|
[7993] | 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>'; |
---|
[7988] | 207 | } |
---|
| 208 | |
---|
| 209 | echo '</body> |
---|
| 210 | </html>'; |
---|
| 211 | ?> |
---|