From 1c50ed49fe5d5f21356db7a3ae8d7627cd675247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Thu, 19 Dec 2013 08:38:26 +0100 Subject: [PATCH] little code refactoring. re #34 --- base.php | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/base.php b/base.php index 9546bdf..a8e2324 100644 --- a/base.php +++ b/base.php @@ -805,33 +805,30 @@ class PageAbout extends Page class PageCustomize extends Page { + private function isChecked ($key, $testedValue = NULL) { + $value = getCurrentOption ($key); + if (!is_null ($testedValue)) { + if (in_array ($testedValue, $value)) { + return "checked='checked'"; + } + } else { + if ($value == 1) { + return "checked='checked'"; + } + } + return ""; + } + public function InitializeContent () { $this->title = localize ("customize.title"); $this->entryArray = array (); - - $use_fancybox = ""; - if (getCurrentOption ("use_fancyapps") == 1) { - $use_fancybox = "checked='checked'"; - } - $html_tag_filter = ""; - if (getCurrentOption ("html_tag_filter") == 1) { - $html_tag_filter = "checked='checked'"; - } - $ignored_categories = array (); $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, PageQueryResult::SCOPE_TAG, PageQueryResult::SCOPE_SERIES, PageQueryResult::SCOPE_PUBLISHER, "language"); - foreach ($ignoredBaseArray as $key) { - if (in_array ($key, getCurrentOption ('ignored_categories'))) { - $ignored_categories [$key] = "checked='checked'"; - } else { - $ignored_categories [$key] = ""; - } - } $content = ""; if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { @@ -862,7 +859,7 @@ class PageCustomize extends Page $content, "text", array ())); if (!useServerSideRendering ()) { - $content = ''; + $content = 'isChecked ("use_fancyapps") . ' />'; array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "", $content, "text", array ())); @@ -875,14 +872,14 @@ class PageCustomize extends Page array_push ($this->entryArray, new Entry (localize ("customize.email"), "", $content, "text", array ())); - $content = ''; + $content = 'isChecked ("html_tag_filter") . ' />'; array_push ($this->entryArray, new Entry (localize ("customize.filter"), "", $content, "text", array ())); $content = ""; foreach ($ignoredBaseArray as $key) { $keyPlural = preg_replace ('/(ss)$/', 's', $key . "s"); - $content .= ' ' . localize ("{$keyPlural}.title") . ' '; + $content .= 'isChecked ("ignored_categories", $key) . ' > ' . localize ("{$keyPlural}.title") . ' '; } array_push ($this->entryArray, new Entry (localize ("customize.ignored"), "",