Mercurial > hg > fapweb
annotate faptool.php @ 1026:37901bdbc545
Switch to the official --end-time parameter of openmpt123
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Nov 2015 23:43:54 +0200 |
parents | 2a96426159f1 |
children | 8f242f756b0b |
rev | line source |
---|---|
827 | 1 #!/usr/bin/php |
2 <? | |
943 | 3 // |
4 // FAPWeb - Simple Web-based Demoparty Management System | |
5 // Special entry/preview/etc backend management commandline utility | |
1001 | 6 // (C) Copyright 2012-2015 Tecnic Software productions (TNSP) |
943 | 7 // |
1024
2a96426159f1
Fix configuration file checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
1019
diff
changeset
|
8 if (!file_exists(realpath(dirname(__FILE__))."/mconfig.inc.php")) |
1019
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
9 { |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
10 die( |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
11 "ERROR: Missing site configuration file. Please copy ". |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
12 "'mconfig.inc.php.example' to 'mconfig.inc.php' and ". |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
13 "edit it as needed.\n"); |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
14 } |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1013
diff
changeset
|
15 |
827 | 16 require_once "mconfig.inc.php"; |
17 require_once "msite.inc.php"; | |
18 | |
19 | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
20 function wtConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb, $useGfxConv) |
882 | 21 { |
22 global $setPreviewPath; | |
912 | 23 $isTemp = FALSE; |
882 | 24 |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
25 if ($useGfxConv) |
884 | 26 { |
27 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit | |
951 | 28 $tmpFilename = tempnam($setPreviewPath, "tmp"); |
912 | 29 $isTemp = TRUE; |
30 if (wtExec( | |
884 | 31 "/usr/local/bin/gfxconv", |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
32 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename), |
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
33 0) === false) |
912 | 34 return FALSE; |
35 | |
951 | 36 if (!file_exists($tmpFilename)) |
912 | 37 { |
38 echo "ERROR: gfxconv did not output a temporary conversion inbetween.\n"; | |
39 return FALSE; | |
40 } | |
884 | 41 } |
42 else | |
951 | 43 $tmpFilename = $inFilename; |
884 | 44 |
45 // Create conversion entity | |
951 | 46 $img = new Imagick($tmpFilename); |
1004 | 47 if ($img === FALSE) |
912 | 48 { |
951 | 49 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n"; |
912 | 50 return FALSE; |
51 } | |
884 | 52 |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
53 if ($outDim !== FALSE) |
884 | 54 { |
963 | 55 // Get dimensions, setup background |
56 $dim = $img->getImageGeometry(); | |
969 | 57 // $img->setBackgroundColor(imagick::COLOR_BLACK); |
963 | 58 $img->setGravity(imagick::GRAVITY_CENTER); |
59 | |
60 // Act based on image size vs. desired size and $thumb mode | |
61 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1]) | |
62 { | |
63 // Image is larger | |
64 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1); | |
969 | 65 $img->setImageExtent($outDim[0], $outDim[1]); |
963 | 66 $img->normalizeImage(); |
67 $img->unsharpMaskImage(0, 0.5, 1, 0.05); | |
68 } | |
69 else | |
70 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1]) | |
71 { | |
72 // Image is smaller than requested dimension(s)? | |
73 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_POINT, 1); | |
969 | 74 $img->setImageExtent($outDim[0], $outDim[1]); |
963 | 75 } |
884 | 76 } |
77 | |
78 $img->setFormat($outFormat); | |
79 $img->setCompressionQuality($outQuality); | |
80 | |
81 $img->stripImage(); | |
82 $img->writeImage($outFilename); | |
83 $img->removeImage(); | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
84 return TRUE; |
882 | 85 } |
86 | |
87 | |
898 | 88 function wtRenderSample($inFilename, $outFilename) |
882 | 89 { |
898 | 90 $sfreq = intval(stGetSetting("sampleFreq")); |
91 $sduration = intval(stGetSetting("sampleDuration")); | |
92 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 93 |
902 | 94 return wtExec( |
898 | 95 "/usr/local/bin/openmpt123" |
96 , | |
954 | 97 "--force --quiet ". |
884 | 98 "--samplerate ".$sfreq." ". |
99 "--channels ".$schannels." ". | |
1026
37901bdbc545
Switch to the official --end-time parameter of openmpt123
Matti Hamalainen <ccr@tnsp.org>
parents:
1024
diff
changeset
|
100 "--end-time ".($sduration)." ". |
954 | 101 escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename), |
963 | 102 0); |
882 | 103 } |
104 | |
105 | |
948
1334b93939a3
Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents:
947
diff
changeset
|
106 function wtConvertSample($inFilename, $outFilename, $outOpts) |
882 | 107 { |
898 | 108 $sfreq = intval(stGetSetting("sampleFreq")); |
109 $sduration = intval(stGetSetting("sampleDuration")); | |
110 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 111 |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
112 $optStr = ""; |
948
1334b93939a3
Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents:
947
diff
changeset
|
113 foreach ($outOpts as $okey => $oval) |
898 | 114 $optStr .= $okey." ".$oval." "; |
939 | 115 |
902 | 116 return wtExec( |
898 | 117 "/usr/local/bin/avconv", |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
118 "-y -v 1 -t ".intval($sduration)." ". |
898 | 119 "-i ".escapeshellarg($inFilename). |
120 " ".$optStr." -ac ".$schannels. | |
121 " -map_metadata -1 ". | |
122 escapeshellarg($outFilename)); | |
882 | 123 } |
124 | |
125 | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
126 function wtEntryToSource($compo, $inFilename, $edata, $entryFilename, &$outData, &$outFilename, $force) |
882 | 127 { |
963 | 128 // Does compo preview type match this file class? |
129 if ($edata["class"] != $compo["preview_type"]) | |
130 return FALSE; | |
954 | 131 |
969 | 132 switch ($edata["class"]) |
133 { | |
134 case EFILE_AUDIO: $fext = "wav"; break; | |
135 case EFILE_IMAGE: $fext = "png"; break; | |
136 default: | |
137 return FALSE; | |
138 } | |
139 | |
140 $outFilename = stReplaceFileExt($entryFilename, "_preview.".$fext); | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
141 if (!$force && file_exists($outFilename) && filemtime($outFilename) >= filemtime($entryFilename)) |
969 | 142 return TRUE; |
963 | 143 |
969 | 144 printf("GENERATING: %s -> %s\n", $inFilename, $outFilename); |
145 | |
954 | 146 switch ($edata["class"]) |
939 | 147 { |
954 | 148 case EFILE_AUDIO: |
149 if ($edata["mime"] == "audio/x-mod") | |
963 | 150 $res = wtRenderSample($inFilename, $outFilename); |
954 | 151 else |
969 | 152 $res = wtConvertSample($inFilename, $outFilename, |
153 array("-f" => "wav")); | |
954 | 154 break; |
963 | 155 |
954 | 156 case EFILE_IMAGE: |
963 | 157 $res = wtConvertImage( |
158 $inFilename, | |
159 $outFilename, | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
160 FALSE, "PNG", 9, |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
161 FALSE, ($edata["mime"] == "gfx")); |
963 | 162 break; |
939 | 163 } |
963 | 164 |
165 return $res; | |
882 | 166 } |
167 | |
168 | |
902 | 169 function wtUnpackArchiveTo($atype, $filename, $path) |
882 | 170 { |
171 // Check file type before doing anything | |
953 | 172 echo "INFO: Preparing to unpack archive file '".$filename."' ...\n"; |
902 | 173 switch ($atype) |
882 | 174 { |
175 case "LHA": | |
176 $exe = "/usr/bin/lha"; | |
967 | 177 $args = "x ".escapeshellarg($filename); |
882 | 178 break; |
179 | |
180 case "ZIP": | |
181 $exe = "/usr/bin/unzip"; | |
182 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename); | |
183 break; | |
184 | |
898 | 185 case "RAR": |
186 $exe = "/usr/bin/rar"; | |
968 | 187 $args = "x -w".escapeshellarg($path)." ".escapeshellarg($filename); |
188 break; | |
189 | |
190 case "7ZIP": | |
191 $exe = "/usr/bin/7z"; | |
192 $args = "x -o".escapeshellarg($path)." ".escapeshellarg($filename); | |
898 | 193 break; |
194 | |
882 | 195 default: |
902 | 196 echo "Unsupported archive file type: ".$atype."\n"; |
898 | 197 return FALSE; |
882 | 198 } |
199 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
200 // Delete any pre-existing directory |
882 | 201 wtPurgeDir($path); |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
202 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
203 // Create temporary directory for unpacking |
935 | 204 wtMakeDir($path, 0700); |
882 | 205 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
206 // Save current working directory and chdir to target |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
207 $cwd = getcwd(); |
882 | 208 if (!is_dir($path) || chdir($path) === false) |
902 | 209 { |
953 | 210 echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n"; |
902 | 211 return FALSE; |
212 } | |
882 | 213 |
214 // Unpack archive | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
215 $ret = wtExec($exe, $args); |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
216 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
217 // Return to stored cwd |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
218 chdir($cwd); |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
219 return $ret; |
902 | 220 } |
221 | |
222 | |
882 | 223 function wtHandleEntryPreview($compo, $entry, $mode) |
224 { | |
941 | 225 global $fileTypeData, $setEntryPath; |
933 | 226 |
227 // Get current preview file(s) data | |
898 | 228 if (!stGetPreviewFileData($compo, $entry, $pdata)) |
229 return FALSE; | |
230 | |
933 | 231 // Get entry file data |
963 | 232 $efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"]); |
898 | 233 |
234 // Check preview file(s) status | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
235 if ($mode == "sta" || $mode == "lis") |
898 | 236 { |
237 printf(" %03d | %s%s%s | %-40s | %-5s | %s\n", | |
238 $entry["id"], | |
933 | 239 ($efile !== false) ? "E" : ".", |
240 isset($pdata["file"]) ? "P" : ".", | |
241 $pdata["valid"] ? "V" : ".", | |
242 substr($entry["name"]." by ".$entry["author"], 0, 40), | |
898 | 243 isset($pdata["file"]) ? $pdata["file"]["filetype"] : "", |
244 isset($pdata["file"]) ? $pdata["file"]["filename"] : "" | |
245 ); | |
954 | 246 return TRUE; |
898 | 247 } |
248 else | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
249 if ($mode != "gen" && $mode != "upd") |
953 | 250 die("ERROR: Unsupported previews mode ".$mode."\n"); |
933 | 251 |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
252 $force = ($mode == "upd"); |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
253 |
933 | 254 // Check validity of previews |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
255 if ($pdata["valid"] && !$force) |
933 | 256 return TRUE; |
257 | |
258 // Okay, no valid previews .. lets see what we can do .. | |
259 // First, check if we have a source preview file | |
260 if (!isset($pdata["file"])) | |
898 | 261 { |
935 | 262 // No source preview, check if we have entry file either? |
263 if ($efile === false) | |
264 { | |
265 echo | |
266 "INFO: No entry file for ".wtNiceName($compo, $entry, $efile). | |
267 ", can't attempt to generate preview.\n"; | |
268 return FALSE; | |
269 } | |
954 | 270 |
271 // Actual entry filename + path | |
272 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"])); | |
273 if (!file_exists($filename)) | |
274 { | |
275 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n"; | |
276 return FALSE; | |
277 } | |
278 | |
935 | 279 // Preview source file does not exist, let's see .. |
963 | 280 $edata = stProbeFileInfo($filename, TRUE); |
281 if ($edata === false) | |
882 | 282 { |
935 | 283 echo |
284 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
285 return FALSE; | |
286 } | |
287 | |
942 | 288 $found = FALSE; |
935 | 289 if ($edata["class"] == EFILE_ARCHIVE) |
290 { | |
291 // Entry is an archive file .. | |
963 | 292 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $efile["filename"])); |
941 | 293 |
294 if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false) | |
295 return FALSE; | |
935 | 296 |
941 | 297 // Scan through files ... |
298 $dir = opendir($path); | |
299 while (($dentry = readdir($dir)) !== false) | |
300 { | |
301 $fname = $path."/".$dentry; | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
302 if ($dentry != "." && $dentry != "..") |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
303 { |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
304 if (is_dir($fname)) |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
305 echo "XXX: ".$dentry." :: ".$fname."\n"; |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
306 else |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
307 if (is_file($fname) && |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
308 ($mdata = stProbeFileInfo($fname, TRUE)) !== false && |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
309 ($found = wtEntryToSource($compo, $fname, $mdata, $filename, $pdata, $outFilename, $force)) === true) |
954 | 310 break; |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
311 } |
941 | 312 } |
954 | 313 |
314 // Cleanup | |
941 | 315 closedir($dir); |
316 wtPurgeDir($path); | |
954 | 317 } |
318 else | |
319 if ($edata["class"] == $compo["preview_type"]) | |
320 { | |
321 // Single file | |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
322 $found = wtEntryToSource($compo, $filename, $edata, $filename, $pdata, $outFilename, $force); |
954 | 323 } |
969 | 324 |
950 | 325 if (!$found) |
882 | 326 { |
935 | 327 echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n"; |
328 return FALSE; | |
898 | 329 } |
969 | 330 |
331 $inFilename = $outFilename; | |
898 | 332 } |
969 | 333 else |
334 $inFilename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $pdata["file"]["filename"])); | |
898 | 335 |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
336 // Check validity vs. |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
337 if (!$force) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
338 { |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
339 $valid = TRUE; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
340 $inMTime = filemtime($inFilename); |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
341 foreach ($pdata["files"] as $stype => $sdata) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
342 { |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
343 if (!file_exists($sdata["file"]) || filemtime($sdata["file"]) < $inMTime) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
344 { |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
345 $valid = FALSE; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
346 break; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
347 } |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
348 } |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
349 if ($valid) |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
350 return TRUE; |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
351 } |
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
352 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
353 // |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
354 // Either we now have a "user specified" source file or |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
355 // a generated source file - in any case, now convert it |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
356 // to the final form(s). |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
357 // |
969 | 358 switch ($compo["preview_type"]) |
941 | 359 { |
963 | 360 case EFILE_AUDIO: |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
361 // Convert to each specified sample type (MP3, Ogg, etc.) |
950 | 362 foreach (stGetSetting("sampleTypes") as $stype => $sopts) |
942 | 363 { |
950 | 364 wtConvertSample( |
365 $inFilename, | |
969 | 366 $pdata["files"][$stype]["file"], |
950 | 367 $sopts |
368 ); | |
942 | 369 } |
370 break; | |
969 | 371 |
963 | 372 case EFILE_IMAGE: |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
373 // Images we convert to bigger image and thumbnail |
969 | 374 wtConvertImage( |
375 $inFilename, | |
376 $pdata["files"]["image"]["file"], | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
377 stGetSetting("previewImageSize"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
378 stGetSetting("previewImageType"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
379 stGetSetting("previewImageQuality"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
380 FALSE, FALSE); |
882 | 381 |
969 | 382 wtConvertImage( |
383 $inFilename, | |
384 $pdata["files"]["thumb"]["file"], | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
385 stGetSetting("previewThumbSize"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
386 stGetSetting("previewThumbType"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
387 stGetSetting("previewThumbQuality"), |
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
388 TRUE, FALSE); |
942 | 389 break; |
941 | 390 } |
963 | 391 |
933 | 392 return TRUE; |
882 | 393 } |
394 | |
395 | |
884 | 396 function wtHandleEntry($compo, $entry, $mode) |
397 { | |
398 } | |
399 | |
400 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
401 // |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
402 // Crop a filename to specified length |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
403 // |
986 | 404 function wtCropFilename($filename, $len) |
405 { | |
406 if ($len !== FALSE && strlen($filename) > $len) | |
407 { | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
408 // Check if the filename has a path and attempt |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
409 // to get the filename extension |
986 | 410 $fext = ""; |
411 $dpos = strrpos($filename, "/"); | |
412 if (($spos = strrpos($filename, ".")) !== FALSE && | |
413 ($dpos === FALSE || $dpos < $spos)) | |
414 $fext = substr($filename, $spos); | |
415 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
416 // Is the filename extension too long, if yes, just dump it |
986 | 417 if (strlen($fext) >= $len) |
418 $fext = ""; | |
419 | |
987 | 420 return substr($filename, 0, $len - strlen($fext) - 1).$fext; |
986 | 421 } |
422 else | |
423 return $filename; | |
424 } | |
425 | |
426 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
427 // |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
428 // Recursively goes through directory/files and subdirectories, |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
429 // cropping file/dir names to specified length. |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
430 // |
986 | 431 function wtCropFilenamesRec($path, $len) |
432 { | |
433 $dir = opendir($path); | |
434 while (($dentry = readdir($dir)) !== false) | |
435 { | |
436 $fname = $path."/".$dentry; | |
987 | 437 $nname = $path."/".wtCropFilename($dentry, $len); |
986 | 438 if ($dentry != "." && $dentry != "..") |
439 { | |
440 if (is_dir($fname)) | |
441 { | |
442 wtCropFilenamesRec($fname, $len); | |
987 | 443 if (rename($fname, $nname) === false) |
444 { | |
445 echo "ERROR: Could not rename DIR '".$fname."' -> '".$nname."'.\n"; | |
446 return FALSE; | |
447 } | |
986 | 448 } |
449 else | |
987 | 450 if (is_file($fname) && rename($fname, $nname) === false) |
451 { | |
452 echo "ERROR: Could not rename FILE '".$fname."' -> '".$nname."'.\n"; | |
453 return FALSE; | |
454 } | |
986 | 455 } |
456 } | |
457 closedir($dir); | |
458 } | |
459 | |
460 | |
991 | 461 function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig, $cropNames, $copyOnly) |
963 | 462 { |
463 global $setEntryPath; | |
464 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
465 // Get latest file for the entry |
963 | 466 if (($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"])) === false) |
467 { | |
468 echo "INFO: No entry file for ".wtNiceName($compo, $entry, $efile)."\n"; | |
469 return FALSE; | |
470 } | |
471 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
472 // Create source file full path |
963 | 473 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"])); |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
474 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
475 // Check if the file exists |
963 | 476 if (!file_exists($filename)) |
477 { | |
478 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n"; | |
479 return FALSE; | |
480 } | |
481 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
482 // Get file data |
963 | 483 $edata = stProbeFileInfo($filename, TRUE); |
484 if ($edata === false) | |
485 { | |
486 echo | |
487 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
488 return FALSE; | |
489 } | |
490 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
491 // Create the destination directory |
963 | 492 if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false) |
493 return FALSE; | |
494 | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
495 // Form the destination path and/or filename |
991 | 496 if ($copyOnly) |
497 $dstFileBase = $useOrig ? $efile["origname"] : $efile["filename"]; | |
498 else | |
499 $dstFileBase = wtCropFilename($entry["show_id"]."-".($useOrig ? $efile["origname"] : $efile["filename"]), $cropNames); | |
963 | 500 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
501 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
502 // Handle based on class/type and whether we are just copying or not |
991 | 503 if (!$copyOnly && $edata["class"] == EFILE_ARCHIVE) |
963 | 504 { |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
505 // Entry is an archive file, so unpack it |
963 | 506 $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, ""))); |
964 | 507 if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false) |
963 | 508 return FALSE; |
986 | 509 |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
510 // Crop the filenames from the unpacked archive, if we need to |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
511 if ($cropNames !== false) |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
512 wtCropFilenamesRec($dstPath, $cropNames); |
963 | 513 } |
514 else | |
515 { | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
516 // We have a single file (or copyOnly mode) |
963 | 517 $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase)); |
518 if (copy($filename, $dstFilename) === false) | |
519 { | |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
520 echo "ERROR: Failed to copy '".$filename."' to '".$dstFilename."'\n"; |
963 | 521 return FALSE; |
522 } | |
523 } | |
524 | |
525 return TRUE; | |
526 } | |
527 | |
528 | |
827 | 529 // |
941 | 530 // Misc helper functions |
827 | 531 // |
993
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
532 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
533 function wtNiceName($compo, $entry, $efile = FALSE) |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
534 { |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
535 return sprintf( |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
536 "%d: %s by %s%s", |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
537 $entry["id"], |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
538 $entry["name"], |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
539 $entry["author"], |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
540 ($efile !== false) ? " [".$efile["filename"]." / TYPE: '".$efile["filetype"]."']" : ""); |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
541 } |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
542 |
fbc2e6514dfa
Cleanups and improved comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
991
diff
changeset
|
543 |
941 | 544 function wtExec($exe, $args, $expect = 0) |
545 { | |
984
03b245ef3a47
Various fixes to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
546 echo "EXEC: ".$exe." @ ".$args."\n"; |
941 | 547 exec(escapeshellcmd($exe)." ".$args, $output, $code); |
548 if ($code !== $expect) | |
549 { | |
550 echo | |
953 | 551 "ERROR: Executing ".$exe.": ".$code."\n".$args."\n". |
941 | 552 "------------------------------------------------\n". |
553 implode("\n", $output). | |
554 "------------------------------------------------\n"; | |
555 return FALSE; | |
556 } | |
557 return TRUE; | |
558 } | |
559 | |
560 | |
561 function wtExecOrDie($exe, $args) | |
562 { | |
563 if (wtExec($exe, $args) === false) | |
564 die(); | |
565 } | |
566 | |
567 | |
568 function wtPurgeDir($path) | |
569 { | |
942 | 570 if ($path != "" && $path !== false && file_exists($path) && is_dir($path)) |
941 | 571 { |
969 | 572 // echo "PURGING: ".$path."\n"; |
942 | 573 foreach (scandir($path) as $file) |
574 if ($file !== "." && $file !== "..") | |
575 { | |
576 $sub = $path."/".$file; | |
577 if (is_dir($sub)) | |
578 wtPurgeDir($sub); | |
579 else | |
580 unlink($sub); | |
581 } | |
582 rmdir($path); | |
941 | 583 } |
584 } | |
585 | |
586 | |
935 | 587 function wtMakeDir($path, $perm) |
827 | 588 { |
589 if (!file_exists($path)) | |
590 { | |
953 | 591 echo "INFO: Creating ".$path."\n"; |
827 | 592 if (mkdir($path, $perm, TRUE) === false) |
593 die("Could not create directory '".$path."'\n"); | |
594 } | |
595 } | |
596 | |
597 | |
935 | 598 function wtInitializeDirs() |
827 | 599 { |
902 | 600 global |
601 $setEntryPath, $setPreviewPath, $setThumbDir, | |
827 | 602 $setEntryPathPerms, $setPrevPathPerms; |
603 | |
604 echo "Checking for missing directories ...\n"; | |
935 | 605 wtMakeDir($setEntryPath, $setEntryPathPerms); |
606 wtMakeDir($setPreviewPath, $setPrevPathPerms); | |
827 | 607 |
608 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
609 { | |
935 | 610 wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); |
611 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); | |
612 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); | |
827 | 613 } |
614 } | |
615 | |
616 | |
968 | 617 function wtPrintCompoHeader($compo) |
618 { | |
619 global $setTermWidth; | |
620 printf("==%'=-".($setTermWidth-2)."s\n", | |
621 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) | |
622 ); | |
623 } | |
624 | |
625 | |
626 function wtPrintDivider($chr = "-") | |
627 { | |
628 global $setTermWidth; | |
629 echo str_repeat($chr, $setTermWidth)."\n"; | |
630 } | |
631 | |
632 | |
935 | 633 function wtShowHelp() |
827 | 634 { |
935 | 635 global $argv; |
827 | 636 echo |
637 "faptool - Do stuff with FAPWeb database\n". | |
1001 | 638 "(C) Copyright 2015 ccr/TNSP\n". |
827 | 639 "\n". |
917 | 640 "Usage: ".$argv[0]." <command> [args]\n". |
641 "Where command is one of following:\n". | |
827 | 642 "\n". |
643 " init\n". | |
644 " Create directories for entries and previews, if needed.\n". | |
645 "\n". | |
928 | 646 /* |
917 | 647 " clean [delete|crap]\n". |
648 " Clean files marked to be deleted and 'stale' files. This includes\n". | |
649 " any old or stale preview files and entry files.\n". | |
650 " Without 'delete' parameter just checks and shows what would deleted.\n". | |
651 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n". | |
652 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n". | |
653 " KNOW WHAT YOU ARE DOING!!!!!\n". | |
901 | 654 "\n". |
928 | 655 */ |
938 | 656 " probe <filename> [filename2 ..]\n". |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
657 " Probe specified file for file information.\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
658 "\n". |
881 | 659 " previews <cmd> [args]\n". |
660 " Where <cmd> is one of:\n". | |
933 | 661 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n". |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
662 " generate - Generate preview files that are missing OR out of date.\n". |
928 | 663 " (older then preview source file OR entry file where appropriate)\n". |
664 // " add <entry_id> <filename> - Add file as preview for entry_id.\n". | |
901 | 665 "\n". |
666 " entry <cmd> [args]\n". | |
933 | 667 " status [cid] - List entries for all compos or <cid>.\n". |
966 | 668 " unpack <path> - Create subdirs and copy all entries UNPACKED there.\n". |
991 | 669 " release <path> - Like unpack, but just copies files (does not unpack archives).\n". |
928 | 670 /* |
671 " add <filename> '<name>' '<author>' - Add file as entry file\n". | |
672 " (works same as uploading from admin interface)\n". | |
673 " package <lha|zip|rar|7z>\n". | |
674 " Repackages/packages entries (unpacks first if archive),\n". | |
675 " and adds generated infofile.txt to packages.\n". | |
676 */ | |
827 | 677 "\n"; |
935 | 678 } |
679 | |
1005 | 680 |
681 function wtSigHandler($signo) | |
682 { | |
683 global $flagQuit; | |
684 switch ($signo) | |
685 { | |
686 case SIGTERM: | |
687 mgFatal("Received SIGTERM.\n"); | |
688 break; | |
689 | |
690 case SIGQUIT: | |
691 case SIGINT: | |
692 $flagQuit = TRUE; | |
693 break; | |
1013
720078ca799e
Oops, a missing bracket. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
694 } |
1005 | 695 } |
696 | |
697 | |
935 | 698 // |
699 // Main program starts | |
700 // | |
944
535466595a5a
Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents:
943
diff
changeset
|
701 stCheckCLIExec(); |
935 | 702 if ($argc < 2) |
703 { | |
704 wtShowHelp(); | |
827 | 705 exit; |
706 } | |
707 | |
1005 | 708 pcntl_signal(SIGTERM, "wtSigHandler"); |
709 pcntl_signal(SIGHUP, "wtSigHandler"); | |
710 pcntl_signal(SIGQUIT, "wtSigHandler"); | |
711 pcntl_signal(SIGINT, "wtSigHandler"); | |
935 | 712 |
827 | 713 // Try to connect to database |
714 $spec = stGetSetting("sqlDB"); | |
715 if (($db = stConnectSQLDBSpec($spec)) === false) | |
716 die("Could not connect to SQL database '".$spec."'.\n"); | |
717 | |
718 echo "Using database spec '".$spec."'.\n"; | |
719 | |
720 // Fetch non-"hardcoded" settings from SQL database | |
721 stReloadSettings(); | |
722 | |
723 // Set some globals for our benefit | |
922 | 724 $setTermWidth = 75; |
827 | 725 $setEntryPath = stGetSetting("entryPath"); |
726 $setPreviewPath = stGetSetting("previewPath"); | |
727 $setPreviewURL = stGetSetting("previewURL"); | |
728 $setThumbDir = stGetSetting("thumbnailSubDir"); | |
832 | 729 $setEntryPathPerms = stGetSetting("entryPathPerms"); |
730 $setPrevPathPerms = stGetSetting("previewPathPerms"); | |
827 | 731 |
732 if ($setEntryPath === FALSE || $setPreviewPath === FALSE || | |
832 | 733 $setPreviewURL === FALSE || $setThumbDir === FALSE || |
734 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE) | |
827 | 735 { |
922 | 736 die("Some required settings are not defined in mconfig.inc.php!\n"); |
827 | 737 } |
738 | |
739 | |
740 // Act according to specified command | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
741 switch (stCArgLC(1, 3)) |
827 | 742 { |
935 | 743 case "-?": case "--h": |
744 wtShowHelp(); | |
745 exit; | |
746 break; | |
747 | |
884 | 748 case "ini": |
827 | 749 // |
750 // Initialize the data directories etc | |
751 // | |
953 | 752 echo "INFO: Checking for missing directories ...\n"; |
935 | 753 wtInitializeDirs(); |
827 | 754 break; |
755 | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
756 case "pro": |
945 | 757 // |
758 // Probe specified files | |
759 // | |
760 if ($argc < 2) | |
761 die("No filename specified.\n"); | |
762 | |
763 if (($finfo = finfo_open()) === false) | |
954 | 764 die("Internal error. Failed to initialize finfo()."); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
765 |
945 | 766 for ($i = 2; $i < $argc; $i++) |
767 { | |
768 // Probe one file | |
769 $filename = $argv[$i]; | |
770 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); | |
771 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); | |
772 | |
773 echo | |
774 "\n". | |
775 "File : ".$filename."\n". | |
776 "Probed : ".$sdata."\n". | |
777 "Mime : ".$smime."\n"; | |
778 | |
954 | 779 if (($info = stProbeFileInfo($filename, TRUE)) !== false) |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
780 { |
945 | 781 $tmp = array(); |
782 foreach ($info as $ikey => $ival) | |
783 $tmp[] = $ikey."='".$ival."'"; | |
784 | |
785 echo "Data : ".implode(", ", $tmp)."\n"; | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
786 } |
946 | 787 } |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
788 |
946 | 789 finfo_close($finfo); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
790 break; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
791 |
901 | 792 case "cle": |
947 | 793 // |
794 // File cleanup / deletion | |
795 // | |
901 | 796 $doDelete = (stCArgLC(2) == "delete"); |
797 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
798 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
799 { | |
968 | 800 wtPrintCompoHeader($compo); |
801 wtPrintDivider(); | |
901 | 802 |
803 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
804 { | |
805 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
806 { | |
935 | 807 if ($efile["deleted"] != 0) |
901 | 808 { |
809 echo "X"; | |
810 } | |
811 } | |
812 } | |
813 echo "\n"; | |
968 | 814 wtPrintDivider(); |
901 | 815 } |
816 break; | |
817 | |
818 case "ent": | |
819 // | |
820 // Entry files handling | |
821 // | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
822 $mode = stCArgLC(2, 3); |
901 | 823 switch ($mode) |
824 { | |
825 case "sta": | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
826 case "lis": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
827 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; |
933 | 828 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) |
901 | 829 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
830 { | |
968 | 831 wtPrintCompoHeader($compo); |
832 wtPrintDivider(); | |
901 | 833 |
834 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
835 wtHandleEntry($compo, $entry, $mode); | |
836 | |
968 | 837 wtPrintDivider(); |
901 | 838 } |
839 break; | |
840 | |
963 | 841 case "unp": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
842 if (($setPrefix = stCArg(3)) === FALSE) |
963 | 843 die("Unpack needs a destination path.\n"); |
844 | |
845 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
846 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
847 { | |
991 | 848 // wtUnpackEntry($compo, $entry, $setPrefix, TRUE, 32, FALSE); |
849 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, FALSE); | |
850 } | |
851 break; | |
852 | |
853 case "rel": | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
854 if (($setPrefix = stCArg(3)) === FALSE) |
991 | 855 die("Releases needs a destination path.\n"); |
856 | |
857 if (!file_exists($setPrefix) || is_dir($setPrefix)) | |
858 { | |
859 // Create new one | |
860 wtMakeDir($setPrefix, 0755); | |
861 | |
862 // Create results.txt if it does not exist | |
863 $resultsFile = stMakePath(FALSE, TRUE, array($setPrefix, "results.txt")); | |
864 if (!file_exists($resultsFile)) | |
865 { | |
866 // Use a header file if it exists | |
867 $resultsHeader = "results.logo"; | |
868 if (file_exists($resultsHeader) && is_file($resultsHeader)) | |
869 $resultsText = file_get_contents($resultsHeader); | |
870 else | |
871 { | |
872 $resultsText = $pageTitle." results"; | |
873 $resultsText .= "\n".str_repeat("=", strlen($resultsText))."-- -\n\n"; | |
874 } | |
875 | |
876 file_put_contents( | |
877 $resultsFile, | |
878 $resultsText.stGetCompoResultsASCIIStr(FALSE, 0) | |
879 ); | |
880 } | |
881 | |
882 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
883 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
884 { | |
885 wtUnpackEntry($compo, $entry, $setPrefix, TRUE, FALSE, TRUE); | |
886 } | |
963 | 887 } |
888 break; | |
889 | |
901 | 890 case "pac": |
929 | 891 echo "Not implemented. :D\n"; |
901 | 892 break; |
893 | |
894 case "add": | |
929 | 895 echo "Not implemented. :D\n"; |
901 | 896 break; |
897 | |
898 default: | |
899 if ($mode == "") | |
900 die("ERROR! Entry command requires a sub-command argument.\n"); | |
901 else | |
902 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
903 break; | |
904 } | |
905 break; | |
906 | |
884 | 907 case "pre": |
881 | 908 // |
909 // Preview files handling | |
910 // | |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
911 $mode = stCArgLC(2, 3); |
881 | 912 switch ($mode) |
913 { | |
970
9c93a3c4f95c
Clean out the debug code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
969
diff
changeset
|
914 case "gen": |
983
1e347288712d
Add "upd" option to previews generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
915 case "upd": |
881 | 916 case "sta": |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
917 case "lis": |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1005
diff
changeset
|
918 $sql = (stCArg(3) !== FALSE) ? " AND id=".intval(stCArg(3)) : ""; |
933 | 919 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) |
898 | 920 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 921 { |
968 | 922 wtPrintCompoHeader($compo); |
881 | 923 printf( |
898 | 924 "PrevType : %s\n", |
925 $previewTypeList[$compo["preview_type"]][0]); | |
941 | 926 |
968 | 927 if ($mode == "sta" || $mode == "lis") |
941 | 928 { |
929 printf(" %-3s | %-3s | %-40s |\n", | |
968 | 930 "#ID", "EPV", "Entry name/author"); |
941 | 931 } |
932 | |
968 | 933 wtPrintDivider("-"); |
881 | 934 |
935 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
936 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 937 |
968 | 938 wtPrintDivider("="); |
939 } | |
940 if ($mode == "sta" || $mode == "lis") | |
941 { | |
942 echo "Flags: E = Entry has file, P = Has preview file, V = Generated previews are up to date.\n"; | |
881 | 943 } |
944 break; | |
945 | |
901 | 946 case "add": |
929 | 947 echo "Not implemented. :D\n"; |
901 | 948 break; |
949 | |
881 | 950 default: |
951 if ($mode == "") | |
952 die("ERROR! Previews command requires a sub-command argument.\n"); | |
953 else | |
954 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
955 break; | |
956 } | |
957 break; | |
958 | |
827 | 959 default: |
960 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
961 break; | |
962 } | |
963 | |
941 | 964 /* Dummy |
965 { | |
966 | |
967 } | |
968 */ | |
827 | 969 ?> |