Ignore:
Timestamp:
Nov 19, 2007, 8:51:54 PM (16 years ago)
Author:
vdigital
Message:

Minor code review

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/language_switch/language_switch.inc.php

    r2161 r2162  
    1 <?php /*
    2 Plugin Name: Language Switch
    3 Version: 1.0
    4 Description: Give you an advice on the administration page.
    5 Plugin URI: http://www.phpwebgallery.net
    6 Author: PhpWebGallery team
    7 Author URI: http://www.phpwebgallery.net
    8 */
     1<?php
    92// +-----------------------------------------------------------------------+
    103// | PhpWebGallery - a PHP based picture gallery                           |
     
    3326function language_switch()
    3427{
    35 global $user, $template, $conf, $lang;
    36 
    37 if (!isset($user['status']))
    38 { die('You are not authorized to access this page'); };
    39 
    40 if ( isset( $_GET['lang']) )
    41 {
    42   if ( !empty($_GET['lang'] ) and
    43   file_exists( PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php') )
     28  global $user, $template, $conf, $lang;
     29  if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
     30  if ( isset( $_GET['lang']) )
    4431  {
    45     if ($user['is_the_guest'] or $user['status'] == 'generic')
     32    if ( !empty($_GET['lang'] ) and
     33      file_exists( PHPWG_ROOT_PATH.'language/'
     34      . $_GET['lang'].'/common.lang.php') )
    4635    {
    47       setcookie( 'pwg_lang_switch', $_GET['lang'],
    48         time()+60*60*24*30, cookie_path() );
     36      if (is_a_guest() or is_generic())
     37      {
     38        setcookie( 'pwg_lang_switch', $_GET['lang'],
     39          time()+60*60*24*30, cookie_path() );
     40      }
     41      else
     42      {
     43        $query = 'UPDATE '.USER_INFOS_TABLE.'
     44        SET language = \''.$_GET['lang'].'\'
     45        WHERE user_id = '.$user['id'].'
     46        ;';
     47        pwg_query($query);
     48      }
     49      $user['language'] = $_GET['lang'];
    4950    }
    50     else
    51     {
    52         $query = '
    53     UPDATE '.USER_INFOS_TABLE.'
    54     SET language = \''.$_GET['lang'].'\'
    55     WHERE user_id = '.$user['id'].'
    56     ;';
    57       pwg_query($query);
    58     }
    59     $user['language'] = $_GET['lang'];
    6051  }
    61 }
    6252// Users have $user['language']
    6353// Guest or generic members will use their cookied language !
     54  if ((is_a_guest() or is_generic())
     55    and isset( $_COOKIE['pwg_lang_switch'] ) )
     56  {
     57    $user['language'] = $_COOKIE['pwg_lang_switch'];
     58  }
    6459
    65 if ((is_a_guest() or is_generic())
    66   and isset( $_COOKIE['pwg_lang_switch'] ) )
    67 { $user['language'] = $_COOKIE['pwg_lang_switch']; }
    68 
    69 load_language('common.lang', '', $user['language']);
    70 load_language('local.lang', '', $user['language']);
    71 if (defined('IN_ADMIN') and IN_ADMIN)
    72 {
    73   load_language('admin.lang', '', $user['language']);
    74 }
     60  load_language('common.lang', '', $user['language']);
     61  load_language('local.lang', '', $user['language']);
     62  if (defined('IN_ADMIN') and IN_ADMIN)
     63  {
     64    load_language('admin.lang', '', $user['language']);
     65  }
    7566}
    7667//if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); }
    7768
    78 
    79 
    80 
    81 
    8269function Lang_flags()
    8370{
    84 global $user, $template;
    85 $available_lang = get_languages();
    86 foreach ( $available_lang as $code => $displayname )
    87 {
    88   $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) );
    89   $qlc_alt = ucwords( $displayname );
    90   $qlc_title =  $qlc_alt;
    91   $qlc_img =  PHPWG_PLUGINS_PATH.'language_switch/icons/'
     71  global $user, $template;
     72  $available_lang = get_languages();
     73  foreach ( $available_lang as $code => $displayname )
     74  {
     75    $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) );
     76    $qlc_alt = ucwords( $displayname );
     77    $qlc_title =  $qlc_alt;
     78    $qlc_img =  PHPWG_PLUGINS_PATH.'language_switch/icons/'
    9279       . $code . '.gif';
    93    // echo $code . ' '. $qlc_url .' // <br />';
    94    // echo $user['language'] . ' '. $qlc_img .' /// <br />';
    9580 
    9681    if ( $code !== $user['language'] and file_exists($qlc_img) )
    97   {
    98     $template -> concat_var( 'PLUGIN_INDEX_ACTIONS',
    99       '<li><a href="' . $qlc_url . '" ><img src="' . $qlc_img . '" alt="'
    100       . $qlc_alt . '" title="'
    101       . $qlc_title . '" style="border: 1px solid #000000; '
    102       . ' margin: 0px 2px;" /></a></li>');
     82    {
     83      $template -> concat_var( 'PLUGIN_INDEX_ACTIONS',
     84        '<li><a href="' . $qlc_url . '" ><img src="' . $qlc_img . '" alt="'
     85        . $qlc_alt . '" title="'
     86        . $qlc_title . '" style="border: 1px solid #000000; '
     87        . ' margin: 0px 2px;" /></a></li>');
     88    }
    10389  }
    10490}
    105 }
    10691?>
Note: See TracChangeset for help on using the changeset viewer.