Skip to content

Commit

Permalink
clean up theme file
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Jun 2, 2024
1 parent efab082 commit 095b3fc
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions app/Core/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,16 @@ public function __construct(
$this->language = $language;
}

/**
* Retrieves the available color schemes.
*
* @return array The available color schemes.
*/
public function getAvailableColorSchemes(): array
{

$this->readIniData();
;

$parsedColorSchemes = $this->colorSchemes;
$parsedColorSchemes["themeDefault"] = array(
"name" => "label.themeDefault",
Expand All @@ -157,7 +162,8 @@ public function getAvailableColorSchemes(): array

$settingsRepo = app()->make(Setting::class);
$primaryColor = $settingsRepo->getSetting("companysettings.primarycolor") ? $settingsRepo->getSetting("companysettings.primarycolor") : null;
$secondaryColor = $settingsRepo->getSetting("companysettings.secondarycolor") ? $settingsRepo->getSetting("companysettings.secondarycolor") : null; ;
$secondaryColor = $settingsRepo->getSetting("companysettings.secondarycolor") ? $settingsRepo->getSetting("companysettings.secondarycolor") : null;
;
$parsedColorSchemes["companyColors"] = array(
"name" => "label.companyColors",
"primaryColor" => $primaryColor ?? $this->config->primarycolor ?? $parsedColorSchemes["themeDefault"]["primaryColor"],
Expand Down Expand Up @@ -192,7 +198,7 @@ public function getActive(): string

// Return user specific theme, if active
//This is an active logged in session.
if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
//User is logged in, we don't have a theme yet, check settings
$settingsRepo = app()->make(Setting::class);
$theme = $settingsRepo->getSetting("usersettings." . $_SESSION["userdata"]["id"] . ".theme");
Expand Down Expand Up @@ -234,7 +240,7 @@ public function getColorMode()
return $_SESSION['usersettings.colorMode'];
}

if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
//User is logged in, we don't have a theme yet, check settings
$settingsRepo = app()->make(Setting::class);
$colorMode = $settingsRepo->getSetting("usersettings." . $_SESSION["userdata"]["id"] . ".colorMode");
Expand Down Expand Up @@ -272,7 +278,7 @@ public function getColorScheme()
return $_SESSION['usersettings.colorScheme'];
}

if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
//User is logged in, we don't have a theme yet, check settings
$settingsRepo = app()->make(Setting::class);
$colorScheme = $settingsRepo->getSetting("usersettings." . $_SESSION["userdata"]["id"] . ".colorScheme");
Expand Down Expand Up @@ -307,7 +313,7 @@ public function getFont()
return $_SESSION['usersettings.themeFont'];
}

if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
//User is logged in, we don't have a theme yet, check settings
$settingsRepo = app()->make(Setting::class);
$themeFont = $settingsRepo->getSetting("usersettings." . $_SESSION["userdata"]["id"] . ".themeFont");
Expand Down Expand Up @@ -350,7 +356,7 @@ public function setActive(string $id): void
}

//Only set if user is logged in
if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
$_SESSION['usersettings.theme'] = $id;
}

Expand Down Expand Up @@ -381,7 +387,7 @@ public function setColorMode(string $colorMode): void
}

//Only store colors in session for logged in users
if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
$_SESSION['usersettings.colorMode'] = $colorMode;
}

Expand Down Expand Up @@ -412,7 +418,7 @@ public function setFont(string $font): void
$font = 'roboto';
}

if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
$_SESSION['usersettings.themeFont'] = $font;
}

Expand Down Expand Up @@ -443,7 +449,7 @@ public function setColorScheme(string $colorScheme): void
$colorScheme = 'themeDefault';
}

if(Auth::isLoggedIn()){
if (Auth::isLoggedIn()) {
$_SESSION['usersettings.colorScheme'] = $colorScheme;
$this->setAccentColors($colorScheme);
}
Expand All @@ -458,8 +464,6 @@ public function setColorScheme(string $colorScheme): void
->withSameSite('Strict')
))
);


}


Expand Down Expand Up @@ -767,7 +771,7 @@ public function setThemeDefaultColors()
public function setCompanyColors()
{

if (! isset($_SESSION["usersettings.colorScheme.primaryColor"]) ) {
if (! isset($_SESSION["usersettings.colorScheme.primaryColor"])) {
$settingsRepo = app()->make(Setting::class);
$primaryColor = $settingsRepo->getSetting("companysettings.primarycolor");

Expand Down Expand Up @@ -814,19 +818,22 @@ public function setSchemeColors($colorscheme)
*
* @return string The primary color.
*/
public function getPrimaryColor() {
public function getPrimaryColor()
{

if (isset($_SESSION["usersettings.colorScheme.primaryColor"])
if (
isset($_SESSION["usersettings.colorScheme.primaryColor"])
&& $_SESSION["usersettings.colorScheme.primaryColor"] != ''
&& Auth::isLoggedIn()) {
&& Auth::isLoggedIn()
) {
return $_SESSION["usersettings.colorScheme.primaryColor"];
}

$currentColorScheme = $this->getColorScheme();

$colorSchemes = $this->getAvailableColorSchemes();

if(Auth::isLoggedIn()) {
if (Auth::isLoggedIn()) {
$_SESSION["usersettings.colorScheme.primaryColor"] = $colorSchemes[$currentColorScheme]['primaryColor'];
}

Expand All @@ -845,18 +852,21 @@ public function getPrimaryColor() {
* @access public
* @return string The secondary color for the current user's color scheme
*/
public function getSecondaryColor() {
public function getSecondaryColor()
{

if (isset($_SESSION["usersettings.colorScheme.secondaryColor"])
&& $_SESSION["usersettings.colorScheme.secondaryColor"] != ''
&& Auth::isLoggedIn()) {
if (
isset($_SESSION["usersettings.colorScheme.secondaryColor"])
&& $_SESSION["usersettings.colorScheme.secondaryColor"] != ''
&& Auth::isLoggedIn()
) {
return $_SESSION["usersettings.colorScheme.secondaryColor"];
}

$colorSchemes = $this->getAvailableColorSchemes();
$currentColorScheme = $this->getColorScheme();

if(Auth::isLoggedIn()) {
if (Auth::isLoggedIn()) {
$_SESSION["usersettings.colorScheme.secondaryColor"] = $colorSchemes[$currentColorScheme]['secondaryColor'];
}

Expand All @@ -876,7 +886,6 @@ private function readIniData(): void
error_log("Configuration file for theme " . $this->getActive() . " not found");
$this->clearCache();
$this->setActive("default");

}
$this->iniData = parse_ini_file(
ROOT . '/theme/' . $this->getActive() . '/' . static::DEFAULT_INI . '.ini',
Expand Down

0 comments on commit 095b3fc

Please sign in to comment.