mirror of
https://github.com/Mibew/design.git
synced 2025-01-22 18:10:33 +03:00
Remove some duplicated code in libs/chat.php
This commit is contained in:
parent
e731d9869e
commit
d4e51d3dfd
@ -223,48 +223,51 @@ function setup_groups_select($groupid, $markoffline)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_chatview_for_user($thread, $level)
|
/**
|
||||||
{
|
* Set up some page variables for chat for user
|
||||||
global $page, $webimroot;
|
*
|
||||||
$page = array();
|
* @global array $page The page array. Use to pass values to page templates.
|
||||||
|
* @param Thread $thread thread object
|
||||||
|
*/
|
||||||
|
function setup_chatview(Thread $thread) {
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
// Get group info
|
||||||
if (! empty($thread->groupId)) {
|
if (! empty($thread->groupId)) {
|
||||||
$group = group_by_id($thread->groupId);
|
$group = group_by_id($thread->groupId);
|
||||||
$group = get_top_level_group($group);
|
$group = get_top_level_group($group);
|
||||||
} else {
|
} else {
|
||||||
$group = array();
|
$group = array();
|
||||||
}
|
}
|
||||||
$page['agent'] = false;
|
|
||||||
$page['user'] = true;
|
// Set thread params
|
||||||
$page['canpost'] = true;
|
|
||||||
$nameisset = getstring("chat.default.username") != $thread->userName;
|
|
||||||
$page['displ1'] = $nameisset ? "none" : "inline";
|
|
||||||
$page['displ2'] = $nameisset ? "inline" : "none";
|
|
||||||
$page['level'] = $level;
|
|
||||||
$page['ct.chatThreadId'] = $thread->id;
|
$page['ct.chatThreadId'] = $thread->id;
|
||||||
$page['ct.token'] = $thread->lastToken;
|
$page['ct.token'] = $thread->lastToken;
|
||||||
$page['ct.user.name'] = htmlspecialchars(topage($thread->userName));
|
$page['chat.title'] = topage(
|
||||||
$page['canChangeName'] = Settings::get('usercanchangename') == "1";
|
empty($group['vcchattitle'])
|
||||||
$page['chat.title'] = topage(empty($group['vcchattitle'])?Settings::get('chattitle'):$group['vcchattitle']);
|
? Settings::get('chattitle')
|
||||||
|
: $group['vcchattitle']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Setup logo
|
||||||
setup_logo($group);
|
setup_logo($group);
|
||||||
|
|
||||||
|
// Set enter key shortcut
|
||||||
if (Settings::get('sendmessagekey') == 'enter') {
|
if (Settings::get('sendmessagekey') == 'enter') {
|
||||||
$page['send_shortcut'] = "Enter";
|
$page['send_shortcut'] = "Enter";
|
||||||
$page['ignorectrl'] = 1;
|
$page['ignorectrl'] = 1;
|
||||||
} else {
|
} else {
|
||||||
$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
|
$page['send_shortcut'] = is_mac_opera()
|
||||||
|
? "⌘-Enter"
|
||||||
|
: "Ctrl-Enter";
|
||||||
$page['ignorectrl'] = 0;
|
$page['ignorectrl'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
|
// Set some browser info
|
||||||
$page['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread";
|
|
||||||
|
|
||||||
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['isOpera95'] = is_agent_opera95();
|
||||||
$page['neediframesrc'] = needsFramesrc();
|
$page['neediframesrc'] = needsFramesrc();
|
||||||
|
|
||||||
|
// Set refresh frequency
|
||||||
$page['frequency'] = Settings::get('updatefrequency_chat');
|
$page['frequency'] = Settings::get('updatefrequency_chat');
|
||||||
|
|
||||||
// Load dialogs style options
|
// Load dialogs style options
|
||||||
@ -277,45 +280,82 @@ function setup_chatview_for_user($thread, $level)
|
|||||||
$page['coreStyles.historyWindowParams'] = $style_config['history']['window_params'];
|
$page['coreStyles.historyWindowParams'] = $style_config['history']['window_params'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup_chatview_for_operator($thread, $operator)
|
/**
|
||||||
{
|
* Set up some page variables for chat for user
|
||||||
global $page, $webimroot, $company_logo_link, $webim_encoding, $company_name;
|
*
|
||||||
|
* @global array $page The page array. Use to pass values to page templates.
|
||||||
|
* @global string $webimroot Root URL path for Mibew
|
||||||
|
* @param Thread $thread thread object
|
||||||
|
* @param string $level Chat level. Indicates ajax or old chat window should
|
||||||
|
* be used
|
||||||
|
*/
|
||||||
|
function setup_chatview_for_user(Thread $thread, $level) {
|
||||||
|
global $page, $webimroot;
|
||||||
$page = array();
|
$page = array();
|
||||||
if (! is_null($thread->groupId)) {
|
|
||||||
$group = group_by_id($thread->groupId);
|
setup_chatview($thread);
|
||||||
$group = get_top_level_group($group);
|
|
||||||
} else {
|
// Set user info
|
||||||
$group = array();
|
$page['agent'] = false;
|
||||||
|
$page['user'] = true;
|
||||||
|
$page['canpost'] = true;
|
||||||
|
$page['level'] = $level;
|
||||||
|
$page['ct.user.name'] = htmlspecialchars(topage($thread->userName));
|
||||||
|
$page['canChangeName'] = Settings::get('usercanchangename') == "1";
|
||||||
|
|
||||||
|
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
|
||||||
|
|
||||||
|
// Set link to send mail page
|
||||||
|
$page['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread";
|
||||||
|
|
||||||
|
// Set SSL link
|
||||||
|
if (Settings::get('enablessl') == "1" && !is_secure_request()) {
|
||||||
|
$page['sslLink'] = get_app_location(true, true) . "/client.php?" . $params . "&level=$level";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up some page variables for chat for operator
|
||||||
|
*
|
||||||
|
* @global array $page The page array. Use to pass values to page templates.
|
||||||
|
* @global string $webimroot Root URL path for Mibew
|
||||||
|
* @global string $webim_encoding Current Mibew encoding
|
||||||
|
* @param Thread $thread thread object
|
||||||
|
* @param string $level Chat level. Indicates ajax or old chat window should
|
||||||
|
* be used
|
||||||
|
*/
|
||||||
|
function setup_chatview_for_operator(Thread $thread, $operator) {
|
||||||
|
global $page, $webimroot, $webim_encoding;
|
||||||
|
$page = array();
|
||||||
|
|
||||||
|
setup_chatview($thread);
|
||||||
|
|
||||||
|
// Set operator info
|
||||||
$page['agent'] = true;
|
$page['agent'] = true;
|
||||||
$page['user'] = false;
|
$page['user'] = false;
|
||||||
$page['canpost'] = $thread->agentId == $operator['operatorid'];
|
$page['canpost'] = $thread->agentId == $operator['operatorid'];
|
||||||
$page['ct.chatThreadId'] = $thread->id;
|
|
||||||
$page['ct.token'] = $thread->lastToken;
|
|
||||||
$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread->userName, $thread->remote, $thread->userId)));
|
$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread->userName, $thread->remote, $thread->userId)));
|
||||||
$page['chat.title'] = topage(empty($group['vcchattitle'])?Settings::get('chattitle'):$group['vcchattitle']);
|
|
||||||
|
|
||||||
setup_logo($group);
|
|
||||||
if (Settings::get('sendmessagekey') == 'enter') {
|
|
||||||
$page['send_shortcut'] = "Enter";
|
|
||||||
$page['ignorectrl'] = 1;
|
|
||||||
} else {
|
|
||||||
$page['send_shortcut'] = is_mac_opera() ? "⌘-Enter" : "Ctrl-Enter";
|
|
||||||
$page['ignorectrl'] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Set SSL link
|
||||||
if (Settings::get('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->id . "&token=" . $thread->lastToken;
|
$page['sslLink'] = get_app_location(true, true) . "/operator/agent.php?thread=" . $thread->id . "&token=" . $thread->lastToken;
|
||||||
}
|
}
|
||||||
$page['isOpera95'] = is_agent_opera95();
|
|
||||||
$page['neediframesrc'] = needsFramesrc();
|
// Set history window params
|
||||||
$page['historyParams'] = array("userid" => "" . $thread->userId);
|
$page['historyParams'] = array("userid" => (string)$thread->userId);
|
||||||
$page['historyParamsLink'] = add_params($webimroot . "/operator/userhistory.php", $page['historyParams']);
|
$page['historyParamsLink'] = add_params(
|
||||||
|
$webimroot . "/operator/userhistory.php",
|
||||||
|
$page['historyParams']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set tracking params
|
||||||
if (Settings::get('enabletracking')) {
|
if (Settings::get('enabletracking')) {
|
||||||
$visitor = track_get_visitor_by_threadid($thread->id);
|
$visitor = track_get_visitor_by_threadid($thread->id);
|
||||||
$page['trackedParams'] = array("visitor" => "" . $visitor['visitorid']);
|
$page['trackedParams'] = array("visitor" => "" . $visitor['visitorid']);
|
||||||
$page['trackedParamsLink'] = add_params($webimroot . "/operator/tracked.php", $page['trackedParams']);
|
$page['trackedParamsLink'] = add_params($webimroot . "/operator/tracked.php", $page['trackedParams']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get predefined answers
|
||||||
$canned_messages = load_canned_messages($thread->locale, 0);
|
$canned_messages = load_canned_messages($thread->locale, 0);
|
||||||
if ($thread->groupId) {
|
if ($thread->groupId) {
|
||||||
$canned_messages = array_merge(
|
$canned_messages = array_merge(
|
||||||
@ -324,7 +364,6 @@ function setup_chatview_for_operator($thread, $operator)
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get predefined answers
|
|
||||||
$predefined_answers = array();
|
$predefined_answers = array();
|
||||||
foreach ($canned_messages as $answer) {
|
foreach ($canned_messages as $answer) {
|
||||||
$predefined_answers[] = array(
|
$predefined_answers[] = array(
|
||||||
@ -336,20 +375,11 @@ function setup_chatview_for_operator($thread, $operator)
|
|||||||
}
|
}
|
||||||
$page['predefinedAnswers'] = json_encode($predefined_answers);
|
$page['predefinedAnswers'] = json_encode($predefined_answers);
|
||||||
|
|
||||||
|
// Set link to user redirection page
|
||||||
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
|
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
|
||||||
$page['redirectLink'] = "$webimroot/operator/agent.php?" . $params . "&act=redirect";
|
$page['redirectLink'] = "$webimroot/operator/agent.php?" . $params . "&act=redirect";
|
||||||
|
|
||||||
$page['namePostfix'] = "";
|
$page['namePostfix'] = "";
|
||||||
$page['frequency'] = Settings::get('updatefrequency_chat');
|
|
||||||
|
|
||||||
// Load dialogs style options
|
|
||||||
$style_config = get_dialogs_style_config(getchatstyle());
|
|
||||||
$page['chatStyles.chatWindowParams'] = $style_config['chat']['window_params'];
|
|
||||||
$page['chatStyles.mailWindowParams'] = $style_config['mail']['window_params'];
|
|
||||||
|
|
||||||
// Load core style options
|
|
||||||
$style_config = get_core_style_config();
|
|
||||||
$page['coreStyles.historyWindowParams'] = $style_config['history']['window_params'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ban_for_addr($addr)
|
function ban_for_addr($addr)
|
||||||
|
Loading…
Reference in New Issue
Block a user