tiki-setup.php 31.6 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 21

ini_set('session.cookie_httponly', 1);

22 23
if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
	header('location: index.php');
changi67's avatar
changi67 committed
24
	exit;
redflo's avatar
redflo committed
25
}
rjsmelo's avatar
rjsmelo committed
26 27
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
	if (php_sapi_name() != 'cli') {					// if not running a command line version of php, show requirements
28 29 30
		header('location: tiki-install.php');
		exit;
	}
31
	// This is command-line. No 'location' command make sense here. Let admins access what works and deal with the rest.
32
	echo "Warning: Tiki16 and above expects PHP 5.6.0 and above. You are running " . phpversion() . " at your own risk\n";
33
}
34 35 36 37

// 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);

38 39 40 41 42 43 44 45
// Ensure that we clean PROXY headers
if (! empty($_SERVER['HTTP_PROXY'])) {
	$_SERVER['HTTP_PROXY_RENAMED'] = $_SERVER['HTTP_PROXY'];
	unset($_SERVER['HTTP_PROXY']);
	putenv('HTTP_PROXY');
	putenv('PHP_PEAR_HTTP_PROXY=');
}

46
require_once 'lib/setup/third_party.php';
47
// Enable Versioning
rjsmelo's avatar
rjsmelo committed
48
include_once('lib/setup/twversion.class.php');
49
$TWV = new TWVersion();
50 51 52 53
$num_queries = 0;
$elapsed_in_db = 0.0;
$server_load = '';
$area = 'tiki';
rjsmelo's avatar
rjsmelo committed
54 55 56
$crumbs = [];
require_once('lib/setup/tikisetup.class.php');
require_once('lib/setup/timer.class.php');
57 58
$tiki_timer = new timer();
$tiki_timer->start();
rjsmelo's avatar
rjsmelo committed
59
require_once('tiki-setup_base.php');
60 61

// Attempt setting locales. This code is just a start, locales should be set per-user.
62
// 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.
63
setlocale(LC_ALL, ''); // Attempt changing the locale to the system default.
64
// 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.
65
// This will have no effect if the locale string is not valid or if the designated locale is not generated.
66

rjsmelo's avatar
rjsmelo committed
67
foreach (['en_US.utf8'] as $UnicodeLocale) {
68 69 70 71
	if (setlocale(LC_COLLATE, $UnicodeLocale)) {
		break;
	}
}
72

73
if ($prefs['feature_tikitests'] == 'y') {
rjsmelo's avatar
rjsmelo committed
74
	require_once('tiki_tests/tikitestslib.php');
75
}
76
$crumbs[] = new Breadcrumb($prefs['browsertitle'], '', $prefs['tikiIndex']);
77
if ($prefs['site_closed'] == 'y') {
rjsmelo's avatar
rjsmelo committed
78
	require_once('lib/setup/site_closed.php');
79
}
rjsmelo's avatar
rjsmelo committed
80
require_once('lib/setup/error_reporting.php');
81
if ($prefs['use_load_threshold'] == 'y') {
rjsmelo's avatar
rjsmelo committed
82
	require_once('lib/setup/load_threshold.php');
83
}
rjsmelo's avatar
rjsmelo committed
84
require_once('lib/setup/sections.php');
85
/** @var HeaderLib $headerlib */
86
$headerlib = TikiLib::lib('header');
87

rjsmelo's avatar
rjsmelo committed
88 89
$domain_map = [];
if (isset($_SERVER['HTTP_HOST'])) {
90 91 92 93
	$host = $_SERVER['HTTP_HOST'];
} else {
	$host = "";
}
rjsmelo's avatar
rjsmelo committed
94
if (isset($_SERVER['REQUEST_URI'])) {
95 96 97 98
	$requestUri = $_SERVER['REQUEST_URI'];
} else {
	$requestUri = "";
}
99

rjsmelo's avatar
rjsmelo committed
100
if ($prefs['tiki_domain_prefix'] == 'strip' && substr($host, 0, 4) == 'www.') {
101
	$domain_map[$host] = substr($host, 4);
rjsmelo's avatar
rjsmelo committed
102
} elseif ($prefs['tiki_domain_prefix'] == 'force' && substr($host, 0, 4) != 'www.') {
103 104
	$domain_map[$host] = 'www.' . $host;
}
105

106
if (strpos($prefs['tiki_domain_redirects'], ',') !== false) {
107
	foreach (explode("\n", $prefs['tiki_domain_redirects']) as $row) {
108 109
		list($old, $new) = array_map('trim', explode(',', $row, 2));
		$domain_map[$old] = $new;
110
	}
111 112
	unset($old);
	unset($new);
113 114
}

