<commit_before><?php declare(strict_types=1);

function htmliseMessage($message) {
	$message = htmlentities($message, ENT_COMPAT, 'utf-8');
	$message = str_replace('&lt;br /&gt;', '<br />', $message);
	return $message;
}

function parseBoolean($check) {
	// Only negative strings are not implicitly converted to the correct bool
	if (is_string($check) && (strcasecmp($check, 'NO') == 0 || strcasecmp($check, 'FALSE') == 0)) {
		return false;
	}
	return (bool)$check;
}

function linkCombatLog($logID) {
	$container = Page::create('combat_log_viewer_verify.php');
	$container['log_id'] = $logID;
	return '<a href="' . $container->href() . '"><img src="images/notify.gif" width="14" height="11" border="0" title="View the combat log" /></a>';
}

/**
 * Converts a BBCode tag into some other text depending on the tag and value.
 * This is called in two stages: first with action BBCODE_CHECK (where the
 * returned value must be a boolean) and second, if the first check passes,
 * with action BBCODE_OUTPUT.
 */
function smrBBCode($bbParser, $action, $tagName, $default, $tagParams, $tagContent) {
	global $overrideGameID, $disableBBLinks, $player, $account, $var;
	$session = Smr\Session::getInstance();
	try {
		switch ($tagName) {
			case 'combatlog':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$logID = (int)$default;
				return linkCombatLog($logID);
			break;
			case 'player':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$playerID = (int)$default;
				$bbPlayer = SmrPlayer::getPlayerByPlayerID($playerID, $overrideGameID);
				$showAlliance = isset($tagParams['showalliance']) ? parseBoolean($tagParams['showalliance']) : false;
				if ($disableBBLinks === false && $overrideGameID == $session->getGameID()) {
					return $bbPlayer->getLinkedDisplayName($showAlliance);
				}
				return $bbPlayer->getDisplayName($showAlliance);
			break;
			case 'alliance':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$allianceID = (int)$default;
				$alliance = SmrAlliance::getAlliance($allianceID, $overrideGameID);
				if ($disableBBLinks === false && $overrideGameID == $session->getGameID()) {
					$container = Page::create('skeleton.php');
					$container['alliance_id'] = $alliance->getAllianceID();
					if (is_object($player) && $alliance->getAllianceID() == $player->getAllianceID()) {
						$container['body'] = 'alliance_mod.php';
					} else {
						$container['body'] = 'alliance_roster.php';
					}
					return create_link($container, $alliance->getAllianceDisplayName());
				}
				return $alliance->getAllianceDisplayName();
			break;
			case 'race':
				$raceNameID = $default;
				foreach (Globals::getRaces() as $raceID => $raceInfo) {
					if ((is_numeric($raceNameID) && $raceNameID == $raceID)
						|| $raceNameID == $raceInfo['Race Name']) {
						if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
							return true;
						}
						$linked = $disableBBLinks === false && $overrideGameID == $session->getGameID();
						return AbstractSmrPlayer::getColouredRaceNameOrDefault($raceID, $player, $linked);
					}
				}
			break;
			case 'servertimetouser':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return true;
				}
				$timeString = $default;
				if ($timeString != '' && ($time = strtotime($timeString)) !== false) {
					if (is_object($account)) {
						$time += $account->getOffset() * 3600;
					}
					return date(DATE_FULL_SHORT, $time);
				}
			break;
			case 'chess':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$chessGameID = (int)$default;
				$chessGame = ChessGame::getChessGame($chessGameID);
				return '<a href="' . $chessGame->getPlayGameHREF() . '">chess game (' . $chessGame->getChessGameID() . ')</a>';
			break;

			case 'sector':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}

				$sectorID = (int)$default;
				$sectorTag = '<span class="sectorColour">#' . $sectorID . '</span>';

				// The use of $var here is for a corner case where an admin can check reported messages whilst being in-game.
				// Ugly but working, probably want a better mechanism to check if more BBCode tags get added
				if ($disableBBLinks === false
					&& $session->hasGame()
					&& $session->getGameID() == $overrideGameID
					&& SmrSector::sectorExists($overrideGameID, $sectorID)) {
					return '<a href="' . Globals::getPlotCourseHREF($player->getSectorID(), $sectorID) . '">' . $sectorTag . '</a>';
				}

				return $sectorTag;
			break;
			case 'join_alliance':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$allianceID = (int)$default;
				$alliance = SmrAlliance::getAlliance($allianceID, $overrideGameID);
				$container = Page::create('alliance_invite_accept_processing.php');
				$container['alliance_id'] = $alliance->getAllianceID();
				return '<div class="buttonA"><a class="buttonA" href="' . $container->href() . '">Join ' . $alliance->getAllianceDisplayName() . '</a></div>';
			break;
		}
	} catch (Throwable $e) {<commit_msg>smr.inc.php: remove globals in smrBBCode<commit_after><?php declare(strict_types=1);

function htmliseMessage($message) {
	$message = htmlentities($message, ENT_COMPAT, 'utf-8');
	$message = str_replace('&lt;br /&gt;', '<br />', $message);
	return $message;
}

function parseBoolean($check) {
	// Only negative strings are not implicitly converted to the correct bool
	if (is_string($check) && (strcasecmp($check, 'NO') == 0 || strcasecmp($check, 'FALSE') == 0)) {
		return false;
	}
	return (bool)$check;
}

function linkCombatLog($logID) {
	$container = Page::create('combat_log_viewer_verify.php');
	$container['log_id'] = $logID;
	return '<a href="' . $container->href() . '"><img src="images/notify.gif" width="14" height="11" border="0" title="View the combat log" /></a>';
}

/**
 * Converts a BBCode tag into some other text depending on the tag and value.
 * This is called in two stages: first with action BBCODE_CHECK (where the
 * returned value must be a boolean) and second, if the first check passes,
 * with action BBCODE_OUTPUT.
 */
function smrBBCode($bbParser, $action, $tagName, $default, $tagParams, $tagContent) {
	global $overrideGameID, $disableBBLinks, $var;
	$session = Smr\Session::getInstance();
	try {
		switch ($tagName) {
			case 'combatlog':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$logID = (int)$default;
				return linkCombatLog($logID);
			break;
			case 'player':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$playerID = (int)$default;
				$bbPlayer = SmrPlayer::getPlayerByPlayerID($playerID, $overrideGameID);
				$showAlliance = isset($tagParams['showalliance']) ? parseBoolean($tagParams['showalliance']) : false;
				if ($disableBBLinks === false && $overrideGameID == $session->getGameID()) {
					return $bbPlayer->getLinkedDisplayName($showAlliance);
				}
				return $bbPlayer->getDisplayName($showAlliance);
			break;
			case 'alliance':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$allianceID = (int)$default;
				$alliance = SmrAlliance::getAlliance($allianceID, $overrideGameID);
				if ($disableBBLinks === false && $overrideGameID == $session->getGameID()) {
					$container = Page::create('skeleton.php');
					$container['alliance_id'] = $alliance->getAllianceID();
					if ($session->hasGame() && $alliance->getAllianceID() == $session->getPlayer()->getAllianceID()) {
						$container['body'] = 'alliance_mod.php';
					} else {
						$container['body'] = 'alliance_roster.php';
					}
					return create_link($container, $alliance->getAllianceDisplayName());
				}
				return $alliance->getAllianceDisplayName();
			break;
			case 'race':
				$raceNameID = $default;
				foreach (Globals::getRaces() as $raceID => $raceInfo) {
					if ((is_numeric($raceNameID) && $raceNameID == $raceID)
						|| $raceNameID == $raceInfo['Race Name']) {
						if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
							return true;
						}
						$linked = $disableBBLinks === false && $overrideGameID == $session->getGameID();
						$player = $session->hasGame() ? $session->getPlayer() : null;
						return AbstractSmrPlayer::getColouredRaceNameOrDefault($raceID, $player, $linked);
					}
				}
			break;
			case 'servertimetouser':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return true;
				}
				$timeString = $default;
				if ($timeString != '' && ($time = strtotime($timeString)) !== false) {
					if ($session->hasAccount()) {
						$time += $session->getAccount()->getOffset() * 3600;
					}
					return date(DATE_FULL_SHORT, $time);
				}
			break;
			case 'chess':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$chessGameID = (int)$default;
				$chessGame = ChessGame::getChessGame($chessGameID);
				return '<a href="' . $chessGame->getPlayGameHREF() . '">chess game (' . $chessGame->getChessGameID() . ')</a>';
			break;

			case 'sector':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}

				$sectorID = (int)$default;
				$sectorTag = '<span class="sectorColour">#' . $sectorID . '</span>';

				// The use of $var here is for a corner case where an admin can check reported messages whilst being in-game.
				// Ugly but working, probably want a better mechanism to check if more BBCode tags get added
				if ($disableBBLinks === false
					&& $session->hasGame()
					&& $session->getGameID() == $overrideGameID
					&& SmrSector::sectorExists($overrideGameID, $sectorID)) {
					return '<a href="' . Globals::getPlotCourseHREF($session->getPlayer()->getSectorID(), $sectorID) . '">' . $sectorTag . '</a>';
				}

				return $sectorTag;
			break;
			case 'join_alliance':
				if ($action == \Nbbc\BBCode::BBCODE_CHECK) {
					return is_numeric($default);
				}
				$allianceID = (int)$default;
				$alliance = SmrAlliance::getAlliance($allianceID, $overrideGameID);
				$container = Page::create('alliance_invite_accept_processing.php');
				$container['alliance_id'] = $alliance->getAllianceID();
				return '<div class="buttonA"><a class="buttonA" href="' . $container->href() . '">Join ' . $alliance->getAllianceDisplayName() . '</a></div>';
			break;
		}
	} catch (Throwable $e) {
{'fraction_non_alphanumeric': 0.17253925698965913, 'fraction_numerical': 0.00248946763692072, 'mean_word_length': 3.990444338270425, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 80, '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': '1047983', 'n_tokens_mistral': 4134, 'n_tokens_neox': 3448, 'n_words': 736}