1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

toGlyph() additional tests, Media-Manager includes bootstrap5 when detected and backward compatibility.

This commit is contained in:
Cameron 2021-01-31 13:09:53 -08:00
parent 2dedc8719f
commit 0b1a84068f
10 changed files with 362 additions and 172 deletions

View File

@ -2106,33 +2106,46 @@ class media_admin_ui extends e_admin_ui
'saveValue' => 'fas-'.$val.'.glyph',
'thumbUrl' => 'fas-'.$val,
'title' => 'FA5 fa-'.$val,
'slideCaption' => 'Font-Awesome 5 (free)',
'slideCaption' => 'Font-Awesome 5 (solid)',
'slideCategory' => 'font-awesome'
);
}
}
else
{
$far = e107::getMedia()->getGlyphs('far');
$fa4 = e107::getMedia()->getGlyphs('fa4');
foreach($fa4 as $val)
foreach($far as $val)
{
$items[] = array(
'previewHtml' => $md->previewTag('fa-'.$val,array('type'=>'glyph')),
'previewUrl' => 'fa fa-'.$val,
'saveValue' => 'fa-'.$val.'.glyph',
'thumbUrl' => 'fa-'.$val,
'title' => 'FA4 '.$val,
'slideCaption' => 'Font-Awesome 4',
'previewHtml' => $md->previewTag('far-'.$val, array('type'=>'glyph')),
'previewUrl' => 'far fa-'.$val,
'saveValue' => 'far-'.$val.'.glyph',
'thumbUrl' => 'far-'.$val,
'title' => 'FA5 far-'.$val,
'slideCaption' => 'Font-Awesome 5 (regular)',
'slideCategory' => 'font-awesome'
);
}
}
$fa4 = e107::getMedia()->getGlyphs('fa4');
foreach($fa4 as $val)
{
$items[] = array(
'previewHtml' => $md->previewTag('fa-'.$val,array('type'=>'glyph')),
'previewUrl' => 'fa fa-'.$val,
'saveValue' => 'fa-'.$val.'.glyph',
'thumbUrl' => 'fa-'.$val,
'title' => 'FA4 '.$val,
'slideCaption' => 'Font-Awesome 4',
'slideCategory' => 'font-awesome'
);
}
if($this->fontawesome === false || ($this->fontawesome < 4))
{

View File

@ -142,7 +142,7 @@ class signup_shortcodes extends e_shortcode
break;
}
if (defset('FONTAWESOME') && in_array($ic, e107::getMedia()->getGlyphs()))
if (defset('FONTAWESOME') && in_array($ic, e107::getMedia()->getGlyphs('fa4')))
$button = "<span title='" . $tp->lanVars($lan_plugin_social_xup, $p) . "'>" . $tp->toGlyph('fa-' . $ic, array('size' => $size, 'fw' => true)) . "</span>";
elseif (is_file(e107::getFolder('images') . "xup/{$ic}.png"))
$button = "<img class='e-tip' title='" . $tp->lanVars($lan_plugin_social_xup, $p) . "' src='" . e_IMAGE_ABS . "xup/{$ic}.png' alt='' />";

View File

