From 1e1e1ec8b1bf4c7bc0737c1caa82ff4f0a6a922e Mon Sep 17 00:00:00 2001 From: jim-p Date: Fri, 2 Nov 2012 10:47:50 -0400 Subject: Make a function to get the current theme and use it everywhere rather than duplicating code or missing functions. (Fixes forced themes using the wrong theme for login screen) --- etc/inc/authgui.inc | 4 ++-- etc/inc/util.inc | 23 +++++++++++++++++++++++ usr/local/www/guiconfig.inc | 17 +---------------- usr/local/www/head.inc | 20 +------------------- usr/local/www/progress.php | 5 +---- 5 files changed, 28 insertions(+), 41 deletions(-) diff --git a/etc/inc/authgui.inc b/etc/inc/authgui.inc index 1591c07..f87494b 100644 --- a/etc/inc/authgui.inc +++ b/etc/inc/authgui.inc @@ -92,7 +92,7 @@ if (!$_SESSION['Post_Login']) { */ function display_error_form($http_code, $desc) { global $config, $g; - $g['theme'] = $config['theme']; + $g['theme'] = get_current_theme(); if(isAjax()) { printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc); return; @@ -149,7 +149,7 @@ function display_error_form($http_code, $desc) { function display_login_form() { require_once("globals.inc"); global $config, $g; - $g['theme'] = $config['theme']; + $g['theme'] = get_current_theme(); unset($input_errors); diff --git a/etc/inc/util.inc b/etc/inc/util.inc index e7a0734..94e8553 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -1852,4 +1852,27 @@ function setup_library_paths() { } } +function get_current_theme() { + global $config, $g; + /* + * if user has selected a custom template, use it. + * otherwise default to pfsense tempalte + */ + if (($g["disablethemeselection"] === true) && !empty($g["default_theme"]) && (is_dir($g["www_path"].'/themes/'.$g["default_theme"]))) + $theme = $g["default_theme"]; + elseif($config['theme'] <> "" && (is_dir($g["www_path"].'/themes/'.$config['theme']))) + $theme = $config['theme']; + else + $theme = "pfsense"; + /* + * If this device is an apple ipod/iphone + * switch the theme to one that works with it. + */ + $lowres_ua = array("iPhone", "iPod", "iPad", "Android", "BlackBerry", "Opera Mini", "Opera Mobi", "PlayBook"); + foreach($lowres_ua as $useragent) + if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent)) + $theme = (empty($g['theme_lowres']) && (is_dir($g["www_path"].'/themes/'.$g['theme_lowres']))) ? "pfsense" : $g['theme_lowres']; + return $theme; +} + ?> diff --git a/usr/local/www/guiconfig.inc b/usr/local/www/guiconfig.inc index c8962c8..68d0a02 100755 --- a/usr/local/www/guiconfig.inc +++ b/usr/local/www/guiconfig.inc @@ -62,23 +62,8 @@ foreach (scandir("/usr/local/www/classes/") as $file) { require_once("classes/{$file}"); } } -/* - * if user has selected a custom template, use it. - * otherwise default to pfsense template - */ -if($config['theme'] <> "") - $g['theme'] = $config['theme']; -else - $g['theme'] = "pfsense"; -/* - * If this device is an apple ipod/iphone - * switch the theme to one that works with it. - */ -$apple_ua = array("iPhone","iPod", "iPad"); -foreach($apple_ua as $useragent) - if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent)) - $g['theme'] = "pfsense"; +$g['theme'] = get_current_theme(); /* Set the default interface language */ if($config['system']['language'] <> "") { diff --git a/usr/local/www/head.inc b/usr/local/www/head.inc index 5063728..c8454a6 100755 --- a/usr/local/www/head.inc +++ b/usr/local/www/head.inc @@ -3,25 +3,7 @@ pfSense_MODULE: header */ -/* - * if user has selected a custom template, use it. - * otherwise default to pfsense tempalte - */ -if (($g["disablethemeselection"] === true) && !empty($g["default_theme"]) && (is_dir($g["www_path"].'/themes/'.$g["default_theme"]))) - $g['theme'] = $g["default_theme"]; -elseif($config['theme'] <> "" && (is_dir($g["www_path"].'/themes/'.$config['theme']))) - $g['theme'] = $config['theme']; -else - $g['theme'] = "pfsense"; - -/* - * If this device is an apple ipod/iphone - * switch the theme to one that works with it. - */ -$lowres_ua = array("iPhone", "iPod", "iPad", "Android", "BlackBerry", "Opera Mini", "Opera Mobi", "PlayBook"); -foreach($lowres_ua as $useragent) - if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent)) - $g['theme'] = empty($g['theme_lowres']) ? "pfsense" : $g['theme_lowres']; +$g['theme'] = get_current_theme(); $pagetitle = gentitle( $pgtitle ); diff --git a/usr/local/www/progress.php b/usr/local/www/progress.php index 0a6b50d..f222215 100755 --- a/usr/local/www/progress.php +++ b/usr/local/www/progress.php @@ -4,10 +4,7 @@ include("guiconfig.inc"); -if($config['theme'] <> "") - $g['theme'] = $config['theme']; -else - $g['theme'] = "pfsense"; +$g['theme'] = get_current_theme(); $url = 'progress.php?UPLOAD_IDENTIFIER='. $_GET["UPLOAD_IDENTIFIER"] .'&e=1'; -- cgit v1.1