[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 | |
---|
[7991] | 10 | include('files/header.php'); |
---|
[7988] | 11 | include('files/functions.php'); |
---|
| 12 | |
---|
| 13 | |
---|
[7991] | 14 | |
---|
| 15 | ### DEMARRAGE ### |
---|
| 16 | // Fichier de configuration |
---|
| 17 | if (!file_exists('config.xml')) { |
---|
| 18 | die('<div class="error">Erreur fatale : Fichier de configuration introuvable. <a href="index.php">Retour</a></div>'); |
---|
[7988] | 19 | } |
---|
| 20 | |
---|
[7991] | 21 | // Configuration |
---|
| 22 | $config = simplexml_load_file('config.xml'); |
---|
| 23 | $config = XMLParse($config); |
---|
| 24 | $config = array_settype($config); |
---|
| 25 | extract($config); |
---|
| 26 | |
---|
| 27 | // Afficher la configuration |
---|
| 28 | if (!$silentORNOT) { |
---|
| 29 | include('files/display_config.php'); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | // Dossiers |
---|
| 33 | if (!file_exists($DIRsource)) { |
---|
| 34 | mkdir($DIRsource); |
---|
| 35 | } |
---|
| 36 | if (!file_exists($DIRsortie)) { |
---|
| 37 | mkdir($DIRsortie); |
---|
| 38 | } |
---|
[7988] | 39 | if (is_dir_empty($DIRsource)) { |
---|
[7991] | 40 | die('<div class="error">Erreur fatale : Dossier source vide. <a href="index.php">Retour</a> <a href="setup.php">Configurer</a></div>'); |
---|
[7988] | 41 | } |
---|
| 42 | if ($silentORNOT) { |
---|
[7991] | 43 | rrmdir($DIRsortie); // Si mode silencieux |
---|
| 44 | mkdir($DIRsortie); // vidage automatique du dossier de sortie |
---|
[7988] | 45 | } else if (!is_dir_empty($DIRsortie)) { |
---|
[7991] | 46 | die('<div class="error">Erreur fatale : Dossier de sortie non vide. <a href="index.php">Retour</a> <a href="setup.php">Configurer</a></div>'); |
---|
[7988] | 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
[7991] | 50 | |
---|
| 51 | ### EXECUTION ### |
---|
| 52 | if (isset($_GET['Process'])) { |
---|
| 53 | |
---|
| 54 | ### Supprimer les caractères spéciaux - dossiers & fichiers ### |
---|
| 55 | if ($renameORNOT) { |
---|
| 56 | function recursive_delete_special_car($dir) { |
---|
| 57 | $dir = rtrim($dir, '/'); |
---|
| 58 | $dh = opendir($dir); |
---|
[7988] | 59 | |
---|
[7991] | 60 | while (($file = readdir($dh)) !== false ) { |
---|
| 61 | if ($file !== '.' && $file !== '..') { |
---|
| 62 | $path = $dir.'/'.$file; |
---|
| 63 | $new_path = $dir.'/'.delete_special_car($file); |
---|
| 64 | rename($path, $new_path); |
---|
| 65 | |
---|
| 66 | if (is_dir($new_path)) { |
---|
| 67 | recursive_delete_special_car($new_path); |
---|
| 68 | } |
---|
| 69 | } |
---|
[7988] | 70 | } |
---|
[7991] | 71 | closedir($dh); |
---|
[7988] | 72 | } |
---|
[7991] | 73 | |
---|
| 74 | recursive_delete_special_car($DIRsource); |
---|
[7988] | 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
[7991] | 78 | ### Copyright ### |
---|
| 79 | if ($copyONhd) { |
---|
| 80 | $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"'; |
---|
| 81 | } else { |
---|
| 82 | $copyHD = null; |
---|
| 83 | } |
---|
| 84 | if ($copyONnormal) { |
---|
| 85 | $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"'; |
---|
| 86 | } else { |
---|
| 87 | $copyNormal = null; |
---|
| 88 | } |
---|
[7988] | 89 | |
---|
| 90 | |
---|
[7991] | 91 | ### Plugins avant execution ### |
---|
| 92 | foreach ($PluginsBefore as $name => $config) { |
---|
| 93 | if ($config['active']) { |
---|
| 94 | include('plugins/'.$name.'.php'); |
---|
| 95 | } |
---|
[7988] | 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
[7991] | 99 | ### Processus principal ### |
---|
[7988] | 100 | |
---|
[7991] | 101 | // Tableau avec les fichiers source |
---|
| 102 | $FilesSource = array(); |
---|
| 103 | recursive_readdir($DIRsource, 'FilesSource'); |
---|
| 104 | // Tableau avec les fichiers de sortie |
---|
| 105 | $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource); |
---|
[7988] | 106 | |
---|
[7991] | 107 | for ($i=0; $i<count($FilesSource); $i++) { |
---|
| 108 | // Découpe le nom de fichier : dossier/fichier |
---|
| 109 | preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches); |
---|
| 110 | # matches[1] = dossier sortie |
---|
| 111 | # matches[2] = fichier.ext |
---|
| 112 | |
---|
| 113 | // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail' |
---|
| 114 | if (!file_exists($matches[1].'/pwg_high') AND $DIRhighORNOT) { |
---|
| 115 | mkdir($matches[1].'/pwg_high', 0777, true); |
---|
| 116 | } |
---|
| 117 | if (!file_exists($matches[1].'/thumbnail')) { |
---|
| 118 | mkdir($matches[1].'/thumbnail', 0777, true); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // Plugins pendant l'execution |
---|
| 122 | foreach ($PluginsProcess as $name => $config) { |
---|
| 123 | if ($config['active']) { |
---|
| 124 | include('plugins/'.$name.'.php'); |
---|
| 125 | } |
---|
| 126 | } |
---|
[7988] | 127 | |
---|
[7991] | 128 | // Compresse les fichiers dans le dossier de sortie |
---|
| 129 | if (!isset($BlockNormal)) { |
---|
| 130 | exec('nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$matches[1].'/'.$matches[2].'" -dpi 72 -ratio -rtype lanczos -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"'); |
---|
[7988] | 131 | } |
---|
[7991] | 132 | if (!isset($BlockThumbnail)) { |
---|
| 133 | 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] | 134 | } |
---|
[7991] | 135 | if ($DIRhighORNOT AND !isset($BlockHigh)) { |
---|
| 136 | if ($DIMhdORNOT) { |
---|
| 137 | 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].'"'); |
---|
| 138 | } else { |
---|
| 139 | copy($FilesSource[$i], $matches[1].'/pwg_high/'.$matches[2]); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | // Réinitialise les bloqueurs |
---|
| 144 | unset($BlockNormal); |
---|
| 145 | unset($BlockThumbnail); |
---|
| 146 | unset($BlockHigh); |
---|
| 147 | |
---|
[7988] | 148 | } |
---|
| 149 | |
---|
[7991] | 150 | if (!$silentORNOT) { |
---|
| 151 | echo '<div class="files"> |
---|
| 152 | <h2>Fichiers source</h2> |
---|
| 153 | <ul>'; |
---|
| 154 | foreach ($FilesSource as $value) { |
---|
| 155 | echo '<li>'.$value.'</li>'; |
---|
| 156 | } |
---|
| 157 | echo '</ul> |
---|
| 158 | <i>'.count($FilesSource).' fichiers</i> |
---|
| 159 | </div>'; |
---|
| 160 | } |
---|
[7988] | 161 | |
---|
[7991] | 162 | unset($FilesSource); |
---|
| 163 | unset($FilesSortie); |
---|
[7988] | 164 | |
---|
| 165 | |
---|
[7991] | 166 | ### Supprime les dossiers vides et copie les fichiers index.php ### |
---|
| 167 | // Tableau avec les dossiers de sortie |
---|
| 168 | $DirsSortie = array(); |
---|
| 169 | recursive_readdir($DIRsortie, 'DirsSortie', true); |
---|
[7988] | 170 | |
---|
[7991] | 171 | foreach($DirsSortie as $dir) { |
---|
| 172 | if (is_dir_empty($dir)) { |
---|
| 173 | rmdir($dir); |
---|
| 174 | } else if ($indexORNOT) { |
---|
| 175 | copy('files/index.php', $dir.'/index.php'); |
---|
| 176 | } |
---|
[7988] | 177 | } |
---|
| 178 | |
---|
[7991] | 179 | unset($DirsSortie); |
---|
[7988] | 180 | |
---|
| 181 | |
---|
[7991] | 182 | ### Plugins après execution ### |
---|
| 183 | foreach ($PluginsAfter as $name => $config) { |
---|
| 184 | if ($config['active']) { |
---|
| 185 | include('plugins/'.$name.'.php'); |
---|
| 186 | } |
---|
[7988] | 187 | } |
---|
| 188 | |
---|
| 189 | |
---|
[7991] | 190 | echo '<div class="finish">Opération terminée : '.intval((microtime(true)-$TIME_START)) .' secondes. <a href="index.php">Retour</a> <a href="setup.php">Configurer</a></div>'; |
---|
[7988] | 191 | |
---|
[7991] | 192 | |
---|
| 193 | |
---|
[7988] | 194 | } else { |
---|
[7991] | 195 | echo '<div class="finish">Prêt à commencer. <a href="index.php?Process=true">Exécuter</a> <a href="setup.php">Configurer</a></div>'; |
---|
[7988] | 196 | } |
---|
| 197 | |
---|
| 198 | echo '</body> |
---|
| 199 | </html>'; |
---|
| 200 | ?> |
---|