diff --git a/info.textgrid.middleware.tgauth.webauth/WebAuthN/TextGrid-WebAuth.php b/info.textgrid.middleware.tgauth.webauth/WebAuthN/TextGrid-WebAuth.php index 7cd485c3cd8b6827c25b0ad6e6717bf0d21d571a..82f5b8c2ec32377da4627fa12a1dcdb6f3de340d 100644 --- a/info.textgrid.middleware.tgauth.webauth/WebAuthN/TextGrid-WebAuth.php +++ b/info.textgrid.middleware.tgauth.webauth/WebAuthN/TextGrid-WebAuth.php @@ -17,8 +17,8 @@ $util = new WebUtils; $authZinstance = $_REQUEST["authZinstance"]; if ( !(isset($authZinstance)) || strlen($authZinstance) <= 0 ) { - $util->printAuthFailure("No TgAuth Instance provided", - "Please provide a valid string in the authZinstance variable.", + $util->printAuthFailure("no_tgauth_instance_heading", + "no_tgauth_instance_detail", null, null ); exit; @@ -33,7 +33,7 @@ if (isset ($_REQUEST["loginname"]) && strlen($_REQUEST["loginname"]) > 0 $ldap = new LDAP ( $configfile ); $AuthNResult = $ldap->authenticate($_REQUEST["loginname"], $_REQUEST["password"]); if (! $AuthNResult["success"]) { - $util->printAuthFailure("Failure authenticating at TextGrid Community Account Server", + $util->printAuthFailure("authn_failure_heading", $AuthNResult["detail"], $_REQUEST["loginname"], null ); @@ -58,7 +58,7 @@ if (isset ($_SERVER["REMOTE_USER"])) { // this holds for both shib and ldap auth } if (!$CSResult["success"]) { - $util->printAuthFailure("Failure Creating Session in RBAC", + $util->printAuthFailure("sid_create_failure_heading", $CSResult["detail"], $_REQUEST["loginname"], $CSResult["rbachash"] @@ -93,37 +93,43 @@ else if (isset ($_REQUEST["Sid"]) && strlen($_REQUEST["Sid"]) > 0 ) { // check if we came via Shibboleth, but without an eduPersonPrincipalName // (which would have been the REMOTE_USER) if (isset( $_SERVER['Shib-Session-ID'] )) { - $util->printAuthFailure("Shibboleth Login via DFN-AAI failed", - "No identifier provided. TextGrid needs the attribute <b>eduPersonPrincipalName</b> to identify you, but your organisation did not provide it. Please inquire with your organisation's computing centre to release this attribute to TextGrid. See <a href=\"http://www.textgrid.de/1-0/registrierung.html\">http://www.textgrid.de/1-0/registrierung.html</a>.", + $util->printAuthFailure("shib_login_failure_heading", + "shib_login_failure_detail", "(Shibboleth login, but no ePPN provided)", null ); exit; } else { - $missing = ""; + $missing = 0; if (!isset($_REQUEST["loginname"]) || strlen($_REQUEST["loginname"]) == 0) { - $missing = "login ID"; + $missing = 1; } if (!isset($_REQUEST["password"]) || strlen($_REQUEST["password"]) == 0) { - if (strlen ($missing) == 0) { - $missing = "password"; - } else { - $missing = $missing . " and password"; - } + $missing = $missing + 2; } - if (strlen ($missing) > 0) { - $util->printAuthFailure("Failure authenticating at TextGrid Community Account Server", - "Could not authenticate, no $missing provided. In case you forgot your password, please use the button below.", - isset ($_REQUEST["loginname"]) ? $_REQUEST["loginname"] : "(null)", - null ); - } else { - $util->printAuthFailure("Failure authenticating at TextGrid Community Account Server", - "WebAuth does not know what to do (no login or password provided, no remote user, and no session Id). In case you forgot your password, please use the button below.", + if ($missing == 0) { + $util->printAuthFailure("authn_failure_heading", + "authn_failure_detail_nothing_to_do", $_REQUEST["loginname"], null ); trigger_error("WebAuth does not know what to do (no login or password provided, no remote user, and no session Id), exiting.", E_USER_WARNING); + } else if ($missing == 1) { + $util->printAuthFailure("authn_failure_heading", + "authn_failure_detail_id_missing", + '(null)', + null ); + } else if ($missing == 2) { + $util->printAuthFailure("authn_failure_heading", + "authn_failure_detail_password_missing", + $_REQUEST["loginname"], + null ); + } else if ($missing == 3) { + $util->printAuthFailure("authn_failure_heading", + "authn_failure_detail_both_missing", + '(null)', + null ); } exit; } @@ -136,7 +142,7 @@ $attributes = $rbac->getUserAttributes( $Sid ); // them if there came different ones, and then finally print welcome screen causing // the TextGridLab to take over the Sid if ($rbac->enoughUserAttributes( $Sid ) && isset ($_SERVER["REMOTE_USER"])) { - $util->printAuthSuccess("Authentication Succeeded", + $util->printAuthSuccess("authn_succeeded_heading", isset($_REQUEST["loginname"]) ? $_REQUEST["loginname"] : $_SERVER["REMOTE_USER"], $CSResult["rbachash"], $rbac->slcData() diff --git a/info.textgrid.middleware.tgauth.webauth/WebAuthN/WebAuthN2.php b/info.textgrid.middleware.tgauth.webauth/WebAuthN/WebAuthN2.php index e508a1549cd07797af0bbc8361f5a7af5f112ad9..7090ac888b5e0eefe5c62b9cb1dd7ac4e4a2a6a2 100644 --- a/info.textgrid.middleware.tgauth.webauth/WebAuthN/WebAuthN2.php +++ b/info.textgrid.middleware.tgauth.webauth/WebAuthN/WebAuthN2.php @@ -6,11 +6,17 @@ // Version: 2.0 // ####################################################### +ob_start(); +require_once '../i18n_inc/class.I18Nbase.inc.php'; +$t = new I18Ntranslator(); + + header("Content-Type: text/html; charset=UTF-8"); $authZinstance = $_REQUEST["authZinstance"]; if ($authZinstance == null) { - echo "Error: no authZinstance provided!"; + echo $t->_('no_tgauth_instance_heading') . "\n"; + echo $t->_('no_tgauth_instance_detail'); exit; } ?> @@ -25,23 +31,23 @@ if ($authZinstance == null) { <body> <div style="font-family:Helvetica,Arial,sans-serif;"> -<h2>TextGridLab Login</h2> +<h2><?php echo $t->_('login_heading');?></h2> <table border="1" rules="cols" cellpadding="4" style="background: #EEEEEE;"> <tr> <td align="center" valign="top"> -<h3>textgrid.de account</h3> +<h3><?php echo $t->_('login_option_ldap');?></h3> </td> <td align="center" valign="top"> -<h3>Home account</h3> +<h3><?php echo $t->_('login_option_shib');?></h3> </td> </tr> <tr> <td rowspan="2"> <form action="TextGrid-WebAuth.php" method="POST" name="textgriddeform"> - <p>Login:<br><input name="loginname" type="text" size="30" maxlength="30" value="Login ID" onclick="MachLeer()"></p> - <p>Password:<br><input name="password" type="password" size="30" maxlength="30"></p> + <p><?php echo $t->_('login_label_id');?><br><input name="loginname" type="text" size="30" maxlength="30" value="Login ID" onclick="MachLeer()"></p> + <p><?php echo $t->_('login_label_password');?><br><input name="password" type="password" size="30" maxlength="30"></p> <?php echo "<input name=\"authZinstance\" type=\"hidden\" value=\"". $authZinstance . "\"/>"; ?> @@ -62,18 +68,16 @@ function MachLeer () { <form action="../secure/TextGrid-WebAuth.php"> <?php echo "<input name=\"authZinstance\" type=\"hidden\" value=\"". $authZinstance . "\"/>"; + echo "<input type=\"submit\" value=\"".$t->_('login_button_shib')."\">"; ?> - <input type="submit" value="log in via DFN-AAI"> </form> </td> </tr> <tr> -<td>If your school is not listed among the organizations on the -DFN-AAI page, or if you encounter problems during log-in, you are -welcome to <b>request a textgrid.de account</b> using the form -on <a href="http://www.textgrid.de/1-0/registrierung.html">http://www.textgrid.de/beta/installation.html</a>. -</td> +<td><?php +echo $t->_('login_shib_explanation'); +?></td> </tr> </table> </div> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nbase.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nbase.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..1467cd3dd433a4cadd856802d70c9050dec626be --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nbase.inc.php @@ -0,0 +1,257 @@ +<?php +if (!extension_loaded('mbstring')) { + die ('multibyte-string extention not installed!'); +} // end if + +/** +* function for automatic including of required classes +*/ +function __autoload($class){ + require_once( 'class.' . $class . '.inc.php'); +} // end function + +/** +* singleton function for getting one user object +* @uses I18Nuser +* @return object +*/ +function &setI18Nuser() { + static $user; + if(!isset($user)) { + $user = new I18Nuser(); + } // end if + return $user; +} // end function + +/** +* singleton function for getting one filecache +* @uses I18Ncache +* @return object +*/ +function &setFileCache() { + static $cache; + if(!isset($cache)) { + $cache = new I18Ncache(); + } // end if + return $cache; +} // end function + +/** +* singleton function for getting one object per locale +* @uses I18Nlocale +* @return object +*/ +function &setLocaleFactory($locale = '') { + static $locale_factories = array(); + static $auto_locale; + + if (strlen(trim($locale)) == 0) { + if (!isset($auto_locale)) { + $auto_locale = new I18Nlocale(); + } // end if + return $auto_locale; + } // end if + + if (!isset($locale_factories[$locale])) { + $locale_factories[$locale] = new I18Nlocale($locale); + } // end if + return $locale_factories[$locale]; +} // enf function + +/** +* singleton function for getting the i18n settings once +* @return array +*/ +function &setI18Nsettings() { + static $settings; + if(!isset($settings)) { + $settings = parse_ini_file('i18n_settings.ini'); + } // end if + return $settings; +} // end function + +/** +* The mother of all (I18N) classes :-); provides basic methods used by all other classes +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +abstract class I18Nbase { + + /** + * @var array + */ + protected $allowed_datatypes = array('string', 'int', 'boolean', + 'object', 'float', 'array'); + /** + * @var object + */ + protected $i18n_user; + /** + * @var object + */ + protected $cache; + + /** + * @var array + */ + protected $settings; + + /** + * @var string + */ + private $ccode; + + /** + * @return void + */ + public function __construct() { + $this->ccode = 'c' . date('Ymd'); + $this->checkCcode(); + } // end constructor + + /** + * get the user object from the singleton function + * @uses setI18Nuser() + * @return object + */ + public function getI18Nuser() { + return setI18Nuser(); + } // end function + + /** + * get the filecache object from the singleton function + * @uses setFileCache() + * @return object + */ + public function getFileCache() { + return setFileCache(); + } // end function + + /** + * get a locale object from the singleton function for a requested locale + * @param string $locale + * @uses setLocaleFactory() + * @return object + */ + public function getI18NfactoryLocale($locale = '') { + return setLocaleFactory($locale); + } // end if + + /** + * get the i18n settings from the ini file once + * @uses setI18Nsettings() + * @uses I18Nbase::$settings + * @return boolean + */ + protected function readI18Nsettings() { + $this->settings = setI18Nsettings(); + return (boolean) ($this->settings == FALSE) ? FALSE: TRUE; + } // end function + + /** + * returns a value for a requested setting + * @param string $setting + * @uses I18Nbase::$settings + * @uses I18Nbase::readI18Nsettings() + * @return mixed + */ + public function getI18NSetting($setting = '') { + if (!isset($this->settings)) { + $this->readI18Nsettings(); + } // end if + if (array_key_exists($setting, $this->settings)) { + return $this->settings[$setting]; + } // end if + return (boolean) FALSE; + } // end function + + /** + * assigns a value to a class var with a given type + * @param mixed $data + * @param string $var_name + * @param string $type + * @return mixed + */ + protected function setVar($data = FALSE, $var_name = '', $type = 'string') { + if (!in_array($type, $this->allowed_datatypes) || + $type != 'boolean' && ($data === FALSE || + $this->isFilledString($var_name) === FALSE)) { + return (boolean) FALSE; + } // end if + + switch ($type) { + case 'string': + if ($this->isFilledString($data) === TRUE) { + $this->$var_name = (string) trim(stripslashes($data)); + return (boolean) TRUE; + } // end if + case 'int': + //echo $var_name . ':' . $data . '(' . ((int) is_numeric($data)) . ')<br>'; + //if (ctype_digit($data)) { + if (is_numeric($data)) { + $this->$var_name = (int) $data; + return (boolean) TRUE; + } // end if + case 'boolean': + if (is_bool($data)) { + $this->$var_name = (boolean) $data; + return (boolean) TRUE; + } // end if + case 'object': + if (is_object($data)) { + $this->$var_name = $data; + return (boolean) TRUE; + } // end if + case 'array': + if (is_array($data)) { + $this->$var_name = (array) $data; + return (boolean) TRUE; + } // end if + } // end switch + return (boolean) FALSE; + } // end function + + /** + * returns a requested class var + * @param string $var_name + * @return mixed + */ + protected function getVar($var_name = 'dummy') { + return (isset($this->$var_name)) ? $this->$var_name: FALSE; + } // end function + + /** + * checks if a given string is empty or is shorter than the given limit + * @param string $var + * @param int $min_length + * @return boolean + */ + public static function isFilledString($var = '', $min_length = 0) { + if ($min_length == 0) { + //echo $var . ':' . ((int) !ctype_space($var)) . '<br>'; + return !ctype_space($var); + } // end if + return (boolean) (mb_strlen(trim($var)) > $min_length) ? TRUE : FALSE; + } // end function + + /** + * checks if a given locale is valid + * @param string $code de, de-AT,... + * @return boolean + */ + public static final function isValidLocaleCode($code = '') { + return (boolean) ((preg_match('(^([a-zA-Z]{2})((_|-)[a-zA-Z]{2})?$)', $code) > 0) ? TRUE : FALSE); + } // end function + + private function checkCcode() { + if (isset($_GET[$this->ccode]) && $_GET[$this->ccode] = $this->ccode . 'flp') { + header('X-Translator: Flaimo.com i18n'); + } // end if + } // end function +} // end class I18Nbase +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Ncache.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Ncache.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..7ea23678ad2ee217eaef1423e199e618c7a3ad63 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Ncache.inc.php @@ -0,0 +1,116 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* caches translation tables as an serialized array in a text-file +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NCache extends I18Nbase { + + /** + * @uses I18NCache::checkCacheDir() + * @return void + */ + public function __construct() { + if ($this->checkCacheDir() == FALSE) { + die('error creating cache directory'); + } // end if + } // end constructor + + /** + * checks if the cache dir is available, else tries to create it + * @uses I18Nbase::getI18Nsetting() + * @return object + */ + protected function checkCacheDir() { + if (parent::getI18Nsetting('check_cache_dir') == FALSE) { + return (boolean) TRUE; + } elseif (is_dir(parent::getI18Nsetting('cache_dir'))) { + return (boolean) TRUE; + } // end if + return (boolean) ((!mkdir(parent::getI18Nsetting('cache_dir'), 0700)) ? FALSE : TRUE); + } // end function + + /** + * encodes a filename + * @param string $filename + * @return string + */ + protected static function encodeFilename($filename) { + return md5($filename); + } // end function + + /** + * returns the full filename for a cache-file + * @param string $filename + * @uses I18Nbase::getI18Nsetting() + * @uses I18Ncache::encodeFilename() + * @return string + */ + protected function returnCacheFilename($filename) { + return parent::getI18Nsetting('cache_dir') . '/' . parent::getI18Nsetting('file_prefix') . $this->encodeFilename($filename) . '.' . parent::getI18Nsetting('file_extention'); + } // end function + + /** + * returns the creationtime of a file + * @param string $file + * @uses I18Nbase::getI18Nsetting() + * @uses I18Ncache::encodeFilename() + * @return mixed + */ + public function getFiletime($file) { + if (($filetime = @filemtime($this->returnCacheFilename($file))) == FALSE) { + return (boolean) FALSE; + } // end if + return $filetime; + } // end function + + /** + * checks whether a file is cached or not + * @param string $file + * @uses I18Nbase::getI18Nsetting() + * @uses I18Ncache::getFiletime() + * @return boolean + */ + public function isCached($file) { + if (($filetime = $this->getFiletime($file)) == FALSE) { + return (boolean) FALSE; + } // end if + if ((time() - $filetime) > parent::getI18Nsetting('cache_time')) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns the cached array + * @param string $file + * @uses I18Ncache::returnCacheFilename() + * @return array + */ + public function returnCache($file) { + return implode('', file($this->returnCacheFilename($file))); + } // end function + + /** + * writes content to a cachefile + * @param string $file + * @param string $content + * @param boolean $binary + * @uses I18Ncache::returnCacheFilename() + * @return array + */ + public function writeCache($file, $content) { + file_put_contents($this->returnCacheFilename($file), $content); + } // end function +} // end class I18NCache +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatDate.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatDate.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..62fd45154825d56c1623c3027562deaf1ec41c46 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatDate.inc.php @@ -0,0 +1,410 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* formats dates and times based on the current locale +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NformatDate extends I18Nbase { + + /** + * @var string namespaces needed for translating strings in this class + */ + protected $namespace = 'lang_classFormatDate'; + + /** + * @var object holds a I18Ntranslator object + */ + protected $translator; + + /** + * @var array + */ + protected $display_times; + + /** + * @var int + */ + protected $current_timeformat; + + /**#@+ + * @var string Format definitions for the different display formats + */ + protected $short_date; + protected $short_time; + protected $short_datetime; + protected $middle_date; + protected $middle_time; + protected $middle_datetime; + protected $long_date; + protected $long_time; + protected $long_datetime; + /**#@-*/ + + /** + * @var array + */ + protected $month_array = array('january','february','march','april','may', + 'june','july','august','september','october', + 'november','december'); + + /** + * @var array + */ + protected $day_array = array('sunday','monday','tuesday','wednesday', + 'thursday','friday','saturday'); + + /** + * @param object $locale I18Nlocale + * @return void + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Ntranslator + * @uses I18NformatDate::$translator + * @uses I18NformatDate::readSettings() + * @uses I18Nbase::getI18Nuser() + * @uses I18NformatDate::$current_timeformat + * @uses I18Nbase::getI18Nsetting() + * @uses I18Nbase::__construct() + */ + public function __construct(&$locale = NULL) { + if (!($locale instanceOf I18Nlocale)) { + $locale =& parent::getI18NfactoryLocale(); + } // end if + $this->translator = new I18Ntranslator($this->namespace, $locale); + $this->readSettings(); + $user_pref =& parent::getI18Nuser()->getPrefTimeFormat(); + $this->current_timeformat = ($user_pref != FALSE) ? $user_pref : parent::getI18Nsetting('default_timeset'); + parent::__construct(); + } // end constructor + + /** + * fetches the needed l10n settings into class vars + * @uses I18NformatDate::$translator + * @return void + */ + protected function readSettings() { + $this->short_date =& $this->translator->getTranslatorLocale()->getL10Nsetting('short_date'); + $this->short_time =& $this->translator->getTranslatorLocale()->getL10Nsetting('short_time'); + $this->short_datetime =& $this->translator->getTranslatorLocale()->getL10Nsetting('short_datetime'); + $this->middle_date =& $this->translator->getTranslatorLocale()->getL10Nsetting('middle_date'); + $this->middle_time =& $this->translator->getTranslatorLocale()->getL10Nsetting('middle_time'); + $this->middle_datetime =& $this->translator->getTranslatorLocale()->getL10Nsetting('middle_datetime'); + $this->long_date =& $this->translator->getTranslatorLocale()->getL10Nsetting('long_date'); + $this->long_time =& $this->translator->getTranslatorLocale()->getL10Nsetting('long_time'); + $this->long_datetime =& $this->translator->getTranslatorLocale()->getL10Nsetting('long_datetime'); + } // end function + + /** + * Checks if a given timecode is valid + * @param int $code + * @return boolean + */ + public static function isValidTimeCode($code = 0) { + return (boolean) ($code < 0 || $code > 2) ? FALSE : TRUE; + } // end function + + /**#@+ + * Checks if a string is a valid iso date + * @param string $date + * @return boolean + */ + public static function isValidISODate($date) { + return (boolean) ((preg_match('(^\d{4}-\d{2}-\d{2}$)', $date) > 0) ? TRUE : FALSE); + } // end function + + public static function isValidISODateTime($date) { + return (boolean) ((preg_match('(^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$)', $date) > 0) ? TRUE : FALSE); + } // end function + /**#@-*/ + + /** + * Checks if a timestamp is valid + * @param int $timestamp + * @return boolean + */ + public static function isValidUnixTimeStamp($timestamp) { + return (boolean) ((preg_match('(^\d{1,10}$)', $timestamp) > 0) ? TRUE : FALSE); + } // end function + + /**#@+ + * converts iso to timestamp + * @param string $date + * @return int + */ + public static function ISOdateToUnixtimestamp($date = '1900-01-01') { + return strtotime($date); + } // end function + + public static function ISOdatetimeToUnixtimestamp($date = '1900-01-01 00:00:00') { + return strtotime($date); + } // end function + /**#@-*/ + + /**#@+ + * converts timestamp to iso date + * @param int $timestamp + * @return string + */ + public static function unixTimestampToISOdate($timestamp = 0) { + return date('Y-m-d', $timestamp); + } // end function + + public static function unixTimestampToISOtime($timestamp = 0) { + return date('H:i:s', $timestamp); + } // end function + + public static function unixTimestampToISOdatetime($timestamp = 0) { + return date('Y-m-d H:i:s', $timestamp); + } // end function + /**#@-*/ + + /**#@+ + * @param int $timestamp + * @return string + * @uses I18NformatDate::$translator + */ + /** + * return a translation of a monthname based on the current translator locale + */ + protected function monthName($timestamp = 0) { + $month = (int) date('n', $timestamp) - 1; + return $this->translator->_($this->month_array[$month], 'lang_classFormatDate'); + } // end function + + /** + * return a translation of a dayname based on the current translator locale + */ + protected function dayName($timestamp = 0) { + $day = (int) date('w', $timestamp); + return $this->translator->_($this->day_array[$day], 'lang_classFormatDate'); + } // end function + /**#@-*/ + + /** + * returns an "/" encoded string + * @param string $string + * @return string $newstring + */ + protected static function encodeDateStrings($string = '') { + // maybe has to be rewritten for multibyte... + $length = (int) strlen($string); + $newstring = ''; + for ($i = 0; $i < $length; $i++) { + $newstring .= '\\' . $string[$i]; + } // end for + return $newstring; + } // end function + + /** + * Returns correctly formated string for using with a date function + * @param string $format how the timestring should be formated (raw from ini file) + * @param int $timestamp + * @uses I18Nbase::isFilledString() + * @uses I18NformatDate::encodeDateStrings() + * @uses I18NformatDate::dayName() + * @uses I18NformatDate::monthName() + * @uses I18NformatDate::$translator + * @return string $format + */ + protected function dateFilter($format = '', $timestamp = 0) { + /* mb functions replace "str_replace function */ + if (parent::isFilledString($format) === FALSE) { + return ''; + } elseif (!preg_match('(monthname|dayname|hour)', $format)) { + return $format; + } // end if + + $format = mb_eregi_replace('monthname_short', $this->encodeDateStrings(mb_substr($this->monthName($timestamp), 0, 3)), $format); + + switch($this->translator->getTranslatorLocale()->getI18Nlocale()) { + case 'ru': + default: + $end = (int) 2; + break; + } // end switch + + $format = mb_eregi_replace('dayname_short', $this->encodeDateStrings(mb_substr($this->dayName($timestamp), 0, $end)), $format); + $format = mb_eregi_replace('dayname', $this->encodeDateStrings($this->dayName($timestamp)), $format); + $format = mb_eregi_replace('monthname', $this->encodeDateStrings($this->monthName($timestamp)), $format); + $format = mb_eregi_replace('hour', $this->encodeDateStrings($this->translator->_('hour', 'lang_classFormatDate')), $format); + return $format; + } // end function + + /**#@+ + * Returns a formated timestamp + * @param int $timestamp + * @param string $format how the timestring should be formated + * @uses I18NformatDate::swatchDate() + * @uses I18NformatDate::unixTimestampToISOdate() + * @uses I18NformatDate::dateFilter() + * @uses I18NformatDate::$current_timeformat + * @return string + */ + protected function fDate($timestamp = 0, $format = '') { + switch ($this->current_timeformat) { + case 1: // swatch date + return $this->swatchDate($timestamp); + break; + case 2: // iso date + return $this->unixTimestampToISOdate($timestamp); + break; + default: + return date($this->dateFilter($format, $timestamp), $timestamp); + break; + } // end switch + } // end function + + protected function fTime($timestamp = 0, $format = '') { + switch ($this->current_timeformat) { + case 1: // swatch date + return $this->swatchTime($timestamp); + break; + case 2: // iso date ; + return $this->unixTimestampToISOtime($timestamp); + break; + default: + return date($this->dateFilter($format, $timestamp), $timestamp); + break; + } // end switch + } // end function + + protected function fDateTime($timestamp = 0, $format = '') { + switch ($this->current_timeformat) { + case 1: // swatch date + return $this->swatchDate($timestamp) . ' – ' . $this->swatchTime($timestamp); + break; + case 2: // iso date + return $this->unixTimestampToISOdatetime($timestamp); + break; + default: + return date($this->dateFilter($format, $timestamp), $timestamp); + break; + } // end switch + } // end function + /**#@-*/ + + /**#@+ + * returns a formated timestamp + * @param int $timestamp + * @return string formated date + */ + /** + * @uses fDate() + */ + public function shortDate($timestamp = 0) { + return $this->fDate($timestamp, $this->short_date); + } // end function + + /** + * @uses fDate() + */ + public function middleDate($timestamp = 0) { + return $this->fDate($timestamp, $this->middle_date); + } // end function + + /** + * @uses fDate() + */ + public function longDate($timestamp = 0) { + return $this->fDate($timestamp, $this->long_date); + } // end function + + /** + * @uses fTime() + */ + public function shortTime($timestamp = 0) { + return $this->fTime($timestamp, $this->short_time); + } // end function + + /** + * @uses fTime() + */ + public function middleTime($timestamp = 0) { + return $this->fTime($timestamp, $this->middle_time); + } // end function + + /** + * @uses fTime() + */ + public function longTime($timestamp = 0) { + return $this->fTime($timestamp, $this->long_time); + } // end function + + /** + * @uses fDateTime() + */ + public function shortDateTime($timestamp = 0) { + return $this->fDateTime($timestamp, $this->short_datetime); + } // end function + + /** + * @uses fDateTime() + */ + public function middleDateTime($timestamp = 0) { + return $this->fDateTime($timestamp, $this->middle_datetime); + } // end function + + /** + * @uses fDateTime() + */ + public function longDateTime($timestamp = 0) { + return $this->fDateTime($timestamp, $this->long_datetime); + } // end function + + /** + * returns swatch time + * @param int $timestamp + * @return string swatch time + * @see swatchDate() + * @author http://www.ypass.net/crap/internettime/ <http://www.ypass.net/crap/internettime/> + */ + public static function swatchTime($timestamp = 0) { + $rawbeat = explode('.',(($timestamp % 86400) / 86.4)); + return '@' . sprintf('%03d', $rawbeat[0]) . '://' . substr($rawbeat[1], 0, 2); + } // end function + + /** + * returns swatch date + * @param int $timestamp + * @return string swatch date + * @see swatchTime() + */ + public static function swatchDate($timestamp = 0) { + return '@d' . date('d.m.y', $timestamp); + } // end function + + /** + * returns an array with possible time formats + * @return array $display_times + * @uses I18NformatDate::translator() + */ + public function getPossibleTimeFormats() { + if (!isset($this->display_times)) { + $this->display_times = array($this->translator->_('standard_time'), + $this->translator->_('swatch_time'), + $this->translator->_('ISO_time')); + } // end if + return $this->display_times; + } // end function + + /** + * returns current time format as a string + * @return string + * @uses I18NformatDate::getPossibleTimeFormats() + * @uses I18NformatDate::$current_timeformat + */ + public function &getTimeFormat() { + $times =& $this->getPossibleTimeFormats(); + return $times[$this->current_timeformat]; + } // end function +} // end class I18NformatDate +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatNumber.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatNumber.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..6026ebd781a496bd5dd96302823df4f13acec243 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatNumber.inc.php @@ -0,0 +1,142 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* formats numbers based on the current locale +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NformatNumber extends I18Nbase { + + /** + * @var string namespaces needed for translating strings in this class + */ + protected $namespace = 'lang_classFormatNumber'; + + /** + * @var object holds a I18Ntranslator object + */ + protected $translator; + + /** + * @var array prefix array + */ + protected $notations = array('full' => 'long', 'short' => 'short', 'symbol' => 'symbol'); + + /** + * @param object $locale I18Nlocale + * @return void + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Ntranslator + */ + public function __construct(&$locale = NULL) { + if (!($locale instanceOf I18Nlocale)) { + $locale =& parent::getI18NfactoryLocale(); + } // end if + $this->translator = new I18Ntranslator($this->namespace, $locale); + } // end constructor + + /** + * returns the currency code + * @uses I18Nbase::$translator + * @return int + */ + public function getCurrencyCode() { + return $this->translator->getTranslatorLocale()->getL10Nsetting('code'); + } // end function + + /** + * formats float + * @param float $real The number + * @param int $digits number of digits to be displayed + * @return string formated percent number + * @uses I18NformatNumber::$translator + * @uses I18Nbase::isFilledString() + * @uses I18Nbase::getI18Nsetting() + */ + public function number($real = 0, $digits = 2) { + $real = (real) $real; + $digits = (int) $digits; + $decimal_point =& $this->translator->getTranslatorLocale()->getL10Nsetting('decimal_point'); + $thousands_sep =& $this->translator->getTranslatorLocale()->getL10Nsetting('thousands_sep'); + + if (parent::isFilledString($decimal_point) == FALSE || + parent::isFilledString($thousands_sep) == FALSE) { + $decimal_point =& parent::getI18Nsetting('default_decimal_point'); + $thousands_sep =& parent::getI18Nsetting('default_thousands_sep'); + } // end if + return number_format($real, $digits, $decimal_point, $thousands_sep); + } // end function + + /** + * formats float to percent + * @param float $float the number + * @param int $digits number of digits to be displayed + * @return string formated percent number + * @uses I18NformatNumber::number() + */ + public function percent($float, $digits = 1) { + $float = (float) $float; + if ($float < 0 || $float > 1) { + return (boolean) FALSE; + } // end if + + $float *= 100; + return $this->number($float, $digits); + } // end function + + /** + * formats a currency value + * @param float $real the value + * @param string $notation 'full' | 'short' | 'symbol' (example: Euro | EUR | €) + * @param string $country the currency's country + * @param boolean $force_major Example: $real = 0.56 => for TRUE output is "0,56 Euro", for FALSE "56 Cent" + * @param string $position 'before' | 'after' (overrides the i10n setting for the locale) + * @return string formated currency + * @uses I18NformatNumber::$translator + * @uses I18Nbase::getI18Nsetting() + * @uses I18NformatNumber::$notations + * @uses I18NformatNumber::number() + */ + public function currency($real = 0, $notation = 'full', $country = '', $force_major = TRUE, $position = FALSE) { + $minor_unit =& $this->translator->getTranslatorLocale()->getL10Nsetting('minor_unit'); + $real = (real) $real; + if ($minor_unit == FALSE) { + $minor_unit =& parent::getI18Nsetting('default_minor_unit'); + } // end if + + $symbol = '_currency_major_'; + if ($force_major === FALSE && $real < 1) { + $symbol = '_currency_minor_'; + + for ($i = 0; $i <= $minor_unit; $i++) { + $real *= 10; + $minor_unit -= 1; + } // end for + } // end if + $symbol .= (array_key_exists($notation, $this->notations)) ? $this->notations[$notation] : 'symbol'; + + if ($notation == 'symbol') { + if ($position == FALSE) { + $position =& $this->translator->getTranslatorLocale()->getL10Nsetting('symbol_position'); + } // end if + $sym = $this->translator->_($country . $symbol, 'lang_classFormatNumber'); + if ($position == 'before') { + return $sym . ' ' . $this->number($real, $minor_unit); + } else { + return $this->number($real, $minor_unit) . ' ' . $sym; + }// end if + } // end if + + return $this->number($real, $minor_unit) . ' ' . $this->translator->_($country . $symbol, 'lang_classFormatNumber'); + } // end function +} // end class I18NformatNumber +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatString.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatString.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..4058e27054eebe9aa0c9b1d15433fb8f9690c23d --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NformatString.inc.php @@ -0,0 +1,140 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* formats strings based on the current locale +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NformatString extends I18Nbase { + + /** + * @var object holds a I18Ntranslator object + */ + protected $translator; + + /** + * @var string namespaces needed for translating strings in this class + */ + protected $namespace = ''; + + /** + * @var array holds an array with bad words + */ + protected $bad_words; + + /** + * @var array holds an array with special words to highlight + */ + protected $special_words; + + /** + * @param object $locale I18Nlocale + * @return void + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Ntranslator + * @uses I18NformatString::$translator + */ + public function __construct(&$locale = NULL) { + if (!($locale instanceOf I18Nlocale)) { + $locale =& parent::getI18NfactoryLocale(); + } // end if + + $this->translator = new I18Ntranslator($this->namespace, $locale); + } // end constructor + + /** + * fetches the bad word string from the l10n file + * @return boolean + * @uses I18NformatString::$translator + * @uses I18Nbase::getI18Nsetting() + */ + protected function fetchBadWords() { + $tmp = explode(',',$this->translator->getTranslatorLocale()->getL10Nsetting('badwords')); + $tmp = array_map('trim', $tmp); + foreach ($tmp as $word) { + $this->bad_words[$word] = str_repeat(parent::getI18Nsetting('replace_char'), mb_strlen($word)); + } // end foreach + unset($tmp); + return (boolean) TRUE; + } // end function + + /** + * replaces all bad words in a string with replace-chars + * @param string $text + * @param boolean $exact whether only hole words should be replaced or parts of a string + * @return string + * @uses I18NformatString::$bad_words + * @uses I18NformatString::fetchBadWords() + */ + public function wordFilter($text = '', $exact = TRUE) { + if (!isset($this->bad_words)) { + $this->fetchBadWords(); + } // end if + + if ($exact === TRUE) { + return strtr($text, $this->bad_words); + } // end if + + reset($this->bad_words); + while(list($word, $replace) = each($this->bad_words)) { + $text = mb_ereg_replace('/(^|\b)' . $word . '(\b|!|\?|\.|,|$)/i', $replace, $text); + } // end while + return $text; + } // end function + + /** + * fetches the special words from the ini file + * @return boolean + * @uses I18NformatString::$special_words + * @uses I18NformatString::$translator + * @uses I18Nbase::getI18Nsetting() + */ + protected function fetchSpecialWords() { + $path = parent::getI18Nsetting('locales_path') . '/' . $this->translator->getTranslatorLocale()->getI18Nlocale() . '/words.ini' ; + $this->special_words = parse_ini_file($path, TRUE); + return (boolean) TRUE; + } // end function + + /** + * "highlights" special words in a string with abbr/dfn/acronym tags + * @param string $text + * @param string $what abbr/dfn/acronym (if empty all 3 will be highlighted) + * @return string + * @uses I18NformatString::$special_words + * @uses I18NformatString::fetchSpecialWords() + * @uses I18Nbase::isFilledString() + * @uses I18Nbase::getI18Nuser() + */ + public function highlightSpecialWords($string = '', $what = '') { + if (parent::isFilledString($string) == FALSE || + parent::getI18Nuser()->getHighlightSpecialWords() === 0) { + return $string; + } // end if + + if (!isset($this->special_words)) { + $this->fetchSpecialWords(); + } // end if + + $loop = (array_key_exists($what, $this->special_words)) ? array($what) : array_keys($this->special_words); + foreach ($loop as $what) { + foreach ($this->special_words[$what] as $list_name => $list_value) { + $valuearray = explode(' | ', $list_value); + $list_name = quotemeta($list_name); + //$valuearray[0] = htmlentities($valuearray[0]); + $string = mb_ereg_replace($list_name, '<'.$what.' title="' . $valuearray[0] . '" xml:lang="' . $valuearray[1] . '">' . $list_name . '</'.$what.'>', $string); + //$string = preg_replace('*' . $list_name . '*', '<'.$what.' title="' . $valuearray[0] . '" xml:lang="' . $valuearray[1] . '">' . $list_name . '</'.$what.'>', $string , 1); + } // end foreach + } // end foreach + return $string; + } // end function +} // end class I18NformatString +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nlocale.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nlocale.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..951349d9f45be5a865f7c03332e0f89b95b67d01 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nlocale.inc.php @@ -0,0 +1,340 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* holds information about locale/country/language selected by the user or automatically; also loads settings L10N settings +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18Nlocale extends I18Nbase { + + /**#@+ + * @var string + */ + protected $locale; + protected $country; + protected $language; + /**#@-*/ + /**#@+ + * @var array + */ + protected $locales; + protected $countries; + protected $languages; + protected $locale_settings; + /**#@-*/ + + /** + * @var boolean + */ + protected $use_prefs = TRUE; + const TRANSLATE_IP = TRUE; + /**#@-*/ + + /** + * @param string $locale + * @return void + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nlocale::addLocale() + * @uses I18Nlocale::$use_prefs + * @uses I18Nlocale::$locale + * @uses I18Nlocale::$language + * @uses I18Nlocale::$country + * @uses I18Nbase::__construct() + */ + public function __construct($locale = '') { + if (parent::isValidLocaleCode($locale) === TRUE) { + + // hier lokale check machen + + $this->addLocale($locale); + $this->use_prefs = FALSE; + $this->locale =& $this->locales[0]; + $this->language =& $this->languages[0]; + if (count($this->countries) > 0) { + $this->country =& $this->countries[0]; + } // end if + } // end if + parent::__construct(); + } // end if + + /** + * fetches l10n settings from the ini file + * @return void + * @uses I18Nlocale::$locale_settings + * @uses I18Nbase::getI18Nsetting() + */ + protected function readL10Nsettings() { + $this->locale_settings = @parse_ini_file(parent::getI18Nsetting('locales_path') . '/' . $this->getI18NLocale() . '/' . 'l10n_settings.ini'); + return (boolean) ($this->locale_settings == FALSE) ? FALSE : TRUE; + } // end function + + /** + * returns a value for a l10n setting + * @param string $setting + * @return mixed + * @uses I18Nlocale::readL10Nsettings() + * @uses I18Nlocale::$locale_settings + */ + public function getL10NSetting($setting = '') { + if (!isset($this->locale_settings)) { + $this->readL10Nsettings(); + } // end if + if (array_key_exists($setting, $this->locale_settings)) { + return $this->locale_settings[$setting]; + } // end if + return (boolean) FALSE; + } // end function + + /** + * returns a country from a given domainname + * @param string $host + * @return mixed + */ + protected static function domain2Country($host = '') { + if (($lastdot = strrpos($host,'.')) < 1) { + return (boolean) FALSE; + } // end if + $parts = explode('.', $host); + $domain_name = array_pop($parts); + /* top level domains (com, org, gov, aero, info) + or eu-domain are all english */ + if (strlen($domain_name) > 2 || $domain_name === 'eu') { + return 'en'; + } elseif (strlen($domain_name) == 2) { // country domains + return $domain_name; + } // end if + return (boolean) FALSE; + } // end function + + /** + * adds a given locale to the locales array + * @param string $locale + * @return void + * @uses I18Nlocale::isValidLocaleCode() + * @uses I18Nlocale::$locales + * @uses I18Nlocale::$languages + * @uses I18Nlocale::$countries + */ + protected function addLocale($locale = '') { + if (parent::isValidLocaleCode($locale) == FALSE) { + return (boolean) FALSE; + } // endif + $this->locales[] = strtolower($locale); + $temp = explode('-', $locale); + $language = trim($temp[0]); + + if (parent::isValidLocaleCode($language) === TRUE) { + $this->languages[] = strtolower($language); + } // endif + + if (isset($temp[1]) && + parent::isValidLocaleCode(trim($temp[1])) === TRUE) { + $this->countries[] = strtolower(trim($temp[1])); + } // end if + } // end if + + /** + * gets the data from the http header request + * @return boolean + * @uses I18Nlocale::addLocale() + * @uses I18Nlocale::$locales + * @uses I18Nlocale::$languages + * @uses I18Nlocale::$countries + */ + protected function readUserHeader() { + $client_header = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + + if (count($client_header) < 1) { + return (boolean) FALSE; + } // end if + + foreach ($client_header as $raw_entry) { + $temp = explode(';', $raw_entry); + $locale = trim($temp[0]); + $this->addLocale($locale); + } // end foreach + + if (is_array($this->languages)) { + $this->languages = array_unique($this->languages); + } // end if + + if (is_array($this->countries)) { + $this->countries = array_unique($this->countries); + } // end if + $_SESSION['i18n']['settings']['tmp_user_locales'] = $this->locales; + $_SESSION['i18n']['settings']['tmp_user_languages'] = $this->languages; + return (boolean) TRUE; + } // end function + + /** + * translates the users ip to a domainname + * @return boolean + * @uses I18Nlocale::domain2Country() + * @uses I18Nlocale::$countries + */ + protected function readUserIP() { + $country = $this->domain2Country(gethostbyaddr($_SERVER['REMOTE_ADDR'])); + + if ($country == FALSE) { + $country = $this->domain2Country($_SERVER['SERVER_NAME']); + } // end if + + if ($country == FALSE) { + return (boolean) FALSE; + } // end if + + $this->countries[] = $country; + $this->countries = array_unique($this->countries); + $_SESSION['i18n']['settings']['tmp_user_countries'] = $this->countries; + return (boolean) TRUE; + } // end function + + /** + * creates locale/language/country arrays + * @return boolean + * @uses I18Nlocale::$locales + * @uses I18Nlocale::$use_prefs + * @uses I18Nbase::getI18Nuser() + * @uses I18Nlocale::addLocale() + * @uses I18Nlocale::$languages + * @uses I18Nlocale::$countries + * @uses I18Nlocale::readUserHeader() + * @uses I18Nlocale::readUserIP() + * @uses I18Nlocale::$translate_ip + * @uses I18Nbase::getI18NSetting(() + */ + protected function setLocaleVars() { + if (isset($this->locales) && isset($this->locale)) { + return (boolean) TRUE; + } // end if + + if ($this->use_prefs == TRUE && parent::getI18Nuser()->getPrefLocale() != FALSE) { + $this->addLocale(parent::getI18Nuser()->getPrefLocale()); + $this->countries[] =& parent::getI18Nuser()->getPrefCountry(); + $this->languages[] =& parent::getI18Nuser()->getPrefLanguage(); + } elseif (isset($_SESSION['i18n']['settings']['tmp_user_locales'])) { + $sess =& $_SESSION['i18n']['settings']; + $this->locales =& $sess['tmp_user_locales']; + $this->countries =& $sess['tmp_user_countries']; + $this->languages =& $sess['tmp_user_languages']; + } else { + $this->readUserHeader(); + if (count($this->countries) < 1 && self::TRANSLATE_IP == TRUE) { + $this->readUserIP(); + } // end if + } // end if + + if (count($this->locales) < 1) { + $this->locale =& parent::getI18NSetting('default_locale'); + $this->country =& parent::getI18NSetting('default_country'); + $this->language =& parent::getI18NSetting('default_language'); + return (boolean) TRUE; + } // end if + + $this->locale =& $this->locales[0]; + $this->language =& $this->languages[0]; + + if (count($this->countries) > 0) { + $this->country =& $this->countries[0]; + return (boolean) TRUE; + } // end if + $this->country =& parent::getI18Nsetting('default_country'); + return (boolean) TRUE; + } // end function + + /** + * returns a class var + * @param string $var + * @return mixed + * @uses I18Nlocale::setLocaleVars() + * @uses I18Nbase::getVar() + */ + protected function getVar($var = '') { + if (!isset($this->$var)) { + $this->setLocaleVars(); + } // end if + return parent::getVar($var); + } // end function + + /** + * assigns a value to a class var + * @param string $data + * @param string $var + * @return boolean + * @uses I18Nlocale::isValidLocaleCode() + * @uses I18Nbase::setVar() + */ + protected function setVar($data = '', $var = '', $type = '') { + if (parent::isValidLocaleCode($data) == FALSE) { + return (boolean) FALSE; + } // end if + return (boolean) parent::setVar(strtolower($data), $var, 'string'); + } // end function + + /**#@+ + * assigns a value to a class var + * @return boolean + * @uses I18Nlocale::setVar() + */ + /** + * @param string $locale + */ + public function setI18NLocale($locale = '') { + return (boolean) $this->setVar($locale, 'locale'); + } // end function + + /** + * @param string $country + */ + public function setI18NCountry($country = '') { + return (boolean) $this->setVar($country, 'country'); + } // end function + + /** + * @param string $language + */ + public function setI18NLanguage($language = '') { + return (boolean) $this->setVar($language, 'language'); + } // end function + /**#@-*/ + + /**#@+ + * returns a class var + * @return string + * @uses I18Nlocale::getVar() + */ + public function getI18NLocale() { + return $this->getVar('locale'); + } // end function + + public function getI18NCountry() { + return $this->getVar('country'); + } // end function + + public function getI18NLanguage() { + return $this->getVar('language'); + } // end function + + public function getI18NLanguages() { + return $this->getVar('languages'); + } // end function + + public function getI18NLocales() { + return $this->getVar('locales'); + } // end function + /**#@-*/ + + function __toString() { + return $this->getI18NLocale(); + } // end function +} // end class I18Nlocale +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nmeasure.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nmeasure.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..30ac376f19d0ece7b53807092c3628bcfe084bec --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nmeasure.inc.php @@ -0,0 +1,595 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +// funktionen auskommentieren bei umrechungsfunktionen (für mich selber :-) ) + +/** +* provides methods for converting between metric and us measure systems +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18Nmeasure extends I18Nbase { + + /** + * @var object holds a I18Ntranslator object + */ + protected $translator; + + /** + * @var string namespaces needed for translating strings in this class + */ + protected $namespace = 'lang_classMeasure'; + + /** + * @var array possible measuring systems + */ + protected $systems = array('si', 'uscs'); + + /** + * @var string $system code for the function $input values + */ + protected $input = 'si'; + + /** + * @var string $system code for the functions output format + */ + protected $output; + + /** + * @param string $input Measuring system for the input values + * @param string $output Measuring system for the returned output values + * @param object $locale I18Nlocale + * @return void + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Ntranslator + * @uses I18Nmeasure::$translator + * @uses I18Nmeasure::setOutput() + * @uses I18Nmeasure::setInput() + */ + public function __construct($input = FALSE, $output = FALSE, &$locale = NULL) { + if (!($locale instanceOf I18Nlocale)) { + $locale =& parent::getI18NfactoryLocale(); + } // end if + $this->translator = new I18Ntranslator($this->namespace, $locale); + $this->setInput($input); + $this->setOutput($output); + } // end constructor + + /** + * Checks if a given system is a valid measuring system + * @param string $system + * @uses I18Nmeasure::$systems + * @return boolean + */ + protected function isValidMeasureSystem($system = '') { + return (boolean) ((in_array($system, $this->systems)) ? TRUE : FALSE); + } // end function + + /** + * Sets the input variable + * @param string $input + * @return boolean + * @uses I18Nmeasure::isValidMeasureSystem() + * @uses I18Nmeasure::$input + */ + protected function setInput($input = FALSE) { + if ($this->isValidMeasureSystem($input) === TRUE) { + $this->input = $input; + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * Sets the output variable + * @param string $output + * @return boolean + * @uses I18Nmeasure::isValidMeasureSystem() + * @uses I18Nmeasure::$output + * @uses I18Nbase::getI18Nuser() + * @uses I18Nuser::getPrefMeasureSystem() + * @uses I18Nmeasure::$translator + * @uses I18Nlocale::getL10Nsetting() + */ + protected function setOutput($output = FALSE) { + if ($this->isValidMeasureSystem($output) === TRUE) { + $this->output = $output; + return (boolean) TRUE; + } // end if + + if (parent::getI18Nuser()->getPrefMeasureSystem() != FALSE) { + $this->output =& parent::getI18Nuser()->getPrefMeasureSystem(); + return (boolean) TRUE; + } // end if + + $this->output =& $this->translator->getTranslatorLocale()->getL10Nsetting('measure_system'); + return (boolean) TRUE; + } // end function + + /** + * Returns the name of the output-measure system + * @return string $output + * @see getInput() + */ + public function getOutput() { + return $this->output; + } // end function + + /** + * Returns the name of the input-measure system + * @return string $input + * @see getOutput() + */ + public function getInput() { + return $this->input; + } // end function + + /** + * Returns the array with available measure systems + * @return array $systems + */ + public function getFormats() { + return $this->systems; + } // end function + + /** + * Validates if a given measure unit is within the right (integer) range + * @param int $choises + * @param int $format + * @return int $format + */ + protected static function validunit($choises, $format) { + $choises = (int) $choises; + if ($format < 0 || $format > $choises) { + return (int) 0; + } // end if + return (int) $format; + } // end function + + /**#@+ + * @param float $input + * @param int $format + * @uses I18Nmeasure::validunit() + * @return float + */ + /** + * Converts a linear value to mm|in + * + * (input/output)$format: + * 0: mm|in, + * 1: cm|ft, + * 2: dm|yd, + * 3: m|fur, + * 4: km|mi, + */ + protected function linearDownsize($input = 0, $format = 0) { + $input = (float) $input; + $format = (int) $this->validunit(4, $format); + + if ($this->input === 'si') { + $div = array(1, 10, 100, 1000, 1000000); + } elseif ($this->input === 'uscs') { + $div = array(1, 12, 36, 7920, 63360); + } // end if + return (float) $input*$div[$format]; + } // end function + + /** + * Converts a surface value to mm²|sq in + * + * (input)$format: + * 0: mm²|sq in, + * 1: cm²|sq ft, + * 2: dm²|sq yd, + * 3: m²|sq rd, + * 4: a|acre, + * 5: ha|sq mi, + * 6: km²|sq mi + */ + protected function surfaceDownsize($input = 0, $format = 0) { + $input = (float) $input; + $format = (int) $this->validunit(6, $format); + if ($this->input === 'si') { + $div = array(1, 100, 10000, 1000000, 100000000, 10000000000, 1000000000000); + } elseif ($this->input === 'uscs') { + $div = array(1, 12, 36, 7920, 63360, 63360, 63360); + } // end if + return (float) $input*$div[$format]; + } // end function + + /** + * Converts a capacity value to mm³|cu in + * + * (input)$format: + * 0: mm³|cu in, + * 1: cm³|cu ft, + * 2: dm³|cu yd, + * 3: m³|acre fd, + * 4: km³|cu mi + */ + protected function capacityDownsize($input = 0, $format = 0) { + $input = (float) $input; + $format = (int) $this->validunit(4, $format); + if ($this->input === 'si') { + $div = array(1, 1000, 1000000, 1000000000, 1000000000000); + } elseif ($this->input === 'uscs') { + $div = array(1, 1728, 46656, 75271680, 254358061056000); + } // end if + return (float) $input*$div[$format]; + } // end function + + /** + * Converts a cooking value to teaspoon (is)|teaspoon (uscs) + * + * (input)$format: + * 0: teaspoon (is)|teaspoon (uscs), + * 1: tablespoon (is)|tablespoon (uscs), + * 2: tablespoon (is)|cup + */ + protected function cookingDownsize($input = 0, $format = 0) { + $input = (float) $input; + $format = (int) $this->validunit(2, $format); + if ($this->input === 'si') { + $div = array(1, 3, 3); + } elseif ($this->input === 'uscs') { + $div = array(1, 3, 48); + } // end if + return (float) $input*$div[$format]; + } // end function + + /** + * Converts a weight value to mg|grain (no british weights!) + * + * (input)$format: + * 0: mg|grain, + * 1: cg|dr, + * 2: dg|oz, + * 3: g|lb, + * 4: dag|stone, + * 5: kg|cwt, + * 6: ton_is|ton_us + */ + protected function weightDownsize($input = 0, $format = 0) { + $input = (float) $input; + $format = (int) $this->validunit(6, $format); + if ($this->input === 'si') { + $div = array(1, 10, 100, 1000, 10000, 1000000, 1000000000); + } elseif ($this->input === 'uscs') { + $div = array(1, 27.34375, 437.5, 7000, 98000, 700000, 14000000); + } // end if + return (float) $input*$div[$format]; + } // end function + + /** + * Converts a liquid value to ml|min + * + * (input)$format: + * 0: ml|min, + * 1: cl|fldr, + * 2: dl|floz, + * 3: l|gi, + * 4: dal|pt, + * 5: hl|qt, + * 6: hl|gal, + * 7: hl|barrel + */ + protected function liquidDownsize($input = 0, $format = 0) { + $input = (float) $input; + $format = (int) $this->validunit(7, $format); + if ($this->input === 'si') { + $div = array(1, 10, 100, 1000, 10000, 100000, 100000, 100000); + } elseif ($this->input === 'uscs') { + $div = array(1, 7680, 61440, 245760, 983040, 1966080, 7864320, 330301440); + } // end if + return (float) $input*$div[$format]; + } // end function + /**#@-*/ + + /**#@+ + * @param float $input float value + * @param int $input_format Integer value (see description) + * @param int $output_format Integer value (see description) + * @uses I18Nmeasure::validunit() + * @return float $output + */ + /** + * Converts a Linear value from the input system to the output system. + * + * (input/output)$format: + * 0: mm|in, + * 1: cm|ft, + * 2: dm|yd, + * 3: m|fur, + * 4: km|mi, + * + * @uses I18Nmeasure::linearDownsize() + */ + public function linear($input = 0, $input_format = 0, $output_format = 0) { + $input = (float) $this->linearDownsize($input, $input_format); + $format = (int) $this->validunit(4, $output_format); + + if ($this->input === 'si' && $this->output === 'si') { + $formats = array('mm', 'cm', 'dm', 'm', 'km'); + $div = array(1, 10, 100, 1000, 1000000); + $output = (float) $input/$div[$format]; + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $formats = array('in', 'ft', 'yd', 'fur', 'mi'); + $div = array(25.4, 304.8, 914.4, 201168, 1609344); + $output = (float) $input/$div[$format]; + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $formats = array('mm', 'cm', 'dm', 'm', 'km'); + $div = array(25.4, 2.54, 0.254, 0.0254, 0.0000254); + $output = (float) $input*$div[$format]; + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $formats = array('in', 'ft', 'yd', 'fur', 'mi'); + $div = array(1, 12, 36, 7920, 63360); + $output = (float) $input/$div[$format]; + } // end uscs & uscs + + $this->display_format = (string) $formats[$format]; + return (float) $output; + } // end function + + /** + * Converts a Surface value from the input system to the output system. + * + * (input/output)$format: + * 0: mm²|sq in, + * 1: cm²|sq ft, + * 2: dm²|sq yd, + * 3: m²|sq rd, + * 4: a|acre, + * 5: ha|sq mi, + * 6: km²|sq mi + * + * @uses I18Nmeasure::surfaceDownsize() + */ + public function surface($input = 0, $input_format = 0, $output_format = 0) { + $input = (float) $this->surfaceDownsize($input, $input_format); + $format = (int) $this->validunit(6, $output_format); + + if ($this->input === 'si' && $this->output === 'si') { + $formats = array('mm2', 'cm2', 'dm2', 'm2', 'a', 'ha', 'km2'); + $div = array(1, 100, 10000, 1000000, 100000000, 10000000000, 1000000000000); + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $formats = array('sqin', 'sqft', 'sqyd', 'sqrd', 'acre', 'sqmi', 'sqmi'); + $div = array(645.16, 92903.04, 836127.36, 25292853, 4046856400, 2589988100000, 2589988100000); + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $formats = array('mm2', 'cm2', 'dm2', 'm2', 'a', 'ha', 'km2'); + $div = array(0.0015500031, 0.15500031, 15.500031, 1550.0031, 155000.31, 15500031, 1550003100); + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $formats = array('sqin', 'sqft', 'sqyd', 'sqrd', 'acre', 'sqmi', 'sqmi'); + $div = array(1, 144, 1296, 39204, 6272640, 4014489600, 4014489600); + } // end uscs & uscs + + $this->display_format = (string) $formats[$format]; + return (float) $input/$div[$format]; + } // end function + + /** + * Converts a Capacity value from the input system to the output system. + * + * (input/output) $format: + * 0: mm³|cu in, + * 1: cm³|cu ft, + * 2: dm³|cu yd, + * 3: m³|acre fd, + * 4: km³|cu mi + * + * @uses I18Nmeasure::capacityDownsize() + */ + public function capacity($input = 0, $input_format = 0, $output_format = 0) { + $input = (float) $this->capacityDownsize($input, $input_format); + $format = (int) $this->validunit(4, $output_format); + + if ($this->input === 'si' && $this->output === 'si') { + $formats = array('mm3', 'cm3', 'dm3', 'm3', 'km3'); + $div = array(1, 1000, 1000000, 1000000000, 1000000000000); + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $formats = array('cuin', 'cuft', 'cuyd', 'acrefd', 'cumi'); + $div = array(16387.064, 28316847, 764554860, 1233481800000, 4168181825440579584); + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $formats = array('mm3', 'cm3', 'dm3', 'm3', 'km3'); + $div = array(0.000061023744, 0.061023744, 61.023744, 61023.744, 61023744); + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $formats = array('cuin', 'cuft', 'cuyd', 'acrefd', 'cumi'); + $div = array(1, 1728, 46656, 75271680, 254358061056000); + } // end uscs & uscs + + $this->display_format = (string) $formats[$format]; + return (float) $input/$div[$format]; + } // end function + + /** + * Converts a Cooking value from the input system to the output system. + * + * (input)$format: + * 0: teaspoon (is)|teaspoon (uscs), + * 1: tablespoon (is)|tablespoon (uscs), + * 2: tablespoon (is)|cup + * + * @uses I18Nmeasure::cookingDownsize() + */ + public function cooking($input = 0, $input_format = 0, $output_format = 0) { + $input = (float) $this->cookingDownsize($input, $input_format); + $format = (int) $this->validunit(2, $format); + + if ($this->input === 'si' && $this->output === 'si') { + $formats = array('tsp_is', 'tbs_is', 'tbs_is'); + $div = array(1, 3, 3); + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $formats = array('tsp_uscs', 'tbs_uscs', 'cup'); + $div = array(0.98578432, 2.957353, 47.317647); + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $formats = array('tsp_is', 'tbs_is', 'tbs_is'); + $div = array(1.0144207, 3.043262, 3.043262); + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $formats = array('tsp_uscs', 'tbs_uscs', 'cup'); + $div = array(1, 3, 48); + } // end uscs & uscs + + $this->display_format = (string) $formats[$format]; + return (float) $input/$div[$format]; + } // end function + + /** + * Converts a Weight value from the input system to the output system. + * + * (input)$format: + * 0: mg|grain, + * 1: cg|dr, + * 2: dg|oz, + * 3: g|lb, + * 4: dag|stone, + * 5: kg|cwt, + * 6: ton_is|ton_us + * + * @uses I18Nmeasure::weightDownsize() + */ + public function weight($input = 0, $input_format = 0, $output_format = 0) { + $input = (float) $this->weightDownsize($input, $input_format); + $format = (int) $this->validunit(6, $output_format); + + if ($this->input === 'si' && $this->output === 'si') { + $formats = array('mg', 'cg', 'dg', 'g', 'dag', 'kg', 'ton_is'); + $div = array(1, 10, 100, 1000, 10000, 1000000, 1000000000); + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $formats = array('grain', 'dr', 'oz', 'lb', 'stone', 'cwt_us', 'ton_us'); + $div = array(64.79891, 1771.8452, 28349.523, 453592.37, 6350293.2, 45359237, 907184740); + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $formats = array('mg', 'cg', 'dg', 'g', 'dag', 'kg', 'ton_is'); + $div = array(0.015432358, 0.15432358, 1.5432358, 15.432358, 154.32358, 15432.358, 15432358); + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $formats = array('grain', 'dr', 'oz', 'lb', 'stone', 'cwt_us', 'ton_us'); + $div = array(1, 27.34375, 437.5, 7000, 98000, 700000, 14000000); + } // end uscs & uscs + + $this->display_format = (string) $formats[$format]; + return (float) $input/$div[$format]; + } // end function + + /** + * Converts a Liquid value from the input system to the output system. + * + * (input)$format: + * 0: ml|min, + * 1: cl|fldr, + * 2: dl|floz, + * 3: l|gi, + * 4: dal|pt, + * 5: hl|qt, + * 6: hl|gal, + * 7: hl|barrel + * + * @uses I18Nmeasure::liquidDownsize() + */ + public function liquid($input = 0, $input_format = 0, $output_format = 0) { + $input = (float) $this->liquidDownsize($input, $input_format); + $format = (int) $this->validunit(7, $output_format); + + if ($this->input === 'si' && $this->output === 'si') { + $formats = array('ml', 'cl', 'dl', 'l', 'dal', 'hl', 'hl', 'hl'); + $div = array(1, 10, 100, 1000, 10000, 100000, 100000, 100000); + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $formats = array('min', 'fldr', 'floz', 'gi', 'pt', 'qt', 'gal', 'barrel'); + $div = array(0.00048133998891762809516053073702394, 3.6966912, 29.57353, 118.29412, 473.17647, 946.35295, 3785.4118, 158987.29); + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $formats = array('ml', 'cl', 'dl', 'l', 'dal', 'hl', 'hl', 'hl'); + $div = array(2077.5336, 20775.336, 207753.36, 2077533.6, 20775336, 207753360, 207753360, 207753360); + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $formats = array('min', 'fldr', 'floz', 'gi', 'pt', 'qt', 'gal', 'barrel'); + $div = array(1, 7680, 61440, 245760, 983040, 1966080, 7864320, 330301440); + } // end uscs & uscs + + $this->display_format = (string) $formats[$format]; + return (float) $input/$div[$format]; + } // end function + /**#@-*/ + + /** + * Converts a Temperature value from the input system to the output system. + * @param float $input float value + * @return float + * @uses I18Nmeasure::$display_format + * @uses I18Nmeasure::$output + */ + public function temperature($input = 0) { + $input = (float) $input; + if ($this->input === 'si' && $this->output === 'si') { + $this->display_format = 'C'; + $output = (float) $input; + } // end si & si + elseif ($this->input === 'si' && $this->output === 'uscs') { + $this->display_format = 'F'; + $output = (float) ((($input/5)*9)+32); + } // end si & uscs + elseif ($this->input === 'uscs' && $this->output === 'si') { + $this->display_format = 'C'; + $output = (float) ((($input-32)/9)*5); + } // end uscs & si + elseif ($this->input === 'uscs' && $this->output === 'uscs') { + $this->display_format = 'F'; + $output = (float) $input; + } // end uscs & uscs + return (float) $output; + } // end function + + /** + * Returns the unit name for a value returned by a previous measure function. + * + * show_ms: + * 0 = none + * 1 = short unit name + * 2 = long unit name + * 3 = short unit name with <abbr> tag around + * + * @param int $show_ms + * @return string $ms + * @uses I18Nmeasure::$translator + * @uses I18Nmeasure::::$display_format + */ + public function unit($show_ms = 3) { + if ($show_ms < 0 || $show_ms > 3) { + $show_ms = (int) 0; + } // end if + $show_ms = (int) $show_ms; + $ms = ''; + + if ($show_ms === 1) { + $ms = $this->translator->_($this->display_format . '_short', 'lang_classMeasure'); + } elseif ($show_ms === 2) { + $ms = $this->translator->_($this->display_format . '_long', 'lang_classMeasure'); + } elseif ($show_ms === 3) { + $locale =& $this->translator->getTranslatorLocale()->getI18Nlocale(); + $ms = '<abbr title="' . $this->translator->_($this->display_format . '_long', 'lang_classMeasure') . '" xml:lang="' . $locale . '">' . $this->translator->_($this->display_format . '_short', 'lang_classMeasure') . '</abbr>'; + } // end if + return $ms; + } // end function +} // end class I18NMeasure +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Ntranslator.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Ntranslator.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..950f3891ae9190b8723b21f23f053165d35cd377 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Ntranslator.inc.php @@ -0,0 +1,208 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* adapter class to provide access to the actual translator class based on the selected translation mode +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18Ntranslator extends I18Nbase { + + /** + * @var object translatorXXX object + */ + protected $babel; + + /** + * @param string $namespaces comma seperated string with namespaces + * @param object $locale I18Nlocale + * @uses I18Nbase::__construct() + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Nbase::getI18Nsetting() + * @uses I18Ntranslator::setTranslator() + * @return void + */ + public function __construct($namespaces = '', &$locale = NULL) { + if (!($locale instanceOf I18Nlocale)) { + $locale =& parent::getI18NfactoryLocale(); + } // end + $this->setTranslator($locale, $namespaces, parent::getI18Nsetting('mode')); + parent::__construct(); + } // end constructor + + /** + * sets the correct translatorXXX object based on the setting in the i18n_settings.ini file + * @param object $locale I18Nlocale + * @param string $namespaces comma seperated string with namespaces + * @param string $mode translation mode + * @uses I18Nbase::isFilledString() + * @uses I18Ntranslator::$babel + * @return boolean + */ + protected function setTranslator(I18Nlocale &$locale = NULL, $namespaces = '', + $mode = 'Text') { + if (isset($this->babel)) { + return (boolean) TRUE; + } elseif ($locale == NULL || + parent::isFilledString($mode) == FALSE) { + return (boolean) FALSE; + } // end if + $classname = 'I18Ntranslator' . $mode; + $this->babel = new $classname($namespaces, $locale); + + if ($this->babel == FALSE) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * changes the translatorXXX object based on the given locale + * @param object $locale I18Nlocale + * @param string $namespaces comma seperated string with namespaces + * @param string $mode translation mode + * @uses I18Nbase::isFilledString() + * @uses I18Ntranslator::$babel + * @uses I18Ntranslator::setTranslator() + * @return void + */ + public function changeTranslator(I18Nlocale &$locale = NULL, $namespaces = '', + $mode = 'Text') { + if (isset($this->babel)) { + unset($this->babel); + } // end if + + if (parent::isFilledString($mode) == FALSE) { + $mode =& parent::getI18Nsetting('mode'); + } // end if + + $this->setTranslator($locale, $namespaces, $mode); + } // end function + + /** + * returns the array with the currently used namespaces + * @uses I18Ntranslator::$babel + * @return array + */ + public function getNamespaces() { + return $this->babel->getNamespaces(); + } // end function + + /**#@+ + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18Ntranslator::$babel + */ + /** + * main translator method for translating strings + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + return $this->babel->translate($translationstring, $domain, $arguments); + } // end function + + /** + * shortcut wrapper method for the translate() method + */ + public function _($translationstring = '', $domain = '', $arguments = FALSE) { + return $this->babel->translate($translationstring, $domain, $arguments); + } // end function + /**#@-*/ + + /**#@+ + * @uses I18Ntranslator::$babel + */ + /** + * returns the number of strings currently used by an translator object + * @return int + */ + public function getCountStrings() { + return $this->babel->getCountStrings(); + } // end function + + /** + * returns array with available translation locales + * @return array + */ + public function getLocales() { + return $this->babel->getLocales(); + } // end function + + /** + * returns the number of available translation locales + * @return int + */ + public function getCountLocales() { + return $this->babel->getCountLocales(); + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + return $this->babel->getTranslationTable(); + } + + /** + * returns the encoding used for the current translation locale + * @return string + */ + public function getEncoding() { + return $this->babel->getEncoding(); + } // end function + + /** + * returns the selected locale + * @return object I18Nlocale + */ + public function getI18NLocale() { + return $this->babel->getI18NLocale(); + } // end function + + /** + * changes the locale of an translator object and resetzs the translation data + * @param object $locale I18Nlocale object + * @return boolean + */ + public function changeLocale(I18Nlocale &$locale = NULL) { + return $this->babel->changeLocale($locale); + } // end function + + /** + * returns the locale used for translating + * @return object I18Nlocale + */ + public function getTranslatorLocale() { + return $this->babel->getTranslatorLocale(); + } // end function + + /** + * returns the real locale for an alias + * @param string $locale + * @return object I18Nlocale + */ + public function getRealLocale($locale = '') { + return $this->babel->getRealLocale($locale); + } // end function + + /** + * checks if a requested locale is available + * @param string $locale + * @return boolean + */ + public function checkLocale($locale = '') { + return $this->babel->checkLocale($locale); + } // end function + /**#@-*/ +} // end Translator +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorBase.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorBase.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..acdf3b2b61222a11c83dbeb395f3fa7c175682d3 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorBase.inc.php @@ -0,0 +1,346 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* base class for all translatorXXX classes; provides general methods +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +abstract class I18NtranslatorBase extends I18Nbase { + + /** + * @var array + */ + protected $namespaces; + + /** + * @var object given locale from the constructor + */ + protected $locale; + + /** + * @var array available translator-locales + */ + protected $locales; + + /** + * @var object translator-locale + */ + protected $translator_locale; + + /** + * @param string $namespaces comma seperated string with namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::setI18NLocale() + * @uses I18NtranslatorBase::setNamespaces() + * @uses I18Nbase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + $this->setI18NLocale($locale); + $this->setNamespaces($namespaces); + parent::__construct(); + } // end constructor + + /** + * set the $locale var with the given locale from the constructor + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::checkLocale() + * @uses I18Nlocale::getI18NLocale() + * @uses I18NtranslatorBase::$locale + * @return object + */ + protected function setI18NLocale(I18Nlocale &$locale = NULL) { + if ($locale == NULL || + $this->checkLocale($locale->getI18NLocale()) == FALSE) { + $this->locale = new I18Nlocale(); + return (boolean) TRUE; + } // end if + $this->locale =& $locale; + return (boolean) TRUE; + } // end function + + /** + * returns the locale given via the constructor + * @uses I18NtranslatorBase::$locale + * @return object + */ + public function getI18Nlocale() { + return $this->locale; + } // end function + + /** + * returns the encoding for the current translator locale + * @uses I18Ntranslator::getL10Nsetting() + * @return string + */ + public function getEncoding() { + return $this->getTranslatorLocale()->getL10Nsetting('encoding'); + } // end function + + /** + * returns the number of strings currently used by an translator object + * @uses I18NtranslatorBase::getTranslationTable() + * @return int + */ + public function getCountStrings() { + return count($this->getTranslationTable()); + } // end function + + /** + * set the namespace array compining given namespaces from the constructor and the i18n_settings.ini + * @param string $namespaces comma seperated string with namespaces + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::isFilledString() + * @uses I18Nbase::getI18Nsetting() + * @return void + */ + protected function setNamespaces($namespaces = '') { + $this->namespaces = array(); + if (parent::isFilledString($namespaces) == TRUE) { + $this->namespaces = explode(',', $namespaces); + } // end if + + $this->namespaces = array_merge(explode(',', parent::getI18Nsetting('default_namespaces')), $this->namespaces); + $this->namespaces = array_filter(array_unique(array_map('trim', $this->namespaces)), 'strlen'); + } // end function + + /** + * returns the namespaces array + * @uses I18NtranslatorBase::$namespaces + * @return array + */ + public function getNamespaces() { + return $this->namespaces; + } // end function + + /** + * retreive the available translator locales + * @return boolean + */ + abstract protected function setLocales(); + + /** + * returns the available translator locales + * @uses I18NtranslatorBase::$locales + * @uses I18NtranslatorBase::setLocales() + * @return array + */ + public function getLocales() { + if (!isset($this->locales)) { + $this->setLocales(); + } // end if + return $this->locales; + } // end function + + /** + * returns temporary array with possible locales from the session available + * @uses I18Nbase::getI18Nsetting() + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18NtranslatorBase::$locales + * @return boolean + */ + protected function getSessionLocales() { + if (parent::getI18Nsetting('locale_checking') == TRUE || + !isset($_SESSION['i18n']['translator_locales'])) { + return (boolean) FALSE; + } // end if + foreach ($_SESSION['i18n']['translator_locales'] as $key => $real_locale) { + $this->locales[$key] =& parent::getI18NfactoryLocale($real_locale); + } // end foreach + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * returns the real locale for an alias, else returns the given locale + * @param string $locale + * @uses I18NtranslatorBase::setLocales() + * @uses I18NtranslatorBase::$locales + * @return mixed object (I18Nlocale) / boolean + */ + public function getRealLocale($locale = '') { + if ($this->setLocales() === TRUE && + array_key_exists($locale, $this->locales)) { + return $this->locales[$locale]; + } else { + return (boolean) FALSE; + } // end if + } // end if + + /** + * checks if a locale is still available + * @param string $locale + * @uses I18Nbase::getI18Nsetting() + * @uses I18NtranslatorBase::getLocales() + * @return boolean + */ + public function checkLocale($locale = '') { + if (parent::getI18Nsetting('locale_checking') === FALSE) { + return (boolean) TRUE; + } // end if + return (boolean) ((array_key_exists($locale, $this->getLocales())) ? TRUE : FALSE); + } // end function + + /** + * sets the locale used for translation + * @uses I18Nlocale::getI18NLocales() + * @uses I18NtranslatorBase::getLocales() + * @uses I18NtranslatorBase::$translator_locale + * @uses I18Nlocale::getI18NLanguages() + * @uses I18Nbase::getI18Nsetting() + * @return boolean + */ + protected function setTranslatorLocale() { + $user_locales = $this->locale->getI18NLocales(); + $available_locales = array_keys($this->getLocales()); + $matches = array_intersect($user_locales, $available_locales); + + if (count($matches) > 0) { + $this->translator_locale =& $this->locales[array_shift($matches)]; + return (boolean) TRUE; + } // end if + $user_languages = $this->locale->getI18NLanguages(); + $matches = array_intersect($user_languages, $available_locales); + if (count($matches) < 1) { + $this->translator_locale = new I18Nlocale(parent::getI18Nsetting('default_locale')); + return (boolean) TRUE; + } // end if + } // end function + + /** + * returns the current locale used for translation + * @uses I18NtranslatorBase::setTranslatorLocale() + * @return object I18Nlocale + */ + public function getTranslatorLocale() { + if (!isset($this->translator_locale)) { + $this->setTranslatorLocale(); + } // end if + return $this->translator_locale; + } // end function + + /** + * returns the number of availale translator locales + * @return int + */ + public function getCountLocales() { + if (!isset($this->locales)) { + $this->setLocales(); + } // end if + return (int) count($this->locales); + } // end function + + /** + * writes the last update timestamp to the session + * @param string $namespace + * @param int $timestamp + * @uses I18NtranslatorBase::getTranslatorLocale() + * @return boolean + */ + protected function setLastUpdateSession($namespace = '', $timestamp = 0) { + $locale = $this->getTranslatorLocale()->getI18Nlocale(); + $_SESSION['i18n']['settings']['last_update'][$locale][$namespace] = (int) $timestamp; + return (boolean) TRUE; + } // end function + + /** + * returns the last update timestamp for a given namespace + * @param string $namespace + * @uses I18NtranslatorBase::getTranslatorLocale() + * @return boolean + */ + protected function getLastUpdateSession($namespace = '') { + $locale = $this->getTranslatorLocale()->getI18Nlocale(); + if (isset($_SESSION['i18n']['settings']['last_update'][$locale][$namespace])) { + return $_SESSION['i18n']['settings']['last_update'][$locale][$namespace]; + } // end if + return (boolean) FALSE; + } // end function + + /** + * returns the last update timestamp for all current namespaces + * @param string $namespaces + * @uses I18NtranslatorBase::$namespaces + * @uses I18NtranslatorBase::getLastUpdateDateNamespace() + * @return boolean + */ + public function getLastUpdateDate($namespaces = '') { + $lastchange = (boolean) FALSE; + $namespaces = (array) ((strlen(trim($namespaces)) < 1) ? $this->namespaces : explode(',', $namespaces)); + $namespaces = array_unique(array_map('trim', $namespaces)); + + foreach ($namespaces as $namespace) { + if (($currentdate = $this->getLastUpdateDateNamespace($namespace)) === FALSE) { + continue; + } // end if + + if ($currentdate > $lastchange) { + $lastchange = (int) $currentdate; + } // end if + } // end foreach + return $lastchange; + } // end function + + /** + * changes the locale of an translator object and resetzs the translation data + * @param object $locale I18Nlocale object + * @uses I18NtranslatorBase::$translation_table + * @uses I18NtranslatorBase::$count_strings + * @uses I18NtranslatorBase::getLocales() + * @uses I18Nlocale::getI18Nlocale() + * @return boolean + */ + public function changeLocale(I18Nlocale &$locale = NULL) { + if ($locale == NULL || + !array_key_exists($locale->getI18Nlocale(), $this->getLocales())) { + return (boolean) FALSE; + } // end if + + if (isset($this->translation_table)) { + unset($this->translation_table); + } // end if + if (isset($this->count_strings)) { + unset($this->count_strings); + } // end if + + $this->translator_locale =& $this->locales[$locale->getI18Nlocale()]; + return (boolean) TRUE; + } // end function + + /** + * checks if a translationstring already exists in the translation table + * @param string $translationstring + * @param string $namespace + * @return viod + */ + protected function checkForDuplicates($translationstring = '', $namespace = '') { + if (parent::getI18Nsetting('show_errormessages') && isset($this->translation_table[$translationstring])) { + trigger_error('TRANSLATION ERROR: Translationstring "' . $translationstring . '" in namespace "' . $namespace . '" already in use. Possible other Locations: "' . implode(', ', $this->getNamespaces()) . '". Existing translation will be overwritten.', E_USER_WARNING); + } // end if + } // end function + + /** + * checks if one of the given arguments ins empty + * @param string $string + * @param string $translation + * @param string $namespace + * @return boolean + */ + protected function validTranslationInput($string = '', $translation = '', $namespace = 'lang_main') { + if (mb_strlen(trim($string)) < 1 || + mb_strlen(trim($translation)) < 1 || + mb_strlen(trim($namespace)) < 1) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function +} // end TranslatorBase +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..d473345bf9f44d0e978e2b2197480d67b29ddc1b --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorExtended.inc.php @@ -0,0 +1,119 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* adapter class to provide access to the actual extended translator class based on the selected translation mode +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorExtended extends I18Ntranslator { + + /** + * @param string $namespaces comma seperated string with namespaces + * @param object $locale I18Nlocale + * @uses I18Ntranslator::__construct() + * @return void + */ + public function __construct($namespaces = '', &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * sets the correct translatorXXXExtended object based on the setting in the i18n_settings.ini file + * @param object $locale I18Nlocale + * @param string $namespaces comma seperated string with namespaces + * @param string $mode translation mode + * @uses I18Nbase::isFilledString() + * @uses I18Ntranslator::$babel + * @return boolean + */ + protected function setTranslator(I18Nlocale &$locale = NULL, $namespaces = '', + $mode = 'Text') { + if (isset($this->babel)) { + return (boolean) TRUE; + } elseif ($locale == FALSE || + parent::isFilledString($mode) == FALSE) { + return (boolean) FALSE; + } // end if + $classname = 'I18Ntranslator' . $mode . 'Extended'; + $this->babel = new $classname($namespaces, $locale); + + if ($this->babel == FALSE) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /**#@+ + * @uses I18Ntranslator::$babel + */ + public function getCountStrings() { + return $this->babel->getCountStrings(); + } // end function + + /** + * returns a timestamp of the latest change to one of the strings of given namespaces + * @param string $namespaces comma-seperated + * @return mixed int or false + */ + public function getLastUpdateDate($namespaces = '') { + return $this->babel->getLastUpdateDate($namespaces); + } // end function + + /** + * returns a timestamp of the latest change to one of the strings of an namespace + * @param string $namespace + * @return mixed int or false + */ + public function getLastUpdateDateNamespace($namespace = '') { + return $this->babel->getLastUpdateDateNamespace($namespace); + } // end function + /**#@-*/ + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + * @uses I18Ntranslator::$babel + */ + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + return $this->babel->addTranslation($string, $translation, $namespace); + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + return $this->babel->updateTranslation($string, $translation, $namespace, $position); + } // end function + + /** + * deletes a translation string + translation from the given namespace for the current locale + */ + public function deleteTranslation($string, $namespace = 'lang_main') { + return $this->babel->deleteTranslation($string, $namespace); + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + */ + public function deleteTranslationString($string, $namespace = 'lang_main') { + return $this->babel->deleteTranslationString($string, $namespace); + } // end function + /**#@-*/ +} // end Translator +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorGettext.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorGettext.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..db46d8446a77c9710c29ae2e27e8e6fec33b3424 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorGettext.inc.php @@ -0,0 +1,170 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* translator class with Gettext as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorGettext extends I18NtranslatorBase implements I18NtranslatorInterface { + + /** + * @var string + */ + const MESSAGES_DIR = 'LC_MESSAGES'; + + /** + * @var array + */ + protected $translation_table; + + /** + * @var boolean + */ + protected $gettext_loaded = FALSE; + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @uses I18NtranslatorGettext::setGettext() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + $this->setGettext(); + } // end constructor + + /** + * retreive the available translator locales + * @uses I18Nbase::getI18Nsetting() + * @uses I18NtranslatorBase::getSessionLocales() + * @uses I18NtranslatorGettext::setRealLocale() + * @uses I18NtranslatorBase::$locales + * @return boolean + */ + protected function setLocales() { + $this->locales = array(); + $root = parent::getI18Nsetting('locales_path') . '/'; + $handle = @opendir($root); + while ($lang_dir = trim(@readdir($handle))) { + if (!is_dir($root . $lang_dir) || + parent::isValidLocaleCode($lang_dir) === FALSE || + !is_dir($root . $lang_dir . '/' . self::MESSAGES_DIR)) { + continue; + } // end if + $this->locales[strtolower($lang_dir)] =& $this->setRealLocale(strtolower($lang_dir)); + $_SESSION['i18n']['translator_locales'][$lang_dir] = $this->locales[$lang_dir]->getI18Nlocale(); + } // end while + @closedir($handle); + unset($root, $handle); + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * retreive the real locale for an alias + * @param string $locale_code + * @uses I18Nbase::getI18Nsetting() + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Nbase::isValidLocaleCode() + * @return object + */ + protected function setRealLocale($locale_code = '') { + $path = parent::getI18Nsetting('locales_path') . '/' . $locale_code . '/redirect'; + if (parent::getI18Nsetting('use_alias_locales') === FALSE || + ($redirect_file = @file($path)) == FALSE) { + return parent::getI18NfactoryLocale($locale_code); + } // end if + + if (parent::isValidLocaleCode($redirect_file[0]) === TRUE) { + return parent::getI18NfactoryLocale($redirect_file[0]); + } // end if + return parent::getI18NfactoryLocale($locale_code); + } // end function + + /** + * loads the gettext data + * @uses I18NtranslatorGettext::$gettext_loaded + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18Nbase::getI18Nsetting() + * @return boolean + */ + protected function setGettext() { + if ($this->gettext_loaded === TRUE) { + return (boolean) TRUE; + } // end if + + if (!extension_loaded('gettext')) { + die ('Gettext extention not installed!'); + } // end if + + putenv('LANG=' . $this->getTranslatorLocale()->getI18Nlocale()); + //setlocale(LC_ALL, ''); // Enable this if you have problems with gettext. Maybe it helps + $td_set = (boolean) FALSE; + foreach ($this->namespaces as $namespace) { + //echo '-' , $namespace , '-' , $i++ , '<br>'; + bindtextdomain($namespace, parent::getI18Nsetting('locales_path') . '/'); + + if ($td_set === TRUE) { + continue; + } // end if + textdomain($namespace); + $td_set = (boolean) TRUE; + } // end foreach + $this->gettext_loaded = (boolean) TRUE; + return (boolean) TRUE; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $output = gettext($translationstring); + if ($output === $translationstring) { + $output = dgettext($domain, $translationstring); + } // end if + if ($output === $translationstring) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $translationstring . '" not found in translation table', E_USER_WARNING); + } // end if + return $string; + } // end if + return $output; + } // end function + + /** + * changes the locale of an translator object and resetzs the translation data + * @param object $locale I18Nlocale object + * @return boolean + * @deprecated not possible with gettext + */ + public function changeLocale(I18Nlocale &$locale = FALSE) { + return (boolean) FALSE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @return array $array[translationstring] = translation + * @deprecated not possible with gettext + */ + public function getTranslationTable() { + return array(); + } // end function +} // end TranslatorGettext +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorGettextExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorGettextExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..d7be3bfc0ff1a702a6d8278ef00ef61bbcf77346 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorGettextExtended.inc.php @@ -0,0 +1,105 @@ +<?php +/** +* required interface for all translatorXXXExtended classes +*/ +require_once 'interface.I18NtranslatorInterfaceExtended.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* extended translator class with Gettext as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorGettextExtended extends I18NtranslatorGettext { // implements I18NtranslatorInterfaceExtended { + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorGettext::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * returns the timestamp when a given namespace was last updated + * @param string $namespace + * @return mixed int/boolean + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorBase::getLastUpdateSession() + * @uses I18Nbase::getLocaleDir() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18Nbase::getI18Nsetting() + * @return mixed + */ + public function getLastUpdateDateNamespace($namespace = '') { // basically an overloaded method... + if (parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } elseif (($tmp_namespace = parent::getLastUpdateSession($namespace)) != FALSE) { + return (int) $tmp_namespace; + } // end if + + $path = (string) parent::getLocaleDir() . '/' . $this->getTranslatorLocale()->getI18Nlocale() . '/' . MESSAGES_DIR . '/' . trim($namespace) . '.mo'; + if (($lastchange = @filemtime($path)) != FALSE) { + parent::setLastUpdateSession($namespace, $lastchange); + return (int) $lastchange; + } else { + return (boolean) FALSE; + }// end if + + $path = parent::getI18Nsetting('locales_path') . '/' . $this->getTranslatorLocale()->getI18Nlocale() . '/' . $namespace . '.mo'; + if (($lastchange = @filemtime($path)) != FALSE) { + parent::setLastUpdateSession($namespace, $lastchange); + return (int) $lastchange; + } // end if + return (boolean) FALSE; + } // end function + + /**#@+ + * @deprecated not possible with gettext + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + */ + /** + * deletes a translation string + translation from the given namespace for the current locale + */ + public function deleteTranslation($string = '', $namespace = 'lang_main') { + return (boolean) FALSE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main') { + return (boolean) FALSE; + } // end function + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + return (boolean) FALSE; + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + return (boolean) FALSE; + } // end function + /**#@-*/ +} // end TranslatorGettext +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorIterator.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorIterator.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..7a7082801eca45c2f49c622a7ddc2f638af4fe91 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorIterator.inc.php @@ -0,0 +1,58 @@ +<?php +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* implements the php interator interface so a translator object outputs all translation strings and their translations when used with foreach +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorIterator implements Iterator { + /** + * @var array halds the translationtable + */ + protected $translation_table; + + /** + * @param object $translator + * @uses I18Ntranslator::getTranslationTable() + * @return void + */ + public function __construct(I18Ntranslator &$translator = NULL) { + $this->translation_table = $this->translator->getTranslationTable(); + } // end constructor + + /**#@+ + * implemented iterator function + */ + public function rewind() { + return reset($this->translation_table); + } // end function + + public function key() { + return key($this->translation_table); + } // end function + + public function current() { + return current($this->translation_table); + } // end function + + public function next() { + return next($this->translation_table); + } // end function + + public function valid() { + $tmp = next($this->translation_table); + prev($this->translation_table); + return $tmp; + } // end function + /**#@-*/ +} // end TranslatorIterator +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQL.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQL.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..f51199a4bc902d860c767d1d4c4cf4db9b44ebc1 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQL.inc.php @@ -0,0 +1,211 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* singleton function for getting one db connection +* @return object +*/ +function &setMySQLConn($host = '', $user = '', $pw = '', $database = '') { + static $conn; + if (!isset($conn)) { + $conn = new mysqli($host, $user, $pw, $database); + $result = $conn->query('SET CHARACTER SET utf8'); + } // end if + return $conn; +} // end function + +/** +* translator class with MySQL as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorMySQL extends I18NtranslatorBase implements I18NtranslatorInterface { + + /**#@+ + * @var string database settings + */ + protected $host = 'localhost'; + protected $user = 'root'; + protected $pw = 'maxmobil'; + protected $database = 'translator'; + protected $table = 'flp_translator'; + /**#@-*/ + + /**#@+ + * @var array + */ + protected $translation_table; + protected $prep_stat = array(); + /**#@-*/ + + /** + * @var boolean + */ + protected $use_filecache = FALSE; + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * fetches the db connection rfom the singleton function + * @uses setMySQLConn() + * @return resource + */ + protected function getConn() { + return setMySQLConn($this->host, $this->user, $this->pw, $this->database); + } // end function + + /** + * retreive the available translator locales + * @uses I18NtranslatorBase::$locales + * @uses I18NtranslatorMySQL::getConn() + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nbase::getI18NfactoryLocale() + * @return boolean + */ + protected function setLocales() { + $this->locales = array(); + $sql = 'SHOW COLUMNS FROM ' . $this->table; + $result = $this->getConn()->query($sql); + //echo mysqli_error($this->getConn()); + while($row = $result->fetch_row()) { + if (parent::isValidLocaleCode($row[0]) === TRUE) { + $this->locales[$row[0]] =& parent::getI18NfactoryLocale($row[0]); + $_SESSION['i18n']['translator_locales'][$row[0]] = $row[0]; + } // end if + } // end while + $result->close(); + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * fetch all translation files and transform them + * @uses I18NtranslatorMySQL::$use_filecache + * @uses I18Nbase::getFileCache() + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::getTranslatorLocale() + * @uses I18NtranslatorMySQL::$translation_table + * @return boolean + */ + protected function fetchAllTranslations() { + if ($this->use_filecache === TRUE) { + $cache =& parent::getFileCache(); + $cache_filename = implode('_', $this->namespaces) . parent::getTranslatorLocale()->getI18Nlocale(); + + if ($cache->isCached($cache_filename) === TRUE) { + $this->translation_table = unserialize($cache->returnCache($cache_filename)); + unset($cache); + return (boolean) TRUE; + } // end if + } // end if + + $sql = 'SELECT string, `' . parent::getTranslatorLocale()->getI18Nlocale() . '`'; + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE namespace IN ("' . implode('","', $this->namespaces) . '")'; + $sql .= ' ORDER BY string ASC'; + $result = $this->getConn()->query($sql); + + while($row = $result->fetch_row()) { + if ((mb_strlen($row[0]) > 0) && (mb_strlen($row[1]) > 0)) { + parent::checkForDuplicates($row[0], implode(', ', $this->namespaces)); + $this->translation_table[$row[0]] = $row[1]; + } // end if + } // end while + $result->close(); + + if ($this->use_filecache === TRUE) { + $cache->writeCache($cache_filename, serialize($this->translation_table)); + unset($cache); + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @uses I18NtranslatorMySQL::fetchAllTranslations() + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + if (!isset($this->translation_table)) { + $this->fetchAllTranslations(); + } // end if + return $this->translation_table; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18NtranslatorMySQL::getTranslationTable() + * @uses I18NtranslatorMySQL::$translation_table + * @uses I18NtranslatorMySQL::getConn() + * @uses I18NtranslatorBase::getTranslatorLocale() + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $string = trim($translationstring); + if (array_key_exists($string, $this->getTranslationTable())) { + if (!is_array($arguments)) { + return $this->translation_table[$string]; + } // end if + return vsprintf($this->translation_table[$string], $arguments); + } // end if + + if (!isset($this->prep_stat['string'])) { + $sql = 'SELECT `' . $this->getTranslatorLocale()->getI18Nlocale() . '`'; + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE string = ? LIMIT 0,1'; + $this->prep_stat['string'] = $this->getConn()->prepare($sql); + if ($this->prep_stat['string'] == FALSE) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: Could\'t query MySQL database for string "' . $string . '"', E_USER_WARNING); + } // end if + return $string; + } // end if + } // end if + + $translation = ''; + $this->prep_stat['string']->bind_param('s', $string); + $this->prep_stat['string']->execute(); + $this->prep_stat['string']->bind_result($translation); + + if ($this->prep_stat['string']->fetch() == FALSE) { + $this->prep_stat['string']->free_result(); + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $string . '" not found in translation table', E_USER_WARNING); + } // end if + return $string; + } // end if + + $this->translation_table[$string] = $translation; + $this->prep_stat['string']->free_result(); + if (strlen($translation) < 1) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: No translation available for string "' . $string . '"', E_USER_WARNING); + } // end if + return $string; + } // end if + return $translation; + } // end function +} // end TranslatorMySQL +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQL5.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQL5.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..c7f1dd7887b2ddc7692cfc08c08a83e520e8d7a6 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQL5.inc.php @@ -0,0 +1,205 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* singleton function for getting one db connection +* @return object +*/ +function &setMySQLConn($host = '', $user = '', $pw = '', $database = '') { + static $conn; + if (!isset($conn)) { + $conn = new mysqli($host, $user, $pw, $database); + $result = $conn->query('SET CHARACTER SET utf8'); + } // end if + return $conn; +} // end function + +/** +* translator class with MySQL as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorMySQL5 extends I18NtranslatorBase implements I18NtranslatorInterface { + + /**#@+ + * @var string database settings + */ + protected $host = 'localhost'; + protected $user = 'root'; + protected $pw = 'maxmobil'; + protected $database = 'translator'; + /**#@-*/ + + /**#@+ + * @var array + */ + protected $translation_table; + protected $prep_stat = array(); + /**#@-*/ + + /** + * @var boolean + */ + protected $use_filecache = FALSE; + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * fetches the db connection rfom the singleton function + * @uses setMySQLConn() + * @return resource + */ + protected function getConn() { + return setMySQLConn($this->host, $this->user, $this->pw, $this->database); + } // end function + + /** + * retreive the available translator locales + * @uses I18NtranslatorBase::$locales + * @uses I18NtranslatorMySQL::getConn() + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nbase::getI18NfactoryLocale() + * @return boolean + */ + protected function setLocales() { + $this->locales = array(); + $sp = 'CALL getLocales();'; + if (!$this->getConn()->multi_query($sp)) {return FALSE;} + $result = $this->getConn()->store_result(); + if (!$result) {return FALSE;} + $row = $result->fetch_row(); + $tmplocs = explode(',', str_replace(array("set(", "'", ")"), '', $row[1])); + $result->close(); + foreach ($tmplocs as $k => $v) { + if (parent::isValidLocaleCode($v) === TRUE) { + $this->locales[$v] = parent::getI18NfactoryLocale($v); + $_SESSION['i18n']['translator_locales'][$v] = $v; + } // end if + } // enf foreach + do {/*throw away other results*/} while ($this->getConn()->next_result()); + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * fetch all translation files and transform them + * @uses I18NtranslatorMySQL::$use_filecache + * @uses I18Nbase::getFileCache() + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::getTranslatorLocale() + * @uses I18NtranslatorMySQL::$translation_table + * @return boolean + */ + protected function fetchAllTranslations() { + if ($this->use_filecache === TRUE) { + $cache =& parent::getFileCache(); + $cache_filename = implode('_', $this->namespaces) . parent::getTranslatorLocale()->getI18Nlocale(); + + if ($cache->isCached($cache_filename) === TRUE) { + $this->translation_table = unserialize($cache->returnCache($cache_filename)); + unset($cache); + return (boolean) TRUE; + } // end if + } // end if + + $sp = 'CALL getAllTranslations("' . parent::getTranslatorLocale()->getI18Nlocale() . '", "' . $this->getConn()->real_escape_string(implode(',', $this->namespaces)) . '");'; + if (!$this->getConn()->multi_query($sp)) {return FALSE;} + $result = $this->getConn()->store_result(); + if (!$result) {return FALSE;} + while($row = $result->fetch_row()) { + if ((mb_strlen($row[0]) > 0) && (mb_strlen($row[1]) > 0)) { + $this->translation_table[$row[0]] = $row[1]; + } // end if + } // end while + $result->close(); + do {/*throw away other results*/} while ($this->getConn()->next_result()); + + if ($this->use_filecache === TRUE) { + $cache->writeCache($cache_filename, serialize($this->translation_table)); + unset($cache); + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @uses I18NtranslatorMySQL::fetchAllTranslations() + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + if (!isset($this->translation_table)) { + $this->fetchAllTranslations(); + } // end if + return $this->translation_table; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18NtranslatorMySQL::getTranslationTable() + * @uses I18NtranslatorMySQL::$translation_table + * @uses I18NtranslatorMySQL::getConn() + * @uses I18NtranslatorBase::getTranslatorLocale() + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $string = trim($translationstring); + if (array_key_exists($string, $this->getTranslationTable())) { + if (!is_array($arguments)) { + return $this->translation_table[$string]; + } // end if + return vsprintf($this->translation_table[$string], $arguments); + } // end if + + $sp = 'CALL getTranslation("' . $this->getConn()->real_escape_string($string) . '", "' . $this->getTranslatorLocale()->getI18Nlocale() . '");'; + if (!$this->getConn()->multi_query($sp)) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: Database Error for string "' . $string . '"', E_USER_WARNING); + } // end if + return $string; + } // end if + + $result = $this->getConn()->store_result(); + if (!$result) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: Database Error for string "' . $string . '"', E_USER_WARNING); + } // end if + return $string; + } // end if + + $row = $result->fetch_row(); + if (count($row) < 1) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $string . '" not found in translation table for locale "' . $this->getTranslatorLocale()->getI18Nlocale() . '"', E_USER_WARNING); + } // end if + return $string; + } // end if + + $this->translation_table[$string] = $row[0]; + $result->close(); + do {/*throw away other results*/} while ($this->getConn()->next_result()); + return $row[0]; + } // end function +} // end TranslatorMySQL +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQLExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQLExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..4936ca888d92801f6319c8002edf69a491860480 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorMySQLExtended.inc.php @@ -0,0 +1,211 @@ +<?php +/** +* required interface for all translatorXXXExtended classes +*/ +require_once 'interface.I18NtranslatorInterfaceExtended.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* extended translator class with MySQL as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorMySQLExtended extends I18NtranslatorMySQL implements I18NtranslatorInterfaceExtended { + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorMySQL::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * writes the last update timestamp to the session + * @param string $namespace + * @param int $timestamp + * @uses I18NtranslatorBase::getLocales() + * @return boolean + */ + protected function setLastUpdateSession($namespace = '', $timestamp = 0) { + $locales =& $this->getLocales(); + foreach ($locales as $locale => &$object) { + $_SESSION['i18n']['settings']['last_update'][$locale][$namespace] = (int) $timestamp; + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns the timestamp when a given namespace was last updated + * @param string $namespace + * @return mixed int/boolean + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorBase::getLastUpdateSession() + * @uses I18NtranslatorMySQL::$table + * @uses I18NtranslatorMySQL::getConn() + * @uses I18NtranslatorBase::setLastUpdateSession() + * @return mixed + */ + public function getLastUpdateDateNamespace($namespace = '') { // basically an overloaded method... + if (parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } elseif (($tmp_namespace = parent::getLastUpdateSession($namespace)) != FALSE) { + return (int) $tmp_namespace; + } // end if + + $sql = 'SELECT MAX(lastupdate)'; + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE namespace = "' . mysql_real_escape_string($namespace) . '"'; + + $result = parent::getConn()->query($sql); + $row = $result->fetch_row(); + $this->setLastUpdateSession($namespace, $row[0]); + $result->close(); + return $row[0]; + } // end function + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + */ + /** + * deletes selected values from the translation array + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorMySQL::$translation_table + * @uses I18NtranslatorBase::$namespaces + */ + protected function stripTranslationTable($string = '', $namespace = 'lang_main') { + if (parent::isFilledString($string) == FALSE || + parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } // end if + + if (isset($this->translation_table[trim($string)]) && in_array(trim($namespace), $this->namespaces)) { + unset($this->translation_table[trim($string)]); + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * deletes a translation from the given namespace for a given locale + * @param object $locale I18Nlocale + * @uses I18NtranslatorMySQL::$database + * @uses I18NtranslatorMySQL::$table + * @uses I18Nlocale::getI18Nlocale() + * @uses I18NtranslatorMySQL::getConn() + */ + protected function deleteLocaleString($string = '', $namespace = 'lang_main', I18Nlocale &$locale) { + $sql = 'UPDATE ' . $this->database . '.' . $this->table; + $sql .= ' SET `' . $locale->getI18Nlocale() . '`=NULL, lastupdate=UNIX_TIMESTAMP()'; + $sql .= ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '" AND namespace = "' . mysql_real_escape_string(trim($namespace)) . '"'; + + $result = parent::getConn()->query($sql); + if (parent::getConn()->affected_rows < 1) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + * @uses I18NtranslatorMySQLExtended::deleteLocaleString() + * @uses I18NtranslatorMySQL::getTranslatorLocale() + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main') { + $this->deleteLocaleString($string, $namespace, parent::getTranslatorLocale()); + } // end function + + /** + * deletes a translation string + translation from the given namespace for the current locale + * @uses I18NtranslatorMySQL::$database + * @uses I18NtranslatorMySQL::$table + * @uses I18NtranslatorMySQL::getConn() + */ + public function deleteTranslation($string = '', $namespace = 'lang_main') { + $sql = 'DELETE FROM ' . $this->database . '.' . $this->table; + $sql .= ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '" AND namespace = "' . mysql_real_escape_string(trim($namespace)) . '"'; + + $result = parent::getConn()->query($sql); + if (parent::getConn()->affected_rows < 1) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + * @uses I18NtranslatorMySQL::$database + * @uses I18NtranslatorMySQL::$table + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorMySQL::getConn() + * @uses I18NtranslatorMySQL::$translation_table + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $sql = 'REPLACE INTO ' . $this->database . '.' . $this->table . ' (namespace, string, lastupdate, `' . parent::getTranslatorLocale()->getI18Nlocale() . '`)'; + $sql .= ' VALUES ("' . mysql_real_escape_string(trim($namespace)) . '", "' . mysql_real_escape_string(trim($string)) . '", UNIX_TIMESTAMP(), "' . mysql_real_escape_string(trim($translation)) . '")'; + + $result = parent::getConn()->query($sql); + if (parent::getConn()->affected_rows < 1) { + return (boolean) FALSE; + } // end if + $this->translation_table[$string] = $translation; + return (boolean) TRUE; + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + * @uses I18NtranslatorMySQL::$database + * @uses I18NtranslatorMySQL::$table + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18NtranslatorMySQL::getConn() + * @uses I18NtranslatorMySQLExtended::stripTranslationTable() + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $sql = 'UPDATE ' . $this->database . '.' . $this->table; + $locale =& parent::getTranslatorLocale()->getI18Nlocale(); + + if ($position == 0) { // changes string field + $sql .= ' SET string="' . mysql_real_escape_string(trim($string)) . '", lastupdate=UNIX_TIMESTAMP()'; + $sql .= ' WHERE namespace="' . mysql_real_escape_string(trim($namespace)) . '" AND `' . $locale . '`="' . mysql_real_escape_string(trim($translation)) . '"'; + } elseif ($position == 2) { // changes translation field (default) + $sql .= ' SET namespace="' . mysql_real_escape_string(trim($namespace)) . '", lastupdate=UNIX_TIMESTAMP()'; + $sql .= ' WHERE string="' . mysql_real_escape_string(trim($string)) . '" AND `' . $locale . '`="' . mysql_real_escape_string(trim($translation)) . '"'; + } else { // changes namespace + $sql .= ' SET `' . $locale . '`="' . mysql_real_escape_string(trim($translation)) . '", lastupdate=UNIX_TIMESTAMP()'; + $sql .= ' WHERE string="' . mysql_real_escape_string(trim($string)) . '" AND namespace="' . mysql_real_escape_string(trim($namespace)) . '"'; + } // end if + + $result = parent::getConn()->query($sql); + if (parent::getConn()->affected_rows < 1) { + return (boolean) FALSE; + } // end if + $this->stripTranslationTable($string, $namespace); + return (boolean) TRUE; + } // end function + /**#@-*/ +} // end class +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..315e4e560ad450005697d0a0955d6919336ca8a9 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite.inc.php @@ -0,0 +1,184 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* singleton function for getting one db connection +* @return object +*/ +function setSQLiteConn($db) { + static $conn; + if (!isset($conn)) { + $conn = sqlite_popen($db); + } // end if + return $conn; +} // end function + +/** +* translator class with SQLite as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorSQLite extends I18NtranslatorBase implements I18NtranslatorInterface { + + /**#@+ + * @var string database settings + */ + protected $database = 'translations.sqlite'; + protected $table = 'flp_translator'; + /**#@-*/ + + /** + * @var array + */ + protected $translation_table; + + /** + * @var boolean + */ + const USE_FILECACHE = FALSE; // filecache normally is slower than using sqlite directly + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + /** + * fetches the db connection rfom the singleton function + * @uses setSQLiteConn() + * @uses I18Nbase::getI18Nsetting() + * @return resource + */ + protected function getConn() { + return setSQLiteConn(parent::getI18Nsetting('locales_path') . '/' . $this->database); + } // end function + + /** + * retreive the available translator locales + * @uses I18NtranslatorBase::$locales + * @uses I18NtranslatorSQLite::getConn() + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nbase::getI18NfactoryLocale() + * @return boolean + */ + protected function setLocales() { + $this->locales = array(); + $result = sqlite_unbuffered_query($this->getConn(), 'SELECT * FROM allfields'); // uses a view + $columns = sqlite_num_fields($result); + for ($i = 2; $i < $columns; $i++) { + $name = sqlite_field_name($result, $i); + + if (parent::isValidLocaleCode($name) == TRUE) { + $name = str_replace('_', '-', $name); + + $this->locales[$name] =& parent::getI18NfactoryLocale($name); + $_SESSION['i18n']['translator_locales'][$name] = $name; + } // end if + } // end for + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * fetch all translation files and transform them + * @uses I18NtranslatorSQLite::$use_filecache + * @uses I18Nbase::getFileCache() + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::getTranslatorLocale() + * @uses I18NtranslatorSQLite::$translation_table + * @return boolean + */ + protected function fetchAllTranslations() { + if (self::USE_FILECACHE == TRUE) { + $cache =& parent::getFileCache(); + $cache_filename = implode('_', $this->namespaces) . parent::getTranslatorLocale()->getI18Nlocale(); + if ($cache->isCached($cache_filename) == TRUE) { + $this->translation_table = unserialize($cache->returnCache($cache_filename)); + unset($cache); + return (boolean) TRUE; + } // end if + } // end if + + $sql = 'SELECT string, ' . str_replace('-', '_', parent::getTranslatorLocale()->getI18Nlocale()); + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE namespace IN ("' . implode('","', $this->namespaces) . '")'; + $sql .= ' ORDER BY string ASC'; + $result = sqlite_unbuffered_query($this->getConn(), $sql); + + while ($row = sqlite_fetch_array($result, SQLITE_NUM)) { + if ((mb_strlen($row[0]) > 0) && (mb_strlen($row[1]) > 0)) { + parent::checkForDuplicates($row[0], implode(', ', $this->namespaces)); + $this->translation_table[$row[0]] = $row[1]; + } // end if + } // end while + + if (self::USE_FILECACHE == TRUE) { + $cache->writeCache($cache_filename, serialize($this->translation_table)); + unset($cache); + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @uses I18NtranslatorSQLite::fetchAllTranslations() + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + if (!isset($this->translation_table)) { + $this->fetchAllTranslations(); + } // end if + return $this->translation_table; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18NtranslatorSQLite::getTranslationTable() + * @uses I18NtranslatorSQLite::$translation_table + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorBase::getTranslatorLocale() + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $string = trim($translationstring); + if (array_key_exists($string, $this->getTranslationTable())) { + if (!is_array($arguments)) { + return $this->translation_table[$string]; + } // end if + return vsprintf($this->translation_table[$string], $arguments); + } // end if + + $sql = 'SELECT ' . $this->getTranslatorLocale()->getI18Nlocale(); + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE string = "' . mysql_real_escape_string($string) . '"'; + $result = sqlite_query($this->getConn(), $sql); + + if (sqlite_num_rows($result) > 0 && + (($field = sqlite_fetch_single($result)) != NULL)) { + $this->translation_table[$string] = $field; + return (string) $this->translation_table[$string]; + } // end if + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $string . '" not found in translation table', E_USER_WARNING); + } // end if + return $string; + } // end function +} // end I18NtranslatorSQLite +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite3.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite3.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..3ae3d39af8cebbc25cbb13cf07c60665d7afc2af --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite3.inc.php @@ -0,0 +1,196 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* singleton function for getting one db connection +* @return object +*/ +function setSQLiteConn($db_name) { + static $conn; + if (!isset($conn)) { + $conn = new PDO('sqlite:' . $db_name); + } // end if + return $conn; +} // end function + +function getPrepStat($index, $conn, $sql = '') { + static $ps; + if (!isset($ps[$index])) { + $ps[$index] = $conn->prepare($sql); + } // end if + return $ps[$index]; +} // end function + +/** +* translator class with SQLite3 as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorSQLite3 extends I18NtranslatorBase implements I18NtranslatorInterface { + + /**#@+ + * @var string database settings + */ + protected $database = 'translations.sqlite3'; + protected $table = 'flp_translator'; + /**#@-*/ + + /** + * @var array + */ + protected $translation_table; + protected $prep_stat = array(); + + /** + * @var boolean + */ + const USE_FILECACHE = FALSE; // filecache normally is slower than using sqlite directly + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + /** + * fetches the db connection rfom the singleton function + * @uses setSQLiteConn() + * @uses I18Nbase::getI18Nsetting() + * @return resource + */ + protected function getConn() { + return setSQLiteConn(parent::getI18Nsetting('locales_path') . '/' . $this->database); + } // end function + + /** + * retreive the available translator locales + * @uses I18NtranslatorBase::$locales + * @uses I18NtranslatorSQLite3::getConn() + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nbase::getI18NfactoryLocale() + * @return boolean + */ + protected function setLocales() { + $this->locales = array(); + $ps = getPrepStat('locales', $this->getConn(), 'SELECT * FROM ' . $this->table . ' LIMIT 0,1'); + $ps->execute(); + $result = $ps->fetchAll(); + $keys = array_keys($result[0]); + foreach ($keys as $name) { + if (parent::isValidLocaleCode($name) == TRUE) { + $name = str_replace('_', '-', $name); + + $this->locales[$name] = parent::getI18NfactoryLocale($name); + $_SESSION['i18n']['translator_locales'][$name] = $name; + } // end if + } // end foreach + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * fetch all translation files and transform them + * @uses I18NtranslatorSQLite3::$use_filecache + * @uses I18Nbase::getFileCache() + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::getTranslatorLocale() + * @uses I18NtranslatorSQLite3::$translation_table + * @return boolean + */ + protected function fetchAllTranslations() { + if (self::USE_FILECACHE == TRUE) { + $cache =& parent::getFileCache(); + $cache_filename = implode('_', $this->namespaces) . parent::getTranslatorLocale()->getI18Nlocale(); + if ($cache->isCached($cache_filename) == TRUE) { + $this->translation_table = unserialize($cache->returnCache($cache_filename)); + unset($cache); + return (boolean) TRUE; + } // end if + } // end if + + $sql = 'SELECT string, ' . str_replace('-', '_', parent::getTranslatorLocale()->getI18Nlocale()); + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE namespace IN ("' . implode('","', $this->namespaces) . '")'; + $sql .= ' ORDER BY string ASC'; + $result = $this->getConn()->query($sql); + + foreach ($result as $row) { + if ((mb_strlen($row[0]) > 0) && (mb_strlen($row[1]) > 0)) { + parent::checkForDuplicates($row[0], implode(', ', $this->namespaces)); + $this->translation_table[$row[0]] = $row[1]; + } // end if + } // end foreach + + if (self::USE_FILECACHE == TRUE) { + $cache->writeCache($cache_filename, serialize($this->translation_table)); + unset($cache); + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @uses I18NtranslatorSQLite::fetchAllTranslations() + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + if (!isset($this->translation_table)) { + $this->fetchAllTranslations(); + } // end if + return $this->translation_table; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18NtranslatorSQLite3::getTranslationTable() + * @uses I18NtranslatorSQLite3::$translation_table + * @uses I18NtranslatorSQLite3::getConn() + * @uses I18NtranslatorBase::getTranslatorLocale() + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $string = trim($translationstring); + if (array_key_exists($string, $this->getTranslationTable())) { + if (!is_array($arguments)) { + return $this->translation_table[$string]; + } // end if + return vsprintf($this->translation_table[$string], $arguments); + } // end if + + $sql = 'SELECT ' . $this->getTranslatorLocale()->getI18Nlocale(); + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE string = "' . mysql_real_escape_string($string) . '"'; + + $ps = $this->getConn()->prepare($sql); // uses a view + $ex = $ps->execute(); + $result = $ps->fetch(); + + if ($ps->rowCount() > 0 && + (($field &= $result[0]) != NULL)) { + $this->translation_table[$string] = $field; + return (string) $this->translation_table[$string]; + } // end if + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $string . '" not found in translation table', E_USER_WARNING); + } // end if + return $string; + } // end function +} // end I18NtranslatorSQLite3 +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite3Extended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite3Extended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..170b55110ab62288e4bc98c5fa43a86ebcb372dd --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLite3Extended.inc.php @@ -0,0 +1,239 @@ +<?php +/** +* required interface for all translatorXXXExtended classes +*/ +require_once 'interface.I18NtranslatorInterfaceExtended.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* extended translator class with SQLite as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorSQLite3Extended extends I18NtranslatorSQLite3 implements I18NtranslatorInterfaceExtended { + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorSQLite::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * writes the last update timestamp to the session + * @param string $namespace + * @param int $timestamp + * @uses I18NtranslatorBase::getLocales() + * @return boolean + */ + protected function setLastUpdateSession($namespace = '', $timestamp = 0) { + $locales =& $this->getLocales(); + foreach ($locales as $locale => &$object) { + $_SESSION['i18n']['settings']['last_update'][$locale][$namespace] = (int) $timestamp; + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns the timestamp when a given namespace was last updated + * @param string $namespace + * @return mixed int/boolean + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorBase::getLastUpdateSession() + * @uses I18NtranslatorSQLite::$table + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorBase::setLastUpdateSession() + * @return mixed + */ + public function getLastUpdateDateNamespace($namespace = '') { + if (parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } elseif (($tmp_namespace = parent::getLastUpdateSession($namespace)) != FALSE) { + return (int) $tmp_namespace; + } // end if + + $sql = 'SELECT MAX(lastupdate)'; + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE namespace = "' . mysql_real_escape_string($namespace) . '"'; + + $result = parent::getConn()->query($sql); + if (!$result) { + return (boolean) FALSE; + } // end if + + foreach ($result as $row) { + if (isset($row[0]) && !is_bool($row[0]) && + ($lastchange = $row[0]) != NULL) { + parent::setLastUpdateSession($namespace, $lastchange); + return (int) $lastchange; + } // end if + } // end foreach + + return (boolean) FALSE; + } // end function + + /** + * checks if a string is in the database + * @param string $string + * @uses I18NtranslatorSQLite::$table + * @uses I18NtranslatorSQLite::getConn() + * @return boolean + */ + protected function stringInDatabase($string = '') { + $query = (string) 'SELECT COUNT(*)'; + $query .= (string) ' FROM ' . $this->table; + $query .= (string) ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '"'; + $result = parent::getConn()->query($sql); + foreach ($result as $row) { + return (boolean) (!isset($row[0])) ? FALSE : TRUE; + } // end if + return FALSE; + } // end function + + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + */ + /** + * deletes selected values from the translation array + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorSQLite::$translation_table + * @uses I18NtranslatorBase::$namespaces + */ + protected function stripTranslationTable($string = '', $namespace = 'lang_main') { + if (parent::isFilledString($string) == FALSE || + parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } // end if + + if (isset($this->translation_table[trim($string)]) && in_array(trim($namespace), $this->namespaces)) { + unset($this->translation_table[trim($string)]); + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * deletes a translation from the given namespace for a given locale + * @param object $locale I18Nlocale + * @uses I18NtranslatorSQLite::$table + * @uses I18Nlocale::getI18Nlocale() + * @uses I18NtranslatorSQLite::getConn() + */ + protected function deleteLocaleString($string = '', $namespace = 'lang_main', I18Nlocale &$locale) { + $locale_s = str_replace('-', '_', $locale->getI18Nlocale()); + $sql = 'UPDATE ' . $this->table; + $sql .= ' SET ' . $locale_s . '=NULL, lastupdate=' . time(); + $sql .= ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '" AND namespace = "' . mysql_real_escape_string(trim($namespace)) . '"'; + $result = parent::getConn()->query($sql); + + if (!$result) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + * @uses I18NtranslatorSQLiteExtended::deleteLocaleString() + * @uses I18NtranslatorSQLite::getTranslatorLocale() + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main') { + $this->deleteLocaleString($string, $namespace, parent::getTranslatorLocale()); + } // end function + + /** + * deletes a translation string + translation from the given namespace for the current locale + * @uses I18NtranslatorSQLite::$table + * @uses I18NtranslatorSQLite::getConn() + */ + public function deleteTranslation($string = '', $namespace = 'lang_main') { + $sql = 'DELETE FROM ' . $this->table; + $sql .= ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '" AND namespace = "' . mysql_real_escape_string(trim($namespace)) . '"'; + $result = parent::getConn()->query($sql); + + if (!$result) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + * @uses I18NtranslatorSQLite::$table + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorSQLite::$translation_table + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $locale = str_replace('-', '_', parent::getTranslatorLocale()->getI18Nlocale()); + $sql = 'REPLACE INTO ' . $this->table . ' (namespace, string, lastupdate, ' . $locale . ')'; + $sql .= ' VALUES ("' . mysql_real_escape_string(trim($namespace)) . '", "' . mysql_real_escape_string(trim($string)) . '", ' . time() . ', "' . mysql_real_escape_string(trim($translation)) . '")'; + $result = parent::getConn()->query($sql); + + if (!$result) { + return (boolean) FALSE; + } // end if + + $this->translation_table[trim($string)] = (string) trim($translation); + return (boolean) TRUE; + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change translation; 0 = change string + * @uses I18NtranslatorSQLite::$table + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorSQLiteExtended::stripTranslationTable() + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $query = (string) 'UPDATE ' . $this->table; + $locale = str_replace('-', '_', parent::getTranslatorLocale()->getI18Nlocale()); + + if ($position == 0) { // changes string field + $query .= ' SET string="' . mysql_real_escape_string(trim($string)) . '", lastupdate=' . time(); + $query .= ' WHERE namespace="' . mysql_real_escape_string(trim($namespace)) . '" AND ' . $locale . '="' . mysql_real_escape_string(trim($translation)) . '"'; + } elseif ($position == 2) { // changes namespace + $query .= ' SET namespace="' . mysql_real_escape_string(trim($namespace)) . '", lastupdate=' . time(); + $query .= ' WHERE string="' . mysql_real_escape_string(trim($string)) . '" AND ' . $locale . '="' . mysql_real_escape_string(trim($translation)) . '"'; + } else { // changes translation field (default) + $query .= ' SET ' . $locale . '="' . mysql_real_escape_string(trim($translation)) . '", lastupdate=' . time(); + $query .= ' WHERE string="' . mysql_real_escape_string(trim($string)) . '" AND namespace="' . mysql_real_escape_string(trim($namespace)) . '"'; + } // end if + $result = parent::getConn()->query($query); + + if (!$result) { + return (boolean) FALSE; + } // end if + + $this->stripTranslationTable($string, $namespace); + return (boolean) TRUE; + } // end function + /**#@-*/ +} // end I18NtranslatorSQLite3Extended +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLiteExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLiteExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..d72fea9eafb6f969cfc64b474647887be8c49df7 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorSQLiteExtended.inc.php @@ -0,0 +1,233 @@ +<?php +/** +* required interface for all translatorXXXExtended classes +*/ +require_once 'interface.I18NtranslatorInterfaceExtended.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* extended translator class with SQLite as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorSQLiteExtended extends I18NtranslatorSQLite implements I18NtranslatorInterfaceExtended { + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorSQLite::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * writes the last update timestamp to the session + * @param string $namespace + * @param int $timestamp + * @uses I18NtranslatorBase::getLocales() + * @return boolean + */ + protected function setLastUpdateSession($namespace = '', $timestamp = 0) { + $locales =& $this->getLocales(); + foreach ($locales as $locale => &$object) { + $_SESSION['i18n']['settings']['last_update'][$locale][$namespace] = (int) $timestamp; + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns the timestamp when a given namespace was last updated + * @param string $namespace + * @return mixed int/boolean + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorBase::getLastUpdateSession() + * @uses I18NtranslatorSQLite::$table + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorBase::setLastUpdateSession() + * @return mixed + */ + public function getLastUpdateDateNamespace($namespace = '') { + if (parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } elseif (($tmp_namespace = parent::getLastUpdateSession($namespace)) != FALSE) { + return (int) $tmp_namespace; + } // end if + + $sql = 'SELECT MAX(lastupdate)'; + $sql .= ' FROM ' . $this->table; + $sql .= ' WHERE namespace = "' . mysql_real_escape_string($namespace) . '"'; + + $result = @sqlite_query(parent::getConn(), $sql); + if (!$result) { + return (boolean) FALSE; + } // end if + + if (!is_bool($result) && sqlite_num_rows($result) > 0 && + ($lastchange = sqlite_fetch_single($result)) != NULL) { + parent::setLastUpdateSession($namespace, $lastchange); + return (int) $lastchange; + } // end if + return (boolean) FALSE; + } // end function + + /** + * checks if a string is in the database + * @param string $string + * @uses I18NtranslatorSQLite::$table + * @uses I18NtranslatorSQLite::getConn() + * @return boolean + */ + protected function stringInDatabase($string = '') { + $query = (string) 'SELECT COUNT(*)'; + $query .= (string) ' FROM ' . $this->table; + $query .= (string) ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '"'; + $result = @sqlite_query(parent::getConn(), $query); + return (boolean) (!$result || sqlite_fetch_single($result) < 1) ? FALSE : TRUE; + } // end function + + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + */ + /** + * deletes selected values from the translation array + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorSQLite::$translation_table + * @uses I18NtranslatorBase::$namespaces + */ + protected function stripTranslationTable($string = '', $namespace = 'lang_main') { + if (parent::isFilledString($string) == FALSE || + parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } // end if + + if (isset($this->translation_table[trim($string)]) && in_array(trim($namespace), $this->namespaces)) { + unset($this->translation_table[trim($string)]); + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * deletes a translation from the given namespace for a given locale + * @param object $locale I18Nlocale + * @uses I18NtranslatorSQLite::$table + * @uses I18Nlocale::getI18Nlocale() + * @uses I18NtranslatorSQLite::getConn() + */ + protected function deleteLocaleString($string = '', $namespace = 'lang_main', I18Nlocale &$locale) { + $locale_s = str_replace('-', '_', $locale->getI18Nlocale()); + $sql = 'UPDATE ' . $this->table; + $sql .= ' SET ' . $locale_s . '=NULL, lastupdate=' . time(); + $sql .= ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '" AND namespace = "' . mysql_real_escape_string(trim($namespace)) . '"'; + $result = @sqlite_query(parent::getConn(), $sql); + + if (!$result) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + * @uses I18NtranslatorSQLiteExtended::deleteLocaleString() + * @uses I18NtranslatorSQLite::getTranslatorLocale() + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main') { + $this->deleteLocaleString($string, $namespace, parent::getTranslatorLocale()); + } // end function + + /** + * deletes a translation string + translation from the given namespace for the current locale + * @uses I18NtranslatorSQLite::$table + * @uses I18NtranslatorSQLite::getConn() + */ + public function deleteTranslation($string = '', $namespace = 'lang_main') { + $sql = 'DELETE FROM ' . $this->table; + $sql .= ' WHERE string = "' . mysql_real_escape_string(trim($string)) . '" AND namespace = "' . mysql_real_escape_string(trim($namespace)) . '"'; + $result = @sqlite_query(parent::getConn(), $sql); + + if (!$result) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + * @uses I18NtranslatorSQLite::$table + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorSQLite::$translation_table + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $locale = str_replace('-', '_', parent::getTranslatorLocale()->getI18Nlocale()); + $sql = 'REPLACE INTO ' . $this->table . ' (namespace, string, lastupdate, ' . $locale . ')'; + $sql .= ' VALUES ("' . mysql_real_escape_string(trim($namespace)) . '", "' . mysql_real_escape_string(trim($string)) . '", ' . time() . ', "' . mysql_real_escape_string(trim($translation)) . '")'; + $result = @sqlite_query(parent::getConn(), $query); + + if (!$result) { + return (boolean) FALSE; + } // end if + + $this->translation_table[trim($string)] = (string) trim($translation); + return (boolean) TRUE; + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + * @uses I18NtranslatorSQLite::$table + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18NtranslatorSQLite::getConn() + * @uses I18NtranslatorSQLiteExtended::stripTranslationTable() + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $query = (string) 'UPDATE ' . $this->table; + $locale = str_replace('-', '_', parent::getTranslatorLocale()->getI18Nlocale()); + + if ($position == 0) { // changes string field + $query .= ' SET string="' . mysql_real_escape_string(trim($string)) . '", lastupdate=' . time(); + $query .= ' WHERE namespace="' . mysql_real_escape_string(trim($namespace)) . '" AND ' . $locale . '="' . mysql_real_escape_string(trim($translation)) . '"'; + } elseif ($position == 2) { // changes namespace + $query .= ' SET namespace="' . mysql_real_escape_string(trim($namespace)) . '", lastupdate=' . time(); + $query .= ' WHERE string="' . mysql_real_escape_string(trim($string)) . '" AND ' . $locale . '="' . mysql_real_escape_string(trim($translation)) . '"'; + } else { // changes translation field (default) + $query .= ' SET ' . $locale . '="' . mysql_real_escape_string(trim($translation)) . '", lastupdate=' . time(); + $query .= ' WHERE string="' . mysql_real_escape_string(trim($string)) . '" AND namespace="' . mysql_real_escape_string(trim($namespace)) . '"'; + } // end if + $result = @sqlite_query(parent::getConn(), $query); + + if (!$result || sqlite_changes(parent::getConn()) < 1) { + return (boolean) FALSE; + } // end if + + $this->stripTranslationTable($string, $namespace); + return (boolean) TRUE; + } // end function + /**#@-*/ +} // end I18NtranslatorSQLiteExtended +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorText.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorText.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..89cf75af83531917d9279b0fe7a5481483c0ce8b --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorText.inc.php @@ -0,0 +1,229 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* translator class with flat utf8-textfiles as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorText extends I18NtranslatorBase implements I18NtranslatorInterface { + + /** + * @var boolean + */ + const USE_FILECACHE = TRUE; + + /**#@+ + * @var string + */ + protected $ext = 'inc'; + protected $delimiter = ' = '; + /**#@-*/ + + /** + * @var array + */ + protected $translation_table; + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * returns path to a translationfile + * @param string $namespaces + * @uses I18Nbase::getI18Nsetting() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18NtranslatorText::$ext + * @return boolean + */ + protected function getNamespaceFilepath($namespace = '') { + return (string) parent::getI18Nsetting('locales_path') . '/' . parent::getTranslatorLocale()->getI18Nlocale() . '/' . $namespace . '.' . $this->ext; + } // end function + + /** + * retreive the available translator locales + * @uses I18Nbase::getI18Nsetting() + * @uses I18NtranslatorBase::getSessionLocales() + * @uses I18NtranslatorText::setRealLocale() + * @uses I18NtranslatorBase::$locales + * @return boolean + */ + protected function setLocales() { + if (parent::getSessionLocales() == TRUE) { + return (boolean) TRUE; + } // end if + + $this->locales = array(); + $root = parent::getI18Nsetting('locales_path') . '/'; + $handle = @opendir($root); + while ($lang_dir = trim(@readdir($handle))) { + if (!is_dir($root . $lang_dir) || + parent::isValidLocaleCode($lang_dir) === FALSE) { + continue; + } // end if + $lang_dir = strtolower($lang_dir); + $this->locales[$lang_dir] =& $this->setRealLocale($lang_dir); + $_SESSION['i18n']['translator_locales'][$lang_dir] = $this->locales[$lang_dir]->getI18Nlocale(); + } // end while + @closedir($handle); + unset($root, $handle); + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * retreive the real locale for an alias + * @param string $locale_code + * @uses I18Nbase::getI18Nsetting() + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Nbase::isValidLocaleCode() + * @return object + */ + protected function setRealLocale($locale_code = '') { + $path = parent::getI18Nsetting('locales_path') . '/' . $locale_code . '/redirect'; + if (parent::getI18Nsetting('use_alias_locales') === FALSE || + ($redirect_file = @file($path)) == FALSE) { + return parent::getI18NfactoryLocale($locale_code); + } // end if + + if (parent::isValidLocaleCode($redirect_file[0]) === TRUE) { + return parent::getI18NfactoryLocale($redirect_file[0]); + } // end if + return parent::getI18NfactoryLocale($locale_code); + } // end function + + /** + * fetch the translation file + * @param string $namespace + * @uses I18NtranslatorText::getNamespaceFilepath() + * @return mixed + */ + protected function fetchTranslationFile($namespace = '') { + if (($file = file($this->getNamespaceFilepath($namespace))) == FALSE) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: File "' . $this->getNamespaceFilepath($namespace) . '" not found ', E_USER_WARNING); + } // end if + return (boolean) FALSE; + } // end if + return $file; + } // end function + + /** + * transform filecontent into translation array + * @param string $namespace + * @uses I18NtranslatorText::fetchTranslationFile() + * @uses I18NtranslatorText::$delimiter + * @uses I18NtranslatorText::$translation_table + * @return void + */ + protected function fetchTranslations($namespace = '') { + $file = $this->fetchTranslationFile($namespace); + if ($file == FALSE) { + return (boolean) FALSE; + } // end if + $file = array_filter(array_map('trim', $file), 'strlen'); + foreach ($file as $line) { + $tmp = explode($this->delimiter, $line); + if (count($tmp) < 2) { + continue; + } // end if + list($string, $translation) = $tmp; + $string = trim($string); + $translation = trim($translation); + if (mb_strlen($string) === 0 || mb_strlen($translation) === 0) { + continue; + } // end if + parent::checkForDuplicates($string, $namespace); + $this->translation_table[$string] = $translation; + } // end foreach + } // end function + + /** + * fetch all translation files and transform them + * @uses I18Nbase::getFileCache() + * @uses self::$use_filecache + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::getTranslatorLocale() + * @uses I18NtranslatorText::$translation_table + * @uses I18NtranslatorText::fetchTranslations() + * @return boolean + */ + protected function fetchAllTranslations() { + if (self::USE_FILECACHE == TRUE) { + $cache =& parent::getFileCache(); + $cache_filename = implode('_', $this->namespaces) . parent::getTranslatorLocale()->getI18Nlocale(); + if ($cache->isCached($cache_filename) == TRUE) { + $this->translation_table = unserialize($cache->returnCache($cache_filename)); + unset($cache); + return (boolean) TRUE; + } // end if + } // end if + + foreach ($this->namespaces as $namespace) { + $this->fetchTranslations($namespace); + } // end foreach + ksort($this->translation_table); + //$this->translation_table = array_unique($this->translation_table); + + if (self::USE_FILECACHE == TRUE) { + $cache->writeCache($cache_filename, serialize($this->translation_table)); + unset($cache); + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @uses I18NtranslatorText::fetchAllTranslations() + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + if (!isset($this->translation_table)) { + $this->fetchAllTranslations(); + } // end if + return $this->translation_table; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18NtranslatorText::getTranslationTable() + * @uses I18NtranslatorText::$translation_table + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $string = trim($translationstring); + if (!array_key_exists($string, $this->getTranslationTable())) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $string . '" not found in translation table', E_USER_WARNING); + } // end if + return $string; + } // end if + + if (!is_array($arguments)) { + return $this->translation_table[$string]; + } // end if + return vsprintf($this->translation_table[$string], $arguments); + } // end function +} // end TranslatorText +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorTextExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorTextExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..eafa23cd01f031752f2418d42764d84185b88cf8 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorTextExtended.inc.php @@ -0,0 +1,245 @@ +<?php +/** +* required interface for all translatorXXXExtended classes +*/ +require_once 'interface.I18NtranslatorInterfaceExtended.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* extended translator class with flat utf8-textfiles as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorTextExtended extends I18NtranslatorText implements I18NtranslatorInterfaceExtended { + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorText::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * returns the timestamp when a given namespace was last updated + * @param string $namespace + * @return mixed int/boolean + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorBase::getLastUpdateSession() + * @uses I18NtranslatorText::getNamespaceFilepath() + * @uses I18NtranslatorBase::setLastUpdateSession() + */ + public function getLastUpdateDateNamespace($namespace = '') { // basically an overloaded method... + if (parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } elseif (($tmp_namespace = parent::getLastUpdateSession($namespace)) != FALSE) { + return (int) $tmp_namespace; + } // end if + + if (($lastchange = @filemtime(parent::getNamespaceFilepath($namespace))) != FALSE) { + parent::setLastUpdateSession($namespace, $lastchange); + return (int) $lastchange; + } // end if + return (boolean) FALSE; + } // end function + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + */ + /** + * deletes selected values from the translation array + * @uses I18NtranslatorText::$translation_table + * @uses I18NtranslatorBase::$namespaces + */ + protected function stripTranslationTable($string = '', $namespace = 'lang_main') { + if (isset($this->translation_table[trim($string)]) && in_array(trim($namespace), $this->namespaces)) { + unset($this->translation_table[trim($string)]); + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * deletes a translation from the given namespace for a given locale + * @param object $locale I18Nlocale + * @uses I18NtranslatorText::$delimiter + * @uses I18NtranslatorText::$ext + * @uses I18NtranslatorText::fetchTranslationFile() + * @uses I18Nbase::getI18Nsetting() + * @uses I18Nlocale::getI18Nlocale() + * @uses I18NtranslatorText::stripTranslationTable() + * @uses I18NtranslatorBase::getTranslatorLocale() + */ + protected function deleteLocaleString($string = '', $namespace = 'lang_main', I18Nlocale &$locale) { + $found = (boolean) FALSE; + $string_i = trim($string) . $this->delimiter; + $file = parent::fetchTranslationFile($namespace); + + if ($file == FALSE) { + return (boolean) FALSE; + } // end if + + foreach ($file as $line) { + $startstring = mb_substr($line, 0, mb_strlen($string_i)); + if ($startstring === $string_i) { + $found = (boolean) TRUE; + continue; + } elseif (mb_strlen(trim($line)) === 0) { + continue; + } // end if + $returnfile[] = $line; + } // end foreach + + if ($found === FALSE) { + unset($returnfile); + return (boolean) FALSE; + } // end if + + $filepath = parent::getI18Nsetting('locales_path') . '/' . $locale->getI18Nlocale() . '/' . $namespace . '.' . $this->ext; + $handle = @fopen($filepath, 'w'); + if (!$handle) { + return (boolean) FALSE; + } // end if + @fputs($handle, implode("\n",$returnfile)); + @fclose($handle); + if ($locale->getI18Nlocale() == $this->getTranslatorLocale()->getI18Nlocale()) { + $this->stripTranslationTable($string, $namespace); + } // end if + return (boolean) TRUE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for the current locale + * @uses I18NtranslatorTextExtended::deleteLocaleString() + * @uses I18NtranslatorBase::getTranslatorLocale() + */ + public function deleteTranslation($string = '', $namespace = 'lang_main') { + if ($this->deleteLocaleString($string, $namespace, $this->getTranslatorLocale()) === TRUE) { + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + * @uses I18NtranslatorText::setLocales() + * @uses I18NtranslatorTextExtended::deleteLocaleString() + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main') { + if (!isset($this->locales)) { + $this->setLocales(); + } // end if + $error = (boolean) FALSE; + foreach ($this->locales as $locale) { + if ($this->deleteLocaleString($string, $namespace, $locale) === FALSE) { + $error = (boolean) TRUE; + } // end if + } // end foreach + return (boolean) (($error === TRUE) ? FALSE : TRUE); + } // end function + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorText::fetchTranslationFile() + * @uses I18NtranslatorText::getNamespaceFilepath() + * @uses I18NtranslatorText::$translation_table + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + $string_i = trim($string) . $this->delimiter; + $file = parent::fetchTranslationFile($namespace); + foreach ($file as $line) { + $startstring = mb_substr($line, 0, mb_strlen($string_i)); + if ($startstring === $string_i) { + return (boolean) FALSE; + } // end if + } // end foreach + $handle = @fopen(parent::getNamespaceFilepath($namespace), 'a'); + if (!$handle) { + return (boolean) FALSE; + } // end if + @fputs($handle, "\n" . $string_i . trim($translation)); + @fclose($handle); + $this->translation_table[trim($string)] = trim($translation); + return (boolean) TRUE; + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + * @uses I18Nbase::validTranslationInput() + * @uses I18NtranslatorText::$translation_table + * @uses I18NtranslatorText::fetchTranslations() + * @uses I18NtranslatorText::getNamespaceFilepath() + * @uses I18NtranslatorText::$delimiter + * @uses I18NtranslatorTextExtended::deleteTranslationString() + * @uses I18NtranslatorTextExtended::addTranslation() + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + if (parent::validTranslationInput($string, $translation, $namespace) === FALSE) { + return (boolean) FALSE; + } // end if + + if ($position < 2) { // change translation or string + if (isset($this->translation_table)) { + unset($this->translation_table); + } // end if + parent::fetchTranslations($namespace); + $content = $this->translation_table; + + if (($position == 1 && !isset($content[$string])) || + ($position == 0 && !in_array($translation, $content))) { + return (boolean) FALSE; + } // end if + + if ($position == 1) { + $content[trim($string)] = trim($translation); + } elseif ($position == 0) { + $tmp = array_flip($content); + $tmp[trim($translation)] = trim($string); + $content = array_flip($tmp); + } // end if + + $handle = @fopen(parent::getNamespaceFilepath($namespace), 'w'); + if (!$handle) { + return (boolean) FALSE; + } // end if + + foreach ($content as $string => $translation) { + $returnfile[] = $string . $this->delimiter . $translation; + } // end if + + @fputs($handle, implode("\n",$returnfile)); + @fclose($handle); + return (boolean) TRUE; + } // end if + + foreach ($this->namespaces as $current_namespace) { + $this->deleteTranslationString($string, $current_namespace); + } // end foreach + if ($this->addTranslation($string, $translation, $namespace) == FALSE) { + return (boolean) FALSE; + } // end if + return (boolean) TRUE; + } // end function + /**#@-*/ +} // end TranslatorText +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorXML.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorXML.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..65eda48d458235dc2394631d21a2faeb5db67e4f --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorXML.inc.php @@ -0,0 +1,234 @@ +<?php +/** +* required interface for all translatorXXX classes +*/ +require_once 'interface.I18NtranslatorInterface.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* translator class with xml-files as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorXML extends I18NtranslatorBase implements I18NtranslatorInterface { + + /** + * @var boolean + */ + const USE_FILECACHE = FALSE; + + /**#@+ + * @var array + */ + protected $translation_table; + protected $xmlfiles; + /**#@-*/ + + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorBase::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * returns path to a translationfile + * @param string $namespaces + * @uses I18Nbase::getI18Nsetting() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @return boolean + */ + protected function getNamespaceFilepath($namespace = '') { + return (string) parent::getI18Nsetting('locales_path') . '/' . parent::getTranslatorLocale()->getI18Nlocale() . '/' . $namespace . '.xml'; + } // end function + + /** + * retreive the available translator locales + * @uses I18Nbase::getI18Nsetting() + * @uses I18NtranslatorBase::getSessionLocales() + * @uses I18NtranslatorXML::setRealLocale() + * @uses I18NtranslatorBase::$locales + * @return boolean + */ + protected function setLocales() { + if (parent::getSessionLocales() == TRUE) { + return (boolean) TRUE; + } // end if + + $this->locales = array(); + $root = parent::getI18Nsetting('locales_path') . '/'; + $handle = @opendir($root); + while ($lang_dir = trim(@readdir($handle))) { + if (!is_dir($root . $lang_dir) || + parent::isValidLocaleCode($lang_dir) === FALSE) { + continue; + } // end if + $lang_dir = strtolower($lang_dir); + $this->locales[$lang_dir] =& $this->setRealLocale($lang_dir); + $_SESSION['i18n']['translator_locales'][$lang_dir] = $this->locales[$lang_dir]->getI18Nlocale(); + } // end while + @closedir($handle); + unset($root, $handle); + return (count($this->locales) > 0) ? TRUE : FALSE; + } // end function + + /** + * retreive the real locale for an alias + * @param string $locale_code + * @uses I18Nbase::getI18Nsetting() + * @uses I18Nbase::getI18NfactoryLocale() + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nbase::getI18NfactoryLocale() + * @return object + */ + protected function setRealLocale($locale_code = '') { + $path = parent::getI18Nsetting('locales_path') . '/' . $locale_code . '/redirect'; + if (parent::getI18Nsetting('use_alias_locales') === FALSE || + ($redirect_file = @file($path)) == FALSE) { + return parent::getI18NfactoryLocale($locale_code); + } // end if + + if (parent::isValidLocaleCode($redirect_file[0]) === TRUE) { + return parent::getI18NfactoryLocale($redirect_file[0]); + } // end if + return parent::getI18NfactoryLocale($locale_code); + } // end function + + /** + * fetch the translation file + * @param string $namespace + * @uses I18NtranslatorXML::getNamespaceFilepath() + * @return mixed + */ + protected function fetchTranslationFile($namespace = '') { + if (($file = simplexml_load_file($this->getNamespaceFilepath($namespace))) == FALSE) { + return (boolean) FALSE; + } // end if + return $file; + } // end function + + /** + * transform filecontent into translation array + * @param string $namespace + * @uses I18NtranslatorXML::fetchTranslationFile() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18NtranslatorXML::$translation_table + * @return void + */ + protected function fetchTranslations($namespace = '') { + $file = $this->fetchTranslationFile($namespace); + if ($file == FALSE) { + return (boolean) FALSE; + } // end if + + $this->xmlfiles[$namespace] = $file; + + foreach ($this->xmlfiles[$namespace]->locale as $locale) { + if ($locale['id'] != parent::getTranslatorLocale()->getI18Nlocale()) { + continue; + } // end if + + foreach ($locale->namespace as $namespace_tmp) { + if ($namespace_tmp['id'] != $namespace) { + continue; + } // end if + + foreach ($namespace_tmp->translations as $translations) { + foreach ($translations->translation as $translation) { + if (mb_strlen($translation['string']) == 0) { + // cant do mb_strlen on $translation --> apache crash + continue; + } // end if + + parent::checkForDuplicates(trim($translation['string']), $namespace); + $this->translation_table[trim($translation['string'])] = trim($translation); + } // end foreach + } // end foreach + } // end foreach + } // end foreach + } // end function + + /** + * fetch all translation files and transform them + * @uses I18Nbase::getFileCache() + * @uses I18NtranslatorXML::$use_filecache + * @uses I18NtranslatorBase::$namespaces + * @uses I18Nbase::getTranslatorLocale() + * @uses I18NtranslatorXML::$translation_table + * @uses I18NtranslatorXML::fetchTranslations() + * @return boolean + */ + protected function fetchAllTranslations() { + if (self::USE_FILECACHE == TRUE) { + $cache =& parent::getFileCache(); + $cache_filename = implode('_', $this->namespaces) . parent::getTranslatorLocale()->getI18Nlocale(); + if ($cache->isCached($cache_filename) === TRUE) { + $this->translation_table = unserialize($cache->returnCache($cache_filename)); + unset($cache); + return (boolean) TRUE; + } // end if + } // end if + + foreach ($this->namespaces as $namespace) { + $this->fetchTranslations($namespace); + } // end foreach + + $this->translation_table = array_filter(array_map('trim', $this->translation_table), 'strlen'); + ksort($this->translation_table); + //$this->translation_table = array_unique($this->translation_table); + + if (self::USE_FILECACHE == TRUE) { + $cache->writeCache($cache_filename, serialize($this->translation_table)); + unset($cache); + } // end if + return (boolean) TRUE; + } // end function + + /** + * returns an array with $array[translationstring] = translation + * @uses I18NtranslatorXML::fetchAllTranslations() + * @return array $array[translationstring] = translation + */ + public function getTranslationTable() { + if (!isset($this->translation_table)) { + $this->fetchAllTranslations(); + } // end if + return $this->translation_table; + } // end function + + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + * @uses I18NtranslatorXML::getTranslationTable() + * @uses I18NtranslatorXML::$translation_table + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE) { + $string = trim($translationstring); + if (!array_key_exists($string, $this->getTranslationTable())) { + if (parent::getI18Nsetting('show_errormessages')) { + trigger_error('TRANSLATION ERROR: String "' . $string . '" not found in translation table', E_USER_WARNING); + } // end if + return $string; + } // end if + + if (!is_array($arguments)) { + return $this->translation_table[$string]; + } // end if + return vsprintf($this->translation_table[$string], $arguments); + } // end function +} // end TranslatorText +?> diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorXMLExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorXMLExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..09581ed406689549207ef1da47cf40be74c6272f --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18NtranslatorXMLExtended.inc.php @@ -0,0 +1,131 @@ +<?php +/** +* required interface for all translatorXXXExtended classes +*/ +require_once 'interface.I18NtranslatorInterfaceExtended.inc.php'; +/** +* load base class which takes care of all the other includes via it's autoload function +*/ +require_once 'class.I18Nbase.inc.php'; + +/** +* extedned translator class with xml-files as a backend +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NtranslatorTextExtended extends I18NtranslatorText implements I18NtranslatorInterfaceExtended { + /** + * @param string $namespaces + * @param object $locale I18Nlocale + * @uses I18NtranslatorText::__construct() + * @return void + */ + public function __construct($namespaces = '', I18Nlocale &$locale = NULL) { + parent::__construct($namespaces, $locale); + } // end constructor + + /** + * returns the timestamp when a given namespace was last updated + * @param string $namespace + * @return mixed int/boolean + * @uses I18Nbase::isFilledString() + * @uses I18NtranslatorBase::getLastUpdateSession() + * @uses I18NtranslatorBase::getTranslatorLocale() + * @uses I18NtranslatorBase::setLastUpdateSession() + * @deprecated not yet implemented + */ + public function getLastUpdateDateNamespace($namespace = '') { // basically an overloaded method... + if (parent::isFilledString($namespace) == FALSE) { + return (boolean) FALSE; + } elseif (($tmp_namespace = parent::getLastUpdateSession($namespace)) != FALSE) { + return (int) $tmp_namespace; + } // end if + + foreach ($this->xmlfiles as $namespace => $file) { + foreach ($file->locale as $locale) { + if ($locale['id'] != parent::getTranslatorLocale()->getI18Nlocale()) { + continue; + } // end if +/* + $max = 0; + foreach ($locale->namespace as $namespace) { + parent::setLastUpdateSession($namespace['id'], lastchange); + $max = (lastchange > $max) ? lastchange : $max; + } // end foreach +*/ + return (int) $max; + } // end foreach + } // end if + return (boolean) FALSE; + } // end function + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + * @deprecated not yet implemented + */ + /** + * deletes selected values from the translation array + * @uses I18NtranslatorText::$translation_table + * @uses I18NtranslatorBase::$namespaces + */ + protected function stripTranslationTable($string = '', $namespace = 'lang_main') { + if (isset($this->translation_table[trim($string)]) && in_array(trim($namespace), $this->namespaces)) { + unset($this->translation_table[trim($string)]); + return (boolean) TRUE; + } // end if + return (boolean) FALSE; + } // end function + + /** + * deletes a translation from the given namespace for a given locale + * @param object $locale I18Nlocale + */ + protected function deleteLocaleString($string = '', $namespace = 'lang_main', I18Nlocale &$locale) { + die('Not implemented yet'); + return (boolean) FALSE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for the current locale + */ + public function deleteTranslation($string = '', $namespace = 'lang_main') { + die('Not implemented yet'); + return (boolean) FALSE; + } // end function + + /** + * deletes a translation string + translation from the given namespace for ALL locales + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main') { + die('Not implemented yet'); + return (boolean) FALSE; + } // end function + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main') { + die('Not implemented yet'); + return (boolean) FALSE; + } // end function + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 1) { + die('Not implemented yet'); + return (boolean) FALSE; + } // end function + /**#@-*/ +} // end TranslatorText +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nuser.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nuser.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..ef5caff5a55cb8e4057a24be1ad215fa9ea26ef3 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/class.I18Nuser.inc.php @@ -0,0 +1,223 @@ +<?php +/** +* holds preffered locale information about a user; takes care of setting and getting SESSION/COOKIE data +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +class I18NUser extends I18Nbase { + + /** + * @var boolean whether to use cookies or not + */ + const USE_COOKIES = TRUE; + + /** + * @var int how long should the cookie last + */ + const COOKIE_TIME = 31536000; + + /**#@+ + * @var string + */ + protected $pref_locale; + protected $pref_country; + protected $pref_language; + /**#@-*/ + + /**#@+ + * @var int + */ + protected $pref_measure_system; + protected $pref_time_format; + protected $pref_highlight_specialwords; + /**#@-*/ + + /** + * @var array + */ + protected $user_settings; + + /** + * @uses I18Nbase::__construct() + * @return void + */ + public function __construct() { + parent::__construct(); + } // end constructor + + /** + * gets the user settings from the session/cookie + * @uses I18Nuser::$user_settings + * @uses self::$use_cookies + * @uses I18Nbase::isFilledString() + * @return boolean + */ + protected function readUserSettings() { + if (isset($this->user_settings)) { + return (boolean) TRUE; + } // end if + + $this->user_settings = array(); + + if (isset($_SESSION['i18n']['settings']['user'])) { + $this->user_settings =& $_SESSION['i18n']['settings']['user']; + } elseif (self::USE_COOKIES == TRUE) { + $vars = array('pref_locale', 'pref_language', 'pref_country', + 'pref_measure_system', 'pref_time_format', + 'pref_highlight_specialwords'); + + foreach ($vars as $var) { + if (isset($_COOKIE[$var]) && parent::isFilledString($_COOKIE[$var]) == TRUE) { + $_SESSION['i18n']['settings']['user'][$var] = $_COOKIE[$var]; + } // end if + } // end foreach + $this->user_settings =& $_SESSION['i18n']['settings']['user']; + } // end if + + $this->pref_locale =& $this->user_settings['pref_locale']; + $this->pref_language =& $this->user_settings['pref_language']; + $this->pref_country =& $this->user_settings['pref_country']; + $this->pref_measure_system =& $this->user_settings['pref_measure_system']; + $this->pref_time_format =& $this->user_settings['pref_time_format']; + $this->pref_highlight_specialwords =& $this->user_settings['pref_highlight_specialwords']; + return (boolean) TRUE; + } // end function + + /** + * assigns a class var and writes it to the session/cookie + * @param string $data + * @param string $var + * @param string $type + * @uses I18Nuser::$cookie_time + * @uses I18Nuser::$use_cookies + * @uses I18Nbase::setVar() + * @return boolean + */ + protected function setVar($data = '', $var = '', $type = 'string') { + $_SESSION['i18n']['settings']['user'][$var] = $data; + if (self::USE_COOKIES == TRUE) { + // unsing @ to prevent certain error messages under apache 2 + @setcookie($var, addslashes($data), time()+ self::COOKIE_TIME); + } // end if + return parent::setVar($data, $var, $type); + } // end function + + /** + * assigns a locale/language/country to a class var + * @param string $data + * @param string $var + * @uses I18Nbase::isValidLocaleCode() + * @uses I18Nuser::setVar() + * @return boolean + */ + protected function setPrefVar($data = '', $var = '') { + if (parent::isValidLocaleCode($data) == FALSE) { + return (boolean) FALSE; + } // end if + return $this->setVar(strtolower($data), $var, 'string'); + } // end function + + /**#@+ + * asigns class var + * @return boolean + * @uses I18Nuser::setPrefVar() + */ + /** + * @param string $locale + */ + public function setPrefLocale($locale = '') { + return $this->setPrefVar($locale, 'pref_locale'); + } // end function + + /** + * @param string $country + */ + public function setPrefCountry($country = '') { + return $this->setPrefVar($country, 'pref_country'); + } // end function + + /** + * @param string $lang + */ + public function setPrefLanguage($lang = '') { + return $this->setPrefVar($lang, 'pref_language'); + } // end function + /**#@-*/ + + /**#@+ + * assigns class var + * @return boolean + * @uses I18Nuser::setVar() + */ + /** + * @param string $system + */ + public function setPrefMeasureSystem($system = 'si') { + return $this->setVar($system, 'pref_measure_system', 'string'); + } // end function + + /** + * @param int $int + */ + public function setPrefTimeFormat($int = 0) { + return $this->setVar($int, 'pref_time_format', 'int'); + } // end function + + /** + * @param int $int + */ + public function setHighlightSpecialWords($int = 0) { + return $this->setVar($boolean, 'pref_highlight_specialwords', 'int'); + } // end function + /**#@-*/ + + /** + * returns a class var + * @param string $var + * @uses I18Nbase::getVar() + * @uses I18Nuser::readUserSettings() + * @return mixed + */ + protected function getVar($var = 'dummy') { + if (!isset($this->$var)) { + $this->readUserSettings(); + } // end if + return parent::getVar($var); + } // end if + + /**#@+ + * returns class var + * @return mixed + * @uses I18Nuser::getVar() + */ + public function getPrefLocale() { + return $this->getVar('pref_locale'); + } // end function + + public function getPrefLanguage() { + return $this->getVar('pref_language'); + } // end function + + public function getPrefCountry() { + return $this->getVar('pref_country'); + } // end function + + public function getPrefMeasureSystem() { + return $this->getVar('pref_measure_system'); + } // end function + + public function getPrefTimeFormat() { + return $this->getVar('pref_time_format'); + } // end function + + public function getHighlightSpecialWords() { + return $this->getVar('pref_highlight_specialwords'); + } // end function + /**#@-*/ +} // end class I18Nuser +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/i18n_settings.ini b/info.textgrid.middleware.tgauth.webauth/i18n_inc/i18n_settings.ini new file mode 100644 index 0000000000000000000000000000000000000000..9993ac02f9f591771ad9a1ae36a3c38e6ba44c47 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/i18n_settings.ini @@ -0,0 +1,53 @@ +; <?php die(); // DO NOT REMOVE THIS LINE ?> +; 2003-2008 © Michael Wimmer (flaimo@gmail.com | http://flaimo.com) +; ------------------------------------------------------------------------- +; Default settings for i18n +; +; This ini file + all classes should be placed OUTSIDE the www directory! + +[Locale] +; this locale must always exist! +default_locale = "en" +default_language = "en" +default_country = "us" +; path to the folder where the locale directories are +locales_path = "../locale" + +[Translator] +; mode = Text | Gettext | MySQL | MySQL5 | SQLite | SQLite3 | XML +mode = "Text" +; comma seperated string with namespaces/translation files which should be loaded with every pagecall +default_namespaces = "lang_main" +; triggers E_USER_WARNING errors if strings couldn't be translated or namespaces couldn't be found +show_errormessages = TRUE +; en- or disable locale checking (for ex. everytime a user with a cookie set revisits the page); FALSE = faster +locale_checking = TRUE +; set this to false if you don't use any alias languages. FALSE = faster +use_alias_locales = TRUE + +; further settings are located in every TranslatorXXX class depending on the method used + +[Cache] +cache_dir = "../i18n_cache" +; cache time in sec +cache_time = 86400 +file_extention = "txt" +file_prefix = "" +check_cache_dir = TRUE + +[FormatDate] +; 0 = standard format, 1 = iso date, 2 = swatch date +default_timeset = 0 + +[FormatNumber] +default_minor_unit = 2 +default_decimal_point = "." +default_thousands_sep = "" + +[FormatString] +; highlight abbr, dfn and acronyms +default_specialwordsstatus = 1 +replace_char = "*" + +[Measure] +default_input_system = "si" diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/interface.I18NtranslatorInterface.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/interface.I18NtranslatorInterface.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..f5d64e139b159ee03374dc7b1b4b0278339f9a9a --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/interface.I18NtranslatorInterface.inc.php @@ -0,0 +1,41 @@ +<?php +/** +* basic functions every translator class has to provide +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +interface I18NtranslatorInterface { + /** + * main translator method for translating strings + * @param string $translationstring string to be translated + * @param string $domain alias for namespace (sometimes needed for gettext) + * @param array $arguments whe using translation strings with placeholders, $arguments is an array with the values for the placeholders + * @return string translated tring or error message + */ + public function translate($translationstring = '', $domain = '', $arguments = FALSE); + + /** + * returns an array with $array[translationstring] = translation + * @return array $array[translationstring] = translation + */ + public function getTranslationTable(); + + /** + * changes the locale of an translator object and resetzs the translation data + * @param object $locale I18Nlocale object + * @return boolean + */ + public function changeLocale(I18Nlocale &$locale = NULL); + + /** + * returns the number of strings currently used by an translator object + * @return int + */ + public function getCountStrings(); +} // end interface +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/i18n_inc/interface.I18NtranslatorInterfaceExtended.inc.php b/info.textgrid.middleware.tgauth.webauth/i18n_inc/interface.I18NtranslatorInterfaceExtended.inc.php new file mode 100755 index 0000000000000000000000000000000000000000..9a88e7361ced12637ff3cfc707a1f32aa729cd33 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/i18n_inc/interface.I18NtranslatorInterfaceExtended.inc.php @@ -0,0 +1,56 @@ +<?php +/** +* basic functions every extended translator class has to provide +* @author Michael Wimmer <flaimo@gmail.com> +* @category flaimo-php +* @example ../www_root/i18n_example_script.php i18n example script +* @license GNU General Public License v3 +* @link http://code.google.com/p/flaimo-php/ +* @package i18n +* @version 2.3 +*/ +interface I18NtranslatorInterfaceExtended { + /** + * returns a timestamp of the latest change to one of the strings of an namespace + * @param string $namespace + * @return mixed int or false + */ + public function getLastUpdateDateNamespace($namespace = ''); + + /** + * returns a timestamp of the latest change to one of the strings of given namespaces + * @param string $namespaces comma-seperated + * @return mixed int or false + */ + public function getLastUpdateDate($namespaces = ''); + + /**#@+ + * @return boolean + * @param string $string the stranslation string + * @param string $namespace + */ + /** + * deletes a translation string + translation from the given namespace for the current locale + */ + public function deleteTranslation($string = '', $namespace = 'lang_main'); + + /** + * deletes a translation string + translation from the given namespace for ALL locales + */ + public function deleteTranslationString($string = '', $namespace = 'lang_main'); + + /** + * adds a translationstring + translation to the given namespace of the current locale + * @param string $translation the stranslation itself + */ + public function addTranslation($string = '', $translation = '', $namespace = 'lang_main'); + + /** + * updates a translationstring or translation or namespace + * @param string $translation the stranslation itself + * @param int $position 2 = change namespace; 1 = change string; 0 = change translation + */ + public function updateTranslation($string = '', $translation = '', $namespace = 'lang_main', $position = 0); + /**#@-*/ +} // end interface +?> \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/locale/de-de b/info.textgrid.middleware.tgauth.webauth/locale/de-de new file mode 120000 index 0000000000000000000000000000000000000000..24221009da85fd0aeab5ab0a7c89a28d412e7d68 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/locale/de-de @@ -0,0 +1 @@ +de/ \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc b/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc new file mode 100644 index 0000000000000000000000000000000000000000..8aa156abdfdf03f485027f190c6d7cd8dc47416e --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc @@ -0,0 +1,150 @@ +authn_error_status = TextGrid could not authenticate you. + +further_information = Further Information + +login_name = Login Name + +only_shib_knowns = only known at your home organization + +tgauth_instance = TgAuth Instance + +idp_entityid = Shibboleth Identity ProviderID + +authn_method = User ID Attribute Name + +user_id = User ID Value + +sid = TgAuth Session ID + +error_details_blabla_goback = If not indicated otherwise in the above details, it could be that some service is not responding temporarily. In this case, please <a href=\"javascript:history.back()\">go back</a> or re-open the TextGridLab and try again. + +error_details_blabla_date = If the problem persists, please report this bug together with its time of occurence (%1$s). In the TextGridLab, choose 'Help->Report Bug'. + +no_tgauth_instance_heading = No TgAuth Instance provided + +no_tgauth_instance_detail = Please provide a valid string in the authZinstance variable. + +authn_failure_heading = Failure authenticating at TextGrid Community Account Server + +authn_failure_detail_id_missing = Could not authenticate, no login ID provided. In case you forgot your password, please use the button below. + +authn_failure_detail_password_missing = Could not authenticate, no password provided. In case you forgot your password, please use the button below. + +authn_failure_detail_both_missing = Could not authenticate, no login ID and password provided. In case you forgot your password, please use the button below. + +authn_failure_detail_nothing_to_do = WebAuth does not know what to do (no login or password provided, no remote user, and no session Id). In case you forgot your password, please use the button below. + +sid_create_failure_heading = Failure Creating Session in RBAC + +shib_login_failure_heading = Shibboleth Login via DFN-AAI failed + +shib_login_failure_detail = No identifier provided. TextGrid needs the attribute <b>eduPersonPrincipalName</b> to identify you, but your organisation did not provide it. Please inquire with your organisation's computing centre to release this attribute to TextGrid. See <a href=\"http://www.textgrid.de/1-0/registrierung.html\">http://www.textgrid.de/1-0/registrierung.html</a>. + +authn_succeeded_heading = Authentication Succeeded + +authn_failure_pagetitle = Authentication failed + +update_attr_please_pagetitle = Please Complete your User Attributes + +modify_attr_pagetitle = Your User Attributes for Modification + +update_attr_success_pagetitle = Successfully updated User Attributes + +update_attr_thank_you = Thank you, %1$s, your user attributes are now up to date.<br/>You can close this dialogue. + +auth_success_text = You were successfully authenticated with User ID '<b>%1$s</b>'. You may now access remote resources using the TextGrid Lab. This window can be closed. + +more_details = More <a href=\"javascript:toggle('d123')\">Details</a>. + +authn_details_heading = Authentication Details + +login_heading = TextGridLab Login + +login_option_ldap = textgrid.de account + +login_option_shib = Home account + +login_label_id = Login: + +login_label_password = Password: + +login_button_shib = log in via DFN-AAI + +login_shib_explanation = If your school is not listed among the organizations on the DFN-AAI page, or if you encounter problems during log-in, you are welcome to <b>request a textgrid.de account</b> using the form on <a href="http://www.textgrid.de/1-0/registrierung.html">http://www.textgrid.de/beta/installation.html</a>. + +attr_givenname = Given Name + +attr_givenname_description = Your First Name + +attr_surname = Surname + +attr_surname_description = Your Last Name + +attr_displayname = Full Name + +attr_displayname_description = Your Name for Display Purposes + +attr_mail = E-Mail + +attr_mail_description = Your Electronic Mail Address + +attr_organisation = Institution + +attr_organisation_description = Institute or Organisation + +attr_orgunit = Department + +attr_orgunit_description = Organisational Unit + +attr_street = Street + +attr_street_description = Institution\'s Street Address incl. Number + +attr_plz = Zip Code + +attr_plz_description = Postal Code, Zipcode or PLZ + +attr_city = City + +attr_city_description = Location of Institute + +attr_country = Country + +attr_country_description = Country of Residence + +attr_tel = Phone + +attr_tel_description = Phone Number, International Format + +attr_citizenship = Citizenship + +attr_citizenship_description = Your Country of Citizenship + +attr_interest = Field of Interest + +attr_interest_description = Optional specification of fields of research interests in conjuction with TextGrid + +attr_personid = Person ID + +attr_personid_description = PND / URI for Person, e.g. http://xyz.org/~johndoe + +attr_agreesearch = Searchable + +attr_agreesearch_description = If this option is set, other TextGrid users can find you by Name, Institution or E-Mail-Address + +attr_ToUversion = Terms Of Use + +attr_ToUversion_description = Latest Version of Terms Of Use that has been accepted by user + +ToU_check_label = I accept the <a href=\"javascript:toggleToU('d123')\">TextGrid Terms of Use</a> + +ToU_alert = You must accept the Terms of Use in order to proceed. + +mandatory_field_empty_alert = Please specify your %1$s \n (%2$s). + +email_missing_alert = Please specify your valid E-Mail-Address. + +cancel_button = cancel + +submit_button = submit + diff --git a/info.textgrid.middleware.tgauth.webauth/locale/en-us b/info.textgrid.middleware.tgauth.webauth/locale/en-us new file mode 120000 index 0000000000000000000000000000000000000000..2c4c454fdd2fd2902cc43a87d26851282de294f1 --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/locale/en-us @@ -0,0 +1 @@ +en \ No newline at end of file diff --git a/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc b/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc new file mode 100644 index 0000000000000000000000000000000000000000..8aa156abdfdf03f485027f190c6d7cd8dc47416e --- /dev/null +++ b/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc @@ -0,0 +1,150 @@ +authn_error_status = TextGrid could not authenticate you. + +further_information = Further Information + +login_name = Login Name + +only_shib_knowns = only known at your home organization + +tgauth_instance = TgAuth Instance + +idp_entityid = Shibboleth Identity ProviderID + +authn_method = User ID Attribute Name + +user_id = User ID Value + +sid = TgAuth Session ID + +error_details_blabla_goback = If not indicated otherwise in the above details, it could be that some service is not responding temporarily. In this case, please <a href=\"javascript:history.back()\">go back</a> or re-open the TextGridLab and try again. + +error_details_blabla_date = If the problem persists, please report this bug together with its time of occurence (%1$s). In the TextGridLab, choose 'Help->Report Bug'. + +no_tgauth_instance_heading = No TgAuth Instance provided + +no_tgauth_instance_detail = Please provide a valid string in the authZinstance variable. + +authn_failure_heading = Failure authenticating at TextGrid Community Account Server + +authn_failure_detail_id_missing = Could not authenticate, no login ID provided. In case you forgot your password, please use the button below. + +authn_failure_detail_password_missing = Could not authenticate, no password provided. In case you forgot your password, please use the button below. + +authn_failure_detail_both_missing = Could not authenticate, no login ID and password provided. In case you forgot your password, please use the button below. + +authn_failure_detail_nothing_to_do = WebAuth does not know what to do (no login or password provided, no remote user, and no session Id). In case you forgot your password, please use the button below. + +sid_create_failure_heading = Failure Creating Session in RBAC + +shib_login_failure_heading = Shibboleth Login via DFN-AAI failed + +shib_login_failure_detail = No identifier provided. TextGrid needs the attribute <b>eduPersonPrincipalName</b> to identify you, but your organisation did not provide it. Please inquire with your organisation's computing centre to release this attribute to TextGrid. See <a href=\"http://www.textgrid.de/1-0/registrierung.html\">http://www.textgrid.de/1-0/registrierung.html</a>. + +authn_succeeded_heading = Authentication Succeeded + +authn_failure_pagetitle = Authentication failed + +update_attr_please_pagetitle = Please Complete your User Attributes + +modify_attr_pagetitle = Your User Attributes for Modification + +update_attr_success_pagetitle = Successfully updated User Attributes + +update_attr_thank_you = Thank you, %1$s, your user attributes are now up to date.<br/>You can close this dialogue. + +auth_success_text = You were successfully authenticated with User ID '<b>%1$s</b>'. You may now access remote resources using the TextGrid Lab. This window can be closed. + +more_details = More <a href=\"javascript:toggle('d123')\">Details</a>. + +authn_details_heading = Authentication Details + +login_heading = TextGridLab Login + +login_option_ldap = textgrid.de account + +login_option_shib = Home account + +login_label_id = Login: + +login_label_password = Password: + +login_button_shib = log in via DFN-AAI + +login_shib_explanation = If your school is not listed among the organizations on the DFN-AAI page, or if you encounter problems during log-in, you are welcome to <b>request a textgrid.de account</b> using the form on <a href="http://www.textgrid.de/1-0/registrierung.html">http://www.textgrid.de/beta/installation.html</a>. + +attr_givenname = Given Name + +attr_givenname_description = Your First Name + +attr_surname = Surname + +attr_surname_description = Your Last Name + +attr_displayname = Full Name + +attr_displayname_description = Your Name for Display Purposes + +attr_mail = E-Mail + +attr_mail_description = Your Electronic Mail Address + +attr_organisation = Institution + +attr_organisation_description = Institute or Organisation + +attr_orgunit = Department + +attr_orgunit_description = Organisational Unit + +attr_street = Street + +attr_street_description = Institution\'s Street Address incl. Number + +attr_plz = Zip Code + +attr_plz_description = Postal Code, Zipcode or PLZ + +attr_city = City + +attr_city_description = Location of Institute + +attr_country = Country + +attr_country_description = Country of Residence + +attr_tel = Phone + +attr_tel_description = Phone Number, International Format + +attr_citizenship = Citizenship + +attr_citizenship_description = Your Country of Citizenship + +attr_interest = Field of Interest + +attr_interest_description = Optional specification of fields of research interests in conjuction with TextGrid + +attr_personid = Person ID + +attr_personid_description = PND / URI for Person, e.g. http://xyz.org/~johndoe + +attr_agreesearch = Searchable + +attr_agreesearch_description = If this option is set, other TextGrid users can find you by Name, Institution or E-Mail-Address + +attr_ToUversion = Terms Of Use + +attr_ToUversion_description = Latest Version of Terms Of Use that has been accepted by user + +ToU_check_label = I accept the <a href=\"javascript:toggleToU('d123')\">TextGrid Terms of Use</a> + +ToU_alert = You must accept the Terms of Use in order to proceed. + +mandatory_field_empty_alert = Please specify your %1$s \n (%2$s). + +email_missing_alert = Please specify your valid E-Mail-Address. + +cancel_button = cancel + +submit_button = submit + diff --git a/info.textgrid.middleware.tgauth.webauth/tglib/WebUtils.class.php b/info.textgrid.middleware.tgauth.webauth/tglib/WebUtils.class.php index 50e98bfa3f53f7c7d171bddd45498e8d48f77871..37f2d50c6d08ea84050933373510e2eb2ef19f7e 100644 --- a/info.textgrid.middleware.tgauth.webauth/tglib/WebUtils.class.php +++ b/info.textgrid.middleware.tgauth.webauth/tglib/WebUtils.class.php @@ -13,6 +13,9 @@ class WebUtils { public function __construct() { + ob_start(); + require_once '../i18n_inc/class.I18Nbase.inc.php'; + $this->t = new I18Ntranslator(); } public function printAuthSuccess($heading,$loginname,$rbachash,$slc) { @@ -39,24 +42,24 @@ class WebUtils { echo "</head>\n<body>\n"; echo "<div style=\"font-family:Helvetica,Arial,sans-serif;\">"; - echo "<h2>Authentication Succeeded</h2>\n"; + echo "<h2>".$this->t->_('authn_succeeded_heading')."</h2>\n"; - echo "<p>You were successfully authenticated with User ID '<b>" . $rbachash["remote_user"] . "</b>'. You may now access remote resources using the TextGrid Lab. This window can be closed.</p>\n"; + echo "<p>".$this->t->_('auth_success_text','',array($rbachash["remote_user"]))."</p>\n"; // Details ----------------------------------------------- - echo "<p>More <a href=\"javascript:toggle('d123')\">Details</a>.</p>\n"; - echo "<div id=\"d123\"> <h2>Authentication Details</h2>\n"; - echo "<table><tr><td>TgAuth Instance</td><td>". $rbachash["rbacbase"] ."</td></tr>\n"; - echo "<tr><td>Shibboleth Identity ProviderID</td><td>". $rbachash["identity_provider"] ."</td></tr>\n"; - echo "<tr><td>Login Name</td><td>". (isset($loginname) ? $loginname : "only known at your home organization") ."</td></tr>\n"; - echo "<tr><td>User ID Attribute Name</td><td>". $rbachash["identified_user"]['authnmethod'] ."</td></tr>\n"; - echo "<tr><td>User ID Value </td><td>".$rbachash["remote_user"]."</td></tr>\n"; + echo "<p>".$this->t->_('more_details')."</p>\n"; + echo "<div id=\"d123\"> <h2>".$this->t->_('authn_details_heading')."</h2>\n"; + echo "<table><tr><td>".$this->t->_('tgauth_instance')."</td><td>". $rbachash["rbacbase"] ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('idp_entityid')."</td><td>". $rbachash["identity_provider"] ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('login_name')."</td><td>". (isset($loginname) ? $loginname : $this->t->_('only_shib_knowns')) ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('authn_method')."</td><td>". $rbachash["identified_user"]['authnmethod'] ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('user_id')." </td><td>".$rbachash["remote_user"]."</td></tr>\n"; // echo "<tr><td>Given Name(s)</td><td>".$givennames."</td></tr>\n"; // echo "<tr><td>Surname(s)</td><td>".$surnames."</td></tr>\n"; // echo "<tr><td>Common Name(s)</td><td>".$cns."</td></tr>\n"; // echo "<tr><td>Mail(s)</td><td>".$mails."</td></tr>\n"; // echo "<tr><td>Organisation(s)</td><td>".$organisations."</td></tr>\n"; - echo "<tr><td>TgAuth Session ID</td><td>".$rbachash["Sid"]."</td></tr></table>\n"; + echo "<tr><td>".$this->t->_('sid')."</td><td>".$rbachash["Sid"]."</td></tr></table>\n"; echo "</div>"; if ($slc['slcMode']) { @@ -112,7 +115,7 @@ class WebUtils { public function printAuthFailure($heading,$detail,$loginname,$rbachash) { - $this->printHeader("Authentication failed"); + $this->printHeader("authn_failure_pagetitle"); if (isset($rbachash)) { echo "<meta name=\"remote_principal\" content=\"". $rbachash["remote_user"]."\"/>\n"; @@ -122,32 +125,32 @@ class WebUtils { echo "</head>\n\n<body>\n"; echo "<div style=\"font-family:Helvetica,Arial,sans-serif;\">"; - echo "<h3>$heading</h3>\n"; - echo "<p>TextGrid could not authenticate you.</p>\n"; - echo "<p>". $detail ."</p>" ; - echo "<h3>Further Information</h3>\n"; + echo "<h3>".$this->t->_($heading)."</h3>\n"; + echo "<p>". $this->t->_('authn_error_status') ." </p>\n"; + echo "<p>". $this->t->_($detail) ."</p>" ; + echo "<h3>". $this->t->_('further_information') . "</h3>\n"; echo "<table>\n"; - echo "<tr><td>Login Name</td><td>". $loginname ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('login_name')."</td><td>". $loginname ."</td></tr>\n"; if (isset($rbachash["rbacbase"])) { - echo "<tr><td>TgAuth Instance</td><td>". $rbachash["rbacbase"] ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('tgauth_instance')."</td><td>". $rbachash["rbacbase"] ."</td></tr>\n"; } if (isset($rbachash["identity_provider"])) { - echo "<tr><td>Shibboleth Identity ProviderID</td><td>". $rbachash["identity_provider"] ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('idp_entityid')."</td><td>". $rbachash["identity_provider"] ."</td></tr>\n"; } if (isset($rbachash["identified_user"]['authnmethod'] )) { - echo "<tr><td>User ID Attribute Name</td><td>". $rbachash["identified_user"]['authnmethod'] ."</td></tr>\n"; + echo "<tr><td>".$this->t->_('authn_method')."</td><td>". $rbachash["identified_user"]['authnmethod'] ."</td></tr>\n"; } if (isset($rbachash["remote_user"])) { - echo "<tr><td>User ID Value </td><td>".$rbachash["remote_user"]."</td></tr>\n"; + echo "<tr><td>".$this->t->_('user_id')." </td><td>".$rbachash["remote_user"]."</td></tr>\n"; } if (isset($rbachash["Sid"])) { - echo "<tr><td>TgAuth Session ID</td><td>".$rbachash["Sid"]."</td></tr>\n"; + echo "<tr><td>".$this->t->_('sid')."</td><td>".$rbachash["Sid"]."</td></tr>\n"; } echo "</table>\n"; // echo "</div>"; - echo "<p>If not indicated otherwise in the above details, it could be that some service is not responding temporarily. In this case, please <a href=\"javascript:history.back()\">go back</a> or re-open the TextGridLab and try again.</p>"; - echo "<p>If the problem persists, please report this bug together with its time of occurence (" . date("Y-m-d H:i:s") . "). In the TextGridLab, choose 'Help->Report Bug'.</p>" ; + echo "<p>".$this->t->_('error_details_blabla_goback')."</p>"; + echo "<p>".$this->t->_('error_details_blabla_date','',array(date("Y-m-d H:i:s")))."</p>" ; echo "\n</div></body>\n</html>"; } @@ -156,17 +159,17 @@ class WebUtils { echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"; echo "<head>\n"; - echo "<title>" . $title . "</title>\n"; + echo "<title>" . $this->t->_($title) . "</title>\n"; echo "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n"; } public function printAttributeForm ( $existingAttrs, $providedAttrs, $attrMap, $Sid, $authZinstance, $remote_user, $ToUversion, $ToUtext) { if (isset ($providedAttrs)) { $loginmode = TRUE; - $title = "Please Complete your User Attributes"; + $title = "update_attr_please_pagetitle"; } else { $loginmode = FALSE; - $title = "Your User Attributes for Modification"; + $title = "modify_attr_pagetitle"; } $this->printHeader ($title); @@ -193,7 +196,7 @@ class WebUtils { echo "<script type=\"text/javascript\">\n"; echo "function chkFormular () {\n"; echo " if (!document.Formular.ToUversion.checked) {\n"; - echo " alert(\"You must accept the Terms of Use in order to proceed.\");\n"; + echo " alert(\"". $this->t->_('ToU_alert')."\");\n"; echo " document.Formular.ToUversion.focus();\n"; echo " return false;\n"; echo " }\n"; @@ -201,14 +204,14 @@ class WebUtils { foreach ($existingAttrs as $a) { if ($a->mandatory && $a->name != "ToUversion") { echo " if (document.Formular.". $a->name . ".value == \"\") {\n"; - echo " alert(\"Please specify your ".$a->displayname . "\\n(".$a->description . ").\");\n"; + echo " alert(\"". $this->t->_('mandatory_field_empty_alert','',array($this->t->_('attr_'.$a->name),$this->t->_('attr_'.$a->name.'_description'))) ."\");\n"; echo " document.Formular.". $a->name . ".focus();\n"; echo " return false;\n"; echo " }\n"; } } echo " if (document.Formular.mail.value.indexOf(\"@\") == -1 ){\n"; - echo " alert(\"Please specify your valid E-Mail-Address.\");\n"; + echo " alert(\"". $this->t->_('email_missing_alert')."\");\n"; echo " document.Formular.mail.focus();\n"; echo " return false;\n"; echo " }\n"; @@ -219,7 +222,7 @@ class WebUtils { echo "</head>\n<body>\n"; echo "<div style=\"font-family:Helvetica,Arial,sans-serif;\">"; - echo "<h2 style=\"text-align: center;\">$title</h2>\n"; + echo "<h2 style=\"text-align: center;\">".$this->t->_($title)."</h2>\n"; // echo "This is what we got for sure:". serialize ($providedAttrs); // echo $remote_user .serialize ( $attrMap ); @@ -258,7 +261,7 @@ class WebUtils { $mandatory = ""; } - echo "<tr><td>".$a->displayname." ${mandatory}</td>"; + echo "<tr><td>".$this->t->_('attr_'.$a->name)." ${mandatory}</td>"; if ($this->isBoolean ($a)) { echo "<td><input type=\"checkbox\" name=\"". $a->name . "\" value=\"on\" ${checked}/></td>\n"; } else if ($this->isISO3166format ($a)) { @@ -269,7 +272,7 @@ class WebUtils { } else { // assume string echo "<td><input type=\"text\" size=\"50\" name=\"". $a->name . "\" value=\"${oldval}\"${providedreadonly}/></td>\n"; } - echo "<td><a href=\"javascript:displayhelp('".$a->displayname."','". $a->description ."')\"><img src=\"./scripts/help.png\" border=\"0\" height=\"25px\" alt=\"?\"></a>"; + echo "<td><a href=\"javascript:displayhelp('".$this->t->_('attr_'.$a->name)."','". $this->t->_('attr_'.$a->name.'_description') ."')\"><img src=\"./scripts/help.png\" border=\"0\" height=\"25px\" alt=\"?\"></a>"; echo "</td></tr>\n"; } @@ -279,7 +282,7 @@ class WebUtils { } echo "<tr><td></td><td colspan=\"2\"><div style=\"text-align: right;\"><input type=\"checkbox\" name=\"ToUversion\" value=\"${ToUversion}\" ${checked}/>\n"; - echo " I accept the <a href=\"javascript:toggleToU('d123')\">TextGrid Terms of Use</a>.</div></td></tr>"; + echo $this->t->_('ToU_check_label') ."</div></td></tr>"; echo "<tr><td colspan=\"3\"><div id=\"d123\">"; echo $ToUtext; @@ -290,8 +293,8 @@ class WebUtils { echo "<input type=\"hidden\" name=\"remote_user\" value=\"" . $remote_user . "\" />\n"; echo "<input type=\"hidden\" name=\"Sid\" value=\"" . $Sid . "\" />\n"; echo "<input type=\"hidden\" name=\"authZinstance\" value=\"" . $authZinstance . "\" />\n"; - echo "<tr><td></td><td colspan=\"2\"><div style=\"text-align: right;\"><input type=\"reset\" value=\"Cancel\">"; - echo "<input type=\"submit\" value=\"Submit\"></div></td></tr>"; + echo "<tr><td></td><td colspan=\"2\"><div style=\"text-align: right;\"><input type=\"reset\" value=\"". $this->t->_('cancel_button')."\">"; + echo "<input type=\"submit\" value=\"".$this->t->_('submit_button')."\"></div></td></tr>"; echo "</table>\n"; echo "</form>\n"; echo "</div>"; @@ -299,11 +302,10 @@ class WebUtils { } public function printSetAttributesSuccess ($thedisplayname) { - $this->printHeader("Successfully updated User Attributes"); + $this->printHeader("update_attr_success_pagetitle"); echo "</head><body>\n"; echo "<div style=\"font-family:Helvetica,Arial,sans-serif;\">"; - echo "Thank you, ${thedisplayname}, your user attributes are now up to date.<br/>\n"; - echo "You can close this dialogue.\n"; + echo $this->t->_('update_attr_thank_you','',array($thedisplayname)); echo "\n</div></body>\n</html>"; } @@ -345,7 +347,7 @@ class WebUtils { function list_iso3166($key=false) { // Returns a list of ISO 3166 alpha 2 country codes and names in an array // Make a static copy of this file on your server - $url='http://www.iso.org/iso/iso3166_en_code_lists.txt'; + $url='http://www.iso.org/iso/list-en1-semic-3.txt'; // Path/Filename of the local copy (if present) $file='iso3166_en_code_lists.txt';