"; $blog_file = "blog.txt"; include("load_entries.php"); error_reporting(22519); $mode = $_GET["mode"]; if (!isset($mode) || $mode == "show") show_blog(); elseif ($mode == "new") { new_entry_form(); } elseif ($mode == "add") { add_entry(); } function new_entry_form() { $tags = array(); $entries = load_entries("blog.txt"); foreach ($entries as $entry) { foreach ($entry["tags"] as $tag) { if (!in_array($tag, $tags)) $tags[] = $tag; } } sort($tags); ?>

New entry

Title:
Date:
Text:
Tags: $tag\n"); } ?>
New tag(s): (separate with commas)
",$params,""); echo "
";
var_dump($params);
echo "
"; */ $f = fopen("blog.txt", "a"); fwrite($f, "{$params['title']}\n"); if (isset($params['tags'])) $tags = $params['tags']; else $tags = array(); if (isset($params['newtags'])) { foreach (explode(",", $params['newtags']) as $new) { $new = trim($new); if ($new && !in_array($new, $tags)) $tags[] = $new; } } if (count($tags) != 0) { fwrite($f, "tags: " . implode(",", $tags) . "\n"); } fwrite($f, "{$params['date']}\n"); fwrite($f, "{$params['text']}\n"); fwrite($f, ".end\n"); show_blog(); } function show_blog() { echo "
\n"; $entries = load_entries("blog.txt"); if (isset($_GET["filter"])) { $filter_tag = $_GET["filter"]; echo "

Posts tagged $filter_tag  X 

\n"; } $entry_num = 1; $posts = ""; foreach ($entries as $entry) { if ($filter_tag && !in_array($filter_tag, $entry["tags"])) continue; #var_dump($entry); $title = $entry["title"]; echo generate_date_div($entry["date"]); echo "
\n"; $link = "$title
"; $posts = $link . $posts; $title = hop($title); echo "

$title

\n"; echo "
\n"; foreach (explode("\n",$entry["text"]) as $line) { if ($line == "") continue; if ($line[0] == ".") echo process_dot_line($line); else echo "$line\n"; } echo "
"; if ($entry["tags"]) { echo "
"; foreach ($entry["tags"] as $tag) { echo "$tag "; } echo "
"; } echo "\n"; echo "

\n"; $entry_num += 1; } echo "

My Posts
(most recent first)

$posts
\n"; echo "
\n"; } function hop($s) { $result = ""; for ($i = 0; $i < strlen($s); $i++) { $result .= "$s[$i]"; } return $result; } function process_dot_line($line) { if ($line == ".p") { return "

"; } elseif ($line[2] == " ") { // .X ... $rest = substr($line, 3); return "<{$line[1]}>$rest\n"; } elseif ($line[3] == " ") { if ($line[1] == "r") $float = "right"; else $float = "left"; $src = substr($line, 4); return ""; } } function generate_date_div($date) { $months = "JanFebMarAprMayJunJulAugSepOctNovDec"; $month = substr($months, (substr($date, 5, 2)-1)*3, 3); $day = ltrim(substr($date, 8, 2), "0"); $year = substr($date, 0, 4); return "

$month $day
$year
\n"; }