[13492] | 1 | <?php |
---|
[31454] | 2 | /* |
---|
| 3 | Plugin Name: Language Switch Menubar |
---|
| 4 | Version: auto |
---|
| 5 | Description: Switch to another language from flags on your menubar gallery. |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=601 |
---|
| 7 | Author: ddtddt |
---|
| 8 | Author URI: http://temmii.com/piwigo/ |
---|
| 9 | */ |
---|
| 10 | |
---|
[13492] | 11 | // +-----------------------------------------------------------------------+ |
---|
[31455] | 12 | // | Language Switch Menubar plugin for piwigo | |
---|
[13492] | 13 | // +-----------------------------------------------------------------------+ |
---|
[31455] | 14 | // | Copyright(C) 2012-2016 ddtddt http://temmii.com/piwigo/ | |
---|
[13492] | 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 17 | // | it under the terms of the GNU General Public License as published by | |
---|
| 18 | // | the Free Software Foundation | |
---|
| 19 | // | | |
---|
| 20 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 21 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 22 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 23 | // | General Public License for more details. | |
---|
| 24 | // | | |
---|
| 25 | // | You should have received a copy of the GNU General Public License | |
---|
| 26 | // | along with this program; if not, write to the Free Software | |
---|
| 27 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 28 | // | USA. | |
---|
| 29 | // +-----------------------------------------------------------------------+ |
---|
| 30 | |
---|
[17067] | 31 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 32 | { |
---|
| 33 | die('Hacking attempt!'); |
---|
| 34 | } |
---|
[13492] | 35 | |
---|
| 36 | define('LSM_DIR' , basename(dirname(__FILE__))); |
---|
| 37 | define('LSM_PATH' , PHPWG_PLUGINS_PATH . LSM_DIR . '/'); |
---|
| 38 | |
---|
| 39 | add_event_handler('blockmanager_register_blocks', 'register_lsm_menubar_blocks'); |
---|
| 40 | add_event_handler('blockmanager_apply', 'lsm_apply'); |
---|
| 41 | add_event_handler('loading_lang', 'reloadlang'); |
---|
| 42 | |
---|
| 43 | function register_lsm_menubar_blocks( $menu_ref_arr ) |
---|
| 44 | { |
---|
| 45 | $menu = & $menu_ref_arr[0]; |
---|
| 46 | if ($menu->get_id() != 'menubar') |
---|
| 47 | return; |
---|
| 48 | $menu->register_block( new RegisteredBlock( 'mbLSM', 'lsm', 'LSM')); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | function lsm_apply($menu_ref_arr) |
---|
| 52 | { |
---|
[17067] | 53 | global $template, $user, $template, $conf, $page; |
---|
[13492] | 54 | |
---|
[17067] | 55 | $menu = & $menu_ref_arr[0]; |
---|
[13492] | 56 | |
---|
[17067] | 57 | load_language('plugin.lang', LSM_PATH); |
---|
| 58 | $template->assign( |
---|
| 59 | array ( |
---|
| 60 | 'LSMTITLE' => l10n('Language'), |
---|
| 61 | ) |
---|
| 62 | ); |
---|
| 63 | |
---|
| 64 | if (($block = $menu->get_block( 'mbLSM' )) != null) |
---|
| 65 | { |
---|
| 66 | $template->set_template_dir(LSM_PATH.'template/'); |
---|
| 67 | $block->template = 'flags.tpl'; |
---|
| 68 | } |
---|
| 69 | |
---|
[17148] | 70 | if (isset($page['section']) and $page['section'] == 'additional_page' and isset($page['additional_page'])) |
---|
[17067] | 71 | { |
---|
| 72 | $base_url = make_index_url(array('section'=>'page')).'/'.(isset($page['additional_page']['permalink']) ? $page['additional_page']['permalink'] : $page['additional_page']['id']); |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | $base_url = duplicate_index_url(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | $available_lang = get_languages(); |
---|
| 80 | foreach ($available_lang as $code => $displayname) |
---|
| 81 | { |
---|
[29844] | 82 | $code2=explode("_", $code); |
---|
[17067] | 83 | $qlc = array ( |
---|
| 84 | 'url' => add_url_params($base_url, array('lang'=> $code)), |
---|
| 85 | 'alt' => ucwords($displayname), |
---|
[29844] | 86 | 'hreflang' =>$code2[0], |
---|
[17067] | 87 | 'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg', |
---|
| 88 | ); |
---|
| 89 | |
---|
| 90 | $lsw['flags'][$code] = $qlc ; |
---|
| 91 | |
---|
| 92 | if ($code == $user['language']) |
---|
[13492] | 93 | { |
---|
[17067] | 94 | $lsw['Active'] = $qlc; |
---|
[13492] | 95 | } |
---|
[17067] | 96 | } |
---|
[13492] | 97 | |
---|
[17067] | 98 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
| 99 | $template->clear_assign('lang_switch'); |
---|
| 100 | $template->assign( |
---|
| 101 | array( |
---|
| 102 | 'lang_switch'=> $lsw, |
---|
| 103 | 'LSM_PATH' => LSM_PATH, |
---|
| 104 | ) |
---|
| 105 | ); |
---|
[13492] | 106 | } |
---|
| 107 | |
---|
| 108 | function reloadlang() |
---|
| 109 | { |
---|
| 110 | global $user; |
---|
[17067] | 111 | $same = $user['language']; |
---|
[13492] | 112 | |
---|
[17067] | 113 | if (isset($_GET['lang'])) |
---|
| 114 | { |
---|
| 115 | if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php')) |
---|
[13492] | 116 | { |
---|
[17067] | 117 | if (is_a_guest() or is_generic()) |
---|
[13492] | 118 | { |
---|
[17067] | 119 | pwg_set_session_var('lang_switch', $_GET['lang']); |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | $query = ' |
---|
[13492] | 124 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 125 | SET language = \''.$_GET['lang'].'\' |
---|
| 126 | WHERE user_id = '.$user['id'].' |
---|
| 127 | ;'; |
---|
[17067] | 128 | pwg_query($query); |
---|
[13492] | 129 | } |
---|
[17067] | 130 | $user['language'] = $_GET['lang']; |
---|
[13492] | 131 | } |
---|
[17067] | 132 | } |
---|
| 133 | elseif ((is_a_guest() or is_generic())) |
---|
| 134 | { |
---|
| 135 | $user['language'] = pwg_get_session_var('lang_switch', $user['language']); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | if ( $same !== $user['language']) |
---|
| 139 | { |
---|
| 140 | load_language('common.lang', '', array('language'=>$user['language'])); |
---|
[13492] | 141 | |
---|
[17067] | 142 | load_language( |
---|
| 143 | 'lang', |
---|
| 144 | PHPWG_ROOT_PATH.PWG_LOCAL_DIR, |
---|
| 145 | array( |
---|
| 146 | 'language' => $user['language'], |
---|
| 147 | 'no_fallback' => true, |
---|
| 148 | 'local' => true |
---|
| 149 | ) |
---|
| 150 | ); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
| 154 | { |
---|
| 155 | load_language('admin.lang', '', array('language'=>$user['language'])); |
---|
| 156 | } |
---|
[13492] | 157 | } |
---|
| 158 | |
---|
| 159 | ?> |
---|