tiki-setup.php 29.7 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2
/**
kstingel's avatar
kstingel committed
3
 * contains the hooks for Tiki's internal functionality.
4
 *
kstingel's avatar
kstingel committed
5
 * this script may only be included, it will die if called directly.
6
 *
kstingel's avatar
kstingel committed
7
 * @package TikiWiki
8
 * @copyright (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project. All Rights Reserved. See copyright.txt for details and a complete list of authors.
kstingel's avatar
kstingel committed
9
 * @licence Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
10
 */
changi67's avatar
changi67 committed
11
// $Id$
changi67's avatar
changi67 committed
12

kstingel's avatar
kstingel committed
13
// die if called directly.
14
/**
kstingel's avatar
kstingel committed
15
 * @global array $prefs
16
 * @global array $tikilib
kstingel's avatar
kstingel committed
17
 */
sylvieg's avatar
sylvieg committed
18
global $prefs, $tikilib;
19 20
if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
	header('location: index.php');
changi67's avatar
changi67 committed
21
	exit;
redflo's avatar
redflo committed
22
}
23
if (version_compare(PHP_VERSION, '5.5.0', '<') && php_sapi_name() != 'cli') {
24
	header('location: tiki-install.php');
changi67's avatar
changi67 committed
25
	exit;
26 27 28
} elseif (version_compare(PHP_VERSION, '5.5.0', '<') && php_sapi_name() == 'cli') {
	// This is command-line. No 'location' command make sense here. Let admins access what works and deal with the rest.
	echo "Warning: Tiki13 and above expects PHP 5.5.0 and above. You are running " . phpversion() . " at your own risk\n";
campbe13's avatar
campbe13 committed
29
}
30 31 32 33

// Be sure that the user is not already defined by PHP on hosts that still have the php.ini config "register_globals = On"
unset($user);

34
require_once 'lib/setup/third_party.php';
35 36 37
// Enable Versioning
include_once ('lib/setup/twversion.class.php');
$TWV = new TWVersion();
38 39 40 41 42
$num_queries = 0;
$elapsed_in_db = 0.0;
$server_load = '';
$area = 'tiki';
$crumbs = array();
changi67's avatar
changi67 committed
43 44
require_once ('lib/setup/tikisetup.class.php');
require_once ('lib/setup/timer.class.php');
45 46
$tiki_timer = new timer();
$tiki_timer->start();
changi67's avatar
changi67 committed
47
require_once ('tiki-setup_base.php');
48 49

// Attempt setting locales. This code is just a start, locales should be set per-user.
50
// Also, different operating systems use different locale strings. en_US.utf8 is valid on POSIX systems, maybe not on Windows, feel free to add alternative locale strings.
51
setlocale(LC_ALL, ''); // Attempt changing the locale to the system default.
52
// Since the system default may not be UTF-8 but we may be dealing with multilingual content, attempt ensuring the collations are intelligent by forcing a general UTF-8 collation.
53
// This will have no effect if the locale string is not valid or if the designated locale is not generated.
54

55
foreach (array('en_US.utf8') as $UnicodeLocale) {
56 57 58 59
	if (setlocale(LC_COLLATE, $UnicodeLocale)) {
		break;
	}
}
60

61 62 63
if ($prefs['feature_tikitests'] == 'y') {
	require_once ('tiki_tests/tikitestslib.php');
}
64
$crumbs[] = new Breadcrumb($prefs['browsertitle'], '', $prefs['tikiIndex']);
65 66 67
if ($prefs['site_closed'] == 'y') {
	require_once ('lib/setup/site_closed.php');
}
changi67's avatar
changi67 committed
68
require_once ('lib/setup/error_reporting.php');
69 70 71
if ($prefs['use_load_threshold'] == 'y') {
	require_once ('lib/setup/load_threshold.php');
}
changi67's avatar
changi67 committed
72
require_once ('lib/setup/sections.php');
73
$headerlib = TikiLib::lib('header');
74

75
$domain_map = array();
76 77 78 79 80 81 82 83 84 85
if ( isset($_SERVER['HTTP_HOST']) ) {
	$host = $_SERVER['HTTP_HOST'];
} else {
	$host = "";
}
if ( isset($_SERVER['REQUEST_URI']) ) {
	$requestUri = $_SERVER['REQUEST_URI'];
} else {
	$requestUri = "";
}
86

87 88
if ( $prefs['tiki_domain_prefix'] == 'strip' && substr($host, 0, 4) == 'www.' ) {
	$domain_map[$host] = substr($host, 4);
89
} elseif ( $prefs['tiki_domain_prefix'] == 'force' && substr($host, 0, 4) != 'www.' ) {
90 91
	$domain_map[$host] = 'www.' . $host;
}
92

