<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: all_functions_include.php
| Author: <NAME> (Rimelek)
+--------------------------------------------------------+
| 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;
use PHPFusion\Database\AbstractDatabaseDriver;
use PHPFusion\Database\Exception\SelectionException;

/*
 * It will be called after everything else even if the script is
 * halted by exit(), die(), fatal error or exception.
 *
 * It shows all sent query per connection
 */
register_shutdown_function(function() {
	if (DatabaseFactory::isDebug()) {
		$log = AbstractDatabaseDriver::getGlobalQueryLog();
		foreach ($log as $connectionid => $value) {
			if (!DatabaseFactory::isDebug($connectionid)) {
				unset($log[$connectionid]);
			}
		}
		//print_p($log);

		$html = "<a href='#queries' class='queries-btn btn btn-primary pull-left'>View Queries</a>\n";
		$html .= "<div id='queries' class='well queries-log' style='display: none'>\n";
		foreach ($log as $connID => $queries) {
			$html .= "Database connection ID: '<strong>".$connID."</strong>'<br/>\n";

			$queries_time = 0;
			$queries_log = '';
			foreach ($queries as $key => $query) {
				$queries_time = $queries_time + $query[0];
				// The time and the query
				$queries_log .= "<strong>#".($key + 1)." Time: ".$query[0]."</strong><br/>\n".stripinput($query[1])."<br />\n";
				// The query explained
				$exp_title = "";
				$exp_value = "";
				$queries_log .= "<table class='tbl-border'>";
				// For more info on this see: http://dev.mysql.com/doc/refman/5.0/en/explain-output.html
				// and http://dev.mysql.com/doc/refman/5.0/en/explain-extended.html
				foreach (dbarray(dbquery("EXPLAIN EXTENDED ".$query[1]."")) as $key => $value) {
					$exp_title .= "<td class='tbl1 panel panel-default'>".$key."</td>";
					$exp_value .= "<td class='tbl2 panel panel-default'>".($value == '' ? '-' : $value)."</td>";
				}
				$queries_log .= "<tr>".$exp_title."</tr><tr>".$exp_value."</tr>";
				$queries_log .= "</table>";
				
				// For more info on this please see: http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html
				$more_info = dbarray(dbquery("SHOW WARNINGS"));
				if ($more_info) {
					$queries_log .= "<a class='query-more-btn' href='#'>View additional info on this query generated by SHOW WARNINGS</a>";
					$queries_log .= "<table class='tbl-border query-more-info' style='display:none'>";
					$queries_log .= "<tr><td class='tbl1 panel panel-default'>Code</td>
										<td class='tbl1 panel panel-default'>Level</td>
										<td class='tbl1 panel panel-default'>Message</td>
									</tr>";
					$queries_log .= "<tr><td class='tbl2 panel panel-default'>".$more_info['Code']."</td>
										<td class='tbl2 panel panel-default'>".$more_info['Level']."</td>
										<td class='tbl2 panel panel-default'>".stripinput($more_info['Message'])."</td>
									</tr>";
					$queries_log .= "</table>";
				}
				$queries_log .= "<hr />\n";
			}

			$html .= "Total time taken by queries to execute in this connection: <strong>".$queries_time."</strong> seconds<br/>\n";
			$html .= "<code>".$queries_log."</code>\n";
		}
		$html .= "</div>\n";
		$html .= "<style>.queries-log code {white-space: normal} .queries-log hr {border-color: #ccc}</style>\n";<commit_msg>the code of explanation of sql queries is commented out<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: all_functions_include.php
| Author: <NAME> (Rimelek)
+--------------------------------------------------------+
| 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;
use PHPFusion\Database\AbstractDatabaseDriver;
use PHPFusion\Database\Exception\SelectionException;

/*
 * It will be called after everything else even if the script is
 * halted by exit(), die(), fatal error or exception.
 *
 * It shows all sent query per connection
 */
register_shutdown_function(function() {
	if (DatabaseFactory::isDebug()) {
		$log = AbstractDatabaseDriver::getGlobalQueryLog();
		foreach ($log as $connectionid => $value) {
			if (!DatabaseFactory::isDebug($connectionid)) {
				unset($log[$connectionid]);
			}
		}
		//print_p($log);

		$html = "<a href='#queries' class='queries-btn btn btn-primary pull-left'>View Queries</a>\n";
		$html .= "<div id='queries' class='well queries-log' style='display: none'>\n";
		foreach ($log as $connID => $queries) {
			$html .= "Database connection ID: '<strong>".$connID."</strong>'<br/>\n";

			$queries_time = 0;
			$queries_log = '';
			foreach ($queries as $key => $query) {
				$queries_time = $queries_time + $query[0];
				// The time and the query
				$queries_log .= "<strong>#".($key + 1)." Time: ".$query[0]."</strong><br/>\n".stripinput($query[1])."<br />\n";
				/*
				 // The query explained
				$exp_title = "";
				$exp_value = "";
				$queries_log .= "<table class='tbl-border'>";
				// For more info on this see: http://dev.mysql.com/doc/refman/5.0/en/explain-output.html
				// and http://dev.mysql.com/doc/refman/5.0/en/explain-extended.html
				foreach (dbarray(dbquery("EXPLAIN EXTENDED ".$query[1]."")) as $key => $value) {
					$exp_title .= "<td class='tbl1 panel panel-default'>".$key."</td>";
					$exp_value .= "<td class='tbl2 panel panel-default'>".($value == '' ? '-' : $value)."</td>";
				}
				$queries_log .= "<tr>".$exp_title."</tr><tr>".$exp_value."</tr>";
				$queries_log .= "</table>";
				
				// For more info on this please see: http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html
				$more_info = dbarray(dbquery("SHOW WARNINGS"));
				if ($more_info) {
					$queries_log .= "<a class='query-more-btn' href='#'>View additional info on this query generated by SHOW WARNINGS</a>";
					$queries_log .= "<table class='tbl-border query-more-info' style='display:none'>";
					$queries_log .= "<tr><td class='tbl1 panel panel-default'>Code</td>
										<td class='tbl1 panel panel-default'>Level</td>
										<td class='tbl1 panel panel-default'>Message</td>
									</tr>";
					$queries_log .= "<tr><td class='tbl2 panel panel-default'>".$more_info['Code']."</td>
										<td class='tbl2 panel panel-default'>".$more_info['Level']."</td>
										<td class='tbl2 panel panel-default'>".stripinput($more_info['Message'])."</td>
									</tr>";
					$queries_log .= "</table>";
				}
				$queries_log .= "<hr />\n";
				*/
			}

			$html .= "Total time taken by queries to execute in this connection: <strong>".$queries_time."</strong> seconds<br/>\n";
			$html .= "<code>".$queries_log."</code>\n";
		}
		$html .= "</div>\n";
		$html .= "<style>.queries-log code {white-space: normal} .queries-log hr {border-color: #ccc}</style>\n";
{'fraction_non_alphanumeric': 0.23783369523566228, 'fraction_numerical': 0.00510920934985311, 'mean_word_length': 2.8176499268649438, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 111, 'https://': 2, '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': '5316880', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2446, 'n_words': 590}