<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: settings_main.php
| Author: <NAME> (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
if (!checkrights("S1") || !defined("iAUTH") || !isset($_GET['aid']) || $_GET['aid'] != iAUTH) {
	redirect("../index.php");
}
require_once THEMES."templates/admin_header.php";
include LOCALE.LOCALESET."admin/settings.php";
if (isset($_GET['error']) && isnum($_GET['error']) && !isset($message)) {
	if ($_GET['error'] == 0) {
		$message = $locale['900'];
	} elseif ($_GET['error'] == 1) {
		$message = $locale['901'];
	} elseif ($_GET['error'] == 2) {
		$message = $locale['902'];
	}
	if (isset($message)) {
		echo "<div id='close-message'><div class='admin-message'>".$message."</div></div>\n";
	}
}
if (isset($_POST['savesettings'])) {
	$error = 0;
	$siteintro = descript(stripslash($_POST['intro']));
	$sitefooter = descript(stripslash($_POST['footer']));
	//$localeset     = stripinput($_POST['localeset']);
	$old_localeset = stripinput($_POST['old_localeset']);
	$site_host = "";
	$site_path = "/";
	$site_protocol = "http";
	$site_port = "";
	if (in_array($_POST['site_protocol'], array("http", "https"))) {
		$site_protocol = $_POST['site_protocol'];
	}
	if ($_POST['site_host'] && $_POST['site_host'] != "/") {
		$site_host = stripinput($_POST['site_host']);
		if (strpos($site_host, "/") !== FALSE) {
			$site_host = explode("/", $site_host, 2);
			if ($site_host[1] != "") {
				$site_path = "/".$site_host[1];
			}
			$site_host = $site_host[0];
		}
	} else {
		$defender->stop();
		$defender->addNotice($locale['902']);
	}
	if (($_POST['site_path'] && $_POST['site_path'] != "/") || $site_path != "/") {
		if ($site_path == "/") {
			$site_path = stripinput($_POST['site_path']);
		}
		$site_path = (substr($site_path, 0, 1) != "/" ? "/" : "").$site_path.(strrchr($site_path, "/") != "/" ? "/" : "");
	}
	if ((isnum($_POST['site_port']) || $_POST['site_port'] == "") && !in_array($_POST['site_port'], array(0, 80, 443))
	) {
		$site_port = $_POST['site_port'];
	}
	$siteurl = $site_protocol."://".$site_host.($site_port ? ":".$site_port : "").$site_path;
	$sitename = !defined('FUSION_NULL') ? form_sanitizer($_POST['sitename'], '', 'sitename') : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$sitename' WHERE settings_name='sitename'") : '';
	$sitebanner = form_sanitizer($_POST['sitebanner'], '', 'sitebanner');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$sitebanner' WHERE settings_name='sitebanner'") : '';
	$siteemail = form_sanitizer($_POST['siteemail'], '', 'siteemail');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$siteemail' WHERE settings_name='siteemail'") : '';
	$username = form_sanitizer($_POST['username'], '', 'username');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$username' WHERE settings_name='siteusername'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_protocol."' WHERE settings_name='site_protocol'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_host."' WHERE settings_name='site_host'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_path."' WHERE settings_name='site_path'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_port."' WHERE settings_name='site_port'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$siteurl."' WHERE settings_name='siteurl'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".addslashes(addslashes($siteintro))."' WHERE settings_name='siteintro'") : '';
	$description = form_sanitizer($_POST['description'], '', 'description');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$description' WHERE settings_name='description'") : '';
	$keywords = form_sanitizer($_POST['keywords'], '', 'keywords');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$keywords' WHERE settings_name='keywords'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".addslashes(addslashes($sitefooter))."' WHERE settings_name='footer'") : '';
	$opening_page = form_sanitizer($_POST['opening_page'], '', 'opening_page');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$opening_page' WHERE settings_name='opening_page'") : '';
	$admin_theme = form_sanitizer($_POST['admin_theme'], '', 'admin_theme');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$admin_theme' WHERE settings_name='admin_theme'") : '';
	$theme = form_sanitizer($_POST['theme'], '', 'theme');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$theme' WHERE settings_name='theme'") : '';
	$bootstrap = form_sanitizer($_POST['bootstrap'], 0, 'bootstrap');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$bootstrap' WHERE settings_name='bootstrap'") : '';
	$site_seo = form_sanitizer($_POST['site_seo'], 0, 'site_seo');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$site_seo' WHERE settings_name='site_seo'") : '';
	if ($site_seo == 1) {
		// enable
		// create .htaccess
		if (!file_exists(BASEDIR.".htaccess")) {
			if (file_exists(BASEDIR."_htaccess") && function_exists("rename")) {
				@rename(BASEDIR."_htaccess", BASEDIR.".htaccess");
			} else {
				// create a file.
				$handle = fopen(BASEDIR.".htaccess", "w");
				fclose($handle);
			}
		}
		// write file. wipe out all .htaccess current configuration.
		$htaccess = "ErrorDocument 400 ".$settings['site_path']."/error.php?code=400\n";
		$htaccess .= "ErrorDocument 401 ".$settings['site_path']."/error.php?code=401\n";
		$htaccess .= "ErrorDocument 403 ".$settings['site_path']."/error.php?code=403\n";
		$htaccess .= "ErrorDocument 404 ".$settings['site_path']."/error.php?code=404\n";
		$htaccess .= "ErrorDocument 500 ".$settings['site_path']."/error.php?code=500\n";
		$htacess .= "Options +FollowSymlinks -MultiViews\n";
		$htacess .= "RewriteEngine On\n";
		$htacess .= "RewriteBase ".$settings['site_path']."\n";
		$htacess .= "# Fix Apache internal dummy connections from breaking [(site_url)] cache\n";
		$htacess .= "RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]\n";
		$htacess .= "RewriteRule .* - [F,L]\n";
		$htacess .= "# Exclude /assets and /manager directories and images from rewrite rules\n";
		$htacess .= "RewriteRule ^(administration|themes)/*$ - [L]\n";
		$htacess .= "RewriteCond %{REQUEST_FILENAME} !-f\n";
		$htacess .= "RewriteCond %{REQUEST_FILENAME} !-d\n";
		$htacess .= "RewriteCond %{REQUEST_FILENAME} !-l\n";
		$htacess .= "RewriteCond %{REQUEST_URI} !^/(administration|config|rewrite.php)\n";
		$htacess .= "RewriteRule ^(.*?)$ rewrite.php [L]\n";
		$temp = fopen(BASEDIR.".htaccess", "w");
		if (fwrite($temp, $htacess)) {
			fclose($temp);
		}
	} else {
		// disable
		if (file_exists(BASEDIR.".htaccess")) {
			// delete file. wipe out all main .htaccess settings to prevent redirect and crash the server.
			if (file_exists(BASEDIR.".htaccess") && function_exists("rename")) {
				// rename file.
				@rename(BASEDIR.".htaccess", BASEDIR."_htaccess");
			}
		}
	}
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".stripinput($_POST['default_search'])."' WHERE settings_name='default_search'") : '';
	$exclude_left = form_sanitizer($_POST['exclude_left'], '', 'exclude_left');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_left' WHERE settings_name='exclude_left'") : '';
	$exclude_upper = form_sanitizer($_POST['exclude_upper'], '', 'exclude_upper');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_upper' WHERE settings_name='exclude_upper'") : '';
	$exclude_aupper = form_sanitizer($_POST['exclude_aupper'], '', 'exclude_aupper');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_aupper' WHERE settings_name='exclude_aupper'") : '';
	$exclude_lower = form_sanitizer($_POST['exclude_lower'], '', 'exclude_lower');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_lower' WHERE settings_name='exclude_lower'") : '';
	$exclude_blower = form_sanitizer($_POST['exclude_blower'], '', 'exclude_blower');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_blower' WHERE settings_name='exclude_blower'") : '';
	$exclude_right = form_sanitizer($_POST['exclude_right'], '', 'exclude_right');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_right' WHERE settings_name='exclude_right'") : '';
}<commit_msg>Corrected .htaccess config<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: settings_main.php
| Author: <NAME> (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
if (!checkrights("S1") || !defined("iAUTH") || !isset($_GET['aid']) || $_GET['aid'] != iAUTH) {
	redirect("../index.php");
}
require_once THEMES."templates/admin_header.php";
include LOCALE.LOCALESET."admin/settings.php";
if (isset($_GET['error']) && isnum($_GET['error']) && !isset($message)) {
	if ($_GET['error'] == 0) {
		$message = $locale['900'];
	} elseif ($_GET['error'] == 1) {
		$message = $locale['901'];
	} elseif ($_GET['error'] == 2) {
		$message = $locale['902'];
	}
	if (isset($message)) {
		echo "<div id='close-message'><div class='admin-message'>".$message."</div></div>\n";
	}
}
if (isset($_POST['savesettings'])) {
	$error = 0;
	$siteintro = descript(stripslash($_POST['intro']));
	$sitefooter = descript(stripslash($_POST['footer']));
	//$localeset     = stripinput($_POST['localeset']);
	$old_localeset = stripinput($_POST['old_localeset']);
	$site_host = "";
	$site_path = "/";
	$site_protocol = "http";
	$site_port = "";
	if (in_array($_POST['site_protocol'], array("http", "https"))) {
		$site_protocol = $_POST['site_protocol'];
	}
	if ($_POST['site_host'] && $_POST['site_host'] != "/") {
		$site_host = stripinput($_POST['site_host']);
		if (strpos($site_host, "/") !== FALSE) {
			$site_host = explode("/", $site_host, 2);
			if ($site_host[1] != "") {
				$site_path = "/".$site_host[1];
			}
			$site_host = $site_host[0];
		}
	} else {
		$defender->stop();
		$defender->addNotice($locale['902']);
	}
	if (($_POST['site_path'] && $_POST['site_path'] != "/") || $site_path != "/") {
		if ($site_path == "/") {
			$site_path = stripinput($_POST['site_path']);
		}
		$site_path = (substr($site_path, 0, 1) != "/" ? "/" : "").$site_path.(strrchr($site_path, "/") != "/" ? "/" : "");
	}
	if ((isnum($_POST['site_port']) || $_POST['site_port'] == "") && !in_array($_POST['site_port'], array(0, 80, 443))
	) {
		$site_port = $_POST['site_port'];
	}
	$siteurl = $site_protocol."://".$site_host.($site_port ? ":".$site_port : "").$site_path;
	$sitename = !defined('FUSION_NULL') ? form_sanitizer($_POST['sitename'], '', 'sitename') : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$sitename' WHERE settings_name='sitename'") : '';
	$sitebanner = form_sanitizer($_POST['sitebanner'], '', 'sitebanner');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$sitebanner' WHERE settings_name='sitebanner'") : '';
	$siteemail = form_sanitizer($_POST['siteemail'], '', 'siteemail');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$siteemail' WHERE settings_name='siteemail'") : '';
	$username = form_sanitizer($_POST['username'], '', 'username');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$username' WHERE settings_name='siteusername'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_protocol."' WHERE settings_name='site_protocol'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_host."' WHERE settings_name='site_host'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_path."' WHERE settings_name='site_path'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$site_port."' WHERE settings_name='site_port'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$siteurl."' WHERE settings_name='siteurl'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".addslashes(addslashes($siteintro))."' WHERE settings_name='siteintro'") : '';
	$description = form_sanitizer($_POST['description'], '', 'description');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$description' WHERE settings_name='description'") : '';
	$keywords = form_sanitizer($_POST['keywords'], '', 'keywords');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$keywords' WHERE settings_name='keywords'") : '';
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".addslashes(addslashes($sitefooter))."' WHERE settings_name='footer'") : '';
	$opening_page = form_sanitizer($_POST['opening_page'], '', 'opening_page');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$opening_page' WHERE settings_name='opening_page'") : '';
	$admin_theme = form_sanitizer($_POST['admin_theme'], '', 'admin_theme');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$admin_theme' WHERE settings_name='admin_theme'") : '';
	$theme = form_sanitizer($_POST['theme'], '', 'theme');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$theme' WHERE settings_name='theme'") : '';
	$bootstrap = form_sanitizer($_POST['bootstrap'], 0, 'bootstrap');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$bootstrap' WHERE settings_name='bootstrap'") : '';
	$site_seo = form_sanitizer($_POST['site_seo'], 0, 'site_seo');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$site_seo' WHERE settings_name='site_seo'") : '';
	if ($site_seo == 1) {
		// enable
		// create .htaccess
		if (!file_exists(BASEDIR.".htaccess")) {
			if (file_exists(BASEDIR."_htaccess") && function_exists("rename")) {
				@rename(BASEDIR."_htaccess", BASEDIR.".htaccess");
			} else {
				// create a file.
				$handle = fopen(BASEDIR.".htaccess", "w");
				fclose($handle);
			}
		}
		// write file. wipe out all .htaccess current configuration.
		$htc = "ErrorDocument 400 ".$settings['site_path']."/error.php?code=400\n";
		$htc .= "ErrorDocument 401 ".$settings['site_path']."/error.php?code=401\n";
		$htc .= "ErrorDocument 403 ".$settings['site_path']."/error.php?code=403\n";
		$htc .= "ErrorDocument 404 ".$settings['site_path']."/error.php?code=404\n";
		$htc .= "ErrorDocument 500 ".$settings['site_path']."/error.php?code=500\n";
		$htc .= "Options +FollowSymlinks -MultiViews\n";
		$htc .= "RewriteEngine On\n";
		$htc .= "RewriteBase ".$settings['site_path']."\n";
		$htc .= "# Fix Apache internal dummy connections from breaking [(site_url)] cache\n";
		$htc .= "RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]\n";
		$htc .= "RewriteRule .* - [F,L]\n";
		$htc .= "# Exclude /assets and /manager directories and images from rewrite rules\n";
		$htc .= "RewriteRule ^(administration|themes)/*$ - [L]\n";
		$htc .= "RewriteCond %{REQUEST_FILENAME} !-f\n";
		$htc .= "RewriteCond %{REQUEST_FILENAME} !-d\n";
		$htc .= "RewriteCond %{REQUEST_FILENAME} !-l\n";
		$htc .= "RewriteCond %{REQUEST_URI} !^/(administration|config|rewrite.php)\n";
		$htc .= "RewriteRule ^(.*?)$ rewrite.php [L]\n";
		$temp = fopen(BASEDIR.".htaccess", "w");
		if (fwrite($temp, $htc)) {
			fclose($temp);
		}
	} else {
		// disable
		if (file_exists(BASEDIR.".htaccess")) {
			// delete file. wipe out all main .htaccess settings to prevent redirect and crash the server.
			if (file_exists(BASEDIR.".htaccess") && function_exists("rename")) {
				// rename file.
				@rename(BASEDIR.".htaccess", BASEDIR."_htaccess");
			}
		}
	}
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".stripinput($_POST['default_search'])."' WHERE settings_name='default_search'") : '';
	$exclude_left = form_sanitizer($_POST['exclude_left'], '', 'exclude_left');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_left' WHERE settings_name='exclude_left'") : '';
	$exclude_upper = form_sanitizer($_POST['exclude_upper'], '', 'exclude_upper');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_upper' WHERE settings_name='exclude_upper'") : '';
	$exclude_aupper = form_sanitizer($_POST['exclude_aupper'], '', 'exclude_aupper');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_aupper' WHERE settings_name='exclude_aupper'") : '';
	$exclude_lower = form_sanitizer($_POST['exclude_lower'], '', 'exclude_lower');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_lower' WHERE settings_name='exclude_lower'") : '';
	$exclude_blower = form_sanitizer($_POST['exclude_blower'], '', 'exclude_blower');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_blower' WHERE settings_name='exclude_blower'") : '';
	$exclude_right = form_sanitizer($_POST['exclude_right'], '', 'exclude_right');
	$result = !defined('FUSION_NULL') ? dbquery("UPDATE ".DB_SETTINGS." SET settings_value='$exclude_right' WHERE settings_name='exclude_right'") : '';
}
{'fraction_non_alphanumeric': 0.2315353968740423, 'fraction_numerical': 0.006333639799775258, 'mean_word_length': 5.199810006333122, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865284', 'n_tokens_mistral': 6999, 'n_tokens_neox': 6590, 'n_words': 1156}