From 0e0a6f5f8d58061f727da94646a232d9ee5f4c67 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 11 Jun 2016 15:23:13 -0700 Subject: Work supporting issue #411, add an optional priority (int) as a second arg to head_add_js to affect the load ordering, larger numbered priorities will be included after lower numbered ones. Default priority is 0.Note that we treat main.js differently and always add main.js to the page last, regardless of any other ordering. --- include/plugin.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index be4e92f03..94385550c 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -593,26 +593,38 @@ function script_path() { return $scheme . '://' . $hostname; } -function head_add_js($src) { - App::$js_sources[] = $src; +function head_add_js($src, $priority = 0) { + if(! is_array(App::$js_sources[$priority])) + App::$js_sources[$priority] = array(); + App::$js_sources[$priority][] = $src; } -function head_remove_js($src) { +function head_remove_js($src, $priority = 0) { - $index = array_search($src, App::$js_sources); + $index = array_search($src, App::$js_sources[$priority]); if($index !== false) - unset(App::$js_sources[$index]); + unset(App::$js_sources[$priority][$index]); } +// We should probably try to register main.js with a high priority, but currently we handle it +// separately and put it at the end of the html head block in case any other javascript is +// added outside the head_add_js construct. + function head_get_js() { + +logger('sources:' . print_r(App::$js_sources,true)); $str = ''; - $sources = App::$js_sources; - if(count($sources)) - foreach($sources as $source) { - if($source === 'main.js') - continue; - $str .= format_js_if_exists($source); + if(App::$js_sources) { + foreach(App::$js_sources as $sources) { + if(count($sources)) { + foreach($sources as $source) { + if($src === 'main.js') + continue; + $str .= format_js_if_exists($source); + } + } } + } return $str; } -- cgit v1.2.3 From f41380de773c7a37b17cea7b925e439c4db9a201 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 11 Jun 2016 15:28:52 -0700 Subject: remove debugging --- include/plugin.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 94385550c..9b84039a6 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -612,7 +612,6 @@ function head_remove_js($src, $priority = 0) { function head_get_js() { -logger('sources:' . print_r(App::$js_sources,true)); $str = ''; if(App::$js_sources) { foreach(App::$js_sources as $sources) { -- cgit v1.2.3 From ed166608670c5b5d237c43bd0d672502d5b624f5 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 20 Jun 2016 20:34:19 -0700 Subject: code optimisation --- include/plugin.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 9b84039a6..c95f8cbf9 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -167,6 +167,12 @@ function reload_plugins() { } } +function visible_plugin_list() { + $r = q("select * from addon where hidden = 0 order by aname asc"); + return(($r) ? ids_to_array($r,'aname') : array()); +} + + /** * @brief registers a hook. -- cgit v1.2.3 From 2dc1236dcae487bf3887942a2e58a240157bb896 Mon Sep 17 00:00:00 2001 From: Treer Date: Sat, 25 Jun 2016 22:38:15 +1000 Subject: Allow absolute links to css and js files --- include/plugin.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index c95f8cbf9..3f60e5e04 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -551,15 +551,21 @@ function head_get_css() { } function format_css_if_exists($source) { - if (strpos($source[0], '/') !== false) + $path_prefix = script_path() . '/'; + + if (strpos($source[0], '/') !== false) { + // The source is a URL $path = $source[0]; - else + // If the url starts with // then it's an absolute URL + if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + } else { + // It's a file from the theme $path = theme_include($source[0]); + } if($path) { - $path = script_path() . '/' . $path; $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; - return '' . "\r\n"; + return '' . "\r\n"; } } @@ -643,14 +649,20 @@ function head_get_main_js() { } function format_js_if_exists($source) { - if(strpos($source,'/') !== false) + $path_prefix = script_path() . '/'; + + if(strpos($source,'/') !== false) { + // The source is a URL $path = $source; - else + // If the url starts with // then it's an absolute URL + if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + } else { + // It's a file from the theme $path = theme_include($source); + } if($path) { - $path = script_path() . '/' . $path; $qstring = ((parse_url($path, PHP_URL_QUERY)) ? '&' : '?') . 'v=' . STD_VERSION; - return '' . "\r\n" ; + return '' . "\r\n" ; } } -- cgit v1.2.3 From e0a76376265937a62c48fde03c7947cde972f8b7 Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 26 Jun 2016 13:08:40 +1000 Subject: fix absolute .js urls --- include/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/plugin.php') diff --git a/include/plugin.php b/include/plugin.php index 3f60e5e04..6dfda1cc9 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -655,7 +655,7 @@ function format_js_if_exists($source) { // The source is a URL $path = $source; // If the url starts with // then it's an absolute URL - if($source[0][0] === '/' && $source[0][1] === '/') $path_prefix = ''; + if($source[0] === '/' && $source[1] === '/') $path_prefix = ''; } else { // It's a file from the theme $path = theme_include($source); -- cgit v1.2.3