annotate mgallery.inc.php @ 306:2c5ff6aa9845

Bump copyright years.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 03 Apr 2020 16:26:00 +0300
parents b816e80bc002
children a09452ac196e
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 <?php
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 // Yet Another Image Gallery
69
7777887bc515 Update header/copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
4 // -- Common functions and data include
7777887bc515 Update header/copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
5 // Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
306
2c5ff6aa9845 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 305
diff changeset
6 // (C) Copyright 2015-2020 Tecnic Software productions (TNSP)
0
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
295
df66529eff47 Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
9 $mgProgVersion = "v0.9.10";
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 $mgProgEmail = "<ccr@tnsp.org>";
306
2c5ff6aa9845 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 305
diff changeset
12 $mgProgCopyright = "2015-2020 Tecnic Software productions (TNSP)";
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
297
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
14 $mgProgConfigFile = "mgallery.cfg";
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
15
274
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
16 $mgalDebug = FALSE;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
275
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
18
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 //
106
a3b8cd4183e6 Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
20 // Navigation control defines
a3b8cd4183e6 Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
21 //
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
22 define("MGF_JAVASCRIPT" , 0x01);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
23 define("MGF_BREADCRUMBS" , 0x10);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
24 define("MGF_CAPTIONS" , 0x20);
106
a3b8cd4183e6 Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
25
a3b8cd4183e6 Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
26 //
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 // Constants for different value types
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 //
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
29 define("MG_STR" , 1);
303
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
30 define("MG_STR_LC" , 2);
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
31 define("MG_INT" , 3);
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
32 define("MG_DVA" , 4);
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
33 define("MG_BOOL" , 5);
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
34 define("MG_FLAGS" , 6);
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
35 define("MG_DATE" , 7);
0
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
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
38 define("yes" , 1);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
39 define("no" , 0);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
42 $mgGFlags = [
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
43 "javascript" => MGF_JAVASCRIPT,
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
44 "breadcrumbs" => MGF_BREADCRUMBS,
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
45 "captions" => MGF_CAPTIONS,
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
46 ];
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
47
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
48
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 function mgPathName($path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 $tmp = mgCleanPathArray(TRUE, 0, func_num_args(), func_get_args());
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 if (count($tmp) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 return implode("/", array_splice($tmp, 0, -1))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 return $path;
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
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 // Configuration settings and their default values
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 //
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
61 $mgDefaults = [
130
f825d644cf7a Implement new config setting "timezone" for specifying the timezone used for date/timestamp interpretation.
Matti Hamalainen <ccr@tnsp.org>
parents: 127
diff changeset
62 "timezone" => [MG_STR, NULL],
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
141
18061527d1cd Reorder some settings in configuration data.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
64 "clean_urls" => [MG_BOOL, FALSE],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
65 "base_path" => [MG_STR, mgPathName(mgRealPath($_SERVER["SCRIPT_FILENAME"]))],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
66 "base_url" => [MG_STR, mgPathName($_SERVER["PHP_SELF"])],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
67 "image_url" => [MG_STR, mgPathName($_SERVER["PHP_SELF"])],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
68 "mgallery_php" => [MG_STR, "mgallery.php"],
250
3af3b3f50cb0 Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents: 241
diff changeset
69 "format_exts" => [MG_STR, "\.jpg|\.png|\.gif|\.jpeg|\.webp"],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
70 "captions_file" => [MG_STR, "captions.txt"],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
71 "header_file" => [MG_STR, "header.txt"],
267
108b354ea2ea Rename default gallery info file from "gallery.info" to "mgallery.info".
Matti Hamalainen <ccr@tnsp.org>
parents: 266
diff changeset
72 "info_file" => [MG_STR, "mgallery.info"],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
73 "cache_file" => [MG_STR, ".mgallery.cache"],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
74
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
75 "cover_images" => [MG_BOOL, TRUE],
141
18061527d1cd Reorder some settings in configuration data.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
76 "album_icon" => [MG_STR, "album_sm.png"],
18061527d1cd Reorder some settings in configuration data.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
77
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
78 "title_prefix" => [MG_STR, ""],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
79 "title_sep" => [MG_STR, " - "],
224
77e72455c99f "Powered by MGallery" ..
Matti Hamalainen <ccr@tnsp.org>
parents: 219
diff changeset
80 "page_info" => [MG_STR, "Powered by <b>MGallery ".$mgProgVersion."</b> &copy; Copyright ".$mgProgCopyright],
151
4e25150aa868 Change js_path configuration setting to js_file.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
81
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
82 "css" => [MG_STR, NULL],
151
4e25150aa868 Change js_path configuration setting to js_file.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
83 "js_file" => [MG_STR, NULL],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
84 "urchin_file" => [MG_STR, FALSE],
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
86 "global_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS | MGF_CAPTIONS, &$mgGFlags],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
87 "image_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
88 "album_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags],
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
90 "tn_path" => [MG_STR, "tn/"],
185
cb7019690a73 Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
91 "med_path" => [MG_STR, "med/"],
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
303
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
93 "tn_format" => [MG_STR_LC, "jpeg"],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
94 "tn_width" => [MG_INT, 140], // In pixels, applies as bounding box for w/h
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
95 "tn_height" => [MG_INT, 100],
289
13cff35dfbec Change default thumbnail/medium formats from JPEG to WEBP.
Matti Hamalainen <ccr@tnsp.org>
parents: 285
diff changeset
96 "tn_quality" => [MG_INT, 90], // JPEG/WEBP quality percent
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
303
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
98 "med_format" => [MG_STR_LC, "jpeg"],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
99 "med_width" => [MG_INT, 960],
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
100 "med_height" => [MG_INT, 640],
162
3c2674dbd185 Increase the generated mid- and thumbnail images JPEG quality slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
101 "med_quality" => [MG_INT, 90],
195
f3098855ad58 Add debug option setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
102
303
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
103 "backend" => [MG_STR_LC, "php"],
290
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
104 "sql_db" => [MG_STR, NULL],
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
105 "sql_username" => [MG_STR, ""],
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
106 "sql_password" => [MG_STR, ""],
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
107 "sql_options" => [MG_STR, []],
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
108 ];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 function mgDebug($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
274
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
113 global $mgalDebug;
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
114 if ($mgalDebug)
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
115 {
275
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
116 echo "<p>MGAL[debug]: ".htmlspecialchars($msg)."</p>";
274
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
117 error_log("MGAL[debug]: ".$msg);
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
118 }
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 function mgFatal($msg)
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 die("MGAL[fatal]: ".$msg);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 }
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 function mgError($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 {
275
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
130 error_log("MGAL[error]: ".$msg);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 return FALSE;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 function mgCArg($index, $clip = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 global $argc, $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 if ($index < $argc)
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 $str = $argv[$index];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 else
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 function mgCArgLC($index, $clip = FALSE)
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 global $argc, $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 if ($index < $argc)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 $str = strtolower($argv[$index]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str;
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 function mgGetSetting($key, $default = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 global $mgSettings, $mgDefaults;
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 if (!array_key_exists($key, $mgDefaults))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 mgFatal("Setting '".$key."' does not exist.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 if (array_key_exists($key, $mgSettings))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 $val = $mgSettings[$key];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 $val = $mgDefaults[$key][1];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 if (!isset($val) || $val === NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 if ($default !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 $val = $default;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n");
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
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
181 switch ($mgDefaults[$key][0])
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
182 {
303
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
183 case MG_STR_LC:
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
184 $val = strtolower($val);
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
185 break;
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
186
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
187 case MG_FLAGS:
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
188 if (is_string($val))
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
189 {
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
190 $flags = $mgDefaults[$key][2];
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
191 $cval = preg_split("/\s*[,|]\s*/", strtolower($val), -1, PREG_SPLIT_NO_EMPTY);
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
192 $nval = 0;
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
193 foreach ($cval as $qval)
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
194 {
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
195 if (array_key_exists($qval, $flags))
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
196 $nval |= $flags[$qval];
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
197 else
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
198 mgFatal("Invalid flag value for '".$key."': '".$qval."'.");
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
199 }
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
200 }
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
201 break;
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
202 }
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
203
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
293
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
208 function mgGetAlbumSetting(&$data, $key, $default = NULL)
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
209 {
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
210 if (array_key_exists($key, $data))
305
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
211 $val = $data[$key];
293
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
212 else
305
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
213 $val = mgGetSetting($key, $default);
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
214
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
215 // XXX This is a rather silly place for this check, but since any album can
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
216 // set their own formats, we can't do this check globally without scanning
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
217 // all the sub-albums etc .. maybe we'll do that some day.
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
218 if (($key == "tn_format" || $key == "med_format") &&
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
219 $val == "webp" && version_compare(PHP_VERSION, "7.1.0") < 0)
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
220 {
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
221 die("ERROR: WEBP image format support requires PHP version 7.1 or later.");
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
222 }
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
223
b816e80bc002 Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
224 return $val;
293
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
225 }
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
226
486398fb60ea Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
227
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 function mgGetPath($path, $key)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 $val = mgGetSetting($key);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 return ($val !== FALSE) ? $path."/".$val : FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
297
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
235 function mgReadSettings(&$spaths)
0
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 global $mgSettings, $mgDefaults;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
239 $spaths = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 $spaths[] = getcwd()."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 $spaths[] = $tmp."/.config/mgallery/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 $spaths[] = $tmp."/.";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 else
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 $data = posix_getpwuid(posix_getuid());
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 if ($data !== FALSE && isset($data["dir"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 $tmp = $data["dir"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 $spaths[] = $tmp."/.config/mgallery/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 $spaths[] = $tmp."/.";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 }
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 $spaths[] = dirname(__FILE__)."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
297
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
258 $spaths = array_map(function ($path)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 {
297
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
260 global $mgProgConfigFile;
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
261 return $path.$mgProgConfigFile;
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
262 }, $spaths);
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
263
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
264 foreach (array_unique($spaths) as $file)
77f85b1f35f2 Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
265 {
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 mgDebug("Checking '".$file."' for configuration ..\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 if (file_exists($file) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE)
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 mgDebug("Found '".$file."' config.\n");
278
6770ef8b3575 Disable checking of undefined configuration settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 275
diff changeset
271 return TRUE;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
275 $mgSettings = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 function mgRealPath($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 return realpath($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285
285
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
286 function mgCleanPathStr($path)
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
287 {
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
288 return str_replace("//", "/", $path);
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
289 }
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
290
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
291
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 function mgCleanPathArray($refs, $start, $argc, $argv)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 {
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
294 $path = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 $first = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 for ($n = $start; $n < $argc; $n++)
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 foreach (explode("/", $argv[$n]) as $piece)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 switch ($piece)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 case ".":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 case "":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 if ($first)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 $path[] = $piece;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 break;
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 case "..":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 if ($refs && count($path) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 array_pop($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 break;
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 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 $path[] = $piece;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 break;
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 $first = FALSE;
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 }
285
25324e33fc78 Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
320 return mgCleanPathStr($path);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 function mgCleanPath($refs)
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 implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args()));
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 mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 {
47
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
332 global $pageLang;
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
333
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 if (!is_array($skeys))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 $skeys = array($skeys);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 foreach ($skeys as $skey)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 if (!array_key_exists($skey, $data))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 return $sfmt2;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 $str = $sfmt1;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 for ($i = 1; $i <= sizeof($skeys); $i++)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 $val = $data[$skeys[$i - 1]];
47
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
345 if (is_array($val))
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
346 $vtmp = array_key_exists($pageLang, $val) ? $val[$pageLang] : reset($val);
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
347 else
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
348 $vtmp = $val;
0
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 (is_callable($func))
77
fcfd635d7abf Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
351 $vtmp = call_user_func($func, $vtmp);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
47
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
353 $str = str_replace("%".$i, $vtmp, $str);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 return $str;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 }
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
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
360 function mgGetDValStr($mdef, $val)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 {
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
362 switch ($mdef[0])
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 {
298
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
364 case MG_STR:
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
365 if (is_array($val))
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
366 return implode(", ", $val);
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
367 else
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
368 return "\"".$val."\"";
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
369
303
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
370 case MG_STR_LC:
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
371 if (is_array($val))
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
372 return implode(", ", array_map('strtolower', $val));
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
373 else
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
374 return "\"".strtolower($val)."\"";
6bb434968623 Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents: 298
diff changeset
375
298
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
376 case MG_BOOL:
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
377 return $val ? "yes" : "no";
cf166dcc6e77 Handle arrays in some way (not useful way, tho.) in config dumping.
Matti Hamalainen <ccr@tnsp.org>
parents: 297
diff changeset
378
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
379 case MG_FLAGS:
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
380 {
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
381 $mstr = [];
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
382 foreach ($mdef[2] as $vkey => $vval)
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
383 {
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
384 if ($val & $vval)
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
385 $mstr[] = $vkey;
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
386 }
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
387 return implode($mstr, " | ");
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
388 }
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 case MG_INT :
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 default : return (string) $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393
290
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
394
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
395 function mgLogSQLError($dbh, $sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
396 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
397 return mgError("SQL error '".implode("; ", $dbh->errorInfo())."' in statement: \"".$sql."\"");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
398 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
399
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
400
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
401 function mgDBGetSQLParam($dbh, $type, $value)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
402 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
403 switch ($type)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
404 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
405 case "d": return intval($value);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
406 case "s": return $dbh->quote($value);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
407 case "b": return intval($value) ? 1 : 0;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
408 case "D":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
409 if ($value instanceOf DateTime)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
410 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
411 switch ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME))
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
412 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
413 case "pgsql" : $fmt = "Y-m-d H:i:sP"; break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
414 case "sqlite" : $fmt = DATE_RFC3339; break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
415 case "mysql" : $fmt = "Y-m-d H:i:s"; break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
416 default : $fmt = DATE_RFC3339;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
417 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
418 return $dbh->quote($value->format($fmt));
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
419 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
420 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
421 return intval($value);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
422 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
423 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
424
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
425
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
426 function mgSQLToDateTime($dbh, $stamp)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
427 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
428 switch ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME))
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
429 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
430 case "pgsql":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
431 // PostgreSQL 'timestamptz' format
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
432 $tmp = DateTime::createFromFormat("Y-m-d H:i:sP", $stamp);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
433 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
434
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
435 case "sqlite":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
436 // SQLite can use RFC3339 format
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
437 $tmp = DateTime::createFromFormat(DATE_RFC3339, $stamp);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
438 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
439
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
440 case "mysql":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
441 // MySQL uses UTC internally, no way to specify TZ
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
442 $tmp = DateTime::createFromFormat("Y-m-d H:i:s", $stamp);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
443 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
444
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
445 default:
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
446 $tmp = NULL;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
447 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
448
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
449 // echo "<p>".$stamp." :: ".var_export(($tmp instanceOf DateTime) ? $tmp : NULL, TRUE)."</p>";
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
450 return ($tmp instanceOf DateTime) ? $tmp : NULL;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
451 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
452
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
453
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
454 function mgConnectSQLDB()
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
455 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
456 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
457 try {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
458 $db = new PDO(mgGetSetting("sql_db"),
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
459 mgGetSetting("sql_username", NULL),
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
460 mgGetSetting("sql_password", NULL),
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
461 mgGetSetting("sql_options", array()));
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
462 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
463 catch (PDOException $e) {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
464 mgError("Could not connect to SQL database: ".$e->getMessage().".");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
465 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
466 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
467 return ($db !== false);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
468 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
469
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
470
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
471 function mgDBPrepareSQLUpdate($dbh, $table, $cond, $pairs, $values = NULL)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
472 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
473 $sql = [];
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
474 foreach ($pairs as $name => $attr)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
475 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
476 $sql[] = $name."=".mgDBGetSQLParam($dbh,
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
477 $attr, $values !== NULL ? $values[$name] : $name);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
478 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
479 return
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
480 "UPDATE ".$table." SET ".implode(",", $sql).
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
481 ($cond != "" ? " ".$cond : "");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
482 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
483
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
484
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
485 function mgDBPrepareSQL_V($dbh, $fmt, $argv)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
486 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
487 $len = strlen($fmt);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
488 $sql = "";
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
489 $argn = 0;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
490 $argc = count($argv);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
491
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
492 for ($pos = 0; $pos < $len; $pos++)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
493 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
494 if ($fmt[$pos] == "%")
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
495 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
496 if ($argn < $argc)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
497 $sql .= mgDBGetSQLParam($dbh, $fmt[++$pos], $argv[$argn++]);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
498 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
499 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
500 mgError("Invalid SQL statement format string '".$fmt.
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
501 "', not enough parameters specified (".$argn." of ".$argc.")");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
502 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
503 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
504 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
505 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
506 $sql .= $fmt[$pos];
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
507 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
508
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
509 return $sql;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
510 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
511
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
512
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
513 function mgDBPrepareSQL($dbh)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
514 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
515 $argv = func_get_args();
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
516 return mgDBPrepareSQL_V($dbh, $argv[1], array_splice($argv, 2));
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
517 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
518
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
519
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
520 function mgPrepareSQL()
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
521 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
522 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
523 $argv = func_get_args();
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
524 return mgDBPrepareSQL_V($db, $argv[0], array_splice($argv, 1));
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
525 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
526
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
527
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
528 function mgDBExecSQLInsert($dbh, $sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
529 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
530 switch ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME))
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
531 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
532 case "pgsql":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
533 if (($res = mgDBFetchSQLColumn($dbh, $sql." RETURNING id")) !== false)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
534 return $res;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
535 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
536 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
537
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
538 default:
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
539 if (mgDBExecSQL($dbh, $sql) !== false)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
540 return $dbh->lastInsertId();
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
541 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
542 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
543 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
544 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
545
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
546
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
547 function mgDBExecSQL($dbh, $sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
548 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
549 if (($res = $dbh->query($sql)) !== FALSE)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
550 return $res;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
551 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
552 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
553 mgLogSQLError($dbh, $sql);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
554 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
555 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
556 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
557
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
558
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
559 function mgDBFetchSQL($dbh, $sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
560 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
561 if (($res = $dbh->query($sql)) !== FALSE)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
562 return $res->fetch();
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
563 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
564 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
565 mgLogSQLError($dbh, $sql);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
566 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
567 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
568 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
569
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
570
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
571 function mgDBFetchSQLColumn($dbh, $sql, $column = 0)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
572 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
573 if (($res = $dbh->query($sql)) !== FALSE)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
574 return $res->fetchColumn($column);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
575 else
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
576 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
577 mgLogSQLError($dbh, $sql);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
578 return FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
579 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
580 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
581
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
582
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
583 function mgPrepareSQLUpdate($table, $cond, $pairs)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
584 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
585 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
586 return mgDBPrepareSQLUpdate($db, $table, $cond, $pairs);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
587 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
588
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
589
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
590 function mgExecSQLInsert($sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
591 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
592 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
593 return mgDBExecSQLInsert($db, $sql);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
594 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
595
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
596
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
597 function mgExecSQL($sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
598 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
599 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
600 return mgDBExecSQL($db, $sql);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
601 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
602
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
603
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
604 function mgFetchSQL($sql)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
605 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
606 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
607 return mgDBFetchSQL($db, $sql);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
608 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
609
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
610
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
611 function mgFetchSQLColumn($sql, $column = 0)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
612 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
613 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
614 return mgDBFetchSQLColumn($db, $sql, $column);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
615 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
616
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
617
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
618 function mgDBBeginTransaction($dbh = FALSE)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
619 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
620 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
621 return mgDBExecSQL(($dbh !== FALSE) ? $dbh : $db, "BEGIN TRANSACTION");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
622 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
623
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
624
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
625 function mgDBCommitTransaction($dbh = FALSE)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
626 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
627 global $db;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
628 return mgDBExecSQL(($dbh !== FALSE) ? $dbh : $db, "COMMIT");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
629 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
630
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
631
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
632 function mgDBGetTableSchema($dbh, $schema)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
633 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
634 $res = [];
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
635 $driver = $dbh->getAttribute(PDO::ATTR_DRIVER_NAME);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
636
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
637 // Go through the table schema, definition by definition
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
638 foreach ($schema as $scol)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
639 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
640 $tmp = [];
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
641
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
642 // And each element of the one definition
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
643 // (like 'foo INTEGER AUTOINCREMENT')
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
644 foreach ($scol as $elem)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
645 switch ($driver)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
646 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
647 case "pgsql":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
648 switch ($elem)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
649 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
650 case "AUTOINCREMENT":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
651 // For Postgres, use SERIAL for autoincrement and
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
652 // "cleverly" replace the 2nd element with SERIAL
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
653 // assuming that it is INTEGER or such.
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
654 $tmp[1] = "SERIAL";
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
655 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
656
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
657 case "DATETIME":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
658 $tmp[] = "TIMESTAMPTZ";
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
659 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
660
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
661 default:
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
662 $tmp[] = $elem;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
663 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
664 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
665 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
666
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
667 case "mysql":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
668 switch ($elem)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
669 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
670 case "AUTOINCREMENT":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
671 $tmp[] = "AUTO_INCREMENT";
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
672 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
673
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
674 case "DATETIME":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
675 $tmp[] = "TIMESTAMP";
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
676 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
677
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
678 default:
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
679 $tmp[] = $elem;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
680 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
681 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
682 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
683
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
684 case "sqlite":
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
685 $tmp[] = $elem;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
686 break;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
687
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
688 default:
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
689 die("Don't know how to handle PDO driver '".$driver."' yet.\n");
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
690 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
691
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
692 $res[] = implode(" ", $tmp);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
693 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
694
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
695 return implode(", ", $res);
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
696 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
697
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
698
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
699 function mgDBCreateOneTable($dbh, $name, $schema)
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
700 {
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
701 return (mgDBExecSQL($dbh, "CREATE TABLE IF NOT EXISTS ".$name." (".$schema.")") !== FALSE) ? TRUE : FALSE;
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
702 }
19fbf800b1f7 Work on very early form of virtual gallery support.
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
703
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704 ?>