[9201] | 1 | <?php |
---|
| 2 | // Si mode silencieux vidage automatique du dossier de sortie |
---|
| 3 | if ($CONF['silentORNOT'] == 'erase') { |
---|
| 4 | @rrmdir($CONF['DIRsortie']); |
---|
| 5 | @mkdir($CONF['DIRsortie']); |
---|
| 6 | } |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | ### Supprimer les caractères spéciaux - dossiers & fichiers ### |
---|
| 10 | // Les caractères '%' et '$' sont systématiquement échappés, ca génère des bugs dans les noms de fichiers |
---|
| 11 | function recursive_delete_special_car($dir) { |
---|
| 12 | $dir = rtrim($dir, '/'); |
---|
| 13 | $dh = opendir($dir); |
---|
| 14 | |
---|
| 15 | while (($file = readdir($dh)) !== false ) { |
---|
| 16 | if ($file !== '.' && $file !== '..') { |
---|
| 17 | $path = $dir.'/'.$file; |
---|
| 18 | $new_path = $dir.'/'.delete_special_car($file); |
---|
| 19 | rename($path, $new_path); |
---|
| 20 | |
---|
| 21 | if (is_dir($new_path)) { |
---|
| 22 | recursive_delete_special_car($new_path); |
---|
| 23 | } |
---|
| 24 | } |
---|
| 25 | } |
---|
| 26 | closedir($dh); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | recursive_delete_special_car($CONF['DIRsource']); |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | ### Copyright & Options générales des conversion ### |
---|
| 33 | $CONF['copyright'] = utf8_decode($CONF['copyright']); |
---|
| 34 | $CONF['copyCOLOR'] = hex2RGB(nice_hex_color($CONF['copyCOLOR']), true, ' '); |
---|
| 35 | |
---|
| 36 | if ($CONF['copyONhd']) { |
---|
| 37 | $CONF['copyHD'] = '-text_font "'.$CONF['copyFONT'].'" '.$CONF['DIMnormal']*$CONF['copySIZE'].' -text_color '.$CONF['copyCOLOR'].' -text_flag '.$CONF['copyPOS'].' -text_pos 0 0 -text "'.$CONF['copyright'].'"'; |
---|
| 38 | } else { |
---|
| 39 | $CONF['copyHD'] = null; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | if ($CONF['copyONnormal']) { |
---|
| 43 | $CONF['copyNormal'] = '-text_font "'.$CONF['copyFONT'].'" '.$CONF['DIMnormal']*$CONF['copySIZE'].' -text_color '.$CONF['copyCOLOR'].' -text_flag '.$CONF['copyPOS'].' -text_pos 0 0 -text "'.$CONF['copyright'].'"'; |
---|
| 44 | } else { |
---|
| 45 | $CONF['copyNormal'] = null; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | $CONF['convOptions'] = '-ratio -rtype lanczos -rflag decr'; |
---|
| 49 | $CONF['JPGexts'] = array('jpg', 'JPG', 'jpeg', 'JPEG'); // extensions admises pour le jpg |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | ### Plugins avant execution ### |
---|
| 53 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 54 | if ($plugin_config['mode'] == 'Before' AND $plugin_config['active']) { |
---|
| 55 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | ### Processus principal ### |
---|
| 61 | // Tableau avec les fichiers source |
---|
| 62 | $FilesSource = array(); |
---|
| 63 | recursive_readdir($CONF['DIRsource'], 'FilesSource'); |
---|
| 64 | |
---|
| 65 | // Tableau avec les fichiers de sortie |
---|
| 66 | $FilesSortie = str_replace($CONF['DIRsource'], $CONF['DIRsortie'], $FilesSource); |
---|
| 67 | |
---|
| 68 | // Boucle sur tous les fichiers |
---|
| 69 | for ($i=0; $i<count($FilesSource); $i++) { |
---|
| 70 | // Découpe le nom de fichier : dossier/fichier |
---|
| 71 | preg_match('#(.*)/(.*).([a-z]{3})$#', $FilesSortie[$i], $matches); |
---|
| 72 | $FileFolder = $matches[1].'/'; // dossier de sortie |
---|
| 73 | $FileName = $matches[2].'.jpg'; // nom final |
---|
| 74 | $FileExt = $matches[3]; // extension orginale |
---|
| 75 | |
---|
| 76 | // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail' |
---|
| 77 | if (!file_exists($FileFolder.'pwg_high') AND $CONF['DIRhighORNOT']) { |
---|
| 78 | mkdir($FileFolder.'pwg_high', 0777, true); |
---|
| 79 | } |
---|
| 80 | if (!file_exists($FileFolder.'thumbnail')) { |
---|
| 81 | mkdir($FileFolder.'thumbnail', 0777, true); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | // Informations sur le fichier |
---|
| 85 | exec('include\nconvert.exe -info "'.$FilesSource[$i].'"', $FileInfos); |
---|
| 86 | for ($m=0; $m<=5; $m++) { |
---|
| 87 | unset($FileInfos[$m]); |
---|
| 88 | } |
---|
| 89 | foreach ($FileInfos as $key) { |
---|
| 90 | $a = explode(':', $key); |
---|
| 91 | $FileInfos[trim($a[0])] = trim($a[1]); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // Plugins pendant l'execution |
---|
| 95 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 96 | if ($plugin_config['mode'] == 'Process' AND $plugin_config['active']) { |
---|
| 97 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | // Compresse les fichiers dans le dossier de sortie |
---|
| 102 | if (!isset($BlockNormal)) { |
---|
| 103 | exec('include\nconvert.exe -q '.$CONF['Qnormal'].' -out jpeg -o "'.$FileFolder.$FileName.'" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMnormal'].' '.$CONF['DIMnormal'].' '.$CONF['copyNormal'].' "'.$FilesSource[$i].'"'); |
---|
| 104 | } |
---|
| 105 | if (!isset($BlockThumbnail)) { |
---|
| 106 | exec('include\nconvert.exe -q '.$CONF['Qthumbnail'].' -out jpeg -o "'.$FileFolder.'thumbnail/'.$CONF['prefixe_mini'].$FileName.'" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMthumbnail'].' '.$CONF['DIMthumbnail'].' -rmeta -rexifthumb "'.$FilesSource[$i].'"'); |
---|
| 107 | } |
---|
| 108 | if (!isset($BlockHigh) AND $CONF['DIRhighORNOT']) { |
---|
| 109 | if ($CONF['DIMhdORNOT']) { |
---|
| 110 | exec('include\nconvert.exe -q '.$CONF['Qhd'].' -out jpeg -o "'.$FileFolder.'pwg_high/'.$FileName.'" -dpi '.$CONF['DPI'].' '.$CONF['convOptions'].' -resize '.$CONF['DIMhd'].' '.$CONF['DIMhd'].' '.$CONF['copyHD'].' "'.$FilesSource[$i].'"'); |
---|
| 111 | } else if (!in_array($FileExt, $CONF['JPGexts'])) { |
---|
| 112 | exec('include\nconvert.exe -q '.$CONF['Qhd'].' -out jpeg -o "'.$FileFolder.'pwg_high/'.$FileName.'" "'.$FilesSource[$i].'"'); |
---|
| 113 | } else { |
---|
| 114 | copy($FilesSource[$i], $FileFolder.'pwg_high/'.$FileName); |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | // Réinitialise les bloqueurs |
---|
| 119 | unset($FileInfos); |
---|
| 120 | unset($BlockNormal); |
---|
| 121 | unset($BlockThumbnail); |
---|
| 122 | unset($BlockHigh); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | ### Supprime les dossiers vides et copie les fichiers index.php ### |
---|
| 127 | $DirsSortie = array(); |
---|
| 128 | recursive_readdir($CONF['DIRsortie'], 'DirsSortie', true); |
---|
| 129 | |
---|
| 130 | foreach($DirsSortie as $dir) { |
---|
| 131 | if (is_dir_empty($dir)) { |
---|
| 132 | rmdir($dir); |
---|
| 133 | } else if ($CONF['indexORNOT']) { |
---|
| 134 | copy('includes/index.php', $dir.'/index.php'); |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | unset($DirsSortie); |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | ### Plugins après execution ### |
---|
| 142 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 143 | if ($plugin_config['mode'] == 'After' AND $plugin_config['active']) { |
---|
| 144 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | ?> |
---|