<?php
 
// Google doesn't correctly link to the entry URL's so this is an attempt to correct Google's mistake..
 
if (stristr($_SERVER["HTTP_REFERER"], "google") && (isset($_GET['edit']) && is_numeric($_GET['edit']))) {
  
header("Location: ./?id=".$_GET['edit']);
 }


 
// TODO: http://naked.dustindiaz.com/
 // ----------------------------------


 // Fallback for browsers that do not support "application/xhtml+xml" (with the exception of the W3C validator).
 //if ((!stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") || isset($_GET['ancient'])) && (!stristr($_SERVER["HTTP_USER_AGENT"], "W3C")) && stristr($_SERVER["HTTP_USER_AGENT"], "MSIE")) include("text.php");
 
if ((!stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml") || isset($_GET['ancient'])) && (!stristr($_SERVER["HTTP_USER_AGENT"], "W3C"))) include("text.php");

 
// I used to check if the browser supports "application/xhtml+xml" and if so feed the page as such and if not feed it as "text/html".
 // I did this to be backwards compatible with Internet Explorer but I've now given up support; I really couldn't care less about IE's lack of standards compliance.
 // Besides that, it really is bad practice to serve X(HT)ML as "text/html", so it's best like this.
 
header("Content-type: application/xhtml+xml; charset=ISO-8859-1");
 echo 
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" [

 <!-- Add tabindexes so that the bar will be visible when tab is initially pressed. -->
 <!ATTLIST head tabindex CDATA #IMPLIED>

 <!--
  Because a child cannot set the parent to display as a block element, the menu will collapse in on itself when a <link>-element is selected.
  I keep this anyway, though, if just so users can select the links (while not seeing them).
  Maybe, some day, there will be a solution for this (CSS3?). :)
 -->
 <!ATTLIST link tabindex CDATA #IMPLIED>

 <!-- Add the onclick attribute to the Link-tags (fall-back for Opera). -->
 <!ATTLIST link onclick CDATA #IMPLIED>

]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head tabindex="1" profile="http://a9.com/-/spec/opensearch/1.1/">
<meta name="description" content="The weblog of Alessandro Lo-Presti, a.k.a. Agilo." />
<meta name="keywords"    content="Alessandro Lo-Presti, Alessandro Gabriele Isidoro Lo-Presti, Alessandro, Gabriele, Isidoro, Lo-Presti, weblog, blog, cool, links, stuff, things" />
<meta name="language"    content="en" />
<meta name="author"      content="Agilo" />
<meta name="contact"     content="agilo3@gmail.com" />
<link rel="start" title="Home" href="http://agilo.acjs.net/" tabindex="2" onclick="javascript:gotolink(this);" />
<!-- <link rel="help" title="About" href="#" tabindex="3" />  Note to self: this also bumps up the text in the bottom bar, be sure to edit when implementing. -->
<?php
 
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
  
$nav_total count(@file("blog.txt"));
  if ((
$_GET['id']>1) && ($_GET['id']<=$nav_total)) echo '<link rel="prev" tabindex="3" title="Previous Entry" href="http://agilo.acjs.net/?id='.($_GET['id']-1)."\" onclick=\"javascript:gotolink(this);\" />\n";
  if ((
$_GET['id']>=1) && ($_GET['id']<$nav_total)) echo '<link rel="next" tabindex="4" title="Next Entry" href="http://agilo.acjs.net/?id='.($_GET['id']+1)."\" onclick=\"javascript:gotolink(this);\" />\n";
 }
