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