Skip to content

Commit

Permalink
Closes #4969, Fixes #5008, Fixes #4498 - FontAwesome6 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Nov 17, 2023
1 parent bf3ba04 commit 34ba780
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 62 deletions.
16 changes: 8 additions & 8 deletions e107_admin/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2211,10 +2211,10 @@ private function glyphTab($cat='', $parm=array())
$md = e107::getMedia();


if($this->fontawesome === 5)
if($this->fontawesome > 4) // Fontawesome 5 and 6
{
// e107::getParser()->setFontAwesome(5);
$fab = e107::getMedia()->getGlyphs('fab');

$fab = e107::getMedia()->getGlyphs('fa'.$this->fontawesome.'-fab');

foreach($fab as $val)
{
Expand All @@ -2224,13 +2224,13 @@ private function glyphTab($cat='', $parm=array())
'saveValue' => 'fab-'.$val.'.glyph',
'thumbUrl' => 'fab-'.$val,
'title' => 'FA5 fa-'.$val,
'slideCaption' => 'Font-Awesome 5 (brand)',
'slideCaption' => "Font-Awesome $this->fontawesome (brand)",
'slideCategory' => 'font-awesome'
);

}

$fas = e107::getMedia()->getGlyphs('fas');
$fas = e107::getMedia()->getGlyphs('fa'.$this->fontawesome.'-fas');

foreach($fas as $val)
{
Expand All @@ -2240,13 +2240,13 @@ private function glyphTab($cat='', $parm=array())
'saveValue' => 'fas-'.$val.'.glyph',
'thumbUrl' => 'fas-'.$val,
'title' => 'FA5 fa-'.$val,
'slideCaption' => 'Font-Awesome 5 (solid)',
'slideCaption' => "Font-Awesome $this->fontawesome (solid)",
'slideCategory' => 'font-awesome'
);

}

$far = e107::getMedia()->getGlyphs('far');
$far = e107::getMedia()->getGlyphs('fa'.$this->fontawesome.'-far');

foreach($far as $val)
{
Expand All @@ -2256,7 +2256,7 @@ private function glyphTab($cat='', $parm=array())
'saveValue' => 'far-'.$val.'.glyph',
'thumbUrl' => 'far-'.$val,
'title' => 'FA5 far-'.$val,
'slideCaption' => 'Font-Awesome 5 (regular)',
'slideCaption' => "Font-Awesome $this->fontawesome (regular)",
'slideCategory' => 'font-awesome'
);

Expand Down
13 changes: 8 additions & 5 deletions e107_handlers/e_parse_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3973,6 +3973,7 @@ public function toGlyph($text, $options = ' ')
$cat = '';
$name = '';
list($id) = explode('.glyph', $text, 2); // trim .glyph from the end.
$origID = $id;
if (strpos($id, '-') !== false)
{
list($cat, $name) = explode('-', $id, 2);
Expand Down Expand Up @@ -4031,10 +4032,11 @@ public function toGlyph($text, $options = ' ')
default:
if ($this->fontawesome === 5 || $this->fontawesome === 6)
{
$fab = e107::getMedia()->getGlyphs('fab');
$fas = e107::getMedia()->getGlyphs('fas');
$far = e107::getMedia()->getGlyphs('far');
$shims = e107::getMedia()->getGlyphs('fa5-shims');
$vr = 'fa'.$this->fontawesome.'-';
$fab = e107::getMedia()->getGlyphs($vr.'fab');
$fas = e107::getMedia()->getGlyphs($vr.'fas');
$far = e107::getMedia()->getGlyphs($vr.'far');
$shims = e107::getMedia()->getGlyphs($vr.'shims');
$fa4 = e107::getMedia()->getGlyphs('fa4');

list($tmp) = explode('-', $id);
Expand All @@ -4051,7 +4053,7 @@ public function toGlyph($text, $options = ' ')
}
elseif (isset($fas[$code]))
{
$prefix = 'fas ';
$prefix = 'fas '; // 'fa-solid' for fa6?
$id = 'fa-' . $code;
}
elseif (in_array($code, $far))
Expand Down Expand Up @@ -4125,6 +4127,7 @@ public function toGlyph($text, $options = ' ')
{
$prefix = $glyphConfig['class'] . ' ';
$tag = $glyphConfig['tag'];
$id = $origID;
continue;
}
}
Expand Down
12 changes: 7 additions & 5 deletions e107_handlers/library_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public function config()
// Override library path.
'library_path' => '{e_WEB}lib/jquery-once',
'version' => '2.2.3',
'path' => '',
);

