Mercurial > hg > fapweb
annotate msitegen.inc.php @ 575:1ec34a220df3
Another merge from generic custom site branch.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 20 Sep 2014 02:03:07 +0300 |
parents | 463189fc05ed |
children | ba521a7e7653 |
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); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
29 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
30 |
173
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
31 function stDebug($msg) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
32 { |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
33 if (stGetSetting("debug")) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
34 error_log($msg); |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
35 } |
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 |
0 | 38 function stError($msg) |
39 { | |
210 | 40 global $errorSet, $errorMsgs; |
0 | 41 $errorSet = TRUE; |
210 | 42 $errorMsgs[] = $msg; |
0 | 43 } |
44 | |
45 | |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
46 function stSetStatus($status, $msg) |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
47 { |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
48 global $statusSet, $statusMsg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
49 $statusMsg = $msg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
50 $statusSet = $status; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
51 } |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
52 |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
53 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
54 function stDumpAJAXStatusErrors() |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
55 { |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
56 global $errorSet, $errorMsgs, $statusSet, $statusMsg; |
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 if ($errorSet && !$statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
59 stSetStatus(902, "Error"); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
60 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
61 if ($statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
62 { |
229 | 63 header("HTTP/1.0 ".$statusSet." ".$statusMsg); |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
64 header("Status: ".$statusSet." ".$statusMsg); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
65 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
66 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
67 if ($errorSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
68 { |
559 | 69 echo |
70 "<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
|
71 "<ul>\n"; |
559 | 72 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
73 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
|
74 echo " <li>".chentities($msg)."</li>\n"; |
559 | 75 |
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 "</ul>\n"; |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
77 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
78 } |
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 |
0 | 81 function stCheckHTTPS() |
82 { | |
83 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
84 } | |
85 | |
86 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
87 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
88 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
89 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
|
90 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
|
91 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
92 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
93 |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
94 function stGetSQLSettingData($item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
95 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
96 switch ($item["vtype"]) |
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 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
|
99 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
|
100 case VT_STR: return $item["vstr"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
101 case VT_TEXT: return $item["vtext"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
102 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
103 } |
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 function stGetSettingSQL($item, $val) |
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 global $db; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
109 switch ($item["vtype"]) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
110 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 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
|
115 default: return FALSE; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
116 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
117 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
118 |
293 | 119 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
120 function stReloadSettings() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
121 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
122 global $siteSettings; |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
123 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
124 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
|
125 { |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
126 foreach ($res as $item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
127 $siteSettings[$item["key"]] = stGetSQLSettingData($item); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
128 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
129 else |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
130 die("Error fetching site settings."); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
131 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
132 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
133 |
538 | 134 function stGetSetting($name, $default = FALSE) |
0 | 135 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
136 global $siteSettings; |
0 | 137 if (isset($siteSettings[$name])) |
138 return $siteSettings[$name]; | |
139 else | |
538 | 140 if ($default !== FALSE) |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
141 return $default; |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
142 else |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
143 { |
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
144 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
|
145 die("No config value for '".$name."'.\n"); |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
146 } |
0 | 147 } |
148 | |
149 | |
150 function stChkSetting($name) | |
151 { | |
152 global $siteSettings; | |
153 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
154 } | |
155 | |
156 | |
157 function dhentities($str) | |
158 { | |
159 return str_replace(array("<",">"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8")); | |
160 } | |
161 | |
162 | |
163 function chentities($str) | |
164 { | |
165 return htmlentities($str, ENT_NOQUOTES, "UTF-8"); | |
166 } | |
167 | |
485 | 168 |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
169 function ihentities($str) |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
170 { |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
171 return htmlentities($str, ENT_QUOTES, "UTF-8"); |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
172 } |
0 | 173 |
485 | 174 |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
175 function stGetIDName($name, $id, $prefix = "") |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
176 { |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
177 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
178 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : ""). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
179 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : ""); |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
180 } |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
181 |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
182 |
0 | 183 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") |
184 { | |
185 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
186 "<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
|
187 ($checked ? "checked=\"checked\" " : "")." />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
188 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
0 | 189 } |
190 | |
191 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
192 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
|
193 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
194 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
195 "<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
|
196 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
197 ($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
|
198 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
199 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
200 |
0 | 201 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") |
202 { | |
203 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
204 "<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
|
205 "value=\" ".ihentities($label)." \" ". |
0 | 206 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
207 } | |
208 | |
209 | |
210 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") | |
211 { | |
212 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
213 "<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
|
214 "rows=\"".$rows."\" cols=\"".$cols."\">". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
215 (isset($value) ? ihentities($value) : ""). |
0 | 216 "</textarea>"; |
217 } | |
218 | |
219 | |
220 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
221 { | |
222 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
223 "<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
|
224 "size=\"".$size."\" maxlength=\"".$len."\"". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
225 (isset($value) ? " value=\"".ihentities($value)."\"" : ""). |
0 | 226 " />"; |
227 } | |
228 | |
229 | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
230 function stGetFormPasswordInput($name, $id, $prefix, $extra = "") |
0 | 231 { |
232 return | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
233 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." ".$extra." />"; |
0 | 234 } |
235 | |
236 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
237 function stGetFormSubmitInput($name, $label, $onclick = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
238 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
239 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
240 "<input type=\"submit\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
241 "\" value=\" ".ihentities($label)." \" ". |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
242 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
243 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
244 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
245 |
0 | 246 function stGetFormHiddenInput($name, $value) |
247 { | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
248 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
249 "<input type=\"hidden\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
250 "\" value=\"".ihentities($value)."\" />"; |
0 | 251 } |
252 | |
253 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
254 function stGetFormStart($name, $action = "", $method = "post") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
255 { |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
256 $str = |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
257 "<form name=\"".$name."\" action=\"". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
258 ($action != "" ? $action : $name). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
259 "\" method=\"".$method."\">\n"; |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
260 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
261 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
|
262 $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
|
263 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
264 return $str; |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
265 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
266 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
267 |
0 | 268 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "") |
269 { | |
270 return | |
271 "<td class=\"".$name."\">". | |
272 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)). | |
273 "</td>"; | |
274 } | |
275 | |
276 | |
277 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") | |
278 { | |
279 echo " <tr><th>".chentities($text1)."</th><td>". | |
15
ea0f98a0bed8
Fix some issues and bugs caused by recent changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
280 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra). |
0 | 281 "</td><td>".chentities($text2)."</td></tr>\n"; |
282 } | |
283 | |
284 | |
285 function stPrintFormHiddenInput($name, $value) | |
286 { | |
287 echo " ".stGetFormHiddenInput($name, $value)."\n"; | |
288 } | |
289 | |
290 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
291 function stErrorStrF($msg, $data) |
0 | 292 { |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
293 stError($msg); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
294 return FALSE; |
0 | 295 } |
296 | |
297 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
298 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
299 // 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
|
300 // 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
|
301 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
302 // stChkRequestItem("name", FALSE, |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
303 // 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
|
304 // 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
|
305 // 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
|
306 // 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
|
307 // ^- 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
|
308 // |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
309 // 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
|
310 // ^- can be any callable/anonymous function etc. |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
311 // ... |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
312 // |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
313 function stChkRequestDataItem($type, $value, $cmp) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
314 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
315 switch ($type) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
316 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
317 case CHK_ISLT : return $value < $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
318 case CHK_ISGT : return $value > $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
319 case CHK_ISEQ : return $value == $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
320 case CHK_LTEQ : return $value <= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
321 case CHK_GTEQ : return $value >= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
322 case CHK_RANGE: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
323 if (!is_array($cmp)) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
324 return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
325 else |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
326 return ($value >= $cmp[0] && $value <= $cmp[1]); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
327 break; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
328 default: return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
329 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
330 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
331 |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
332 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
333 function stChkRequestItem($name, &$sdata) |
0 | 334 { |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
335 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
|
336 { |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
337 if (!isset($_REQUEST[$name])) |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
338 return stErrorStrF("Required data item '".$name."' not set.", $name); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
339 |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
340 $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
|
341 } |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
342 else |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
343 { |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
344 if (!isset($_POST[$name])) |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
345 return stErrorStrF("Required data item '".$name."' not set.", $name); |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
346 |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
347 $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
|
348 } |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
349 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
350 $slen = strlen($data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
351 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
352 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
353 // Go through list of validation checks |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
354 $argc = func_num_args(); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
355 $argv = func_get_args(); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
356 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
357 for ($argn = 2; $argn < $argc; $argn++) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
358 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
359 // 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
|
360 $check = $argv[$argn]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
361 switch ($check[0]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
362 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
363 case CHK_TYPE: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
364 // 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
|
365 switch ($check[1]) |
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 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
368 if ($slen == 0) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
369 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
|
370 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
371 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
372 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
373 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
374 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
|
375 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
|
376 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
377 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
378 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
379 |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
380 case CHK_ISLT: case CHK_ISGT: case CHK_ISEQ: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
381 case CHK_GTEQ: case CHK_LTEQ: case CHK_RANGE: |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
382 // 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
|
383 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
384 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
385 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
386 case VT_TEXT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
387 // Strings get their length checked |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
388 if (!stChkRequestDataItem($check[0], $slen, $check[2])) |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
389 return stErrorStrF($check[3], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
390 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
391 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
392 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
393 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
394 // Integer values checked against .. value |
292 | 395 if (!stChkRequestDataItem($check[0], 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
|
396 return stErrorStrF($check[3], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
397 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
398 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
399 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
400 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
401 case CHK_CUSTOM: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
402 // 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
|
403 $func = $check[1]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
404 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
|
405 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
|
406 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
407 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
408 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
409 |
436
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
410 if ($sdata !== FALSE) |
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
411 $sdata = $data; |
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
412 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
413 return TRUE; |
0 | 414 } |
415 | |
416 | |
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
|
417 function stGetRequestItem($name, $default = "", $allowGet = FALSE) |
0 | 418 { |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
419 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
|
420 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
|
421 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
|
422 return isset($_POST[$name]) ? trim($_POST[$name]) : $default; |
0 | 423 } |
424 | |
425 | |
486 | 426 function stConnectSQLDBSpec($dbspec) |
427 { | |
428 try { | |
429 $dbh = new PDO($dbspec); | |
430 } | |
431 catch (PDOException $e) { | |
432 error_log("Could not connect to SQL database: ".$e->getMessage()."."); | |
433 return FALSE; | |
434 } | |
435 return $dbh; | |
436 } | |
437 | |
438 | |
439 function stDBGetSQLParam($dbh, $type, $value) | |
440 { | |
441 switch ($type) | |
442 { | |
443 case "d": return intval($value); | |
444 case "s": return $dbh->quote($value); | |
445 case "b": return intval($value) ? 1 : 0; | |
446 case "D": return intval(stGetRequestItem($value)); | |
447 case "S": return $dbh->quote(stGetRequestItem($value)); | |
448 case "Q": return $dbh->quote(stGetRequestItem($value)); | |
449 case "B": return intval(stGetRequestItem($value)) ? 1 : 0; | |
450 } | |
451 } | |
452 | |
453 | |
501 | 454 function stLogSQLError($dbh, $sql) |
0 | 455 { |
501 | 456 error_log("SQL error ".implode("; ", $dbh->errorInfo())." in statement \"".$sql."\""); |
0 | 457 } |
458 | |
459 | |
460 function stConnectSQLDB() | |
461 { | |
462 global $db; | |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
463 try { |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
464 $db = new PDO(stGetSetting("sqlDB"), |
538 | 465 stGetSetting("sqlUsername", NULL), |
466 stGetSetting("sqlPassword", NULL), | |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
467 stGetSetting("sqlOptions", array())); |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
468 } |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
469 catch (PDOException $e) { |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
470 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
|
471 return FALSE; |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
472 } |
486 | 473 $db = stConnectSQLDBSpec(stGetSetting("sqlDB")); |
474 return ($db !== false); | |
0 | 475 } |
476 | |
477 | |
487 | 478 function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs) |
0 | 479 { |
487 | 480 $sql = array(); |
481 foreach ($pairs as $name => $attr) | |
0 | 482 { |
487 | 483 $sql[] = $name."=".stDBGetSQLParam($dbh, $attr, $name); |
0 | 484 } |
487 | 485 return |
486 "UPDATE ".$table." SET ".implode(",", $sql). | |
487 ($cond != "" ? " ".$cond : ""); | |
0 | 488 } |
489 | |
490 | |
487 | 491 function stDBPrepareSQL($dbh) |
0 | 492 { |
493 $argc = func_num_args(); | |
494 $argv = func_get_args(); | |
87 | 495 |
487 | 496 $fmt = $argv[1]; |
0 | 497 $len = strlen($fmt); |
498 $sql = ""; | |
487 | 499 $argn = 2; |
500 for ($pos = 0; $pos < $len; $pos++) | |
0 | 501 { |
502 if ($fmt[$pos] == "%") | |
503 { | |
504 if ($argn < $argc) | |
501 | 505 $sql .= stDBGetSQLParam($dbh, $fmt[++$pos], $argv[$argn++]); |
0 | 506 else |
507 { | |
508 error_log("Invalid SQL statement format string '".$fmt. | |
509 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
510 return FALSE; | |
511 } | |
512 } | |
513 else | |
514 $sql .= $fmt[$pos]; | |
515 } | |
485 | 516 |
0 | 517 return $sql; |
518 } | |
519 | |
520 | |
487 | 521 function stPrepareSQL() |
0 | 522 { |
487 | 523 global $db; |
524 $argc = func_num_args(); | |
525 $argv = func_get_args(); | |
526 | |
527 $fmt = $argv[0]; | |
528 $len = strlen($fmt); | |
529 $sql = ""; | |
530 $argn = 1; | |
531 for ($pos = 0; $pos < $len; $pos++) | |
0 | 532 { |
487 | 533 if ($fmt[$pos] == "%") |
534 { | |
535 if ($argn < $argc) | |
492 | 536 $sql .= stDBGetSQLParam($db, $fmt[++$pos], $argv[$argn++]); |
487 | 537 else |
538 { | |
539 error_log("Invalid SQL statement format string '".$fmt. | |
540 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
541 return FALSE; | |
542 } | |
543 } | |
544 else | |
545 $sql .= $fmt[$pos]; | |
0 | 546 } |
487 | 547 |
548 return $sql; | |
0 | 549 } |
550 | |
551 | |
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
|
552 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
|
553 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
554 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
|
555 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
556 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
568 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
569 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
570 |
487 | 571 function stDBExecSQL($dbh, $sql) |
0 | 572 { |
487 | 573 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 574 return $res; |
575 else | |
576 { | |
501 | 577 stLogSQLError($dbh, $sql); |
0 | 578 stError("Oh noes! SQL error #23!"); |
579 return FALSE; | |
580 } | |
581 } | |
582 | |
583 | |
487 | 584 function stDBFetchSQL($dbh, $sql) |
0 | 585 { |
487 | 586 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 587 return $res->fetch(); |
588 else | |
589 { | |
501 | 590 stLogSQLError($dbh, $sql); |
0 | 591 stError("Oh noes! SQL error #31!"); |
592 return FALSE; | |
593 } | |
594 } | |
595 | |
596 | |
487 | 597 function stDBFetchSQLColumn($dbh, $sql, $column = 0) |
0 | 598 { |
487 | 599 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 600 return $res->fetchColumn($column); |
601 else | |
602 { | |
501 | 603 stLogSQLError($dbh, $sql); |
0 | 604 stError("Oh noes! SQL error #81!"); |
605 return FALSE; | |
606 } | |
607 } | |
608 | |
609 | |
487 | 610 function stPrepareSQLUpdate($table, $cond, $pairs) |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
611 { |
487 | 612 global $db; |
613 return stDBPrepareSQLUpdate($db, $table, $cond, $pairs); | |
614 } | |
615 | |
616 | |
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
|
617 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
|
618 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
619 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
|
620 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
|
621 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
622 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
623 |
492 | 624 function stExecSQL($sql) |
487 | 625 { |
626 global $db; | |
627 return stDBExecSQL($db, $sql); | |
628 } | |
629 | |
630 | |
492 | 631 function stFetchSQL($sql) |
487 | 632 { |
633 global $db; | |
634 return stDBFetchSQL($db, $sql); | |
635 } | |
636 | |
637 | |
638 function stFetchSQLColumn($sql, $column = 0) | |
639 { | |
640 global $db; | |
641 return stDBFetchSQLColumn($db, $sql, $column); | |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
642 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
643 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
644 |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
645 function stStrChop($str, $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
646 { |
569
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
647 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
|
648 } |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
649 |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
650 |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
651 function stStrChopPad($str, $len) |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
652 { |
569
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
653 $tmp = stStrChop($str, $len); |
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
654 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
|
655 $tmp .= " "; |
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
656 return $tmp; |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
657 } |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
658 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
659 |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
660 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
|
661 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
662 echo |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
663 " <link rel=\"stylesheet\" href=\"".$filename. |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
664 "\" 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
|
665 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
666 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
667 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
668 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
|
669 { |
575
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
670 global $pageCSS, $pageCSSIndex, $pageCharset, $pageAuthor, $pageCSSData, $pageUrchin; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
671 |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
672 if (!isset($pageCSS)) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
673 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
674 if (!isset($pageCSSData)) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
675 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
676 $pageCSSData = array( |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
677 "cookie" => "docscss", |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
678 "prefix" => "/css/docs", |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
679 ); |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
680 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
681 |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
682 if (isset($_GET["css"])) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
683 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
684 $pageCSSIndex = intval($_GET["css"]); |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
685 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
|
686 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
687 else |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
688 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
689 $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
|
690 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
691 $pageCSS = $pageCSSData["prefix"].$pageCSSIndex.".css"; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
692 } |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
693 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
694 echo |
363 | 695 "<!DOCTYPE html>\n". |
178 | 696 "<html>\n". |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
697 "<head>\n". |
232 | 698 " <meta charset=\"".$pageCharset."\">\n". |
362
38dfe9e0a017
Add meta-equiv for document content type.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
699 " <meta http-equiv=\"Content-type\" content=\"text/html;charset=".$pageCharset."\">\n". |
232 | 700 " <title>".strip_tags($pageTitle)."</title>\n". |
701 $pageExtra; | |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
702 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
703 if (is_array($pageCSS)) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
704 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
705 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
|
706 cmPrintCSSLine($uri, $media); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
707 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
708 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
709 { |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
710 cmPrintCSSLine($pageCSS, FALSE); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
711 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
712 |
232 | 713 echo |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
714 "</head>\n". |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
715 "<body>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
716 |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
717 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
|
718 require_once $pageUrchin; |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
719 else |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
720 if (file_exists("urchin.inc.php")) |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
721 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
|
722 |
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
723 echo "<div id=\"messageBox\"></div>\n"; |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
724 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
725 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
726 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
|
727 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
728 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
729 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
730 function cmPrintPageFooter($useContents = TRUE) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
731 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
732 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
733 echo "</div>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
734 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
735 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
|
736 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
737 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
738 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
739 function cmQM($msg) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
740 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
741 global $pageTranslations, $pageLang; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
742 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
743 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
|
744 $str = $pageTranslations[$msg][$pageLang]; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
745 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
746 $str = $msg; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
747 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
748 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
|
749 $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
|
750 return $str; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
751 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
752 |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
753 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
754 // |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
755 // CLI related helper functions |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
756 // |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
757 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
758 // 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
|
759 function stCheckCLIExec($fail = TRUE) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
760 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
761 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
|
762 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
763 if ($fail) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
764 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
765 header("Status: 404 Not Found"); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
766 die(); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
767 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
768 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
769 return TRUE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
770 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
771 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
772 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
773 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
774 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
775 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
776 function stCArg($index) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
777 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
778 global $argc, $argv; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
779 if ($index < $argc) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
780 return $argv[$index]; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
781 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
782 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
783 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
784 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
785 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
786 function stCArgLC($index) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
787 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
788 global $argc, $argv; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
789 if ($index < $argc) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
790 return strtolower($argv[$index]); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
791 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
792 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
793 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
794 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
795 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
796 function stGetDBMeta($dbh, $name) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
797 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
798 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
|
799 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
800 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
801 return stGetSQLSettingData($item); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
802 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
803 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
804 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
805 function stSetDBMeta($dbh, $name, $value) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
806 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
807 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
|
808 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
809 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
810 $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
|
811 return stDBExecSQL($dbh, $sql); |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
812 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
813 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
814 |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
815 // |
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
816 // Global locale initialization |
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
817 // |
562 | 818 if (!isset($localeInited) || !$localeInited) |
819 { | |
820 $localeInited = TRUE; | |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
821 $pageCharset = "UTF-8"; |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
822 |
562 | 823 mb_internal_encoding($pageCharset); |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
824 |
562 | 825 $tmp = "en_US.".strtolower(str_replace("-", "", $pageCharset)); |
826 setlocale(LC_ALL, $tmp); | |
827 } | |
0 | 828 ?> |