// Echramath's blog script // (c) Mikko Järvinen 2004 // License: do what thou wilt // This main file does not do much more than write the basic // structure of the resulting page and handle magic words // or errors. include("magic.php"); define("INIFILE", "blog.ini"); define("HTMLFILE", "base.html"); global $setup; global $translation; global $page; $page = $_GET['page']; $page = check_page_format($page); $setup = parse_ini_file(INIFILE); // read all languagespesific text $translation = parse_ini_file("lang/lang.ini." . $setup["lang"]); process_html(HTMLFILE); function process_html($target){ if (!is_readable($target)){ die("
$target not found or unreadable.\n
"); } $whole_page = file($target); // if the line contains a magic word, something special happens // normal lines are dumped to the page as they are foreach ($whole_page as $baseline){ if (substr($baseline, 0, 1) == ":"){ magicline(substr($baseline,1)); // cut of the ":" } else{ echo($baseline); } } } // well, actually this check if $page is a valid page request // either first, recent or a 8-digit number yyyymmdd. function check_page_format($page){ global $page_type; $page_type= 0; if (!$page || $page=="") $page="recent"; if ($page == "recent"){ $page = date_to_blogdate(find_previous(time() + SECS_IN_DAY)); } if ($page == "first"){ $page = date_to_blogdate(find_next(blogdate_to_date(first_year() . "0000"))); } if (strlen($page) == 8 && is_numeric($page)){ // page is a date $page_type = DAY; return $page; } if (strlen($page) == 4 && is_numeric($page)){ // page is a year $page_type = YEAR; return $page; } return($page); } function first_year(){ if (!($handle = opendir(ENTRYPATH))){ die("Error opening folder" . ENTRYPATH . "
\n"); } while (false !== ($file = readdir($handle))) { if(is_numeric($file)){ return $file; // the first year must be this } } } ?>