rjsmelo's avatar
rjsmelo committed
115
if (isset($domain_map[$host]) && ! defined('TIKI_CONSOLE')) {
116
	$prefix = $tikilib->httpPrefix();
117
	$prefix = str_replace("://$host", "://{$domain_map[$host]}", $prefix);
118
	$url = $prefix . $requestUri;
119

120
	$access->redirect($url, null, 301);
121 122 123
	exit;
}

124 125
if (isset($_REQUEST['PHPSESSID'])) {
	$tikilib->setSessionId($_REQUEST['PHPSESSID']);
rjsmelo's avatar
rjsmelo committed
126 127
} elseif (function_exists('session_id')) {
	$tikilib->setSessionId(session_id());
128
}
129

130
// Session info needs to be kept up to date if pref login_multiple_forbidden is set
rjsmelo's avatar
rjsmelo committed
131
if ($prefs['login_multiple_forbidden'] == 'y') {
132 133 134
	$tikilib->update_session();
}

rjsmelo's avatar
rjsmelo committed
135
require_once('lib/setup/cookies.php');
136

137
if ($prefs['mobile_feature'] === 'y') {
rjsmelo's avatar
rjsmelo committed
138
	require_once('lib/setup/mobile.php');	// needs to be before js_detect but after cookies
139 140
} else {
	$prefs['mobile_mode'] = '';
141 142
}

rjsmelo's avatar
rjsmelo committed
143 144 145 146
require_once('lib/setup/user_prefs.php');
require_once('lib/setup/language.php');
require_once('lib/setup/wiki.php');
require_once('lib/setup/javascript.php');
147

148 149
require_once('lib/setup/theme.php');

150 151 152 153
/* Cookie consent setup, has to be after the JS decision and wiki setup */

$cookie_consent_html = '';
if ($prefs['cookie_consent_feature'] === 'y') {
rjsmelo's avatar
rjsmelo committed
154
	if (! empty($_REQUEST['cookie_consent_checkbox']) || $prefs['site_closed'] === 'y') {
155
		// js disabled
156
		setCookieSection($prefs['cookie_consent_name'], 'y');	// set both real cookie and tiki_cookie_jar
157 158 159 160 161 162 163 164 165 166
		$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']) . '";');
		}
167
		foreach ($_COOKIE as $k => $v) {
168 169 170
			if (strpos($k, session_name()) === false) {
				setcookie($k, '', time() - 3600);        // unset any previously existing cookies except the session
			}
171
		}
172 173 174 175 176 177 178
		$cookie_consent_html = $smarty->fetch('cookie_consent.tpl');
	} else {
		$feature_no_cookie = false;
	}
}
$smarty->assign('cookie_consent_html', $cookie_consent_html);

179
if ($prefs['feature_polls'] == 'y') {
rjsmelo's avatar
rjsmelo committed
180
	require_once('lib/setup/polls.php');
181 182
}
if ($prefs['feature_mailin'] == 'y') {
rjsmelo's avatar
rjsmelo committed
183
	require_once('lib/setup/mailin.php');
184
}
rjsmelo's avatar
rjsmelo committed
185
require_once('lib/setup/tikiIndex.php');
186
if ($prefs['useGroupHome'] == 'y') {
rjsmelo's avatar
rjsmelo committed
187
	require_once('lib/setup/default_homepage.php');
188
}
189
if ($prefs['user_force_avatar_upload'] === 'y') {
rjsmelo's avatar
rjsmelo committed
190
		require_once('lib/setup/avatar_force_upload.php');
191
}
192
if ($prefs['tracker_force_fill'] == 'y') {
rjsmelo's avatar
rjsmelo committed
193
	require_once('lib/setup/tracker_force_fill.php');
194
}
195
// change $prefs['tikiIndex'] if feature_sefurl is enabled (e.g. tiki-index.php?page=HomePage becomes HomePage)
196
if ($prefs['feature_sefurl'] == 'y' && ! defined('TIKI_CONSOLE')) {
197 198 199
	//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
200
		$wikilib = TikiLib::lib('wiki');
201
		$prefs['tikiIndex'] = $wikilib->sefurl($userlib->best_multilingual_page($prefs['wikiHomePage']));
rjsmelo's avatar
rjsmelo committed
202
	} elseif (substr($prefs['tikiIndex'], 0, strlen('tiki-view_blog.php')) == 'tiki-view_blog.php') {
203
		include_once('tiki-sefurl.php');
204
		$prefs['tikiIndex'] = filter_out_sefurl($prefs['tikiIndex'], 'blog');
205
	}
