HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/init.php
<?php
/**
 * This file serves up every HTML page through the front end. XML, RSS and remote requests are handled by different files.
 *
 * @version $Revision$
 * 
 *
 * @package IWP
 */

// Our primary class
include(dirname(__FILE__) . '/api/iwp.php');

// Initialize everything!
IWP::Init();

/* If we're on IIS, we will be using ISAPI rewrite, and with some versions it will be using an alternative variable */
if (isset($_SERVER["HTTP_X_REWRITE_URL"])) {
	$_SERVER['REQUEST_URI'] = $_SERVER["HTTP_X_REWRITE_URL"];
}

if(substr($_SERVER['REQUEST_URI'],-22) == 'iwp-rewrite-check.html') {
	echo "rewriting works <!--" . PRODUCT_VERSION . "-->";
	die();
}

if(!IWP::isInstalled()){
	header('Location: ./admin/index.php');
	die();
}

if(iwp_config::Get('downForMaintenance') && (!defined('IGNORE_MAINTENANCE') || (defined('IGNORE_MAINTENANCE') && IGNORE_MAINTENANCE == false))) {
	echo iwp_language::GetHtml('maintenance');
	die();
}

/* Check the URL for get variables that might be needed  */
if(in_string('?', $_SERVER['REQUEST_URI'])){
	$Qmark					= strpos($_SERVER['REQUEST_URI'], '?');
	$QueryString			= substr($_SERVER['REQUEST_URI'], $Qmark+1);
	$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 0, $Qmark);
	$ArgumentList			= explode("&", $QueryString);

	foreach ($ArgumentList as $name => $value) {
		$tmpArray = array();
		$tmpArray = explode("=", $value);
		if(isset($tmpArray[0]) && isset($tmpArray[1])){
			$_REQUEST[$tmpArray[0]] = $_GET[$tmpArray[0]] = urldecode($tmpArray[1]);
		}elseif(isset($tmpArray[0])){
			$_REQUEST[$tmpArray[0]] = $_GET[$tmpArray[0]] = urldecode($tmpArray[0]);
		}
	}
}

$_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']);

if (class_exists('iwp_config') && iwp_config::Get('AllowTestingCommands')) {
	//	these are used by internal test mechanisms and are safely ignored if testing is not allowed by the config file
	if (isset($_GET['IWP_TEMPLATE'])) {
		$layout = iwp_admin_layout::getInstance();
		$oldTemplate = iwp_config::Get('template');
		if ($layout->SelectTemplate($_GET['IWP_TEMPLATE'], $_GET['IWP_TEMPLATE_COLOR'])) {
			$newTemplate = iwp_config::Get('template');
			if ($newTemplate != $oldTemplate) {
				iwp_config::SetPublic('CurrentTemplateUrl', iwp_config::Get('siteURL') . "/templates/" . $newTemplate);
				iwp_config::SetPublic('CurrentTemplatePath', IWP_BASE_PATH . "/templates/" . $newTemplate);
				iwp_config::SetPublic('TemplateColor', iwp_config::Get('SiteColor'));
				iwp_activity::AddEntry('core', 'layout', 'selecttemplate', 0, $newTemplate, null, 'Testing Commands');
			}
		} else {
			die('Invalid template specified by testing commands.');
		}
	}

	/* We want the URL that we're working with, but we don't want any of the application paths */
	if (isset($_GET['IWP_REQUEST_URI'])) {
		//	debugging purposes, allow a querystring to override the URL
		$_SERVER['REQUEST_URI'] = $_GET['IWP_REQUEST_URI'];
	}
}

$CurrentURL = $_SERVER['REQUEST_URI'];

if(substr($CurrentURL,0, strlen(GetConfig('appPath'))) == GetConfig('appPath')){
	$CurrentURL = substr($CurrentURL, strlen(GetConfig('appPath')));
}

// If we can easily detect that they're accessing the home page, then show it without processing any URL information

if(in_array($CurrentURL, array('/','//','','/index.php', 'index.php'))){
	iwp_controller::getInstance()->ShowPage('home');
	die();
}

// check to see if they're accessing via a canonical URL
if((int)$CurrentURL > 0 && strlen((int)$CurrentURL) == strlen($CurrentURL)) {
	// the URL is just an ID number, lets redirect to the correct content item
	$content = iwp_content::getInstance();
	$content->Load((int)$CurrentURL);
	header('Location: ' . $content->GetUrl(true), true, 301);
	die();
}

