PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/chimbien/app/webroot/js/ckfinder/core/connector/php/php4/Core/Config.php

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