diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 4bcd6493d..673c10db0 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -2157,7 +2157,9 @@ class e107 return null; } - $libraryPath = self::getParser()->replaceConstants($info['library_path'].'/'.$info['path'], 'abs').'/'; + $tp = self::getParser(); + + $libraryPath = $tp->replaceConstants($info['library_path'].'/'.$info['path'], 'abs').'/'; foreach($info['preload'] as $pre) { @@ -2290,18 +2292,17 @@ class e107 /** * Add a tag to the head of the html document. - * @param array $attributes - * @param bool $browserCache set to true to add the cacheId to the href. + * @param array|string $attributes + * @param bool $browserCache set to true to add the cacheId to the href. (when an array is used) * @example e107::link(array('rel'=>"dns-prefetch", "href" => "http://example-domain.com/")); + * @example e107::link('rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin'); */ - public static function link($attributes=array(), $browserCache = false) + public static function link($attributes, $browserCache = false) { self::getJs()->addLink($attributes, $browserCache); } - - /** * CSS Common Public Function. Prefered is shortcode script path * @param string $type core|theme|footer|inline|footer-inline|url or any existing plugin_name diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 82568b64e..985ef4476 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2718,6 +2718,8 @@ class e_parse extends e_parser */ public function staticUrl($path=null, $opts=array()) { + $path = $this->replaceConstants($path,'abs'); + if(!defined('e_HTTP_STATIC') || deftrue('e_ADMIN_AREA')) { // e107::getDebug()->log("e_HTTP_STATIC not defined"); diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index f51b9deb1..dd38c8c33 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -772,17 +772,23 @@ class e_jsmanager /** * Add a tag to the head. - * @param array $attributes key>value pairs + * @param array|string $attributes key>value pairs or html attributes string * @param bool $browserCache - set to true to add the cacheId to the href. * @example addLink(array('rel'=>'prefetch', 'href'=>THEME.'images/browsers.png')); + * @example addLink('rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin'); */ - public function addLink($attributes=array(), $browserCache=false) + public function addLink($attributes, $browserCache=false) { - if(!empty($attributes['href']) && $browserCache === true) + if(is_array($attributes) && !empty($attributes['href'])) { - $attributes['href'] .= "?".$this->getCacheId(); + $attributes['href'] .= ($browserCache === true) ? "?".$this->getCacheId() : ''; + $attributes['href'] = e107::getParser()->staticUrl($attributes['href']); } + if(is_string($attributes)) + { + $attributes = e107::getParser()->staticUrl($attributes); + } if(!empty($attributes)) { @@ -806,10 +812,24 @@ class e_jsmanager foreach($this->_e_link as $v) { + if(is_string($v)) + { + if(strpos($v, "text/css") !== false) + { + e107::getDebug()->log("e107::link(".$v.") ignored. Use e107::css() instead for css stylesheets"); + continue; + } + + $text .= "\n"; + continue; + } + + if(!empty($v['type'])) { if($v['type'] == 'text/css' || $v['rel'] == 'stylesheet') // not for this purpose. use e107::css(); { + e107::getDebug()->log("e107::link(".$v['href'].") ignored. Use e107::css() instead for css stylesheets"); continue; } } diff --git a/e107_handlers/library_manager.php b/e107_handlers/library_manager.php index ceee284bb..e246cab1d 100755 --- a/e107_handlers/library_manager.php +++ b/e107_handlers/library_manager.php @@ -469,6 +469,16 @@ class core_library ), 'library_path' => '{e_WEB}lib/bootstrap', 'path' => '3', + 'preload' => array( + 0 => array( + 'as' => 'font', + 'type' => 'font/woff2', + 'path' => 'fonts/glyphicons-halflings-regular.woff2', + 'crossorigin' => true, + 'browsercache' => false, + ), + + ), ); // Bootstrap Editable (CDN). @@ -855,6 +865,7 @@ class core_library /** * Alters library information before detection and caching takes place. + * @param array $libraries */ function config_alter(&$libraries) {