mirror of
https://github.com/e107inc/e107.git
synced 2025-01-29 18:47:54 +01:00
Merge pull request #2758 from lonalore/sitepath
Issue #2756 - Ability to override site_path. Done: "TODO create direc…
This commit is contained in:
commit
1764aa1cf7
@ -380,9 +380,17 @@ class e107
|
||||
|
||||
// mysql connection info
|
||||
$this->e107_config_mysql_info = $e107_config_mysql_info;
|
||||
|
||||
// unique folder for e_MEDIA - support for multiple websites from single-install. Must be set before setDirs()
|
||||
$this->site_path = $this->makeSiteHash($e107_config_mysql_info['mySQLdefaultdb'], $e107_config_mysql_info['mySQLprefix']);
|
||||
|
||||
// unique folder for e_MEDIA - support for multiple websites from single-install. Must be set before setDirs()
|
||||
if (!empty($e107_config_override['site_path']))
|
||||
{
|
||||
// $E107_CONFIG['site_path']
|
||||
$this->site_path = $e107_config_override['site_path'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->site_path = $this->makeSiteHash($e107_config_mysql_info['mySQLdefaultdb'], $e107_config_mysql_info['mySQLprefix']);
|
||||
}
|
||||
|
||||
// Set default folder (and override paths) if missing from e107_config.php
|
||||
$this->setDirs($e107_paths, $e107_config_override);
|
||||
@ -408,17 +416,20 @@ class e107
|
||||
mkdir(e_SYSTEM, 0755);
|
||||
}
|
||||
|
||||
// Prepare essential directories.
|
||||
$this->prepareDirs();
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Create a unique hash for each database configuration (multi-site support)
|
||||
function makeSiteHash($db,$prefix) // also used by install.
|
||||
/**
|
||||
* Create a unique hash for each database configuration (multi-site support).
|
||||
*/
|
||||
function makeSiteHash($db, $prefix) // also used by install.
|
||||
{
|
||||
return substr(md5($db.".".$prefix),0,10);
|
||||
|
||||
return substr(md5($db . "." . $prefix), 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -449,11 +460,15 @@ class e107
|
||||
$this->e107_dirs['MEDIA_BASE_DIRECTORY'] = $this->e107_dirs['MEDIA_DIRECTORY'];
|
||||
$this->e107_dirs['SYSTEM_BASE_DIRECTORY'] = $this->e107_dirs['SYSTEM_DIRECTORY'];
|
||||
|
||||
// FIXME - remove this condition because:
|
||||
// $this->site_path is appended to MEDIA_DIRECTORY in defaultDirs(), which is called above.
|
||||
if(strpos($this->e107_dirs['MEDIA_DIRECTORY'],$this->site_path) === false)
|
||||
{
|
||||
$this->e107_dirs['MEDIA_DIRECTORY'] .= $this->site_path."/"; // multisite support.
|
||||
}
|
||||
|
||||
|
||||
// FIXME - remove this condition because:
|
||||
// $this->site_path is appended to SYSTEM_DIRECTORY in defaultDirs(), which is called above.
|
||||
if(strpos($this->e107_dirs['SYSTEM_DIRECTORY'],$this->site_path) === false)
|
||||
{
|
||||
$this->e107_dirs['SYSTEM_DIRECTORY'] .= $this->site_path."/"; // multisite support.
|
||||
@ -468,6 +483,42 @@ class e107
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares essential directories.
|
||||
*/
|
||||
public function prepareDirs()
|
||||
{
|
||||
$file = e107::getFile();
|
||||
|
||||
// Essential directories which should be created and writable.
|
||||
$essential_directories = array(
|
||||
'MEDIA_DIRECTORY',
|
||||
'SYSTEM_DIRECTORY',
|
||||
'CACHE_DIRECTORY',
|
||||
|
||||
'CACHE_CONTENT_DIRECTORY',
|
||||
'CACHE_IMAGE_DIRECTORY',
|
||||
'CACHE_DB_DIRECTORY',
|
||||
'CACHE_URL_DIRECTORY',
|
||||
|
||||
'LOGS_DIRECTORY',
|
||||
'BACKUP_DIRECTORY',
|
||||
'TEMP_DIRECTORY',
|
||||
'IMPORT_DIRECTORY',
|
||||
);
|
||||
|
||||
// Create directories which don't exist.
|
||||
foreach($essential_directories as $directory)
|
||||
{
|
||||
if (!isset($this->e107_dirs[$directory])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = e_ROOT . $this->e107_dirs[$directory];
|
||||
$file->prepareDirectory($path, FILE_CREATE_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default e107 folders, root folders can be overridden by passed override array
|
||||
*
|
||||
@ -531,7 +582,6 @@ class e107
|
||||
$ret['BACKUP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'backup/';
|
||||
$ret['TEMP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'temp/';
|
||||
$ret['IMPORT_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'import/';
|
||||
//TODO create directories which don't exist.
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
@ -62,6 +62,16 @@ Note:
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Flag used by prepareDirectory() method -- create directory if not present.
|
||||
*/
|
||||
define('FILE_CREATE_DIRECTORY', 1);
|
||||
|
||||
/**
|
||||
* Flag used by prepareDirectory() method -- file permissions may be changed.
|
||||
*/
|
||||
define('FILE_MODIFY_PERMISSIONS', 2);
|
||||
|
||||
|
||||
class e_file
|
||||
{
|
||||
@ -1650,4 +1660,109 @@ class e_file
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the directory exists and is writable.
|
||||
*
|
||||
* @param string $directory
|
||||
* A string containing the name of a directory path. A trailing slash will be trimmed from a path.
|
||||
* @param int $options
|
||||
* A bitmask to indicate if the directory should be created if it does not exist (FILE_CREATE_DIRECTORY) or
|
||||
* made writable if it is read-only (FILE_MODIFY_PERMISSIONS).
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the directory exists (or was created) and is writable. FALSE otherwise.
|
||||
*/
|
||||
public function prepareDirectory($directory, $options = FILE_MODIFY_PERMISSIONS)
|
||||
{
|
||||
$directory = e107::getParser()->replaceConstants($directory);
|
||||
$directory = rtrim($directory, '/\\');
|
||||
|
||||
// Check if directory exists.
|
||||
if(!is_dir($directory))
|
||||
{
|
||||
// Let mkdir() recursively create directories and use the default directory permissions.
|
||||
if(($options & FILE_CREATE_DIRECTORY) && @$this->mkDir($directory, null, true))
|
||||
{
|
||||
return $this->_chMod($directory);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// The directory exists, so check to see if it is writable.
|
||||
$writable = is_writable($directory);
|
||||
|
||||
if(!$writable && ($options & FILE_MODIFY_PERMISSIONS))
|
||||
{
|
||||
return $this->_chMod($directory);
|
||||
}
|
||||
|
||||
return $writable;
|
||||
}
|
||||
|
||||
/**
|
||||
* (Non-Recursive) Sets the permissions on a file or directory.
|
||||
*
|
||||
* @param string $path
|
||||
* A string containing a file, or directory path.
|
||||
* @param int $mode
|
||||
* Integer value for the permissions. Consult PHP chmod() documentation for more information.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE for success, FALSE in the event of an error.
|
||||
*/
|
||||
public function _chMod($path, $mode = null)
|
||||
{
|
||||
if(!isset($mode))
|
||||
{
|
||||
if(is_dir($path))
|
||||
{
|
||||
$mode = 0775;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mode = 0664;
|
||||
}
|
||||
}
|
||||
|
||||
if(@chmod($path, $mode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a directory.
|
||||
*
|
||||
* @param string $path
|
||||
* A string containing a file path.
|
||||
* @param int $mode
|
||||
* Mode is used.
|
||||
* @param bool $recursive
|
||||
* Default to FALSE.
|
||||
* @param null $context
|
||||
* Refer to http://php.net/manual/ref.stream.php
|
||||
*
|
||||
* @return bool
|
||||
* Boolean TRUE on success, or FALSE on failure.
|
||||
*/
|
||||
public function mkDir($path, $mode = null, $recursive = false, $context = null)
|
||||
{
|
||||
if(!isset($mode))
|
||||
{
|
||||
$mode = 0775;
|
||||
}
|
||||
|
||||
if(!isset($context))
|
||||
{
|
||||
return mkdir($path, $mode, $recursive);
|
||||
}
|
||||
else
|
||||
{
|
||||
return mkdir($path, $mode, $recursive, $context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user