annotate mgtool.php @ 250:3af3b3f50cb0

Add settings for med_format and tn_format (currently allowed values are "jpeg" and "webp") to specify the med/tn image formats. The default is JPEG.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 08 Dec 2018 15:51:02 +0200
parents abcd21b01829
children 19dab8b0c340
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>
161
458c2d6637b1 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
7 // (C) Copyright 2015-2018 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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 define("GCMD_UPDATE" , 1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 define("GCMD_RESCAN" , 2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 define("GCMD_CLEAN" , 3);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 define("GCLEAN_CACHES" , 0x01);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 define("GCLEAN_THUMBNAILS", 0x02);
188
a5ce6144fbf5 Add an option to clean medium images separately from thumbnails.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
38 define("GCLEAN_MEDIUMS" , 0x04);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 define("GCLEAN_ALL" , 0x0f);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 define("GUPD_MED_IMAGE" , 0x01);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 define("GUPD_TN_IMAGE" , 0x02);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 define("GUPD_IMAGES" , 0x0f);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 define("GUPD_EXIF_INFO" , 0x10);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 define("GUPD_CAPTION" , 0x20);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 // Convert and scale image file function, for generating
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 // the intermediate size images and thumbnails. Uses the
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 // PHP ImageMagick bindings.
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 function mgConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 // Create conversion entity
53
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
56 try
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
57 {
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
58 $img = new Imagick($inFilename);
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
59 }
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
60 catch (Exception $e)
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
61 {
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
62 return mgError("ImageMagick exception for file '".$inFilename."':\n".$e->getMessage()."\n");
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
63 }
4c0a08b0ef65 Handle ImageMagick exceptions for loading input images.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
64
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 if ($img === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 return mgError("ImageMagick could not digest the file '".$inFilename."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
51
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
68 $profiles = $img->getImageProfiles("icc", true);
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
69 $img->setImageDepth(16);
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
70 $img->transformImageColorspace(Imagick::COLORSPACE_SRGB);
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
71 $img->setImageColorspace(Imagick::COLORSPACE_SRGB);
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
72
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 if ($outDim !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 // Get dimensions, setup background
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 $dim = $img->getImageGeometry();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 //$img->setImageBackgroundColor(imagick::COLOR_BLACK);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 $img->setGravity(imagick::GRAVITY_CENTER);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 if ($dim["width"] < $dim["height"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 $stmp = $outDim[0];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 $outDim[0] = $outDim[1];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 $outDim[1] = $stmp;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 if ($dim["width"] != $outDim[0] || $dim["height"] != $outDim[1])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 $outDim[1] = ($dim["height"] * $outDim[0]) / $dim["width"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 // Act based on image size vs. desired size and $thumb mode
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 // Image is larger
1
a07447c02b13 Use Lanczos filter for scaling instead of quadratic. Better quality and
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
97 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 $img->setImageExtent($outDim[0], $outDim[1]);
51
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
99 // $img->normalizeImage();
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 $img->unsharpMaskImage(0, 0.5, 1, 0.05);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 // Image is smaller than requested dimension(s)?
1
a07447c02b13 Use Lanczos filter for scaling instead of quadratic. Better quality and
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
105 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 $img->setImageExtent($outDim[0], $outDim[1]);
51
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
107 // $img->normalizeImage();
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 $img->unsharpMaskImage(0, 0.5, 1, 0.05);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
250
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
112 $img->setImageDepth(8);
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
113 switch (strtolower($outFormat))
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
114 {
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
115 case "jpeg":
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
116 $img->setFormat("JPEG");
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
117 $img->setImageCompression(Imagick::COMPRESSION_JPEG);
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
118 break;
51
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
119
250
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
120 case "webp":
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
121 $img->setFormat("webp");
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
122 $img->setOption('webp:method', '6');
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
123 break;
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
124
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
125 default:
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
126 return mgError("Unsupported MGallery med/tn format '".$tfmt."'.\n");
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
127 }
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
128
55
b1fa4fd593d1 Fix thumbnail/medium image JPEG quality handling to actually work. :S
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
129 $img->setImageCompressionQuality($outQuality);
80
121613e40d87 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
130
51
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
131 $img->stripImage();
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
132 if (!empty($profiles))
549541f3e9c0 Possibly improve medium and thumbnail image generation by controlling Imagick components better.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
133 $img->profileImage("icc", $profiles["icc"]);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 $img->writeImage($outFilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 $img->removeImage();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 return TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 // Converts one value (mainly from EXIF tag information)
52
5fbc443be538 Typofix.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
143 // by doing explicit type casting and special conversions.
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 function mgConvertExifData($val, $vtype)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 switch ($vtype)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 {
46
e58292065b01 Let arrays through mgConvertExifData() when the type is MG_STR without
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
149 case MG_STR: return is_array($val) ? $val : (string) $val;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 case MG_INT: return intval($val);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 case MG_BOOL: return intval($val);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 case MG_DVA:
223
438277861f51 Implement better interpretation of DVA values (exposure times, for example),
Matti Hamalainen <ccr@tnsp.org>
parents: 189
diff changeset
153 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
154 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 if ($v1 < $v2)
249
abcd21b01829 Use floating point formatting for certain DVA values.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
156 return sprintf("1/%1.1f", $v2 / $v1);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 return sprintf("%1.1f", $v1 / $v2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
124
eac2cf04261a Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
163 case MG_DATE:
eac2cf04261a Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
164 return date_timestamp_get(date_create_from_format("Y:m:d H:i:s", $val));
eac2cf04261a Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
165
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 // Conditionally copies one "field" from an associated array/hash to another.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 // 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
175 // 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
176 // a default value will be used, if provided.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 // Source may have multi-depth keys, destination has one key.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 function mgCopyEntryData(&$dst, $src, $vtype, $dkey, $skeys, $default = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 // Is destination already set?
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 if (isset($dst[$dkey]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 // If input key is not array, change it into one
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 if (!is_array($skeys))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 $skeys = array($skeys);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 // Traverse input array by using consequent keys
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 $tmp = &$src;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 foreach ($skeys as $skey)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 if (!array_key_exists($skey, $tmp))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 // Key didn't exist, try for default
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 if ($default !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 $dst[$dkey] = $default;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 $tmp = &$tmp[$skey];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 // Optionally convert the input value
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 $dst[$dkey] = mgConvertExifData($tmp, $vtype);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 return TRUE;
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
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 // Attempt to get gallery album data from various sources.
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 function mgGetAlbumData($galBasePath, $galPath)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 // Check path permissions
60
ef9f17280372 Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
216 $galData = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 if (is_readable($galPath))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 // First, try to read gallery/album info file
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 $filename = mgGetPath($galPath, "info_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 if ($filename !== FALSE && file_exists($filename))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 mgDebug("Reading INFOFILE: ".$filename."\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 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
225 $galData = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 // 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
229 $filename = mgGetPath($galPath, "header_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 if ($filename !== FALSE && file_exists($filename) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 !isset($galData["header"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 mgDebug("Reading HEADERFILE: ".$filename."\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 $galData["header"] = file_get_contents($filename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 // Check for alternate key/values for album title/caption
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 if (isset($galData["title"]) && !isset($galData["caption"]))
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 $galData["caption"] = $galData["title"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 unset($galData["title"]);
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 $galData["hide"] = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 // If caption is not set, use last path component for
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 // a fallback value in case we don't discover proper title
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 // from other sources we can't check here yet.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 $path = explode("/", $galPath);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 $galData["fallback_caption"] = ucfirst(str_replace("_", " ", end($path)));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 // Last, store the current gallery path
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 $len = strlen($galBasePath);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 if ($len < strlen($galPath) && substr($galPath, 0, $len) == $galBasePath)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 $galData["path"] = substr($galPath, $len);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 $galData["path"] = "";
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 return $galData;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
264 //
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
265 // 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
266 // Lines starting with "# " are comments (note the whitespace), empty lines ignored.
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
267 // First continuous non-whitespace text is file/dirname, followed
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
268 // by caption text, which is separate with whitespace from the filename.
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
269 // Filenames starting with # will be made hidden entries.
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
270 // Filenames starging with % will hide contents.
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
271 //
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 function mgReadCaptionsFile($galBasePath, $galPath)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 {
60
ef9f17280372 Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
274 $captions = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 $filename = mgGetPath($galPath, "captions_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 if ($filename === FALSE || ($fp = @fopen($filename, "rb")) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 return $captions;
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 mgDebug("Reading CAPTIONS: ".$filename."\n");
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 // Read and parse data
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 while (!feof($fp))
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 $str = trim(fgets($fp));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 // Ignore comments and empty lines
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 if ($str != "#" && $str != "")
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 {
11
0b097770061d Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
288 if (preg_match("/^([#%]?)\s*(\S+?)\s+(.+)$/", $str, $m))
45
d555734526d6 Use newer PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
289 $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
290 else
11
0b097770061d Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
291 if (preg_match("/^([#%]?)\s*(\S+?)$/", $str, $m))
45
d555734526d6 Use newer PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
292 $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
293 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 fclose($fp);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 return $captions;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
301 //
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
302 // Create directory with specified permissions
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
303 //
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 function mgMakeDir($path, $perm)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 if (!file_exists($path))
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 if (mkdir($path, $perm, TRUE) === false)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 return mgError("Could not create directory '".$path."'\n");
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 return TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 }
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
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
315 //
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
316 // Print a simple yes/no prompt with given message
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
317 // and default value.
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
318 //
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 function mgYesNoPrompt($msg, $default = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 echo $msg." [".($default ? "Y/n" : "y/N")."]? ";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 $sprompt = strtolower(trim(fgets(STDIN)));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
166
d8387b48b08d Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
324 if ($sprompt == "")
d8387b48b08d Improve yes/no prompt check.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
325 return $default;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 else
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
327 return $sprompt[0] == 'y';
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
331 //
182
c0439644da6a Clarify a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
332 // Delete given directory OR file, recursively
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
333 //
183
74889db8e6a2 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 182
diff changeset
334 function mgDelete($path, $showFiles)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 {
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
336 global $flagDoDelete, $countDoDelete;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 if (is_dir($path))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 if (($dirHandle = @opendir($path)) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 return mgError("Could not read directory '".$path."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 while (($dirFile = @readdir($dirHandle)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 if ($dirFile != "." && $dirFile != "..")
183
74889db8e6a2 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 182
diff changeset
345 mgDelete($path."/".$dirFile, $showFiles);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 }
183
74889db8e6a2 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 182
diff changeset
347
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 closedir($dirHandle);
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 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
351 $countDoDelete++;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 if ($flagDoDelete)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 rmdir($path);
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 else
54
624c50e1b52d Fix 'mgtool clean' to not attempt deleting files that do not exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
356 if (file_exists($path))
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 {
183
74889db8e6a2 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 182
diff changeset
358 if ($showFiles)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 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
360
62
3f60a5f5b4b3 Actually fix checking for files to be deleted to work.
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
361 $countDoDelete++;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 if ($flagDoDelete)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 unlink($path);
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
165
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
368 //
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
369 // Check if we have received the quit signal
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
370 // and if yes, quit cleanly now.
da70f1c05ebe Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
371 //
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 function mgCheckQuit($now = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 global $flagQuit;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 // Dispatch pending signals
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 pcntl_signal_dispatch();
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 // Check result
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 if ($now && $flagQuit)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 mgFatal("Quitting.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 return $flagQuit;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 function mgNeedUpdate($entry, $field, $cvalue)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 if (!array_key_exists($field, $entry))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 return TRUE;
80
121613e40d87 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
391
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 return ($entry[$field] < $cvalue);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395
30
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
396 function mgSortFunc($a, $b)
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
397 {
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
398 if (isset($a["datetime"]) && isset($b["datetime"]))
124
eac2cf04261a Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
399 return $b["datetime"] - $a["datetime"];
30
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
400 else
108
417cdd9f8864 Use image file base name for sorting if timestamps are not available.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
401 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
402 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
403 else
30
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
404 return 0;
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
405 }
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
406
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
407
16
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
408 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
409 {
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
410 // 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
411 $images = [];
ef9f17280372 Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
412 $albums = [];
61
ee82f7c8d44c Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
413 $output = [];
60
ef9f17280372 Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
414
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
415 // 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
416 if (!$parentEntry["hide_contents"])
15
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
417 {
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
418 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
419 {
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
420 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
421 continue;
15
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
422
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
423 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
424 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
425 $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
426 else
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
427 $albums[$ename] = &$edata;
61
ee82f7c8d44c Do not include hidden entries in the entry list.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
428
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
429 $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
430 }
30
f2c21a8b9071 Sort images in a folder by their capture timestamp.
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
431
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
432 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
433 krsort($albums);
15
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
434
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
435 // 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
436 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
437 {
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
438 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
439 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
440 {
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
441 $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
442 }
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
443 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
444 {
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
445 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
446 $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
447 }
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
448 }
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
449 else
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
450 {
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
451 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
452 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
453 {
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
454 $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
455 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
456 }
64
9a01e14b27ef Implement hide_contents setting for galleries, which hides contents of an album.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
457 }
35
985596db0f01 Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
458 }
16
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
459
15
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
460 $str =
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
461 "<?\n".
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
462 "\$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
463 "\$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
464 "\$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
465 "\$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
466 "?>";
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
467
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
468 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
469 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
470
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
471 return TRUE;
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
472 }
805f93962cf9 Factorize gallery cache file writing to a separate function.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
473
16
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
474
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
475 function mgHandleDirectory($mode, $basepath, $path, &$parentData, &$parentEntry, $writeMode, $startAt)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 {
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
477 global $galExifConversions, $galTNPath, $galMedPath, $galCleanFlags;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 // Get cache file path
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 return mgError("Cache filename / path not set.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 mgCheckQuit(TRUE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 // Read directory contents
60
ef9f17280372 Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
486 $entries = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 if (($dirHandle = @opendir($path)) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 return mgError("Could not read directory '".$path."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 while (($dirFile = @readdir($dirHandle)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 $realFile = $path."/".$dirFile;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 if (is_dir($realFile))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 {
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
495 if ($dirFile[0] != "." && $dirFile != $galTNPath && $dirFile != $galMedPath)
63
1c32ece9acde Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
496 $entries[$dirFile] = ["type" => 1, "base" => $dirFile, "ext" => "", "mtime" => filemtime($realFile)];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 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
499 if (preg_match("/^([^\/]+)(".mgGetSetting("format_exts").")$/i", $dirFile, $dirMatch))
63
1c32ece9acde Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
500 $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
501 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 closedir($dirHandle);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 mgCheckQuit();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 // Cleanup mode
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 if ($mode == GCMD_CLEAN)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 {
60
ef9f17280372 Use modern PHP array definition in some places.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
509 $gallery = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 if ($writeMode)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 if ($galCleanFlags & GCLEAN_CACHES)
183
74889db8e6a2 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 182
diff changeset
514 mgDelete($cacheFilename, TRUE);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 if ($galCleanFlags & GCLEAN_THUMBNAILS)
183
74889db8e6a2 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 182
diff changeset
517 mgDelete($path."/".$galTNPath, FALSE);
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
518
188
a5ce6144fbf5 Add an option to clean medium images separately from thumbnails.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
519 if ($galCleanFlags & GCLEAN_MEDIUMS)
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
520 mgDelete($path."/".$galMedPath, FALSE);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 // Update modes
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 // 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
528 $galEntries = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 $cacheTime = -1;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 if ($mode == GCMD_UPDATE && file_exists($cacheFilename))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 $cacheTime = filemtime($cacheFilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 @include $cacheFilename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 // Read caption data
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 $captions = mgReadCaptionsFile($basepath, $path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 $gallery = mgGetAlbumData($basepath, $path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 if ($parentData !== NULL && $parentEntry !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 {
16
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
541 $gallery["parent"] = &$parentData;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 // Start actual processing
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 $nentries = count($entries);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 $nentry = 0;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 echo $path." .. ";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 foreach ($entries as $ename => &$edata)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 printf("\r%s (%1.1f%%) ..", $path, ($nentry * 100.0) / $nentries);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 $nentry++;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 $efilename = $path."/".$ename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 if (array_key_exists($ename, $galEntries))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557 $galEntry = &$galEntries[$ename];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 else
63
1c32ece9acde Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
559 $galEntry = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560
57
29bb365e3ee2 Be more responsive when processing images, check for signals after each
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
561 mgCheckQuit(TRUE);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 // Update with captions file data, if any
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 if (array_key_exists($ename, $captions))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 foreach ($captions[$ename] as $ckey => $cval)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 $edata[$ckey] = $cval;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 // Handle entry based on type
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 if ($edata["type"] == 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 $updFlags = 0;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 $tnPath = $path."/".$galTNPath;
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
575 $medPath = $path."/".$galMedPath;
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
576 $medFilename = $medPath."/".$ename;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 $tnFilename = $tnPath."/".$ename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 $capFilename = $path."/".$edata["base"].".txt";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 // Check what we need to update ..
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 $updFlags |= GUPD_MED_IMAGE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 if (!file_exists($tnFilename) || filemtime($tnFilename) < $edata["mtime"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 $updFlags |= GUPD_TN_IMAGE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 if (mgNeedUpdate($galEntry, "mtime", $edata["mtime"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 $updFlags |= GUPD_EXIF_INFO;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 if (file_exists($capFilename) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 mgNeedUpdate($galEntry, "mtime", filemtime($capFilename)))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 $updFlags |= GUPD_CAPTION;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 // Check for EXIF info
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 if (($updFlags & GUPD_EXIF_INFO) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 ($exif = @exif_read_data($efilename)) !== FALSE)
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 echo "%";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 foreach ($galExifConversions as $conv)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 mgCopyEntryData($edata, $exif, $conv[0], $conv[1], $conv[2]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 // Copy old data that is not yet in new
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 echo "*";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 foreach ($galEntry as $okey => $odata)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 if (!array_key_exists($okey, $edata))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 $edata[$okey] = $odata;
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 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 // Generate thumbnails, etc.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 if ($updFlags & GUPD_IMAGES)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 mgMakeDir($tnPath, 0755);
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
617 mgMakeDir($medPath, 0755);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 if ($updFlags & GUPD_MED_IMAGE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 echo "1";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 mgConvertImage($efilename, $medFilename,
63
1c32ece9acde Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
623 [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
624 mgGetSetting("med_format"), mgGetSetting("med_quality"), TRUE);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 if ($updFlags & GUPD_TN_IMAGE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 echo "2";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 mgConvertImage($efilename, $tnFilename,
63
1c32ece9acde Some residual array() => [] conversions.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
631 [mgGetSetting("tn_width"), mgGetSetting("tn_height")],
250
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 249
diff changeset
632 mgGetSetting("tn_quality"), TRUE);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 // Check for .txt caption file
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 if ($updFlags & GUPD_CAPTION)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 echo "?";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640 if (($tmpData = @file_get_contents($capFilename)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 $edata["caption"] = $tmpData;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 if ($edata["type"] == 1)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 {
10
d63d2f0307b0 Added a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
647 // Set some of the album data here
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 $tmp = mgGetAlbumData($basepath, $efilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "caption");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "fallback_caption");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE);
11
0b097770061d Improve content hiding functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
653 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide_contents", "hide_contents", FALSE);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 }
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 echo "\r".$path." ..... DONE\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 mgCheckQuit(TRUE);
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 mgFatal("Invalid work mode '".$mode."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 mgCheckQuit(TRUE);
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 // 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
667 foreach ($entries as $ename => &$edata)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 if ($edata["type"] == 1)
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 $epath = $path."/".$ename."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676
16
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
677 // Finish update modes
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
678 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
679 {
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
680 // Store gallery cache for this directory
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
681 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
682 return FALSE;
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
683 }
3491ab93630e Add sub-gallery thumbnails to gallery cache data.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
684
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 mgCheckQuit(TRUE);
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 return TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 function mgSigHandler($signo)
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 global $flagQuit;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 switch ($signo)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 case SIGTERM:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 mgFatal("Received SIGTERM.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698 break;
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 case SIGQUIT:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 case SIGINT:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 $flagQuit = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
709 function mgCheckMPath($path, $id)
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
710 {
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
711 if ($path."/" != mgGetSetting($id))
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
712 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
713
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
714 if (strpos($path, "/") !== FALSE || $path == "")
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
715 mgFatal("Invalid ".$id." '".$path."'.\n");
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
716 }
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
717
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
718
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719 function mgProcessGalleries($cmd, $path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 {
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
721 global $galTNPath, $galMedPath;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723 // Check validity of some settings
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 $galPath = mgGetSetting("base_path");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path"));
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
726 $galMedPath = mgCleanPath(TRUE, mgGetSetting("med_path"));
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
728 mgCheckMPath($galTNPath, "tn_path");
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
729 mgCheckMPath($galMedPath, "med_path");
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 $parentData = $parentEntry = NULL;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 $writeMode = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 $startAt = NULL;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 // Check for path argument
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 if ($path !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 // Check the given path, needs to be "under" the gallery path
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 $cmp = mgCleanPath(TRUE, mgRealPath($galPath))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 $tmp = mgCleanPath(TRUE, mgRealPath($path))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 if (substr($tmp, 0, strlen($cmp)) != $cmp)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 mgFatal("Path '".$path."' ('".$tmp."') does not reside under '".$galPath."' ('".$cmp."')!\n");
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 // Check if we need to bootstrap
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 if ($cmp != $tmp)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 $bpath = mgCleanPath(TRUE, mgRealPath($tmp."../"));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 if ($cmd != GCMD_CLEAN)
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 $cacheFile = mgGetPath($bpath, "cache_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 if (!file_exists($cacheFile))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 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
754
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 @include($cacheFile);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 if (!isset($galEntries) || !isset($galData))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 mgFatal("Cache file '".$cacheFile."' is broken or stale.\n");
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 $writeMode = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 $startAt = $tmp;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 $path = $bpath;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 echo "Starting: '".$startAt."' inside '".$path."'.\n";
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 $path = $tmp;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 $path = $galPath;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 // Start working
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 echo "Gallery path: '".$galPath."', starting at '".$path."' ...\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 mgHandleDirectory($cmd, $galPath, $path, $parentData, $parentEntry, $writeMode, $startAt);
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 function mgShowCopyright()
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 global $mgProgVersion, $mgProgCopyright,
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 $mgProgInfo, $mgProgEmail;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 echo
184
087df916b6b4 Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 183
diff changeset
784 "MGTool ".$mgProgVersion." - MGallery management tool\n".
087df916b6b4 Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 183
diff changeset
785 $mgProgInfo." ".$mgProgEmail."\n".
087df916b6b4 Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 183
diff changeset
786 "(C) Copyright ".$mgProgCopyright."\n";
0
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 function mgShowHelp()
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 global $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 echo
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 "Usage: ".basename($argv[0])." <command> [arguments]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 " --help - Show this help.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 " --version - Show version information.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 " update [path]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 " Update directories under <path> or all gallery dirs.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 " Conditionally scans dirs for new or changed images and\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 " updates cache files as needed.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
803 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804 " rescan [path]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 " Like 'update', but forces all cache files to be regenerated\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 " and EXIF/caption/etc information to be re-scanned even\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 " if the file timestamps do not justify re-scanning.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 "\n".
188
a5ce6144fbf5 Add an option to clean medium images separately from thumbnails.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
809 " clean <all|caches|thumbnails|mediums|generated> [path]\n".
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 " Delete all generated files or selectively cache files or\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 " everything inside thumbnail directories.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 "\n".
159
b010c763a1fc Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
813 " config|dump\n".
b010c763a1fc Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
814 " Display configuration values (with extra information) or\n".
b010c763a1fc Document mgtool 'dump' command.
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
815 " \"dump\" current configuration as is.\n".
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 "\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817 }
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
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 // Main code starts
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 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
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 header("Status: 404 Not Found");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826 die();
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 pcntl_signal(SIGTERM, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 pcntl_signal(SIGHUP, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 pcntl_signal(SIGQUIT, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832 pcntl_signal(SIGINT, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833
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
834 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
835 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
836
f825d644cf7a Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
837 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
838 date_default_timezone_set($pageTimeZone);
0
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 $cmd = mgCArgLC(1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841 switch ($cmd)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843 case "--version":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 case "version":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 case "ver":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
846 mgShowCopyright();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
847 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 case FALSE:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850 // No arguments
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851 mgError("Nothing to do. Showing help:\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 case "--help":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 case "help":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 if ($cmd !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 mgShowCopyright();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 mgShowHelp();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860 case "update": case "up": case "upd": case "upda":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 mgProcessGalleries(GCMD_UPDATE, mgCArg(2));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 case "rescan": case "re": case "res":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 mgProcessGalleries(GCMD_RESCAN, mgCArg(2));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
866 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
868 case "clean": case "cl": case "cle":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
869 $cmode = mgCArgLC(2, 2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 switch ($cmode)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
872 case "al": $galCleanFlags = GCLEAN_ALL; break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
873 case "ca": $galCleanFlags = GCLEAN_CACHES; break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
874 case "th": $galCleanFlags = GCLEAN_THUMBNAILS; break;
188
a5ce6144fbf5 Add an option to clean medium images separately from thumbnails.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
875 case "me": $galCleanFlags = GCLEAN_MEDIUMS; break;
a5ce6144fbf5 Add an option to clean medium images separately from thumbnails.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
876 case "ge": $galCleanFlags = GCLEAN_THUMBNAILS | GCLEAN_MEDIUMS; break;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 case FALSE:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
878 mgFatal("Cleaning requires a mode argument.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
879
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
880 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
881 mgFatal("Invalid clean mode '".mgCArg(2)."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882 }
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
883 $countDoDelete = 0;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
884 $flagDoDelete = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
885 mgProcessGalleries(GCMD_CLEAN, mgCArg(3));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886 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
887 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
888 {
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
889 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
890 }
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
891 else
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
892 if (mgYesNoPrompt("Really delete the above files and directories?"))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
893 {
25
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
894 echo "Deleting ...\n";
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
895 $flagDoDelete = TRUE;
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
896 mgProcessGalleries(GCMD_CLEAN, mgCArg(3));
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
897 }
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
898 else
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
899 {
c698618e6f67 Actually implement deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
900 echo "Okay, canceling operation.\n";
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
902 break;
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 case "config":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
905 case "dump":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
906
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
907 foreach ($mgDefaults as $key => $dval)
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 $sval = mgGetSetting($key);
26
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
910 if ($cmd == "dump")
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
911 {
189
5e7319ccb7cf Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
912 printf("%-20s = %s\n",
5e7319ccb7cf Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
913 $key,
5e7319ccb7cf Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
914 mgGetDValStr($dval, $sval));
26
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
915 }
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
916 else
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
917 {
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
918 printf("%-20s = %s%s\n",
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
919 $key,
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
920 mgGetDValStr($dval, $sval),
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
921 ($dval[1] !== NULL && $sval !== $dval[1]) ? " (default: ".mgGetDValStr($dval, $dval[1]).")" : "");
26
59cf3acc4440 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
922 }
0
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 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
925
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
926 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
927 mgError("Unknown option/command '".$cmd."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 ?>