206
}
207

rjsmelo's avatar
rjsmelo committed
208
if (! empty($varcheck_errors)) {
209
	$smarty->assign('msg', $varcheck_errors);
210
	$smarty->display('error_raw.tpl');
211
	die;
212
}
213
if ($prefs['feature_usermenu'] == 'y') {
rjsmelo's avatar
rjsmelo committed
214
	require_once('lib/setup/usermenu.php');
215 216
}
if ($prefs['feature_live_support'] == 'y') {
rjsmelo's avatar
rjsmelo committed
217
	require_once('lib/setup/live_support.php');
218 219
}
if ($prefs['feature_referer_stats'] == 'y' || $prefs['feature_stats'] == 'y') {
rjsmelo's avatar
rjsmelo committed
220
	require_once('lib/setup/stats.php');
221
}
rjsmelo's avatar
rjsmelo committed
222 223
require_once('lib/setup/dynamic_variables.php');
require_once('lib/setup/output_compression.php');
changi67's avatar
changi67 committed
224
if ($prefs['feature_debug_console'] == 'y') {
225
	// Include debugger class declaration. So use loggin facility in php files become much easier :)
rjsmelo's avatar
rjsmelo committed
226
	include_once('lib/debug/debugger.php');
227
}
228
if ($prefs['feature_integrator'] == 'y') {
rjsmelo's avatar
rjsmelo committed
229
	require_once('lib/setup/integrator.php');
230 231
}
if (isset($_REQUEST['comzone'])) {
rjsmelo's avatar
rjsmelo committed
232
	require_once('lib/setup/comments_zone.php');
233 234
}
if ($prefs['feature_lastup'] == 'y') {
rjsmelo's avatar
rjsmelo committed
235
	require_once('lib/setup/last_update.php');
236
}
rjsmelo's avatar
rjsmelo committed
237
if (! empty($_SESSION['interactive_translation_mode']) && ($_SESSION['interactive_translation_mode'] == 'on')) {
238
	$cachelib->empty_cache('templates_c');
239
}
240
if ($prefs['feature_freetags'] == 'y') {
rjsmelo's avatar
rjsmelo committed
241
	require_once('lib/setup/freetags.php');
242
}
rjsmelo's avatar
rjsmelo committed
243 244
if ($prefs['feature_categories'] == 'y') {
	require_once('lib/setup/categories.php');
245 246 247 248
	if ($prefs['feature_areas'] == 'y' &&  $prefs['categories_used_in_tpl'] == 'y') {
		$areaslib = TikiLib::lib('areas');
		$areaslib->HandleObjectCategories($objectCategoryIdsNoJail);
	}
oeversetten's avatar
oeversetten committed
249
}
250
if ($prefs['feature_userlevels'] == 'y') {
rjsmelo's avatar
rjsmelo committed
251
	require_once('lib/setup/userlevels.php');
252 253
}
if ($prefs['auth_method'] == 'openid') {
rjsmelo's avatar
rjsmelo committed
254
	require_once('lib/setup/openid.php');
255
}
changi67's avatar
changi67 committed
256
if ($prefs['feature_wysiwyg'] == 'y') {
rjsmelo's avatar
rjsmelo committed
257
	if (! isset($_SESSION['wysiwyg'])) {
258 259
		$_SESSION['wysiwyg'] = 'n';
	}
260
	$smarty->assign_by_ref('wysiwyg', $_SESSION['wysiwyg']);
261 262
} else {
	$smarty->assign('wysiwyg', 'n');
263
}
264

265

266 267
if ($prefs['feature_antibot'] == 'y' && empty($user)) {
	if ($prefs['recaptcha_enabled'] === 'y') {
268
		if ($prefs['recaptcha_version'] == '2') {
rjsmelo's avatar
rjsmelo committed
269
			if (! empty($prefs['language'])) {
270 271 272
				$headerlib->add_jsfile_cdn("$url_scheme://www.google.com/recaptcha/api.js?hl=" . $prefs['language']);
			} else {
				$headerlib->add_jsfile_cdn("$url_scheme://www.google.com/recaptcha/api.js");
rjsmelo's avatar
rjsmelo committed
273
			}
274 275 276
		} else {
			$headerlib->add_jsfile_cdn("$url_scheme://www.google.com/recaptcha/api/js/recaptcha_ajax.js");
		}
277
	}
278 279
	$captchalib = TikiLib::lib('captcha');
	$smarty->assign('captchalib', $captchalib);
280
}
281

