From 882efff6ec04cb0888a8f415f671b48ed645f54f Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 1 Jan 2017 08:13:42 -0800 Subject: [PATCH] Support for theme glyphicons. --- e107_admin/header.php | 8 +++- e107_admin/image.php | 46 +++++++++++++++++++++- e107_handlers/e107_class.php | 32 +++++++++++++++ e107_handlers/media_class.php | 70 +++++++++++++++++++++++++-------- e107_handlers/theme_handler.php | 30 +++++++++++++- 5 files changed, 166 insertions(+), 20 deletions(-) diff --git a/e107_admin/header.php b/e107_admin/header.php index 873da70bf..b499a06ef 100644 --- a/e107_admin/header.php +++ b/e107_admin/header.php @@ -99,7 +99,6 @@ loadJSAddons(); - // e107::js("core", "core/admin.js","prototype",3); // Load all default functions. @@ -198,6 +197,13 @@ if (!isset($no_core_css) || !$no_core_css) $e_js->otherCSS('{e_WEB_CSS}e107.css'); } + +$custom = e107::getThemeGlyphs(); +foreach($custom as $val) +{ + $e_js->otherCSS($val['path']); +} + // Register Plugin specific CSS // DEPRECATED, use $e_js->pluginCSS('myplug', 'style/myplug.css'[, $media = 'all|screen|...']); if (isset($eplug_css) && $eplug_css) diff --git a/e107_admin/image.php b/e107_admin/image.php index 55c1ca861..d78e73227 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -1408,8 +1408,6 @@ class media_admin_ui extends e_admin_ui $items = array(); - //TODO FIXME Upgrade to bs3 when Bootstrap3 Admin is ready. - $bs2 = e107::getMedia()->getGlyphs('bs3','glyphicon-'); foreach($bs2 as $val) @@ -1441,6 +1439,50 @@ class media_admin_ui extends e_admin_ui ); } + + + + $custom = e107::getThemeGlyphs(); + + if(!empty($custom)) + { + foreach($custom as $glyphConfig) + { + + $tmp = e107::getMedia()->getGlyphs($glyphConfig,$glyphConfig['prefix']); + + if(!empty($tmp)) + { + foreach($tmp as $val) + { + $items[] = array( + 'previewUrl' => $val, + 'saveValue' => $val.'.glyph', + 'thumbUrl' => $val, + 'title' => $val, + 'slideCaption' => ucfirst($glyphConfig['name']), + 'slideCategory' => $glyphConfig['name'] + ); + + } + + + } + + + + + + } + + + + } + + + + + if(vartrue($parm['search'])) { diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 664f330ff..2feac3f1d 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -1117,6 +1117,38 @@ class e107 return e107::getConfig()->updatePref('sitetheme_pref/'.$pref_name, $pref_value, false); } + + public static function getThemeGlyphs() + { + + $custom = self::getConfig()->getPref('sitetheme_glyphicons', false); + $theme = self::getConfig()->getPref('sitetheme', false); + + $arr = array(); + + if(!empty($custom)) + { + + foreach($custom as $glyphConfig) + { + + if(substr($glyphConfig['path'],0,4) !== 'http') + { + $glyphConfig['path'] = e_THEME."$theme/".$glyphConfig['path']; + } + + $arr[] = $glyphConfig; + } + + } + + return $arr; + + } + + + + /** * Retrieve text parser singleton object * diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index 1785c9d85..84a3a77c5 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -871,13 +871,19 @@ class e_media /** - * Get all Glyphs + * @param string|array $type + * @param $type['name'] + * @param $type[['type'] + * @param $type['path'] URL or e107 path {e_THEME} etc. + * @param $type['prefix'] + * @param string $addPrefix + * @return array */ - function getGlyphs($type='fa4',$prefix = '') + function getGlyphs($type='fa4', $addPrefix = '') { $icons = array(); - if($type == 'bs2') + if($type === 'bs2') { $matches = array( 'glass','music','search','envelope','heart','star','star-empty','user','film','th-large','th','th-list','ok', @@ -899,13 +905,13 @@ class e_media foreach($matches as $match) { - $icons[] = $prefix.$match; + $icons[] = $addPrefix.$match; } return $icons; } - if($type == 'bs3') + if($type === 'bs3') { $matches = array( 'adjust','align-center','align-justify','align-left','align-right','arrow-down','arrow-left','arrow-right','arrow-up','asterisk','backward','ban-circle','barcode','bell','bold','book @@ -924,14 +930,27 @@ class e_media foreach($matches as $match) { - $icons[] = $prefix.$match; + $icons[] = $addPrefix.$match; } return $icons; } - + + if(is_array($type)) + { + $prefix = $type['prefix']; + $pattern = $type['pattern']; + $path = $type['path']; + $type = $type['name']; + + } + + + $cache = e107::getCache(); - $cachTag = !empty($prefix) ? "Glyphs_".$prefix."_".$type : "Glyphs_".$type; + $cachTag = !empty($addPrefix) ? "Glyphs_".$addPrefix."_".$type : "Glyphs_".$type; + + if($data = $cache->retrieve($cachTag ,360,true,true)) { @@ -939,25 +958,43 @@ class e_media } - if($type == 'fa4') + if($type === 'fa4') { $pattern = '/\.(fa-(?:\w+(?:-)?)+):before/'; $subject = e107::getFile()->getRemoteContent('http://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css'); - // print_a($subject); + $prefix = 'fa-'; } - elseif($type == 'fa3') + elseif($type === 'fa3') { $pattern = '/\.(icon-(?:\w+(?:-)?)+):before/'; $subject = file_get_contents(e_WEB_JS.'font-awesome/css/font-awesome.css'); + $prefix = 'fa-'; } - + elseif(!empty($pattern) && !empty($path)) + { + $pattern = '/'.$pattern.'/'; + if(substr($path,0,4) === 'http') + { + $subject = e107::getFile()->getRemoteContent($path); + } + else + { + $path = e107::getParser()->replaceConstants($path); + $subject = file_get_contents($path); + } + + + + } + + + $prefixLength = !empty($prefix) ? strlen($prefix) : 3; + preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER); - - - + foreach($matches as $match) { - $icons[] = $prefix.substr($match[1],3); + $icons[] = $addPrefix.substr($match[1],$prefixLength); } if(empty($icons)) // failed to produce a result so don't cache it. . @@ -975,6 +1012,7 @@ class e_media + function getPath($mime, $path=null) { $mes = e107::getMessage(); diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index 3aa1fe41d..70ec2074b 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -1785,12 +1785,14 @@ class themeHandler $deflayout = $this->findDefault($name); $customPages = $this->themeArray[$name]['custompages']; $version = $this->themeArray[$name]['version']; + $glyphs = $this->themeArray[$name]['glyphs']; $core->set('sitetheme', $name); $core->set('themecss', 'style.css'); $core->set('sitetheme_layouts', $layout); $core->set('sitetheme_deflayout', $deflayout); $core->set('sitetheme_custompages', $customPages); + $core->set('sitetheme_glyphicons', $glyphs); $core->set('sitetheme_version', $version); @@ -2293,7 +2295,29 @@ class themeHandler unset($vars['stylesheets']); } - + + + $vars['glyphs'] = array(); + if(!empty($vars['glyphicons']['glyph'])) + { + + foreach($vars['glyphicons']['glyph'] as $val) + { + $vars['glyphs'][] = array( + 'name' => $val['@attributes']['name'], + 'pattern' => $val['@attributes']['pattern'], + 'path' => $val['@attributes']['path'], + 'prefix' => $val['@attributes']['prefix'], + 'tag' => $val['@attributes']['tag'], + ); + + } + + unset($vars['glyphicons']); + + } + + // $mes = e107::getMessage(); // DEBUG @@ -2316,6 +2340,10 @@ class themeHandler return $vars; } + + + + } interface e_theme_config