9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
10 * |
10 * |
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
13 */ |
13 */ |
14 |
14 |
15 function getConfig($n) { |
15 /** |
|
16 * Fetch a value from the site configuration. |
|
17 * @param string The identifier of the value ("site_name" etc.) |
|
18 * @return string Configuration value, or bool(false) if the value is not set |
|
19 */ |
|
20 |
|
21 function getConfig($n) |
|
22 { |
16 global $enano_config; |
23 global $enano_config; |
17 if(isset($enano_config[$n])) return $enano_config[$n]; |
24 if ( isset( $enano_config[ $n ] ) ) |
18 else return false; |
25 { |
19 } |
26 return $enano_config[$n]; |
20 |
27 } |
21 function setConfig($n, $v) { |
28 else |
|
29 { |
|
30 return false; |
|
31 } |
|
32 } |
|
33 |
|
34 /** |
|
35 * Update or change a configuration value. |
|
36 * @param string The identifier of the value ("site_name" etc.) |
|
37 * @param string The new value |
|
38 * @return null |
|
39 */ |
|
40 |
|
41 function setConfig($n, $v) |
|
42 { |
|
43 |
22 global $enano_config, $db; |
44 global $enano_config, $db; |
23 $enano_config[$n] = $v; |
45 $enano_config[$n] = $v; |
24 $v = $db->escape($v); |
46 $v = $db->escape($v); |
25 $e=$db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';'); |
47 |
26 if(!$e) $db->_die('Error during generic setConfig() call row deletion.'); |
48 $e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';'); |
27 $e=$db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')'); |
49 if ( !$e ) |
28 if(!$e) $db->_die('Error during generic setConfig() call row insertion.'); |
50 { |
29 } |
51 $db->_die('Error during generic setConfig() call row deletion.'); |
|
52 } |
|
53 |
|
54 $e = $db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')'); |
|
55 if ( !$e ) |
|
56 { |
|
57 $db->_die('Error during generic setConfig() call row insertion.'); |
|
58 } |
|
59 } |
|
60 |
|
61 /** |
|
62 * Create a URI for an internal link. |
|
63 * @param string The full identifier of the page to link to (Special:Administration) |
|
64 * @param string The GET query string to append |
|
65 * @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe |
|
66 * @return string |
|
67 */ |
30 |
68 |
31 function makeUrl($t, $query = false, $escape = false) |
69 function makeUrl($t, $query = false, $escape = false) |
32 { |
70 { |
33 global $db, $session, $paths, $template, $plugins; // Common objects |
71 global $db, $session, $paths, $template, $plugins; // Common objects |
34 $flags = ''; |
72 $flags = ''; |
35 $sep = urlSeparator; |
73 $sep = urlSeparator; |
36 if(isset($_GET['printable'])) { $flags .= $sep.'printable'; $sep = '&'; } |
74 if ( isset($_GET['printable'] ) ) |
37 if(isset($_GET['theme'])) { $flags .= $sep.'theme='.$session->theme; $sep = '&'; } |
75 { |
38 if(isset($_GET['style'])) { $flags .= $sep.'style='.$session->style; $sep = '&'; } |
76 $flags .= $sep . 'printable=yes'; |
|
77 $sep = '&'; |
|
78 } |
|
79 if ( isset($_GET['theme'] ) ) |
|
80 { |
|
81 $flags .= $sep . 'theme='.$session->theme; |
|
82 $sep = '&'; |
|
83 } |
|
84 if ( isset($_GET['style'] ) ) { |
|
85 $flags .= $sep . 'style='.$session->style; |
|
86 $sep = '&'; |
|
87 } |
|
88 |
39 $url = $session->append_sid(contentPath.$t.$flags); |
89 $url = $session->append_sid(contentPath.$t.$flags); |
40 if($query) |
90 if($query) |
41 { |
91 { |
42 $sep = strstr($url, '?') ? '&' : '?'; |
92 $sep = strstr($url, '?') ? '&' : '?'; |
43 $url = $url . $sep . $query; |
93 $url = $url . $sep . $query; |
44 } |
94 } |
|
95 |
45 return ($escape) ? htmlspecialchars($url) : $url; |
96 return ($escape) ? htmlspecialchars($url) : $url; |
46 } |
97 } |
|
98 |
|
99 /** |
|
100 * Create a URI for an internal link, and be namespace-friendly. Watch out for this one because it's different from most other Enano functions, in that the namespace is the first parameter. |
|
101 * @param string The namespace ID |
|
102 * @param string The page ID |
|
103 * @param string The GET query string to append |
|
104 * @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe |
|
105 * @return string |
|
106 */ |
47 |
107 |
48 function makeUrlNS($n, $t, $query = false, $escape = false) |
108 function makeUrlNS($n, $t, $query = false, $escape = false) |
49 { |
109 { |
50 global $db, $session, $paths, $template, $plugins; // Common objects |
110 global $db, $session, $paths, $template, $plugins; // Common objects |
51 $flags = ''; |
111 $flags = ''; |
52 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) $sep = urlSeparator; |
|
53 else $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; |
|
54 if(isset($_GET['printable'])) { $flags .= $sep.'printable'; $sep = '&'; } |
|
55 if(isset($_GET['theme'])) { $flags .= $sep.'theme='.$session->theme; $sep = '&'; } |
|
56 if(isset($_GET['style'])) { $flags .= $sep.'style='.$session->style; $sep = '&'; } |
|
57 |
112 |
58 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
113 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
59 { |
114 { |
60 $url = contentPath.$paths->nslist[$n].$t.$flags; |
115 $sep = urlSeparator; |
61 } |
116 } |
62 else |
117 else |
63 { |
118 { |
64 $url = contentPath.$n.':'.$t.$flags; |
119 $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; |
65 } |
120 } |
66 |
121 if ( isset( $_GET['printable'] ) ) { |
|
122 $flags .= $sep . 'printable'; |
|
123 $sep = '&'; |
|
124 } |
|
125 if ( isset( $_GET['theme'] ) ) |
|
126 { |
|
127 $flags .= $sep . 'theme='.$session->theme; |
|
128 $sep = '&'; |
|
129 } |
|
130 if ( isset( $_GET['style'] ) ) |
|
131 { |
|
132 $flags .= $sep . 'style='.$session->style; |
|
133 $sep = '&'; |
|
134 } |
|
135 |
|
136 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
137 { |
|
138 $url = contentPath . $paths->nslist[$n] . $t . $flags; |
|
139 } |
|
140 else |
|
141 { |
|
142 // If the path manager hasn't been initted yet, take an educated guess at what the URI should be |
|
143 $url = contentPath . $n . ':' . $t . $flags; |
|
144 } |
|
145 |
|
146 if($query) |
|
147 { |
|
148 if(strstr($url, '?')) |
|
149 { |
|
150 $sep = '&'; |
|
151 } |
|
152 else |
|
153 { |
|
154 $sep = '?'; |
|
155 } |
|
156 $url = $url . $sep . $query . $flags; |
|
157 } |
|
158 |
|
159 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
160 { |
|
161 $url = $session->append_sid($url); |
|
162 } |
|
163 |
|
164 return ($escape) ? htmlspecialchars($url) : $url; |
|
165 } |
|
166 |
|
167 /** |
|
168 * Create a URI for an internal link, be namespace-friendly, and add http://hostname/scriptpath to the beginning if possible. Watch out for this one because it's different from most other Enano functions, in that the namespace is the first parameter. |
|
169 * @param string The namespace ID |
|
170 * @param string The page ID |
|
171 * @param string The GET query string to append |
|
172 * @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe |
|
173 * @return string |
|
174 */ |
|
175 |
|
176 function makeUrlComplete($n, $t, $query = false, $escape = false) |
|
177 { |
|
178 global $db, $session, $paths, $template, $plugins; // Common objects |
|
179 $flags = ''; |
|
180 |
|
181 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
182 { |
|
183 $sep = urlSeparator; |
|
184 } |
|
185 else |
|
186 { |
|
187 $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; |
|
188 } |
|
189 if ( isset( $_GET['printable'] ) ) { |
|
190 $flags .= $sep . 'printable'; |
|
191 $sep = '&'; |
|
192 } |
|
193 if ( isset( $_GET['theme'] ) ) |
|
194 { |
|
195 $flags .= $sep . 'theme='.$session->theme; |
|
196 $sep = '&'; |
|
197 } |
|
198 if ( isset( $_GET['style'] ) ) |
|
199 { |
|
200 $flags .= $sep . 'style='.$session->style; |
|
201 $sep = '&'; |
|
202 } |
|
203 |
|
204 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
205 { |
|
206 $url = $session->append_sid(contentPath . $paths->nslist[$n] . $t . $flags); |
|
207 } |
|
208 else |
|
209 { |
|
210 // If the path manager hasn't been initted yet, take an educated guess at what the URI should be |
|
211 $url = contentPath . $n . ':' . $t . $flags; |
|
212 } |
67 if($query) |
213 if($query) |
68 { |
214 { |
69 if(strstr($url, '?')) $sep = '&'; |
215 if(strstr($url, '?')) $sep = '&'; |
70 else $sep = '?'; |
216 else $sep = '?'; |
71 $url = $url . $sep . $query . $flags; |
217 $url = $url . $sep . $query . $flags; |
72 } |
218 } |
73 |
219 |
74 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
75 { |
|
76 $url = $session->append_sid($url); |
|
77 } |
|
78 |
|
79 return ($escape) ? htmlspecialchars($url) : $url; |
|
80 } |
|
81 |
|
82 function makeUrlComplete($n, $t, $query = false, $escape = false) |
|
83 { |
|
84 global $db, $session, $paths, $template, $plugins; // Common objects |
|
85 $flags = ''; |
|
86 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) $sep = urlSeparator; |
|
87 else $sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; |
|
88 if(isset($_GET['printable'])) { $flags .= $sep.'printable'; $sep = '&'; } |
|
89 if(isset($_GET['theme'])) { $flags .= $sep.'theme='.$session->theme; $sep = '&'; } |
|
90 if(isset($_GET['style'])) { $flags .= $sep.'style='.$session->style; $sep = '&'; } |
|
91 if(defined('ENANO_BASE_CLASSES_INITIALIZED')) $url = $session->append_sid(contentPath.$paths->nslist[$n].$t.$flags); |
|
92 else $url = contentPath.$n.':'.$t.$flags; |
|
93 if($query) |
|
94 { |
|
95 if(strstr($url, '?')) $sep = '&'; |
|
96 else $sep = '?'; |
|
97 $url = $url . $sep . $query . $flags; |
|
98 } |
|
99 $baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST']; |
220 $baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST']; |
100 $url = $baseprot . $url; |
221 $url = $baseprot . $url; |
|
222 |
101 return ($escape) ? htmlspecialchars($url) : $url; |
223 return ($escape) ? htmlspecialchars($url) : $url; |
102 } |
224 } |
103 |
225 |
104 /** |
226 /** |
105 * Redirect the user to the specified URL. |
227 * Redirect the user to the specified URL. |