<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: settings_main.php
| Author: PHP-Fusion Development Team
+--------------------------------------------------------+
| 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";
pageAccess('S1');
require_once THEMES."templates/admin_header.php";
include LOCALE.LOCALESET."admin/settings.php";
add_breadcrumb(array('link' => ADMIN."settings_main.php".$aidlink, 'title' => $locale['main_settings']));
// These are the default settings and the only settings we expect to be posted
$settings_main = array('siteintro' => fusion_get_settings('siteintro'),
	'sitename' => fusion_get_settings('sitename'),
	'sitebanner' => fusion_get_settings('sitebanner'),
	'siteemail' => fusion_get_settings('siteemail'),
	'siteusername' => fusion_get_settings('siteusername'),
	'footer' => fusion_get_settings('footer'),
	'site_protocol' => fusion_get_settings('site_protocol'),
	'site_host' => fusion_get_settings('site_host'),
	'site_path' => fusion_get_settings('site_path'),
	'site_port' => fusion_get_settings('site_port'),
	'description' => fusion_get_settings('description'),
	'keywords' => fusion_get_settings('keywords'),
	'opening_page' => fusion_get_settings('opening_page'),
	'default_search' => fusion_get_settings('default_search'),
	'exclude_left' => fusion_get_settings('exclude_left'),
	'exclude_upper' => fusion_get_settings('exclude_upper'),
	'exclude_aupper' => fusion_get_settings('exclude_aupper'),
	'exclude_lower' => fusion_get_settings('exclude_lower'),
	'exclude_blower' => fusion_get_settings('exclude_blower'),
	'exclude_right' => fusion_get_settings('exclude_right'));
// Default Search options
$dir = LOCALE.LOCALESET."search/";
$temp = opendir($dir);
$search_opts = array();
if (file_exists($dir)) {
	include LOCALE.LOCALESET."search/converter.php";
	while ($folder = readdir($temp)) {
		if (!in_array($folder, array("..", ".", 'users.json.php', 'converter.php', '.DS_Store', 'index.php'))) {
			$val = $filename_locale[$folder];
			$search_opts[$val] = ucwords($val);
		}
	}
}
// Saving settings
if (isset($_POST['savesettings'])) {
	foreach ($settings_main as $key => $value) {
		if (isset($_POST[$key])) {
			if ($key == 'siteintro') {
				$settings_main['siteintro'] = descript(addslashes(addslashes($_POST['siteintro'])));
			} elseif ($key == 'footer') {
				$settings_main['footer'] = descript(addslashes(addslashes($_POST['footer'])));
			} elseif ($key == 'site_host') {
				$settings_main['site_host'] = (empty($_POST['site_host']) ? $settings_main['site_host'] : stripinput($_POST['site_host']));
				if (strpos($settings_main['site_host'], "/") !== FALSE) {
					$settings_main['site_host'] = explode("/", $settings_main['site_host'], 2);
					if ($settings_main['site_host'][1] != "") {
						$_POST['site_path'] = "/".$settings_main['site_host'][1];
					}
					$settings_main['site_host'] = $settings_main['site_host'][0];
				}
			} elseif ($key == 'site_port') {
				$settings_main['site_port'] = ((isnum($_POST['site_port']) || $_POST['site_port'] == "") && !in_array($_POST['site_port'], array(0,
						80,
						443)) && $_POST['site_port'] < 65001) ? $_POST['site_port'] : '';
			} elseif ($key == 'default_search') {
				$settings_main['default_search'] = (in_array(stripinput($_POST['default_search']), $search_opts) ? stripinput($_POST['default_search']) : $settings_main['default_search']);
			} else {
				$settings_main[$key] = form_sanitizer($_POST[$key], $settings_main[$key], $key);
			}
		} else {
			$settings_main[$key] = form_sanitizer($settings_main[$key], $settings_main[$key], $key);
		}
		if (!defined('FUSION_NULL')) {
			dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$settings_main[$key]."' WHERE settings_name='".$key."'");
		}
	}
	if (!defined('FUSION_NULL')) {
		addNotice("success", "<i class='fa fa-check-square-o m-r-10 fa-lg'></i>".$locale['900']);
		$settings_main['siteurl'] = $settings_main['site_protocol']."://".$settings_main['site_host'].($settings_main['site_port'] ? ":".$settings_main['site_port'] : "").$settings_main['site_path'];
		dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$settings_main['siteurl']."' WHERE settings_name='siteurl'");
		redirect(FUSION_SELF.$aidlink);
	}
}
opentable($locale['main_settings']);
echo "<div class='well'>".$locale['main_description']."</div>";
echo openform('settingsform', 'post', FUSION_SELF.$aidlink, array('max_tokens' => 2));
echo "<div class='row'><div class='col-xs-12 col-sm-12 col-md-6'>\n";
openside('');
echo form_text('sitename', $locale['402'], $settings_main['sitename'], array('max_length' => 255,
	'required' => 1,
	'error_text' => $locale['error_value'],
	'inline' => 1));
