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,20 +805,37 @@ 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");
@ -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) {
$content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>";
} }
foreach (glob ("styles/style-*.css") as $filename) {
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",