<commit_before><?php
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

//this script may only be included - so its better to die if called directly.
$access->check_script($_SERVER['SCRIPT_NAME'], basename(__FILE__));


// need to rebuild because they were created in tiki-setup and just removed due to clear cache
// we need to create upfront in case codemirror is used later on. 
require_once("lib/codemirror_tiki/tiki_codemirror.php");
createCodemirrorModes();

// Javascript auto-detection
//   (to be able to generate non-javascript code if there is no javascript, when noscript tag is not useful enough)
//   It uses cookies instead of session vars to keep the correct value after a session timeout

$js_cookie = getCookie('javascript_enabled');

if ($prefs['disableJavascript'] == 'y' ) {
	$prefs['javascript_enabled'] = 'n';
} elseif (!empty($js_cookie)) {
	// Update the pref with the cookie value
	$prefs['javascript_enabled'] = 'y';
	setCookieSection('javascript_enabled_detect', '', '', time() - 3600);	// remove the test cookie
} else {
	if (isset($_COOKIE['runs_before_js_detect'])) {	// pre-tiki 14 method detected, delete both tests and reload
		setcookie('runs_before_js_detect', '', time() - 3600);
		setcookie('javascript_enabled_detect', '', time() - 3600);
		$access->redirect();
	}
	$prefs['javascript_enabled'] = '';
}

// the first and second time, we should not trust the absence of javascript_enabled cookie yet,
// as it could be a redirection and the js will not get a chance to run yet, so we wait until the third run,
// assuming that js is on before then
$javascript_enabled_detect = getCookie('javascript_enabled_detect', '', '0');

if ( $prefs['javascript_enabled'] === '' && $prefs['disableJavascript'] != 'y' && $javascript_enabled_detect < 2) {
	// Set the cookie to 'y', through javascript - expires: approx. 1 year
	$prefs['javascript_enabled'] = 'y';											// temporarily enable to we output the test js
	$plus_one_year = $tikilib->now + 365 * 24 * 3600;
	$headerlib->add_js("setCookieBrowser('javascript_enabled', 'y', '', new Date({$plus_one_year}000));", 0);		// setCookieBrowser does not use the tiki_cookie_jar

	if ( strpos($_SERVER['PHP_SELF'], 'tiki-download') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-ajax_services.php') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-jsmodule.php') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-jsplugin.php') === false) {
<commit_msg>[FIX] javascript_enabled: Another tweak to the js detect code, exclude the installer from the count as the cookie doesn't get set in that page. Also have one more test just in case - thanks Torsten.<commit_after><?php
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

//this script may only be included - so its better to die if called directly.
$access->check_script($_SERVER['SCRIPT_NAME'], basename(__FILE__));


// need to rebuild because they were created in tiki-setup and just removed due to clear cache
// we need to create upfront in case codemirror is used later on. 
require_once("lib/codemirror_tiki/tiki_codemirror.php");
createCodemirrorModes();

// Javascript auto-detection
//   (to be able to generate non-javascript code if there is no javascript, when noscript tag is not useful enough)
//   It uses cookies instead of session vars to keep the correct value after a session timeout

$js_cookie = getCookie('javascript_enabled');

if ($prefs['disableJavascript'] == 'y' ) {
	$prefs['javascript_enabled'] = 'n';
} elseif (!empty($js_cookie)) {
	// Update the pref with the cookie value
	$prefs['javascript_enabled'] = 'y';
	setCookieSection('javascript_enabled_detect', '', '', time() - 3600);	// remove the test cookie
} else {
	if (isset($_COOKIE['runs_before_js_detect'])) {	// pre-tiki 14 method detected, delete both tests and reload
		setcookie('runs_before_js_detect', '', time() - 3600);
		setcookie('javascript_enabled_detect', '', time() - 3600);
		$access->redirect();
	}
	$prefs['javascript_enabled'] = '';
}

// the first and second time, we should not trust the absence of javascript_enabled cookie yet,
// as it could be a redirection and the js will not get a chance to run yet, so we wait until the third run,
// assuming that js is on before then
$javascript_enabled_detect = getCookie('javascript_enabled_detect', '', '0');

if ( $prefs['javascript_enabled'] === '' && $prefs['disableJavascript'] != 'y' && $javascript_enabled_detect < 3) {
	// Set the cookie to 'y', through javascript - expires: approx. 1 year
	$prefs['javascript_enabled'] = 'y';											// temporarily enable to we output the test js
	$plus_one_year = $tikilib->now + 365 * 24 * 3600;
	$headerlib->add_js("setCookieBrowser('javascript_enabled', 'y', '', new Date({$plus_one_year}000));", 0);		// setCookieBrowser does not use the tiki_cookie_jar

	if ( strpos($_SERVER['PHP_SELF'], 'tiki-download') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-ajax_services.php') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-jsmodule.php') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-jsplugin.php') === false &&
			strpos($_SERVER['PHP_SELF'], 'tiki-install.php') === false) {

{'fraction_non_alphanumeric': 0.1371171171171171, 'fraction_numerical': 0.013693693693693694, 'mean_word_length': 4.675869120654396, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '628505', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1655, 'n_words': 580}