|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* COPS (Calibre OPDS PHP Server) class file |
|
4
|
|
|
* |
|
5
|
|
|
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
|
6
|
|
|
* @author Sébastien Lucas <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
class PageCustomize extends Page |
|
10
|
|
|
{ |
|
11
|
|
|
private function isChecked ($key, $testedValue = 1) { |
|
12
|
|
|
$value = getCurrentOption ($key); |
|
13
|
|
|
if (is_array ($value)) { |
|
14
|
|
|
if (in_array ($testedValue, $value)) { |
|
15
|
|
|
return "checked='checked'"; |
|
16
|
|
|
} |
|
17
|
|
|
} else { |
|
18
|
|
|
if ($value == $testedValue) { |
|
19
|
|
|
return "checked='checked'"; |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
return ""; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
private function isSelected ($key, $value) { |
|
26
|
|
|
if (getCurrentOption ($key) == $value) { |
|
27
|
|
|
return "selected='selected'"; |
|
28
|
|
|
} |
|
29
|
|
|
return ""; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
private function getStyleList () { |
|
33
|
|
|
$result = array (); |
|
34
|
|
|
foreach (glob ("templates/" . getCurrentTemplate () . "/styles/style-*.css") as $filename) { |
|
35
|
|
|
if (preg_match ('/styles\/style-(.*?)\.css/', $filename, $m)) { |
|
36
|
|
|
array_push ($result, $m [1]); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
return $result; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function InitializeContent () |
|
43
|
|
|
{ |
|
44
|
|
|
$this->title = localize ("customize.title"); |
|
45
|
|
|
$this->entryArray = array (); |
|
46
|
|
|
|
|
47
|
|
|
$ignoredBaseArray = array (PageQueryResult::SCOPE_AUTHOR, |
|
48
|
|
|
PageQueryResult::SCOPE_TAG, |
|
49
|
|
|
PageQueryResult::SCOPE_SERIES, |
|
50
|
|
|
PageQueryResult::SCOPE_PUBLISHER, |
|
51
|
|
|
PageQueryResult::SCOPE_RATING, |
|
52
|
|
|
"language"); |
|
53
|
|
|
|
|
54
|
|
|
$content = ""; |
|
55
|
|
|
array_push ($this->entryArray, new Entry ("Template", "", |
|
56
|
|
|
"<span style='cursor: pointer;' onclick='$.cookie(\"template\", \"bootstrap\", { expires: 365 });window.location=$(\".headleft\").attr(\"href\");'>Click to switch to Bootstrap</span>", "text", |
|
57
|
|
|
array ())); |
|
58
|
|
|
if (!preg_match("/(Kobo|Kindle\/3.0|EBRD1101)/", $_SERVER['HTTP_USER_AGENT'])) { |
|
59
|
|
|
$content .= '<select id="style" onchange="updateCookie (this);">'; |
|
60
|
|
View Code Duplication |
foreach ($this-> getStyleList () as $filename) { |
|
|
|
|
|
|
61
|
|
|
$content .= "<option value='{$filename}' " . $this->isSelected ("style", $filename) . ">{$filename}</option>"; |
|
62
|
|
|
} |
|
63
|
|
|
$content .= '</select>'; |
|
64
|
|
|
} else { |
|
65
|
|
View Code Duplication |
foreach ($this-> getStyleList () as $filename) { |
|
|
|
|
|
|
66
|
|
|
$content .= "<input type='radio' onchange='updateCookieFromCheckbox (this);' id='style-{$filename}' name='style' value='{$filename}' " . $this->isChecked ("style", $filename) . " /><label for='style-{$filename}'> {$filename} </label>"; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.style"), "", |
|
70
|
|
|
$content, "text", |
|
71
|
|
|
array ())); |
|
72
|
|
|
if (!useServerSideRendering ()) { |
|
73
|
|
|
$content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="use_fancyapps" ' . $this->isChecked ("use_fancyapps") . ' />'; |
|
74
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.fancybox"), "", |
|
75
|
|
|
$content, "text", |
|
76
|
|
|
array ())); |
|
77
|
|
|
} |
|
78
|
|
|
$content = '<input type="number" onchange="updateCookie (this);" id="max_item_per_page" value="' . getCurrentOption ("max_item_per_page") . '" min="-1" max="1200" pattern="^[-+]?[0-9]+$" />'; |
|
79
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.paging"), "", |
|
80
|
|
|
$content, "text", |
|
81
|
|
|
array ())); |
|
82
|
|
|
$content = '<input type="text" onchange="updateCookie (this);" id="email" value="' . getCurrentOption ("email") . '" />'; |
|
83
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.email"), "", |
|
84
|
|
|
$content, "text", |
|
85
|
|
|
array ())); |
|
86
|
|
|
$content = '<input type="checkbox" onchange="updateCookieFromCheckbox (this);" id="html_tag_filter" ' . $this->isChecked ("html_tag_filter") . ' />'; |
|
87
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.filter"), "", |
|
88
|
|
|
$content, "text", |
|
89
|
|
|
array ())); |
|
90
|
|
|
$content = ""; |
|
91
|
|
|
foreach ($ignoredBaseArray as $key) { |
|
92
|
|
|
$keyPlural = preg_replace ('/(ss)$/', 's', $key . "s"); |
|
93
|
|
|
$content .= '<input type="checkbox" name="ignored_categories[]" onchange="updateCookieFromCheckboxGroup (this);" id="ignored_categories_' . $key . '" ' . $this->isChecked ("ignored_categories", $key) . ' > ' . localize ("{$keyPlural}.title") . '</input> '; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
array_push ($this->entryArray, new Entry (localize ("customize.ignored"), "", |
|
97
|
|
|
$content, "text", |
|
98
|
|
|
array ())); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.