tray/src/messenger/webim/libs/common.php

755 lines
18 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Mibew Messenger project.
*
2011-02-16 03:22:22 +03:00
* Copyright (c) 2005-2011 Mibew Messenger Community
* All rights reserved. The contents of this file are subject to the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and
* is available at http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which case
* the provisions of the GPL are applicable instead of those above. If you wish
* to allow use of your version of this file only under the terms of the GPL, and
* not to allow others to use your version of this file under the terms of the
* EPL, indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL.
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
session_start();
2011-02-26 17:04:12 +03:00
require_once(dirname(__FILE__) . '/converter.php');
require_once(dirname(__FILE__) . '/config.php');
2011-02-16 03:47:12 +03:00
$version = '1.6.4';
$jsver = "164";
2011-02-26 17:04:12 +03:00
function myiconv($in_enc, $out_enc, $string)
{
global $_utf8win1251, $_win1251utf8;
2011-02-26 17:04:12 +03:00
if ($in_enc == $out_enc) {
return $string;
}
2011-02-26 17:04:12 +03:00
if (function_exists('iconv')) {
$converted = @iconv($in_enc, $out_enc, $string);
2011-02-26 17:04:12 +03:00
if ($converted !== FALSE) {
return $converted;
}
}
2011-02-26 17:04:12 +03:00
if ($in_enc == "cp1251" && $out_enc == "utf-8")
return strtr($string, $_win1251utf8);
2011-02-26 17:04:12 +03:00
if ($in_enc == "utf-8" && $out_enc == "cp1251")
return strtr($string, $_utf8win1251);
return $string; // do not know how to convert
}
2011-02-26 17:04:12 +03:00
function verifyparam($name, $regexp, $default = null)
{
if (isset($_GET[$name])) {
$val = $_GET[$name];
2011-02-26 17:04:12 +03:00
if (preg_match($regexp, $val))
return $val;
2011-02-26 17:04:12 +03:00
} else if (isset($_POST[$name])) {
$val = $_POST[$name];
2011-02-26 17:04:12 +03:00
if (preg_match($regexp, $val))
return $val;
} else {
2011-02-26 17:04:12 +03:00
if (isset($default))
return $default;
}
2011-02-26 17:04:12 +03:00
echo "<html><head></head><body>Wrong parameter used or absent: " . $name . "</body></html>";
exit;
}
2011-02-26 17:04:12 +03:00
function debugexit_print($var)
{
echo "<html><body><pre>";
2011-02-26 17:04:12 +03:00
print_r($var);
echo "</pre></body></html>";
exit;
}
$locale_pattern = "/^[\w-]{2,5}$/";
2011-02-26 17:04:12 +03:00
function locale_exists($locale)
{
return file_exists(dirname(__FILE__) . "/../locales/$locale/properties");
}
2011-02-26 17:04:12 +03:00
function get_available_locales()
{
global $locale_pattern;
$list = array();
2011-02-26 17:04:12 +03:00
$folder = dirname(__FILE__) . "/../locales";
if ($handle = opendir($folder)) {
while (false !== ($file = readdir($handle))) {
if (preg_match($locale_pattern, $file) && $file != 'names' && is_dir("$folder/$file")) {
$list[] = $file;
}
}
closedir($handle);
}
sort($list);
return $list;
}
2011-02-26 17:04:12 +03:00
function get_user_locale()
{
global $default_locale;
2011-02-26 17:04:12 +03:00
if (isset($_COOKIE['webim_locale'])) {
$requested_lang = $_COOKIE['webim_locale'];
2011-02-26 17:04:12 +03:00
if (locale_exists($requested_lang))
return $requested_lang;
}
2011-02-26 17:04:12 +03:00
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$requested_langs = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($requested_langs as $requested_lang) {
if (strlen($requested_lang) > 2)
$requested_lang = substr($requested_lang, 0, 2);
2011-02-26 17:04:12 +03:00
if (locale_exists($requested_lang))
return $requested_lang;
}
}
2011-02-26 17:04:12 +03:00
if (locale_exists($default_locale))
return $default_locale;
return 'en';
}
2011-02-26 17:04:12 +03:00
function get_locale()
{
global $webimroot, $locale_pattern;
$locale = verifyparam("locale", $locale_pattern, "");
2011-02-26 17:04:12 +03:00
if ($locale && locale_exists($locale)) {
$_SESSION['locale'] = $locale;
2011-02-26 17:04:12 +03:00
setcookie('webim_locale', $locale, time() + 60 * 60 * 24 * 1000, "$webimroot/");
} else if (isset($_SESSION['locale'])) {
$locale = $_SESSION['locale'];
}
2011-02-26 17:04:12 +03:00
if (!$locale || !locale_exists($locale))
$locale = get_user_locale();
return $locale;
}
$current_locale = get_locale();
$messages = array();
$output_encoding = array();
2011-02-26 17:04:12 +03:00
if (function_exists("date_default_timezone_set")) {
// TODO try to get timezone from config.php/session etc.
// autodetect timezone
@date_default_timezone_set(function_exists("date_default_timezone_get") ? @date_default_timezone_get() : "GMT");
}
2011-02-26 17:04:12 +03:00
function get_locale_links($href)
{
global $current_locale;
$localeLinks = array();
$allLocales = get_available_locales();
2011-02-26 17:04:12 +03:00
if (count($allLocales) < 2) {
return null;
}
2011-02-26 17:04:12 +03:00
foreach ($allLocales as $k) {
$localeLinks[$k] = getlocal_($k, "names");
}
return $localeLinks;
}
2011-02-26 17:04:12 +03:00
function load_messages($locale)
{
global $messages, $webim_encoding, $output_encoding;
$hash = array();
$current_encoding = $webim_encoding;
2011-02-26 17:04:12 +03:00
$fp = fopen(dirname(__FILE__) . "/../locales/$locale/properties", "r");
while (!feof($fp)) {
$line = fgets($fp, 4096);
2011-02-26 17:04:12 +03:00
$keyval = preg_split("/=/", $line, 2);
if (isset($keyval[1])) {
if ($keyval[0] == 'encoding') {
$current_encoding = trim($keyval[1]);
2011-02-26 17:04:12 +03:00
} else if ($keyval[0] == 'output_encoding') {
$output_encoding[$locale] = trim($keyval[1]);
2011-02-26 17:04:12 +03:00
} else if ($current_encoding == $webim_encoding) {
$hash[$keyval[0]] = str_replace("\\n", "\n", trim($keyval[1]));
} else {
2011-02-26 17:04:12 +03:00
$hash[$keyval[0]] = myiconv($current_encoding, $webim_encoding, str_replace("\\n", "\n", trim($keyval[1])));
}
}
}
fclose($fp);
$messages[$locale] = $hash;
}
2011-02-26 17:04:12 +03:00
function getoutputenc()
{
global $current_locale, $output_encoding, $webim_encoding, $messages;
2011-02-26 17:04:12 +03:00
if (!isset($messages[$current_locale]))
load_messages($current_locale);
return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $webim_encoding;
}
2011-02-26 17:04:12 +03:00
function getstring_($text, $locale)
{
global $messages;
2011-02-26 17:04:12 +03:00
if (!isset($messages[$locale]))
load_messages($locale);
$localized = $messages[$locale];
2011-02-26 17:04:12 +03:00
if (isset($localized[$text]))
return $localized[$text];
2011-02-26 17:04:12 +03:00
if ($locale != 'en') {
return getstring_($text, 'en');
}
2011-02-26 17:04:12 +03:00
return "!" . $text;
}
2011-02-26 17:04:12 +03:00
function getstring($text)
{
global $current_locale;
2011-02-26 17:04:12 +03:00
return getstring_($text, $current_locale);
}
2011-02-26 17:04:12 +03:00
function getlocal($text)
{
global $current_locale, $webim_encoding;
2011-02-26 17:04:12 +03:00
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
}
2011-02-26 17:04:12 +03:00
function getlocal_($text, $locale)
{
global $webim_encoding;
2011-02-26 17:04:12 +03:00
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $locale));
}
2011-02-26 17:04:12 +03:00
function topage($text)
{
global $webim_encoding;
2011-02-26 17:04:12 +03:00
return myiconv($webim_encoding, getoutputenc(), $text);
}
2011-02-26 17:04:12 +03:00
function getstring2_($text, $params, $locale)
{
$string = getstring_($text, $locale);
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
}
return $string;
}
2011-02-26 17:04:12 +03:00
function getstring2($text, $params)
{
global $current_locale;
2011-02-26 17:04:12 +03:00
return getstring2_($text, $params, $current_locale);
}
2011-02-26 17:04:12 +03:00
function getlocal2($text, $params)
{
global $current_locale, $webim_encoding;
2011-02-26 17:04:12 +03:00
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
}
return $string;
}
/* prepares for Javascript string */
2011-02-26 17:04:12 +03:00
function getlocalforJS($text, $params)
{
global $current_locale, $webim_encoding;
2011-02-26 17:04:12 +03:00
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
}
return $string;
}
/* ajax server actions use utf-8 */
2011-02-26 17:04:12 +03:00
function getrawparam($name)
{
global $webim_encoding;
2011-02-26 17:04:12 +03:00
if (isset($_POST[$name])) {
$value = myiconv("utf-8", $webim_encoding, $_POST[$name]);
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
return $value;
}
2011-02-26 17:04:12 +03:00
die("no " . $name . " parameter");
}
/* form processors use current Output encoding */
2011-02-26 17:04:12 +03:00
function getparam($name)
{
global $webim_encoding;
2011-02-26 17:04:12 +03:00
if (isset($_POST[$name])) {
$value = myiconv(getoutputenc(), $webim_encoding, $_POST[$name]);
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
return $value;
}
2011-02-26 17:04:12 +03:00
die("no " . $name . " parameter");
}
function unicode_urldecode($url)
{
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
foreach ($a[1] as $uniord) {
$dec = hexdec($uniord);
$utf = '';
if ($dec < 128) {
$utf = chr($dec);
} else if ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
} else {
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
$url = str_replace('%u' . $uniord, $utf, $url);
}
return urldecode($url);
}
2011-02-26 17:04:12 +03:00
function getgetparam($name, $default = '')
{
global $webim_encoding;
2011-02-26 17:04:12 +03:00
if (!isset($_GET[$name]) || !$_GET[$name]) {
return $default;
}
$value = myiconv("utf-8", $webim_encoding, unicode_urldecode($_GET[$name]));
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
return $value;
}
2011-02-26 17:04:12 +03:00
function connect()
{
global $mysqlhost, $mysqllogin, $mysqlpass, $mysqldb, $dbencoding, $force_charset_in_connection, $use_persistent_connection;
2011-02-26 17:04:12 +03:00
if (!extension_loaded("mysql")) {
die('Mysql extension is not loaded');
}
if ($use_persistent_connection) {
$link = @mysql_pconnect($mysqlhost, $mysqllogin, $mysqlpass);
}else{
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass);
}
if (! $link) {
die('Could not connect: ' . mysql_error());
}
2011-02-26 17:04:12 +03:00
mysql_select_db($mysqldb, $link) or die('Could not select database');
if ($force_charset_in_connection) {
perform_query("SET NAMES '$dbencoding'", $link);
}
return $link;
}
2011-11-08 21:29:33 +04:00
function close_connection($link)
{
global $use_persistent_connection;
if (! $use_persistent_connection) {
mysql_close($link);
}
}
function db_escape_string($string, $link = NULL)
{
if ( is_null($link) ) {
return mysql_real_escape_string($string);
}
return mysql_real_escape_string($string, $link);
}
2011-11-09 23:43:49 +04:00
function db_error($link)
{
return mysql_error($link);
}
function db_insert_id($link)
{
return mysql_insert_id($link);
}
function db_fetch_row($result)
{
return mysql_fetch_row($result);
}
function db_fetch_assoc($result){
return mysql_fetch_assoc($result);
}
2011-02-26 17:04:12 +03:00
function perform_query($query, $link)
{
$result = mysql_query($query, $link);
if (! $result) {
die(' Query failed: ' . db_error($link));
}
return $result;
}
function db_free_result($result)
{
mysql_free_result($result);
}
2011-02-26 17:04:12 +03:00
function select_one_row($query, $link)
{
$result = perform_query($query, $link);
$line = db_fetch_assoc($result);
db_free_result($result);
return $line;
}
2011-02-26 17:04:12 +03:00
function select_multi_assoc($query, $link)
{
$sqlresult = perform_query($query, $link);
$result = array();
while ($row = db_fetch_assoc($sqlresult)) {
$result[] = $row;
}
db_free_result($sqlresult);
return $result;
}
2011-02-26 17:04:12 +03:00
function db_build_select($fields, $table, $conditions, $orderandgroup)
{
$condition = count($conditions) > 0 ? " where " . implode(" and ", $conditions) : "";
if ($orderandgroup) $orderandgroup = " " . $orderandgroup;
return "select $fields from $table$condition$orderandgroup";
2011-02-26 17:04:12 +03:00
}
2011-02-26 17:04:12 +03:00
function db_rows_count($table, $conditions, $countfields, $link)
{
$result = perform_query(db_build_select("count(" . ($countfields ? $countfields : "*") . ")", $table, $conditions, ""), $link);
$line = db_fetch_row($result);
db_free_result($result);
return $line[0];
}
2011-02-26 17:04:12 +03:00
function start_xml_output()
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
}
2011-02-26 17:04:12 +03:00
function start_html_output()
{
$charset = getstring("output_charset");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
2011-02-26 17:04:12 +03:00
header("Content-type: text/html" . (isset($charset) ? "; charset=" . $charset : ""));
}
2011-12-09 14:18:52 +04:00
function start_js_output(){
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: application/javascript; charset=utf-8");
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
}
2011-02-26 17:04:12 +03:00
function escape_with_cdata($text)
{
return "<![CDATA[" . str_replace("]]>", "]]>]]&gt;<![CDATA[", $text) . "]]>";
}
2011-02-26 17:04:12 +03:00
function form_value($key)
{
global $page;
2011-02-26 17:04:12 +03:00
if (isset($page) && isset($page["form$key"]))
return htmlspecialchars($page["form$key"]);
return "";
}
2011-02-26 17:04:12 +03:00
function form_value_cb($key)
{
global $page;
2011-02-26 17:04:12 +03:00
if (isset($page) && isset($page["form$key"]))
return $page["form$key"] === true;
return false;
}
2011-02-26 17:04:12 +03:00
function form_value_mb($key, $id)
{
global $page;
2011-02-26 17:04:12 +03:00
if (isset($page) && isset($page["form$key"]) && is_array($page["form$key"])) {
return in_array($id, $page["form$key"]);
}
return false;
}
2011-02-26 17:04:12 +03:00
function no_field($key)
{
return getlocal2("errors.required", array(getlocal($key)));
}
2011-02-26 17:04:12 +03:00
function failed_uploading_file($filename, $key)
{
return getlocal2("errors.failed.uploading.file",
2011-02-26 17:04:12 +03:00
array($filename, getlocal($key)));
}
2011-02-26 17:04:12 +03:00
function wrong_field($key)
{
return getlocal2("errors.wrong_field", array(getlocal($key)));
}
2011-02-26 17:04:12 +03:00
function get_popup($href, $jshref, $message, $title, $wndName, $options)
{
if (!$jshref) {
$jshref = "'$href'";
}
return "<a href=\"$href\" target=\"_blank\" " . ($title ? "title=\"$title\" " : "") . "onclick=\"if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 &amp;&amp; window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open($jshref, '$wndName', '$options');this.newWindow.focus();this.newWindow.opener=window;return false;\">$message</a>";
}
2011-02-26 17:04:12 +03:00
function get_image($href, $width, $height)
{
if ($width != 0 && $height != 0)
return "<img src=\"$href\" border=\"0\" width=\"$width\" height=\"$height\" alt=\"\"/>";
return "<img src=\"$href\" border=\"0\" alt=\"\"/>";
}
2011-02-26 17:04:12 +03:00
function get_gifimage_size($filename)
{
if (function_exists('gd_info')) {
$info = gd_info();
2011-02-26 17:04:12 +03:00
if (isset($info['GIF Read Support']) && $info['GIF Read Support']) {
$img = @imagecreatefromgif($filename);
2011-02-26 17:04:12 +03:00
if ($img) {
$height = imagesy($img);
$width = imagesx($img);
imagedestroy($img);
2011-02-26 17:04:12 +03:00
return array($width, $height);
}
}
}
2011-02-26 17:04:12 +03:00
return array(0, 0);
}
2011-02-26 17:04:12 +03:00
function add_params($servlet, $params)
{
$infix = '?';
2011-02-26 17:04:12 +03:00
if (strstr($servlet, $infix) !== FALSE)
$infix = '&amp;';
2011-02-26 17:04:12 +03:00
foreach ($params as $k => $v) {
$servlet .= $infix . $k . "=" . $v;
$infix = '&amp;';
}
return $servlet;
}
2011-02-26 17:04:12 +03:00
function div($a, $b)
{
return ($a - ($a % $b)) / $b;
}
2011-02-26 17:04:12 +03:00
function date_diff_to_text($seconds)
{
$minutes = div($seconds, 60);
$seconds = $seconds % 60;
2011-02-26 17:04:12 +03:00
if ($minutes < 60) {
return sprintf("%02d:%02d", $minutes, $seconds);
} else {
2011-02-26 17:04:12 +03:00
$hours = div($minutes, 60);
$minutes = $minutes % 60;
2011-02-26 17:04:12 +03:00
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
}
}
2011-02-26 17:04:12 +03:00
function is_valid_email($email)
{
return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
}
2011-02-26 17:04:12 +03:00
function get_app_location($showhost, $issecure)
{
global $webimroot;
2011-02-26 17:04:12 +03:00
if ($showhost) {
return ($issecure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $webimroot;
} else {
return $webimroot;
}
}
2011-02-26 17:04:12 +03:00
function is_secure_request()
{
return
2011-02-26 17:04:12 +03:00
isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443'
|| isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"
|| isset($_SERVER["HTTP_HTTPS"]) && $_SERVER["HTTP_HTTPS"] == "on";
}
2011-02-26 17:04:12 +03:00
function get_month_selection($fromtime, $totime)
{
$start = getdate($fromtime);
$month = $start['mon'];
$year = $start['year'];
$result = array();
do {
2011-02-26 17:04:12 +03:00
$current = mktime(0, 0, 0, $month, 1, $year);
$result[date("m.y", $current)] = strftime("%B, %Y", $current);
$month++;
2011-02-26 17:04:12 +03:00
if ($month > 12) {
$month = 1;
$year++;
}
2011-02-26 17:04:12 +03:00
} while ($current < $totime);
return $result;
}
2011-02-26 17:04:12 +03:00
function get_form_date($day, $month)
{
if (preg_match('/^(\d{2}).(\d{2})$/', $month, $matches)) {
return mktime(0, 0, 0, $matches[1], $day, $matches[2]);
}
return 0;
}
2011-02-26 17:04:12 +03:00
function set_form_date($utime, $prefix)
{
global $page;
$page["form${prefix}day"] = date("d", $utime);
$page["form${prefix}month"] = date("m.y", $utime);
}
2011-02-26 17:04:12 +03:00
function date_to_text($unixtime)
{
if ($unixtime < 60 * 60 * 24 * 30)
return getlocal("time.never");
2011-02-26 17:04:12 +03:00
$then = getdate($unixtime);
$now = getdate();
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
$date_format = getlocal("time.today.at");
2011-02-26 17:04:12 +03:00
} else if (($then['yday'] + 1) == $now['yday'] && $then['year'] == $now['year']) {
$date_format = getlocal("time.yesterday.at");
} else {
$date_format = getlocal("time.dateformat");
}
2011-02-26 17:04:12 +03:00
return strftime($date_format . " " . getlocal("time.timeformat"), $unixtime);
}
$dbversion = '1.6.3';
2011-02-26 15:15:35 +03:00
$featuresversion = '1.6.4';
$settings = array(
'dbversion' => 0,
2011-02-26 15:15:35 +03:00
'featuresversion' => 0,
'title' => 'Your Company',
'hosturl' => 'http://mibew.org',
'logo' => '',
'usernamepattern' => '{name}',
'chatstyle' => 'default',
'chattitle' => 'Live Support',
'geolink' => 'http://api.hostip.info/get_html.php?ip={ip}',
'geolinkparams' => 'width=440,height=100,toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1',
'max_uploaded_file_size' => 100000,
'max_connections_from_one_host' => 10,
2011-11-26 01:00:22 +04:00
'thread_lifetime' => 60,
2011-02-26 17:04:12 +03:00
'email' => '', /* inbox for left messages */
'left_messages_locale' => $home_locale,
'sendmessagekey' => 'center',
'enableban' => '0',
'enablessl' => '0',
2011-02-26 17:04:12 +03:00
'forcessl' => '0',
'usercanchangename' => '1',
'enablegroups' => '0',
'enablestatistics' => '1',
2011-04-07 12:34:04 +04:00
'enabletracking' => '0',
'enablepresurvey' => '1',
2011-02-26 17:04:12 +03:00
'surveyaskmail' => '0',
'surveyaskgroup' => '1',
'surveyaskmessage' => '0',
'enablepopupnotification' => '0',
'showonlineoperators' => '0',
'enablecaptcha' => '0',
2011-02-26 17:04:12 +03:00
'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
'updatefrequency_operator' => 2,
'updatefrequency_chat' => 2,
'updatefrequency_oldchat' => 7,
2011-04-07 12:34:04 +04:00
'updatefrequency_tracking' => 10,
'visitors_limit' => 20, /* Number of visitors to look over */
'invitation_lifetime' => 60, /* Lifetime for invitation to chat */
'tracking_lifetime' => 600, /* Time to store tracked old visitors' data */
);
$settingsloaded = false;
$settings_in_db = array();
2011-02-26 17:04:12 +03:00
function loadsettings_($link)
{
2011-02-26 16:13:16 +03:00
global $settingsloaded, $settings_in_db, $settings, $mysqlprefix;
2011-02-26 17:04:12 +03:00
if ($settingsloaded) {
return;
}
$settingsloaded = true;
$sqlresult = perform_query("select vckey,vcvalue from ${mysqlprefix}chatconfig", $link);
while ($row = db_fetch_assoc($sqlresult)) {
$name = $row['vckey'];
$settings[$name] = $row['vcvalue'];
$settings_in_db[$name] = true;
}
db_free_result($sqlresult);
}
2011-02-26 17:04:12 +03:00
function loadsettings()
{
global $settingsloaded;
2011-02-26 17:04:12 +03:00
if (!$settingsloaded) {
$link = connect();
loadsettings_($link);
close_connection($link);
2011-02-26 17:04:12 +03:00
}
}
2011-02-26 17:04:12 +03:00
function getchatstyle()
{
global $settings;
2011-02-26 17:04:12 +03:00
$chatstyle = verifyparam("style", "/^\w+$/", "");
if ($chatstyle) {
return $chatstyle;
}
loadsettings();
return $settings['chatstyle'];
}
2011-02-26 17:04:12 +03:00
function jspath()
{
global $jsver;
2011-02-26 17:04:12 +03:00
return "js/$jsver";
}
?>