Merge #16967 - Fix code using relative paths for themes and lib imports
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
commit
2232818da9
@ -260,7 +260,7 @@ final class ReplaceController extends AbstractController
|
||||
) {
|
||||
$filename = 'libraries/classes/Plugins/Transformations/'
|
||||
. $mime_map[$column_name]['input_transformation'];
|
||||
if (is_file($filename)) {
|
||||
if (is_file(ROOT_PATH . $filename)) {
|
||||
$classname = $this->transformations->getClassName($filename);
|
||||
if (class_exists($classname)) {
|
||||
/** @var IOTransformationsPlugin $transformation_plugin */
|
||||
|
||||
@ -2830,7 +2830,7 @@ class Results
|
||||
$file = $mime_map[$orgFullColName]['transformation'];
|
||||
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;
|
||||
|
||||
if (@file_exists($include_file)) {
|
||||
if (@file_exists(ROOT_PATH . $include_file)) {
|
||||
$class_name = $this->transformations->getClassName($include_file);
|
||||
if (class_exists($class_name)) {
|
||||
// todo add $plugin_manager
|
||||
@ -2863,7 +2863,7 @@ class Results
|
||||
&& (trim($row[$i]) != '')
|
||||
&& ! $_SESSION['tmpval']['hide_transformation']
|
||||
) {
|
||||
include_once $this->transformationInfo[$dbLower][$tblLower][$nameLower][0];
|
||||
include_once ROOT_PATH . $this->transformationInfo[$dbLower][$tblLower][$nameLower][0];
|
||||
$transformation_plugin = new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1](null);
|
||||
|
||||
$transform_options = $this->transformations->getOptions(
|
||||
|
||||
@ -2602,7 +2602,7 @@ class InsertEdit
|
||||
$type
|
||||
) {
|
||||
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;
|
||||
if (is_file($include_file)) {
|
||||
if (is_file(ROOT_PATH . $include_file)) {
|
||||
// $cfg['SaveCellsAtOnce'] = true; JS code sends an array
|
||||
$whereClause = is_array($_POST['where_clause']) ? $_POST['where_clause'][0] : $_POST['where_clause'];
|
||||
$_url_params = [
|
||||
@ -3425,7 +3425,7 @@ class InsertEdit
|
||||
if (! empty($column_mime['input_transformation'])) {
|
||||
$file = $column_mime['input_transformation'];
|
||||
$include_file = 'libraries/classes/Plugins/Transformations/' . $file;
|
||||
if (is_file($include_file)) {
|
||||
if (is_file(ROOT_PATH . $include_file)) {
|
||||
$class_name = $this->transformations->getClassName($include_file);
|
||||
if (class_exists($class_name)) {
|
||||
$transformation_plugin = new $class_name();
|
||||
|
||||
@ -48,6 +48,7 @@ use function strcmp;
|
||||
use function strtolower;
|
||||
use function ucfirst;
|
||||
use function usort;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Plugins class
|
||||
@ -77,8 +78,11 @@ class Plugins
|
||||
. mb_strtoupper($plugin_format[0])
|
||||
. mb_strtolower(mb_substr($plugin_format, 1));
|
||||
$file = $class_name . '.php';
|
||||
if (is_file($plugins_dir . $file)) {
|
||||
//include_once $plugins_dir . $file;
|
||||
|
||||
$fullFsPathPluginDir = ROOT_PATH . DIRECTORY_SEPARATOR . $plugins_dir;
|
||||
|
||||
if (is_file($fullFsPathPluginDir . $file)) {
|
||||
//include_once $fullFsPathPluginDir . $file;
|
||||
$fqnClass = 'PhpMyAdmin\\' . str_replace('/', '\\', mb_substr($plugins_dir, 18)) . $class_name;
|
||||
// check if class exists, could be caused by skip_import
|
||||
if (class_exists($fqnClass)) {
|
||||
@ -136,7 +140,9 @@ class Plugins
|
||||
|
||||
$GLOBALS['plugin_param'] = $plugin_param;
|
||||
|
||||
$handle = @opendir($plugins_dir);
|
||||
$fullFsPathPluginDir = ROOT_PATH . DIRECTORY_SEPARATOR . $plugins_dir;
|
||||
|
||||
$handle = @opendir($fullFsPathPluginDir);
|
||||
if (! $handle) {
|
||||
return [];
|
||||
}
|
||||
@ -154,7 +160,7 @@ class Plugins
|
||||
// (for example ._csv.php) so the following regexp
|
||||
// matches a file which does not start with a dot but ends
|
||||
// with ".php"
|
||||
if (! is_file($plugins_dir . $file)
|
||||
if (! is_file($fullFsPathPluginDir . $file)
|
||||
|| ! preg_match(
|
||||
'@^' . $class_type . '([^\.]+)\.php$@i',
|
||||
$file,
|
||||
@ -167,7 +173,7 @@ class Plugins
|
||||
/** @var bool $skip_import */
|
||||
$skip_import = false;
|
||||
|
||||
include_once $plugins_dir . $file;
|
||||
include_once $fullFsPathPluginDir . $file;
|
||||
|
||||
if ($skip_import) {
|
||||
continue;
|
||||
|
||||
@ -18,6 +18,7 @@ use function sprintf;
|
||||
use function trigger_error;
|
||||
use function trim;
|
||||
use function version_compare;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* handles theme
|
||||
@ -56,11 +57,17 @@ class Theme
|
||||
private $fsPath = '';
|
||||
|
||||
/**
|
||||
* @var string image path
|
||||
* @var string image path as an URL
|
||||
* @access protected
|
||||
*/
|
||||
public $imgPath = '';
|
||||
|
||||
/**
|
||||
* @var string image path on the file-system
|
||||
* @access protected
|
||||
*/
|
||||
public $imgPathFs = '';
|
||||
|
||||
/**
|
||||
* @var int last modification time for info file
|
||||
* @access protected
|
||||
@ -195,16 +202,21 @@ class Theme
|
||||
public function checkImgPath()
|
||||
{
|
||||
// try current theme first
|
||||
if (is_dir($this->getFsPath() . 'img/')) {
|
||||
if (is_dir($this->getFsPath() . 'img' . DIRECTORY_SEPARATOR)) {
|
||||
$this->setImgPath($this->getPath() . '/img/');
|
||||
$this->setImgPathFs($this->getFsPath() . 'img' . DIRECTORY_SEPARATOR);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// try fallback theme
|
||||
$fallback = ThemeManager::getThemesDir() . ThemeManager::FALLBACK_THEME . '/img/';
|
||||
if (is_dir(ThemeManager::getThemesFsDir() . ThemeManager::FALLBACK_THEME . '/img/')) {
|
||||
$this->setImgPath($fallback);
|
||||
$fallbackFsPathThemeDir = ThemeManager::getThemesFsDir() . ThemeManager::FALLBACK_THEME
|
||||
. DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR;
|
||||
if (is_dir($fallbackFsPathThemeDir)) {
|
||||
$fallbackUrl = ThemeManager::getThemesDir() . ThemeManager::FALLBACK_THEME
|
||||
. '/img/';
|
||||
$this->setImgPath($fallbackUrl);
|
||||
$this->setImgPathFs($fallbackFsPathThemeDir);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -363,7 +375,7 @@ class Theme
|
||||
/**
|
||||
* Sets path to images for the theme
|
||||
*
|
||||
* @param string $path path to images for this theme
|
||||
* @param string $path path to images for this theme as an URL path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
@ -374,6 +386,16 @@ class Theme
|
||||
$this->imgPath = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets path to images for the theme
|
||||
*
|
||||
* @param string $path file-system path to images for this theme
|
||||
*/
|
||||
public function setImgPathFs(string $path): void
|
||||
{
|
||||
$this->imgPathFs = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to image for the theme.
|
||||
* If filename is given, it possibly fallbacks to fallback
|
||||
@ -392,7 +414,7 @@ class Theme
|
||||
return $this->imgPath;
|
||||
}
|
||||
|
||||
if (is_readable($this->imgPath . $file)) {
|
||||
if (is_readable($this->imgPathFs . $file)) {
|
||||
return $this->imgPath . $file;
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ use function opendir;
|
||||
use function readdir;
|
||||
use function sprintf;
|
||||
use function trigger_error;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* phpMyAdmin theme manager
|
||||
@ -36,10 +35,13 @@ class ThemeManager
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @var string path to theme folder
|
||||
* @var string file-system path to the theme folder
|
||||
* @access protected
|
||||
*/
|
||||
private $themesPath = './themes/';
|
||||
private $themesPath;
|
||||
|
||||
/** @var string path to theme folder as an URL */
|
||||
private $themesPathUrl = './themes/';
|
||||
|
||||
/** @var array available themes */
|
||||
public $themes = [];
|
||||
@ -69,8 +71,9 @@ class ThemeManager
|
||||
$this->themes = [];
|
||||
$this->themeDefault = self::FALLBACK_THEME;
|
||||
$this->activeTheme = '';
|
||||
$this->themesPath = self::getThemesFsDir();
|
||||
|
||||
if (! $this->setThemesPath('./themes/')) {
|
||||
if (! $this->checkThemeFolder($this->themesPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -124,26 +127,6 @@ class ThemeManager
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets path to folder containing the themes
|
||||
*
|
||||
* @param string $path path to themes folder
|
||||
*
|
||||
* @return bool success
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setThemesPath($path): bool
|
||||
{
|
||||
if (! $this->checkThemeFolder($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->themesPath = trim($path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets if there are different themes per server
|
||||
*
|
||||
@ -295,7 +278,7 @@ class ThemeManager
|
||||
// Skip non dirs, . and ..
|
||||
if ($PMA_Theme === '.'
|
||||
|| $PMA_Theme === '..'
|
||||
|| ! @is_dir(ROOT_PATH . $this->themesPath . $PMA_Theme)
|
||||
|| ! @is_dir($this->themesPath . $PMA_Theme)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@ -303,8 +286,8 @@ class ThemeManager
|
||||
continue;
|
||||
}
|
||||
$new_theme = Theme::load(
|
||||
$this->themesPath . $PMA_Theme,
|
||||
ROOT_PATH . $this->themesPath . $PMA_Theme . '/'
|
||||
$this->themesPathUrl . $PMA_Theme,
|
||||
$this->themesPath . $PMA_Theme . DIRECTORY_SEPARATOR
|
||||
);
|
||||
if (! $new_theme) {
|
||||
continue;
|
||||
|
||||
@ -108,7 +108,6 @@ class Transformations
|
||||
* @return array array[mimetype], array[transformation]
|
||||
*
|
||||
* @access public
|
||||
* @staticvar array mimetypes
|
||||
*/
|
||||
public function getAvailableMimeTypes()
|
||||
{
|
||||
@ -126,7 +125,7 @@ class Transformations
|
||||
];
|
||||
|
||||
foreach ($sub_dirs as $sd => $prefix) {
|
||||
$handle = opendir('libraries/classes/Plugins/Transformations/' . $sd);
|
||||
$handle = opendir(ROOT_PATH . 'libraries/classes/Plugins/Transformations/' . $sd);
|
||||
|
||||
if (! $handle) {
|
||||
$stack[$prefix . 'transformation'] = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user