93
if (strpos($prefs['tiki_domain_redirects'], ',') !== false) {
94
	foreach (explode("\n", $prefs['tiki_domain_redirects']) as $row) {
95 96
		list($old, $new) = array_map('trim', explode(',', $row, 2));
		$domain_map[$old] = $new;
97
	}
98 99
	unset($old);
	unset($new);
100 101
}

102
if ( isset($domain_map[$host]) && ! defined('TIKI_CONSOLE') ) {
103
	$prefix = $tikilib->httpPrefix();
104
	$prefix = str_replace("://$host", "://{$domain_map[$host]}", $prefix);
105
	$url = $prefix . $requestUri;
106

107
	$access->redirect($url, null, 301);
108 109 110
	exit;
}

111 112 113
if (isset($_REQUEST['PHPSESSID'])) {
	$tikilib->setSessionId($_REQUEST['PHPSESSID']);
}
changi67's avatar
changi67 committed
114
elseif (function_exists('session_id')) $tikilib->setSessionId(session_id());
115

116 117 118 119 120
// Session info needs to be kept up to date if pref login_multiple_forbidden is set
if ( $prefs['login_multiple_forbidden'] == 'y' ) {
	$tikilib->update_session();
}

121 122
require_once ('lib/setup/cookies.php');

123
if ($prefs['mobile_feature'] === 'y') {
124
	require_once ('lib/setup/mobile.php');	// needs to be before js_detect but after cookies
125 126
} else {
	$prefs['mobile_mode'] = '';
127 128
}

changi67's avatar
changi67 committed
129 130
require_once ('lib/setup/user_prefs.php');
require_once ('lib/setup/language.php');
131
require_once ('lib/setup/javascript.php');
changi67's avatar
changi67 committed
132
require_once ('lib/setup/wiki.php');
133 134 135 136 137

/* Cookie consent setup, has to be after the JS decision and wiki setup */

$cookie_consent_html = '';
if ($prefs['cookie_consent_feature'] === 'y') {
138
	if (!empty($_REQUEST['cookie_consent_checkbox']) || $prefs['site_closed'] === 'y') {
139
		// js disabled
140
		setCookieSection($prefs['cookie_consent_name'], 'y');	// set both real cookie and tiki_cookie_jar
141 142 143 144 145 146 147 148 149 150
		$feature_no_cookie = false;
		setCookieSection($prefs['cookie_consent_name'], 'y');
	}
	$cookie_consent = getCookie($prefs['cookie_consent_name']);
	if (empty($cookie_consent)) {
		if ($prefs['javascript_enabled'] !== 'y') {
			$prefs['cookie_consent_mode'] = '';
		} else {
			$headerlib->add_js('jqueryTiki.no_cookie = true; jqueryTiki.cookie_consent_alert = "' . addslashes($prefs['cookie_consent_alert']) . '";');
		}
151
		foreach ($_COOKIE as $k => $v) {
152 153 154
			if (strpos($k, session_name()) === false) {
				setcookie($k, '', time() - 3600);        // unset any previously existing cookies except the session
			}
155
		}
156 157 158 159 160 161 162
		$cookie_consent_html = $smarty->fetch('cookie_consent.tpl');
	} else {
		$feature_no_cookie = false;
	}
}
$smarty->assign('cookie_consent_html', $cookie_consent_html);

163 164 165 166 167 168
if ($prefs['feature_polls'] == 'y') {
	require_once ('lib/setup/polls.php');
}
if ($prefs['feature_mailin'] == 'y') {
	require_once ('lib/setup/mailin.php');
}
169
require_once ('lib/setup/tikiIndex.php');
170 171 172
if ($prefs['useGroupHome'] == 'y') {
	require_once ('lib/setup/default_homepage.php');
}
173 174 175
if ($prefs['tracker_force_fill'] == 'y') {
	require_once ('lib/setup/tracker_force_fill.php');
}
176
// change $prefs['tikiIndex'] if feature_sefurl is enabled (e.g. tiki-index.php?page=HomePage becomes HomePage)
177
if ($prefs['feature_sefurl'] == 'y' && ! defined('TIKI_CONSOLE')) {
178 179 180
	//TODO: need a better way to know which is the type of the tikiIndex URL (wiki page, blog, file gallery etc)
	//TODO: implement support for types other than wiki page and blog
	if ($prefs['tikiIndex'] == 'tiki-index.php' && $prefs['wikiHomePage']) {
lphuberdeau's avatar
lphuberdeau committed
181
		$wikilib = TikiLib::lib('wiki');
182
		$prefs['tikiIndex'] = $wikilib->sefurl($userlib->best_multilingual_page($prefs['wikiHomePage']));
183 184
	} else if (substr($prefs['tikiIndex'], 0, strlen('tiki-view_blog.php')) == 'tiki-view_blog.php') {
		include_once('tiki-sefurl.php');
185
		$prefs['tikiIndex'] = filter_out_sefurl($prefs['tikiIndex'], 'blog');
186
	}
187
}
188

