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/api/class.controller.php
<?php
/**
 * This file contains the iwp_controller class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_API
 */

/**
 * IWP Frontend Controller class
 * This class extends the iwp_engine abstract class.
 * This class handles the actions for viewing pages on the frontend
 *
 * @package IWP
 * @subpackage IWP_API
 */
class iwp_controller extends iwp_engine {
	/**
	 * This is the variable that holds the final output HTML for the content area of the page
	 *
	 * @var object Content
	 */
	public $Content;

	/**
	 * Instance
	 * This static variable holds the current instance of this object being loaded.
	 * So using the getInstance function anywhere will return the very same instance.
	 *
	 * @var iwp_controller Instance
	 */
	public static $Instance;

	/**
	 * getInstance
	 * This is a static function that sets up the class instance and stores it to the static variable. It will then return that instantiation in the future.
	 *
	 * @return iwp_controller Returns the instantiated object
	 **/
	public static function getInstance($page=null){
		if(!isset(self::$Instance)){
			self::$Instance = new self($page);
		}
		return self::$Instance;
	}

	/**
	 * This function displays a page for the front end. It takes an arguement and calls the class based on that.
	 *
	 * @param string $page The name of the class to call. If none is supplied to checks to see if there was one set in the class.
	 *
	 * @return void Doesn't return anything
	 */
	public function ShowPage($page=null){
		//	check to see if the template caches have been generated
		iwp_cache::getInstance()->ConfirmDir('sectionhtml');
		if (!file_exists(IWP_CACHE_SECTION_HTML_PATH .'/layout.html')) {
			iwp_admin_layout::getInstance()->SelectTemplate(GetConfig('template'), GetConfig('SiteColor'));
		}

		if($page === null){
			$page = $this->urls->GetCurrentStaticPage();
		}

		$className = iwp_strtolower("iwp_page_".$page);
		if(!class_exists($className) && iwp_strtolower($page) != 'notfound'){
			$this->ShowPage('NotFound');
			die();
		}
		$class = new $className;
		$class->ShowPage();
	}

	/**
	 * Sets the content value of the page for output
	 *
	 * @param string $val The content to be set ready for output
	 *
	 * @return void Doesn't return anything
	 *
	 * @see $Content
	 */
	public function SetContent($val){
		$this->Content = $val;
	}

	/**
	 * Retrieves the Content variable's value
	 *
	 * @return string The value of the content member variable
	 *
	 * @see $Content
	 */
	public function GetContent(){
		return $this->Content;
	}


	/**
	 * This assigns the blocks used for the template. Its called for each section that is being output.
	 *
	 * @param string $name The name of the section of blocks. e.g. leftBlock
	 * @param array $layoutArray The array of variables already set and that needs to be added to for this blocks. Called by reference
	 * @param array $blockList The block array to add to the $layoutArray
	 *
	 * @return void Doesn't return anything
	 */
	private function AssignBlocks($name, &$layoutArray, $blockList){
		$namePlural = $name . 's';
		$layoutArray[$namePlural] = implode("\n", $blockList);
		foreach ($blockList as $key=>$val){
			$keyName = $name.($key+1);
			$layoutArray[$keyName] = $val;
		}
	}

	/**
	 * This function outputs the final template code for a frontend page. It sets any last variables and calls the parse template function.
	 *
	 * @param string $template The name of the template to run based on the admin's Site layout. e.g. 'home', 'error'
	 *
	 * @return Doesn't return anything
	 */

