texts = array(
* // Module level
* 'haus' => array(
* // Language level
* 'default' => array(
* // File level
* 'main' => array(
* // Content level
* 'nav_build' => 'Bauamt',
*
* 'nav_cat_entrance' => 'Wohnviertel',
* ) // Content end
* ) // File end
* ) // Language end
* ) // Module end
*
* @var array
*/
var $texts;
/**
* Settings für aktuelle Zugriffe auf die Textdaten
* @example $this->current = array(
* 'basedir' => 'texts/',
* 'module' => 'haus/',
* 'language' => 'default',
* 'file' => 'main',
* )
* @var array
*/
var $current;
// CONSTRUCTOR
function sysTxt($startfile,$language=false,$module=false,$basedir=false){
$this->buildCurrentArray($startfile,$language,$module,$basedir);
$this->loadModule();
$this->loadLanguage();
$this->loadFile($startfile);
}
// GRAB-METHODS
/**
* true => default
* false => dont use
*
* @param mixed $text
* @param mixed $file
* @param mixed $language
* @param mixed $module
* @return mixed
*/
function fullGrab($text=false,$file=true,$language=true,$module=true){
if ($module === true) $module = $this->current['module'];
if ($language === true) $language = $this->current['language'];
if ($file === true) $file = $this->current['file'];
if (!$module) {
return $this->texts;
} elseif (!$language && !empty($this->texts[$module])) {
return $this->texts[$module];
} elseif (!$file && !empty($this->texts[$module]) && !empty($this->texts[$module][$language])) {
return $this->texts[$module][$language];
} elseif(!$text && !empty($this->texts[$module]) && !empty($this->texts[$module][$language]) && !empty($this->texts[$module][$language][$file])) {
return $this->texts[$module][$language][$file];
} elseif (!empty($this->texts[$module]) && !empty($this->texts[$module][$language]) && !empty($this->texts[$module][$language][$file]) && !empty($this->texts[$module][$language][$file][$text])) {
return $this->texts[$module][$language][$file][$text];
} else {
return false;
}
}
/**
* false => default!
*
* @param unknown_type $text
* @param unknown_type $file
* @param unknown_type $language
* @param unknown_type $module
* @return unknown
*/
function quickGrab($text,$file=false,$language=false,$module=false) {
if (!$module) $module = $this->current['module'];
if (!$language) $language = $this->current['language'];
if (!$file) $file = $this->current['file'];
return $this->texts[$module][$language][$file][$text];
}
// BUILD-METHODS
function buildCurrentPart($partname,$actval,$defval){
$ret = '';
if ($actval === false && empty($this->current[$partname])) $ret = $defval;
elseif(!empty($this->current[$partname])) $ret = $this->current[$partname];
else $ret = $actval;
return $ret;
}
function buildCurrentArray($file,$language,$module,$basedir){
$this->current = array(
'basedir' => $this->buildCurrentPart('basedir', $basedir, SYSTXT_DEF_DIR),
'module' => $this->buildCurrentPart('module', $module, SYSTXT_DEF_MODULE),
'language' => $this->buildCurrentPart('language', $language,SYSTXT_DEF_LANG),
'file' => $file,
);
}
function buildFileStrPart($partname,$ending='/'){
return $this->current[$partname] . (substr($this->current[$partname],-1*strlen($ending)) == $ending ? '' : $ending);
}
function buildFileStr($file=true,$language=true,$module=true,$basedir=true){
$str = "";
if ($basedir) $str .= $this->buildFileStrPart('basedir');
if ($module) $str .= $this->buildFileStrPart('module');
if ($language) $str .= $this->buildFileStrPart('language');
if ($file) $str .= $this->buildFileStrPart('file','.php');
return $str;
}
// LOAD-METHODS
function loadModule($module=false){
if (!empty($module)) $this->current['module'] = $module;
if (!file_exists($this->buildFilestr(false,false)))
die("Moduldirectory ".$this->buildFileStr(false,false)." not found!
".print_r($this->current,true));
if (!isset($this->texts[$this->current['module']]))
$this->texts[$this->current['module']] = array();
}
function loadLanguage($language=false){
if (!empty($language)) $this->current['language'] = $language;
if (!file_exists($this->buildFilestr(false)))
die("Languagedirectory ".$this->buildFilestr(false)." not found!
".print_r($this->current,true));
if (!isset($this->texts[$this->current['module']][$this->current['language']]))
$this->texts[$this->current['module']][$this->current['language']] = array();
}
function loadFile($file,$setdef=true){
if (!$setdef) $bakfile = $this->current['file'];
$this->current['file'] = $file;
$str = $this->buildFilestr();
if (!file_exists($str))
die("Textfile ".$str." not found!
".print_r($this->current,true));
require_once $str;
$varstr = 'text_' . $this->current['file'];
$this->texts[$this->current['module']][$this->current['language']][$this->current['file']] = $$varstr;
if(!$setdef) $this->current['file'] = $bakfile;
}
// HAS-METHODS
function hasText($text) {
$g = $this->fullGrab($text);
return !empty($g);
}
function hasFile($file){
$g = $this->fullGrab(false,$file);
return !empty($g);
}
function hasLanguage($language){
$g = $this->fullGrab(false,false,$language);
return !empty($g);
}
function hasModule($module){
$g = $this->fullGrab(false,false,false,$module);
return !empty($g);
}
// GET-METHODS
function get($text,$file=false){
if (!empty($file) && !$this->hasFile($file)) {
$this->loadFile($file,false);
}
$ret = $this->quickGrab($text,$file);
if (empty($ret)) echo "Konnte '$text' in '".($file?$file:$this->current['file'])."' nicht finden!
";
return $ret;
}
function getReplaced($text,$sea,$rep,$file=false) {
$base = $this->get($text,$file);
return str_replace($sea,$rep,$base);
}
function getFormated($text,$params,$file=false){
$base = $this->get($text,$file);
return vsprintf($base,$params);
}
// SET-METHODS
function set($field, $value) {
return $this->buildCurrentPart($field,$value,$this->current[$field]);
}
// RESTORE-METHODS
function save($field){
$this->current[SYSTXT_SAVE_TAG.$field] = $this->current[$field];
}
function restore($field){
if(!empty($this->current[$field])) {
$this->current[$field] = $this->current[SYSTXT_SAVE_TAG.$field];
return true;
} else {
return false;
}
}
// EXISTS-METHODS
function exsitsFile($filename) {
$str = $this->buildFileStr($filename);
return file_exists($str);
}
// SINGLETON-HANDLING
/**
* Returns an instance of the sysTxt-Class
*
* @param mixed $startfile
* @param mixed $language
* @param mixed $module
* @param mixed $basedir
* @return sysTxt
*/
function &instance($startfile=false,$language=false,$module=false,$basedir=false){
static $instance;
if (!is_object($instance)) $instance = new sysTxt($startfile,$language,$module,$basedir);
return $instance;
}
}
?>