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