echo form_text('siteemail', $locale['405'], $settings_main['siteemail'], array('max_length' => 128,
	'required' => 1,
	'type' => 'email',
	'inline' => 1));
echo form_text('siteusername', $locale['406'], $settings_main['siteusername'], array('max_length' => 32,
	'required' => 1,
	'error_text' => $locale['error_value'],
	'inline' => 1));
echo form_text('sitebanner', $locale['404'], $settings_main['sitebanner'], array('required' => 1,
	'error_text' => $locale['error_value'],
	'inline' => 1));
closeside();
openside('');
echo form_textarea('description', $locale['409'], $settings_main['description'], array('autosize' => 1));
echo form_textarea('keywords', $locale['410']."<br/><small>".$locale['411']."</small>", $settings_main['keywords'], array('autosize' => 1));
echo form_textarea('footer', $locale['412'], stripslashes($settings_main['footer']), array('autosize' => 1));
echo form_select('default_search', $locale['419'], $settings_main['default_search'], array('options' => $search_opts,
	'width' => '100%'));
closeside();
openside('');<commit_msg>Fixes #910<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: settings_main.php
| Author: PHP-Fusion Development Team
+--------------------------------------------------------+
| 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";
pageAccess('S1');
require_once THEMES."templates/admin_header.php";
$locale = fusion_get_locale('', LOCALE.LOCALESET.'admin/settings.php');
add_breadcrumb(array('link' => ADMIN."settings_main.php".$aidlink, 'title' => $locale['main_settings']));

// Saving settings
if (isset($_POST['savesettings'])) {
    foreach ($_POST as $key => $value) {
        if (isset($_POST[$key])) {
            if ($key == 'siteintro') {
                $settings_main['siteintro'] = descript(addslashes(addslashes($_POST['siteintro'])));
            } elseif ($key == 'footer') {
                $settings_main['footer'] = descript(addslashes(addslashes($_POST['footer'])));
            } elseif ($key == 'site_host') {
                $settings_main['site_host'] = (empty($_POST['site_host']) ? $settings_main['site_host'] : stripinput($_POST['site_host']));
                if (strpos($settings_main['site_host'], "/") !== FALSE) {
                    $settings_main['site_host'] = explode("/", $settings_main['site_host'], 2);
                    if ($settings_main['site_host'][1] != "") {
                        $_POST['site_path'] = "/".$settings_main['site_host'][1];
                    }
                    $settings_main['site_host'] = $settings_main['site_host'][0];
                }
            } elseif ($key == 'site_port') {
                $settings_main['site_port'] = ((isnum($_POST['site_port']) || $_POST['site_port'] == "")
                    && !in_array($_POST['site_port'], array(0,80,443)) && $_POST['site_port'] < 65001) ? $_POST['site_port'] : '';
            } elseif ($key == 'default_search') {
                $settings_main['default_search'] = (in_array(stripinput($_POST['default_search']), $search_opts) ? stripinput($_POST['default_search']) : $settings_main['default_search']);
            } else {
                $settings_main[$key] = form_sanitizer($_POST[$key], $settings_main[$key], $key);
            }
        } else {
            $settings_main[$key] = form_sanitizer($settings_main[$key], $settings_main[$key], $key);
        }
        if ( defender::safe() ) {
            dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$settings_main[$key]."' WHERE settings_name='".$key."'");
        }
    }

    if ( defender::safe() ) {
        addNotice("success", $locale['900']);
        $settings_main['siteurl'] = $settings_main['site_protocol']."://".$settings_main['site_host'].($settings_main['site_port'] ? ":".$settings_main['site_port'] : "").$settings_main['site_path'];
        dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$settings_main['siteurl']."' WHERE settings_name='siteurl'");
        redirect(FUSION_SELF.$aidlink);
    }
}

