Changeset 15923


Ignore:
Timestamp:
Jun 21, 2012, 12:23:12 PM (8 years ago)
Author:
mistic100
Message:

[Language Switch] new version using 2.4 drop-down menus

Location:
trunk/plugins/language_switch
Files:
3 added
3 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/language_switch/flags.tpl

    r12342 r15923  
    1 </ul>
    2 <ul class="categoryActions">
    3 <li class="menuf">
    4   <div>
    5     <ul>
    6       <li>
    7         <a rel="nofollow" href="#" class="activeFlag">
    8           <img class="flags" src="{$lang_switch.Active.img}" alt="{$lang_switch.Active.alt}" title="{$lang_switch.Active.alt}"/>
    9         </a>
    10 <!--[if lte IE 6]>
    11         <a rel="nofollow" href="#">
    12           <img class="flags" src="{$lang_switch.Active.img}" alt="{$lang_switch.Active.alt}" title="{$lang_switch.Active.alt}"/>
    13           <table>
    14             <tr>
    15               <td>
    16 <![endif]-->
    17         <ul class="flag-pan">
    18          <li class="languageSwitchBoxTitle">{'Language'|@translate}</li>
     1<li>{strip}<a id="languageSwitchLink" title="{'Language'|@translate}" class="pwg-state-default pwg-button" rel="nofollow">
     2  <span class="pwg-icon" style="background:url('{$lang_switch.Active.img}') center center no-repeat;">&nbsp;</span><span class="pwg-button-text">{'Language'|@translate}</span>
     3</a>
     4<div id="languageSwitchBox" class="switchBox">
     5  <div class="switchBoxTitle">{'Language'|@translate}</div>
     6  {foreach from=$lang_switch.flags item=flag name=f}
     7  <a rel="nofollow" href="{$flag.url}"><img class="flags" src="{$flag.img}" alt="{$flag.alt}"> {$flag.title}</a>
     8  {if ($smarty.foreach.f.index+1)%3 == 0}<br>{/if}
     9  {/foreach}
     10</div>
     11{/strip}</li>
    1912
    20 {foreach from=$lang_switch.flags key=code item=flag name=f}
    21           <li>
    22             <a rel="nofollow" href="{$flag.url}">
    23               <img class="flags" src="{$flag.img}" alt="{$flag.alt}" title="{$flag.alt}"/> {$flag.title}
    24             </a>
    25           </li>
    26 {/foreach}
     13{footer_script require='jquery'}{literal}
     14jQuery("#languageSwitchLink").click(function() {
     15        var elt = jQuery("#languageSwitchBox");
     16        elt.css("left", Math.min(jQuery(this).offset().left, jQuery(window).width() - elt.outerWidth(true) - 5))
     17                .css("top", jQuery(this).offset().top + jQuery(this).outerHeight(true))
     18                .toggle();
     19});
     20jQuery("#languageSwitchBox").on("mouseleave", function() {
     21        jQuery(this).hide();
     22});
     23{/literal}{/footer_script}
    2724
    28         </ul>
    29 <!--[if lte IE 6]>
    30               </td>
    31             </tr>
    32           </table>
    33         </a>
    34 <![endif]-->
    35       </li>
    36     </ul>
    37   </div>
    38 </li>
    39 
    40 {combine_css path="plugins/language_switch/language_switch-default.css"}
    41 
    42 {if $themeconf.name eq 'Sylvia'}
    43 {combine_css path="plugins/language_switch/language_switch-Sylvia.css"}
     25{* <!-- switchBox structure for theme which don't include default style --> *}
     26{if $themeconf.parent != 'default' or (isset($themeconf.load_parent_local_head) and $themeconf.load_parent_local_head == false) }
     27{combine_css path=$LANGUAGE_SWITCH_PATH|@cat:"default.css"}
    4428{/if}
    4529
    46 {html_head}
    47 <!--[if lte IE 6]>
    48 <link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/language_switch/language_switch-ie6.css">
    49 <![endif]-->
    50 {/html_head}
     30{* <!-- stylish for non core themes (should be removed when all themes are updated) --> *}
     31{if $themeconf.name != 'clear' and $themeconf.name != 'dark' and $themeconf.name != 'elegant' and $themeconf.name != 'Sylvia'}
     32{combine_css path=$LANGUAGE_SWITCH_PATH|@cat:"style.css"}
     33{/if}
     34
     35{* <!-- common style specific for LanguageSwitch --> *}
     36{combine_css path=$LANGUAGE_SWITCH_PATH|@cat:"language_switch.css"}
  • trunk/plugins/language_switch/language_switch.inc.php

    r13956 r15923  
    2222// +-----------------------------------------------------------------------+
    2323
    24 if (!defined('LANGUAGE_SWITCH_PATH'))
     24if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     25
     26function language_controler_switch()
    2527{
    26   define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
    27 }
     28  global $user;
     29   
     30  $same = $user['language'];
     31 
     32  if (isset($_GET['lang']))
     33  {
     34    include_once(PHPWG_ROOT_PATH . 'admin/include/languages.class.php');
     35    $languages = new languages();
     36    if ( !in_array($_GET['lang'], array_keys($languages->fs_languages)) )
     37    {
     38      $_GET['lang'] = PHPWG_DEFAULT_LANGUAGE;
     39    }
    2840
    29 class language_controler
    30 {
    31   static public function _switch()
    32   {
    33     global $user;
    34    
    35     if (!defined('PHPWG_ROOT_PATH'))
     41    if ( !empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php') )
    3642    {
    37       die('Hacking attempt!');
    38     }
    39    
    40     $same = $user['language'];
    41    
    42     if (isset($_GET['lang']))
    43     {
    44       include_once(PHPWG_ROOT_PATH . 'admin/include/languages.class.php');
    45       $languages = new languages();
    46       if (!in_array($_GET['lang'], array_keys($languages->fs_languages)))
     43      if ( is_a_guest() or is_generic() )
    4744      {
    48         $_GET['lang'] = PHPWG_DEFAULT_LANGUAGE;
     45        pwg_set_session_var('lang_switch', $_GET['lang']);
    4946      }
    50 
    51       if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php'))
     47      else
    5248      {
    53         if (is_a_guest() or is_generic())
    54         {
    55           pwg_set_session_var('lang_switch', $_GET['lang']);
    56         }
    57         else
    58         {
    59           $query = '
     49        $query = '
    6050UPDATE '.USER_INFOS_TABLE.'
    6151  SET language = \''.$_GET['lang'].'\'
    6252  WHERE user_id = '.$user['id'].'
    6353;';
    64           pwg_query($query);
    65         }
    66        
    67         $user['language'] = $_GET['lang'];
     54        pwg_query($query);
    6855      }
     56     
     57      $user['language'] = $_GET['lang'];
    6958    }
    70     elseif ((is_a_guest() or is_generic()))
     59  }
     60  elseif ( (is_a_guest() or is_generic()) )
     61  {
     62    $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
     63  }
     64 
     65  // Reload language only if it isn't the same one
     66  if ( $same !== $user['language'] )
     67  {
     68    load_language('common.lang', '', array('language'=>$user['language']));
     69   
     70    load_language(
     71      'lang',
     72      PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
     73      array(
     74        'language' => $user['language'],
     75        'no_fallback' => true,
     76        'local' => true
     77        )
     78      );
     79   
     80    if ( defined('IN_ADMIN') and IN_ADMIN )
    7181    {
    72       $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
     82      // Never currently
     83      load_language('admin.lang', '', array('language'=>$user['language']));
    7384    }
     85  }
     86}
     87
     88function language_controler_flags()
     89{
     90  global $user, $template, $conf;
     91 
     92  $available_lang = get_languages();
     93 
     94  if (isset($conf['no_flag_languages']))
     95  {
     96    $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages']));
     97  }
     98 
     99  $url_starting = get_query_string_diff(array('lang'));
     100
     101  foreach ($available_lang as $code => $displayname)
     102  {
     103    $qlc = array (
     104      'url' => add_url_params(duplicate_index_url(), array('lang'=> $code)),
     105      'alt' => ucwords($displayname),
     106      'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
     107      'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
     108      );
    74109   
    75     // Reload language only if it isn't the same one
    76     if ( $same !== $user['language'])
     110    $lsw['flags'][$code] = $qlc;
     111   
     112    if ($code == $user['language'])
    77113    {
    78       load_language('common.lang', '', array('language'=>$user['language']));
    79      
    80       load_language(
    81         'lang',
    82         PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
    83         array(
    84           'language' => $user['language'],
    85           'no_fallback' => true,
    86           'local' => true
    87           )
    88         );
    89      
    90       if (defined('IN_ADMIN') and IN_ADMIN)
    91       {
    92         // Never currently
    93         load_language('admin.lang', '', array('language'=>$user['language']));
    94       }
     114      $lsw['Active'] = $qlc;
    95115    }
    96116  }
    97117 
    98   static public function _flags()
    99   {
    100     global $user, $template, $conf;
    101    
    102     $available_lang = get_languages();
    103    
    104     if (isset($conf['no_flag_languages']))
    105     {
    106       $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages']));
    107     }
    108    
    109     $url_starting = get_query_string_diff(array('lang'));
    110 
    111     foreach ($available_lang as $code => $displayname)
    112     {
    113       $qlc = array (
    114         'url' => add_url_params(duplicate_index_url(), array('lang'=> $code)),
    115         'alt' => ucwords($displayname),
    116         'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
    117         'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
    118         );
    119      
    120       $lsw['flags'][$code] = $qlc ;
    121      
    122       if ($code == $user['language'])
    123       {
    124         $lsw['Active'] = $qlc;
    125       }
    126     }
    127    
    128     $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
    129    
    130     $lsw['side'] = ceil(sqrt(count($available_lang)));
    131    
    132     $template->assign(
    133       array(
    134         'lang_switch'=> $lsw,
    135         'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
    136         )
    137       );
    138    
    139     $flags = $template->parse('language_flags',true);
    140     $template->clear_assign('lang_switch');
    141     $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
    142   }
    143 }
    144 
    145   /* {html_head} usage function */
    146   /* See flags.tpl for example (due no catenation available) */
    147 if (!function_exists('Componant_exists'))
    148 {
    149   function Componant_exists($path, $file)
    150   {
    151     return file_exists( $path . $file);
    152   }
     118  $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
     119 
     120  $template->assign(
     121    array(
     122      'lang_switch'=> $lsw,
     123      'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
     124      )
     125    );
     126 
     127  $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('language_flags', true) );
     128  $template->clear_assign('lang_switch');
    153129}
    154130
  • trunk/plugins/language_switch/main.inc.php

    r12922 r15923  
    2424/*
    2525Plugin Name: Language Switch
    26 Version: 2.3.0
     26Version: 2.4.0
    2727Description: Switch to another language from flags on your gallery home page.
    2828Plugin URI: http://piwigo.org/ext/extension_view.php?eid=123
     
    3131*/
    3232
    33 include_once(PHPWG_PLUGINS_PATH.'language_switch/language_switch.inc.php');
    34 $language_controler = new language_controler();
    35 add_event_handler('loading_lang', array(&$language_controler, '_switch'), 5 );
    36 add_event_handler('loc_end_index', array(&$language_controler, '_flags'), 95 );
     33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     34
     35define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
     36
     37include_once(LANGUAGE_SWITCH_PATH.'language_switch.inc.php');
     38
     39add_event_handler('loading_lang', 'language_controler_switch', 5 );
     40add_event_handler('loc_end_index', 'language_controler_flags', 95 );
     41
    3742?>
Note: See TracChangeset for help on using the changeset viewer.