annotate mgallery.inc.php @ 16:3491ab93630e

Add sub-gallery thumbnails to gallery cache data.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 14 Sep 2015 10:57:10 +0300
parents c9fad00199f9
children 3f7bc4202df3
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 // (C) Copyright 2015 Tecnic Software productions (TNSP)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
14
c9fad00199f9 Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
7 $mgProgVersion = "v0.5";
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 $mgProgEmail = "<ccr@tnsp.org>";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 $mgProgCopyright = "2015 Tecnic Software productions (TNSP)";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 // Constants for different value types
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 define("MG_STR", 1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 define("MG_INT", 2);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 define("MG_DVA", 3);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 define("MG_BOOL", 4);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 define("yes", 1);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 define("no", 0);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 // Navigation control defines
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 define("GNAV_TOP" , 0x01);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 define("GNAV_BOTTOM" , 0x02);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 define("GNAV_IMG" , 0x04);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 define("GNAV_TEXT" , 0x08);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 define("GNAV_SIDE_IMG" , 0x10);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 define("GNAV_JAVASCRIPT" , 0x20);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 define("GNAV_BREADCRUMBS", 0x40);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 function mgPathName($path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 $tmp = mgCleanPathArray(TRUE, 0, func_num_args(), func_get_args());
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 if (count($tmp) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 return implode("/", array_splice($tmp, 0, -1))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 return $path;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 // Configuration settings and their default values
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 $mgDefaults = array(
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 "base_path" => array(MG_STR, mgPathName(mgRealPath($_SERVER["SCRIPT_FILENAME"]))),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 "base_url" => array(MG_STR, mgPathName($_SERVER["PHP_SELF"])),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 "image_url" => array(MG_STR, mgPathName($_SERVER["PHP_SELF"])),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 "mgallery_php" => array(MG_STR, "mgallery.php"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 "format_exts" => array(MG_STR, "\.jpg|\.png|\.gif|\.jpeg"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 "captions_file" => array(MG_STR, "captions.txt"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 "header_file" => array(MG_STR, "header.txt"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 "info_file" => array(MG_STR, "gallery.info"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 "cache_file" => array(MG_STR, ".mgallery.cache"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 "clean_urls" => array(MG_BOOL, FALSE),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 "title_prefix" => array(MG_STR, ""),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 "title_sep" => array(MG_STR, " - "),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 "page_info" => array(MG_STR, "<b>MGallery ".$mgProgVersion."</b> &copy; Copyright ".$mgProgCopyright),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 "css_select" => array(MG_BOOL, FALSE),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 "css" => array(MG_STR, NULL),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 "album_icon" => array(MG_STR, "album_sm.png"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 "image_navigation" => array(MG_INT, GNAV_TOP | GNAV_BOTTOM | GNAV_SIDE_IMG | GNAV_TEXT | GNAV_JAVASCRIPT | GNAV_BREADCRUMBS),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 "album_navigation" => array(MG_INT, GNAV_BREADCRUMBS),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
7
dec931d9e860 Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
73 "navi_ctrl_up" => array(MG_STR, "^^"),
dec931d9e860 Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
74 "navi_ctrl_prev" => array(MG_STR, "<<"),
dec931d9e860 Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
75 "navi_ctrl_next" => array(MG_STR, ">>"),
dec931d9e860 Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
76
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 "album_row_limit" => array(MG_INT, 5),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 "album_page_limit" => array(MG_INT, 100),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 "med_suffix" => array(MG_STR, ".med"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 "tn_path" => array(MG_STR, "tn/"),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 "tn_width" => array(MG_INT, 140), // In pixels, applies as bounding box for w/h
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 "tn_height" => array(MG_INT, 100),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 "tn_quality" => array(MG_INT, 80), // JPEG quality percent
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 "med_width" => array(MG_INT, 800),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 "med_height" => array(MG_INT, 600),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 "med_quality" => array(MG_INT, 95),
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 );
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 function mgDebug($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 // echo "MGAL[debug]: ".$msg;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 function mgFatal($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 die("MGAL[fatal]: ".$msg);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 function mgError($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 echo "MGAL[error]: ".$msg;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 return FALSE;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 function mgCArg($index, $clip = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 global $argc, $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 if ($index < $argc)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 $str = $argv[$index];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str;
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 function mgCArgLC($index, $clip = FALSE)
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 global $argc, $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 if ($index < $argc)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 $str = strtolower($argv[$index]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str;
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 function mgGetSetting($key, $default = NULL)
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 global $mgSettings, $mgDefaults;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 if (!array_key_exists($key, $mgDefaults))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 mgFatal("Setting '".$key."' does not exist.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 if (array_key_exists($key, $mgSettings))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 $val = $mgSettings[$key];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 $val = $mgDefaults[$key][1];
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 if (!isset($val) || $val === NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 if ($default !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 $val = $default;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 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
156 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 return $val;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 function mgGetPath($path, $key)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 $val = mgGetSetting($key);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 return ($val !== FALSE) ? $path."/".$val : FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 }
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 function mgReadSettings($filename = "mgallery.cfg")
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 global $mgSettings, $mgDefaults;
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 $spaths = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 $spaths[] = getcwd()."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 $spaths[] = $tmp."/.config/mgallery/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 $spaths[] = $tmp."/.";
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 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 $data = posix_getpwuid(posix_getuid());
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 if ($data !== FALSE && isset($data["dir"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 $tmp = $data["dir"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 $spaths[] = $tmp."/.config/mgallery/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 $spaths[] = $tmp."/.";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 $spaths[] = dirname(__FILE__)."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 foreach (array_unique($spaths) as $path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 $file = $path.$filename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 mgDebug("Checking '".$file."' for configuration ..\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 if (file_exists($file) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 mgDebug("Found '".$file."' config.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 // Validate settings
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 $ok = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 foreach ($mgSettings as $setting => $val)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 if (!array_key_exists($setting, $mgDefaults))
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 mgError("Setting '".$setting."' does not exist.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 $ok = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 return $ok;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 $mgSettings = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 function mgRealPath($path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 return realpath($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 function mgCleanPathArray($refs, $start, $argc, $argv)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 $path = array();
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 $first = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 for ($n = $start; $n < $argc; $n++)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 foreach (explode("/", $argv[$n]) as $piece)
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 switch ($piece)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 case ".":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 case "":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 if ($first)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 $path[] = $piece;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 case "..":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 if ($refs && count($path) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 array_pop($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 $path[] = $piece;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 break;
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 $first = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 return $path;
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 function mgCleanPath($refs)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args()));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 if (!is_array($skeys))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 $skeys = array($skeys);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 foreach ($skeys as $skey)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 if (!array_key_exists($skey, $data))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 return $sfmt2;
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 $str = $sfmt1;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 for ($i = 1; $i <= sizeof($skeys); $i++)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 $val = $data[$skeys[$i - 1]];
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 if (is_callable($func))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 $val = call_user_func($func, $val);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 $str = str_replace("%".$i, $val, $str);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 }
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 return $str;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 function mgGetVal($skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 function mgGetDValStr($type, $val)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 switch ($type)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 case MG_STR : return "\"".$val."\"";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 case MG_BOOL : return $val ? "yes" : "no";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 case MG_INT :
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 default : return (string) $val;
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 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 ?>