[7988] | 1 | <?php |
---|
| 2 | /***************************************\ |
---|
| 3 | | PHP OPTIMISATEUR | |
---|
| 4 | | Version 1.0 | |
---|
| 5 | \***************************************/ |
---|
| 6 | |
---|
| 7 | set_time_limit(3600); |
---|
| 8 | $TIME_START = microtime(true); |
---|
| 9 | |
---|
| 10 | echo '<?xml version="1.0" encoding="utf-8"?> |
---|
| 11 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
---|
| 12 | "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
---|
| 13 | <html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr"> |
---|
| 14 | <head> |
---|
| 15 | <link rel="stylesheet" type="text/css" media="screen" href="files/style.css" /> |
---|
| 16 | <title>PHP Optimisateur 1.0</title> |
---|
| 17 | </head> |
---|
| 18 | <body> |
---|
| 19 | <div class="title">PHP Optimisateur 1.0</div>'; |
---|
| 20 | |
---|
| 21 | include('config.php'); |
---|
| 22 | include('files/functions.php'); |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | ### Erreurs fatales ### |
---|
| 26 | if (!is_int($DIMhd) || !is_int($DIMnormal) || !is_int($DIMthumbnail) || !is_int($Qhd) || !is_int($Qnormal) || !is_int($Qthumbnail) || |
---|
| 27 | !is_bool($silentORNOT) || !is_bool($DIRhighORNOT) || !is_bool($DIMhdORNOT) || !is_bool($renameORNOT) || !is_bool($indexORNOT) || !is_string($prefixe_mini)) { |
---|
| 28 | die('<div class="error">Erreur fatale : Configuration incorrecte. <a href="index.php">Retour</a></div>'); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | if (is_dir_empty($DIRsource)) { |
---|
| 32 | die('<div class="error">Erreur fatale : Dossier source vide. <a href="index.php">Retour</a></div>'); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | if ($silentORNOT) { |
---|
| 36 | rrmdir($DIRsortie); |
---|
| 37 | mkdir($DIRsortie); |
---|
| 38 | } else if (!is_dir_empty($DIRsortie)) { |
---|
| 39 | die('<div class="error">Erreur fatale : Dossier de sortie non vide. <a href="index.php">Retour</a></div>'); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | if (!$silentORNOT AND isset($_GET['Process'])) { |
---|
| 44 | ### Supprimer les caractères spéciaux - dossiers & fichiers ### |
---|
| 45 | function recursive_delete_special_car($dir) { |
---|
| 46 | $dir = rtrim($dir, '/'); |
---|
| 47 | $dh = opendir($dir); |
---|
| 48 | |
---|
| 49 | while (($file = readdir($dh)) !== false ) { //boucle pour parcourir le repertoire |
---|
| 50 | if ($file !== '.' && $file !== '..') { |
---|
| 51 | $path = $dir.'/'.$file; |
---|
| 52 | $new_path = $dir.'/'.delete_special_car($file); |
---|
| 53 | rename($path, $new_path); |
---|
| 54 | |
---|
| 55 | if (is_dir($new_path)) { //si on tombe sur un sous-repertoire |
---|
| 56 | recursive_delete_special_car($new_path); // appel recursif pour lire a l'interieur de ce sous-repertoire |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | closedir($dh); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | recursive_delete_special_car($DIRsource); |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | ### Copyright ### |
---|
| 68 | if ($copyONhd) { |
---|
| 69 | $copyHD = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"'; |
---|
| 70 | } else { |
---|
| 71 | $copyHD = null; |
---|
| 72 | } |
---|
| 73 | if ($copyONnormal) { |
---|
| 74 | $copyNormal = '-text_font "'.$copyFONT.'" '.$DIMnormal*$copySIZE.' -text_color '.$copyCOLOR.' -text_flag '.$copyPOS.' -text_pos 0 0 -text "'.$copyright.'"'; |
---|
| 75 | } else { |
---|
| 76 | $copyNormal = null; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | ### Plugins avant execution ### |
---|
| 82 | foreach ($PluginsBefore as $name => $config) { |
---|
| 83 | if ($config['active']) { |
---|
| 84 | include('plugins/'.$name.'.php'); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | ### Processus principal ### |
---|
| 91 | |
---|
| 92 | // Tableau avec les fichiers source |
---|
| 93 | $FilesSource = array(); |
---|
| 94 | recursive_readdir($DIRsource, 'FilesSource'); |
---|
| 95 | // Tableau avec les fichiers de sortie |
---|
| 96 | $FilesSortie = str_replace($DIRsource, $DIRsortie, $FilesSource); |
---|
| 97 | |
---|
| 98 | for ($i=0; $i<count($FilesSource); $i++) { |
---|
| 99 | // Découpe le nom de fichier : dossier/fichier |
---|
| 100 | preg_match('#(.*)/(.*)$#', $FilesSortie[$i], $matches); |
---|
| 101 | # matches[1] = dossier sortie |
---|
| 102 | # matches[2] = fichier.ext |
---|
| 103 | |
---|
| 104 | // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail' |
---|
| 105 | if (!file_exists($matches[1].'/pwg_high') AND $DIRhighORNOT) { |
---|
| 106 | mkdir($matches[1].'/pwg_high', 0777, true); |
---|
| 107 | } |
---|
| 108 | if (!file_exists($matches[1].'/thumbnail')) { |
---|
| 109 | mkdir($matches[1].'/thumbnail', 0777, true); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // Plugins pendant l'execution |
---|
| 113 | foreach ($PluginsProcess as $name => $config) { |
---|
| 114 | if ($config['active']) { |
---|
| 115 | include('plugins/'.$name.'.php'); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | // Compresse les fichiers dans le dossier de sortie |
---|
| 120 | if (!isset($BlockNormal)) { |
---|
| 121 | exec('nconvert.exe -q '.$Qnormal.' -out jpeg -o "'.$matches[1].'/'.$matches[2].'" -dpi 72 -ratio -rtype lanczos -resize '.$DIMnormal.' '.$DIMnormal.' '.$copyNormal.' "'.$FilesSource[$i].'"'); |
---|
| 122 | } |
---|
| 123 | if (!isset($BlockThumbnail)) { |
---|
| 124 | 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].'"'); |
---|
| 125 | } |
---|
| 126 | if ($DIRhighORNOT AND !isset($BlockHigh)) { |
---|
| 127 | if ($DIMhdORNOT) { |
---|
| 128 | 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].'"'); |
---|
| 129 | } else { |
---|
| 130 | copy($FilesSource[$i], $matches[1].'/pwg_high/'.$matches[2]); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | // Réinitialise les bloqueurs |
---|
| 135 | unset($BlockNormal); |
---|
| 136 | unset($BlockThumbnail); |
---|
| 137 | unset($BlockHigh); |
---|
| 138 | |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if (!$silentORNOT) { |
---|
| 142 | echo '<div class="files"> |
---|
| 143 | <h2>Fichiers source</h2> |
---|
| 144 | <ul>'; |
---|
| 145 | foreach ($FilesSource as $value) { |
---|
| 146 | echo '<li>'.$value.'</li>'; |
---|
| 147 | } |
---|
| 148 | echo '</ul> |
---|
| 149 | <i>'.count($FilesSource).' fichiers</i> |
---|
| 150 | </div>'; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | unset($FilesSource); |
---|
| 154 | unset($FilesSortie); |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | ### Supprime les dossiers vides et copie les fichiers index.php ### |
---|
| 159 | // Tableau avec les dossiers de sortie |
---|
| 160 | $DirsSortie = array(); |
---|
| 161 | recursive_readdir($DIRsortie, 'DirsSortie', true); |
---|
| 162 | |
---|
| 163 | foreach($DirsSortie as $dir) { |
---|
| 164 | if (is_dir_empty($dir)) { |
---|
| 165 | rmdir($dir); |
---|
| 166 | } else if ($indexORNOT) { |
---|
| 167 | copy('files/index.php', $dir.'/index.php'); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | unset($DirsSortie); |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | ### Plugins après execution ### |
---|
| 176 | foreach ($PluginsAfter as $name => $config) { |
---|
| 177 | if ($config['active']) { |
---|
| 178 | include('plugins/'.$name.'.php'); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | echo '<div class="finish">Opération terminée : '.intval((microtime(true)-$TIME_START)) .' secondes. <a href="index.php">Retour</a></div>'; |
---|
| 185 | |
---|
| 186 | } else { |
---|
| 187 | |
---|
| 188 | echo '<div class="finish">Prêt à commencer. <a href="index.php?Process=true">Exécuter</a></div>'; |
---|
| 189 | |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | echo '</body> |
---|
| 193 | </html>'; |
---|
| 194 | ?> |
---|