Skip to content

Commit

Permalink
Merge pull request #1467 from RaspAP/fix/theme-options
Browse files Browse the repository at this point in the history
Feature / fix: Theme updates
  • Loading branch information
billz authored Nov 30, 2023
2 parents 1a16f3c + 194ca3a commit ff7f1f0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 84 deletions.
5 changes: 4 additions & 1 deletion app/css/custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_once '../../includes/functions.php';
$color = getColorOpt();
?>

/*
Theme Name: RaspAP default
Author: @billz
Expand All @@ -26,6 +25,10 @@
font-weight: 500;
}

.sidebar-brand-text {
color: <?php echo $color; ?>;
}

.card .card-header, .modal-header {
border-color: <?php echo $color; ?>;
color: #fff;
Expand Down
37 changes: 25 additions & 12 deletions app/css/lightsout.css → app/css/lightsout.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<?php header("Content-Type: text/css; charset=utf-8"); ?>
<?php
require_once '../../includes/functions.php';
$color = getColorOpt();
?>

/*
Theme Name: Lights Out
Author: @billz
Expand All @@ -6,6 +12,13 @@
License: GNU General Public License v3.0
*/

<?php
// Base color
$baseColor = $color;
$textColor = lightenColor($baseColor, 95);
$secondaryColor = lightenColor($baseColor, 30);
?>

@import url('all.css');

html * {
Expand All @@ -31,13 +44,17 @@
}

.sidebar-light .nav-item.active .nav-link i {
color: #d2d2d2;
color: <?php echo $secondaryColor; ?>;
}

.sidebar .nav-item.active .nav-link {
font-weight: 400;
}

.sidebar-brand-text {
color: <?php echo $color; ?>;
}

#wrapper #content-wrapper #content {
background-color: #202020;
}
Expand Down Expand Up @@ -139,10 +156,6 @@
border-top: .01rem solid #d2d2d2;
}

.sidebar-brand-text {
color: #2b8080 !important;
}

.ra-raspap:before {
color: #ac1b3d !important;
}
Expand Down Expand Up @@ -201,7 +214,7 @@
}

.sidebar-light .nav-item .nav-link i {
color: rgba(230, 230, 230, .3);
color: <?php echo $color; ?>
}

.sidebar .nav-item .nav-link {
Expand Down Expand Up @@ -319,16 +332,16 @@
filter: opacity(0.7);
}

.ra-wireguard:before {
color: #404040 !important;
}

.ra-wireguard:hover:before {
color: #d1d3e2 !important;
}

.sidebar .nav-item.active .nav-link span.ra-wireguard:before {
color: #d2d2d2 !important;
.sidebar-light .nav-link span.ra-wireguard:before {
color: <?php echo $color; ?>!important;
}

.sidebar-light .nav-item.active .nav-link span.ra-wireguard:before {
color: <?php echo $textColor; ?>;
}

.logoutput {
Expand Down
31 changes: 0 additions & 31 deletions app/css/material-dark.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,12 @@
// Base color
$baseColor = $color;

// Function to darken a color by a percentage
function darkenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));

$r = round($r * (1 - $percent));
$g = round($g * (1 - $percent));
$b = round($b * (1 - $percent));

return sprintf("#%02x%02x%02x", $r, $g, $b);
}

// Function to lighten a color by a percentage
function lightenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));

$r = round($r + (255 - $r) * $percent);
$g = round($g + (255 - $g) * $percent);
$b = round($b + (255 - $b) * $percent);

return sprintf("#%02x%02x%02x", $r, $g, $b);
}

$textColor = lightenColor($baseColor, 95);
// Create other color variables
$cardsColor = darkenColor($baseColor, 60);
$secondaryColor = lightenColor($baseColor, 30);
$primaryColor = $baseColor;
$backgroundColor = darkenColor($baseColor, 90);

?>

@import url('all.css');
Expand Down
33 changes: 0 additions & 33 deletions app/css/material-light.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
$color = getColorOpt();
?>


