Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JFolder

Liste de tous les membres

Fonctions membres publiques statiques

static copy ($src, $dest, $path= '', $force=false, $use_streams=false)
static create ($path= '', $mode=0755)
static delete ($path)
static move ($src, $dest, $path= '', $use_streams=false)
static exists ($path)
static files ($path, $filter= '.', $recurse=false, $full=false, $exclude=array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter=array('^\..*', '.*~'), $naturalSort=false)
static folders ($path, $filter= '.', $recurse=false, $full=false, $exclude=array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter=array('^\..*'))
static listFolderTree ($path, $filter, $maxLevel=3, $level=0, $parent=0)
static makeSafe ($path)

Fonctions membres protégées statiques

static _items ($path, $filter, $recurse, $full, $exclude, $excludefilter_string, $findfiles)

Description détaillée

Définition à la ligne 21 du fichier folder.php.


Documentation des fonctions membres

static JFolder::_items (   $path,
  $filter,
  $recurse,
  $full,
  $exclude,
  $excludefilter_string,
  $findfiles 
)
staticprotected

Function to read the files/folders in a folder.

Paramètres:
string$pathThe path of the folder to read.
string$filterA filter for file names.
mixed$recurseTrue to recursively search into sub-folders, or an integer to specify the maximum depth.
boolean$fullTrue to return the full path to the file.
array$excludeArray with names of files which should not be shown in the result.
string$excludefilter_stringRegexp of files to exclude
boolean$findfilesTrue to read the files, false to read the folders
Renvoie:
array Files.
Depuis:
11.1

Définition à la ligne 601 du fichier folder.php.

{
@set_time_limit(ini_get('max_execution_time'));
$arr = array();
// Read the source directory
if (!($handle = @opendir($path)))
{
return $arr;
}
while (($file = readdir($handle)) !== false)
{
if ($file != '.' && $file != '..' && !in_array($file, $exclude)
&& (empty($excludefilter_string) || !preg_match($excludefilter_string, $file)))
{
// Compute the fullpath
$fullpath = $path . '/' . $file;
// Compute the isDir flag
$isDir = is_dir($fullpath);
if (($isDir xor $findfiles) && preg_match("/$filter/", $file))
{
// (fullpath is dir and folders are searched or fullpath is not dir and files are searched) and file matches the filter
if ($full)
{
// Full path is requested
$arr[] = $fullpath;
}
else
{
// Filename is requested
$arr[] = $file;
}
}
if ($isDir && $recurse)
{
// Search recursively
if (is_int($recurse))
{
// Until depth 0 is reached
$arr = array_merge($arr, self::_items($fullpath, $filter, $recurse - 1, $full, $exclude, $excludefilter_string, $findfiles));
}
else
{
$arr = array_merge($arr, self::_items($fullpath, $filter, $recurse, $full, $exclude, $excludefilter_string, $findfiles));
}
}
}
}
closedir($handle);
return $arr;
}
static JFolder::copy (   $src,
  $dest,
  $path = '',
  $force = false,
  $use_streams = false 
)
static

Copy a folder.

Paramètres:
string$srcThe path to the source folder.
string$destThe path to the destination folder.
string$pathAn optional base path to prefix to the file names.
boolean$forceForce copy.
boolean$use_streamsOptionally force folder/file overwrites.
Renvoie:
boolean True on success.
Depuis:
11.1
Exceptions:
RuntimeException

Définition à la ligne 37 du fichier folder.php.

Références JPath\clean(), JClientHelper\getCredentials(), JClientFtp\getInstance(), et JFactory\getStream().

