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