From a6a5f84bc21180f84708953ddebd5110be5120ee Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 26 Feb 2019 15:03:29 -0800 Subject: [PATCH] FontAwesome5 support in toGlyph(); --- e107_handlers/e_parse_class.php | 72 ++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 6afbea734..f2c8e4988 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -3752,14 +3752,19 @@ class e_parser /** * @var DOMDocument */ - public $domObj = null; + public $domObj = null; public $isHtml = false; - protected $removedList = array(); - protected $nodesToDelete = array(); - protected $nodesToConvert = array(); - protected $nodesToDisableSC = array(); - protected $pathList = array(); - protected $allowedAttributes = array( + + + protected $bootstrap = null; + protected $fontawesome = null; + + protected $removedList = array(); + protected $nodesToDelete = array(); + protected $nodesToConvert = array(); + protected $nodesToDisableSC = array(); + protected $pathList = array(); + protected $allowedAttributes = array( 'default' => array('id', 'style', 'class'), 'img' => array('id', 'src', 'style', 'class', 'alt', 'title', 'width', 'height'), 'a' => array('id', 'href', 'style', 'class', 'title', 'target'), @@ -3816,6 +3821,16 @@ class e_parser { $this->domObj = new DOMDocument(); + if(defined('FONTAWESOME')) + { + $this->fontawesome = (int) FONTAWESOME; + } + + if(defined('BOOTSTRAP')) + { + $this->bootstrap = (int) BOOTSTRAP; + + } } @@ -3887,6 +3902,24 @@ class e_parser $this->scriptTags = $array; } + + /** + * @param int $version + */ + public function setFontAwesome($version) + { + $this->fontawesome = (int) $version; + } + + /** + * @param int $version + */ + public function setBootstrap($version) + { + $this->bootstrap = (int) $version; + } + + /** * Add leading zeros to a number. eg. 3 might become 000003 * @param $num integer @@ -4089,7 +4122,7 @@ class e_parser } */ - if(strpos($text, 'fa-') === 0) // Font-Awesome + if(strpos($text, 'fa-') === 0) // Font-Awesome 4 & 5 { $prefix = 'fa '; $size = (vartrue($parm['size'])) ? ' fa-'.$parm['size'] : ''; @@ -4097,6 +4130,25 @@ class e_parser $spin = !empty($parm['spin']) ? ' fa-spin' : ''; $rotate = !empty($parm['rotate']) ? ' fa-rotate-'.intval($parm['rotate']) : ''; $fixedW = !empty($parm['fw']) ? ' fa-fw' : ""; + + if($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 "; + } + + } + } elseif(strpos($text, 'glyphicon-') === 0) // Bootstrap 3 { @@ -4106,7 +4158,7 @@ class e_parser } elseif(strpos($text, 'icon-') === 0) // Bootstrap 2 { - if(deftrue('BOOTSTRAP') != 2) // bootrap 2 icon but running bootstrap3. + if($this->bootstrap !== 2) // bootrap 2 icon but running bootstrap3. { $prefix = 'glyphicon '; $tag = 'span'; @@ -4721,7 +4773,7 @@ class e_parser $ytqry = http_build_query($ytpref, null, '&'); - $defClass = (deftrue('BOOTSTRAP')) ? "embed-responsive embed-responsive-16by9" : "video-responsive"; // levacy backup. + $defClass = !empty($this->bootstrap) ? "embed-responsive embed-responsive-16by9" : "video-responsive"; // levacy backup. if($type === 'youtube')