4 * ==================== Configuration of/for the platform ===============
6 $pages = array('logout.html' => array('lib' => 'login.inc',
8 'login.html' => array('lib' => 'login.inc',
9 'func' => 'process_login'),
10 'activate.html' => array('lib' => 'login.inc',
11 'func' => 'process_activate'),
12 'passwd.html' => array('lib' => 'login.inc',
13 'func' => 'process_passwd'),
14 'options.html' => array('lib' => 'login.inc',
15 'func' => 'process_options'),
16 'search.html' => array('lib' => 'search.inc',
17 'func' => 'process_search'),
18 'topic.html' => array('lib' => 'board.inc',
19 'func' => 'process_topic'),
20 'reply.html' => array('lib' => 'board.inc',
21 'func' => 'process_reply'),
22 'tags.html' => array('lib' => 'tags.inc',
23 'func' => 'process_tags'),
24 'edit.html' => array('lib' => 'zeitung.inc',
25 'func' => 'process_edit'),
26 'new.html' => array('lib' => 'zeitung.inc',
27 'func' => 'process_new'),
28 'bookmark.html' => array('lib' => 'bookmarks.inc',
29 'func' => 'process_bookmark'),
30 'contact.html' => array('func' => 'process_contact'),
31 'sitemap.html' => array('lib' => 'layout.inc',
32 'func' => 'layout_sitemap'),
35 $dirs = array('zeitung' => array('func' => 'layout_showpaper'),
36 'archiv' => array('func' => 'layout_archive'),
37 'tag' => array('func' => 'layout_showtag'),
38 'topic' => array('func' => 'layout_topic'),
43 * ==================== Commonly use code ===============================
45 include_once('layout.inc');
57 if (isset($_SESSION['uid']))
58 $info = array($_SESSION['online'], $_SESSION['users'], $_SESSION['zeitungen'],
59 $_SESSION['ztags'], $_SESSION['tags']);
61 $info = userstatus_info();
63 return sprintf('%d Nutzer von %d online | %d Zeitungen | Bewertungen: %d | Tags: %d',
64 $info[0], $info[1], $info[2], $info[3], $info[4]);
78 $zlist['info'] = array('info_searchform', 'info_new', 'info_tags', 'info_tagcloud',
79 'info_actions', 'info_bookmarks','info_hitlist');
81 if (strlen($cfg['path']) && array_key_exists($cfg['path'], $pages)) {
82 if (array_key_exists('lib', $pages[$cfg['path']]))
83 include_once($pages[$cfg['path']]['lib']);
84 if (array_key_exists('func', $pages[$cfg['path']])) {
85 if (function_exists($pages[$cfg['path']]['func']))
86 $body = $pages[$cfg['path']]['func']();
90 } elseif (strlen($cfg['dir']) && array_key_exists($cfg['dir'], $dirs)) {
91 if (array_key_exists('lib', $dirs[$cfg['dir']]))
92 include_once($dirs[$cfg['dir']]['lib']);
93 if (array_key_exists('func', $dirs[$cfg['dir']])) {
94 if (function_exists($dirs[$cfg['dir']]['func']))
95 $body = $dirs[$cfg['dir']]['func']();
99 } elseif (empty($_SERVER['QUERY_STRING']) &&
100 empty($cfg['path']) && empty($cfg['dir'])) {
101 $body .= load_template('main.html');
102 $zlist['page'] = 'index';
107 return layout_page($body);
110 function tagcloud_min()
112 $query = 'SELECT count(uid) AS count FROM zeitung_tags GROUP BY zeitung,tag ORDER BY count ASC LIMIT 1';
114 $sth = db_query($query);
119 if (pg_NumRows($sth) === 0)
122 $row = pg_fetch_array($sth, 0);
123 return $row['count'];
126 function tagcloud_max()
128 $query = 'SELECT count(uid) AS count FROM zeitung_tags GROUP BY zeitung,tag ORDER BY count DESC LIMIT 1';
130 $sth = db_query($query);
135 if (pg_NumRows($sth) === 0)
138 $row = pg_fetch_array($sth, 0);
139 return $row['count'];
142 function tag_class($count)
146 if (isset($_SESSION['uid'])) {
147 if (!isset($_SESSION['tagcloud_lastupdate']) ||
148 $_SESSION["tagcloud_lastupdate"] < time() - 60*60*12) {
149 $min = $_SESSION["tagcloud_min"] = tagcloud_min();
150 $max = $_SESSION["tagcloud_max"] = tagcloud_max();
151 $_SESSION["tagcloud_lastupdate"] = time();
156 $min = tagcloud_min();
157 $max = tagcloud_max();
160 if ($count > (int)($min + ($max - $min) * 0.8))
162 elseif ($count > (int)($min + ($max - $min) * 0.6))
164 elseif ($count > (int)($min + ($max - $min) * 0.4))
166 elseif ($count > (int)($min + ($max - $min) * 0.2))
172 function load_template($template, $replace=false)
176 $fname = $cfg['tmpldir'] . '/' . $template;
177 if (!file_exists($fname))
180 $f = fopen($fname, 'r');
181 $content = fread($f, filesize($fname));
184 if (preg_match_all('/@([^@]+)@/', $content, $matches)) {
188 $found = array_unique($matches[1]);
190 foreach ($found as $field) {
191 $fields[] = '/@'.$field.'@/';
192 if ($replace != false && array_key_exists($field, $replace))
193 $values[] = $replace[$field];
198 $content = preg_replace($fields, $values, $content);
204 function load_javascript($file)
208 if (!javascript_ok())
211 $fname = $cfg['tmpldir'] . '/' . $file;
212 if (!file_exists($fname))
215 $f = fopen($fname, 'r');
216 $content = fread($f, filesize($fname));
219 $ret = "\n" . '<script type="text/javascript"><!--' . "\n";
221 $ret .= "\n" . '//--></script>' . "\n";
226 function format_date($date)
228 setlocale(LC_TIME, "de_DE.UTF-8");
230 return strftime("%e. %B %Y, %H:%M", strtotime($date));
233 function format_newspaper($id)
238 $query = sprintf("SELECT * FROM zeitungen WHERE id = %d AND deleted IS false", $id);
240 $sth = db_query($query) or carp("format_newspaper");
242 if (pg_NumRows ($sth) == 0)
245 $row = pg_fetch_array ($sth, 0);
247 $ret = '<div class="newspaper">';
248 $ret .= sprintf('<h3>%s</h3>', htmlspecialchars($row['name']));
249 $zlist['newspaper'] = htmlspecialchars($row['name']);
251 $ret .= sprintf('<p>%s<br>Ort: %s<br>URL: <a href="%s"><code>%s</code></a></p>',
252 $row['description'], $row['city'],
253 $row['url'], $row['url']);
259 function format_topten($uid)
264 $query = sprintf("SELECT zeitung,name,counter FROM hits " .
265 "INNER JOIN zeitungen ON id = zeitung " .
266 "WHERE deleted IS false AND uid = %d " .
267 "ORDER BY counter DESC LIMIT 10", $uid);
269 $query = "SELECT zeitung,name,sum(counter) as counter FROM hits " .
270 "INNER JOIN zeitungen ON id = zeitung " .
271 "WHERE deleted IS false " .
272 "GROUP BY zeitung,name ORDER BY counter DESC LIMIT 10";
274 $sth = db_query($query) or carp("format_topten");
276 if (pg_NumRows ($sth) == 0)
279 $ret = '<h3>Top 10</h3>';
281 for ($n=0; $n < pg_NumRows ($sth); $n++) {
282 $row = pg_fetch_array ($sth, $n);
283 $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
284 $cfg['basepath'], $row['zeitung'], $row['name']);
291 function format_topic($topic)
297 $query = sprintf("SELECT topic,archived,zeitung FROM topics WHERE id = %d",
300 if (($sth = db_query($query)) === false)
301 return warning('Es ist ein Datenbankfehler aufgetreten.');
303 if (pg_NumRows ($sth) == 0)
304 return warning('Keine passende Diskussion gefunden.');
306 if (($info = pg_fetch_array ($sth, 0)) == false)
307 return warning('Es ist ein Datenbankfehler aufgetreten.');
309 $query = sprintf("SELECT nickname,url,created,body FROM article " .
310 "JOIN users ON users.id = uid " .
311 "WHERE topic = %d AND article.status = 1 " .
312 "ORDER BY created", $topic);
314 if (($sth2 = db_query($query)) === false) return false;
316 if (pg_NumRows ($sth2) > 0) {
317 $ret .= '<div class="topic">';
318 $ret .= sprintf ('<h3>%s</h3>', htmlspecialchars($info['topic']));
320 $zlist['zid'] = $info['zeitung'];
321 $zlist['topic'] = $info['topic'];
322 $zlist['archived'] = $info['archived'] == 't';
324 for ($j=0; $j < pg_NumRows ($sth2); $j++) {
325 $row = pg_fetch_array ($sth2, $j);
327 $ret .= sprintf('<div class="art%d">', $col);
329 if (strlen($row['url']))
330 $author = sprintf('<a href="%s">%s</a>', $row['url'], $row['nickname']);
332 $author = $row['nickname'];
334 $ret .= sprintf('<p><b>%s</b>, %s</p>', $author, format_date($row['created']));
335 $ret .= sprintf('<p>%s</p>', $row['body']);
340 if ($info['archived'] == 'f' &&
341 strpos($_SERVER['REQUEST_URI'], "/reply.html", 0) === false) {
342 $ret .= '<div class="buttons"><p>';
344 $link_rep = sprintf('%sreply.html?topic=%d', $cfg['basepath'], $topic);
346 $link_rep = sprintf('%slogin.html?from=article', $cfg['basepath']);
349 $ret .= sprintf('<img src="%santworten.gif" width="21" height="17"> ', $cfg['basepath']);
350 $ret .= sprintf('<a href="%s"><strong>antworten</strong></a>', $link_rep);
351 $ret .= '</p></div>';
359 function format_board($zid, $archived=false)
364 $query = sprintf("SELECT id FROM topics " .
365 "WHERE zeitung = %d AND archived IS %s " .
366 "ORDER BY created DESC", $zid,
367 $archived?'true':'false');
369 if (($sth = db_query($query)) === false) return false;
371 if (pg_NumRows ($sth) == 0 && !$archived) {
372 $zlist['notopic'] = true;
377 if (pg_NumRows ($sth) > 0) {
379 $ret = '<h3>Abgeschlossene Diskussionen</h3>';
381 $ret = '<h3>Diskussion</h3>';
384 for ($i=0; $i < pg_NumRows ($sth); $i++) {
385 $row = pg_fetch_array ($sth, $i);
387 $ret .= format_topic($row['id']);
393 function fix_url($url) {
397 if (strpos($url, "http://") === false)
398 $url = "http://" . $url;
400 $parts = parse_url($url);
402 if ($parts === false)
405 if (empty($parts['path']))
411 function is_valid_url($url) {
412 $parts = parse_url($url);
414 if (empty($parts['host']) || empty($parts['scheme']) || empty($parts['path']))
417 if ($parts['scheme'] != 'http' && $parts['scheme'] != 'https')
420 if (!preg_match ('/^[a-zA-Z][a-zA-Z0-9\.-]+$/', $parts['host'], $matches))
423 if (preg_match ('/[\\\\<>"\'\(\)\[\]]/', $parts['path'], $matches))
426 if (!empty($parts['query']) && preg_match ('/[\\\\<>"\'\(\)\[\]]/', $parts['query'], $matches))
432 function ajax_check_url()
436 if (!empty($_POST['url']) && is_valid_url($_POST['url']))
442 function sendmail($to, $name, $subject, $body, $header=array())
449 $header[] = 'From: ' . $cfg['from'];
451 $header[] = 'To: ' . $to;
453 $header[] = sprintf('To: %s <%s>', $name, $to);
454 $header[] = 'MIME-Version: 1.0';
455 $header[] = 'Content-type: text/plain; charset=utf-8';
456 $header[] = 'Content-Disposition: inline';
457 $header[] = 'Content-Transfer-Encoding: 8bit';
459 $sig = load_template('signature');
463 $subject = mb_encode_mimeheader($subject,"UTF-8", "Q", "\n");
465 if (mail ($to, $subject, $body, implode("\n", $header)) === false)
471 function logbook($table,$refid,$column,$old,$new)
475 $query = sprintf("INSERT INTO logbook (uid,tab,refid,col,oldval,newval,modified) " .
476 "VALUES (%d,'%s',%d,'%s','%s','%s',now())",
477 $_SESSION['uid'], $table,$refid,$column,
478 pg_escape_string($old),
479 pg_escape_string($new));
484 function hits_inc($zeitung)
492 $uid = isset($_SESSION['uid'])?$_SESSION['uid']:0;
494 $query = sprintf("SELECT counter FROM hits WHERE uid = %d AND zeitung = %d", $uid, $zeitung);
496 $sth = db_query($query);
498 if (pg_NumRows ($sth) == 0)
499 $query = sprintf("INSERT INTO hits (zeitung,uid,counter) " .
500 "VALUES (%d,%d,1)", $zeitung, $uid);
502 $query = sprintf("UPDATE hits SET counter = counter + 1 " .
503 "WHERE zeitung = %d AND uid = %d", $zeitung, $uid);