From ebbd830a333123024a13ef12be4579a4bb02cd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 20 Dec 2013 15:16:57 +0100 Subject: [PATCH] Refactorize a little. re #127 --- base.php | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/base.php b/base.php index a8e2324..ecad72b 100644 --- a/base.php +++ b/base.php @@ -805,25 +805,42 @@ class PageAbout extends Page class PageCustomize extends Page { - private function isChecked ($key, $testedValue = NULL) { + private function isChecked ($key, $testedValue = 1) { $value = getCurrentOption ($key); - if (!is_null ($testedValue)) { + if (is_array ($value)) { if (in_array ($testedValue, $value)) { return "checked='checked'"; } } else { - if ($value == 1) { + if ($value == $testedValue) { return "checked='checked'"; } } return ""; } + private function isSelected ($key, $value) { + if (getCurrentOption ($key) == $value) { + return "selected='selected'"; + } + return ""; + } + + private function getStyleList () { + $result = array (); + foreach (glob ("styles/style-*.css") as $filename) { + if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) { + array_push ($result, $m [1]); + } + } + return $result; + } + public function InitializeContent () { $this->title = localize ("customize.title"); $this->entryArray = array (); - + $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, PageQueryResult::SCOPE_TAG, PageQueryResult::SCOPE_SERIES, @@ -833,27 +850,14 @@ class PageCustomize extends Page $content = ""; if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { $content .= '"; - } + foreach ($this-> getStyleList () as $filename) { + $content .= ""; } - if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { $content .= ''; + } else { + foreach ($this-> getStyleList () as $filename) { + $content .= "isChecked ("style", $filename) . " />"; + } } array_push ($this->entryArray, new Entry (localize ("customize.style"), "", $content, "text", @@ -922,7 +926,7 @@ abstract class Base global $config; return is_array ($config['calibre_directory']); } - + public static function noDatabaseSelected () { return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); } @@ -935,7 +939,7 @@ abstract class Base return array ("" => $config['calibre_directory']); } } - + public static function getDbNameList () { global $config; if (self::isMultipleDatabaseEnabled ()) { @@ -991,7 +995,7 @@ abstract class Base } return self::$db; } - + public static function checkDatabaseAvailability () { if (self::noDatabaseSelected ()) { for ($i = 0; $i < count (self::getDbList ()); $i++) {