Refactorize a little. re #127

This commit is contained in:
Sébastien Lucas 2013-12-20 15:16:57 +01:00
parent 1c50ed49fe
commit ebbd830a33

View file

@ -805,25 +805,42 @@ class PageAbout extends Page
class PageCustomize extends Page class PageCustomize extends Page
{ {
private function isChecked ($key, $testedValue = NULL) { private function isChecked ($key, $testedValue = 1) {
$value = getCurrentOption ($key); $value = getCurrentOption ($key);
if (!is_null ($testedValue)) { if (is_array ($value)) {
if (in_array ($testedValue, $value)) { if (in_array ($testedValue, $value)) {
return "checked='checked'"; return "checked='checked'";
} }
} else { } else {
if ($value == 1) { if ($value == $testedValue) {
return "checked='checked'"; return "checked='checked'";
} }
} }
return ""; 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 () public function InitializeContent ()
{ {
$this->title = localize ("customize.title"); $this->title = localize ("customize.title");
$this->entryArray = array (); $this->entryArray = array ();
$ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, $ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR,
PageQueryResult::SCOPE_TAG, PageQueryResult::SCOPE_TAG,
PageQueryResult::SCOPE_SERIES, PageQueryResult::SCOPE_SERIES,
@ -833,27 +850,14 @@ class PageCustomize extends Page
$content = ""; $content = "";
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
$content .= '<select id="style" onchange="updateCookie (this);">'; $content .= '<select id="style" onchange="updateCookie (this);">';
} foreach ($this-> getStyleList () as $filename) {
foreach (glob ("styles/style-*.css") as $filename) { $content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>";
if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) {
$filename = $m [1];
}
$selected = "";
if (getCurrentOption ("style") == $filename) {
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
$selected = "selected='selected'";
} else {
$selected = "checked='checked'";
}
}
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
$content .= "<option value='{$filename}' {$selected}>{$filename}</option>";
} else {
$content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' {$selected} /><label for='style-{$filename}'> {$filename} </label>";
}
} }
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) {
$content .= '</select>'; $content .= '</select>';
} else {
foreach ($this-> getStyleList () as $filename) {
$content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked ("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>";
}
} }
array_push ($this->entryArray, new Entry (localize ("customize.style"), "", array_push ($this->entryArray, new Entry (localize ("customize.style"), "",
$content, "text", $content, "text",
@ -922,7 +926,7 @@ abstract class Base
global $config; global $config;
return is_array ($config['calibre_directory']); return is_array ($config['calibre_directory']);
} }
public static function noDatabaseSelected () { public static function noDatabaseSelected () {
return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB)); return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB));
} }
@ -935,7 +939,7 @@ abstract class Base
return array ("" => $config['calibre_directory']); return array ("" => $config['calibre_directory']);
} }
} }
public static function getDbNameList () { public static function getDbNameList () {
global $config; global $config;
if (self::isMultipleDatabaseEnabled ()) { if (self::isMultipleDatabaseEnabled ()) {
@ -991,7 +995,7 @@ abstract class Base
} }
return self::$db; return self::$db;
} }
public static function checkDatabaseAvailability () { public static function checkDatabaseAvailability () {
if (self::noDatabaseSelected ()) { if (self::noDatabaseSelected ()) {
for ($i = 0; $i < count (self::getDbList ()); $i++) { for ($i = 0; $i < count (self::getDbList ()); $i++) {