<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: theme_functions_include.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).
+--------------------------------------------------------*/

use PHPFusion\Database\DatabaseFactory;
if (!defined("IN_FUSION")) {
	die("Access Denied");
}
/**
 * Show PHP-Fusion Performance
 * @param bool $queries
 * @return string
 */
function showrendertime($queries = TRUE) {
	global $mysql_queries_count;
	$locale = array();
	include LOCALE.LOCALESET."global.php";
	$db = DatabaseFactory::getConnection();
	if ($db) {
		$mysql_queries_count = $db->getGlobalQueryCount();
	}
	if (fusion_get_settings('rendertime_enabled') == 1 || (fusion_get_settings('rendertime_enabled') == 2 && iADMIN)) {
		$render_time = substr((microtime(TRUE)-START_TIME), 0, 7);
		$_SESSION['performance'][] = $render_time;
		if (count($_SESSION['performance']) > 5) array_shift($_SESSION['performance']);
		$average_speed = $render_time;
		$diff = 0;
		if (isset($_SESSION['performance'])) {
			$average_speed = substr(array_sum($_SESSION['performance'])/count($_SESSION['performance']), 0, 7);
			$previous_render = array_values(array_slice($_SESSION['performance'], -2, 1, TRUE));
			$diff = $render_time-(!empty($previous_render) ? $previous_render[0] : 0);
		}

		$res = sprintf($locale['global_172'], $render_time)." | ".sprintf($locale['global_175'], $average_speed." ($diff)");
		$res .= ($queries ? " | ".ucfirst($locale['global_173']).": $mysql_queries_count" : "");
		return $res;
	} else {
		return "";
	}
}

function showMemoryUsage() {
	$locale = array();
	include LOCALE.LOCALESET."global.php";
	$memory_allocated = parsebytesize(memory_get_peak_usage(TRUE));
	$memory_used = parsebytesize(memory_get_peak_usage(FALSE));
	return " | ".$locale['global_174'].": ".$memory_used."/".$memory_allocated;
}

function showcopyright($class = "", $nobreak = FALSE) {
	$link_class = $class ? " class='$class' " : "";
	$res = "Powered by <a href='https://www.php-fusion.co.uk'".$link_class.">PHP-Fusion</a> Copyright &copy; ".date("Y")." PHP-Fusion Inc";
	$res .= ($nobreak ? "&nbsp;" : "<br />\n");
	$res .= "Released as free software without warranties under <a href='http://www.fsf.org/licensing/licenses/agpl-3.0.html'".$link_class." target='_blank'>GNU Affero GPL</a> v3.\n";
	return $res;
}

function showcounter() {
	global $locale, $settings;
	if ($settings['visitorcounter_enabled']) {
		return "<!--counter-->".number_format($settings['counter'])." ".($settings['counter'] == 1 ? $locale['global_170'] : $locale['global_171']);
	} else {
		return "";
	}
}


/**
 * Creates an alert bar
 * @param        $title
 * @param string $text
 * @param array  $options
 * @return string
 */
if (!function_exists("alert")) {
	function alert($title, $text = "", array $options = array()) {
		$options += array(
			"class" => !empty($options['class']) ? $options['class'] : "alert-info",
			"dismiss" => !empty($options['dismiss']) && $options['dismiss'] == TRUE ? TRUE : FALSE
		);
		if ($options['dismiss'] == TRUE) {
			$html = "<div class='alert alert-dismissable ".$options['class']."'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button><strong>$title</strong>".($text ? " ".$text : "")."</div>";
		} else {
			$html = "<div class='alert ".$options['class']."'><strong>$title</strong>".($text ? " ".$text : "")."</div>";
		}
		add_to_jquery("$('div.alert a').addClass('alert-link');");
		return $html;
	}
}