changi67's avatar
changi67 committed
189 190
require_once ('lib/setup/theme.php');
if (!empty($varcheck_errors)) {
191
	$smarty->assign('msg', $varcheck_errors);
192
	$smarty->display('error_raw.tpl');
193
	die;
194
}
drsassafras's avatar
drsassafras committed
195 196 197
if ($prefs['feature_challenge'] == 'y') {
	require_once ('lib/setup/challenge.php');
}
198 199 200 201 202 203 204 205 206
if ($prefs['feature_usermenu'] == 'y') {
	require_once ('lib/setup/usermenu.php');
}
if ($prefs['feature_live_support'] == 'y') {
	require_once ('lib/setup/live_support.php');
}
if ($prefs['feature_referer_stats'] == 'y' || $prefs['feature_stats'] == 'y') {
	require_once ('lib/setup/stats.php');
}
changi67's avatar
changi67 committed
207 208 209
require_once ('lib/setup/dynamic_variables.php');
require_once ('lib/setup/output_compression.php');
if ($prefs['feature_debug_console'] == 'y') {
210 211 212
	// Include debugger class declaration. So use loggin facility in php files become much easier :)
	include_once ('lib/debug/debugger.php');
}
213 214 215 216 217 218 219 220 221
if ($prefs['feature_integrator'] == 'y') {
	require_once ('lib/setup/integrator.php');
}
if (isset($_REQUEST['comzone'])) {
	require_once ('lib/setup/comments_zone.php');
}
if ($prefs['feature_lastup'] == 'y') {
	require_once ('lib/setup/last_update.php');
}
changi67's avatar
changi67 committed
222
if (!empty($_SESSION['interactive_translation_mode']) && ($_SESSION['interactive_translation_mode'] == 'on')) {
223
	$cachelib->empty_cache('templates_c');
224
}
225 226 227
if ($prefs['feature_freetags'] == 'y') {
	require_once ('lib/setup/freetags.php');
}
228
if ($prefs['feature_areas'] == 'y' && $prefs['feature_categories'] == 'y' && $prefs['categories_used_in_tpl'] == 'y') {
229
	require_once ('lib/setup/categories.php');
230
	$areaslib = TikiLib::lib('areas');
231
	$areaslib->HandleObjectCategories($objectCategoryIdsNoJail);
232 233
} elseif ($prefs['feature_categories'] == 'y') {
	require_once ('lib/setup/categories.php');
oeversetten's avatar
 
oeversetten committed
234
}
235 236 237 238 239 240
if ($prefs['feature_userlevels'] == 'y') {
	require_once ('lib/setup/userlevels.php');
}
if ($prefs['auth_method'] == 'openid') {
	require_once ('lib/setup/openid.php');
}
changi67's avatar
changi67 committed
241
if ($prefs['feature_wysiwyg'] == 'y') {
242 243 244
	if (!isset($_SESSION['wysiwyg'])) {
		$_SESSION['wysiwyg'] = 'n';
	}
245
	$smarty->assign_by_ref('wysiwyg', $_SESSION['wysiwyg']);
246
}
247

248

249 250
if ($prefs['feature_antibot'] == 'y' && empty($user)) {
	if ($prefs['recaptcha_enabled'] === 'y') {
ameoba32's avatar
ameoba32 committed
251 252 253 254 255
		if ($prefs['recaptcha_version'] == '2') {
			$headerlib->add_jsfile_cdn("$url_scheme://www.google.com/recaptcha/api.js");
		} else {
			$headerlib->add_jsfile_cdn("$url_scheme://www.google.com/recaptcha/api/js/recaptcha_ajax.js");
		}
256
	}
257 258
	$captchalib = TikiLib::lib('captcha');
	$smarty->assign('captchalib', $captchalib);
259
}
260

261 262 263 264
if ($prefs['feature_credits'] == 'y') {
	require_once('lib/setup/credits.php');
}

265
if ( $prefs['https_external_links_for_users'] == 'y' ) {
266
	$base_url_canonical_default = $base_url_https;
267
} else {
268 269 270 271 272 273 274
	$base_url_canonical_default = $base_url_http;
}

if ( !empty($prefs['feature_canonical_domain']) ) {
	$base_url_canonical = $prefs['feature_canonical_domain'];
} else {
	$base_url_canonical = $base_url_canonical_default;
275
}
276 277 278 279
// Since it's easier to be error-resistant than train users, ensure base_url_canonical ends with '/'
if ( substr($base_url_canonical,-1) != '/' ) {
	$base_url_canonical .= '/';
}
280

