source: extensions/language_switch_menubar/main.inc.php

Last change on this file was 32406, checked in by ddtddt, 3 years ago

[language_switch_menubar] piwigo 11 / compatibility smartpocket and bootstrap

File size: 5.0 KB
Line 
1<?php
2/*
3Plugin Name: Language Switch Menubar
4Version: auto
5Description: Switch to another language from flags on your menubar gallery.
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=601
7Author: ddtddt
8Author URI: http://temmii.com/piwigo/
9*/
10
11// +-----------------------------------------------------------------------+
12// | Language Switch Menubar plugin for piwigo by TEMMII                   |
13// +-----------------------------------------------------------------------+
14// | Copyright(C) 2012-2021 ddtddt               http://temmii.com/piwigo/ |
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
31if (!defined('PHPWG_ROOT_PATH'))
32{
33  die('Hacking attempt!');
34}
35
36define('LSM_DIR' , basename(dirname(__FILE__)));
37define('LSM_PATH' , PHPWG_PLUGINS_PATH . LSM_DIR . '/');
38
39add_event_handler('blockmanager_register_blocks', 'register_lsm_menubar_blocks');
40add_event_handler('blockmanager_apply', 'lsm_apply');
41add_event_handler('loading_lang', 'reloadlang');
42
43function 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
51function lsm_apply($menu_ref_arr)
52{
53  global $template, $user, $template, $conf, $page;
54
55  $menu = & $menu_ref_arr[0];
56 
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        if ($user['theme'] == 'bootstrapdefault'||$user['theme'] == 'bootstrap_darkroom'){
68          $block->template = 'flags_bootstrap.tpl';     
69        }else if ($user['theme'] == 'smartpocket'){
70          $block->template = 'flags_smartpocket.tpl';           
71        }else{
72          $block->template = 'flags.tpl';
73        }
74  }
75 
76  if (isset($page['section']) and $page['section'] == 'additional_page' and isset($page['additional_page']))
77  {
78    $base_url = make_index_url(array('section'=>'page')).'/'.(isset($page['additional_page']['permalink']) ? $page['additional_page']['permalink'] : $page['additional_page']['id']);
79  }
80  else
81  {
82    $base_url = duplicate_index_url();
83  }
84 
85  $available_lang = get_languages();
86  foreach ($available_lang as $code => $displayname)
87  {
88        $code2=explode("_", $code);
89    $qlc = array (
90      'url' => add_url_params($base_url, array('lang'=> $code)),
91      'alt' => ucwords($displayname),
92          'hreflang' =>$code2[0],
93      'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
94      );
95   
96    $lsw['flags'][$code] = $qlc ;
97   
98    if ($code == $user['language'])
99    {
100      $lsw['Active'] = $qlc;
101    }
102  }
103
104  $lsw['side'] = ceil(sqrt(count($available_lang)));
105  $template->clear_assign('lang_switch');   
106  $template->assign(
107    array(
108      'lang_switch'=> $lsw,
109      'LSM_PATH' => LSM_PATH,
110      )
111    );
112}
113
114function reloadlang()
115{
116  global $user;
117  $same = $user['language'];   
118 
119  if (isset($_GET['lang']))
120  {
121    if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php'))
122    {
123      if (is_a_guest() or is_generic())
124      {
125        pwg_set_session_var('lang_switch', $_GET['lang']);
126      }
127      else
128      {
129        $query = '
130UPDATE '.USER_INFOS_TABLE.'
131  SET language = \''.$_GET['lang'].'\'
132  WHERE user_id = '.$user['id'].'
133;';
134        pwg_query($query);
135      }
136      $user['language'] = $_GET['lang'];
137    }
138  }
139  elseif ((is_a_guest() or is_generic()))
140  {
141    $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
142  }
143 
144  if ( $same !== $user['language'])
145  {
146    load_language('common.lang', '', array('language'=>$user['language']));
147   
148    load_language(
149      'lang',
150      PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
151      array(
152        'language' => $user['language'],
153        'no_fallback' => true,
154        'local' => true
155        )
156      );
157  }
158   
159  if (defined('IN_ADMIN') and IN_ADMIN)
160  {
161    load_language('admin.lang', '', array('language'=>$user['language']));
162  }
163}
164
165?>
Note: See TracBrowser for help on using the repository browser.