annotate mgtool.php @ 277:4080b9bde2ac

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