<?php 
// ******************  Configuration: *****************************
// MySQL Config:
include "config.php";
// Site Settings
$title = "The Greedy Capitalist: David Veksler's Homepage";

$sitedir = "/kunden/homepages/14/d91181612/htdocs/rationalmind/";
$achivedir = "/kunden/homepages/14/d91181612/htdocs/rationalmind/archives";
// Caching Method  (Set equal to 1 for the type you want to use)
$gzip = 1;
$jpache = 0;
$debug = 0; //Debug Mode:

// Check for Banned IP Addresses
$banned_ip = array();
$banned_ip[] = '216.239.39.99';
$banned_ip[] = '68.58.123.98';
// Page Variable
$page = $HTTP_GET_VARS[page];
// ******************  End Configuration: *****************************
foreach($banned_ip as $banned) {
    $ip = $_SERVER['REMOTE_ADDR'];
    if ($ip == $banned) {
        echo "You have been banned!";
        exit();
    } 
} 
// Escape image references
if (strstr($page, "gif.")) {
    header ("Content-type: image/gif");
    $page = str_replace("gif.php", "gif", $page);
    $page = str_replace("gif.html", "gif", $page);
    $page = str_replace("gif.htm", "gif", $page);
    include $sitedir . $page;
    die();
} 
if (strstr($page, "jpg.")) {
    header ("Content-type: image/jpeg");
    $page = str_replace("jpg.php", "jpg", $page);
    $page = str_replace("jpg.html", "jpg", $page);
    $page = str_replace("jpg.htm", "jpg", $page);
    include $sitedir . $page;
    die();
} 
// Enable caching/compression
if ($gzip == 1) {
    ob_start();
    ob_implicit_flush(0);
    function CheckCanGzip()
    {
        global $HTTP_ACCEPT_ENCODING;
        if (headers_sent() || connection_aborted()) {
            return 0;
        } 
        if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip";
        if (strpos($HTTP_ACCEPT_ENCODING, 'gzip') !== false) return "gzip";
        return 0;
    } 
    // require "gzdoc.php" ;
} elseif ($jpache == 1) {
    $cachetimeout = 120;
    require "jpcache.php" ;
} 
// Format title
if ($page) {
    if (!$t) {
        $ext = strrchr($page, ".php");
        $filename = substr($page, 0, - strlen($ext));
        $filename = str_replace("/", " :: ", $filename);
        $title = $title . " :: " . ucwords(strtolower($filename));
    } else {
        $title = $title . " :: " . ucwords(strtolower($t));
    } 
} 
// Show Main Content
function ShowBody()
{
    global $page;

    if ($page == "") {
        echo "<p class=blueBoxHeader align=\"center\">The Greedy Capitalist's Blog:</p>";
        include("blog.html");
    } else if ($page == "links.php" || $page == "links") {
        print"<iframe src=\"http://greedycapitalist.europe.webmatrixhosting.net/links/links.aspx\" name=\"content\"  width =\"1200\" height =\"1200\" align=\"left\" frameborder=\"0\" id=\"content\"></iframe>" ;
    } else if ($page == ".php" || $page == "essay/.html") {
        include("blog.html");
    } else if ($author) {
        echo "<br><br><br>Please <a href=\"/editquote.php\">add your quote suggestions</a><br>";
    } else {
        $page = str_replace("/.htm", ".htm", $page);
        $page = str_replace("/.php", ".php", $page);
        $page = str_replace(".php.php", ".php", $page);
        $page = str_replace(".html.php", ".html", $page);
        $page = str_replace(".htm.php", ".htm", $page);
        $page = str_replace(".html.html", ".html", $page);

        $page = str_replace("archives", $archivedir, $page);
        if (substr($page, -1) == '/') {
            $page = substr($page, 0, strlen($page) - 1);
        } 

        if (file_exists($page)) {
            include("$page") ;
        } else {
            echo "<br><br><h1>Requested file (" . $page . ") not found! 	</h1><br><br><br><h2>The file could not be found -- probably because of recent changes on my website. <br>Please <a href=\"/david/contact\">contact me about it </a>if you want the missing content.</h2>";
        } 
    } 
} // End ShowBody
function ShowFooter()
{
    global $gzip, $debug;
    include "footer.php";
    if ($gzip == 1) {
        GzDocOut();
    } 
} 

function GzDocOut()
{
    /* $level = compression level 0-9, 0=none, 9=max */

    global $debug;
    $ENCODING = CheckCanGzip();

    if ($ENCODING) {
        // print "\n<!-- Compressed with: $ENCODING -->\n";
        $Contents = ob_get_contents();
        ob_end_clean();

        if ($debug) {
            $s = "<p>Not compress length: " . strlen($Contents);
            $s .= "<br />Compressed length: " . strlen(gzcompress($Contents, $level));
            $Contents .= $s;
        } 
        header("Content-Encoding: $ENCODING");
        print "\x1f\x8b\x08\x00\x00\x00\x00\x00";
        $Size = strlen($Contents);
        $Crc = crc32($Contents);
        $Contents = gzcompress($Contents, $level);
        $Contents = substr($Contents, 0, strlen($Contents) - 4);
        print $Contents;
        print pack('V', $Crc);
        print pack('V', $Size);
        exit;
    } else {
        ob_end_flush();
        exit;
    } 
} // End GzDocOut
function ShowMenu()
{
    include "config.php";

    $result = mysql_query("SELECT * FROM David_Menu ORDER BY id", $con);
    if ($myrow = mysql_fetch_array($result)) {
        do {
            printf("<p class=\"navbox\"><a href=\"%s\" title=\"%s\">%s</a></p>", $myrow["url"], $myrow["description"], $myrow["title"]);
        } while ($myrow = mysql_fetch_array($result));
    } 
    mysql_close($con);
} 

function ShowFooterMenu()
{
    include "config.php";

    $result = mysql_query("SELECT * FROM David_Menu ORDER BY id", $con);
    if ($myrow = mysql_fetch_array($result)) {
        do {
            printf("<a href=\"%s\" title=\"%s\">%s</a> | ", $myrow["url"], $myrow["description"], $myrow["title"]);
        } while ($myrow = mysql_fetch_array($result));

        mysql_close($con);
    } 
} 

?>
