1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* webtrees: online genealogy |
4
|
|
|
* Copyright (C) 2015 webtrees development team |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU General Public License for more details. |
13
|
|
|
* You should have received a copy of the GNU General Public License |
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
15
|
|
|
*/ |
16
|
|
|
namespace Fisharebest\Webtrees\Theme; |
17
|
|
|
|
18
|
|
|
use Fisharebest\Webtrees\Auth; |
19
|
|
|
use Fisharebest\Webtrees\Functions\Functions; |
20
|
|
|
use Fisharebest\Webtrees\I18N; |
21
|
|
|
use Fisharebest\Webtrees\Menu; |
22
|
|
|
use Fisharebest\Webtrees\Session; |
23
|
|
|
use Fisharebest\Webtrees\Site; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The colors theme. |
27
|
|
|
*/ |
28
|
|
|
class ColorsTheme extends CloudsTheme implements ThemeInterface { |
29
|
|
|
/** @var string[] A list of color palettes */ |
30
|
|
|
protected $palettes; |
31
|
|
|
|
32
|
|
|
/** @var string Which of the color palettes to use on this page */ |
33
|
|
|
protected $palette; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Where are our CSS, JS and other assets? |
37
|
|
|
* |
38
|
|
|
* @return string A relative path, such as "themes/foo/" |
39
|
|
|
*/ |
40
|
|
|
public function assetUrl() { |
41
|
|
|
return 'themes/colors/css-1.7.0/'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Add markup to the secondary menu. |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
protected function formatSecondaryMenu() { |
|
|
|
|
50
|
|
|
return |
51
|
|
|
'<ul class="secondary-menu">' . |
52
|
|
|
implode('', $this->secondaryMenu()) . |
53
|
|
|
'<li>' . |
54
|
|
|
$this->formQuickSearch() . |
55
|
|
|
'</li>' . |
56
|
|
|
'</ul>'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Create the contents of the <header> tag. |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
protected function headerContent() { |
65
|
|
|
return |
66
|
|
|
//$this->accessibilityLinks() . |
|
|
|
|
67
|
|
|
$this->formatTreeTitle() . |
68
|
|
|
$this->formatSecondaryMenu(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Create resources for the colors theme. |
73
|
|
|
*/ |
74
|
|
|
public function hookAfterInit() { |
|
|
|
|
75
|
|
|
$this->palettes = array( |
|
|
|
|
76
|
|
|
'aquamarine' => /* I18N: The name of a colour-scheme */ I18N::translate('Aqua Marine'), |
77
|
|
|
'ash' => /* I18N: The name of a colour-scheme */ I18N::translate('Ash'), |
78
|
|
|
'belgianchocolate' => /* I18N: The name of a colour-scheme */ I18N::translate('Belgian Chocolate'), |
79
|
|
|
'bluelagoon' => /* I18N: The name of a colour-scheme */ I18N::translate('Blue Lagoon'), |
80
|
|
|
'bluemarine' => /* I18N: The name of a colour-scheme */ I18N::translate('Blue Marine'), |
81
|
|
|
'coffeeandcream' => /* I18N: The name of a colour-scheme */ I18N::translate('Coffee and Cream'), |
82
|
|
|
'coldday' => /* I18N: The name of a colour-scheme */ I18N::translate('Cold Day'), |
83
|
|
|
'greenbeam' => /* I18N: The name of a colour-scheme */ I18N::translate('Green Beam'), |
84
|
|
|
'mediterranio' => /* I18N: The name of a colour-scheme */ I18N::translate('Mediterranio'), |
85
|
|
|
'mercury' => /* I18N: The name of a colour-scheme */ I18N::translate('Mercury'), |
86
|
|
|
'nocturnal' => /* I18N: The name of a colour-scheme */ I18N::translate('Nocturnal'), |
87
|
|
|
'olivia' => /* I18N: The name of a colour-scheme */ I18N::translate('Olivia'), |
88
|
|
|
'pinkplastic' => /* I18N: The name of a colour-scheme */ I18N::translate('Pink Plastic'), |
89
|
|
|
'sage' => /* I18N: The name of a colour-scheme */ I18N::translate('Sage'), |
90
|
|
|
'shinytomato' => /* I18N: The name of a colour-scheme */ I18N::translate('Shiny Tomato'), |
91
|
|
|
'tealtop' => /* I18N: The name of a colour-scheme */ I18N::translate('Teal Top'), |
92
|
|
|
); |
93
|
|
|
uasort($this->palettes, '\Fisharebest\Webtrees\I18N::strcasecmp'); |
94
|
|
|
|
95
|
|
|
// If we've selected a new palette, and we are logged in, set this value as a default. |
96
|
|
|
if (isset($_GET['themecolor']) && array_key_exists($_GET['themecolor'], $this->palettes)) { |
97
|
|
|
// Request to change color |
98
|
|
|
$this->palette = $_GET['themecolor']; |
99
|
|
|
Auth::user()->setPreference('themecolor', $this->palette); |
100
|
|
|
if (Auth::isAdmin()) { |
101
|
|
|
Site::setPreference('DEFAULT_COLOR_PALETTE', $this->palette); |
102
|
|
|
} |
103
|
|
|
unset($_GET['themecolor']); |
104
|
|
|
// Rember that we have selected a value |
105
|
|
|
Session::put('subColor', $this->palette); |
106
|
|
|
} |
107
|
|
|
// If we are logged in, use our preference |
108
|
|
|
$this->palette = Auth::user()->getPreference('themecolor'); |
109
|
|
|
// If not logged in or no preference, use one we selected earlier in the session? |
110
|
|
|
if (!$this->palette) { |
|
|
|
|
111
|
|
|
$this->palette = Session::get('subColor'); |
112
|
|
|
} |
113
|
|
|
// We haven't selected one this session? Use the site default |
114
|
|
|
if (!$this->palette) { |
115
|
|
|
$this->palette = Site::getPreference('DEFAULT_COLOR_PALETTE'); |
116
|
|
|
} |
117
|
|
|
// Make sure our selected palette actually exists |
118
|
|
|
if (!array_key_exists($this->palette, $this->palettes)) { |
119
|
|
|
$this->palette = 'ash'; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Generate a list of items for the user menu. |
125
|
|
|
* |
126
|
|
|
* @return Menu[] |
127
|
|
|
*/ |
128
|
|
View Code Duplication |
protected function secondaryMenu() { |
|
|
|
|
129
|
|
|
return array_filter(array( |
130
|
|
|
$this->menuPendingChanges(), |
131
|
|
|
$this->menuMyPages(), |
132
|
|
|
$this->menuFavorites(), |
133
|
|
|
$this->menuThemes(), |
134
|
|
|
$this->menuPalette(), |
135
|
|
|
$this->menuLanguages(), |
136
|
|
|
$this->menuLogin(), |
137
|
|
|
$this->menuLogout(), |
138
|
|
|
)); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Create a menu of palette options |
143
|
|
|
* |
144
|
|
|
* @return Menu |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
protected function menuPalette() { |
147
|
|
|
if ($this->tree && Site::getPreference('ALLOW_USER_THEMES') && $this->tree->getPreference('ALLOW_THEME_DROPDOWN')) { |
|
|
|
|
148
|
|
|
$menu = new Menu(/* I18N: A colour scheme */ |
149
|
|
|
I18N::translate('Palette'), '#', 'menu-color'); |
150
|
|
|
|
151
|
|
|
foreach ($this->palettes as $palette_id => $palette_name) { |
152
|
|
|
$menu->addSubmenu(new Menu( |
153
|
|
|
$palette_name, |
154
|
|
|
Functions::getQueryUrl(array('themecolor' => $palette_id), '&'), |
155
|
|
|
'menu-color-' . $palette_id . ($this->palette === $palette_id ? ' active' : '') |
|
|
|
|
156
|
|
|
)); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
return $menu; |
160
|
|
|
} else { |
161
|
|
|
return null; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* A list of CSS files to include for this page. |
167
|
|
|
* |
168
|
|
|
* @return string[] |
169
|
|
|
*/ |
170
|
|
|
protected function stylesheets() { |
171
|
|
|
return array( |
172
|
|
|
'themes/colors/jquery-ui-1.11.2/jquery-ui.css', |
173
|
|
|
$this->assetUrl() . 'style.css', |
174
|
|
|
$this->assetUrl() . 'palette/' . $this->palette . '.css', |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* A fixed string to identify this theme, in settings, etc. |
180
|
|
|
* |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
|
|
public function themeId() { |
184
|
|
|
return 'colors'; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* What is this theme called? |
189
|
|
|
* |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
public function themeName() { |
193
|
|
|
return /* I18N: Name of a theme. */ I18N::translate('colors'); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
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.