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'),
39 'admin' => array('lib' => 'admin.inc',
40 'func' => 'layout_admin'),
45 * ==================== Commonly use code ===============================
47 include_once('layout.inc');
59 if (isset($_SESSION['uid']))
60 $info = array($_SESSION['online'], $_SESSION['users'], $_SESSION['zeitungen'],
61 $_SESSION['ztags'], $_SESSION['tags']);
63 $info = userstatus_info();
65 return sprintf('%d Nutzer von %d online | %d Zeitungen | Bewertungen: %d | Tags: %d',
66 $info[0], $info[1], $info[2], $info[3], $info[4]);
80 $zlist['info'] = array('info_searchform', 'info_new', 'info_tags', 'info_tagcloud',
81 'info_actions', 'info_bookmarks','info_hitlist');
83 if (strlen($cfg['path']) && array_key_exists($cfg['path'], $pages)) {
84 if (array_key_exists('lib', $pages[$cfg['path']]))
85 include_once($pages[$cfg['path']]['lib']);
86 if (array_key_exists('func', $pages[$cfg['path']])) {
87 if (function_exists($pages[$cfg['path']]['func']))
88 $body = $pages[$cfg['path']]['func']();
92 } elseif (strlen($cfg['dir']) && array_key_exists($cfg['dir'], $dirs)) {
93 if (array_key_exists('lib', $dirs[$cfg['dir']]))
94 include_once($dirs[$cfg['dir']]['lib']);
95 if (array_key_exists('func', $dirs[$cfg['dir']])) {
96 if (function_exists($dirs[$cfg['dir']]['func']))
97 $body = $dirs[$cfg['dir']]['func']();
101 } elseif (empty($_SERVER['QUERY_STRING']) &&
102 empty($cfg['path']) && empty($cfg['dir'])) {
103 $body .= load_template('main.html');
104 $zlist['page'] = 'index';
109 return layout_page($body);
112 function tagcloud_min()
114 $query = 'SELECT count(uid) AS count FROM zeitung_tags GROUP BY zeitung,tag ORDER BY count ASC LIMIT 1';
116 $sth = db_query($query);
121 if (pg_num_rows($sth) === 0)
124 $row = pg_fetch_array($sth, 0);
125 return $row['count'];
128 function tagcloud_max()
130 $query = 'SELECT count(uid) AS count FROM zeitung_tags GROUP BY zeitung,tag ORDER BY count DESC LIMIT 1';
132 $sth = db_query($query);
137 if (pg_num_rows($sth) === 0)
140 $row = pg_fetch_array($sth, 0);
141 return $row['count'];
144 function tag_class($count)
148 if (isset($_SESSION['uid'])) {
149 if (!isset($_SESSION['tagcloud_lastupdate']) ||
150 $_SESSION["tagcloud_lastupdate"] < time() - 60*60*12) {
151 $min = $_SESSION["tagcloud_min"] = tagcloud_min();
152 $max = $_SESSION["tagcloud_max"] = tagcloud_max();
153 $_SESSION["tagcloud_lastupdate"] = time();
158 $min = tagcloud_min();
159 $max = tagcloud_max();
162 if ($count > (int)($min + ($max - $min) * 0.8))
164 elseif ($count > (int)($min + ($max - $min) * 0.6))
166 elseif ($count > (int)($min + ($max - $min) * 0.4))
168 elseif ($count > (int)($min + ($max - $min) * 0.2))
174 function load_template($template, $replace=false)
178 $fname = $cfg['tmpldir'] . '/' . $template;
179 if (!file_exists($fname))
182 $f = fopen($fname, 'r');
183 $content = fread($f, filesize($fname));
186 if (preg_match_all('/@([^@]+)@/', $content, $matches)) {
190 $found = array_unique($matches[1]);
192 foreach ($found as $field) {
193 $fields[] = '/@'.$field.'@/';
194 if ($replace != false && array_key_exists($field, $replace))
195 $values[] = $replace[$field];
200 $content = preg_replace($fields, $values, $content);
206 function load_javascript($file)
210 if (!javascript_ok())
213 $fname = $cfg['tmpldir'] . '/' . $file;
214 if (!file_exists($fname))
217 $f = fopen($fname, 'r');
218 $content = fread($f, filesize($fname));
221 $ret = "\n" . '<script type="text/javascript"><!--' . "\n";
223 $ret .= "\n" . '//--></script>' . "\n";
228 function format_date($date)
230 setlocale(LC_TIME, "de_DE.UTF-8");
232 return strftime("%e. %B %Y, %H:%M", strtotime($date));
235 function format_newspaper($id)
240 $query = sprintf("SELECT * FROM zeitungen WHERE id = %d AND deleted IS false", $id);
242 $sth = db_query($query) or carp("format_newspaper");
244 if (pg_num_rows ($sth) == 0)
247 $row = pg_fetch_array ($sth, 0);
249 $ret = '<div class="newspaper">';
250 $ret .= sprintf('<h3>%s</h3>', $row['name']);
251 $zlist['newspaper'] = $row['name'];
252 $zlist['city'] = $row['city'];
254 $ret .= sprintf('<p>%s<br>Ort: %s<br>URL: <a href="%s"><code>%s</code></a></p>',
255 $row['description'], $row['city'],
256 $row['url'], $row['url']);
262 function format_topten($uid)
267 $query = sprintf("SELECT zeitung,name,counter FROM hits " .
268 "INNER JOIN zeitungen ON id = zeitung " .
269 "WHERE deleted IS false AND uid = %d " .
270 "ORDER BY counter DESC LIMIT 10", $uid);
272 $query = "SELECT zeitung,name,sum(counter) as counter FROM hits " .
273 "INNER JOIN zeitungen ON id = zeitung " .
274 "WHERE deleted IS false " .
275 "GROUP BY zeitung,name ORDER BY counter DESC LIMIT 10";
277 $sth = db_query($query) or carp("format_topten");
279 if (pg_num_rows ($sth) == 0)
282 $ret = '<h3>Top 10</h3>';
284 for ($n=0; $n < pg_num_rows ($sth); $n++) {
285 $row = pg_fetch_array ($sth, $n);
286 $ret .= sprintf('<li><a href="%szeitung/%d.html">%s</a></li>',
287 $cfg['basepath'], $row['zeitung'], $row['name']);
294 function format_topic($topic)
300 $query = sprintf("SELECT topic,archived,zeitung FROM topics WHERE id = %d",
303 if (($sth = db_query($query)) === false)
304 return warning('Es ist ein Datenbankfehler aufgetreten.');
306 if (pg_num_rows ($sth) == 0)
307 return warning('Keine passende Diskussion gefunden.');
309 if (($info = pg_fetch_array ($sth, 0)) == false)
310 return warning('Es ist ein Datenbankfehler aufgetreten.');
312 $query = sprintf("SELECT nickname,url,created,body FROM article " .
313 "JOIN users ON users.id = uid " .
314 "WHERE topic = %d AND article.status = 1 " .
315 "ORDER BY created", $topic);
317 if (($sth2 = db_query($query)) === false) return false;
319 if (pg_num_rows ($sth2) > 0) {
320 $ret .= '<div class="topic">';
321 $ret .= sprintf ('<h3>%s</h3>', htmlspecialchars($info['topic']));
323 $zlist['zid'] = $info['zeitung'];
324 $zlist['topic'] = $info['topic'];
325 $zlist['archived'] = $info['archived'] == 't';
327 for ($j=0; $j < pg_num_rows ($sth2); $j++) {
328 $row = pg_fetch_array ($sth2, $j);
330 $ret .= sprintf('<div class="art%d">', $col);
332 if (strlen($row['url']))
333 $author = sprintf('<a href="%s">%s</a>', $row['url'], $row['nickname']);
335 $author = $row['nickname'];
337 $ret .= sprintf('<p><b>%s</b>, %s</p>', $author, format_date($row['created']));
338 $ret .= sprintf('<p>%s</p>', $row['body']);
343 if ($info['archived'] == 'f' &&
344 strpos($_SERVER['REQUEST_URI'], "/reply.html", 0) === false) {
345 $ret .= '<div class="buttons"><p>';
347 $link_rep = sprintf('%sreply.html?topic=%d', $cfg['basepath'], $topic);
349 $link_rep = sprintf('%slogin.html?from=article', $cfg['basepath']);
352 $ret .= sprintf('<img src="%santworten.gif" width="21" height="17"> ', $cfg['basepath']);
353 $ret .= sprintf('<a href="%s"><strong>antworten</strong></a>', $link_rep);
354 $ret .= '</p></div>';
362 function format_board($zid, $archived=false)
367 $query = sprintf("SELECT id FROM topics " .
368 "WHERE zeitung = %d AND archived IS %s " .
369 "ORDER BY created DESC", $zid,
370 $archived?'true':'false');
372 if (($sth = db_query($query)) === false) return false;
374 if (pg_num_rows ($sth) == 0 && !$archived) {
375 $zlist['notopic'] = true;
380 if (pg_num_rows ($sth) > 0) {
382 $ret = '<h3>Abgeschlossene Diskussionen</h3>';
384 $ret = '<h3>Diskussion</h3>';
387 for ($i=0; $i < pg_num_rows ($sth); $i++) {
388 $row = pg_fetch_array ($sth, $i);
390 $ret .= format_topic($row['id']);
396 function fix_url($url) {
400 if (strpos($url, "http://") === false)
401 $url = "http://" . $url;
403 $parts = parse_url($url);
405 if ($parts === false)
408 if (empty($parts['path']))
414 function is_valid_url($url) {
415 if (strpos($url, '.') === false)
418 $parts = parse_url($url);
420 if (empty($parts['host']) || empty($parts['scheme']) || empty($parts['path']))
423 if ($parts['scheme'] != 'http' && $parts['scheme'] != 'https')
426 if (!preg_match ('/^[a-zA-Z][a-zA-Z0-9\.-]+$/', $parts['host'], $matches))
429 if (preg_match ('/[\\\\<>"\'\(\)\[\]]/', $parts['path'], $matches))
432 if (!empty($parts['query']) && preg_match ('/[\\\\<>"\'\(\)\[\]]/', $parts['query'], $matches))
438 function ajax_check_url()
442 if (!empty($_POST['url']) && is_valid_url($_POST['url']))
448 function sendmail($to, $name, $subject, $body, $header=array())
455 $header[] = 'From: ' . $cfg['from'];
457 $header[] = 'To: ' . $to;
459 $header[] = sprintf('To: %s <%s>', $name, $to);
460 $header[] = 'MIME-Version: 1.0';
461 $header[] = 'Content-type: text/plain; charset=utf-8';
462 $header[] = 'Content-Disposition: inline';
463 $header[] = 'Content-Transfer-Encoding: 8bit';
465 $sig = load_template('signature');
469 $subject = mb_encode_mimeheader($subject,"UTF-8", "Q", "\n");
471 if (mail ($to, $subject, $body, implode("\n", $header)) === false)
477 function logbook($table,$refid,$column,$old,$new)
481 $query = sprintf("INSERT INTO logbook (uid,tab,refid,col,oldval,newval,modified) " .
482 "VALUES (%d,'%s',%d,'%s','%s','%s',now())",
483 $_SESSION['uid'], $table,$refid,$column,
484 pg_escape_string($old),
485 pg_escape_string($new));
490 function hits_inc($zeitung)
498 $uid = isset($_SESSION['uid'])?$_SESSION['uid']:0;
500 $query = sprintf("SELECT counter FROM hits WHERE uid = %d AND zeitung = %d", $uid, $zeitung);
502 $sth = db_query($query);
504 if (pg_num_rows ($sth) == 0)
505 $query = sprintf("INSERT INTO hits (zeitung,uid,counter) " .
506 "VALUES (%d,%d,1)", $zeitung, $uid);
508 $query = sprintf("UPDATE hits SET counter = counter + 1 " .
509 "WHERE zeitung = %d AND uid = %d", $zeitung, $uid);