<?php
#########################################
#Content Management System fors
#The Honolulu Advertiser - version: 1.1 (prev. 1.0 beta 3)
#Author - Chris Kanemura
#Modified by - Tyson Oshiro
#Fusebox type system with Apache hack
#Copyright 2001 - The Honolulu Advertiser
#Modified notes:
#- updated all PHP super globals to newer version 
#- kept all passing variables :: due to legacy scripts
#########################################

$url 		= $_SERVER['REQUEST_URI'];
$domain 	= $_SERVER['SERVER_NAME'];
$copyyear 	= date("Y"); //Date info

// HEADER AND FOOTER
$defaultHeader = 'header.php';
$defaultFooter = 'footer.php';


//Article global attributes ***********
//$firstslash 	= (root)
//$engine 		= This file
//$year 		= Year
//$mon 			= Month
//$day 			= Day
//$section 		= Section
//$article 		= Article
//$printemail 	= Print - email - other
//$other 	  	= Unspecified variable
// ************************************
// Rip requested URI apart via a slash as diliminator
list($firstslash,$engine,$year,$mon,$day,$section,$article,$printemail,$other) = explode("/", $url);

// Get the correct styled month
$_arr_month_name = array("Jan"=>"January","Feb"=>"February","Mar"=>"March","Apr"=>"April","May"=>"May","Jun"=>"June","Jul"=>"July","Aug"=>"August","Sep"=>"September","Oct"=>"October","Nov"=>"November","Dec"=>"December");
$_arr_month_int = array("Jan"=>"01","Feb"=>"02","Mar"=>"03","Apr"=>"04","May"=>"05","Jun"=>"06","Jul"=>"07","Aug"=>"08","Sep"=>"09","Oct"=>"10","Nov"=>"11","Dec"=>"12");
if( array_key_exists($mon,$_arr_month_name) && array_key_exists($mon,$_arr_month_int) ) {
	$month = $_arr_month_name[$mon];
	$monnum = $_arr_month_int[$mon];
} else { // default values
	$month = "Month";
	$monnum = "01";
}
unset($_arr_month_name,$_arr_month_int); // clean-up

// Create variables for file access to clean up code a bit
$pe_url 		= "$year/$mon/$day/$section/$article";
$article_file 	= "/www/$year/$mon/$day/$section/$article";
$index_file 	= "/www/$year/$mon/$day/$section/index.html";
$indexer 		= "/www/$year/$mon/$day";
$filedir 		= "/www/engine";
$include_path 	= "/www/cms/site_includes";

if( file_exists($article_file) ) {

	// Get refering url - get section cat
	$_refer_url = $_SERVER['HTTP_REFERER'];

	// get category from url
	$_url_elem 		= explode("/",$_refer_url);
	$_url_elem_end 	= explode("=",end($_url_elem));
	$_url_section	= trim($_url_elem_end[1]); // category value from publicus
	// validate section determined from url
	// and set props
	$arr_brSecTags  = array("NEWS"=>"breaking-local","SPORTS"=>"breaking-sports","BUSINESS"=>"breaking-business","LIFE"=>"breaking-lifestyle",
							"ENT"=>"breaking-entertainment","OPINION"=>"breaking-opinion","TRAVEL"=>"breaking-travel");
	if( array_key_exists($_url_section,$arr_brSecTags) ) {
		$brSecDesignation = $arr_brSecTags[$_url_section];
	} else {
		$brSecDesignation = "breaking-main";
	}
	unset($_refer_url,$_url_elem,$_url_elem_end,$_url_section,$arr_brSecTags); // clean-up
} // end article check

// Set site/page attributes
switch($domain) {
 	case "the.honoluluadvertiser.com":
 		$header 	= $include_path."/".$defaultHeader; 
		$footer 	= $include_path."/".$defaultFooter; 
		$displayidx = "on";
		$homepage 	= "http://www.honoluluadvertiser.com";
		$copyright 	= "";
        break;
 	case "news.hawaii.com":
 		$header 	= "/www/cb/hdcheader.php";
		$footer 	= "/www/cb/hdcfooter.php";
		$displayidx = "off";
		$homepage 	= "http://www.hawaii.com";
		$copyright 	= " and hawaii.com";
 	break;
 	case "www.news.hawaii.com":
 		$header 	= "/www/cb/hdcheader.php";
		$footer 	= "/www/cb/hdcfooter.php";
		$displayidx = "off";
		$homepage 	= "http://www.hawaii.com";
		$copyright 	= " and hawaii.com";
 	break;
 	default:
 		$header 	= "/www/advinc/header.php";
		$footer 	= "/www/advinc/footer.php";
		$displayidx = "on";
		$homepage 	= "http://www.honoluluadvertiser.com";
		$copyright 	= "";
	break;
}
	
//Select which template to build
if($email == "on" && file_exists($article_file)) { // Email Version

	$show = "no";
	require($header);
	require("$filedir/email.php");
	require($footer);

} elseif($print == "on" && file_exists($article_file)) { // Print Version

	print("<html><head><meta name=\"robots\" content=\"noindex,nofollow\"><title>Print version - &copy; COPYRIGHT $copyyear The Honolulu Advertiser - Hawaii's Newspaper "."$copyright, a division of Gannett Co. Inc.</title><style type=\"text/css\" media=\"screen\"><!--
.storyText   { font-size: 14px; font-family: \"Times New Roman\", Georgia, Times }
--></style></head><body>");
	print("<p><center><a href=\"http://www.honoluluadvertiser.com\"><img src=\"http://the.honoluluadvertiser.com/inc/pix/halogoprnt.gif\" width=\"283\" height=\"60\" border=\"0\"></a>");
	print("<!-- <H1>Printable Version</H1>--></center></p>");
	require($filedir."/print.php");
	include($filedir."/printfooter.php");

} elseif($article && file_exists($article_file)) { // Display Article

	require($header);
	if ($displayidx == "off") {
		$article_file = file($article_file);	
		$article_file = implode($article_file, "");
		$article_file = ereg_replace("the.honoluluadvertiser.com/article", "news.hawaii.com/article", "$article_file");
		print($article_file);
	} else {
		include($article_file);
	}
	require($footer);

} elseif($day && !$section && file_exists($indexer)) { // Display index for the day

	if ($displayidx == "off") {
		header("Location: http://www.hawaii.com");
	} else {
		$show = "no";
		require($header);
		require("$filedir/indexer.php");
		require($footer);
	}

} elseif($section && !$article && file_exists($index_file)) { // Display index for the section front

	if ($displayidx == "off") {
		header("Location: http://www.hawaii.com");
	} else {
		$show = "no";
		require($header);
		require($index_file);
		require($footer);
	}

} else { // None of the above, too bad 404 a'ohe page

	$err = "404";
	require($header);
	echo('Aloha. The page you are looking for does not exist at this address. It may have been removed, or 
is otherwise unavailable. Please report any dead links to us by sending us an email at the address below. 
<div class="dotted"></div>
If you are looking for a story published within the last 7 days, please try our <a href="#">story search</a>.
<br><br>
To search for stories older than 7 days, please go to our archive search.
<br><br>
If you still need assistance, try our <a href="#">Customer Service</a> page or email us at <a href="mailto:feedback@honoluluadvertiser.com">feedback@honoluluadvertiser.com</a>.
<br><br>
Mahalo for your interest in <a href="http://www.honoluluadvertiser.com">HonoluluAdvertiser.com</a>.');
	require($footer);
}
//EOF
?> 
