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