Mercurial > hg > fapweb
annotate faptool.php @ 951:6549fb84a814
Rename a variable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Nov 2014 08:40:32 +0200 |
parents | 527e62f39af6 |
children | 3b18afe14e46 |
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 | |
951 | 28 $tmpFilename = tempnam($setPreviewPath, "tmp"); |
912 | 29 $isTemp = TRUE; |
30 if (wtExec( | |
884 | 31 "/usr/local/bin/gfxconv", |
951 | 32 escapeshellarg($inFilename)." -f png -o ".escapeshellarg($tmpFilename)) === false) |
912 | 33 return FALSE; |
34 | |
951 | 35 if (!file_exists($tmpFilename)) |
912 | 36 { |
37 echo "ERROR: gfxconv did not output a temporary conversion inbetween.\n"; | |
38 return FALSE; | |
39 } | |
40 | |
884 | 41 } |
42 else | |
951 | 43 $tmpFilename = $inFilename; |
884 | 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 | |
951 | 49 $img = new Imagick($tmpFilename); |
884 | 50 if ($img === false) |
912 | 51 { |
951 | 52 echo "ERROR: Oh noes! ImageMagick could not digest the file '".$tmpFilename."' (".$inFilename.")\n"; |
912 | 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 |
950 | 280 // $found = wtRenderConvertEntryToSource(); |
935 | 281 |
950 | 282 if (!$found) |
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: |
950 | 294 foreach (stGetSetting("sampleTypes") as $stype => $sopts) |
942 | 295 { |
950 | 296 if (!isset($fileTypeData[$stype])) |
297 die("Internal error: Sample type ".$stype." in sampleTypes in mconfig.inc.php, but not defined in file type data.\n"); | |
298 | |
299 $filename = $pdata["files"][$sdata]["file"]; | |
300 | |
301 wtConvertSample( | |
302 $inFilename, | |
303 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), | |
304 $sopts | |
305 ); | |
942 | 306 } |
307 break; | |
308 | |
309 case image: | |
310 wtConvertImage($inFilename, | |
311 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), | |
312 "previewImageSize", "previewImageType", | |
313 "previewImageQuality", FALSE); | |
882 | 314 |
942 | 315 wtConvertImage($inFilename, |
316 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $setThumbPath, $filename)), | |
317 "previewThumbSize", "previewThumbType", | |
318 "previewThumbQuality", TRUE); | |
319 break; | |
941 | 320 } |
882 | 321 */ |
933 | 322 return TRUE; |
882 | 323 } |
324 | |
325 | |
884 | 326 function wtHandleEntry($compo, $entry, $mode) |
327 { | |
328 } | |
329 | |
330 | |
827 | 331 // |
941 | 332 // Misc helper functions |
827 | 333 // |
941 | 334 function wtExec($exe, $args, $expect = 0) |
335 { | |
336 echo "@@EXEC: ".$exe." ".$args."\n"; | |
337 exec(escapeshellcmd($exe)." ".$args, $output, $code); | |
338 if ($code !== $expect) | |
339 { | |
340 echo | |
341 "Error executing ".$exe.": ".$code."\n".$args."\n". | |
342 "------------------------------------------------\n". | |
343 implode("\n", $output). | |
344 "------------------------------------------------\n"; | |
345 return FALSE; | |
346 } | |
347 return TRUE; | |
348 } | |
349 | |
350 | |
351 function wtExecOrDie($exe, $args) | |
352 { | |
353 if (wtExec($exe, $args) === false) | |
354 die(); | |
355 } | |
356 | |
357 | |
358 function wtPurgeDir($path) | |
359 { | |
942 | 360 if ($path != "" && $path !== false && file_exists($path) && is_dir($path)) |
941 | 361 { |
362 echo "PURGING: ".$path."\n"; | |
942 | 363 foreach (scandir($path) as $file) |
364 if ($file !== "." && $file !== "..") | |
365 { | |
366 $sub = $path."/".$file; | |
367 if (is_dir($sub)) | |
368 wtPurgeDir($sub); | |
369 else | |
370 { | |
371 echo " - ".$sub."\n"; | |
372 unlink($sub); | |
373 } | |
374 } | |
375 rmdir($path); | |
941 | 376 } |
377 } | |
378 | |
379 | |
935 | 380 function wtMakeDir($path, $perm) |
827 | 381 { |
382 if (!file_exists($path)) | |
383 { | |
384 echo " - Creating ".$path."\n"; | |
385 if (mkdir($path, $perm, TRUE) === false) | |
386 die("Could not create directory '".$path."'\n"); | |
387 } | |
388 } | |
389 | |
390 | |
935 | 391 function wtInitializeDirs() |
827 | 392 { |
902 | 393 global |
394 $setEntryPath, $setPreviewPath, $setThumbDir, | |
827 | 395 $setEntryPathPerms, $setPrevPathPerms; |
396 | |
397 echo "Checking for missing directories ...\n"; | |
935 | 398 wtMakeDir($setEntryPath, $setEntryPathPerms); |
399 wtMakeDir($setPreviewPath, $setPrevPathPerms); | |
827 | 400 |
401 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
402 { | |
935 | 403 wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); |
404 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); | |
405 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); | |
827 | 406 } |
407 } | |
408 | |
409 | |
935 | 410 function wtShowHelp() |
827 | 411 { |
935 | 412 global $argv; |
827 | 413 echo |
414 "faptool - Do stuff with FAPWeb database\n". | |
415 "(C) Copyright 2014 ccr/TNSP\n". | |
416 "\n". | |
917 | 417 "Usage: ".$argv[0]." <command> [args]\n". |
418 "Where command is one of following:\n". | |
827 | 419 "\n". |
420 " init\n". | |
421 " Create directories for entries and previews, if needed.\n". | |
422 "\n". | |
928 | 423 /* |
917 | 424 " clean [delete|crap]\n". |
425 " Clean files marked to be deleted and 'stale' files. This includes\n". | |
426 " any old or stale preview files and entry files.\n". | |
427 " Without 'delete' parameter just checks and shows what would deleted.\n". | |
428 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n". | |
429 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n". | |
430 " KNOW WHAT YOU ARE DOING!!!!!\n". | |
901 | 431 "\n". |
928 | 432 */ |
938 | 433 " probe <filename> [filename2 ..]\n". |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
434 " Probe specified file for file information.\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
435 "\n". |
881 | 436 " previews <cmd> [args]\n". |
437 " Where <cmd> is one of:\n". | |
933 | 438 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n". |
928 | 439 " update - Generate preview files that are missing OR out of date.\n". |
440 " (older then preview source file OR entry file where appropriate)\n". | |
441 // " add <entry_id> <filename> - Add file as preview for entry_id.\n". | |
901 | 442 "\n". |
443 " entry <cmd> [args]\n". | |
933 | 444 " status [cid] - List entries for all compos or <cid>.\n". |
445 " unpack - Create subdirs and unpack archives under them.\n". | |
928 | 446 /* |
447 " add <filename> '<name>' '<author>' - Add file as entry file\n". | |
448 " (works same as uploading from admin interface)\n". | |
449 " package <lha|zip|rar|7z>\n". | |
450 " Repackages/packages entries (unpacks first if archive),\n". | |
451 " and adds generated infofile.txt to packages.\n". | |
452 */ | |
827 | 453 "\n"; |
935 | 454 } |
455 | |
456 // | |
457 // Main program starts | |
458 // | |
944
535466595a5a
Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents:
943
diff
changeset
|
459 stCheckCLIExec(); |
935 | 460 if ($argc < 2) |
461 { | |
462 wtShowHelp(); | |
827 | 463 exit; |
464 } | |
465 | |
935 | 466 |
827 | 467 // Try to connect to database |
468 $spec = stGetSetting("sqlDB"); | |
469 if (($db = stConnectSQLDBSpec($spec)) === false) | |
470 die("Could not connect to SQL database '".$spec."'.\n"); | |
471 | |
472 echo "Using database spec '".$spec."'.\n"; | |
473 | |
474 // Fetch non-"hardcoded" settings from SQL database | |
475 stReloadSettings(); | |
476 | |
477 // Set some globals for our benefit | |
922 | 478 $setTermWidth = 75; |
827 | 479 $setEntryPath = stGetSetting("entryPath"); |
480 $setPreviewPath = stGetSetting("previewPath"); | |
481 $setPreviewURL = stGetSetting("previewURL"); | |
482 $setThumbDir = stGetSetting("thumbnailSubDir"); | |
832 | 483 $setEntryPathPerms = stGetSetting("entryPathPerms"); |
484 $setPrevPathPerms = stGetSetting("previewPathPerms"); | |
827 | 485 |
486 if ($setEntryPath === FALSE || $setPreviewPath === FALSE || | |
832 | 487 $setPreviewURL === FALSE || $setThumbDir === FALSE || |
488 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE) | |
827 | 489 { |
922 | 490 die("Some required settings are not defined in mconfig.inc.php!\n"); |
827 | 491 } |
492 | |
493 | |
494 // Act according to specified command | |
884 | 495 switch (substr(stCArgLC(1), 0, 3)) |
827 | 496 { |
935 | 497 case "-?": case "--h": |
498 wtShowHelp(); | |
499 exit; | |
500 break; | |
501 | |
884 | 502 case "ini": |
827 | 503 // |
504 // Initialize the data directories etc | |
505 // | |
935 | 506 wtInitializeDirs(); |
827 | 507 break; |
508 | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
509 case "pro": |
945 | 510 // |
511 // Probe specified files | |
512 // | |
513 if ($argc < 2) | |
514 die("No filename specified.\n"); | |
515 | |
516 if (($finfo = finfo_open()) === false) | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
517 { |
945 | 518 stLogError("Internal error. Failed to initialize finfo()."); |
519 return stError("Internal error, failed to probe file."); | |
520 } | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
521 |
945 | 522 for ($i = 2; $i < $argc; $i++) |
523 { | |
524 // Probe one file | |
525 $filename = $argv[$i]; | |
526 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); | |
527 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); | |
528 | |
529 echo | |
530 "\n". | |
531 "File : ".$filename."\n". | |
532 "Probed : ".$sdata."\n". | |
533 "Mime : ".$smime."\n"; | |
534 | |
535 if (($info = stProbeFileInfo($filename)) !== false) | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
536 { |
945 | 537 $tmp = array(); |
538 foreach ($info as $ikey => $ival) | |
539 $tmp[] = $ikey."='".$ival."'"; | |
540 | |
541 echo "Data : ".implode(", ", $tmp)."\n"; | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
542 } |
946 | 543 } |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
544 |
946 | 545 finfo_close($finfo); |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
546 break; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
547 |
901 | 548 case "cle": |
947 | 549 // |
550 // File cleanup / deletion | |
551 // | |
901 | 552 $doDelete = (stCArgLC(2) == "delete"); |
553 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
554 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
555 { | |
556 printf( | |
935 | 557 "==%'=-".($setTermWidth-2)."s\n", |
901 | 558 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
559 ); | |
922 | 560 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 561 |
562 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
563 { | |
564 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
565 { | |
935 | 566 if ($efile["deleted"] != 0) |
901 | 567 { |
568 echo "X"; | |
569 } | |
570 } | |
571 } | |
572 echo "\n"; | |
922 | 573 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 574 } |
575 break; | |
576 | |
577 case "ent": | |
578 // | |
579 // Entry files handling | |
580 // | |
581 $mode = substr(stCArgLC(2), 0, 3); | |
582 switch ($mode) | |
583 { | |
584 case "unp": | |
585 case "sta": | |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
586 case "lis": |
933 | 587 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
588 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
901 | 589 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
590 { | |
591 printf( | |
922 | 592 "==%'=-".($setTermWidth-2)."s\n". |
901 | 593 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
594 ); | |
922 | 595 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 596 |
597 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
598 wtHandleEntry($compo, $entry, $mode); | |
599 | |
922 | 600 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 601 } |
602 break; | |
603 | |
604 case "pac": | |
929 | 605 echo "Not implemented. :D\n"; |
901 | 606 break; |
607 | |
608 case "add": | |
929 | 609 echo "Not implemented. :D\n"; |
901 | 610 break; |
611 | |
612 default: | |
613 if ($mode == "") | |
614 die("ERROR! Entry command requires a sub-command argument.\n"); | |
615 else | |
616 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
617 break; | |
618 } | |
619 break; | |
620 | |
884 | 621 case "pre": |
881 | 622 // |
623 // Preview files handling | |
624 // | |
625 $mode = substr(stCArgLC(2), 0, 3); | |
626 switch ($mode) | |
627 { | |
898 | 628 case "upd": |
881 | 629 case "sta": |
949
2179600710d1
Add "lis" as alias to "sta".
Matti Hamalainen <ccr@tnsp.org>
parents:
948
diff
changeset
|
630 case "lis": |
933 | 631 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
632 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
898 | 633 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 634 { |
635 printf( | |
922 | 636 "==%'=-".($setTermWidth-2)."s\n". |
898 | 637 "PrevType : %s\n", |
638 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)), | |
639 $previewTypeList[$compo["preview_type"]][0]); | |
941 | 640 |
641 if ($mode == "sta") | |
642 { | |
643 printf(" %-3s | %-3s | %-40s |\n", | |
644 "#ID", "FLG", "Entry name/author"); | |
645 } | |
646 | |
922 | 647 echo str_repeat("-", $setTermWidth)."\n"; |
881 | 648 |
649 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
650 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 651 |
922 | 652 echo str_repeat("=", $setTermWidth)."\n\n"; |
881 | 653 } |
654 break; | |
655 | |
901 | 656 case "add": |
929 | 657 echo "Not implemented. :D\n"; |
901 | 658 break; |
659 | |
881 | 660 default: |
661 if ($mode == "") | |
662 die("ERROR! Previews command requires a sub-command argument.\n"); | |
663 else | |
664 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
665 break; | |
666 } | |
667 break; | |
668 | |
827 | 669 default: |
670 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
671 break; | |
672 } | |
673 | |
941 | 674 /* Dummy |
675 { | |
676 | |
677 } | |
678 */ | |
827 | 679 ?> |