annotate mgtool.php @ 311:8fd5c850f921

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