Skip to content

Commit

Permalink
Fix #16237 - Logo missing in upper left corner of navigation panel
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jul 1, 2020
1 parent 524b0b6 commit 9444234
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 21 deletions.
14 changes: 8 additions & 6 deletions libraries/classes/Navigation/Navigation.php
Expand Up @@ -268,12 +268,14 @@ private function getHiddenItems(string $database, ?string $table): array
*/
private function getLogoSource(): string
{
global $pmaThemeImage;

if (isset($pmaThemeImage) && @file_exists($pmaThemeImage . 'logo_left.png')) {
return $pmaThemeImage . 'logo_left.png';
} elseif (isset($pmaThemeImage) && @file_exists($pmaThemeImage . 'pma_logo2.png')) {
return $pmaThemeImage . 'pma_logo2.png';
/** @var \PhpMyAdmin\Theme|null $PMA_Theme */
global $PMA_Theme;
if ($PMA_Theme !== null) {
if (@file_exists($PMA_Theme->getFsPath() . 'img/logo_left.png')) {
return $PMA_Theme->getPath() . '/img/logo_left.png';
} elseif (@file_exists($PMA_Theme->getFsPath() . 'img/pma_logo2.png')) {
return $PMA_Theme->getPath() . '/img/pma_logo2.png';
}
}
return '';
}
Expand Down
44 changes: 36 additions & 8 deletions libraries/classes/Theme.php
Expand Up @@ -48,6 +48,11 @@ class Theme
*/
public $path = '';

/**
* @var string file system theme path
*/
private $fsPath = '';

/**
* @var string image path
* @access protected
Expand Down Expand Up @@ -106,7 +111,7 @@ public function __construct()
*/
public function loadInfo()
{
$infofile = $this->getPath() . '/theme.json';
$infofile = $this->getFsPath() . 'theme.json';
if (! @file_exists($infofile)) {
return false;
}
Expand Down Expand Up @@ -158,16 +163,18 @@ public function loadInfo()
* or false if theme is invalid
*
* @param string $folder path to theme
* @param string $fsPath file-system path to theme
*
* @return Theme|false
* @static
* @access public
*/
public static function load($folder)
public static function load(string $folder, string $fsPath)
{
$theme = new Theme();

$theme->setPath($folder);
$theme->setFsPath($fsPath);

if (! $theme->loadInfo()) {
return false;
Expand All @@ -187,14 +194,14 @@ public static function load($folder)
public function checkImgPath()
{
// try current theme first
if (is_dir($this->getPath() . '/img/')) {
if (is_dir($this->getFsPath() . 'img/')) {
$this->setImgPath($this->getPath() . '/img/');
return true;
}

// try fallback theme
$fallback = './themes/' . ThemeManager::FALLBACK_THEME . '/img/';
if (is_dir($fallback)) {
$fallback = ThemeManager::getThemesDir() . ThemeManager::FALLBACK_THEME . '/img/';
if (is_dir(ThemeManager::getThemesFsDir() . ThemeManager::FALLBACK_THEME . '/img/')) {
$this->setImgPath($fallback);
return true;
}
Expand All @@ -221,6 +228,16 @@ public function getPath()
return $this->path;
}

/**
* returns file system path to the theme
*
* @return string file system path to theme
*/
public function getFsPath(): string
{
return $this->fsPath;
}

/**
* set path to theme
*
Expand All @@ -234,6 +251,18 @@ public function setPath($path)
$this->path = trim($path);
}

/**
* set file system path to the theme
*
* @param string $path path to theme
*
* @return void
*/
public function setFsPath(string $path): void
{
$this->fsPath = trim($path);
}

/**
* sets version
*
Expand Down Expand Up @@ -371,9 +400,8 @@ public function getPrintPreview()
{
$url_params = ['set_theme' => $this->getId()];
$screen = null;
$path = $this->getPath() . '/screen.png';
if (@file_exists($path)) {
$screen = $path;
if (@file_exists($this->getFsPath() . 'screen.png')) {
$screen = $this->getPath() . '/screen.png';
}

return $this->template->render('theme_preview', [
Expand Down
21 changes: 20 additions & 1 deletion libraries/classes/ThemeManager.php
Expand Up @@ -302,7 +302,8 @@ public function loadThemes()
continue;
}
$new_theme = Theme::load(
$this->_themes_path . $PMA_Theme
$this->_themes_path . $PMA_Theme,
ROOT_PATH . $this->_themes_path . $PMA_Theme . '/'
);
if ($new_theme) {
$new_theme->setId($PMA_Theme);
Expand Down Expand Up @@ -414,4 +415,22 @@ public static function initializeTheme()
*/
$GLOBALS['pmaThemeImage'] = $GLOBALS['PMA_Theme']->getImgPath();
}

/**
* Return the themes directory with a trailing slash
* @return string
*/
public static function getThemesFsDir(): string
{
return ROOT_PATH . 'themes' . DIRECTORY_SEPARATOR;
}

/**
* Return the themes directory with a trailing slash as a relative public path
* @return string
*/
public static function getThemesDir(): string
{
return './themes' . DIRECTORY_SEPARATOR;
}
}
2 changes: 1 addition & 1 deletion test/bootstrap-dist.php
Expand Up @@ -99,6 +99,6 @@

// Standard environment for tests
$_SESSION[' PMA_token '] = 'token';
$GLOBALS['PMA_Theme'] = Theme::load(ROOT_PATH . 'themes/pmahomme');
$GLOBALS['PMA_Theme'] = Theme::load('./themes/pmahomme', ROOT_PATH . 'themes/pmahomme/');
$_SESSION['tmpval']['pftext'] = 'F';
$GLOBALS['lang'] = 'en';
10 changes: 5 additions & 5 deletions test/classes/ThemeTest.php
Expand Up @@ -91,7 +91,7 @@ public function testCheckImgPathIncorrect()
*/
public function testCheckImgPathFull()
{
$this->object->setPath(ROOT_PATH . 'test/classes/_data/gen_version_info');
$this->object->setFsPath(ROOT_PATH . 'test/classes/_data/gen_version_info/');
$this->assertTrue($this->object->loadInfo());
$this->assertEquals('Test Theme', $this->object->getName());
$this->assertEquals('5.0', $this->object->getVersion());
Expand All @@ -104,8 +104,8 @@ public function testCheckImgPathFull()
*/
public function testLoadInfo()
{
$this->object->setPath(ROOT_PATH . 'themes/original');
$infofile = $this->object->getPath() . '/theme.json';
$this->object->setFsPath(ROOT_PATH . 'themes/original/');
$infofile = $this->object->getFsPath() . 'theme.json';
$this->assertTrue($this->object->loadInfo());

$this->assertEquals(
Expand All @@ -126,7 +126,7 @@ public function testLoadInfo()
*/
public function testLoad()
{
$newTheme = Theme::load(ROOT_PATH . 'themes/original');
$newTheme = Theme::load('./themes/original', ROOT_PATH . 'themes/original');
$this->assertNotNull($newTheme);
}

Expand All @@ -137,7 +137,7 @@ public function testLoad()
*/
public function testLoadNotExisted()
{
$this->assertFalse(Theme::load('/path/to/nowhere'));
$this->assertFalse(Theme::load('/path/to/nowhere', '/path/to/nowhere'));
}

/**
Expand Down

0 comments on commit 9444234

Please sign in to comment.