1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage platformFilesystem
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 */
8 // Protect from unauthorized access
9 defined('FOF_INCLUDED') or die;
10
11 class FOFIntegrationJoomlaFilesystem extends FOFPlatformFilesystem implements FOFPlatformFilesystemInterface
12 {
13 public function __construct()
14 {
15 if (class_exists('JLoader'))
16 {
17 JLoader::import('joomla.filesystem.path');
18 JLoader::import('joomla.filesystem.folder');
19 JLoader::import('joomla.filesystem.file');
20 }
21 }
22
23 /**
24 * Does the file exists?
25 *
26 * @param $path string Path to the file to test
27 *
28 * @return bool
29 */
30 public function fileExists($path)
31 {
32 return JFile::exists($path);
33 }
34
35 /**
36 * Delete a file or array of files
37 *
38 * @param mixed $file The file name or an array of file names
39 *
40 * @return boolean True on success
41 *
42 */
43 public function fileDelete($file)
44 {
45 return JFile::delete($file);
46 }
47
48 /**
49 * Copies a file
50 *
51 * @param string $src The path to the source file
52 * @param string $dest The path to the destination file
53 * @param string $path An optional base path to prefix to the file names
54 * @param boolean $use_streams True to use streams
55 *
56 * @return boolean True on success
57 */
58 public function fileCopy($src, $dest, $path = null, $use_streams = false)
59 {
60 return JFile::copy($src, $dest, $path, $use_streams);
61 }
62
63 /**
64 * Write contents to a file
65 *
66 * @param string $file The full file path
67 * @param string &$buffer The buffer to write
68 * @param boolean $use_streams Use streams
69 *
70 * @return boolean True on success
71 */
72 public function fileWrite($file, &$buffer, $use_streams = false)
73 {
74 return JFile::write($file, $buffer, $use_streams);
75 }
76
77 /**
78 * Checks for snooping outside of the file system root.
79 *
80 * @param string $path A file system path to check.
81 *
82 * @return string A cleaned version of the path or exit on error.
83 *
84 * @throws Exception
85 */
86 public function pathCheck($path)
87 {
88 return JPath::check($path);
89 }
90
91 /**
92 * Function to strip additional / or \ in a path name.
93 *
94 * @param string $path The path to clean.
95 * @param string $ds Directory separator (optional).
96 *
97 * @return string The cleaned path.
98 *
99 * @throws UnexpectedValueException
100 */
101 public function pathClean($path, $ds = DIRECTORY_SEPARATOR)
102 {
103 return JPath::clean($path, $ds);
104 }
105
106 /**
107 * Searches the directory paths for a given file.
108 *
109 * @param mixed $paths An path string or array of path strings to search in
110 * @param string $file The file name to look for.
111 *
112 * @return mixed The full path and file name for the target file, or boolean false if the file is not found in any of the paths.
113 */
114 public function pathFind($paths, $file)
115 {
116 return JPath::find($paths, $file);
117 }
118
119 /**
120 * Wrapper for the standard file_exists function
121 *
122 * @param string $path Folder name relative to installation dir
123 *
124 * @return boolean True if path is a folder
125 */
126 public function folderExists($path)
127 {
128 return JFolder::exists($path);
129 }
130
131 /**
132 * Utility function to read the files in a folder.
133 *
134 * @param string $path The path of the folder to read.
135 * @param string $filter A filter for file names.
136 * @param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth.
137 * @param boolean $full True to return the full path to the file.
138 * @param array $exclude Array with names of files which should not be shown in the result.
139 * @param array $excludefilter Array of filter to exclude
140 * @param boolean $naturalSort False for asort, true for natsort
141 *
142 * @return array Files in the given folder.
143 */
144 public function folderFiles($path, $filter = '.', $recurse = false, $full = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'),
145 $excludefilter = array('^\..*', '.*~'), $naturalSort = false)
146 {
147 return JFolder::files($path, $filter, $recurse, $full, $exclude, $excludefilter, $naturalSort);
148 }
149
150 /**
151 * Utility function to read the folders in a folder.
152 *
153 * @param string $path The path of the folder to read.
154 * @param string $filter A filter for folder names.
155 * @param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth.
156 * @param boolean $full True to return the full path to the folders.
157 * @param array $exclude Array with names of folders which should not be shown in the result.
158 * @param array $excludefilter Array with regular expressions matching folders which should not be shown in the result.
159 *
160 * @return array Folders in the given folder.
161 */
162 public function folderFolders($path, $filter = '.', $recurse = false, $full = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'),
163 $excludefilter = array('^\..*'))
164 {
165 return JFolder::folders($path, $filter, $recurse, $full, $exclude, $excludefilter);
166 }
167
168 /**
169 * Create a folder -- and all necessary parent folders.
170 *
171 * @param string $path A path to create from the base path.
172 * @param integer $mode Directory permissions to set for folders created. 0755 by default.
173 *
174 * @return boolean True if successful.
175 */
176 public function folderCreate($path = '', $mode = 0755)
177 {
178 return JFolder::create($path, $mode);
179 }
180 }