1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Added option for themes to load only the css or js portion of a library via theme.xml attribute. See bootstrap5/theme.xml for an example.

Empty comments in glyphs removed due to conflict with Fontawesome JS. Tests updated.
This commit is contained in:
Cameron
2021-10-11 12:33:59 -07:00
parent da219c31ae
commit 7755dd1743
14 changed files with 217 additions and 92 deletions

View File

@@ -2290,10 +2290,15 @@ class e107
* - In case of 'info': An associative array containing registered information for all libraries, the registered
* information for the library specified by $name, or FALSE if the library $name is not registered.
*/
public static function library($action = '', $library = null, $variant = null)
public static function library($action = '', $library = null, $variant = null, $types = null)
{
$libraryHandler = self::getLibrary();
if(empty($types))
{
$types = array('js', 'css');
}
switch($action)
{
case 'detect':
@@ -2317,7 +2322,7 @@ class e107
if(!empty($variant) && !empty($lib['variants'][$variant]['installed']))
{
// Load CDN version with the variant.
return $libraryHandler->load('cdn.' . $library, $variant);
return $libraryHandler->load('cdn.' . $library, $variant, $types);
}
// If CDN version is available, but no variant is specified,
@@ -2325,11 +2330,11 @@ class e107
if(empty($variant) && $debug && !empty($lib['variants']['dev']['installed']))
{
// Load CDN version with 'debug' variant.
return $libraryHandler->load('cdn.' . $library, 'dev');
return $libraryHandler->load('cdn.' . $library, 'dev', $types);
}
// Load CDN version without variant.
return $libraryHandler->load('cdn.' . $library, $variant);
return $libraryHandler->load('cdn.' . $library, $variant, $types);
}
}
@@ -2342,11 +2347,11 @@ class e107
if($lib && !empty($lib['variants']['dev']['installed']))
{
// Load library with 'debug' variant.
return $libraryHandler->load($library, 'dev');
return $libraryHandler->load($library, 'dev', $types);
}
}
return $libraryHandler->load($library, $variant);
return $libraryHandler->load($library, $variant, $types);
break;
case 'info':
@@ -2356,27 +2361,22 @@ class e107
case 'files':
$info = $libraryHandler->info($library);
$ret = [];
if(!empty($info['files']['css']))
foreach($types as $t)
{
foreach($info['files']['css'] as $path => $other)
if(!empty($info['files'][$t]))
{
$file = $info['library_path'].'/';
$file .= !empty($info['path']) ? $info['path'].'/' : '';
$file .= $path;
$ret['css'][] = $file;
}
}
if(!empty($info['files']['js']))
{
foreach($info['files']['js'] as $path => $other)
{
$file = $info['library_path'].'/';
$file .= !empty($info['path']) ? $info['path'].'/' : '';
$file .= $path;
$ret['js'][] = $file;
foreach($info['files'][$t] as $path => $other)
{
$file = $info['library_path'].'/';
$file .= !empty($info['path']) ? $info['path'].'/' : '';
$file .= $path;
$ret[$t][] = $file;
}
}
}
return $ret;
break;
@@ -2480,6 +2480,7 @@ class e107
{
$jshandler->requireCoreLib($data);
}
break;
case 'bootstrap': //TODO Eventually add own method and render for bootstrap.
@@ -2539,6 +2540,7 @@ class e107
{
$jshandler->headerFile($data, 5, $pre, $post);
}
break;
case 'footer':

View File

@@ -3888,7 +3888,7 @@ class e_parse
$idAtt = (!empty($parm['id'])) ? "id='" . $parm['id'] . "' " : '';
$style = (!empty($parm['style'])) ? "style='" . $parm['style'] . "' " : '';
$class = (!empty($parm['class'])) ? $parm['class'] . ' ' : '';
$placeholder = isset($parm['placeholder']) ? $parm['placeholder'] : '<!-- -->';
$placeholder = isset($parm['placeholder']) ? $parm['placeholder'] : '';
$title = (!empty($parm['title'])) ? " title='" . $this->toAttribute($parm['title']) . "' " : '';
$text = '<' . $tag . " {$idAtt}class='" . $class . $prefix . $id . $size . $spin . $rotate . $fixedW . "' " . $style . $title . '>' . $placeholder . '</' . $tag . '>';

View File