// jQuery UI (CDN).
Expand Down Expand Up @@ -713,6 +714,7 @@ public function config()
// Override library path.
'library_path' => '{e_WEB}js/bootstrap3-editable',
'version' => '1.5.1',
'path' => '',
);

// Bootstrap Switch (CDN).
Expand Down Expand Up @@ -934,7 +936,7 @@ public function config()
'version' => '5.15.4',
);

// Font-Awesome (local).
// Font-Awesome 5 (local).
$libraries['fontawesome5'] = array(
'name' => 'Font-Awesome 5 (local)',
'vendor_url' => 'https://fontawesome.com/',
Expand Down Expand Up @@ -1038,7 +1040,7 @@ public function config()
'variants' => array(),
'library_path' => '{e_WEB}lib/font-awesome',
'path' => '6',
'version' => '6.2.1',
'version' => '6.4.2',

);

Expand Down Expand Up @@ -1076,9 +1078,9 @@ public function config()
),
'variants' => array(),
// Override library path to CDN.
'library_path' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1',
'library_path' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2',
'path' => '',
'version' => '6.2.1',
'version' => '6.4.2',
);


Expand Down Expand Up @@ -1655,7 +1657,7 @@ public function getProperty($library, $property)
public function getPath($library, $mode=null)
{
$path = self::getProperty($library, 'library_path').'/'. self::getProperty($library, 'path');
return e107::getParser()->replaceConstants($path,$mode).'/';
return trim(e107::getParser()->replaceConstants($path,$mode),'/') .'/';
}


Expand Down
37 changes: 27 additions & 10 deletions e107_handlers/media_class.php

Large diffs are not rendered by default.

86 changes: 81 additions & 5 deletions e107_tests/tests/unit/e_library_managerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function _before()
}
catch(Exception $e)
{
$this->assertTrue(false, $e->getMessage());
$this->fail($e->getMessage());
}


Expand All @@ -34,7 +34,7 @@ protected function _before()
}
catch(Exception $e)
{
$this->assertTrue(false, $e->getMessage());
$this->fail($e->getMessage());
}

$coreLibraries = $this->corelib->config();
Expand All @@ -60,7 +60,7 @@ public function testDetectionCallbacks()

foreach($lookups as $name)
{
$this->assertFalse(true, "'version' key is missing in core_library:config() -- ".$name);
$this->fail("'version' key is missing in core_library:config() -- " . $name);
}


Expand All @@ -71,17 +71,18 @@ function testDetectionVersionConsistency()

foreach($this->libraries as $name)
{
echo $name."\n";
$coded = $this->lib->detect($name);
$detected = $this->lib->detect($name, true);

if(empty($coded['version']))
{
$this->assertTrue(false, "No coded version returned in core_library:config() -- ".$name);
$this->fail("No coded version returned in core_library:config() -- " . $name);
}

if(empty($detected['version']))
{
$this->assertTrue(false, "No looked-up version in core_library:config() -- ".$name);
$this->fail("No looked-up version in core_library:config() -- " . $name);
}

$this->assertSame($coded['version'],$detected['version'], 'Version mismatch in core_library:config() -- '.$name);
Expand All @@ -90,6 +91,81 @@ function testDetectionVersionConsistency()


}

public function testCoreLibraryPresence()
{
$coreLibraries = $this->corelib->config();

foreach($coreLibraries as $id => $item)
{
$path = $this->lib->getPath($id);

if(strpos($path, 'http') === 0) // Remote
{
if(!empty($item['files']))
{
foreach($item['files'] as $k=>$v)
{
foreach($v as $file => $info)
{
$url = $path.$file;
$valid = $this->isValidURL($url);
$this->assertTrue($valid, $url.' is not valid. (404)');
}
}
}
}
else // Local
{

if(!empty($item['files']))
{
foreach($item['files'] as $k=>$v)
{
foreach($v as $file => $info)
{
$this->assertStringNotContainsString('//',$path);
$this->assertFileExists($path.$file);
}


}




}

}

}



}