/*
Theme Name: Material Light
Author: @marek-guran
Expand All @@ -16,44 +15,12 @@
<?php
// Base color
$baseColor = $color;

// Function to darken a color by a percentage
function darkenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));

$r = round($r * (1 - $percent));
$g = round($g * (1 - $percent));
$b = round($b * (1 - $percent));

return sprintf("#%02x%02x%02x", $r, $g, $b);
}

// Function to lighten a color by a percentage
function lightenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));

$r = round($r + (255 - $r) * $percent);
$g = round($g + (255 - $g) * $percent);
$b = round($b + (255 - $b) * $percent);

return sprintf("#%02x%02x%02x", $r, $g, $b);
}

$textColor = lightenColor($baseColor, 95);
// Create other color variables
$cardsColor = lightenColor($baseColor, 50);
$secondaryColor = lightenColor($baseColor, 30);
$primaryColor = $baseColor;
$backgroundColor = lightenColor($baseColor, 60);

?>

@import url('all.css');
Expand Down
8 changes: 4 additions & 4 deletions app/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ function set_theme(theme) {
$(function() {
var currentTheme = getCookie('theme');
// Check if the current theme is a dark theme
var isDarkTheme = currentTheme === 'lightsout.css' || currentTheme === 'material-dark.php';
var isDarkTheme = currentTheme === 'lightsout.php' || currentTheme === 'material-dark.php';

$('#night-mode').prop('checked', isDarkTheme);
$('#night-mode').change(function() {
Expand All @@ -764,12 +764,12 @@ $(function() {

if (state == true) {
if (currentTheme == 'custom.php') {
set_theme('lightsout.css');
set_theme('lightsout.php');
} else if (currentTheme == 'material-light.php') {
set_theme('material-dark.php');
}
} else {
if (currentTheme == 'lightsout.css') {
if (currentTheme == 'lightsout.php') {
set_theme('custom.php');
} else if (currentTheme == 'material-dark.php') {
set_theme('material-light.php');
Expand All @@ -795,7 +795,7 @@ function getCookie(cname) {
var themes = {
"default": "custom.php",
"hackernews" : "hackernews.css",
"lightsout" : "lightsout.css",
"lightsout" : "lightsout.php",
"material-light" : "material-light.php",
"material-dark" : "material-dark.php",
}
Expand Down
43 changes: 40 additions & 3 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,10 @@ function getColorOpt()
$color = "#2b8080";
} else {
$color = $_COOKIE['color'];
setcookie('color', $color);
}
return $color;
}

function getSidebarState()
{
if(isset($_COOKIE['sidebarToggled'])) {
Expand Down Expand Up @@ -784,7 +784,7 @@ function validate_host($host)
// @return boolean
function getNightmode()
{
if (isset($_COOKIE['theme']) && $_COOKIE['theme'] == 'lightsout.css') {
if (isset($_COOKIE['theme']) && $_COOKIE['theme'] == 'lightsout.php') {
return true;
} else {
return false;
Expand Down Expand Up @@ -924,7 +924,7 @@ function checkReleaseVersion($installed, $latest) {
return false;
}

/**
/**
* Returns logfile contents up to a maximum defined limit, in kilobytes
*
* @param string $file_path
Expand All @@ -945,5 +945,42 @@ function getLogLimited($file_path, $file_data = null) {
$log_limited = substr($file_data, $start_position);
}
return $log_limited;
}

/**
* Function to darken a color by a percentage
* From @marek-guran's material-dark theme for RaspAP
* Author URI: https://github.com/marek-guran
*/
function darkenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));

$r = round($r * (1 - $percent));
$g = round($g * (1 - $percent));
$b = round($b * (1 - $percent));

return sprintf("#%02x%02x%02x", $r, $g, $b);
}

/**
* Function to lighten a color by a percentage
* From @marek-guran's material-dark theme for RaspAP
* Author URI: https://github.com/marek-guran
*/
function lightenColor($color, $percent)
{
$percent /= 100;
$r = hexdec(substr($color, 1, 2));
$g = hexdec(substr($color, 3, 2));
$b = hexdec(substr($color, 5, 2));

$r = round($r + (255 - $r) * $percent);
$g = round($g + (255 - $g) * $percent);
$b = round($b + (255 - $b) * $percent);

return sprintf("#%02x%02x%02x", $r, $g, $b);
}

0 comments on commit ff7f1f0

Please sign in to comment.