Merge pull request #1733 from Tithugues/templateForLogo_master

Manage logo display in navigation panel, with a template.
This commit is contained in:
Atul Pratap Singh 2015-06-15 16:41:31 +05:30
commit ec43664014
2 changed files with 70 additions and 40 deletions

View File

@ -9,6 +9,9 @@ if (! defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/Template.class.php';
use PMA\Template;
/**
* This class renders the logo, links, server selection,
* which are then displayed at the top of the navigation panel
@ -73,11 +76,10 @@ class PMA_NavigationHeader
*/
private function _logo()
{
$retval = '<!-- LOGO START -->';
// display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
if (!$GLOBALS['cfg']['NavigationDisplayLogo']) {
$retval .= '<!-- LOGO END -->';
return $retval;
return Template::get('logo')
->render(array('displayLogo' => false));
}
$logo = 'phpMyAdmin';
@ -88,44 +90,57 @@ class PMA_NavigationHeader
$logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" '
. 'alt="' . $logo . '" id="imgpmalogo" />';
}
$retval .= '<div id="pmalogo">';
if ($GLOBALS['cfg']['NavigationLogoLink']) {
$logo_link = trim(
htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink'])
);
// prevent XSS, see PMASA-2013-9
// if link has protocol, allow only http and https
if (preg_match('/^[a-z]+:/i', $logo_link)
&& ! preg_match('/^https?:/i', $logo_link)
) {
$logo_link = 'index.php';
}
$retval .= ' <a href="' . $logo_link;
switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
case 'new':
$retval .= '" target="_blank"';
break;
case 'main':
// do not add our parameters for an external link
$navLogoLinkLower = /*overload*/mb_strtolower(
$GLOBALS['cfg']['NavigationLogoLink']
);
if (/*overload*/mb_substr($navLogoLinkLower, 0, 4) !== '://') {
$retval .= $GLOBALS['url_query'] . '"';
} else {
$retval .= '" target="_blank"';
}
}
$retval .= '>';
$retval .= $logo;
$retval .= '</a>';
} else {
$retval .= $logo;
}
$retval .= '</div>';
$retval .= '<!-- LOGO END -->';
return $retval;
if (!$GLOBALS['cfg']['NavigationLogoLink']) {
return Template::get('logo')
->render(
array(
'displayLogo' => true,
'useLogoLink' => false,
'logo' => $logo,
)
);
}
$useLogoLink = true;
$logoLink = null;
$linkAttriks = null;
$logoLink = trim(
htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink'])
);
// prevent XSS, see PMASA-2013-9
// if link has protocol, allow only http and https
if (preg_match('/^[a-z]+:/i', $logoLink)
&& ! preg_match('/^https?:/i', $logoLink)
) {
$logoLink = 'index.php';
}
switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
case 'new':
$linkAttriks = 'target="_blank"';
break;
case 'main':
// do not add our parameters for an external link
$navLogoLinkLower = /*overload*/mb_strtolower(
$GLOBALS['cfg']['NavigationLogoLink']
);
if (/*overload*/mb_substr($navLogoLinkLower, 0, 4) !== '://') {
$logoLink .= $GLOBALS['url_query'];
} else {
$linkAttriks = 'target="_blank"';
}
}
return Template::get('logo')
->render(
array(
'displayLogo' => true,
'useLogoLink' => $useLogoLink,
'logoLink' => $logoLink,
'linkAttribs' => $linkAttriks,
'logo' => $logo,
)
);
}
/**

15
templates/logo.phtml Normal file
View File

@ -0,0 +1,15 @@
<!-- LOGO START -->
<?php if (false === $displayLogo) : ?>
<!-- LOGO END -->
<?php return; ?>
<?php endif; ?>
<div id="pmalogo">
<?php if (true === $useLogoLink) : ?>
<a href="<?php echo $logoLink; ?>" <?php echo $linkAttribs; ?>>
<?php endif; ?>
<?php echo $logo; ?>
<?php if (true === $useLogoLink) : ?>
</a>
<?php endif; ?>
</div>
<!-- LOGO END -->