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