Skip to content

Commit 36f7ccd

Browse files
committed
Library/Template: Reduce repetition and improve sideboxs loading efficiency
1 parent beee561 commit 36f7ccd

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

application/libraries/Template.php

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ private function getHeader(bool|string|array $css = false, bool|string|array $js
389389
"slider_interval" => $this->CI->config->item('slider_interval'),
390390
"slider_style" => $this->CI->config->item('slider_style'),
391391
"vote_reminder" => $this->voteReminder(),
392-
"keywords" => ($this->custom_keywords) ? $this->custom_keywords : $this->CI->config->item("keywords"),
393-
"description" => ($this->custom_description) ? $this->custom_description : $this->CI->config->item("description"),
392+
"keywords" => ($this->custom_keywords) ?? $this->CI->config->item("keywords"),
393+
"description" => ($this->custom_description) ?? $this->CI->config->item("description"),
394394
"menu_top" => $this->getMenu("top"),
395395
"menu_side" => $this->getMenu("side"),
396396
"menu_bottom" => $this->getMenu("bottom"),
@@ -410,12 +410,12 @@ private function getHeader(bool|string|array $css = false, bool|string|array $js
410410
"cdn_link" => $this->CI->config->item('cdn') === true ? $this->CI->config->item('cdn_link') : null,
411411
"isOnline" => $this->CI->user->isOnline(),
412412
"isRTL" => $this->CI->language->getLanguage() == 'persian' || $this->CI->language->getClientData() == 'persian',
413-
"social_media" => array(
413+
"social_media" => [
414414
'facebook' => $this->CI->config->item('facebook'),
415415
'twitter' => $this->CI->config->item('twitter'),
416416
'youtube' => $this->CI->config->item('youtube'),
417417
'discord' => $this->CI->config->item('discord')
418-
),
418+
],
419419
"use_captcha" => false,
420420
"captcha_type" => $this->CI->config->item('captcha_type')
421421
);
@@ -459,48 +459,39 @@ private function voteReminder(): bool|string
459459
*/
460460
public function loadSideboxes(string $location = 'side'): array
461461
{
462-
$out = [];
462+
$output = [];
463+
$module = CI::$APP->router->fetch_module();
464+
$sideBoxes = $this->CI->cms_model->getSideboxes($location, $module);
463465

464-
$sideBoxes_db = $this->CI->cms_model->getSideboxes($location, CI::$APP->router->fetch_module());
465-
466-
// If we got sideboxes
467-
if ($sideBoxes_db)
468-
{
469-
// Go through them all and add them to the output.
470-
foreach ($sideBoxes_db as $sideBox)
471-
{
472-
if ($sideBox['permission'] && !hasViewPermission($sideBox['permission'], "--SIDEBOX--"))
473-
continue;
466+
foreach ((array) $sideBoxes as $sideBox) {
467+
if ($sideBox['permission'] && !hasViewPermission($sideBox['permission'], "--SIDEBOX--")) {
468+
continue;
469+
}
474470

475-
$fileLocation = 'application/modules/sidebox_' . $sideBox['type'] . '/controllers/' . ucfirst($sideBox['type']) . '.php';
471+
$sideboxType = $sideBox['type'];
472+
$fileLocation = APPPATH . 'modules/sidebox_' . $sideboxType . '/controllers/' . ucfirst($sideboxType) . '.php';
476473

477-
if (file_exists($fileLocation))
478-
{
479-
require_once($fileLocation);
480-
481-
if ($sideBox['type'] == 'custom')
482-
$object = new $sideBox['type']($sideBox['id']);
483-
else
484-
$object = new $sideBox['type']();
485-
486-
$out[] = array(
487-
'name' => langColumn($sideBox['displayName']),
488-
'location' => $sideBox['location'],
489-
'data' => $object->view(),
490-
'type' => $sideBox['type']
491-
);
492-
}
493-
else
494-
{
495-
$out[] = array(
496-
'name' => "Oops, something went wrong",
497-
'data' => 'The following sideBox module is missing or contains an invalid module structure: <b>sidebox_' . $sideBox['type'] . '</b>'
498-
);
499-
}
474+
if (!file_exists($fileLocation)) {
475+
$output[] = [
476+
'name' => "Oops, something went wrong",
477+
'data' => 'The following sideBox module is missing or contains an invalid module structure: <b>sidebox_' . $sideboxType . '</b>'
478+
];
479+
continue;
500480
}
481+
482+
require_once($fileLocation);
483+
484+
$object = ($sideboxType === 'custom') ? new $sideboxType($sideBox['id']) : new $sideboxType();
485+
486+
$output[] = [
487+
'name' => langColumn($sideBox['displayName']),
488+
'location' => $sideBox['location'],
489+
'data' => $object->view(),
490+
'type' => $sideboxType,
491+
];
501492
}
502493

503-
return $out;
494+
return $output;
504495
}
505496

506497
/**
@@ -510,7 +501,7 @@ public function loadSideboxes(string $location = 'side'): array
510501
* @param Array $data Array of additional template data
511502
* @return String
512503
*/
513-
public function loadPage(string $page, array $data = array()): string
504+
public function loadPage(string $page, array $data = []): string
514505
{
515506
// Get the module, we need to check if it's enabled first
516507
$data['module'] = array_key_exists("module", $data) ? $data['module'] : $this->module_name;

0 commit comments

Comments
 (0)