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