Mercurial > hg > fapweb
annotate faptool.php @ 966:eea2b92287ca
Update help.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 29 Nov 2014 03:52:50 +0200 |
parents | 280dc9b01297 |
children | 62c90ec5edce |
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 | |
6 // (C) Copyright 2012-2014 Tecnic Software productions (TNSP) | |
7 // | |
827 | 8 require_once "mconfig.inc.php"; |
9 require_once "msite.inc.php"; | |
10 | |
11 | |
12 | |
882 | 13 function wtConvertImage($inFilename, $inFileType, $outFilename, $setDim, $setFormat, $setQuality, $thumb) |
14 { | |
15 global $setPreviewPath; | |
912 | 16 $isTemp = FALSE; |
882 | 17 |
884 | 18 if ($inFileType == "gfx") |
19 { | |
20 // Oh great .. we need gfxconv here because Imagick handles ILBM like shit | |
951 | 21 $tmpFilename = tempnam($setPreviewPath, "tmp"); |
912 | 22 $isTemp = TRUE; |
23 if (wtExec( | |
884 | 24 "/usr/local/bin/gfxconv", |
951 | 25 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename)) === false) |
912 | 26 return FALSE; |
27 | |
951 | 28 if (!file_exists($tmpFilename)) |
912 | 29 { |
30 echo "ERROR: gfxconv did not output a temporary conversion inbetween.\n"; | |
31 return FALSE; | |
32 } | |
884 | 33 } |
34 else | |
951 | 35 $tmpFilename = $inFilename; |
884 | 36 |
882 | 37 // convert -resize 640x480 -background black -gravity center -extent 640x480 |
38 // -unsharp "0x0.75+0.75+0.008" lol.lbm -quality 95 test.jpg | |
884 | 39 |
40 // Create conversion entity | |
951 | 41 $img = new Imagick($tmpFilename); |
884 | 42 if ($img === false) |
912 | 43 { |
951 | 44 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n"; |
912 | 45 return FALSE; |
46 } | |
884 | 47 |
963 | 48 if ($setDim !== FALSE) |
884 | 49 { |
963 | 50 if (($outDim = stGetSetting($setDim)) === FALSE || |
51 ($outFormat = stGetSetting($setFormat)) === FALSE || | |
52 ($outQuality = stGetSetting($setQuality)) === FALSE) | |
53 { | |
54 die("Missing one of res/format/quality settings for '".$outFilename."'\n"); | |
55 } | |
56 | |
57 // Get dimensions, setup background | |
58 $dim = $img->getImageGeometry(); | |
59 $img->setBackgroundColor(imagick::COLOR_BLACK); | |
60 $img->setGravity(imagick::GRAVITY_CENTER); | |
61 | |
62 // Act based on image size vs. desired size and $thumb mode | |
63 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1]) | |
64 { | |
65 // Image is larger | |
66 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1); | |
67 $img->setExtent($outDim[0], $outDim[1]); | |
68 $img->normalizeImage(); | |
69 $img->unsharpMaskImage(0, 0.5, 1, 0.05); | |
70 } | |
71 else | |
72 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1]) | |
73 { | |
74 // Image is smaller than requested dimension(s)? | |
75 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_POINT, 1); | |
76 $img->setExtent($outDim[0], $outDim[1]); | |
77 } | |
884 | 78 } |
79 | |
80 $img->setFormat($outFormat); | |
81 $img->setCompressionQuality($outQuality); | |
82 | |
83 $img->stripImage(); | |
84 $img->writeImage($outFilename); | |
85 $img->removeImage(); | |
882 | 86 } |
87 | |
88 | |
898 | 89 function wtRenderSample($inFilename, $outFilename) |
882 | 90 { |
898 | 91 $sfreq = intval(stGetSetting("sampleFreq")); |
92 $sduration = intval(stGetSetting("sampleDuration")); | |
93 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 94 |
902 | 95 return wtExec( |
898 | 96 "/usr/local/bin/openmpt123" |
97 , | |
954 | 98 "--force --quiet ". |
884 | 99 "--samplerate ".$sfreq." ". |
100 "--channels ".$schannels." ". | |
101 "--playtime ".$sduration." ". | |
954 | 102 escapeshellarg($inFilename)." -o ".escapeshellarg($outFilename), |
963 | 103 0); |
882 | 104 } |
105 | |
106 | |
948
1334b93939a3
Change how output options are handled in wtConvertSample().
Matti Hamalainen <ccr@tnsp.org>
parents:
947
diff
changeset
|
107 function wtConvertSample($inFilename, $outFilename, $outOpts) |
882 | 108 { |
898 | 109 $sfreq = intval(stGetSetting("sampleFreq")); |
110 $sduration = intval(stGetSetting("sampleDuration")); | |
111 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 112 |
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", |
118 "-y -t ".intval($sduration)." ". | |
119 "-i ".escapeshellarg($inFilename). | |
120 " ".$optStr." -ac ".$schannels. | |
121 " -map_metadata -1 ". | |
122 escapeshellarg($outFilename)); | |
882 | 123 } |
124 | |
125 | |
963 | 126 function wtRenderConvertEntryToSource($inFilename, $edata, $entryFilename, &$outData, &$outFilename) |
882 | 127 { |
963 | 128 // Does compo preview type match this file class? |
129 if ($edata["class"] != $compo["preview_type"]) | |
130 return FALSE; | |
954 | 131 |
963 | 132 $outFilename = stReplaceFileExt($entryFilename, "_preview.".$edata["fext"]); |
133 if (file_exists($outFilename) && filemtime($outFilename) >= filemtime($entryFilename)) | |
134 return FALSE; | |
135 | |
136 echo "CHECKING: ".$inFilename." / ".$edata["id"]."\n"; | |
954 | 137 switch ($edata["class"]) |
939 | 138 { |
954 | 139 case EFILE_AUDIO: |
140 if ($edata["mime"] == "audio/x-mod") | |
963 | 141 $res = wtRenderSample($inFilename, $outFilename); |
954 | 142 else |
963 | 143 $res = wtConvertSample($inFilename, $outFilename, array()); |
954 | 144 break; |
963 | 145 |
954 | 146 case EFILE_IMAGE: |
963 | 147 $res = wtConvertImage( |
148 $inFilename, | |
149 $edata["mime"], | |
150 $outFilename, | |
151 FALSE, "PNG", 9, FALSE); | |
152 break; | |
153 | |
154 default: | |
155 return FALSE; | |
939 | 156 } |
963 | 157 |
158 return $res; | |
882 | 159 } |
160 | |
161 | |
902 | 162 function wtUnpackArchiveTo($atype, $filename, $path) |
882 | 163 { |
164 // Check file type before doing anything | |
953 | 165 echo "INFO: Preparing to unpack archive file '".$filename."' ...\n"; |
902 | 166 switch ($atype) |
882 | 167 { |
168 case "LHA": | |
169 $exe = "/usr/bin/lha"; | |
170 $args = "e ".escapeshellarg($filename); | |
171 break; | |
172 | |
173 case "ZIP": | |
174 $exe = "/usr/bin/unzip"; | |
175 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename); | |
176 break; | |
177 | |
898 | 178 case "RAR": |
179 $exe = "/usr/bin/rar"; | |
180 $args = "e ".escapeshellarg($filename); | |
181 break; | |
182 | |
882 | 183 default: |
902 | 184 echo "Unsupported archive file type: ".$atype."\n"; |
898 | 185 return FALSE; |
882 | 186 } |
187 | |
188 // Create temporary directory | |
189 wtPurgeDir($path); | |
935 | 190 wtMakeDir($path, 0700); |
882 | 191 |
192 if (!is_dir($path) || chdir($path) === false) | |
902 | 193 { |
953 | 194 echo "ERROR: Failed to chdir to '".$path."', can't unpack archive.\n"; |
902 | 195 return FALSE; |
196 } | |
882 | 197 |
198 // Unpack archive | |
902 | 199 return wtExec($exe, $args); |
200 } | |
201 | |
202 | |
933 | 203 function wtNiceName($compo, $entry, $efile = FALSE) |
204 { | |
205 return sprintf( | |
206 "%d: %s by %s%s", | |
207 $entry["id"], | |
208 $entry["name"], | |
209 $entry["author"], | |
210 ($efile !== false) ? " [".$efile["filename"]." / TYPE: '".$efile["filetype"]."']" : ""); | |
211 } | |
212 | |
213 | |
882 | 214 function wtHandleEntryPreview($compo, $entry, $mode) |
215 { | |
941 | 216 global $fileTypeData, $setEntryPath; |
933 | 217 |
218 // Get current preview file(s) data | |
898 | 219 if (!stGetPreviewFileData($compo, $entry, $pdata)) |
220 return FALSE; | |
221 | |
933 | 222 // Get entry file data |
963 | 223 $efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"]); |
898 | 224 |
225 // Check preview file(s) status | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
226 if ($mode == "sta" || $mode == "lis") |
898 | 227 { |
228 printf(" %03d | %s%s%s | %-40s | %-5s | %s\n", | |
229 $entry["id"], | |
933 | 230 ($efile !== false) ? "E" : ".", |
231 isset($pdata["file"]) ? "P" : ".", | |
232 $pdata["valid"] ? "V" : ".", | |
233 substr($entry["name"]." by ".$entry["author"], 0, 40), | |
898 | 234 isset($pdata["file"]) ? $pdata["file"]["filetype"] : "", |
235 isset($pdata["file"]) ? $pdata["file"]["filename"] : "" | |
236 ); | |
954 | 237 return TRUE; |
898 | 238 } |
239 else | |
933 | 240 if ($mode != "upd") |
953 | 241 die("ERROR: Unsupported previews mode ".$mode."\n"); |
933 | 242 |
243 // Check validity of previews | |
244 if ($pdata["valid"]) | |
245 return TRUE; | |
246 | |
247 // Okay, no valid previews .. lets see what we can do .. | |
248 // First, check if we have a source preview file | |
249 if (!isset($pdata["file"])) | |
898 | 250 { |
935 | 251 // No source preview, check if we have entry file either? |
252 if ($efile === false) | |
253 { | |
254 echo | |
255 "INFO: No entry file for ".wtNiceName($compo, $entry, $efile). | |
256 ", can't attempt to generate preview.\n"; | |
257 return FALSE; | |
258 } | |
954 | 259 |
260 // Actual entry filename + path | |
261 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"])); | |
262 if (!file_exists($filename)) | |
263 { | |
264 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n"; | |
265 return FALSE; | |
266 } | |
267 | |
935 | 268 // Preview source file does not exist, let's see .. |
963 | 269 $edata = stProbeFileInfo($filename, TRUE); |
270 if ($edata === false) | |
882 | 271 { |
935 | 272 echo |
273 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
274 return FALSE; | |
275 } | |
276 | |
942 | 277 $found = FALSE; |
935 | 278 if ($edata["class"] == EFILE_ARCHIVE) |
279 { | |
280 // Entry is an archive file .. | |
963 | 281 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $efile["filename"])); |
941 | 282 |
953 | 283 echo "INFO: Entry file is an ".$efile["filetype"]." archive, scanning '".$filename."' ...\n"; |
941 | 284 |
285 if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false) | |
286 return FALSE; | |
935 | 287 |
941 | 288 // Scan through files ... |
289 $dir = opendir($path); | |
290 while (($dentry = readdir($dir)) !== false) | |
291 { | |
292 $fname = $path."/".$dentry; | |
954 | 293 // check file type against entry's preview_type |
294 // if match, render / convert / cp to as source and exit loop. | |
295 if (is_file($fname) && | |
296 ($mdata = stProbeFileInfo($fname, TRUE)) !== false && | |
963 | 297 ($found = wtRenderConvertEntryToSource($fname, $mdata, $filename, $pdata, $outFilename)) === true) |
954 | 298 break; |
941 | 299 } |
954 | 300 |
301 // Cleanup | |
941 | 302 closedir($dir); |
303 wtPurgeDir($path); | |
954 | 304 } |
305 else | |
306 if ($edata["class"] == $compo["preview_type"]) | |
307 { | |
308 // Single file | |
963 | 309 $found = wtRenderConvertEntryToSource($filename, $edata, $filename, $pdata, $outFilename); |
954 | 310 } |
311 | |
950 | 312 if (!$found) |
882 | 313 { |
935 | 314 echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n"; |
315 return FALSE; | |
898 | 316 } |
317 } | |
318 | |
935 | 319 // Either we now have a sourcefile or generated file |
963 | 320 switch ($outData["class"]) |
941 | 321 { |
963 | 322 case EFILE_AUDIO: |
950 | 323 foreach (stGetSetting("sampleTypes") as $stype => $sopts) |
942 | 324 { |
950 | 325 if (!isset($fileTypeData[$stype])) |
326 die("Internal error: Sample type ".$stype." in sampleTypes in mconfig.inc.php, but not defined in file type data.\n"); | |
327 | |
328 $filename = $pdata["files"][$sdata]["file"]; | |
329 | |
330 wtConvertSample( | |
331 $inFilename, | |
332 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), | |
333 $sopts | |
334 ); | |
942 | 335 } |
336 break; | |
337 | |
963 | 338 case EFILE_IMAGE: |
942 | 339 wtConvertImage($inFilename, |
340 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), | |
341 "previewImageSize", "previewImageType", | |
342 "previewImageQuality", FALSE); | |
882 | 343 |
942 | 344 wtConvertImage($inFilename, |
345 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $setThumbPath, $filename)), | |
346 "previewThumbSize", "previewThumbType", | |
347 "previewThumbQuality", TRUE); | |
348 break; | |
941 | 349 } |
963 | 350 |
933 | 351 return TRUE; |
882 | 352 } |
353 | |
354 | |
884 | 355 function wtHandleEntry($compo, $entry, $mode) |
356 { | |
357 } | |
358 | |
359 | |
963 | 360 function wtUnpackEntry($compo, $entry, $pathPrefix, $useOrig = TRUE) |
361 { | |
362 global $setEntryPath; | |
363 | |
364 if (($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"])) === false) | |
365 { | |
366 echo "INFO: No entry file for ".wtNiceName($compo, $entry, $efile)."\n"; | |
367 return FALSE; | |
368 } | |
369 | |
370 $filename = stMakePath(FALSE, TRUE, array($setEntryPath, $compo["cpath"], $efile["filename"])); | |
371 if (!file_exists($filename)) | |
372 { | |
373 echo "ERROR: Entry file '".$filename."' for ".wtNiceName($compo, $entry, FALSE)." does not exist!\n"; | |
374 return FALSE; | |
375 } | |
376 | |
377 $edata = stProbeFileInfo($filename, TRUE); | |
378 if ($edata === false) | |
379 { | |
380 echo | |
381 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
382 return FALSE; | |
383 } | |
384 | |
385 if (wtMakeDir(stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"])), 0755) === false) | |
386 return FALSE; | |
387 | |
964 | 388 $dstFileBase = $entry["show_id"]."--".($useOrig ? $efile["origname"] : $efile["filename"]); |
963 | 389 |
390 if ($edata["class"] == EFILE_ARCHIVE) | |
391 { | |
392 // Entry is an archive file .. | |
393 $dstPath = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], stReplaceFileExt($dstFileBase, ""))); | |
964 | 394 if (wtUnpackArchiveTo($edata["id"], $filename, $dstPath) === false) |
963 | 395 return FALSE; |
396 } | |
397 else | |
398 { | |
399 $dstFilename = stMakePath(FALSE, FALSE, array($pathPrefix, $compo["cpath"], $dstFileBase)); | |
400 if (copy($filename, $dstFilename) === false) | |
401 { | |
402 echo "Failed to copy '".$filename."' to '".$dstFilename."'\n"; | |
403 return FALSE; | |
404 } | |
405 } | |
406 | |
407 return TRUE; | |
408 } | |
409 | |
410 | |
827 | 411 // |
941 | 412 // Misc helper functions |
827 | 413 // |
941 | 414 function wtExec($exe, $args, $expect = 0) |
415 { | |
953 | 416 echo "EXEC: ".$exe." ".$args."\n"; |
941 | 417 exec(escapeshellcmd($exe)." ".$args, $output, $code); |
418 if ($code !== $expect) | |
419 { | |
420 echo | |
953 | 421 "ERROR: Executing ".$exe.": ".$code."\n".$args."\n". |
941 | 422 "------------------------------------------------\n". |
423 implode("\n", $output). | |
424 "------------------------------------------------\n"; | |
425 return FALSE; | |
426 } | |
427 return TRUE; | |
428 } | |
429 | |
430 | |
431 function wtExecOrDie($exe, $args) | |
432 { | |
433 if (wtExec($exe, $args) === false) | |
434 die(); | |
435 } | |
436 | |
437 | |
438 function wtPurgeDir($path) | |
439 { | |
942 | 440 if ($path != "" && $path !== false && file_exists($path) && is_dir($path)) |
941 | 441 { |
442 echo "PURGING: ".$path."\n"; | |
942 | 443 foreach (scandir($path) as $file) |
444 if ($file !== "." && $file !== "..") | |
445 { | |
446 $sub = $path."/".$file; | |
447 if (is_dir($sub)) | |
448 wtPurgeDir($sub); | |
449 else | |
450 { | |
451 echo " - ".$sub."\n"; | |
452 unlink($sub); | |
453 } | |
454 } | |
455 rmdir($path); | |
941 | 456 } |
457 } | |
458 | |
459 | |
935 | 460 function wtMakeDir($path, $perm) |
827 | 461 { |
462 if (!file_exists($path)) | |
463 { | |
953 | 464 echo "INFO: Creating ".$path."\n"; |
827 | 465 if (mkdir($path, $perm, TRUE) === false) |
466 die("Could not create directory '".$path."'\n"); | |
467 } | |
468 } | |
469 | |
470 | |
935 | 471 function wtInitializeDirs() |
827 | 472 { |
902 | 473 global |
474 $setEntryPath, $setPreviewPath, $setThumbDir, | |
827 | 475 $setEntryPathPerms, $setPrevPathPerms; |
476 | |
477 echo "Checking for missing directories ...\n"; | |
935 | 478 wtMakeDir($setEntryPath, $setEntryPathPerms); |
479 wtMakeDir($setPreviewPath, $setPrevPathPerms); | |
827 | 480 |
481 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
482 { | |
935 | 483 wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); |
484 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); | |
485 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); | |
827 | 486 } |
487 } | |
488 | |
489 | |
935 | 490 function wtShowHelp() |
827 | 491 { |
935 | 492 global $argv; |
827 | 493 echo |
494 "faptool - Do stuff with FAPWeb database\n". | |
495 "(C) Copyright 2014 ccr/TNSP\n". | |
496 "\n". | |
917 | 497 "Usage: ".$argv[0]." <command> [args]\n". |
498 "Where command is one of following:\n". | |
827 | 499 "\n". |
500 " init\n". | |
501 " Create directories for entries and previews, if needed.\n". | |
502 "\n". | |
928 | 503 /* |
917 | 504 " clean [delete|crap]\n". |
505 " Clean files marked to be deleted and 'stale' files. This includes\n". | |
506 " any old or stale preview files and entry files.\n". | |
507 " Without 'delete' parameter just checks and shows what would deleted.\n". | |
508 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n". | |
509 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n". | |
510 " KNOW WHAT YOU ARE DOING!!!!!\n". | |
901 | 511 "\n". |
928 | 512 */ |
938 | 513 " probe <filename> [filename2 ..]\n". |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
514 " Probe specified file for file information.\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
515 "\n". |
881 | 516 " previews <cmd> [args]\n". |
517 " Where <cmd> is one of:\n". | |
933 | 518 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n". |
928 | 519 " update - Generate preview files that are missing OR out of date.\n". |
520 " (older then preview source file OR entry file where appropriate)\n". | |
521 // " add <entry_id> <filename> - Add file as preview for entry_id.\n". | |
901 | 522 "\n". |
523 " entry <cmd> [args]\n". | |
933 | 524 " status [cid] - List entries for all compos or <cid>.\n". |
966 | 525 " unpack <path> - Create subdirs and copy all entries UNPACKED there.\n". |
928 | 526 /* |
527 " add <filename> '<name>' '<author>' - Add file as entry file\n". | |
528 " (works same as uploading from admin interface)\n". | |
529 " package <lha|zip|rar|7z>\n". | |
530 " Repackages/packages entries (unpacks first if archive),\n". | |
531 " and adds generated infofile.txt to packages.\n". | |
532 */ | |
827 | 533 "\n"; |
935 | 534 } |
535 | |
536 // | |
537 // Main program starts | |
538 // | |
944
535466595a5a
Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents:
943
diff
changeset
|
539 stCheckCLIExec(); |
935 | 540 if ($argc < 2) |
541 { | |
542 wtShowHelp(); | |
827 | 543 exit; |
544 } | |
545 | |
935 | 546 |
827 | 547 // Try to connect to database |
548 $spec = stGetSetting("sqlDB"); | |
549 if (($db = stConnectSQLDBSpec($spec)) === false) | |
550 die("Could not connect to SQL database '".$spec."'.\n"); | |
551 | |
552 echo "Using database spec '".$spec."'.\n"; | |
553 | |
554 // Fetch non-"hardcoded" settings from SQL database | |
555 stReloadSettings(); | |
556 | |
557 // Set some globals for our benefit | |
922 | 558 $setTermWidth = 75; |
827 | 559 $setEntryPath = stGetSetting("entryPath"); |
560 $setPreviewPath = stGetSetting("previewPath"); | |
561 $setPreviewURL = stGetSetting("previewURL"); | |
562 $setThumbDir = stGetSetting("thumbnailSubDir"); | |
832 | 563 $setEntryPathPerms = stGetSetting("entryPathPerms"); |
564 $setPrevPathPerms = stGetSetting("previewPathPerms"); | |
827 | 565 |
566 if ($setEntryPath === FALSE || $setPreviewPath === FALSE || | |
832 | 567 $setPreviewURL === FALSE || $setThumbDir === FALSE || |
568 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE) | |
827 | 569 { |
922 | 570 die("Some required settings are not defined in mconfig.inc.php!\n"); |
827 | 571 } |
572 | |
573 | |
574 // Act according to specified command | |
884 | 575 switch (substr(stCArgLC(1), 0, 3)) |
827 | 576 { |
935 | 577 case "-?": case "--h": |
578 wtShowHelp(); | |
579 exit; | |
580 break; | |
581 | |
884 | 582 case "ini": |
827 | 583 // |
584 // Initialize the data directories etc | |
585 // | |
953 | 586 echo "INFO: Checking for missing directories ...\n"; |
935 | 587 wtInitializeDirs(); |
827 | 588 break; |
589 | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
590 case "pro": |
945 | 591 // |
592 // Probe specified files | |
593 // | |
594 if ($argc < 2) | |
595 die("No filename specified.\n"); | |
596 | |
597 if (($finfo = finfo_open()) === false) | |
954 | 598 die("Internal error. Failed to initialize finfo()."); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
599 |
945 | 600 for ($i = 2; $i < $argc; $i++) |
601 { | |
602 // Probe one file | |
603 $filename = $argv[$i]; | |
604 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); | |
605 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); | |
606 | |
607 echo | |
608 "\n". | |
609 "File : ".$filename."\n". | |
610 "Probed : ".$sdata."\n". | |
611 "Mime : ".$smime."\n"; | |
612 | |
954 | 613 if (($info = stProbeFileInfo($filename, TRUE)) !== false) |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
614 { |
945 | 615 $tmp = array(); |
616 foreach ($info as $ikey => $ival) | |
617 $tmp[] = $ikey."='".$ival."'"; | |
618 | |
619 echo "Data : ".implode(", ", $tmp)."\n"; | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
620 } |
946 | 621 } |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
622 |
946 | 623 finfo_close($finfo); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
624 break; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
625 |
901 | 626 case "cle": |
947 | 627 // |
628 // File cleanup / deletion | |
629 // | |
901 | 630 $doDelete = (stCArgLC(2) == "delete"); |
631 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
632 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
633 { | |
634 printf( | |
935 | 635 "==%'=-".($setTermWidth-2)."s\n", |
901 | 636 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
637 ); | |
922 | 638 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 639 |
640 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
641 { | |
642 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
643 { | |
935 | 644 if ($efile["deleted"] != 0) |
901 | 645 { |
646 echo "X"; | |
647 } | |
648 } | |
649 } | |
650 echo "\n"; | |
922 | 651 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 652 } |
653 break; | |
654 | |
655 case "ent": | |
656 // | |
657 // Entry files handling | |
658 // | |
659 $mode = substr(stCArgLC(2), 0, 3); | |
660 switch ($mode) | |
661 { | |
662 case "sta": | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
663 case "lis": |
933 | 664 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
665 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
901 | 666 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
667 { | |
668 printf( | |
922 | 669 "==%'=-".($setTermWidth-2)."s\n". |
901 | 670 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
671 ); | |
922 | 672 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 673 |
674 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
675 wtHandleEntry($compo, $entry, $mode); | |
676 | |
922 | 677 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 678 } |
679 break; | |
680 | |
963 | 681 case "unp": |
682 if (($setPrefix = stCArg(3)) == "") | |
683 die("Unpack needs a destination path.\n"); | |
684 | |
685 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
686 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
687 { | |
688 wtUnpackEntry($compo, $entry, $setPrefix); | |
689 } | |
690 break; | |
691 | |
901 | 692 case "pac": |
929 | 693 echo "Not implemented. :D\n"; |
901 | 694 break; |
695 | |
696 case "add": | |
929 | 697 echo "Not implemented. :D\n"; |
901 | 698 break; |
699 | |
700 default: | |
701 if ($mode == "") | |
702 die("ERROR! Entry command requires a sub-command argument.\n"); | |
703 else | |
704 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
705 break; | |
706 } | |
707 break; | |
708 | |
884 | 709 case "pre": |
881 | 710 // |
711 // Preview files handling | |
712 // | |
713 $mode = substr(stCArgLC(2), 0, 3); | |
714 switch ($mode) | |
715 { | |
898 | 716 case "upd": |
881 | 717 case "sta": |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
718 case "lis": |
933 | 719 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
720 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
898 | 721 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 722 { |
723 printf( | |
922 | 724 "==%'=-".($setTermWidth-2)."s\n". |
898 | 725 "PrevType : %s\n", |
726 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)), | |
727 $previewTypeList[$compo["preview_type"]][0]); | |
941 | 728 |
729 if ($mode == "sta") | |
730 { | |
731 printf(" %-3s | %-3s | %-40s |\n", | |
732 "#ID", "FLG", "Entry name/author"); | |
733 } | |
734 | |
922 | 735 echo str_repeat("-", $setTermWidth)."\n"; |
881 | 736 |
737 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
738 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 739 |
922 | 740 echo str_repeat("=", $setTermWidth)."\n\n"; |
881 | 741 } |
742 break; | |
743 | |
901 | 744 case "add": |
929 | 745 echo "Not implemented. :D\n"; |
901 | 746 break; |
747 | |
881 | 748 default: |
749 if ($mode == "") | |
750 die("ERROR! Previews command requires a sub-command argument.\n"); | |
751 else | |
752 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
753 break; | |
754 } | |
755 break; | |
756 | |
827 | 757 default: |
758 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
759 break; | |
760 } | |
761 | |
941 | 762 /* Dummy |
763 { | |
764 | |
765 } | |
766 */ | |
827 | 767 ?> |