	public function ShowTemplate($template, $return=false){
		$layout = array();
		$urls = array();
		$urls['search'] = $this->urls->GetStaticURL('search');
		$urls['homepage'] = iwp_config::Get('siteURL') .'/';

		$this->template->Assign('urls', $urls);

		$template = $this->valid->FilterAlphaNumericExtended($template,'_');
		$this->template->Assign('hasWebsiteLogo', false);

		if(iwp_config::Get('UsingLogoEditor')){
			$this->template->Assign('hasWebsiteLogo', true);
			$this->template->Assign('WebsiteLogo', iwp_config::Get('siteURL').'/images/websitelogo.png');
		}

		if(!iwp_config::Get('UsingLogoEditor') && !iwp_config::Get('UseTextTitle') && strlen(iwp_config::Get('UploadLogoFileName')) > 0){
			$this->template->Assign('hasWebsiteLogo', true);
			$this->template->Assign('WebsiteLogo', iwp_config::Get('siteURL').'/images/'.iwp_config::Get('UploadLogoFileName'));
		}

		if(is_blank($this->template->Get('metaDescription'))){
			$this->template->Assign('metaDescription', iwp_config::Get('siteDesc'));
		}

		if(is_blank($this->template->Get('metaKeywords'))){
			$this->template->Assign('metaKeywords', iwp_config::Get('siteKeywords'));
		}

		if(is_blank($this->template->Get('websiteTitle'))){
			$this->template->Assign('websiteTitle', iwp_config::Get('siteName'));
		}

		$this->template->PrependRequiredJS('%%language%%', '', false);
		$this->template->PrependRequiredJS(IWP_BASE_URI . '/javascript/common.js');
		$this->template->PrependRequiredJS(IWP_BASE_URI . '/javascript/jquery/jquery-plugins-frontend.js');
		$this->template->PrependRequiredJS(IWP_BASE_URI . '/javascript/jquery/jquery.js');

		$jsGlobals = array();

		$jsGlobals[] = "iwp.config.set('siteURL', " . iwp_FilterJavascriptString(iwp_config::Get('siteURL')) . ");";
		$jsGlobals[] = "iwp.config.set('ShortDateFormat', " . iwp_FilterJavascriptString(iwp_getShortDateFormat()) . ");";
		$jsGlobals[] = "iwp.config.set('ShortDateFormatJS', " . iwp_FilterJavascriptString(iwp_getShortDateFormatJS()) . ");";

		//	the following globals are to be deprecated in favour of the above
		$jsGlobals[] = "var iwp_global_tpl_path = '" . IWP_TPL_URI ."';";
		$jsGlobals[] = "var iwp_global_siteurl = iwp.config.get('siteURL');";
		$jsGlobals[] = "var iwp_short_date_format = iwp.config.get('ShortDateFormatJS');";

		$this->template->LoadTemplateConfigFile();
		$currentSet = $this->db->FetchOne('select value from ' . IWP_TABLE_TEMPLATE_SETTINGS .' where name="layoutSet" and template="'.$this->db->Quote($template).'"');

		// if all sections are locked to master, use the master layout's column count
		$countUnlocked = $this->db->FetchOne('select count(*) from ' . IWP_TABLE_TEMPLATE_SETTINGS .' where name LIKE "layoutBox%" and value NOT LIKE "%usemaster%" and template="'.$this->db->Quote($template).'"');

		if($countUnlocked > 0) {
			$this->template->config->SetCurrentSet($currentSet);
		} else {
			$currentSet = $this->db->FetchOne('select value from ' . IWP_TABLE_TEMPLATE_SETTINGS .' where name="layoutSet" and template="master"');
			$this->template->config->SetCurrentSet($currentSet);
		}

		$layout['columnCount'] = $this->template->config->CalculateColumns();

		$output = array();

		$sections = array('left', 'right', 'middle' , 'bottom', 'top');
		$layout['template'] = 'master';
		foreach($sections as $thisSection){

			$output = array();

			$attempts = 0;
			while ($attempts <= 1) {
				//	loop over the include code so we dont have to literally repeat it after regenerating

				if (file_exists(IWP_CACHE_SECTION_PATH . '/tpl_'.$template.'_' . $thisSection . '.php')) {
					//	include template specific section
					include(IWP_CACHE_SECTION_PATH . '/tpl_'.$template.'_' . $thisSection . '.php');
					$layout['template'] = $template;
					break;
				} elseif (file_exists(IWP_CACHE_SECTION_PATH . '/tpl_master_' . $thisSection . '.php')) {
					//	or include master section
					include(IWP_CACHE_SECTION_PATH . '/tpl_master_' . $thisSection . '.php');
					break;
				} elseif (!$attempts) {
					//	nothing for this section at all, meaning its not cached? regenerate the layout caches
					iwp_admin_layout::getInstance()->RegenerateAllCacheFiles();
				}

				$attempts++;
			}

			if ($thisSection == 'middle') {
				foreach($output as $k=>$val){
					if(iwp_strtolower($val) == 'contentplaceholder'){
						$output[$k] = $this->GetContent();
					}
				}
			}

			$this->AssignBlocks($thisSection . 'Block', $layout, $output);
		}

		$this->template->Append('headTagEnd', '<link href="'.iwp_config::Get('siteURL'). '/styles.php?v='. iwp_htmlspecialchars(PRODUCT_VERSION_INTERNAL) .'&amp;tpl='. iwp_htmlspecialchars(iwp_config::Get('template')) .'&amp;tplv='. iwp_htmlspecialchars($this->template->config->GetAttribute('version')) .'" type="text/css" rel="stylesheet" />'."\n", false);
		$headerBgImage = $this->GetHeaderImage();
		if($headerBgImage){
			$this->template->Append('headTagEnd', '<style type="text/css">'."\n\t" . '.headerBgImage { background-image: url("'.$headerBgImage.'"); }'. "\n" .'</style>'."\n", false);
		}

		$rssFeeds = iwp_lists::getInstance()->GetFeeds();
		if(is_array($rssFeeds) && sizeof($rssFeeds) > 0){
			foreach($rssFeeds as $feed){
				$this->template->Append('headTagEnd', '<link rel="alternate" type="application/rss+xml" title="'.$feed['title'].'" href="'.$feed['url'].'" />'."\n", false);
			}
		}

		if (sizeof($this->template->JSfiles) > 0) {
			foreach ($this->template->JSfiles as $key=>$file) {

				if ($file == '%%language%%') {
					//	language definitions need to happen before includes, but after common.js has been included, so it needs to be included using a placeholder in the JSfiles array
					$languageForJs = $this->template->GetLanguageForJS();
					if (sizeof($languageForJs) > 0) {
						$this->template->Append('headTagEnd', '<' . 'script type="text/javascript">//<!--' . "\n" . '/* languageForJs */ iwp.lang.set(' . json_encode($languageForJs) . ');' . "\n" . '//--></script>' . "\n", false);
					}
					continue;
				}

				if ($this->template->JSfilesIF[$key] !== false) {
					$this->template->Append('headTagEnd', "<!--[if ".$this->template->JSfilesIF[$key].']><script type="text/javascript" src="'.$file.'"></script><![endif]-->'."\n", false);
				} else {
					$this->template->Append('headTagEnd', '<script type="text/javascript" src="'.$file.'"></script>'."\n", false);
				}
			}
		}

		// nested content menus
		//$this->template->Append('headTagEnd', '<script type="text/javascript"> jQuery(function(){ $(\'#Menu .tplrepeat-parent\').superfish({ delay: 0, speed: \'fast\', disableHI: true, autoArrows: false, animation: {}, dropShadows: false }); }); </script>'."\n", false);

		if (sizeof($this->template->onPageLoadJs) > 0) {
			$onload = "<script  type='text/javascript'>//<!--\n".implode($jsGlobals, "\n") ."\n".'$(document).ready(function() {'."\n";
			foreach ($this->template->onPageLoadJs as $key => $script) {
				$onload .= "\t".$script."\n";
			}
			$onload .= "\n".'});'."\n//--></script>";
			$this->template->Append('headTagEnd', $onload, false);
		}else{
			$onload = "<script  type='text/javascript'>//<!--\n".implode($jsGlobals, "\n") ."\n//--></script>";
			$this->template->Append('headTagEnd', $onload, false);
		}

		if (sizeof($this->template->CSSfiles) > 0) {
			foreach ($this->template->CSSfiles as $key => $file) {
				$this->template->Append('headTagEnd', '<link rel="stylesheet" type="text/css" href="'.$file.'" />'."\n", false);
			}
		}

		//$this->template->Append('headTagEnd', '<meta http-equiv="Content-Type" content="text/html; charset='.iwp_config::Get('charset').'" />', false);

		$layout['htmlHead'] = $this->template->ParseSection('htmlhead_standard');

		$this->template->Assign('layout', $layout, false);
		$this->template->Assign('styleHeaderAppend',  iwp_styleguide::getInstance()->getStyle(), false);
		iwp_event::trigger(new iwp_event_controller_showtemplate($template, $this));

		$finalHTML = $this->template->ParseSection('layout');

		// do any final HTML cleaning up
		$finalHTML = str_replace("target=''", "", $finalHTML);

		if($return) {
			return $finalHTML;
		}

		echo $finalHTML;
	}

