From: Lo?c C. <lo...@us...> - 2001-04-03 20:10:18
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/localization In directory usw-pr-cvs1:/tmp/cvs-serv3216/chat/localization Added Files: admin.lib.php3 languages.lib.php3 Log Message: The first dev. version that works! Still many things to do, of course... --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library defines the language that will be used for the | // | administration work. If there is no language already defined (neither in | // | a cookie, neither from a variable sent in the query part of the url) it | // | will try to get the most probable language the administrator would like | // | to use thanks to some environment variables. | // | | // | This file is called by the 'chat/admin.php3' script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: admin.lib.php3,v 1.1 2001/04/03 20:10:14 loic1 Exp $ // // Defines the language to be used for the administration work of phpMyChat. // /** * Analyzes some PHP environment variables to find the most probable language * that should be used * * @param string string to analyze * @param integer type of the PHP environment variable which value is $str * * @global array the list of available translations * @global string the language to use * * @access private */ function pmcAdminDetect($str = '', $envType = '') { global $availableAdmins; global $lang; $notFound = true; reset($availableAdmins); while ($notFound && list($key, $name) = each($availableAdmins)) { // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, // 2 for the 'HTTP_USER_AGENT' one if ( ($envType == 1 && eregi('^' . $key . '$', $str)) || ($envType == 2 && eregi('(\(|\[|;[[:space:]])' . $key . '(;|\]|\))', $str))) { $lang = $availableAdmins[$key]; $notFound = false; } } } // end of the 'pmcAdminDetect()' function /** * Creates the array containing available languages */ // Defines available languages $availableAdmins = array(); $languageDirectories = dir('./localization/'); while ($name = $languageDirectories->read()) { if (is_dir('./localization/' . $name) && file_exists('./localization/' . $name . '/localized.admin.' . C_EXTENSION) { list($key) = file('./localization/' . $name . '/regex.txt'); $availableAdmins[$key] = $name; } } $languageDirectories->close(); // Sorts the $availableAdmins array in a convenient order if (!function_exists('krsort')) include('./localization/sort_languages.lib.' . C_EXTENSION); krsort($availableAdmins); /** * Get some predefined variables */ if (isset($HTTP_COOKIE_VARS['cookieLang'])) $cookieLang = $HTTP_COOKIE_VARS['cookieLang']; pmcGrabGlobals('HTTP_ACCEPT_LANGUAGE'); pmcGrabGlobals('HTTP_USER_AGENT'); /** * Finds the appropriate language file */ // If a language is defined in a cookie, ensures the translation exists if (isset($cookieLang) && file_exists('./localization/' . $cookieLang . '/localized.admin.' . C_EXTENSION)) { $lang = $cookieLang; } // Checks for an existing translation corresponding to the // 'HTTP_ACCEPT_LANGUAGE' variable sent by the browser else if ($HTTP_ACCEPT_LANGUAGE != '') { $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE); pmcAdminDetect($accepted[0], 1); } // Checks for an existing translation corresponding to the // 'HTTP_USER_AGENT' variable sent by the browser else if ($HTTP_USER_AGENT != '') { pmcAdminDetect($HTTP_USER_AGENT, 2); } // If no translation has been retained, uses the default one if (!isset($lang)) $lang = (file_exists('./localization/' . C_LANGUAGE . '/localized.admin.' . C_EXTENSION)) ? C_LANGUAGE : 'english'; // Clears the table unset($availableAdmins); ?> --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library defines the language that will be used during the chat | // | session. If there is no language already defined (neither in a cookie, | // | neither from a variable sent in the query part of the url) it will try | // | to get the most probable language the user would like to use thanks to | // | some environment variables. | // | | // | This file is called by most of the phpMyChat scripts. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: languages.lib.php3,v 1.1 2001/04/03 20:10:14 loic1 Exp $ // // Defines the language to be used during the chat session. // /** * Analyzes some PHP environment variables to find the most probable language * that should be used * * @param string string to analyze * @param integer type of the PHP environment variable which value is $str * * @global array the list of available translations * @global string the session table * * @access private */ function pmcLangDetect($str = '', $envType = '') { global $availableLanguages; global $dbSessionVars; $notFound = true; reset($availableLanguages); while ($notFound && list($key, $name) = each($availableLanguages)) { // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, // 2 for the 'HTTP_USER_AGENT' one if ( ($envType == 1 && eregi('^' . $key . '$', $str)) || ($envType == 2 && eregi('(\(|\[|;[[:space:]])' . $key . '(;|\]|\))', $str))) { $dbSessionVars['lang'] = $availableLanguages[$key]; $notFound = false; } } } // end of the 'pmcLangDetect()' function /** * Creates the array containing available languages */ // Ensures the _CHAT_PATH constant is defined if (!defined('_CHAT_PATH')) define('_CHAT_PATH', ''); // Defines available languages $availableLanguages = array(); $languageDirectories = dir('./' . _CHAT_PATH . 'localization/'); while ($name = $languageDirectories->read()) { if (is_dir('./' . _CHAT_PATH . 'localization/' . $name) && file_exists('./' . _CHAT_PATH . 'localization/' . $name . '/regex.txt') && file_exists('./' . _CHAT_PATH . 'localization/' . $name . '/localized.chat.' . C_EXTENSION) && file_exists('./' . _CHAT_PATH . 'localization/' . $name . '/flag.gif')) { list($key) = file('./' . _CHAT_PATH . 'localization/' . $name . '/regex.txt'); $availableLanguages[$key] = $name; } } $languageDirectories->close(); // Sorts the $availableLanguages array in a convenient order if (!function_exists('krsort')) include('./' . _CHAT_PATH . 'localization/sort_languages.lib.' . C_EXTENSION); krsort($availableLanguages); /** * Get some predefined variables */ if (isset($HTTP_COOKIE_VARS['cookieLang'])) $cookieLang = $HTTP_COOKIE_VARS['cookieLang']; pmcGrabGlobals('HTTP_ACCEPT_LANGUAGE'); pmcGrabGlobals('HTTP_USER_AGENT'); /** * Finds the appropriate language file */ // The language is already defined if ((dbSessionIsRegistered('lang') && !empty($dbSessionVars['lang'])) || C_MULTI_LANG == 0) { // void } // If a language is defined in a cookie, ensures the translation exists else if (isset($cookieLang) && file_exists('./' . _CHAT_PATH . 'localization/' . $cookieLang . '/localized.chat.' . C_EXTENSION)) { $dbSessionVars['lang'] = $cookieLang; } // Checks for an existing translation corresponding to the // 'HTTP_ACCEPT_LANGUAGE' variable sent by the browser else if ($HTTP_ACCEPT_LANGUAGE != '') { $accepted = explode(',', $HTTP_ACCEPT_LANGUAGE); pmcLangDetect($accepted[0], 1); } // Checks for an existing translation corresponding to the // 'HTTP_USER_AGENT' variable sent by the browser else if ($HTTP_USER_AGENT != '') { pmcLangDetect($HTTP_USER_AGENT, 2); } // If no translation has been retained, uses the default one if (!dbSessionIsRegistered('lang')) $dbSessionVars['lang'] = C_LANGUAGE; // Puts the language retained in a cookie that will expire in one year setcookie('cookieLang', $dbSessionVars['lang'], time() + 60*60*24*365); ?> |