// checking the URL
$urls = iwp_urls::getInstance();
$urls->SetCurrentURL($CurrentURL);

if($urls->IsStaticURL()){
	// they're accessing a IWP specific URL
	iwp_controller::getInstance()->ShowPage();
	die();
}

// It wasn't a static URL, lets see if its in our database for content
$query = 'select * from ' . IWP_TABLE_URLS .' where urlpath="/'.$urls->db->Quote($CurrentURL).'"';
$data = $urls->db->FetchQuery($query);

if(!$data || is_null($data) || !is_array($data) || empty($data)) {
	// The URL wasn't in our database, so we'll check the modules
	if($urls->IsModuleURL('/'.$CurrentURL)){
		// It is a module URL
		$module = iwp_modules::getInstance()->GetModule($urls->GetCurrentModule());

		// Set the module language variables like {$moduleName.lang.myLangVar}
		$setVar = array();
		$setVar['lang'] = $module->lang->GetLangVars();
		$setVar['urlToModule'] = IWP_MODULES_URI . '/' . $urls->GetCurrentModule();
		$module->template->assign($urls->GetCurrentModule(), $setVar);
		// Calls the main module function to display a page
		$module->ShowPageByIniUri($CurrentURL);
	}else{
		// Unknown URL, show 404 not found
		iwp_controller::getInstance()->ShowPage('NotFound');
	}
	die();
}

// There was a a URL in the database
if($data['assoctype'] == 'redirect'){

	if($data['redirecttype'] == 'users') {
		// users use static URLs
		$redirectPath = iwp_urls::getInstance()->ViewAuthorProfileURL($data['associd']);
		if(substr($redirectPath, 0, 1) == '/') {
			$redirectPath = substr($redirectPath, 1);
		}
	}else {
		// its just a redirect though, find the new URL and redirect to it
		if($data['redirecttype'] == 'content') {
			$data = $urls->db->FetchQuery('select * from ' . IWP_TABLE_URLS .' as u inner join ' . IWP_TABLE_CONTENT . ' as c on u.associd=c.contentid where assoctype="redirect" and associd='.(int)$data['associd']);

			if($data['parentid'] > 0) {
				// it's a sub page
				$q = $urls->db->Query("select * from ". IWP_TABLE_CONTENT . " where parentid=".$data['parentid'] ." AND contentid!=".$data['parentid']  ." order by `pagesortorder` asc");
				$pages = array();
				$page = 2;
				while(($row = $urls->db->Fetch($q))) {
					if($row['contentid'] == $data['contentid']) {
						break;
					}
					$page++;
				}
				$data = $urls->db->FetchQuery('select * from ' . IWP_TABLE_URLS .' where assoctype="'.$urls->db->Quote($data['redirecttype']).'" and associd='.(int)$data['parentid']);
				$data['urlpath'] = $data['urlpath'] . '?page=' . $page;
			} else {
				$data = $urls->db->FetchQuery('select * from ' . IWP_TABLE_URLS .' where assoctype="'.$urls->db->Quote($data['redirecttype']).'" and associd='.(int)$data['associd']);
			}
		} else {
			$data = $urls->db->FetchQuery('select * from ' . IWP_TABLE_URLS .' where assoctype="'.$urls->db->Quote($data['redirecttype']).'" and associd='.(int)$data['associd']);
		}
		if(!isset($data['urlpath'])){
			iwp_controller::getInstance()->ShowPage('NotFound');
		}
		$redirectPath = $data['urlpath'];

		if(substr($redirectPath,0,1) == '/'){
			$redirectPath = substr($redirectPath, 1);
		}
	}

	header("HTTP/1.1 301 Moved Permanently");
	header("Location: ". iwp_urls::getInstance()->ForceSlash(iwp_config::Get('siteURL'), false, true) . $redirectPath);
	die();

}elseif($data['assoctype'] == 'content'){
	// they're using a content url
	$content = new iwp_page_viewcontent();
	$content->ShowPage($data['associd']);

}elseif($data['assoctype'] == 'categories'){
	// they're using a category url
	$content = new iwp_page_viewcategory();
	$content->ShowPage($data['associd']);

}elseif($data['assoctype'] == 'module'){
	// lastly, is it a module URL stored in the database
	$module = iwp_modules::getInstance()->GetModule($data['modulename'])->ShowPageByDbUri($data);
}