PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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