282 283 284 285
if ($prefs['feature_credits'] == 'y') {
	require_once('lib/setup/credits.php');
}

rjsmelo's avatar
rjsmelo committed
286
if ($prefs['https_external_links_for_users'] == 'y') {
287
	$base_url_canonical_default = $base_url_https;
288
} else {
289 290 291
	$base_url_canonical_default = $base_url_http;
}

rjsmelo's avatar
rjsmelo committed
292
if (! empty($prefs['feature_canonical_domain'])) {
293 294 295
	$base_url_canonical = $prefs['feature_canonical_domain'];
} else {
	$base_url_canonical = $base_url_canonical_default;
296
}
297
// Since it's easier to be error-resistant than train users, ensure base_url_canonical ends with '/'
rjsmelo's avatar
rjsmelo committed
298
if (substr($base_url_canonical, -1) != '/') {
299 300
	$base_url_canonical .= '/';
}
301

302 303 304 305 306
$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);
307 308
$smarty->assign('edit_page', 'n');
$smarty->assign('forum_mode', 'n');
309
$smarty->assign('wiki_extras', 'n');
310 311 312 313 314 315
$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);
316
$dir_level = (! empty($dir_level)) ? $dir_level : '';
317
$smarty->assign('dir_level', $dir_level);
318 319 320 321
$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);
322
$smarty->assign('base_url_canonical', $base_url_canonical);
323
$smarty->assign('base_url_canonical_default', $base_url_canonical_default);
324 325
$smarty->assign('show_stay_in_ssl_mode', $show_stay_in_ssl_mode);
$smarty->assign('stay_in_ssl_mode', $stay_in_ssl_mode);
326 327
$smarty->assign('tiki_version', $TWV->version);
$smarty->assign('tiki_branch', $TWV->branch);
328
$smarty->assign('tiki_star', $TWV->getStar());
329
$smarty->assign('tiki_uses_svn', $TWV->svn);
330

331 332
$smarty->assign('symbols', TikiLib::symbols());

333
// Used by TikiAccessLib::redirect()
rjsmelo's avatar
rjsmelo committed
334
if (isset($_GET['msg'])) {
335
	Feedback::add(['mes' => $_GET['msg'], 'type' => $_GET['msgtype']], 'tpl');
rjsmelo's avatar
rjsmelo committed
336
} elseif (isset($_SESSION['msg'])) {
337
	Feedback::add(['mes' => $_SESSION['msg'], 'type' => $_SESSION['msgtype']], 'tpl');
338
	unset($_SESSION['msg']);
339 340 341
	unset($_SESSION['msgtype']);
}

342 343
require_once 'lib/setup/events.php';

rjsmelo's avatar
rjsmelo committed
344
if ($prefs['rating_advanced'] == 'y' && $prefs['rating_recalculation'] == 'randomload') {
lphuberdeau's avatar
lphuberdeau committed
345
	$ratinglib = TikiLib::lib('rating');
346 347 348
	$ratinglib->attempt_refresh();
}

349
$headerlib->add_jsfile('lib/tiki-js.js');
350

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

rjsmelo's avatar
rjsmelo committed
353
if (isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'google') {
354 355
	$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
356
	$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jquery-migrate/jquery-migrate.min.js", true);
rjsmelo's avatar
rjsmelo committed
357
} elseif (isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery') {
358
	$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/jquery-$headerlib->jquery_version.min.js");
359
	$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/jquery-migrate-$headerlib->jquerymigrate_version.min.js");
360
} else {
rjsmelo's avatar
rjsmelo committed
361
	if (isset($prefs['tiki_minify_javascript']) && $prefs['tiki_minify_javascript'] === 'y') {
362 363
		$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jquery/jquery.min.js", true);
		$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jquery-migrate/jquery-migrate.min.js", true);
364
	} else {
365 366
		$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jquery/jquery.js", true);
		$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jquery-migrate/jquery-migrate.js", true);
367
	}
368
}
369

