<commit_before><?php

$rootpath = './';
$page_access = 'guest';
require_once $rootpath . 'includes/inc_default.php';

$fa = 'comments-o';

$mdb->connect();

$topic = (isset($_GET['t'])) ? $_GET['t'] : false;
$del = (isset($_GET['del'])) ? $_GET['del'] : false;
$edit = (isset($_GET['edit'])) ? $_GET['edit'] : false;
$add = (isset($_GET['add'])) ? true : false;
$q = (isset($_GET['q'])) ? $_GET['q'] : '';

if (!($s_user || $s_admin))
{
	if ($del)
	{
		$alert->error('Je hebt geen rechten om te verwijderen.');
		cancel();
	}
	if ($add)
	{
		$alert->error('Je hebt geen rechten om te toe te voegen.');
		cancel();
	}
	if ($edit)
	{
		$alert->error('Je hebt geen rechten om aan te passen.');
		cancel();
	}
}

$submit = (isset($_POST['zend'])) ? true : false;

if (!readconfigfromdb('forum_en'))
{
	$alert->error('De forum pagina is niet ingeschakeld.');
	redirect_index();
}

if ($del || $edit)
{
	$t = ($del) ? $del : $edit;

	$forum_post = $mdb->forum->findOne(['_id' => new MongoId($t)]);

	if (!$forum_post)
	{
		$alert->error('Post niet gevonden.');
		cancel();
	}

	$s_owner = ($forum_post['uid'] == $s_id && $s_group_self) ? true : false;

	if (!($s_admin || $s_owner))
	{
		$str = ($forum_post['parent_id']) ? 'deze reactie' : 'dit onderwerp';

		if ($del)
		{
			$alert->error('Je hebt onvoldoende rechten om ' . $str . ' te verwijderen.');
		}
		else
		{
			$alert->error('Je hebt onvoldoende rechten om ' . $str . ' aan te passen.');
		}

		cancel(($forum_post['parent_id']) ?: $t);
	}

	$topic = (isset($forum_post['parent_id'])) ? $forum_post['parent_id'] : false;
}

if ($submit)
{
	if ($del)
	{
		if ($error_token = get_error_form_token())
		{
			$alert->error($error_token);
			cancel();
		}

		$mdb->forum->remove(
			['_id' => new MongoId($del)],
			['justOne'	=> true]
		);

		if (!$forum_post['parent_id'])
		{
			$mdb->forum->remove(
				['parent_id' => $del]
			);

			$alert->success('Het forum onderwerp is verwijderd.');
			cancel();
		}

		$alert->success('De reactie is verwijderd.');
		cancel($forum_post['parent_id']);
	}

	$content = $_POST['content'];

	$content = trim(preg_replace('/(<br>)+$/', '', $_POST['content']));

	$content = str_replace(["\n", "\r", '<p>&nbsp;</p>'], '', $content);

	$content = trim($content);

	$forum_post = ['content'	=> $content];

	if ($topic)
	{
		$forum_post['parent_id'] = $topic;
	}
	else
	{
		$forum_post['subject'] = $_POST['subject'];
		$forum_post['access']	= $access_control->get_post_value(); // $_POST['access'];
	}

	if ($edit)
	{
		$forum_post['modified'] = gmdate('Y-m-d H:i:s');
	}
	else
	{
		$forum_post['ts'] = gmdate('Y-m-d H:i:s');
		$forum_post['uid'] = ($s_master) ? 0 : $s_id;
	}

 	if (!($forum_post['subject'] || $topic))
	{
		 $errors[] = 'Vul een onderwerp in.';
	}

 	if (strlen($forum_post['content']) < 2)
	{
		 $errors[] = 'De inhoud van je bericht is te kort.';
	}

	if (!$topic)
	{
		$access_error = $access_control->get_post_error();

		if ($access_error)
		{
			$errors[] = $access_error;
		}
	}

	if (!$topic && ($forum_post['access'] < $access_level || $forum_post['access'] > 2))
	{
		$errors[] = 'Ongeldige zichtbaarheid';
	}

	if ($token_error = get_error_form_token())
	{
		$errors[] = $token_error;
	}

	if (count($errors))
	{
		$alert->error($errors);
	}
	else if ($edit)
	{
		$mdb->forum->update(['_id' => new MongoId($edit)],
			['$set'	=> $forum_post, '$inc' => ['edit_count' => 1]],
			['upsert'	=> true]);

		$alert->success((($topic) ? 'Reactie' : 'Onderwerp') . ' aangepast.');
		cancel($topic);
	}
	else
	{
		$mdb->forum->insert($forum_post);

		$alert->success((($topic) ? 'Reactie' : 'Onderwerp') . ' toegevoegd.');
		cancel($topic);
	}
}