{
@set_time_limit(ini_get('max_execution_time'));
$FTPOptions = JClientHelper::getCredentials('ftp');
if ($path)
{
$src = JPath::clean($path . '/' . $src);
$dest = JPath::clean($path . '/' . $dest);
}
// Eliminate trailing directory separators, if any
$src = rtrim($src, DIRECTORY_SEPARATOR);
$dest = rtrim($dest, DIRECTORY_SEPARATOR);
if (!self::exists($src))
{
throw new RuntimeException('Source folder not found', -1);
}
if (self::exists($dest) && !$force)
{
throw new RuntimeException('Destination folder not found', -1);
}
// Make sure the destination exists
if (!self::create($dest))
{
throw new RuntimeException('Cannot create destination folder', -1);
}
// If we're using ftp and don't have streams enabled
if ($FTPOptions['enabled'] == 1 && !$use_streams)
{
// Connect the FTP client
$ftp = JClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
if (!($dh = @opendir($src)))
{
throw new RuntimeException('Cannot open source folder', -1);
}
// Walk through the directory copying files and recursing into folders.
while (($file = readdir($dh)) !== false)
{
$sfid = $src . '/' . $file;
$dfid = $dest . '/' . $file;
switch (filetype($sfid))
{
case 'dir':
if ($file != '.' && $file != '..')
{
$ret = self::copy($sfid, $dfid, null, $force);
if ($ret !== true)
{
return $ret;
}
}
break;
case 'file':
// Translate path for the FTP account
$dfid = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dfid), '/');
if (!$ftp->store($sfid, $dfid))
{
throw new RuntimeException('Copy file failed', -1);
}
break;
}
}
}
else
{
if (!($dh = @opendir($src)))
{
throw new RuntimeException('Cannot open source folder', -1);
}
// Walk through the directory copying files and recursing into folders.
while (($file = readdir($dh)) !== false)
{
$sfid = $src . '/' . $file;
$dfid = $dest . '/' . $file;
switch (filetype($sfid))
{
case 'dir':
if ($file != '.' && $file != '..')
{
$ret = self::copy($sfid, $dfid, null, $force, $use_streams);
if ($ret !== true)
{
return $ret;
}
}
break;
case 'file':
if ($use_streams)
{
$stream = JFactory::getStream();
if (!$stream->copy($sfid, $dfid))
{
throw new RuntimeException('Cannot copy file: ' . $stream->getError(), -1);
}
}
else
{
if (!@copy($sfid, $dfid))
{
throw new RuntimeException('Copy file failed', -1);
}
}
break;
}
}
}
return true;
}

+ Voici le graphe d'appel pour cette fonction :

static JFolder::create (   $path = '',
  $mode = 0755 
)
static

Create a folder – and all necessary parent folders.

Paramètres:
string$pathA path to create from the base path.
integer$modeDirectory permissions to set for folders created. 0755 by default.
Renvoie:
boolean True if successful.
Depuis:
11.1

Définition à la ligne 170 du fichier folder.php.

Références JText\_(), JLog\add(), JPath\clean(), JClientHelper\getCredentials(), JClientFtp\getInstance(), et JLog\WARNING.

Référencé par JFile\copy(), JArchive\extract(), JArchiveTar\extract(), JArchiveZip\extractCustom(), JArchiveZip\extractNative(), JLogLoggerFormattedtext\initFile(), JFile\upload(), JFile\write(), et JApplicationDaemon\writeProcessIdFile().

{
$FTPOptions = JClientHelper::getCredentials('ftp');
static $nested = 0;
// Check to make sure the path valid and clean
$path = JPath::clean($path);
// Check if parent dir exists
$parent = dirname($path);
if (!self::exists($parent))
{
// Prevent infinite loops!
$nested++;
if (($nested > 20) || ($parent == $path))
{
JLog::add(__METHOD__ . ': ' . JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_LOOP'), JLog::WARNING, 'jerror');
$nested--;
return false;
}
// Create the parent directory
if (self::create($parent, $mode) !== true)
{
// JFolder::create throws an error
$nested--;
return false;
}
// OK, parent directory has been created
$nested--;
}
// Check if dir already exists
if (self::exists($path))
{
return true;
}
// Check for safe mode
if ($FTPOptions['enabled'] == 1)
{
// Connect the FTP client
$ftp = JClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
// Translate path to FTP path
$path = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $path), '/');
$ret = $ftp->mkdir($path);
$ftp->chmod($path, $mode);
}
else
{
// We need to get and explode the open_basedir paths
$obd = ini_get('open_basedir');
// If open_basedir is set we need to get the open_basedir that the path is in
if ($obd != null)
{
if (IS_WIN)
{
$obdSeparator = ";";
}
else
{
$obdSeparator = ":";
}
// Create the array of open_basedir paths
$obdArray = explode($obdSeparator, $obd);
$inBaseDir = false;
// Iterate through open_basedir paths looking for a match
foreach ($obdArray as $test)
{
$test = JPath::clean($test);
if (strpos($path, $test) === 0)
{
$inBaseDir = true;
break;
}
}
if ($inBaseDir == false)
{
// Return false for JFolder::create because the path to be created is not in open_basedir
JLog::add(__METHOD__ . ': ' . JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_PATH'), JLog::WARNING, 'jerror');
return false;
}
}
// First set umask
$origmask = @umask(0);
// Create the path
if (!$ret = @mkdir($path, $mode))
{
@umask($origmask);
__METHOD__ . ': ' . JText::_('JLIB_FILESYSTEM_ERROR_COULD_NOT_CREATE_DIRECTORY') . 'Path: ' . $path, JLog::WARNING, 'jerror'
);
return false;
}
// Reset umask
@umask($origmask);
}
return $ret;
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JFolder::delete (   $path)
static

Delete a folder.

Paramètres:
string$pathThe path to the folder to delete.
Renvoie:
boolean True on success.
Depuis:
11.1
Exceptions:
UnexpectedValueException