?>
<link rel="StyleSheet" type="text/css" media="screen" href="<?= /* Just for fun :P: */ ((isset($_GET['gay'])) ? "gay.css" "style.css"?>" title="Default StyleSheet" />
<link rel="Alternate StyleSheet" type="text/css" media="screen" href="kryptondog/style.css" title="StyleSheet by kryptondog" />
<link rel="alternate" type="application/rss+xml"  title="RSS 2.0 feed"  href="http://agilo.acjs.net/weblog.rss?syndication=2.0" tabindex="5" onclick="javascript:gotolink(this);" />
<link rel="alternate" type="application/rss+xml"  title="RSS 0.91 feed" href="http://agilo.acjs.net/weblog.rss?syndication=0.91" tabindex="6" onclick="javascript:gotolink(this);" />
<link rel="alternate" type="application/atom+xml" title="Atom feed"     href="http://agilo.acjs.net/weblog.rss?syndication=atom" tabindex="7" onclick="javascript:gotolink(this);" />
<link rel="search" type="application/opensearchdescription+xml" href="http://agilo.acjs.net/opensearch.php" title="Agilo's Weblog" />
<link rel="Shortcut Icon" href="data:image/x-icon,%00%00%01%00%01%00%10%10%00%00%00%00%20%00h%04%00%00%16%00%00%00(%00%00%00%10%00%00%00%20%00%00%00%01%00%20%00%00%00%00%00%40%04%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FD%FD%FD%03%F4%F4%FB%3B%BA%BA%EC%97mm%D4%D7CC%C6%F1CC%C6%F1mm%D4%D7%BA%BA%EC%97%F4%F4%FB%3B%FD%FD%FD%03%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FD%FD%FD%11%CB%CB%F0%83MO%C7%E9%1C%1E%B1%FF%15%15%AD%FF%14%14%AC%FF%14%14%AC%FF%15%15%AD%FF%1B%1C%B2%FFMP%C6%E9%CB%CB%F0%83%FD%FD%FD%11%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FD%FD%FD%11%AD%AD%E8%A3%1F%1E%B4%FF%26%40%B7%FF0X%BE%FF%14%15%AB%FF%14%13%AC%FF%14%14%AC%FF%13%13%AC%FF%18%23%AD%FF5d%C3%FF%24-%B7%FF%AD%AD%E8%A3%FD%FD%FD%11%FF%FF%FF%01%FD%FD%FD%03%CB%CB%F0%83%1F%1F%B5%FF%12%12%AB%FF!7%B3%FFH%8E%D1%FF%1A'%AE%FF%13%13%AC%FF%14%13%AC%FF%13%13%AB%FF)J%B9%FFB%82%CD%FF%15%1A%AB%FF%1F%1F%B5%FF%CB%CB%F0%83%FD%FD%FD%03%F3%F3%FB%3DRR%C9%E7%16%16%AD%FF%13%13%AC%FF%15%1A%AB%FFC~%CB%FF.T%BC%FF%13%13%AB%FF%13%13%AC%FF%14%18%AB%FF%3Fz%CA%FF.U%BC%FF%13%13%AB%FF%13%13%AC%FFPP%C8%E7%F3%F3%FB%3D%BA%BA%EC%97%2B%2B%B8%FF%1D%1D%AF%FF%13%13%AC%FF%13%13%AB%FF%2CL%B9%FFC%83%CD%FF%16%1C%AB%FF%13%12%AC%FF%1E1%B0%FFH%8E%D1%FF%1C%2B%AF%FF%13%13%AC%FF%13%13%AC%FF%1B%1B%B2%FF%BA%BA%EC%97pp%D4%D7--%B6%FF%22%22%B1%FF%14%14%AC%FF%13%13%AC%FF%19%24%AC%FFG%8E%D0%FF%24%3D%B4%FF%12%12%AA%FF2%5E%BF%FF%3Ct%C7%FF%14%16%AA%FF%14%13%AC%FF%14%14%AC%FF%15%15%AD%FFmm%D4%D7JJ%C9%F1%2F%2F%B6%FF%2B%2B%B4%FF%18%18%AE%FF%13%14%AB%FF%26%40%B4%FFV%A9%DC%FF%3Aq%C6%FF%17!%AA%FFD%86%CE%FF'D%B6%FF%13%12%AB%FF%14%14%AC%FF%14%14%AC%FF%14%14%AC%FFCC%C6%F1JJ%C9%F1%2F%2F%B6%FF00%B6%FF%24%25%B1%FF(C%B6%FFS%94%D4%FF%3Bk%C0%FFL%8F%D0%FF-V%B7%FFE%88%CF%FF%18!%AC%FF%13%13%AC%FF%14%14%AC%FF%14%14%AC%FF%14%14%AC%FFCC%C6%F1pp%D4%D7..%B6%FF12%B5%FF%3FX%BE%FFW%9A%D6%FF0O%BA%FF%15%1A%A9%FFM%7D%CA%FF%5D%AB%DA%FF3a%C0%FF%13%14%AA%FF%14%13%AC%FF%14%14%AC%FF%13%13%AC%FF%15%15%AD%FFmm%D4%D7%BA%BA%EC%97-%2C%B8%FF%3EP%BC%FFh%AA%DC%FFDe%C0%FF%26(%B1%FF%1A%1A%AE%FF2J%B8%FFj%AC%DE%FF%203%B1%FF%13%12%AC%FF%13%13%AC%FF%13%13%AC%FF%14%14%AC%FF%1B%1B%B2%FF%BA%BA%EC%97%F3%F3%FB%3DVU%CA%E7%3CK%BB%FFo%A2%D9%FF%5C%8B%CF%FF9I%B9%FF%2C-%B3%FF(%2C%B2%FF.%3D%B6%FF%1A%1D%AE%FF%18%18%AE%FF%19%19%AE%FF%1B%1B%AF%FF%20%20%B0%FFRR%C9%E7%F3%F3%FB%3D%FD%FD%FD%03%CB%CB%F0%83.%2F%BA%FF7%40%B7%FFW%7D%CB%FFd%9F%D8%FFKo%C6%FF3%3A%B6%FF-%2C%B4%FF%2C%2C%B5%FF%2C%2C%B5%FF%2C%2C%B5%FF--%B5%FF%2F%2F%BB%FF%CB%CB%F0%83%FD%FD%FD%03%FF%FF%FF%01%FD%FD%FD%11%AE%AE%E8%A3..%BA%FF.0%B4%FF%40S%BC%FF%5E%92%D3%FF%5D%95%D4%FF%3FU%BE%FF12%B6%FF11%B6%FF%2F%2F%B5%FF%2F%2F%BB%FF%AE%AE%E8%A3%FD%FD%FD%11%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FD%FD%FD%11%CB%CB%F0%83SS%C9%E9--%B8%FF06%B5%FFIi%C5%FFNx%CB%FF%2F3%B6%FF..%B8%FFTT%C9%E9%CB%CB%F0%83%FD%FD%FD%11%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%FD%FD%FD%03%F4%F4%FB%3B%BA%BA%EC%97po%D4%D7IJ%C7%F1KN%C8%F1pq%D4%D7%BA%BA%EC%97%F4%F4%FB%3B%FD%FD%FD%03%FF%FF%FF%01%FF%FF%FF%01%FF%FF%FF%01%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF%00%00%FF%FF" />
<title>Agilo's Weblog</title>

<!-- Google Analytics. -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>

<!-- Miscellaneous javascript and Google Analytics variables. -->
<script src="./scripts.js" type="text/javascript"></script>

