Location: PHPKode > projects > raSMP > rasmp/index.php
<?php

/*******************************************************************

 Name		: raSMP 2.0
 Copyright	: 2002, Adam Alkins
 Website	: http://www.rasmp.com
 email		: hide@address.com

 $Id: index.php,v 1.36 2003/03/22 00:53:37 rasadam Exp $: 

*******************************************************************/

/*******************************************************************

This program 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 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the 
Free Software Foundation Inc., 59 Temple Place, Suite 330,
Boston, MA  02111-1307  USA

*******************************************************************/

define('RASMP',true);

define('SCRIPT_PATH','./');

//
// Include common Files
//
include SCRIPT_PATH.'common/extension.inc';
include SCRIPT_PATH.'common.'.FILE_EXT;

// Check if Site is disabled
$query = "SELECT config_value FROM ".CONFIG_TABLE." WHERE config_name = 'site_disabled'";
$config = db_fetchassoc('',$query,'Could not select Site Disabled value from Config Table');

if($config['config_value']==1)
{
	$query = "SELECT config_value FROM ".CONFIG_TABLE." WHERE config_name = 'disabled_message'";
	$row = db_fetchassoc('',$query,'Could not select Site Disabled message from Config Table');

	display_message($row['config_value']);
}

//
// If the category isn't specified
//
unset($cat);
unset($page);
// if category var isn't passed
if( (!isset($_GET[CATEGORY_NAME]))&&(!isset($_POST[CATEGORY_NAME])) )
{
	// If the page var isn't passed either, will pull the default page from the default cat
	if( (!isset($_GET[PAGE_NAME]))&&(!isset($_POST[PAGE_NAME])) )
	{
		$query = "SELECT p.page_id,p.page_name,c.cat_id,c.page_id as default_page,p.date,p.page_title,p.page_content,p.template_id,p.use_php,c.redirect,c.redirect_url,t.header,t.footer FROM ".PAGES_TABLE." AS p, ".CATEGORIES_TABLE." as c, ".TEMPLATES_TABLE." as t WHERE c.default_cat = 1 AND p.page_id = c.page_id AND p.template_id = t.template_id limit 1";
	}
	else
	{
		// check page var
		if(!isset($_GET[PAGE_NAME]))
		{
			$page = clean($_POST[PAGE_NAME]);
		}
		else
		{
			$page = clean($_GET[PAGE_NAME]);
		}
		// will pull the page from the default cat
		$query = "SELECT p.page_id,p.page_name,c.cat_id,c.page_id as default_page,p.date,p.page_title,p.page_content,p.template_id,p.use_php,c.redirect,c.redirect_url,t.header,t.footer FROM ".PAGES_TABLE." AS p, ".CATEGORIES_TABLE." as c, ".TEMPLATES_TABLE." as t WHERE c.default_cat = 1 AND p.page_name = '".$page."' AND c.cat_id = p.cat_id AND p.template_id = t.template_id limit 1";		
	}
}
else
{
	if(!isset($_GET[CATEGORY_NAME]))
	{
		$cat = clean($_POST[CATEGORY_NAME]);
	}
	else
	{
		$cat = clean($_GET[CATEGORY_NAME]);
	}
	
	// if page isn't set, will pull the default page from the cat
	if( (!isset($_GET[PAGE_NAME]))&&(!isset($_POST[PAGE_NAME])) )
	{
		$query = "SELECT p.page_id,p.page_name,c.cat_id,c.page_id as default_page,p.date,p.page_title,p.page_content,p.template_id,p.use_php,c.redirect,c.redirect_url,t.header,t.footer FROM ".PAGES_TABLE." AS p, ".CATEGORIES_TABLE." as c, ".TEMPLATES_TABLE." as t WHERE c.cat_name = '".$cat."' AND p.page_id = c.page_id AND p.template_id = t.template_id limit 1";
	}
	else
	{
		if(!isset($_GET[PAGE_NAME]))
		{
			$page = clean($_POST[PAGE_NAME]);
		}
		else
		{
			$page = clean($_GET[PAGE_NAME]);
		}
		// will pull the defined cat and page
		$query = "SELECT p.page_id,p.page_name,c.cat_id,c.page_id as default_page,p.date,p.page_title,p.page_content,p.template_id,p.use_php,c.redirect,c.redirect_url,t.header,t.footer FROM ".PAGES_TABLE." AS p, ".CATEGORIES_TABLE." as c, ".TEMPLATES_TABLE." as t WHERE c.cat_name = '".$cat."' AND p.page_name = '".$page."' AND c.cat_id = p.cat_id AND p.template_id = t.template_id limit 1";
	}
}

