<commit_before><?php
/**
 * @package tikiwiki
 */
// (c) Copyright 2002-2014 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

$section = 'forums';
require_once ('tiki-setup.php');

$access->check_feature('feature_forums');

$commentslib = TikiLib::lib('comments');
if (!isset($_REQUEST['comments_parentId']) && isset($_REQUEST['threadId'])) {
	$_REQUEST['comments_parentId'] = $_REQUEST['threadId'];
}
if (!isset($_REQUEST['comments_parentId'])) {
	$smarty->assign('msg', tra("No thread indicated"));
	$smarty->display("error.tpl");
	die;
}

if (empty($_REQUEST['forumId'])) {
	$thread_info = $commentslib->get_comment($_REQUEST['comments_parentId']);
	if (empty($thread_info['object']) || $thread_info['objectType'] != 'forum') {
		$smarty->assign('msg', tra('Incorrect thread'));
		$smarty->display('error.tpl');
		die;
	}
	$_REQUEST['forumId'] = $thread_info['object'];
}
$forum_info = $commentslib->get_forum($_REQUEST["forumId"]);
if (empty($forum_info)) {
		$smarty->assign('msg', tra('Incorrect thread'));
		$smarty->display('error.tpl');
		die;
}

$pageCache = Tiki_PageCache::create()
	->disableForRegistered()
	->onlyForGet()
	->requiresPreference('memcache_forum_output')
	->addArray($_GET)
	->addValue('role', 'forum-page-output')
	->addKeys($_REQUEST, array( 'locale', 'forumId', 'comments_parentId' ))
	->checkMeta(
		'forum-page-output-meta-time', array(
			'forumId'           => $jitRequest->forumId->int(),
			'comments_parentId' => $jitRequest->comments_parentId->int(),
		)
	)
	->applyCache();

if ($prefs['feature_categories'] == 'y') {
	$categlib = TikiLib::lib('categ');
}
if (!isset($_REQUEST['topics_offset'])) {
	$_REQUEST['topics_offset'] = 0;
}
if (!isset($_REQUEST['topics_sort_mode']) || empty($_REQUEST['topics_sort_mode'])) {
	$_REQUEST['topics_sort_mode'] = $forum_info['topicOrdering'];
} else {
	$smarty->assign('topics_sort_mode_param', '&amp;topics_sort_mode=' . $_REQUEST['topics_sort_mode']);
}
if (!isset($_REQUEST['topics_find'])) {
	$_REQUEST['topics_find'] = '';
}
if (!isset($_REQUEST['topics_threshold']) || empty($_REQUEST['topics_threshold'])) {
	$_REQUEST['topics_threshold'] = 0;
}
if (isset($_REQUEST["quote"]) && $_REQUEST["quote"]) {
	$quote = $_REQUEST["quote"];
} else {
	$quote = 0;
}
$smarty->assign('quote', $quote);
$comments_parentId = $_REQUEST["comments_parentId"];
if (isset($_REQUEST["openpost"])) {
	$smarty->assign('openpost', 'y');
} else {
	$smarty->assign('openpost', 'n');
}
$smarty->assign('comments_parentId', $_REQUEST["comments_parentId"]);
if (isset($_REQUEST["comments_grandParentId"])) {
	$smarty->assign('comments_grandParentId', $_REQUEST["comments_grandParentId"]);
}
if (isset($_REQUEST["comments_reply_threadId"])) {
	$smarty->assign('comments_reply_threadId', $_REQUEST["comments_reply_threadId"]);
} else {
	$_REQUEST["comments_reply_threadId"] = $_REQUEST["comments_parentId"];
	$smarty->assign('comments_reply_threadId', $_REQUEST["comments_reply_threadId"]);
}
$smarty->assign('forumId', $_REQUEST["forumId"]);
if (isset($_REQUEST['lock'])) {
	check_ticket('view-forum');
	if ($_REQUEST['lock'] == 'y') {
		$commentslib->lock_comment($_REQUEST["comments_parentId"]);
	} elseif ($_REQUEST['lock'] == 'n') {
		$commentslib->unlock_comment($_REQUEST["comments_parentId"]);
	}
}
$commentslib->comment_add_hit($_REQUEST["comments_parentId"]);
$commentslib->mark_comment($user, $_REQUEST['forumId'], $_REQUEST["comments_parentId"]);