Définition à la ligne 295 du fichier folder.php.

Références JText\_(), JLog\add(), JPath\clean(), JFile\delete(), JClientHelper\getCredentials(), JClientFtp\getInstance(), jimport(), JText\sprintf(), et JLog\WARNING.

Référencé par JCacheStorageCachelite\clean().

{
@set_time_limit(ini_get('max_execution_time'));
// Sanity check
if (!$path)
{
// Bad programmer! Bad Bad programmer!
JLog::add(__METHOD__ . ': ' . JText::_('JLIB_FILESYSTEM_ERROR_DELETE_BASE_DIRECTORY'), JLog::WARNING, 'jerror');
return false;
}
$FTPOptions = JClientHelper::getCredentials('ftp');
try
{
// Check to make sure the path valid and clean
$path = JPath::clean($path);
}
catch (UnexpectedValueException $e)
{
throw $e;
}
// Is this really a folder?
if (!is_dir($path))
{
JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path), JLog::WARNING, 'jerror');
return false;
}
// Remove all the files in folder if they exist; disable all filtering
$files = self::files($path, '.', false, true, array(), array());
if (!empty($files))
{
jimport('joomla.filesystem.file');
if (JFile::delete($files) !== true)
{
// JFile::delete throws an error
return false;
}
}
// Remove sub-folders of folder; disable all filtering
$folders = self::folders($path, '.', false, true, array(), array());
foreach ($folders as $folder)
{
if (is_link($folder))
{
// Don't descend into linked directories, just delete the link.
jimport('joomla.filesystem.file');
if (JFile::delete($folder) !== true)
{
// JFile::delete throws an error
return false;
}
}
elseif (self::delete($folder) !== true)
{
// JFolder::delete throws an error
return false;
}
}
if ($FTPOptions['enabled'] == 1)
{
// Connect the FTP client
$ftp = JClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
}
// In case of restricted permissions we zap it one way or the other
// as long as the owner is either the webserver or the ftp.
if (@rmdir($path))
{
$ret = true;
}
elseif ($FTPOptions['enabled'] == 1)
{
// Translate path and delete
$path = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $path), '/');
// FTP connector throws an error
$ret = $ftp->delete($path);
}
else
{
JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path), JLog::WARNING, 'jerror');
$ret = false;
}
return $ret;
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JFolder::exists (   $path)
static

Wrapper for the standard file_exists function

Paramètres:
string$pathFolder name relative to installation dir
Renvoie:
boolean True if path is a folder
Depuis:
11.1

Définition à la ligne 479 du fichier folder.php.

Références JPath\clean().

{
return is_dir(JPath::clean($path));
}

+ Voici le graphe d'appel pour cette fonction :

static JFolder::files (   $path,
  $filter = '.',
  $recurse = false,
  $full = false,
  $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'),
  $excludefilter = array('^\..*', '.*~'),
  $naturalSort = false 
)
static

Utility function to read the files in a folder.

Paramètres:
string$pathThe path of the folder to read.
string$filterA filter for file names.
mixed$recurseTrue to recursively search into sub-folders, or an integer to specify the maximum depth.
boolean$fullTrue to return the full path to the file.
array$excludeArray with names of files which should not be shown in the result.
array$excludefilterArray of filter to exclude
boolean$naturalSortFalse for asort, true for natsort
Renvoie:
array Files in the given folder.
Depuis:
11.1

Définition à la ligne 499 du fichier folder.php.

Références JLog\add(), JPath\clean(), JText\sprintf(), et JLog\WARNING.

Référencé par JFormFieldModulelayout\getInput(), JFormFieldComponentlayout\getInput(), et JFormFieldFileList\getOptions().

