array('/^[a-z]+$/', 'kiwi'), 'c' => array('/^\d+$/', '0'), ); $VAR = array(); foreach( $PARAMETERS as $PNAME => $PATTR ) { if( !isset($_REQUEST[$PNAME]) OR preg_match($PATTR[0],$_REQUEST[$PNAME]) == 0 ) $VAR[$PNAME] = $PATTR[1]; else $VAR[$PNAME] = $_REQUEST[$PNAME]; } if (function_exists('mysql_set_charset') === false) { /** * Sets the client character set. * * Note: This function requires MySQL 5.0.7 or later. * * @see http://www.php.net/mysql-set-charset * @param string $charset A valid character set name * @param resource $link_identifier The MySQL connection * @return TRUE on success or FALSE on failure */ function mysql_set_charset($charset, $link_identifier = null) { if ($link_identifier == null) { return mysql_query('SET CHARACTER SET "'.$charset.'"'); } else { return mysql_query('SET CHARACTER SET "'.$charset.'"', $link_identifier); } } } function htmlentitiesutf8($s) { return htmlentities($s, ENT_COMPAT, 'UTF-8'); } header("Content-Type: text/html; charset=utf-8"); mysql_connect($dbhost,$dbuser, $dbpass); mysql_select_db($dbname); mysql_set_charset('utf8'); if( $VAR['c'] == 0) { // Get first Chapter $minchapter = mysql_query("SELECT min(e.chapter) FROM $ttrips as t LEFT OUTER JOIN $tentries as e ON e.trip = t.id WHERE t.name = 'kiwi' AND e.published = 1 GROUP BY e.trip"); if( mysql_num_rows($minchapter) == 1 ) { $minchapter = mysql_fetch_row($minchapter); $VAR['c'] = $minchapter[0]; } } $entries = mysql_query("SELECT t.id, e.id as eid, e.title, e.subtitle, e.content FROM $ttrips as t LEFT OUTER JOIN $tentries as e ON e.trip = t.id WHERE t.name = '$VAR[t]' AND e.published = 1 AND e.chapter = $VAR[c] ORDER BY e.id ASC"); if( mysql_num_rows($entries) != 0 ) { $lastupdate = mysql_fetch_row(mysql_query("SELECT max(e.lastupdate) FROM $ttrips as t LEFT OUTER JOIN $tentries as e ON e.trip = t.id WHERE t.name = 'kiwi' AND e.published = 1")); $chapters = mysql_query("SELECT c.chapter, c.title FROM $ttrips AS t LEFT OUTER JOIN $tentries AS e ON t.id = e.trip LEFT OUTER JOIN $tchapters AS c ON c.trip = t.id AND c.chapter = e.chapter WHERE t.name = 'kiwi' AND e.published =1 GROUP BY e.chapter ORDER BY e.chapter ASC"); $currentchaptertitle = mysql_fetch_row(mysql_query("SELECT title FROM diary_chapters as c LEFT OUTER JOIN diary_trips as t ON c.trip = t.id WHERE t.name = '$VAR[t]' AND chapter = $VAR[c]")); $MAIN = new template($VAR['t'].'/index.html'); $MAIN->replace('LASTUPDATE', $lastupdate[0]); $MAIN->replace('CURRENTCHAPTER', $VAR['c']); $MAIN->replace('CURRENTCHAPTERTITLE', $currentchaptertitle[0]); $MAIN->block('CHAPTERS', 'CHAPTER', 'CHAPTERTITLE'); while(($row = mysql_fetch_assoc($chapters)) !== false) $MAIN->blocks['CHAPTERS']->data($row['chapter'], $row['title']); $MAIN->block('ENTRYLINKS', 'ENTRYTITLE', 'ENTRYSUBTITLE','ENTRYID'); $MAIN->block('ENTRIES', 'TITLE', 'SUBTITLE', 'CONTENT', 'ID'); while(($row = mysql_fetch_assoc($entries)) !== false) { $MAIN->blocks['ENTRIES']->data($row['title'],$row['subtitle'],preg_replace('/^(.*)\[IMG:(.*),(.*)\](.*)$/msU','$1$3$4',$row['content']),$row['eid']); $MAIN->blocks['ENTRYLINKS']->data($row['title'],$row['subtitle'],$row['eid']); } echo $MAIN->parse(); } else { echo 'Tagebuch existiert nicht.'; //header('Location: index.php'); } ?>