Skip to content

Commit

Permalink
Fixes #5156 Static URL issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Dec 18, 2023
1 parent 59f05d7 commit ab5f0fb
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 16 deletions.
16 changes: 10 additions & 6 deletions e107_handlers/e_parse_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class e_parse
private $bootstrap;
private $fontawesome;

private $modRewriteMedia;

private $removedList = array();
private $nodesToDelete = array();
private $nodesToConvert = array();
Expand Down Expand Up @@ -2487,7 +2489,6 @@ public function staticUrl($path = null, $opts = array())
*/
public function setStaticUrl($url)
{

$this->staticUrl = $url;
}

Expand Down Expand Up @@ -2636,10 +2637,10 @@ public function thumbUrl($url = null, $options = array(), $raw = false, $full =
}


if (e_MOD_REWRITE_MEDIA == true && empty($options['nosef']))// Experimental SEF URL support.
if ($this->modRewriteMedia && empty($options['nosef']))// SEF URL support.
{
$options['full'] = $full;
$options['ext'] = substr($url, -3);
$options['ext'] = pathinfo($url, PATHINFO_EXTENSION);
$options['thurl'] = $thurl;
// $options['x'] = $this->thumbEncode();

Expand Down Expand Up @@ -3606,9 +3607,10 @@ public function init()
if (defined('BOOTSTRAP'))
{
$this->bootstrap = (int) BOOTSTRAP;

}

$this->modRewriteMedia = deftrue('e_MOD_REWRITE_MEDIA');

if (defined('e_HTTP_STATIC'))
{
$this->staticUrl = e_HTTP_STATIC;
Expand Down Expand Up @@ -3781,7 +3783,6 @@ public function setScriptTags($array = array())
*/
public function setFontAwesome($version)
{

$this->fontawesome = (int) $version;
}

Expand All @@ -3790,10 +3791,13 @@ public function setFontAwesome($version)
*/
public function setBootstrap($version)
{

$this->bootstrap = (int) $version;
}

public function setmodRewriteMedia($bool)
{
$this->modRewriteMedia = (bool) $bool;
}

/**
* Add leading zeros to a number. eg. 3 might become 000003
Expand Down
11 changes: 6 additions & 5 deletions e107_handlers/js_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ public function setFavicon($path)
public function renderFavicon()
{
$sitetheme = $this->getCurrentTheme();

$tp = e107::getParser();
$ret = '';

if(!empty($this->_favicon))
Expand All @@ -2276,7 +2276,7 @@ public function renderFavicon()
foreach($iconSizes as $size => $rel)
{
$sizes = $size.'x'.$size;
$url = e107::getParser()->thumbUrl($this->_favicon, ['w'=>$size, 'h'=>$size, 'crop'=>1]);
$url = $tp->thumbUrl($this->_favicon, ['w'=>$size, 'h'=>$size, 'crop'=>1]);
$ret .= "<link rel='$rel' type='image/png' sizes='$sizes' href='".$url."'>\n";
}

Expand All @@ -2285,7 +2285,7 @@ public function renderFavicon()

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='" . $tp->staticUrl(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'))
{
Expand All @@ -2294,13 +2294,14 @@ public function renderFavicon()
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";
$href = $tp->staticUrl(e_MEDIA_ICON_ABS.$sizes."_favicon.png");
$ret .= "<link rel='$rel' type='image/png' sizes='$sizes' href='$href'>\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";
$ret = "<link rel='icon' href='".$tp->staticUrl(SITEURL."favicon.ico")."' type='image/x-icon' />\n<link rel='shortcut icon' href='".$tp->staticUrl(SITEURL."favicon.ico")."' type='image/xicon' />\n";
}


Expand Down
10 changes: 5 additions & 5 deletions e107_plugins/siteinfo/e_shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function sc_logo($parm = array())
// Paths to image file, link are relative to site base
$tp = e107::getParser();

$logopref = e107::getConfig('core')->get('sitelogo');
$logopref = e107::getConfig()->get('sitelogo');
$logop = $tp->replaceConstants($logopref);

if(isset($parm['login'])) // Login Page. BC fix.
Expand Down Expand Up @@ -138,9 +138,9 @@ function sc_logo($parm = array())
else
{

if(vartrue($logopref) && is_readable($logop))
if(!empty($logopref) && is_readable($logop))
{
$logo = $tp->replaceConstants($logopref,'abs');
$logo = $logopref;
$path = $tp->replaceConstants($logopref);
}
elseif (isset($file) && $file && is_readable($file))
Expand Down Expand Up @@ -169,8 +169,8 @@ function sc_logo($parm = array())

if((isset($parm['w']) || isset($parm['h'])))
{
//
$dimensions[0] = isset($parm['w']) ? $parm['w'] : 0;

$dimensions[0] = $parm['w'] ?? 0;
$dimensions[1] = !empty($parm['h']) ? $parm['h'] : 0;

if(empty($parm['noresize']) && !empty($logopref)) // resize by default - avoiding large files.
Expand Down
109 changes: 109 additions & 0 deletions e107_tests/tests/unit/plugins/siteinfo/siteinfo_shortcodesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php


/**
* @group plugins
*/
class siteinfo_shortcodesTest extends \Codeception\Test\Unit
{

/** @var siteinfo_shortcodes */
protected $sc;

protected function _before()
{

try
{
require_once(e_PLUGIN."siteinfo/e_shortcode.php");
$this->sc = $this->make('siteinfo_shortcodes');
}
catch(Exception $e)
{
self::fail($e->getMessage());
}

}

public function testSc_sitename()
{
$result = $this->sc->sc_sitename();
self::assertSame('e107', $result);

}

/* public function testSc_siteurl()
{
}
public function testSc_sitedisclaimer()
{
}
public function testSc_sitedescription()
{
}
public function testSc_sitetag()
{
}
public function testSc_sitebutton()
{
}
public function testSc_sitelogo()
{
}*/

public function testSc_logo()
{
$tp = e107::getParser();

$result = $this->sc->sc_logo(['w'=>200, 'h'=>100]);
$expected = '<img class="logo img-responsive img-fluid" src="/thumb.php?src=e_IMAGE%2FlogoHD.png&amp;w=200&amp;h=100" alt="e107" srcset="/thumb.php?src=e_IMAGE%2FlogoHD.png&amp;w=400&amp;h=200 2x" width="200" height="100" />';
self::assertSame($expected, $result);

$tp->setStaticUrl('https://my.cdn.com/');
$result = $this->sc->sc_logo(['w'=>240, 'h'=>120]);
$expected = '<img class="logo img-responsive img-fluid" src="https://my.cdn.com/thumb.php?src=e_IMAGE%2FlogoHD.png&amp;w=240&amp;h=120" alt="e107" srcset="https://my.cdn.com/thumb.php?src=e_IMAGE%2FlogoHD.png&amp;w=480&amp;h=240 2x" width="240" height="120" />';
self::assertSame($expected, $result);

file_put_contents(e_MEDIA_IMAGE.'logo.png','dummy image content');
e107::getConfig()->set('sitelogo', '{e_MEDIA_IMAGE}logo.png');
$tp->setStaticUrl('https://my.cdn.com/');
$tp->thumbWidth(100);
$tp->thumbHeight(0);
$tp->thumbCrop(0);
$result = $this->sc->sc_logo();
$expected = '<img class="logo img-responsive img-fluid" src="https://my.cdn.com/thumb.php?src=e_MEDIA_IMAGE%2Flogo.png&amp;w=100&amp;h=0" alt="e107" srcset="https://my.cdn.com/thumb.php?src=e_MEDIA_IMAGE%2Flogo.png&amp;w=200&amp;h=0 2x" width="100" />';
self::assertSame($expected, $result);


$tp->setmodRewriteMedia(true);
$result = $this->sc->sc_logo(['w'=>240, 'h'=>120]);
$expected = '<img class="logo img-responsive img-fluid" src="https://my.cdn.com/media/img/240x120/logo.png" alt="e107" srcset="https://my.cdn.com/media/img/480x240/logo.png 2x" width="240" height="120" />';

self::assertSame($expected, $result);

// Reset for other tests.
$tp->setmodRewriteMedia(false);
$tp->setStaticUrl(null);

}

/* public function testSc_theme_disclaimer()
{
$result = $this->sc->sc_theme_disclaimer();
}*/



}

0 comments on commit ab5f0fb

Please sign in to comment.