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.permissionoption.php
<?php
/**
* This file contains the iwp_permissionoption class
*
* @package IWP
* @subpackage Permissions
*/

IWP::GetLib('class.permissionoption');

/**
* IWP Permission Option class
*
* This class contains an IWP specific extension of the base Permission Option class
*
* @package IWP
* @subpackage Permissions
*/
class iwp_permissionoption extends PermissionOption {

	/**
	 * Returns the language entry for a given scope type
	 *
	 * @param string $scopeType Scope type e.g. 'core', 'sitemodules', etc.
	 * @return string Language text
	 */
	public static function GetScopeTypeLang ($scopeType) {
		return GetLang('permissiongroup_'. $scopeType);
	}

	/**
	 * Returns the language entry for a given scope type and scope name. Will look up module and content names, etc.
	 *
	 * @param string $scopeType Scope type e.g. 'core', 'sitemodules', etc.
	 * @param string $scopeName Scope name e.g. (module codename), (contenttype id), 'user', 'groups', etc.
	 * @return string Language text
	 */
	public static function GetScopeNameLang ($scopeType, $scopeName) {
		if ($scopeType == 'sitemodules') {
			$module = iwp_modules::getInstance()->GetModule($scopeName);
			$lang = $module->lang->Get('ModuleNamePlural');
		} else if (($scopeType == 'content' && $scopeName == '__all') || $scopeType != 'content') {
			$lang = GetLang('permissiongroup_'. $scopeType .'_'. $scopeName);
		} else if ($scopeType == 'content') {
			$contenttypes = iwp_contenttypes::getInstance();
			$contenttypes->Load($scopeName);
			$lang = $contenttypes->Get('name');
		} else {
			$lang = $scopeName;
		}

		return $lang;
	}

	/**
	 * Returns the language entry for a given scope type and scope item.
	 *
	 * @param string $scopeType 'core', 'sitemodules', etc.
	 * @param string $scopeName (name of module), etc.
	 * @param string $scopeItem 'full', 'delete', etc.
	 * @return string Language text
	 */
	public static function GetScopeItemLang ($scopeType, $scopeName, $scopeItem) {
		if ($scopeType == 'sitemodules') {
			$module = iwp_modules::getInstance()->GetModule($scopeName);
			return $module->lang->Get('permission_'. $scopeType .'_'. $scopeItem);
		}

		if ($scopeType == 'content' && strstr($scopeItem, '_')) {
			//	look up module language
			list($moduleName, $moduleScope) = explode('_', $scopeItem, 2);
			$moduleLang = new iwp_language();
			$moduleLang->LoadMod($moduleName);
			return $moduleLang->Get('field_'. $moduleName .'_permission_'. $moduleScope);
		}

		return GetLang('permission_'. $scopeType .'_'. $scopeItem);
	}

	/**
	 * Returns the iwp_permissionoption relevant to the given scope
	 *
	 * @param string $scopeType 'core', 'sitemodules', etc.
	 * @param string $scopeName Scope name e.g. (module codename), (contenttype id), 'user', 'groups', etc.
	 * @param string $scopeItem
	 * @return iwp_permissionoption Returns iwp_permissionoption if found, otherwise FALSE
	 */
	public function GetPermissionOption ($scopeType, $scopeName, $scopeItem) {
		$items = iwp_permissionoption::GetScopeItemList($scopeType, $scopeName);
		foreach ($items as $key => $item) {
			if ($key == $scopeItem) {
				return $item;
			}
		}
		return false;
	}

	/**
	 * Returns the class name which represents a given scope type / scope name combination.
	 *
	 * @param string $scopeType 'core', 'sitemodules', etc.
	 * @param string $scopeName Scope name e.g. (module codename), (contenttype id), 'user', 'groups', etc.
	 * @return string Name of the class, or blank string if no valid class found.
	 */
	public static function GetScopeClassName ($scopeType, $scopeName)
	{
		//	only allow a-z A-Z 0-9 and underscores
		$scopeName = preg_replace('/[^a-zA-Z0-9_]/', '', $scopeName);

		$scopeClass = '';

		if ($scopeType == 'core') {
			if ($scopeName == 'root') {
				$scopeClass = '';
			} else {
				switch ($scopeName) {
					case 'importer':
					case 'maintenance':
						$scopeClass = 'iwp_admin_'. $scopeName;
						break;

					default:
						$scopeClass = 'iwp_' . $scopeName;
						break;
				}
			}
		} else if ($scopeType == 'content') {
			$scopeClass = 'iwp_content';
		} else if ($scopeType == 'sitemodules') {
			$scopeClass = 'iwp_module_' . $scopeName;
		}

		if ($scopeClass && !class_exists($scopeClass)) {
			$scopeClass = '';
		}

		return $scopeClass;
	}

