mirror of
https://github.com/e107inc/e107.git
synced 2025-10-25 03:36:42 +02:00
Issue #5119 setFavicon() method added.
This commit is contained in:
@@ -187,6 +187,8 @@ class e_jsmanager
|
||||
|
||||
protected $_theme_css_processor = false;
|
||||
|
||||
private $_favicon = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -2246,6 +2248,16 @@ class e_jsmanager
|
||||
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
|
||||
@@ -2257,6 +2269,20 @@ class e_jsmanager
|
||||
|
||||
$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"))
|
||||
{
|
||||
$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";
|
||||
|
||||
@@ -378,7 +378,7 @@ class e_plugin
|
||||
|
||||
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."' />";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
/**
|
||||
* e107 website system
|
||||
*
|
||||
* 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 */
|
||||
protected $js;
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
public function testHeaderPlugin()
|
||||
{
|
||||
|
||||
@@ -39,14 +39,15 @@
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
*/
|
||||
public function testIsInAdmin()
|
||||
{
|
||||
$result = $this->js->isInAdmin();
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
public function testRequireCoreLib()
|
||||
{
|
||||
|
||||
@@ -166,7 +167,7 @@
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
*/
|
||||
public function testHeaderFile()
|
||||
{
|
||||
$load = array(
|
||||
@@ -189,7 +190,7 @@
|
||||
3 => array(
|
||||
'file' => 'https://somewhere/something.min.js',
|
||||
'zone' => 3,
|
||||
'opts' => array('defer'=>true)
|
||||
'opts' => array('defer' => true)
|
||||
),
|
||||
4 => array(
|
||||
'file' => 'https://somewhere/async.js',
|
||||
@@ -243,7 +244,7 @@
|
||||
3 => array(
|
||||
'file' => 'https://somewhere/something.min.js',
|
||||
'zone' => 3,
|
||||
'opts' => array('defer'=>true)
|
||||
'opts' => array('defer' => true)
|
||||
),
|
||||
|
||||
4 => array(
|
||||
@@ -275,7 +276,8 @@
|
||||
$this->assertStringContainsString('priority #4', $result);
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
public function testSetDependency()
|
||||
{
|
||||
|
||||
@@ -330,23 +332,23 @@
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
*/
|
||||
public function testAddLink()
|
||||
{
|
||||
$tests = array(
|
||||
0 => array(
|
||||
'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,
|
||||
),
|
||||
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',
|
||||
'cacheid' => false,
|
||||
),
|
||||
2 => array(
|
||||
'expected' => '<link rel="preload" href="'.e_WEB_ABS.'script.js?0" as="script" />',
|
||||
'input' => array('rel'=>'preload', 'href'=>'{e_WEB}script.js', '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'),
|
||||
'cacheid' => true,
|
||||
),
|
||||
|
||||
@@ -354,7 +356,7 @@
|
||||
|
||||
3 => array(
|
||||
'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,
|
||||
'static' => true,
|
||||
),
|
||||
@@ -376,14 +378,14 @@
|
||||
foreach($tests as $var)
|
||||
{
|
||||
$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);
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
/*
|
||||
public function testLibDisabled()
|
||||
{
|
||||
|
||||
@@ -403,7 +405,16 @@
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
function testRenderFavicon()
|
||||
{
|
||||
$file = e_PLUGIN."gsitemap/images/icon.png";
|
||||
$result = $this->js->renderFavicon($file);
|
||||
self::assertNotEmpty($result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user