Egh. Here we go.
Index.php
Code: Select all
<?php
// Start the session
session_start();
// Declare globals
global $gCurrPage;
// Set globals
$gCurrPage = !empty($_GET['q']) ? $_GET['q'] : 'home';
// Constants
define('MYSQL_HOST', 'localhost');
define('MYSQL_USER', 'root');
define('MYSQL_PASS', 'youwish');
define('MYSQL_DBNAME', 'dbname');
// Initialize classes
function __autoload($class_name) {
require_once('inc/'.$class_name.'.class.php'); }
$PageBuilder = new PageBuilder();
$DatabaseLayer = new DatabaseLayer();
// Inlude functions
require_once('inc/functions.inc.php');
// Build the page
$PageBuilder->BuildPage();
?>
pagebuilder.class.php
Code: Select all
class PageBuilder
{
private $current_page;
public function __construct()
{
$this->current_page = $gCurrPage;
}
public function BuildPage()
{
PageBuilder::ShowTop();
PageBuilder::ShowHeader();
PageBuilder::ShowMenu();
PageBuilder::ShowCurrPage();
PageBuilder::ShowFooter();
}
public function ShowTop()
{
print '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1═strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http═equiv="Content═Type" content="text/html; charset=utf═8" />';
?>
<style type="text/css">
<!--
@import "inc/css/layout.css";
@import "inc/css/menu.css";
@import "inc/css/style.css";
-->
</style>
<!--[if IE]>
<style type="text/css" media="screen">
#menu { float:none; }
body { behavior:url("inc/csshover2.htc"); font═size:100%; }
#menu ul li { float:left; width: 100%; }
#menu h2, #menu a { height:1%;font:bold 0.7em/1.4em arial,helvetica,sans═serif; }
</style>
<![endif]-->
<title>Camicus.net ][ Home ][</title>
<?php
print '
</head>
<body>';
}
public function ShowHeader()
{
print '
<div id="oldBrowserNotice" class="hide">
<img src="img/camicus.jpg" alt="Camicus.net" />
<p>
This site will look much better in a browser that supports
<a href="http://www.webstandards.org/upgrade/"
title="Download a browser that complies with Web standards.">web
standards</a>, but it is accessible to any browser or Internet
device.
</p>
</div>
<div id="pageWrapper">
<div id="hnav" class="bottomBorderOnly">
<img src="img/banner.jpg" width="350" height="63" id="banner" alt="Camicus.net" />';
}
public function ShowMenu()
{
?>
<div id="menu">
<ul>
<li><h2>Home</h2>
<ul>
<li><a href="">personal.camicus</a></li>
<li><a href="/camicus/professional/">professional.camicus</a></li>
<li><a href="?q=admin_index">admin cp</a></li>
</ul>
</li>
</ul>
<ul>
<li><h2>Weblog</h2>
<ul>
<li><a href="">Last 5 Articles</a></li>
<li><a href="?q=weblog&a=all">All Articles</a></li>
<li><a href="?q=weblog&a=search">Search Archives</a></li>
</ul>
</li>
</ul>
<ul>
<li><h2>Projects</h2></li>
<ul>
<li><a href="?q=projects">All Projects</a></li>
<li><a href="?q=projects&a=browse">Browse Projects</a></li>
<li><a href="?q=projects&a=search">Search Projects</a></li>
</ul>
</ul>
<ul id="menuTail"><div class="tail"> </div></ul>
</div>
<?php
}
public function ShowCurrPage()
{
print '
</div>
<div id="outerColumnContainer">
<div id="innerColumnContainer">
<hr class="hide" />
<div id="rightColumn">
<div class="inside">';
/* Here is where we include the page */
if (file_exists('cnt/vnav/'.$this->current_page.'.php'))
{
include_once('cnt/vnav/'.$this->current_page.'.php');
}
else
{
include_once('cnt/vnav/home.php');
}
/* End include */
print '
</div>
</div>
<div id="contentColumn">
<hr class="hide" />
<a name="skipToContent" id="skipToContent"></a>
<div class="inside pHeader">';
/* Here is where we include the page */
if ((include_once('cnt/'.$this->current_page.'.php')) == 0)
{
echo "Apparantly there was an error, and the specified page didn't load.\n";
echo "The page probably doesn't exist, in which case you should return to the main page";
}
/* End include */
print '
</div>
</div>
<div class="clear mozclear"></div>
</div>
</div>
<div class="hide" id="nsFooterClear"><!-- for NS4\'s sake --></div>
<hr class="hide" />
<div id="footer" class="inside">';
}
public function ShowFooter()
{
?>
<p>
All HTML and CSS released into the public domain. All other intellectual property is not. Please view the <a href="?q=disclaimer" title="View the Disclaimer">Disclaimer</a>.<br />
If you experience any technical problems with this website, you can e-mail the <a href="mailto: webmaster@camicus.net" title="E═mail the Webmaster">webmaster</a>.<br />
csshover2.htc - Available for download from: http://www.xs4all.nl/~peterned/csshover.html
</p>
<?php
print '
</div>
<hr class="hide" />
</div>
</body>
</html>';
}
}
?>
databaselayer.class.php
Code: Select all
class DatabaseLayer
{
public function MakeConnection()
{
$mysql_link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
mysql_select_db(MYSQL_DBNAME);
}
// I was then going to add functions to handle mysql queries
public function BreakConnection()
{
mysql_free_result($mysql_result);
mysql_close($mysql_link);
}
}
functions.inc.php - Now, I don't really need to post this but at some point it could become relevant and I would also like to have opinions on the IfLoggedIn() and AuthenticateUserCredentials functions. I am 70% that they are malfunctiong due to my inability to code. There are some garbage echo's in there for error testing, they never print to the screen :- /
I also realise that many people frown upon storing passwords in cookies and unless you have a better way that doesn't involve more database, I probably don't care. When I get the function working, more encryption will be added.
Code: Select all
<?php
function TitleOfTheDay()
{
$title = array('Home of Daedalus');
$i = rand(0, count($title)-1);
return $title[$i];
}
function FormatTimestamp($unix_timestamp)
{
return date('Hi \/\/ m\.d\.Y \/\/ \G\M\T O', $unix_timestamp);
}
function ShowErrors()
{
if (isset($_SESSION['error']))
{
print '<p class="error">'.$_SESSION['error'].'</p>';
unset($_SESSION['error']);
}
}
function IsLoggedIn()
{
if (isset($_SESSION['user']) && isset($_SESSION['password']) && isset($_SESSION['admin_flag']))
{
if (AuthenticateLoginCredentials())
{
echo "username and password are okay";
return true;
}
else
{
echo "username and password are not okay - destroying session";
session_destroy();
$_SESSION['error'] = 'You must log-in again and validate your credentials.';
return false;
}
}
}
function AuthenticateLoginCredentials()
{
$mysql_result = mysql_query(sprintf("
SELECT username, password
FROM users
WHERE username = '%s'
", $_SESSION['user']));
if (is_resource($mysql_result))
{
$row = mysql_fetch_row($mysql_result);
if ($_SESSION['password'] == md5('the_salt_string_i_use_which_you_will_never_know'.$row[1]))
{
echo "passwords did not match";
return true;
}
}
else
{
echo "user does not exist";
return false;
}
}
function QuoteOfTheDay()
{
$result = mysql_query('
SELECT quotes
FROM quotes
');
if (is_resource($mysql_result))
{
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$quote_of_the_day[$i] = $row[$i];
$i++;
}
}
else
{
$quote_of_the_day = array('No quotes!');
}
$i = rand(0, count($quote_of_the_day)-1);
print '
<div class="qotd">
'.$quote_of_the_day[$i].'
</div>
';
}
?>
cnt/vnav/home.php
Code: Select all
<div class="vnav">
<h2>
<img src="img/vnavCatPrefiix.gif" width="8" height="8" alt="" />
Home Page
</h2>
<a href="?q=construction" title="Under Construction">
under construction <span>Ω</span>
</a>
</div>
<div class="vnav">
<h2>
<img src="img/vnavCatPrefiix.gif" width="8" height="8" alt="" />
My Favorite Sites
</h2>
<a href="http://www.drudgereport.com" title="Visit http://www.drudgereport.com" target="_blank">
http://www.drudgereport.com <span>Ω</span>
</a>
<a href="http://www.sitepoint.com" title="Visit http://www.sitepoint.com" target="_blank">
http://www.sitepoint.com <span>Ω</span>
</a>
<a href="http://www.php-dev.net" title="Visit http://www.php-dev.net" target="_blank">
http://www.php-dev.net <span>Ω</span>
</a>
</div>
<?php QuoteOfTheDay(); ?>
<div class="vnav">
<h2>
<img src="img/vnavCatPrefiix.gif" width="8" height="8" alt="" />
Other Links
</h2>
<a href="?q=construction" title="Under Construction">
under construction <span>Ω</span>
</a>
</div>
I guess that I will address questions as they come. I also suppose that I am looking for suggestions more than a fix at this point. I realise that I am not going about this correctly and I wish to understand what correctly would be.
In case you are wondering why there is tons of HTML in there, someone said 'post the actual code', so I did. I tried to leave the HTML out of the earlier examples, you'll find that the page is pretty much the same as the examples I posted earlier.
Thanks for everything.