From c1354532bbeba7905f48fd75fc768f361d9bfe0f Mon Sep 17 00:00:00 2001 From: Nils Steinger Date: Tue, 22 Sep 2015 21:48:17 +0200 Subject: [PATCH 1/3] Removed duplicate code: Made getImage() use getImageSrc() --- includes/functions.php | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 84e95af1dd..337445e0bd 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -149,31 +149,7 @@ function interface_errors($rrd_file, $period = '-1d') { function getImage($device) { global $config; - $device['os'] = strtolower($device['os']); - - if ($device['icon'] && file_exists($config['html_dir'] . "/images/os/" . $device['icon'] . ".png")) { - $image = ''; - } - elseif (isset($config['os'][$device['os']]['icon']) && $config['os'][$device['os']]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png")) { - $image = ''; - } - else { - if (file_exists($config['html_dir'] . '/images/os/' . $device['os'] . '.png')) { - $image = ''; - } - if ($device['os'] == "linux") { - $features = strtolower(trim($device['features'])); - list($distro) = explode(" ", $features); - if (file_exists($config['html_dir'] . "/images/os/$distro" . ".png")) { - $image = ''; - } - } - if (empty($image)) { - $image = ''; - } - } - - return $image; + return ''; } function getImageSrc($device) { From ff57e67f5574b6d8b94d5f5b4734e5c8bf2eb0a2 Mon Sep 17 00:00:00 2001 From: Nils Steinger Date: Tue, 22 Sep 2015 21:48:48 +0200 Subject: [PATCH 2/3] Check if variable is set before trying to read it --- includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/functions.php b/includes/functions.php index 337445e0bd..f26027bdce 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -160,7 +160,7 @@ function getImageSrc($device) { if ($device['icon'] && file_exists($config['html_dir'] . "/images/os/" . $device['icon'] . ".png")) { $image = $config['base_url'] . '/images/os/' . $device['icon'] . '.png'; } - elseif ($config['os'][$device['os']]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png")) { + elseif (isset($config['os'][$device['os']]['icon']) && $config['os'][$device['os']]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png")) { $image = $config['base_url'] . '/images/os/' . $config['os'][$device['os']]['icon'] . '.png'; } else { From dba95472dc98e6537b41efcf1f24f44913d62309 Mon Sep 17 00:00:00 2001 From: Nils Steinger Date: Tue, 22 Sep 2015 22:58:38 +0200 Subject: [PATCH 3/3] Use empty() instead of isset() and PHP's implicit boolean conversion --- includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index f26027bdce..2b95c28ff5 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -157,10 +157,10 @@ function getImageSrc($device) { $device['os'] = strtolower($device['os']); - if ($device['icon'] && file_exists($config['html_dir'] . "/images/os/" . $device['icon'] . ".png")) { + if (!empty($device['icon']) && file_exists($config['html_dir'] . "/images/os/" . $device['icon'] . ".png")) { $image = $config['base_url'] . '/images/os/' . $device['icon'] . '.png'; } - elseif (isset($config['os'][$device['os']]['icon']) && $config['os'][$device['os']]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png")) { + elseif (!empty($config['os'][$device['os']]['icon']) && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png")) { $image = $config['base_url'] . '/images/os/' . $config['os'][$device['os']]['icon'] . '.png'; } else {