if ($del)
{
	if (isset($forum_post['parent_id']))
	{
		$h1 = 'Reactie';
		$t = $forum_post['parent_id'];
	}
	else
	{
		$t = $forum_post['_id']->__toString();
		$h1 = 'Forum onderwerp ' . aphp('forum', ['t' => $t], $forum_post['subject']);
	}

	$h1 .= ' verwijderen?';

	require_once $rootpath . 'includes/inc_header.php';

	echo '<div class="panel panel-info">';
	echo '<div class="panel-heading">';

	echo '<p>' . $forum_post['content'] . '</p>';

	echo '<form method="post">';

	echo aphp('forum', ['t' => $t], 'Annuleren', 'btn btn-default') . '&nbsp;';
	echo '<input type="submit" value="Verwijderen" name="zend" class="btn btn-danger">';
	generate_form_token();

	echo '</form>';

	echo '</div>';
	echo '</div>';
	require_once $rootpath . 'includes/inc_footer.php';
	exit;
}

/**
 * add / edit topic / reply
 */

if ($add || $edit)
{
	$includejs = '<script src="' . $cdn_ckeditor . '"></script>
		<script src="' . $rootpath . 'js/forum.js"></script>
		<script src="' . $rootpath . 'js/access_input_cache.js"></script>';

	if ($topic)
	{
		$topic_id = new MongoId($topic);
		$topic_post = $mdb->forum->findOne(['_id' => $topic_id]);

		if ($topic_post['access'] < $access_level)
		{
			$alert->error('Je hebt geen toegang tot dit forum onderwerp.');
			cancel();
		}
	}

	if ($edit)
	{
		$h1 = ($topic) ? 'Reactie aanpassen' : 'Forum onderwerp aanpassen';
	}
	else
	{
		$h1 = ($topic) ? 'Nieuwe reactie' : 'Nieuw forum onderwerp';
	}

	include $rootpath . 'includes/inc_header.php';

	echo '<div class="panel panel-info" id="add">';
	echo '<div class="panel-heading">';

	echo '<form method="post" class="form-horizontal">';

	if (!$topic)
	{
		echo '<div class="form-group">';
		echo '<div class="col-sm-12">';
		echo '<input type="text" class="form-control" id="subject" name="subject" ';
		echo 'placeholder="Onderwerp" ';
		echo 'value="' . $forum_post['subject'] . '" required>';
		echo '</div>';
		echo '</div>';
	}

	echo '<div class="form-group">';
	echo '<div class="col-sm-12">';
	echo '<textarea name="content" class="form-control" id="content" rows="4" required>';
	echo $forum_post['content'];
	echo '</textarea>';
	echo '</div>';
	echo '</div>';

	if (!$topic)
	{
		if (!$edit)
		{
			$forum_post['access'] = false;
		}

		if ($s_user)
		{
			$omit_access = 'admin';
			$forum_post['access'] = ($forum_post['access']) ?: 1;
		}
		else
		{
			$omit_access = false;
		}

		echo $access_control->get_radio_buttons('forum_topic', $forum_post['access'], $omit_access);
	}

	$str = ($topic) ? 'Reactie' : 'Onderwerp';
	$btn = ($edit) ? 'primary' : 'success';
	$action = ($edit) ? 'aanpassen' : 'toevoegen';
	$cancel_dest = ($topic) ? ['t' => $topic] : [];

	echo aphp('forum', $cancel_dest, 'Annuleren', 'btn btn-default') . '&nbsp;';
	echo '<input type="submit" name="zend" value="' . $str . ' ' . $action . '" class="btn btn-' . $btn . '">';
	generate_form_token();

	echo '</form>';

	echo '</div>';
	echo '</div>';

	include $rootpath . 'includes/inc_footer.php';
	exit;
}

