Changeset 16241 for extensions/theme_switch/trunk/theme_switch.inc.php
- Timestamp:
- Jul 1, 2012, 2:29:15 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/theme_switch/trunk/theme_switch.inc.php
r7171 r16241 4 4 // | Theme switch plugin | 5 5 // +-----------------------------------------------------------------------+ 6 // | Copyright(C) 2012 Piwigo Team http://piwigo.org | 6 7 // | Copyright(C) 2010 Pavel Budka http://budkovi.ic.cz | 7 8 // +-----------------------------------------------------------------------+ … … 20 21 // | USA. | 21 22 // +-----------------------------------------------------------------------+ 22 if (!defined('THEME_SWITCH_PATH'))23 define('THEME_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');24 23 25 i nclude_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');24 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 26 25 27 class theme_controler { 28 static public function _switch() 26 function theme_controler_switch() 29 27 { 30 28 global $user, $template, $conf; 31 32 load_language('plugin.lang', dirname(__FILE__).'/'); 33 34 if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } 29 35 30 $same = $user['theme']; 36 31 if ( isset( $_GET['theme']) ) 37 32 { 38 if ( !empty($_GET['theme']) and 39 file_exists( PHPWG_ROOT_PATH.'themes/'.$_GET['theme']) ) 33 if ( !empty($_GET['theme']) and file_exists(PHPWG_THEMES_PATH.$_GET['theme']) ) 40 34 { 41 if (is_a_guest() or is_generic()) 42 setcookie( 'pwg_theme_switch', $_GET['theme'], 43 time()+60*60*24*30, cookie_path() ); 35 if ( is_a_guest() or is_generic() ) 36 { 37 pwg_set_session_var('theme_switch', $_GET['theme']); 38 } 44 39 else 45 40 { 46 $query = 'UPDATE '.USER_INFOS_TABLE.' 47 SET theme = \''.$_GET['theme'].'\' 48 WHERE user_id = '.$user['id'].' 49 ;'; 41 $query = ' 42 UPDATE '.USER_INFOS_TABLE.' 43 SET theme = "'.$_GET['theme'].'" 44 WHERE user_id = '.$user['id'].' 45 ;'; 50 46 pwg_query($query); 51 47 } … … 53 49 } 54 50 } 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()) 59 and isset( $_COOKIE['pwg_theme_switch'] ) ) 51 else if ( (is_a_guest() or is_generic()) and pwg_get_session_var('theme_switch')!=null ) 60 52 { 61 $user['theme'] = $_COOKIE['pwg_theme_switch'];53 $user['theme'] = pwg_get_session_var('theme_switch'); 62 54 } 63 } // function _switch()64 65 static public function _installed_themes()66 // id, name, screenshot67 {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 55 } 76 56 77 $active_themes = array(); 78 79 80 foreach ($themes->fs_themes as $theme_id => $fs_theme) 57 function theme_controler_init() 81 58 { 82 if (in_array($theme_id, $db_theme_ids)) 83 array_push($active_themes, $fs_theme); 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 } 84 69 } 85 70 86 return $active_themes; 87 } // function _installed_themes() 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 $template->assign('THEME_SWITCH_PATH', THEME_SWITCH_PATH); 98 99 $template->set_filename('theme_thumb', dirname(__FILE__) . '/thumb.tpl'); 100 $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_thumb', true)); 101 102 $template->clear_assign('theme_thumb'); 103 } 88 104 105 function theme_controler_select() 106 { 107 global $user, $template; 89 108 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 { 95 global $user, $template, $conf, $lang; 109 foreach (get_pwg_themes() as $id => $name) 110 { 111 $template->append('theme_switch', array( 112 'id' => $id, 113 'name' => $name, 114 'url' => add_url_params( duplicate_index_url(), array('theme'=>$id) ), 115 'select' => ($id==$user['theme']) ? 'selected="selected"' : null, 116 )); 117 } 96 118 97 $available_theme = get_pwg_themes(); 98 99 $url_starting = get_query_string_diff(array('theme')); 119 $template->set_filename('theme_select', dirname(__FILE__) . '/select.tpl'); 120 $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_select', true)); 100 121 101 foreach ( theme_controler::_installed_themes() as $theme ) { 102 $qlc_img = $theme['screenshot']; // $conf['themes_dir'].'/'.$theme_id.'/'.'screenshot.png'; 103 104 if (file_exists($qlc_img)) { 105 106 $qlc_url = str_replace(array('=&','?&'),array('&','?'), 107 add_url_params( $url_starting, array( 'theme' => $theme['id'] ))); 108 if (isset($lang['theme'])) 109 $qlc_alt = $lang['theme'].' '.ucwords( $theme['name'] ); 110 else 111 $qlc_alt = ucwords( $theme['name'] ); 112 $qlc_title = $qlc_alt; 113 $qlc = array ( 114 'url' => $qlc_url, 115 'alt' => $qlc_alt, 116 'img' => $qlc_img, 117 ); 118 if ( $theme['id'] !== $user['theme']) 119 $lsw['flags'][$theme['id']] = $qlc ; 120 else $lsw['Active'] = $qlc; 121 } 122 } 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); 133 } // function _flags() 134 135 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(); 143 $url_starting = get_query_string_diff(array('theme')); 144 $options='<li class="selector">' 145 .$lang['theme']. 146 ' <select onchange="javasript:window.location=this.value">'; 147 foreach ( theme_controler::_installed_themes() as $theme ) 148 { 149 $qlc_url = str_replace(array('=&','?&'),array('&','?'), 150 add_url_params( $url_starting, array( 'theme' => $theme['id'] ) )); 151 152 if ( $theme['id'] == $user['theme'] ) 153 $tmp='" selected="selected">'; 154 else 155 $tmp='">'; 156 $options=$options.' 157 <option label="'.$theme['name'].'" value="'.$qlc_url.$tmp.$theme['name'].'</option>'; 158 } 159 $options=$options.' 160 </select></li>'; 161 $template->concat( 'PLUGIN_INDEX_ACTIONS',$options); 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 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); } 122 $template->clear_assign('theme_select'); 180 123 } 181 124
Note: See TracChangeset
for help on using the changeset viewer.