diff options
author | Urban Müller | 2008-05-06 14:03:57 +0000 |
---|---|---|
committer | Urban Müller | 2008-05-06 14:03:57 +0000 |
commit | 6df42208f46913a65e3b4e099d678407b4f77bca (patch) | |
tree | 8b3a0216f103ce2f1745de266d7807add45487a0 /it_text.class | |
parent | aaa330cc11e7eb161b913ff62476a9f4d51c1e27 (diff) | |
download | itools-6df42208f46913a65e3b4e099d678407b4f77bca.tar.gz itools-6df42208f46913a65e3b4e099d678407b4f77bca.tar.bz2 itools-6df42208f46913a65e3b4e099d678407b4f77bca.zip |
added search_text_db
Diffstat (limited to 'it_text.class')
-rw-r--r-- | it_text.class | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/it_text.class b/it_text.class index 901f51a..e8e2c57 100644 --- a/it_text.class +++ b/it_text.class @@ -31,8 +31,6 @@ class it_text * Constructor * Loads all texts.php in include path for translated labels. Singleton; if instanciated mutiple times, texts are merged * Example texts.php: <?php return array('_' => array('en'=>"English", 'de'=>"Deutsch"), 'edit'=>array('en'=>"Edit", 'de'=>("Editieren"))); - * @param $p['cookiename'] optional cookie name (default: 'LANGUAGE') - * @param $p['debug'] optional debug mode: display label of unknown texts, set to 'label' to always display labels instead of actual text * @param $p['fallbacklanguage'] optional language to use for undefined texts (useful for partially translated projects) * @param $p['forcelanguage'] optional language to use instead of user's preferred language * @param $p['global'] store text object in global it_text for global functions (default: true) @@ -40,34 +38,31 @@ class it_text */ function it_text($p = array()) { - $this->p = $p + array('cookiename' => 'LANGUAGE', 'debug' => (EDC('label') ? "label" : ""), 'global' => true); - - $phpfiles = array(); - if ($p['phpfile']) - $phpfiles = (array)$p['phpfile']; - else + if (!$p['phpfile']) { # Find texts.php in path (abs path in case we need to save) foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $dir) if (file_exists($phpfile = "$dir/texts.php")) - $phpfiles[] = $phpfile; + $p['phpfile'][] = $phpfile; } + $this->p = ($p += array('global' => true)); + # Read and merge texts from php files if none defined yet - foreach ($phpfiles as $phpfile) + foreach ((array)$p['phpfile'] as $phpfile) { - $oldtexts = $this->statictexts; + $oldtext = $this->statictext; if (is_array($ret = @include($phpfile))) $this->statictext += $ret; else - $this->statictext = $oldtexts + $this->statictext; # FIXME: compatibility mode + $this->statictext = $oldtext + $this->statictext; # FIXME: compatibility mode } # Get array of supported languages and their names $this->languages_available = (array)$this->statictext['_']; foreach($this->languages_available as $code => $languagename) { - # Only use a language in browser/cookie detection below if it's not disabled by a leading '-' + # Only use a language in browser detection below if it's not disabled by a leading '-' if (substr($languagename, 0, 1) != '-') { $this->languages[$code] = $languagename; @@ -86,11 +81,11 @@ function it_text($p = array()) $this->defaultlanguage = $this->actlanguage; $this->initlang(it::match('\.([a-z]{2})\.[^./]+$', $_SERVER['PHP_SELF']), "setting language from url override"); - $this->initlang($this->languages[$_COOKIE[$this->p['cookiename']]], "setting language from cookie"); - $this->initlang($this->p['forcelanguage'], "setting language from programmer override"); + $this->initlang($p['forcelanguage'], "setting language from programmer override"); # Make this object available under $GLOBALS['it_text'], or add my texts to $GLOBALS['it_text'] if it exists - if ($this->p['global']) { + if ($p['global']) + { if (!$GLOBALS['it_text']) $GLOBALS['it_text'] =& $this; else @@ -100,7 +95,7 @@ function it_text($p = array()) # internal: overwrite language setting if code is valid, return success -function initlang($code, $debugmsg) +function initlang($code) { if ($this->languages[$code]) $this->actlanguage = $code; @@ -125,24 +120,24 @@ function init() */ function text($label, $language = null) { - if ($this->p['debug'] === 'label') - return $label; - - if (!isset($language)) + if (!$language) $language = $this->actlanguage; - if (isset($this->statictext[$label][$language])) - return $this->statictext[$label][$language]; - elseif ($this->p['fallbacklanguage'] && isset($this->statictext[$label][$this->p['fallbacklanguage']])) - return $this->statictext[$label][$this->p['fallbacklanguage']]; - - if ($fh = fopen($GLOBALS['ULTRAHOME'] . "/log/text_log", "a")) + $text = $this->statictext[$label][$language]; + if (!$text && !$this->text_exists($label, $language)) { - fputs($fh, date("Y-m-d H:i:s") . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $label . "\t" . $language . "\t" . it::replace(array('auto_prepend\S+\s+'=>''), it_debug::backtrace()) . "\n"); - fclose($fh); + $text = $this->statictext[$label][$this->p['fallbacklanguage']]; + if (!$text && !$this->text_exists($label, $this->p['fallbacklanguage'])) + { + $text = "<span style='background:#F88' title='$label (" . it_debug::backtrace(array('levels'=>1, 'skipfiles'=>"text|auto_prepend")) . ")'>$label</span'>"; + it::error(array('title'=>"unknown label $label language $language - see /tmp/alertdata/alert.log", 'backtraceskip'=>2, 'blockmail'=>21600)); + } } - return $this->p['debug'] ? "<blink>$label ($language)</blink>" : ''; + if ($GLOBALS['debug_texts'] && !eregi('submit|reset|button|_search$|service|claim', $label)) + $text = "<span style='background:#8F8' title='$label (" . it_debug::backtrace(array('levels'=>1, 'skipfiles'=>"text|auto_prepend")) . ")'>$text</span'>"; + + return $text; } |