[7072] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // | Theme switch plugin | |
---|
| 5 | // +-----------------------------------------------------------------------+ |
---|
[16241] | 6 | // | Copyright(C) 2012 Piwigo Team http://piwigo.org | |
---|
[7093] | 7 | // | Copyright(C) 2010 Pavel Budka http://budkovi.ic.cz | |
---|
[7072] | 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 | // +-----------------------------------------------------------------------+ |
---|
[7093] | 23 | |
---|
[16241] | 24 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[7171] | 25 | |
---|
[16241] | 26 | function theme_controler_switch() |
---|
[7072] | 27 | { |
---|
[7093] | 28 | global $user, $template, $conf; |
---|
[16241] | 29 | |
---|
[7093] | 30 | $same = $user['theme']; |
---|
| 31 | if ( isset( $_GET['theme']) ) |
---|
[7072] | 32 | { |
---|
[16241] | 33 | if ( !empty($_GET['theme']) and file_exists(PHPWG_THEMES_PATH.$_GET['theme']) ) |
---|
[7072] | 34 | { |
---|
[16241] | 35 | if ( is_a_guest() or is_generic() ) |
---|
| 36 | { |
---|
| 37 | pwg_set_session_var('theme_switch', $_GET['theme']); |
---|
| 38 | } |
---|
[7072] | 39 | else |
---|
| 40 | { |
---|
[16241] | 41 | $query = ' |
---|
| 42 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 43 | SET theme = "'.$_GET['theme'].'" |
---|
| 44 | WHERE user_id = '.$user['id'].' |
---|
| 45 | ;'; |
---|
[7072] | 46 | pwg_query($query); |
---|
| 47 | } |
---|
| 48 | $user['theme'] = $_GET['theme']; |
---|
| 49 | } |
---|
| 50 | } |
---|
[16241] | 51 | else if ( (is_a_guest() or is_generic()) and pwg_get_session_var('theme_switch')!=null ) |
---|
[7072] | 52 | { |
---|
[16241] | 53 | $user['theme'] = pwg_get_session_var('theme_switch'); |
---|
[7072] | 54 | } |
---|
[7171] | 55 | } |
---|
| 56 | |
---|
[16241] | 57 | function theme_controler_init() |
---|
[7171] | 58 | { |
---|
[16241] | 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 | } |
---|
[7171] | 69 | } |
---|
| 70 | |
---|
[16241] | 71 | function theme_controler_thumb() |
---|
[7072] | 72 | { |
---|
[16241] | 73 | global $user, $template, $conf; |
---|
[7072] | 74 | |
---|
[16241] | 75 | foreach (get_pwg_themes() as $id => $name) |
---|
| 76 | { |
---|
| 77 | $img = PHPWG_THEMES_PATH.$id.'/screenshot.png'; |
---|
[7072] | 78 | |
---|
[16241] | 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, |
---|
[7072] | 86 | ); |
---|
[16241] | 87 | |
---|
| 88 | if ($id==$user['theme']) |
---|
| 89 | { |
---|
| 90 | $template->assign('theme_switch_active', $theme); |
---|
[7072] | 91 | } |
---|
[16241] | 92 | |
---|
| 93 | $template->append('theme_switch', $theme); |
---|
| 94 | } |
---|
[7093] | 95 | } |
---|
[21355] | 96 | |
---|
[21360] | 97 | $safe_themes = array('clear','dark','elegant','Sylvia','simple-grey','simple-black','simple-white','kardon','luciano','montblancxl'); // stripped (2.6) |
---|
[7072] | 98 | |
---|
[21355] | 99 | $template->assign(array( |
---|
| 100 | 'THEME_SWITCH_PATH' => THEME_SWITCH_PATH, |
---|
| 101 | 'THEME_SWITCH_LOAD_STYLE' => !in_array($user['theme'], $safe_themes), |
---|
| 102 | )); |
---|
[16241] | 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 | } |
---|
[7093] | 108 | |
---|
[16241] | 109 | function theme_controler_select() |
---|
[7093] | 110 | { |
---|
[16241] | 111 | global $user, $template; |
---|
[7093] | 112 | |
---|
[16241] | 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'); |
---|
[7072] | 126 | } |
---|
[7093] | 127 | |
---|
[16241] | 128 | ?> |
---|