Skip to content

How to enable disable the portal quickly

Bugo edited this page Dec 3, 2024 · 1 revision

Create a file toggle_portal.php in your forum root:

<?php declare(strict_types=1);

global $smcFunc;

require_once __DIR__ . '/SSI.php';

$target = '$sourcedir/LightPortal/app.php';
$hook = 'integrate_pre_include';

$result = $smcFunc['db_query']('', '
	SELECT value
	FROM {db_prefix}settings
	WHERE variable = {string:hook}',
	[
		'hook' => $hook,
	]
);

if ($smcFunc['db_num_rows']($result) === 0) {
	$smcFunc['db_insert']('',
		'{db_prefix}settings',
		['variable' => 'string', 'value' => 'string'],
		[$hook, $target],
		[]
	);

	clean_cache();

	redirectexit('action=admin;area=lp_settings');
} else {
	[$data] = $smcFunc['db_fetch_row']($result);

	$smcFunc['db_free_result']($result);

	$values = explode(',', $data);

	if (in_array($target, array_map('trim', $values))) {
		$values = array_filter($values, fn($value) => trim($value) !== $target);
	} else {
		$values[] = $target;
	}

	$smcFunc['db_query']('', '
		UPDATE {db_prefix}settings
		SET value = {string:value}
		WHERE variable = {string:hook}',
		[
			'value' => ltrim(implode(',', $values), ','),
			'hook'  => $hook,
		]
	);

	clean_cache();

	redirectexit();
}

Run this file via your browser: `https://your_forum_url/toggle_portal.php';