diff options
author | patdenice <patdenice@piwigo.org> | 2011-03-04 10:41:36 +0000 |
---|---|---|
committer | patdenice <patdenice@piwigo.org> | 2011-03-04 10:41:36 +0000 |
commit | 2e44cc79de44f10abc217becac00a3b76e3079bb (patch) | |
tree | f596b26b7fd6b57fcc63ba505e689293f3dae03d /admin | |
parent | 5b9f42b785d0fe97b8645aaa3eb69e898f6eb7fb (diff) |
feature:2210
Improve language management.
git-svn-id: http://piwigo.org/svn/trunk@9518 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r-- | admin/include/languages.class.php | 96 | ||||
-rw-r--r-- | admin/languages_installed.php | 8 | ||||
-rw-r--r-- | admin/languages_new.php | 2 |
3 files changed, 82 insertions, 24 deletions
diff --git a/admin/include/languages.class.php b/admin/include/languages.class.php index 44d1ee916..abaef1353 100644 --- a/admin/include/languages.class.php +++ b/admin/include/languages.class.php @@ -80,8 +80,10 @@ class languages $query = ' INSERT INTO '.LANGUAGES_TABLE.' - (id, name) - VALUES(\''.$language_id.'\', \''.$this->fs_languages[$language_id].'\') + (id, version, name) + VALUES(\''.$language_id.'\', + \''.$this->fs_languages[$language_id]['version'].'\', + \''.$this->fs_languages[$language_id]['name'].'\') ;'; pwg_query($query); break; @@ -157,21 +159,60 @@ UPDATE '.USER_INFOS_TABLE.' $target_charset = strtolower($target_charset); $dir = opendir(PHPWG_ROOT_PATH.'language'); - while ($file = readdir($dir)) { - $path = PHPWG_ROOT_PATH.'language/'.$file; - if (!is_link($path) and is_dir($path) and file_exists($path.'/iso.txt')) + if ($file!='.' and $file!='..') { - list($language_name) = @file($path.'/iso.txt'); - - $languages[$file] = convert_charset($language_name, 'utf-8', $target_charset); + $path = PHPWG_ROOT_PATH.'language/'.$file; + if (is_dir($path) and !is_link($path) + and preg_match('/^[a-zA-Z0-9-_]+$/', $file ) + and file_exists($path.'/common.lang.php') + ) + { + $language = array( + 'code'=>$file, + 'version'=>'0', + 'uri'=>'', + 'author'=>'', + ); + $plg_data = implode( '', file($path.'/common.lang.php') ); + + if ( preg_match("|Language Name: (.*)|", $plg_data, $val) ) + { + $language['name'] = trim( $val[1] ); + $language['name'] = convert_charset($language['name'], 'utf-8', $target_charset); + } + if (preg_match("|Version: (.*)|", $plg_data, $val)) + { + $language['version'] = trim($val[1]); + } + if ( preg_match("|Language URI: (.*)|", $plg_data, $val) ) + { + $language['uri'] = trim($val[1]); + } + if ( preg_match("|Author: (.*)|", $plg_data, $val) ) + { + $language['author'] = trim($val[1]); + } + if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) + { + $language['author uri'] = trim($val[1]); + } + if (!empty($language['uri']) and strpos($language['uri'] , 'extension_view.php?eid=')) + { + list( , $extension) = explode('extension_view.php?eid=', $language['uri']); + if (is_numeric($extension)) $language['extension'] = $extension; + } + // IMPORTANT SECURITY ! + $language = array_map('htmlspecialchars', $language); + $this->fs_languages[$file] = $language; + } } } closedir($dir); - @asort($languages); + @uasort($this->fs_languages, 'name_compare'); - return $languages; + return $this->fs_languages; } function get_db_languages() @@ -192,7 +233,7 @@ UPDATE '.USER_INFOS_TABLE.' /** * Retrieve PEM server datas to $server_languages */ - function get_server_languages() + function get_server_languages($new=false) { global $user; @@ -225,6 +266,16 @@ UPDATE '.USER_INFOS_TABLE.' return false; } + // Languages to check + $languages_to_check = array(); + foreach($this->fs_languages as $fs_language) + { + if (isset($fs_language['extension'])) + { + $languages_to_check[] = $fs_language['extension']; + } + } + // Retrieve PEM languages infos $url = PEM_URL . '/api/get_revision_list.php'; $get_data = array_merge($get_data, array( @@ -233,6 +284,17 @@ UPDATE '.USER_INFOS_TABLE.' 'lang' => $user['language'], ) ); + if (!empty($languages_to_check)) + { + if ($new) + { + $get_data['extension_exclude'] = implode(',', $languages_to_check); + } + else + { + $get_data['extension_include'] = implode(',', $languages_to_check); + } + } if (fetchRemote($url, $result, $get_data)) { @@ -243,12 +305,12 @@ UPDATE '.USER_INFOS_TABLE.' } foreach ($pem_languages as $language) { - if (preg_match('/^.*? \[[A-Z]{2}\]$/', $language['extension_name']) - and !in_array($language['extension_name'], $this->fs_languages)) + if (preg_match('/^.*? \[[A-Z]{2}\]$/', $language['extension_name'])) { - $this->server_languages[] = $language; + $this->server_languages[$language['extension_name']] = $language; } } + @ksort($this->server_languages); return true; } return false; @@ -280,8 +342,8 @@ UPDATE '.USER_INFOS_TABLE.' { foreach ($list as $file) { - // we search iso.txt in archive - if (basename($file['filename']) == 'iso.txt' + // we search common.lang.php in archive + if (basename($file['filename']) == 'common.lang.php' and (!isset($main_filepath) or strlen($file['filename']) < strlen($main_filepath))) { @@ -290,7 +352,7 @@ UPDATE '.USER_INFOS_TABLE.' } if (isset($main_filepath)) { - $root = basename(dirname($main_filepath)); // iso.txt path in archive + $root = basename(dirname($main_filepath)); // common.lang.php path in archive if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $root)) { if ($action == 'install') diff --git a/admin/languages_installed.php b/admin/languages_installed.php index a43883708..2f4c23f30 100644 --- a/admin/languages_installed.php +++ b/admin/languages_installed.php @@ -54,13 +54,9 @@ $default_language = get_default_language(); $tpl_languages = array(); -foreach($languages->fs_languages as $language_id => $language_name) +foreach($languages->fs_languages as $language_id => $language) { - $language = array( - 'id' => $language_id, - 'name' => $language_name, - 'u_action' => $base_url.'&language='.$language_id, - ); + $language['u_action'] = add_url_params($base_url, array('language' => $language_id)); if (in_array($language_id, array_keys($languages->db_languages))) { diff --git a/admin/languages_new.php b/admin/languages_new.php index 98bd52d9a..6f3d0abfa 100644 --- a/admin/languages_new.php +++ b/admin/languages_new.php @@ -107,7 +107,7 @@ if (isset($_GET['installstatus'])) // +-----------------------------------------------------------------------+ // | start template output | // +-----------------------------------------------------------------------+ -if ($languages->get_server_languages()) +if ($languages->get_server_languages(true)) { foreach($languages->server_languages as $language) { |