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.template.config.php
<?php

/**
 * This file contains the iwp_template_config class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 */

/**
 * Template Config Class
 * This class is used to manage options for a template
 *
 * @package IWP
 */

class iwp_template_config extends iwp_engine {
	/**
	 * 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 object Instance
	 */
	public static $Instance;

	/**
	 * This number represents which column is the 'content' column -- that is how should the columns be laid out
	 * on the Site Layout Page (which column is the thick one and which one has the 'content' placeholder
	 */
	private $contentColumn = 2;

	/**
	 * This variables holds an array with the available layout sets for the template
	 *
	 * @var array
	 */

	private $layoutSets = array();

	/**
	 * This variable is the name of the db table which contains the settings for this template
	 */

	protected $baseTableName = 'template_settings';

	/**
	 * This variable is an array containing template attributes such as name or version
	 */

	protected $attributes = array();

	/**
	 * This restricts the number of blocks that can be placed into a section
	 *
	 * @see RestrictBlocksPerSection
	 */

	protected $restrictedSections = array();

	/**
	 * This is the structure of the db table
	 *
	 * @var _columns
	 *
	 * @see ValidColumn
	 **/
	protected $_columns = array(
							'settingid' => '',
							'name' => '',
							'value' => '',
						);

	/**
	 * This is the currently selected layoutSet
	 *
	 * @var string
	 */

	protected $currentSet = '';

	/**
	 * This variable holds an array of the valid sections available in the layout.
	 *
	 * @var array
	 */

	private $validSections = array('top', 'left', 'middle', 'right', 'bottom');

	/**
	 * 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 object Returns the instantiated object
	 */
	public static function getInstance(){
		if(!isset(self::$Instance)){
			self::$Instance = new self();
		}
		return self::$Instance;
	}

	/**
	 * The constructor which runs common routines needed for each intialisation of the class
	 */

	public function __construct(){
		$this->primaryKey = 'settingid';
		parent::__construct();
	}

	/**
	 * This function checks the current set and calculates how many columns it has
	 *
	 * @return integer The number of columns the currently selected set has
	 *
	 * @see $layoutSets
	 * @see $currentSet
	 */

	public function CalculateColumns(){
		if(isset($this->layoutSets[$this->GetCurrentSet()])){
			$thisLayoutSet = $this->layoutSets[$this->GetCurrentSet()];
		}else{
			$thisLayoutSet = $this->layoutSets[$this->GetAttribute('defaultLayoutSet')];
		}
		$sections = $thisLayoutSet['sections'];
		$minus = 0;
		if(in_array('top', $sections)){
			++$minus;
		}
		if(in_array('bottom', $sections)){
			++$minus;
		}
		return (int)(count($sections)-$minus);
	}

	public function SetContentColumn($contentColumn){
		$this->contentColumn = $contentColumn;
	}

	public function GetContentColumn(){
		return $this->contentColumn;
	}

	/**
	 * This function creates a layout set. A layout set is the list of sections that are shown on the template
	 *
	 * @param	string	$name This is the code name for the layout set being created. Its recommended to keep this simple without spaces. e.g. 1column
	 * @param	string	$displayName This is the name of the layout set that is displayed to the end user
	 * @param	array	$sections This is an array of the sections that this layout set uses. The list of valid sections are defined in $this->validSections
	 *
	 * @see $validSections
	 * @see $layoutSets
	 */

	public function CreateSet($name=null, $displayName=null, $sections=null){
		if(is_null($name) || is_null($displayName) || is_null($sections) || !is_array($sections)){
			return;
		}

		foreach($sections as $k=>$section){
			if(!in_array($section, $this->validSections)){
				unset($sections[$k]);
			}
		}

		if(sizeof($sections) < 1){
			return;
		}

		$newSet = array();
		$newSet['displayName'] = $displayName;
		$newSet['sections'] = $sections;

		$this->layoutSets[$name] = $newSet;
	}

	/**
	 * This function removes a set from the layoutSets array based upon the name
	 *
	 * @param string The name of the set to remove
	 *
	 * @see $layoutSets
	 */

	public function RemoveSet($name){
		foreach($this->layoutSets as $k=>$val){
			if(iwp_strtolower($val['name']) == iwp_strtolower($name)){
				unset($this->layoutSets[$k]);
				break;
			}
		}
	}

	/**
	 * This function sets the currentSet
	 *
	 * @param string $set The value/name of the current set
	 *
	 * @return void
	 * @see currentSet
	 */

	public function SetCurrentSet($set){
		if(isset($this->layoutSets[$set])){
			$this->currentSet = $set;
		} else {
			$this->currentSet = $this->GetAttribute('defaultLayoutSet');
		}
	}

	/**
	 * This function gets the currentSet
	 *
	 * @return string The name of the current selected set
	 * @see currentSet
	 */

	public function GetCurrentSet(){
		if($this->currentSet == '' && $this->attributes['defaultLayoutSet'] != ''){
			return $this->attributes['defaultLayoutSet'];
		}else{
			return $this->currentSet;
		}
	}

	/**
	 * This function returns the array of layoutSets
	 *
	 * @see $layoutSets
	 */
	public function GetLayoutSets(){
		return $this->layoutSets;
	}

	/**
	 * This function is an automated way of setting up 'layoutSets'.
	 * It uses the default/common set of sections that are used for 1, 2 and 3 column layouts.
	 *
	 * @see CreateSet()
	 */
	public function UseDefaultSets(){
		$columnNums = func_get_args();
		foreach($columnNums as $k=>$number){
			$number = (int)$number;
			switch($number){
				case 1:
					$this->CreateSet('1column', GetLang('Layout_1Column'), array('top', 'middle', 'bottom'));
					break;
				case 2:
					$this->CreateSet('2columns', GetLang('Layout_2Columns'), array('top', 'left', 'middle', 'bottom'));
					break;
				case 3:
					$this->CreateSet('3columns', GetLang('Layout_3Columns'), array('top', 'left', 'middle', 'right', 'bottom'));
					break;
			}
		}
	}

	/**
	 * This function takes one arguement and checks if it is indeed a valid section
	 *
	 * @param string $section This is the string that is checked to see if it is a valid section
	 *
	 * @see $validSections
	 */

	 public function ValidSection($section){
	 	return (bool)in_array($section, $this->validSections);
	 }

	/**
	 * This function sets the number of blocks that a section is restricted to
	 *
	 * @see $restrictedSections
	 */
	public function RestrictBlocksPerSection($section, $number){
		if(!$this->ValidSection($section)){
			return;
		}

		$this->restrictedSections[$section] = (int)$number;
	}

	/**
	 * This function retrieves the set restriction array
	 *
	 * @see $restrictedSections
	 */

	 public function GetRestrictions(){
	 	return $this->restrictedSections;
	 }

	/**
	 * This sets a template attribute such as version or name
	 *
	 * @param string $templateName The name of the template
	 */
	public function SetAttribute($name, $value){
		$this->attributes[$name] = $value;
	}

	/**
	 * This returns a template attribute such as name or version number
	 *
	 * @return string Returns the value of $templateName which is the name of the template
	 */
	public function GetAttribute($name){
		if(isset($this->attributes[$name])){
			return $this->attributes[$name];
		}
		return '';
	}

	/**
	 * This returns a template attribute such as name or version number
	 *
	 * @return string Returns the value of $templateName which is the name of the template
	 */
	public function GetSetting($name){
		foreach($this->data as $k=>$setting){
			if($name == $setting['name']){
				return $setting['value'];
			}
		}
		return false;
	}
}