Mercurial > hg > fapweb
annotate faptool.php @ 933:f05c896622e1
Moar work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 27 Nov 2014 22:21:32 +0200 |
parents | 0e073f489ff7 |
children | 7fdf03e6a80d |
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); | |
178 stMakeDir($path, 0700); | |
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 { |
882 | 281 /* |
898 | 282 if (previewSourceFile does not exist) |
882 | 283 { |
284 if (entry is module file) | |
285 { | |
286 render sample | |
287 } | |
288 else | |
289 if (entry is image file) | |
290 { | |
291 convert image | |
292 } | |
898 | 293 else |
294 if (entry is archive) | |
295 { | |
296 if compo preview type is image, scan archive for images .. | |
297 } | |
298 } | |
299 | |
300 if (previewFiles older than previewSourceFile) | |
301 { | |
302 if (source == audio) | |
303 convert via avconv | |
304 else | |
305 if (source == image) | |
306 convert via imagick | |
882 | 307 } |
308 | |
309 // Based on compo / entry preview type .. | |
310 | |
311 // Convert preview image file, if any | |
312 // Create thumbnail for it, too | |
313 wtConvertImage($inFilename, $outFilename, | |
314 "previewImageSize", "previewImageType", | |
315 "previewImageQuality", FALSE); | |
316 | |
317 wtConvertImage($inFilename, $outFilename, | |
318 "previewThumbSize", "previewThumbType", | |
319 "previewThumbQuality", TRUE); | |
320 */ | |
898 | 321 } |
933 | 322 return TRUE; |
882 | 323 } |
324 | |
325 | |
884 | 326 function wtHandleEntry($compo, $entry, $mode) |
327 { | |
328 } | |
329 | |
330 | |
827 | 331 // |
332 // Create directories | |
333 // | |
334 function stMakeDir($path, $perm) | |
335 { | |
336 if (!file_exists($path)) | |
337 { | |
338 echo " - Creating ".$path."\n"; | |
339 if (mkdir($path, $perm, TRUE) === false) | |
340 die("Could not create directory '".$path."'\n"); | |
341 } | |
342 } | |
343 | |
344 | |
345 function stInitializeDirs() | |
346 { | |
902 | 347 global |
348 $setEntryPath, $setPreviewPath, $setThumbDir, | |
827 | 349 $setEntryPathPerms, $setPrevPathPerms; |
350 | |
351 echo "Checking for missing directories ...\n"; | |
352 stMakeDir($setEntryPath, $setEntryPathPerms); | |
353 stMakeDir($setPreviewPath, $setPrevPathPerms); | |
354 | |
355 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
356 { | |
357 stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms); | |
927
9a440921bbc2
Preview directory creation stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
926
diff
changeset
|
358 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"])), $setPrevPathPerms); |
9a440921bbc2
Preview directory creation stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
926
diff
changeset
|
359 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $compo["cpath"], $setThumbDir)), $setPrevPathPerms); |
827 | 360 } |
361 } | |
362 | |
363 | |
364 // | |
365 // Main program starts | |
366 // | |
367 if ($argc < 2) | |
368 { | |
369 echo | |
370 "faptool - Do stuff with FAPWeb database\n". | |
371 "(C) Copyright 2014 ccr/TNSP\n". | |
372 "\n". | |
917 | 373 "Usage: ".$argv[0]." <command> [args]\n". |
374 "Where command is one of following:\n". | |
827 | 375 "\n". |
376 " init\n". | |
377 " Create directories for entries and previews, if needed.\n". | |
378 "\n". | |
928 | 379 /* |
917 | 380 " clean [delete|crap]\n". |
381 " Clean files marked to be deleted and 'stale' files. This includes\n". | |
382 " any old or stale preview files and entry files.\n". | |
383 " Without 'delete' parameter just checks and shows what would deleted.\n". | |
384 " 'crap' parameter will purge EVERYTHING that is NOT in the database,\n". | |
385 " e.g. any other files, like temp files, etc. DANGEROUS IF YOU DO NOT\n". | |
386 " KNOW WHAT YOU ARE DOING!!!!!\n". | |
901 | 387 "\n". |
928 | 388 */ |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
389 " probe <filename>\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
390 " Probe specified file for file information.\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
391 "\n". |
881 | 392 " previews <cmd> [args]\n". |
393 " Where <cmd> is one of:\n". | |
933 | 394 " status [cid] - List files and show what is missing, etc. (All or <cid>)\n". |
928 | 395 " update - Generate preview files that are missing OR out of date.\n". |
396 " (older then preview source file OR entry file where appropriate)\n". | |
397 // " add <entry_id> <filename> - Add file as preview for entry_id.\n". | |
901 | 398 "\n". |
399 " entry <cmd> [args]\n". | |
933 | 400 " status [cid] - List entries for all compos or <cid>.\n". |
401 " unpack - Create subdirs and unpack archives under them.\n". | |
928 | 402 /* |
403 " add <filename> '<name>' '<author>' - Add file as entry file\n". | |
404 " (works same as uploading from admin interface)\n". | |
405 " package <lha|zip|rar|7z>\n". | |
406 " Repackages/packages entries (unpacks first if archive),\n". | |
407 " and adds generated infofile.txt to packages.\n". | |
408 */ | |
827 | 409 "\n"; |
410 exit; | |
411 } | |
412 | |
413 // Try to connect to database | |
414 $spec = stGetSetting("sqlDB"); | |
415 if (($db = stConnectSQLDBSpec($spec)) === false) | |
416 die("Could not connect to SQL database '".$spec."'.\n"); | |
417 | |
418 echo "Using database spec '".$spec."'.\n"; | |
419 | |
420 // Fetch non-"hardcoded" settings from SQL database | |
421 stReloadSettings(); | |
422 | |
423 // Set some globals for our benefit | |
922 | 424 $setTermWidth = 75; |
827 | 425 $setEntryPath = stGetSetting("entryPath"); |
426 $setPreviewPath = stGetSetting("previewPath"); | |
427 $setPreviewURL = stGetSetting("previewURL"); | |
428 $setThumbDir = stGetSetting("thumbnailSubDir"); | |
832 | 429 $setEntryPathPerms = stGetSetting("entryPathPerms"); |
430 $setPrevPathPerms = stGetSetting("previewPathPerms"); | |
827 | 431 |
432 if ($setEntryPath === FALSE || $setPreviewPath === FALSE || | |
832 | 433 $setPreviewURL === FALSE || $setThumbDir === FALSE || |
434 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE) | |
827 | 435 { |
922 | 436 die("Some required settings are not defined in mconfig.inc.php!\n"); |
827 | 437 } |
438 | |
439 | |
440 // Act according to specified command | |
884 | 441 switch (substr(stCArgLC(1), 0, 3)) |
827 | 442 { |
884 | 443 case "ini": |
827 | 444 // |
445 // Initialize the data directories etc | |
446 // | |
447 stInitializeDirs(); | |
448 break; | |
449 | |
925
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
450 case "pro": |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
451 { |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
452 $filename = stCArg(2); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
453 if ($filename == "") |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
454 die("No filename specified.\n"); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
455 |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
456 if (($finfo = finfo_open()) === false) |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
457 { |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
458 stLogError("Internal error. Failed to initialize finfo()."); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
459 return stError("Internal error, failed to probe file."); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
460 } |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
461 |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
462 $sdata = @finfo_file($finfo, $filename, FILEINFO_NONE); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
463 $smime = @finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
464 finfo_close($finfo); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
465 |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
466 echo |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
467 "Probed: ".$sdata."\n". |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
468 "Mime : '".$smime."'\n"; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
469 |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
470 if (($finfo = stProbeFileInfo($filename)) !== false) |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
471 print_r($finfo); |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
472 } |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
473 break; |
5d53b9d6c319
Add 'probe' function to faptool.
Matti Hamalainen <ccr@tnsp.org>
parents:
922
diff
changeset
|
474 |
901 | 475 case "cle": |
476 $doDelete = (stCArgLC(2) == "delete"); | |
477 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo) | |
478 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) | |
479 { | |
480 printf( | |
922 | 481 "==%'=-".($setTermWidth-2)."s\n". |
901 | 482 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
483 ); | |
922 | 484 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 485 |
486 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
487 { | |
488 foreach (stExecSQL("SELECT * FROM files WHERE entry_id=".$entry["id"]) as $efile) | |
489 { | |
490 if ($efile["delete"] != 0) | |
491 { | |
492 echo "X"; | |
493 } | |
494 } | |
495 } | |
496 echo "\n"; | |
922 | 497 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 498 } |
499 break; | |
500 | |
501 case "ent": | |
502 // | |
503 // Entry files handling | |
504 // | |
505 $mode = substr(stCArgLC(2), 0, 3); | |
506 switch ($mode) | |
507 { | |
508 case "unp": | |
509 case "sta": | |
933 | 510 $sql = (stCArg(3) != "") ? " AND id=".intval(stCArg(3)) : ""; |
511 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL".$sql) as $compo) | |
901 | 512 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
513 { | |
514 printf( | |
922 | 515 "==%'=-".($setTermWidth-2)."s\n". |
901 | 516 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)) |
517 ); | |
922 | 518 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 519 |
520 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
521 wtHandleEntry($compo, $entry, $mode); | |
522 | |
922 | 523 echo str_repeat("-", $setTermWidth)."\n"; |
901 | 524 } |
525 break; | |
526 | |
527 case "pac": | |
929 | 528 echo "Not implemented. :D\n"; |
901 | 529 break; |
530 | |
531 case "add": | |
929 | 532 echo "Not implemented. :D\n"; |
901 | 533 break; |
534 | |
535 default: | |
536 if ($mode == "") | |
537 die("ERROR! Entry command requires a sub-command argument.\n"); | |
538 else | |
539 die("ERROR! Invalid entry sub-command '".stCArg(2)."'.\n"); | |
540 break; | |
541 } | |
542 break; | |
543 | |
884 | 544 case "pre": |
881 | 545 // |
546 // Preview files handling | |
547 // | |
548 $mode = substr(stCArgLC(2), 0, 3); | |
549 switch ($mode) | |
550 { | |
898 | 551 case "upd": |
881 | 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) | |
898 | 555 if (stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE compo_id=".$compo["id"]) > 0) |
881 | 556 { |
557 printf( | |
922 | 558 "==%'=-".($setTermWidth-2)."s\n". |
898 | 559 "PrevType : %s\n", |
560 sprintf("[ #%03d - %s ]", $compo["id"], substr($compo["name"], 0, 40)), | |
561 $previewTypeList[$compo["preview_type"]][0]); | |
562 | |
563 printf(" %-3s | %-3s | %-40s |\n", | |
564 "#ID", "FLG", "Entry name/author"); | |
565 | |
922 | 566 echo str_repeat("-", $setTermWidth)."\n"; |
881 | 567 |
568 foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$compo["id"]) as $entry) | |
569 wtHandleEntryPreview($compo, $entry, $mode); | |
898 | 570 |
922 | 571 echo str_repeat("=", $setTermWidth)."\n\n"; |
881 | 572 } |
573 break; | |
574 | |
901 | 575 case "add": |
929 | 576 echo "Not implemented. :D\n"; |
901 | 577 break; |
578 | |
881 | 579 default: |
580 if ($mode == "") | |
581 die("ERROR! Previews command requires a sub-command argument.\n"); | |
582 else | |
583 die("ERROR! Invalid previews sub-command '".stCArg(2)."'.\n"); | |
584 break; | |
585 } | |
586 break; | |
587 | |
827 | 588 default: |
589 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; | |
590 break; | |
591 } | |
592 | |
593 ?> |