[7072] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // | Theme switch plugin | |
---|
| 5 | // +-----------------------------------------------------------------------+ |
---|
[7093] | 6 | // | Copyright(C) 2010 Pavel Budka http://budkovi.ic.cz | |
---|
[7072] | 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 9 | // | it under the terms of the GNU General Public License as published by | |
---|
| 10 | // | the Free Software Foundation | |
---|
| 11 | // | | |
---|
| 12 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 13 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 14 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 15 | // | General Public License for more details. | |
---|
| 16 | // | | |
---|
| 17 | // | You should have received a copy of the GNU General Public License | |
---|
| 18 | // | along with this program; if not, write to the Free Software | |
---|
| 19 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 20 | // | USA. | |
---|
| 21 | // +-----------------------------------------------------------------------+ |
---|
| 22 | if (!defined('THEME_SWITCH_PATH')) |
---|
| 23 | define('THEME_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
[7093] | 24 | |
---|
[7171] | 25 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
| 26 | |
---|
[7072] | 27 | class theme_controler { |
---|
| 28 | static public function _switch() |
---|
| 29 | { |
---|
[7093] | 30 | global $user, $template, $conf; |
---|
| 31 | |
---|
| 32 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 33 | |
---|
[7072] | 34 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
[7093] | 35 | $same = $user['theme']; |
---|
| 36 | if ( isset( $_GET['theme']) ) |
---|
[7072] | 37 | { |
---|
[7093] | 38 | if ( !empty($_GET['theme']) and |
---|
| 39 | file_exists( PHPWG_ROOT_PATH.'themes/'.$_GET['theme']) ) |
---|
[7072] | 40 | { |
---|
| 41 | if (is_a_guest() or is_generic()) |
---|
| 42 | setcookie( 'pwg_theme_switch', $_GET['theme'], |
---|
| 43 | time()+60*60*24*30, cookie_path() ); |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | $query = 'UPDATE '.USER_INFOS_TABLE.' |
---|
[7093] | 47 | SET theme = \''.$_GET['theme'].'\' |
---|
[7072] | 48 | WHERE user_id = '.$user['id'].' |
---|
| 49 | ;'; |
---|
| 50 | pwg_query($query); |
---|
| 51 | } |
---|
| 52 | $user['theme'] = $_GET['theme']; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | else |
---|
| 56 | // Users have $user['template']/$user['theme'] |
---|
| 57 | // Guest or generic members will use their cookied $user['template']/$user['theme'] ! |
---|
| 58 | if ((is_a_guest() or is_generic()) |
---|
[7093] | 59 | and isset( $_COOKIE['pwg_theme_switch'] ) ) |
---|
[7072] | 60 | { |
---|
| 61 | $user['theme'] = $_COOKIE['pwg_theme_switch']; |
---|
| 62 | } |
---|
[7093] | 63 | } // function _switch() |
---|
[7072] | 64 | |
---|
[7171] | 65 | static public function _installed_themes() |
---|
| 66 | // id, name, screenshot |
---|
| 67 | { |
---|
| 68 | $themes = new themes(); |
---|
| 69 | $themes->sort_fs_themes(); |
---|
| 70 | $db_themes = $themes->get_db_themes(); |
---|
| 71 | $db_theme_ids = array(); |
---|
| 72 | foreach ($db_themes as $db_theme) |
---|
| 73 | { |
---|
| 74 | array_push($db_theme_ids, $db_theme['id']); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | $active_themes = array(); |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | foreach ($themes->fs_themes as $theme_id => $fs_theme) |
---|
| 81 | { |
---|
| 82 | if (in_array($theme_id, $db_theme_ids)) |
---|
| 83 | array_push($active_themes, $fs_theme); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | return $active_themes; |
---|
| 87 | } // function _installed_themes() |
---|
| 88 | |
---|
| 89 | |
---|
[7072] | 90 | static public function _flags() |
---|
| 91 | // Lets user choose from icons |
---|
| 92 | // Only themes which have gif icon provided in icons plugin directory will be provided to users. |
---|
| 93 | // Gif file name must be the same as theme's name and must be stored in sub directory named according to template's name. |
---|
| 94 | { |
---|
[7093] | 95 | global $user, $template, $conf, $lang; |
---|
[7072] | 96 | |
---|
| 97 | $available_theme = get_pwg_themes(); |
---|
| 98 | |
---|
[7093] | 99 | $url_starting = get_query_string_diff(array('theme')); |
---|
[7171] | 100 | |
---|
| 101 | foreach ( theme_controler::_installed_themes() as $theme ) { |
---|
| 102 | $qlc_img = $theme['screenshot']; // $conf['themes_dir'].'/'.$theme_id.'/'.'screenshot.png'; |
---|
[7072] | 103 | |
---|
[7093] | 104 | if (file_exists($qlc_img)) { |
---|
| 105 | |
---|
[7072] | 106 | $qlc_url = str_replace(array('=&','?&'),array('&','?'), |
---|
[7171] | 107 | add_url_params( $url_starting, array( 'theme' => $theme['id'] ))); |
---|
[7072] | 108 | if (isset($lang['theme'])) |
---|
[7171] | 109 | $qlc_alt = $lang['theme'].' '.ucwords( $theme['name'] ); |
---|
[7072] | 110 | else |
---|
[7171] | 111 | $qlc_alt = ucwords( $theme['name'] ); |
---|
[7072] | 112 | $qlc_title = $qlc_alt; |
---|
| 113 | $qlc = array ( |
---|
| 114 | 'url' => $qlc_url, |
---|
| 115 | 'alt' => $qlc_alt, |
---|
| 116 | 'img' => $qlc_img, |
---|
| 117 | ); |
---|
[7171] | 118 | if ( $theme['id'] !== $user['theme']) |
---|
| 119 | $lsw['flags'][$theme['id']] = $qlc ; |
---|
[7072] | 120 | else $lsw['Active'] = $qlc; |
---|
| 121 | } |
---|
[7093] | 122 | } |
---|
[7072] | 123 | |
---|
| 124 | $template->set_filename('theme_flags', dirname(__FILE__) . '/flags.tpl'); |
---|
| 125 | $lsw['side'] = ceil(sqrt(count($available_theme))); |
---|
| 126 | $template->assign(array( |
---|
| 127 | 'theme_switch'=> $lsw, |
---|
| 128 | 'THEME_SWITCH_PATH' => THEME_SWITCH_PATH, |
---|
| 129 | )); |
---|
| 130 | $flags = $template->parse('theme_flags',true); |
---|
| 131 | $template->clear_assign('theme_switch'); |
---|
| 132 | $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); |
---|
[7093] | 133 | } // function _flags() |
---|
[7072] | 134 | |
---|
[7171] | 135 | |
---|
[7072] | 136 | static public function _select() |
---|
| 137 | // Lets user choose using select control |
---|
| 138 | // All available themes will be provided to users. |
---|
| 139 | { |
---|
| 140 | global $user, $template, $lang; |
---|
| 141 | |
---|
| 142 | $available_theme = get_pwg_themes(); |
---|
[7093] | 143 | $url_starting = get_query_string_diff(array('theme')); |
---|
[7171] | 144 | $options='<li class="selector">' |
---|
| 145 | .$lang['theme']. |
---|
| 146 | ' <select onchange="javasript:window.location=this.value">'; |
---|
| 147 | foreach ( theme_controler::_installed_themes() as $theme ) |
---|
[7072] | 148 | { |
---|
| 149 | $qlc_url = str_replace(array('=&','?&'),array('&','?'), |
---|
[7171] | 150 | add_url_params( $url_starting, array( 'theme' => $theme['id'] ) )); |
---|
[7072] | 151 | |
---|
[7171] | 152 | if ( $theme['id'] == $user['theme'] ) |
---|
[7072] | 153 | $tmp='" selected="selected">'; |
---|
| 154 | else |
---|
| 155 | $tmp='">'; |
---|
| 156 | $options=$options.' |
---|
[7171] | 157 | <option label="'.$theme['name'].'" value="'.$qlc_url.$tmp.$theme['name'].'</option>'; |
---|
[7072] | 158 | } |
---|
| 159 | $options=$options.' |
---|
| 160 | </select></li>'; |
---|
| 161 | $template->concat( 'PLUGIN_INDEX_ACTIONS',$options); |
---|
[7093] | 162 | } // function _select() |
---|
| 163 | |
---|
| 164 | static public function _theme_admin($menu) |
---|
| 165 | // adds menu options for future configuration |
---|
| 166 | { |
---|
| 167 | // load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 168 | array_push($menu, array('NAME' => 'Theme Switch', |
---|
| 169 | 'URL' => get_admin_plugin_menu_link(THEME_SWITCH_PATH.'admin/admin.php'))); |
---|
| 170 | return $menu; |
---|
| 171 | } // function _theme_admin() |
---|
| 172 | |
---|
| 173 | } // class theme_controler |
---|
| 174 | |
---|
[7072] | 175 | /* {html_head} usage function */ |
---|
| 176 | /* See flags.tpl for example (due no catenation available) */ |
---|
| 177 | if (!function_exists('Componant_exists')) { |
---|
| 178 | function Componant_exists($path, $file) |
---|
| 179 | { return file_exists( $path . $file); } |
---|
| 180 | } |
---|
[7093] | 181 | |
---|
[7072] | 182 | ?> |
---|