@@ -936,15 +936,25 @@ class core_library
'vendor_url' => 'https://fontawesome.com/',
'version_arguments' => array(
'file' => 'css/all.css',
'pattern' => '/(\d\.\d\.\d+)/',
'lines' => 10,
'pattern' => '/(\d\.\d*\.\d+)/',
'lines' => 2,
),
'files' => array(
'js' => array(
'js/all.min.js' => array(
'zone' => 2,
'type' => 'footer',
),
'js/v4-shims.min.js' => array(
'zone' => 2,
'type' => 'footer',
),
),
'css' => array(
'css/all.css' => array(
'css/all.min.css' => array(
'zone' => 2,
),
'css/v4-shims.css' => array(
'css/v4-shims.min.css' => array(
'zone' => 2,
),
),
@@ -962,9 +972,9 @@ class core_library
),
),*/
// Override library path to CDN.
'library_path' => 'https://use.fontawesome.com/releases',
'path' => 'v5.8.1',
'version' => '5.8.1',
'library_path' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0',
'path' => '',
'version' => '5.14.0',
);
// Font-Awesome (local).
@@ -977,6 +987,16 @@ class core_library
'lines' => 3,
),
'files' => array(
'js' => array(
'js/all.min.js' => array(
'zone' => 2,
'type' => 'footer',
),
'js/v4-shims.min.js' => array(
'zone' => 2,
'type' => 'footer',
),
),
'css' => array(
'css/all.min.css' => array(
'zone' => 2,
@@ -1445,7 +1465,7 @@ class e_library_manager
* - loaded: Either the amount of library files that have been loaded, or FALSE if the library could not be
* loaded. See MYPLUGIN_library::config() for more information.
*/
public function load($name, $variant = null)
public function load($name, $variant = null, $types = ['js', 'css'])
{
// Re-use the statically cached value to save memory.
@@ -1511,7 +1531,7 @@ class e_library_manager
$this->invoke('pre_load', $library);
// Load all the files associated with the library.
$library['loaded'] = $this->loadFiles($library);
$library['loaded'] = $this->loadFiles($library, $types);
// TODO:
// Invoke callbacks in the 'post_load' group.
@@ -1996,7 +2016,7 @@ class e_library_manager
* @return int
* The number of loaded files.
*/
private function loadFiles($library)
private function loadFiles($library, $types = array('js', 'css'))
{
$siteTheme = e107::getPref('sitetheme');
$adminTheme = e107::getPref('admintheme');
@@ -2048,7 +2068,7 @@ class e_library_manager
$count = 0;
// Load both the JavaScript and the CSS files.
foreach(array('js', 'css') as $type)
foreach($types as $type)
{
if(!empty($library['files'][$type]))
{

View File

@@ -235,6 +235,13 @@ class e_theme
{
foreach($data as $name => $var)
{
$files = !empty($var['files']) ? array($var['files']) : null;
if(strpos($name,'fontawesome')!==false && ($files === null))
{
$files = array('css');
}
if($name === 'bootstrap' && ((int) $var['version'] > 3)) // quick fix.
{
$name .= (string) $var['version'];
@@ -244,7 +251,8 @@ class e_theme
$name .= (string) $var['version'];
}
$ret[] = e107::library('files', $name);
$ret[] = e107::library('files', $name, null, $files);
}
}
elseif($type === 'css')
@@ -315,9 +323,19 @@ class e_theme
{
define('FONTAWESOME', (int) $library['version']);
}
if(empty($library['files'])) // force CSS only for backward compatibility.
{
$library['files'] = 'css';
}
}
e107::library('load', $name);
// support for 'files' attribute in theme.xml library tag. Specific which part of library to load. js || css or leave empty for both.
/* @see theme.xml <library name="fontawesome" version="5" scope="front" files=XXX /> */
$files = !empty($library['files']) ? array($library['files']) : ['js', 'css'];
e107::library('load', $name, null, $files);
e107::library('preload', $name);
$loaded[] = $name;
@@ -1097,13 +1115,17 @@ class e_theme
{
$vars['css'] = array();
foreach($vars['libraries']['library'] as $val)
foreach($vars['libraries']['library'] as $c=>$val)
{
$vars['library'][] = array(
foreach($val['@attributes'] as $k=>$v)
{
$vars['library'][$c][$k] = $v;
}
/* $vars['library'][] = array(
'name' => $val['@attributes']['name'],
'version' => varset($val['@attributes']['version']),
'scope' => varset($val['@attributes']['scope'], 'front'),
);
);*/
}
unset($vars['libraries']);

View File

@@ -735,25 +735,48 @@ class e107Test extends \Codeception\Test\Unit
$e107 = $this->e107;
$expected = array (
'js' =>
array (
0 => '{e_WEB}lib/font-awesome/5/js/all.min.js',
1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js',
),
'css' =>
array (
0 => '{e_WEB}lib/font-awesome/5/css/all.min.css',
1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css',
),
);
$result = $e107::library('files', 'fontawesome5');
$this->assertSame($expected, $result);
// -------------------
// Expecting only the JS portion of the library.
$expected = array (
'css' =>
'js' =>
array (
0 => '{e_WEB}lib/bootstrap/5/css/bootstrap.min.css',
0 => '{e_WEB}lib/font-awesome/5/js/all.min.js',
1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js',
),
);
$result = $e107::library('files', 'fontawesome5', null, ['js']);
$this->assertSame($expected, $result);
// -------------------
$expected = array (
'js' =>
array (
0 => '{e_WEB}lib/bootstrap/5/js/bootstrap.bundle.min.js',
),
'css' =>
array (
0 => '{e_WEB}lib/bootstrap/5/css/bootstrap.min.css',
),
);
$result = $e107::library('files', 'bootstrap5');

File diff suppressed because one or more lines are too long

View File

@@ -2035,24 +2035,24 @@ while(&#036;row = &#036;sql-&gt;fetch())
$this->tp->setFontAwesome(4);
$result = $this->tp->toGlyph('fa-envelope.glyph');
$expected = "<i class='fa fa-envelope' ><!-- --></i> ";
$expected = "<i class='fa fa-envelope' ></i> ";
$this->assertEquals($expected,$result);
$this->tp->setFontAwesome(5);
$result = $this->tp->toGlyph('fa-mailchimp');
$expected = "<i class='fab fa-mailchimp' ><!-- --></i> ";
$expected = "<i class='fab fa-mailchimp' ></i> ";
$this->assertEquals($expected, $result);
$this->tp->setFontAwesome(4);
$result = $this->tp->toGlyph('fab-mailchimp'); // spefific call
$expected = "<i class='fab fa-mailchimp' ><!-- --></i> ";
$expected = "<i class='fab fa-mailchimp' ></i> ";
$this->assertEquals($expected, $result);
$result = $this->tp->toGlyph('fas-camera'); // spefific call
$this->assertSame( "<i class='fas fa-camera' ><!-- --></i> ", $result);
$this->assertSame( "<i class='fas fa-camera' ></i> ", $result);
// test core, shims and old identifiers with FontAwesome 5 installed.
$this->tp->setFontAwesome(5);
@@ -2060,17 +2060,17 @@ while(&#036;row = &#036;sql-&gt;fetch())
$tests = array(
'e-database-16' => "<i class='S16 e-database-16'></i>",
'e-database-32' => "<i class='S32 e-database-32'></i>",
'fa-sun-o' => "<i class='far fa-sun' ><!-- --></i> ",
'fa-comments-o' => "<i class='far fa-comments' ><!-- --></i> ",
'fa-file-text-o' => "<i class='far fa-file-alt' ><!-- --></i> ",
'fa-bank' => "<i class='fa fa-university' ><!-- --></i> ",
'fa-warning' => "<i class='fa fa-exclamation-triangle' ><!-- --></i> ",
'glyphicon-star' => "<i class='fas fa-star' ><!-- --></i> ",
'icon-star' => "<i class='fas fa-star' ><!-- --></i> ",
'floppy-disk' => "<i class='glyphicon glyphicon-floppy-disk' ><!-- --></i> ",
'icon-user' => "<i class='fas fa-user' ><!-- --></i> ",
'user' => "<i class='fas fa-user' ><!-- --></i> ",
'flag' => "<i class='fas fa-flag' ><!-- --></i> ",
'fa-sun-o' => "<i class='far fa-sun' ></i> ",
'fa-comments-o' => "<i class='far fa-comments' ></i> ",
'fa-file-text-o' => "<i class='far fa-file-alt' ></i> ",
'fa-bank' => "<i class='fa fa-university' ></i> ",
'fa-warning' => "<i class='fa fa-exclamation-triangle' ></i> ",
'glyphicon-star' => "<i class='fas fa-star' ></i> ",
'icon-star' => "<i class='fas fa-star' ></i> ",
'floppy-disk' => "<i class='glyphicon glyphicon-floppy-disk' ></i> ",
'icon-user' => "<i class='fas fa-user' ></i> ",
'user' => "<i class='fas fa-user' ></i> ",
'flag' => "<i class='fas fa-flag' ></i> ",
'fa-' => null,
);
@@ -2088,17 +2088,17 @@ while(&#036;row = &#036;sql-&gt;fetch())
$tests = array(
'e-database-16' => "<i class='S16 e-database-16'></i>",
'e-database-32' => "<i class='S32 e-database-32'></i>",
'fa-sun-o' => "<i class='fa fa-sun-o' ><!-- --></i> ",
'fa-comments-o' => "<i class='fa fa-comments-o' ><!-- --></i> ",
'fa-file-text-o' => "<i class='fa fa-file-text-o' ><!-- --></i> ",
'fa-bank' => "<i class='fa fa-bank' ><!-- --></i> ",
'fa-warning' => "<i class='fa fa-warning' ><!-- --></i> ",
'glyphicon-star' => "<i class='fa fa-star' ><!-- --></i> ",
'icon-star' => "<i class='fa fa-star' ><!-- --></i> ",
'floppy-disk' => "<i class='glyphicon glyphicon-floppy-disk' ><!-- --></i> ",
'icon-user' => "<i class='fa fa-user' ><!-- --></i> ",
'user' => "<i class='glyphicon glyphicon-user' ><!-- --></i> ",
'flag' => "<i class='glyphicon glyphicon-flag' ><!-- --></i> ",
'fa-sun-o' => "<i class='fa fa-sun-o' ></i> ",
'fa-comments-o' => "<i class='fa fa-comments-o' ></i> ",
'fa-file-text-o' => "<i class='fa fa-file-text-o' ></i> ",
'fa-bank' => "<i class='fa fa-bank' ></i> ",
'fa-warning' => "<i class='fa fa-warning' ></i> ",
'glyphicon-star' => "<i class='fa fa-star' ></i> ",
'icon-star' => "<i class='fa fa-star' ></i> ",
'floppy-disk' => "<i class='glyphicon glyphicon-floppy-disk' ></i> ",
'icon-user' => "<i class='fa fa-user' ></i> ",
'user' => "<i class='glyphicon glyphicon-user' ></i> ",
'flag' => "<i class='glyphicon glyphicon-flag' ></i> ",
'fa-' => null,
);
@@ -2118,7 +2118,7 @@ while(&#036;row = &#036;sql-&gt;fetch())
{
$this->tp->setFontAwesome(5);
$result = $this->tp->toGlyph('fa-paypal.glyph');
$this->assertSame("<i class='fab fa-paypal' ><!-- --></i> ", $result);
$this->assertSame("<i class='fab fa-paypal' ></i> ", $result);
}
/*
public function testToBadge()
@@ -2448,7 +2448,7 @@ Your browser does not support the audio tag.
// -----
$result = $tp->makeClickable($email, 'email', array('sub' => 'fa-envelope.glyph'));
$this->assertStringContainsString("fa-envelope' ><!-- --></i></a>", $result);
$this->assertStringContainsString("fa-envelope' ></i></a>", $result);
// links standard.
$tests = array(

View File

@@ -513,7 +513,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
'=extended' => '<!-- bbcode-html-start --><p><strong>Extended Body</strong></p><!-- bbcode-html-end -->',
),
'newscommentlink' => array(
': class=me' => "<a title='0 Comments' class='e-tip me' href='".e107::url('news/view/item', ['news_id'=>1, 'news_sef'=>'welcome-to-e107-me-again-x'])."'><i class='fas fa-comment' ><!-- --></i></a>"
': class=me' => "<a title='0 Comments' class='e-tip me' href='".e107::url('news/view/item', ['news_id'=>1, 'news_sef'=>'welcome-to-e107-me-again-x'])."'><i class='fas fa-comment' ></i></a>"
),
@@ -1726,7 +1726,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
{
$tp = e107::getParser();
$result = $tp->parseTemplate('{GLYPH=fa-user}');
$this->assertSame("<i class='fas fa-user' ><!-- --></i>", $result);
$this->assertSame("<i class='fas fa-user' ></i>", $result);
}

View File

@@ -86,7 +86,7 @@ class e_themeTest extends \Codeception\Test\Unit
'bootstrap.editable' =>
array(
'name' => 'bootstrap.editable',
'version' => '',
// 'version' => '',
),
)
),
@@ -108,7 +108,7 @@ class e_themeTest extends \Codeception\Test\Unit
'bootstrap.editable' =>
array(
'name' => 'bootstrap.editable',
'version' => '',
// 'version' => '',
),
)
),
@@ -256,14 +256,15 @@ class e_themeTest extends \Codeception\Test\Unit
$expected = array(
0 =>
array(
'js' =>
array(
0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js',
),
'css' =>
array(
0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css',
),
'js' =>
array(
0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js',
),
),
1 =>
array(
@@ -272,6 +273,7 @@ class e_themeTest extends \Codeception\Test\Unit
0 => '{e_WEB}lib/font-awesome/5/css/all.min.css',
1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css',
),
),
);
@@ -283,14 +285,15 @@ class e_themeTest extends \Codeception\Test\Unit
$expected = array(
0 =>
array(
'js' =>
array(
0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js',
),
'css' =>
array(
0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css',
),
'js' =>
array(
0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js',
),
),
1 =>
array(
@@ -299,6 +302,7 @@ class e_themeTest extends \Codeception\Test\Unit
0 => '{e_WEB}lib/font-awesome/5/css/all.min.css',
1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css',
),
),
);
@@ -315,6 +319,42 @@ class e_themeTest extends \Codeception\Test\Unit
// $result = e107::getTheme('bootstrap5')->getThemeFiles('css', 'wysiwyg');
/** Expecting bootstrap 5 files fontawesome 5 (js only) */
$expected = array (
0 =>
array (
'js' =>
array (
0 => '{e_WEB}lib/bootstrap/5/js/bootstrap.bundle.min.js',
),
'css' =>
array (
0 => '{e_WEB}lib/bootstrap/5/css/bootstrap.min.css',
),
),
1 =>
array (
'js' =>
array (
0 => '{e_WEB}lib/font-awesome/5/js/all.min.js',
1 => '{e_WEB}lib/font-awesome/5/js/v4-shims.min.js',
),
),
2 =>
array (
'css' =>
array (
0 => '{e_WEB}lib/animate.css/animate.min.css',
),
),
);
$result = e107::getTheme('bootstrap5')->getThemeFiles('library', 'front');
$this->assertSame($expected, $result);
}
@@ -337,6 +377,11 @@ class e_themeTest extends \Codeception\Test\Unit
'scope' => 'front',
'expected' => ['bootstrap', 'fontawesome']
),
3 => array(
'theme' => 'bootstrap5',
'scope' => 'front',
'expected' => ['bootstrap5', 'fontawesome5', 'animate.css']
),
);
@@ -374,7 +419,7 @@ class e_themeTest extends \Codeception\Test\Unit
2 =>
array(
'name' => 'bootstrap.editable',
'version' => '',
// 'version' => '',
'scope' => 'admin',
),
)
@@ -398,7 +443,7 @@ class e_themeTest extends \Codeception\Test\Unit
2 =>
array(
'name' => 'bootstrap.editable',
'version' => '',
// 'version' => '',
'scope' => 'admin',
),
)
@@ -579,7 +624,7 @@ class e_themeTest extends \Codeception\Test\Unit
2 =>
array (
'name' => 'bootstrap.editable',
'version' => '',
// 'version' => '',
'scope' => 'admin',
),
)
@@ -598,10 +643,11 @@ class e_themeTest extends \Codeception\Test\Unit
'name' => 'fontawesome',
'version' => '5',
'scope' => 'front',
'files' => 'js',
),
2 => array (
'name' => 'animate.css',
'version' => '',
// 'version' => '',
'scope' => 'front',
)
),

View File

@@ -132,12 +132,9 @@
{
}
*/
public function testParse_theme_xml()
{
}
/*
public function testThemeUpload()
{

View File

@@ -15,7 +15,7 @@
</keywords>
<libraries>
<library name="bootstrap" version="5" scope="front"/>
<library name="fontawesome" version="5" scope="front"/>
<library name="fontawesome" version="5" scope="front" files="js" />
<library name="animate.css" scope="front" />
</libraries>
<stylesheets>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long