- phpgw --> egw

- fixed a problem php5 complained about, which is present in php4 too: arrays in $GLOBALS[egw][server] are NOT unserialized. As this seems to be only used for the lang_ctimes, I just took care of it here
This commit is contained in:
Ralf Becker 2005-05-31 13:52:14 +00:00
parent a3fb79a6a4
commit fd5576e3ee
2 changed files with 118 additions and 103 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
if (empty($GLOBALS['phpgw_info']['server']['translation_system'])) if (empty($GLOBALS['egw_info']['server']['translation_system']))
{ {
$GLOBALS['phpgw_info']['server']['translation_system'] = 'sql'; $GLOBALS['egw_info']['server']['translation_system'] = 'sql';
} }
include(PHPGW_API_INC.'/class.translation_' . $GLOBALS['phpgw_info']['server']['translation_system'].'.inc.php'); include(EGW_API_INC.'/class.translation_' . $GLOBALS['egw_info']['server']['translation_system'].'.inc.php');
?> ?>

View File

@ -46,6 +46,9 @@
var $loaded_apps = array(); var $loaded_apps = array();
var $line_rejected = array(); var $line_rejected = array();
/**
* Constructor, sets up a copy of the db-object, gets the system-charset and tries to load the mbstring extension
*/
function translation($warnings = False) function translation($warnings = False)
{ {
for ($i = 1; $i <= 9; $i++) for ($i = 1; $i <= 9; $i++)
@ -97,9 +100,11 @@
} }
} }
/* /**
@function charset * returns the charset to use (!$lang) or the charset of the lang-files or $lang
@abstract returns the charset to use (!$lang) or the charset of the lang-files or $lang *
* @param string/boolean $lang=False return charset of the active user-lang, or $lang if specified
* @return string charset
*/ */
function charset($lang=False) function charset($lang=False)
{ {
@ -134,6 +139,9 @@
return $charset; return $charset;
} }
/**
* Initialises global lang-array and loads the 'common' and app-spec. translations
*/
function init() function init()
{ {
// post-nuke and php-nuke are using $GLOBALS['lang'] too // post-nuke and php-nuke are using $GLOBALS['lang'] too
@ -157,10 +165,13 @@
$this->add_app($GLOBALS['egw_info']['flags']['currentapp']); $this->add_app($GLOBALS['egw_info']['flags']['currentapp']);
} }
/*! /**
@function translate * translates a phrase and evtl. substitute some variables
@abstract translates a phrase and evtl. substitute some variables *
@returns the translation * @param string $key phrase to translate, may contain placeholders %N (N=1,2,...) for vars
* @param array/boolean $vars=false vars to replace the placeholders, or false for none
* @param string $not_found='*' what to add to not found phrases, default '*'
* @return string with translation
*/ */
function translate($key, $vars=false, $not_found='*' ) function translate($key, $vars=false, $not_found='*' )
{ {
@ -198,12 +209,11 @@
return $ret; return $ret;
} }
/*! /**
@function add_app * adds translations for an application from the database to the lang-array
@abstract adds translations for an application from the database to the lang-array *
@syntax add_app($app,$lang=False) * @param string $app name of the application to add (or 'common' for the general translations)
@param $app name of the application to add (or 'common' for the general translations) * @param string/boolean $lang=false 2 or 5 char lang-code or false for the users language
@param $lang 2-char code of the language to use or False if the users language should be used
*/ */
function add_app($app,$lang=False) function add_app($app,$lang=False)
{ {
@ -227,13 +237,15 @@
/** /**
* Adds setup's translations, they are not in the DB! * Adds setup's translations, they are not in the DB!
*
* @param string $lang 2 or 5 char lang-code
*/ */
function add_setup($lang) function add_setup($lang)
{ {
$fn = PHPGW_SERVER_ROOT.'/setup/lang/phpgw_' . $lang . '.lang'; $fn = EGW_SERVER_ROOT.'/setup/lang/phpgw_' . $lang . '.lang';
if (!file_exists($fn)) if (!file_exists($fn))
{ {
$fn = PHPGW_SERVER_ROOT.'/setup/lang/phpgw_en.lang'; $fn = EGW_SERVER_ROOT.'/setup/lang/phpgw_en.lang';
} }
if (file_exists($fn)) if (file_exists($fn))
{ {
@ -253,10 +265,10 @@
} }
$this->loaded_apps['setup'] = $lang; $this->loaded_apps['setup'] = $lang;
} }
/*! /**
@function get_installed_langs * returns a list of installed langs
@abstract returns a list of installed langs *
@returns array with 2-character lang-code as key and descriptiv lang-name as data * @return array with lang-code => descriptiv lang-name pairs
*/ */
function get_installed_langs() function get_installed_langs()
{ {
@ -279,22 +291,17 @@
return $this->langs; return $this->langs;
} }
/*! /**
@function get_installed_charsets * returns a list of installed charsets
@abstract returns a list of installed charsets *
@returns array with charset as key and comma-separated list of langs useing the charset as data * @return array with charset as key and comma-separated list of langs useing the charset as data
*/ */
function get_installed_charsets() function get_installed_charsets()
{ {
if (!is_array($this->charsets)) if (!is_array($this->charsets))
{ {
$distinct = 'DISTINCT'; $distinct = $this->db->capabilities['distinct_on_text'] ? 'DISTINCT' : '';
switch($this->db->Type)
{
case 'sapdb': case 'maxdb':
case 'mssql':
$distinct = ''; // cant use distinct on text columns (l.content is text)
}
$this->db->query("SELECT $distinct l.lang,lx.lang_name,l.content AS charset FROM phpgw_lang l,phpgw_languages lx WHERE l.lang = lx.lang_id AND l.message_id='charset'",__LINE__,__FILE__); $this->db->query("SELECT $distinct l.lang,lx.lang_name,l.content AS charset FROM phpgw_lang l,phpgw_languages lx WHERE l.lang = lx.lang_id AND l.message_id='charset'",__LINE__,__FILE__);
if (!$this->db->num_rows()) if (!$this->db->num_rows())
{ {
@ -313,14 +320,13 @@
return $this->charsets; return $this->charsets;
} }
/*! /**
@function convert * converts a string $data from charset $from to charset $to
@abstract converts a string $data from charset $from to charset $to *
@syntax convert($data,$from=False,$to=False) * @param string/array $data string(s) to convert
@param $data string or array of strings to convert * @param string/boolean $from charset $data is in or False if it should be detected
@param $from charset $data is in or False if it should be detected * @param string/boolean $to charset to convert to or False for the system-charset the converted string
@param $to charset to convert to or False for the system-charset * @return string/array converted string(s) from $data
@returns the converted string
*/ */
function convert($data,$from=False,$to=False) function convert($data,$from=False,$to=False)
{ {
@ -405,12 +411,12 @@
return $data; return $data;
} }
/*! /**
@function install_langs * installs translations for the selected langs into the database
@abstract installs translations for the selected langs into the database *
@syntax install_langs($langs,$upgrademethod='dumpold') * @param array $langs langs to install (as data NOT keys (!))
@param $langs array of langs to install (as data NOT keys (!)) * @param string $upgrademethod='dumpold' 'dumpold' (recommended & fastest), 'addonlynew' languages, 'addmissing' phrases
@param $upgrademethod 'dumpold' (recommended & fastest), 'addonlynew' languages, 'addmissing' phrases * @param string/boolean $only_app=false app-name to install only one app or default false for all
*/ */
function install_langs($langs,$upgrademethod='dumpold',$only_app=False) function install_langs($langs,$upgrademethod='dumpold',$only_app=False)
{ {
@ -464,8 +470,8 @@
//echo '<br>Test: loop above file()'; //echo '<br>Test: loop above file()';
if (!is_object($GLOBALS['egw_setup'])) if (!is_object($GLOBALS['egw_setup']))
{ {
$GLOBALS['egw_setup'] = CreateObject('setup.setup'); $GLOBALS['egw_setup'] =& CreateObject('setup.setup');
$GLOBALS['egw_setup']->db = $this->db; $GLOBALS['egw_setup']->db = clone($this->db);
} }
$setup_info = $GLOBALS['egw_setup']->detection->get_versions(); $setup_info = $GLOBALS['egw_setup']->detection->get_versions();
$setup_info = $GLOBALS['egw_setup']->detection->get_db_versions($setup_info); $setup_info = $GLOBALS['egw_setup']->detection->get_db_versions($setup_info);
@ -474,7 +480,7 @@
// Visit each app/setup dir, look for a phpgw_lang file // Visit each app/setup dir, look for a phpgw_lang file
foreach($apps as $app) foreach($apps as $app)
{ {
$appfile = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang'; $appfile = EGW_SERVER_ROOT . SEP . $app . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang';
//echo '<br>Checking in: ' . $app; //echo '<br>Checking in: ' . $app;
if($GLOBALS['egw_setup']->app_registered($app) && file_exists($appfile)) if($GLOBALS['egw_setup']->app_registered($app) && file_exists($appfile))
{ {
@ -498,6 +504,10 @@
$app_name = chop($app_name); $app_name = chop($app_name);
$raw[$app_name][$message_id] = $content; $raw[$app_name][$message_id] = $content;
} }
if ($GLOBALS['egw_info']['server']['lang_ctimes'] && !is_array($GLOBALS['egw_info']['server']['lang_ctimes']))
{
$GLOBALS['egw_info']['server']['lang_ctimes'] = unserialize($GLOBALS['egw_info']['server']['lang_ctimes']);
}
$GLOBALS['egw_info']['server']['lang_ctimes'][$lang][$app] = filectime($appfile); $GLOBALS['egw_info']['server']['lang_ctimes'][$lang][$app] = filectime($appfile);
} }
} }
@ -580,9 +590,8 @@
$config->save_value('lang_ctimes',$GLOBALS['egw_info']['server']['lang_ctimes'],'phpgwapi'); $config->save_value('lang_ctimes',$GLOBALS['egw_info']['server']['lang_ctimes'],'phpgwapi');
} }
/*! /**
@function autolaod_changed_langfiles * re-loads all (!) langfiles if one langfile for the an app and the language of the user has changed
@abstract re-loads all (!) langfiles if one langfile for the an app and the language of the user has changed
*/ */
function autoload_changed_langfiles() function autoload_changed_langfiles()
{ {
@ -598,7 +607,7 @@
$apps['phpgwapi'] = True; // check the api too $apps['phpgwapi'] = True; // check the api too
foreach($apps as $app => $data) foreach($apps as $app => $data)
{ {
$fname = PHPGW_SERVER_ROOT . "/$app/setup/phpgw_$lang.lang"; $fname = EGW_SERVER_ROOT . "/$app/setup/phpgw_$lang.lang";
if (file_exists($fname)) if (file_exists($fname))
{ {
@ -623,9 +632,11 @@
/* Following functions are called for app (un)install */ /* Following functions are called for app (un)install */
/*! /**
@function get_langs * gets array of installed languages, e.g. array('de','en')
@abstract return array of installed languages, e.g. array('de','en') *
* @param boolean $DEBUG=false debug messages or not, default not
* @return array with installed langs
*/ */
function get_langs($DEBUG=False) function get_langs($DEBUG=False)
{ {
@ -640,10 +651,12 @@
return $this->langs ? array_keys($this->langs) : array(); return $this->langs ? array_keys($this->langs) : array();
} }
/*! /**
@function drop_langs * delete all lang entries for an application, return True if langs were found
@abstract delete all lang entries for an application, return True if langs were found *
@param $appname app_name whose translations you want to delete * @param $appname app_name whose translations you want to delete
* @param boolean $DEBUG=false debug messages or not, default not
* @return boolean true if $appname had translations installed, false otherwise
*/ */
function drop_langs($appname,$DEBUG=False) function drop_langs($appname,$DEBUG=False)
{ {
@ -654,8 +667,8 @@
$this->db->select($this->lang_table,'COUNT(message_id)',array( $this->db->select($this->lang_table,'COUNT(message_id)',array(
'app_name' => $appname 'app_name' => $appname
),__LINE__,__FILE__); ),__LINE__,__FILE__);
$this->db->next_record();
if($this->db->f(0)) if($this->db->next_record() && $this->db->f(0))
{ {
$this->db->delete($this->lang_table,array( $this->db->delete($this->lang_table,array(
'app_name' => $appname 'app_name' => $appname
@ -665,10 +678,12 @@
return False; return False;
} }
/*! /**
@function add_langs * process an application's lang files, calling get_langs() to see what langs the admin installed already
@abstract process an application's lang files, calling get_langs() to see what langs the admin installed already *
@param $appname app_name of application to process * @param string $appname app_name of application to process
* @param boolean $DEBUG=false debug messages or not, default not
* @param array/boolean $force_langs=false array with langs to install anyway (beside the allready installed ones), or false for none
*/ */
function add_langs($appname,$DEBUG=False,$force_langs=False) function add_langs($appname,$DEBUG=False,$force_langs=False)
{ {