Mercurial > hg > fapweb
annotate faptool.php @ 947:f709816c71cd
Add a comment.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Nov 2014 07:38:07 +0200 |
parents | 99086b6afcdb |
children | 1334b93939a3 |
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 | |
939 | 104 function wtConvertSample($inFilename, $outFilename, $type) |
882 | 105 { |
898 | 106 $sfreq = intval(stGetSetting("sampleFreq")); |
107 $sduration = intval(stGetSetting("sampleDuration")); | |
108 $schannels = intval(stGetSetting("sampleChannels")); | |
882 | 109 |
939 | 110 $stypes = stGetSetting("sampleTypes"); |
111 if (!isset($stypes[$type])) | |
112 die("ERROR: Specified sample type '".$type."' not defined in sampleTypes in mconfig.inc.php\n"); | |
113 | |
114 foreach ($stypes[$type] 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 | |
941 | 127 function wtRenderConvertEntryToSource() |
882 | 128 { |
941 | 129 /* |
130 if (entry is module file) | |
939 | 131 { |
941 | 132 // Construct output filename |
133 return wtRenderSample(); | |
939 | 134 } |
941 | 135 else |
136 if (entry is image file) | |
137 { | |
138 // Construct output filename | |
139 return wtConvertImage(); | |
140 } | |
141 */ | |
142 return FALSE; | |
882 | 143 } |
144 | |
145 | |
902 | 146 function wtUnpackArchiveTo($atype, $filename, $path) |
882 | 147 { |
148 // Check file type before doing anything | |
902 | 149 echo "Preparing to unpack archive file '".$filename."' ...\n"; |
150 switch ($atype) | |
882 | 151 { |
152 case "LHA": | |
153 $exe = "/usr/bin/lha"; | |
154 $args = "e ".escapeshellarg($filename); | |
155 break; | |
156 | |
157 case "ZIP": | |
158 $exe = "/usr/bin/unzip"; | |
159 $args = "-d ".escapeshellarg($path)." ".escapeshellarg($filename); | |
160 break; | |
161 | |
898 | 162 case "RAR": |
163 $exe = "/usr/bin/rar"; | |
164 $args = "e ".escapeshellarg($filename); | |
165 break; | |
166 | |
882 | 167 default: |
902 | 168 echo "Unsupported archive file type: ".$atype."\n"; |
898 | 169 return FALSE; |
882 | 170 } |
171 | |
172 // Create temporary directory | |
173 wtPurgeDir($path); | |
935 | 174 wtMakeDir($path, 0700); |
882 | 175 |
176 if (!is_dir($path) || chdir($path) === false) | |
902 | 177 { |
178 echo "Failed to chdir to '".$path."', can't unpack archive.\n"; | |
179 return FALSE; | |
180 } | |
882 | 181 |
182 // Unpack archive | |
902 | 183 return wtExec($exe, $args); |
184 } | |
185 | |
186 | |
933 | 187 function wtNiceName($compo, $entry, $efile = FALSE) |
188 { | |
189 return sprintf( | |
190 "%d: %s by %s%s", | |
191 $entry["id"], | |
192 $entry["name"], | |
193 $entry["author"], | |
194 ($efile !== false) ? " [".$efile["filename"]." / TYPE: '".$efile["filetype"]."']" : ""); | |
195 } | |
196 | |
197 | |
882 | 198 function wtHandleEntryPreview($compo, $entry, $mode) |
199 { | |
941 | 200 global $fileTypeData, $setEntryPath; |
933 | 201 |
202 // Get current preview file(s) data | |
898 | 203 if (!stGetPreviewFileData($compo, $entry, $pdata)) |
204 return FALSE; | |
205 | |
933 | 206 // Get entry file data |
898 | 207 if ($entry["file_id"] != 0) |
208 $efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["file_id"]); | |
209 else | |
210 $efile = FALSE; | |
211 | |
212 // Check preview file(s) status | |
213 if ($mode == "sta") | |
214 { | |
215 printf(" %03d | %s%s%s | %-40s | %-5s | %s\n", | |
216 $entry["id"], | |
933 | 217 ($efile !== false) ? "E" : ".", |
218 isset($pdata["file"]) ? "P" : ".", | |
219 $pdata["valid"] ? "V" : ".", | |
220 substr($entry["name"]." by ".$entry["author"], 0, 40), | |
898 | 221 isset($pdata["file"]) ? $pdata["file"]["filetype"] : "", |
222 isset($pdata["file"]) ? $pdata["file"]["filename"] : "" | |
223 ); | |
224 } | |
225 else | |
933 | 226 if ($mode != "upd") |
227 die("Unsupported previews mode ".$mode."\n"); | |
228 | |
229 // Check validity of previews | |
230 if ($pdata["valid"]) | |
231 return TRUE; | |
232 | |
233 // Okay, no valid previews .. lets see what we can do .. | |
234 // First, check if we have a source preview file | |
235 if (!isset($pdata["file"])) | |
898 | 236 { |
935 | 237 // No source preview, check if we have entry file either? |
238 if ($efile === false) | |
239 { | |
240 echo | |
241 "INFO: No entry file for ".wtNiceName($compo, $entry, $efile). | |
242 ", can't attempt to generate preview.\n"; | |
243 return FALSE; | |
244 } | |
245 | |
246 // Preview source file does not exist, let's see .. | |
247 if (!isset($fileTypeData[$efile["filetype"]])) | |
882 | 248 { |
935 | 249 echo |
250 "ERROR: Invalid/unsupported file type for entry ".wtNiceName($compo, $entry, $efile)."\n"; | |
251 return FALSE; | |
252 } | |
253 | |
942 | 254 $found = FALSE; |
935 | 255 $edata = $fileTypeData[$efile["filetype"]]; |
256 | |
257 if ($edata["class"] == EFILE_ARCHIVE) | |
258 { | |
259 // Entry is an archive file .. | |
941 | 260 $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename)); |
261 | |
262 echo "Attempting to scan archive file '".$filename."' ...\n"; | |
263 | |
264 if (wtUnpackArchiveTo($efile["filetype"], $filename, $path) === false) | |
265 return FALSE; | |
935 | 266 |
941 | 267 // Scan through files ... |
268 $dir = opendir($path); | |
269 while (($dentry = readdir($dir)) !== false) | |
270 { | |
271 $fname = $path."/".$dentry; | |
272 if (is_file($fname)) | |
273 { | |
274 echo $fname."\n"; | |
942 | 275 // check file type against entry's preview_type |
276 // if match, render / convert / cp to as source and exit loop. | |
941 | 277 } |
278 } | |
279 closedir($dir); | |
280 | |
281 wtPurgeDir($path); | |
942 | 282 } // archive |
941 | 283 // else |
284 // $done = wtRenderConvertEntryToSource(); | |
935 | 285 |
286 if (!$done) | |
882 | 287 { |
935 | 288 echo "WARNING: Could not generate preview from entry ".wtNiceName($compo, $entry, $efile)."\n"; |
289 return FALSE; | |
898 | 290 } |
291 } | |
292 | |
935 | 293 // Either we now have a sourcefile or generated file |
294 /* | |
942 | 295 switch (source) |
941 | 296 { |
942 | 297 case audio: |
298 foreach (...) | |
299 { | |
300 wtConvertSample(); | |
301 } | |
302 break; | |
303 | |
304 case image: | |
305 wtConvertImage($inFilename, | |
306 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $filename)), | |
307 "previewImageSize", "previewImageType", | |
308 "previewImageQuality", FALSE); | |
882 | 309 |
942 | 310 wtConvertImage($inFilename, |
311 stMakePath(FALSE, TRUE, array($setPreviewPath, $compo["cpath"], $setThumbPath, $filename)), | |
312 "previewThumbSize", "previewThumbType", | |
313 "previewThumbQuality", TRUE); | |
314 break; | |
941 | 315 } |
882 | 316 */ |
933 | 317 return TRUE; |
882 | 318 } |
319 | |
320 | |
884 | 321 function wtHandleEntry($compo, $entry, $mode) |
322 { | |
323 } | |
324 | |
325 | |
827 | 326 // |
941 | 327 // Misc helper functions |
827 | 328 // |
941 | 329 function wtExec($exe, $args, $expect = 0) |
330 { | |
331 echo "@@EXEC: ".$exe." ".$args."\n"; | |
332 exec(escapeshellcmd($exe)." ".$args, $output, $code); | |
333 if ($code !== $expect) | |
334 { | |
335 echo | |
336 "Error executing ".$exe.": ".$code."\n".$args."\n". | |
337 "------------------------------------------------\n". | |
338 implode("\n", $output). | |
339 "------------------------------------------------\n"; | |
340 return FALSE; | |
341 } | |
342 return TRUE; | |
343 } | |
344 | |
345 | |
346 function wtExecOrDie($exe, $args) | |
347 { | |
348 if (wtExec($exe, $args) === false) | |
349 die(); | |
350 } | |
351 | |
352 | |
353 function wtPurgeDir($path) | |
354 { | |
942 | 355 if ($path != "" && $path !== false && file_exists($path) && is_dir($path)) |
941 | 356 { |
357 echo "PURGING: ".$path."\n"; | |
942 | 358 foreach (scandir($path) as $file) |
359 if ($file !== "." && $file !== "..") | |
360 { | |
361 $sub = $path."/".$file; | |
362 if (is_dir($sub)) | |
363 wtPurgeDir($sub); | |
364 else | |
365 { | |
366 echo " - ".$sub."\n"; | |
367 unlink($sub); | |
368 } | |
369 } | |
370 rmdir($path); | |
941 | 371 } |
372 } | |
373 | |
374 | |
935 | 375 function wtMakeDir($path, $perm) |
827 | 376 { |
377 if (!file_exists($path)) | |
378 { | |
379 echo " - Creating ".$path."\n"; | |
380 if (mkdir($path, $perm, TRUE) === false) | |
381 die("Could not create directory '".$path."'\n"); | |
382 } | |
383 } | |
384 | |
385 | |
935 | 386 function wtInitializeDirs() |
827 | 387 { |
902 | 388 global |
389 $setEntryPath, $setPreviewPath, $setThumbDir, | |
827 | 390 $setEntryPathPerms, $setPrevPathPerms; |
391 | |
392 echo "Checking for missing directories ...\n"; | |
935 | 393 wtMakeDir($setEntryPath, $setEntryPathPerms); |
394 wtMakeDir($setPreviewPath, $setPrevPathPerms); | |
827 | 395 |
396 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
397 { | |
935 | 398 wtMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); |
399 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); | |
400 wtMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); | |
827 | 401 } |
402 } | |
403 | |
404 | |
935 | 405 function wtShowHelp() |
827 | 406 { |
935 | 407 global $argv; |
827 | 408 echo |
409 "faptool - Do stuff with FAPWeb database\n". | |
410 "(C) Copyright 2014 ccr/TNSP\n". | |
411 "\n". | |
917 | 412 "Usage: ".$argv[0]." <command> [args]\n". |
413 "Where command is one of following:\n". | |
827 | 414 "\n". |
415 " init\n". | |
416 " Create directories for entries and previews, if needed.\n". | |
417 "\n". | |
928 | 418 /* |
917 | 419 " clean [delete|crap]\n". |
420 " Clean files marked to be deleted and 'stale' files. This includes\n". | |
421 " any old or stale preview files and entry files.\n". | |
422 " Without 'delete' parameter just checks and shows what would deleted.\n". | |
423 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n". | |
424 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n". | |
425 " KNOW WHAT YOU ARE DOING!!!!!\n". | |
901 | 426 "\n". |
928 | 427 */ |
938 | 428 " probe <filename> [filename2 ..]\n". |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
429 " Probe specified file for file information.\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
430 "\n". |
881 | 431 " previews <cmd> [args]\n". |
432 " Where <cmd> is one of:\n". | |
933 | 433 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n". |
928 | 434 " update - Generate preview files that are missing OR out of date.\n". |
435 " (older then preview source file OR entry file where appropriate)\n". | |
436 // " add <entry_id> <filename> - Add file as preview for entry_id.\n". | |
901 | 437 "\n". |
438 " entry <cmd> [args]\n". | |
933 | 439 " status [cid] - List entries for all compos or <cid>.\n". |
440 " unpack - Create subdirs and unpack archives under them.\n". | |
928 | 441 /* |
442 " add <filename> '<name>' '<author>' - Add file as entry file\n". | |
443 " (works same as uploading from admin interface)\n". | |
444 " package <lha|zip|rar|7z>\n". | |
445 " Repackages/packages entries (unpacks first if archive),\n". | |
446 " and adds generated infofile.txt to packages.\n". | |
447 */ | |
827 | 448 "\n"; |
935 | 449 } |
450 | |
451 // | |
452 // Main program starts | |
453 // | |
944
535466595a5a
Move CLI exec check to program start.
Matti Hamalainen <ccr@tnsp.org>
parents:
943
diff
changeset
|
454 stCheckCLIExec(); |
935 | 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": |
945 | 505 // |
506 // Probe specified files | |
507 // | |
508 if ($argc < 2) | |
509 die("No filename specified.\n"); | |
510 | |
511 if (($finfo = finfo_open()) === false) | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
512 { |
945 | 513 stLogError("Internal error. Failed to initialize finfo()."); |
514 return stError("Internal error, failed to probe file."); | |
515 } | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
516 |
945 | 517 for ($i = 2; $i < $argc; $i++) |
518 { | |
519 // Probe one file | |
520 $filename = $argv[$i]; | |
521 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); | |
522 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); | |
523 | |
524 echo | |
525 "\n". | |
526 "File : ".$filename."\n". | |
527 "Probed : ".$sdata."\n". | |
528 "Mime : ".$smime."\n"; | |
529 | |
530 if (($info = stProbeFileInfo($filename)) !== false) | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
531 { |
945 | 532 $tmp = array(); |
533 foreach ($info as $ikey => $ival) | |
534 $tmp[] = $ikey."='".$ival."'"; | |
535 | |
536 echo "Data : ".implode(", ", $tmp)."\n"; | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
537 } |
946 | 538 } |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
539 |
946 | 540 finfo_close($finfo); |
925
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": |
947 | 544 // |
545 // File cleanup / deletion | |
546 // | |
901 | 547 $doDelete = (stCArgLC(2) == "delete"); |
548 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
549 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
550 { | |
551 printf( | |
935 | 552 "==%'=-".($setTermWidth-2)."s\n", |
901 | 553 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
554 ); | |
922 | 555 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 556 |
557 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
558 { | |
559 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
560 { | |
935 | 561 if ($efile["deleted"] != 0) |
901 | 562 { |
563 echo "X"; | |
564 } | |
565 } | |
566 } | |
567 echo "\n"; | |
922 | 568 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 569 } |
570 break; | |
571 | |
572 case "ent": | |
573 // | |
574 // Entry files handling | |
575 // | |
576 $mode = substr(stCArgLC(2), 0, 3); | |
577 switch ($mode) | |
578 { | |
579 case "unp": | |
580 case "sta": | |
933 | 581 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
582 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
901 | 583 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
584 { | |
585 printf( | |
922 | 586 "==%'=-".($setTermWidth-2)."s\n". |
901 | 587 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
588 ); | |
922 | 589 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 590 |
591 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
592 wtHandleEntry($compo, $entry, $mode); | |
593 | |
922 | 594 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 595 } |
596 break; | |
597 | |
598 case "pac": | |
929 | 599 echo "Not implemented. :D\n"; |
901 | 600 break; |
601 | |
602 case "add": | |
929 | 603 echo "Not implemented. :D\n"; |
901 | 604 break; |
605 | |
606 default: | |
607 if ($mode == "") | |
608 die("ERROR! Entry command requires a sub-command argument.\n"); | |
609 else | |
610 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
611 break; | |
612 } | |
613 break; | |
614 | |
884 | 615 case "pre": |
881 | 616 // |
617 // Preview files handling | |
618 // | |
619 $mode = substr(stCArgLC(2), 0, 3); | |
620 switch ($mode) | |
621 { | |
898 | 622 case "upd": |
881 | 623 case "sta": |
933 | 624 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
625 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
898 | 626 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 627 { |
628 printf( | |
922 | 629 "==%'=-".($setTermWidth-2)."s\n". |
898 | 630 "PrevType : %s\n", |
631 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)), | |
632 $previewTypeList[$compo["preview_type"]][0]); | |
941 | 633 |
634 if ($mode == "sta") | |
635 { | |
636 printf(" %-3s | %-3s | %-40s |\n", | |
637 "#ID", "FLG", "Entry name/author"); | |
638 } | |
639 | |
922 | 640 echo str_repeat("-", $setTermWidth)."\n"; |
881 | 641 |
642 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
643 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 644 |
922 | 645 echo str_repeat("=", $setTermWidth)."\n\n"; |
881 | 646 } |
647 break; | |
648 | |
901 | 649 case "add": |
929 | 650 echo "Not implemented. :D\n"; |
901 | 651 break; |
652 | |
881 | 653 default: |
654 if ($mode == "") | |
655 die("ERROR! Previews command requires a sub-command argument.\n"); | |
656 else | |
657 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
658 break; | |
659 } | |
660 break; | |
661 | |
827 | 662 default: |
663 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
664 break; | |
665 } | |
666 | |
941 | 667 /* Dummy |
668 { | |
669 | |
670 } | |
671 */ | |
827 | 672 ?> |