1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // | Theme switch plugin | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | Copyright(C) 2012 Piwigo Team http://piwigo.org | |
---|
7 | // | Copyright(C) 2010 Pavel Budka http://budkovi.ic.cz | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
25 | |
---|
26 | function theme_controler_switch() |
---|
27 | { |
---|
28 | global $user, $template, $conf; |
---|
29 | |
---|
30 | $same = $user['theme']; |
---|
31 | if ( isset( $_GET['theme']) ) |
---|
32 | { |
---|
33 | if ( !empty($_GET['theme']) and file_exists(PHPWG_THEMES_PATH.$_GET['theme']) ) |
---|
34 | { |
---|
35 | if ( is_a_guest() or is_generic() ) |
---|
36 | { |
---|
37 | pwg_set_session_var('theme_switch', $_GET['theme']); |
---|
38 | } |
---|
39 | else |
---|
40 | { |
---|
41 | $query = ' |
---|
42 | UPDATE '.USER_INFOS_TABLE.' |
---|
43 | SET theme = "'.$_GET['theme'].'" |
---|
44 | WHERE user_id = '.$user['id'].' |
---|
45 | ;'; |
---|
46 | pwg_query($query); |
---|
47 | } |
---|
48 | $user['theme'] = $_GET['theme']; |
---|
49 | } |
---|
50 | } |
---|
51 | else if ( (is_a_guest() or is_generic()) and pwg_get_session_var('theme_switch')!=null ) |
---|
52 | { |
---|
53 | $user['theme'] = pwg_get_session_var('theme_switch'); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | function theme_controler_init() |
---|
58 | { |
---|
59 | global $conf; |
---|
60 | |
---|
61 | if ( isset($conf['theme_switch_mode']) and $conf['theme_switch_mode'] == 'select' ) |
---|
62 | { |
---|
63 | theme_controler_select(); |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | theme_controler_thumb(); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | function theme_controler_thumb() |
---|
72 | { |
---|
73 | global $user, $template, $conf; |
---|
74 | |
---|
75 | foreach (get_pwg_themes() as $id => $name) |
---|
76 | { |
---|
77 | $img = PHPWG_THEMES_PATH.$id.'/screenshot.png'; |
---|
78 | |
---|
79 | if (file_exists($img)) |
---|
80 | { |
---|
81 | $theme = array( |
---|
82 | 'id' => $id, |
---|
83 | 'name' => $name, |
---|
84 | 'url' => add_url_params( duplicate_index_url(), array('theme'=>$id) ), |
---|
85 | 'img' => $img, |
---|
86 | ); |
---|
87 | |
---|
88 | if ($id==$user['theme']) |
---|
89 | { |
---|
90 | $template->assign('theme_switch_active', $theme); |
---|
91 | } |
---|
92 | |
---|
93 | $template->append('theme_switch', $theme); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | $safe_themes = array('clear','dark','elegant','Sylvia','simple-grey','simple-black','simple-white','kardon','luciano','montblancxl'); // stripped (2.6) |
---|
98 | |
---|
99 | $template->assign(array( |
---|
100 | 'THEME_SWITCH_PATH' => THEME_SWITCH_PATH, |
---|
101 | 'THEME_SWITCH_LOAD_STYLE' => !in_array($user['theme'], $safe_themes), |
---|
102 | )); |
---|
103 | |
---|
104 | $template->set_filename('theme_thumb', dirname(__FILE__) . '/thumb.tpl'); |
---|
105 | $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_thumb', true)); |
---|
106 | $template->clear_assign('theme_thumb'); |
---|
107 | } |
---|
108 | |
---|
109 | function theme_controler_select() |
---|
110 | { |
---|
111 | global $user, $template; |
---|
112 | |
---|
113 | foreach (get_pwg_themes() as $id => $name) |
---|
114 | { |
---|
115 | $template->append('theme_switch', array( |
---|
116 | 'id' => $id, |
---|
117 | 'name' => $name, |
---|
118 | 'url' => add_url_params( duplicate_index_url(), array('theme'=>$id) ), |
---|
119 | 'select' => ($id==$user['theme']) ? 'selected="selected"' : null, |
---|
120 | )); |
---|
121 | } |
---|
122 | |
---|
123 | $template->set_filename('theme_select', dirname(__FILE__) . '/select.tpl'); |
---|
124 | $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_select', true)); |
---|
125 | $template->clear_assign('theme_select'); |
---|
126 | } |
---|
127 | |
---|
128 | ?> |
---|