<?php
//**********************************************************************//
// Caiyern's Site Engine v2.0                                           //
// Copyright 2009 Nate Eckardt (Nate@Caiyern.net)                       //
//                                                                      //
// This file is part of Caiyern's Site Engine.                          //
//                                                                      //
// This script is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or    //
// (at your option) any later version as long as this header remains    //
// intact in its entirety.                                              //
//**********************************************************************// 
    
header('Content-Type: text/html; charset=utf-8');
    include(
"./classes/timer.php");
    
$timer = new Timer;

    include(
"./classes/config.php");
    include(
"./classes/mysql.php");
    include(
"./classes/user.php");
    include(
"./classes/mailer.php");

    
session_start(); //Session start must come after class declarations, or else objects will not be accessible.
    
    //Object creation
    
$sql Mysql::create(Config::mysql_serverConfig::mysql_userConfig::mysql_passConfig::mysql_db);
    
$mailer = new Mailer;
    
    include(
"./modules/logintester.php");

    
//Base URLs
    
define('UNSECURE'"http://".$_SERVER['SERVER_NAME']);
    
define('SECURE'"https://".$_SERVER['SERVER_NAME']);
    
    
$modules = array(
        
"index" => array(
            
"path" => "./modules/default.php",
            
"title" => "Index",
            
"https" => false),
        
"login" => array(
            
"path" => "./modules/login.php",
            
"title" => "Login",
            
"https" => true),
        
"register" => array(
            
"path" => "./modules/register.php",
            
"title" =>"Register",
            
"https" => true,
            
"scripts" => array(
                    
"./captcha/swfobject.js"
                
)
            ),
        
"messages" => array(
            
"path" => "./modules/disp_messages.php"
            
"title" => "Messages",
            
"https" => true,
            
"scripts" => array(
                    
"./captcha/swfobject.js"
                
)
            ),
        
"request" => array(
            
"path" => "./modules/request.php"
            
"title" => "Requests",
            
"https" => true
            
),
        
"contact" => array(
            
"path" => "./modules/contact.php",
            
"title" => "Contact",
            
"https" => false,
            
"scripts" => array(
                
"./captcha/swfobject.js"
                
)
            ),
        
"view_article" => array(
            
"path" => "./modules/view_article.php",
            
"title" => "View Article",
            
"https" => false,
            
"scripts" =>array(
                
"./functions/comments.js"
                
)
            ),
        
"global" => array(
            
"scripts" => array("./functions/jquery.js")
            )
        );
            
    if(isset(
$_GET['page']) && isset($modules[strtolower($_GET['page'])]['path'])){
        
$page $modules[strtolower($_GET['page'])];
    }else{
        
$page $modules["index"];
    }
    if(isset(
$page['scripts']) && is_array($page['scripts'])){
        
$page['scripts'] = array_merge($modules['global']['scripts'],$page['scripts']);
    }else{
        
$page['scripts'] = $modules['global']['scripts'];
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title><?php echo $page['title']." &ndash; http://www.caiyern.net/";?></title>

        <link rel="stylesheet" href="/style.css" type="text/css" />
        
        <?php
            
foreach($page['scripts'] as $url){
                echo 
'<script type="text/javascript" src="'.$url.'"></script>'."\r\n";
            }
        
?>
        
        <meta name="description" content="Behold the awesomeness that is Caiyern.net" />
        <meta name="keywords" content="bullshit moron idiot caiyern rant hate bored" />
    </head>
    <body>
        <table style="width:100%;">
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="0" style="width:100%;height:200px;">
                        <tr>
                            <td width="250" height="212" style="padding:8px 0px 0px 4px;">
                                <img src="/images/siteimages/caiyernlogo.jpg" alt="" />
                            </td>
                            <td align="right" valign="bottom" style="padding:0px 10px 2px 0px;">
                                <img src="/images/siteimages/caiyernlogo.gif" alt="" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td width="165" valign="top" class="leftcolumn">
                                <div id="leftcolumn">
                                    <?php include("./modules/links.php");?>
                                </div>
                            </td>
                            <td valign="top">
                                <div id="rightcolumn">
                                    <?php
                                        
if(!$page['https'] || $_SERVER['HTTPS']){
                                            include(
$page['path']);
                                            if(isset(
$_GET['debug'])){
                                                echo 
"<br /><hr />";
                                                
$sql->show_queries();
                                                
$sql->show_errors();
                                                if(isset(
$timer)) echo "Page rendered in ".$timer->get_time()." seconds.";
                                            }
                                        }else{
                                    
?>
                                        <div style="width:100%;text-align:center;">
                                            This page must be viewed with HTTPS. Redirecting you now.
                                        </div>
                                        <script type="text/javascript">
                                            var t=setTimeout('window.location="<?php 
                                                
echo "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
                                                
?>"',3000);
                                        </script>
                                    <?php
                                        
}
                                    
?>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>