Mercurial > hg > mgallery
annotate mgtool.php @ 348:596196f2b0c5 default tip
Improve relative URL translation in header text blobs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 20 Dec 2023 09:17:55 +0200 |
parents | 9fbec6399cdd |
children |
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> |
345 | 7 // (C) Copyright 2015-2023 Tecnic Software productions (TNSP) |
0 | 8 // |
9 require_once "mgallery.inc.php"; | |
10 | |
11 // | |
282 | 12 // Operating modes and update flags |
13 // | |
14 define("GCMD_UPDATE" , 1); | |
15 define("GCMD_RESCAN" , 2); | |
16 define("GCMD_CLEAN" , 3); | |
17 | |
18 define("GCLEAN_CACHES" , 0x01); | |
19 define("GCLEAN_IMAGES" , 0x02); | |
20 define("GCLEAN_TRASH" , 0x04); | |
21 define("GCLEAN_ALL" , 0x0f); | |
22 | |
23 define("GUPD_MED_IMAGE" , 0x01); | |
24 define("GUPD_TN_IMAGE" , 0x02); | |
25 define("GUPD_IMAGES" , 0x0f); | |
26 define("GUPD_EXIF_INFO" , 0x10); | |
27 define("GUPD_CAPTION" , 0x20); | |
28 | |
29 | |
30 // | |
0 | 31 // Array for specifying what will be copied and converted |
32 // from the image file's EXIF information tag(s). | |
33 // | |
283
1bcaab2d3e6a
Define named constants for $galExifConversions array fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
282
diff
changeset
|
34 define("GEC_TYPE" , 0); |
1bcaab2d3e6a
Define named constants for $galExifConversions array fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
282
diff
changeset
|
35 define("GEC_NAME" , 1); |
1bcaab2d3e6a
Define named constants for $galExifConversions array fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
282
diff
changeset
|
36 define("GEC_FIELDS" , 2); |
286
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
37 define("GEC_IS_UNIQUE" , 3); |
283
1bcaab2d3e6a
Define named constants for $galExifConversions array fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
282
diff
changeset
|
38 |
45 | 39 $galExifConversions = |
40 [ | |
286
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
41 [ MG_STR, "caption" , "ImageDescription" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
42 [ MG_STR, "copyright" , "Copyright" , FALSE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
43 [ MG_STR, "model" , "Model" , FALSE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
44 [ MG_STR, "lensmodel" , "UndefinedTag:0xA434" , FALSE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
45 [ MG_INT, "width" , ["COMPUTED", "Width"] , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
46 [ MG_INT, "height" , ["COMPUTED", "Height"] , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
47 [ MG_DVA, "fnumber" , "FNumber" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
48 [ MG_DVA, "exposure" , "ExposureTime" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
49 [ MG_INT, "iso" , "ISOSpeedRatings" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
50 [ MG_DVA, "focallength" , "FocalLength" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
51 [ MG_DATE, "datetime" , "DateTimeOriginal" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
52 [ MG_DATE, "datetime" , "DateTimeDigitized" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
53 [ MG_INT, "filesize" , "FileSize" , TRUE ], |
878d2a772fd6
Add new $galExifConversions field, a boolean to distinguish unique and non-unique metadata fields.
Matti Hamalainen <ccr@tnsp.org>
parents:
284
diff
changeset
|
54 [ MG_STR, "keywords" , "keywords" , FALSE ], |
341
9210052bb649
Actually extract XMP title field. Oops.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
55 [ MG_STR, "title" , "title" , TRUE ], |
45 | 56 ]; |
0 | 57 |
275 | 58 |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
59 // |
0 | 60 // Convert and scale image file function, for generating |
61 // 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
|
62 // PHP ImageMagick or GraphicsMagick bindings. |
0 | 63 // |
64 function mgConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb) | |
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 if (extension_loaded("imagick")) |
0 | 67 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
68 // 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
|
69 try |
0 | 70 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
71 $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
|
72 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
73 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
|
74 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
75 return mgError("ImageMagick exception for file '".$inFilename."':\n".$e->getMessage()."\n"); |
0 | 76 } |
77 | |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
78 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
|
79 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
|
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 $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
|
82 $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
|
83 $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
|
84 $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
|
85 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
86 if ($outDim !== FALSE) |
0 | 87 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
88 // 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
|
89 $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
|
90 $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
|
91 |
301 | 92 // Width smaller than height? Swap dimensions |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
93 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
|
94 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
95 $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
|
96 $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
|
97 $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
|
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 |
301 | 100 // Compute new height if needed |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
101 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
|
102 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
103 $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
|
104 } |
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 // 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
|
107 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
|
108 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
109 $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
|
110 $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
|
111 $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
|
112 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
113 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
114 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
115 $img->setImageDepth(8); |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
116 switch ($outFormat) |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
117 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
118 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
|
119 $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
|
120 $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
|
121 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
122 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
123 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
|
124 $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
|
125 $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
|
126 break; |
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 default: |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
129 return mgError("Unsupported MGallery med/tn format '".$outFormat."'.\n"); |
0 | 130 } |
131 | |
261
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->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
|
133 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
134 $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
|
135 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
|
136 $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
|
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 $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
|
139 $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
|
140 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
141 else |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
142 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
|
143 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
144 // 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
|
145 try |
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 $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
|
148 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
149 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
|
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 return mgError("GraphicsMagick exception for file '".$inFilename."':\n".$e->getMessage()."\n"); |
0 | 152 } |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
153 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
154 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
|
155 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
|
156 |
284 | 157 //$profiles = $img->getImageProfile("icc"); |
158 //$img->setImageDepth(16); | |
159 //$img->setImageColorspace(Gmagick::COLORSPACE_SRGB); | |
261
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 ($outDim !== FALSE) |
0 | 162 { |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
163 // 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
|
164 $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
|
165 //$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
|
166 |
301 | 167 // Compute new height if needed |
261
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"] < $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
|
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 $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
|
171 $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
|
172 $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
|
173 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
174 |
301 | 175 // Compute new height if needed |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
176 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
|
177 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
178 $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
|
179 } |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
180 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
181 // 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
|
182 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
|
183 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
184 $img->resizeImage($outDim[0], $outDim[1], Gmagick::FILTER_LANCZOS, 1); |
268
07b2b271c12a
Some fixes to GraphicsMagick image conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
185 $img->cropImage($outDim[0], $outDim[1], 0, 0); |
07b2b271c12a
Some fixes to GraphicsMagick image conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
186 $img->unsharpMaskImage(0, 0.5, 1, 0.05); |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
187 } |
0 | 188 } |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
189 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
190 $img->setImageDepth(8); |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
191 switch ($outFormat) |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
192 { |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
193 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
|
194 $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
|
195 $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
|
196 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
197 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
198 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
|
199 $img->setFormat("WEBP"); |
284 | 200 //$img->setOption('webp:method', '6'); |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
201 break; |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
202 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
203 default: |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
204 return mgError("Unsupported MGallery med/tn format '".$outFormat."'.\n"); |
261
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 |
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->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
|
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 $img->stripImage(); |
284 | 210 //if (!empty($profiles)) |
211 // $img->profileImage("icc", $profiles); | |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
212 |
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
213 $img->writeImage($outFilename); |
268
07b2b271c12a
Some fixes to GraphicsMagick image conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
214 $img->destroy(); |
261
32c13f594e39
Add support for PHP GraphicsMagick bindings, though it kind of sucks due to
Matti Hamalainen <ccr@tnsp.org>
parents:
257
diff
changeset
|
215 } |
0 | 216 |
217 return TRUE; | |
218 } | |
219 | |
220 | |
221 // | |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
222 // Read EXIF and XMP data from a file |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
223 // |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
224 // TODO XXX: Perhaps support XMP sidecar files? |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
225 // |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
226 function mgReadEXIFAndXMPData($filename, &$exif, &$xmp) |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
227 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
228 $exif = FALSE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
229 $xmp = FALSE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
230 |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
231 if (($fh = @fopen($filename, 'rb')) === FALSE) |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
232 return "Could not open file for reading."; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
233 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
234 $fileData = fstat($fh); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
235 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
236 // Probe the file for type |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
237 $probeSize = 4 * 3; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
238 if (($probeData = @fread($fh, $probeSize)) === FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
239 return "Error reading file for type probe"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
240 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
241 $probe = unpack("C4magic/L1riffsize/c4riffid", $probeData); |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
242 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
243 // Check for RIFF / WEBP |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
244 if ($probe["magic1"] == 0x52 && $probe["magic2"] == 0x49 && |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
245 $probe["magic3"] == 0x46 && $probe["magic4"] == 0x46 && |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
246 $probe["riffid1"] == 0x57 && $probe["riffid2"] == 0x45 && |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
247 $probe["riffid3"] == 0x42 && $probe["riffid4"] == 0x50) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
248 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
249 if ($probe["riffsize"] > $fileData["size"]) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
250 return "Invalid WebP file, chunk size larger than file size"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
251 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
252 $done = 0; |
319
bf4115b6dc2a
Improve WebP parsing resiliency. feof($fh) does not return true when ftell() == filesize exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
317
diff
changeset
|
253 while (!feof($fh) && ftell($fh) < $fileData["size"] && $done < 2) |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
254 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
255 // Read chunk header |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
256 if (($data = @fread($fh, 2 * 4)) == FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
257 return "File read error in WebP RIFF chunk header"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
258 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
259 $chunk = unpack("c4id/L1size", $data); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
260 |
320 | 261 mgDebug(sprintf("WebP chunk: '%c%c%c%c' (%02x %02x %02x %02x) size=%d\n", |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
262 $chunk["id1"], $chunk["id2"], $chunk["id3"], $chunk["id4"], |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
263 $chunk["id1"], $chunk["id2"], $chunk["id3"], $chunk["id4"], |
320 | 264 $chunk["size"])); |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
265 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
266 // Check for EXIF chunk |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
267 if ($chunk["id1"] == 0x45 && $chunk["id2"] == 0x58 && |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
268 $chunk["id3"] == 0x49 && $chunk["id4"] == 0x46) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
269 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
270 // This is an incredibly stupid hack to work around the |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
271 // fact that PHP's exif_read_data() wants to seek to stream |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
272 // start and probe things .. if we just had a direct parser |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
273 // function we would not need this shit. |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
274 if (($tmpEXIF = @fread($fh, $chunk["size"])) === FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
275 return "Error reading WebP EXIF chunk"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
276 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
277 // Create a temporary file for the EXIF data |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
278 if (($tmpFile = @tmpfile()) === FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
279 return "Could not create temporary WebP EXIF data file"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
280 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
281 if ((@fwrite($tmpFile, $tmpEXIF, $chunk["size"])) === FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
282 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
283 fclose($tmpFile); |
338 | 284 return "Error writing WebP EXIF chunk to temporary file"; |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
285 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
286 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
287 // Parse the EXIF from the temp file |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
288 $exif = @exif_read_data($tmpFile); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
289 fclose($tmpFile); |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
290 |
316
af5ce7bf7eeb
Fix EXIF FileSize field for WebP files.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
291 // We need to fix the FileSize data as size comes from the temp file |
af5ce7bf7eeb
Fix EXIF FileSize field for WebP files.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
292 if (is_array($exif)) |
af5ce7bf7eeb
Fix EXIF FileSize field for WebP files.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
293 { |
af5ce7bf7eeb
Fix EXIF FileSize field for WebP files.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
294 $exif["FileSize"] = $fileData["size"]; |
af5ce7bf7eeb
Fix EXIF FileSize field for WebP files.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
295 } |
af5ce7bf7eeb
Fix EXIF FileSize field for WebP files.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
296 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
297 $done++; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
298 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
299 else |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
300 if ($chunk["id1"] == 0x58 && $chunk["id2"] == 0x4d && |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
301 $chunk["id3"] == 0x50 && $chunk["id4"] == 0x20) |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
302 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
303 // Read and parse XMP data chunk |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
304 if (($xmpStr = fread($fh, $chunk["size"])) === FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
305 return "File read error in XMP data read"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
306 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
307 $xmp = mgParseXMPData($xmpStr); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
308 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
309 $done++; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
310 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
311 else |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
312 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
313 // Skip other chunks |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
314 if (fseek($fh, $chunk["size"], SEEK_CUR) < 0) |
334 | 315 return "File seek error in chunk data skip"; |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
316 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
317 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
318 // If the chunk size is not aligned, skip one byte |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
319 if ($chunk["size"] & 1) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
320 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
321 if (fseek($fh, 1, SEEK_CUR) < 0) |
334 | 322 return "File seek error in chunk alignment skip"; |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
323 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
324 } |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
325 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
326 return TRUE; |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
327 } |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
328 else |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
329 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
330 // Other fileformats, e.g. JPEG, PNG, GIF, .. |
320 | 331 mgDebug("Falling back to generic XMP/EXIF read.\n"); |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
332 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
333 // Read EXIF .. |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
334 if (fseek($fh, 0, SEEK_SET) < 0) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
335 return "File seek error in EXIF fptr restore"; |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
336 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
337 $exif = @exif_read_data($fh); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
338 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
339 if (fseek($fh, 0, SEEK_SET) < 0) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
340 return "File seek error in EXIF fptr restore"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
341 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
342 // Read XMP data block from the file .. it's a horrible hack. |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
343 $xmpStartTag = "<x:xmpmeta"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
344 $xmpEndTag = "</x:xmpmeta>"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
345 $xmpBlockSize = 64 * 1024; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
346 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
347 // Check for start tag |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
348 $buffer = ""; |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
349 $xmpOK = FALSE; |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
350 while (!feof($fh)) |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
351 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
352 if (($tmp = fread($fh, $xmpBlockSize)) === FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
353 return "File read error in JPEG XMP read"; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
354 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
355 $buffer .= $tmp; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
356 if (($spos1 = strpos($buffer, "<")) !== FALSE) |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
357 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
358 $buffer = substr($buffer, $spos1); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
359 if (($spos2 = strpos($buffer, $xmpStartTag)) !== FALSE) |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
360 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
361 $buffer = substr($buffer, $spos2); |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
362 $xmpOK = TRUE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
363 break; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
364 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
365 } |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
366 else |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
367 $buffer = ""; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
368 } |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
369 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
370 // Check for end tag if start tag was found |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
371 if ($xmpOK) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
372 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
373 $xmpOK = FALSE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
374 $buffer2 = $buffer; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
375 do |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
376 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
377 if (($spos1 = strpos($buffer2, "<")) !== FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
378 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
379 $buffer2 = substr($buffer2, $spos1); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
380 if (($spos2 = strpos($buffer2, $xmpEndTag)) !== FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
381 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
382 $xmpOK = TRUE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
383 break; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
384 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
385 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
386 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
387 if (($tmp = @fread($fh, $xmpBlockSize)) !== FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
388 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
389 $buffer2 .= $tmp; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
390 $buffer .= $tmp; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
391 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
392 else |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
393 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
394 $xmpOK = FALSE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
395 break; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
396 } |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
397 } while (!$xmpOK); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
398 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
399 if ($xmpOK) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
400 { |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
401 if (($spos = strpos($buffer, $xmpEndTag)) !== FALSE) |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
402 $buffer = substr($buffer, 0, $spos + strlen($xmpEndTag)); |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
403 else |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
404 $xmpOK = FALSE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
405 } |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
406 } |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
407 |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
408 $xmp = mgParseXMPData($buffer); |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
409 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
410 return TRUE; |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
411 } |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
412 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
413 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
414 |
315
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
415 function mgConvertAttribute(&$dst, &$src, $dstName, $srcName) |
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
416 { |
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
417 if (isset($src[$srcName])) |
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
418 $dst[$dstName] = (string) $src[$srcName]; |
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
419 } |
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
420 |
8a69e693e08c
Add (unused) helper function mgConvertAttribute().
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
421 |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
422 function mgParseXMPData($xmpStr) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
423 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
424 // SimpleXML apparently can't handle namespaces, |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
425 // so we will crudely remove them with some regexes |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
426 $xmpPatterns = |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
427 [ |
312
326935332784
Remove <?xpacket ?> from the XMP, as SimpleXML can't parse it.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
428 "/<\?xpacket\s+.*?\?>/", |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
429 "/[a-zA-Z]+:/", |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
430 "/\/[a-zA-Z]+:/", |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
431 "/<\/?(Bag|Alt|Seq)>/" |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
432 ]; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
433 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
434 $xmpReplacements = |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
435 [ |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
436 "", |
312
326935332784
Remove <?xpacket ?> from the XMP, as SimpleXML can't parse it.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
437 "", |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
438 "\/", |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
439 "", |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
440 ]; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
441 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
442 $xmpStr = preg_replace($xmpPatterns, $xmpReplacements, $xmpStr); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
443 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
444 // Parse XML to a SimpleXMLElement structure |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
445 if (($xmpOb = @simplexml_load_string($xmpStr)) === FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
446 return FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
447 |
301 | 448 // Process structure to simple flat array of data for the desired elements only |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
449 $xmpData = []; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
450 |
313
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
451 /* |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
452 // We get these from EXIF, or at least we should .. also EXIF contains information |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
453 // that XMP does not have, for some reason (like width/height, ISO, etc.) |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
454 // Leaving this code here just as an example. |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
455 if (($xres = $xmpOb->xpath("RDF/Description")) !== FALSE) |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
456 { |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
457 $tmp = $xres[0]->attributes(); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
458 mgConvertAttribute($xmpData, $tmp, "lensmodel", "Lens"); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
459 mgConvertAttribute($xmpData, $tmp, "datetime", "CreateDate"); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
460 } |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
461 |
313
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
462 if (($xres = $xmpOb->xpath("RDF/Description/description/li")) !== FALSE) |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
463 $xmpData["description"] = implode(" ", array_map(function($xe) { return (string) $xe; }, $xres)); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
464 */ |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
465 |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
466 // What EXIF does NOT have are the keywords .. so grab them. |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
467 if (($xres = $xmpOb->xpath("RDF/Description/subject/li")) !== FALSE) |
339
04868ed6aab2
Extract image title from XMP tags.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
468 $xmpData["keywords"] = array_map(function($xkw) { return (string) $xkw; }, $xres); |
04868ed6aab2
Extract image title from XMP tags.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
469 |
04868ed6aab2
Extract image title from XMP tags.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
470 // Get image title |
04868ed6aab2
Extract image title from XMP tags.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
471 if (($xres = $xmpOb->xpath("RDF/Description/title/li")) !== FALSE) |
04868ed6aab2
Extract image title from XMP tags.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
472 $xmpData["title"] = implode(" ", array_map(function($xe) { return (string) $xe; }, $xres)); |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
473 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
474 return $xmpData; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
475 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
476 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
477 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
478 // |
0 | 479 // Converts one value (mainly from EXIF tag information) |
52 | 480 // by doing explicit type casting and special conversions. |
0 | 481 // |
482 function mgConvertExifData($val, $vtype) | |
483 { | |
484 switch ($vtype) | |
485 { | |
46
e58292065b01
Let arrays through mgConvertExifData() when the type is MG_STR without
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
486 case MG_STR: return is_array($val) ? $val : (string) $val; |
0 | 487 case MG_INT: return intval($val); |
488 case MG_BOOL: return intval($val); | |
489 case MG_DVA: | |
223
438277861f51
Implement better interpretation of DVA values (exposure times, for example),
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
490 if (sscanf($val, "%d/%d", $v1, $v2) == 2 && $v2 != 0 && $v1 != 0) |
0 | 491 { |
492 if ($v1 < $v2) | |
249
abcd21b01829
Use floating point formatting for certain DVA values.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
493 return sprintf("1/%1.1f", $v2 / $v1); |
0 | 494 else |
495 return sprintf("%1.1f", $v1 / $v2); | |
496 } | |
497 else | |
498 return $val; | |
499 | |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
500 case MG_DATE: |
276
be152168d945
Use DateTime objects instead of UNIX timestamp integers for MG_DATE values.
Matti Hamalainen <ccr@tnsp.org>
parents:
275
diff
changeset
|
501 return date_create_from_format("Y:m:d H:i:s", $val); |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
502 |
0 | 503 default: |
504 return $val; | |
505 } | |
506 } | |
507 | |
508 | |
509 // | |
510 // Conditionally copies one "field" from an associated array/hash to another. | |
511 // If destination is already SET, nothing will be done. If source does | |
512 // not exist (e.g. one or more of the keys do not exist in source array), | |
513 // a default value will be used, if provided. | |
514 // Source may have multi-depth keys, destination has one key. | |
515 // | |
516 function mgCopyEntryData(&$dst, $src, $vtype, $dkey, $skeys, $default = NULL) | |
517 { | |
518 // Is destination already set? | |
519 if (isset($dst[$dkey])) | |
520 return FALSE; | |
521 | |
522 // If input key is not array, change it into one | |
523 if (!is_array($skeys)) | |
524 $skeys = array($skeys); | |
525 | |
526 // Traverse input array by using consequent keys | |
527 $tmp = &$src; | |
528 foreach ($skeys as $skey) | |
529 { | |
530 if (!array_key_exists($skey, $tmp)) | |
531 { | |
532 // Key didn't exist, try for default | |
533 if ($default !== NULL) | |
534 $dst[$dkey] = $default; | |
342 | 535 |
0 | 536 return FALSE; |
537 } | |
538 else | |
539 $tmp = &$tmp[$skey]; | |
540 } | |
541 | |
542 // Optionally convert the input value | |
543 $dst[$dkey] = mgConvertExifData($tmp, $vtype); | |
342 | 544 |
0 | 545 return TRUE; |
546 } | |
547 | |
548 | |
549 // | |
550 // Attempt to get gallery album data from various sources. | |
551 // | |
552 function mgGetAlbumData($galBasePath, $galPath) | |
553 { | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
554 global $mgAlbumDefaults; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
555 |
0 | 556 // Check path permissions |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
557 $galData = []; |
0 | 558 if (is_readable($galPath)) |
559 { | |
560 // First, try to read gallery/album info file | |
561 $filename = mgGetPath($galPath, "info_file"); | |
562 if ($filename !== FALSE && file_exists($filename)) | |
563 { | |
564 mgDebug("Reading INFOFILE: ".$filename."\n"); | |
565 if (($galData = parse_ini_file($filename, FALSE)) === FALSE) | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
566 { |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
567 $galData = []; |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
568 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
569 else |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
570 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
571 // Sanity check settings |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
572 foreach ($galData as $key => $data) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
573 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
574 if (array_key_exists($key, $mgAlbumDefaults)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
575 mgParseConfigSetting($galData, $mgAlbumDefaults, $key, $galData[$key]); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
576 else |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
577 mgFatal("Invalid setting '".$key."' in '".$filename."'\n"); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
578 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
579 } |
0 | 580 } |
581 | |
582 // Read header file, if any, and we don't have "header" field set yet | |
583 $filename = mgGetPath($galPath, "header_file"); | |
584 if ($filename !== FALSE && file_exists($filename) && | |
585 !isset($galData["header"])) | |
586 { | |
587 mgDebug("Reading HEADERFILE: ".$filename."\n"); | |
588 $galData["header"] = file_get_contents($filename); | |
589 } | |
590 | |
591 // Check for alternate key/values for album title/caption | |
592 if (isset($galData["title"]) && !isset($galData["caption"])) | |
593 { | |
594 $galData["caption"] = $galData["title"]; | |
595 unset($galData["title"]); | |
596 } | |
597 } | |
598 else | |
599 $galData["hide"] = TRUE; | |
600 | |
601 // If caption is not set, use last path component for | |
602 // a fallback value in case we don't discover proper title | |
603 // from other sources we can't check here yet. | |
604 $path = explode("/", $galPath); | |
605 $galData["fallback_caption"] = ucfirst(str_replace("_", " ", end($path))); | |
606 | |
607 // Last, store the current gallery path | |
608 $len = strlen($galBasePath); | |
609 if ($len < strlen($galPath) && substr($galPath, 0, $len) == $galBasePath) | |
610 $galData["path"] = substr($galPath, $len); | |
611 else | |
612 $galData["path"] = ""; | |
613 | |
614 return $galData; | |
615 } | |
616 | |
617 | |
165 | 618 // |
619 // Parse a simple image captions file, with format of one entry per line. | |
620 // Lines starting with "# " are comments (note the whitespace), empty lines ignored. | |
621 // First continuous non-whitespace text is file/dirname, followed | |
622 // by caption text, which is separate with whitespace from the filename. | |
623 // Filenames starting with # will be made hidden entries. | |
624 // Filenames starging with % will hide contents. | |
625 // | |
0 | 626 function mgReadCaptionsFile($galBasePath, $galPath) |
627 { | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
628 $captions = []; |
0 | 629 $filename = mgGetPath($galPath, "captions_file"); |
630 if ($filename === FALSE || ($fp = @fopen($filename, "rb")) === FALSE) | |
631 return $captions; | |
632 | |
633 mgDebug("Reading CAPTIONS: ".$filename."\n"); | |
634 | |
635 // Read and parse data | |
636 while (!feof($fp)) | |
637 { | |
638 $str = trim(fgets($fp)); | |
639 // Ignore comments and empty lines | |
640 if ($str != "#" && $str != "") | |
641 { | |
330
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
642 if (($hasData = preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m))) |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
643 $captions[$m[2]] = ["caption" => $m[3]]; |
0 | 644 else |
330
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
645 $hasData = preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m); |
334 | 646 |
330
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
647 if ($hasData) |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
648 { |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
649 $captions[$m[2]] = [ |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
650 "hide" => ($m[1] == "#"), |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
651 "hide_contents" => ($m[1] == "%"), |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
652 ]; |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
653 } |
0 | 654 } |
655 } | |
656 | |
657 fclose($fp); | |
658 return $captions; | |
659 } | |
660 | |
661 | |
165 | 662 // |
663 // Create directory with specified permissions | |
664 // | |
0 | 665 function mgMakeDir($path, $perm) |
666 { | |
667 if (!file_exists($path)) | |
668 { | |
669 if (mkdir($path, $perm, TRUE) === false) | |
670 return mgError("Could not create directory '".$path."'\n"); | |
671 } | |
672 return TRUE; | |
673 } | |
674 | |
675 | |
165 | 676 // |
677 // Print a simple yes/no prompt with given message | |
678 // and default value. | |
679 // | |
0 | 680 function mgYesNoPrompt($msg, $default = FALSE) |
681 { | |
682 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; | |
683 $sprompt = strtolower(trim(fgets(STDIN))); | |
684 | |
166
d8387b48b08d
Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
685 if ($sprompt == "") |
d8387b48b08d
Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
686 return $default; |
0 | 687 else |
165 | 688 return $sprompt[0] == 'y'; |
0 | 689 } |
690 | |
691 | |
165 | 692 // |
182 | 693 // Delete given directory OR file, recursively |
165 | 694 // |
183 | 695 function mgDelete($path, $showFiles) |
0 | 696 { |
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
|
697 global $flagDoDelete, $countDoDelete; |
0 | 698 if (is_dir($path)) |
699 { | |
700 if (($dirHandle = @opendir($path)) === FALSE) | |
701 return mgError("Could not read directory '".$path."'.\n"); | |
702 | |
703 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
704 { | |
705 if ($dirFile != "." && $dirFile != "..") | |
183 | 706 mgDelete($path."/".$dirFile, $showFiles); |
0 | 707 } |
183 | 708 |
0 | 709 closedir($dirHandle); |
710 | |
711 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
|
712 $countDoDelete++; |
0 | 713 if ($flagDoDelete) |
714 rmdir($path); | |
715 } | |
716 else | |
54
624c50e1b52d
Fix 'mgtool clean' to not attempt deleting files that do not exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
717 if (file_exists($path)) |
0 | 718 { |
183 | 719 if ($showFiles) |
0 | 720 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
|
721 |
62
3f60a5f5b4b3
Actually fix checking for files to be deleted to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
722 $countDoDelete++; |
0 | 723 if ($flagDoDelete) |
724 unlink($path); | |
725 } | |
726 } | |
727 | |
728 | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
729 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
|
730 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
731 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
|
732 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
|
733 { |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
734 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
|
735 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
|
736 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
737 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
|
738 { |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
739 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
|
740 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
|
741 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
742 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
743 closedir($dirHandle); |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
744 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
745 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
|
746 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
747 $countDoDelete++; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
748 if ($flagDoDelete) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
749 rmdir($path); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
750 else |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
751 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
|
752 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
753 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
754 else |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
755 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
|
756 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
757 $countDoDelete++; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
758 if ($flagDoDelete) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
759 unlink($path); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
760 else |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
761 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
|
762 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
763 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
764 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
765 |
165 | 766 // |
767 // Check if we have received the quit signal | |
768 // and if yes, quit cleanly now. | |
769 // | |
0 | 770 function mgCheckQuit($now = FALSE) |
771 { | |
772 global $flagQuit; | |
773 | |
774 // Dispatch pending signals | |
775 pcntl_signal_dispatch(); | |
776 | |
777 // Check result | |
778 if ($now && $flagQuit) | |
779 mgFatal("Quitting.\n"); | |
780 | |
781 return $flagQuit; | |
782 } | |
783 | |
784 | |
785 function mgNeedUpdate($entry, $field, $cvalue) | |
786 { | |
787 if (!array_key_exists($field, $entry)) | |
788 return TRUE; | |
80 | 789 |
0 | 790 return ($entry[$field] < $cvalue); |
791 } | |
792 | |
793 | |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
794 function mgSortFunc($a, $b) |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
795 { |
299
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
796 if (isset($a["datetime"]) && is_object($a["datetime"]) && |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
797 isset($b["datetime"]) && is_object($b["datetime"])) |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
798 $cres = $b["datetime"]->getTimestamp() - $a["datetime"]->getTimestamp(); |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
799 else |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
800 if (isset($a["datetime"]) && is_object($a["datetime"]) && |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
801 isset($b["base"])) |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
802 $cres = -1; |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
803 else |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
804 if (isset($b["datetime"]) && is_object($b["datetime"]) && |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
805 isset($a["base"])) |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
806 $cres = 1; |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
807 else |
325
9a4297e59a40
Adjust sorting so that if timestamp difference is 0, compare names.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
808 $cres = 0; |
9a4297e59a40
Adjust sorting so that if timestamp difference is 0, compare names.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
809 |
9a4297e59a40
Adjust sorting so that if timestamp difference is 0, compare names.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
810 if ($cres == 0 && isset($a["base"]) && isset($b["base"])) |
299
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
811 $cres = strcmp($b["base"], $a["base"]); |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
812 |
338bc2941976
For images that have no EXIF timestamp information, always sort them "lower" compared to ones that have.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
813 return $cres; |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
814 } |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
815 |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
816 |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
817 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
|
818 { |
343
d6422e856ecd
Remove the backend/SQL stuff for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
819 global $galBackend, $db, $galExifConversions; |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
820 |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
821 // 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
|
822 $images = []; |
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
823 $albums = []; |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
824 $output = []; |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
825 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
826 // If we are hiding contents of an album, generate no data |
337 | 827 if ($parentEntry === NULL || !$parentEntry["hide_contents"]) |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
828 { |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
829 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
|
830 { |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
831 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
|
832 continue; |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
833 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
834 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
|
835 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
|
836 $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
|
837 else |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
838 $albums[$ename] = &$edata; |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
839 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
840 $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
|
841 } |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
842 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
843 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
|
844 krsort($albums); |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
845 |
317
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
846 // Choose gallery album cover image |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
847 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
|
848 { |
317
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
849 // Is the cover image set in the album data? |
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
850 if (isset($gallery["albumpic"])) |
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
|
851 { |
317
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
852 if (!isset($images[$gallery["albumpic"]])) |
330
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
853 return mgError("Album cover picture '".$gallery["albumpic"]."' set, but is not found in directory.\n"); |
317
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
854 else |
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
855 $parentEntry["image"] = $gallery["albumpic"]; |
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
|
856 } |
317
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
857 |
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
858 // Got anything? |
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
859 if (!isset($parentEntry["image"])) |
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
|
860 { |
317
d66caa602023
Add better checks for custom/user selected album cover image.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
861 // No, use the last image in the album |
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
|
862 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
|
863 $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
|
864 } |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
865 } |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
866 else |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
867 { |
330
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
868 // Is the cover image set in the album data? |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
869 if (isset($gallery["albumpic"])) |
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
|
870 { |
330
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
871 if (!isset($albums[$gallery["albumpic"]])) |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
872 { |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
873 return mgError("Album cover picture '".$gallery["albumpic"]."' set, but subalbum not found.\n"); |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
874 } |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
875 |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
876 $parentEntry["image"] = &$albums[$gallery["albumpic"]]; |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
877 } |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
878 else |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
879 { |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
880 foreach ($albums as $aid => &$adata) |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
881 if (isset($adata["image"])) |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
882 { |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
883 $parentEntry["image"] = &$adata; |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
884 break; |
c1de5571b59c
Improve album cover picture handling, perhaps.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
885 } |
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
|
886 } |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
887 } |
35
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
888 } |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
889 |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
890 $str = |
271 | 891 "<?php\n". |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
892 "\$galData = ".var_export($gallery, TRUE).";\n". |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
893 "\$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
|
894 "\$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
|
895 "\$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
|
896 "?>"; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
897 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
898 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
|
899 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
|
900 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
901 return TRUE; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
902 } |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
903 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
904 |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
905 function mgHandleDirectory($mode, $basepath, $path, &$parentData, &$parentEntry, $writeMode, $startAt) |
0 | 906 { |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
907 global $galExifConversions, $galTNPath, $galMedPath, $galCleanFlags; |
0 | 908 |
909 // Get cache file path | |
910 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE) | |
911 return mgError("Cache filename / path not set.\n"); | |
912 | |
913 mgCheckQuit(TRUE); | |
914 | |
915 // Read directory contents | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
916 $entries = []; |
0 | 917 if (($dirHandle = @opendir($path)) === FALSE) |
918 return mgError("Could not read directory '".$path."'.\n"); | |
919 | |
920 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
921 { | |
922 $realFile = $path."/".$dirFile; | |
923 if (is_dir($realFile)) | |
924 { | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
925 if ($dirFile[0] != "." && $dirFile != $galTNPath && $dirFile != $galMedPath) |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
926 $entries[$dirFile] = ["type" => 1, "base" => $dirFile, "ext" => "", "mtime" => filemtime($realFile)]; |
0 | 927 } |
928 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
|
929 if (preg_match("/^([^\/]+)(".mgGetSetting("format_exts").")$/i", $dirFile, $dirMatch)) |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
930 $entries[$dirFile] = ["type" => 0, "base" => $dirMatch[1], "ext" => $dirMatch[2], "mtime" => filemtime($realFile), "hide" => false]; |
0 | 931 } |
932 closedir($dirHandle); | |
933 | |
934 mgCheckQuit(); | |
935 | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
936 $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
|
937 $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
|
938 $generatedFiles = []; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
939 $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
|
940 $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
|
941 |
0 | 942 // Cleanup mode |
943 if ($mode == GCMD_CLEAN) | |
944 { | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
945 $gallery = mgGetAlbumData($basepath, $path); |
0 | 946 |
947 if ($writeMode) | |
948 { | |
949 if ($galCleanFlags & GCLEAN_CACHES) | |
183 | 950 mgDelete($cacheFilename, TRUE); |
0 | 951 |
251
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
952 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
|
953 { |
183 | 954 mgDelete($path."/".$galTNPath, FALSE); |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
955 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
|
956 } |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
957 |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
958 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
|
959 { |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
960 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
|
961 { |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
962 $medFilename = $medPath."/".$ename.".".mgGetAlbumSetting($gallery, "med_format"); |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
963 $tnFilename = $tnPath."/".$ename.".".mgGetAlbumSetting($gallery, "tn_format"); |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
964 $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
|
965 $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
|
966 } |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
967 |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
968 // 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
|
969 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
|
970 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
|
971 } |
0 | 972 } |
973 } | |
974 else | |
975 // Update modes | |
976 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN) | |
977 { | |
978 // 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
|
979 $galEntries = []; |
0 | 980 $cacheTime = -1; |
981 if ($mode == GCMD_UPDATE && file_exists($cacheFilename)) | |
982 { | |
983 $cacheTime = filemtime($cacheFilename); | |
984 @include $cacheFilename; | |
985 } | |
986 | |
987 // Read caption data | |
988 $captions = mgReadCaptionsFile($basepath, $path); | |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
989 $gallery = mgGetAlbumData($basepath, $path); |
0 | 990 if ($parentData !== NULL && $parentEntry !== NULL) |
991 { | |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
992 $gallery["parent"] = &$parentData; |
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
993 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); |
0 | 994 } |
995 | |
996 // Start actual processing | |
997 $nentries = count($entries); | |
998 $nentry = 0; | |
999 echo $path." .. "; | |
1000 foreach ($entries as $ename => &$edata) | |
1001 { | |
1002 printf("\r%s (%1.1f%%) ..", $path, ($nentry * 100.0) / $nentries); | |
1003 | |
1004 $nentry++; | |
1005 $efilename = $path."/".$ename; | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1006 $medFilename = $medPath."/".$ename.".".mgGetAlbumSetting($gallery, "med_format"); |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1007 $tnFilename = $tnPath."/".$ename.".".mgGetAlbumSetting($gallery, "tn_format"); |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
1008 $capFilename = $path."/".$edata["base"].".txt"; |
0 | 1009 |
1010 if (array_key_exists($ename, $galEntries)) | |
1011 $galEntry = &$galEntries[$ename]; | |
1012 else | |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
1013 $galEntry = []; |
0 | 1014 |
57
29bb365e3ee2
Be more responsive when processing images, check for signals after each
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
1015 mgCheckQuit(TRUE); |
0 | 1016 |
1017 // Update with captions file data, if any | |
1018 if (array_key_exists($ename, $captions)) | |
1019 { | |
1020 foreach ($captions[$ename] as $ckey => $cval) | |
1021 $edata[$ckey] = $cval; | |
1022 } | |
1023 | |
1024 // Handle entry based on type | |
1025 if ($edata["type"] == 0) | |
1026 { | |
1027 $updFlags = 0; | |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
1028 |
0 | 1029 // Check what we need to update .. |
1030 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"]) | |
1031 $updFlags |= GUPD_MED_IMAGE; | |
1032 | |
1033 if (!file_exists($tnFilename) || filemtime($tnFilename) < $edata["mtime"]) | |
1034 $updFlags |= GUPD_TN_IMAGE; | |
1035 | |
1036 if (mgNeedUpdate($galEntry, "mtime", $edata["mtime"])) | |
1037 $updFlags |= GUPD_EXIF_INFO; | |
1038 | |
1039 if (file_exists($capFilename) && | |
1040 mgNeedUpdate($galEntry, "mtime", filemtime($capFilename))) | |
1041 $updFlags |= GUPD_CAPTION; | |
1042 | |
311
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
1043 // Check for EXIF and XMP info |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
1044 if (($updFlags & GUPD_EXIF_INFO) && |
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
1045 ($res = mgReadEXIFAndXMPData($efilename, $exif, $xmp)) === TRUE) |
0 | 1046 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
1047 if ($xmp !== FALSE) |
311
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
1048 { |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
1049 echo "@"; |
311
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
1050 foreach ($galExifConversions as $conv) |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
1051 mgCopyEntryData($edata, $xmp, $conv[GEC_TYPE], $conv[GEC_NAME], $conv[GEC_FIELDS]); |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
1052 } |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
1053 |
314
020d155a179d
Refactor EXIF handling and integrate it with XMP handling. With a disgusting
Matti Hamalainen <ccr@tnsp.org>
parents:
313
diff
changeset
|
1054 if ($exif !== FALSE) |
304
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1055 { |
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1056 echo "%"; |
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1057 foreach ($galExifConversions as $conv) |
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1058 mgCopyEntryData($edata, $exif, $conv[GEC_TYPE], $conv[GEC_NAME], $conv[GEC_FIELDS]); |
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1059 } |
0 | 1060 } |
1061 else | |
1062 { | |
1063 // Copy old data that is not yet in new | |
1064 echo "*"; | |
1065 foreach ($galEntry as $okey => $odata) | |
1066 { | |
1067 if (!array_key_exists($okey, $edata)) | |
1068 $edata[$okey] = $odata; | |
1069 } | |
1070 } | |
1071 | |
1072 // Generate thumbnails, etc. | |
1073 if ($updFlags & GUPD_IMAGES) | |
1074 { | |
1075 mgMakeDir($tnPath, 0755); | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1076 mgMakeDir($medPath, 0755); |
0 | 1077 |
1078 if ($updFlags & GUPD_MED_IMAGE) | |
1079 { | |
1080 echo "1"; | |
1081 mgConvertImage($efilename, $medFilename, | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1082 [mgGetAlbumSetting($gallery, "med_width"), mgGetAlbumSetting($gallery, "med_height")], |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1083 mgGetAlbumSetting($gallery, "med_format"), mgGetAlbumSetting($gallery, "med_quality"), TRUE); |
0 | 1084 } |
1085 | |
1086 if ($updFlags & GUPD_TN_IMAGE) | |
1087 { | |
1088 echo "2"; | |
1089 mgConvertImage($efilename, $tnFilename, | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1090 [mgGetAlbumSetting($gallery, "tn_width"), mgGetAlbumSetting($gallery, "tn_height")], |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1091 mgGetAlbumSetting($gallery, "tn_format"), mgGetAlbumSetting($gallery, "tn_quality"), TRUE); |
0 | 1092 } |
1093 } | |
1094 | |
1095 // Check for .txt caption file | |
1096 if ($updFlags & GUPD_CAPTION) | |
1097 { | |
1098 echo "?"; | |
1099 if (($tmpData = @file_get_contents($capFilename)) !== FALSE) | |
1100 $edata["caption"] = $tmpData; | |
1101 } | |
310
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1102 |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1103 if ($updFlags & GUPD_EXIF_INFO) |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1104 { |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1105 // Get width/height information for thumbnails and mediums |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1106 $edata["med"] = []; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1107 if (($info = getimagesize($medFilename)) !== FALSE && count($info) >= 2) |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1108 { |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1109 $edata["med"]["width"] = $info[0]; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1110 $edata["med"]["height"] = $info[1]; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1111 echo "+"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1112 } |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1113 else |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1114 echo "-"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1115 |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1116 $edata["tn"] = []; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1117 if (($info = @getimagesize($tnFilename)) !== FALSE && count($info) > 0) |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1118 { |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1119 $edata["tn"]["width"] = $info[0]; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1120 $edata["tn"]["height"] = $info[1]; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1121 echo "+"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1122 } |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1123 else |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1124 echo "-"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1125 } |
0 | 1126 } |
1127 else | |
1128 if ($edata["type"] == 1) | |
1129 { | |
10 | 1130 // Set some of the album data here |
0 | 1131 $tmp = mgGetAlbumData($basepath, $efilename); |
1132 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "caption"); | |
1133 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "fallback_caption"); | |
1134 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title"); | |
1135 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE); | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
1136 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE); |
0 | 1137 } |
1138 } | |
1139 | |
1140 echo "\r".$path." ..... DONE\n"; | |
1141 | |
1142 mgCheckQuit(TRUE); | |
1143 } | |
1144 else | |
1145 mgFatal("Invalid work mode '".$mode."'.\n"); | |
1146 | |
1147 mgCheckQuit(TRUE); | |
1148 | |
1149 // 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
|
1150 foreach ($entries as $ename => &$edata) |
0 | 1151 if ($edata["type"] == 1) |
1152 { | |
1153 $epath = $path."/".$ename."/"; | |
1154 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode; | |
1155 | |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
1156 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt)) |
0 | 1157 return FALSE; |
1158 } | |
1159 | |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1160 // Finish update modes |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1161 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
|
1162 { |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1163 // Store gallery cache for this directory |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
1164 if ($writeMode && !mgWriteGalleryCache($cacheFilename, $gallery, $entries, $parentEntry)) |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1165 return FALSE; |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1166 } |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1167 |
0 | 1168 mgCheckQuit(TRUE); |
1169 | |
1170 return TRUE; | |
1171 } | |
1172 | |
1173 | |
1174 function mgSigHandler($signo) | |
1175 { | |
1176 global $flagQuit; | |
1177 switch ($signo) | |
1178 { | |
1179 case SIGTERM: | |
1180 mgFatal("Received SIGTERM.\n"); | |
1181 break; | |
1182 | |
1183 case SIGQUIT: | |
1184 case SIGINT: | |
1185 $flagQuit = TRUE; | |
1186 break; | |
1187 | |
1188 } | |
1189 } | |
1190 | |
1191 | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1192 function mgCheckMPath($path, $id) |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1193 { |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1194 if ($path."/" != mgGetSetting($id)) |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1195 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
|
1196 |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1197 if (strpos($path, "/") !== FALSE || $path == "") |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1198 mgFatal("Invalid ".$id." '".$path."'.\n"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1199 } |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1200 |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1201 |
0 | 1202 function mgProcessGalleries($cmd, $path) |
1203 { | |
343
d6422e856ecd
Remove the backend/SQL stuff for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
1204 global $galTNPath, $galMedPath; |
0 | 1205 |
1206 // Check validity of some settings | |
1207 $galPath = mgGetSetting("base_path"); | |
1208 $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path")); | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1209 $galMedPath = mgCleanPath(TRUE, mgGetSetting("med_path")); |
0 | 1210 |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1211 mgCheckMPath($galTNPath, "tn_path"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1212 mgCheckMPath($galMedPath, "med_path"); |
0 | 1213 |
1214 $parentData = $parentEntry = NULL; | |
1215 $writeMode = TRUE; | |
1216 $startAt = NULL; | |
1217 | |
1218 // Check for path argument | |
1219 if ($path !== FALSE) | |
1220 { | |
1221 // Check the given path, needs to be "under" the gallery path | |
1222 $cmp = mgCleanPath(TRUE, mgRealPath($galPath))."/"; | |
1223 $tmp = mgCleanPath(TRUE, mgRealPath($path))."/"; | |
1224 if (substr($tmp, 0, strlen($cmp)) != $cmp) | |
1225 mgFatal("Path '".$path."' ('".$tmp."') does not reside under '".$galPath."' ('".$cmp."')!\n"); | |
1226 | |
1227 // Check if we need to bootstrap | |
1228 if ($cmp != $tmp) | |
1229 { | |
1230 $bpath = mgCleanPath(TRUE, mgRealPath($tmp."../")); | |
1231 | |
1232 if ($cmd != GCMD_CLEAN) | |
1233 { | |
1234 $cacheFile = mgGetPath($bpath, "cache_file"); | |
1235 if (!file_exists($cacheFile)) | |
1236 mgFatal("Can't start working from '".$path."', parent '".$cacheFile."' does not exist!\n"); | |
1237 | |
1238 @include($cacheFile); | |
1239 if (!isset($galEntries) || !isset($galData)) | |
1240 mgFatal("Cache file '".$cacheFile."' is broken or stale.\n"); | |
1241 } | |
1242 | |
1243 $writeMode = FALSE; | |
1244 $startAt = $tmp; | |
1245 $path = $bpath; | |
1246 | |
1247 echo "Starting: '".$startAt."' inside '".$path."'.\n"; | |
1248 } | |
1249 else | |
1250 $path = $tmp; | |
1251 } | |
1252 else | |
1253 $path = $galPath; | |
1254 | |
1255 // Start working | |
1256 echo "Gallery path: '".$galPath."', starting at '".$path."' ...\n"; | |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1257 |
0 | 1258 mgHandleDirectory($cmd, $galPath, $path, $parentData, $parentEntry, $writeMode, $startAt); |
1259 } | |
1260 | |
1261 | |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1262 function mgGetDValStr($key, $mdata, $val, $format, $multi) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1263 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1264 $vfmt = "%s"; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1265 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1266 switch ($mdata[0]) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1267 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1268 case MG_STR_ARRAY: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1269 if ($val === FALSE) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1270 $val = []; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1271 else |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1272 if (is_array($val) || is_string($val)) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1273 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1274 $vfmt = "\"%s\""; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1275 if (is_string($val)) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1276 $val = [ $val ]; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1277 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1278 else |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1279 $val = "ERROR1"; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1280 break; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1281 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1282 case MG_STR: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1283 case MG_STR_LC: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1284 if (is_string($val)) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1285 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1286 $vfmt = "\"%s\""; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1287 if ($mdata[0] == MG_STR_LC) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1288 $val = strtolower($val); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1289 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1290 else |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1291 $val = "ERROR2"; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1292 break; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1293 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1294 case MG_BOOL: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1295 $val = $val ? "yes" : "no"; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1296 break; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1297 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1298 case MG_FLAGS: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1299 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1300 $mstr = []; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1301 foreach ($mdata[2] as $vkey => $vval) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1302 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1303 if ($val & $vval) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1304 $mstr[] = $vkey; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1305 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1306 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1307 $val = "\"".implode(" | ", $mstr)."\""; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1308 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1309 break; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1310 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1311 case MG_INT: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1312 $val = (string) $val; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1313 break; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1314 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1315 default: |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1316 $val = "ERROR"; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1317 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1318 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1319 if (!is_array($val)) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1320 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1321 if ($val === NULL || $val === FALSE) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1322 $val = []; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1323 else |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1324 $val = [ $val ]; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1325 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1326 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1327 $res = (count($val) == 0) ? "# " : ""; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1328 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1329 if ($multi) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1330 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1331 if (count($val) > 0) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1332 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1333 foreach ($val as $vv) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1334 $res .= sprintf($format, $key, sprintf($vfmt, $vv)); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1335 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1336 else |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1337 $res .= sprintf($format, $key, ""); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1338 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1339 else |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1340 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1341 $res .= sprintf($format, $key, |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1342 implode(", ", array_map(function($vv) use ($vfmt) { return sprintf($vfmt, $vv); }, $val))); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1343 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1344 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1345 return $res; |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1346 } |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1347 |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1348 |
0 | 1349 function mgShowCopyright() |
1350 { | |
1351 global $mgProgVersion, $mgProgCopyright, | |
1352 $mgProgInfo, $mgProgEmail; | |
1353 | |
1354 echo | |
184 | 1355 "MGTool ".$mgProgVersion." - MGallery management tool\n". |
1356 $mgProgInfo." ".$mgProgEmail."\n". | |
1357 "(C) Copyright ".$mgProgCopyright."\n"; | |
0 | 1358 } |
1359 | |
1360 | |
1361 function mgShowHelp() | |
1362 { | |
1363 global $argv; | |
1364 echo | |
1365 "Usage: ".basename($argv[0])." <command> [arguments]\n". | |
1366 "\n". | |
1367 " --help - Show this help.\n". | |
1368 " --version - Show version information.\n". | |
1369 "\n". | |
1370 " update [path]\n". | |
1371 " Update directories under <path> or all gallery dirs.\n". | |
1372 " Conditionally scans dirs for new or changed images and\n". | |
1373 " updates cache files as needed.\n". | |
1374 "\n". | |
1375 " rescan [path]\n". | |
1376 " Like 'update', but forces all cache files to be regenerated\n". | |
1377 " and EXIF/caption/etc information to be re-scanned even\n". | |
1378 " if the file timestamps do not justify re-scanning.\n". | |
1379 "\n". | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
1380 " 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
|
1381 " 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
|
1382 " 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
|
1383 " 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
|
1384 " trash - Delete any 'unmanaged' files inside thumbnail/medium dirs\n". |
0 | 1385 "\n". |
281 | 1386 " NOTICE! You usually probably want to use only the 'caches' and\n". |
308
b9530dda7ff0
Cosmetic fix in mgtool help.
Matti Hamalainen <ccr@tnsp.org>
parents:
306
diff
changeset
|
1387 " 'trash' options. Unless you know what you are doing, that is.\n". |
281 | 1388 "\n". |
159
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
1389 " config|dump\n". |
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
1390 " Display configuration values (with extra information) or\n". |
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
1391 " \"dump\" current configuration as is.\n". |
0 | 1392 "\n"; |
1393 } | |
1394 | |
1395 | |
1396 // | |
1397 // Main code starts | |
1398 // | |
1399 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) | |
1400 { | |
1401 header("Status: 404 Not Found"); | |
1402 die(); | |
1403 } | |
1404 | |
1405 pcntl_signal(SIGTERM, "mgSigHandler"); | |
1406 pcntl_signal(SIGHUP, "mgSigHandler"); | |
1407 pcntl_signal(SIGQUIT, "mgSigHandler"); | |
1408 pcntl_signal(SIGINT, "mgSigHandler"); | |
1409 | |
265 | 1410 // Check for improperly configured PHP |
264
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1411 if (extension_loaded("imagick") && extension_loaded("gmagick")) |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1412 { |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1413 mgError("FATAL ERROR! Both ImageMagick AND GraphicsMagick modules enabled in PHP! This will cause problems! Refusing to work.\n"); |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1414 exit(1); |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1415 } |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1416 else |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1417 if (!extension_loaded("imagick") && !extension_loaded("gmagick")) |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1418 { |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1419 mgError("No ImageMagick OR GraphicsMagick module available in PHP!\n"); |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1420 exit(1); |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1421 } |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1422 |
265 | 1423 // Check settings |
297
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1424 if (mgReadSettings($searchPaths) === FALSE) |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1425 { |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1426 die("MGallery is not configured, failed to find a configuration file.\n". |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1427 "Attempted search paths:\n".implode("\n", $searchPaths)."\n"); |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1428 } |
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
|
1429 |
265 | 1430 // Configure the timezone |
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
|
1431 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
|
1432 date_default_timezone_set($pageTimeZone); |
0 | 1433 |
265 | 1434 |
1435 // Check for commandline arguments | |
0 | 1436 $cmd = mgCArgLC(1); |
1437 switch ($cmd) | |
1438 { | |
340
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1439 case "metatest": |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1440 // Test metadata extraction from given image file |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1441 $efilename = mgCArg(2); |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1442 if ($efilename === FALSE) |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1443 { |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1444 mgFatal("No filename given.\n"); |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1445 } |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1446 |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1447 if (($res = mgReadEXIFAndXMPData($efilename, $exif, $xmp)) === TRUE) |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1448 { |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1449 if ($exif !== FALSE) |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1450 print_r($exif); |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1451 else |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1452 echo "No EXIF data found.\n"; |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1453 |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1454 if ($xmp !== FALSE) |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1455 print_r($xmp); |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1456 else |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1457 echo "No XMP data found.\n"; |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1458 } |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1459 else |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1460 mgFatal($res."\n"); |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1461 break; |
67e5bf30ee9b
Add undocumented 'metatest' command to mgtool, for testing metadata
Matti Hamalainen <ccr@tnsp.org>
parents:
339
diff
changeset
|
1462 |
0 | 1463 case "--version": |
1464 case "version": | |
1465 case "ver": | |
1466 mgShowCopyright(); | |
1467 break; | |
1468 | |
1469 case FALSE: | |
1470 // No arguments | |
1471 mgError("Nothing to do. Showing help:\n"); | |
1472 | |
1473 case "--help": | |
1474 case "help": | |
1475 if ($cmd !== FALSE) | |
1476 mgShowCopyright(); | |
1477 mgShowHelp(); | |
1478 break; | |
1479 | |
1480 case "update": case "up": case "upd": case "upda": | |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1481 $farg = mgCArg(2); |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1482 mgProcessGalleries(GCMD_UPDATE, $farg); |
0 | 1483 break; |
1484 | |
1485 case "rescan": case "re": case "res": | |
1486 mgProcessGalleries(GCMD_RESCAN, mgCArg(2)); | |
1487 break; | |
1488 | |
1489 case "clean": case "cl": case "cle": | |
1490 $cmode = mgCArgLC(2, 2); | |
1491 switch ($cmode) | |
1492 { | |
1493 case "al": $galCleanFlags = GCLEAN_ALL; break; | |
1494 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
|
1495 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
|
1496 case "tr": $galCleanFlags = GCLEAN_TRASH; break; |
0 | 1497 case FALSE: |
1498 mgFatal("Cleaning requires a mode argument.\n"); | |
1499 | |
1500 default: | |
1501 mgFatal("Invalid clean mode '".mgCArg(2)."'.\n"); | |
1502 } | |
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
|
1503 $countDoDelete = 0; |
0 | 1504 $flagDoDelete = FALSE; |
1505 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); | |
1506 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
|
1507 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
|
1508 { |
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
|
1509 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
|
1510 } |
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
|
1511 else |
0 | 1512 if (mgYesNoPrompt("Really delete the above files and directories?")) |
1513 { | |
25
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1514 echo "Deleting ...\n"; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1515 $flagDoDelete = TRUE; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1516 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1517 } |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1518 else |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1519 { |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1520 echo "Okay, canceling operation.\n"; |
0 | 1521 } |
1522 break; | |
1523 | |
1524 case "config": | |
1525 case "dump": | |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1526 foreach ($mgDefaults as $ckey => $cdata) |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1527 { |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1528 $sval = mgGetSetting($ckey); |
0 | 1529 |
26 | 1530 if ($cmd == "dump") |
1531 { | |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1532 echo mgGetDValStr($ckey, $cdata, $sval, "%1\$-15s = %2\$s\n", FALSE); |
26 | 1533 } |
1534 else | |
1535 { | |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1536 echo mgGetDValStr($ckey, $cdata, $sval, "%1\$-15s = %2\$s", TRUE). |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1537 (($cdata[1] !== NULL && $sval !== $cdata[1]) ? |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1538 " (default: ".mgGetDValStr($ckey, $cdata, $cdata[1], "%2\$s", FALSE).")" : "")."\n"; |
26 | 1539 } |
0 | 1540 } |
1541 break; | |
1542 | |
1543 default: | |
1544 mgError("Unknown option/command '".$cmd."'.\n"); | |
1545 break; | |
1546 } | |
1547 | |
1548 ?> |