@ -3588,12 +3588,14 @@ class e_parse
/**
* Parse xxxxx.glyph file to bootstrap glyph format.
* @param string $text
* @param string $text ie. fa-xxxx, fab-xxx, fas-xxxx
* @param array|string $options
* @param bool $options ['size'] 2x, 3x, 4x, or 5x
* @param bool $options ['fw'] Fixed-Width
* @param bool $options ['spin'] Spin
* @param int $options ['rotate'] Rotate in Degrees.
* @example $tp->toGlyph('fab-mailchimp');
* @example $tp->toGlyph('fas-camera');
* @example $tp->toGlyph('fa-spinner', 'spin=1');
* @example $tp->toGlyph('fa-spinner', array('spin'=>1));
* @example $tp->toGlyph('fa-shield', array('rotate'=>90, 'size'=>'2x'));
@ -3621,32 +3623,19 @@ class e_parse
$parm = array();
}
if(strpos($text, 'e-') === 0) // e107 admin icon.
$cat = '';
$name = '';
list($id) = explode('.glyph', $text, 2); // trim .glyph from the end.
if(strpos($id,'-') !== false)
{
$size = (substr($text, -3) === '-32') ? 'S32' : 'S16';
list($cat,$name) = explode('-',$id, 2);
if(substr($text, -3) === '-24')
if(empty($name)) // eg. missing something after 'fa-'
{
$size = 'S24';
return null;
}
return "<i class='" . $size . ' ' . $text . "'></i>";
}
// Get Glyph names.
// $bs3 = e107::getMedia()->getGlyphs('bs3','');
// $fa4 = e107::getMedia()->getGlyphs('fa4','');
list($id) = explode('.glyph', $text, 2);
// list($type, $tmp2) = explode("-",$text,2);
// return $cls;
// $removePrefix = array('glyphicon-','icon-','fa-');
// $id = str_replace($removePrefix, "", $cls);
$spin = null;
$rotate = null;
@ -3655,71 +3644,112 @@ class e_parse
$size = null;
$tag = 'i';
// FontAwesome General settings.
if(strpos($text, 'fa-') === 0 || strpos($text, 'fab-') === 0 || strpos($text, 'fas-') === 0)
switch($cat)
{
$prefix = 'fa ';
$size = (vartrue($parm['size'])) ? ' fa-' . $parm['size'] : '';
$tag = 'i';
$spin = !empty($parm['spin']) ? ' fa-spin' : '';
$rotate = !empty($parm['rotate']) ? ' fa-rotate-' . (int) $parm['rotate'] : '';
$fixedW = !empty($parm['fw']) ? ' fa-fw' : '';
// Core eg. e-database-32
case 'e':
$size = (substr($text, -3) === '-32') ? 'S32' : 'S16';
if(substr($text, -3) === '-24')
{
$size = 'S24';
}
return "<i class='" . $size . ' ' . $text . "'></i>";
break;
case "far":
case "fab":
case "fas":
$prefix = $cat.' ';
$id = str_replace($cat.'-', 'fa-', $id);
break;
case "fa":
default:
if($this->fontawesome === 5)
{
$fab = e107::getMedia()->getGlyphs('fab');
$fas = e107::getMedia()->getGlyphs('fas');
$far = e107::getMedia()->getGlyphs('far');
$shims = e107::getMedia()->getGlyphs('fa5-shims');
$fa4 = e107::getMedia()->getGlyphs('fa4');
list($tmp) = explode('-',$id);
$code = str_replace($tmp.'-','', $id);
if(isset($shims[$code]))
{
$prefix = '';
$id = $shims[$code];
}
elseif(in_array($code, $fab))
{
$prefix = 'fab ';
}
elseif(in_array($code, $fas))
{
$prefix = 'fas ';
$id = 'fa-'.$code;
}
elseif(in_array($code, $far))
{
$prefix = 'far ';
}
elseif(in_array($code, $fa4))
{
$prefix = 'fa ';
$id = 'fa-'.$code;
}
else
{
$prefix = ($this->bootstrap === 3) ? 'glyphicon glyphicon-' : 'fa fa-';
}
}
elseif($this->fontawesome === 4)
{
$fa4 = e107::getMedia()->getGlyphs('fa4');
if(isset($fa4[$name]))
{
$prefix = 'fa ';
$id = 'fa-'.$name;
}
}
elseif(strpos($text, 'glyphicon-') === 0) // Bootstrap 3
{
$prefix = 'glyphicon ';
$tag = 'span';
}
elseif(strpos($text, 'icon-') === 0) // Bootstrap 2
{
if($this->bootstrap !== 2) // bootrap 2 icon but running bootstrap3.
{
$prefix = 'glyphicon ';
$tag = 'span';
$id = str_replace('icon-', 'glyphicon-', $id);
}
else
{
$prefix = '';
$tag = 'i';
}
}
}
if(strpos($text, 'fab-') === 0)
{
$prefix = 'fab ';
$id = str_replace('fab-', 'fa-', $id);
}
elseif(strpos($text, 'fas-') === 0)
{
$prefix = 'fas ';
$id = str_replace('fas-', 'fa-', $id);
}
elseif($this->fontawesome === 5)
{
$fab = e107::getMedia()->getGlyphs('fab');
$fas = e107::getMedia()->getGlyphs('fas');
$code = substr($id, 3);
if(in_array($code, $fab))
{
$prefix = 'fab ';
}
elseif(in_array($code, $fas))
{
$prefix = 'fas ';
}
else
{
trigger_error($code. " not found.");
}
}
elseif(strpos($text, 'glyphicon-') === 0) // Bootstrap 3
{
$prefix = 'glyphicon ';
$tag = 'span';
}
elseif(strpos($text, 'icon-') === 0) // Bootstrap 2
{
if($this->bootstrap !== 2) // bootrap 2 icon but running bootstrap3.
{
$prefix = 'glyphicon ';
$tag = 'span';
$id = str_replace('icon-', 'glyphicon-', $id);
}
else
{
$prefix = '';
$tag = 'i';
}
}
elseif($custom = e107::getThemeGlyphs()) // Custom Glyphs
if($custom = e107::getThemeGlyphs()) // Custom Glyphs
{
foreach($custom as $glyphConfig)
{
@ -3730,7 +3760,13 @@ class e_parse
continue;
}
}
}
else // FontAwesome shouldn't hurt legacy icons.
{
$size = !empty($parm['size']) ? ' fa-' . $parm['size'] : '';
$spin = !empty($parm['spin']) ? ' fa-spin' : '';
$rotate = !empty($parm['rotate']) ? ' fa-rotate-' . (int) $parm['rotate'] : '';
$fixedW = !empty($parm['fw']) ? ' fa-fw' : '';
}

View File

@ -40,6 +40,14 @@
if(empty($this->thm) || !method_exists($this->thm, 'init'))
{
if(deftrue('FONTAWESOME'))
{
e107::getParser()->setFontAwesome(FONTAWESOME);
}
if(deftrue('BOOTSTRAP'))
{
e107::getParser()->setBootstrap(BOOTSTRAP);
}
return null;
}

File diff suppressed because one or more lines are too long

View File

@ -207,17 +207,91 @@
}
*/
private function compileFontAwesome5Meta()
{
$raw = file_get_contents(e_WEB."lib/font-awesome/5/metadata/icons.json");
$icons = e107::unserialize($raw);
$ret = [];
$keys = array('brands' => 'fab', 'solid' => 'fas', 'regular'=> 'far');
foreach($icons as $icon => $meta)
{
foreach($meta['free'] as $type)
{
$key = $keys[$type];
$ret[$key][] = $icon;
}
}
$ret['fa5-shims'] = $this->compileFontAwesome5Shims();
return $ret;
}
private function compileFontAwesome5Shims()
{
$raw = file_get_contents(e_WEB."lib/font-awesome/5/metadata/shims.json");
$icons = e107::unserialize($raw);
$ret = [];
foreach($icons as $var)
{
$i = $var[0];
$prefix = !empty($var[1]) ? $var[1] : 'fa';
$ico = !empty($var[2]) ? $var[2] : $i ;
$ret[$i] = $prefix." fa-".$ico;
}
return $ret;
}
public function testGetGlyphs()
{
// @todo uncomment to rebuild getGlyphs() arrays for fontawesome. (requires 'metadata' folder)
// $meta = $this->compileFontAwesome5Meta();
// var_export($meta);
// $far = $this->md->getGlyphs('far');
// $this->assertSame($meta['far'], $far);
// $fas = $this->md->getGlyphs('fas');
// $this->assertSame($meta['fas'], $fas);
// $fab = $this->md->getGlyphs('fab');
// $this->assertSame($meta['fab'], $fab);
// Check that FontAwesome 5 meta arrays are up-to-date.
// FontAwesome 5
$fab = $this->md->getGlyphs('fab');
$this->assertContains('500px', $fab);
$fas = $this->md->getGlyphs('fas');
$this->assertContains('address-book', $fas);
$far = $this->md->getGlyphs('far');
$this->assertContains('arrow-alt-circle-down', $far);
// Check FontAwesome 4
$fa4 = $this->md->getGlyphs('fas');
$this->assertContains('heart', $fa4);
// Check Bootstrap 3
$result = $this->md->getGlyphs('bs3');
$this->assertEquals('adjust', $result[0]);
$this->assertEquals('zoom-out', $result[198]);
$this->assertNotEmpty($result['adjust']);
$this->assertNotEmpty($result['zoom-out']);
$result = $this->md->getGlyphs('fab');
$this->assertTrue(in_array('xbox', $result));
// Check FontAweomse 5 Shims
$fa5Shims = $this->md->getGlyphs('fa5-shims');
$this->assertArrayHasKey('glass', $fa5Shims);
$result = $this->md->getGlyphs('fas');
$this->assertTrue(in_array('check-circle', $result));
$prefixTest = $this->md->getGlyphs('fab', 'myprefix-');
$this->assertContains('myprefix-500px', $prefixTest);
}
/*

View File

@ -1972,6 +1972,62 @@ while(&#036;row = &#036;sql-&gt;fetch())
$result = $this->tp->toGlyph('fas-camera'); // spefific call
$this->assertSame( "<i class='fas fa-camera' ><!-- --></i> ", $result);
// test core, shims and old identifiers with FontAwesome 5 installed.
$this->tp->setFontAwesome(5);
$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-' => null,
);
foreach($tests as $icon => $expected)
{
$result = $this->tp->toGlyph($icon);
$this->assertSame($expected, $result);
}
// test core, shims and old identifiers with FontAwesome 4 installed.
$this->tp->setFontAwesome(4);
$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-' => null,
);
foreach($tests as $icon => $expected)
{
$result = $this->tp->toGlyph($icon);
$this->assertSame($expected, $result, 'Input was: '.$icon);
}
}
@ -2330,7 +2386,7 @@ Your browser does not support the audio tag.
// -----
$result = $tp->makeClickable($email, 'email', array('sub' => 'fa-envelope.glyph'));
$this->assertStringContainsString("<i class='fa fa-envelope' ><!-- --></i></a>", $result);
$this->assertStringContainsString("fa-envelope' ><!-- --></i></a>", $result);
// links standard.
$tests = array(

View File

@ -458,7 +458,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='fa 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>"
),

View File

@ -1891,7 +1891,7 @@ tr.highlight-even, .table-striped > tbody > tr.highlight-even { background-colo
border-bottom-right-radius: 10px; }
.adminlist img.icon { max-width: 64px }
body#admin-image-main-dialog { margin-top: 0 }
@media (min-width: 1101px ){
.navbar-fixed-top { height: 51px; }

View File

@ -255,10 +255,10 @@ class theme_shortcodes extends e_shortcode
<li class="dropdown dropdown-avatar"><a href="#" class="dropdown-toggle" data-toggle="dropdown">{USER_AVATAR: w=30&h=30&crop=1&shape=circle} '. $userNameLabel.' <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="{LM_USERSETTINGS_HREF}"><span class="glyphicon glyphicon-cog"></span> '.LAN_SETTINGS.'</a>
<a href="{LM_USERSETTINGS_HREF}">{GLYPH=fa-cog}'.LAN_SETTINGS.'</a>
</li>
<li>
<a class="dropdown-toggle no-block" role="button" href="{LM_PROFILE_HREF}"><span class="glyphicon glyphicon-user"></span> '.LAN_LOGINMENU_13.'</a>
<a class="dropdown-toggle no-block" role="button" href="{LM_PROFILE_HREF}">{GLYPH=fa-user}'.LAN_LOGINMENU_13.'</a>
</li>
<li class="divider"></li>';
@ -268,7 +268,7 @@ class theme_shortcodes extends e_shortcode
}
$text .= '
<li><a href="'.e_HTTP.'index.php?logout"><span class="glyphicon glyphicon-off"></span> '.LAN_LOGOUT.'</a></li>
<li><a href="'.e_HTTP.'index.php?logout">{GLYPH=fa-off}'.LAN_LOGOUT.'</a></li>
</ul>
</li>
</ul>