Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to select default homepage #3492

Merged
merged 7 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/classes/Core/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function addCustom(string $url, string $name, bool $widgets = false): voi
{
$this->_pages[$url] = [
'module' => 'Core',
'file' => 'custom.php',
'file' => 'pages/custom.php',
'name' => $name,
'widgets' => $widgets,
'custom' => true,
Expand Down
9 changes: 3 additions & 6 deletions custom/panel_templates/Default/core/general_settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,9 @@
<div class="col-md-6">
<label for="inputHomepage">{$HOMEPAGE_TYPE}</label>
<select name="homepage" class="form-control" id="inputHomepage">
<option value="news" {if $HOMEPAGE_VALUE eq 'news' } selected{/if}>
{$HOMEPAGE_NEWS}</option>
<option value="custom" {if $HOMEPAGE_VALUE eq 'custom' } selected{/if}>
{$HOMEPAGE_CUSTOM}</option>
<option value="portal" {if $HOMEPAGE_VALUE eq 'portal' } selected{/if}>
{$HOMEPAGE_PORTAL}</option>
{foreach from=$HOMEPAGE_PAGES item=page}
<option value="{$page.value}" {if $HOMEPAGE_VALUE eq {$page.value} } selected{/if}>{$page.module} - {$page.name}</option>
{/foreach}
</select>
</div>
<div class="col-md-6">
Expand Down
10 changes: 8 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@
require(ROOT_PATH . '/404.php');
} else {
// Homepage
$pages->setActivePage($pages->getPageByURL('/'));
require(ROOT_PATH . '/modules/Core/pages/index.php');
$homepage = $pages->getPageByURL(Settings::get('home_type'));
if ($homepage != null) {
$pages->setActivePage($homepage);
require(implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'modules', $homepage['module'], $homepage['file']]));
} else {
$pages->setActivePage($pages->getPageByURL('/'));
require(ROOT_PATH . '/modules/Core/pages/index.php');
}
}
die;
}
Expand Down
3 changes: 1 addition & 2 deletions modules/Core/language/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@
"admin/header": "Header",
"admin/header_required": "Header is required.",
"admin/home_custom_content": "Home Custom Content",
"admin/homepage_news": "News",
"admin/homepage_type": "Homepage Type",
"admin/default_homepage": "Default Homepage",
"admin/hook_created": "Hook created successfully.",
"admin/hook_deleted": "Hook deleted successfully.",
"admin/hook_edited": "Hook edited successfully",
Expand Down
5 changes: 4 additions & 1 deletion modules/Core/pages/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
* Custom page
*/

// Check whenever route is homepage or not
$page_route = empty($route) ? Settings::get('home_type') : rtrim($route, '/');

// Get page info from URL
$custom_page = DB::getInstance()->get('custom_pages', ['url', rtrim($route, '/')]);
$custom_page = DB::getInstance()->get('custom_pages', ['url', $page_route]);
if (!$custom_page->count()) {
require(ROOT_PATH . '/404.php');
die();
Expand Down
3 changes: 3 additions & 0 deletions modules/Core/pages/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
}

$home_type = Settings::get('home_type');
if ($home_type === '/') {
$home_type = 'news';
}

$smarty->assign('HOME_TYPE', $home_type);

Expand Down
47 changes: 31 additions & 16 deletions modules/Core/pages/panel/general_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,8 @@
$errors = [$e->getMessage()];
}

// Portal
if ($_POST['homepage'] === 'portal') {
$home_type = 'portal';
} else if ($_POST['homepage'] === 'news') {
$home_type = 'news';
} else if ($_POST['homepage'] === 'custom') {
$home_type = 'custom';
}
// TODO allow to select a custom page to use content as homepage

Settings::set('home_type', $home_type);
// Default Homepage
Settings::set('home_type', $_POST['homepage']);

// Private profile
Settings::set('private_profile', $_POST['privateProfile'] ? '1' : '0');
Expand Down Expand Up @@ -228,6 +219,32 @@
$displaynames = Settings::get('displaynames');
$method = Settings::get('login_method');

$homepage_pages = [[
'value' => 'news',
'name' => $language->get('admin', 'homepage_news'),
'module' => 'Core'
], [
'value' => 'portal',
'name' => $language->get('admin', 'portal'),
'module' => 'Core'
], [
'value' => 'custom',
'name' => $language->get('admin', 'custom_content'),
'module' => 'Core'
]];

foreach ($pages->returnPages() as $key => $page) {
if (str_contains($key, '/panel/') || str_contains($key, '/queries/') || str_contains($key, '/user/')) {
continue;
}

$homepage_pages[] = [
'value' => Output::getPurified($key),
'name' => Output::getPurified($key),
'module' => $page['module']
];
}

$smarty->assign([
'PARENT_PAGE' => PARENT_PAGE,
'DASHBOARD' => $language->get('admin', 'dashboard'),
Expand Down Expand Up @@ -257,10 +274,8 @@
'DEFAULT_TIMEZONE' => $language->get('admin', 'default_timezone'),
'DEFAULT_TIMEZONE_LIST' => Util::listTimezones(),
'DEFAULT_TIMEZONE_VALUE' => $timezone,
'HOMEPAGE_TYPE' => $language->get('admin', 'homepage_type'),
'HOMEPAGE_NEWS' => $language->get('admin', 'homepage_news'),
'HOMEPAGE_PORTAL' => $language->get('admin', 'portal'),
'HOMEPAGE_CUSTOM' => $language->get('admin', 'custom_content'),
'HOMEPAGE_TYPE' => $language->get('admin', 'default_homepage'),
'HOMEPAGE_PAGES' => $homepage_pages,
'HOMEPAGE_VALUE' => Settings::get('home_type'),
'USE_FRIENDLY_URLS' => $language->get('admin', 'use_friendly_urls'),
'USE_FRIENDLY_URLS_VALUE' => Config::get('core.friendly'),
Expand Down Expand Up @@ -298,7 +313,7 @@
'ENABLE_AUTO_LANGUAGE' => $language->get('admin', 'enable_auto_language'),
'AUTO_LANGUAGE_HELP' => $language->get('admin', 'auto_language_help'),
'REQUIRE_STAFFCP_TFA' => $language->get('admin', 'require_two_factor_for_staffcp'),
'REQUIRE_STAFFCP_TFA_VALUE' => Settings::get('require_staffcp_tfa'),
'REQUIRE_STAFFCP_TFA_VALUE' => Settings::get('require_staffcp_tfa')
samerton marked this conversation as resolved.
Show resolved Hide resolved
]);

$template->onPageLoad();
Expand Down
Loading