annotate mgtool.php @ 319:bf4115b6dc2a

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