[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 | |
---|
[10337] | 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 |
---|
[9201] | 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 | |
---|
[10337] | 20 | if ($path != $new_path) { |
---|
| 21 | rename_log($path, $new_path); |
---|
| 22 | } |
---|
| 23 | |
---|
[9201] | 24 | if (is_dir($new_path)) { |
---|
| 25 | recursive_delete_special_car($new_path); |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | closedir($dh); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | recursive_delete_special_car($CONF['DIRsource']); |
---|
| 33 | |
---|
| 34 | |
---|
[10337] | 35 | ### Copyright & Options générales des conversion ### |
---|
[9201] | 36 | $CONF['copyright'] = utf8_decode($CONF['copyright']); |
---|
| 37 | $CONF['copyCOLOR'] = hex2RGB(nice_hex_color($CONF['copyCOLOR']), true, ' '); |
---|
| 38 | |
---|
| 39 | if ($CONF['copyONhd']) { |
---|
| 40 | $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'].'"'; |
---|
| 41 | } else { |
---|
| 42 | $CONF['copyHD'] = null; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | if ($CONF['copyONnormal']) { |
---|
| 46 | $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'].'"'; |
---|
| 47 | } else { |
---|
| 48 | $CONF['copyNormal'] = null; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | $CONF['convOptions'] = '-ratio -rtype lanczos -rflag decr'; |
---|
[10337] | 52 | $CONF['allowedExt'] = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff'); |
---|
[9201] | 53 | |
---|
| 54 | |
---|
| 55 | ### Plugins avant execution ### |
---|
| 56 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 57 | if ($plugin_config['mode'] == 'Before' AND $plugin_config['active']) { |
---|
| 58 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | ### Processus principal ### |
---|
| 64 | // Tableau avec les fichiers source |
---|
| 65 | $FilesSource = array(); |
---|
| 66 | recursive_readdir($CONF['DIRsource'], 'FilesSource'); |
---|
| 67 | |
---|
| 68 | // Tableau avec les fichiers de sortie |
---|
| 69 | $FilesSortie = str_replace($CONF['DIRsource'], $CONF['DIRsortie'], $FilesSource); |
---|
| 70 | |
---|
| 71 | // Boucle sur tous les fichiers |
---|
| 72 | for ($i=0; $i<count($FilesSource); $i++) { |
---|
[10337] | 73 | // Découpe le nom de fichier : dossier/fichier/extension |
---|
| 74 | preg_match('#^(.*)/(.*)\.([a-z0-9]{2,4})$#', $FilesSource[$i], $matches); |
---|
| 75 | $file['folder_src'] = $matches[1].'/'; // dossier d'entrée |
---|
| 76 | $file['folder_out'] = str_replace($CONF['DIRsource'], $CONF['DIRsortie'], $file['folder_src']); // dossier de sortie |
---|
| 77 | $file['name'] = $matches[2]; // nom final |
---|
| 78 | $file['ext'] = $matches[3]; // extension orginale |
---|
| 79 | |
---|
| 80 | // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail' |
---|
| 81 | if (!file_exists($file['folder_out'].'pwg_high') AND $CONF['DIRhighORNOT']) { |
---|
| 82 | mkdir_log($file['folder_out'].'pwg_high'); |
---|
[9201] | 83 | } |
---|
[10337] | 84 | if (!file_exists($file['folder_out'].'thumbnail')) { |
---|
| 85 | mkdir_log($file['folder_out'].'thumbnail'); |
---|
[9201] | 86 | } |
---|
| 87 | |
---|
[10337] | 88 | if (!in_arrayi($file['ext'], $CONF['allowedExt'])) { |
---|
| 89 | $BlockAll['main'] = true; |
---|
| 90 | $LOG[] = 'Not image file : '.$FilesSource[$i]; |
---|
[9201] | 91 | } |
---|
[10337] | 92 | |
---|
| 93 | if (!isset($BlockAll)) { |
---|
| 94 | // Informations sur le fichier |
---|
| 95 | exec('include\nconvert.exe -info "'.$FilesSource[$i].'"', $FileInfos); |
---|
| 96 | |
---|
| 97 | for ($m=0; $m<=5; $m++) { |
---|
| 98 | unset($FileInfos[$m]); |
---|
| 99 | } |
---|
| 100 | foreach ($FileInfos as $key) { |
---|
| 101 | if ($key != '') { |
---|
| 102 | $a = explode(':', $key); |
---|
| 103 | $FileInfos[trim($a[0])] = trim($a[1]); |
---|
| 104 | } |
---|
| 105 | } |
---|
[9201] | 106 | } |
---|
| 107 | |
---|
[10337] | 108 | // Plugins pendant l'execution, haute priorité |
---|
[9420] | 109 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 110 | if ($plugin_config['mode'] == 'ProcessHigh' AND $plugin_config['active']) { |
---|
| 111 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
[9201] | 115 | // Plugins pendant l'execution |
---|
| 116 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 117 | if ($plugin_config['mode'] == 'Process' AND $plugin_config['active']) { |
---|
| 118 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | // Compresse les fichiers dans le dossier de sortie |
---|
[10337] | 123 | if (!isset($BlockNormal) AND !isset($BlockAll)) { |
---|
| 124 | nconvert('-q '.$CONF['Qnormal'].' -out jpeg -o "'.$file['folder_out'].$file['name'].'.jpg" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMnormal'].' '.$CONF['DIMnormal'].' '.$CONF['copyNormal'].' "'.$FilesSource[$i].'"'); |
---|
[9201] | 125 | } |
---|
[10337] | 126 | if (!isset($BlockThumbnail) AND !isset($BlockAll)) { |
---|
| 127 | nconvert('-q '.$CONF['Qthumbnail'].' -out jpeg -o "'.$file['folder_out'].'thumbnail/'.$CONF['prefixe_mini'].$file['name'].'.jpg" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMthumbnail'].' '.$CONF['DIMthumbnail'].' -rmeta -rexifthumb "'.$FilesSource[$i].'"'); |
---|
[9201] | 128 | } |
---|
[10337] | 129 | if (!isset($BlockHigh) AND $CONF['DIRhighORNOT'] AND !isset($BlockAll)) { |
---|
[9201] | 130 | if ($CONF['DIMhdORNOT']) { |
---|
[10337] | 131 | nconvert('-q '.$CONF['Qhd'].' -out jpeg -o "'.$file['folder_out'].'pwg_high/'.$file['name'].'.jpg" -dpi '.$CONF['DPI'].' '.$CONF['convOptions'].' -resize '.$CONF['DIMhd'].' '.$CONF['DIMhd'].' '.$CONF['copyHD'].' "'.$FilesSource[$i].'"'); |
---|
| 132 | } else if (strtolower($file['ext']) != 'jpg') { |
---|
| 133 | nconvert('-q '.$CONF['Qhd'].' -out jpeg -o "'.$file['folder_out'].'pwg_high/'.$file['name'].'.jpg" "'.$FilesSource[$i].'"'); |
---|
[9201] | 134 | } else { |
---|
[10337] | 135 | copy_log($FilesSource[$i], $file['folder_out'].'pwg_high/'.$file['name'].'.jpg'); |
---|
[9201] | 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
[10337] | 139 | // Réinitialise les variables |
---|
| 140 | unset($file, $FileInfos, $BlockNormal, $BlockThumbnail, $BlockHigh, $BlockAll); |
---|
| 141 | $LOG[] = "\r\n"; |
---|
[9201] | 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | ### Supprime les dossiers vides et copie les fichiers index.php ### |
---|
| 146 | $DirsSortie = array(); |
---|
| 147 | recursive_readdir($CONF['DIRsortie'], 'DirsSortie', true); |
---|
| 148 | |
---|
| 149 | foreach($DirsSortie as $dir) { |
---|
| 150 | if (is_dir_empty($dir)) { |
---|
| 151 | rmdir($dir); |
---|
| 152 | } else if ($CONF['indexORNOT']) { |
---|
[10337] | 153 | copy_log('include/index.php', $dir.'/index.php'); |
---|
[9201] | 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | unset($DirsSortie); |
---|
| 158 | |
---|
| 159 | |
---|
[10337] | 160 | ### Plugins après execution ### |
---|
[9201] | 161 | foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) { |
---|
| 162 | if ($plugin_config['mode'] == 'After' AND $plugin_config['active']) { |
---|
| 163 | include('plugins/'.$plugin_id.'/main.php'); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | ?> |
---|