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 | |
---|
20 | if ($path != $new_path) { |
---|
21 | rename_log($path, $new_path); |
---|
22 | } |
---|
23 | |
---|
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 | |
---|
35 | ### Copyright & Options générales des conversion ### |
---|
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'; |
---|
52 | $CONF['allowedExt'] = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff'); |
---|
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++) { |
---|
73 | // Découpe le nom de fichier : dossier/fichier/extension |
---|
74 | preg_match('#^(.*)/(.*)\.([a-z0-9]{2,4})$#i', $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'); |
---|
83 | } |
---|
84 | if (!file_exists($file['folder_out'].'thumbnail')) { |
---|
85 | mkdir_log($file['folder_out'].'thumbnail'); |
---|
86 | } |
---|
87 | |
---|
88 | if (!in_arrayi($file['ext'], $CONF['allowedExt'])) { |
---|
89 | $BlockAll['main'] = true; |
---|
90 | $LOG[] = 'Not image file : '.$FilesSource[$i]; |
---|
91 | } |
---|
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 | } |
---|
106 | } |
---|
107 | |
---|
108 | // Plugins pendant l'execution, haute priorité |
---|
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 | |
---|
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 |
---|
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].'"'); |
---|
125 | } |
---|
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].'"'); |
---|
128 | } |
---|
129 | if (!isset($BlockHigh) AND $CONF['DIRhighORNOT'] AND !isset($BlockAll)) { |
---|
130 | if ($CONF['DIMhdORNOT']) { |
---|
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].'"'); |
---|
134 | } else { |
---|
135 | copy_log($FilesSource[$i], $file['folder_out'].'pwg_high/'.$file['name'].'.jpg'); |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | // Réinitialise les variables |
---|
140 | unset($file, $FileInfos, $BlockNormal, $BlockThumbnail, $BlockHigh, $BlockAll); |
---|
141 | $LOG[] = "\r\n"; |
---|
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']) { |
---|
153 | copy_log('include/index.php', $dir.'/index.php'); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | unset($DirsSortie); |
---|
158 | |
---|
159 | |
---|
160 | ### Plugins après execution ### |
---|
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 | ?> |
---|