<?php if (isset($_GET['scorpion'])) { ?>
<style type="text/css">
/* <![CDATA[ */

 /* So I was bored.. okay? :x */
 html {
  background: #CCA url("bg_main.png") repeat-x;
  height: 100%;
 }
 body {
  background: transparent url("scorpion_corner.png") no-repeat scroll bottom right;
  padding-bottom: 100px;
  min-height: 100%;
 }

/* ]]> */
</style>

<?php ?>
</head>

<body>


<!-- - - - - - - - - - - - - - - - - - - - - - [ Credits ] - -


              ::::::::::::::::::::::::::::::::::
              ::::::::[ Agilo's Weblog ]::::::::
              ::::::::::::::::::::::::::::::::::
              $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
              $$$$$$$$$$$$$$$$$/   /$$$$$$$$$$$$
              $$$$$$$$$$$$$$/   /$$$$$$$$$$$$$$$
              $$$$$$$$$$$/   /$$$$$$$$$$$$$$$$$$
              $$$$$$$$/   /$$$$$$$$$$$$$$$$$$$$$
              $$$$$/   /$$$$$$$$$$$$$$$$$$$$$$$$
              $$$$\   \$$$$$$$/   \$$$$$$$$$$$$$
              $$$$$$\   \$$$$/     \$$$$$$$$$$$$
              $$$$$$$$\   \$/   .   \$$$$$$$$$$$
              $$$$$$$$$$\      /$\   \$$$$$$$$$$
              $$$$$$$$$$$$    /$$$\   \$$$$$$$$$
              $$$$$$$$$$$/   /$$$$$\   \$$$$$$$$
              $$$$$$$$$$/   /$$$$$$$\   \$$$$$$$
              $$$$$$$$$/   /$$$$$$$$$\   \$$$$$$
              $$$$$$$$/   /$$$$$$$$$$$\   \$$$$$
              $$$$$$$$\__/$$$$$$$$$$$$$\__/$$$$$
              $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
              ::::::::::::::::::::::::::::::::::
              ::::[ http://agilo.acjs.net/ ]::::
              ::::::::::::::::::::::::::::::::::


  Technologies used in this weblog:
  - PHP (5 and up)
  - XHTML (1.0 Strict)
  - CSS (2.1)
  - RSS (0.91, 2.0)
  - Atom (1.0)
 
  Built to conform to WAI-AA (http://www.w3.org/TR/WCAG10/).
 
 
  Files:
  - Main weblog .............................. /index.php
  - Weblog source ............................ /index.phps
  - Database ................................. /blog.txt
  - CSS file ................................. /style.css
  - RSS file ................................. /weblog.rss
  - RSS source file .......................... /weblog.phps
  - Quotes ................................... /quotes.txt
 
  Directories:
  - Uploaded files ........................... /files/
  - Smiley icons ............................. /smilies/
 
 
  Built by Alessandro Lo-Presti (Agilo).
  Contact:
  - E-mail .................... agilo3@gmail.com
  - MSN ....................... agilo3@hotmail.com
  - AIM ....................... agilo333
  - YIM ....................... Agilo3
  - ICQ ....................... 174561344
  - IRC ....................... irc.webmaster.com (#gentoo)

 
  Special thanks:
  - ACJ (http://acjs.net/)
  - kryptondog (http://www.jameslabove.org/)
  - Michel Olivier (http://www.molivier.nl/)
  - Ed van der Molen
  - Emanuele Lo-Presti


 - - [ / Credits ] - - - - - - - - - - - - - - - - - - - - -->



<!-- Head bar. -->
<div id="head"></div>

<!-- Header. -->
<div id="header">
 <h1 title="Agilo's Weblog"><a href="./"><acronym title="Alessandro Gabriele Isidoro Lo-Presti">Agilo</acronym>'s Weblog</a></h1>
</div>

<!-- Random quote. -->
<div id="quote">
 <hr class="invisible" />
 <small><?php
  
// Output a random quote from the database, just for fun.
  
if (file_exists("quotes.txt")) {
   foreach (@
file("quotes.txt") as $quote) {
    
$quot explode("|"$quote);
    
$quot preg_replace("/\"(.*?)\"/is""<q>\\1</q>"$quot);
    
$quot preg_replace("/- (.*?)$/is""&#x2015; <cite>\\1</cite>"$quot);
    
$quot preg_replace("/  /is"" &nbsp;"$quot);
    echo 
$quot[rand(1,(count($quot)-2))];
   }
  } else {
   echo 
"<q>The quotes database does not exist!</q> &#x2015; <cite>Agilo</cite>";
  }
 
?><br /></small>
</div>

<?php
  
// Pending deletion..


 /*

  <!-- Internet Explorer users must be warn of the danger they are in! -->

  <!--[if IE]>

  <hr class="invisible" />

  <div class="notice">
   <div class="txt" onclick="javascript:location='http://www.mozilla.org/'">
    <div class="note"><strong>Notice:</strong></div>
    Please use a more capable browser than <strong onmouseover="javascript:this.innerHTML='Intergay Exploiter'" onmouseout="javascript:this.innerHTML='Internet Explorer'">Internet Explorer</strong>.<br />
    Try using a <em>real</em> browser such as <a href="http://www.mozilla.org/products/mozilla1.x/">Mozilla</a> or <a href="http://www.mozilla.org/products/firefox/">Mozilla FireFox</a><br />
    which are built to suit the web by conforming to specifications<br />
    and web-standards to which this site adheres.<br /><br /><br />
    Internet Explorer is the <em>worst</em> browser still in use today.<br />
    For this reason, I have disabled all CSS hacks for Internet Explorer and<br />
    have intentionally left my weblog broken (the way it is now).<br />
    I have no intention to fix any if IE's shortcomings, instead I<br />
    once again redirect (and urge) you to download <strong>any</strong> other browser,<br />
    be it Mozilla, Mozilla FireFox, <a href="http://www.opera.com/">Opera</a>, <a href="http://www.konqueror.org/">Konqueror</a>,<br />
    <a href="http://www.apple.com/safari/">Safari</a>, <a href="http://artax.karlin.mff.cuni.cz/~mikulas/links/">Links</a>, <a href="http://lynx.browser.org/">Lynx</a> or <a href="http://browsers.evolt.org/"><strong>any</strong> other browser</a>!<br />
    Switch now and enjoy the benefits!<br /><br /><br />
    Still not convinced? &nbsp;More elaborate <abbr>info</abbr> on: <a href="http://www.browsehappy.com/">BrowseHappy.com</a>.
   </div>
  </div>

  <![endif]-->

  <!--
   By the way, I won't remove this, so don't contact me about it.
   I'm actually THIS close to redirecting all IE users to something like www.lemonparty.org by HTTP headers.
   So be thankful I'm just putting up a notice and have disabled all IE specific CSS hacks.
  -->

 */
?>

<!-- Main weblog. -->
<div id="main">
 <div id="body">

  <hr class="invisible" />

<?php
 
// Configuration:
 
$file     "blog.txt";
 
$wrap_num 15;

 
// Authentication:
 
$username "Agilo";
 
$password strrev("591986n17q9r576034ssqrnrs6914r831520n2a74z106sjfbha930r4");
 
$email    "agilo3@gmail.com";

 
// Extensions:
 
$extent[] = "Gwen";
 
$extent[] = "Lenna";
 
$extent[] = "King Crimson";
 
$extent[] = "Nintendo DS";
 
$extent[] = "Vlora";


 
// - - - - - - - - - - - - - - - - - - - - - - - -


 
if(!isset($_GET['admin'])) echo '  <span class="left"><small>(<a href="./?admin">Add a new entry</a>)</small> &nbsp; </span>'."\n";


 
// Check if database file exists.
 
if (!file_exists($file))  echo "\n  <br /><h2 class=\"center\">Error: database file is non-existant!</h2>\n\n";

 
// Check if database file is writeable.
 
if (!is_writeable($file)) echo "\n  <!-- Error: database file is not writeable! -->\n\n";



 
// Show the page selection box.
 
function select($num) {
  global 
$wrap_num$file;

  
$i=1;
  
$total_entries count(@file($file));

  if (
$total_entries $wrap_num) {
   echo 
"  <form method=\"get\" action=\"./\">\n".
        
"   <div class=\"right\">\n".
        
"    <label for=\"offset$num\" class=\"invisible\">Select a page: </label>\n".
        
"    <select name=\"offset\" id=\"offset$num\">\n".
        
"     <optgroup label=\"Pages\">\n";
   for (
$x=$total_entries$x>=0$x--) {
    
$page_num = ($x*$wrap_num);
    if (
$page_num $total_entries) {
     if (isset(
$_GET['offset']) && is_numeric($_GET['offset']) && ($_GET['offset'] == $page_num)) $selected ' selected="selected"';
     echo 
"      <option".$selected." value=\"".$page_num."\">Page ".$i."</option>\n";
     unset(
$selected);
     
$i++;
    }
   }
   echo 
"     </optgroup>\n".
        
"    </select>\n".
        
"    <input type=\"submit\" alt=\"Go\" value=\"Go\" class=\"submitbutton\" />\n".
        
"   </div>\n".
        
"  </form>\n\n";
  }
 }



 
// Show the search box.
 
function show_search() {
  if (isset(
$_POST['search'])) {
   
$search preg_replace("/(\<(.*?)\>|[%()#&*^\\\])/"""$_POST['search']);
   
$search htmlentities(stripslashes($search));
  }
  echo <<<___END___

  <form method="post" action="./?search">
   <div class="searchbox">
    <label for="search" class="invisible">Search: </label>
    <input type="text" id="search" name="search" size="15" maxlength="75" alt="Search" value="
$search" />
    <input type="submit" value="Search" alt="Go" class="submitbutton" />
   </div>
  </form>


___END___;
 }



 
// This function isn't written by me (it has been adjusted slightly by me, though).
 
function posted($stamp) {
  
$diff = (time() - strtotime(preg_replace("/,/"""$stamp)));

  if (
$diff <= 3600) {
   
$mins round($diff 60);
   
$since = ($mins <= 1) ? ($mins==1) ? "1 minute" "a few seconds" "$mins minutes";
  } else if ((
$diff <= 86400) && ($diff 3600) && ($diff 31536000)) {
   
$hours round($diff 3600);
   
$since = ($hours <= 1) ? "1 hour" "$hours hours";
  } else if ((
$diff >= 86400) && ($diff 31536000)) {
   
$days round($diff 86400);
   
$since = ($days <= 1) ? "1 day" "$days days";
  } else if (
$diff >= 31536000) {
   
$since "over a year";
  } else {
   
// It should never get here, but I'll let it fall back here anyway.
   
$since "some time";
  }

  return 
"Posted $since ago.";
 }



 
// Show the entries.
 
function show_entry($entry_icon$entry_topic$entry_name$entry_mail$entry_date$entry_txt$entry_id) {
  global 
$extent;

  
// Highlight search results:
  
if (!empty($_GET['highlight']) && strlen($_GET['highlight']) > 1) {
   
$highlight $_GET['highlight'];
   
// Special thanks (for the pattern to exclude HTML) to Aidan (http://aidan.dotgeek.org/repos/?file=function.str_highlight.php)!
   
$entry_topic preg_replace("/(?!<.*?)\b".$highlight."\b(?![^<>]*?>)/i""<span class=\"highlight\">\\0</span>"$entry_topic);
   
$entry_txt   preg_replace("/(?!<.*?)\b".$highlight."\b(?![^<>]*?>)/i""<span class=\"highlight\">\\0</span>"$entry_txt);
  }

  
// Add extensions to the entry.
  
for ($i=0$i<count($extent); $i++) if (preg_match("/".$extent[$i]."/i"$entry_topic)) { 
   
$entry_ext "-".preg_replace("/ /"""strtolower($extent[$i]));
  }

  
// Might do more with this sometime.
  
$posted "<!-- ".posted($entry_date)." -->";

  echo <<<___END___

  <div class="entry
$entry_ext">$posted
   <p class="date">
    <span class="invisible"><strong>Date added:</strong></span>
    <a id="entry
$entry_id" href="#entry$entry_id" title="Link to this entry."><strong>$entry_date</strong></a>
   </p>
   <h2 class="topic">
$entry_topic</h2>
   <div class="text">
    
$entry_txt
   </div>
   <address class="signed">
    &#x2015; <a href="mailto:
$entry_mail" title="E-mail $entry_name.">$entry_name</a>
   </address>
   <div class="container">
    <p class="bar">
     <small>
      <a href="./?id=
$entry_id" title="Permanent link to entry #$entry_id."><abbr>PermaLink</abbr></a>
      &nbsp;|&nbsp;
      <a href="./?admin&amp;edit=
$entry_id" title="Edit entry #$entry_id.">Edit</a>
     </small>
    </p>
   </div>
  </div>

  <hr class="line" />

___END___;
 }



 
// This little function took me 2 (yes; TWO) hours to create.
 // This function takes an argument (the text which needs to be formatted) and creates paragraphs from it.
 // However it filters block-level elements which shouldn't be placed inside paragraphs (according to XHTML guidelines).
 
function paragraphs($text) {
  
// Create paragraphs on multiple line-breaks:
  
$text preg_replace("/(\n){2,9}/""\n    </p>\n    <p>\n     "$text);

  
// If the line doesn't end with "<p>" or "</p>" and neither tag is on the next line, append a line-break:
  
$text preg_replace("/(?<!<p>|<\/p>)\n(?!(\s*)<p>|(\s*)<\/p>)/""<br />\n     "$text);

  
// If there's a block-element in the created paragraphs seperate them (remove preceding "<p>"):
  
$text preg_replace('!<p>\s*(</?(?:table|dl|div|ul|ol|pre|blockquote|p|h2|h3|h4)[^>]*>)!'" $1"$text); // *

  // If there's a block-element in the created paragraphs seperate them (remove trailing "</p>"):
  
$text preg_replace('!(</?(?:table|dl|div|ul|ol|pre|blockquote|p|h2|h3|h4)[^>]*>)\s*</p>!'"$1"$text); // *

  // If the seperated block element (and child elements) has an appended line-break, remove it:
  
$text preg_replace('!(</?(?:table|tr|td|th|dl|dt|dd|div|ul|ol|li|pre|blockquote|p|h2|h3|h4)[^>]*>)\s*<br />!'"$1"$text);


  
// In designing this I forgot that the "<blockquote>" tag needs a child block-element!
  // The following two regular expression replaces will take care of this.
  // It's not pretty (neither code nor output), but it works.

  // If the "<blockquote>"-tag is found, create a trailing "<p>"-tag.
  
$text preg_replace("/<blockquote>/""<blockquote>\n      <p>"$text);

  
// If the "</blockquote>"-tag is found at the end of a line, preceed it with a "</p>"-tag.
  
$text preg_replace("/<\/blockquote>\n/""</p>\n    </blockquote>\n"$text);


  
// If the text doesn't start out with a block-element, start it with a "<p>":
  
$text preg_replace("/^(?!<(?:table|dl|div|ul|ol|pre|p|h2|h3|h4)>)/""<p>\n     "$text);

  
// If the text doesn't end with a block-element, append a "</p>":
  // This doesn't work, can't make it work either:
  //  - $text = preg_replace("/(?!<(?:table|dl|div|ul|ol|pre|blockquote|p)>)$/", "\n</p>", $text);
  // So instead I'm forced to this:
  
if (!preg_match("/<(\/)(?:table|dl|div|ul|ol|pre|p|h2|h3|h4)>$/"$text)) $text .= "\n    </p>";
  
// If anyone can help me, please contact me.

  // Return the formatted text.
  
return $text;


  
// * Thanks to http://photomatt.net/scripts/autop for this regular expression.
  //   I wouldn't have found out how to get it done the right way without it.
  //   Thanks Matt!
 
}



 
// Main weblog function.
 
function weblog() {
  global 
$file$wrap_num;

  
// Show offset selection box.
  
echo "  <hr class=\"invisible\" />\n\n";  select("1");  echo "  <hr class=\"line\" />\n";
  
// Show the search box.
  
show_search();  echo "  <hr class=\"line\" />\n";

  
$entries = @file($file);
  
$total_entries count($entries);
  
$rand rand(1,$total_entries);
  foreach (
$entries as $entry) {
   
$data explode("||"$entry);

   
// Replace "\n" with "<br />".
   //$data[5] = preg_replace("/\\\\n/", "\n    <br />", $data[5]);

   
$data[5] = preg_replace("/\\\\n/""\n"$data[5]);

   
$data[5] = paragraphs($data[5]);


   
// Replace emoticons with a picture resembling them.

   // Set width and height for all images (this way to save space in width).
   
$wh "width=\"15\" height=\"15\"";
   
// Array of smileys.
   
$smileys      = array ("':\)|:-\)'i",                         // :)
                          
"':\(|:-\('i",                         // :(
                          
"':&#124;|:-&#124;|:\||:-\||:O|:-O'i"// :| :o
                          
"':D|:-D'i",                           // :D
                          
"':P|:-P'i",                           // :P
                          
"':S|:-S'i",                           // :S
                          
"':x|:-x'i");                          // :x
   // Array of replacement HTML.
   
$html_smileys = array ("<img src=\"smilies/smile.gif\" $wh alt=\"&#58;)\" title=\"&#58;)\" />",
                          
"<img src=\"smilies/sad.gif\" $wh alt=\"&#58;(\" title=\"&#58;(\" />",
                          
"<img src=\"smilies/amazed.gif\" $wh alt=\"&#58;o\" title=\"&#58;o\" />",
                          
"<img src=\"smilies/laugh.gif\" $wh alt=\"&#58;D\" title=\"&#58;D\" />",
                          
"<img src=\"smilies/tongue.gif\" $wh alt=\"&#58;P\" title=\"&#58;P\" />",
                          
"<img src=\"smilies/confused.gif\" $wh alt=\"&#58;S\" title=\"&#58;S\" />",
                          
"<img src=\"smilies/smile_x.gif\" $wh alt=\"&#58;x\" title=\"&#58;x\" />"); 
   
// Replace.
   
$data[5] = preg_replace($smileys$html_smileys$data[5]); 


   
// Re-format the time string.
   
$date date('l, F j Y, h:iA'strtotime($data[4])); //." +6 hours"));



   // If "id" or "random" are set, don't show all entries (just the entry with the same or random ID).
   
if (isset($_GET['id']) || isset($_GET['random'])) {
    
// We check '"Entry".$data[7]' for backwards compatibility.
    
if ($_GET['id'] == "Entry".$data[7] || $_GET['id'] == $data[7]) {
     
// Show the selected "id" entry.
     
show_entry($data[0], $data[1], $data[2], $data[3], $date$data[5], $data[7]);
    } else if (isset(
$_GET['random']) && $rand == $data[7]) {
     
// Show the random entry.
     
echo "\n  <h3 class=\"center\">Random entry: #<var>".$data[7]."</var><br /></h3>\n";
     
show_entry($data[0], $data[1], $data[2], $data[3], $date$data[5], $data[7]);
    }
   } else {
    
// Show all entries.
    
if (isset($_GET['show']) && $_GET['show'] == "all") {
     
show_entry($data[0], $data[1], $data[2], $data[3], $date$data[5], $data[7]);
    } else {
     if (isset(
$_GET['offset']) && is_numeric($_GET['offset'])) {
      
// Show $wrap_num entries per page starting from "$_GET['offset']".
      
if ($data[7] > $_GET['offset'] && $data[7] <= ($_GET['offset']+$wrap_num)) {
       
show_entry($data[0], $data[1], $data[2], $data[3], $date$data[5], $data[7]);
      } else {
       if (
$_GET['offset'] < || $_GET['offset'] > $total_entries) if (empty($error)) {
        echo 
"\n  <h2 class=\"center\">Error: bad offset!</h2>\n\n  <hr class=\"line\" />\n\n";
        
$error TRUE;
       }
      }
     } else {
      
// Show $wrap_num entries per page starting from "$total_entries - $wrap_num - 1".
      
if ($data[7] > ($total_entries-$wrap_num-1) && $data[7] <= $total_entries) {
       if (
$total_entries >= $wrap_num && $data[7] >= $wrap_num) {
        
show_entry($data[0], $data[1], $data[2], $data[3], $date$data[5], $data[7]);
       } else if(
$total_entries <= $wrap_num) {
        
show_entry($data[0], $data[1], $data[2], $data[3], $date$data[5], $data[7]);
       }
      }
     }
    }
   }
  }

  
// Show offset selection box.
  
echo "\n";  select("2");
 }



 
// Admin functions.
 
function admin() {
  global 
$file;

  
// Edit an entry.
  
if(isset($_GET['edit']) && is_numeric($_GET['edit'])) {
   
$edit $_GET['edit'];

   
$entries = @file($file);
   
$total_entries count($entries);
   foreach (
$entries as $entry) {
    
$data explode("||"$entry);
    if (
$edit == $data[7]) {
?>
  <form method="post" action="<?= $_SERVER['PHP_SELF'?>?admin">
   <fieldset>
    <legend>Editing entry <?= $data[7?></legend>
    <dl>
     <dt><label for="date">Date:</label></dt>
     <dd><input type="text" name="date" id="date" size="36" maxlength="75" value="<?= $data[4?>" /></dd>
     <dt><label for="subject">Subject:</label></dt>
     <dd><input type="text" name="subject" id="subject" size="36" maxlength="75" value="<?= $data[1?>" /></dd>
     <dt><label for="entry">Entry:</label></dt>
     <dd>
      <textarea name="entry" id="entry" cols="52" rows="15"><?= htmlentities(preg_replace("/\\\\n/""\n"$data[5])) ?></textarea>
     </dd>
    </dl>
    <hr class="line2" />
    <dl>
     <dt><label for="username">Username:</label></dt>
     <dd><input type="text" name="username" id="username" size="20" maxlength="50" /></dd>
     <dt><label for="password">Password:</label></dt>
     <dd><input type="password" name="password" id="password" size="20" maxlength="70" /></dd>
    </dl>
    <input type="hidden" alt="" name="cat"          value="<?= $data[0?>" />
    <input type="hidden" alt="" name="author"       value="<?= $data[2?>" />
    <input type="hidden" alt="" name="author_email" value="<?= $data[3?>" />
    <input type="hidden" alt="" name="ip"           value="<?= $_SERVER['REMOTE_ADDR'?>" />
    <input type="hidden" alt="" name="id"           value="<?= $data[7?>" />
    <input type="hidden" alt="" name="editing"      value="1" />
    <input type="submit" alt="Submit" value="Edit entry" />
   </fieldset>
  </form>
<?php
    
}
   }
  } else {
  
// Add a new entry.
?>
  <form method="post" action="<?= $_SERVER['PHP_SELF'?>?admin">
   <fieldset>
    <legend>Create a new entry</legend>
    <dl>
     <dt><label for="subject">Subject:</label></dt>
     <dd><input type="text" name="subject" id="subject" size="36" maxlength="75" value="<?= htmlentities(stripslashes($_POST['subject'])) ?>" /></dd>
     <dt><label for="entry">Entry:</label></dt>
     <dd><textarea name="entry" id="entry" cols="52" rows="15"><?= htmlentities(stripslashes($_POST['entry'])) ?></textarea></dd>
    </dl>
    <hr class="line2" />
    <dl>
     <dt><label for="username">Username:</label></dt>
     <dd><input type="text" name="username" id="username" size="20" maxlength="50" /></dd>
     <dt><label for="password">Password:</label></dt>
     <dd><input type="password" name="password" id="password" size="20" maxlength="70" /></dd>
    </dl>
    <input type="hidden" alt="" name="cat" value="default" />
    <input type="submit" alt="Submit" value="Add entry" />
   </fieldset>
  </form>
<?
  
}
 }


 
// Write an entry to the database.
 
function write() {
  global 
$file$username$password$email;

  
// First we verify that we've properly authenticated.
  
if (($_POST['username'] == $username) && (str_rot13(md5(sha1(md5($_POST['password'])))) === substr(strrev($password),((((strlen(md5("This is the best password-scheme ever."))-strlen(date("%Y %m-%h")))>>2)|3)+93-154+5-1),strlen(md5("Agilo"))))) {

   
// Some safetly checks (I have to rewrite this sometime..).
   
$entry   stripslashes($_POST['entry']);
   
$entry   preg_replace("/\n/"'\n'$entry);
   
$entry   preg_replace("/\r/"''$entry);
   
$entry   preg_replace("/&/""&amp;"$entry);
   
$entry   preg_replace("/  /"" &nbsp;"$entry);
   
$entry   preg_replace("/\|/""&#124;"$entry);
   
$entry   preg_replace("/(&amp;lt;|&amp;&amp;lt;)/""&lt;"$entry);
   
$entry   preg_replace("/(&amp;gt;|&amp;&amp;gt;)/""&gt;"$entry);
   
$entry   preg_replace("/(&amp;mdash;|&amp;&amp;mdash;)/""&mdash;"$entry);
   
$entry   preg_replace("/(&amp;nbsp;|&amp;&amp;nbsp;)/""&nbsp;"$entry);
   
$entry   preg_replace("/(&amp;amp;|&amp;&amp;amp;)/""&amp;"$entry);
   
$entry   preg_replace("/(&amp;euro;|&amp;&amp;euro;)/""&euro;"$entry);
   
$entry   preg_replace("/(&amp;#|&amp;&amp;#)/""&#"$entry);
   
$subject stripslashes($_POST['subject']);
   
$subject preg_replace("/&/""&amp;"$subject);
   
$subject preg_replace("/(&amp;amp;|&amp;&amp;amp;)/""&amp;"$subject);
   
$subject preg_replace("/\|/""&#124;"$subject);

   
// Typo checks. ;)
   
$typos   = array("'\bteh\b'""'\btaht\b'""'\bwaht\b'""(\byo're\b|\byo'ure\b)""'\bliek\b'""'\bgiong\b'""'\banywya\b'");
   
$fixes   = array("the""that""what""you're""like""going""anyway");
   
$entry   preg_replace($typos$fixes$entry);
   
$subject preg_replace($typos$fixes$subject);


   
// Now we start writing functions.
   
if ($_POST['editing']==1) {
    
// Edit an existing entry.

    // Setting up for the save.
    
$id $_POST['id'];
    
$all_entries = @file($file);
    foreach (
$all_entries as $a_entry) {
     
$line $a_entry;
     
$data explode("||"$a_entry);

     
// If the ID of the line doesn't match our ID.
     
if ($id != $data[7]) {
      
// Append it to the array (unedited entry).
      
$lines .= $line;
     } else {
      
// Otherwise append our string (=modified entry) to the array.
      
$lines .= $_POST['cat']."||".$subject."||".$_POST['author']."||".$_POST['author_email']."||".$_POST['date']."||".$entry."||".$_POST['ip']."||".$id."||\n";
     }

    }

    
// The actual save.
    
$save = @fopen($file"w+");
    if (!@
fwrite($save$lines)) {
     echo 
"  <strong>Error:</strong> Unable to save data! &nbsp;<small>(File rights?)</small>";
    } else {
     echo 
"  <strong>Data saved successfully!</strong><br /><br />\n".
          
"  <a href=\"".$_SERVER['PHP_SELF']."?id=$id\">View your entry</a> or <a href=\"./\">return to the weblog</a>.";
    }
    @
fclose($save);

   } else {
    
// Write a new entry.

    // Get old content.
    
$ofile = @fopen($file"rb");
    
$entries = @fread($ofilefilesize($file));
    
$id = @count(@file($file))+1;
    @
fclose($ofile);

    
// Setting up our save-string (=entry).
    
$save_string $_POST['cat']."||".$subject."||".$_POST['username']."||".$email."||".date("F j, Y g:iA")."||".$entry."||".$_SERVER['REMOTE_ADDR']."||".$id."||\n".$entries;

    
// The actual save.
    
$save = @fopen($file"w+");
    if (!@
fwrite($save$save_string)) {
     echo 
"  <strong>Error:</strong> Unable to save data!";
    } else {
     echo 
"  Data saved successfully!<br /><a href=\"".$_SERVER['PHP_SELF']."?id=$id\">View</a> your entry.";
    }
    @
fclose($save);
   }

  } else {
   
// Not properly authenticated.
   
echo "  <p>Bad username and/or password!</p>\n\n";
   
admin();
  }
 }



 
// Search the database.
 
function search($search) {
  global 
$file;

  echo 
"  <hr class=\"line\" />\n\n  <div class=\"searchresults\">\n";

  
// Remove all HTML and potentially dangerous characters from the search.
  
$search preg_replace("/(\<(.*?)\>|[%()#&*^\\\])/"""$search);

  
// Check the length of the search string.
  
if (!empty($search) && strlen($search) > 1) {
 
   
// Search the database.
   
$all_entries = @file($file);
   foreach (
$all_entries as $a_entry) {
    
$data explode("||"$a_entry);

    
// Unset this if it's still set because of the loop.
    
unset($a_result);

    
// Build arrays of the found results' ID's (searching topics and entries).
    
if (preg_match("/\b".$search."\b/i"$data[5])) { // Entries.
     
$results[] = $data[7];
     
$a_result TRUE;
    }
    if (
preg_match("/\b".$search."\b/i"$data[1])) { // Topics.
     
$results[] = $data[7];
     
$a_result TRUE;
    }

    
// Build arrays of the found results' topics.
    
if ($a_result==TRUE$topic_results[] = $data[1];
   }
 
   
// check if there are any results found.
   
if (count($results)>0) {
 
    
// Filter doublicate entries.
    
foreach (@array_keys(@array_unique($results)) as $num$result[] = $results[$num];

    
// Echo results.
    
$search urlencode(htmlentities(htmlspecialchars(stripslashes($search))));
    echo 
"   Search results for <q><strong>".$search."</strong></q>:<br />\n   <ul>\n";
    for (
$a=0$a<count($result); $a++) {
     echo 
"    <li>Entry #".$result[$a].": <a href=\"./?id=".$result[$a]."&amp;highlight=".$search."\">".$topic_results[$a]."</a></li>\n";
    }
    echo 
"   </ul>\n   <br />Total results: <strong>".count($result)."</strong>\n\n";
 
   } else {
    
// No results found.
    
$search urlencode(htmlentities(htmlspecialchars(stripslashes($search))));
    echo 
"    No results found for <q><strong>".$search."</strong></q>. <img src=\"smilies/sad.gif\" width=\"15\" height=\"15\" alt=\"&#58;(\" title=\"&#58;(\" />\n";
   }

  } else {
   
// Search string is too short.
   
echo "   Your search string either contained illigal characters or was too short.<br /><br />\n";
  }

  
// Show the search box.
  
echo "   <hr class=\"line\" />\n";  show_search();

  echo 
"  </div>\n";

 }



 
// Weblog set-up:
 
if (isset($_GET['admin'])) {
  if (isset(
$_POST['cat'])) {
   
write();
  } else {
   
admin();
  }
 } else {
  if (isset(
$_GET['search'])) {
   
search($_POST['search']);
  } else {
   
weblog();
  }
 }
?>

  <hr class="invisible" />

 </div>
</div>

<!-- Footer. -->
<div id="footer">
 <div id="footer_content">
  <p class="right">
   <small>(View: <a href="./?random">random entry</a>; <a href="./?show=all" title="This may take a LONG time to load!">all entries</a>; <a href="<?= $_SERVER['PHP_SELF'?>s">weblog source</a>; <a href="./style.php?file=style.css"><abbr title="Cascading StyleSheet">CSS</abbr> file</a>)</small><br /><br />
   <a href="http://validator.w3.org/check/referer"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr> 1.0 Strict</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer" onmousedown="javascript:alert('The CSS validator will complain about the use of &quot;-moz-border-radius&quot;, however, it is valid CSS! &nbsp;See te CSS file (bottom) for details.')"><abbr title="Cascading StyleSheet">CSS</abbr></a> compliant.<br />
   <!-- The CSS validator will complain about the use of "-moz-border-radius", however, it is valid CSS!  See te CSS file (bottom) for details. -->
   <a href="http://www.w3.org/TR/WCAG10/full-checklist.html"><abbr title="Web Accessibility Initiative (priority 2)">WAI-AA</abbr></a> conformance to the <a href="http://www.w3.org/WAI/intro/wcag.php"><abbr title="Web Content Accessibility Guidelines 1.0">WCAG</abbr></a>.<br /><br />
   <a href="weblog.rss?syndication=2.0" type="application/rss+xml"><img src="rss.gif" width="36" height="14" alt="RSS 2.0 feed" title="RSS 2.0 feed." /></a>
   <a href="weblog.rss?syndication=0.91" type="application/rss+xml"><img src="rss.gif" width="36" height="14" alt="RSS 0.91 feed" title="RSS 0.91 feed." /></a>
   <a href="weblog.rss?syndication=atom" type="application/atom+xml"><img src="atom.gif" width="36" height="14" alt="Atom feed" title="Atom feed." /></a>
  </p>
  <br />
 </div>
</div>

<!-- Foot bar. -->
<div id="foot"></div>

</body>
</html>