Changeset 9518


Ignore:
Timestamp:
03/04/11 11:41:36 (9 years ago)
Author:
patdenice
Message:

feature:2210
Improve language management.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/languages.class.php

    r8728 r9518  
    8181        $query = ' 
    8282INSERT INTO '.LANGUAGES_TABLE.' 
    83   (id, name) 
    84   VALUES(\''.$language_id.'\', \''.$this->fs_languages[$language_id].'\') 
     83  (id, version, name) 
     84  VALUES(\''.$language_id.'\', 
     85         \''.$this->fs_languages[$language_id]['version'].'\', 
     86         \''.$this->fs_languages[$language_id]['name'].'\') 
    8587;'; 
    8688        pwg_query($query); 
     
    158160 
    159161    $dir = opendir(PHPWG_ROOT_PATH.'language'); 
    160  
    161162    while ($file = readdir($dir)) 
    162163    { 
    163       $path = PHPWG_ROOT_PATH.'language/'.$file; 
    164       if (!is_link($path) and is_dir($path) and file_exists($path.'/iso.txt')) 
    165       { 
    166         list($language_name) = @file($path.'/iso.txt'); 
    167  
    168         $languages[$file] = convert_charset($language_name, 'utf-8', $target_charset); 
     164      if ($file!='.' and $file!='..') 
     165      { 
     166        $path = PHPWG_ROOT_PATH.'language/'.$file; 
     167        if (is_dir($path) and !is_link($path) 
     168            and preg_match('/^[a-zA-Z0-9-_]+$/', $file ) 
     169            and file_exists($path.'/common.lang.php') 
     170            ) 
     171        { 
     172          $language = array( 
     173              'code'=>$file, 
     174              'version'=>'0', 
     175              'uri'=>'', 
     176              'author'=>'', 
     177            ); 
     178          $plg_data = implode( '', file($path.'/common.lang.php') ); 
     179 
     180          if ( preg_match("|Language Name: (.*)|", $plg_data, $val) ) 
     181          { 
     182            $language['name'] = trim( $val[1] ); 
     183            $language['name'] = convert_charset($language['name'], 'utf-8', $target_charset); 
     184          } 
     185          if (preg_match("|Version: (.*)|", $plg_data, $val)) 
     186          { 
     187            $language['version'] = trim($val[1]); 
     188          } 
     189          if ( preg_match("|Language URI: (.*)|", $plg_data, $val) ) 
     190          { 
     191            $language['uri'] = trim($val[1]); 
     192          } 
     193          if ( preg_match("|Author: (.*)|", $plg_data, $val) ) 
     194          { 
     195            $language['author'] = trim($val[1]); 
     196          } 
     197          if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) 
     198          { 
     199            $language['author uri'] = trim($val[1]); 
     200          } 
     201          if (!empty($language['uri']) and strpos($language['uri'] , 'extension_view.php?eid=')) 
     202          { 
     203            list( , $extension) = explode('extension_view.php?eid=', $language['uri']); 
     204            if (is_numeric($extension)) $language['extension'] = $extension; 
     205          } 
     206          // IMPORTANT SECURITY ! 
     207          $language = array_map('htmlspecialchars', $language); 
     208          $this->fs_languages[$file] = $language; 
     209        } 
    169210      } 
    170211    } 
    171212    closedir($dir); 
    172     @asort($languages); 
    173  
    174     return $languages; 
     213    @uasort($this->fs_languages, 'name_compare'); 
     214 
     215    return $this->fs_languages; 
    175216  } 
    176217 
     
    193234   * Retrieve PEM server datas to $server_languages 
    194235   */ 
    195   function get_server_languages() 
     236  function get_server_languages($new=false) 
    196237  { 
    197238    global $user; 
     
    224265    { 
    225266      return false; 
     267    } 
     268 
     269    // Languages to check 
     270    $languages_to_check = array(); 
     271    foreach($this->fs_languages as $fs_language) 
     272    { 
     273      if (isset($fs_language['extension'])) 
     274      { 
     275        $languages_to_check[] = $fs_language['extension']; 
     276      } 
    226277    } 
    227278 
     
    234285      ) 
    235286    ); 
     287    if (!empty($languages_to_check)) 
     288    { 
     289      if ($new) 
     290      { 
     291        $get_data['extension_exclude'] = implode(',', $languages_to_check); 
     292      } 
     293      else 
     294      { 
     295        $get_data['extension_include'] = implode(',', $languages_to_check); 
     296      } 
     297    } 
    236298 
    237299    if (fetchRemote($url, $result, $get_data)) 
     
    244306      foreach ($pem_languages as $language) 
    245307      { 
    246         if (preg_match('/^.*? \[[A-Z]{2}\]$/', $language['extension_name']) 
    247           and !in_array($language['extension_name'], $this->fs_languages)) 
    248         { 
    249           $this->server_languages[] = $language; 
    250         } 
    251       } 
     308        if (preg_match('/^.*? \[[A-Z]{2}\]$/', $language['extension_name'])) 
     309        { 
     310          $this->server_languages[$language['extension_name']] = $language; 
     311        } 
     312      } 
     313      @ksort($this->server_languages); 
    252314      return true; 
    253315    } 
     
    281343          foreach ($list as $file) 
    282344          { 
    283             // we search iso.txt in archive 
    284             if (basename($file['filename']) == 'iso.txt' 
     345            // we search common.lang.php in archive 
     346            if (basename($file['filename']) == 'common.lang.php' 
    285347              and (!isset($main_filepath) 
    286348              or strlen($file['filename']) < strlen($main_filepath))) 
     
    291353          if (isset($main_filepath)) 
    292354          { 
    293             $root = basename(dirname($main_filepath)); // iso.txt path in archive 
     355            $root = basename(dirname($main_filepath)); // common.lang.php path in archive 
    294356            if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $root)) 
    295357            { 
  • trunk/admin/languages_installed.php

    r8728 r9518  
    5555$tpl_languages = array(); 
    5656 
    57 foreach($languages->fs_languages as $language_id => $language_name) 
     57foreach($languages->fs_languages as $language_id => $language) 
    5858{ 
    59   $language = array( 
    60     'id' => $language_id, 
    61     'name' => $language_name, 
    62     'u_action' => $base_url.'&amp;language='.$language_id, 
    63     ); 
     59  $language['u_action'] = add_url_params($base_url, array('language' => $language_id)); 
    6460 
    6561  if (in_array($language_id, array_keys($languages->db_languages))) 
  • trunk/admin/languages_new.php

    r8728 r9518  
    108108// |                     start template output                             | 
    109109// +-----------------------------------------------------------------------+ 
    110 if ($languages->get_server_languages()) 
     110if ($languages->get_server_languages(true)) 
    111111{ 
    112112  foreach($languages->server_languages as $language) 
  • trunk/install.php

    r8728 r9518  
    193193  $language = 'en_UK'; 
    194194  // Try to get browser language 
    195   foreach ($languages->fs_languages as $language_code => $language_name) 
     195  foreach ($languages->fs_languages as $language_code => $fs_language) 
    196196  { 
    197197    if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) 
     
    341341 
    342342    // fill languages table 
    343     foreach ($languages->get_fs_languages() as $language_code => $language_name) 
     343    foreach ($languages->get_fs_languages() as $language_code => $fs_language) 
    344344    { 
    345345      $languages->perform_action('activate', $language_code); 
     
    418418$dbengines = available_engines(); 
    419419 
    420 foreach ($languages->fs_languages as $language_code => $language_name) 
     420foreach ($languages->fs_languages as $language_code => $fs_language) 
    421421{ 
    422422  if ($language == $language_code) 
     
    424424    $template->assign('language_selection', $language_code); 
    425425  } 
    426   $languages_options[$language_code] = $language_name; 
     426  $languages_options[$language_code] = $fs_language['name']; 
    427427} 
    428428$template->assign('language_options', $languages_options); 
  • trunk/install/db/90-database.php

    r9086 r9518  
    5050$languages = new languages(PWG_CHARSET); 
    5151 
    52 foreach ($languages->fs_languages as $language_code => $language_name) 
     52foreach ($languages->fs_languages as $language_code => $fs_language) 
    5353{ 
    5454  $languages->perform_action('activate', $language_code); 
  • trunk/install/php5_apache_configuration.php

    r8728 r9518  
    175175    <td> 
    176176      <select name="language" onchange="document.location = \''.$script.'.php?language=\'+this.options[this.selectedIndex].value;">'; 
    177   foreach ($languages->fs_languages as $code => $name) 
     177  foreach ($languages->fs_languages as $code => $fs_language) 
    178178  { 
    179179    echo ' 
    180       <option label="'.$name.'" value="'.$code.'" '.($code == $language ? 'selected="selected"' : '') .'>'.$name.'</option>'; 
     180      <option label="'.$fs_language['name'].'" value="'.$code.'" '.($code == $language ? 'selected="selected"' : '') .'>'.$fs_language['name'].'</option>'; 
    181181  } 
    182182  echo ' 
  • trunk/upgrade.php

    r8728 r9518  
    160160  $language = 'en_UK'; 
    161161  // Try to get browser language 
    162   foreach ($languages->fs_languages as $language_code => $language_name) 
     162  foreach ($languages->fs_languages as $language_code => $fs_language) 
    163163  { 
    164164    if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) 
     
    401401  $languages = new languages(); 
    402402   
    403   foreach ($languages->fs_languages as $language_code => $language_name) 
     403  foreach ($languages->fs_languages as $language_code => $fs_language) 
    404404  { 
    405405    if ($language == $language_code) 
     
    407407      $template->assign('language_selection', $language_code); 
    408408    } 
    409     $languages_options[$language_code] = $language_name; 
     409    $languages_options[$language_code] = $fs_language['name']; 
    410410  } 
    411411  $template->assign('language_options', $languages_options); 
Note: See TracChangeset for help on using the changeset viewer.