annotate mgtool.php @ 284:403f2e1e5e79

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