Skip to content

Commit

Permalink
Closes #5062 - common favicon method for frontend and backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Oct 17, 2023
1 parent 322eaa9 commit 64cf23a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
11 changes: 1 addition & 10 deletions e107_admin/header.php
Expand Up @@ -384,17 +384,8 @@ function loadJSAddons()
e107::getJs()->renderJs('header_inline', 4);

// ---------- Favicon ---------
echo e107::getJs()->renderFavicon();

$sitetheme = e107::getPref('sitetheme');
if(file_exists(e_THEME . $sitetheme . "/favicon.ico"))
{
echo "<link rel='icon' href='" . e_THEME_ABS . $sitetheme . "/favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='" . e_THEME_ABS . $sitetheme . "/favicon.ico' type='image/xicon' />\n";
}
elseif(file_exists(e_BASE . "favicon.ico"))
{
echo "<link rel='icon' href='" . SITEURL . "favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='" . SITEURL . "favicon.ico' type='image/xicon' />\n";
}
unset($sitetheme);
//
// G: Send Theme Headers
//
Expand Down
26 changes: 1 addition & 25 deletions e107_core/templates/header_default.php
Expand Up @@ -253,9 +253,8 @@ function renderTitle()
unset($ret);
}

// -------- Generate Apple Touch Icon ---------
echo renderFavicon();

echo $e_js->renderFavicon();


// Register Plugin specific CSS
Expand Down Expand Up @@ -500,30 +499,7 @@ function renderMeta($type)
return $ret;
}

function renderFavicon()
{
// ---------- Favicon ---------
if (file_exists(THEME."favicon.ico"))
{
return "<link rel='icon' href='".THEME_ABS."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".THEME_ABS."favicon.ico' type='image/xicon' />\n";
}
elseif(file_exists(e_MEDIA_ICON.'16x16_favicon.png'))
{
$iconSizes = [16 => 'icon',32 => 'icon',48 => 'icon',192 => 'icon',167 => 'apple-touch-icon',180 => 'apple-touch-icon'];
$text = '';
foreach($iconSizes as $size => $rel)
{
$sizes = $size.'x'.$size;
$text .= "<link rel='$rel' type='image/png' sizes='$sizes' href='".e_MEDIA_ICON_ABS.$sizes."_favicon.png'>\n";
}
return $text;
}
elseif (file_exists(e_BASE."favicon.ico"))
{
return "<link rel='icon' href='".SITEURL."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".SITEURL."favicon.ico' type='image/xicon' />\n";
}

}
// legay meta-tag checks.
/*
$isKeywords = e107::getUrl()->response()->getMetaKeywords();
Expand Down
49 changes: 43 additions & 6 deletions e107_handlers/js_manager.php
Expand Up @@ -1075,7 +1075,7 @@ protected function addJs($type, $file_path, $runtime_location = '', $opts = arra
$plugfile_path = $runtime_location.$this->_sep.'{e_PLUGIN}'.$pfile_path[0].'/'.trim($pfile_path[1], '/').$this->_sep.$pre.$this->_sep.$post;

// allow for URLs to be attributed to plugins. (loads after theme css in admin area header)
$file_path = ((strpos($pfile_path[1], 'http') !== 0 && strpos($pfile_path[1], '//') !== 0)) ? $plugfile_path : 'all'.$this->_sep.$pfile_path[1].$this->_sep.$pre.$this->_sep.$post;;
$file_path = ((strpos($pfile_path[1], 'http') !== 0 && strpos($pfile_path[1], '//') !== 0)) ? $plugfile_path : 'all'.$this->_sep.$pfile_path[1].$this->_sep.$pre.$this->_sep.$post;
if(!isset($this->_e_css['plugin'])) $this->_e_css['plugin'] = array();
$registry = &$this->_e_css['plugin'];
$runtime = true;
Expand Down Expand Up @@ -1383,9 +1383,7 @@ public function renderJs($mod, $zone = null, $external = true, $return = false)

if($return)
{
$ret = ob_get_clean();

return $ret;
return ob_get_clean();
}
}

Expand Down Expand Up @@ -1475,9 +1473,9 @@ public function renderFile($file_path_array, $external = false, $label = '', $mo
if(strpos($path, 'http') === 0 || strpos($path, '//') === 0) continue; // not allowed

$path = explode($this->_sep, $path, 3);
$pre = varset($path[1], '');
$pre = varset($path[1]);
if($pre) $pre .= "\n";
$post = varset($path[2], '');
$post = varset($path[2]);
if($post) $post = "\n".$post;
$path = $path[0];

Expand Down Expand Up @@ -2248,4 +2246,43 @@ public function setData($data)
return $this;
}


/**
* Render favicon HTML code - used in header.php and header_default.php
* @return string
*/
public function renderFavicon()
{
$sitetheme = $this->getCurrentTheme();

$ret = '';

if(file_exists(e_THEME . $sitetheme . "/favicon.ico"))
{
$ret = "<link rel='icon' href='" . e_THEME_ABS . $sitetheme . "/favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='" . e_THEME_ABS . $sitetheme . "/favicon.ico' type='image/xicon' />\n";
}
elseif(file_exists(e_MEDIA_ICON.'16x16_favicon.png'))
{
$iconSizes = [16 => 'icon',32 => 'icon',48 => 'icon',192 => 'icon',167 => 'apple-touch-icon',180 => 'apple-touch-icon'];

foreach($iconSizes as $size => $rel)
{
$sizes = $size.'x'.$size;
$ret .= "<link rel='$rel' type='image/png' sizes='$sizes' href='".e_MEDIA_ICON_ABS.$sizes."_favicon.png'>\n";
}

}
elseif (file_exists(e_BASE."favicon.ico"))
{
$ret = "<link rel='icon' href='".SITEURL."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".SITEURL."favicon.ico' type='image/xicon' />\n";
}


return $ret;

}




}

0 comments on commit 64cf23a

Please sign in to comment.