array('lib' => 'login.inc', 'func' => 'logout'), 'login.html' => array('lib' => 'login.inc', 'func' => 'process_login'), 'activate.html' => array('lib' => 'login.inc', 'func' => 'process_activate'), 'passwd.html' => array('lib' => 'login.inc', 'func' => 'process_passwd'), 'options.html' => array('lib' => 'login.inc', 'func' => 'process_options'), 'search.html' => array('lib' => 'search.inc', 'func' => 'process_search'), 'topic.html' => array('lib' => 'board.inc', 'func' => 'process_topic'), 'reply.html' => array('lib' => 'board.inc', 'func' => 'process_reply'), 'tags.html' => array('lib' => 'tags.inc', 'func' => 'process_tags'), 'edit.html' => array('lib' => 'zeitung.inc', 'func' => 'process_edit'), 'new.html' => array('lib' => 'zeitung.inc', 'func' => 'process_new'), 'bookmark.html' => array('lib' => 'bookmarks.inc', 'func' => 'process_bookmark'), 'contact.html' => array('func' => 'process_contact'), 'sitemap.html' => array('lib' => 'layout.inc', 'func' => 'layout_sitemap'), ); $dirs = array('zeitung' => array('func' => 'layout_showpaper'), 'archiv' => array('func' => 'layout_archive'), 'tag' => array('func' => 'layout_showtag'), 'topic' => array('func' => 'layout_topic'), 'admin' => array('lib' => 'admin.inc', 'func' => 'layout_admin'), ); /* * ==================== Commonly use code =============================== */ include_once('layout.inc'); function carp($msg) { error_log($msg); exit; } function userstatus() { global $_SESSION; if (isset($_SESSION['uid'])) $info = array($_SESSION['online'], $_SESSION['users'], $_SESSION['zeitungen'], $_SESSION['ztags'], $_SESSION['tags']); else $info = userstatus_info(); return sprintf('%d Nutzer von %d online | %d Zeitungen | Bewertungen: %d | Tags: %d', $info[0], $info[1], $info[2], $info[3], $info[4]); } function dispatch() { global $cfg; global $_SERVER; global $_SESSION; global $_GET; global $_POST; global $zlist; global $pages; global $dirs; $zlist['info'] = array('info_searchform', 'info_new', 'info_tags', 'info_tagcloud', 'info_actions', 'info_bookmarks','info_hitlist'); if (strlen($cfg['path']) && array_key_exists($cfg['path'], $pages)) { if (array_key_exists('lib', $pages[$cfg['path']])) include_once($pages[$cfg['path']]['lib']); if (array_key_exists('func', $pages[$cfg['path']])) { if (function_exists($pages[$cfg['path']]['func'])) $body = $pages[$cfg['path']]['func'](); else $body = notfound(); } } elseif (strlen($cfg['dir']) && array_key_exists($cfg['dir'], $dirs)) { if (array_key_exists('lib', $dirs[$cfg['dir']])) include_once($dirs[$cfg['dir']]['lib']); if (array_key_exists('func', $dirs[$cfg['dir']])) { if (function_exists($dirs[$cfg['dir']]['func'])) $body = $dirs[$cfg['dir']]['func'](); else $body = notfound(); } } elseif (empty($_SERVER['QUERY_STRING']) && empty($cfg['path']) && empty($cfg['dir'])) { $body .= load_template('main.html'); $zlist['page'] = 'index'; } else { $body = notfound(); } return layout_page($body); } function tagcloud_min() { $query = 'SELECT count(uid) AS count FROM zeitung_tags GROUP BY zeitung,tag ORDER BY count ASC LIMIT 1'; $sth = db_query($query); if ($sth === false) return 1; if (pg_num_rows($sth) === 0) return 1; $row = pg_fetch_array($sth, 0); return $row['count']; } function tagcloud_max() { $query = 'SELECT count(uid) AS count FROM zeitung_tags GROUP BY zeitung,tag ORDER BY count DESC LIMIT 1'; $sth = db_query($query); if ($sth === false) return 10; if (pg_num_rows($sth) === 0) return 10; $row = pg_fetch_array($sth, 0); return $row['count']; } function tag_class($count) { global $_SESSION; if (isset($_SESSION['uid'])) { if (!isset($_SESSION['tagcloud_lastupdate']) || $_SESSION["tagcloud_lastupdate"] < time() - 60*60*12) { $min = $_SESSION["tagcloud_min"] = tagcloud_min(); $max = $_SESSION["tagcloud_max"] = tagcloud_max(); $_SESSION["tagcloud_lastupdate"] = time(); } } if (!isset($min)) { $min = tagcloud_min(); $max = tagcloud_max(); } if ($count > (int)($min + ($max - $min) * 0.8)) return 4; elseif ($count > (int)($min + ($max - $min) * 0.6)) return 3; elseif ($count > (int)($min + ($max - $min) * 0.4)) return 2; elseif ($count > (int)($min + ($max - $min) * 0.2)) return 1; else return 0; } function load_template($template, $replace=false) { global $cfg; $fname = $cfg['tmpldir'] . '/' . $template; if (!file_exists($fname)) return false; $f = fopen($fname, 'r'); $content = fread($f, filesize($fname)); fclose($f); if (preg_match_all('/@([^@]+)@/', $content, $matches)) { $fields = array(); $values = array(); $found = array_unique($matches[1]); foreach ($found as $field) { $fields[] = '/@'.$field.'@/'; if ($replace != false && array_key_exists($field, $replace)) $values[] = $replace[$field]; else $values[] = ''; } $content = preg_replace($fields, $values, $content); } return $content; } function load_javascript($file) { global $cfg; if (!javascript_ok()) return; $fname = $cfg['tmpldir'] . '/' . $file; if (!file_exists($fname)) return; $f = fopen($fname, 'r'); $content = fread($f, filesize($fname)); fclose($f); $ret = "\n" . '' . "\n"; return $ret; } function format_date($date) { setlocale(LC_TIME, "de_DE.UTF-8"); return strftime("%e. %B %Y, %H:%M", strtotime($date)); } function format_newspaper($id) { global $cfg; global $zlist; $query = sprintf("SELECT * FROM zeitungen WHERE id = %d AND deleted IS false", $id); $sth = db_query($query) or carp("format_newspaper"); if (pg_num_rows ($sth) == 0) return false; $row = pg_fetch_array ($sth, 0); $ret = '
%s
Ort: %s
URL: %s
%s, %s
', $author, format_date($row['created'])); $ret .= sprintf('%s
', $row['body']); $ret .= '