Update setup_chatview* functions to return data

This commit is contained in:
Dmitriy Simushev 2013-02-15 14:51:04 +00:00
parent 037135cf71
commit f28e65f0cf
3 changed files with 62 additions and 49 deletions

View File

@ -36,6 +36,8 @@ if(Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {
} }
} }
$page = array();
if( !isset($_GET['token']) || !isset($_GET['thread']) ) { if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
$thread = NULL; $thread = NULL;
@ -175,7 +177,10 @@ if (! $thread) {
die("wrong thread"); die("wrong thread");
} }
setup_chatview_for_user($thread, $level); $page = array_merge_recursive(
$page,
setup_chatview_for_user($thread, $level)
);
$pparam = verifyparam( "act", "/^(mailthread)$/", "default"); $pparam = verifyparam( "act", "/^(mailthread)$/", "default");
if( $pparam == "mailthread" ) { if( $pparam == "mailthread" ) {

View File

@ -258,13 +258,13 @@ function setup_groups_select($groupid, $markoffline)
} }
/** /**
* Set up some page variables for chat for user * Prepare some data for chat for both user and operator
* *
* @global array $page The page array. Use to pass values to page templates.
* @param Thread $thread thread object * @param Thread $thread thread object
* @return array Array of chat view data
*/ */
function setup_chatview(Thread $thread) { function setup_chatview(Thread $thread) {
global $page; $data = array();
// Get group info // Get group info
if (! empty($thread->groupId)) { if (! empty($thread->groupId)) {
@ -275,9 +275,9 @@ function setup_chatview(Thread $thread) {
} }
// Set thread params // Set thread params
$page['ct.chatThreadId'] = $thread->id; $data['ct.chatThreadId'] = $thread->id;
$page['ct.token'] = $thread->lastToken; $data['ct.token'] = $thread->lastToken;
$page['chat.title'] = topage( $data['chat.title'] = topage(
empty($group['vcchattitle']) empty($group['vcchattitle'])
? Settings::get('chattitle') ? Settings::get('chattitle')
: $group['vcchattitle'] : $group['vcchattitle']
@ -288,105 +288,107 @@ function setup_chatview(Thread $thread) {
// Set enter key shortcut // Set enter key shortcut
if (Settings::get('sendmessagekey') == 'enter') { if (Settings::get('sendmessagekey') == 'enter') {
$page['send_shortcut'] = "Enter"; $data['send_shortcut'] = "Enter";
$page['ignorectrl'] = 1; $data['ignorectrl'] = 1;
} else { } else {
$page['send_shortcut'] = is_mac_opera() $data['send_shortcut'] = is_mac_opera()
? "⌘-Enter" ? "⌘-Enter"
: "Ctrl-Enter"; : "Ctrl-Enter";
$page['ignorectrl'] = 0; $data['ignorectrl'] = 0;
} }
// Set some browser info // Set some browser info
$page['isOpera95'] = is_agent_opera95(); $data['isOpera95'] = is_agent_opera95();
$page['neediframesrc'] = needsFramesrc(); $data['neediframesrc'] = needsFramesrc();
// Set refresh frequency // Set refresh frequency
$page['frequency'] = Settings::get('updatefrequency_chat'); $data['frequency'] = Settings::get('updatefrequency_chat');
// Load dialogs style options // Load dialogs style options
$style_config = get_dialogs_style_config(getchatstyle()); $style_config = get_dialogs_style_config(getchatstyle());
$page['chatStyles.chatWindowParams'] = $style_config['chat']['window_params']; $data['chatStyles.chatWindowParams'] = $style_config['chat']['window_params'];
$page['chatStyles.mailWindowParams'] = $style_config['mail']['window_params']; $data['chatStyles.mailWindowParams'] = $style_config['mail']['window_params'];
// Load core style options // Load core style options
$style_config = get_core_style_config(); $style_config = get_core_style_config();
$page['coreStyles.historyWindowParams'] = $style_config['history']['window_params']; $data['coreStyles.historyWindowParams'] = $style_config['history']['window_params'];
return $data;
} }
/** /**
* Set up some page variables for chat for user * Prepare some data for chat for user
* *
* @global array $page The page array. Use to pass values to page templates.
* @global string $webimroot Root URL path for Mibew * @global string $webimroot Root URL path for Mibew
* @param Thread $thread thread object * @param Thread $thread thread object
* @param string $level Chat level. Indicates ajax or old chat window should * @param string $level Chat level. Indicates ajax or old chat window should
* be used * be used
* @return array Array of chat view data
*/ */
function setup_chatview_for_user(Thread $thread, $level) { function setup_chatview_for_user(Thread $thread, $level) {
global $page, $webimroot; global $webimroot;
$page = array();
setup_chatview($thread); $data = setup_chatview($thread);
// Set user info // Set user info
$page['agent'] = false; $data['agent'] = false;
$page['user'] = true; $data['user'] = true;
$page['canpost'] = true; $data['canpost'] = true;
$page['level'] = $level; $data['level'] = $level;
$page['ct.user.name'] = htmlspecialchars(topage($thread->userName)); $data['ct.user.name'] = htmlspecialchars(topage($thread->userName));
$page['canChangeName'] = Settings::get('usercanchangename') == "1"; $data['canChangeName'] = Settings::get('usercanchangename') == "1";
$params = "thread=" . $thread->id . "&token=" . $thread->lastToken; $params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
// Set link to send mail page // Set link to send mail page
$page['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread"; $data['mailLink'] = "$webimroot/client.php?" . $params . "&level=$level&act=mailthread";
// Set SSL link // 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) . "/client.php?" . $params . "&level=$level"; $data['sslLink'] = get_app_location(true, true) . "/client.php?" . $params . "&level=$level";
} }
return $data;
} }
/** /**
* Set up some page variables for chat for operator * Prepare some data 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 $webimroot Root URL path for Mibew
* @global string $webim_encoding Current Mibew encoding * @global string $webim_encoding Current Mibew encoding
* @param Thread $thread thread object * @param Thread $thread thread object
* @param string $level Chat level. Indicates ajax or old chat window should * @param string $level Chat level. Indicates ajax or old chat window should
* be used * be used
* @return array Array of chat view data
*/ */
function setup_chatview_for_operator(Thread $thread, $operator) { function setup_chatview_for_operator(Thread $thread, $operator) {
global $page, $webimroot, $webim_encoding; global $webimroot, $webim_encoding;
$page = array();
setup_chatview($thread); $data = setup_chatview($thread);
// Set operator info // Set operator info
$page['agent'] = true; $data['agent'] = true;
$page['user'] = false; $data['user'] = false;
$page['canpost'] = $thread->agentId == $operator['operatorid']; $data['canpost'] = $thread->agentId == $operator['operatorid'];
$page['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread->userName, $thread->remote, $thread->userId))); $data['ct.user.name'] = htmlspecialchars(topage(get_user_name($thread->userName, $thread->remote, $thread->userId)));
// Set SSL link // 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; $data['sslLink'] = get_app_location(true, true) . "/operator/agent.php?thread=" . $thread->id . "&token=" . $thread->lastToken;
} }
// Set history window params // Set history window params
$page['historyParams'] = array("userid" => (string)$thread->userId); $data['historyParams'] = array("userid" => (string)$thread->userId);
$page['historyParamsLink'] = add_params( $data['historyParamsLink'] = add_params(
$webimroot . "/operator/userhistory.php", $webimroot . "/operator/userhistory.php",
$page['historyParams'] $data['historyParams']
); );
// Set tracking params // 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']); $data['trackedParams'] = array("visitor" => "" . $visitor['visitorid']);
$page['trackedParamsLink'] = add_params($webimroot . "/operator/tracked.php", $page['trackedParams']); $data['trackedParamsLink'] = add_params($webimroot . "/operator/tracked.php", $data['trackedParams']);
} }
// Get predefined answers // Get predefined answers
@ -407,13 +409,15 @@ function setup_chatview_for_operator(Thread $thread, $operator) {
'full' => myiconv($webim_encoding, getoutputenc(), $answer['vcvalue']) 'full' => myiconv($webim_encoding, getoutputenc(), $answer['vcvalue'])
); );
} }
$page['predefinedAnswers'] = json_encode($predefined_answers); $data['predefinedAnswers'] = json_encode($predefined_answers);
// Set link to user redirection page // 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"; $data['redirectLink'] = "$webimroot/operator/agent.php?" . $params . "&act=redirect";
$page['namePostfix'] = ""; $data['namePostfix'] = "";
return $data;
} }
function ban_for_addr($addr) function ban_for_addr($addr)

View File

@ -39,6 +39,7 @@ if (Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {
} }
$threadid = verifyparam("thread", "/^\d{1,8}$/"); $threadid = verifyparam("thread", "/^\d{1,8}$/");
$page = array();
if (!isset($_GET['token'])) { if (!isset($_GET['token'])) {
@ -115,7 +116,10 @@ if ($thread->agentId != $operator['operatorid'] && !is_capable($can_viewthreads,
exit; exit;
} }
setup_chatview_for_operator($thread, $operator); $page = array_merge_recursive(
$page,
setup_chatview_for_operator($thread, $operator)
);
start_html_output(); start_html_output();