{
// Check to make sure the path valid and clean
$path = JPath::clean($path);
// Is the path a folder?
if (!is_dir($path))
{
JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FILES', $path), JLog::WARNING, 'jerror');
return false;
}
// Compute the excludefilter string
if (count($excludefilter))
{
$excludefilter_string = '/(' . implode('|', $excludefilter) . ')/';
}
else
{
$excludefilter_string = '';
}
// Get the files
$arr = self::_items($path, $filter, $recurse, $full, $exclude, $excludefilter_string, true);
// Sort the files based on either natural or alpha method
if ($naturalSort)
{
natsort($arr);
}
else
{
asort($arr);
}
return array_values($arr);
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JFolder::folders (   $path,
  $filter = '.',
  $recurse = false,
  $full = false,
  $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'),
  $excludefilter = array('^\..*') 
)
static

Utility function to read the folders in a folder.

Paramètres:
string$pathThe path of the folder to read.
string$filterA filter for folder names.
mixed$recurseTrue to recursively search into sub-folders, or an integer to specify the maximum depth.
boolean$fullTrue to return the full path to the folders.
array$excludeArray with names of folders which should not be shown in the result.
array$excludefilterArray with regular expressions matching folders which should not be shown in the result.
Renvoie:
array Folders in the given folder.
Depuis:
11.1

Définition à la ligne 553 du fichier folder.php.

Références JLog\add(), JPath\clean(), JText\sprintf(), et JLog\WARNING.

Référencé par JTableMenu\check(), et JFormFieldFolderList\getOptions().

{
// Check to make sure the path valid and clean
$path = JPath::clean($path);
// Is the path a folder?
if (!is_dir($path))
{
JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FOLDER', $path), JLog::WARNING, 'jerror');
return false;
}
// Compute the excludefilter string
if (count($excludefilter))
{
$excludefilter_string = '/(' . implode('|', $excludefilter) . ')/';
}
else
{
$excludefilter_string = '';
}
// Get the folders
$arr = self::_items($path, $filter, $recurse, $full, $exclude, $excludefilter_string, false);
// Sort the folders
asort($arr);
return array_values($arr);
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JFolder::listFolderTree (   $path,
  $filter,
  $maxLevel = 3,
  $level = 0,
  $parent = 0 
)
static

Lists folder in format suitable for tree display.

Paramètres:
string$pathThe path of the folder to read.
string$filterA filter for folder names.
integer$maxLevelThe maximum number of levels to recursively read, defaults to three.
integer$levelThe current level, optional.
integer$parentUnique identifier of the parent folder, if any.
Renvoie:
array Folders in the given folder.
Depuis:
11.1

Définition à la ligne 673 du fichier folder.php.

Références $GLOBALS, et JPath\clean().

{
$dirs = array();
if ($level == 0)
{
$GLOBALS['_JFolder_folder_tree_index'] = 0;
}
if ($level < $maxLevel)
{
$folders = self::folders($path, $filter);
// First path, index foldernames
foreach ($folders as $name)
{
$id = ++$GLOBALS['_JFolder_folder_tree_index'];
$fullName = JPath::clean($path . '/' . $name);
$dirs[] = array('id' => $id, 'parent' => $parent, 'name' => $name, 'fullname' => $fullName,
'relname' => str_replace(JPATH_ROOT, '', $fullName));
$dirs2 = self::listFolderTree($fullName, $filter, $maxLevel, $level + 1, $id);
$dirs = array_merge($dirs, $dirs2);
}
}
return $dirs;
}

+ Voici le graphe d'appel pour cette fonction :

static JFolder::makeSafe (   $path)
static

Makes path name safe to use.

Paramètres:
string$pathThe full path to sanitise.
Renvoie:
string The sanitised string.
Depuis:
11.1

Définition à la ligne 710 du fichier folder.php.

{
$regex = array('#[^A-Za-z0-9_\\\/\(\)\[\]\{\}\#\$\^\+\.\'~`!@&=;,-]#');
return preg_replace($regex, '', $path);
}
static JFolder::move (   $src,
  $dest,
  $path = '',
  $use_streams = false 
)
static

Moves a folder.

Paramètres:
string$srcThe path to the source folder.
string$destThe path to the destination folder.
string$pathAn optional base path to prefix to the file names.
boolean$use_streamsOptionally use streams.
Renvoie:
mixed Error message on false or boolean true on success.
Depuis:
11.1

Définition à la ligne 406 du fichier folder.php.

Références JText\_(), JPath\clean(), JClientHelper\getCredentials(), JClientFtp\getInstance(), JFactory\getStream(), et JText\sprintf().

{
$FTPOptions = JClientHelper::getCredentials('ftp');
if ($path)
{
$src = JPath::clean($path . '/' . $src);
$dest = JPath::clean($path . '/' . $dest);
}
if (!self::exists($src))
{
return JText::_('JLIB_FILESYSTEM_ERROR_FIND_SOURCE_FOLDER');
}
if (self::exists($dest))
{
return JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_EXISTS');
}
if ($use_streams)
{
$stream = JFactory::getStream();
if (!$stream->move($src, $dest))
{
return JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_RENAME', $stream->getError());
}
$ret = true;
}
else
{
if ($FTPOptions['enabled'] == 1)
{
// Connect the FTP client
$ftp = JClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
// Translate path for the FTP account
$src = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $src), '/');
$dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
// Use FTP rename to simulate move
if (!$ftp->rename($src, $dest))
{
return JText::_('Rename failed');
}
$ret = true;
}
else
{
if (!@rename($src, $dest))
{
return JText::_('Rename failed');
}
$ret = true;
}
}
return $ret;
}

+ Voici le graphe d'appel pour cette fonction :


La documentation de cette classe a été générée à partir du fichier suivant :