// Pulls Page Data from one of the queries above
$result = db_query($query, 'Could not fetch page data');

if(is_ipv4($_SERVER['REMOTE_ADDR']))
{
	$_SERVER['REMOTE_ADDR'] = format_ipv6($_SERVER['REMOTE_ADDR']);
}

unset($page_data);

// If it couldn't find the page, will check to see if call cat was a redirect or the default
// is a redirect
if(db_numrows($result)=='0')
{
	unset($query_arg);
	if(isset($cat))
	{
		$query_arg = "cat_name = '$cat'";
	}
	else
	{
		$query_arg = "default_cat = 1";
	}
	
	$query = "SELECT redirect_url FROM ".CATEGORIES_TABLE." WHERE $query_arg AND redirect = 1";
	$result = db_query($query,'Could not check redirect information');
	
	if(db_numrows($result)==1)
	{
		$page_data = db_fetchassoc($result);
		header("Location: ".urldecode($page_data['redirect_url']));
	}
	else
	{		 
		$query = "SELECT config_value FROM ".CONFIG_TABLE." WHERE config_name = 'page_not_exist'";
		$row = db_fetchassoc('',$query,'Could not select Page error value from Config Table');

		$query = "SELECT * FROM ".TEMPLATES_TABLE." WHERE default_template = 1";
		$page_data = db_fetchassoc('',$query,'Could not fetch template data');
	 
		$page_data['page_title'] = stripslashes($row['config_value']);
		appendheader();

	    echo "<p align=\"center\"><br /><br />".stripslashes($row['config_value'])."<br /><br /><br />&nbsp;</p>";

		appendfooter();		
	
		include("common/display_stats.".FILE_EXT);
	}
}

// pagedata stored in an array and globalised
$page_data = db_fetchassoc($result);
global $page_data;

// Checks if user is banned, and will do appropriate sutff
if(check_banned($_SERVER['REMOTE_ADDR'],$page_data['page_id'])==true)
{
	$query = "SELECT config_value FROM ".CONFIG_TABLE." WHERE config_name = 'banned_message'";
	$row = db_fetchassoc('',$query,'Could not select Ban error value from Config Table');
	
	$page_data['page_title'] = $row['config_value'];
	
	appendheader();
    echo "<p align=\"center\"><br /><br />$ban_message<br /><br /><br />&nbsp;</p>";
	appendfooter();
	
	include("common/display_stats.".FILE_EXT);
}

// Stores hit information
record_hit($page_data['page_id']);

// if the page needs to redirect
if($page_data['redirect']==1&&$page_data['page_id']==$page_data['default_page'])
{
	header("Location: ".urldecode($page_data['redirect_url']));
}

//
// Apply header to page
//

appendheader();

//
// Pull page content, clean it up, evaluate as PHP or echo
//

$page_data['page_content'] = trim($page_data['page_content']);
$page_data['page_content'] = stripslashes($page_data['page_content']);

if($page_data['use_php']==1)
{
	echo eval($page_data['page_content']);
}
else
{
	echo $page_data['page_content'];
}

// 
// Apply footer
//

appendfooter();

//
// Includes file to display page generation time and "Powered by" text
//

include("common/display_stats.".FILE_EXT);

?>
Return current item: raSMP