rjsmelo's avatar
rjsmelo committed
370
if (isset($prefs['fgal_elfinder_feature']) && $prefs['fgal_elfinder_feature'] === 'y') {
371
	$str = $prefs['tiki_minify_javascript'] === 'y' ? 'min' : 'full';
372 373
	// 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
374 375
	$headerlib->add_jsfile('vendor_bundled/vendor/studio-42/elfinder/js/elfinder.' . $str . '.js', true)
			->add_cssfile('vendor_bundled/vendor/studio-42/elfinder/css/elfinder.' . $str . '.css')
376 377
			->add_jsfile('lib/jquery_tiki/elfinder/tiki-elfinder.js');

rjsmelo's avatar
rjsmelo committed
378
	$elFinderLang = str_replace(['cn', 'pt-br'], ['zh_CN', 'pt_BR'], $language);
379

380 381
	if (file_exists('vendor_bundled/vendor/studio-42/elfinder/js/i18n/elfinder.' . $elFinderLang . '.js')) {
		$headerlib->add_jsfile('vendor_bundled/vendor/studio-42/elfinder/js/i18n/elfinder.' . $elFinderLang . '.js');
382
	}
383
}
384

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

387 388 389 390 391
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';
}
rjsmelo's avatar
rjsmelo committed
392
$headerlib->add_js('var zoomToFoundLocation = "' . addslashes($zoomToFoundLocation) . '";');	// Set the zoom option after searching for a location
393

rjsmelo's avatar
rjsmelo committed
394
if ($prefs['geo_enabled'] === 'y') {
395 396 397 398 399 400
	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');
		$headerlib->add_cssfile('lib/openlayers/theme/default/style.css');
	}
401
}
402
$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/jquery-json/src/jquery.json.js');
403 404

