PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

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

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