281 282 283 284 285
$smarty->assign_by_ref('phpErrors', $phpErrors);
$smarty->assign_by_ref('num_queries', $num_queries);
$smarty->assign_by_ref('elapsed_in_db', $elapsed_in_db);
$smarty->assign_by_ref('crumbs', $crumbs);
$smarty->assign('lock', false);
286 287 288
$smarty->assign('edit_page', 'n');
$smarty->assign('forum_mode', 'n');
$smarty->assign('uses_tabs', 'n');
289
$smarty->assign('wiki_extras', 'n');
290 291 292 293 294 295
$smarty->assign('tikipath', $tikipath);
$smarty->assign('tikiroot', $tikiroot);
$smarty->assign('url_scheme', $url_scheme);
$smarty->assign('url_host', $url_host);
$smarty->assign('url_port', $url_port);
$smarty->assign('url_path', $url_path);
296
$smarty->assign('dir_level', $dir_level);
297 298 299 300
$smarty->assign('base_host', $base_host);
$smarty->assign('base_url', $base_url);
$smarty->assign('base_url_http', $base_url_http);
$smarty->assign('base_url_https', $base_url_https);
301
$smarty->assign('base_url_canonical', $base_url_canonical);
302
$smarty->assign('base_url_canonical_default', $base_url_canonical_default);
303 304
$smarty->assign('show_stay_in_ssl_mode', $show_stay_in_ssl_mode);
$smarty->assign('stay_in_ssl_mode', $stay_in_ssl_mode);
305 306
$smarty->assign('tiki_version', $TWV->version);
$smarty->assign('tiki_branch', $TWV->branch);
307
$smarty->assign('tiki_star', $TWV->getStar());
308
$smarty->assign('tiki_uses_svn', $TWV->svn);
309

310 311
$smarty->assign('symbols', TikiLib::symbols());

312 313 314 315
if ( isset( $_GET['msg'] ) ) {
	$smarty->assign('display_msg', $_GET['msg']);
} elseif ( isset( $_SESSION['msg'] ) ) {
	$smarty->assign('display_msg', $_SESSION['msg']);
316 317
	unset($_SESSION['msg']);
} else {
318
	$smarty->assign('display_msg', '');
319 320
}

321 322 323 324 325 326 327 328 329
if ( isset( $_GET['msgtype'] ) ) {
	$smarty->assign('display_msgtype', $_GET['msgtype']);
} elseif ( isset( $_SESSION['msgtype'] ) ) {
	$smarty->assign('display_msgtype', $_SESSION['msgtype']);
	unset($_SESSION['msgtype']);
} else {
	$smarty->assign('display_msgtype', '');
}

330 331
require_once 'lib/setup/events.php';

332
if ( $prefs['rating_advanced'] == 'y' && $prefs['rating_recalculation'] == 'randomload' ) {
lphuberdeau's avatar
lphuberdeau committed
333
	$ratinglib = TikiLib::lib('rating');
334 335 336
	$ratinglib->attempt_refresh();
}

337
$headerlib->add_jsfile('lib/tiki-js.js');
338

339
// using jquery-migrate-1.3.0.js plugin for tiki 11, still required in tiki 12 LTS to support some 3rd party plugins
340

341
if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'google' ) {
342 343
	$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
344
	$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate-min/jquery-migrate-$headerlib->jquerymigrate_version.min.js", true);
345
} else if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
346
	$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/jquery-$headerlib->jquery_version.min.js");
347
	$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/jquery-migrate-$headerlib->jquerymigrate_version.min.js");
348
} else {
349 350
	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);
351
		$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate-min/jquery-migrate-$headerlib->jquerymigrate_version.min.js", true);
352
	} else {
353
		$headerlib->add_jsfile_dependancy("vendor/jquery/jquery/jquery-$headerlib->jquery_version.js", true);
354
		$headerlib->add_jsfile_dependancy("vendor/jquery/plugins/migrate/jquery-migrate-$headerlib->jquerymigrate_version.js", true);
355
	}
356
}
357

358
if ( isset($prefs['fgal_elfinder_feature']) && $prefs['fgal_elfinder_feature'] === 'y' ) {
359
	$str = $prefs['tiki_minify_javascript'] === 'y' ? 'min' : 'full';
360 361 362
	// elfinder is sensible to js compression - problem is inside elfinder
	// see http://stackoverflow.com/questions/11174170/js-invalid-left-hand-side-expression-in-postfix-operation for more general details
	$headerlib->add_jsfile('vendor_extra/elfinder/js/elfinder.' . $str . '.js', true)
363
			->add_cssfile('vendor_extra/elfinder/css/elfinder.' . $str . '.css')
364 365 366 367 368 369 370
			->add_jsfile('lib/jquery_tiki/elfinder/tiki-elfinder.js');

	$elFinderLang = str_replace(array('cn', 'pt-br'), array('zh_CN', 'pt_BR'), $language);

	if (file_exists('vendor_extra/elfinder/js/i18n/elfinder.' . $elFinderLang . '.js')) {
		$headerlib->add_jsfile('vendor_extra/elfinder/js/i18n/elfinder.' . $elFinderLang . '.js');
	}
371
}
372

373
$headerlib->add_jsfile('lib/jquery_tiki/tiki-jquery.js');
374

