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

/**
 * IWP Modules Class
 * This is the class that manages the modules
 *
 * @package IWP
 * @subpackage IWP_API
 */
class iwp_modules 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 iwp_modules Instance
	 */
	public static $Instance;

	/**
	 * This is an array of all the loaded modules
	 *
	 * @var array
	 */
	private $ModuleList  = array();

	/**
	 * This is an array of all the loaded module's ID numbers in this format: $ModuleIdList[moduleid] = moduleName;
	 *
	 * @var array
	 */
	public $ModuleIdList = array();

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

	/**
	 * The constructor. It runs the LoadModules() function when the class in intialized.
	 *
	 * @return void
	 */
	public function __construct(){
		$this->LoadModules();
	}

	/**
	 * Checks to see if the specified module name is of a valid loaded module
	 *
	 * $param string $module The name of the module to check if it is valid or not
	 *
	 * @return boolean True if the module is loaded, false otherwise
	 */
	public function IsModule($module){
		if(in_array($module, $this->ModuleList) && file_exists(IWP_MODULES_PATH . '/' . $module . '/module.' . $module .'.php')){
			return true;
		}else{
			return false;
		}
	}

	private $_LoadModuleIdList_loaded = false;

	/**
	 * This function loads all the modules from the database into an array with their names and ID numbers as the keys
	 *
	 * @return array An array of the currently active modules from the database
	 */
	public function LoadModuleIdList(){
		if (!$this->_LoadModuleIdList_loaded) {
			$q = $this->db->Query('select * from '.IWP_TABLE_MODULES);
			while(($row = $this->db->Fetch($q))) {
				$this->ModuleIdList[$row['moduleid']] = $row['codename'];
			}
			$this->_LoadModuleIdList_loaded = true;
		}
		return $this->ModuleIdList;
	}

	/**
	 * Returns the $ModuleIdList member variable
	 *
	 * @return array The array of Modules with their ID numbers
	 *
	 * @see $ModuleIdList
	 */
	public function GetModuleIdList (){
		return $this->ModuleIdList;
	}

	/**
	 * Returns the list of valid module directories
	 *
	 * @return array The array of modules
	 *
	 * @see $ModuleList
	 */
	public function ModuleList(){
		return $this->ModuleList;
	}

	/**
	 * Returns the list of valid module directories with the their display names
	 *
	 * @return array The array of modules
	 *
	 * @see $ModuleList
	 */
	public function ModuleListNames ()
	{
		$return = array();
		foreach($this->ModuleList as $k=>$name){
			if($this->GetModule($name)->lang->Exists('ModuleNamePlural')){
				$return[$name] = $this->GetModule($name)->lang->Get('ModuleNamePlural');
			}else{
				$return[$name] = $this->GetModule($name)->lang->Get('ModuleNameSingular');
			}
		}
		ksort($return);
		return $return;
	}

	/**
	 * Returns a list of active modules with their display name.
	 *
	 * @return array Associative array of modules with code as key and display name as value.
	 */
	public function ActiveModuleListNames ()
	{
		$return = array();
		$list = $this->LoadModuleIdList();
		foreach ($list as $moduleName)
		{
			if (!($module = $this->GetModule($moduleName))) {
				continue;
			}

			if ($module->lang->Exists('ModuleNamePlural')) {
				$return[$moduleName] = $module->lang->Get('ModuleNamePlural');
				continue;
			}

			$return[$moduleName] = $module->lang->Get('ModuleNameSingular');
		}
		return $return;
	}

	/**
	 * Returns a list of active modules with 'website' functionality with their display name.
	 *
	 * @return array Associative array of modules with code as key and display name as value.
	 */
	public function ActiveWebsiteModuleListNames ()
	{
		$return = array();
		$list = $this->LoadModuleIdList();
		foreach ($list as $moduleName)
		{
			if (!($module = $this->GetModule($moduleName))) {
				continue;
			}

			if (!$module->IsWebsiteModule()) {
				continue;
			}

			if ($module->lang->Exists('ModuleNamePlural')) {
				$return[$moduleName] = $module->lang->Get('ModuleNamePlural');
				continue;
			}

			$return[$moduleName] = $module->lang->Get('ModuleNameSingular');
		}
		return $return;
	}

	/**
	 * Returns a list of active modules with 'content' functionality with their display name.
	 *
	 * @return array Associative array of modules with code as key and display name as value.
	 */
	public function ActiveContentModuleListNames ()
	{
		$return = array();
		$list = $this->LoadModuleIdList();
		foreach ($list as $moduleName)
		{
			if (!($module = $this->GetModule($moduleName))) {
				continue;
			}

			if (!$module->IsContentModule()) {
				continue;
			}

			if ($module->lang->Exists('ModuleNamePlural')) {
				$return[$moduleName] = $module->lang->Get('ModuleNamePlural');
				continue;
			}

			$return[$moduleName] = $module->lang->Get('ModuleNameSingular');
		}
		return $return;
	}

	/**
	 * This function returns the instance of a specified module
	 *
	 * @param string $module The name of the module to get the object instance of
	 * @return iwp_module Instance of module (as extension of iwp_module class), or FALSE if not a valid module
	 *
	 * @see IsModule()
	 */
	public function GetModule($module){
		if(!$this->IsModule($module)){
			return false;
		}
		return call_user_func(array('iwp_module_'.$module,'getInstance'));
	}

	/**
	 * This function reads the modules directory and loads all the valid modules into the $ModuleList array
	 *
	 * @return void
	 *
	 * @see $ModuleList
	 */
	public function LoadModules(){

		//	a list of filenames to ignore
		$InvalidDirs = array('.', '..', '.svn', 'CVS');

		//	clear the existing list
		$this->ModuleList = array();

		//	open a handle to the modules directory
		if ($handle = @opendir(IWP_MODULES_PATH)) {

			//	loop over module folders
			while (false !== ($dir_element = readdir($handle))) {
				if (!in_array($dir_element, $InvalidDirs)				//	filename should not be ignored
					&& is_dir(IWP_MODULES_PATH . DIRECTORY_SEPARATOR .  $dir_element)	//	it is a directory
					&& file_exists(IWP_MODULES_PATH . DIRECTORY_SEPARATOR .  $dir_element . DIRECTORY_SEPARATOR . 'module.' . $dir_element .'.php')		//	a file defining a module exists
					) {
					if(!in_array($dir_element, $this->ModuleList)){
						$this->ModuleList[] = $dir_element;
					}
				}
			}
			closedir($handle);
		}
	}

	public function GetModulesWithLayouts(){
		$moduleList = $this->ModuleList();
		$return = array();

		foreach ($moduleList as $codename) {
			$module = $this->GetModule($codename);

			if (is_object($module)) {
				if($module->hasLayout){
					$return[] = array(
						'codename' => $codename,
						'name' => $module->lang->Get('ModuleNamePlural')
					);
				}
			}
		}

		return $return;
	}

	public function hasModulesWithLayouts(){
		$moduleList = $this->ModuleList();
		$return = array();

		foreach ($moduleList as $codename) {

			$module = $this->GetModule($codename);
			if (is_object($module)) {
				if($module->hasLayout){
					return true;
				}
			}
		}
		return false;
	}

	public function areModulesWithBlocks(){
		$moduleList = $this->ModuleList();
		$return = array();

		foreach ($moduleList as $codename) {

			$module = $this->GetModule($codename);
			if (is_object($module)) {
				if($module->hasBlocks){
					return true;
				}
			}
		}
		return false;
	}



	/**
	 * Returns a granularity list for this class.
	 *
	 * @param Integer $total Total will be populated with number of rows found in query (by reference)
	 * @param String $filter Filter string, optional
	 * @param Integer $page Page number of records to return, optional
	 * @return Array List of value/text pairs
	 */
	public static function getGranularityList (&$total, &$page, $filter = '')
	{
		$modules = iwp_modules::getInstance();
		$moduleList = $modules->ModuleList();
		$list = array();

		foreach($moduleList as $_key=>$moduleCode) {
			$module = $modules->GetModule($moduleCode);
			if (!$module) {
				//	not a valid module, skip
				continue;
			}

			$moduleName = $module->lang->Get('ModuleNamePlural');

			if
			(
				$module->HasConfigurationScreen()	//	module has a config screen
				&&
				(
					!$filter					//	and no filter is specified, or
					||
					(
						$filter
						&&
						stristr($moduleName, $filter)	//	a filter is specified and matches this module name
					)
				)
			) {
				//	qualified, add it to the list of modules
				$list[] = array(
					'value' => $moduleCode,
					'text' => $moduleName
				);
			}
		}

		$total = count($list);

		$limitStart = ($page * IWP_PERMISSIONGRANULARITEMS_PER_PAGE) - IWP_PERMISSIONGRANULARITEMS_PER_PAGE;
		$list = array_slice($list, $limitStart, IWP_PERMISSIONGRANULARITEMS_PER_PAGE);

		return $list;
	}

	/**
	 * Returns a list of module 'titles' (names) for the supplied ids. Used by the permission management system.
	 *
	 * @param Array $codes
	 * @return Array
	 */
	public static function getTitleList (&$codes)
	{
		$list = array();

		if (count($codes)) {
			$modules = iwp_modules::getInstance();
			$moduleList = $modules->ModuleList();

			foreach ($moduleList as $moduleCode) {
				if (in_array($moduleCode, $codes)) {
					$module = $modules->GetModule($moduleCode);
					if ($module) {
						$list[] = array(
							'value' => $moduleCode,
							'text' => $module->lang->Get('ModuleNamePlural')
						);
					}
				}
			}
		}

		return $list;
	}

	public function GetCacheSalt(){
		$saltReturn = $salt = '';
		foreach($this->ModuleList() as $moduleCode){
			$salt = $this->GetModule($moduleCode)->GetModuleCacheSalt();
			if($salt !== false){
				$saltReturn .= $salt;
			}
		}
		return $saltReturn;
	}

	public static $PermissionOptions;

	public static function GetPermissionOptions () {
		return self::$PermissionOptions;
	}
}

iwp_modules::$PermissionOptions = array(
	'full'			=> new iwp_permissionoption(true, false, false),
	'activate'		=> new iwp_permissionoption(true, false, false),
	'deactivate'	=> new iwp_permissionoption(true, false, false),
	'configure'		=> new iwp_permissionoption(true, false, false)
);