File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.language.php
<?php
/**
* This file contains the iwp_language class
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_API
*/
/**
* IWP Language Class
* This is the language class that handles the loading of language variables for use in output
*
* @package IWP
* @subpackage IWP_API
*/
class iwp_language {
/**
* Instance
* This static variable holds the current instance of this object being loaded.
* So using the getInstance function anywhere will return the very same instance.
*
* @var iwp_language Instance
*/
public static $Instance;
/**
* getInstance
* This is a static function that sets up the class instance and stores it to the static variable. It will then return that instantiation in the future.
*
* @return iwp_language Returns the instantiated object
**/
public static function getInstance(){
if(!isset(self::$Instance)){
self::$Instance = new self();
}
return self::$Instance;
}
/**
* The array of language variables
*
* @var array
*/
private $LangVars = array();
/**
* A flag which is set to true when LoadMod is called. Used by Get to determine whether or not to fall back to the base language files when looking up a language var while acting as a module's language class.
*
* @var boolean
*/
private $isModule = false;
/**
* This method is will return the first existing language variable out of the provided array of language variable names. Essentially, it calls Get() until a valid variable is found.
*
* @param array $varlist An array of language variables to check. Preference will be given to the first items in the array.
*/
public function GetMulti ($varlist) {
foreach ($varlist as $var) {
if ($value = $this->Get($var, true)) {
return $value;
}
}
return '';
}
/**
* This method retrieves a specified language variable if it exists
*
* @param string $var The name/key of the language variable to get
*
* @return string The value of the language variable in whatever language it is
*
* @see $LangVars
*/
public function Get($var, $returnBlankWhenNotExists = false){
if(isset($this->LangVars[$var])){
if(!empty(IWP::$WhiteLabel['ApplicationName'])){
$appname = IWP::$WhiteLabel['ApplicationName'];
$appnamefull = IWP::$WhiteLabel['ApplicationNameWithVersion'];
}else{
$appname = 'Content Manager';
$appnamefull = 'Content Manager 5.0';
}
if(isset(IWP::$WhiteLabel['IWP_4_5']) && IWP::$WhiteLabel['IWP_4_5']) {
$prevAppName = IWP::$WhiteLabel['IWP_4_5'];
}else{
$prevAppName = 'Content Manager 4.5';
}
if(isset(IWP::$WhiteLabel['IWP_4_5_abbr']) && IWP::$WhiteLabel['IWP_4_5_abbr']) {
$prevAppNameAbbr = IWP::$WhiteLabel['IWP_4_5_abbr'];
}else{
$prevAppNameAbbr = 'IWP 4.5';
}
$str = str_replace('{appname}', $appname, $this->LangVars[$var]);
$str = str_replace('{appnamefull}', $appnamefull, $str);
$str = str_replace('{prevappname}', $prevAppName, $str);
$str = str_replace('{prevappnameabbr}', $prevAppNameAbbr, $str);
return $str;
}else{
if(IWP::$DebugMode){
$lang_line = $var .' = ""';
if(!file_exists(IWP_TMP_PATH .'/missing_lang.txt')){
@touch(IWP_TMP_PATH .'/missing_lang.txt');
}
$file = @file_get_contents(IWP_TMP_PATH .'/missing_lang.txt');
if(!is_array($file) || strpos($file, $lang_line) === false){
$mode = 'simple';
if($mode == 'advanced'){
$bt = debug_backtrace();
$str = '';
foreach($bt as $k=>$ray){
foreach($ray as $k2=>$pair){
$str .= $k2. ': '. $pair."\n";
}
$str .= "----\n";
}
@file_put_contents(IWP_TMP_PATH .'/missing_lang.txt', $lang_line."\n".$str."\n-----------\n\n", FILE_APPEND);
}else{
@file_put_contents(IWP_TMP_PATH .'/missing_lang.txt', $lang_line."\n", FILE_APPEND);
}
}
}
if ($returnBlankWhenNotExists) {
return '';
} else {
if ($this->isModule) {
// this language instance was populated using LoadMod, check the base language entries for the var and return that if it wasn't found in the module's language entries
return GetLang($var, 0, $returnBlankWhenNotExists);
}
return '[Invalid Language Variable: '.$var.']';
}
}
return '';
}
/**
* This method retrieves a specified language HTML file and returns it
*
* @param string $var The name of the language HTML file to retrieve
*
* @return string The content of the HTML file
*/
public function GetHtml($htmlFileName){
$locale = self::GetLocale();
$localePath = IWP_BASE_PATH . '/language/' . $locale;
$htmlFileName = iwp_validation::FilterFilename($htmlFileName);
if(!file_exists($localePath . '/' . $htmlFileName . '.html')){
return false;
}
return @file_get_contents($localePath . '/' . $htmlFileName . '.html');
}
/**
* This sets the value of a specified language variable
*
* @param string $var The name/key of the language variable to set
* @param string $val The value of the language variable to set
*
* @return void
*
* @see $LangVars
*/
public function Set($var, $val){
$this->LangVars[$var] = $val;
}
public function GetLocale(){
// build a list of locales to mash up
$locale = iwp_validation::FilterFilename(iwp_config::Get('BaseLocaleCode'));
if ($locale) {
return $locale;
}
$locale = iwp_validation::FilterFilename(iwp_config::Get('LocaleCode'));
if ($locale) {
return $locale;
}
return IWP_LOCALE_DEFAULT;
}
/**
* Takes a filename of the ini file in the language folder and loads it into the LangVars array
*
* @param string $filename The filename to use for the ini file. This must be the name not including the path or extension.
*
* @return void
*
* @see $LangVars
*/
public function Load($filename, $append=false){
$locales = array();
// build a list of locales to mash up
$locale = iwp_validation::FilterFilename(iwp_config::Get('BaseLocaleCode'));
if ($locale) {
array_push($locales, $locale);
}
$locale = iwp_validation::FilterFilename(iwp_config::Get('LocaleCode'));
if ($locale && !in_array($locale, $locales)) {
array_push($locales, $locale);
}
if($append){
$langVars = $this->LangVars;
}else{
$langVars = array();
}
if(sizeof($locales) < 1){
$locales[] = IWP_LOCALE_DEFAULT;
}
// load each locale
$filename = iwp_validation::FilterFilename($filename);
foreach ($locales as $locale) {
$localePath = IWP_BASE_PATH . '/language/' . $locale;
if (file_exists($localePath) && is_dir($localePath)) {
$localeFile = IWP_BASE_PATH . '/language/' . $locale . '/common.ini';
if (file_exists($localeFile)) {
// merge loaded vars...
if (count($langVars)) {
// ...if necessary
$langVars = array_merge($langVars, parse_ini_file($localeFile));
}
else {
// ...otherwise just replace the variable
$langVars = parse_ini_file($localeFile);
}
}
$localeFile = IWP_BASE_PATH . '/language/' . $locale . '/' . $filename . '.ini';
if (file_exists($localeFile)) {
// merge loaded vars...
if (count($langVars)) {
// ...if necessary
$langVars = array_merge($langVars, parse_ini_file($localeFile));
}
else {
// ...otherwise just replace the variable
$langVars = parse_ini_file($localeFile);
}
}
}
}
// set merged lang vars
$this->LangVars = $langVars;
}
/**
* Loads a language file for a specified module.
*
* @param string $modulename The name of the module to load the lnaguage file for
*
* @return void
*
* @see $LangVars
*/
public function LoadMod($modulename){
if(file_exists(IWP_MODULES_PATH. '/'.$modulename.'/language.ini')){
$this->LangVars = parse_ini_file(IWP_MODULES_PATH. '/' .$modulename.'/language.ini');
$this->isModule = true;
}
}
/**
* Checks to see if a specified language variable exists
*
* @param string $name The name of the language variable to check
*
* @return boolean True if it exists false if it doesn't
*/
public function Exists($name){
return isset($this->LangVars[$name]);
}
/**
* This function returns the array of language variables
*
* @return array The list of language variables as an array
*/
public function GetLangVars(){
return $this->LangVars;
}
}