PageRenderTime 49ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Backend/Core/Js/ckfinder/core/connector/php/php5/Core/FolderHandler.php

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