Mercurial > hg > mgallery
annotate mgtool.php @ 262:3c9ce1ad3c45
Fix gmagick/imagick checking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 16 Dec 2018 16:53:48 +0200 |
parents | 32c13f594e39 |
children | 745af791367d |
rev | line source |
---|---|
0 | 1 #!/usr/bin/php |
2 <?php | |
3 // | |
4 // Yet Another Image Gallery | |
69
7777887bc515
Update header/copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
5 // -- Commandline tool for creating / updating gallery |
7777887bc515
Update header/copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
6 // Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
161 | 7 // (C) Copyright 2015-2018 Tecnic Software productions (TNSP) |
0 | 8 // |
9 require_once "mgallery.inc.php"; | |
10 | |
11 // | |
12 // Array for specifying what will be copied and converted | |
13 // from the image file's EXIF information tag(s). | |
14 // | |
45 | 15 $galExifConversions = |
16 [ | |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
17 [ MG_STR, "caption" , "ImageDescription" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
18 [ MG_STR, "copyright" , "Copyright" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
19 [ MG_STR, "model" , "Model" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
20 [ MG_INT, "width" , ["COMPUTED", "Width"] ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
21 [ MG_INT, "height" , ["COMPUTED", "Height"] ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
22 [ MG_DVA, "fnumber" , "FNumber" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
23 [ MG_DVA, "exposure" , "ExposureTime" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
24 [ MG_INT, "iso" , "ISOSpeedRatings" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
25 [ MG_STR, "lensmodel" , "UndefinedTag:0xA434" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
26 [ MG_DVA, "focallength" , "FocalLength" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
27 [ MG_DATE, "datetime" , "DateTimeOriginal" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
28 [ MG_DATE, "datetime" , "DateTimeDigitized" ], |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
29 [ MG_INT, "filesize" , "FileSize" ], |
45 | 30 ]; |
0 | 31 |
32 define("GCMD_UPDATE" , 1); | |
33 define("GCMD_RESCAN" , 2); | |
34 define("GCMD_CLEAN" , 3); | |
35 | |
36 define("GCLEAN_CACHES" , 0x01); | |
251
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
37 define("GCLEAN_IMAGES" , 0x02); |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
38 define("GCLEAN_TRASH" , 0x04); |
0 | 39 define("GCLEAN_ALL" , 0x0f); |
40 | |
41 define("GUPD_MED_IMAGE" , 0x01); | |
42 define("GUPD_TN_IMAGE" , 0x02); | |
43 define("GUPD_IMAGES" , 0x0f); | |
44 define("GUPD_EXIF_INFO" , 0x10); | |
45 define("GUPD_CAPTION" , 0x20); | |
46 | |
47 | |
48 // | |
49 // Convert and scale image file function, for generating | |
50 // the intermediate size images and thumbnails. Uses the | |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
51 // PHP ImageMagick or GraphicsMagick bindings. |
0 | 52 // |
53 function mgConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb) | |
54 { | |
262
3c9ce1ad3c45
Fix gmagick/imagick checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
55 if (extension_loaded("imagick") && extension_loaded("gmagick")) |
53
4c0a08b0ef65
Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents:
52
diff
changeset
|
56 { |
262
3c9ce1ad3c45
Fix gmagick/imagick checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
57 mgError("FATAL ERROR! Both ImageMagick AND GraphicsMagick modules enabled in PHP! This will cause problems! Refusing to work.\n"); |
3c9ce1ad3c45
Fix gmagick/imagick checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
261
diff
changeset
|
58 exit(1); |
53
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 |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
61 if (extension_loaded("imagick")) |
0 | 62 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
63 // Create conversion entity |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
64 try |
0 | 65 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
66 $img = new Imagick($inFilename); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
67 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
68 catch (Exception $e) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
69 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
70 return mgError("ImageMagick exception for file '".$inFilename."':\n".$e->getMessage()."\n"); |
0 | 71 } |
72 | |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
73 if ($img === FALSE) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
74 return mgError("ImageMagick could not digest '".$inFilename."'.\n"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
75 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
76 $profiles = $img->getImageProfiles("icc", true); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
77 $img->setImageDepth(16); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
78 $img->transformImageColorspace(Imagick::COLORSPACE_SRGB); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
79 $img->setImageColorspace(Imagick::COLORSPACE_SRGB); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
80 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
81 if ($outDim !== FALSE) |
0 | 82 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
83 // Get dimensions, setup background |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
84 $dim = $img->getImageGeometry(); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
85 $img->setGravity(imagick::GRAVITY_CENTER); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
86 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
87 if ($dim["width"] < $dim["height"]) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
88 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
89 $stmp = $outDim[0]; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
90 $outDim[0] = $outDim[1]; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
91 $outDim[1] = $stmp; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
92 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
93 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
94 if ($dim["width"] != $outDim[0] || $dim["height"] != $outDim[1]) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
95 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
96 $outDim[1] = ($dim["height"] * $outDim[0]) / $dim["width"]; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
97 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
98 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
99 // Act based on image size vs. desired size and $thumb mode |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
100 if ($thumb || $dim["width"] != $outDim[0] || $dim["height"] != $outDim[1]) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
101 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
102 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
103 $img->setImageExtent($outDim[0], $outDim[1]); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
104 $img->unsharpMaskImage(0, 0.5, 1, 0.05); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
105 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
106 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
107 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
108 $img->setImageDepth(8); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
109 $tfmt = strtolower($outFormat); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
110 switch ($tfmt) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
111 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
112 case "jpeg": |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
113 $img->setFormat("JPEG"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
114 $img->setImageCompression(Imagick::COMPRESSION_JPEG); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
115 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
116 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
117 case "webp": |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
118 $img->setFormat("WEBP"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
119 $img->setOption('webp:method', '6'); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
120 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
121 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
122 default: |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
123 return mgError("Unsupported MGallery med/tn format '".$tfmt."'.\n"); |
0 | 124 } |
125 | |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
126 $img->setImageCompressionQuality($outQuality); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
127 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
128 $img->stripImage(); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
129 if (!empty($profiles)) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
130 $img->profileImage("icc", $profiles["icc"]); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
131 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
132 $img->writeImage($outFilename); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
133 $img->removeImage(); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
134 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
135 else |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
136 if (extension_loaded("gmagick")) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
137 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
138 // Create conversion entity |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
139 try |
0 | 140 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
141 $img = new Gmagick($inFilename); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
142 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
143 catch (Exception $e) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
144 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
145 return mgError("GraphicsMagick exception for file '".$inFilename."':\n".$e->getMessage()."\n"); |
0 | 146 } |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
147 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
148 if ($img === FALSE) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
149 return mgError("GraphicsMagick could not digest '".$inFilename."'.\n"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
150 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
151 // $profiles = $img->getImageProfile("icc"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
152 // $img->setImageDepth(16); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
153 // $img->setImageColorspace(Gmagick::COLORSPACE_SRGB); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
154 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
155 if ($outDim !== FALSE) |
0 | 156 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
157 // Get dimensions, setup background |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
158 $dim = $img->getImageGeometry(); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
159 //$img->setGravity(Gmagick::GRAVITY_CENTER); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
160 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
161 if ($dim["width"] < $dim["height"]) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
162 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
163 $stmp = $outDim[0]; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
164 $outDim[0] = $outDim[1]; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
165 $outDim[1] = $stmp; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
166 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
167 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
168 if ($dim["width"] != $outDim[0] || $dim["height"] != $outDim[1]) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
169 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
170 $outDim[1] = ($dim["height"] * $outDim[0]) / $dim["width"]; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
171 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
172 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
173 // Act based on image size vs. desired size and $thumb mode |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
174 if ($thumb || $dim["width"] != $outDim[0] || $dim["height"] != $outDim[1]) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
175 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
176 $img->resizeImage($outDim[0], $outDim[1], Gmagick::FILTER_LANCZOS, 1); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
177 //$img->setImageExtent($outDim[0], $outDim[1]); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
178 //$img->unsharpMaskImage(0, 0.5, 1, 0.05); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
179 } |
0 | 180 } |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
181 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
182 $img->setImageDepth(8); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
183 $tfmt = strtolower($outFormat); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
184 switch ($tfmt) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
185 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
186 case "jpeg": |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
187 $img->setFormat("JPEG"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
188 $img->setImageCompression(Gmagick::COMPRESSION_JPEG); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
189 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
190 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
191 case "webp": |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
192 $img->setFormat("WEBP"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
193 // $img->setOption('webp:method', '6'); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
194 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
195 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
196 default: |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
197 return mgError("Unsupported MGallery med/tn format '".$tfmt."'.\n"); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
198 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
199 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
200 $img->setCompressionQuality($outQuality); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
201 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
202 $img->stripImage(); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
203 // if (!empty($profiles)) |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
204 // $img->profileImage("icc", $profiles); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
205 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
206 $img->writeImage($outFilename); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
207 $img->removeImage(); |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
208 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
209 else |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
210 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
211 return mgError("No ImageMagick OR GraphicsMagick module in PHP!\n"); |
0 | 212 } |
213 | |
214 return TRUE; | |
215 } | |
216 | |
217 | |
218 // | |
219 // Converts one value (mainly from EXIF tag information) | |
52 | 220 // by doing explicit type casting and special conversions. |
0 | 221 // |
222 function mgConvertExifData($val, $vtype) | |
223 { | |
224 switch ($vtype) | |
225 { | |
46
e58292065b01
Let arrays through mgConvertExifData() when the type is MG_STR without
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
226 case MG_STR: return is_array($val) ? $val : (string) $val; |
0 | 227 case MG_INT: return intval($val); |
228 case MG_BOOL: return intval($val); | |
229 case MG_DVA: | |
223
438277861f51
Implement better interpretation of DVA values (exposure times, for example),
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
230 if (sscanf($val, "%d/%d", $v1, $v2) == 2 && $v2 != 0 && $v1 != 0) |
0 | 231 { |
232 if ($v1 < $v2) | |
249
abcd21b01829
Use floating point formatting for certain DVA values.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
233 return sprintf("1/%1.1f", $v2 / $v1); |
0 | 234 else |
235 return sprintf("%1.1f", $v1 / $v2); | |
236 } | |
237 else | |
238 return $val; | |
239 | |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
240 case MG_DATE: |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
241 return date_timestamp_get(date_create_from_format("Y:m:d H:i:s", $val)); |
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
242 |
0 | 243 default: |
244 return $val; | |
245 } | |
246 } | |
247 | |
248 | |
249 // | |
250 // Conditionally copies one "field" from an associated array/hash to another. | |
251 // If destination is already SET, nothing will be done. If source does | |
252 // not exist (e.g. one or more of the keys do not exist in source array), | |
253 // a default value will be used, if provided. | |
254 // Source may have multi-depth keys, destination has one key. | |
255 // | |
256 function mgCopyEntryData(&$dst, $src, $vtype, $dkey, $skeys, $default = NULL) | |
257 { | |
258 // Is destination already set? | |
259 if (isset($dst[$dkey])) | |
260 return FALSE; | |
261 | |
262 // If input key is not array, change it into one | |
263 if (!is_array($skeys)) | |
264 $skeys = array($skeys); | |
265 | |
266 // Traverse input array by using consequent keys | |
267 $tmp = &$src; | |
268 foreach ($skeys as $skey) | |
269 { | |
270 if (!array_key_exists($skey, $tmp)) | |
271 { | |
272 // Key didn't exist, try for default | |
273 if ($default !== NULL) | |
274 $dst[$dkey] = $default; | |
275 return FALSE; | |
276 } | |
277 else | |
278 $tmp = &$tmp[$skey]; | |
279 } | |
280 | |
281 // Optionally convert the input value | |
282 $dst[$dkey] = mgConvertExifData($tmp, $vtype); | |
283 return TRUE; | |
284 } | |
285 | |
286 | |
287 // | |
288 // Attempt to get gallery album data from various sources. | |
289 // | |
290 function mgGetAlbumData($galBasePath, $galPath) | |
291 { | |
292 // Check path permissions | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
293 $galData = []; |
0 | 294 if (is_readable($galPath)) |
295 { | |
296 // First, try to read gallery/album info file | |
297 $filename = mgGetPath($galPath, "info_file"); | |
298 if ($filename !== FALSE && file_exists($filename)) | |
299 { | |
300 mgDebug("Reading INFOFILE: ".$filename."\n"); | |
301 if (($galData = parse_ini_file($filename, FALSE)) === FALSE) | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
302 $galData = []; |
0 | 303 } |
304 | |
305 // Read header file, if any, and we don't have "header" field set yet | |
306 $filename = mgGetPath($galPath, "header_file"); | |
307 if ($filename !== FALSE && file_exists($filename) && | |
308 !isset($galData["header"])) | |
309 { | |
310 mgDebug("Reading HEADERFILE: ".$filename."\n"); | |
311 $galData["header"] = file_get_contents($filename); | |
312 } | |
313 | |
314 // Check for alternate key/values for album title/caption | |
315 if (isset($galData["title"]) && !isset($galData["caption"])) | |
316 { | |
317 $galData["caption"] = $galData["title"]; | |
318 unset($galData["title"]); | |
319 } | |
320 } | |
321 else | |
322 $galData["hide"] = TRUE; | |
323 | |
324 // If caption is not set, use last path component for | |
325 // a fallback value in case we don't discover proper title | |
326 // from other sources we can't check here yet. | |
327 $path = explode("/", $galPath); | |
328 $galData["fallback_caption"] = ucfirst(str_replace("_", " ", end($path))); | |
329 | |
330 // Last, store the current gallery path | |
331 $len = strlen($galBasePath); | |
332 if ($len < strlen($galPath) && substr($galPath, 0, $len) == $galBasePath) | |
333 $galData["path"] = substr($galPath, $len); | |
334 else | |
335 $galData["path"] = ""; | |
336 | |
337 return $galData; | |
338 } | |
339 | |
340 | |
165 | 341 // |
342 // Parse a simple image captions file, with format of one entry per line. | |
343 // Lines starting with "# " are comments (note the whitespace), empty lines ignored. | |
344 // First continuous non-whitespace text is file/dirname, followed | |
345 // by caption text, which is separate with whitespace from the filename. | |
346 // Filenames starting with # will be made hidden entries. | |
347 // Filenames starging with % will hide contents. | |
348 // | |
0 | 349 function mgReadCaptionsFile($galBasePath, $galPath) |
350 { | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
351 $captions = []; |
0 | 352 $filename = mgGetPath($galPath, "captions_file"); |
353 if ($filename === FALSE || ($fp = @fopen($filename, "rb")) === FALSE) | |
354 return $captions; | |
355 | |
356 mgDebug("Reading CAPTIONS: ".$filename."\n"); | |
357 | |
358 // Read and parse data | |
359 while (!feof($fp)) | |
360 { | |
361 $str = trim(fgets($fp)); | |
362 // Ignore comments and empty lines | |
363 if ($str != "#" && $str != "") | |
364 { | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
365 if (preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m)) |
45 | 366 $captions[$m[2]] = ["caption" => $m[3], "hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; |
0 | 367 else |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
368 if (preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m)) |
45 | 369 $captions[$m[2]] = ["hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; |
0 | 370 } |
371 } | |
372 | |
373 fclose($fp); | |
374 return $captions; | |
375 } | |
376 | |
377 | |
165 | 378 // |
379 // Create directory with specified permissions | |
380 // | |
0 | 381 function mgMakeDir($path, $perm) |
382 { | |
383 if (!file_exists($path)) | |
384 { | |
385 if (mkdir($path, $perm, TRUE) === false) | |
386 return mgError("Could not create directory '".$path."'\n"); | |
387 } | |
388 return TRUE; | |
389 } | |
390 | |
391 | |
165 | 392 // |
393 // Print a simple yes/no prompt with given message | |
394 // and default value. | |
395 // | |
0 | 396 function mgYesNoPrompt($msg, $default = FALSE) |
397 { | |
398 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; | |
399 $sprompt = strtolower(trim(fgets(STDIN))); | |
400 | |
166
d8387b48b08d
Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
401 if ($sprompt == "") |
d8387b48b08d
Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
402 return $default; |
0 | 403 else |
165 | 404 return $sprompt[0] == 'y'; |
0 | 405 } |
406 | |
407 | |
165 | 408 // |
182 | 409 // Delete given directory OR file, recursively |
165 | 410 // |
183 | 411 function mgDelete($path, $showFiles) |
0 | 412 { |
56
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
413 global $flagDoDelete, $countDoDelete; |
0 | 414 if (is_dir($path)) |
415 { | |
416 if (($dirHandle = @opendir($path)) === FALSE) | |
417 return mgError("Could not read directory '".$path."'.\n"); | |
418 | |
419 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
420 { | |
421 if ($dirFile != "." && $dirFile != "..") | |
183 | 422 mgDelete($path."/".$dirFile, $showFiles); |
0 | 423 } |
183 | 424 |
0 | 425 closedir($dirHandle); |
426 | |
427 echo " - ".$path." [DIR]\n"; | |
62
3f60a5f5b4b3
Actually fix checking for files to be deleted to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
428 $countDoDelete++; |
0 | 429 if ($flagDoDelete) |
430 rmdir($path); | |
431 } | |
432 else | |
54
624c50e1b52d
Fix 'mgtool clean' to not attempt deleting files that do not exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
433 if (file_exists($path)) |
0 | 434 { |
183 | 435 if ($showFiles) |
0 | 436 echo " - ".$path."\n"; |
56
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
437 |
62
3f60a5f5b4b3
Actually fix checking for files to be deleted to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
438 $countDoDelete++; |
0 | 439 if ($flagDoDelete) |
440 unlink($path); | |
441 } | |
442 } | |
443 | |
444 | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
445 function mgDeleteConditional($path, &$noDelete) |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
446 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
447 global $flagDoDelete, $countDoDelete; |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
448 if (is_dir($path)) |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
449 { |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
450 if (($dirHandle = @opendir($path)) === FALSE) |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
451 return mgError("Could not read directory '".$path."'.\n"); |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
452 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
453 while (($dirFile = @readdir($dirHandle)) !== FALSE) |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
454 { |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
455 if ($dirFile != "." && $dirFile != "..") |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
456 mgDeleteConditional($path."/".$dirFile, $noDelete); |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
457 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
458 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
459 closedir($dirHandle); |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
460 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
461 if (!array_key_exists($path, $noDelete)) |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
462 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
463 $countDoDelete++; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
464 if ($flagDoDelete) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
465 rmdir($path); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
466 else |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
467 echo "DEL DIR '".$path."'\n"; |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
468 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
469 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
470 else |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
471 if (file_exists($path) && !array_key_exists($path, $noDelete)) |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
472 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
473 $countDoDelete++; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
474 if ($flagDoDelete) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
475 unlink($path); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
476 else |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
477 echo "DEL FILE '".$path."'\n"; |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
478 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
479 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
480 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
481 |
165 | 482 // |
483 // Check if we have received the quit signal | |
484 // and if yes, quit cleanly now. | |
485 // | |
0 | 486 function mgCheckQuit($now = FALSE) |
487 { | |
488 global $flagQuit; | |
489 | |
490 // Dispatch pending signals | |
491 pcntl_signal_dispatch(); | |
492 | |
493 // Check result | |
494 if ($now && $flagQuit) | |
495 mgFatal("Quitting.\n"); | |
496 | |
497 return $flagQuit; | |
498 } | |
499 | |
500 | |
501 function mgNeedUpdate($entry, $field, $cvalue) | |
502 { | |
503 if (!array_key_exists($field, $entry)) | |
504 return TRUE; | |
80 | 505 |
0 | 506 return ($entry[$field] < $cvalue); |
507 } | |
508 | |
509 | |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
510 function mgSortFunc($a, $b) |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
511 { |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
512 if (isset($a["datetime"]) && isset($b["datetime"])) |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
513 return $b["datetime"] - $a["datetime"]; |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
514 else |
108
417cdd9f8864
Use image file base name for sorting if timestamps are not available.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
515 if (isset($a["base"]) && isset($b["base"])) |
417cdd9f8864
Use image file base name for sorting if timestamps are not available.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
516 return strcmp($b["base"], $a["base"]); |
417cdd9f8864
Use image file base name for sorting if timestamps are not available.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
517 else |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
518 return 0; |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
519 } |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
520 |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
521 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
522 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
|
523 { |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
524 // Store gallery cache for this directory |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
525 $images = []; |
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
526 $albums = []; |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
527 $output = []; |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
528 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
529 // If we are hiding contents of an album, generate no data |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
530 if (!$parentEntry["hide_contents"]) |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
531 { |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
532 foreach ($entries as $ename => &$edata) |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
533 { |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
534 if ($edata["hide"]) |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
535 continue; |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
536 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
537 unset($edata["hide"]); |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
538 if ($edata["type"] == 0) |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
539 $images[$ename] = &$edata; |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
540 else |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
541 $albums[$ename] = &$edata; |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
542 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
543 $output[$ename] = &$edata; |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
544 } |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
545 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
546 uasort($images, "mgSortFunc"); |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
547 krsort($albums); |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
548 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
549 // Choose gallery album image |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
550 if (count($images) > 0) |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
551 { |
79
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
552 if (isset($gallery["albumpic"]) && |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
553 isset($images[$gallery["albumpic"]])) |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
554 { |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
555 $parentEntry["image"] = $gallery["albumpic"]; |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
556 } |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
557 else |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
558 { |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
559 end($images); |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
560 $parentEntry["image"] = key($images); |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
561 } |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
562 } |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
563 else |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
564 { |
79
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
565 foreach ($albums as $aid => &$adata) |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
566 if (isset($adata["image"])) |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
567 { |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
568 $parentEntry["image"] = &$adata; |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
569 break; |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
570 } |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
571 } |
35
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
572 } |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
573 |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
574 $str = |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
575 "<?\n". |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
576 "\$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
|
577 "\$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
|
578 "\$galImagesIndex = ".var_export(array_keys($images), TRUE).";\n". |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
579 "\$galEntries = ".var_export($output, TRUE).";\n". |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
580 "?>"; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
581 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
582 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
|
583 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
|
584 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
585 return TRUE; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
586 } |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
587 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
588 |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
589 function mgHandleDirectory($mode, $basepath, $path, &$parentData, &$parentEntry, $writeMode, $startAt) |
0 | 590 { |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
591 global $galExifConversions, $galTNPath, $galMedPath, $galCleanFlags; |
0 | 592 |
593 // Get cache file path | |
594 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE) | |
595 return mgError("Cache filename / path not set.\n"); | |
596 | |
597 mgCheckQuit(TRUE); | |
598 | |
599 // Read directory contents | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
600 $entries = []; |
0 | 601 if (($dirHandle = @opendir($path)) === FALSE) |
602 return mgError("Could not read directory '".$path."'.\n"); | |
603 | |
604 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
605 { | |
606 $realFile = $path."/".$dirFile; | |
607 if (is_dir($realFile)) | |
608 { | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
609 if ($dirFile[0] != "." && $dirFile != $galTNPath && $dirFile != $galMedPath) |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
610 $entries[$dirFile] = ["type" => 1, "base" => $dirFile, "ext" => "", "mtime" => filemtime($realFile)]; |
0 | 611 } |
612 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
|
613 if (preg_match("/^([^\/]+)(".mgGetSetting("format_exts").")$/i", $dirFile, $dirMatch)) |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
614 $entries[$dirFile] = ["type" => 0, "base" => $dirMatch[1], "ext" => $dirMatch[2], "mtime" => filemtime($realFile), "hide" => false]; |
0 | 615 } |
616 closedir($dirHandle); | |
617 | |
618 mgCheckQuit(); | |
619 | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
620 $tnPath = $path."/".$galTNPath; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
621 $medPath = $path."/".$galMedPath; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
622 $generatedFiles = []; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
623 $generatedFiles[$tnPath] = 1; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
624 $generatedFiles[$medPath] = 1; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
625 |
0 | 626 // Cleanup mode |
627 if ($mode == GCMD_CLEAN) | |
628 { | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
629 $gallery = []; |
0 | 630 |
631 if ($writeMode) | |
632 { | |
633 if ($galCleanFlags & GCLEAN_CACHES) | |
183 | 634 mgDelete($cacheFilename, TRUE); |
0 | 635 |
251
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
636 if ($galCleanFlags & GCLEAN_IMAGES) |
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
637 { |
183 | 638 mgDelete($path."/".$galTNPath, FALSE); |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
639 mgDelete($path."/".$galMedPath, FALSE); |
251
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
640 } |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
641 |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
642 if ($galCleanFlags & GCLEAN_TRASH) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
643 { |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
644 foreach ($entries as $ename => &$edata) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
645 { |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
646 $medFilename = $medPath."/".$ename.".".mgGetSetting("med_format"); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
647 $tnFilename = $tnPath."/".$ename.".".mgGetSetting("tn_format"); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
648 $generatedFiles[$medFilename] = 1; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
649 $generatedFiles[$tnFilename] = 1; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
650 } |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
651 |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
652 // Delete any "trash" files from medium/thumbnail dirs |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
653 mgDeleteConditional($tnPath, $generatedFiles); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
654 mgDeleteConditional($medPath, $generatedFiles); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
655 } |
0 | 656 } |
657 } | |
658 else | |
659 // Update modes | |
660 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN) | |
661 { | |
662 // Load current cache file, if it exists | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
663 $galEntries = []; |
0 | 664 $cacheTime = -1; |
665 if ($mode == GCMD_UPDATE && file_exists($cacheFilename)) | |
666 { | |
667 $cacheTime = filemtime($cacheFilename); | |
668 @include $cacheFilename; | |
669 } | |
670 | |
671 // Read caption data | |
672 $captions = mgReadCaptionsFile($basepath, $path); | |
673 $gallery = mgGetAlbumData($basepath, $path); | |
674 if ($parentData !== NULL && $parentEntry !== NULL) | |
675 { | |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
676 $gallery["parent"] = &$parentData; |
0 | 677 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); |
678 } | |
679 | |
680 // Start actual processing | |
681 $nentries = count($entries); | |
682 $nentry = 0; | |
683 echo $path." .. "; | |
684 foreach ($entries as $ename => &$edata) | |
685 { | |
686 printf("\r%s (%1.1f%%) ..", $path, ($nentry * 100.0) / $nentries); | |
687 | |
688 $nentry++; | |
689 $efilename = $path."/".$ename; | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
690 $medFilename = $medPath."/".$ename.".".mgGetSetting("med_format"); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
691 $tnFilename = $tnPath."/".$ename.".".mgGetSetting("tn_format"); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
692 $capFilename = $path."/".$edata["base"].".txt"; |
0 | 693 |
694 if (array_key_exists($ename, $galEntries)) | |
695 $galEntry = &$galEntries[$ename]; | |
696 else | |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
697 $galEntry = []; |
0 | 698 |
57
29bb365e3ee2
Be more responsive when processing images, check for signals after each
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
699 mgCheckQuit(TRUE); |
0 | 700 |
701 // Update with captions file data, if any | |
702 if (array_key_exists($ename, $captions)) | |
703 { | |
704 foreach ($captions[$ename] as $ckey => $cval) | |
705 $edata[$ckey] = $cval; | |
706 } | |
707 | |
708 // Handle entry based on type | |
709 if ($edata["type"] == 0) | |
710 { | |
711 $updFlags = 0; | |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
712 |
0 | 713 // Check what we need to update .. |
714 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"]) | |
715 $updFlags |= GUPD_MED_IMAGE; | |
716 | |
717 if (!file_exists($tnFilename) || filemtime($tnFilename) < $edata["mtime"]) | |
718 $updFlags |= GUPD_TN_IMAGE; | |
719 | |
720 if (mgNeedUpdate($galEntry, "mtime", $edata["mtime"])) | |
721 $updFlags |= GUPD_EXIF_INFO; | |
722 | |
723 if (file_exists($capFilename) && | |
724 mgNeedUpdate($galEntry, "mtime", filemtime($capFilename))) | |
725 $updFlags |= GUPD_CAPTION; | |
726 | |
727 // Check for EXIF info | |
728 if (($updFlags & GUPD_EXIF_INFO) && | |
729 ($exif = @exif_read_data($efilename)) !== FALSE) | |
730 { | |
731 echo "%"; | |
732 foreach ($galExifConversions as $conv) | |
733 mgCopyEntryData($edata, $exif, $conv[0], $conv[1], $conv[2]); | |
734 } | |
735 else | |
736 { | |
737 // Copy old data that is not yet in new | |
738 echo "*"; | |
739 foreach ($galEntry as $okey => $odata) | |
740 { | |
741 if (!array_key_exists($okey, $edata)) | |
742 $edata[$okey] = $odata; | |
743 } | |
744 } | |
745 | |
746 // Generate thumbnails, etc. | |
747 if ($updFlags & GUPD_IMAGES) | |
748 { | |
749 mgMakeDir($tnPath, 0755); | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
750 mgMakeDir($medPath, 0755); |
0 | 751 |
752 if ($updFlags & GUPD_MED_IMAGE) | |
753 { | |
754 echo "1"; | |
755 mgConvertImage($efilename, $medFilename, | |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
756 [mgGetSetting("med_width"), mgGetSetting("med_height")], |
250
3af3b3f50cb0
Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents:
249
diff
changeset
|
757 mgGetSetting("med_format"), mgGetSetting("med_quality"), TRUE); |
0 | 758 } |
759 | |
760 if ($updFlags & GUPD_TN_IMAGE) | |
761 { | |
762 echo "2"; | |
763 mgConvertImage($efilename, $tnFilename, | |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
764 [mgGetSetting("tn_width"), mgGetSetting("tn_height")], |
253
5b41efcec87d
More work on webp/etc support implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
251
diff
changeset
|
765 mgGetSetting("tn_format"), mgGetSetting("tn_quality"), TRUE); |
0 | 766 } |
767 } | |
768 | |
769 // Check for .txt caption file | |
770 if ($updFlags & GUPD_CAPTION) | |
771 { | |
772 echo "?"; | |
773 if (($tmpData = @file_get_contents($capFilename)) !== FALSE) | |
774 $edata["caption"] = $tmpData; | |
775 } | |
776 } | |
777 else | |
778 if ($edata["type"] == 1) | |
779 { | |
10 | 780 // Set some of the album data here |
0 | 781 $tmp = mgGetAlbumData($basepath, $efilename); |
782 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "caption"); | |
783 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "fallback_caption"); | |
784 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title"); | |
785 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE); | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
786 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE); |
0 | 787 } |
788 } | |
789 | |
790 echo "\r".$path." ..... DONE\n"; | |
791 | |
792 mgCheckQuit(TRUE); | |
793 } | |
794 else | |
795 mgFatal("Invalid work mode '".$mode."'.\n"); | |
796 | |
797 mgCheckQuit(TRUE); | |
798 | |
799 // 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
|
800 foreach ($entries as $ename => &$edata) |
0 | 801 if ($edata["type"] == 1) |
802 { | |
803 $epath = $path."/".$ename."/"; | |
804 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode; | |
805 | |
806 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt)) | |
807 return FALSE; | |
808 } | |
809 | |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
810 // Finish update modes |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
811 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
|
812 { |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
813 // Store gallery cache for this directory |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
814 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
|
815 return FALSE; |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
816 } |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
817 |
0 | 818 mgCheckQuit(TRUE); |
819 | |
820 return TRUE; | |
821 } | |
822 | |
823 | |
824 function mgSigHandler($signo) | |
825 { | |
826 global $flagQuit; | |
827 switch ($signo) | |
828 { | |
829 case SIGTERM: | |
830 mgFatal("Received SIGTERM.\n"); | |
831 break; | |
832 | |
833 case SIGQUIT: | |
834 case SIGINT: | |
835 $flagQuit = TRUE; | |
836 break; | |
837 | |
838 } | |
839 } | |
840 | |
841 | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
842 function mgCheckMPath($path, $id) |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
843 { |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
844 if ($path."/" != mgGetSetting($id)) |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
845 mgError("Invalid ".$id." '".mgGetSetting($id)."', using '".$path."'.\n"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
846 |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
847 if (strpos($path, "/") !== FALSE || $path == "") |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
848 mgFatal("Invalid ".$id." '".$path."'.\n"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
849 } |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
850 |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
851 |
0 | 852 function mgProcessGalleries($cmd, $path) |
853 { | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
854 global $galTNPath, $galMedPath; |
0 | 855 |
856 // Check validity of some settings | |
857 $galPath = mgGetSetting("base_path"); | |
858 $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path")); | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
859 $galMedPath = mgCleanPath(TRUE, mgGetSetting("med_path")); |
0 | 860 |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
861 mgCheckMPath($galTNPath, "tn_path"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
862 mgCheckMPath($galMedPath, "med_path"); |
0 | 863 |
864 $parentData = $parentEntry = NULL; | |
865 $writeMode = TRUE; | |
866 $startAt = NULL; | |
867 | |
868 // Check for path argument | |
869 if ($path !== FALSE) | |
870 { | |
871 // Check the given path, needs to be "under" the gallery path | |
872 $cmp = mgCleanPath(TRUE, mgRealPath($galPath))."/"; | |
873 $tmp = mgCleanPath(TRUE, mgRealPath($path))."/"; | |
874 if (substr($tmp, 0, strlen($cmp)) != $cmp) | |
875 mgFatal("Path '".$path."' ('".$tmp."') does not reside under '".$galPath."' ('".$cmp."')!\n"); | |
876 | |
877 // Check if we need to bootstrap | |
878 if ($cmp != $tmp) | |
879 { | |
880 $bpath = mgCleanPath(TRUE, mgRealPath($tmp."../")); | |
881 | |
882 if ($cmd != GCMD_CLEAN) | |
883 { | |
884 $cacheFile = mgGetPath($bpath, "cache_file"); | |
885 if (!file_exists($cacheFile)) | |
886 mgFatal("Can't start working from '".$path."', parent '".$cacheFile."' does not exist!\n"); | |
887 | |
888 @include($cacheFile); | |
889 if (!isset($galEntries) || !isset($galData)) | |
890 mgFatal("Cache file '".$cacheFile."' is broken or stale.\n"); | |
891 } | |
892 | |
893 $writeMode = FALSE; | |
894 $startAt = $tmp; | |
895 $path = $bpath; | |
896 | |
897 echo "Starting: '".$startAt."' inside '".$path."'.\n"; | |
898 } | |
899 else | |
900 $path = $tmp; | |
901 } | |
902 else | |
903 $path = $galPath; | |
904 | |
905 // Start working | |
906 echo "Gallery path: '".$galPath."', starting at '".$path."' ...\n"; | |
907 mgHandleDirectory($cmd, $galPath, $path, $parentData, $parentEntry, $writeMode, $startAt); | |
908 } | |
909 | |
910 | |
911 function mgShowCopyright() | |
912 { | |
913 global $mgProgVersion, $mgProgCopyright, | |
914 $mgProgInfo, $mgProgEmail; | |
915 | |
916 echo | |
184 | 917 "MGTool ".$mgProgVersion." - MGallery management tool\n". |
918 $mgProgInfo." ".$mgProgEmail."\n". | |
919 "(C) Copyright ".$mgProgCopyright."\n"; | |
0 | 920 } |
921 | |
922 | |
923 function mgShowHelp() | |
924 { | |
925 global $argv; | |
926 echo | |
927 "Usage: ".basename($argv[0])." <command> [arguments]\n". | |
928 "\n". | |
929 " --help - Show this help.\n". | |
930 " --version - Show version information.\n". | |
931 "\n". | |
932 " update [path]\n". | |
933 " Update directories under <path> or all gallery dirs.\n". | |
934 " Conditionally scans dirs for new or changed images and\n". | |
935 " updates cache files as needed.\n". | |
936 "\n". | |
937 " rescan [path]\n". | |
938 " Like 'update', but forces all cache files to be regenerated\n". | |
939 " and EXIF/caption/etc information to be re-scanned even\n". | |
940 " if the file timestamps do not justify re-scanning.\n". | |
941 "\n". | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
942 " clean <option> [path]\n". |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
943 " all - Delete all generated files\n". |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
944 " images - Delete generated images (thumbnails/mediums)\n". |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
945 " caches - Delete mgallery data cache files\n". |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
946 " trash - Delete any 'unmanaged' files inside thumbnail/medium dirs\n". |
0 | 947 "\n". |
159
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
948 " config|dump\n". |
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
949 " Display configuration values (with extra information) or\n". |
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
950 " \"dump\" current configuration as is.\n". |
0 | 951 "\n"; |
952 } | |
953 | |
954 | |
955 // | |
956 // Main code starts | |
957 // | |
958 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) | |
959 { | |
960 header("Status: 404 Not Found"); | |
961 die(); | |
962 } | |
963 | |
964 pcntl_signal(SIGTERM, "mgSigHandler"); | |
965 pcntl_signal(SIGHUP, "mgSigHandler"); | |
966 pcntl_signal(SIGQUIT, "mgSigHandler"); | |
967 pcntl_signal(SIGINT, "mgSigHandler"); | |
968 | |
130
f825d644cf7a
Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
969 if (mgReadSettings() === FALSE) |
f825d644cf7a
Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
970 die("MGallery is not configured, failed to find a configuration file.\n"); |
f825d644cf7a
Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
971 |
f825d644cf7a
Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
972 if (($pageTimeZone = mgGetSetting("timezone")) !== NULL) |
f825d644cf7a
Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
973 date_default_timezone_set($pageTimeZone); |
0 | 974 |
975 $cmd = mgCArgLC(1); | |
976 switch ($cmd) | |
977 { | |
978 case "--version": | |
979 case "version": | |
980 case "ver": | |
981 mgShowCopyright(); | |
982 break; | |
983 | |
984 case FALSE: | |
985 // No arguments | |
986 mgError("Nothing to do. Showing help:\n"); | |
987 | |
988 case "--help": | |
989 case "help": | |
990 if ($cmd !== FALSE) | |
991 mgShowCopyright(); | |
992 mgShowHelp(); | |
993 break; | |
994 | |
995 case "update": case "up": case "upd": case "upda": | |
996 mgProcessGalleries(GCMD_UPDATE, mgCArg(2)); | |
997 break; | |
998 | |
999 case "rescan": case "re": case "res": | |
1000 mgProcessGalleries(GCMD_RESCAN, mgCArg(2)); | |
1001 break; | |
1002 | |
1003 case "clean": case "cl": case "cle": | |
1004 $cmode = mgCArgLC(2, 2); | |
1005 switch ($cmode) | |
1006 { | |
1007 case "al": $galCleanFlags = GCLEAN_ALL; break; | |
1008 case "ca": $galCleanFlags = GCLEAN_CACHES; break; | |
251
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
1009 case "im": $galCleanFlags = GCLEAN_IMAGES; break; |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
1010 case "tr": $galCleanFlags = GCLEAN_TRASH; break; |
0 | 1011 case FALSE: |
1012 mgFatal("Cleaning requires a mode argument.\n"); | |
1013 | |
1014 default: | |
1015 mgFatal("Invalid clean mode '".mgCArg(2)."'.\n"); | |
1016 } | |
56
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1017 $countDoDelete = 0; |
0 | 1018 $flagDoDelete = FALSE; |
1019 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); | |
1020 echo "--\n"; | |
56
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1021 if ($countDoDelete == 0) |
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1022 { |
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1023 echo "Nothing to clean!\n"; |
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1024 } |
7384504d7b52
Do not prompt for deletion in cleanup if there are no files/directories to delete.
Matti Hamalainen <ccr@tnsp.org>
parents:
55
diff
changeset
|
1025 else |
0 | 1026 if (mgYesNoPrompt("Really delete the above files and directories?")) |
1027 { | |
25
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1028 echo "Deleting ...\n"; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1029 $flagDoDelete = TRUE; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1030 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1031 } |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1032 else |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1033 { |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1034 echo "Okay, canceling operation.\n"; |
0 | 1035 } |
1036 break; | |
1037 | |
1038 case "config": | |
1039 case "dump": | |
1040 | |
1041 foreach ($mgDefaults as $key => $dval) | |
1042 { | |
1043 $sval = mgGetSetting($key); | |
26 | 1044 if ($cmd == "dump") |
1045 { | |
189 | 1046 printf("%-20s = %s\n", |
1047 $key, | |
1048 mgGetDValStr($dval, $sval)); | |
26 | 1049 } |
1050 else | |
1051 { | |
1052 printf("%-20s = %s%s\n", | |
1053 $key, | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
1054 mgGetDValStr($dval, $sval), |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
1055 ($dval[1] !== NULL && $sval !== $dval[1]) ? " (default: ".mgGetDValStr($dval, $dval[1]).")" : ""); |
26 | 1056 } |
0 | 1057 } |
1058 break; | |
1059 | |
1060 default: | |
1061 mgError("Unknown option/command '".$cmd."'.\n"); | |
1062 break; | |
1063 } | |
1064 | |
1065 ?> |