228 |
kaklik |
1 |
<?php |
|
|
2 |
|
|
|
3 |
//permissions bit flags |
|
|
4 |
define("SG_GRP_READ", 1); |
|
|
5 |
define("SG_GRP_EDIT", 2); |
|
|
6 |
define("SG_GRP_ADD", 4); |
|
|
7 |
define("SG_GRP_DELETE", 8); |
|
|
8 |
define("SG_WLD_READ", 16); |
|
|
9 |
define("SG_WLD_EDIT", 32); |
|
|
10 |
define("SG_WLD_ADD", 64); |
|
|
11 |
define("SG_WLD_DELETE", 128); |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
function getGallery($path) |
|
|
15 |
{ |
|
|
16 |
$gal = new sgGallery('.'); |
|
|
17 |
|
|
|
18 |
$fp = @fopen($path."/metadata.csv","r"); |
|
|
19 |
if($fp) { |
|
|
20 |
|
|
|
21 |
while($temp[] = fgetcsv($fp,2048)); |
|
|
22 |
fclose($fp); |
|
|
23 |
|
|
|
24 |
@list( |
|
|
25 |
$gal->filename, |
|
|
26 |
, |
|
|
27 |
$gal->owner, |
|
|
28 |
$gal->groups, |
|
|
29 |
$gal->permissions, |
|
|
30 |
$gal->categories, |
|
|
31 |
$gal->name, |
|
|
32 |
$gal->artist, |
|
|
33 |
$gal->email, |
|
|
34 |
$gal->copyright, |
|
|
35 |
$gal->desc, |
|
|
36 |
$gal->summary, |
|
|
37 |
$gal->date |
|
|
38 |
) = $temp[1]; |
|
|
39 |
|
|
|
40 |
|
|
|
41 |
for($i=0;$i<count($temp)-3;$i++) { |
|
|
42 |
$gal->images[$i] = new sgImage(); |
|
|
43 |
list( |
|
|
44 |
$gal->images[$i]->filename, |
|
|
45 |
$gal->images[$i]->thumbnail, |
|
|
46 |
$gal->images[$i]->owner, |
|
|
47 |
$gal->images[$i]->groups, |
|
|
48 |
$gal->images[$i]->permissions, |
|
|
49 |
$gal->images[$i]->categories, |
|
|
50 |
$gal->images[$i]->name, |
|
|
51 |
$gal->images[$i]->artist, |
|
|
52 |
$gal->images[$i]->email, |
|
|
53 |
$gal->images[$i]->copyright, |
|
|
54 |
$gal->images[$i]->desc, |
|
|
55 |
$gal->images[$i]->location, |
|
|
56 |
$gal->images[$i]->date, |
|
|
57 |
$gal->images[$i]->camera, |
|
|
58 |
$gal->images[$i]->lens, |
|
|
59 |
$gal->images[$i]->film, |
|
|
60 |
$gal->images[$i]->darkroom, |
|
|
61 |
$gal->images[$i]->digital |
|
|
62 |
) = $temp[$i+2]; |
|
|
63 |
|
|
|
64 |
//don't get image size and type |
|
|
65 |
|
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
} else { |
|
|
69 |
//selected gallery does not exist or no metadata |
|
|
70 |
return null; |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
return $gal; |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
function putGallery($gallery, $path) { |
|
|
77 |
|
|
|
78 |
//backup data file |
|
|
79 |
copy($path."/metadata.csv", $path."/metadata.bak"); |
|
|
80 |
$fp = fopen($path."/metadata.csv","w"); |
|
|
81 |
|
|
|
82 |
if(!$fp) return false; |
|
|
83 |
|
|
|
84 |
$success = true; |
|
|
85 |
|
|
|
86 |
$success &= (bool) fwrite($fp,"filename,thumbnail,owner,group(s),permissions,catergories,image name,artist name,artist email,copyright,image description,image location,date taken,camera info,lens info,film info,darkroom manipulation,digital manipulation"); |
|
|
87 |
$success &= (bool) fwrite($fp,"\n\"". |
|
|
88 |
$gallery->filename."\",,". |
|
|
89 |
$gallery->owner.",". |
|
|
90 |
$gallery->groups.",". |
|
|
91 |
$gallery->permissions.",". |
|
|
92 |
$gallery->categories.',"'. |
|
|
93 |
str_replace('"','""',$gallery->name).'","'. |
|
|
94 |
str_replace('"','""',$gallery->artist).'","'. |
|
|
95 |
str_replace('"','""',$gallery->email).'","'. |
|
|
96 |
str_replace('"','""',$gallery->copyright).'","'. |
|
|
97 |
str_replace('"','""',$gallery->desc).'","'. |
|
|
98 |
str_replace('"','""',$gallery->summary).'","'. |
|
|
99 |
str_replace('"','""',$gallery->date).'"' |
|
|
100 |
); |
|
|
101 |
|
|
|
102 |
for($i=0;$i<count($gallery->images);$i++) |
|
|
103 |
$success &= (bool) fwrite($fp,"\n\"". |
|
|
104 |
$gallery->images[$i]->filename."\",". |
|
|
105 |
$gallery->images[$i]->thumbnail.",". |
|
|
106 |
$gallery->images[$i]->owner.",". |
|
|
107 |
$gallery->images[$i]->groups.",". |
|
|
108 |
$gallery->images[$i]->permissions.",". |
|
|
109 |
$gallery->images[$i]->categories.',"'. |
|
|
110 |
str_replace('"','""',$gallery->images[$i]->name).'","'. |
|
|
111 |
str_replace('"','""',$gallery->images[$i]->artist).'","'. |
|
|
112 |
str_replace('"','""',$gallery->images[$i]->email).'","'. |
|
|
113 |
str_replace('"','""',$gallery->images[$i]->copyright).'","'. |
|
|
114 |
str_replace('"','""',$gallery->images[$i]->desc).'","'. |
|
|
115 |
str_replace('"','""',$gallery->images[$i]->location).'","'. |
|
|
116 |
str_replace('"','""',$gallery->images[$i]->date).'","'. |
|
|
117 |
str_replace('"','""',$gallery->images[$i]->camera).'","'. |
|
|
118 |
str_replace('"','""',$gallery->images[$i]->lens).'","'. |
|
|
119 |
str_replace('"','""',$gallery->images[$i]->film).'","'. |
|
|
120 |
str_replace('"','""',$gallery->images[$i]->darkroom).'","'. |
|
|
121 |
str_replace('"','""',$gallery->images[$i]->digital).'"' |
|
|
122 |
); |
|
|
123 |
$success &= (bool) fclose($fp); |
|
|
124 |
|
|
|
125 |
return $success; |
|
|
126 |
} |
|
|
127 |
|
|
|
128 |
function setPerms($obj) { |
|
|
129 |
$obj->permissions = 0; |
|
|
130 |
if(!empty($_POST["sgGrpRead"])) $obj->permissions |= SG_GRP_READ; |
|
|
131 |
if(!empty($_POST["sgGrpEdit"])) $obj->permissions |= SG_GRP_EDIT; |
|
|
132 |
if(!empty($_POST["sgGrpAdd"])) $obj->permissions |= SG_GRP_ADD; |
|
|
133 |
if(!empty($_POST["sgGrpDelete"])) $obj->permissions |= SG_GRP_DELETE; |
|
|
134 |
if(!empty($_POST["sgWldRead"])) $obj->permissions |= SG_WLD_READ; |
|
|
135 |
if(!empty($_POST["sgWldEdit"])) $obj->permissions |= SG_WLD_EDIT; |
|
|
136 |
if(!empty($_POST["sgWldAdd"])) $obj->permissions |= SG_WLD_ADD; |
|
|
137 |
if(!empty($_POST["sgWldDelete"])) $obj->permissions |= SG_WLD_DELETE; |
|
|
138 |
|
|
|
139 |
$obj->groups = $_REQUEST["sgGroups"]; |
|
|
140 |
$obj->owner = $_REQUEST["sgOwner"]; |
|
|
141 |
|
|
|
142 |
return $obj; |
|
|
143 |
} |
|
|
144 |
|
|
|
145 |
|
|
|
146 |
function convertDirectory ($path) |
|
|
147 |
{ |
|
|
148 |
if (is_dir($path)) { |
|
|
149 |
$gallery = getGallery($path); |
|
|
150 |
echo "<ul><li>Checking $path<br />\n"; |
|
|
151 |
if($gallery) { |
|
|
152 |
if($gallery->summary != "" && empty($_REQUEST["convertOverwrite"])) |
|
|
153 |
echo "Did NOT overwrite non-empty summary in $path<br />\n"; |
|
|
154 |
else { |
|
|
155 |
if($_REQUEST["convertType"]!='none') |
|
|
156 |
$gallery->summary = $gallery->desc; |
|
|
157 |
if($_REQUEST["convertType"]=='move') |
|
|
158 |
$gallery->desc = ""; |
|
|
159 |
} |
|
|
160 |
|
|
|
161 |
$gallery = setPerms($gallery); |
|
|
162 |
|
|
|
163 |
for($i=0; $i<count($gallery->images); $i++) |
|
|
164 |
$gallery->images[$i] = setPerms($gallery->images[$i]); |
|
|
165 |
|
|
|
166 |
if(putGallery($gallery,$path)) |
|
|
167 |
echo "Successfully converted $path<br />\n"; |
|
|
168 |
else |
|
|
169 |
echo "Problem saving data file for $path<br />\n"; |
|
|
170 |
} else |
|
|
171 |
echo "Skipping $path<br />\n"; |
|
|
172 |
$d = dir($path); |
|
|
173 |
while (($file = $d->read()) !== false) { |
|
|
174 |
if ($file == '.' || $file == '..') continue; |
|
|
175 |
$path = $d->path."/".$file; |
|
|
176 |
if (is_dir($path)) { |
|
|
177 |
convertDirectory($path); |
|
|
178 |
} |
|
|
179 |
} |
|
|
180 |
echo "</li></ul>\n"; |
|
|
181 |
} |
|
|
182 |
} |
|
|
183 |
|
|
|
184 |
?> |
|
|
185 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
|
|
186 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
|
187 |
|
|
|
188 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
|
189 |
<head> |
|
|
190 |
<title>database converter</title> |
|
|
191 |
<link rel="stylesheet" type="text/css" href="tools.css" /> |
|
|
192 |
</head> |
|
|
193 |
|
|
|
194 |
<body> |
|
|
195 |
|
|
|
196 |
<h1>database converter</h1> |
|
|
197 |
|
|
|
198 |
<?php |
|
|
199 |
if(isset($_REQUEST["convertType"])) { |
|
|
200 |
|
|
|
201 |
include "../includes/config.class.php"; |
|
|
202 |
include "../includes/gallery.class.php"; |
|
|
203 |
include "../includes/image.class.php"; |
|
|
204 |
$config = new sgConfig("../singapore.ini"); |
|
|
205 |
|
|
|
206 |
$config->base_path = "../"; |
|
|
207 |
|
|
|
208 |
//echo "<ul>\n"; |
|
|
209 |
convertDirectory($config->base_path.$config->pathto_galleries); |
|
|
210 |
//echo "</ul>\n"; |
|
|
211 |
|
|
|
212 |
echo "<p>All operations complete.</p>\n"; |
|
|
213 |
|
|
|
214 |
} else { ?> |
|
|
215 |
<p>This will convert all your metadata files from singapore 0.9.6, 0.9.7, 0.9.8 or 0.9.9 to 0.9.10.</p> |
|
|
216 |
|
|
|
217 |
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> |
|
|
218 |
<h3>summary field</h3> |
|
|
219 |
<p>There is a new gallery summary field that is displayed instead of the |
|
|
220 |
description in the parent gallery. You can choose to either copy or move the |
|
|
221 |
old description field to the summary field or leave both untouched:</p> |
|
|
222 |
|
|
|
223 |
<p><input type="radio" class="radio" name="convertType" value="copy" checked="true" /> Copy<br /> |
|
|
224 |
<input type="radio" class="radio" name="convertType" value="move" /> Move<br /> |
|
|
225 |
<input type="radio" class="radio" name="convertType" value="none" /> Neither<br /> |
|
|
226 |
|
|
|
227 |
<p>By default only empty summary fields will be written to. Check this option to |
|
|
228 |
allow the summary field to be overwritten <input type="checkbox" class="checkbox" name="convertOverwrite" /></p> |
|
|
229 |
|
|
|
230 |
<h3>permissions</h3> |
|
|
231 |
|
|
|
232 |
<p>This version introduces multiple authorised users and image & gallery |
|
|
233 |
permissions. Please choose the default permissions that you would like all |
|
|
234 |
objects to be set to. The default permissions selected below are recommended as |
|
|
235 |
they will make all images & galleries readable by everyone but only |
|
|
236 |
modifiable by administrators. See the readme for more information on the |
|
|
237 |
permissions model used by singapore.</p> |
|
|
238 |
<table> |
|
|
239 |
<tr> |
|
|
240 |
<td>Owner</td> |
|
|
241 |
<td><input type="text" name="sgOwner" value="__nobody__" /></td> |
|
|
242 |
</tr> |
|
|
243 |
<tr> |
|
|
244 |
<td>Groups</td> |
|
|
245 |
<td><input type="text" name="sgGroups" value="" /></td> |
|
|
246 |
</tr> |
|
|
247 |
<tr> |
|
|
248 |
<td>Group permissions</td> |
|
|
249 |
<td><div class="inputbox"> |
|
|
250 |
<input type="checkbox" class="checkbox" name="sgGrpRead" checked="true"/> Read |
|
|
251 |
<input type="checkbox" class="checkbox" name="sgGrpEdit" /> Edit |
|
|
252 |
<input type="checkbox" class="checkbox" name="sgGrpAdd" /> Add |
|
|
253 |
<input type="checkbox" class="checkbox" name="sgGrpDelete" /> Delete |
|
|
254 |
</div></td> |
|
|
255 |
</tr> |
|
|
256 |
<tr> |
|
|
257 |
<td>World permissions</td> |
|
|
258 |
<td><div class="inputbox"> |
|
|
259 |
<input type="checkbox" class="checkbox" name="sgWldRead" checked="true"/> Read |
|
|
260 |
<input type="checkbox" class="checkbox" name="sgWldEdit" /> Edit |
|
|
261 |
<input type="checkbox" class="checkbox" name="sgWldAdd" /> Add |
|
|
262 |
<input type="checkbox" class="checkbox" name="sgWldDelete" /> Delete |
|
|
263 |
</div></td> |
|
|
264 |
</tr> |
|
|
265 |
</table> |
|
|
266 |
|
|
|
267 |
|
|
|
268 |
<p>Please note that while the script will create backups of your metadata files |
|
|
269 |
it is highly recommended that you create your own backups for added security.</p> |
|
|
270 |
|
|
|
271 |
<input type="submit" class="button" value="Go" /></p> |
|
|
272 |
</form> |
|
|
273 |
<?php } ?> |
|
|
274 |
|
|
|
275 |
<p><a href="index.html">Return</a> to tools.</p> |
|
|
276 |
|
|
|
277 |
</body> |
|
|
278 |
</html> |