PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_jce/editor/libraries/classes/extensions/filesystem.php

https://bitbucket.org/kraymitchell/apex
PHP | 284 lines | 177 code | 40 blank | 67 comment | 9 complexity | d0b0c88c6dd26b0c5cd7b03e7b19aeed MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * @package JCE
  4. * @copyright Copyright Š 2009-2011 Ryan Demmer. All rights reserved.
  5. * @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  6. * JCE is free software. This version may have been modified pursuant
  7. * to the GNU General Public License, and as distributed it includes or
  8. * is derivative of works licensed under the GNU General Public License or
  9. * other free or open source software licenses.
  10. */
  11. defined('_JEXEC') or die('RESTRICTED');
  12. class WFFileSystem extends WFExtension
  13. {
  14. /**
  15. * Constructor activating the default information of the class
  16. *
  17. * @access protected
  18. */
  19. function __construct($config = array())
  20. {
  21. parent::__construct();
  22. $this->setProperties(array_merge($config, array(
  23. 'local' => true,
  24. 'upload' => array(
  25. 'stream' => false,
  26. 'chunking' => false,
  27. 'unique_filenames' => false
  28. )
  29. )));
  30. }
  31. /**
  32. * Returns a reference to a plugin object
  33. *
  34. * This method must be invoked as:
  35. * <pre> $advlink =AdvLink::getInstance();</pre>
  36. *
  37. * @access public
  38. * @return JCE The editor object.
  39. * @since 1.5
  40. */
  41. public static function getInstance($type = 'joomla', $config = array())
  42. {
  43. static $instance;
  44. if (!is_object($instance)) {
  45. $fs = parent::loadExtensions(array(
  46. 'types' => array(
  47. 'filesystem'
  48. ),
  49. 'extension' => $type
  50. ));
  51. $classname = 'WF' . ucfirst($fs) . 'FileSystem';
  52. if (class_exists($classname)) {
  53. $instance = new $classname($config);
  54. } else {
  55. $instance = new WFFileSystem($config);
  56. }
  57. }
  58. return $instance;
  59. }
  60. /**
  61. * Get the base directory.
  62. * @return string base dir
  63. */
  64. function getBaseDir()
  65. {
  66. return WFUtility::makePath(JPATH_SITE, $this->getRootDir());
  67. }
  68. /**
  69. * Get the full base url
  70. * @return string base url
  71. */
  72. function getBaseURL()
  73. {
  74. return WFUtility::makePath(JURI::root(true), 'images');
  75. }
  76. /**
  77. * Return the full user directory path. Create if required
  78. *
  79. * @param string The base path
  80. * @access public
  81. * @return Full path to folder
  82. */
  83. function getRootDir()
  84. {
  85. static $root;
  86. if (!$root) {
  87. $user = JFactory::getUser();
  88. $wf = WFEditorPlugin::getInstance();
  89. $profile = $wf->getProfile();
  90. // Get base directory as shared parameter
  91. $root = $this->get('dir', 'images');
  92. // Remove whitespace
  93. $root = trim($root);
  94. // Convert slashes / Strip double slashes
  95. $root = preg_replace('/[\\\\]+/', '/', $root);
  96. // Remove first leading slash
  97. $root = ltrim($root, '/');
  98. // Force default directory if base param starts with a variable or a . eg $id
  99. if (preg_match('/[\.\$]/', $root{0})) {
  100. $root = 'images';
  101. }
  102. jimport('joomla.user.helper');
  103. // Joomla! 1.6+
  104. if (method_exists('JUserHelper', 'getUserGroups')) {
  105. $groups = JUserHelper::getUserGroups($user->id);
  106. $groups = array_keys($groups);
  107. $usertype = array_shift($groups);
  108. } else {
  109. $usertype = $user->usertype;
  110. }
  111. // Replace any path variables
  112. $pattern = array('/\$id/', '/\$username/', '/\$usertype/', '/\$(group|profile)/', '/\$day/', '/\$month/', '/\$year/');
  113. $replace = array($user->id, $user->username, $usertype, $profile->name, date('d'), date('m'), date('Y'));
  114. $root = preg_replace($pattern, $replace, $root);
  115. // split into path parts to preserve /
  116. $parts = explode('/', $root);
  117. // clean path parts
  118. $parts = WFUtility::makeSafe($parts, $wf->getParam('editor.websafe_mode', 'utf-8'));
  119. //join path parts
  120. $root = implode('/', $parts);
  121. }
  122. return $root;
  123. }
  124. function getFiles($path, $filter)
  125. {
  126. return array();
  127. }
  128. function getFolders($path)
  129. {
  130. return array();
  131. }
  132. function getSourceDir($path)
  133. {
  134. return $path;
  135. }
  136. function isMatch($needle, $haystack)
  137. {
  138. return $needle == $haystack;
  139. }
  140. function pathinfo($path)
  141. {
  142. return pathinfo($path);
  143. }
  144. function delete($path)
  145. {
  146. return true;
  147. }
  148. function createFolder($path, $new)
  149. {
  150. return true;
  151. }
  152. function rename($src, $dest)
  153. {
  154. return true;
  155. }
  156. function copy($src, $dest)
  157. {
  158. return true;
  159. }
  160. function move($src, $dest)
  161. {
  162. return true;
  163. }
  164. function getFolderDetails($path)
  165. {
  166. return array(
  167. 'properties' => array('modified' => '')
  168. );
  169. }
  170. function getFileDetails($path)
  171. {
  172. $data = array(
  173. 'properties' => array(
  174. 'size' => '',
  175. 'modified' => ''
  176. )
  177. );
  178. if (preg_match('#\.(jpg|jpeg|bmp|gif|tiff|png)#i', $path)) {
  179. $image = array(
  180. 'properties' => array(
  181. 'width' => 0,
  182. 'height' => 0,
  183. 'preview' => ''
  184. )
  185. );
  186. return array_merge_recursive($data, $image);
  187. }
  188. return $data;
  189. }
  190. function getDimensions($path)
  191. {
  192. return array(
  193. 'width' => '',
  194. 'height' => ''
  195. );
  196. }
  197. function upload($method, $src, $dir, $name, $chunks = 0, $chunk = 0)
  198. {
  199. return true;
  200. }
  201. function exists($path)
  202. {
  203. return true;
  204. }
  205. function read($path)
  206. {
  207. return '';
  208. }
  209. function write($path, $content)
  210. {
  211. return true;
  212. }
  213. function isLocal()
  214. {
  215. return $this->get('local') === true;
  216. }
  217. }
  218. /**
  219. * Filesystem Error class
  220. */
  221. final class WFFileSystemResult
  222. {
  223. /*
  224. * @var Object type eg: file / folder
  225. */
  226. public $type = 'files';
  227. /*
  228. * @boolean Result state
  229. */
  230. public $state = false;
  231. /*
  232. * @int Error code
  233. */
  234. public $code = null;
  235. /*
  236. * @var Error message
  237. */
  238. public $message = null;
  239. /*
  240. * @var File / Folder path
  241. */
  242. public $path = null;
  243. function __construct(){}
  244. }