Mercurial > hg > fapweb
annotate msitegen.inc.php @ 813:c635887048aa
Apply intval() to data when checking type.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 24 Nov 2014 18:26:22 +0200 |
parents | 8083b39d3bde |
children | 83ac4155efe2 |
rev | line source |
---|---|
0 | 1 <? |
2 // | |
571
ce11ea112a65
Change the header blurb a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
569
diff
changeset
|
3 // FAPWeb - Simple Web-based Demoparty Management System |
33 | 4 // Generic and miscellaneous site support code |
565 | 5 // (C) Copyright 2012-2014 Tecnic Software productions (TNSP) |
0 | 6 // |
9
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
7 |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
8 // Globals and definitions |
0 | 9 $errorSet = FALSE; |
210 | 10 $errorMsgs = array(); |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
11 $statusSet = 0; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
12 $statusMsg = ""; |
0 | 13 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
14 // Value types |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
15 define("VT_STR", 1); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
16 define("VT_INT", 2); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
17 define("VT_BOOL", 3); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
18 define("VT_TEXT", 4); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
19 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
20 // Validation check types |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
21 define("CHK_TYPE", 1); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
22 define("CHK_ISLT", 2); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
23 define("CHK_ISGT", 3); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
24 define("CHK_ISEQ", 4); |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
25 define("CHK_GTEQ", 5); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
26 define("CHK_LTEQ", 6); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
27 define("CHK_RANGE", 7); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
28 define("CHK_CUSTOM", 8); |
810
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
29 define("CHK_ARRAY", 9); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
30 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
31 |
173
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
32 function stDebug($msg) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
33 { |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
34 if (stGetSetting("debug")) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
35 error_log($msg); |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
36 } |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
37 |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
38 |
0 | 39 function stError($msg) |
40 { | |
210 | 41 global $errorSet, $errorMsgs; |
0 | 42 $errorSet = TRUE; |
210 | 43 $errorMsgs[] = $msg; |
812
8083b39d3bde
Return FALSE from stError() functions, as a convenience.
Matti Hamalainen <ccr@tnsp.org>
parents:
811
diff
changeset
|
44 return FALSE; |
0 | 45 } |
46 | |
47 | |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
48 function stSetStatus($status, $msg) |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
49 { |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
50 global $statusSet, $statusMsg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
51 $statusMsg = $msg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
52 $statusSet = $status; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
53 } |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
54 |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
55 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
56 function stDumpAJAXStatusErrors() |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
57 { |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
58 global $errorSet, $errorMsgs, $statusSet, $statusMsg; |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
59 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
60 if ($errorSet && !$statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
61 stSetStatus(902, "Error"); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
62 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
63 if ($statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
64 { |
229 | 65 header("HTTP/1.0 ".$statusSet." ".$statusMsg); |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
66 header("Status: ".$statusSet." ".$statusMsg); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
67 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
68 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
69 if ($errorSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
70 { |
559 | 71 echo |
72 "<h1>Following errors occured</h1>\n". | |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
73 "<ul>\n"; |
559 | 74 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
75 foreach ($errorMsgs as $msg) |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
76 echo " <li>".chentities($msg)."</li>\n"; |
559 | 77 |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
78 echo "</ul>\n"; |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
79 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
80 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
81 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
82 |
0 | 83 function stCheckHTTPS() |
84 { | |
85 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
86 } | |
87 | |
88 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
89 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
91 header("Cache-Control: must-revalidate, no-store, private"); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
92 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
93 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
94 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
95 |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
96 function stGetSQLSettingData($item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
97 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
98 switch ($item["vtype"]) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
99 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
100 case VT_INT: return intval($item["vint"]); |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
101 case VT_BOOL: return intval($item["vint"]) ? true : false; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
102 case VT_STR: return $item["vstr"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
103 case VT_TEXT: return $item["vtext"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
104 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
105 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
106 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
107 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
108 function stGetSettingSQL($item, $val) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
109 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
110 global $db; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
111 switch ($item["vtype"]) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
112 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
113 case VT_INT: return "vint=".intval($val); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
114 case VT_BOOL: return "vint=".($val ? "1" : "0"); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
115 case VT_STR: return "vstr=".$db->quote($val); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
116 case VT_TEXT: return "vtext=".$db->quote($val); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
117 default: return FALSE; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
118 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
119 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
120 |
293 | 121 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
122 function stReloadSettings() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
123 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
124 global $siteSettings; |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
125 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
126 if (($res = stExecSQL("SELECT * FROM settings")) !== FALSE) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
127 { |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
128 foreach ($res as $item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
129 $siteSettings[$item["key"]] = stGetSQLSettingData($item); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
130 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
131 else |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
132 die("Error fetching site settings."); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
133 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
134 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
135 |
538 | 136 function stGetSetting($name, $default = FALSE) |
0 | 137 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
138 global $siteSettings; |
0 | 139 if (isset($siteSettings[$name])) |
140 return $siteSettings[$name]; | |
141 else | |
538 | 142 if ($default !== FALSE) |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
143 return $default; |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
144 else |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
145 { |
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
146 error_log("No config value for '".$name."'"); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
147 die("No config value for '".$name."'.\n"); |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
148 } |
0 | 149 } |
150 | |
151 | |
152 function stChkSetting($name) | |
153 { | |
154 global $siteSettings; | |
155 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
156 } | |
157 | |
158 | |
159 function dhentities($str) | |
160 { | |
674 | 161 return str_replace(array("<",">"), array("<", ">"), |
162 htmlentities($str, ENT_NOQUOTES, "UTF-8")); | |
0 | 163 } |
164 | |
165 | |
166 function chentities($str) | |
167 { | |
168 return htmlentities($str, ENT_NOQUOTES, "UTF-8"); | |
169 } | |
170 | |
485 | 171 |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
172 function ihentities($str) |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
173 { |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
174 return htmlentities($str, ENT_QUOTES, "UTF-8"); |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
175 } |
0 | 176 |
485 | 177 |
676 | 178 // |
179 // Helper functions for form/HTML elements | |
180 // XXX/TODO .. this name/id/prefix mess needs to be cleaned up. | |
181 // | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
182 function stGetIDName($name, $id, $prefix = "") |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
183 { |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
184 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
185 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : ""). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
186 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : ""); |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
187 } |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
188 |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
189 |
0 | 190 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") |
191 { | |
192 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
193 "<input ".$extra." type=\"checkbox\" ".stGetIDName($name, $id, $prefix). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
194 ($checked ? "checked=\"checked\" " : "")." />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
195 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
0 | 196 } |
197 | |
198 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
199 function stGetFormRadioButtonInput($name, $id, $prefix, $value, $checked, $label, $extra = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
200 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
201 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
202 "<input ".$extra." type=\"radio\" ".stGetIDName($name, $id, $prefix). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
203 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
204 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
205 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
206 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
207 |
0 | 208 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") |
209 { | |
210 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
211 "<input type=\"button\" ".stGetIDName($name, $id, $prefix). |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
212 "value=\" ".ihentities($label)." \" ". |
0 | 213 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
214 } | |
215 | |
216 | |
680
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
217 function stGetFormButtonElement($name, $id, $prefix, $label, $onclick = "") |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
218 { |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
219 return |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
220 "<button class=\"button\" ".stGetIDName($name, $id, $prefix)." type=\"button\"". |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
221 ($onclick != "" ? " onClick=\"".$onclick."\"" : "")."> ".chentities($label)." </button>"; |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
222 } |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
223 |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
224 |
0 | 225 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") |
226 { | |
227 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
228 "<textarea ".$extra." ".stGetIDName($name, $id, $prefix). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
229 "rows=\"".$rows."\" cols=\"".$cols."\">". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
230 (isset($value) ? ihentities($value) : ""). |
0 | 231 "</textarea>"; |
232 } | |
233 | |
234 | |
235 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
236 { | |
237 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
238 "<input ".$extra." type=\"text\" ".stGetIDName($name, $id, $prefix). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
239 "size=\"".$size."\" maxlength=\"".$len."\"". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
240 (isset($value) ? " value=\"".ihentities($value)."\"" : ""). |
0 | 241 " />"; |
242 } | |
243 | |
244 | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
245 function stGetFormPasswordInput($name, $id, $prefix, $extra = "") |
0 | 246 { |
247 return | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
248 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." ".$extra." />"; |
0 | 249 } |
250 | |
251 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
252 function stGetFormSubmitInput($name, $label, $onclick = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
253 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
254 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
255 "<input type=\"submit\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
256 "\" value=\" ".ihentities($label)." \" ". |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
257 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
258 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
259 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
260 |
0 | 261 function stGetFormHiddenInput($name, $value) |
262 { | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
263 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
264 "<input type=\"hidden\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
265 "\" value=\"".ihentities($value)."\" />"; |
0 | 266 } |
267 | |
268 | |
771
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
269 function stGetFormStart($name, $action = FALSE, $method = FALSE, $extra = FALSE) |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
270 { |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
271 $str = |
771
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
272 "<form name=\"".$name."\"". |
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
273 ($action !== FALSE ? " action=\"".$action."\"" : ""). |
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
274 " method=\"".($method !== FALSE ? $method : "post")."\"". |
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
275 ($extra !== FALSE ? " ".$extra : "").">\n"; |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
276 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
277 if (($csrfID = stGetSessionItem("csrfID", FALSE)) !== FALSE) |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
278 $str .= stGetFormHiddenInput("csrfID", $csrfID)."\n"; |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
279 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
280 return $str; |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
281 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
282 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
283 |
675 | 284 function stGetFormOptionListStart($id, $indent, $outer, $size = 10, $onChange = "") |
0 | 285 { |
286 return | |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
287 ($outer ? $indent."<div id=\"".$id."\">\n" : ""). |
638
79bbd09114c5
Allow selection list size to be zero.
Matti Hamalainen <ccr@tnsp.org>
parents:
637
diff
changeset
|
288 $indent."<select class=\"selectBox\" id=\"".$id."Sel\"". |
79bbd09114c5
Allow selection list size to be zero.
Matti Hamalainen <ccr@tnsp.org>
parents:
637
diff
changeset
|
289 ($size > 0 ? " size=\"".$size."\"" : ""). |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
290 ($onChange != "" ? " onChange=\"".$onChange."\"" : "").">\n"; |
0 | 291 } |
292 | |
293 | |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
294 function stGetFormOptionListItem($indent, $value, $active, $name) |
0 | 295 { |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
296 return |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
297 $indent."<option value=\"".$value."\"". |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
298 ($active ? " selected=\"selected\"" : ""). |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
299 ">".str_replace(" ", " ", chentities($name))."</option>\n"; |
0 | 300 } |
301 | |
302 | |
675 | 303 function stGetFormOptionListEnd($indent, $outer) |
0 | 304 { |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
305 return |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
306 $indent."</select>\n". |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
307 ($outer ? $indent."</div>\n" : ""); |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
308 } |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
309 |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
310 |
752
c714140541d5
Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents:
747
diff
changeset
|
311 function stGetFormOptionListFromArray($id, $indent, $outer, $data, $active, $size = 10, $arrIndex = 0, $onChange = "") |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
312 { |
675 | 313 $str = stGetFormOptionListStart($id, $indent, $outer, $size, $onChange); |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
314 |
639
26ec29d2e728
Elements of arrays passed to selection list can be arrays themselves, the
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
315 foreach ($data as $key => $value) |
26ec29d2e728
Elements of arrays passed to selection list can be arrays themselves, the
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
316 { |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
317 $str .= stGetFormOptionListItem($indent." ", $key, |
642 | 318 ($key == $active), |
752
c714140541d5
Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents:
747
diff
changeset
|
319 is_array($value) ? $value[$arrIndex] : $value); |
639
26ec29d2e728
Elements of arrays passed to selection list can be arrays themselves, the
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
320 } |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
321 |
675 | 322 return $str.stGetFormOptionListEnd($indent, $outer); |
0 | 323 } |
324 | |
325 | |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
326 function stErrorStrF($fmt) |
0 | 327 { |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
328 $argc = func_num_args(); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
329 $argv = func_get_args(); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
330 |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
331 $len = strlen($fmt); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
332 $str = ""; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
333 $argn = 1; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
334 for ($pos = 0; $pos < $len; $pos++) |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
335 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
336 if ($fmt[$pos] == "%") |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
337 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
338 $pos++; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
339 if ($fmt[$pos] == "%") |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
340 $str .= "%"; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
341 else |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
342 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
343 $n = intval($fmt[$pos]); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
344 if ($n >= 1 && $n < $argc) |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
345 $str .= $argv[$n]; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
346 else |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
347 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
348 error_log("Invalid stErrorStrF() format string, arg #".$n. |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
349 " referenced, but only has ".$argc." arguments: '".$fmt."'\n"); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
350 return FALSE; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
351 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
352 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
353 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
354 else |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
355 $str .= $fmt[$pos]; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
356 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
357 |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
358 stError($str); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
359 return FALSE; |
0 | 360 } |
361 | |
362 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
363 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
364 // Check and validate one item from $_REQUEST[], based on |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
365 // list of validation conditions. For example: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
366 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
367 // stChkRequestItem("name", FALSE, |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
368 // array(CHK_ISGT, VT_STR, 0, "Handle / name not given."), |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
369 // array(CHK_ISGT, VT_STR, 3, "Handle / name too short, should be 3 characters or more."), |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
370 // array(CHK_LTEQ, VT_STR, SET_LEN_USERNAME, "Handle / name is too long, should be less than ".SET_LEN_USERNAME." characters."), |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
371 // array(CHK_RANGE, VT_STR, array(3, SET_LEN_USERNAME), "Ulululu!"), |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
372 // ^- ranges specified as array of MIN and MAX values (inclusive) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
373 // |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
374 // array(CHK_CUSTOM, VT_STR, function($value) { return FALSE; }, "Error! Error!"), |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
375 // ^- can be any callable/anonymous function etc. |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
376 // ... |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
377 // |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
378 function stChkRequestDataItem($type, $value, $cmp) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
379 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
380 switch ($type) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
381 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
382 case CHK_ISLT : return $value < $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
383 case CHK_ISGT : return $value > $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
384 case CHK_ISEQ : return $value == $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
385 case CHK_LTEQ : return $value <= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
386 case CHK_GTEQ : return $value >= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
387 case CHK_RANGE: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
388 if (!is_array($cmp)) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
389 return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
390 else |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
391 return ($value >= $cmp[0] && $value <= $cmp[1]); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
392 break; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
393 default: return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
394 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
395 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
396 |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
397 |
670
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
398 function stDoCheckRequestItem($name, &$sdata, $nindex, $argc, $argv) |
0 | 399 { |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
400 if (stGetSetting("debug")) |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
401 { |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
402 if (!isset($_REQUEST[$name])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
403 return stErrorStrF("Required data item '%1' not set.", $name); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
404 |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
405 $data = trim($_REQUEST[$name]); |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
406 } |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
407 else |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
408 { |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
409 if (!isset($_POST[$name])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
410 return stErrorStrF("Required data item '%1' not set.", $name); |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
411 |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
412 $data = trim($_POST[$name]); |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
413 } |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
414 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
415 $slen = strlen($data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
416 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
417 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
418 // Go through list of validation checks |
670
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
419 for ($argn = $nindex; $argn < $argc; $argn++) |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
420 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
421 // Act according to check type |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
422 $check = $argv[$argn]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
423 switch ($check[0]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
424 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
425 case CHK_TYPE: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
426 // Check type of the data |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
427 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
428 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
429 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
430 if ($slen == 0) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
431 return stErrorStrF($check[2], $slen); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
432 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
433 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
434 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
435 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
436 if ($slen == 0 || !is_numeric($data)) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
437 return stErrorStrF($check[2], $data); |
813
c635887048aa
Apply intval() to data when checking type.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
438 else |
c635887048aa
Apply intval() to data when checking type.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
439 $data = intval($data); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
440 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
441 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
442 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
443 |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
444 case CHK_ISLT: case CHK_ISGT: case CHK_ISEQ: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
445 case CHK_GTEQ: case CHK_LTEQ: case CHK_RANGE: |
810
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
446 case CHK_ARRAY: |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
447 // Check length or value of the data |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
448 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
449 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
450 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
451 case VT_TEXT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
452 // Strings get their length checked |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
453 if (!stChkRequestDataItem($check[0], $slen, $check[2])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
454 return stErrorStrF($check[3], $slen, $check[2]); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
455 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
456 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
457 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
458 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
459 // Integer values checked against .. value |
292 | 460 if (!stChkRequestDataItem($check[0], intval($data), $check[2])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
461 return stErrorStrF($check[3], intval($data), $check[2]); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
462 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
463 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
464 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
465 |
810
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
466 case CHK_ARRAY: |
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
467 if (!in_array($data, $check[1], TRUE)) |
811 | 468 return stErrorStrF($check[3], $data); |
810
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
469 break; |
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
470 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
471 case CHK_CUSTOM: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
472 // Call a custom function (or closure) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
473 $func = $check[1]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
474 if (!is_callable($func) || !$func($data)) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
475 return stErrorStrF($check[2], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
476 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
477 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
478 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
479 |
436
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
480 if ($sdata !== FALSE) |
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
481 $sdata = $data; |
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
482 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
483 return TRUE; |
0 | 484 } |
485 | |
486 | |
670
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
487 function stChkRequestItem($name, &$sdata) |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
488 { |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
489 return stDoCheckRequestItem($name, $sdata, 2, func_num_args(), func_get_args()); |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
490 } |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
491 |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
492 |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
493 function stChkRequestItemFail($name, &$sdata, &$sfail) |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
494 { |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
495 $sres = stDoCheckRequestItem($name, $sdata, 3, func_num_args(), func_get_args()); |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
496 if ($sres !== TRUE) $sfail = FALSE; |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
497 return $sres; |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
498 } |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
499 |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
500 |
357
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
501 function stGetRequestItem($name, $default = "", $allowGet = FALSE) |
0 | 502 { |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
503 if ($allowGet || stGetSetting("debug")) |
357
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
504 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default; |
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
505 else |
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
506 return isset($_POST[$name]) ? trim($_POST[$name]) : $default; |
0 | 507 } |
508 | |
509 | |
486 | 510 function stConnectSQLDBSpec($dbspec) |
511 { | |
512 try { | |
513 $dbh = new PDO($dbspec); | |
514 } | |
515 catch (PDOException $e) { | |
516 error_log("Could not connect to SQL database: ".$e->getMessage()."."); | |
517 return FALSE; | |
518 } | |
519 return $dbh; | |
520 } | |
521 | |
522 | |
523 function stDBGetSQLParam($dbh, $type, $value) | |
524 { | |
525 switch ($type) | |
526 { | |
527 case "d": return intval($value); | |
528 case "s": return $dbh->quote($value); | |
529 case "b": return intval($value) ? 1 : 0; | |
530 case "D": return intval(stGetRequestItem($value)); | |
531 case "S": return $dbh->quote(stGetRequestItem($value)); | |
532 case "Q": return $dbh->quote(stGetRequestItem($value)); | |
533 case "B": return intval(stGetRequestItem($value)) ? 1 : 0; | |
534 } | |
535 } | |
536 | |
537 | |
501 | 538 function stLogSQLError($dbh, $sql) |
0 | 539 { |
619
2b4ea04adeea
Improve SQL warning logging.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
540 error_log("SQL error '".implode("; ", $dbh->errorInfo())."' in statement: \"".$sql."\""); |
0 | 541 } |
542 | |
543 | |
544 function stConnectSQLDB() | |
545 { | |
546 global $db; | |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
547 try { |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
548 $db = new PDO(stGetSetting("sqlDB"), |
538 | 549 stGetSetting("sqlUsername", NULL), |
550 stGetSetting("sqlPassword", NULL), | |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
551 stGetSetting("sqlOptions", array())); |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
552 } |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
553 catch (PDOException $e) { |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
554 error_log("Could not connect to SQL database: ".$e->getMessage()."."); |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
555 return FALSE; |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
556 } |
486 | 557 $db = stConnectSQLDBSpec(stGetSetting("sqlDB")); |
558 return ($db !== false); | |
0 | 559 } |
560 | |
561 | |
487 | 562 function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs) |
0 | 563 { |
487 | 564 $sql = array(); |
565 foreach ($pairs as $name => $attr) | |
0 | 566 { |
487 | 567 $sql[] = $name."=".stDBGetSQLParam($dbh, $attr, $name); |
0 | 568 } |
487 | 569 return |
570 "UPDATE ".$table." SET ".implode(",", $sql). | |
571 ($cond != "" ? " ".$cond : ""); | |
0 | 572 } |
573 | |
574 | |
487 | 575 function stDBPrepareSQL($dbh) |
0 | 576 { |
577 $argc = func_num_args(); | |
578 $argv = func_get_args(); | |
87 | 579 |
487 | 580 $fmt = $argv[1]; |
0 | 581 $len = strlen($fmt); |
582 $sql = ""; | |
487 | 583 $argn = 2; |
584 for ($pos = 0; $pos < $len; $pos++) | |
0 | 585 { |
586 if ($fmt[$pos] == "%") | |
587 { | |
588 if ($argn < $argc) | |
501 | 589 $sql .= stDBGetSQLParam($dbh, $fmt[++$pos], $argv[$argn++]); |
0 | 590 else |
591 { | |
592 error_log("Invalid SQL statement format string '".$fmt. | |
593 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
594 return FALSE; | |
595 } | |
596 } | |
597 else | |
598 $sql .= $fmt[$pos]; | |
599 } | |
485 | 600 |
0 | 601 return $sql; |
602 } | |
603 | |
604 | |
487 | 605 function stPrepareSQL() |
0 | 606 { |
487 | 607 global $db; |
608 $argc = func_num_args(); | |
609 $argv = func_get_args(); | |
610 | |
611 $fmt = $argv[0]; | |
612 $len = strlen($fmt); | |
613 $sql = ""; | |
614 $argn = 1; | |
615 for ($pos = 0; $pos < $len; $pos++) | |
0 | 616 { |
487 | 617 if ($fmt[$pos] == "%") |
618 { | |
619 if ($argn < $argc) | |
492 | 620 $sql .= stDBGetSQLParam($db, $fmt[++$pos], $argv[$argn++]); |
487 | 621 else |
622 { | |
623 error_log("Invalid SQL statement format string '".$fmt. | |
624 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
625 return FALSE; | |
626 } | |
627 } | |
628 else | |
629 $sql .= $fmt[$pos]; | |
0 | 630 } |
487 | 631 |
632 return $sql; | |
0 | 633 } |
634 | |
635 | |
547
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
636 function stDBExecSQLInsert($dbh, $sql) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
637 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
638 switch ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME)) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
639 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
640 case "pgsql": |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
641 if (($res = stDBFetchSQLColumn($dbh, $sql." RETURNING id")) !== false) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
642 return $res; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
643 else |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
644 return FALSE; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
645 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
646 default: |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
647 if (stDBExecSQL($dbh, $sql) !== false) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
648 return $dbh->lastInsertId(); |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
649 else |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
650 return FALSE; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
651 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
652 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
653 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
654 |
487 | 655 function stDBExecSQL($dbh, $sql) |
0 | 656 { |
487 | 657 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 658 return $res; |
659 else | |
660 { | |
501 | 661 stLogSQLError($dbh, $sql); |
0 | 662 stError("Oh noes! SQL error #23!"); |
663 return FALSE; | |
664 } | |
665 } | |
666 | |
667 | |
487 | 668 function stDBFetchSQL($dbh, $sql) |
0 | 669 { |
487 | 670 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 671 return $res->fetch(); |
672 else | |
673 { | |
501 | 674 stLogSQLError($dbh, $sql); |
0 | 675 stError("Oh noes! SQL error #31!"); |
676 return FALSE; | |
677 } | |
678 } | |
679 | |
680 | |
487 | 681 function stDBFetchSQLColumn($dbh, $sql, $column = 0) |
0 | 682 { |
487 | 683 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 684 return $res->fetchColumn($column); |
685 else | |
686 { | |
501 | 687 stLogSQLError($dbh, $sql); |
0 | 688 stError("Oh noes! SQL error #81!"); |
689 return FALSE; | |
690 } | |
691 } | |
692 | |
693 | |
487 | 694 function stPrepareSQLUpdate($table, $cond, $pairs) |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
695 { |
487 | 696 global $db; |
697 return stDBPrepareSQLUpdate($db, $table, $cond, $pairs); | |
698 } | |
699 | |
700 | |
547
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
701 function stExecSQLInsert($sql) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
702 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
703 global $db; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
704 return stDBExecSQLInsert($db, $sql); |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
705 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
706 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
707 |
492 | 708 function stExecSQL($sql) |
487 | 709 { |
710 global $db; | |
711 return stDBExecSQL($db, $sql); | |
712 } | |
713 | |
714 | |
492 | 715 function stFetchSQL($sql) |
487 | 716 { |
717 global $db; | |
718 return stDBFetchSQL($db, $sql); | |
719 } | |
720 | |
721 | |
722 function stFetchSQLColumn($sql, $column = 0) | |
723 { | |
724 global $db; | |
725 return stDBFetchSQLColumn($db, $sql, $column); | |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
726 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
727 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
728 |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
729 function stDBBeginTransaction($dbh = FALSE) |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
730 { |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
731 global $db; |
579 | 732 return stDBExecSQL(($dbh !== FALSE) ? $dbh : $db, "BEGIN TRANSACTION"); |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
733 } |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
734 |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
735 |
607
e78d90ca4f4a
Use default database handle for transaction commits if none provided.
Matti Hamalainen <ccr@tnsp.org>
parents:
579
diff
changeset
|
736 function stDBCommitTransaction($dbh = FALSE) |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
737 { |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
738 global $db; |
579 | 739 return stDBExecSQL(($dbh !== FALSE) ? $dbh : $db, "COMMIT"); |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
740 } |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
741 |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
742 |
577
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
743 function stDBGetTableSchema($dbh, $data) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
744 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
745 $res = array(); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
746 $driver = $dbh->getAttribute(PDO::ATTR_DRIVER_NAME); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
747 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
748 foreach ($data as $col) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
749 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
750 $tmp = array(); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
751 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
752 switch ($driver) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
753 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
754 case "pgsql": |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
755 foreach ($col as $elem) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
756 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
757 // For Postgres, use SERIAL for autoincrement |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
758 if ($elem == "AUTOINCREMENT") |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
759 $tmp[1] = "SERIAL"; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
760 else |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
761 $tmp[] = $elem; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
762 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
763 break; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
764 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
765 case "mysql": |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
766 foreach ($col as $elem) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
767 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
768 if ($elem != "AUTOINCREMENT") |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
769 $tmp[] = "AUTO_INCREMENT"; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
770 else |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
771 $tmp[] = $elem; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
772 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
773 break; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
774 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
775 case "sqlite": |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
776 $tmp = $col; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
777 break; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
778 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
779 default: |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
780 die("Don't know how to handle PDO driver '".$driver."' yet.\n"); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
781 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
782 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
783 $res[] = implode(" ", $tmp); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
784 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
785 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
786 return implode(", ", $res); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
787 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
788 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
789 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
790 function stDBCreateOneTable($dbh, $name, $schema) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
791 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
792 // echo "CREATE TABLE ".$name ." (".$schema.")\n"; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
793 return (stDBExecSQL($dbh, "CREATE TABLE ".$name." (".$schema.")") !== FALSE) ? TRUE : FALSE; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
794 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
795 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
796 |
803
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
797 function stSubStrCmp($str, $cmp, $send = FALSE) |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
798 { |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
799 if ($send) |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
800 return substr($str, -strlen($cmp)) == $cmp; |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
801 else |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
802 return substr($str, 0, strlen($cmp)) == $cmp; |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
803 } |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
804 |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
805 |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
806 function stStrChop($str, $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
807 { |
569
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
808 return (mb_strlen($str) > $len) ? mb_substr($str, 0, $len - 3)."..." : $str; |
558
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
809 } |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
810 |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
811 |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
812 function stStrChopPad($str, $len) |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
813 { |
569
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
814 $tmp = stStrChop($str, $len); |
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
815 for ($i = mb_strlen($tmp); $i < $len; $i++) |
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
816 $tmp .= " "; |
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
817 return $tmp; |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
818 } |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
819 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
820 |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
821 function cmPrintCSSLine($filename, $media = FALSE) |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
822 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
823 echo |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
824 " <link rel=\"stylesheet\" href=\"".$filename. |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
825 "\" type=\"text/css\" ".($media !== FALSE ? "media=\"".$media."\"": "")." />\n"; |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
826 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
827 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
828 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
829 function cmPrintPageHeader($pageTitle, $pageExtra = "", $useContents = TRUE) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
830 { |
575
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
831 global $pageCSS, $pageCSSIndex, $pageCharset, $pageAuthor, $pageCSSData, $pageUrchin; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
832 |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
833 if (!isset($pageCSS)) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
834 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
835 if (!isset($pageCSSData)) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
836 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
837 $pageCSSData = array( |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
838 "cookie" => "docscss", |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
839 "prefix" => "/css/docs", |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
840 ); |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
841 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
842 |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
843 if (isset($_GET["css"])) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
844 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
845 $pageCSSIndex = intval($_GET["css"]); |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
846 setcookie($pageCSSData["cookie"], $pageCSSIndex, time() + 365*24*60*60, "/"); // expire in a year |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
847 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
848 else |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
849 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
850 $pageCSSIndex = isset($_COOKIE[$pageCSSData["cookie"]]) ? intval($_COOKIE[$pageCSSData["cookie"]]) : 1; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
851 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
852 $pageCSS = $pageCSSData["prefix"].$pageCSSIndex.".css"; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
853 } |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
854 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
855 echo |
363 | 856 "<!DOCTYPE html>\n". |
178 | 857 "<html>\n". |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
858 "<head>\n". |
232 | 859 " <meta charset=\"".$pageCharset."\">\n". |
362
38dfe9e0a017
Add meta-equiv for document content type.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
860 " <meta http-equiv=\"Content-type\" content=\"text/html;charset=".$pageCharset."\">\n". |
232 | 861 " <title>".strip_tags($pageTitle)."</title>\n". |
862 $pageExtra; | |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
863 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
864 if (is_array($pageCSS)) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
865 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
866 foreach ($pageCSS as $uri => $media) |
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
867 cmPrintCSSLine($uri, $media); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
868 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
869 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
870 { |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
871 cmPrintCSSLine($pageCSS, FALSE); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
872 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
873 |
232 | 874 echo |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
875 "</head>\n". |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
876 "<body>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
877 |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
878 if (isset($pageUrchin) && file_exists($pageUrchin)) |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
879 require_once $pageUrchin; |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
880 else |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
881 if (file_exists("urchin.inc.php")) |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
882 require_once "urchin.inc.php"; |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
883 |
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
884 echo "<div id=\"messageBox\"></div>\n"; |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
885 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
886 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
887 echo "<div id=\"contents\">\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
888 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
889 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
890 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
891 function cmPrintPageFooter($useContents = TRUE) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
892 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
893 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
894 echo "</div>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
895 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
896 echo "</body>\n</html>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
897 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
898 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
899 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
900 function cmQM($msg) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
901 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
902 global $pageTranslations, $pageLang; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
903 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
904 if (isset($pageTranslations[$msg]) && isset($pageTranslations[$msg][$pageLang])) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
905 $str = $pageTranslations[$msg][$pageLang]; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
906 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
907 $str = $msg; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
908 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
909 foreach (func_get_args() as $argn => $argv) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
910 $str = preg_replace("/\%".$argn."/", $argv, $str); |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
911 return $str; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
912 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
913 |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
914 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
915 // |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
916 // CLI related helper functions |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
917 // |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
918 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
919 // Check if we are running from commandline or not |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
920 function stCheckCLIExec($fail = TRUE) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
921 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
922 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
923 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
924 if ($fail) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
925 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
926 header("Status: 404 Not Found"); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
927 die(); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
928 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
929 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
930 return TRUE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
931 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
932 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
933 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
934 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
935 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
936 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
937 function stCArg($index) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
938 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
939 global $argc, $argv; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
940 if ($index < $argc) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
941 return $argv[$index]; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
942 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
943 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
944 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
945 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
946 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
947 function stCArgLC($index) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
948 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
949 global $argc, $argv; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
950 if ($index < $argc) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
951 return strtolower($argv[$index]); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
952 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
953 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
954 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
955 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
956 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
957 function stGetDBMeta($dbh, $name) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
958 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
959 if (($item = stDBFetchSQL($dbh, "SELECT * FROM dbmeta WHERE key=".$dbh->quote($name))) === FALSE) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
960 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
961 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
962 return stGetSQLSettingData($item); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
963 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
964 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
965 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
966 function stSetDBMeta($dbh, $name, $value) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
967 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
968 if (($item = stDBFetchSQL($dbh, "SELECT * FROM dbmeta WHERE key=".$dbh->quote($name))) === FALSE) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
969 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
970 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
971 $sql = "UPDATE dbmeta SET ".stGetSettingSQL($item, $value)." WHERE key=".$dbh->quote($name); |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
972 return stDBExecSQL($dbh, $sql); |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
973 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
974 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
975 |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
976 // |
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
977 // Global locale initialization |
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
978 // |
562 | 979 if (!isset($localeInited) || !$localeInited) |
980 { | |
981 $localeInited = TRUE; | |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
982 $pageCharset = "UTF-8"; |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
983 |
562 | 984 mb_internal_encoding($pageCharset); |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
985 |
562 | 986 $tmp = "en_US.".strtolower(str_replace("-", "", $pageCharset)); |
987 setlocale(LC_ALL, $tmp); | |
988 } | |
0 | 989 ?> |