mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-08 14:30:05 +01:00
"using the global db object"
This commit is contained in:
parent
81a0b796d9
commit
0927d90e09
@ -1,28 +1,15 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* eGroupWare API - Translation class for SQL *
|
||||
* This file written by Joseph Engo <jengo@phpgroupware.org> *
|
||||
* and Dan Kuykendall <seek3r@phpgroupware.org> *
|
||||
* Handles multi-language support use SQL tables *
|
||||
* Copyright (C) 2000, 2001 Joseph Engo *
|
||||
* ------------------------------------------------------------------------ *
|
||||
* This library is part of the eGroupWare API *
|
||||
* http://www.egroupware.org/api *
|
||||
* ------------------------------------------------------------------------ *
|
||||
* This library is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU Lesser General Public License as published by *
|
||||
* the Free Software Foundation; either version 2.1 of the License, *
|
||||
* or any later version. *
|
||||
* This library 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 Lesser General Public License for more details. *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this library; if not, write to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
/**
|
||||
* eGroupWare API - Translations
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Joseph Engo <jengo@phpgroupware.org>
|
||||
* @author Dan Kuykendall <seek3r@phpgroupware.org>
|
||||
* Copyright (C) 2000, 2001 Joseph Engo
|
||||
* @license http://opensource.org/licenses/lgpl-license.php LGPL - GNU Lesser General Public License
|
||||
* @package api
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
// define the maximal length of a message_id, all message_ids have to be unique
|
||||
// in this length, our column is varchar 128
|
||||
@ -44,6 +31,9 @@
|
||||
define('EGW_LANGFILE_PREFIX', 'egw_');
|
||||
define('PHPGW_LANGFILE_PREFIX', 'phpgw_');
|
||||
|
||||
/**
|
||||
* eGroupWare API - Translations
|
||||
*/
|
||||
class translation
|
||||
{
|
||||
var $userlang = 'en';
|
||||
@ -75,7 +65,6 @@
|
||||
$this->placeholders[] = '%'.$i;
|
||||
}
|
||||
$this->db = is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
|
||||
if (is_object($this->db)) $this->db->set_app('phpgwapi');
|
||||
|
||||
if (!isset($GLOBALS['egw_setup'])) {
|
||||
$this->system_charset = @$GLOBALS['egw_info']['server']['system_charset'];
|
||||
@ -112,12 +101,14 @@
|
||||
{
|
||||
if (!isset($this->charsets[$lang]))
|
||||
{
|
||||
$this->db->select($this->lang_table,'content',array(
|
||||
if (!($this->charsets[$lang] = $this->db->select($this->lang_table,'content',array(
|
||||
'lang' => $lang,
|
||||
'message_id'=> 'charset',
|
||||
'app_name' => 'common',
|
||||
),__LINE__,__FILE__);
|
||||
$this->charsets[$lang] = $this->db->next_record() ? strtolower($this->db->f(0)) : 'iso-8859-1';
|
||||
),__LINE__,__FILE__)->fetchSingle()))
|
||||
{
|
||||
$this->charsets[$lang] = 'iso-8859-1';
|
||||
}
|
||||
}
|
||||
return $this->charsets[$lang];
|
||||
}
|
||||
@ -223,13 +214,12 @@
|
||||
{
|
||||
if ($app == 'setup') return $this->add_setup($lang);
|
||||
|
||||
$this->db->select($this->lang_table,'message_id,content',array(
|
||||
foreach($this->db->select($this->lang_table,'message_id,content',array(
|
||||
'lang' => $lang,
|
||||
'app_name' => $app,
|
||||
),__LINE__,__FILE__);
|
||||
while ($this->db->next_record())
|
||||
),__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$this->lang_arr[strtolower ($this->db->f('message_id'))] = $this->db->f('content');
|
||||
$this->lang_arr[strtolower ($row['message_id'])] = $row['content'];
|
||||
}
|
||||
$this->loaded_apps[$app] = $lang;
|
||||
}
|
||||
@ -269,6 +259,14 @@
|
||||
}
|
||||
$this->loaded_apps['setup'] = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached languages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $langs;
|
||||
|
||||
/**
|
||||
* returns a list of installed langs
|
||||
*
|
||||
@ -280,15 +278,14 @@
|
||||
if (!is_array($this->langs) || $force_read)
|
||||
{
|
||||
$this->langs = array();
|
||||
$this->db->select($this->lang_table,'DISTINCT lang,lang_name','lang = lang_id',__LINE__,__FILE__,
|
||||
false,'',false,0,','.$this->languages_table);
|
||||
if (!$this->db->num_rows())
|
||||
foreach($this->db->select($this->lang_table,'DISTINCT lang,lang_name','lang = lang_id',__LINE__,__FILE__,
|
||||
false,'',false,0,','.$this->languages_table) as $row)
|
||||
{
|
||||
return False;
|
||||
$this->langs[$row['lang']] = $row['lang_name'];
|
||||
}
|
||||
while ($this->db->next_record())
|
||||
if (!$this->langs)
|
||||
{
|
||||
$this->langs[$this->db->f('lang')] = $this->db->f('lang_name');
|
||||
return false;
|
||||
}
|
||||
foreach($this->langs as $lang => $name)
|
||||
{
|
||||
@ -311,9 +308,7 @@
|
||||
{
|
||||
return $this->langs[$lang];
|
||||
}
|
||||
$this->db->select($this->languages_table,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__);
|
||||
|
||||
return $this->db->next_record() ? $this->db->f('lang_name') : false;
|
||||
return $this->db->select($this->languages_table,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchSingle();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,18 +331,23 @@
|
||||
$availible = "('".implode("','",$availible)."')";
|
||||
|
||||
// this shows first the installed, then the available and then the rest
|
||||
$this->db->select($this->languages_table,array(
|
||||
foreach($this->db->select($this->languages_table,array(
|
||||
'lang_id','lang_name',
|
||||
"CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible",
|
||||
),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name');
|
||||
|
||||
while (($row = $this->db->row(true)))
|
||||
),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row)
|
||||
{
|
||||
$languages[$row['lang_id']] = $row['lang_name'];
|
||||
}
|
||||
return $languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached charsets
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $charsets;
|
||||
|
||||
/**
|
||||
* returns a list of installed charsets
|
||||
*
|
||||
@ -360,22 +360,22 @@
|
||||
$this->get_installed_langs();
|
||||
|
||||
$distinct = $this->db->capabilities['distinct_on_text'] ? 'DISTINCT' : '';
|
||||
$this->db->select($this->lang_table,$distinct.' lang,lang_name,content AS charset',array(
|
||||
$this->charsets = array();
|
||||
foreach($this->db->select($this->lang_table,$distinct.' lang,lang_name,content AS charset',array(
|
||||
'message_id' => 'charset',
|
||||
),__LINE__,__FILE__,false,'',false,0,",$this->languages_table WHERE lang = lang_id");
|
||||
if (!$this->db->num_rows())
|
||||
),__LINE__,__FILE__,false,'',false,0,",$this->languages_table WHERE lang = lang_id") as $row)
|
||||
{
|
||||
return False;
|
||||
}
|
||||
while ($this->db->next_record())
|
||||
{
|
||||
$data = &$this->charsets[$charset = strtolower($this->db->f('charset'))];
|
||||
$lang = $this->langs[$this->db->f('lang')].' ('.$this->db->f('lang').')';
|
||||
$data = &$this->charsets[$charset = strtolower($row['charset'])];
|
||||
$lang = $this->langs[$row['lang']].' ('.$row['lang'].')';
|
||||
if ($distinct || strpos($data,$lang) === false)
|
||||
{
|
||||
$data .= ($data ? ', ' : $charset.': ').$lang;
|
||||
}
|
||||
}
|
||||
if (!$this->charsets)
|
||||
{
|
||||
return False;
|
||||
}
|
||||
// add the old charsets, to provide some alternatives to utf-8 while importing
|
||||
foreach(array(
|
||||
'iso-8859-1' => 'Western european',
|
||||
@ -473,14 +473,16 @@
|
||||
if(function_exists('iconv'))
|
||||
{
|
||||
// iconv can not convert from/to utf7-imap
|
||||
if ($to == 'utf7-imap' && function_exists(imap_utf7_encode)) {
|
||||
if ($to == 'utf7-imap' && function_exists(imap_utf7_encode))
|
||||
{
|
||||
$convertedData = iconv($from, 'iso-8859-1', $data);
|
||||
$convertedData = imap_utf7_encode($convertedData);
|
||||
|
||||
return $convertedData;
|
||||
}
|
||||
|
||||
if ($from == 'utf7-imap' && function_exists(imap_utf7_decode)) {
|
||||
if ($from == 'utf7-imap' && function_exists(imap_utf7_decode))
|
||||
{
|
||||
$convertedData = imap_utf7_decode($data);
|
||||
$convertedData = iconv('iso-8859-1', $to, $convertedData);
|
||||
|
||||
@ -492,11 +494,13 @@
|
||||
// in an email on the first Traditional/Japanese/Korean character,
|
||||
// but in reality when people send mails in GB2312, UMA mostly use
|
||||
// extended GB13000/GB18030 which allow T/Jap/Korean characters.
|
||||
if($from=='EUC-CN') {
|
||||
if($from=='EUC-CN')
|
||||
{
|
||||
$from='gb18030';
|
||||
}
|
||||
|
||||
if (($convertedData = iconv($from,$to,$data))) {
|
||||
if (($convertedData = iconv($from,$to,$data)))
|
||||
{
|
||||
return $convertedData;
|
||||
}
|
||||
}
|
||||
@ -519,13 +523,12 @@
|
||||
//echo "<p>translation_sql::install_langs(".print_r($langs,true).",'$upgrademthod','$only_app')</p>\n";
|
||||
if (!isset($GLOBALS['egw_info']['server']) && $upgrademethod != 'dumpold')
|
||||
{
|
||||
$this->db->select($this->config_table,'config_value',array(
|
||||
if (($ctimes = $this->db->select($this->config_table,'config_value',array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => 'lang_ctimes',
|
||||
),__LINE__,__FILE__);
|
||||
if ($this->db->next_record())
|
||||
),__LINE__,__FILE__)->fetchSingle()))
|
||||
{
|
||||
$GLOBALS['egw_info']['server']['lang_ctimes'] = unserialize(stripslashes($this->db->f('config_value')));
|
||||
$GLOBALS['egw_info']['server']['lang_ctimes'] = unserialize(stripslashes($ctimes));
|
||||
}
|
||||
}
|
||||
|
||||
@ -549,12 +552,9 @@
|
||||
if ($upgrademethod == 'addonlynew')
|
||||
{
|
||||
//echo "<br>Test: addonlynew - select count(*) from egw_lang where lang='".$lang."'";
|
||||
$this->db->select($this->lang_table,'COUNT(*)',array(
|
||||
if (!$this->db->select($this->lang_table,'COUNT(*)',array(
|
||||
'lang' => $lang,
|
||||
),__LINE__,__FILE__);
|
||||
$this->db->next_record();
|
||||
|
||||
if ($this->db->f(0) == 0)
|
||||
),__LINE__,__FILE__)->fetchSingle())
|
||||
{
|
||||
//echo '<br>Test: addonlynew - True';
|
||||
$addlang = True;
|
||||
@ -623,14 +623,14 @@
|
||||
if ($upgrademethod == 'addmissing')
|
||||
{
|
||||
//echo '<br>Test: addmissing';
|
||||
$this->db->select($this->lang_table,"content,CASE WHEN app_name IN ('common') THEN 1 ELSE 0 END AS in_api",array(
|
||||
$rs = $this->db->select($this->lang_table,"content,CASE WHEN app_name IN ('common') THEN 1 ELSE 0 END AS in_api",array(
|
||||
'message_id' => $message_id,
|
||||
'lang' => $lang,
|
||||
$this->db->expression($this->lang_table,'(',array(
|
||||
'app_name' => $app_name
|
||||
)," OR app_name='common') ORDER BY in_api DESC")),__LINE__,__FILE__);
|
||||
|
||||
if (!($row = $this->db->row(True)))
|
||||
if (!($row = $rs->fetch()))
|
||||
{
|
||||
$addit = True;
|
||||
}
|
||||
@ -640,7 +640,7 @@
|
||||
{
|
||||
$addit = $row['content'] != $content; // only add if not identical
|
||||
}
|
||||
$row2 = $this->db->row(True);
|
||||
$row2 = $rs->fetch();
|
||||
if (!$row['in_api'] || $app_name=='common' || $row2) // phrase is alread in the db
|
||||
{
|
||||
$addit = $content != ($row2 ? $row2['content'] : $row['content']);
|
||||
@ -682,8 +682,7 @@
|
||||
|
||||
// update the ctimes of the installed langsfiles for the autoloading of the lang-files
|
||||
//
|
||||
$config = CreateObject('phpgwapi.config');
|
||||
$config->save_value('lang_ctimes',$GLOBALS['egw_info']['server']['lang_ctimes'],'phpgwapi');
|
||||
config::save_value('lang_ctimes',$GLOBALS['egw_info']['server']['lang_ctimes'],'phpgwapi');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -761,11 +760,9 @@
|
||||
{
|
||||
echo '<br>drop_langs(): Working on: ' . $appname;
|
||||
}
|
||||
$this->db->select($this->lang_table,'COUNT(message_id)',array(
|
||||
if ($this->db->select($this->lang_table,'COUNT(*)',array(
|
||||
'app_name' => $appname
|
||||
),__LINE__,__FILE__);
|
||||
|
||||
if($this->db->next_record() && $this->db->f(0))
|
||||
),__LINE__,__FILE__)->fetchSingle())
|
||||
{
|
||||
$this->db->delete($this->lang_table,array(
|
||||
'app_name' => $appname
|
||||
@ -834,13 +831,11 @@
|
||||
*/
|
||||
function read($lang,$app_name,$message_id)
|
||||
{
|
||||
$this->db->select($this->lang_table,'content',array(
|
||||
return $this->db->select($this->lang_table,'content',array(
|
||||
'lang' => $lang,
|
||||
'app_name' => $app_name,
|
||||
'message_id' => $message_id,
|
||||
),__LINE__,__FILE__);
|
||||
|
||||
return $this->db->next_record() ? $this->db->f('content') : false;
|
||||
),__LINE__,__FILE__)->fetchSingle();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -858,8 +853,6 @@
|
||||
if ($app) $where['app_name'] = $app;
|
||||
if ($lang) $where['lang'] = $lang;
|
||||
|
||||
$this->db->select($this->lang_table,'message_id',$where,__LINE__,__FILE__);
|
||||
|
||||
return $this->db->next_record() ? $this->db->f(0) : false;
|
||||
return $this->db->select($this->lang_table,'message_id',$where,__LINE__,__FILE__)->fetchSingle();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user