	/**
	 * Returns an array of iwp_permissionoption for a given permission scope.
	 *
	 * @param String $scopeType Type of scope, should be 'core', 'content' or 'sitemodules'
	 * @param String $scopeName Scope item name, e.g. 'user', 'group'
	 * @return Array
	 */
	public static function GetScopeItemList ($scopeType, $scopeName, $languageLookup = false)
	{
		$scopeClass = iwp_permissionoption::GetScopeClassName($scopeType, $scopeName);

		if (isset($scopeClass) && $scopeClass) {
			if (class_exists($scopeClass)) {
				if (substr($scopeClass, 0, 11) == 'iwp_module_') {
					//	if we're loading a module's permission options, only load Site permissions here
					$items = call_user_func(array($scopeClass, 'GetSitePermissionOptions'));
				} else {
					$items = call_user_func(array($scopeClass, 'GetPermissionOptions'));
				}
			} else if (strstr($scopeClass, 'iwp_admin_') === false) {
				//	try loading the admin class and looking at that instead
				$scopeClass = str_replace('iwp_', 'iwp_admin_', $scopeClass);
				if (class_exists($scopeClass)) {
					$items = call_user_func(array($scopeClass, 'GetPermissionOptions'));
				} else {
					$scopeClass = false;
				}
			} else {
				$scopeClass = false;
			}
		} else {
			$scopeClass = false;
		}

		if ($scopeType == 'core') {
			if ($scopeName == 'root') {
				$items = array(
					'full'		=> new iwp_permissionoption(false, false, false)
				);
			}
		} else if ($scopeType == 'content') {
			if ($languageLookup) {
				foreach ($items as $key => &$item) {
					$item->LangText = str_replace('{contenttype}', iwp_permissionoption::GetScopeNameLang($scopeType, $scopeName), iwp_permissionoption::GetScopeItemLang($scopeType, $scopeName, $key));
				}
			}

			if ($scopeName !== '__all') {
				$contentTypes = iwp_admin_contenttypes::getInstance();
				$contentTypes->LoadByField('typeid', $scopeName);
				$moduleLang = new iwp_language();
				foreach ($contentTypes->GetFieldsList() as $tab => $arrGroups) {
					foreach ($arrGroups as $group => $arrFields) {
						foreach($arrFields as $field) {
							if (substr($field, 0, 7) == 'module_') {
								$moduleName = substr($field, 7);
								$moduleItems = call_user_func(array('iwp_module_' . $moduleName, 'GetContentPermissionOptions'));
								if (is_array($moduleItems)) {
									//	merge this module's permissions with permissions already present for this content type
									$moduleLang->LoadMod($moduleName);
									foreach ($moduleItems as $moduleItemName => $moduleItem) {
										$moduleItem->LangText = $moduleLang->Get('field_'. $moduleName .'_permission_'. $moduleItemName);
										$items[$moduleName . '_' . $moduleItemName] = $moduleItem;
									}
								}
							}
						}
					}
				}
			}
		}

		if ($languageLookup) {
			//	if requested, perform language lookups and include text in returned data

			if ($scopeClass) {
				$langContainer = call_user_func(array($scopeClass, 'getInstance'));
				if (!isset($langContainer->lang)) {
					$langContainer = new iwp_base();
				}
			} else {
				$langContainer = new iwp_base();
			}

			foreach ($items as $key => &$item) {
				if (!$item->LangText) {
					$item->LangText = str_replace('{contenttype}', $scopeName, $langContainer->lang->Get('permission_'. $scopeType .'_'. $key));
				}
			}
		}

		if (!isset($items)) {
			throw new Exception('$items is not being set when calling GetScopeItemList with arguments: ('. $scopeType .', '. $scopeName .', '. $languageLookup .'). Check the specified permission to scope to make sure it is valid.');
		}

		return $items;
	}

	/**
	 * Returns an array of scope options suitable for powering a select UI element.
	 *
	 * @return Array
	 */
	public static function GetScopeList ()
	{
		$scopes = array(
			'core' => array(
				'root'			=> iwp_permissionoption::GetScopeNameLang('core', 'root'),
				'user'			=> iwp_permissionoption::GetScopeNameLang('core', 'user'),
				'groups'		=> iwp_permissionoption::GetScopeNameLang('core', 'groups'),
				'contenttypes'	=> iwp_permissionoption::GetScopeNameLang('core', 'contenttypes'),
				'categories'	=> iwp_permissionoption::GetScopeNameLang('core', 'categories'),
				'lists'			=> iwp_permissionoption::GetScopeNameLang('core', 'lists'),
				'modules'		=> iwp_permissionoption::GetScopeNameLang('core', 'modules'),
				'settings'		=> iwp_permissionoption::GetScopeNameLang('core', 'settings'),
				'template'		=> iwp_permissionoption::GetScopeNameLang('core', 'template'),
				'sysinfo'		=> iwp_permissionoption::GetScopeNameLang('core', 'sysinfo'),
				'imagemanager'	=> iwp_permissionoption::GetScopeNameLang('core', 'imagemanager'),
				'importer'		=> iwp_permissionoption::GetScopeNameLang('core', 'importer'),
				'maintenance'	=> iwp_permissionoption::GetScopeNameLang('core', 'maintenance'),
			),
			'content'	=> array(
				'__all'			=> 'All Content',
			),
			'sitemodules'	=> array()
		);

		$contentTypes = iwp_admin_contenttypes::getInstance();
		$contentTypeList = $contentTypes->GetContentTypeList();

		while(list(,$row) = each($contentTypeList)) {
			$scopes['content'][$row['typeid']] = $row['name'];
		}

		natcasesort($scopes['content']);

		$modules = iwp_modules::getInstance();
		$moduleList = $modules->ModuleList();

		foreach($moduleList as $_key=>$module) {
			$module = $modules->GetModule($module);
			if (count(call_user_func(array(get_class($module), 'GetSitePermissionOptions')))) {
				$scopes['sitemodules'][$module->moduleName] = $module->lang->Get('ModuleNamePlural');
			}
		}

		natcasesort($scopes['sitemodules']);

		return $scopes;
	}
}