// These are the default settings and the only settings we expect to be posted
$settings_main = array('siteintro' => fusion_get_settings('siteintro'),
	'sitename' => fusion_get_settings('sitename'),
	'sitebanner' => fusion_get_settings('sitebanner'),
	'siteemail' => fusion_get_settings('siteemail'),
	'siteusername' => fusion_get_settings('siteusername'),
	'footer' => fusion_get_settings('footer'),
	'site_protocol' => fusion_get_settings('site_protocol'),
	'site_host' => fusion_get_settings('site_host'),
	'site_path' => fusion_get_settings('site_path'),
	'site_port' => fusion_get_settings('site_port'),
	'description' => fusion_get_settings('description'),
	'keywords' => fusion_get_settings('keywords'),
	'opening_page' => fusion_get_settings('opening_page'),
	'default_search' => fusion_get_settings('default_search'),
	'exclude_left' => fusion_get_settings('exclude_left'),
	'exclude_upper' => fusion_get_settings('exclude_upper'),
	'exclude_aupper' => fusion_get_settings('exclude_aupper'),
	'exclude_lower' => fusion_get_settings('exclude_lower'),
	'exclude_blower' => fusion_get_settings('exclude_blower'),
	'exclude_right' => fusion_get_settings('exclude_right'));
// Default Search options
$dir = LOCALE.LOCALESET."search/";
$temp = opendir($dir);
$search_opts = array();
if (file_exists($dir)) {
	include LOCALE.LOCALESET."search/converter.php";
	while ($folder = readdir($temp)) {
		if (!in_array($folder, array("..", ".", 'users.json.php', 'converter.php', '.DS_Store', 'index.php'))) {
			$val = $filename_locale[$folder];
			$search_opts[$val] = ucwords($val);
		}
	}
}
opentable($locale['main_settings']);
echo "<div class='well'>".$locale['main_description']."</div>";
echo openform('settingsform', 'post', FUSION_SELF.$aidlink, array('max_tokens' => 2));
echo "<div class='row'><div class='col-xs-12 col-sm-12 col-md-6'>\n";
openside('');
echo form_text('sitename', $locale['402'], $settings_main['sitename'], array('max_length' => 255,
	'required' => 1,
	'error_text' => $locale['error_value'],
	'inline' => 1));
echo form_text('siteemail', $locale['405'], $settings_main['siteemail'], array('max_length' => 128,
	'required' => 1,
	'type' => 'email',
	'inline' => 1));
echo form_text('siteusername', $locale['406'], $settings_main['siteusername'], array('max_length' => 32,
	'required' => 1,
	'error_text' => $locale['error_value'],
	'inline' => 1));
echo form_text('sitebanner', $locale['404'], $settings_main['sitebanner'], array('required' => 1,
	'error_text' => $locale['error_value'],
	'inline' => 1));
closeside();
openside('');
echo form_textarea('description', $locale['409'], $settings_main['description'], array('autosize' => 1));
echo form_textarea('keywords', $locale['410']."<br/><small>".$locale['411']."</small>", $settings_main['keywords'], array('autosize' => 1));
echo form_textarea('footer', $locale['412'], stripslashes($settings_main['footer']), array('autosize' => 1));
echo form_select('default_search', $locale['419'], $settings_main['default_search'], array('options' => $search_opts,
	'width' => '100%'));
closeside();
openside('');
{'fraction_non_alphanumeric': 0.23289473684210527, 'fraction_numerical': 0.011842105263157895, 'mean_word_length': 4.637434554973822, 'pattern_counts': {'":': 4, '<': 23, '<?xml version=': 0, '>': 107, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '6252389', 'n_tokens_mistral': 4330, 'n_tokens_neox': 4041, 'n_words': 703}