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