Mercurial > hg > mgallery
annotate mgtool.php @ 55:b1fa4fd593d1
Fix thumbnail/medium image JPEG quality handling to actually work. :S
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 12 Sep 2016 13:49:52 +0300 |
parents | 624c50e1b52d |
children | 7384504d7b52 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/php |
2 <?php | |
3 // | |
4 // Yet Another Image Gallery | |
5 // Commandline tool for creating / updating gallery | |
32 | 6 // (C) Copyright 2015-2016 Tecnic Software productions (TNSP) |
0 | 7 // |
8 require_once "mgallery.inc.php"; | |
9 | |
10 // | |
11 // Array for specifying what will be copied and converted | |
12 // from the image file's EXIF information tag(s). | |
13 // | |
45 | 14 $galExifConversions = |
15 [ | |
16 [ MG_STR, "caption" , "ImageDescription" ], | |
17 [ MG_STR, "copyright" , "Copyright" ], | |
18 [ MG_STR, "model" , "Model" ], | |
19 [ MG_INT, "width" , ["COMPUTED", "Width"] ], | |
20 [ MG_INT, "height" , ["COMPUTED", "Height"] ], | |
21 [ MG_DVA, "fnumber" , "FNumber" ], | |
22 [ MG_DVA, "exposure" , "ExposureTime" ], | |
23 [ MG_INT, "iso" , "ISOSpeedRatings" ], | |
24 [ MG_STR, "lensmodel" , "UndefinedTag:0xA434" ], | |
25 [ MG_DVA, "focallength" , "FocalLength" ], | |
26 [ MG_STR, "datetime" , "DateTimeOriginal" ], | |
27 [ MG_STR, "datetime" , "DateTimeDigitized" ], | |
28 [ MG_INT, "filesize" , "FileSize" ], | |
29 ]; | |
0 | 30 |
31 define("GCMD_UPDATE" , 1); | |
32 define("GCMD_RESCAN" , 2); | |
33 define("GCMD_CLEAN" , 3); | |
34 | |
35 define("GCLEAN_CACHES" , 0x01); | |
36 define("GCLEAN_THUMBNAILS", 0x02); | |
37 define("GCLEAN_ALL" , 0x0f); | |
38 | |
39 define("GUPD_MED_IMAGE" , 0x01); | |
40 define("GUPD_TN_IMAGE" , 0x02); | |
41 define("GUPD_IMAGES" , 0x0f); | |
42 define("GUPD_EXIF_INFO" , 0x10); | |
43 define("GUPD_CAPTION" , 0x20); | |
44 | |
45 | |
46 // | |
47 // Convert and scale image file function, for generating | |
48 // the intermediate size images and thumbnails. Uses the | |
49 // PHP ImageMagick bindings. | |
50 // | |
51 function mgConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb) | |
52 { | |
53 // Create conversion entity | |
53
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
54 try |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
55 { |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
56 $img = new Imagick($inFilename); |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
57 } |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
58 catch (Exception $e) |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
59 { |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
60 return mgError("ImageMagick exception for file '".$inFilename."':\n".$e->getMessage()."\n"); |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
61 } |
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
62 |
0 | 63 if ($img === FALSE) |
64 return mgError("ImageMagick could not digest the file '".$inFilename."'.\n"); | |
65 | |
51
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
66 $profiles = $img->getImageProfiles("icc", true); |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
67 $img->setImageDepth(16); |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
68 $img->transformImageColorspace(Imagick::COLORSPACE_SRGB); |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
69 $img->setImageColorspace(Imagick::COLORSPACE_SRGB); |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
70 |
0 | 71 if ($outDim !== FALSE) |
72 { | |
73 // Get dimensions, setup background | |
74 $dim = $img->getImageGeometry(); | |
75 //$img->setImageBackgroundColor(imagick::COLOR_BLACK); | |
76 $img->setGravity(imagick::GRAVITY_CENTER); | |
77 | |
78 | |
79 if ($dim["width"] < $dim["height"]) | |
80 { | |
81 $stmp = $outDim[0]; | |
82 $outDim[0] = $outDim[1]; | |
83 $outDim[1] = $stmp; | |
84 } | |
85 | |
86 if ($dim["width"] != $outDim[0] || $dim["height"] != $outDim[1]) | |
87 { | |
88 $outDim[1] = ($dim["height"] * $outDim[0]) / $dim["width"]; | |
89 } | |
90 | |
91 // Act based on image size vs. desired size and $thumb mode | |
92 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1]) | |
93 { | |
94 // Image is larger | |
1
a07447c02b13
Use Lanczos filter for scaling instead of quadratic. Better quality and
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
95 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1); |
0 | 96 $img->setImageExtent($outDim[0], $outDim[1]); |
51
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
97 // $img->normalizeImage(); |
0 | 98 $img->unsharpMaskImage(0, 0.5, 1, 0.05); |
99 } | |
100 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1]) | |
101 { | |
102 // Image is smaller than requested dimension(s)? | |
1
a07447c02b13
Use Lanczos filter for scaling instead of quadratic. Better quality and
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
103 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1); |
0 | 104 $img->setImageExtent($outDim[0], $outDim[1]); |
51
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
105 // $img->normalizeImage(); |
0 | 106 $img->unsharpMaskImage(0, 0.5, 1, 0.05); |
107 } | |
108 } | |
109 | |
51
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
110 |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
111 $img->setImageDepth(8); |
0 | 112 $img->setFormat($outFormat); |
55
b1fa4fd593d1
Fix thumbnail/medium image JPEG quality handling to actually work. :S
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
113 $img->setImageCompression(Imagick::COMPRESSION_JPEG); |
b1fa4fd593d1
Fix thumbnail/medium image JPEG quality handling to actually work. :S
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
114 $img->setImageCompressionQuality($outQuality); |
51
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
115 |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
116 $img->stripImage(); |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
117 if (!empty($profiles)) |
549541f3e9c0
Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
118 $img->profileImage("icc", $profiles["icc"]); |
0 | 119 |
120 $img->writeImage($outFilename); | |
121 $img->removeImage(); | |
122 return TRUE; | |
123 } | |
124 | |
125 | |
126 // | |
127 // Converts one value (mainly from EXIF tag information) | |
52 | 128 // by doing explicit type casting and special conversions. |
0 | 129 // |
130 function mgConvertExifData($val, $vtype) | |
131 { | |
132 switch ($vtype) | |
133 { | |
46
e58292065b01
Let arrays through mgConvertExifData() when the type is MG_STR without
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
134 case MG_STR: return is_array($val) ? $val : (string) $val; |
0 | 135 case MG_INT: return intval($val); |
136 case MG_BOOL: return intval($val); | |
137 case MG_DVA: | |
138 if (sscanf($val, "%d/%d", $v1, $v2) == 2) | |
139 { | |
140 if ($v1 < $v2) | |
141 return $val; | |
142 else | |
143 return sprintf("%1.1f", $v1 / $v2); | |
144 } | |
145 else | |
146 return $val; | |
147 | |
148 default: | |
149 return $val; | |
150 } | |
151 } | |
152 | |
153 | |
154 // | |
155 // Conditionally copies one "field" from an associated array/hash to another. | |
156 // If destination is already SET, nothing will be done. If source does | |
157 // not exist (e.g. one or more of the keys do not exist in source array), | |
158 // a default value will be used, if provided. | |
159 // Source may have multi-depth keys, destination has one key. | |
160 // | |
161 function mgCopyEntryData(&$dst, $src, $vtype, $dkey, $skeys, $default = NULL) | |
162 { | |
163 // Is destination already set? | |
164 if (isset($dst[$dkey])) | |
165 return FALSE; | |
166 | |
167 // If input key is not array, change it into one | |
168 if (!is_array($skeys)) | |
169 $skeys = array($skeys); | |
170 | |
171 // Traverse input array by using consequent keys | |
172 $tmp = &$src; | |
173 foreach ($skeys as $skey) | |
174 { | |
175 if (!array_key_exists($skey, $tmp)) | |
176 { | |
177 // Key didn't exist, try for default | |
178 if ($default !== NULL) | |
179 $dst[$dkey] = $default; | |
180 return FALSE; | |
181 } | |
182 else | |
183 $tmp = &$tmp[$skey]; | |
184 } | |
185 | |
186 // Optionally convert the input value | |
187 $dst[$dkey] = mgConvertExifData($tmp, $vtype); | |
188 return TRUE; | |
189 } | |
190 | |
191 | |
192 // | |
193 // Attempt to get gallery album data from various sources. | |
194 // | |
195 function mgGetAlbumData($galBasePath, $galPath) | |
196 { | |
197 // Check path permissions | |
198 $galData = array(); | |
199 if (is_readable($galPath)) | |
200 { | |
201 // First, try to read gallery/album info file | |
202 $filename = mgGetPath($galPath, "info_file"); | |
203 if ($filename !== FALSE && file_exists($filename)) | |
204 { | |
205 mgDebug("Reading INFOFILE: ".$filename."\n"); | |
206 if (($galData = parse_ini_file($filename, FALSE)) === FALSE) | |
207 $galData = array(); | |
208 } | |
209 | |
210 // Read header file, if any, and we don't have "header" field set yet | |
211 $filename = mgGetPath($galPath, "header_file"); | |
212 if ($filename !== FALSE && file_exists($filename) && | |
213 !isset($galData["header"])) | |
214 { | |
215 mgDebug("Reading HEADERFILE: ".$filename."\n"); | |
216 $galData["header"] = file_get_contents($filename); | |
217 } | |
218 | |
219 // Check for alternate key/values for album title/caption | |
220 if (isset($galData["title"]) && !isset($galData["caption"])) | |
221 { | |
222 $galData["caption"] = $galData["title"]; | |
223 unset($galData["title"]); | |
224 } | |
225 } | |
226 else | |
227 $galData["hide"] = TRUE; | |
228 | |
229 // If caption is not set, use last path component for | |
230 // a fallback value in case we don't discover proper title | |
231 // from other sources we can't check here yet. | |
232 $path = explode("/", $galPath); | |
233 $galData["fallback_caption"] = ucfirst(str_replace("_", " ", end($path))); | |
234 | |
235 // Last, store the current gallery path | |
236 $len = strlen($galBasePath); | |
237 if ($len < strlen($galPath) && substr($galPath, 0, $len) == $galBasePath) | |
238 $galData["path"] = substr($galPath, $len); | |
239 else | |
240 $galData["path"] = ""; | |
241 | |
242 return $galData; | |
243 } | |
244 | |
245 | |
246 function mgReadCaptionsFile($galBasePath, $galPath) | |
247 { | |
248 $captions = array(); | |
249 $filename = mgGetPath($galPath, "captions_file"); | |
250 if ($filename === FALSE || ($fp = @fopen($filename, "rb")) === FALSE) | |
251 return $captions; | |
252 | |
253 mgDebug("Reading CAPTIONS: ".$filename."\n"); | |
254 | |
255 // Read and parse data | |
256 while (!feof($fp)) | |
257 { | |
258 $str = trim(fgets($fp)); | |
259 // Ignore comments and empty lines | |
260 if ($str != "#" && $str != "") | |
261 { | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
262 if (preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m)) |
45 | 263 $captions[$m[2]] = ["caption" => $m[3], "hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; |
0 | 264 else |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
265 if (preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m)) |
45 | 266 $captions[$m[2]] = ["hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; |
0 | 267 } |
268 } | |
269 | |
270 fclose($fp); | |
271 return $captions; | |
272 } | |
273 | |
274 | |
275 function mgMakeDir($path, $perm) | |
276 { | |
277 if (!file_exists($path)) | |
278 { | |
279 if (mkdir($path, $perm, TRUE) === false) | |
280 return mgError("Could not create directory '".$path."'\n"); | |
281 } | |
282 return TRUE; | |
283 } | |
284 | |
285 | |
286 function mgYesNoPrompt($msg, $default = FALSE) | |
287 { | |
288 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; | |
289 $sprompt = strtolower(trim(fgets(STDIN))); | |
290 | |
291 if ($default) | |
292 return ($sprompt == "n"); | |
293 else | |
294 return ($sprompt == "y"); | |
295 } | |
296 | |
297 | |
298 function mgDelete($path, $recurse) | |
299 { | |
300 global $flagDoDelete; | |
301 if (is_dir($path)) | |
302 { | |
303 if (($dirHandle = @opendir($path)) === FALSE) | |
304 return mgError("Could not read directory '".$path."'.\n"); | |
305 | |
306 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
307 { | |
308 if ($dirFile != "." && $dirFile != "..") | |
309 mgDelete($path."/".$dirFile, $recurse); | |
310 } | |
311 closedir($dirHandle); | |
312 | |
313 echo " - ".$path." [DIR]\n"; | |
314 if ($flagDoDelete) | |
315 rmdir($path); | |
316 } | |
317 else | |
54
624c50e1b52d
Fix 'mgtool clean' to not attempt deleting files that do not exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
318 if (file_exists($path)) |
0 | 319 { |
320 if (!$recurse) | |
321 echo " - ".$path."\n"; | |
322 if ($flagDoDelete) | |
323 unlink($path); | |
324 } | |
325 } | |
326 | |
327 | |
328 function mgCheckQuit($now = FALSE) | |
329 { | |
330 global $flagQuit; | |
331 | |
332 // Dispatch pending signals | |
333 pcntl_signal_dispatch(); | |
334 | |
335 // Check result | |
336 if ($now && $flagQuit) | |
337 mgFatal("Quitting.\n"); | |
338 | |
339 return $flagQuit; | |
340 } | |
341 | |
342 | |
343 function mgNeedUpdate($entry, $field, $cvalue) | |
344 { | |
345 if (!array_key_exists($field, $entry)) | |
346 return TRUE; | |
347 | |
348 return ($entry[$field] < $cvalue); | |
349 } | |
350 | |
351 | |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
352 function mgSortFunc($a, $b) |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
353 { |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
354 if (isset($a["datetime"]) && isset($b["datetime"])) |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
355 return strcmp($b["datetime"], $a["datetime"]); |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
356 else |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
357 return 0; |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
358 } |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
359 |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
360 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
361 function mgWriteGalleryCache($cacheFilename, &$gallery, &$entries, &$parentEntry) |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
362 { |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
363 // Store gallery cache for this directory |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
364 $images = array(); |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
365 $albums = array(); |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
366 foreach ($entries as $ename => &$edata) |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
367 { |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
368 if ($edata["hide"]) |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
369 continue; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
370 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
371 unset($edata["hide"]); |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
372 if ($edata["type"] == 0) |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
373 $images[$ename] = &$edata; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
374 else |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
375 $albums[$ename] = &$edata; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
376 } |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
377 |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
378 uasort($images, "mgSortFunc"); |
37
99dc0843d7df
Fix sorting of albums to match image sorting.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
379 krsort($albums); |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
380 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
381 // Choose gallery album image |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
382 if (count($images) > 0) |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
383 { |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
384 end($images); |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
385 $parentEntry["image"] = key($images); |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
386 } |
35
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
387 else |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
388 foreach ($albums as $aid => &$adata) |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
389 if (isset($adata["image"])) |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
390 { |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
391 $parentEntry["image"] = &$adata; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
392 break; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
393 } |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
394 |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
395 $str = |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
396 "<?\n". |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
397 "\$galData = ".var_export($gallery, TRUE).";\n". |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
398 "\$galAlbumsIndex = ".var_export(array_keys($albums), TRUE).";\n". |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
399 "\$galImagesIndex = ".var_export(array_keys($images), TRUE).";\n". |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
400 "\$galEntries = ".var_export($entries, TRUE).";\n". |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
401 "?>"; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
402 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
403 if (@file_put_contents($cacheFilename, $str, LOCK_EX) === FALSE) |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
404 return mgError("Error writing '".$cacheFilename."'\n"); |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
405 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
406 return TRUE; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
407 } |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
408 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
409 |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
410 function mgHandleDirectory($mode, $basepath, $path, &$parentData, &$parentEntry, $writeMode, $startAt) |
0 | 411 { |
412 global $galExifConversions, $galTNPath, $galCleanFlags; | |
413 | |
414 // Get cache file path | |
415 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE) | |
416 return mgError("Cache filename / path not set.\n"); | |
417 | |
418 mgCheckQuit(TRUE); | |
419 | |
420 // Read directory contents | |
421 $entries = array(); | |
422 if (($dirHandle = @opendir($path)) === FALSE) | |
423 return mgError("Could not read directory '".$path."'.\n"); | |
424 | |
425 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
426 { | |
427 $realFile = $path."/".$dirFile; | |
428 if (is_dir($realFile)) | |
429 { | |
430 if ($dirFile[0] != "." && $dirFile != $galTNPath) | |
431 $entries[$dirFile] = array("type" => 1, "base" => $dirFile, "ext" => "", "mtime" => filemtime($realFile)); | |
432 } | |
433 else | |
6
405a02586fc2
Fix handling of image files that have spaces in filename (regexp used \S,
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
434 if (preg_match("/^([^\/]+)(".mgGetSetting("format_exts").")$/i", $dirFile, $dirMatch)) |
0 | 435 $entries[$dirFile] = array("type" => 0, "base" => $dirMatch[1], "ext" => $dirMatch[2], "mtime" => filemtime($realFile), "hide" => false); |
436 } | |
437 closedir($dirHandle); | |
438 | |
439 mgCheckQuit(); | |
440 | |
441 // Cleanup mode | |
442 if ($mode == GCMD_CLEAN) | |
443 { | |
444 $gallery = array(); | |
445 | |
446 if ($writeMode) | |
447 { | |
448 if ($galCleanFlags & GCLEAN_CACHES) | |
449 mgDelete($cacheFilename, FALSE); | |
450 | |
451 if ($galCleanFlags & GCLEAN_THUMBNAILS) | |
452 mgDelete($path."/".$galTNPath, TRUE); | |
453 } | |
454 } | |
455 else | |
456 // Update modes | |
457 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN) | |
458 { | |
459 // Load current cache file, if it exists | |
460 $galEntries = array(); | |
461 $cacheTime = -1; | |
462 if ($mode == GCMD_UPDATE && file_exists($cacheFilename)) | |
463 { | |
464 $cacheTime = filemtime($cacheFilename); | |
465 @include $cacheFilename; | |
466 } | |
467 | |
468 // Read caption data | |
469 $captions = mgReadCaptionsFile($basepath, $path); | |
470 $gallery = mgGetAlbumData($basepath, $path); | |
471 if ($parentData !== NULL && $parentEntry !== NULL) | |
472 { | |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
473 $gallery["parent"] = &$parentData; |
0 | 474 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); |
475 } | |
476 | |
477 // Start actual processing | |
478 $nentries = count($entries); | |
479 $nentry = 0; | |
480 echo $path." .. "; | |
481 foreach ($entries as $ename => &$edata) | |
482 { | |
483 printf("\r%s (%1.1f%%) ..", $path, ($nentry * 100.0) / $nentries); | |
484 | |
485 $nentry++; | |
486 $efilename = $path."/".$ename; | |
487 | |
488 if (array_key_exists($ename, $galEntries)) | |
489 $galEntry = &$galEntries[$ename]; | |
490 else | |
491 $galEntry = array(); | |
492 | |
493 mgCheckQuit(FALSE); | |
494 | |
495 // Update with captions file data, if any | |
496 if (array_key_exists($ename, $captions)) | |
497 { | |
498 foreach ($captions[$ename] as $ckey => $cval) | |
499 $edata[$ckey] = $cval; | |
500 } | |
501 | |
502 // Handle entry based on type | |
503 if ($edata["type"] == 0) | |
504 { | |
505 $updFlags = 0; | |
506 $tnPath = $path."/".$galTNPath; | |
507 $medFilename = $tnPath."/".$edata["base"].mgGetSetting("med_suffix").$edata["ext"]; | |
508 $tnFilename = $tnPath."/".$ename; | |
509 $capFilename = $path."/".$edata["base"].".txt"; | |
510 | |
511 // Check what we need to update .. | |
512 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"]) | |
513 $updFlags |= GUPD_MED_IMAGE; | |
514 | |
515 if (!file_exists($tnFilename) || filemtime($tnFilename) < $edata["mtime"]) | |
516 $updFlags |= GUPD_TN_IMAGE; | |
517 | |
518 if (mgNeedUpdate($galEntry, "mtime", $edata["mtime"])) | |
519 $updFlags |= GUPD_EXIF_INFO; | |
520 | |
521 if (file_exists($capFilename) && | |
522 mgNeedUpdate($galEntry, "mtime", filemtime($capFilename))) | |
523 $updFlags |= GUPD_CAPTION; | |
524 | |
525 // Check for EXIF info | |
526 if (($updFlags & GUPD_EXIF_INFO) && | |
527 ($exif = @exif_read_data($efilename)) !== FALSE) | |
528 { | |
529 echo "%"; | |
530 foreach ($galExifConversions as $conv) | |
531 mgCopyEntryData($edata, $exif, $conv[0], $conv[1], $conv[2]); | |
532 } | |
533 else | |
534 { | |
535 // Copy old data that is not yet in new | |
536 echo "*"; | |
537 foreach ($galEntry as $okey => $odata) | |
538 { | |
539 if (!array_key_exists($okey, $edata)) | |
540 $edata[$okey] = $odata; | |
541 } | |
542 } | |
543 | |
544 // Generate thumbnails, etc. | |
545 if ($updFlags & GUPD_IMAGES) | |
546 { | |
547 mgMakeDir($tnPath, 0755); | |
548 | |
549 if ($updFlags & GUPD_MED_IMAGE) | |
550 { | |
551 echo "1"; | |
552 mgConvertImage($efilename, $medFilename, | |
553 array(mgGetSetting("med_width"), mgGetSetting("med_height")), | |
554 "JPEG", mgGetSetting("med_quality"), TRUE); | |
555 } | |
556 | |
557 if ($updFlags & GUPD_TN_IMAGE) | |
558 { | |
559 echo "2"; | |
560 mgConvertImage($efilename, $tnFilename, | |
561 array(mgGetSetting("tn_width"), mgGetSetting("tn_height")), | |
562 "JPEG", mgGetSetting("tn_quality"), TRUE); | |
563 } | |
564 } | |
565 | |
566 // Check for .txt caption file | |
567 if ($updFlags & GUPD_CAPTION) | |
568 { | |
569 echo "?"; | |
570 if (($tmpData = @file_get_contents($capFilename)) !== FALSE) | |
571 $edata["caption"] = $tmpData; | |
572 } | |
573 } | |
574 else | |
575 if ($edata["type"] == 1) | |
576 { | |
10 | 577 // Set some of the album data here |
0 | 578 $tmp = mgGetAlbumData($basepath, $efilename); |
579 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "caption"); | |
580 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "fallback_caption"); | |
581 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title"); | |
582 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE); | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
583 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE); |
0 | 584 } |
585 } | |
586 | |
587 echo "\r".$path." ..... DONE\n"; | |
588 | |
589 mgCheckQuit(TRUE); | |
590 } | |
591 else | |
592 mgFatal("Invalid work mode '".$mode."'.\n"); | |
593 | |
594 mgCheckQuit(TRUE); | |
595 | |
596 // Recurse to subdirectories | |
9
232086da1670
Fix generating of sub-album/dirs names without gallery.info to specify
Matti Hamalainen <ccr@tnsp.org>
parents:
6
diff
changeset
|
597 foreach ($entries as $ename => &$edata) |
0 | 598 if ($edata["type"] == 1) |
599 { | |
600 $epath = $path."/".$ename."/"; | |
601 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode; | |
602 | |
603 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt)) | |
604 return FALSE; | |
605 } | |
606 | |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
607 // Finish update modes |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
608 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN) |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
609 { |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
610 // Store gallery cache for this directory |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
611 if ($writeMode && !mgWriteGalleryCache($cacheFilename, $gallery, $entries, $parentEntry)) |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
612 return FALSE; |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
613 } |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
614 |
0 | 615 mgCheckQuit(TRUE); |
616 | |
617 return TRUE; | |
618 } | |
619 | |
620 | |
621 function mgSigHandler($signo) | |
622 { | |
623 global $flagQuit; | |
624 switch ($signo) | |
625 { | |
626 case SIGTERM: | |
627 mgFatal("Received SIGTERM.\n"); | |
628 break; | |
629 | |
630 case SIGQUIT: | |
631 case SIGINT: | |
632 $flagQuit = TRUE; | |
633 break; | |
634 | |
635 } | |
636 } | |
637 | |
638 | |
639 function mgProcessGalleries($cmd, $path) | |
640 { | |
641 global $galTNPath; | |
642 | |
643 // Fetch the settings we need | |
644 if (mgReadSettings() === FALSE) | |
645 die("MGallery not configured.\n"); | |
646 | |
647 // Check validity of some settings | |
648 $galPath = mgGetSetting("base_path"); | |
649 $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path")); | |
650 if ($galTNPath != mgGetSetting("tn_path")) | |
651 mgError("Invalid tn_path, using '".$galTNPath."'.\n"); | |
652 | |
653 if (strpos($galTNPath, "/") !== FALSE || $galTNPath == "") | |
654 mgFatal("Invalid tn_path '".$galTNPath."'.\n"); | |
655 | |
656 $parentData = $parentEntry = NULL; | |
657 $writeMode = TRUE; | |
658 $startAt = NULL; | |
659 | |
660 // Check for path argument | |
661 if ($path !== FALSE) | |
662 { | |
663 // Check the given path, needs to be "under" the gallery path | |
664 $cmp = mgCleanPath(TRUE, mgRealPath($galPath))."/"; | |
665 $tmp = mgCleanPath(TRUE, mgRealPath($path))."/"; | |
666 if (substr($tmp, 0, strlen($cmp)) != $cmp) | |
667 mgFatal("Path '".$path."' ('".$tmp."') does not reside under '".$galPath."' ('".$cmp."')!\n"); | |
668 | |
669 // Check if we need to bootstrap | |
670 if ($cmp != $tmp) | |
671 { | |
672 $bpath = mgCleanPath(TRUE, mgRealPath($tmp."../")); | |
673 | |
674 if ($cmd != GCMD_CLEAN) | |
675 { | |
676 $cacheFile = mgGetPath($bpath, "cache_file"); | |
677 if (!file_exists($cacheFile)) | |
678 mgFatal("Can't start working from '".$path."', parent '".$cacheFile."' does not exist!\n"); | |
679 | |
680 @include($cacheFile); | |
681 if (!isset($galEntries) || !isset($galData)) | |
682 mgFatal("Cache file '".$cacheFile."' is broken or stale.\n"); | |
683 } | |
684 | |
685 $writeMode = FALSE; | |
686 $startAt = $tmp; | |
687 $path = $bpath; | |
688 | |
689 echo "Starting: '".$startAt."' inside '".$path."'.\n"; | |
690 } | |
691 else | |
692 $path = $tmp; | |
693 } | |
694 else | |
695 $path = $galPath; | |
696 | |
697 // Start working | |
698 echo "Gallery path: '".$galPath."', starting at '".$path."' ...\n"; | |
699 mgHandleDirectory($cmd, $galPath, $path, $parentData, $parentEntry, $writeMode, $startAt); | |
700 } | |
701 | |
702 | |
703 function mgShowCopyright() | |
704 { | |
705 global $mgProgVersion, $mgProgCopyright, | |
706 $mgProgInfo, $mgProgEmail; | |
707 | |
708 echo | |
709 "MGTool ".$mgProgVersion." - MGallery management tool\n". | |
710 $mgProgInfo." ".$mgProgEmail."\n". | |
711 "(C) Copyright ".$mgProgCopyright."\n"; | |
712 } | |
713 | |
714 | |
715 function mgShowHelp() | |
716 { | |
717 global $argv; | |
718 echo | |
719 "Usage: ".basename($argv[0])." <command> [arguments]\n". | |
720 "\n". | |
721 " --help - Show this help.\n". | |
722 " --version - Show version information.\n". | |
723 "\n". | |
724 " update [path]\n". | |
725 " Update directories under <path> or all gallery dirs.\n". | |
726 " Conditionally scans dirs for new or changed images and\n". | |
727 " updates cache files as needed.\n". | |
728 "\n". | |
729 " rescan [path]\n". | |
730 " Like 'update', but forces all cache files to be regenerated\n". | |
731 " and EXIF/caption/etc information to be re-scanned even\n". | |
732 " if the file timestamps do not justify re-scanning.\n". | |
733 "\n". | |
734 " clean <all|caches|thumbnails> [path]\n". | |
735 " Delete all generated files or selectively cache files or\n". | |
736 " everything inside thumbnail directories.\n". | |
737 "\n". | |
738 " config\n". | |
739 " Display configuration values.\n". | |
740 "\n"; | |
741 } | |
742 | |
743 | |
744 // | |
745 // Main code starts | |
746 // | |
747 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) | |
748 { | |
749 header("Status: 404 Not Found"); | |
750 die(); | |
751 } | |
752 | |
753 pcntl_signal(SIGTERM, "mgSigHandler"); | |
754 pcntl_signal(SIGHUP, "mgSigHandler"); | |
755 pcntl_signal(SIGQUIT, "mgSigHandler"); | |
756 pcntl_signal(SIGINT, "mgSigHandler"); | |
757 | |
758 | |
759 $cmd = mgCArgLC(1); | |
760 switch ($cmd) | |
761 { | |
762 case "--version": | |
763 case "version": | |
764 case "ver": | |
765 mgShowCopyright(); | |
766 break; | |
767 | |
768 case FALSE: | |
769 // No arguments | |
770 mgError("Nothing to do. Showing help:\n"); | |
771 | |
772 case "--help": | |
773 case "help": | |
774 if ($cmd !== FALSE) | |
775 mgShowCopyright(); | |
776 mgShowHelp(); | |
777 break; | |
778 | |
779 case "update": case "up": case "upd": case "upda": | |
780 mgProcessGalleries(GCMD_UPDATE, mgCArg(2)); | |
781 break; | |
782 | |
783 case "rescan": case "re": case "res": | |
784 mgProcessGalleries(GCMD_RESCAN, mgCArg(2)); | |
785 break; | |
786 | |
787 case "clean": case "cl": case "cle": | |
788 $cmode = mgCArgLC(2, 2); | |
789 switch ($cmode) | |
790 { | |
791 case "al": $galCleanFlags = GCLEAN_ALL; break; | |
792 case "ca": $galCleanFlags = GCLEAN_CACHES; break; | |
793 case "th": $galCleanFlags = GCLEAN_THUMBNAILS; break; | |
794 case FALSE: | |
795 mgFatal("Cleaning requires a mode argument.\n"); | |
796 | |
797 default: | |
798 mgFatal("Invalid clean mode '".mgCArg(2)."'.\n"); | |
799 } | |
800 $flagDoDelete = FALSE; | |
801 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); | |
802 echo "--\n"; | |
803 if (mgYesNoPrompt("Really delete the above files and directories?")) | |
804 { | |
25
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
805 echo "Deleting ...\n"; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
806 $flagDoDelete = TRUE; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
807 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
808 } |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
809 else |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
810 { |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
811 echo "Okay, canceling operation.\n"; |
0 | 812 } |
813 break; | |
814 | |
815 case "config": | |
816 case "dump": | |
817 if (mgReadSettings() === FALSE) | |
818 die("MGallery not configured.\n"); | |
819 | |
820 foreach ($mgDefaults as $key => $dval) | |
821 { | |
822 $sval = mgGetSetting($key); | |
26 | 823 if ($cmd == "dump") |
824 { | |
825 printf("%-20s = %s\n", $key, mgGetDValStr($dval[0], $sval)); | |
826 } | |
827 else | |
828 { | |
829 printf("%-20s = %s%s\n", | |
830 $key, | |
831 mgGetDValStr($dval[0], $sval), | |
832 ($dval[1] !== NULL && $sval !== $dval[1]) ? " (default: ".mgGetDValStr($dval[0], $dval[1]).")" : ""); | |
833 } | |
0 | 834 } |
835 break; | |
836 | |
837 default: | |
838 mgError("Unknown option/command '".$cmd."'.\n"); | |
839 break; | |
840 } | |
841 | |
842 ?> |