1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-29 10:50:25 +02:00

Issue #5119 setFavicon() method added.

This commit is contained in:
camer0n
2023-11-28 12:17:11 -08:00
parent 6d5aaf7dc8
commit ab64f0f7bf
3 changed files with 411 additions and 374 deletions

View File

@@ -187,6 +187,8 @@ class e_jsmanager
protected $_theme_css_processor = false; protected $_theme_css_processor = false;
private $_favicon = null;
/** /**
* Constructor * Constructor
* *
@@ -2246,6 +2248,16 @@ class e_jsmanager
return $this; return $this;
} }
/**
* Set a custom favicon (must be a .png file)
* @param string $path to a png file. eg. {e_PLUGIN}gallery/images/icon_32.png
* @return e_jsmanager
*/
public function setFavicon($path)
{
$this->_favicon = $path;
return $this;
}
/** /**
* Render favicon HTML code - used in header.php and header_default.php * Render favicon HTML code - used in header.php and header_default.php
@@ -2257,6 +2269,20 @@ class e_jsmanager
$ret = ''; $ret = '';
if(!empty($this->_favicon))
{
$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;
$url = e107::getParser()->thumbUrl($this->_favicon, ['w'=>$size, 'h'=>$size, 'crop'=>1]);
$ret .= "<link rel='$rel' type='image/png' sizes='$sizes' href='".$url."'>\n";
}
return $ret;
}
if(file_exists(e_THEME . $sitetheme . "/favicon.ico")) 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"; $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";

View File

@@ -378,7 +378,7 @@ class e_plugin
if($opt === 'path') if($opt === 'path')
{ {
return e107::getParser()->createConstants(e_PLUGIN_ABS.$this->_plugdir.'/'.$link[$key]); return e107::getParser()->createConstants(e_PLUGIN_ABS.$this->_plugdir.'/'.$link[$key], 2);
} }
return "<img src='".e_PLUGIN.$this->_plugdir.'/'.$link[$key] ."' alt=\"".$caption."\" class='icon S".$size."' />"; return "<img src='".e_PLUGIN.$this->_plugdir.'/'.$link[$key] ."' alt=\"".$caption."\" class='icon S".$size."' />";

View File

@@ -1,5 +1,5 @@
<?php <?php
/** /**
* e107 website system * e107 website system
* *
* Copyright (C) 2008-2019 e107 Inc (e107.org) * Copyright (C) 2008-2019 e107 Inc (e107.org)
@@ -9,8 +9,8 @@
*/ */
class e_jsmanagerTest extends \Codeception\Test\Unit class e_jsmanagerTest extends \Codeception\Test\Unit
{ {
/** @var e_jsmanager */ /** @var e_jsmanager */
protected $js; protected $js;
@@ -29,7 +29,7 @@
} }
/* /*
public function testHeaderPlugin() public function testHeaderPlugin()
{ {
@@ -39,14 +39,15 @@
{ {
} }
*/ */
public function testIsInAdmin() public function testIsInAdmin()
{ {
$result = $this->js->isInAdmin(); $result = $this->js->isInAdmin();
$this->assertFalse($result); $this->assertFalse($result);
} }
/*
/*
public function testRequireCoreLib() public function testRequireCoreLib()
{ {
@@ -166,7 +167,7 @@
{ {
} }
*/ */
public function testHeaderFile() public function testHeaderFile()
{ {
$load = array( $load = array(
@@ -189,7 +190,7 @@
3 => array( 3 => array(
'file' => 'https://somewhere/something.min.js', 'file' => 'https://somewhere/something.min.js',
'zone' => 3, 'zone' => 3,
'opts' => array('defer'=>true) 'opts' => array('defer' => true)
), ),
4 => array( 4 => array(
'file' => 'https://somewhere/async.js', 'file' => 'https://somewhere/async.js',
@@ -243,7 +244,7 @@
3 => array( 3 => array(
'file' => 'https://somewhere/something.min.js', 'file' => 'https://somewhere/something.min.js',
'zone' => 3, 'zone' => 3,
'opts' => array('defer'=>true) 'opts' => array('defer' => true)
), ),
4 => array( 4 => array(
@@ -275,7 +276,8 @@
$this->assertStringContainsString('priority #4', $result); $this->assertStringContainsString('priority #4', $result);
} }
/*
/*
public function testSetDependency() public function testSetDependency()
{ {
@@ -330,23 +332,23 @@
{ {
} }
*/ */
public function testAddLink() public function testAddLink()
{ {
$tests = array( $tests = array(
0 => array( 0 => array(
'expected' => '<link rel="preload" href="https://fonts.googleapis.com/css?family=Nunito&display=swap" as="style" onload="this.onload=null;" />', 'expected' => '<link rel="preload" href="https://fonts.googleapis.com/css?family=Nunito&display=swap" as="style" onload="this.onload=null;" />',
'input' => array('rel'=>'preload', 'href'=>'https://fonts.googleapis.com/css?family=Nunito&display=swap', 'as'=>'style', 'onload' => "this.onload=null;"), 'input' => array('rel' => 'preload', 'href' => 'https://fonts.googleapis.com/css?family=Nunito&display=swap', 'as' => 'style', 'onload' => "this.onload=null;"),
'cacheid' => false, 'cacheid' => false,
), ),
1 => array( 1 => array(
'expected' => '<link rel="preload" href="'.e_THEME_ABS.'bootstrap3/assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin />', // partial 'expected' => '<link rel="preload" href="' . e_THEME_ABS . 'bootstrap3/assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin />', // partial
'input' => 'rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin', 'input' => 'rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin',
'cacheid' => false, 'cacheid' => false,
), ),
2 => array( 2 => array(
'expected' => '<link rel="preload" href="'.e_WEB_ABS.'script.js?0" as="script" />', 'expected' => '<link rel="preload" href="' . e_WEB_ABS . 'script.js?0" as="script" />',
'input' => array('rel'=>'preload', 'href'=>'{e_WEB}script.js', 'as'=>'script'), 'input' => array('rel' => 'preload', 'href' => '{e_WEB}script.js', 'as' => 'script'),
'cacheid' => true, 'cacheid' => true,
), ),
@@ -354,7 +356,7 @@
3 => array( 3 => array(
'expected' => '<link rel="preload" href="https://static.mydomain.com/e107_web/script.js?0" as="script" />', 'expected' => '<link rel="preload" href="https://static.mydomain.com/e107_web/script.js?0" as="script" />',
'input' => array('rel'=>'preload', 'href'=>'{e_WEB}script.js', 'as'=>'script'), 'input' => array('rel' => 'preload', 'href' => '{e_WEB}script.js', 'as' => 'script'),
'cacheid' => true, 'cacheid' => true,
'static' => true, 'static' => true,
), ),
@@ -376,14 +378,14 @@
foreach($tests as $var) foreach($tests as $var)
{ {
$result = (strpos($actual, $var['expected']) !== false); $result = (strpos($actual, $var['expected']) !== false);
$this->assertTrue($result, $var['expected']." was not found in the rendered links. Render links result:".$actual."\n\n"); $this->assertTrue($result, $var['expected'] . " was not found in the rendered links. Render links result:" . $actual . "\n\n");
} }
$tp->setStaticUrl(null); $tp->setStaticUrl(null);
} }
/* /*
public function testLibDisabled() public function testLibDisabled()
{ {
@@ -403,7 +405,16 @@
{ {
} }
*/ */
function testRenderFavicon()
{
$file = e_PLUGIN."gsitemap/images/icon.png";
$result = $this->js->renderFavicon($file);
self::assertNotEmpty($result);
} }
}