	public function GetHeaderImage(){
		$hasCurrent = true;

		$headerImageUriJPG  = IWP_IMAGES_URI . '/'. iwp_config::Get('template') . '_headerImage.jpg';
		$headerImagePathJPG = IWP_IMAGES_PATH . '/'. iwp_config::Get('template') . '_headerImage.jpg';

		$headerImageUriPNG  = IWP_IMAGES_URI . '/'. iwp_config::Get('template') . '_headerImage.png';
		$headerImagePathPNG	 = IWP_IMAGES_PATH . '/'. iwp_config::Get('template') . '_headerImage.png';

		if(file_exists($headerImagePathJPG)){
			$headerImagePath = $headerImagePathJPG;
			$headerImageUri = $headerImageUriJPG;

		}elseif(file_exists($headerImagePathPNG)){
			$headerImagePath = $headerImagePathPNG;
			$headerImageUri = $headerImageUriPNG;

		}else{
			$headerImageUriJPG  = IWP_TPL_URI . '/images/headerImage.jpg';
			$headerImagePathJPG = IWP_TPL_PATH . '/images/headerImage.jpg';

			$headerImageUriPNG  = IWP_TPL_URI . '/images/headerImage.png';
			$headerImagePathPNG	 = IWP_TPL_PATH . '/images/headerImage.png';


			if(file_exists($headerImagePathJPG)){
				$headerImagePath = $headerImagePathJPG;
				$headerImageUri = $headerImageUriJPG;
			}elseif(file_exists($headerImagePathPNG)){
				$headerImagePath = $headerImagePathPNG;
				$headerImageUri = $headerImageUriPNG;
			}else{
				$hasCurrent = false;
			}
		}

		if($hasCurrent){
			return $headerImageUri;
		}

		return false;
	}
}