annotate mgtool.php @ 0:ac688606ec4b

Initial import of code.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 13 May 2015 07:27:40 +0300
parents
children a07447c02b13
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 // Commandline tool for creating / updating gallery
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 // (C) Copyright 2015 Tecnic Software productions (TNSP)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 require_once "mgallery.inc.php";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
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 // Array for specifying what will be copied and converted
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 // from the image file's EXIF information tag(s).
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 $galExifConversions = array(
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 array(MG_STR, "caption" , "ImageDescription"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 array(MG_STR, "copyright" , "Copyright"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 array(MG_STR, "model" , "Model"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 array(MG_INT, "width" , array("COMPUTED", "Width")),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 array(MG_INT, "height" , array("COMPUTED", "Height")),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 array(MG_DVA, "fnumber" , "FNumber"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 array(MG_DVA, "exposure" , "ExposureTime"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 array(MG_INT, "iso" , "ISOSpeedRatings"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 array(MG_DVA, "focallength" , "FocalLength"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 array(MG_STR, "datetime" , "DateTimeOriginal"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 array(MG_STR, "datetime" , "DateTimeDigitized"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 array(MG_INT, "filesize" , "FileSize"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 );
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 define("GCMD_UPDATE" , 1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 define("GCMD_RESCAN" , 2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 define("GCMD_CLEAN" , 3);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 define("GCLEAN_CACHES" , 0x01);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 define("GCLEAN_THUMBNAILS", 0x02);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 define("GCLEAN_ALL" , 0x0f);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 define("GUPD_MED_IMAGE" , 0x01);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 define("GUPD_TN_IMAGE" , 0x02);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 define("GUPD_IMAGES" , 0x0f);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 define("GUPD_EXIF_INFO" , 0x10);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 define("GUPD_CAPTION" , 0x20);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 // Convert and scale image file function, for generating
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 // the intermediate size images and thumbnails. Uses the
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 // PHP ImageMagick bindings.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 function mgConvertImage($inFilename, $outFilename, $outDim, $outFormat, $outQuality, $thumb)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 // Create conversion entity
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 $img = new Imagick($inFilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 if ($img === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 return mgError("ImageMagick could not digest the file '".$inFilename."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 if ($outDim !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 // Get dimensions, setup background
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 $dim = $img->getImageGeometry();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 //$img->setImageBackgroundColor(imagick::COLOR_BLACK);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 $img->setGravity(imagick::GRAVITY_CENTER);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 if ($dim["width"] < $dim["height"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 $stmp = $outDim[0];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 $outDim[0] = $outDim[1];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 $outDim[1] = $stmp;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 if ($dim["width"] != $outDim[0] || $dim["height"] != $outDim[1])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 $outDim[1] = ($dim["height"] * $outDim[0]) / $dim["width"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 // Act based on image size vs. desired size and $thumb mode
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 if ($thumb || $dim["width"] > $outDim[0] || $dim["height"] > $outDim[1])
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 // Image is larger
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 $img->setImageExtent($outDim[0], $outDim[1]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 $img->normalizeImage();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 $img->unsharpMaskImage(0, 0.5, 1, 0.05);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1])
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 // Image is smaller than requested dimension(s)?
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_QUADRATIC, 1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 $img->setImageExtent($outDim[0], $outDim[1]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 $img->unsharpMaskImage(0, 0.5, 1, 0.05);
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 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 $img->setFormat($outFormat);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 $img->setCompressionQuality($outQuality);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 $img->stripImage();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 $img->writeImage($outFilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 $img->removeImage();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 return TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 // Converts one value (mainly from EXIF tag information)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 // by doing explicing type casting and special conversions.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 function mgConvertExifData($val, $vtype)
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 switch ($vtype)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 case MG_STR: return (string) $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 case MG_INT: return intval($val);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 case MG_BOOL: return intval($val);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 case MG_DVA:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 if (sscanf($val, "%d/%d", $v1, $v2) == 2)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 if ($v1 < $v2)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 return sprintf("%1.1f", $v1 / $v2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 // Conditionally copies one "field" from an associated array/hash to another.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 // 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
136 // 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
137 // a default value will be used, if provided.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 // Source may have multi-depth keys, destination has one key.
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 function mgCopyEntryData(&$dst, $src, $vtype, $dkey, $skeys, $default = NULL)
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 // Is destination already set?
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 if (isset($dst[$dkey]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 // If input key is not array, change it into one
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 if (!is_array($skeys))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 $skeys = array($skeys);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 // Traverse input array by using consequent keys
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 $tmp = &$src;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 foreach ($skeys as $skey)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 if (!array_key_exists($skey, $tmp))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 // Key didn't exist, try for default
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 if ($default !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 $dst[$dkey] = $default;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 $tmp = &$tmp[$skey];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 // Optionally convert the input value
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 $dst[$dkey] = mgConvertExifData($tmp, $vtype);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 return TRUE;
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 // Attempt to get gallery album data from various sources.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 function mgGetAlbumData($galBasePath, $galPath)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 // Check path permissions
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 $galData = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 if (is_readable($galPath))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 // First, try to read gallery/album info file
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 $filename = mgGetPath($galPath, "info_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 if ($filename !== FALSE && file_exists($filename))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 mgDebug("Reading INFOFILE: ".$filename."\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 if (($galData = parse_ini_file($filename, FALSE)) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 $galData = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 }
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 // 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
190 $filename = mgGetPath($galPath, "header_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 if ($filename !== FALSE && file_exists($filename) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 !isset($galData["header"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 mgDebug("Reading HEADERFILE: ".$filename."\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 $galData["header"] = file_get_contents($filename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 // Check for alternate key/values for album title/caption
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 if (isset($galData["title"]) && !isset($galData["caption"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 $galData["caption"] = $galData["title"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 unset($galData["title"]);
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 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 $galData["hide"] = 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 // If caption is not set, use last path component for
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 // a fallback value in case we don't discover proper title
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 // from other sources we can't check here yet.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 $path = explode("/", $galPath);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 $galData["fallback_caption"] = ucfirst(str_replace("_", " ", end($path)));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 // Last, store the current gallery path
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 $len = strlen($galBasePath);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 if ($len < strlen($galPath) && substr($galPath, 0, $len) == $galBasePath)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 $galData["path"] = substr($galPath, $len);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 $galData["path"] = "";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 return $galData;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 function mgReadCaptionsFile($galBasePath, $galPath)
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 $captions = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 $filename = mgGetPath($galPath, "captions_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 if ($filename === FALSE || ($fp = @fopen($filename, "rb")) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 return $captions;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 mgDebug("Reading CAPTIONS: ".$filename."\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 // Read and parse data
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 while (!feof($fp))
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 $str = trim(fgets($fp));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 // Ignore comments and empty lines
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 if ($str != "#" && $str != "")
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 if (preg_match("/^(#?)\s*(\S+?)\s+(.+)$/", $str, $m))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 $captions[$m[2]] = array("caption" => $m[3], "hide" => ($m[1] == "#"), "used" => FALSE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 if (preg_match("/^(#?)\s*(\S+?)$/", $str, $m))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 $captions[$m[2]] = array("hide" => ($m[1] == "#"), "used" => FALSE);
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 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 fclose($fp);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 return $captions;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 function mgMakeDir($path, $perm)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 if (!file_exists($path))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 if (mkdir($path, $perm, TRUE) === false)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 return mgError("Could not create directory '".$path."'\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 return TRUE;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 function mgYesNoPrompt($msg, $default = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 echo $msg." [".($default ? "Y/n" : "y/N")."]? ";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 $sprompt = strtolower(trim(fgets(STDIN)));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 if ($default)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 return ($sprompt == "n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 return ($sprompt == "y");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 function mgDelete($path, $recurse)
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 global $flagDoDelete;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 if (is_dir($path))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 if (($dirHandle = @opendir($path)) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 return mgError("Could not read directory '".$path."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 while (($dirFile = @readdir($dirHandle)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 if ($dirFile != "." && $dirFile != "..")
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 mgDelete($path."/".$dirFile, $recurse);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 closedir($dirHandle);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 echo " - ".$path." [DIR]\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 if ($flagDoDelete)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 rmdir($path);
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 if (!$recurse)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 echo " - ".$path."\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 if ($flagDoDelete)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 unlink($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304
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 function mgCheckQuit($now = FALSE)
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 global $flagQuit;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 // Dispatch pending signals
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 pcntl_signal_dispatch();
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 // Check result
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 if ($now && $flagQuit)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 mgFatal("Quitting.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 return $flagQuit;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
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 function mgNeedUpdate($entry, $field, $cvalue)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 if (!array_key_exists($field, $entry))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 return TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 return ($entry[$field] < $cvalue);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 }
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 function mgHandleDirectory($mode, $basepath, $path, $parentData, $parentEntry, $writeMode, $startAt)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 global $galExifConversions, $galTNPath, $galCleanFlags;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 // Get cache file path
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 if (($cacheFilename = mgGetPath($path, "cache_file")) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 return mgError("Cache filename / path not set.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 mgCheckQuit(TRUE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 // Read directory contents
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 $entries = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 if (($dirHandle = @opendir($path)) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 return mgError("Could not read directory '".$path."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 while (($dirFile = @readdir($dirHandle)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 $realFile = $path."/".$dirFile;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 if (is_dir($realFile))
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 if ($dirFile[0] != "." && $dirFile != $galTNPath)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 $entries[$dirFile] = array("type" => 1, "base" => $dirFile, "ext" => "", "mtime" => filemtime($realFile));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 if (preg_match("/^(\S+)(".mgGetSetting("format_exts").")$/i", $dirFile, $dirMatch))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 $entries[$dirFile] = array("type" => 0, "base" => $dirMatch[1], "ext" => $dirMatch[2], "mtime" => filemtime($realFile), "hide" => false);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 closedir($dirHandle);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 mgCheckQuit();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 // Cleanup mode
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 if ($mode == GCMD_CLEAN)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 $gallery = array();
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 if ($writeMode)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 if ($galCleanFlags & GCLEAN_CACHES)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 mgDelete($cacheFilename, FALSE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 if ($galCleanFlags & GCLEAN_THUMBNAILS)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 mgDelete($path."/".$galTNPath, TRUE);
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 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 // Update modes
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 if ($mode == GCMD_UPDATE || $mode == GCMD_RESCAN)
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 // Load current cache file, if it exists
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 $galEntries = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 $cacheTime = -1;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 if ($mode == GCMD_UPDATE && file_exists($cacheFilename))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 $cacheTime = filemtime($cacheFilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 @include $cacheFilename;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 // Read caption data
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 $captions = mgReadCaptionsFile($basepath, $path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 $gallery = mgGetAlbumData($basepath, $path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 if ($parentData !== NULL && $parentEntry !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 $gallery["parent"] = $parentData;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 mgCopyEntryData($gallery, $parentEntry, MG_STR, "caption", "caption");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 // Start actual processing
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 $nentries = count($entries);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 $nentry = 0;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 echo $path." .. ";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 foreach ($entries as $ename => &$edata)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 printf("\r%s (%1.1f%%) ..", $path, ($nentry * 100.0) / $nentries);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 $nentry++;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 $efilename = $path."/".$ename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 if (array_key_exists($ename, $galEntries))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 $galEntry = &$galEntries[$ename];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 $galEntry = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 mgCheckQuit(FALSE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415 // Update with captions file data, if any
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 if (array_key_exists($ename, $captions))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 foreach ($captions[$ename] as $ckey => $cval)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 $edata[$ckey] = $cval;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 // Handle entry based on type
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 if ($edata["type"] == 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 $updFlags = 0;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 $tnPath = $path."/".$galTNPath;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 $medFilename = $tnPath."/".$edata["base"].mgGetSetting("med_suffix").$edata["ext"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 $tnFilename = $tnPath."/".$ename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 $capFilename = $path."/".$edata["base"].".txt";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 // Check what we need to update ..
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 if (!file_exists($medFilename) || filemtime($medFilename) < $edata["mtime"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 $updFlags |= GUPD_MED_IMAGE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 if (!file_exists($tnFilename) || filemtime($tnFilename) < $edata["mtime"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 $updFlags |= GUPD_TN_IMAGE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 if (mgNeedUpdate($galEntry, "mtime", $edata["mtime"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 $updFlags |= GUPD_EXIF_INFO;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 if (file_exists($capFilename) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 mgNeedUpdate($galEntry, "mtime", filemtime($capFilename)))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 $updFlags |= GUPD_CAPTION;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 // Check for EXIF info
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 if (($updFlags & GUPD_EXIF_INFO) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 ($exif = @exif_read_data($efilename)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 echo "%";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 foreach ($galExifConversions as $conv)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 mgCopyEntryData($edata, $exif, $conv[0], $conv[1], $conv[2]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 // Copy old data that is not yet in new
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 echo "*";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 foreach ($galEntry as $okey => $odata)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 if (!array_key_exists($okey, $edata))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 $edata[$okey] = $odata;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 // Generate thumbnails, etc.
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 if ($updFlags & GUPD_IMAGES)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 mgMakeDir($tnPath, 0755);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 if ($updFlags & GUPD_MED_IMAGE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 echo "1";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 mgConvertImage($efilename, $medFilename,
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 array(mgGetSetting("med_width"), mgGetSetting("med_height")),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 "JPEG", mgGetSetting("med_quality"), TRUE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 if ($updFlags & GUPD_TN_IMAGE)
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 echo "2";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 mgConvertImage($efilename, $tnFilename,
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 array(mgGetSetting("tn_width"), mgGetSetting("tn_height")),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 "JPEG", mgGetSetting("tn_quality"), TRUE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 // Check for .txt caption file
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 if ($updFlags & GUPD_CAPTION)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 echo "?";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 if (($tmpData = @file_get_contents($capFilename)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 $edata["caption"] = $tmpData;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 if ($edata["type"] == 1)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 $tmp = mgGetAlbumData($basepath, $efilename);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "caption");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "fallback_caption");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 mgCopyEntryData($edata, $tmp, MG_STR, "caption", "title");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 mgCopyEntryData($edata, $tmp, MG_BOOL, "hide", "hide", FALSE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 echo "\r".$path." ..... DONE\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 mgCheckQuit(TRUE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 // Store gallery cache for this directory
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 if ($writeMode)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 $images = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 $albums = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 foreach ($entries as $ename => &$edata)
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 ($edata["hide"])
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 continue;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 unset($edata["hide"]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 if ($edata["type"] == 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 $images[$ename] = &$edata;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 $albums[$ename] = &$edata;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 ksort($images);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 ksort($albums);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 $str =
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 "<?\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 "\$galData = ".var_export($gallery, TRUE).";\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 "\$galAlbumsIndex = ".var_export(array_keys($albums), TRUE).";\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 "\$galImagesIndex = ".var_export(array_keys($images), TRUE).";\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 "\$galEntries = ".var_export($entries, TRUE).";\n".
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 if (@file_put_contents($cacheFilename, $str, LOCK_EX) === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 return mgError("Error writing '".$cacheFilename."'\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 mgFatal("Invalid work mode '".$mode."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 mgCheckQuit(TRUE);
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 // Recurse to subdirectories
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 foreach ($entries as $ename => $edata)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 if ($edata["type"] == 1)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 $epath = $path."/".$ename."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 $newWriteMode = ($writeMode === FALSE && $epath == $startAt) || $writeMode;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 if (!mgHandleDirectory($mode, $basepath, $epath, $gallery, $edata, $newWriteMode, $startAt))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 }
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 mgCheckQuit(TRUE);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558 return TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 function mgSigHandler($signo)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 global $flagQuit;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 switch ($signo)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 case SIGTERM:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 mgFatal("Received SIGTERM.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 case SIGQUIT:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 case SIGINT:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 $flagQuit = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578
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 function mgProcessGalleries($cmd, $path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 global $galTNPath;
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 // Fetch the settings we need
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 if (mgReadSettings() === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 die("MGallery not configured.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 // Check validity of some settings
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 $galPath = mgGetSetting("base_path");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 $galTNPath = mgCleanPath(TRUE, mgGetSetting("tn_path"));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 if ($galTNPath != mgGetSetting("tn_path"))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 mgError("Invalid tn_path, using '".$galTNPath."'.\n");
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 if (strpos($galTNPath, "/") !== FALSE || $galTNPath == "")
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 mgFatal("Invalid tn_path '".$galTNPath."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 $parentData = $parentEntry = NULL;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 $writeMode = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 $startAt = NULL;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
601 // Check for path argument
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
602 if ($path !== FALSE)
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 // Check the given path, needs to be "under" the gallery path
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605 $cmp = mgCleanPath(TRUE, mgRealPath($galPath))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 $tmp = mgCleanPath(TRUE, mgRealPath($path))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 if (substr($tmp, 0, strlen($cmp)) != $cmp)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 mgFatal("Path '".$path."' ('".$tmp."') does not reside under '".$galPath."' ('".$cmp."')!\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 // Check if we need to bootstrap
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 if ($cmp != $tmp)
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 $bpath = mgCleanPath(TRUE, mgRealPath($tmp."../"));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 if ($cmd != GCMD_CLEAN)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 $cacheFile = mgGetPath($bpath, "cache_file");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 if (!file_exists($cacheFile))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 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
620
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 @include($cacheFile);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 if (!isset($galEntries) || !isset($galData))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 mgFatal("Cache file '".$cacheFile."' is broken or stale.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 $writeMode = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 $startAt = $tmp;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 $path = $bpath;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630 echo "Starting: '".$startAt."' inside '".$path."'.\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 $path = $tmp;
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 $path = $galPath;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 // Start working
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 echo "Gallery path: '".$galPath."', starting at '".$path."' ...\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
640 mgHandleDirectory($cmd, $galPath, $path, $parentData, $parentEntry, $writeMode, $startAt);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 }
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 function mgShowCopyright()
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 global $mgProgVersion, $mgProgCopyright,
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 $mgProgInfo, $mgProgEmail;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 echo
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 "MGTool ".$mgProgVersion." - MGallery management tool\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651 $mgProgInfo." ".$mgProgEmail."\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 "(C) Copyright ".$mgProgCopyright."\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 }
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 function mgShowHelp()
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 global $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 echo
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 "Usage: ".basename($argv[0])." <command> [arguments]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 " --help - Show this help.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 " --version - Show version information.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 " update [path]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 " Update directories under <path> or all gallery dirs.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 " Conditionally scans dirs for new or changed images and\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 " updates cache files as needed.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 " rescan [path]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 " Like 'update', but forces all cache files to be regenerated\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 " and EXIF/caption/etc information to be re-scanned even\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 " if the file timestamps do not justify re-scanning.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 " clean <all|caches|thumbnails> [path]\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676 " Delete all generated files or selectively cache files or\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
677 " everything inside thumbnail directories.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 "\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 " config\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
680 " Display configuration values.\n".
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681 "\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 // Main code starts
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"]))
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 header("Status: 404 Not Found");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 die();
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 pcntl_signal(SIGTERM, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 pcntl_signal(SIGHUP, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 pcntl_signal(SIGQUIT, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 pcntl_signal(SIGINT, "mgSigHandler");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698
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 $cmd = mgCArgLC(1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 switch ($cmd)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 case "--version":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704 case "version":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 case "ver":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 mgShowCopyright();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 case FALSE:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710 // No arguments
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 mgError("Nothing to do. Showing help:\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 case "--help":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 case "help":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 if ($cmd !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 mgShowCopyright();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717 mgShowHelp();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
719
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 case "update": case "up": case "upd": case "upda":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
721 mgProcessGalleries(GCMD_UPDATE, mgCArg(2));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
723
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 case "rescan": case "re": case "res":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 mgProcessGalleries(GCMD_RESCAN, mgCArg(2));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
727
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 case "clean": case "cl": case "cle":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 $cmode = mgCArgLC(2, 2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730 switch ($cmode)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 case "al": $galCleanFlags = GCLEAN_ALL; break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
733 case "ca": $galCleanFlags = GCLEAN_CACHES; break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 case "th": $galCleanFlags = GCLEAN_THUMBNAILS; break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
735 case FALSE:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 mgFatal("Cleaning requires a mode argument.\n");
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 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 mgFatal("Invalid clean mode '".mgCArg(2)."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 $flagDoDelete = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 mgProcessGalleries(GCMD_CLEAN, mgCArg(3));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
743 echo "--\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 if (mgYesNoPrompt("Really delete the above files and directories?"))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 echo "OKAY.\n";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 case "config":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751 if (mgReadSettings() === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 die("MGallery not configured.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 foreach ($mgDefaults as $key => $dval)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 $sval = mgGetSetting($key);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 printf("%-20s = %s%s\n",
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 $key,
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759 mgGetDValStr($dval[0], $sval),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 ($dval[1] !== NULL && $sval !== $dval[1]) ? " (default: ".mgGetDValStr($dval[0], $dval[1]).")" : "");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 break;
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 case "dump":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765 if (mgReadSettings() === FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
766 die("MGallery not configured.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 foreach ($mgDefaults as $key => $dval)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 $sval = mgGetSetting($key);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 printf("%-20s = %s\n", $key, mgGetDValStr($dval[0], $sval));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 mgError("Unknown option/command '".$cmd."'.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 }
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 ?>