<commit_before><?php
if (!file_exists("./config.php"))
{
header("Location: ./install.php");
}

include("config.php");
include("inc/common.php");
include("inc/common.caching.php");
include("inc/common.posting.php");
include("inc/common.plugins.php");

if (isset($_POST['mode']))
{
$conn = new mysqli($db_host, $db_username, $db_password, $db_database);
loadPlugins($conn);
	$mode = $_POST['mode'];
	switch($mode)
	{
		case "regist":
			$filename = null;
			if (empty($_POST['board']))
			{
			?>
			
<html>
<head>
<title>Error</title>
</head>
<body>
			<?php
				echo "<center><h1>No board selected!</h1></center></body></html>";
				exit;
			}
			$board = $_POST['board'];
			banMessage($conn, $board);
			?>
<html>
<head>
<title>Updating index</title>
</head>
<body>
<center><h1>Updating Index...</h1></center>
			<?php
			
			$md5 = "";
			$bdata = getBoardData($conn, $_POST['board']);
			if ((!empty($_POST['embed'])) && (!empty($_FILES['upfile']['tmp_name'])))
			{
				echo "<center><h1>Choose one: image or embed! ;_;</h1></center></body></html>";
				exit;
			}
			
			$lastdate = $conn->query("SELECT date FROM posts_".$_POST['board']." WHERE ip='".$_SERVER['REMOTE_ADDR']."' ORDER BY date DESC LIMIT 0, 1");
			if ($lastdate->num_rows == 1)
			{
				$pdate = $lastdate->fetch_assoc();
				$pdate = $pdate['date'];
				
				if (($pdate + $bdata['time_between_posts']) > time())
				{
					if ($bdata['embeds']==0)
					{
						echo "<center><h1>You'll have to wait more between posts!</h1></center></body></html>";
						exit;
					}
				}
			}
			if (!empty($_POST['embed']))
			{
				if ($bdata['embeds']==0)
				{
					echo "<center><h1>Embed not supported!</h1></center></body></html>";
					exit;
				}
				
				$embed_table = array();
				$result = $conn->query("SELECT * FROM embeds;");
				while ($row = $result->fetch_assoc())
				{
					$embed_table[] = $row;
				}
				if (isEmbed($_POST['embed'], $embed_table))
				{
					$filename = "embed:".$_POST['embed'];
				} else {
					echo "<center><h1>Embed not supported!</h1></center></body></html>";
					exit;
				}
			} else {
				if ((empty($_FILES['upfile']['tmp_name'])) && (!empty($_FILES['upfile']['name'])))
				{
					echo "<h1>File size too big!</h1></body></html>";
					exit;
				}
				if (!empty($_FILES['upfile']['tmp_name']))
				{
					$target_path = "./".$board."/src/";
					$fileid = time() . mt_rand(10000000, 999999999);
					$ext = pathinfo($_FILES['upfile']['name'], PATHINFO_EXTENSION);
					$filename = $fileid . "." . $ext; 
					$target_path .= $filename;
					$file_size = $_FILES['upfile']['size'];
					if ($file_size > 2097152)
					{
						echo "<h1>File size too big!</h1></body></html>";
						exit;
					}
					if (!isImage($_FILES['upfile']['tmp_name']))
					{
						echo "<h1>File is not an image!</h1></body></html>";
						exit;
					}
					$md5 = md5_file($_FILES['upfile']['tmp_name']);
					if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
						echo "The file ".basename( $_FILES['upfile']['name'])." has been uploaded";
					} else {
						echo "There was an error uploading the file, please try again!";<commit_msg>Little fix won't hurt<commit_after><?php
if (!file_exists("./config.php"))
{
header("Location: ./install.php");
}

include("config.php");
include("inc/common.php");
include("inc/common.caching.php");
include("inc/common.posting.php");
include("inc/common.plugins.php");

if (isset($_POST['mode']))
{
$conn = new mysqli($db_host, $db_username, $db_password, $db_database);
loadPlugins($conn);
	$mode = $_POST['mode'];
	switch($mode)
	{
		case "regist":
			$filename = null;
			if (empty($_POST['board']))
			{
			?>
			
<html>
<head>
<title>Error</title>
</head>
<body>
			<?php
				echo "<center><h1>No board selected!</h1></center></body></html>";
				exit;
			}
			$board = $_POST['board'];
			banMessage($conn, $board);
			?>
<html>
<head>
<title>Updating index</title>
</head>
<body>
<center><h1>Updating Index...</h1></center>
			<?php
			
			$md5 = "";
			$bdata = getBoardData($conn, $_POST['board']);
			if ((!empty($_POST['embed'])) && (!empty($_FILES['upfile']['tmp_name'])))
			{
				echo "<center><h1>Choose one: image or embed! ;_;</h1></center></body></html>";
				exit;
			}
			
			$lastdate = $conn->query("SELECT date FROM posts_".$_POST['board']." WHERE ip='".$_SERVER['REMOTE_ADDR']."' ORDER BY date DESC LIMIT 0, 1");
			if ($lastdate->num_rows == 1)
			{
				$pdate = $lastdate->fetch_assoc();
				$pdate = $pdate['date'];
				
				if (($pdate + $bdata['time_between_posts']) > time())
				{
					if ($bdata['embeds']==0)
					{
						echo "<center><h1>You'll have to wait more between posts!</h1></center></body></html>";
						exit;
					}
				}
			}
			if (!empty($_POST['embed']))
			{
				if ($bdata['embeds']==0)
				{
					echo "<center><h1>Embed not supported!</h1></center></body></html>";
					exit;
				}
				
				$embed_table = array();
				$result = $conn->query("SELECT * FROM embeds;");
				while ($row = $result->fetch_assoc())
				{
					$embed_table[] = $row;
				}
				if (isEmbed($_POST['embed'], $embed_table))
				{
					$filename = "embed:".$_POST['embed'];
				} else {
					echo "<center><h1>Embed not supported!</h1></center></body></html>";
					exit;
				}
			} else {
				if ((empty($_FILES['upfile']['tmp_name'])) && (!empty($_FILES['upfile']['name'])))
				{
					echo "<h1>File size too big!</h1></body></html>";
					exit;
				}
				if (!empty($_FILES['upfile']['tmp_name']))
				{
					$target_path = "./".$board."/src/";
					$fileid = time() . mt_rand(10000000, 999999999);
					$ext = pathinfo($_FILES['upfile']['name'], PATHINFO_EXTENSION);
					$filename = $fileid . "." . $ext; 
					$target_path .= $filename;
					$file_size = $_FILES['upfile']['size'];
					if ($file_size > $bdata['filesize'])
					{
						echo "<h1>File size too big!</h1></body></html>";
						exit;
					}
					if (!isImage($_FILES['upfile']['tmp_name']))
					{
						echo "<h1>File is not an image!</h1></body></html>";
						exit;
					}
					$md5 = md5_file($_FILES['upfile']['tmp_name']);
					if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
						echo "The file ".basename( $_FILES['upfile']['name'])." has been uploaded";
					} else {
						echo "There was an error uploading the file, please try again!";
{'fraction_non_alphanumeric': 0.23635500711912671, 'fraction_numerical': 0.014712861888941622, 'mean_word_length': 3.318306010928962, 'pattern_counts': {'":': 2, '<': 125, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '1243849', 'n_tokens_mistral': 2891, 'n_tokens_neox': 2238, 'n_words': 410}