$tikilib->get_perm_object($_REQUEST["forumId"], 'forum');

if ($user) {
	if ($forum_info["moderator"] == $user) {
		$tiki_p_admin_forum = 'y';
		$smarty->assign('tiki_p_admin_forum', 'y');
	} elseif (in_array($forum_info['moderator_group'], $userlib->get_user_groups($user))) {
		$tiki_p_admin_forum = 'y';
		$smarty->assign('tiki_p_admin_forum', 'y');
	}
}
if ($tiki_p_admin_forum == 'y') {
	$tiki_p_forum_post = 'y';
	$smarty->assign('tiki_p_forum_post', 'y');
	$tiki_p_forum_read = 'y';
	$smarty->assign('tiki_p_forum_read', 'y');
	$tiki_p_forum_vote = 'y';
	$smarty->assign('tiki_p_forum_vote', 'y');
	$tiki_p_forum_post_topic = 'y';
	$smarty->assign('tiki_p_forum_post_topic', 'y');
}

$access->check_permission(array('tiki_p_forum_read'), '', 'forum', $forum_info['forumId']);

$smarty->assign('topics_next_offset', $_REQUEST['topics_offset'] + 1);
$smarty->assign('topics_prev_offset', $_REQUEST['topics_offset'] - 1);

$threads = $commentslib->get_forum_topics($_REQUEST['forumId'], max(0, $_REQUEST['topics_offset'] - 1), 3, $_REQUEST["topics_sort_mode"]);
if ($threads[0]['threadId'] == $_REQUEST['comments_parentId'] && count($threads) >= 1 && isset($threads[1])) {
	$next_thread = $threads[1];
	$smarty->assign('next_topic', $next_thread['threadId']);
} elseif (count($threads) >= 2 && $threads[1]['threadId'] == $_REQUEST['comments_parentId']) {
	$next_thread = $threads[2];
	$smarty->assign('next_topic', $next_thread['threadId']);
} else {
	$smarty->assign('next_topic', false);
}
if ($threads[0]['threadId'] != $_REQUEST['comments_parentId']) {
	$prev_thread = $threads[0];
	$smarty->assign('prev_topic', $prev_thread['threadId']);
} else {
	$smarty->assign('prev_topic', false);
}

