Mercurial > hg > fapweb
annotate msite.inc.php @ 5:76c3b89d7b11
Improve voting, clean up the code, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 05 Dec 2012 08:08:58 +0200 |
parents | 8019b357cc03 |
children | d76020022881 |
rev | line source |
---|---|
0 | 1 <? |
2 // | |
3 // Nothing to touch after this, mostly | |
4 // | |
5 $errorSet = FALSE; | |
6 $errorMsg = ""; | |
7 | |
8 function stError($msg) | |
9 { | |
10 global $errorSet, $errorMsg; | |
11 $errorSet = TRUE; | |
12 $errorMsg .= "<li>".$msg."</li>\n"; | |
13 } | |
14 | |
15 | |
16 function stCheckHTTPS() | |
17 { | |
18 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
19 } | |
20 | |
21 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
22 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
23 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
24 header("Cache-Control: private"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
25 header("Cache-Control: must-revalidate"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
26 header("Cache-Control: no-store"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
27 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
28 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
29 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
30 function stSessionExpire($type) |
0 | 31 { |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
32 // Check for session expiration |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
33 if (!isset($_SESSION["expires"]) || $_SESSION["expires"] < time()) |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
34 return FALSE; |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
35 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
36 // Add more time to expiration |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
37 $_SESSION["expires"] = time() + stGetSetting($type); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
38 return TRUE; |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
39 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
40 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
41 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
42 function stAdmSessionAuth() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
43 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
44 if (@session_start() === TRUE && isset($_SESSION["admPassword"]) && |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 $_SESSION["admPassword"] == stGetSetting("admPassword")) |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 return stSessionExpire("admTimeout"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 else |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 return FALSE; |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
49 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
51 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
52 function stAdmSessionStart() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
53 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
54 if (@session_start() === TRUE) |
0 | 55 { |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
56 $_SESSION["admPassword"] = stGetSetting("admPassword"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
57 $_SESSION["expires"] = time() + stGetSetting("admTimeout"); |
0 | 58 return TRUE; |
59 } | |
60 else | |
61 return FALSE; | |
62 } | |
63 | |
64 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
65 function stVoteSessionAuth() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 { |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
67 if (@session_start() === TRUE && isset($_SESSION["key"]) && isset($_SESSION["votes"])) |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
68 return stSessionExpire("voteTimeout"); |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 else |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
70 return FALSE; |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
71 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
72 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
73 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
74 function stVoteSessionStart() |
0 | 75 { |
76 if (@session_start() === TRUE) | |
77 { | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
78 $_SESSION["expires"] = time() + stGetSetting("voteTimeout"); |
0 | 79 return TRUE; |
80 } | |
81 else | |
82 return FALSE; | |
83 } | |
84 | |
85 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
86 function stSetVoteStatus($st) |
0 | 87 { |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
88 $_SESSION["status"] = $st; |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
89 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 |
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 function stSessionEnd($ok) |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
93 { |
0 | 94 $_SESSION = array(); |
95 if (ini_get("session.use_cookies")) | |
96 { | |
97 $params = session_get_cookie_params(); | |
98 setcookie(session_name(), "", time() - 242000, | |
99 $params["path"], $params["domain"], | |
100 $params["secure"], $params["httponly"] | |
101 ); | |
102 } | |
103 @session_destroy(); | |
104 return $ok; | |
105 } | |
106 | |
107 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
108 function stGetSetting($name) |
0 | 109 { |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
110 global $siteSettings, $siteDefaults; |
0 | 111 if (isset($siteSettings[$name])) |
112 return $siteSettings[$name]; | |
113 else | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
114 if (isset($siteDefaults[$name])) |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
115 return $siteDefaults[$name]; |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
116 else |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
117 die("No config value or default for '".$name."'.\n"); |
0 | 118 } |
119 | |
120 | |
121 function stChkSetting($name) | |
122 { | |
123 global $siteSettings; | |
124 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
125 } | |
126 | |
127 | |
128 function stSpecURL($id) | |
129 { | |
130 global $specURLs; | |
131 if (isset($specURLs[$id])) | |
132 return "<a href=\"".$specURLs[$id][0]."\">".$specURLs[$id][1]."</a>"; | |
133 else | |
134 return ""; | |
135 } | |
136 | |
137 | |
138 function stPrintSpecURL($id) | |
139 { | |
140 echo stSpecURL($id); | |
141 } | |
142 | |
143 | |
144 function dhentities($str) | |
145 { | |
146 return str_replace(array("<",">"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8")); | |
147 } | |
148 | |
149 | |
150 function chentities($str) | |
151 { | |
152 return htmlentities($str, ENT_NOQUOTES, "UTF-8"); | |
153 } | |
154 | |
155 | |
156 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") | |
157 { | |
158 return | |
159 "<input ".$extra." type=\"checkbox\" id=\"".$prefix.$name.$id."\" ". | |
160 "name=\"".$prefix.$name.$id."\" ".($checked ? "checked=\"checked\" " : "")." />". | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
161 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
0 | 162 } |
163 | |
164 | |
165 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") | |
166 { | |
167 return | |
168 "<input type=\"button\" id=\"".$prefix.$name.$id."\" ". | |
169 "name=\"".$name."\" value=\"".$label."\" ". | |
170 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; | |
171 } | |
172 | |
173 | |
174 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") | |
175 { | |
176 return | |
177 "<textarea ".$extra." id=\"".$prefix.$name.$id."\" ". | |
178 "name=\"".$name."\" rows=\"".$rows."\" cols=\"".$cols."\">". | |
179 (isset($value) ? chentities($value) : ""). | |
180 "</textarea>"; | |
181 } | |
182 | |
183 | |
184 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
185 { | |
186 return | |
187 "<input ".$extra." type=\"text\" id=\"".$prefix.$name.$id."\" ". | |
188 "name=\"".$name."\" size=\"".$size."\" maxlength=\"".$len."\"". | |
189 (isset($value) ? " value=\"".chentities($value)."\"" : ""). | |
190 " />"; | |
191 } | |
192 | |
193 | |
194 function stGetFormPasswordInput($name, $id, $prefix) | |
195 { | |
196 return | |
197 "<input type=\"password\" id=\"".$prefix.$name.$id. | |
198 "\" name=\"".$name."\" />"; | |
199 } | |
200 | |
201 | |
202 function stGetFormHiddenInput($name, $value) | |
203 { | |
204 return "<input type=\"hidden\" name=\"".$name."\" value=\"".chentities($value)."\" />"; | |
205 } | |
206 | |
207 | |
208 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "") | |
209 { | |
210 return | |
211 "<td class=\"".$name."\">". | |
212 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)). | |
213 "</td>"; | |
214 } | |
215 | |
216 | |
217 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") | |
218 { | |
219 echo " <tr><th>".chentities($text1)."</th><td>". | |
220 stGetFormTextInput($size, $len, $name, "", "", $_REQUEST[$name], $extra). | |
221 "</td><td>".chentities($text2)."</td></tr>\n"; | |
222 } | |
223 | |
224 | |
225 function stPrintFormHiddenInput($name, $value) | |
226 { | |
227 echo " ".stGetFormHiddenInput($name, $value)."\n"; | |
228 } | |
229 | |
230 | |
231 function stPrintAttendee($item, $row, $edit, $eclass = "") | |
232 { | |
233 $id = $item["id"]; | |
234 $prefix = "at"; | |
235 echo " ". | |
236 "<tr class=\"".($row % 2 == 1 ? "rodd" : "reven").$eclass."\" id=\"attendee".$id."\">". | |
237 stGetTDEditTextItem(FALSE, 20, 40, "name", $id, $prefix, $item["name"]). | |
238 stGetTDEditTextItem(FALSE, 20, 40, "groups", $id, $prefix, $item["groups"]). | |
239 "<td class=\"regtime\">".date("d M Y / H:i", $item["regtime"])."</td>". | |
240 stGetTDEditTextItem($edit, 30, 64, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\""); | |
241 | |
242 if ($edit) | |
243 { | |
244 echo | |
245 stGetTDEditTextItem($edit, 20, 40, "email", $id, $prefix, $item["email"], "autocomplete=\"off\""). | |
246 "<td>". | |
247 "<button class=\"button\" id=\"atupd".$id."\" type=\"button\" onclick=\"updateAttendee(".$id.")\">Update</button>". | |
248 "<button class=\"button\" id=\"atdel".$id."\" type=\"button\" onclick=\"deleteAttendee(".$id.")\">Delete</button>". | |
249 "</td>"; | |
250 } | |
251 | |
252 echo "</tr>\n"; | |
253 } | |
254 | |
255 | |
256 function stPrintNewsItem($item, $edit = "") | |
257 { | |
258 echo | |
259 "<div class=\"newsitem\" id=\"news".$item["id"]."\">\n". | |
260 " <h2>".chentities($item["title"])."</h2>\n". | |
261 " <div class=\"text\">".dhentities($item["text"])."</div>\n". | |
262 " <div class=\"sig\">-- ".chentities($item["author"])."<br />". | |
263 date("d M Y / H:i", $item["utime"]). | |
264 $edit."</div>\n". | |
265 "</div>\n"; | |
266 } | |
267 | |
268 | |
269 function stChkDataItem($name) | |
270 { | |
271 return !isset($_REQUEST[$name]) || strlen(trim($_REQUEST[$name])) < 1; | |
272 } | |
273 | |
274 | |
275 function stChkRequestItem($name) | |
276 { | |
277 return isset($_REQUEST[$name]); | |
278 } | |
279 | |
280 | |
281 function stGetRequestItem($name, $default = "") | |
282 { | |
283 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default; | |
284 } | |
285 | |
286 | |
287 function stGetDRequestItem($name, $default = "") | |
288 { | |
289 return trim(urldecode(stGetRequestItem($name, $default))); | |
290 } | |
291 | |
292 | |
293 function stLogSQLError($sql) | |
294 { | |
295 global $db; | |
296 error_log("SQL error ".implode("; ", $db->errorInfo())." in statement \"".$sql."\""); | |
297 } | |
298 | |
299 | |
300 function stConnectSQLDB() | |
301 { | |
302 global $db; | |
303 try { | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
304 $db = new PDO("sqlite:".stGetSetting("sqlDBfilename")); |
0 | 305 } |
306 catch (PDOException $e) { | |
307 error_log("Could not connect to SQL database: ".$e->getMessage()."."); | |
308 return FALSE; | |
309 } | |
310 return TRUE; | |
311 } | |
312 | |
313 | |
314 function stGetSQLParam($type, $value) | |
315 { | |
316 global $db; | |
317 switch ($type) | |
318 { | |
319 case "d": | |
320 return intval($value); | |
321 | |
322 case "s": | |
323 return $db->quote($value); | |
324 | |
325 case "D": | |
326 return intval(stGetRequestItem($value)); | |
327 | |
328 case "S": | |
329 return $db->quote(stGetDRequestItem($value)); | |
330 | |
331 case "Q": | |
332 return $db->quote(stripslashes(stGetDRequestItem($value))); | |
333 | |
334 case "B": | |
335 return intval(stGetRequestItem($value)) ? 1 : 0; | |
336 } | |
337 } | |
338 | |
339 | |
340 function stPrepareSQL() | |
341 { | |
342 $argc = func_num_args(); | |
343 $argv = func_get_args(); | |
344 if ($argc < 1) | |
345 { | |
346 error_log("Invalid stPrepareSQL() call, no arguments!"); | |
347 return FALSE; | |
348 } | |
349 | |
350 $fmt = $argv[0]; | |
351 $len = strlen($fmt); | |
352 $sql = ""; | |
353 $argn = 1; | |
354 $pos = 0; | |
355 while ($pos < $len) | |
356 { | |
357 if ($fmt[$pos] == "%") | |
358 { | |
359 if ($argn < $argc) | |
360 $sql .= stGetSQLParam($fmt[++$pos], $argv[$argn++]); | |
361 else | |
362 { | |
363 error_log("Invalid SQL statement format string '".$fmt. | |
364 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
365 return FALSE; | |
366 } | |
367 } | |
368 else | |
369 $sql .= $fmt[$pos]; | |
370 $pos++; | |
371 } | |
372 | |
373 return $sql; | |
374 } | |
375 | |
376 | |
377 function stPrepareSQLUpdate($table, $cond, $pairs) | |
378 { | |
379 $sql = array(); | |
380 foreach ($pairs as $name => $attr) | |
381 { | |
382 $sql[] = $name."=".stGetSQLParam($attr, $name); | |
383 } | |
384 return | |
385 "UPDATE ".$table." SET ".implode(",", $sql). | |
386 ($cond != "" ? " ".$cond : ""); | |
387 } | |
388 | |
389 | |
390 function stExecSQL($sql) | |
391 { | |
392 global $db; | |
393 if (($res = $db->query($sql)) !== FALSE) | |
394 return $res; | |
395 else | |
396 { | |
397 stLogSQLError($sql); | |
398 stError("Oh noes! SQL error #23!"); | |
399 return FALSE; | |
400 } | |
401 } | |
402 | |
403 | |
404 function stFetchSQL($sql) | |
405 { | |
406 global $db; | |
407 if (($res = $db->query($sql)) !== FALSE) | |
408 { | |
409 return $res->fetch(); | |
410 } | |
411 else | |
412 { | |
413 stLogSQLError($sql); | |
414 stError("Oh noes! SQL error #31!"); | |
415 return FALSE; | |
416 } | |
417 } | |
418 | |
419 | |
420 function stFetchSQLColumn($sql, $column = 0) | |
421 { | |
422 global $db; | |
423 if (($res = $db->query($sql)) !== FALSE) | |
424 { | |
425 return $res->fetchColumn($column); | |
426 } | |
427 else | |
428 { | |
429 stLogSQLError($sql); | |
430 stError("Oh noes! SQL error #81!"); | |
431 return FALSE; | |
432 } | |
433 } | |
434 | |
435 | |
436 function stGetCompoList($all) | |
437 { | |
438 global $compos; | |
439 | |
440 // Get entries and competitions into an array structure | |
441 $sql = "SELECT * FROM compos ".($all ? "" :"WHERE enabled<>0 ")."ORDER BY name DESC"; | |
442 foreach (stExecSQL($sql) as $compo) | |
443 { | |
444 $id = $compo["id"]; | |
445 | |
446 $compos[$compo["id"]] = array( | |
447 "name" => $compo["name"], | |
448 "entries" => array() | |
449 ); | |
450 | |
451 $sql = stPrepareSQL("SELECT * FROM entries WHERE compo_id=%d", $id); | |
452 foreach (stExecSQL($sql) as $entry) | |
453 { | |
454 $compos[$id]["entries"][$entry["id"]] = $entry; | |
455 } | |
456 } | |
457 } | |
458 | |
459 | |
460 function stConvSwitchMode(&$str, &$mode, $newMode) | |
461 { | |
462 if ($newMode != $mode) | |
463 { | |
464 if ($mode != "") | |
465 $str .= "\n</".$mode.">\n"; | |
466 | |
467 $mode = $newMode; | |
468 | |
469 if ($mode != "") | |
470 $str .= "<".$mode.">\n"; | |
471 } | |
472 } | |
473 | |
474 | |
475 function stConvertCompoDesc($desc) | |
476 { | |
477 global $stDescConversion; | |
478 $str = ""; | |
479 $mode = ""; | |
480 | |
481 foreach (explode("\n", $desc) as $line) | |
482 { | |
483 if (preg_match("/^\s*\s*\*(.+)$/", $line, $m)) | |
484 { | |
485 stConvSwitchMode($str, $mode, "ol"); | |
486 $str .= "<li>".$m[1]."</li>\n"; | |
487 } | |
488 else | |
489 if (preg_match("/^\s*-\s*(.+)$/", $line, $m)) | |
490 { | |
491 stConvSwitchMode($str, $mode, "ul"); | |
492 $str .= "<li>".$m[1]."</li>\n"; | |
493 } | |
494 else | |
495 { | |
496 stConvSwitchMode($str, $mode, "p"); | |
497 $str .= $line; | |
498 } | |
499 } | |
500 | |
501 stConvSwitchMode($str, $mode, ""); | |
502 | |
503 return $str; | |
504 } | |
505 | |
506 ?> |