PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/webpolis/liiv
PHP | 514 lines | 212 code | 38 blank | 264 comment | 34 complexity | 542c8d9459f47f43f8023429704a72a0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * CKFinder
  4. * ========
  5. * http://ckfinder.com
  6. * Copyright (C) 2007-2009, 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. function CKFinder_Connector_Core_Config()
  171. {
  172. $this->loadValues();
  173. }
  174. /**
  175. * Get file system encoding, returns null if encoding is not set
  176. *
  177. * @access public
  178. * @return string
  179. */
  180. function getFilesystemEncoding()
  181. {
  182. return $this->_filesystemEncoding;
  183. }
  184. /**
  185. * Get "secureImageUploads" value
  186. *
  187. * @access public
  188. * @return boolean
  189. */
  190. function getSecureImageUploads()
  191. {
  192. return $this->_secureImageUploads;
  193. }
  194. /**
  195. * Get "checkSizeAfterScaling" value
  196. *
  197. * @access public
  198. * @return boolean
  199. */
  200. function checkSizeAfterScaling()
  201. {
  202. return $this->_checkSizeAfterScaling;
  203. }
  204. /**
  205. * Get "htmlExtensions" value
  206. *
  207. * @access public
  208. * @return array
  209. */
  210. function getHtmlExtensions()
  211. {
  212. return $this->_htmlExtensions;
  213. }
  214. /**
  215. * Get regular expression to hide folders
  216. *
  217. * @access public
  218. * @return array
  219. */
  220. function getHideFoldersRegex()
  221. {
  222. static $folderRegex;
  223. if (!isset($folderRegex)) {
  224. if (is_array($this->_hideFolders) && $this->_hideFolders) {
  225. $folderRegex = join("|", $this->_hideFolders);
  226. $folderRegex = strtr($folderRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__"));
  227. $folderRegex = preg_quote($folderRegex, "/");
  228. $folderRegex = strtr($folderRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|"));
  229. $folderRegex = "/^(?:" . $folderRegex . ")$/uim";
  230. }
  231. else {
  232. $folderRegex = "";
  233. }
  234. }
  235. return $folderRegex;
  236. }
  237. /**
  238. * Get regular expression to hide files
  239. *
  240. * @access public
  241. * @return array
  242. */
  243. function getHideFilesRegex()
  244. {
  245. static $fileRegex;
  246. if (!isset($fileRegex)) {
  247. if (is_array($this->_hideFiles) && $this->_hideFiles) {
  248. $fileRegex = join("|", $this->_hideFiles);
  249. $fileRegex = strtr($fileRegex, array("?" => "__QMK__", "*" => "__AST__", "|" => "__PIP__"));
  250. $fileRegex = preg_quote($fileRegex, "/");
  251. $fileRegex = strtr($fileRegex, array("__QMK__" => ".", "__AST__" => ".*", "__PIP__" => "|"));
  252. $fileRegex = "/^(?:" . $fileRegex . ")$/uim";
  253. }
  254. else {
  255. $fileRegex = "";
  256. }
  257. }
  258. return $fileRegex;
  259. }
  260. /**
  261. * Get "Check double extension" value
  262. *
  263. * @access public
  264. * @return boolean
  265. */
  266. function getCheckDoubleExtension()
  267. {
  268. return $this->_checkDoubleExtension;
  269. }
  270. /**
  271. * Get default resource types
  272. *
  273. * @access public
  274. * @return array()
  275. */
  276. function getDefaultResourceTypes()
  277. {
  278. return $this->_defaultResourceTypes;
  279. }
  280. /**
  281. * Is CKFinder enabled
  282. *
  283. * @access public
  284. * @return boolean
  285. */
  286. function getIsEnabled()
  287. {
  288. return $this->_isEnabled;
  289. }
  290. /**
  291. * Get license key
  292. *
  293. * @access public
  294. * @return string
  295. */
  296. function getLicenseKey()
  297. {
  298. return $this->_licenseKey;
  299. }
  300. /**
  301. * Get license name
  302. *
  303. * @access public
  304. * @return string
  305. */
  306. function getLicenseName()
  307. {
  308. return $this->_licenseName;
  309. }
  310. /**
  311. * Get chmod settings for uploaded files
  312. *
  313. * @access public
  314. * @return integer
  315. */
  316. function getChmodFiles()
  317. {
  318. return $this->_chmodFiles;
  319. }
  320. /**
  321. * Get chmod settings for created directories
  322. *
  323. * @access public
  324. * @return integer
  325. */
  326. function getChmodFolders()
  327. {
  328. return $this->_chmodFolders;
  329. }
  330. /**
  331. * Get role sesion variable name
  332. *
  333. * @access public
  334. * @return string
  335. */
  336. function getRoleSessionVar()
  337. {
  338. return $this->_roleSessionVar;
  339. }
  340. /**
  341. * Get resourceTypeName config
  342. *
  343. * @param string $resourceTypeName
  344. * @return CKFinder_Connector_Core_ResourceTypeConfig|null
  345. * @access public
  346. */
  347. function &getResourceTypeConfig($resourceTypeName)
  348. {
  349. $_null = null;
  350. if (isset($this->_resourceTypeConfigCache[$resourceTypeName])) {
  351. return $this->_resourceTypeConfigCache[$resourceTypeName];
  352. }
  353. if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
  354. return $_null;
  355. }
  356. reset($GLOBALS['config']['ResourceType']);
  357. while (list($_key,$_resourceTypeNode) = each($GLOBALS['config']['ResourceType'])) {
  358. if ($_resourceTypeNode['name'] === $resourceTypeName) {
  359. $this->_resourceTypeConfigCache[$resourceTypeName] = new CKFinder_Connector_Core_ResourceTypeConfig($_resourceTypeNode);
  360. return $this->_resourceTypeConfigCache[$resourceTypeName];
  361. }
  362. }
  363. return $_null;
  364. }
  365. /**
  366. * Get thumbnails config
  367. *
  368. * @access public
  369. * @return CKFinder_Connector_Core_ThumbnailsConfig
  370. */
  371. function &getThumbnailsConfig()
  372. {
  373. if (!isset($this->_thumbnailsConfigCache)) {
  374. $this->_thumbnailsConfigCache = new CKFinder_Connector_Core_ThumbnailsConfig(isset($GLOBALS['config']['Thumbnails']) ? $GLOBALS['config']['Thumbnails'] : array());
  375. }
  376. return $this->_thumbnailsConfigCache;
  377. }
  378. /**
  379. * Get images config
  380. *
  381. * @access public
  382. * @return CKFinder_Connector_Core_ImagesConfig
  383. */
  384. function &getImagesConfig()
  385. {
  386. if (!isset($this->_imagesConfigCache)) {
  387. $this->_imagesConfigCache = new CKFinder_Connector_Core_ImagesConfig(isset($GLOBALS['config']['Images']) ? $GLOBALS['config']['Images'] : array());
  388. }
  389. return $this->_imagesConfigCache;
  390. }
  391. /**
  392. * Get access control config
  393. *
  394. * @access public
  395. * @return CKFinder_Connector_Core_AccessControlConfig
  396. */
  397. function &getAccessControlConfig()
  398. {
  399. if (!isset($this->_accessControlConfigCache)) {
  400. $this->_accessControlConfigCache = new CKFinder_Connector_Core_AccessControlConfig(isset($GLOBALS['config']['AccessControl']) ? $GLOBALS['config']['AccessControl'] : array());
  401. }
  402. return $this->_accessControlConfigCache;
  403. }
  404. /**
  405. * Load values from config
  406. *
  407. * @access private
  408. */
  409. function loadValues()
  410. {
  411. if (function_exists('CheckAuthentication')) {
  412. $this->_isEnabled = CheckAuthentication();
  413. }
  414. if (isset($GLOBALS['config']['LicenseName'])) {
  415. $this->_licenseName = (string)$GLOBALS['config']['LicenseName'];
  416. }
  417. if (isset($GLOBALS['config']['LicenseKey'])) {
  418. $this->_licenseKey = (string)$GLOBALS['config']['LicenseKey'];
  419. }
  420. if (isset($GLOBALS['config']['FilesystemEncoding'])) {
  421. $this->_filesystemEncoding = (string)$GLOBALS['config']['FilesystemEncoding'];
  422. }
  423. if (isset($GLOBALS['config']['RoleSessionVar'])) {
  424. $this->_roleSessionVar = (string)$GLOBALS['config']['RoleSessionVar'];
  425. }
  426. if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
  427. $this->_checkDoubleExtension = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
  428. }
  429. if (isset($GLOBALS['config']['SecureImageUploads'])) {
  430. $this->_secureImageUploads = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
  431. }
  432. if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) {
  433. $this->_checkSizeAfterScaling = CKFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']);
  434. }
  435. if (isset($GLOBALS['config']['HtmlExtensions'])) {
  436. $this->_htmlExtensions = (array)$GLOBALS['config']['HtmlExtensions'];
  437. }
  438. if (isset($GLOBALS['config']['HideFolders'])) {
  439. $this->_hideFolders = (array)$GLOBALS['config']['HideFolders'];
  440. }
  441. if (isset($GLOBALS['config']['HideFiles'])) {
  442. $this->_hideFiles = (array)$GLOBALS['config']['HideFiles'];
  443. }
  444. if (isset($GLOBALS['config']['ChmodFiles'])) {
  445. $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
  446. }
  447. if (isset($GLOBALS['config']['ChmodFolders'])) {
  448. $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
  449. }
  450. if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
  451. $_defaultResourceTypes = (string)$GLOBALS['config']['DefaultResourceTypes'];
  452. if (strlen($_defaultResourceTypes)) {
  453. $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
  454. }
  455. }
  456. }
  457. /**
  458. * Get all resource type names defined in config
  459. *
  460. * @return array
  461. * @access public
  462. */
  463. function getResourceTypeNames()
  464. {
  465. if (!isset($GLOBALS['config']['ResourceType']) || !is_array($GLOBALS['config']['ResourceType'])) {
  466. return array();
  467. }
  468. $_names = array();
  469. foreach ($GLOBALS['config']['ResourceType'] as $key => $_resourceType) {
  470. if (isset($_resourceType['name'])) {
  471. $_names[] = (string)$_resourceType['name'];
  472. }
  473. }
  474. return $_names;
  475. }
  476. }