if ($tiki_p_admin_forum == 'y') {
	if (isset($_REQUEST['delsel'])) {
		if (isset($_REQUEST['forumthread'])) {
			check_ticket('view-forum');
			foreach (array_values($_REQUEST['forumthread']) as $thread) {
				$commentslib->remove_comment($thread);
				$commentslib->register_remove_post($_REQUEST['forumId'], $_REQUEST['comments_parentId']);
			}
		}
	}
	if (isset($_REQUEST['remove_attachment'])) {
		$access->check_authenticity(tra('Are you sure you want to remove that attachment?'));
		$commentslib->remove_thread_attachment($_REQUEST['remove_attachment']);
	}
	if (isset($_REQUEST['movesel'])) {
		if (isset($_REQUEST['forumthread'])) {
			check_ticket('view-forum');
			foreach (array_values($_REQUEST['forumthread']) as $thread) {
				$commentslib->set_parent($thread, $_REQUEST['moveto']);
			}
		}
	}
	if ($prefs['feature_forum_topics_archiving'] == 'y' && isset($_REQUEST['archive']) && isset($_REQUEST['comments_parentId'])) {
		check_ticket('view-forum');
		if ($_REQUEST['archive'] == 'y') {
			$commentslib->archive_thread($_REQUEST['comments_parentId']);
		} elseif ($_REQUEST['archive'] == 'n') {
			$commentslib->unarchive_thread($_REQUEST['comments_parentId']);
		}<commit_msg>[FIX] forum: remove merge action converted to ajax services in r53458<commit_after><?php
/**
 * @package tikiwiki
 */
// (c) Copyright 2002-2014 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

$section = 'forums';
require_once ('tiki-setup.php');

$access->check_feature('feature_forums');

$commentslib = TikiLib::lib('comments');
if (!isset($_REQUEST['comments_parentId']) && isset($_REQUEST['threadId'])) {
	$_REQUEST['comments_parentId'] = $_REQUEST['threadId'];
}
if (!isset($_REQUEST['comments_parentId'])) {
	$smarty->assign('msg', tra("No thread indicated"));
	$smarty->display("error.tpl");
	die;
}

if (empty($_REQUEST['forumId'])) {
	$thread_info = $commentslib->get_comment($_REQUEST['comments_parentId']);
	if (empty($thread_info['object']) || $thread_info['objectType'] != 'forum') {
		$smarty->assign('msg', tra('Incorrect thread'));
		$smarty->display('error.tpl');
		die;
	}
	$_REQUEST['forumId'] = $thread_info['object'];
}
$forum_info = $commentslib->get_forum($_REQUEST["forumId"]);
if (empty($forum_info)) {
		$smarty->assign('msg', tra('Incorrect thread'));
		$smarty->display('error.tpl');
		die;
}

$pageCache = Tiki_PageCache::create()
	->disableForRegistered()
	->onlyForGet()
	->requiresPreference('memcache_forum_output')
	->addArray($_GET)
	->addValue('role', 'forum-page-output')
	->addKeys($_REQUEST, array( 'locale', 'forumId', 'comments_parentId' ))
	->checkMeta(
		'forum-page-output-meta-time', array(
			'forumId'           => $jitRequest->forumId->int(),
			'comments_parentId' => $jitRequest->comments_parentId->int(),
		)
	)
	->applyCache();

if ($prefs['feature_categories'] == 'y') {
	$categlib = TikiLib::lib('categ');
}
if (!isset($_REQUEST['topics_offset'])) {
	$_REQUEST['topics_offset'] = 0;
}
if (!isset($_REQUEST['topics_sort_mode']) || empty($_REQUEST['topics_sort_mode'])) {
	$_REQUEST['topics_sort_mode'] = $forum_info['topicOrdering'];
} else {
	$smarty->assign('topics_sort_mode_param', '&amp;topics_sort_mode=' . $_REQUEST['topics_sort_mode']);
}
if (!isset($_REQUEST['topics_find'])) {
	$_REQUEST['topics_find'] = '';
}
if (!isset($_REQUEST['topics_threshold']) || empty($_REQUEST['topics_threshold'])) {
	$_REQUEST['topics_threshold'] = 0;
}
if (isset($_REQUEST["quote"]) && $_REQUEST["quote"]) {
	$quote = $_REQUEST["quote"];
} else {
	$quote = 0;
}
$smarty->assign('quote', $quote);
$comments_parentId = $_REQUEST["comments_parentId"];
if (isset($_REQUEST["openpost"])) {
	$smarty->assign('openpost', 'y');
} else {
	$smarty->assign('openpost', 'n');
}
$smarty->assign('comments_parentId', $_REQUEST["comments_parentId"]);
if (isset($_REQUEST["comments_grandParentId"])) {
	$smarty->assign('comments_grandParentId', $_REQUEST["comments_grandParentId"]);
}
if (isset($_REQUEST["comments_reply_threadId"])) {
	$smarty->assign('comments_reply_threadId', $_REQUEST["comments_reply_threadId"]);
} else {
	$_REQUEST["comments_reply_threadId"] = $_REQUEST["comments_parentId"];
	$smarty->assign('comments_reply_threadId', $_REQUEST["comments_reply_threadId"]);
}
$smarty->assign('forumId', $_REQUEST["forumId"]);
if (isset($_REQUEST['lock'])) {
	check_ticket('view-forum');
	if ($_REQUEST['lock'] == 'y') {
		$commentslib->lock_comment($_REQUEST["comments_parentId"]);
	} elseif ($_REQUEST['lock'] == 'n') {
		$commentslib->unlock_comment($_REQUEST["comments_parentId"]);
	}
}
$commentslib->comment_add_hit($_REQUEST["comments_parentId"]);
$commentslib->mark_comment($user, $_REQUEST['forumId'], $_REQUEST["comments_parentId"]);

$tikilib->get_perm_object($_REQUEST["forumId"], 'forum');

if ($user) {
	if ($forum_info["moderator"] == $user) {
		$tiki_p_admin_forum = 'y';
		$smarty->assign('tiki_p_admin_forum', 'y');
	} elseif (in_array($forum_info['moderator_group'], $userlib->get_user_groups($user))) {
		$tiki_p_admin_forum = 'y';
		$smarty->assign('tiki_p_admin_forum', 'y');
	}
}
if ($tiki_p_admin_forum == 'y') {
	$tiki_p_forum_post = 'y';
	$smarty->assign('tiki_p_forum_post', 'y');
	$tiki_p_forum_read = 'y';
	$smarty->assign('tiki_p_forum_read', 'y');
	$tiki_p_forum_vote = 'y';
	$smarty->assign('tiki_p_forum_vote', 'y');
	$tiki_p_forum_post_topic = 'y';
	$smarty->assign('tiki_p_forum_post_topic', 'y');
}

$access->check_permission(array('tiki_p_forum_read'), '', 'forum', $forum_info['forumId']);

$smarty->assign('topics_next_offset', $_REQUEST['topics_offset'] + 1);
$smarty->assign('topics_prev_offset', $_REQUEST['topics_offset'] - 1);

$threads = $commentslib->get_forum_topics($_REQUEST['forumId'], max(0, $_REQUEST['topics_offset'] - 1), 3, $_REQUEST["topics_sort_mode"]);
if ($threads[0]['threadId'] == $_REQUEST['comments_parentId'] && count($threads) >= 1 && isset($threads[1])) {
	$next_thread = $threads[1];
	$smarty->assign('next_topic', $next_thread['threadId']);
} elseif (count($threads) >= 2 && $threads[1]['threadId'] == $_REQUEST['comments_parentId']) {
	$next_thread = $threads[2];
	$smarty->assign('next_topic', $next_thread['threadId']);
} else {
	$smarty->assign('next_topic', false);
}
if ($threads[0]['threadId'] != $_REQUEST['comments_parentId']) {
	$prev_thread = $threads[0];
	$smarty->assign('prev_topic', $prev_thread['threadId']);
} else {
	$smarty->assign('prev_topic', false);
}

if ($tiki_p_admin_forum == 'y') {
	if (isset($_REQUEST['delsel'])) {
		if (isset($_REQUEST['forumthread'])) {
			check_ticket('view-forum');
			foreach (array_values($_REQUEST['forumthread']) as $thread) {
				$commentslib->remove_comment($thread);
				$commentslib->register_remove_post($_REQUEST['forumId'], $_REQUEST['comments_parentId']);
			}
		}
	}
	if (isset($_REQUEST['remove_attachment'])) {
		$access->check_authenticity(tra('Are you sure you want to remove that attachment?'));
		$commentslib->remove_thread_attachment($_REQUEST['remove_attachment']);
	}
	if ($prefs['feature_forum_topics_archiving'] == 'y' && isset($_REQUEST['archive']) && isset($_REQUEST['comments_parentId'])) {
		check_ticket('view-forum');
		if ($_REQUEST['archive'] == 'y') {
			$commentslib->archive_thread($_REQUEST['comments_parentId']);
		} elseif ($_REQUEST['archive'] == 'n') {
			$commentslib->unarchive_thread($_REQUEST['comments_parentId']);
		}
{'fraction_non_alphanumeric': 0.21689194468317838, 'fraction_numerical': 0.004297210719587468, 'mean_word_length': 7.821502412129566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 126, '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': '4862565', 'n_tokens_mistral': 4663, 'n_tokens_neox': 4431, 'n_words': 639}