Commit 3a913a20 authored by walper's avatar walper

[FIX] Fixed and iproved handling of including Javascript, CDNs user defined...

[FIX] Fixed and iproved handling of including Javascript, CDNs user defined CDNs and minification. This is a major rewrite and impacts any place that uses JS on file level. Added a lot of comments to make inner workings clear and updated all areas using JS Files.
parent 4f422684
......@@ -48,7 +48,7 @@ class WYSIWYGLib
$headerlib = TikiLib::lib('header');
$headerlib->add_js_config('window.CKEDITOR_BASEPATH = "'. $tikiroot . 'vendor/ckeditor/ckeditor/";')
->add_jsfile('vendor/ckeditor/ckeditor/ckeditor.js', 0, true)
->add_jsfile('vendor/ckeditor/ckeditor/ckeditor.js', true)
->add_js('window.CKEDITOR.config._TikiRoot = "'.$tikiroot.'";', 1);
// Inline editing config
......@@ -121,7 +121,7 @@ window.CKEDITOR.config.toolbar = ' .$cktools.';
$headerlib->add_js_config('window.CKEDITOR_BASEPATH = "'. $tikiroot . 'vendor/ckeditor/ckeditor/";')
//// for js debugging - copy _source from ckeditor distribution to libs/ckeditor to use
//// note, this breaks ajax page load via wikitopline edit icon
->add_jsfile('vendor/ckeditor/ckeditor/ckeditor.js', 0, true)
->add_jsfile('vendor/ckeditor/ckeditor/ckeditor.js', true)
->add_js('window.CKEDITOR.config._TikiRoot = "'.$tikiroot.'";', 1);
$headerlib->add_js(
......
......@@ -111,10 +111,11 @@ class Tiki_PageCache
if ( $cachedOutput && $cachedOutput['output'] ) {
$headerlib = TikiLib::lib('header');
if (is_array($cachedOutput['jsiles'])) {
foreach ($cachedOutput['jsiles'] as $rank => $files) {
if (is_array($cachedOutput['jsfiles'])) {
foreach ($cachedOutput['jsfiles'] as $rank => $files) {
foreach ($files as $file) {
$headerlib->add_jsfile($file, $rank);
$skip_minify = isset($cachedOutput['skip_minify']) ? true : false;
$headerlib->add_jsfile_by_rank($file, $rank, $skip_minify);
}
}
}
......@@ -174,7 +175,8 @@ class Tiki_PageCache
if ($this->headerLibCopy) {
$headerlib = TikiLib::lib('header');
$cachedOutput['jsiles'] = array_diff($headerlib->jsfiles, $this->headerLibCopy->jsfiles);
$cachedOutput['jsfiles'] = array_diff($headerlib->jsfiles, $this->headerLibCopy->jsfiles);
$cachedOutput['skip_minify']= array_diff($headerlib->skip_minify, $this->headerLibCopy->skip_minify);
$cachedOutput['jq_onready'] = array_diff($headerlib->jq_onready, $this->headerLibCopy->jq_onready);
$cachedOutput['js'] = array_diff($headerlib->js, $this->headerLibCopy->js);
$cachedOutput['css'] = array_diff($headerlib->css, $this->headerLibCopy->css);
......
......@@ -596,11 +596,6 @@ class WikiPlugin_Negotiator_Wiki
}
}
$headerlib->add_jsfile('tiki-jsplugin.php?language='.$this->prefs['language'], 'dynamic');
if ($this->prefs['wikiplugin_module'] === 'y' && $this->prefs['wikiplugininline_module'] === 'n') {
$headerlib->add_jsfile('tiki-jsmodule.php?language='.$this->prefs['language'], 'dynamic');
}
$headerlib->add_jq_onready(
'$("#' . $id . '")
.click( function(event) {'
......
This diff is collapsed.
......@@ -61,31 +61,35 @@ if ($prefs['javascript_enabled'] == 'y') { // we have JavaScript
if (file_exists('lang/' . $prefs['language'] . '/language.js')) {
// after the usual lib includes (up to 10) but before custom.js (50)
$headerlib
->add_jsfile('lang/' . $prefs['language'] . '/language.js', 25)
->add_jsfile('lang/' . $prefs['language'] . '/language.js')
->add_js("$.lang = '" . $prefs['language'] . "';");
}
/** Use custom.js in lang dir if there **/
$language = $prefs['language'];
if (is_file("lang/$language/custom.js")) {
TikiLib::lib('header')->add_jsfile("lang/$language/custom.js"); // before styles custom.js
}
if (!empty($tikidomain) && is_file("lang/$language/$tikidomain/custom.js")) { // Note: lang tikidomain dirs not created automatically
TikiLib::lib('header')->add_jsfile("lang/$language/$tikidomain/custom.js");
}
/** Use custom.js in themes or options dir if there **/
$themelib = TikiLib::lib('theme');
$custom_js = $themelib->get_theme_path($prefs['theme'], $prefs['theme_option'], 'custom.js');
if (!empty($custom_js)) {
$headerlib->add_jsfile($custom_js, 50);
$headerlib->add_jsfile($custom_js);
} else { // there's no custom.js in the current theme or option
$custom_js = $themelib->get_theme_path('', '', 'custom.js'); // so use one in the root of /themes if there
if (!empty($custom_js)) {
$headerlib->add_jsfile($custom_js, 50);
$headerlib->add_jsfile($custom_js);
}
}
/** Use custom.js in lang dir if there **/
$language = $prefs['language'];
if (is_file("lang/$language/custom.js")) {
TikiLib::lib('header')->add_jsfile("lang/$language/custom.js", 40); // before styles custom.js
}
if (!empty($tikidomain) && is_file("lang/$language/$tikidomain/custom.js")) { // Note: lang tikidomain dirs not created automatically
TikiLib::lib('header')->add_jsfile("lang/$language/$tikidomain/custom.js", 40);
}
// setup timezone array
$tz = TikiDate::getTimezoneAbbreviations();
......@@ -220,7 +224,7 @@ var syntaxHighlighter = {
$fixondom = "DD_belatedPNG.fixPng($fixondom); // list of HTMLDomElements to fix separated by commas (default is none)";
}
$scriptpath = 'lib/iepngfix/DD_belatedPNG-min.js';
$headerlib->add_jsfile($scriptpath, 200);
$headerlib->add_jsfile($scriptpath, true);
$headerlib->add_js(
<<<JS
DD_belatedPNG.fix('$fixoncss'); // list of CSS selectors to fix separated by commas (default is set to fix sitelogo)
......
......@@ -59,8 +59,8 @@ if ( !isset($_REQUEST['mobile_mode']) || $_REQUEST['mobile_mode'] === 'y' ) {
if ($prefs['feature_shadowbox'] === 'y') {
$headerlib
->add_jsfile('vendor/jquery/photoswipe/lib/klass.min.js', 'external')
->add_jsfile('vendor/jquery/photoswipe/code.photoswipe.jquery-3.0.5.min.js', 'external')
->add_jsfile_external('vendor/jquery/photoswipe/lib/klass.min.js', true)
->add_jsfile_external('vendor/jquery/photoswipe/code.photoswipe.jquery-3.0.5.min.js', true)
->add_cssfile('vendor/jquery/photoswipe/photoswipe.css');
}
......
......@@ -395,9 +395,9 @@ class SheetLib extends TikiLib
->add_jsfile( 'vendor/jquery/jquery-sheet/plugins/globalize.js' )
->add_jsfile( 'vendor/jquery/jquery-sheet/plugins/globalize.cultures.js' )
->add_jsfile( 'vendor/jquery/jquery-sheet/plugins/jquery.nearest.min.js', 'external' )
->add_jsfile( 'vendor/jquery/jquery-sheet/plugins/raphael-min.js', 'external' )
->add_jsfile( 'vendor/jquery/jquery-sheet/plugins/g.raphael-min.js', 'external' );
->add_jsfile_external( 'vendor/jquery/jquery-sheet/plugins/jquery.nearest.min.js', true )
->add_jsfile_external( 'vendor/jquery/jquery-sheet/plugins/raphael-min.js', true )
->add_jsfile_external( 'vendor/jquery/jquery-sheet/plugins/g.raphael-min.js', true );
$this->setup_jQuery_sheet_files = true;
}
......
......@@ -5467,9 +5467,11 @@ class TikiLib extends TikiDb_Bridge
/**
* @return string
* Get URL Scheme (http / https)
* Considers the use of a reverse proxy / ssl offloader. I.e If request is https -> ssl offloader -> http tiki, then it will correctly return https
* @return string http | https
*/
function httpScheme()
static function httpScheme()
{
global $url_scheme;
return $url_scheme;
......
......@@ -73,8 +73,8 @@ function wikiplugin_contributionsdashboard($data, $params)
$types = explode(',', $types);
$headerlib->add_jsfile("vendor/jquery/jquery-sheet/plugins/raphael-min.js", "external");
$headerlib->add_jsfile("vendor/jquery/jquery-sheet/plugins/g.raphael-min.js", "external");
$headerlib->add_jsfile_external("vendor/jquery/jquery-sheet/plugins/raphael-min.js", true);
$headerlib->add_jsfile_external("vendor/jquery/jquery-sheet/plugins/g.raphael-min.js", true);
$headerlib->add_jq_onready("$('.cDashDate').datepicker();");
$usersTrackerItems = array();
......
......@@ -238,7 +238,7 @@ REG
}
TikiLib::lib('header')
->add_jsfile("{$prefs['kaltura_kServiceUrl']}/p/{$prefs['kaltura_partnerId']}/sp/{$prefs['kaltura_partnerId']}00{$embedIframeJs}/uiconf_id/{$params['player_id']}/partner_id/{$prefs['kaltura_partnerId']}")
->add_jsfile_cdn("{$prefs['kaltura_kServiceUrl']}/p/{$prefs['kaltura_partnerId']}/sp/{$prefs['kaltura_partnerId']}00{$embedIframeJs}/uiconf_id/{$params['player_id']}/partner_id/{$prefs['kaltura_partnerId']}")
->add_jq_onready(
"
mw.setConfig('Kaltura.LeadWithHTML5', $leadWithHTML5);
......
......@@ -203,7 +203,7 @@ function wikiplugin_trackercalendar($data, $params)
static $id = 0;
$headerlib = TikiLib::lib('header');
$headerlib->add_cssfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.css');
$headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js');
$headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js', true);
$jit = new JitFilter($params);
$definition = Tracker_Definition::get($jit->trackerId->int());
......
......@@ -151,7 +151,7 @@ function wikiplugin_vimeo($data, $params)
$instance++;
if ($params['useFroogaloopApi']) {
TikiLib::lib('header')->add_jsfile('vendor_extra/vimeo/froogaloop.min.js');
TikiLib::lib('header')->add_jsfile('vendor_extra/vimeo/froogaloop.min.js', true);
TikiLib::lib('header')->add_jsfile('vendor_extra/vimeo/vimeo.js');
}
......
......@@ -509,13 +509,13 @@ class WikiLib extends TikiLib
$canBeRefreshed = true;
} else {
$jsFile1 = $headerlib->getJsfiles();
$jsFile1 = $headerlib->getJsFilesWithScriptTags();
$js1 = $headerlib->getJs();
$info['outputType'] = $tikilib->getOne ("SELECT `outputType` FROM `tiki_output` WHERE `entityId` = ? AND `objectType` = ? AND `version` = ?", array($info['pageName'], 'wikiPage', $info['version']));
$content = (new WikiLibOutput($info, $info['data'],$parse_options))->parsedValue;
$info['outputType'] = $tikilib->getOne ("SELECT `outputType` FROM `tiki_output` WHERE `entityId` = ? AND `objectType` = ? AND `version` = ?", array($info['pageName'], 'wikiPage', $info['version']));
$content = (new WikiLibOutput($info, $info['data'],$parse_options))->parsedValue;
// get any JS added to headerlib during parse_data and add to the bottom of the data to cache
$jsFile2 = $headerlib->getJsfiles();
$jsFile2 = $headerlib->getJsFilesWithScriptTags();
$js2 = $headerlib->getJs();
$jsFile = array_diff($jsFile2, $jsFile1);
......
......@@ -93,7 +93,7 @@ $smarty->assign('offset', $maxgal ? $offset - ($offset % $maxgal) : 0);
//$smarty->assign_by_ref('theme',$gal_info["theme"]);
//$smarty->assign('use_theme','y');
if ($prefs['feature_gal_slideshow'] != 'n') {
$headerlib->add_jsfile('lib/imagegals/imagegallib.js', 50);
$headerlib->add_jsfile('lib/imagegals/imagegallib.js');
$listImgId = implode(',', $listImgId);
$smarty->assign('listImgId', $listImgId);
}
......
......@@ -800,7 +800,7 @@ ask_ticket('calendar');
if (!empty($prefs['calendar_fullcalendar']) && $prefs['calendar_fullcalendar'] === 'y') {
$headerlib->add_cssfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.css');
$headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js');
$headerlib->add_jsfile('vendor_extra/fullcalendar-resourceviews/fullcalendar/fullcalendar.min.js', true);
$smarty->assign('minHourOfDay', $minHourOfDay);
$smarty->assign('maxHourOfDay', $maxHourOfDay);
if ($prefs['feature_wysiwyg'] == 'y' && $prefs['wysiwyg_default'] == 'y') {
......
......@@ -246,7 +246,7 @@ if ($prefs['feature_wysiwyg'] == 'y') {
if ($prefs['feature_antibot'] == 'y' && empty($user)) {
if ($prefs['recaptcha_enabled'] === 'y') {
$headerlib->add_jsfile('https://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
$headerlib->add_jsfile_cdn("$url_scheme://www.google.com/recaptcha/api/js/recaptcha_ajax.js");
}
$captchalib = TikiLib::lib('captcha');
$smarty->assign('captchalib', $captchalib);
......@@ -324,22 +324,23 @@ $headerlib->add_jsfile('lib/tiki-js.js');
// using jquery-migrate-1.2.1.js plugin for tiki 11, still required in tiki 12 LTS to support some 3rd party plugins
if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'google' ) {
$headerlib->add_jsfile_dependancy("$url_scheme://ajax.googleapis.com/ajax/libs/jquery/$headerlib->jquery_version/jquery.min.js");
$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate-min/jquery-migrate-1.2.1.min.js");
$headerlib->add_jsfile_cdn("$url_scheme://ajax.googleapis.com/ajax/libs/jquery/$headerlib->jquery_version/jquery.min.js");
// goggle is not hosting migrate so load from local
$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate-min/jquery-migrate-1.2.1.min.js", true);
} else if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
$headerlib->add_jsfile_dependancy("//code.jquery.com/jquery-$headerlib->jquery_version.min.js");
$headerlib->add_jsfile_dependancy("//code.jquery.com/jquery-migrate-1.2.1.min.js");
$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/jquery-$headerlib->jquery_version.min.js");
$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/jquery-migrate-1.2.1.min.js");
} else {
if ( $prefs['tiki_minify_javascript'] === 'y' ) {
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-min/jquery-$headerlib->jquery_version.min.js");
$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate-min/jquery-migrate-1.2.1.min.js");
if ( isset($prefs['tiki_minify_javascript']) && $prefs['tiki_minify_javascript'] === 'y' ) {
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-min/jquery-$headerlib->jquery_version.min.js", true);
$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate-min/jquery-migrate-1.2.1.min.js", true);
} else {
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery/jquery-$headerlib->jquery_version.js");
$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate/jquery-migrate-1.2.1.js");
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery/jquery-$headerlib->jquery_version.js", true);
$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate/jquery-migrate-1.2.1.js", true);
}
}
if ( $prefs['fgal_elfinder_feature'] === 'y' ) {
if ( isset($prefs['fgal_elfinder_feature']) && $prefs['fgal_elfinder_feature'] === 'y' ) {
$str = $prefs['tiki_minify_javascript'] === 'y' ? 'min' : 'full';
$headerlib->add_jsfile('vendor_extra/elfinder/js/elfinder.' . $str . '.js')
->add_cssfile('vendor_extra/elfinder/css/elfinder.' . $str . '.css')
......@@ -391,11 +392,11 @@ if ($prefs['feature_syntax_highlighter'] == 'y') {
$headerlib
->add_cssfile('vendor/codemirror/codemirror/lib/codemirror.css')
->add_jsfile_dependancy('vendor/codemirror/codemirror/lib/codemirror.js')
->add_jsfile('vendor/codemirror/codemirror/addon/search/searchcursor.js', 3)
->add_jsfile('vendor/codemirror/codemirror/addon/search/searchcursor.js')
->add_jsfile('vendor/codemirror/codemirror/addon/mode/overlay.js')
//add tiki stuff
->add_cssfile('lib/codemirror_tiki/codemirror_tiki.css')
->add_jsfile('lib/codemirror_tiki/codemirror_tiki.js', 5);
->add_jsfile('lib/codemirror_tiki/codemirror_tiki.js');
require_once("lib/codemirror_tiki/tiki_codemirror.php");
codemirrorModes($prefs['tiki_minify_javascript'] === 'y');
......@@ -418,14 +419,16 @@ if ( $prefs['feature_ajax'] === 'y' ) {
}
}
// $url_scheme is 'http' or 'https' depending on request type condsidering already a reverse proxy
// $https_mode is true / false depending on request type condsidering already a reverse proxy
if ( $prefs['feature_jquery_ui'] == 'y' ) {
if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'google' ) {
$headerlib->add_jsfile_dependancy("$url_scheme://ajax.googleapis.com/ajax/libs/jqueryui/$headerlib->jqueryui_version/jquery-ui.min.js");
$headerlib->add_jsfile_cdn("$url_scheme://ajax.googleapis.com/ajax/libs/jqueryui/$headerlib->jqueryui_version/jquery-ui.min.js");
} else if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
$headerlib->add_jsfile_dependancy("//code.jquery.com/ui/$headerlib->jqueryui_version/jquery-ui.min.js");
$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/ui/$headerlib->jqueryui_version/jquery-ui.min.js");
} else {
if ( $prefs['tiki_minify_javascript'] === 'y' ) {
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-ui/jquery-ui.min.js");
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-ui/jquery-ui.min.js", true);
} else {
$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-ui/jquery-ui.js");
}
......@@ -433,7 +436,7 @@ if ( $prefs['feature_jquery_ui'] == 'y' ) {
if ( $prefs['feature_jquery_ui_theme'] !== 'none' ) {
if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
$headerlib->add_cssfile("//code.jquery.com/ui/$headerlib->jqueryui_version/themes/{$prefs['feature_jquery_ui_theme']}/jquery-ui.css");
$headerlib->add_cssfile("$url_scheme://code.jquery.com/ui/$headerlib->jqueryui_version/themes/{$prefs['feature_jquery_ui_theme']}/jquery-ui.css");
} else {
$headerlib->add_cssfile('vendor/jquery/jquery-ui-themes/themes/' . $prefs['feature_jquery_ui_theme'] . '/jquery-ui.css');
}
......@@ -498,14 +501,15 @@ if ( $prefs['feature_jquery_validation'] == 'y' ) {
$headerlib->add_jsfile('lib/validators/validator_tiki.js');
}
$headerlib->add_jsfile('vendor/jquery/plugins/async/jquery.async.js', 10);
// note: jquery.async.js load a copy of jquery
$headerlib->add_jsfile('vendor/jquery/plugins/async/jquery.async.js');
$headerlib->add_jsfile('vendor/jquery/plugins/treetable/javascripts/src/jquery.treetable.js');
$headerlib->add_cssfile('vendor/jquery/plugins/treetable/stylesheets/jquery.treetable.css');
$headerlib->add_jsfile('vendor/cwspear/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js');
if (empty($user) && $prefs['feature_antibot'] == 'y') {
$headerlib->add_jsfile('lib/captcha/captchalib.js');
$headerlib->add_jsfile_late('lib/captcha/captchalib.js');
}
if ( $prefs['feature_jcapture'] === 'y' ) {
......@@ -595,9 +599,11 @@ if ($prefs['mustread_enabled'] == 'y') {
if (true) {
// Before being clever and moving this close to where you think it's needed (again),
// consider there are more places that you think.
$headerlib->add_jsfile('tiki-jsplugin.php?language='.$prefs['language'], 'dynamic');
// This is not a very helpful comment...
$headerlib->add_jsfile_dynamic('tiki-jsplugin.php?language='.$prefs['language']);
if ($prefs['wikiplugin_module'] === 'y' && $prefs['wikiplugininline_module'] === 'n') {
$headerlib->add_jsfile('tiki-jsmodule.php?language='.$prefs['language'], 'dynamic');
$headerlib->add_jsfile_dynamic('tiki-jsmodule.php?language='.$prefs['language']);
}
}
......@@ -628,7 +634,7 @@ if ( isset($token_error) ) {
require_once( 'lib/setup/plugins_actions.php' );
if ($tiki_p_admin == 'y') {
$headerlib->add_jsfile('lib/jquery_tiki/tiki-admin.js');
$headerlib->add_jsfile_late('lib/jquery_tiki/tiki-admin.js');
}
if ($prefs['wikiplugin_addtocart'] == 'y') {
......@@ -689,7 +695,9 @@ if( $prefs['feature_hidden_links'] == 'y' && isset($jitRequest['wysiwyg']) && $j
});");
}
$headerlib->lockMinifiedJs();
// any furher $headerlib->add_js() call not using rank = 'external' will be put into rank 'late'
// this should separate the overall JS from page specific JS
$headerlib->forceJsRankLate();
if ( $prefs['conditions_enabled'] == 'y' ) {
if (! Services_User_ConditionsController::hasRequiredAge($user)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment