PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/ckfinder/core/connector/php/php5/Core/Config.php

http://speedcms.googlecode.com/
PHP | 536 lines | 221 code | 39 blank | 276 comment | 36 complexity | 2880f4e892df94d508b1bc75dc6408ee MD5 | raw file
  1. <?php
  2. /*
  3. * CKFinder
  4. * ========
  5. * http://ckfinder.com
  6. * Copyright (C) 2007-2010, CKSource - Frederico Knabben. All rights reserved.
  7. *
  8. * The software, this file and its contents are subject to the CKFinder
  9. * License. Please read the license.txt file before using, installing, copying,
  10. * modifying or distribute this file or part of its contents. The contents of
  11. * this file is part of the Source Code of CKFinder.
  12. */
  13. if (!defined('IN_CKFINDER')) exit;
  14. /**
  15. * @package CKFinder
  16. * @subpackage Config
  17. * @copyright CKSource - Frederico Knabben
  18. */
  19. /**
  20. * Include access control config class
  21. */
  22. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/AccessControlConfig.php";
  23. /**
  24. * Include resource type config class
  25. */
  26. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ResourceTypeConfig.php";
  27. /**
  28. * Include thumbnails config class
  29. */
  30. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ThumbnailsConfig.php";
  31. /**
  32. * Include images config class
  33. */
  34. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Core/ImagesConfig.php";
  35. /**
  36. * Main config parser
  37. *
  38. *
  39. * @package CKFinder
  40. * @subpackage Config
  41. * @copyright CKSource - Frederico Knabben
  42. * @global string $GLOBALS['config']
  43. */
  44. class CKFinder_Connector_Core_Config
  45. {
  46. /**
  47. * Is CKFinder enabled
  48. *
  49. * @var boolean
  50. * @access private
  51. */
  52. private $_isEnabled = false;
  53. /**
  54. * License Name
  55. *
  56. * @var string
  57. * @access private
  58. */
  59. private $_licenseName = "";
  60. /**
  61. * License Key
  62. *
  63. * @var string
  64. * @access private
  65. */
  66. private $_licenseKey = "";
  67. /**
  68. * Role session variable name
  69. *
  70. * @var string
  71. * @access private
  72. */
  73. private $_roleSessionVar = "CKFinder_UserRole";
  74. /**
  75. * Access Control Configuration
  76. *
  77. * @var CKFinder_Connector_Core_AccessControlConfig
  78. * @access private
  79. */
  80. private $_accessControlConfigCache;
  81. /**
  82. * ResourceType config cache
  83. *
  84. * @var array
  85. * @access private
  86. */
  87. private $_resourceTypeConfigCache = array();
  88. /**
  89. * Thumbnails config cache
  90. *
  91. * @var CKFinder_Connector_Core_ThumbnailsConfig
  92. * @access private
  93. */
  94. private $_thumbnailsConfigCache;
  95. /**
  96. * Images config cache
  97. *
  98. * @var CKFinder_Connector_Core_ImagesConfig
  99. * @access private
  100. */
  101. private $_imagesConfigCache;
  102. /**
  103. * Array with default resource types names
  104. *
  105. * @access private
  106. * @var array
  107. */
  108. private $_defaultResourceTypes = array();
  109. /**
  110. * Filesystem encoding
  111. *
  112. * @var string
  113. * @access private
  114. */
  115. private $_filesystemEncoding;
  116. /**
  117. * Check double extension
  118. *
  119. * @var boolean
  120. * @access private
  121. */
  122. private $_checkDoubleExtension = true;
  123. /**
  124. * If set to true, validate image size
  125. *
  126. * @var boolean
  127. * @access private
  128. */
  129. private $_secureImageUploads = true;
  130. /**
  131. * Check file size after scaling images (applies to images only)
  132. *
  133. * @var boolean
  134. */
  135. private $_checkSizeAfterScaling = true;
  136. /**
  137. * For security, HTML is allowed in the first Kb of data for files having the following extensions only
  138. *
  139. * @var array
  140. * @access private
  141. */
  142. private $_htmlExtensions = array('html', 'htm', 'xml', 'xsd', 'txt', 'js');
  143. /**
  144. * Chmod files after upload to the following permission
  145. *
  146. * @var integer
  147. * @access private
  148. */
  149. private $_chmodFiles = 0777;
  150. /**
  151. * Chmod directories after creation
  152. *
  153. * @var integer
  154. * @access private
  155. */
  156. private $_chmodFolders = 0755;
  157. /**
  158. * Hide folders
  159. *
  160. * @var array
  161. * @access private
  162. */
  163. private $_hideFolders = array(".svn", "CVS");
  164. /**
  165. * Hide files
  166. *
  167. * @var integer
  168. * @access private
  169. */
  170. private $_hideFiles = array(".*");
  171. /**
  172. * If set to true, force ASCII names
  173. *
  174. * @var boolean
  175. * @access private
  176. */
  177. private $_forceAscii = false;
  178. function __construct()
  179. {
  180. $this->loadValues();
  181. }
  182. /**
  183. * Get file system encoding, returns null if encoding is not set
  184. *
  185. * @access public
  186. * @return string
  187. */
  188. public function getFilesystemEncoding()
  189. {
  190. return $this->_filesystemEncoding;
  191. }
  192. /**
  193. * Get "secureImageUploads" value
  194. *
  195. * @access public
  196. * @return boolean
  197. */
  198. public function getSecureImageUploads()
  199. {
  200. return $this->_secureImageUploads;
  201. }
  202. /**
  203. * Get "checkSizeAfterScaling" value
  204. *
  205. * @access public
  206. * @return boolean
  207. */
  208. public function checkSizeAfterScaling()
  209. {
  210. return $this->_checkSizeAfterScaling;
  211. }
  212. /**
  213. * Get "htmlExtensions" value
  214. *
  215. * @access public
  216. * @return array
  217. */
  218. public function getHtmlExtensions()
  219. {
  220. return $this->_htmlExtensions;
  221. }
  222. /**
  223. * Get "forceAscii" value
  224. *
  225. * @access public
  226. * @return array
  227. */
  228. public function forceAscii()
  229. {
  230. return $this->_forceAscii;
  231. }
  232. /**
  233. * Get regular expression to hide folders
  234. *
  235. * @access public
  236. * @return array
  237. */
  238. public function getHideFoldersRegex()
  239. {
  240. static $folderRegex;
  241. if (!isset($folderRegex)) {
  242. if (is_array($this->_hideFolders) && $this->_hideFolders) {
  243. $folderRegex = join("|", $this->_hideFolders);
  244. $folderRegex = strtr($folderRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__"));
  245. $folderRegex = preg_quote($folderRegex, "/");
  246. $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|"));
  247. $folderRegex = "/^(?:" . $folderRegex . ")$/uim";
  248. }
  249. else {
  250. $folderRegex = "";
  251. }
  252. }
  253. return $folderRegex;
  254. }
  255. /**
  256. * Get regular expression to hide files
  257. *
  258. * @access public
  259. * @return array
  260. */
  261. public function getHideFilesRegex()
  262. {
  263. static $fileRegex;
  264. if (!isset($fileRegex)) {
  265. if (is_array($this->_hideFiles) && $this->_hideFiles) {
  266. $fileRegex = join("|", $this->_hideFiles);
  267. $fileRegex = strtr($fileRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__"));
  268. $fileRegex = preg_quote($fileRegex, "/");
  269. $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|"));
  270. $fileRegex = "/^(?:" . $fileRegex . ")$/uim";
  271. }
  272. else {
  273. $fileRegex = "";
  274. }
  275. }
  276. return $fileRegex;
  277. }
  278. /**
  279. * Get "Check double extension" value
  280. *
  281. * @access public
  282. * @return boolean
  283. */
  284. public function getCheckDoubleExtension()
  285. {
  286. return $this->_checkDoubleExtension;
  287. }
  288. /**
  289. * Get default resource types
  290. *
  291. * @access public
  292. * @return array()
  293. */
  294. public function getDefaultResourceTypes()
  295. {
  296. return $this->_defaultResourceTypes;
  297. }
  298. /**
  299. * Is CKFinder enabled
  300. *
  301. * @access public
  302. * @return boolean
  303. */
  304. public function getIsEnabled()
  305. {
  306. return $this->_isEnabled;
  307. }
  308. /**
  309. * Get license key
  310. *
  311. * @access public
  312. * @return string
  313. */
  314. public function getLicenseKey()
  315. {
  316. return $this->_licenseKey;
  317. }
  318. /**
  319. * Get license name
  320. *
  321. * @access public
  322. * @return string
  323. */
  324. public function getLicenseName()
  325. {
  326. return $this->_licenseName;
  327. }
  328. /**
  329. * Get chmod settings for uploaded files
  330. *
  331. * @access public
  332. * @return integer
  333. */
  334. public function getChmodFiles()
  335. {
  336. return $this->_chmodFiles;
  337. }
  338. /**
  339. * Get chmod settings for created directories
  340. *
  341. * @access public
  342. * @return integer
  343. */
  344. public function getChmodFolders()
  345. {
  346. return $this->_chmodFolders;
  347. }
  348. /**
  349. * Get role sesion variable name
  350. *
  351. * @access public
  352. * @return string
  353. */
  354. public function getRoleSessionVar()
  355. {
  356. return $this->_roleSessionVar;
  357. }
  358. /**
  359. * Get resourceTypeName config
  360. *
  361. * @param string $resourceTypeName
  362. * @return CKFinder_Connector_Core_ResourceTypeConfig|null
  363. * @access public
  364. */
  365. public function &getResourceTypeConfig($resourceTypeName)
  366. {
  367. $_null = null;
  368. if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) {
  369. return $this->_resourceTypeConfigCache[$resourceTypeName];
  370. }
  371. if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
  372. return $_null;
  373. }
  374. reset($GLOBALS['config']['ResourceType']);
  375. while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) {
  376. if ($_resourceTypeNode['name'] === $resourceTypeName) {
  377. $this->_resourceTypeConfigCache[$resourceTypeName] = new CKFinder_Connector_Core_ResourceTypeConfig($_resourceTypeNode);
  378. return $this->_resourceTypeConfigCache[$resourceTypeName];
  379. }
  380. }
  381. return $_null;
  382. }
  383. /**
  384. * Get thumbnails config
  385. *
  386. * @access public
  387. * @return CKFinder_Connector_Core_ThumbnailsConfig
  388. */
  389. public function &getThumbnailsConfig()
  390. {
  391. if (!isset($this->_thumbnailsConfigCache)) {
  392. $this->_thumbnailsConfigCache = new CKFinder_Connector_Core_ThumbnailsConfig(isset($GLOBALS['config']['Thumbnails']) ? $GLOBALS['config']['Thumbnails'] : array());
  393. }
  394. return $this->_thumbnailsConfigCache;
  395. }
  396. /**
  397. * Get images config
  398. *
  399. * @access public
  400. * @return CKFinder_Connector_Core_ImagesConfig
  401. */
  402. public function &getImagesConfig()
  403. {
  404. if (!isset($this->_imagesConfigCache)) {
  405. $this->_imagesConfigCache = new CKFinder_Connector_Core_ImagesConfig(isset($GLOBALS['config']['Images']) ? $GLOBALS['config']['Images'] : array());
  406. }
  407. return $this->_imagesConfigCache;
  408. }
  409. /**
  410. * Get access control config
  411. *
  412. * @access public
  413. * @return CKFinder_Connector_Core_AccessControlConfig
  414. */
  415. public function &getAccessControlConfig()
  416. {
  417. if (!isset($this->_accessControlConfigCache)) {
  418. $this->_accessControlConfigCache = new CKFinder_Connector_Core_AccessControlConfig(isset($GLOBALS['config']['AccessControl']) ? $GLOBALS['config']['AccessControl'] : array());
  419. }
  420. return $this->_accessControlConfigCache;
  421. }
  422. /**
  423. * Load values from config
  424. *
  425. * @access private
  426. */
  427. private function loadValues()
  428. {
  429. if (function_exists('CheckAuthentication')) {
  430. $this->_isEnabled = CheckAuthentication();
  431. }
  432. if (isset($GLOBALS['config']['LicenseName'])) {
  433. $this->_licenseName = (string)$GLOBALS['config']['LicenseName'];
  434. }
  435. if (isset($GLOBALS['config']['LicenseKey'])) {
  436. $this->_licenseKey = (string)$GLOBALS['config']['LicenseKey'];
  437. }
  438. if (isset($GLOBALS['config']['FilesystemEncoding'])) {
  439. $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding'];
  440. }
  441. if (isset($GLOBALS['config']['RoleSessionVar'])) {
  442. $this->_roleSessionVar = (string)$GLOBALS['config']['RoleSessionVar'];
  443. }
  444. if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
  445. $this->_checkDoubleExtension = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
  446. }
  447. if (isset($GLOBALS['config']['SecureImageUploads'])) {
  448. $this->_secureImageUploads = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
  449. }
  450. if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) {
  451. $this->_checkSizeAfterScaling = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']);
  452. }
  453. if (isset($GLOBALS['config']['ForceAscii'])) {
  454. $this->_forceAscii = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['ForceAscii']);
  455. }
  456. if (isset($GLOBALS['config']['HtmlExtensions'])) {
  457. $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions'];
  458. }
  459. if (isset($GLOBALS['config']['HideFolders'])) {
  460. $this->_hideFolders = (array)$GLOBALS['config']['HideFolders'];
  461. }
  462. if (isset($GLOBALS['config']['HideFiles'])) {
  463. $this->_hideFiles = (array)$GLOBALS['config']['HideFiles'];
  464. }
  465. if (isset($GLOBALS['config']['ChmodFiles'])) {
  466. $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
  467. }
  468. if (isset($GLOBALS['config']['ChmodFolders'])) {
  469. $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
  470. }
  471. if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
  472. $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes'];
  473. if (strlen($_defaultResourceTypes)) {
  474. $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
  475. }
  476. }
  477. }
  478. /**
  479. * Get all resource type names defined in config
  480. *
  481. * @return array
  482. * @access public
  483. */
  484. public function getResourceTypeNames()
  485. {
  486. if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
  487. return array();
  488. }
  489. $_names = array();
  490. foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) {
  491. if (isset($_resourceType['name'])) {
  492. $_names[] = (string)$_resourceType['name'];
  493. }
  494. }
  495. return $_names;
  496. }
  497. }