private function isValidURL($url)
{
if(empty($url))
{
return false;
}

if(!$headers = get_headers($url))
{
return false;
}

if(!empty($headers[0]) && strpos($headers[0], 'OK') !== false)
{
return true;
}

return false;


}

/*
public function testInfo()
{
Expand Down
34 changes: 22 additions & 12 deletions e107_tests/tests/unit/e_mediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ public function testListIcons()
}
*/

private function compileFontAwesome5Meta()
private function compileFontAwesomeMeta($version)
{
$raw = file_get_contents(e_WEB."lib/font-awesome/5/metadata/icons.json");
$raw = file_get_contents(e_WEB."lib/font-awesome/$version/metadata/icons.json");
$icons = e107::unserialize($raw);

$ret = [];
Expand All @@ -261,15 +261,19 @@ private function compileFontAwesome5Meta()

}

$ret['fa5-shims'] = $this->compileFontAwesome5Shims();
$ret['fa'.$version.'-shims'] = $this->compileFontAwesomeShims($version);

return $ret;

}

private function compileFontAwesome5Shims()
/**
* @param string $version (major version number. eg. 5 or 6)
* @return array
*/
private function compileFontAwesomeShims($version)
{
$raw = file_get_contents(e_WEB."lib/font-awesome/5/metadata/shims.json");
$raw = file_get_contents(e_WEB."lib/font-awesome/$version/metadata/shims.json");
$icons = e107::unserialize($raw);

$ret = [];
Expand All @@ -289,7 +293,7 @@ public function testGetGlyphs()
{

// @todo uncomment to rebuild getGlyphs() arrays for fontawesome. (requires 'metadata' folder)
// $meta = $this->compileFontAwesome5Meta();
// $meta = $this->compileFontAwesomeMeta(6);
// var_export($meta);
// $far = $this->md->getGlyphs('far');
// $this->assertSame($meta['far'], $far);
Expand All @@ -299,31 +303,37 @@ public function testGetGlyphs()
// $this->assertSame($meta['fab'], $fab);
// Check that FontAwesome 5 meta arrays are up-to-date.

// FontAwesome 6
$fa6_fas = $this->md->getGlyphs('fa6-fas');
$this->assertContains('wine-glass-empty', $fa6_fas);

$fa6Shims = $this->md->getGlyphs('fa6-shims');
$this->assertArrayHasKey('glass', $fa6Shims);

// FontAwesome 5
$fab = $this->md->getGlyphs('fab');
$fab = $this->md->getGlyphs('fa5-fab');
$this->assertContains('500px', $fab);

$fas = $this->md->getGlyphs('fas');
$fas = $this->md->getGlyphs('fa5-fas');
$this->assertContains('address-book', $fas);

$far = $this->md->getGlyphs('far');
$far = $this->md->getGlyphs('fa5-far');
$this->assertContains('arrow-alt-circle-down', $far);

// Check FontAwesome 4
$fa4 = $this->md->getGlyphs('fas');
$fa4 = $this->md->getGlyphs('fa5-fas');
$this->assertContains('heart', $fa4);

// Check Bootstrap 3
$result = $this->md->getGlyphs('bs3');
$this->assertNotEmpty($result['adjust']);
$this->assertNotEmpty($result['zoom-out']);

// Check FontAweomse 5 Shims
// Check FontAwesome 5 Shims
$fa5Shims = $this->md->getGlyphs('fa5-shims');
$this->assertArrayHasKey('glass', $fa5Shims);

$prefixTest = $this->md->getGlyphs('fab', 'myprefix-');
$prefixTest = $this->md->getGlyphs('fa5-fab', 'myprefix-');
$this->assertContains('myprefix-500px', $prefixTest);

}
Expand Down

0 comments on commit 34ba780

Please sign in to comment.