aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2010-03-25 20:18:28 +0000
committerpatdenice <patdenice@piwigo.org>2010-03-25 20:18:28 +0000
commit6b445114da301438f386eeb9853448b53fd9e516 (patch)
tree029b826deec8d484047a7394c92b9477f3e54f43
parent7ebdbee901b1290fc3578b81241b25227c786efb (diff)
Feature 1535: Add language manager.
git-svn-id: http://piwigo.org/svn/trunk@5357 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin.php1
-rw-r--r--admin/include/functions.php1
-rw-r--r--admin/include/languages.class.php228
-rw-r--r--admin/languages_installed.php90
-rw-r--r--admin/themes/default/default-layout.css8
-rw-r--r--admin/themes/default/template/admin.tpl1
-rw-r--r--admin/themes/default/template/languages_installed.tpl34
-rw-r--r--include/functions.inc.php26
-rw-r--r--install.php18
-rw-r--r--install/db/90-database.php14
-rw-r--r--language/en_UK/admin.lang.php3
-rw-r--r--language/fr_FR/admin.lang.php1
12 files changed, 389 insertions, 36 deletions
diff --git a/admin.php b/admin.php
index f05cb8f3e..b08343f24 100644
--- a/admin.php
+++ b/admin.php
@@ -111,6 +111,7 @@ $template->assign(
'U_CONFIG_DISPLAY'=> $conf_link.'default',
'U_CONFIG_EXTENTS'=> $link_start.'extend_for_templates',
'U_CONFIG_MENUBAR'=> $link_start.'menubar',
+ 'U_CONFIG_LANGUAGES' => $link_start.'languages_installed',
'U_CONFIG_THEMES'=> $link_start.'themes_installed',
'U_CATEGORIES'=> $link_start.'cat_list',
'U_MOVE'=> $link_start.'cat_move',
diff --git a/admin/include/functions.php b/admin/include/functions.php
index d16b518c0..f4a332623 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1949,6 +1949,7 @@ function get_active_menu($menu_page)
case 'menubar':
case 'themes_new':
case 'themes_installed':
+ case 'languages_installed':
return 5;
}
return 0;
diff --git a/admin/include/languages.class.php b/admin/include/languages.class.php
new file mode 100644
index 000000000..dd65c8abd
--- /dev/null
+++ b/admin/include/languages.class.php
@@ -0,0 +1,228 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+class languages
+{
+ var $fs_languages = array();
+ var $db_languages = array();
+ var $server_languages = array();
+
+ /**
+ * Initialize $fs_languages and $db_languages
+ */
+ function languages($target_charset = null)
+ {
+ $this->fs_languages = $this->get_fs_languages($target_charset);
+ }
+
+ /**
+ * Perform requested actions
+ * @param string - action
+ * @param string - language id
+ * @param array - errors
+ */
+ function perform_action($action, $language_id)
+ {
+ global $conf;
+
+ if (isset($this->db_languages[$language_id]))
+ {
+ $crt_db_language = $this->db_languages[$language_id];
+ }
+
+ $errors = array();
+
+ switch ($action)
+ {
+ case 'activate':
+ if (isset($crt_db_language))
+ {
+ array_push($errors, 'CANNOT ACTIVATE - LANGUAGE IS ALREADY ACTIVATED');
+ break;
+ }
+
+ $query = "
+INSERT INTO ".LANGUAGES_TABLE."
+ SET id = '".$language_id."',
+ name = '".$this->fs_languages[$language_id]."'
+;";
+ pwg_query($query);
+ break;
+
+ case 'deactivate':
+ if (!isset($crt_db_language))
+ {
+ array_push($errors, 'CANNOT DEACTIVATE - LANGUAGE IS ALREADY DEACTIVATED');
+ break;
+ }
+
+ if ($language_id == get_default_language())
+ {
+ array_push($errors, 'CANNOT DEACTIVATE - LANGUAGE IS DEFAULT LANGUAGE');
+ break;
+ }
+
+ $query = "
+DELETE
+ FROM ".LANGUAGES_TABLE."
+ WHERE id= '".$language_id."'
+;";
+ pwg_query($query);
+ break;
+
+ case 'delete':
+ if (!empty($crt_db_language))
+ {
+ array_push($errors, 'CANNOT DELETE - LANGUAGE IS ACTIVATED');
+ break;
+ }
+ if (!isset($this->fs_languages[$language_id]))
+ {
+ array_push($errors, 'CANNOT DELETE - LANGUAGE DOES NOT EXIST');
+ break;
+ }
+
+ // Set default language to user who are using this language
+ $query = '
+UPDATE '.USER_INFOS_TABLE.'
+ SET language = "'.get_default_language().'"
+ WHERE language = "'.$language_id.'"
+;';
+ pwg_query($query);
+
+ if (!$this->deltree(PHPWG_ROOT_PATH.'language/'.$language_id))
+ {
+ $this->send_to_trash(PHPWG_ROOT_PATH.'language/'.$language_id);
+ }
+ break;
+
+ case 'set_default':
+ $query = '
+UPDATE '.USER_INFOS_TABLE.'
+ SET language = "'.$language_id.'"
+ WHERE user_id = '.$conf['default_user_id'].'
+;';
+ pwg_query($query);
+ break;
+ }
+ return $errors;
+ }
+
+ /**
+ * Get languages defined in the language directory
+ */
+ function get_fs_languages($target_charset = null)
+ {
+ if ( empty($target_charset) )
+ {
+ $target_charset = get_pwg_charset();
+ }
+ $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'))
+ {
+ list($language_name) = @file($path.'/iso.txt');
+
+ $languages[$file] = convert_charset($language_name, $target_charset);
+ }
+ }
+ closedir($dir);
+ @asort($languages);
+
+ return $languages;
+ }
+
+ function get_db_languages()
+ {
+ $query = '
+ SELECT id, name
+ FROM '.LANGUAGES_TABLE.'
+ ORDER BY name ASC
+ ;';
+ $result = pwg_query($query);
+
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ $this->db_languages[ $row['id'] ] = $row['name'];
+ }
+ }
+
+ /**
+ * delete $path directory
+ * @param string - path
+ */
+ function deltree($path)
+ {
+ if (is_dir($path))
+ {
+ $fh = opendir($path);
+ while ($file = readdir($fh))
+ {
+ if ($file != '.' and $file != '..')
+ {
+ $pathfile = $path . '/' . $file;
+ if (is_dir($pathfile))
+ {
+ $this->deltree($pathfile);
+ }
+ else
+ {
+ @unlink($pathfile);
+ }
+ }
+ }
+ closedir($fh);
+ return @rmdir($path);
+ }
+ }
+
+ /**
+ * send $path to trash directory
+ * @param string - path
+ */
+ function send_to_trash($path)
+ {
+ $trash_path = PHPWG_ROOT_PATH . 'language/trash';
+ if (!is_dir($trash_path))
+ {
+ @mkdir($trash_path);
+ $file = @fopen($trash_path . '/.htaccess', 'w');
+ @fwrite($file, 'deny from all');
+ @fclose($file);
+ }
+ while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
+ {
+ if (!is_dir($r))
+ {
+ @rename($path, $r);
+ break;
+ }
+ }
+ }
+}
+?> \ No newline at end of file
diff --git a/admin/languages_installed.php b/admin/languages_installed.php
new file mode 100644
index 000000000..ec12ae74b
--- /dev/null
+++ b/admin/languages_installed.php
@@ -0,0 +1,90 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+if( !defined("PHPWG_ROOT_PATH") )
+{
+ die ("Hacking attempt!");
+}
+
+include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
+
+$template->set_filenames(array('languages' => 'languages_installed.tpl'));
+
+$base_url = get_root_url().'admin.php?page='.$page['page'];
+
+$languages = new languages();
+$languages->get_db_languages();
+
+//--------------------------------------------------perform requested actions
+if (isset($_GET['action']) and isset($_GET['language']) and !is_adviser())
+{
+ $page['errors'] = $languages->perform_action($_GET['action'], $_GET['language']);
+
+ if (empty($page['errors']))
+ {
+ redirect($base_url);
+ }
+}
+
+// +-----------------------------------------------------------------------+
+// | start template output |
+// +-----------------------------------------------------------------------+
+$default_language = get_default_language();
+
+foreach($languages->fs_languages as $language_id => $language_name)
+{
+ $template->append('languages', array(
+ 'ID' => $language_id,
+ 'NAME' => $language_name,
+ 'U_ACTION' => $base_url.'&amp;language='.$language_id,
+ 'STATE' => isset($languages->db_languages[$language_id]) ? 'active' : '',
+ 'IS_DEFAULT' => $language_id == $default_language,
+ )
+ );
+}
+
+
+$missing_language_ids = array_diff(
+ array_keys($languages->db_languages),
+ array_keys($languages->fs_languages)
+ );
+
+foreach($missing_language_ids as $language_id)
+{
+ $query = '
+UPDATE '.USER_INFOS_TABLE.'
+ SET language = "'.get_default_language().'"
+ WHERE language = "'.$language_id.'"
+;';
+ pwg_query($query);
+
+ $query = "
+DELETE
+ FROM ".LANGUAGES_TABLE."
+ WHERE id= '".$language_id."'
+;";
+ pwg_query($query);
+}
+
+$template->assign_var_from_handle('ADMIN_CONTENT', 'languages');
+?> \ No newline at end of file
diff --git a/admin/themes/default/default-layout.css b/admin/themes/default/default-layout.css
index d9c71d96a..68cba396e 100644
--- a/admin/themes/default/default-layout.css
+++ b/admin/themes/default/default-layout.css
@@ -36,13 +36,14 @@ TABLE#detailedStats {
width: 99%;
}
-/* Plugins tables */
+/* Plugins, languages tables */
TABLE.plugins { min-width: 400px; }
TABLE.plugins A { border: 0; }
TABLE.plugins TR TD { padding: 4px 10px; }
TABLE.plugins TR TD.pluginState { padding: 4px 16px; }
-TABLE.plugins TR TD.active {
+TABLE.plugins TR TD.active,
+TABLE.languages TR TD.active {
background: url(icon/plugin_active.gif) no-repeat center left;
background-color: inherit; /* IE need it */
}
@@ -63,6 +64,9 @@ TABLE.plugins ul.pluginsActions {
TABLE.plugins ul.pluginsActions li { display: inline; }
+TABLE.languages { min-width: 400px; }
+TABLE.languages TR TD { text-align: center; padding: 4px 20px; }
+
/* categoryOrdering */
SELECT.categoryList {
width: 100%;
diff --git a/admin/themes/default/template/admin.tpl b/admin/themes/default/template/admin.tpl
index 23da23182..9f2bde9e0 100644
--- a/admin/themes/default/template/admin.tpl
+++ b/admin/themes/default/template/admin.tpl
@@ -84,6 +84,7 @@ jQuery().ready(function(){ldelim}
<li><a href="{$U_CONFIG_GENERAL}">{'Options'|@translate}</a></li>
<li><a href="{$U_CONFIG_MENUBAR}">{'Menu'|@translate}</a></li>
<li><a href="{$U_CONFIG_EXTENTS}">{'Templates'|@translate}</a></li>
+ <li><a href="{$U_CONFIG_LANGUAGES}">{'Languages'|@translate}</a></li>
<li><a href="{$U_CONFIG_THEMES}">{'Themes'|@translate}</a></li>
</ul>
</dd>
diff --git a/admin/themes/default/template/languages_installed.tpl b/admin/themes/default/template/languages_installed.tpl
new file mode 100644
index 000000000..e83f13437
--- /dev/null
+++ b/admin/themes/default/template/languages_installed.tpl
@@ -0,0 +1,34 @@
+<div class="titrePage">
+ <h2>{'Languages'|@translate}</h2>
+</div>
+
+<table class="table2 languages">
+<thead>
+ <tr class="throw">
+ <td>{'Language'|@translate}</td>
+ <td>{'Actions'|@translate}</td>
+ </tr>
+</thead>
+
+{foreach from=$languages item=language name=languages_loop}
+ <tr class="{if $smarty.foreach.languages_loop.index is odd}row1{else}row2{/if}">
+ <td class="{$language.STATE}" style="text-align: left;">
+ {$language.NAME}
+ {if $language.IS_DEFAULT}<i>({'Default'|@translate})</i>{/if}
+ </td>
+ <td>
+ {if !$language.IS_DEFAULT}
+ {if $language.STATE == 'active' or $language.STATE == 'missing'}
+ <a href="{$language.U_ACTION}&amp;action=deactivate">{'Deactivate'|@translate}</a> |
+ <a href="{$language.U_ACTION}&amp;action=set_default">{'Default'|@translate}</a>
+ {else}
+ <a href="{$language.U_ACTION}&amp;action=activate">{'Activate'|@translate}</a> |
+ <a href="{$language.U_ACTION}&amp;action=delete" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Delete'|@translate}</a>
+ {/if}
+ {else}
+ ---
+ {/if}
+ </td>
+ </tr>
+{/foreach}
+</table> \ No newline at end of file
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 5d095eaa1..b31a074a0 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -396,29 +396,23 @@ function str2url($str)
*
* @returns array
*/
-function get_languages($target_charset = null)
+function get_languages()
{
- if ( empty($target_charset) )
- {
- $target_charset = get_pwg_charset();
- }
- $target_charset = strtolower($target_charset);
+ $query = '
+SELECT id, name
+ FROM '.LANGUAGES_TABLE.'
+ ORDER BY name ASC
+;';
+ $result = pwg_query($query);
- $dir = opendir(PHPWG_ROOT_PATH.'language');
$languages = array();
-
- while ($file = readdir($dir))
+ while ($row = pwg_db_fetch_assoc($result))
{
- $path = PHPWG_ROOT_PATH.'language/'.$file;
- if (!is_link($path) and is_dir($path) and file_exists($path.'/iso.txt'))
+ if (is_dir(PHPWG_ROOT_PATH.'language/'.$row['id']))
{
- list($language_name) = @file($path.'/iso.txt');
-
- $languages[$file] = convert_charset($language_name, $target_charset);
+ $languages[ $row['id'] ] = $row['name'];
}
}
- closedir($dir);
- @asort($languages);
return $languages;
}
diff --git a/install.php b/install.php
index e1d7a96fe..926dddc67 100644
--- a/install.php
+++ b/install.php
@@ -188,6 +188,9 @@ include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
include(PHPWG_ROOT_PATH . 'admin/include/functions.php');
include(PHPWG_ROOT_PATH . 'admin/include/functions_upgrade.php');
+include(PHPWG_ROOT_PATH . 'admin/include/languages.class.php');
+$languages = new languages('utf-8');
+
if (isset($_GET['language']))
{
$language = strip_tags($_GET['language']);
@@ -196,7 +199,7 @@ else
{
$language = 'en_UK';
// Try to get browser language
- foreach (get_languages('utf-8') as $language_code => $language_name)
+ foreach ($languages->fs_languages as $language_code => $language_name)
{
if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2))
{
@@ -286,7 +289,7 @@ if ( isset( $_POST['install'] ))
$pwg_charset = 'iso-8859-1';
$pwg_db_charset = 'latin1';
$install_charset_collate = '';
- if ( !array_key_exists($language, get_languages($pwg_charset) ) )
+ if ( !array_key_exists($language, $languages->get_fs_languages($pwg_charset) ) )
{
$language='en_UK';
}
@@ -375,15 +378,10 @@ INSERT INTO '.$prefixeTable.'config (param,value,comment)
pwg_query($query);
// fill languages table
- $inserts = array();
- foreach (get_languages('utf-8') as $language_code => $language_name)
+ foreach ($languages->get_fs_languages($pwg_charset) as $language_code => $language_name)
{
- $inserts[] = array(
- 'id' => $language_code,
- 'name' => $language_name,
- );
+ $languages->perform_action('activate', $language_code);
}
- mass_inserts(LANGUAGES_TABLE, array('id', 'name'), $inserts);
// fill $conf global array
load_conf_from_db();
@@ -475,7 +473,7 @@ else
{
$dbengines = available_engines();
- foreach (get_languages('utf-8') as $language_code => $language_name)
+ foreach ($languages->fs_languages as $language_code => $language_name)
{
if ($language == $language_code)
{
diff --git a/install/db/90-database.php b/install/db/90-database.php
index 2daa931a1..532f36a2c 100644
--- a/install/db/90-database.php
+++ b/install/db/90-database.php
@@ -44,15 +44,15 @@ if (DB_CHARSET == 'utf8')
pwg_query($query);
// Fill table
-$inserts = array();
-foreach (get_languages('utf-8') as $language_code => $language_name)
+include_once(PHPWG_ROOT_PATH.'include/constants.php');
+include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
+
+$languages = new languages(PWG_CHARSET);
+
+foreach ($languages->fs_languages as $language_code => $language_name)
{
- $inserts[] = array(
- 'id' => $language_code,
- 'name' => $language_name,
- );
+ $languages->perform_action('activate', $language_code);
}
-mass_inserts(PREFIX_TABLE.'languages', array('id', 'name'), $inserts);
echo
"\n"
diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php
index 4803cbd86..f6913a1de 100644
--- a/language/en_UK/admin.lang.php
+++ b/language/en_UK/admin.lang.php
@@ -749,5 +749,6 @@ $lang['Activate Navigation Thumbnails'] = 'Activate Navigation Thumbnails';
$lang['Activate icon "%s"'] = 'Activate icon "%s"';
$lang['Activate field "%s"'] = 'Activate field "%s"';
$lang['Photo Properties'] = 'Photo Properties';
-$lang['Allow user customization'] = 'Allow user customization';
+$lang['Allow user customization'] = 'Allow user customization';
+$lang['Languages'] = 'Languages';
?>
diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php
index e75b5b805..3885e4227 100644
--- a/language/fr_FR/admin.lang.php
+++ b/language/fr_FR/admin.lang.php
@@ -751,4 +751,5 @@ $lang['Upgrade from %s to %s'] = 'Mis à jour de %s vers %s';
$lang['Visit Gallery'] = 'Visiter la galerie';
$lang['Visit Piwigo project website'] = 'Visiter le site web du projet Piwigo';
$lang['pLoader stands for <em>Piwigo Uploader</em>. From your computer, pLoader prepares your photos and transfer them to your Piwigo photo gallery.'] = 'pLoader signifie <em>Piwigo Uploader</em>. Depuis votre ordinateur, pLoader prépare vos photos et les transfert vers votre galerie photo Piwigo.';
+$lang['Languages'] = 'Langues';
?>