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