summaryrefslogtreecommitdiff
path: root/app/Theme/ColorsTheme.php
blob: 35805f23083cac392c6e96ca9b5c69c4c940dddc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace Fisharebest\Webtrees;

/**
 * webtrees: online genealogy
 * Copyright (C) 2015 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Class ColorsTheme - The colors theme.
 */
class ColorsTheme extends CloudsTheme {
	/** @var string[] A list of color palettes */
	protected $palettes;

	/** @var string Which of the color palettes to use on this page */
	protected $palette;

	/** {@inheritdoc} */
	public function assetUrl() {
		return 'themes/colors/css-1.7.0/';
	}

	/** {@inheritdoc} */
	protected function formatSecondaryMenu() {
		return
			'<ul class="secondary-menu">' .
			implode('', $this->secondaryMenu()) .
			'<li>' .
			$this->formQuickSearch() .
			'</li>' .
			'</ul>';
	}

	/** {@inheritdoc} */
	protected function headerContent() {
		return
			//$this->accessibilityLinks() .
			$this->formatTreeTitle() .
			$this->formatSecondaryMenu();
	}

	/**
	 * Create resources for the colors theme.
	 *
	 * {@inheritdoc}
	 */
	public function hookAfterInit() {
		$this->palettes = array(
			'aquamarine'       => /* I18N: The name of a colour-scheme */ I18N::translate('Aqua Marine'),
			'ash'              => /* I18N: The name of a colour-scheme */ I18N::translate('Ash'),
			'belgianchocolate' => /* I18N: The name of a colour-scheme */ I18N::translate('Belgian Chocolate'),
			'bluelagoon'       => /* I18N: The name of a colour-scheme */ I18N::translate('Blue Lagoon'),
			'bluemarine'       => /* I18N: The name of a colour-scheme */ I18N::translate('Blue Marine'),
			'coffeeandcream'   => /* I18N: The name of a colour-scheme */ I18N::translate('Coffee and Cream'),
			'coldday'          => /* I18N: The name of a colour-scheme */ I18N::translate('Cold Day'),
			'greenbeam'        => /* I18N: The name of a colour-scheme */ I18N::translate('Green Beam'),
			'mediterranio'     => /* I18N: The name of a colour-scheme */ I18N::translate('Mediterranio'),
			'mercury'          => /* I18N: The name of a colour-scheme */ I18N::translate('Mercury'),
			'nocturnal'        => /* I18N: The name of a colour-scheme */ I18N::translate('Nocturnal'),
			'olivia'           => /* I18N: The name of a colour-scheme */ I18N::translate('Olivia'),
			'pinkplastic'      => /* I18N: The name of a colour-scheme */ I18N::translate('Pink Plastic'),
			'sage'             => /* I18N: The name of a colour-scheme */ I18N::translate('Sage'),
			'shinytomato'      => /* I18N: The name of a colour-scheme */ I18N::translate('Shiny Tomato'),
			'tealtop'          => /* I18N: The name of a colour-scheme */ I18N::translate('Teal Top'),
		);
		uasort($this->palettes, __NAMESPACE__ . '\I18N::strcasecmp');

		// If we've selected a new palette, and we are logged in, set this value as a default.
		if (isset($_GET['themecolor']) && array_key_exists($_GET['themecolor'], $this->palettes)) {
			// Request to change color
			$this->palette = $_GET['themecolor'];
			Auth::user()->setPreference('themecolor', $this->palette);
			if (Auth::isAdmin()) {
				Site::setPreference('DEFAULT_COLOR_PALETTE', $this->palette);
			}
			unset($_GET['themecolor']);
			// Rember that we have selected a value
			Session::put('subColor', $this->palette);
		}
		// If we are logged in, use our preference
		$this->palette = Auth::user()->getPreference('themecolor');
		// If not logged in or no preference, use one we selected earlier in the session?
		if (!$this->palette) {
			$this->palette = Session::get('subColor');
		}
		// We haven't selected one this session?  Use the site default
		if (!$this->palette) {
			$this->palette = Site::getPreference('DEFAULT_COLOR_PALETTE');
		}
		// Make sure our selected palette actually exists
		if (!array_key_exists($this->palette, $this->palettes)) {
			$this->palette = 'ash';
		}
	}

	/**
	 * Generate a list of items for the user menu.
	 *
	 * @return Menu[]
	 */
	protected function secondaryMenu() {
		return array_filter(array(
			$this->menuPendingChanges(),
			$this->menuMyPages(),
			$this->menuFavorites(),
			$this->menuThemes(),
			$this->menuPalette(),
			$this->menuLanguages(),
			$this->menuLogin(),
			$this->menuLogout(),
		));
	}

	/**
	 * Create a menu of palette options
	 *
	 * @return Menu
	 */
	protected function menuPalette() {
		$menu = new Menu(/* I18N: A colour scheme */ I18N::translate('Palette'), '#', 'menu-color');

		foreach ($this->palettes as $palette_id => $palette_name) {
			$menu->addSubmenu(new Menu(
				$palette_name,
				get_query_url(array('themecolor' => $palette_id), '&amp;'),
				'menu-color-' . $palette_id . ($this->palette === $palette_id ? ' active' : '')
			));
		}

		return $menu;
	}

	/** {@inheritdoc} */
	protected function stylesheets() {
		return array(
			'themes/colors/jquery-ui-1.11.2/jquery-ui.css',
			$this->assetUrl() . 'style.css',
			$this->assetUrl() . 'palette/' . $this->palette . '.css',
		);
	}

	/** {@inheritdoc} */
	public function themeId() {
		return 'colors';
	}

	/** {@inheritdoc} */
	public function themeName() {
		return /* I18N: Name of a theme. */ I18N::translate('colors');
	}
}