Mercurial > hg > mgallery
annotate mgtool.php @ 313:d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Apr 2020 18:37:49 +0300 |
parents | 326935332784 |
children | 020d155a179d |
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> |
306 | 7 // (C) Copyright 2015-2020 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 // | |
301 | 251 // Read XMP data block from given file |
252 // .. it's a horrible hack. | |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
253 // |
311
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
254 function mgReadXMPFromRAWData($filename, $xmpBlockSize = 1024*64) |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
255 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
256 if (($fh = @fopen($filename, 'rb')) === FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
257 return FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
258 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
259 $xmpStartTag = "<x:xmpmeta"; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
260 $xmpEndTag = "</x:xmpmeta>"; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
261 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
262 // Check for start tag |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
263 $buffer = ""; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
264 $xmpOK = FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
265 while (!feof($fh)) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
266 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
267 if (($tmp = @fread($fh, $xmpBlockSize)) === FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
268 return FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
269 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
270 $buffer .= $tmp; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
271 if (($spos1 = strpos($buffer, "<")) !== FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
272 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
273 $buffer = substr($buffer, $spos1); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
274 if (($spos2 = strpos($buffer, $xmpStartTag)) !== FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
275 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
276 $buffer = substr($buffer, $spos2); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
277 $xmpOK = TRUE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
278 break; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
279 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
280 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
281 else |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
282 $buffer = ""; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
283 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
284 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
285 // Check for end tag if start tag was found |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
286 if ($xmpOK) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
287 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
288 $xmpOK = FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
289 $buffer2 = $buffer; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
290 do |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
291 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
292 if (($spos1 = strpos($buffer2, "<")) !== FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
293 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
294 $buffer2 = substr($buffer2, $spos1); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
295 if (($spos2 = strpos($buffer2, $xmpEndTag)) !== FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
296 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
297 $xmpOK = TRUE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
298 break; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
299 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
300 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
301 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
302 if (($tmp = @fread($fh, $xmpBlockSize)) !== FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
303 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
304 $buffer2 .= $tmp; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
305 $buffer .= $tmp; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
306 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
307 else |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
308 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
309 $xmpOK = FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
310 break; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
311 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
312 } while (!$xmpOK); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
313 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
314 if ($xmpOK) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
315 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
316 if (($spos = strpos($buffer, $xmpEndTag)) !== FALSE) |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
317 $buffer = substr($buffer, 0, $spos + strlen($xmpEndTag)); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
318 else |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
319 $xmpOK = FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
320 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
321 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
322 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
323 fclose($fh); |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
324 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
325 return $xmpOK ? $buffer : FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
326 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
327 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
328 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
329 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
|
330 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
331 // 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
|
332 // 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
|
333 $xmpPatterns = |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
334 [ |
312
326935332784
Remove <?xpacket ?> from the XMP, as SimpleXML can't parse it.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
335 "/<\?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
|
336 "/[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
|
337 "/\/[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
|
338 "/<\/?(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
|
339 ]; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
340 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
341 $xmpReplacements = |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
342 [ |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
343 "", |
312
326935332784
Remove <?xpacket ?> from the XMP, as SimpleXML can't parse it.
Matti Hamalainen <ccr@tnsp.org>
parents:
311
diff
changeset
|
344 "", |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
345 "\/", |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
346 "", |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
347 ]; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
348 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
349 $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
|
350 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
351 // 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
|
352 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
|
353 return FALSE; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
354 |
301 | 355 // 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
|
356 $xmpData = []; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
357 |
313
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
358 /* |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
359 // 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
|
360 // 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
|
361 // 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
|
362 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
|
363 { |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
364 $tmp = $xres[0]->attributes(); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
365 mgConvertAttribute($xmpData, $tmp, "lensmodel", "Lens"); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
366 mgConvertAttribute($xmpData, $tmp, "datetime", "CreateDate"); |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
367 } |
279
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
368 |
313
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
369 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
|
370 $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
|
371 */ |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
372 |
d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
Matti Hamalainen <ccr@tnsp.org>
parents:
312
diff
changeset
|
373 // 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
|
374 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
|
375 { |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
376 $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
|
377 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
378 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
379 return $xmpData; |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
380 } |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
381 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
382 |
54a54921426c
Add functions for extracting XMP information from files and parsing the XMP
Matti Hamalainen <ccr@tnsp.org>
parents:
277
diff
changeset
|
383 // |
0 | 384 // Converts one value (mainly from EXIF tag information) |
52 | 385 // by doing explicit type casting and special conversions. |
0 | 386 // |
387 function mgConvertExifData($val, $vtype) | |
388 { | |
389 switch ($vtype) | |
390 { | |
46
e58292065b01
Let arrays through mgConvertExifData() when the type is MG_STR without
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
391 case MG_STR: return is_array($val) ? $val : (string) $val; |
0 | 392 case MG_INT: return intval($val); |
393 case MG_BOOL: return intval($val); | |
394 case MG_DVA: | |
223
438277861f51
Implement better interpretation of DVA values (exposure times, for example),
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
395 if (sscanf($val, "%d/%d", $v1, $v2) == 2 && $v2 != 0 && $v1 != 0) |
0 | 396 { |
397 if ($v1 < $v2) | |
249
abcd21b01829
Use floating point formatting for certain DVA values.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
398 return sprintf("1/%1.1f", $v2 / $v1); |
0 | 399 else |
400 return sprintf("%1.1f", $v1 / $v2); | |
401 } | |
402 else | |
403 return $val; | |
404 | |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
405 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
|
406 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
|
407 |
0 | 408 default: |
409 return $val; | |
410 } | |
411 } | |
412 | |
413 | |
414 // | |
415 // Conditionally copies one "field" from an associated array/hash to another. | |
416 // If destination is already SET, nothing will be done. If source does | |
417 // not exist (e.g. one or more of the keys do not exist in source array), | |
418 // a default value will be used, if provided. | |
419 // Source may have multi-depth keys, destination has one key. | |
420 // | |
421 function mgCopyEntryData(&$dst, $src, $vtype, $dkey, $skeys, $default = NULL) | |
422 { | |
423 // Is destination already set? | |
424 if (isset($dst[$dkey])) | |
425 return FALSE; | |
426 | |
427 // If input key is not array, change it into one | |
428 if (!is_array($skeys)) | |
429 $skeys = array($skeys); | |
430 | |
431 // Traverse input array by using consequent keys | |
432 $tmp = &$src; | |
433 foreach ($skeys as $skey) | |
434 { | |
435 if (!array_key_exists($skey, $tmp)) | |
436 { | |
437 // Key didn't exist, try for default | |
438 if ($default !== NULL) | |
439 $dst[$dkey] = $default; | |
440 return FALSE; | |
441 } | |
442 else | |
443 $tmp = &$tmp[$skey]; | |
444 } | |
445 | |
446 // Optionally convert the input value | |
447 $dst[$dkey] = mgConvertExifData($tmp, $vtype); | |
448 return TRUE; | |
449 } | |
450 | |
451 | |
452 // | |
453 // Attempt to get gallery album data from various sources. | |
454 // | |
455 function mgGetAlbumData($galBasePath, $galPath) | |
456 { | |
457 // Check path permissions | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
458 $galData = []; |
0 | 459 if (is_readable($galPath)) |
460 { | |
461 // First, try to read gallery/album info file | |
462 $filename = mgGetPath($galPath, "info_file"); | |
463 if ($filename !== FALSE && file_exists($filename)) | |
464 { | |
465 mgDebug("Reading INFOFILE: ".$filename."\n"); | |
466 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
|
467 $galData = []; |
0 | 468 } |
469 | |
470 // Read header file, if any, and we don't have "header" field set yet | |
471 $filename = mgGetPath($galPath, "header_file"); | |
472 if ($filename !== FALSE && file_exists($filename) && | |
473 !isset($galData["header"])) | |
474 { | |
475 mgDebug("Reading HEADERFILE: ".$filename."\n"); | |
476 $galData["header"] = file_get_contents($filename); | |
477 } | |
478 | |
479 // Check for alternate key/values for album title/caption | |
480 if (isset($galData["title"]) && !isset($galData["caption"])) | |
481 { | |
482 $galData["caption"] = $galData["title"]; | |
483 unset($galData["title"]); | |
484 } | |
485 } | |
486 else | |
487 $galData["hide"] = TRUE; | |
488 | |
489 // If caption is not set, use last path component for | |
490 // a fallback value in case we don't discover proper title | |
491 // from other sources we can't check here yet. | |
492 $path = explode("/", $galPath); | |
493 $galData["fallback_caption"] = ucfirst(str_replace("_", " ", end($path))); | |
494 | |
495 // Last, store the current gallery path | |
496 $len = strlen($galBasePath); | |
497 if ($len < strlen($galPath) && substr($galPath, 0, $len) == $galBasePath) | |
498 $galData["path"] = substr($galPath, $len); | |
499 else | |
500 $galData["path"] = ""; | |
501 | |
502 return $galData; | |
503 } | |
504 | |
505 | |
165 | 506 // |
507 // Parse a simple image captions file, with format of one entry per line. | |
508 // Lines starting with "# " are comments (note the whitespace), empty lines ignored. | |
509 // First continuous non-whitespace text is file/dirname, followed | |
510 // by caption text, which is separate with whitespace from the filename. | |
511 // Filenames starting with # will be made hidden entries. | |
512 // Filenames starging with % will hide contents. | |
513 // | |
0 | 514 function mgReadCaptionsFile($galBasePath, $galPath) |
515 { | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
516 $captions = []; |
0 | 517 $filename = mgGetPath($galPath, "captions_file"); |
518 if ($filename === FALSE || ($fp = @fopen($filename, "rb")) === FALSE) | |
519 return $captions; | |
520 | |
521 mgDebug("Reading CAPTIONS: ".$filename."\n"); | |
522 | |
523 // Read and parse data | |
524 while (!feof($fp)) | |
525 { | |
526 $str = trim(fgets($fp)); | |
527 // Ignore comments and empty lines | |
528 if ($str != "#" && $str != "") | |
529 { | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
530 if (preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m)) |
45 | 531 $captions[$m[2]] = ["caption" => $m[3], "hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; |
0 | 532 else |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
533 if (preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m)) |
45 | 534 $captions[$m[2]] = ["hide" => ($m[1] == "#"), "hide_contents" => ($m[1] == "%"), "used" => FALSE]; |
0 | 535 } |
536 } | |
537 | |
538 fclose($fp); | |
539 return $captions; | |
540 } | |
541 | |
542 | |
165 | 543 // |
544 // Create directory with specified permissions | |
545 // | |
0 | 546 function mgMakeDir($path, $perm) |
547 { | |
548 if (!file_exists($path)) | |
549 { | |
550 if (mkdir($path, $perm, TRUE) === false) | |
551 return mgError("Could not create directory '".$path."'\n"); | |
552 } | |
553 return TRUE; | |
554 } | |
555 | |
556 | |
165 | 557 // |
558 // Print a simple yes/no prompt with given message | |
559 // and default value. | |
560 // | |
0 | 561 function mgYesNoPrompt($msg, $default = FALSE) |
562 { | |
563 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; | |
564 $sprompt = strtolower(trim(fgets(STDIN))); | |
565 | |
166
d8387b48b08d
Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
566 if ($sprompt == "") |
d8387b48b08d
Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
567 return $default; |
0 | 568 else |
165 | 569 return $sprompt[0] == 'y'; |
0 | 570 } |
571 | |
572 | |
165 | 573 // |
182 | 574 // Delete given directory OR file, recursively |
165 | 575 // |
183 | 576 function mgDelete($path, $showFiles) |
0 | 577 { |
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
|
578 global $flagDoDelete, $countDoDelete; |
0 | 579 if (is_dir($path)) |
580 { | |
581 if (($dirHandle = @opendir($path)) === FALSE) | |
582 return mgError("Could not read directory '".$path."'.\n"); | |
583 | |
584 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
585 { | |
586 if ($dirFile != "." && $dirFile != "..") | |
183 | 587 mgDelete($path."/".$dirFile, $showFiles); |
0 | 588 } |
183 | 589 |
0 | 590 closedir($dirHandle); |
591 | |
592 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
|
593 $countDoDelete++; |
0 | 594 if ($flagDoDelete) |
595 rmdir($path); | |
596 } | |
597 else | |
54
624c50e1b52d
Fix 'mgtool clean' to not attempt deleting files that do not exist.
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
598 if (file_exists($path)) |
0 | 599 { |
183 | 600 if ($showFiles) |
0 | 601 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
|
602 |
62
3f60a5f5b4b3
Actually fix checking for files to be deleted to work.
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
603 $countDoDelete++; |
0 | 604 if ($flagDoDelete) |
605 unlink($path); | |
606 } | |
607 } | |
608 | |
609 | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
610 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
|
611 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
612 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
|
613 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
|
614 { |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
615 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
|
616 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
|
617 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
618 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
|
619 { |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
620 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
|
621 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
|
622 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
623 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
624 closedir($dirHandle); |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
625 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
626 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
|
627 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
628 $countDoDelete++; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
629 if ($flagDoDelete) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
630 rmdir($path); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
631 else |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
632 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
|
633 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
634 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
635 else |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
636 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
|
637 { |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
638 $countDoDelete++; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
639 if ($flagDoDelete) |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
640 unlink($path); |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
641 else |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
642 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
|
643 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
644 } |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
645 |
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
646 |
165 | 647 // |
648 // Check if we have received the quit signal | |
649 // and if yes, quit cleanly now. | |
650 // | |
0 | 651 function mgCheckQuit($now = FALSE) |
652 { | |
653 global $flagQuit; | |
654 | |
655 // Dispatch pending signals | |
656 pcntl_signal_dispatch(); | |
657 | |
658 // Check result | |
659 if ($now && $flagQuit) | |
660 mgFatal("Quitting.\n"); | |
661 | |
662 return $flagQuit; | |
663 } | |
664 | |
665 | |
666 function mgNeedUpdate($entry, $field, $cvalue) | |
667 { | |
668 if (!array_key_exists($field, $entry)) | |
669 return TRUE; | |
80 | 670 |
0 | 671 return ($entry[$field] < $cvalue); |
672 } | |
673 | |
674 | |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
675 function mgSortFunc($a, $b) |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
676 { |
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
|
677 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
|
678 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
|
679 $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
|
680 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
|
681 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
|
682 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
|
683 $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
|
684 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
|
685 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
|
686 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
|
687 $cres = 1; |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
688 else |
108
417cdd9f8864
Use image file base name for sorting if timestamps are not available.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
689 if (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
|
690 $cres = strcmp($b["base"], $a["base"]); |
108
417cdd9f8864
Use image file base name for sorting if timestamps are not available.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
691 else |
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
|
692 $cres = 0; |
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
|
693 |
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
|
694 return $cres; |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
695 } |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
696 |
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
697 |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
698 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
|
699 { |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
700 global $galBackend, $db, $galExifConversions, $flagSQL; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
701 |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
702 // 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
|
703 $images = []; |
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
704 $albums = []; |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
705 $output = []; |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
706 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
707 // 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
|
708 if (!$parentEntry["hide_contents"]) |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
709 { |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
710 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
|
711 { |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
712 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
|
713 continue; |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
714 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
715 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
|
716 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
|
717 $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
|
718 else |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
719 $albums[$ename] = &$edata; |
61
ee82f7c8d44c
Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents:
60
diff
changeset
|
720 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
721 $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
|
722 } |
30
f2c21a8b9071
Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
723 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
724 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
|
725 krsort($albums); |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
726 |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
727 // Choose gallery album image |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
728 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
|
729 { |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
730 if (isset($gallery["albumpic"]) && |
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
731 isset($images[$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
|
732 { |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
733 $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
|
734 } |
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
|
735 else |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
736 { |
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
|
737 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
|
738 $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
|
739 } |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
740 } |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
741 else |
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
742 { |
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
|
743 foreach ($albums as $aid => &$adata) |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
744 if (isset($adata["image"])) |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
745 { |
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
|
746 $parentEntry["image"] = &$adata; |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
747 break; |
8d8b361a76af
Allow setting "albumpic" in gallery.info for each album, e.g. forced album cover picture.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
748 } |
64
9a01e14b27ef
Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
749 } |
35
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
750 } |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
751 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
752 if ($galBackend == "sql" && $flagSQL) |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
753 { |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
754 mgDBBeginTransaction(); |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
755 |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
756 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
|
757 ($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
|
758 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
|
759 |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
760 foreach ($output as $entry => &$edata) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
761 if ($edata["type"] == 0) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
762 { |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
763 $ekeys = ["path_id", "filename"]; |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
764 $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
|
765 $esets = []; |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
766 |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
767 foreach ($galExifConversions as $econv) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
768 if ($econv[GEC_IS_UNIQUE]) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
769 { |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
770 $ekey = $econv[GEC_NAME]; |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
771 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
772 // 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
|
773 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
|
774 { |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
775 $esets[$ekey] = TRUE; |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
776 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
777 switch ($econv[GEC_TYPE]) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
778 { |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
779 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
|
780 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
|
781 default: $etype = "s"; break; |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
782 } |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
783 |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
784 $ekeys[] = $ekey; |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
785 $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
|
786 } |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
787 } |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
788 |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
789 $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
|
790 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
|
791 mgFatal("Failed.\n"); |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
792 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
793 // 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
|
794 foreach ($galExifConversions as $econv) |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
795 { |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
796 $ekey = $econv[GEC_NAME]; |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
797 if (!$econv[GEC_IS_UNIQUE] && |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
798 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
|
799 { |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
800 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
|
801 { |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
802 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
|
803 { |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
804 $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
|
805 if (($id = mgExecSQLInsert($sql)) === FALSE) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
806 mgFatal("Failure!\n"); |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
807 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
808 $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
|
809 if (($id = mgExecSQL($sql)) === FALSE) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
810 mgFatal("Failure!\n"); |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
811 } |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
812 } |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
813 else |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
814 { |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
815 $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
|
816 if (($id = mgExecSQLInsert($sql)) === FALSE) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
817 mgFatal("Failure!\n"); |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
818 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
819 $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
|
820 if (($id = mgExecSQL($sql)) === FALSE) |
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
821 mgFatal("Failure!\n"); |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
822 } |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
823 |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
824 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
825 } |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
826 } |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
827 |
300
7bccb4204e6e
Cleanup indent and use if instead of switch/case.
Matti Hamalainen <ccr@tnsp.org>
parents:
299
diff
changeset
|
828 mgDBCommitTransaction(); |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
829 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
830 |
15
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
831 $str = |
271 | 832 "<?php\n". |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
833 "\$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
|
834 "\$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
|
835 "\$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
|
836 "\$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
|
837 "?>"; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
838 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
839 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
|
840 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
|
841 |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
842 return TRUE; |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
843 } |
805f93962cf9
Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
844 |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
845 |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
846 function mgHandleDirectory($mode, $basepath, $path, &$parentData, &$parentEntry, $writeMode, $startAt) |
0 | 847 { |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
848 global $galExifConversions, $galTNPath, $galMedPath, $galCleanFlags; |
0 | 849 |
850 // Get cache file path | |
851 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE) | |
852 return mgError("Cache filename / path not set.\n"); | |
853 | |
854 mgCheckQuit(TRUE); | |
855 | |
856 // Read directory contents | |
60
ef9f17280372
Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
857 $entries = []; |
0 | 858 if (($dirHandle = @opendir($path)) === FALSE) |
859 return mgError("Could not read directory '".$path."'.\n"); | |
860 | |
861 while (($dirFile = @readdir($dirHandle)) !== FALSE) | |
862 { | |
863 $realFile = $path."/".$dirFile; | |
864 if (is_dir($realFile)) | |
865 { | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
866 if ($dirFile[0] != "." && $dirFile != $galTNPath && $dirFile != $galMedPath) |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
867 $entries[$dirFile] = ["type" => 1, "base" => $dirFile, "ext" => "", "mtime" => filemtime($realFile)]; |
0 | 868 } |
869 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
|
870 if (preg_match("/^([^\/]+)(".mgGetSetting("format_exts").")$/i", $dirFile, $dirMatch)) |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
871 $entries[$dirFile] = ["type" => 0, "base" => $dirMatch[1], "ext" => $dirMatch[2], "mtime" => filemtime($realFile), "hide" => false]; |
0 | 872 } |
873 closedir($dirHandle); | |
874 | |
875 mgCheckQuit(); | |
876 | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
877 $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
|
878 $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
|
879 $generatedFiles = []; |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
880 $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
|
881 $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
|
882 |
0 | 883 // Cleanup mode |
884 if ($mode == GCMD_CLEAN) | |
885 { | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
886 $gallery = mgGetAlbumData($basepath, $path); |
0 | 887 |
888 if ($writeMode) | |
889 { | |
890 if ($galCleanFlags & GCLEAN_CACHES) | |
183 | 891 mgDelete($cacheFilename, TRUE); |
0 | 892 |
251
19dab8b0c340
Remove clean command suboptions 'thumbnails' and 'mediums' and replace them with 'images'.
Matti Hamalainen <ccr@tnsp.org>
parents:
250
diff
changeset
|
893 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
|
894 { |
183 | 895 mgDelete($path."/".$galTNPath, FALSE); |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
896 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
|
897 } |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
898 |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
899 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
|
900 { |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
901 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
|
902 { |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
903 $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
|
904 $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
|
905 $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
|
906 $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
|
907 } |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
908 |
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
909 // 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
|
910 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
|
911 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
|
912 } |
0 | 913 } |
914 } | |
915 else | |
916 // Update modes | |
917 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN) | |
918 { | |
919 // 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
|
920 $galEntries = []; |
0 | 921 $cacheTime = -1; |
922 if ($mode == GCMD_UPDATE && file_exists($cacheFilename)) | |
923 { | |
924 $cacheTime = filemtime($cacheFilename); | |
925 @include $cacheFilename; | |
926 } | |
927 | |
928 // Read caption data | |
929 $captions = mgReadCaptionsFile($basepath, $path); | |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
930 $gallery = mgGetAlbumData($basepath, $path); |
0 | 931 if ($parentData !== NULL && $parentEntry !== NULL) |
932 { | |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
933 $gallery["parent"] = &$parentData; |
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
934 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption"); |
0 | 935 } |
936 | |
937 // Start actual processing | |
938 $nentries = count($entries); | |
939 $nentry = 0; | |
940 echo $path." .. "; | |
941 foreach ($entries as $ename => &$edata) | |
942 { | |
943 printf("\r%s (%1.1f%%) ..", $path, ($nentry * 100.0) / $nentries); | |
944 | |
945 $nentry++; | |
946 $efilename = $path."/".$ename; | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
947 $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
|
948 $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
|
949 $capFilename = $path."/".$edata["base"].".txt"; |
0 | 950 |
951 if (array_key_exists($ename, $galEntries)) | |
952 $galEntry = &$galEntries[$ename]; | |
953 else | |
63
1c32ece9acde
Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
954 $galEntry = []; |
0 | 955 |
57
29bb365e3ee2
Be more responsive when processing images, check for signals after each
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
956 mgCheckQuit(TRUE); |
0 | 957 |
958 // Update with captions file data, if any | |
959 if (array_key_exists($ename, $captions)) | |
960 { | |
961 foreach ($captions[$ename] as $ckey => $cval) | |
962 $edata[$ckey] = $cval; | |
963 } | |
964 | |
965 // Handle entry based on type | |
966 if ($edata["type"] == 0) | |
967 { | |
968 $updFlags = 0; | |
255
d0bcc6c7fc66
Automatically clean any unnecessary "trash" from thumbnail and medium image directories.
Matti Hamalainen <ccr@tnsp.org>
parents:
253
diff
changeset
|
969 |
0 | 970 // Check what we need to update .. |
971 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"]) | |
972 $updFlags |= GUPD_MED_IMAGE; | |
973 | |
974 if (!file_exists($tnFilename) || filemtime($tnFilename) < $edata["mtime"]) | |
975 $updFlags |= GUPD_TN_IMAGE; | |
976 | |
977 if (mgNeedUpdate($galEntry, "mtime", $edata["mtime"])) | |
978 $updFlags |= GUPD_EXIF_INFO; | |
979 | |
980 if (file_exists($capFilename) && | |
981 mgNeedUpdate($galEntry, "mtime", filemtime($capFilename))) | |
982 $updFlags |= GUPD_CAPTION; | |
983 | |
311
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
984 // Check for EXIF and XMP info |
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
|
985 if ($updFlags & GUPD_EXIF_INFO) |
0 | 986 { |
311
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
987 // TODO XXX: Perhaps support XMP sidecar files |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
988 if (($xmpStr = mgReadXMPFromRAWData($efilename)) !== FALSE && |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
989 ($xmp = mgParseXMPData($xmpStr)) !== FALSE) |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
990 { |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
991 foreach ($galExifConversions as $conv) |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
992 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
|
993 } |
8fd5c850f921
Minor cleanup to XMP/EXIF fetching.
Matti Hamalainen <ccr@tnsp.org>
parents:
310
diff
changeset
|
994 |
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
|
995 if (($exif = @exif_read_data($efilename)) !== FALSE) |
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
996 { |
da150fe627b6
Collect dimension/size (width/height) information of thumbnail and medium images into the cache.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
997 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
|
998 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
|
999 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
|
1000 } |
0 | 1001 } |
1002 else | |
1003 { | |
1004 // Copy old data that is not yet in new | |
1005 echo "*"; | |
1006 foreach ($galEntry as $okey => $odata) | |
1007 { | |
1008 if (!array_key_exists($okey, $edata)) | |
1009 $edata[$okey] = $odata; | |
1010 } | |
1011 } | |
1012 | |
1013 // Generate thumbnails, etc. | |
1014 if ($updFlags & GUPD_IMAGES) | |
1015 { | |
1016 mgMakeDir($tnPath, 0755); | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1017 mgMakeDir($medPath, 0755); |
0 | 1018 |
1019 if ($updFlags & GUPD_MED_IMAGE) | |
1020 { | |
1021 echo "1"; | |
1022 mgConvertImage($efilename, $medFilename, | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1023 [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
|
1024 mgGetAlbumSetting($gallery, "med_format"), mgGetAlbumSetting($gallery, "med_quality"), TRUE); |
0 | 1025 } |
1026 | |
1027 if ($updFlags & GUPD_TN_IMAGE) | |
1028 { | |
1029 echo "2"; | |
1030 mgConvertImage($efilename, $tnFilename, | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
292
diff
changeset
|
1031 [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
|
1032 mgGetAlbumSetting($gallery, "tn_format"), mgGetAlbumSetting($gallery, "tn_quality"), TRUE); |
0 | 1033 } |
1034 } | |
1035 | |
1036 // Check for .txt caption file | |
1037 if ($updFlags & GUPD_CAPTION) | |
1038 { | |
1039 echo "?"; | |
1040 if (($tmpData = @file_get_contents($capFilename)) !== FALSE) | |
1041 $edata["caption"] = $tmpData; | |
1042 } | |
310
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1043 |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1044 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
|
1045 { |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1046 // 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
|
1047 $edata["med"] = []; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1048 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
|
1049 { |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1050 $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
|
1051 $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
|
1052 echo "+"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1053 } |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1054 else |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1055 echo "-"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1056 |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1057 $edata["tn"] = []; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1058 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
|
1059 { |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1060 $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
|
1061 $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
|
1062 echo "+"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1063 } |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1064 else |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1065 echo "-"; |
b1fc8a908eac
Get med/tn image sizes after they have been generated.
Matti Hamalainen <ccr@tnsp.org>
parents:
308
diff
changeset
|
1066 } |
0 | 1067 } |
1068 else | |
1069 if ($edata["type"] == 1) | |
1070 { | |
10 | 1071 // Set some of the album data here |
0 | 1072 $tmp = mgGetAlbumData($basepath, $efilename); |
1073 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "caption"); | |
1074 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "fallback_caption"); | |
1075 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title"); | |
1076 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE); | |
11
0b097770061d
Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
1077 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE); |
0 | 1078 } |
1079 } | |
1080 | |
1081 echo "\r".$path." ..... DONE\n"; | |
1082 | |
1083 mgCheckQuit(TRUE); | |
1084 } | |
1085 else | |
1086 mgFatal("Invalid work mode '".$mode."'.\n"); | |
1087 | |
1088 mgCheckQuit(TRUE); | |
1089 | |
1090 // 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
|
1091 foreach ($entries as $ename => &$edata) |
0 | 1092 if ($edata["type"] == 1) |
1093 { | |
1094 $epath = $path."/".$ename."/"; | |
1095 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode; | |
1096 | |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
1097 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt)) |
0 | 1098 return FALSE; |
1099 } | |
1100 | |
16
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1101 // Finish update modes |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1102 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
|
1103 { |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1104 // Store gallery cache for this directory |
292
418f932763f2
Backed out changeset 13a23b120e72
Matti Hamalainen <ccr@tnsp.org>
parents:
291
diff
changeset
|
1105 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
|
1106 return FALSE; |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1107 } |
3491ab93630e
Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
1108 |
0 | 1109 mgCheckQuit(TRUE); |
1110 | |
1111 return TRUE; | |
1112 } | |
1113 | |
1114 | |
1115 function mgSigHandler($signo) | |
1116 { | |
1117 global $flagQuit; | |
1118 switch ($signo) | |
1119 { | |
1120 case SIGTERM: | |
1121 mgFatal("Received SIGTERM.\n"); | |
1122 break; | |
1123 | |
1124 case SIGQUIT: | |
1125 case SIGINT: | |
1126 $flagQuit = TRUE; | |
1127 break; | |
1128 | |
1129 } | |
1130 } | |
1131 | |
1132 | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1133 function mgCheckMPath($path, $id) |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1134 { |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1135 if ($path."/" != mgGetSetting($id)) |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1136 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
|
1137 |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1138 if (strpos($path, "/") !== FALSE || $path == "") |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1139 mgFatal("Invalid ".$id." '".$path."'.\n"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1140 } |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1141 |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1142 |
0 | 1143 function mgProcessGalleries($cmd, $path) |
1144 { | |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1145 global $galTNPath, $galMedPath, $galSQLTables, $flagSQL; |
0 | 1146 |
1147 // Check validity of some settings | |
1148 $galPath = mgGetSetting("base_path"); | |
1149 $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path")); | |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1150 $galMedPath = mgCleanPath(TRUE, mgGetSetting("med_path")); |
0 | 1151 |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1152 mgCheckMPath($galTNPath, "tn_path"); |
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
1153 mgCheckMPath($galMedPath, "med_path"); |
0 | 1154 |
1155 $parentData = $parentEntry = NULL; | |
1156 $writeMode = TRUE; | |
1157 $startAt = NULL; | |
1158 | |
1159 // Check for path argument | |
1160 if ($path !== FALSE) | |
1161 { | |
1162 // Check the given path, needs to be "under" the gallery path | |
1163 $cmp = mgCleanPath(TRUE, mgRealPath($galPath))."/"; | |
1164 $tmp = mgCleanPath(TRUE, mgRealPath($path))."/"; | |
1165 if (substr($tmp, 0, strlen($cmp)) != $cmp) | |
1166 mgFatal("Path '".$path."' ('".$tmp."') does not reside under '".$galPath."' ('".$cmp."')!\n"); | |
1167 | |
1168 // Check if we need to bootstrap | |
1169 if ($cmp != $tmp) | |
1170 { | |
1171 $bpath = mgCleanPath(TRUE, mgRealPath($tmp."../")); | |
1172 | |
1173 if ($cmd != GCMD_CLEAN) | |
1174 { | |
1175 $cacheFile = mgGetPath($bpath, "cache_file"); | |
1176 if (!file_exists($cacheFile)) | |
1177 mgFatal("Can't start working from '".$path."', parent '".$cacheFile."' does not exist!\n"); | |
1178 | |
1179 @include($cacheFile); | |
1180 if (!isset($galEntries) || !isset($galData)) | |
1181 mgFatal("Cache file '".$cacheFile."' is broken or stale.\n"); | |
1182 } | |
1183 | |
1184 $writeMode = FALSE; | |
1185 $startAt = $tmp; | |
1186 $path = $bpath; | |
1187 | |
1188 echo "Starting: '".$startAt."' inside '".$path."'.\n"; | |
1189 } | |
1190 else | |
1191 $path = $tmp; | |
1192 } | |
1193 else | |
1194 $path = $galPath; | |
1195 | |
1196 // Start working | |
1197 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
|
1198 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1199 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
|
1200 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1201 foreach ($galSQLTables as $tname => $tdata) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1202 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1203 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
|
1204 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
|
1205 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1206 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1207 |
0 | 1208 mgHandleDirectory($cmd, $galPath, $path, $parentData, $parentEntry, $writeMode, $startAt); |
1209 } | |
1210 | |
1211 | |
1212 function mgShowCopyright() | |
1213 { | |
1214 global $mgProgVersion, $mgProgCopyright, | |
1215 $mgProgInfo, $mgProgEmail; | |
1216 | |
1217 echo | |
184 | 1218 "MGTool ".$mgProgVersion." - MGallery management tool\n". |
1219 $mgProgInfo." ".$mgProgEmail."\n". | |
1220 "(C) Copyright ".$mgProgCopyright."\n"; | |
0 | 1221 } |
1222 | |
1223 | |
1224 function mgShowHelp() | |
1225 { | |
1226 global $argv; | |
1227 echo | |
1228 "Usage: ".basename($argv[0])." <command> [arguments]\n". | |
1229 "\n". | |
1230 " --help - Show this help.\n". | |
1231 " --version - Show version information.\n". | |
1232 "\n". | |
1233 " update [path]\n". | |
1234 " Update directories under <path> or all gallery dirs.\n". | |
1235 " Conditionally scans dirs for new or changed images and\n". | |
1236 " updates cache files as needed.\n". | |
1237 "\n". | |
1238 " rescan [path]\n". | |
1239 " Like 'update', but forces all cache files to be regenerated\n". | |
1240 " and EXIF/caption/etc information to be re-scanned even\n". | |
1241 " if the file timestamps do not justify re-scanning.\n". | |
1242 "\n". | |
256
6ad17bc3d1a6
Add 'trash' option to 'clean' command to clean up any unmanaged files
Matti Hamalainen <ccr@tnsp.org>
parents:
255
diff
changeset
|
1243 " 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
|
1244 " 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
|
1245 " 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
|
1246 " 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
|
1247 " trash - Delete any 'unmanaged' files inside thumbnail/medium dirs\n". |
0 | 1248 "\n". |
281 | 1249 " 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
|
1250 " 'trash' options. Unless you know what you are doing, that is.\n". |
281 | 1251 "\n". |
159
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
1252 " config|dump\n". |
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
1253 " Display configuration values (with extra information) or\n". |
b010c763a1fc
Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents:
130
diff
changeset
|
1254 " \"dump\" current configuration as is.\n". |
0 | 1255 "\n"; |
1256 } | |
1257 | |
1258 | |
1259 // | |
1260 // Main code starts | |
1261 // | |
1262 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) | |
1263 { | |
1264 header("Status: 404 Not Found"); | |
1265 die(); | |
1266 } | |
1267 | |
1268 pcntl_signal(SIGTERM, "mgSigHandler"); | |
1269 pcntl_signal(SIGHUP, "mgSigHandler"); | |
1270 pcntl_signal(SIGQUIT, "mgSigHandler"); | |
1271 pcntl_signal(SIGINT, "mgSigHandler"); | |
1272 | |
265 | 1273 // Check for improperly configured PHP |
264
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1274 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
|
1275 { |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1276 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
|
1277 exit(1); |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1278 } |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1279 else |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1280 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
|
1281 { |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1282 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
|
1283 exit(1); |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1284 } |
745af791367d
Move Imagick/Gmagick module check to script startup.
Matti Hamalainen <ccr@tnsp.org>
parents:
262
diff
changeset
|
1285 |
265 | 1286 // Check settings |
297
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1287 if (mgReadSettings($searchPaths) === FALSE) |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1288 { |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1289 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
|
1290 "Attempted search paths:\n".implode("\n", $searchPaths)."\n"); |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
1291 } |
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
|
1292 |
265 | 1293 // 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
|
1294 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
|
1295 date_default_timezone_set($pageTimeZone); |
0 | 1296 |
290
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1297 // Check backend |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1298 if (($galBackend = mgGetSetting("backend")) === null) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1299 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
|
1300 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1301 switch ($galBackend = strtolower($galBackend)) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1302 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1303 case "sql": |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1304 // Connect to database |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1305 if (mgConnectSQLDB() === FALSE) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1306 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
|
1307 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1308 // 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
|
1309 $tmpSQL = []; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1310 foreach ($galExifConversions as $econv) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1311 if ($econv[GEC_IS_UNIQUE]) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1312 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1313 switch ($econv[GEC_TYPE]) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1314 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1320 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1321 $tmpSQL[$econv[GEC_NAME]] = $etype; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1322 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1323 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1324 // 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
|
1325 foreach ($tmpSQL as $ekey => $etype) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1326 $galSQLTables["images"][] = [$ekey, $etype]; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1327 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1328 // Check tables |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1329 foreach ($galSQLTables as $name => $schemaData) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1330 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1331 $schema = mgDBGetTableSchema($db, $schemaData); |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1332 if (!mgDBCreateOneTable($db, $name, $schema)) |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1333 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
|
1334 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1335 break; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1336 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1337 case "php": |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1338 break; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1339 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1340 default: |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1341 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
|
1342 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1343 |
265 | 1344 |
1345 // Check for commandline arguments | |
0 | 1346 $cmd = mgCArgLC(1); |
1347 switch ($cmd) | |
1348 { | |
1349 case "--version": | |
1350 case "version": | |
1351 case "ver": | |
1352 mgShowCopyright(); | |
1353 break; | |
1354 | |
1355 case FALSE: | |
1356 // No arguments | |
1357 mgError("Nothing to do. Showing help:\n"); | |
1358 | |
1359 case "--help": | |
1360 case "help": | |
1361 if ($cmd !== FALSE) | |
1362 mgShowCopyright(); | |
1363 mgShowHelp(); | |
1364 break; | |
1365 | |
1366 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
|
1367 $farg = mgCArg(2); |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1368 if ($farg == "--sql") |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1369 { |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1370 $farg = FALSE; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1371 $flagSQL = TRUE; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1372 } |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1373 else |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1374 $flagSQL = mgCArg(3) == "--sql"; |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1375 |
19fbf800b1f7
Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents:
286
diff
changeset
|
1376 mgProcessGalleries(GCMD_UPDATE, $farg); |
0 | 1377 break; |
1378 | |
1379 case "rescan": case "re": case "res": | |
1380 mgProcessGalleries(GCMD_RESCAN, mgCArg(2)); | |
1381 break; | |
1382 | |
1383 case "clean": case "cl": case "cle": | |
1384 $cmode = mgCArgLC(2, 2); | |
1385 switch ($cmode) | |
1386 { | |
1387 case "al": $galCleanFlags = GCLEAN_ALL; break; | |
1388 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
|
1389 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
|
1390 case "tr": $galCleanFlags = GCLEAN_TRASH; break; |
0 | 1391 case FALSE: |
1392 mgFatal("Cleaning requires a mode argument.\n"); | |
1393 | |
1394 default: | |
1395 mgFatal("Invalid clean mode '".mgCArg(2)."'.\n"); | |
1396 } | |
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
|
1397 $countDoDelete = 0; |
0 | 1398 $flagDoDelete = FALSE; |
1399 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); | |
1400 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
|
1401 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
|
1402 { |
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
|
1403 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
|
1404 } |
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
|
1405 else |
0 | 1406 if (mgYesNoPrompt("Really delete the above files and directories?")) |
1407 { | |
25
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1408 echo "Deleting ...\n"; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1409 $flagDoDelete = TRUE; |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1410 mgProcessGalleries(GCMD_CLEAN, mgCArg(3)); |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1411 } |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1412 else |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1413 { |
c698618e6f67
Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents:
16
diff
changeset
|
1414 echo "Okay, canceling operation.\n"; |
0 | 1415 } |
1416 break; | |
1417 | |
1418 case "config": | |
1419 case "dump": | |
1420 | |
1421 foreach ($mgDefaults as $key => $dval) | |
1422 { | |
1423 $sval = mgGetSetting($key); | |
26 | 1424 if ($cmd == "dump") |
1425 { | |
189 | 1426 printf("%-20s = %s\n", |
1427 $key, | |
1428 mgGetDValStr($dval, $sval)); | |
26 | 1429 } |
1430 else | |
1431 { | |
1432 printf("%-20s = %s%s\n", | |
1433 $key, | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
1434 mgGetDValStr($dval, $sval), |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
1435 ($dval[1] !== NULL && $sval !== $dval[1]) ? " (default: ".mgGetDValStr($dval, $dval[1]).")" : ""); |
26 | 1436 } |
0 | 1437 } |
1438 break; | |
1439 | |
1440 default: | |
1441 mgError("Unknown option/command '".$cmd."'.\n"); | |
1442 break; | |
1443 } | |
1444 | |
1445 ?> |