if ($prefs['feature_jquery_zoom'] === 'y') {
405
	$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/zoom/jquery.zoom.js')
406 407 408 409 410 411 412 413 414 415 416 417
		->add_css('
.img_zoom {
	display:inline-block;
}
.img_zoom:after {
	content:"";
	display:block;
	width:33px;
	height:33px;
	position:absolute;
	top:0;
	right:0;
418
	background:url(vendor_bundled/vendor/jquery/plugins/zoom/icon.png);
419 420 421 422 423 424
}
.img_zoom img {
	display:block;
}
');
}
425

426 427 428
if ($prefs['feature_syntax_highlighter'] == 'y') {
	//add codemirror stuff
	$headerlib
429 430 431 432
		->add_cssfile('vendor_bundled/vendor/codemirror/codemirror/lib/codemirror.css')
		->add_jsfile_dependancy('vendor_bundled/vendor/codemirror/codemirror/lib/codemirror.js')
		->add_jsfile('vendor_bundled/vendor/codemirror/codemirror/addon/search/searchcursor.js')
		->add_jsfile('vendor_bundled/vendor/codemirror/codemirror/addon/mode/overlay.js')
433
	//add tiki stuff
434
		->add_cssfile('themes/base_files/feature_css/codemirror_tiki.css')
435
		->add_jsfile('lib/codemirror_tiki/codemirror_tiki.js');
436

437
	require_once("lib/codemirror_tiki/tiki_codemirror.php");
438
	createCodemirrorModes();
439
}
440

rjsmelo's avatar
rjsmelo committed
441
if ($prefs['feature_jquery_carousel'] == 'y') {
442
	$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/infinitecarousel/jquery.infinitecarousel3.js');
443
}
444

rjsmelo's avatar
rjsmelo committed
445
if ($prefs['feature_ajax'] === 'y') {
446
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-ajax_services.js');
rjsmelo's avatar
rjsmelo committed
447
	if ($prefs['ajax_autosave'] === 'y') {
448
		$headerlib->add_jsfile('lib/ajax/autosave.js');
449
	}
450
}
451

452 453
// $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
rjsmelo's avatar
rjsmelo committed
454 455
if ($prefs['feature_jquery_ui'] == 'y') {
	if (isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'google') {
456
		$headerlib->add_jsfile_cdn("$url_scheme://ajax.googleapis.com/ajax/libs/jqueryui/$headerlib->jqueryui_version/jquery-ui.min.js");
rjsmelo's avatar
rjsmelo committed
457
	} elseif (isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery') {
458
		$headerlib->add_jsfile_cdn("$url_scheme://code.jquery.com/ui/$headerlib->jqueryui_version/jquery-ui.min.js");
459
	} else {
rjsmelo's avatar
rjsmelo committed
460
		if ($prefs['tiki_minify_javascript'] === 'y') {
461
			$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jqueryui/jquery-ui.min.js", true);
462
		} else {
463
			$headerlib->add_jsfile_dependancy("vendor_bundled/vendor/components/jqueryui/jquery-ui.js");
464
		}
465
	}
466

467 468
	// restore jquery-ui buttons function, thanks to http://stackoverflow.com/a/23428433/2459703
	$headerlib->add_js('
469 470 471 472 473
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
}
474 475
');

rjsmelo's avatar
rjsmelo committed
476 477 478
	if ($prefs['feature_jquery_ui_theme'] !== 'none') {
		// cdn for css not working - this is the only css from a cdn anyway - so use local version
		//if ( isset($prefs['javascript_cdn']) && $prefs['javascript_cdn'] == 'jquery' ) {
479
			// $headerlib->add_cssfile("$url_scheme://code.jquery.com/ui/$headerlib->jqueryui_version/themes/{$prefs['feature_jquery_ui_theme']}/jquery-ui.css");
480
			$headerlib->add_cssfile('vendor_bundled/vendor/components/jqueryui/themes/' . $prefs['feature_jquery_ui_theme'] . '/jquery-ui.css');
481
	//	} else {
482
	//		$headerlib->add_cssfile('vendor_bundled/vendor/jquery/jquery-ui-themes/themes/' . $prefs['feature_jquery_ui_theme'] . '/jquery-ui.css');
483
	//	}
484
	}
485

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

rjsmelo's avatar
rjsmelo committed
530
if ($prefs['feature_jquery_tagcanvas'] == 'y') {
531
	$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/tagcanvas/jquery.tagcanvas.js');
gezzzan's avatar
gezzzan committed
532 533
}

rjsmelo's avatar
rjsmelo committed
534
if ($prefs['feature_shadowbox'] == 'y') {
535 536
	$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/colorbox/jquery.colorbox.js');
	$headerlib->add_cssfile('vendor_bundled/vendor/jquery/plugins/colorbox/' . $prefs['jquery_colorbox_theme'] . '/colorbox.css');
537
}
538

rjsmelo's avatar
rjsmelo committed
539
if ($prefs['wikiplugin_flash'] == 'y') {
540
	$headerlib->add_jsfile('lib/swfobject/swfobject.js', true);
541
}
542
if ($prefs['jquery_timeago'] === 'y') {
543
	$headerlib->add_jsfile('vendor_bundled/vendor/rmm5t/jquery-timeago/jquery.timeago.js');
544
	$language_short = substr($prefs['language'], 0, 2);
545
	$timeago_locale = "vendor_bundled/vendor/rmm5t/jquery-timeago/locales/jquery.timeago.{$language_short}.js";
546 547 548
	if (is_readable($timeago_locale)) {
		$headerlib->add_jsfile($timeago_locale);	// TODO handle zh-CN and zh-TW
	}
549
	$headerlib->add_jq_onready('$("time.timeago").timeago(); jQuery.timeago.settings.allowFuture = true;');
550
}
551

rjsmelo's avatar
rjsmelo committed
552
if ($prefs['feature_jquery_validation'] == 'y') {
553
	$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/jquery-validation/dist/jquery.validate.js');
554
	$headerlib->add_jsfile('lib/validators/validator_tiki.js');
555 556
}

557
// note: jquery.async.js load a copy of jquery
558
// Used by treetable and a few more places
559
$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/async/jquery.async.js');
560

561 562
$headerlib->add_jsfile('vendor_bundled/vendor/jquery/plugins/treetable/jquery.treetable.js');
$headerlib->add_cssfile('vendor_bundled/vendor/jquery/plugins/treetable/css/jquery.treetable.css');
563

564
$headerlib->add_jsfile('vendor_bundled/vendor/cwspear/bootstrap-hover-dropdown/bootstrap-hover-dropdown.js');
565

rjsmelo's avatar
rjsmelo committed
566
if ($prefs['feature_equal_height_rows_js'] == 'y') {
567
	$headerlib->add_jsfile("vendor_bundled/vendor/Sam152/Javascript-Equal-Height-Responsive-Rows/grids.min.js");
568 569
}

570
if (empty($user) && $prefs['feature_antibot'] == 'y') {
571
	$headerlib->add_jsfile_late('lib/captcha/captchalib.js');
572 573
}

rjsmelo's avatar
rjsmelo committed
574
if (! empty($prefs['header_custom_css'])) {
575
	$headerlib->add_css($prefs['header_custom_css']);
576 577
}

rjsmelo's avatar
rjsmelo committed
578
if (! empty($prefs['header_custom_js'])) {
579
	$headerlib->add_js($prefs['header_custom_js']);
580 581
}

582 583 584 585
if ($prefs['feature_file_galleries'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/files.js');
}

586 587
if ($prefs['feature_trackers'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-trackers.js');
588 589 590

	if ($prefs['feed_tracker'] === 'y') {
		$opts = TikiLib::lib('trk')->get_trackers_options(null, 'publishRSS', 'y');
591
		foreach ($opts as & $o) {
592 593 594 595
			$o = $o['trackerId'];
		}
		$trackers = TikiLib::lib('trk')->list_trackers();

rjsmelo's avatar
rjsmelo committed
596
		$rss_trackers = [];
597
		foreach ($trackers['data'] as $trk) {
598
			if (in_array($trk['trackerId'], $opts)) {
rjsmelo's avatar
rjsmelo committed
599
				$rss_trackers[] = [
600 601
					'trackerId' => $trk['trackerId'],
					'name' => $trk['name'],
rjsmelo's avatar
rjsmelo committed
602
				];
603 604 605 606
			}
		}
		TikiLib::lib('smarty')->assign('rsslist_trackers', $rss_trackers);
	}
607 608
}

609
if ($prefs['feature_draw'] == 'y') {
610
	//svg-edit/empbedapi.js neededs to be external - why?
611
	$headerlib->add_jsfile("vendor_bundled/vendor/svg-edit/svg-edit/embedapi.js");
612
	$headerlib->add_jsfile("lib/svg-edit_tiki/draw.js");
613
	$headerlib->add_cssfile("themes/base_files/feature_css/svg-edit-draw.css");
614 615
}

616 617 618 619
if ($prefs['geo_always_load_openlayers'] == 'y') {
	$headerlib->add_map();
}

620 621 622 623
if ($prefs['workspace_ui'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/tiki-workspace-ui.js');
}

624
if ($prefs['feature_sefurl'] != 'y') {
625
	$headerlib->add_js(
626
		'$.service = function (controller, action, query) {
627 628 629 630 631
		if (! query) {
			query = {};
		}
		query.controller = controller;

632
		if (action) {
633
			query.action = action;
634
		}
635

636
		return "tiki-ajax_services.php?" + $.buildParams(query);
637
	};'
638
	);
639 640
}

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

645 646 647 648
if ($prefs['ajax_inline_edit'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/inline_edit.js');
}

649 650 651 652
if ($prefs['mustread_enabled'] == 'y') {
	$headerlib->add_jsfile('lib/jquery_tiki/mustread.js');
}

653
if ($prefs['feature_inline_comments'] === 'y' && $prefs['comments_inline_annotator'] === 'y') {
654 655 656
	if (empty($object)) {
		$object = current_object();
	}
657 658
	$commentController = new Services_Comment_Controller();

659 660
	if ($commentController->isEnabled($object['type'], $object['object']) &&
		$commentController->canView($object['type'], $object['object'])) {
661 662 663 664 665 666 667
		$canPost = $commentController->canPost($object['type'], $object['object']);
		$objectIdentifier = urlencode($object['type']) . ':' . urlencode($object['object']);    // spoof a URI from type and id

		$headerlib
			->add_jsfile('vendor_bundled/vendor/openannotation/annotator/annotator-full.min.js')
			->add_cssfile('vendor_bundled/vendor/openannotation/annotator/annotator.min.css')
			->add_jq_onready('var annotatorContent = $("#top").annotator({readOnly: ' . ($canPost ? 'false' : 'true') . '});
668 669 670 671 672
annotatorContent.annotator("addPlugin", "Store", {
	prefix: "tiki-ajax_services.php?controller=annotation&action=",

	urls: {
		create:  "create",
673 674
		update:  "update&threadId=:id",
		destroy: "destroy&threadId=:id",
675 676 677 678 679 680 681 682 683 684 685 686
		search:  "search"
	},

	annotationData: {
		"uri": "' . $objectIdentifier . '"
	},

	loadFromSearch: {
		"limit": 20,
		"uri": "' . $objectIdentifier . '"
	},
	
687 688
	emulateJSON: true,	// send the data in a form request so we can get it later
	emulateHTTP: true	// tiki services need GET or POST
689
	
690 691 692 693 694 695 696 697 698 699
});
annotatorContent.annotator("addPlugin", "Permissions", {
	user: "' . $user . '",
	showViewPermissionsCheckbox: false,	// TODO for private comments
	showEditPermissionsCheckbox: false,
	userAuthorize: function(action, annotation, user) {
		return annotation.permissions[action];
	}	
});
');
700
	}
701 702
}

703
$headerlib->add_jsfile('lib/jquery_tiki/pluginedit.js');
704

rjsmelo's avatar
rjsmelo committed
705 706
if (session_id()) {
	if ($prefs['tiki_cachecontrol_session']) {
707
		header('Cache-Control: ' . $prefs['tiki_cachecontrol_session']);
708 709
	}
} else {
rjsmelo's avatar
rjsmelo committed
710
	if ($prefs['tiki_cachecontrol_nosession']) {
711
		header('Cache-Control: ' . $prefs['tiki_cachecontrol_nosession']);
712 713
	}
}
714

rjsmelo's avatar
rjsmelo committed
715
if (! empty($prefs['access_control_allow_origin']) && ! empty($_SERVER['HTTP_ORIGIN']) && $base_host !== $_SERVER['HTTP_ORIGIN']) {
716 717 718
	$http_origin = $_SERVER['HTTP_ORIGIN'];

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

rjsmelo's avatar
rjsmelo committed
723
if (isset($token_error)) {
724 725 726 727 728
	$smarty->assign('token_error', $token_error);
	$smarty->display('error.tpl');
	die;
}

rjsmelo's avatar
rjsmelo committed
729
require_once('lib/setup/plugins_actions.php');
730

731
if ($tiki_p_admin == 'y') {
732
	$headerlib->add_jsfile_late('lib/jquery_tiki/tiki-admin.js');
733 734
}

735 736 737 738
if ($prefs['wikiplugin_addtocart'] == 'y') {
	$headerlib->add_jsfile('lib/payment/cartlib.js');
}

739
//////////////////////////////////////////////////////////////////////////
kstingel's avatar
kstingel committed
740 741 742 743 744 745 746 747 748 749 750
// ******************************************************************** //
// ** 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       ** //
751
// ** CONFIGURED TIKI-SENDER KEYPAIR (PRIVATE/PUBLIC) AND ALL USER   ** //
kstingel's avatar
kstingel committed
752 753 754
// ** ACCOUNT-RELATED PUBLIC KEYS                                    ** //
// **                                                                ** //
// ** DO NOT SWITCH THIS VARIABLE TO TRUE FOR THIS EXPERIMENTAL      ** //
755
// ** FULLY PGP/MIME-ENCRYPTION COMPLIANT EMAIL FUNCTIONALITY, IF    ** //
kstingel's avatar
kstingel committed
756 757 758
// ** YOU ARE **NOT ABSOLUTE SURE HOW TO CONFIGURE IT**!             ** //
// **                                                                ** //
// ** ONCE PROPERLY CONFIGURED, SUCH 100% OPAQUE FUNCTIONALITY       ** //
759
// ** DELIVERS ROBUST END-TO-END PRIVACY WITH HIGH DEGREE OF TESTED  ** //
kstingel's avatar
kstingel committed
760 761 762 763 764 765
// ** ROBUSTNESS FOR THE FOLLOWING MAIL TRAFFIC:                     ** //
// **                                                                ** //
// **   - all webmail-based messaging from messu-compose.php         ** //
// **   - all admin notifications                                    ** //
// **   - all newsletters                                            ** //
// **                                                                ** //
766 767 768 769
// ** 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
770 771 772 773 774
// ** 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.      ** //
// **                                                                ** //
775
if ($prefs['openpgp_gpg_pgpmimemail'] == 'y') {
776 777
	// hollmeer 2012-11-03:
	// TURNED ON openPGP support from a lib based class
rjsmelo's avatar
rjsmelo committed
778
	require_once('lib/openpgp/openpgplib.php');
779
}
kstingel's avatar
kstingel committed
780 781
// **                                                                ** //
// ******************************************************************** //
782 783
//////////////////////////////////////////////////////////////////////////

784 785 786 787 788
//adding pdf creation javascript, used to integrate plugins like tablesorter, trackerfilter with mpdf.
if ($prefs['print_pdf_from_url'] != 'none') {
	$headerlib->add_jsfile('lib/jquery_tiki/pdf.js');
}

789 790
if (file_exists('_custom/lib/setup/custom.php')) {
	include_once('_custom/lib/setup/custom.php');
791 792
}

793 794 795
// 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();
796

rjsmelo's avatar
rjsmelo committed
797
if ($prefs['conditions_enabled'] == 'y') {
798 799 800 801 802 803
	if (! Services_User_ConditionsController::hasRequiredAge($user)) {
		$servicelib = TikiLib::lib('service');
		$broker = $servicelib->getBroker();
		$broker->process('user_conditions', 'age_validation', $jitRequest);
		exit;
	}
804 805 806 807 808 809 810
	if (Services_User_ConditionsController::requiresApproval($user)) {
		$servicelib = TikiLib::lib('service');
		$broker = $servicelib->getBroker();
		$broker->process('user_conditions', 'approval', $jitRequest);
		exit;
	}
}