/**
 * Show topic
 */
 
if ($topic)
{
	$topic_id = new MongoId($topic);
	$topic_post = $mdb->forum->findOne(['_id' => $topic_id]);

	if ($topic_post['access'] < $access_level)
	{
		$alert->error('Je hebt geen toegang tot dit forum onderwerp.');
		cancel();
	}

	$find = ['$or'=> [['parent_id' => $topic], ['_id' => $topic_id]]];

	$forum_posts = $mdb->forum->find($find);
	$forum_posts->sort(['ts' => (($topic) ? 1 : -1)]);

	$forum_posts = iterator_to_array($forum_posts);

	$s_owner = ($s_id && $forum_posts[$topic]['uid'] == $s_id && $s_group_self) ? true : false;

	$find = [
		'parent_id' => ['$exists' => false],
		'access'	=> ['$gte'	=> (string) $access_level],
		'ts' 		=> ['$lt' => $topic_post['ts']],
	];

	$prev = $mdb->forum->findOne($find);

	$prev = ($prev) ? $prev['_id']->__toString() : false;

	$find = [
		'parent_id' => ['$exists' => false],
		'access' 	=> ['$gte'	=> (string) $access_level],
		'ts' 		=> ['$gt' => $topic_post['ts']],
	];

	$next = $mdb->forum->findOne($find);

	$next = ($next) ? $next['_id']->__toString() : false;

	if ($s_admin || $s_owner)
	{
		$top_buttons .= aphp('forum', ['del' => $topic], 'Onderwerp verwijderen', 'btn btn-danger', 'Onderwerp verwijderen', 'times', true);
	}

	if ($prev)
	{
		$top_buttons .= aphp('forum', ['t' => $prev], 'Vorige', 'btn btn-default', 'Vorige', 'chevron-down', true);
	}

	if ($next)
	{
		$top_buttons .= aphp('forum', ['t' => $next], 'Volgende', 'btn btn-default', 'Volgende', 'chevron-up', true);
	}

	$top_buttons .= aphp('forum', [], 'Forum onderwerpen', 'btn btn-default', 'Forum onderwerpen', 'comments', true);

	$includejs = '<script src="' . $cdn_ckeditor . '"></script>
		<script src="' . $rootpath . 'js/forum.js"></script>';

	$h1 = $forum_posts[$topic]['subject'];

	require_once $rootpath . 'includes/inc_header.php';

	foreach ($forum_posts as $p)
	{
		$s_owner = (($p['uid'] == $s_id) && $s_group_self) ? true : false;

		$pid = $p['_id']->__toString();

		echo '<div class="panel panel-default printview">';

		echo '<div class="panel-body">';
		echo $p['content'];
		echo '</div>';

		echo '<div class="panel-footer">';
		echo '<p>' . link_user((int) $p['uid']) . ' @' . $p['ts'];
		echo (isset($p['edit_count'])) ? ' Aangepast: ' . $p['edit_count'] : '';

		if ($s_admin || $s_owner)
		{
			echo '<span class="inline-buttons pull-right">';
			echo aphp('forum', ['edit' => $pid], 'Aanpassen', 'btn btn-primary btn-xs', false, 'pencil');
			echo aphp('forum', ['del' => $pid], 'Verwijderen', 'btn btn-danger btn-xs', false, 'times');
			echo '</span>';
		}
<commit_msg>show access level in forum topic<commit_after><?php

$rootpath = './';
$page_access = 'guest';
require_once $rootpath . 'includes/inc_default.php';

$fa = 'comments-o';

$mdb->connect();

$topic = (isset($_GET['t'])) ? $_GET['t'] : false;
$del = (isset($_GET['del'])) ? $_GET['del'] : false;
$edit = (isset($_GET['edit'])) ? $_GET['edit'] : false;
$add = (isset($_GET['add'])) ? true : false;
$q = (isset($_GET['q'])) ? $_GET['q'] : '';

if (!($s_user || $s_admin))
{
	if ($del)
	{
		$alert->error('Je hebt geen rechten om te verwijderen.');
		cancel();
	}
	if ($add)
	{
		$alert->error('Je hebt geen rechten om te toe te voegen.');
		cancel();
	}
	if ($edit)
	{
		$alert->error('Je hebt geen rechten om aan te passen.');
		cancel();
	}
}

$submit = (isset($_POST['zend'])) ? true : false;

if (!readconfigfromdb('forum_en'))
{
	$alert->error('De forum pagina is niet ingeschakeld.');
	redirect_index();
}

if ($del || $edit)
{
	$t = ($del) ? $del : $edit;

	$forum_post = $mdb->forum->findOne(['_id' => new MongoId($t)]);

	if (!$forum_post)
	{
		$alert->error('Post niet gevonden.');
		cancel();
	}

	$s_owner = ($forum_post['uid'] == $s_id && $s_group_self) ? true : false;

	if (!($s_admin || $s_owner))
	{
		$str = ($forum_post['parent_id']) ? 'deze reactie' : 'dit onderwerp';

		if ($del)
		{
			$alert->error('Je hebt onvoldoende rechten om ' . $str . ' te verwijderen.');
		}
		else
		{
			$alert->error('Je hebt onvoldoende rechten om ' . $str . ' aan te passen.');
		}

		cancel(($forum_post['parent_id']) ?: $t);
	}

	$topic = (isset($forum_post['parent_id'])) ? $forum_post['parent_id'] : false;
}

if ($submit)
{
	if ($del)
	{
		if ($error_token = get_error_form_token())
		{
			$alert->error($error_token);
			cancel();
		}

		$mdb->forum->remove(
			['_id' => new MongoId($del)],
			['justOne'	=> true]
		);

		if (!$forum_post['parent_id'])
		{
			$mdb->forum->remove(
				['parent_id' => $del]
			);

			$alert->success('Het forum onderwerp is verwijderd.');
			cancel();
		}

		$alert->success('De reactie is verwijderd.');
		cancel($forum_post['parent_id']);
	}

	$content = $_POST['content'];

	$content = trim(preg_replace('/(<br>)+$/', '', $_POST['content']));

	$content = str_replace(["\n", "\r", '<p>&nbsp;</p>'], '', $content);

	$content = trim($content);

	$forum_post = ['content'	=> $content];

	if ($topic)
	{
		$forum_post['parent_id'] = $topic;
	}
	else
	{
		$forum_post['subject'] = $_POST['subject'];
		$forum_post['access']	= $access_control->get_post_value(); // $_POST['access'];
	}

	if ($edit)
	{
		$forum_post['modified'] = gmdate('Y-m-d H:i:s');
	}
	else
	{
		$forum_post['ts'] = gmdate('Y-m-d H:i:s');
		$forum_post['uid'] = ($s_master) ? 0 : $s_id;
	}

 	if (!($forum_post['subject'] || $topic))
	{
		 $errors[] = 'Vul een onderwerp in.';
	}

 	if (strlen($forum_post['content']) < 2)
	{
		 $errors[] = 'De inhoud van je bericht is te kort.';
	}

	if (!$topic)
	{
		$access_error = $access_control->get_post_error();

		if ($access_error)
		{
			$errors[] = $access_error;
		}
	}

	if (!$topic && ($forum_post['access'] < $access_level || $forum_post['access'] > 2))
	{
		$errors[] = 'Ongeldige zichtbaarheid';
	}

	if ($token_error = get_error_form_token())
	{
		$errors[] = $token_error;
	}

	if (count($errors))
	{
		$alert->error($errors);
	}
	else if ($edit)
	{
		$mdb->forum->update(['_id' => new MongoId($edit)],
			['$set'	=> $forum_post, '$inc' => ['edit_count' => 1]],
			['upsert'	=> true]);

		$alert->success((($topic) ? 'Reactie' : 'Onderwerp') . ' aangepast.');
		cancel($topic);
	}
	else
	{
		$mdb->forum->insert($forum_post);

		$alert->success((($topic) ? 'Reactie' : 'Onderwerp') . ' toegevoegd.');
		cancel($topic);
	}
}

if ($del)
{
	if (isset($forum_post['parent_id']))
	{
		$h1 = 'Reactie';
		$t = $forum_post['parent_id'];
	}
	else
	{
		$t = $forum_post['_id']->__toString();
		$h1 = 'Forum onderwerp ' . aphp('forum', ['t' => $t], $forum_post['subject']);
	}

	$h1 .= ' verwijderen?';

	require_once $rootpath . 'includes/inc_header.php';

	echo '<div class="panel panel-info">';
	echo '<div class="panel-heading">';

	echo '<p>' . $forum_post['content'] . '</p>';

	echo '<form method="post">';

	echo aphp('forum', ['t' => $t], 'Annuleren', 'btn btn-default') . '&nbsp;';
	echo '<input type="submit" value="Verwijderen" name="zend" class="btn btn-danger">';
	generate_form_token();

	echo '</form>';

	echo '</div>';
	echo '</div>';
	require_once $rootpath . 'includes/inc_footer.php';
	exit;
}

/**
 * add / edit topic / reply
 */

if ($add || $edit)
{
	$includejs = '<script src="' . $cdn_ckeditor . '"></script>
		<script src="' . $rootpath . 'js/forum.js"></script>
		<script src="' . $rootpath . 'js/access_input_cache.js"></script>';

	if ($topic)
	{
		$topic_id = new MongoId($topic);
		$topic_post = $mdb->forum->findOne(['_id' => $topic_id]);

		if ($topic_post['access'] < $access_level)
		{
			$alert->error('Je hebt geen toegang tot dit forum onderwerp.');
			cancel();
		}
	}

	if ($edit)
	{
		$h1 = ($topic) ? 'Reactie aanpassen' : 'Forum onderwerp aanpassen';
	}
	else
	{
		$h1 = ($topic) ? 'Nieuwe reactie' : 'Nieuw forum onderwerp';
	}

	include $rootpath . 'includes/inc_header.php';

	echo '<div class="panel panel-info" id="add">';
	echo '<div class="panel-heading">';

	echo '<form method="post" class="form-horizontal">';

	if (!$topic)
	{
		echo '<div class="form-group">';
		echo '<div class="col-sm-12">';
		echo '<input type="text" class="form-control" id="subject" name="subject" ';
		echo 'placeholder="Onderwerp" ';
		echo 'value="' . $forum_post['subject'] . '" required>';
		echo '</div>';
		echo '</div>';
	}

	echo '<div class="form-group">';
	echo '<div class="col-sm-12">';
	echo '<textarea name="content" class="form-control" id="content" rows="4" required>';
	echo $forum_post['content'];
	echo '</textarea>';
	echo '</div>';
	echo '</div>';

	if (!$topic)
	{
		if (!$edit)
		{
			$forum_post['access'] = false;
		}

		if ($s_user)
		{
			$omit_access = 'admin';
			$forum_post['access'] = ($forum_post['access']) ?: 1;
		}
		else
		{
			$omit_access = false;
		}

		echo $access_control->get_radio_buttons('forum_topic', $forum_post['access'], $omit_access);
	}

	$str = ($topic) ? 'Reactie' : 'Onderwerp';
	$btn = ($edit) ? 'primary' : 'success';
	$action = ($edit) ? 'aanpassen' : 'toevoegen';
	$cancel_dest = ($topic) ? ['t' => $topic] : [];

	echo aphp('forum', $cancel_dest, 'Annuleren', 'btn btn-default') . '&nbsp;';
	echo '<input type="submit" name="zend" value="' . $str . ' ' . $action . '" class="btn btn-' . $btn . '">';
	generate_form_token();

	echo '</form>';

	echo '</div>';
	echo '</div>';

	include $rootpath . 'includes/inc_footer.php';
	exit;
}

/**
 * Show topic
 */
 
if ($topic)
{
	$topic_id = new MongoId($topic);
	$topic_post = $mdb->forum->findOne(['_id' => $topic_id]);

	if ($topic_post['access'] < $access_level)
	{
		$alert->error('Je hebt geen toegang tot dit forum onderwerp.');
		cancel();
	}

	$find = ['$or'=> [['parent_id' => $topic], ['_id' => $topic_id]]];

	$forum_posts = $mdb->forum->find($find);
	$forum_posts->sort(['ts' => (($topic) ? 1 : -1)]);

	$forum_posts = iterator_to_array($forum_posts);

	$s_owner = ($s_id && $forum_posts[$topic]['uid'] == $s_id && $s_group_self) ? true : false;

	$find = [
		'parent_id' => ['$exists' => false],
		'access'	=> ['$gte'	=> (string) $access_level],
		'ts' 		=> ['$lt' => $topic_post['ts']],
	];

	$prev = $mdb->forum->findOne($find);

	$prev = ($prev) ? $prev['_id']->__toString() : false;

	$find = [
		'parent_id' => ['$exists' => false],
		'access' 	=> ['$gte'	=> (string) $access_level],
		'ts' 		=> ['$gt' => $topic_post['ts']],
	];

	$next = $mdb->forum->findOne($find);

	$next = ($next) ? $next['_id']->__toString() : false;

	if ($s_admin || $s_owner)
	{
		$top_buttons .= aphp('forum', ['del' => $topic], 'Onderwerp verwijderen', 'btn btn-danger', 'Onderwerp verwijderen', 'times', true);
	}

	if ($prev)
	{
		$top_buttons .= aphp('forum', ['t' => $prev], 'Vorige', 'btn btn-default', 'Vorige', 'chevron-down', true);
	}

	if ($next)
	{
		$top_buttons .= aphp('forum', ['t' => $next], 'Volgende', 'btn btn-default', 'Volgende', 'chevron-up', true);
	}

	$top_buttons .= aphp('forum', [], 'Forum onderwerpen', 'btn btn-default', 'Forum onderwerpen', 'comments', true);

	$includejs = '<script src="' . $cdn_ckeditor . '"></script>
		<script src="' . $rootpath . 'js/forum.js"></script>';

	$h1 = $forum_posts[$topic]['subject'];

	require_once $rootpath . 'includes/inc_header.php';

	if (!$s_guest)
	{
		echo '<p>Zichtbaarheid: ';
		echo $access_control->get_label($topic_post['access']);
		echo '</p>';
	}

	foreach ($forum_posts as $p)
	{
		$s_owner = (($p['uid'] == $s_id) && $s_group_self) ? true : false;

		$pid = $p['_id']->__toString();

		echo '<div class="panel panel-default printview">';

		echo '<div class="panel-body">';
		echo $p['content'];
		echo '</div>';

		echo '<div class="panel-footer">';
		echo '<p>' . link_user((int) $p['uid']) . ' @' . $p['ts'];
		echo (isset($p['edit_count'])) ? ' Aangepast: ' . $p['edit_count'] : '';

		if ($s_admin || $s_owner)
		{
			echo '<span class="inline-buttons pull-right">';
			echo aphp('forum', ['edit' => $pid], 'Aanpassen', 'btn btn-primary btn-xs', false, 'pencil');
			echo aphp('forum', ['del' => $pid], 'Verwijderen', 'btn btn-danger btn-xs', false, 'times');
			echo '</span>';
		}

{'fraction_non_alphanumeric': 0.25078082929456114, 'fraction_numerical': 0.0019386106623586429, 'mean_word_length': 4.108940852819807, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 262, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '160129', 'n_tokens_mistral': 7977, 'n_tokens_neox': 7399, 'n_words': 1461}