include "includes/theme.inc"; function diary_overview($num = 20) { global $theme, $user; $result = db_query("SELECT d.*, u.userid FROM diaries d LEFT JOIN users u ON d.author = u.id ORDER BY d.timestamp DESC LIMIT $num"); $output .= "
This part of the website is dedicated to providing easy to write and easy to read online diaries or journals filled with daily thoughts, poetry, boneless blather, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on actuality, fresh insights, diverse dreams, chronicles and general madness available for general human consumption.
"; while ($diary = db_fetch_object($result)) { if ($time != date("F jS", $diary->timestamp)) { $output .= "". date("l, F jS", $diary->timestamp) ."\n"; $time = date("F jS", $diary->timestamp); } $output .= "$diary->userid wrote:
". check_output($diary->text, 1) ."
[ userid\">more ]
[ edit ]
". check_output($text, 1) ."
". check_output($text, 1) ."
"); while ($diary = db_fetch_object($result)) $output .= diary_entry($diary->timestamp, $diary->text, $diary->id); } else { $output .= "
". format_username($username) ."'s diary:
\n"; while ($diary = db_fetch_object($result)) $output .= diary_entry($diary->timestamp, $diary->text); } $theme->header(); $theme->box("$username's online diary", $output); $theme->footer(); } function diary_add() { global $theme, $user, $allowed_html; $output .= "\n"; $theme->header(); $theme->box("Online diary", $output); $theme->footer(); } function diary_edit($id) { global $theme, $user, $allowed_html; $result = db_query("SELECT * FROM diaries WHERE id = $id"); $diary = db_fetch_object($result); $output .= diary_entry($diary->timestamp, $diary->text); $output .= "\n"; $theme->header(); $theme->box("Online diary", $output); $theme->footer(); } function diary_preview($text, $timestamp, $id = 0) { global $theme, $user, $allowed_html; $output .= diary_entry($timestamp, $text); $output .= "\n"; $theme->header(); $theme->box("Online diary", $output); $theme->footer(); } function diary_submit($text, $id = 0) { global $user, $theme; if ($id) { watchdog("message", "old diary entry updated"); db_query("UPDATE diaries SET text = '". check_input($text) ."' WHERE id = $id"); } else { watchdog("diary", "new diary entry added"); db_query("INSERT INTO diaries (author, text, timestamp) VALUES ('$user->id', '". check_input($text) ."', '". time() ."')"); } header("Location: diary.php?op=view&name=$user->userid"); } ### Security check: if (strstr($id, " ") || strstr($name, " ")) { watchdog("error", "diary: attempt to provide malicious input through URI"); exit(); } switch($op) { case "add": diary_add(); break; case "edit": diary_edit($id); break; case "view": diary_display($name); break; case "Preview diary entry": if ($id) diary_preview($text, $timestamp, $id); else diary_preview($text, time()); break; case "Submit diary entry": if ($id) diary_submit($text, $id); else diary_submit($text); break; default: diary_overview(); } ?>