/modules/ckfinder/core/connector/php/php5/Core/FolderHandler.php

https://github.com/nDIGAH3CEYIiCsq/gold · PHP · 270 lines · 110 code · 27 blank · 133 comment · 20 complexity · 0b184a247d696514f192531513fb85bc 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. /**
  14. * @package CKFinder
  15. * @subpackage Core
  16. * @copyright CKSource - Frederico Knabben
  17. */
  18. /**
  19. * Include file system utils class
  20. */
  21. require_once CKFINDER_CONNECTOR_LIB_DIR . "/Utils/FileSystem.php";
  22. /**
  23. * @package CKFinder
  24. * @subpackage Core
  25. * @copyright CKSource - Frederico Knabben
  26. */
  27. class CKFinder_Connector_Core_FolderHandler
  28. {
  29. /**
  30. * CKFinder_Connector_Core_ResourceTypeConfig object
  31. *
  32. * @var CKFinder_Connector_Core_ResourceTypeConfig
  33. * @access private
  34. */
  35. private $_resourceTypeConfig;
  36. /**
  37. * ResourceType name
  38. *
  39. * @var string
  40. * @access private
  41. */
  42. private $_resourceTypeName = "";
  43. /**
  44. * Client path
  45. *
  46. * @var string
  47. * @access private
  48. */
  49. private $_clientPath = "/";
  50. /**
  51. * Url
  52. *
  53. * @var string
  54. * @access private
  55. */
  56. private $_url;
  57. /**
  58. * Server path
  59. *
  60. * @var string
  61. * @access private
  62. */
  63. private $_serverPath;
  64. /**
  65. * Thumbnails server path
  66. *
  67. * @var string
  68. * @access private
  69. */
  70. private $_thumbsServerPath;
  71. /**
  72. * ACL mask
  73. *
  74. * @var int
  75. * @access private
  76. */
  77. private $_aclMask;
  78. /**
  79. * Folder info
  80. *
  81. * @var mixed
  82. * @access private
  83. */
  84. private $_folderInfo;
  85. /**
  86. * Thumbnails folder info
  87. *
  88. * @var mized
  89. * @access private
  90. */
  91. private $_thumbsFolderInfo;
  92. function __construct()
  93. {
  94. if (isset($_GET["type"])) {
  95. $this->_resourceTypeName = (string)$_GET["type"];
  96. }
  97. if (isset($_GET["currentFolder"])) {
  98. $this->_clientPath = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding((string)$_GET["currentFolder"]);
  99. }
  100. if (!strlen($this->_clientPath)) {
  101. $this->_clientPath = "/";
  102. }
  103. else {
  104. if (substr($this->_clientPath, -1, 1) != "/") {
  105. $this->_clientPath .= "/";
  106. }
  107. if (substr($this->_clientPath, 0, 1) != "/") {
  108. $this->_clientPath = "/" . $this->_clientPath;
  109. }
  110. }
  111. $this->_aclMask = -1;
  112. }
  113. /**
  114. * Get resource type config
  115. *
  116. * @return CKFinder_Connector_Core_ResourceTypeConfig
  117. * @access public
  118. */
  119. public function &getResourceTypeConfig()
  120. {
  121. if (!isset($this->_resourceTypeConfig)) {
  122. $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
  123. $this->_resourceTypeConfig = $_config->getResourceTypeConfig($this->_resourceTypeName);
  124. }
  125. if (is_null($this->_resourceTypeConfig)) {
  126. $connector =& CKFinder_Connector_Core_Factory::getInstance("Core_Connector");
  127. $oErrorHandler =& $connector->getErrorHandler();
  128. $oErrorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_TYPE);
  129. }
  130. return $this->_resourceTypeConfig;
  131. }
  132. /**
  133. * Get resource type name
  134. *
  135. * @return string
  136. * @access public
  137. */
  138. public function getResourceTypeName()
  139. {
  140. return $this->_resourceTypeName;
  141. }
  142. /**
  143. * Get Client path
  144. *
  145. * @return string
  146. * @access public
  147. */
  148. public function getClientPath()
  149. {
  150. return $this->_clientPath;
  151. }
  152. /**
  153. * Get Url
  154. *
  155. * @return string
  156. * @access public
  157. */
  158. public function getUrl()
  159. {
  160. if (is_null($this->_url)) {
  161. $this->_resourceTypeConfig = $this->getResourceTypeConfig();
  162. if (is_null($this->_resourceTypeConfig)) {
  163. $connector =& CKFinder_Connector_Core_Factory::getInstance("Core_Connector");
  164. $oErrorHandler =& $connector->getErrorHandler();
  165. $oErrorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_TYPE);
  166. $this->_url = "";
  167. }
  168. else {
  169. $this->_url = $this->_resourceTypeConfig->getUrl() . ltrim($this->getClientPath(), "/");
  170. }
  171. }
  172. return $this->_url;
  173. }
  174. /**
  175. * Get server path
  176. *
  177. * @return string
  178. * @access public
  179. */
  180. public function getServerPath()
  181. {
  182. if (is_null($this->_serverPath)) {
  183. $this->_resourceTypeConfig = $this->getResourceTypeConfig();
  184. $this->_serverPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_resourceTypeConfig->getDirectory(), ltrim($this->_clientPath, "/"));
  185. }
  186. return $this->_serverPath;
  187. }
  188. /**
  189. * Get server path to thumbnails directory
  190. *
  191. * @access public
  192. * @return string
  193. */
  194. public function getThumbsServerPath()
  195. {
  196. if (is_null($this->_thumbsServerPath)) {
  197. $this->_resourceTypeConfig = $this->getResourceTypeConfig();
  198. $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
  199. $_thumbnailsConfig = $_config->getThumbnailsConfig();
  200. // Get the resource type directory.
  201. $this->_thumbsServerPath = CKFinder_Connector_Utils_FileSystem::combinePaths($_thumbnailsConfig->getDirectory(), $this->_resourceTypeConfig->getName());
  202. // Return the resource type directory combined with the required path.
  203. $this->_thumbsServerPath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_thumbsServerPath, ltrim($this->_clientPath, '/'));
  204. if (!is_dir($this->_thumbsServerPath)) {
  205. if(!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively($this->_thumbsServerPath)) {
  206. /**
  207. * @todo Ckfinder_Connector_Utils_Xml::raiseError(); perhaps we should return error
  208. *
  209. */
  210. }
  211. }
  212. }
  213. return $this->_thumbsServerPath;
  214. }
  215. /**
  216. * Get ACL Mask
  217. *
  218. * @return int
  219. * @access public
  220. */
  221. public function getAclMask()
  222. {
  223. $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
  224. $_aclConfig = $_config->getAccessControlConfig();
  225. if ($this->_aclMask == -1) {
  226. $this->_aclMask = $_aclConfig->getComputedMask($this->_resourceTypeName, $this->_clientPath);
  227. }
  228. return $this->_aclMask;
  229. }
  230. /**
  231. * Check ACL
  232. *
  233. * @access public
  234. * @param int $aclToCkeck
  235. * @return boolean
  236. */
  237. public function checkAcl($aclToCkeck)
  238. {
  239. $aclToCkeck = intval($aclToCkeck);
  240. $maska = $this->getAclMask();
  241. return (($maska & $aclToCkeck) == $aclToCkeck);
  242. }
  243. }