$basesections) {
if ($domainparts[(count($domainparts) - ($basesections+1))] <> 'www') {
$redirect = 'http://www.'.$basedomain.str_replace("%sub%", $domainparts[(count($domainparts) - ($basesections + 1))], $appurl);
header ( "HTTP/1.1 301 Moved Permanently" );
header("Location: $redirect");
}
}
// ########################### LOAD SUBDREAMER CORE ############################
include($rootpath . 'includes/core.php');
// ############################ LOAD MAIN SETTINGS #############################
$getmainsettings = $DB->query("SELECT varname, value FROM " . TABLE_PREFIX . "mainsettings");
for($i = 0; $setting = $DB->fetch_array($getmainsettings); $i++)
{
$mainsettings[$setting['varname']] = $setting['value'];
}
// ################################ MOD REWRITE ################################
if($mainsettings['modrewrite'] AND strlen($_SERVER['REQUEST_URI']) AND !strstr($_SERVER['REQUEST_URI'], '?') AND substr($_SERVER['REQUEST_URI'], -4) != '.php')
{
// use to determine if the variable's values need addslashes
$addslashses = get_magic_quotes_gpc() ? false : true;
// first thing to do is get the real $_SERVER['REQUEST_URI']
// because if Subdreamer is in a subfolder, then that subfolder will be part of the request_uri
// for example, if url = http://localhost/subdreamer/ then the request_uri is /subdreamer/
// so in a way, we have to subtract the url from the request_uri
// and that can be done thanks to my buddy Oliver Reeves!
// request_uri, get rid of the trailing slash
$requesturi = substr($_SERVER['REQUEST_URI'], -1) == '/' ? substr($_SERVER['REQUEST_URI'], 0, -1) : $_SERVER['REQUEST_URI'];
// pattern to get rid of the root url, ex: http://localhost
// leaving only the subfolders, ex: /subdreamer/
$subfolders = preg_replace("#https?://[^/]+(/?.*)#", "\$1", $sdurl);
// now subtract the subfolders from the request_uri, and get the url with the variables
// ex: var1/val1/var2/val2 (trailing slash removed above)
$urlvariables = substr($requesturi, strlen($subfolders));
// explode the url variables
$variables = explode('/', $urlvariables);
// at this point $variables should be an array with an odd number of values (cat/var1/val1)
// so exit if it's not!
if(!count($variables) % 2 != 0)
{
header("HTTP/1.0 404 Not Found"); // set the HTTP header
PrintMessage($sdlanguage['url_not_found'] . '
' . $sdlanguage['redirect_to_homepage'] . '');
exit;
}
if(strlen($variables[0]))
{
// before we loop the variable into the $_GET array, lets first grab the categoryid
$urlcategoryname = $variables[0];
// now clean the categoryname and addslashes:
$urlcategoryname = $addslashes ? addslashes(PreClean($urlcategoryname)) : PreClean($urlcategoryname);
if($category = $DB->query_first("SELECT categoryid FROM " . TABLE_PREFIX . "categories WHERE urlname = '$urlcategoryname'"))
{
// set the categoryid
$_GET['categoryid'] = $category['categoryid'];
// now it's time to create the variables
// i = 1 because we're skipping the home category
for($i = 1; $i < count($variables); $i = $i+2)
{
// ($i + 1 = value of variable, ex: var1/val1/ etc...)
$variablevalue = $variables[$i + 1];
// clean the values first
$variablevalue = $addslashes ? addslashes(PreClean($variablevalue)) : PreClean($variablevalue);
// variable names dont' have to be cleaned, because they are called directly
$_GET[$variables[$i]] = $variablevalue;
}
}
else
{
header("HTTP/1.0 404 Not Found"); // set HTTP header
PrintMessage($sdlanguage['page_not_found'] . '
' . $sdlanguage['redirect_to_homepage'] . '');
exit;
}
}
else
{
// no strlen for category name probably means we've loaded the main url
// ex:www.subdreamer.com
$_GET['categoryid'] = 1;
}
}
// ############################## GET CATEGORYID ###############################
$categoryid = (isset($_GET['categoryid']) AND ereg("^[0-9]+$", $_GET['categoryid'])) ? $_GET['categoryid'] : 1;
// ####################### ALTER TITLE AND META SETTINGS #######################
if(isset($_GET['p2_articleid']) AND ereg("^[0-9]+$", $_GET['p2_articleid']))
{
if($article = $DB->query_first("SELECT title, metakeywords, metadescription FROM " . TABLE_PREFIX . "p2_news WHERE articleid = '" . $_GET['p2_articleid'] . "'"))
{
$mainsettings['websitetitle'] .= ' - ' . $article['title'];
$mainsettings['metadescription'] .= ', ' . $article['metadescription'];
$mainsettings['metakeywords'] .= ', ' . $article['metakeywords'];
}
}
// ################### SET LOCALE TIME AND HEADER INFORMATION ##################
$languageinfo = explode('|', $mainsettings['language']);
header("Content-Type: text/html; charset=$languageinfo[2]");
// ################################# GET LOGO #################################
$logo = $mainsettings['currentlogo'];
// ################################# COPYRIGHT #################################
// please do not remove this unless you have purchased the branding free option
$copyright = $mainsettings['copyrighttext'];
if(!$mainsettings['bfo'])
{
$copyright .= ' Website Powered by Subdreamer';
}
// ############################### USER SYSTEM ################################
// usersystem is fetched in core.php
// fix username and password for foreign chracters, this only needs to be done
// on the frontend, becuase subdreamer doesn't htmlspecialchars data in the backend.
if(isset($_POST['loginusername']) OR isset($_POST['loginpassword']))
{
// IPB actually changes usernames from test' to test'
// so if using IPB don't unhtmlspecialchars the username & password
// it should also be noted that subdreamer converts ' to '
// so if using IPB, not only will we not unhtmlspecialchars but we have to fix the single quote
if($usersystem['name'] == 'Invision Power Board 2')
{
$_POST['loginusername'] = str_replace(''', ''', $_POST['loginusername']);
// this of course doen't need to be done in the password (it will never have entities)
}
else
{
$_POST['loginusername'] = unhtmlspecialchars($_POST['loginusername']);
$_POST['loginpassword'] = unhtmlspecialchars($_POST['loginpassword']);
}
}
// switch database?
if($usersystem['dbname'] != $dbname)
{
// Subdreamer is being integrated with a Forum in a different database
$DB->select_db($usersystem['dbname']);
require($rootpath . 'includes/usersystems/' . $usersystem['queryfile']);
$DB->select_db($dbname);
}
else
{
// Subdreamer may be integrated with a forum in the same database,
// or is using the Subdreamer User System
require($rootpath . 'includes/usersystems/' . $usersystem['queryfile']);
}
unset($userinfo);
$userinfo = GetUserInfo($usersettings);
unset($usersettings);
// ############################### WEBSITE OFF? ################################
if($mainsettings['siteactivation'] == 'off')
{
if($userinfo['offlinecategoryaccess'])
{
echo '
| Website in Offline Mode |