// Get the widget settings for the theme settings table
if (!function_exists('get_theme_settings')) {
	function get_theme_settings($theme_folder) {
		$settings_arr = array();
		$set_result = dbquery("SELECT settings_name, settings_value FROM ".DB_SETTINGS_THEME." WHERE settings_theme='".$theme_folder."'");
		if (dbrows($set_result)) {
			while ($set_data = dbarray($set_result)) {
				$settings_arr[$set_data['settings_name']] = $set_data['settings_value'];
			}
			return $settings_arr;
		} else {
			return FALSE;
		}
	}
}

/**
 * Java script that transform html table sortable
 * @param $table_id - table ID
 * @return string
 */
function fusion_sort_table($table_id) {
	add_to_head("<script type='text/javascript' src='".INCLUDES."jquery/tablesorter/jquery.tablesorter.min.js'></script>");
	add_to_jquery("
	$('#".$table_id."').tablesorter();
	");
	return "tablesorter";
}

if (!function_exists("label")) {
	function label($label, array $options = array()) {
		$options += array(
			"class" => !empty($array['class']) ? $array['class'] : "",
			"icon" => !empty($array['icon']) ? "<i class='".$array['icon']."'></i> " : "",
		);
		return "<span class='label ".$options['class']."'>".$options['icon'].$label."</span>\n";
	}
}
if (!function_exists("badge")) {
	function badge($label, array $options = array()) {
		$options += array(
			"class" => !empty($array['class']) ? $array['class'] : "",
			"icon" => !empty($array['icon']) ? "<i class='".$array['icon']."'></i> " : "",
		);
		return "<span class='badge ".$options['class']."'>".$options['icon'].$label."</span>\n";
	}
}
if (!function_exists("openmodal") && !function_exists("closemodal")) {
	/**
	 * Generate modal
	 * @param       $id - unique CSS id
	 * @param       $title - modal title
	 * @param array $options
	 * @return string
	 */
	function openmodal($id, $title, $options = array()) {
		global $locale;
		$options += array(
			'class' => !empty($options['class']) ? : 'modal-lg',
			'button_id' => !empty($options['button_id']) ? : 0,
			'static' => !empty($options['static']) ? : 0,
		);
		if ($options['static'] && $options['button_id']) {
			add_to_jquery("$('#".$options['button_id']."').bind('click', function(e){ $('#".$id."-Modal').modal({backdrop: 'static', keyboard: false}).modal('show'); });");
		} elseif ($options['static'] && empty($options['button_id'])) {
			add_to_jquery("$('#".$id."-Modal').modal({	backdrop: 'static',	keyboard: false }).modal('show');");
		} elseif ($options['button_id'] && empty($options['static'])) {
			add_to_jquery("$('#".$options['button_id']."').bind('click', function(e){ $('#".$id."-Modal').modal('show'); });");
		} else {
			add_to_jquery("	$('#".$id."-Modal').modal('show');");
		}
		$html = '';
		$html .= "<div class='modal' id='$id-Modal' tabindex='-1' role='dialog' aria-labelledby='$id-ModalLabel' aria-hidden='true'>\n";
		$html .= "<div class='modal-dialog ".$options['class']."'>\n";
		$html .= "<div class='modal-content'>\n";
		if ($title) {
			$html .= "<div class='modal-header'>";
			$html .= (empty($options['static'])) ? "<button type='button' class='btn btn-sm pull-right btn-default' data-dismiss='modal'><i class='entypo cross'></i> ".$locale['close']."</button>\n" : '';
			$html .= "<h4 class='modal-title text-dark' id='$id-title'>$title</h4>\n";
			$html .= "</div>\n";
		}
		$html .= "<div class='modal-body'>\n";<commit_msg>Modal - added css class, and unique id to trigger modal.<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: theme_functions_include.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).
+--------------------------------------------------------*/

use PHPFusion\Database\DatabaseFactory;
if (!defined("IN_FUSION")) {
	die("Access Denied");
}
/**
 * Show PHP-Fusion Performance
 * @param bool $queries
 * @return string
 */
function showrendertime($queries = TRUE) {
	global $mysql_queries_count;
	$locale = array();
	include LOCALE.LOCALESET."global.php";
	$db = DatabaseFactory::getConnection();
	if ($db) {
		$mysql_queries_count = $db->getGlobalQueryCount();
	}
	if (fusion_get_settings('rendertime_enabled') == 1 || (fusion_get_settings('rendertime_enabled') == 2 && iADMIN)) {
		$render_time = substr((microtime(TRUE)-START_TIME), 0, 7);
		$_SESSION['performance'][] = $render_time;
		if (count($_SESSION['performance']) > 5) array_shift($_SESSION['performance']);
		$average_speed = $render_time;
		$diff = 0;
		if (isset($_SESSION['performance'])) {
			$average_speed = substr(array_sum($_SESSION['performance'])/count($_SESSION['performance']), 0, 7);
			$previous_render = array_values(array_slice($_SESSION['performance'], -2, 1, TRUE));
			$diff = $render_time-(!empty($previous_render) ? $previous_render[0] : 0);
		}

		$res = sprintf($locale['global_172'], $render_time)." | ".sprintf($locale['global_175'], $average_speed." ($diff)");
		$res .= ($queries ? " | ".ucfirst($locale['global_173']).": $mysql_queries_count" : "");
		return $res;
	} else {
		return "";
	}
}

function showMemoryUsage() {
	$locale = array();
	include LOCALE.LOCALESET."global.php";
	$memory_allocated = parsebytesize(memory_get_peak_usage(TRUE));
	$memory_used = parsebytesize(memory_get_peak_usage(FALSE));
	return " | ".$locale['global_174'].": ".$memory_used."/".$memory_allocated;
}

function showcopyright($class = "", $nobreak = FALSE) {
	$link_class = $class ? " class='$class' " : "";
	$res = "Powered by <a href='https://www.php-fusion.co.uk'".$link_class.">PHP-Fusion</a> Copyright &copy; ".date("Y")." PHP-Fusion Inc";
	$res .= ($nobreak ? "&nbsp;" : "<br />\n");
	$res .= "Released as free software without warranties under <a href='http://www.fsf.org/licensing/licenses/agpl-3.0.html'".$link_class." target='_blank'>GNU Affero GPL</a> v3.\n";
	return $res;
}

function showcounter() {
	global $locale, $settings;
	if ($settings['visitorcounter_enabled']) {
		return "<!--counter-->".number_format($settings['counter'])." ".($settings['counter'] == 1 ? $locale['global_170'] : $locale['global_171']);
	} else {
		return "";
	}
}


/**
 * Creates an alert bar
 * @param        $title
 * @param string $text
 * @param array  $options
 * @return string
 */
if (!function_exists("alert")) {
	function alert($title, $text = "", array $options = array()) {
		$options += array(
			"class" => !empty($options['class']) ? $options['class'] : "alert-info",
			"dismiss" => !empty($options['dismiss']) && $options['dismiss'] == TRUE ? TRUE : FALSE
		);
		if ($options['dismiss'] == TRUE) {
			$html = "<div class='alert alert-dismissable ".$options['class']."'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button><strong>$title</strong>".($text ? " ".$text : "")."</div>";
		} else {
			$html = "<div class='alert ".$options['class']."'><strong>$title</strong>".($text ? " ".$text : "")."</div>";
		}
		add_to_jquery("$('div.alert a').addClass('alert-link');");
		return $html;
	}
}

// Get the widget settings for the theme settings table
if (!function_exists('get_theme_settings')) {
	function get_theme_settings($theme_folder) {
		$settings_arr = array();
		$set_result = dbquery("SELECT settings_name, settings_value FROM ".DB_SETTINGS_THEME." WHERE settings_theme='".$theme_folder."'");
		if (dbrows($set_result)) {
			while ($set_data = dbarray($set_result)) {
				$settings_arr[$set_data['settings_name']] = $set_data['settings_value'];
			}
			return $settings_arr;
		} else {
			return FALSE;
		}
	}
}

/**
 * Java script that transform html table sortable
 * @param $table_id - table ID
 * @return string
 */
function fusion_sort_table($table_id) {
	add_to_head("<script type='text/javascript' src='".INCLUDES."jquery/tablesorter/jquery.tablesorter.min.js'></script>");
	add_to_jquery("
	$('#".$table_id."').tablesorter();
	");
	return "tablesorter";
}

if (!function_exists("label")) {
	function label($label, array $options = array()) {
		$options += array(
			"class" => !empty($array['class']) ? $array['class'] : "",
			"icon" => !empty($array['icon']) ? "<i class='".$array['icon']."'></i> " : "",
		);
		return "<span class='label ".$options['class']."'>".$options['icon'].$label."</span>\n";
	}
}
if (!function_exists("badge")) {
	function badge($label, array $options = array()) {
		$options += array(
			"class" => !empty($array['class']) ? $array['class'] : "",
			"icon" => !empty($array['icon']) ? "<i class='".$array['icon']."'></i> " : "",
		);
		return "<span class='badge ".$options['class']."'>".$options['icon'].$label."</span>\n";
	}
}
if (!function_exists("openmodal") && !function_exists("closemodal")) {
	/**
	 * Generate modal
	 * @param       $id - unique CSS id
	 * @param       $title - modal title
	 * @param array $options
	 * @return string
	 */
	function openmodal($id, $title, $options = array()) {
		global $locale;
		$options += array(
			'class' => !empty($options['class']) ? : 'modal-lg',
			'button_id' => !empty($options['button_id']) ? : 0,
			"button_class" => !empty($options['button_id']) ? : 0,
			'static' => !empty($options['static']) ? : 0,
		);

		$modal_trigger = "";
		if (!empty($options['button_id']) || !empty($options['button_class'])) {
			$modal_trigger = !empty($options['button_id']) ? "#".$options['button_id'] : ".".$options['button_class'];
		}

		if ($options['static'] && !empty($modal_trigger)) {
			add_to_jquery("$('".$modal_trigger."').bind('click', function(e){ $('#".$id."-Modal').modal({backdrop: 'static', keyboard: false}).modal('show'); });");
		} elseif ($options['static'] && empty($options['button_id'])) {
			add_to_jquery("$('#".$id."-Modal').modal({	backdrop: 'static',	keyboard: false }).modal('show');");
		} elseif ($modal_trigger && empty($options['static'])) {
			add_to_jquery("$('".$modal_trigger."').bind('click', function(e){ $('#".$id."-Modal').modal('show'); });");
		} else {
			add_to_jquery("	$('#".$id."-Modal').modal('show');");
		}
		$html = '';
		$html .= "<div class='modal' id='$id-Modal' tabindex='-1' role='dialog' aria-labelledby='$id-ModalLabel' aria-hidden='true'>\n";
		$html .= "<div class='modal-dialog ".$options['class']."'>\n";
		$html .= "<div class='modal-content'>\n";
		if ($title) {
			$html .= "<div class='modal-header'>";
			$html .= (empty($options['static'])) ? "<button type='button' class='btn btn-sm pull-right btn-default' data-dismiss='modal'><i class='entypo cross'></i> ".$locale['close']."</button>\n" : '';
			$html .= "<h4 class='modal-title text-dark' id='$id-title'>$title</h4>\n";
			$html .= "</div>\n";
		}
		$html .= "<div class='modal-body'>\n";
{'fraction_non_alphanumeric': 0.2539672087969974, 'fraction_numerical': 0.005201817343780865, 'mean_word_length': 4.21565934065934, 'pattern_counts': {'":': 4, '<': 81, '<?xml version=': 0, '>': 102, 'https://': 4, 'lorem ipsum': 0, 'www.': 8, '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': '957228', 'n_tokens_mistral': 5280, 'n_tokens_neox': 4948, 'n_words': 971}