diff --git a/src/messenger/webim/b.php b/src/messenger/webim/b.php
index 93610209..6713114e 100644
--- a/src/messenger/webim/b.php
+++ b/src/messenger/webim/b.php
@@ -37,8 +37,7 @@ if(!$lang || !locale_exists($lang)) {
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
if($groupid) {
- loadsettings();
- if($settings['enablegroups'] == '1') {
+ if(Settings::get('enablegroups') == '1') {
$group = group_by_id($groupid);
if(!$group) {
$groupid = "";
diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php
index 210c988d..eb179c9a 100644
--- a/src/messenger/webim/client.php
+++ b/src/messenger/webim/client.php
@@ -23,8 +23,7 @@ require_once('libs/expand.php');
require_once('libs/captcha.php');
require_once('libs/invitation.php');
-loadsettings();
-if($settings['enablessl'] == "1" && $settings['forcessl'] == "1") {
+if(Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {
if(!is_secure_request()) {
$requested = $_SERVER['PHP_SELF'];
if($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
@@ -47,7 +46,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
$groupid = "";
$groupname = "";
$group = NULL;
- if($settings['enablegroups'] == '1') {
+ if(Settings::get('enablegroups') == '1') {
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
if($groupid) {
$group = group_by_id($groupid);
@@ -67,7 +66,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
$email = getparam("email");
$referrer = urldecode(getparam("referrer"));
- if($settings['usercanchangename'] == "1" && isset($_POST['name'])) {
+ if(Settings::get('usercanchangename') == "1" && isset($_POST['name'])) {
$newname = getparam("name");
if($newname != $visitor['name']) {
$data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,');
@@ -95,8 +94,8 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
}
$invitation_state = invitation_state($_SESSION['visitorid']);
- $visitor_is_invited = $settings['enabletracking'] && $invitation_state['invited'] && !$invitation_state['threadid'];
- if($settings['enablepresurvey'] == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on') && !$visitor_is_invited) {
+ $visitor_is_invited = Settings::get('enabletracking') && $invitation_state['invited'] && !$invitation_state['threadid'];
+ if(Settings::get('enablepresurvey') == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on') && !$visitor_is_invited) {
$page = array();
setup_logo($group);
setup_survey($visitor['name'], $email, $groupid, $info, $referrer);
diff --git a/src/messenger/webim/install/index.php b/src/messenger/webim/install/index.php
index b73556d4..d9e6001d 100644
--- a/src/messenger/webim/install/index.php
+++ b/src/messenger/webim/install/index.php
@@ -295,7 +295,7 @@ function add_canned_messages($link){
function check_status()
{
- global $page, $webimroot, $settings, $dbversion;
+ global $page, $webimroot, $dbversion;
$page['done'][] = getlocal2("install.0.php", array(phpversion()));
@@ -343,9 +343,8 @@ function check_status()
mysql_close($link);
- loadsettings();
- $settings['dbversion'] = $dbversion;
- update_settings();
+ Settings::set('dbversion', $dbversion);
+ Settings::update();
}
check_status();
diff --git a/src/messenger/webim/leavemessage.php b/src/messenger/webim/leavemessage.php
index 94da339d..e5318cae 100644
--- a/src/messenger/webim/leavemessage.php
+++ b/src/messenger/webim/leavemessage.php
@@ -46,8 +46,7 @@ function store_message($name, $email, $info, $message,$groupid,$referrer) {
$groupid = "";
$groupname = "";
$group = NULL;
-loadsettings();
-if($settings['enablegroups'] == '1') {
+if(Settings::get('enablegroups') == '1') {
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
if($groupid) {
$group = group_by_id($groupid);
@@ -77,7 +76,7 @@ if( !$email ) {
}
}
-if($settings["enablecaptcha"] == "1" && can_show_captcha()) {
+if(Settings::get("enablecaptcha") == "1" && can_show_captcha()) {
$captcha = getparam('captcha');
$original = isset($_SESSION["mibew_captcha"]) ? $_SESSION["mibew_captcha"] : "";
if(empty($original) || empty($captcha) || $captcha != $original) {
@@ -93,7 +92,7 @@ if( count($errors) > 0 ) {
exit;
}
-$message_locale = $settings['left_messages_locale'];
+$message_locale = Settings::get('left_messages_locale');
if(!locale_exists($message_locale)) {
$message_locale = $home_locale;
}
@@ -115,7 +114,7 @@ if (isset($group) && !empty($group['vcemail'])) {
}
if (empty($inbox_mail)) {
- $inbox_mail = $settings['email'];
+ $inbox_mail = Settings::get('email');
}
if($inbox_mail) {
diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php
index 83702360..a5fa9d80 100644
--- a/src/messenger/webim/libs/chat.php
+++ b/src/messenger/webim/libs/chat.php
@@ -175,7 +175,7 @@ function get_messages($threadid, $meth, $isuser, &$lastid)
function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agentid = null)
{
- global $webim_encoding, $webimroot, $connection_timeout, $settings;
+ global $webim_encoding, $webimroot, $connection_timeout;
$threadid = $thread['threadid'];
$istyping = abs($thread['current'] - $thread[$isuser ? "lpagent" : "lpuser"]) < $connection_timeout
&& $thread[$isuser ? "agentTyping" : "userTyping"] == "1" ? "1" : "0";
@@ -190,7 +190,6 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
}
print("");
} else if ($format == "html") {
- loadsettings();
$output = get_messages($threadid, "html", $isuser, $lastid);
start_html_output();
@@ -200,7 +199,7 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
"" .
"\n
\n" .
"\n" .
- "\n" .
+ "\n" .
"\n" .
"chat\n" .
"\n" .
@@ -219,11 +218,13 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen
function get_user_name($username, $addr, $id)
{
- global $settings;
- loadsettings();
- return str_replace("{addr}", $addr,
- str_replace("{id}", $id,
- str_replace("{name}", $username, $settings['usernamepattern'])));
+ return str_replace(
+ "{addr}", $addr,
+ str_replace(
+ "{id}", $id,
+ str_replace("{name}", $username, Settings::get('usernamepattern'))
+ )
+ );
}
function is_ajax_browser($browserid, $ver, $useragent)
@@ -306,27 +307,26 @@ function needsFramesrc()
function setup_logo($group = NULL)
{
- global $page, $settings;
- loadsettings();
+ global $page;
$toplevelgroup = (!$group)?array():get_top_level_group($group);
- $page['ct.company.name'] = topage(empty($toplevelgroup['vctitle'])?$settings['title']:$toplevelgroup['vctitle']);
- $page['ct.company.chatLogoURL'] = topage(empty($toplevelgroup['vclogo'])?$settings['logo']:$toplevelgroup['vclogo']);
- $page['webimHost'] = topage(empty($toplevelgroup['vchosturl'])?$settings['hosturl']:$toplevelgroup['vchosturl']);
+ $page['ct.company.name'] = topage(empty($toplevelgroup['vctitle'])?Settings::get('title'):$toplevelgroup['vctitle']);
+ $page['ct.company.chatLogoURL'] = topage(empty($toplevelgroup['vclogo'])?Settings::get('logo'):$toplevelgroup['vclogo']);
+ $page['webimHost'] = topage(empty($toplevelgroup['vchosturl'])?Settings::get('hosturl'):$toplevelgroup['vchosturl']);
}
function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info, $referrer, $canshowcaptcha)
{
- global $settings, $page;
+ global $page;
$page['formname'] = topage($name);
$page['formemail'] = topage($email);
$page['formmessage'] = $message ? topage($message) : "";
- $page['showcaptcha'] = $settings["enablecaptcha"] == "1" && $canshowcaptcha ? "1" : "";
+ $page['showcaptcha'] = Settings::get("enablecaptcha") == "1" && $canshowcaptcha ? "1" : "";
$page['formgroupid'] = $groupid;
$page['formgroupname'] = $groupname;
$page['forminfo'] = topage($info);
$page['referrer'] = urlencode(topage($referrer));
- if ($settings['enablegroups'] == '1') {
+ if (Settings::get('enablegroups') == '1') {
$groups = setup_groups_select($groupid, false);
if ($groups) {
$page['groups'] = $groups['select'];
@@ -339,7 +339,7 @@ function setup_leavemessage($name, $email, $message, $groupid, $groupname, $info
function setup_survey($name, $email, $groupid, $info, $referrer)
{
- global $settings, $page;
+ global $page;
$page['formname'] = topage($name);
$page['formemail'] = topage($email);
@@ -347,7 +347,7 @@ function setup_survey($name, $email, $groupid, $info, $referrer)
$page['forminfo'] = topage($info);
$page['referrer'] = urlencode(topage($referrer));
- if ($settings['enablegroups'] == '1' && $settings["surveyaskgroup"] == "1") {
+ if (Settings::get('enablegroups') == '1' && Settings::get('surveyaskgroup') == '1') {
$groups = setup_groups_select($groupid, true);
if ($groups) {
$page['groups'] = $groups['select'];
@@ -356,15 +356,13 @@ function setup_survey($name, $email, $groupid, $info, $referrer)
}
}
- $page['showemail'] = $settings["surveyaskmail"] == "1" ? "1" : "";
- $page['showmessage'] = $settings["surveyaskmessage"] == "1" ? "1" : "";
- $page['showname'] = $settings['usercanchangename'] == "1" ? "1" : "";
+ $page['showemail'] = Settings::get("surveyaskmail") == "1" ? "1" : "";
+ $page['showmessage'] = Settings::get("surveyaskmessage") == "1" ? "1" : "";
+ $page['showname'] = Settings::get('usercanchangename') == "1" ? "1" : "";
}
function setup_groups_select($groupid, $markoffline)
{
- global $settings;
-
$showgroups = ($groupid == '')?true:group_has_children($groupid);
if (!$showgroups) {
return false;
@@ -384,7 +382,7 @@ function setup_groups_select($groupid, $markoffline)
if ($k['inumofagents'] == 0 || ($groupid && $k['parent'] != $groupid && $k['groupid'] != $groupid )) {
continue;
}
- if ($k['ilastseen'] !== NULL && $k['ilastseen'] < $settings['online_timeout']) {
+ if ($k['ilastseen'] !== NULL && $k['ilastseen'] < Settings::get('online_timeout')) {
if (!$selectedgroupid) {
$selectedgroupid = $k['groupid']; // select first online group
}
@@ -408,8 +406,7 @@ function setup_groups_select($groupid, $markoffline)
function setup_chatview_for_user($thread, $level)
{
- global $page, $webimroot, $settings;
- loadsettings();
+ global $page, $webimroot;
$page = array();
if (! empty($thread['groupid'])) {
$group = group_by_id($thread['groupid']);
@@ -427,12 +424,12 @@ function setup_chatview_for_user($thread, $level)
$page['ct.chatThreadId'] = $thread['threadid'];
$page['ct.token'] = $thread['ltoken'];
$page['ct.user.name'] = htmlspecialchars(topage($thread['userName']));
- $page['canChangeName'] = $settings['usercanchangename'] == "1";
- $page['chat.title'] = topage(empty($group['vcchattitle'])?$settings['chattitle']:$group['vcchattitle']);
+ $page['canChangeName'] = Settings::get('usercanchangename') == "1";
+ $page['chat.title'] = topage(empty($group['vcchattitle'])?Settings::get('chattitle'):$group['vcchattitle']);
$page['chat.close.confirmation'] = getlocal('chat.close.confirmation');
setup_logo($group);
- if ($settings['sendmessagekey'] == 'enter') {
+ if (Settings::get('sendmessagekey') == 'enter') {
$page['send_shortcut'] = "Enter";
$page['ignorectrl'] = 1;
} else {
@@ -443,20 +440,19 @@ function setup_chatview_for_user($thread, $level)
$params = "thread=" . $thread['threadid'] . "&token=" . $thread['ltoken'];
$page['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread";
- if ($settings['enablessl'] == "1" && !is_secure_request()) {
+ if (Settings::get('enablessl') == "1" && !is_secure_request()) {
$page['sslLink'] = get_app_location(true, true) . "/client.php?" . $params . "&level=$level";
}
$page['isOpera95'] = is_agent_opera95();
$page['neediframesrc'] = needsFramesrc();
- $page['frequency'] = $settings['updatefrequency_chat'];
+ $page['frequency'] = Settings::get('updatefrequency_chat');
}
function setup_chatview_for_operator($thread, $operator)
{
- global $page, $webimroot, $company_logo_link, $webim_encoding, $company_name, $settings;
- loadsettings();
+ global $page, $webimroot, $company_logo_link, $webim_encoding, $company_name;
$page = array();
if (! is_null($thread['groupid'])) {
$group = group_by_id($thread['groupid']);
@@ -470,11 +466,11 @@ function setup_chatview_for_operator($thread, $operator)
$page['ct.chatThreadId'] = $thread['threadid'];
$page['ct.token'] = $thread['ltoken'];
$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread['userName'], $thread['remote'], $thread['userid'])));
- $page['chat.title'] = topage(empty($group['vcchattitle'])?$settings['chattitle']:$group['vcchattitle']);
+ $page['chat.title'] = topage(empty($group['vcchattitle'])?Settings::get('chattitle'):$group['vcchattitle']);
$page['chat.close.confirmation'] = getlocal('chat.close.confirmation');
setup_logo($group);
- if ($settings['sendmessagekey'] == 'enter') {
+ if (Settings::get('sendmessagekey') == 'enter') {
$page['send_shortcut'] = "Enter";
$page['ignorectrl'] = 1;
} else {
@@ -482,14 +478,14 @@ function setup_chatview_for_operator($thread, $operator)
$page['ignorectrl'] = 0;
}
- if ($settings['enablessl'] == "1" && !is_secure_request()) {
+ if (Settings::get('enablessl') == "1" && !is_secure_request()) {
$page['sslLink'] = get_app_location(true, true) . "/operator/agent.php?thread=" . $thread['threadid'] . "&token=" . $thread['ltoken'];
}
$page['isOpera95'] = is_agent_opera95();
$page['neediframesrc'] = needsFramesrc();
$page['historyParams'] = array("userid" => "" . $thread['userid']);
$page['historyParamsLink'] = add_params($webimroot . "/operator/userhistory.php", $page['historyParams']);
- if ($settings['enabletracking']) {
+ if (Settings::get('enabletracking')) {
$visitor = track_get_visitor_by_threadid($thread['threadid']);
$page['trackedParams'] = array("visitor" => "" . $visitor['visitorid']);
$page['trackedParamsLink'] = add_params($webimroot . "/operator/tracked.php", $page['trackedParams']);
@@ -512,7 +508,7 @@ function setup_chatview_for_operator($thread, $operator)
$page['redirectLink'] = "$webimroot/operator/agent.php?" . $params . "&act=redirect";
$page['namePostfix'] = "";
- $page['frequency'] = $settings['updatefrequency_chat'];
+ $page['frequency'] = Settings::get('updatefrequency_chat');
}
function update_thread_access($threadid, $params)
@@ -619,8 +615,8 @@ function close_thread($thread, $isuser)
function close_old_threads()
{
- global $state_closed, $state_left, $state_chatting, $settings;
- if ($settings['thread_lifetime'] == 0) {
+ global $state_closed, $state_left, $state_chatting;
+ if (Settings::get('thread_lifetime') == 0) {
return;
}
@@ -641,7 +637,7 @@ function close_old_threads()
':next_revision' => next_revision(),
':state_closed' => $state_closed,
':state_left' => $state_left,
- ':thread_lifetime' => $settings['thread_lifetime']
+ ':thread_lifetime' => Settings::get('thread_lifetime')
)
);
}
@@ -721,14 +717,14 @@ function do_take_thread($threadid, $operatorId, $operatorName, $chatstart = fals
function reopen_thread($threadid)
{
- global $state_queue, $state_loading, $state_waiting, $state_chatting, $state_closed, $state_left, $kind_events, $settings;
+ global $state_queue, $state_loading, $state_waiting, $state_chatting, $state_closed, $state_left, $kind_events;
$thread = thread_by_id($threadid);
if (!$thread)
return FALSE;
- if ($settings['thread_lifetime'] != 0 && abs($thread['lpuser'] - time()) > $settings['thread_lifetime'] && abs($thread['lpagent'] - time()) > $settings['thread_lifetime']) {
+ if (Settings::get('thread_lifetime') != 0 && abs($thread['lpuser'] - time()) > Settings::get('thread_lifetime') && abs($thread['lpagent'] - time()) > Settings::get('thread_lifetime')) {
return FALSE;
}
@@ -806,8 +802,8 @@ function check_for_reassign($thread, $operator)
function check_connections_from_remote($remote)
{
- global $settings, $state_closed, $state_left;
- if ($settings['max_connections_from_one_host'] == 0) {
+ global $state_closed, $state_left;
+ if (Settings::get('max_connections_from_one_host') == 0) {
return true;
}
@@ -820,7 +816,7 @@ function check_connections_from_remote($remote)
);
if ($result && isset($result['opened'])) {
- return $result['opened'] < $settings['max_connections_from_one_host'];
+ return $result['opened'] < Settings::get('max_connections_from_one_host');
}
return true;
}
diff --git a/src/messenger/webim/libs/classes/settings.php b/src/messenger/webim/libs/classes/settings.php
index 981cf410..ce11bdcf 100644
--- a/src/messenger/webim/libs/classes/settings.php
+++ b/src/messenger/webim/libs/classes/settings.php
@@ -64,6 +64,7 @@ Class Settings {
'logo' => '',
'usernamepattern' => '{name}',
'chatstyle' => 'default',
+ 'invitationstyle' => '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',
diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php
index ed262826..9608ef45 100644
--- a/src/messenger/webim/libs/common.php
+++ b/src/messenger/webim/libs/common.php
@@ -20,6 +20,7 @@ session_start();
require_once(dirname(__FILE__) . '/converter.php');
require_once(dirname(__FILE__) . '/config.php');
require_once(dirname(__FILE__) . '/classes/database.php');
+require_once(dirname(__FILE__) . '/classes/settings.php');
$version = '1.6.5';
$jsver = "165";
@@ -563,85 +564,13 @@ function date_to_text($unixtime)
$dbversion = '1.6.3';
$featuresversion = '1.6.4';
-$settings = array(
- 'dbversion' => 0,
- '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,
- 'thread_lifetime' => 600,
-
- 'email' => '', /* inbox for left messages */
- 'left_messages_locale' => $home_locale,
- 'sendmessagekey' => 'center',
-
- 'enableban' => '0',
- 'enablessl' => '0',
- 'forcessl' => '0',
- 'usercanchangename' => '1',
- 'enablegroups' => '0',
- 'enablegroupsisolation' => '0',
- 'enablestatistics' => '1',
- 'enabletracking' => '0',
- 'enablepresurvey' => '1',
- 'surveyaskmail' => '0',
- 'surveyaskgroup' => '1',
- 'surveyaskmessage' => '0',
- 'enablepopupnotification' => '0',
- 'showonlineoperators' => '0',
- 'enablecaptcha' => '0',
-
- 'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
- 'updatefrequency_operator' => 2,
- 'updatefrequency_chat' => 2,
- 'updatefrequency_oldchat' => 7,
-
- '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();
-
-function loadsettings()
-{
- global $settingsloaded, $settings_in_db, $settings;
- if ($settingsloaded) {
- return;
- }
- $settingsloaded = true;
-
- $db = Database::getInstance();
- $rows = $db->query(
- "select vckey,vcvalue from {chatconfig}",
- NULL,
- array('return_rows' => Database::RETURN_ALL_ROWS)
- );
- foreach ($rows as $row) {
- $name = $row['vckey'];
- $settings[$name] = $row['vcvalue'];
- $settings_in_db[$name] = true;
- }
-}
-
function getchatstyle()
{
- global $settings;
$chatstyle = verifyparam("style", "/^\w+$/", "");
if ($chatstyle) {
return $chatstyle;
}
- loadsettings();
- return $settings['chatstyle'];
+ return Settings::get('chatstyle');
}
function jspath()
diff --git a/src/messenger/webim/libs/demothread.php b/src/messenger/webim/libs/demothread.php
index 81ba0b9f..fee689d1 100644
--- a/src/messenger/webim/libs/demothread.php
+++ b/src/messenger/webim/libs/demothread.php
@@ -27,8 +27,7 @@ function demo_print_message($msg, $format)
function demo_process_thread($act, $outformat, $lastid, $isuser, $canpost, $istyping, $postmessage)
{
- global $kind_for_agent, $kind_info, $kind_events, $kind_user, $kind_agent, $webimroot, $settings;
- loadsettings();
+ global $kind_for_agent, $kind_info, $kind_events, $kind_user, $kind_agent, $webimroot;
if ($act == "refresh" || $act == "post") {
$lastid++;
if ($outformat == "xml") {
@@ -42,7 +41,7 @@ function demo_process_thread($act, $outformat, $lastid, $isuser, $canpost, $isty
"" .
"\n\n" .
"\n" .
- "\n" .
+ "\n" .
"\n" .
"chat\n" .
"\n" .
diff --git a/src/messenger/webim/libs/getcode.php b/src/messenger/webim/libs/getcode.php
index 1f5305f6..f72a3b21 100644
--- a/src/messenger/webim/libs/getcode.php
+++ b/src/messenger/webim/libs/getcode.php
@@ -17,7 +17,6 @@
function generate_button($title, $locale, $style, $invitationstyle, $group, $inner, $showhost, $forcesecure, $modsecurity)
{
- global $settings;
$link = get_app_location($showhost, $forcesecure) . "/client.php";
if ($locale)
$link = append_query($link, "locale=$locale");
@@ -30,14 +29,14 @@ function generate_button($title, $locale, $style, $invitationstyle, $group, $inn
$jslink = append_query("'" . $link, "url='+escape(document.location.href$modsecfix)+'&referrer='+escape(document.referrer$modsecfix)");
$temp = get_popup($link, "$jslink",
$inner, $title, "webim", "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1");
- if ($settings['enabletracking']) {
+ if (Settings::get('enabletracking')) {
$temp = preg_replace('/^(