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