<?php 


/** 
***************************************************
*欢迎使用免费版SiteTeam企业建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.SiteTeam.cn 
***************************************************
**/




 if (!defined('IN_CKFINDER')) exit; class CKFinder_Connector_Core_ResourceTypeConfig { private $_name = ""; private $_url = ""; private $_directory = ""; private $_maxSize = 0; private $_allowedExtensions = array(); private $_deniedExtensions = array(); private $_config; function __construct($resourceTypeNode) { if (isset($resourceTypeNode["name"])) { $this->_name = $resourceTypeNode["name"]; } if (isset($resourceTypeNode["url"])) { $this->_url = $resourceTypeNode["url"]; } if (!strlen($this->_url)) { $this->_url = "/"; } else if(substr($this->_url,-1,1) != "/") { $this->_url .= "/"; } if (isset($resourceTypeNode["maxSize"])) { $this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string)$resourceTypeNode["maxSize"]); } if (isset($resourceTypeNode["directory"])) { $this->_directory = $resourceTypeNode["directory"]; } if (!strlen($this->_directory)) { $this->_directory = resolveUrl($this->_url); } if (isset($resourceTypeNode["allowedExtensions"])) { if (is_array($resourceTypeNode["allowedExtensions"])) { foreach ($resourceTypeNode["allowedExtensions"] as $e) { $this->_allowedExtensions[] = strtolower(trim((string)$e)); } } else { $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]); if (strlen($resourceTypeNode["allowedExtensions"])) { $extensions = explode(",", $resourceTypeNode["allowedExtensions"]); foreach ($extensions as $e) { $this->_allowedExtensions[] = strtolower(trim($e)); } } } } if (isset($resourceTypeNode["deniedExtensions"])) { if (is_array($resourceTypeNode["deniedExtensions"])) { foreach ($resourceTypeNode["deniedExtensions"] as $extension) { $this->_deniedExtensions[] = strtolower(trim((string)$e)); } } else { $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]); if (strlen($resourceTypeNode["deniedExtensions"])) { $extensions = explode(",", $resourceTypeNode["deniedExtensions"]); foreach ($extensions as $e) { $this->_deniedExtensions[] = strtolower(trim($e)); } } } } } public function getName() { return $this->_name; } public function getUrl() { return $this->_url; } public function getDirectory() { return $this->_directory; } public function getMaxSize() { return $this->_maxSize; } public function getAllowedExtensions() { return $this->_allowedExtensions; } public function getDeniedExtensions() { return $this->_deniedExtensions; } public function checkExtension(&$fileName, $renameIfRequired = true) { if (strpos($fileName, '.') === false) { return true; } if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $toCheck = array(); if ($this->_config->getCheckDoubleExtension()) { $pieces = explode('.', $fileName); if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) { return false; } if ($renameIfRequired) { $fileName = $pieces[0] ; for ($i=1; $i<sizeof($pieces)-1; $i++) { $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ; $fileName .= $pieces[$i]; } $fileName .= '.' . $pieces[sizeof($pieces)-1] ; } } else { return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) ); } return true; } public function checkIsHiddenFolder($folderName) { if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $regex = $this->_config->getHideFoldersRegex(); if ($regex) { return preg_match($regex, $folderName); } return false; } public function checkIsHiddenFile($fileName) { if (is_null($this->_config)) { $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config"); } $regex = $this->_config->getHideFilesRegex(); if ($regex) { return preg_match($regex, $fileName); } return false; } public function checkIsHiddenPath($path) { $_clientPathParts = explode("/", trim($path, "/")); if ($_clientPathParts) { foreach ($_clientPathParts as $_part) { if ($this->checkIsHiddenFolder($_part)) { return true; } } } return false; } public function checkSingleExtension($extension) { $extension = strtolower(ltrim($extension,'.')); if (sizeof($this->_deniedExtensions)) { if (in_array($extension, $this->_deniedExtensions)) { return false; } } if (sizeof($this->_allowedExtensions)) { return in_array($extension, $this->_allowedExtensions); } return true; } } 