375 376 377 378 379 380
if (isset($_REQUEST['geo_zoomlevel_to_found_location'])) {
	$zoomToFoundLocation = $_REQUEST['geo_zoomlevel_to_found_location'];
} else {
	$zoomToFoundLocation = isset($prefs['geo_zoomlevel_to_found_location']) ? $prefs['geo_zoomlevel_to_found_location'] : 'street';
}
$headerlib->add_js('var zoomToFoundLocation = "'.$zoomToFoundLocation.'";');	// Set the zoom option after searching for a location
381

382 383 384 385 386
if ($prefs['geo_openlayers_version'] === 'ol3') {
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-maps-ol3.js');
} else {
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-maps.js');
}
387
$headerlib->add_jsfile('vendor/jquery/plugins/jquery-json/src/jquery.json.js');
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409

if ($prefs['feature_jquery_zoom'] === 'y') {
	$headerlib->add_jsfile('vendor/jquery/plugins/zoom/jquery.zoom.js')
		->add_css('
.img_zoom {
	display:inline-block;
}
.img_zoom:after {
	content:"";
	display:block;
	width:33px;
	height:33px;
	position:absolute;
	top:0;
	right:0;
	background:url(vendor/jquery/plugins/zoom/icon.png);
}
.img_zoom img {
	display:block;
}
');
}
410

411 412 413
if ($prefs['feature_syntax_highlighter'] == 'y') {
	//add codemirror stuff
	$headerlib
414 415
		->add_cssfile('vendor/codemirror/codemirror/lib/codemirror.css')
		->add_jsfile_dependancy('vendor/codemirror/codemirror/lib/codemirror.js')
416
		->add_jsfile('vendor/codemirror/codemirror/addon/search/searchcursor.js')
417
		->add_jsfile('vendor/codemirror/codemirror/addon/mode/overlay.js')
418 419
	//add tiki stuff
		->add_cssfile('lib/codemirror_tiki/codemirror_tiki.css')
420
		->add_jsfile('lib/codemirror_tiki/codemirror_tiki.js');
421

422
	require_once("lib/codemirror_tiki/tiki_codemirror.php");
423
	createCodemirrorModes();
424
}
425
if ($prefs['feature_wikilingo'] == 'y') {
426 427 428 429
	$headerlib
		//flp stuff
		->add_cssfile('vendor/jquery/plugins/tablesorter/css/theme.dropbox.css')
		->add_jsfile('vendor/jquery/plugins/tablesorter/js/jquery.tablesorter.js');
430 431
}

432 433 434
if ( $prefs['feature_jquery_carousel'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/infinitecarousel/jquery.infinitecarousel3.js');
}
435

436
if ( $prefs['feature_ajax'] === 'y' ) {
437
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-ajax_services.js');
438 439
	if ( $prefs['ajax_autosave'] === 'y' ) {
		$headerlib->add_jsfile('lib/ajax/autosave.js');
440
	}
441
}
442

443 444
// $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
445 446
if ( $prefs['feature_jquery_ui'] == 'y' ) {
	if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'google' ) {
447
		$headerlib->add_jsfile_cdn("$url_scheme://ajax.googleapis.com/ajax/libs/jqueryui/$headerlib->jqueryui_version/jquery-ui.min.js");
448
	} else if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
449
		$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/ui/$headerlib->jqueryui_version/jquery-ui.min.js");
450 451
	} else {
		if ( $prefs['tiki_minify_javascript'] === 'y' ) {
452
			$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-ui/jquery-ui.min.js", true);
453
		} else {
454
			$headerlib->add_jsfile_dependancy("vendor/jquery/jquery-ui/jquery-ui.js");
455
		}
456
	}
457

458 459
	// restore jquery-ui buttons function, thanks to http://stackoverflow.com/a/23428433/2459703
	$headerlib->add_js('
460 461 462 463 464
var bootstrapButton;
if (typeof $.fn.button.noConflict === "function") {
	bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
	$.fn.bootstrapBtn = bootstrapButton            // give $().bootstrapBtn the Bootstrap functionality
}
465 466
');

467 468
	if ( $prefs['feature_jquery_ui_theme'] !== 'none' ) {
		if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
469 470 471
			// // cdn for css not working - this is the only css from a cdn anyway - so use local version 
			// $headerlib->add_cssfile("$url_scheme://code.jquery.com/ui/$headerlib->jqueryui_version/themes/{$prefs['feature_jquery_ui_theme']}/jquery-ui.css");
			$headerlib->add_cssfile('vendor/jquery/jquery-ui-themes/themes/' . $prefs['feature_jquery_ui_theme'] . '/jquery-ui.css');
472
		} else {
473
			$headerlib->add_cssfile('vendor/jquery/jquery-ui-themes/themes/' . $prefs['feature_jquery_ui_theme'] . '/jquery-ui.css');
474
		}
475
	}
476

477 478 479 480 481 482 483
	if ( $prefs['feature_jquery_autocomplete'] == 'y' ) {
		$headerlib->add_css(
			'.ui-autocomplete-loading { background: white url("img/spinner.gif") right center no-repeat; }'
		);
	}
	if ( $prefs['jquery_ui_chosen'] == 'y' ) {
		$headerlib->add_jsfile('vendor/jquery/plugins/chosen/chosen.jquery.js');
484
	//	$headerlib->add_cssfile('vendor/jquery/plugins/chosen/chosen.css'); Replaced by github.com/alxlit/bootstrap-chosen
485 486 487
		$headerlib->add_css(
			'select { font-size: 16px; padding: 4px; border-color:#fff; /* this forces chrome to apply the font-size */ }'
		);
488
	}
489 490 491
	$headerlib->add_jsfile('vendor/jquery/jquery-timepicker-addon/dist/jquery-ui-timepicker-addon.js');
	$headerlib->add_cssfile('vendor/jquery/jquery-timepicker-addon/dist/jquery-ui-timepicker-addon.css');
}
492 493 494 495
if ( $prefs['jquery_fitvidjs'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/fitvidjs/jquery.fitvids.js')
				->add_jq_onready('$("article").fitVids();');		// apply fitvid to any video in the middle section
}
496 497 498 499 500 501 502 503 504 505 506 507 508 509
if ( $prefs['feature_jquery_superfish'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/superfish/dist/js/superfish.js');
	$headerlib->add_jsfile('vendor/jquery/plugins/superfish/dist/js/supersubs.js');
}
if ( $prefs['feature_jquery_tooltips'] === 'y' || $prefs['feature_jquery_superfish'] === 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/superfish/dist/js/hoverIntent.js');
}
if ( $prefs['feature_jquery_reflection'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/reflection-jquery/js/reflection.js');
}
if ( $prefs['feature_jquery_media'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/media/jquery.media.js');
}
if ( $prefs['feature_jquery_tablesorter'] == 'y' ) {
510
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/jquery.tablesorter.combined.js');
511
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-pager.js');
512 513
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-filter-formatter-jui.js');
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-grouping.js');
514
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-columnSelector.js');
515
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/parsers/parser-input-select.js');
516
	$headerlib->add_jsfile('vendor/jquery/plugins/tablesorter/js/widgets/widget-math.js');
517
}
gezzzan's avatar
gezzzan committed
518 519 520 521 522

if ( $prefs['feature_jquery_tagcanvas'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/tagcanvas/jquery.tagcanvas.js');
}

523 524 525 526
if ( $prefs['feature_shadowbox'] == 'y' ) {
	$headerlib->add_jsfile('vendor/jquery/plugins/colorbox/jquery.colorbox.js');
	$headerlib->add_cssfile('vendor/jquery/plugins/colorbox/' . $prefs['jquery_colorbox_theme'] . '/colorbox.css');
}
527

528 529 530
if ( $prefs['wikiplugin_flash'] == 'y' ) {
	$headerlib->add_jsfile('lib/swfobject/swfobject.js');
}
531 532 533 534 535 536 537
if ($prefs['jquery_timeago'] === 'y') {
	$headerlib->add_jsfile('vendor/jquery/plugins/timeago/jquery.timeago.js');
	$language_short = substr($prefs['language'], 0, 2);
	$timeago_locale = "vendor/jquery/plugins/timeago/locales/jquery.timeago.{$language_short}.js";
	if (is_readable($timeago_locale)) {
		$headerlib->add_jsfile($timeago_locale);	// TODO handle zh-CN and zh-TW
	}
538
	$headerlib->add_jq_onready('$("time.timeago").timeago(); jQuery.timeago.settings.allowFuture = true;');
539
}
540 541

if ( $prefs['feature_jquery_validation'] == 'y' ) {
542
	$headerlib->add_jsfile('vendor/jquery/plugins/jquery-validation/dist/jquery.validate.js');
543
	$headerlib->add_jsfile('lib/validators/validator_tiki.js');
544 545
}

546 547
// note: jquery.async.js load a copy of jquery
$headerlib->add_jsfile('vendor/jquery/plugins/async/jquery.async.js');
548 549
$headerlib->add_jsfile('vendor/jquery/plugins/treetable/javascripts/src/jquery.treetable.js');
$headerlib->add_cssfile('vendor/jquery/plugins/treetable/stylesheets/jquery.treetable.css');
550

551 552
$headerlib->add_jsfile('vendor/cwspear/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js');

553 554 555 556
if ($prefs['feature_equal_height_rows_js'] == 'y'){
	$headerlib->add_jsfile("vendor/Sam152/Javascript-Equal-Height-Responsive-Rows/grids.min.js");
}

557
if (empty($user) && $prefs['feature_antibot'] == 'y') {
558
	$headerlib->add_jsfile_late('lib/captcha/captchalib.js');
559 560 561 562 563
}

if ( $prefs['feature_jcapture'] === 'y' ) {
	$headerlib->add_jsfile('lib/jcapture_tiki/tiki-jcapture.js');
}
564

565
if ( ! empty( $prefs['header_custom_css'] ) ) {
566
	$headerlib->add_css($prefs['header_custom_css']);
567 568
}

569
if ( ! empty( $prefs['header_custom_js'] ) ) {
570
	$headerlib->add_js($prefs['header_custom_js']);
571 572
}

573 574 575 576
if ($prefs['feature_file_galleries'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/files.js');
}

577 578
if ($prefs['feature_trackers'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-trackers.js');
579 580 581

	if ($prefs['feed_tracker'] === 'y') {
		$opts = TikiLib::lib('trk')->get_trackers_options(null, 'publishRSS', 'y');
582
		foreach ($opts as & $o) {
583 584 585 586 587
			$o = $o['trackerId'];
		}
		$trackers = TikiLib::lib('trk')->list_trackers();

		$rss_trackers = array();
588
		foreach ($trackers['data'] as $trk) {
589 590 591 592 593 594 595 596 597 598
			if (in_array($trk['trackerId'], $opts)) {
				$rss_trackers[] = array(
					'trackerId' => $trk['trackerId'],
					'name' => $trk['name'],
				);
			}
		}
		TikiLib::lib('smarty')->assign('rsslist_trackers', $rss_trackers);
	}

599 600
}

601
if ($prefs['feature_draw'] == 'y') {
602 603
	//svg-edit/empbedapi.js neededs to be external - why?
	$headerlib->add_jsfile("vendor/svg-edit/svg-edit/embedapi.js");
604 605 606 607
	$headerlib->add_jsfile("lib/svg-edit_tiki/draw.js");
	$headerlib->add_cssfile("lib/svg-edit_tiki/draw.css");
}

608 609 610 611
if ($prefs['geo_always_load_openlayers'] == 'y') {
	$headerlib->add_map();
}

612 613 614 615
if ($prefs['workspace_ui'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-workspace-ui.js');
}

616
if ($prefs['feature_sefurl'] != 'y') {
617
	$headerlib->add_js(
618
		'$.service = function (controller, action, query) {
619 620 621 622 623
		if (! query) {
			query = {};
		}
		query.controller = controller;

624
		if (action) {
625
			query.action = action;
626
		}
627

628
		return "tiki-ajax_services.php?" + $.buildParams(query);
629
	};'
630
	);
631 632
}

633
if ($prefs['feature_friends'] == 'y' || $prefs['monitor_enabled'] == 'y') {
634 635 636
	$headerlib->add_jsfile('lib/jquery_tiki/social.js');
}

637 638 639 640
if ($prefs['ajax_inline_edit'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/inline_edit.js');
}

641 642 643 644
if ($prefs['mustread_enabled'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/mustread.js');
}

645 646 647
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.
648 649 650
	
	// This is not a very helpful comment...
	$headerlib->add_jsfile_dynamic('tiki-jsplugin.php?language='.$prefs['language']);
651
	if ($prefs['wikiplugin_module'] === 'y' && $prefs['wikiplugininline_module'] === 'n') {
652
		$headerlib->add_jsfile_dynamic('tiki-jsmodule.php?language='.$prefs['language']);
653 654 655
	}
}

656 657
if ( session_id() ) {
	if ( $prefs['tiki_cachecontrol_session'] ) {
658
		header('Cache-Control: ' . $prefs['tiki_cachecontrol_session']);
659 660
	}
} else {
661
	if ( $prefs['tiki_cachecontrol_nosession'] ) {
662
		header('Cache-Control: ' . $prefs['tiki_cachecontrol_nosession']);
663 664
	}
}
665

666 667 668 669 670 671 672 673
if ( !empty($prefs['access_control_allow_origin']) && !empty($_SERVER['HTTP_ORIGIN']) && $base_host !== $_SERVER['HTTP_ORIGIN']) {
	$http_origin = $_SERVER['HTTP_ORIGIN'];

	if (in_array($http_origin, preg_split('/[\s,]+/', $prefs['access_control_allow_origin']))) {
	    header("Access-Control-Allow-Origin: $http_origin");
	}
}

674 675 676 677 678 679
if ( isset($token_error) ) {
	$smarty->assign('token_error', $token_error);
	$smarty->display('error.tpl');
	die;
}

680 681
require_once( 'lib/setup/plugins_actions.php' );

682
if ($tiki_p_admin == 'y') {
683
	$headerlib->add_jsfile_late('lib/jquery_tiki/tiki-admin.js');
684 685
}

686 687 688 689
if ($prefs['wikiplugin_addtocart'] == 'y') {
	$headerlib->add_jsfile('lib/payment/cartlib.js');
}

690
//////////////////////////////////////////////////////////////////////////
kstingel's avatar
kstingel committed
691 692 693 694 695 696 697 698 699 700 701
// ******************************************************************** //
// ** IMPORTANT NOTE:                                                ** //
// ** USE THE GLOBAL VARIABLE BELOW TO CONTROL THE VERSION OF EMAIL  ** //
// ** WHICH IS USED                                                  ** //
// **   $prefs['openpgp_gpg_pgpmimemail'] == 'y'                     ** //
// **       USE TIKI OpenPGP Enabled PGP/MIME-standard mail          ** //
// **   $prefs['openpgp_gpg_pgpmimemail'] == 'n'                     ** //
// **       USE TIKI normal mail functionality                       ** //
// **                                                                ** //
// ** SETTING THIS PREFERENCES VARIABLE TO "y" NEED PROPER           ** //
// ** CONFIGURATION OF gnupg AND RELATED KEYRING WITH PROPERLY       ** //
702
// ** CONFIGURED TIKI-SENDER KEYPAIR (PRIVATE/PUBLIC) AND ALL USER   ** //
kstingel's avatar
kstingel committed
703 704 705
// ** ACCOUNT-RELATED PUBLIC KEYS                                    ** //
// **                                                                ** //
// ** DO NOT SWITCH THIS VARIABLE TO TRUE FOR THIS EXPERIMENTAL      ** //
706
// ** FULLY PGP/MIME-ENCRYPTION COMPLIANT EMAIL FUNCTIONALITY, IF    ** //
kstingel's avatar
kstingel committed
707 708 709
// ** YOU ARE **NOT ABSOLUTE SURE HOW TO CONFIGURE IT**!             ** //
// **                                                                ** //
// ** ONCE PROPERLY CONFIGURED, SUCH 100% OPAQUE FUNCTIONALITY       ** //
710
// ** DELIVERS ROBUST END-TO-END PRIVACY WITH HIGH DEGREE OF TESTED  ** //
kstingel's avatar
kstingel committed
711 712 713 714 715 716
// ** ROBUSTNESS FOR THE FOLLOWING MAIL TRAFFIC:                     ** //
// **                                                                ** //
// **   - all webmail-based messaging from messu-compose.php         ** //
// **   - all admin notifications                                    ** //
// **   - all newsletters                                            ** //
// **                                                                ** //
717 718 719 720
// ** PLEASE NOTE THAT ALL SITE ACCOUNTS **MUST** HAVE PROPERLY	     ** //
// ** CONFIGURED OpenPGP-COMPLIANT PUBLIC-KEY IN THE SYSTEM's	     ** //
// ** KEYRING, SO IT IS NOT THEN WISE/POSSIBLE TO ALLOW ANONYMOUS    ** //
// ** SUBSCRIPTIONS TO NEWSLETTERS ETC, OR USE NOT FULLY PGP/MIME    ** //
kstingel's avatar
kstingel committed
721 722 723 724 725
// ** READY ACCOUNTS IN SUCH SYSTEM.                                 ** //
// **                                                                ** //
// ** IT IS ASSUMED, THAT IF AND WHEN YOU TURN SUCH PGP/MIME ON      ** //
// ** YOU ARE FULLY AWARE OF THE REQUIREMENTS AND CONSEQUENCES.      ** //
// **                                                                ** //
726
if ($prefs['openpgp_gpg_pgpmimemail'] == 'y') {
727 728 729 730
	// hollmeer 2012-11-03:
	// TURNED ON openPGP support from a lib based class
	require_once( 'lib/openpgp/openpgplib.php' );
}
kstingel's avatar
kstingel committed
731 732
// **                                                                ** //
// ******************************************************************** //
733 734
//////////////////////////////////////////////////////////////////////////

735
if( $prefs['feature_hidden_links'] == 'y' && isset($jitRequest['wysiwyg']) && $jitRequest['wysiwyg'] != 'y') {
736 737 738 739 740 741
	$headerlib->add_js("$('body').find('h1, h2, h3, h4, h5, h6').each(function() {
	var headerid = $(this).attr('id');
		if(headerid != undefined) {
			$(this).append('<a class=\"tiki_anchor\" href=\"#'+headerid+'\"></a>');
		}
	});");
742 743
}

744 745 746
// 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();
747 748

if ( $prefs['conditions_enabled'] == 'y' ) {
749 750 751 752 753 754
	if (! Services_User_ConditionsController::hasRequiredAge($user)) {
		$servicelib = TikiLib::lib('service');
		$broker = $servicelib->getBroker();
		$broker->process('user_conditions', 'age_validation', $jitRequest);
		exit;
	}
755 756 757 758 759 760 761
	if (Services_User_ConditionsController::requiresApproval($user)) {
		$servicelib = TikiLib::lib('service');
		$broker = $servicelib->getBroker();
		$broker->process('user_conditions', 'approval', $jitRequest);
		exit;
	}
}