diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 65eafbb5..fc1edb6c 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -26,7 +26,7 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { if( !$thread ) { if(!has_online_operators()) { - expand("design/default/leavemessage.tpl"); + expand("styles", getchatstyle(), "leavemessage.tpl"); exit; } @@ -66,13 +66,13 @@ setup_chatview_for_user($thread, $level); $pparam = verifyparam( "act", "/^(mailthread)$/", "default"); if( $pparam == "mailthread" ) { - expand("design/default/mail.tpl"); + expand("styles", getchatstyle(), "mail.tpl"); } else if( $level == "ajaxed" ) { - expand("design/default/chat.tpl"); + expand("styles", getchatstyle(), "chat.tpl"); } else if( $level == "simple" ) { - expand("design/default/chatsimple.tpl"); + expand("styles", getchatstyle(), "chatsimple.tpl"); } else if( $level == "old" ) { - expand("design/default/nochat.tpl"); + expand("styles", getchatstyle(), "nochat.tpl"); } ?> \ No newline at end of file diff --git a/src/messenger/webim/leavemessage.php b/src/messenger/webim/leavemessage.php index 34f8c234..14e2e55e 100644 --- a/src/messenger/webim/leavemessage.php +++ b/src/messenger/webim/leavemessage.php @@ -39,7 +39,7 @@ if( count($errors) > 0 ) { $page['formname'] = topage($visitor_name); $page['formemail'] = $email; $page['formmessage'] = topage($message); - expand("design/default/leavemessage.tpl"); + expand("styles", getchatstyle(), "leavemessage.tpl"); exit; } @@ -53,5 +53,5 @@ if($inbox_mail) { webim_mail($inbox_mail, $email, $subject, $body); } -expand("design/default/leavemessagesent.tpl"); +expand("styles", getchatstyle(), "leavemessagesent.tpl"); ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/common.php b/src/messenger/webim/libs/common.php index 5caa4e77..c1b73674 100644 --- a/src/messenger/webim/libs/common.php +++ b/src/messenger/webim/libs/common.php @@ -433,7 +433,8 @@ $settings = array( 'logo' => '', 'enableban' => '0', 'usernamepattern' => '{name}', - 'usercanchangename' => '1' + 'usercanchangename' => '1', + 'chatstyle' => 'default' ); $settingsloaded = false; $settings_in_db = array(); @@ -457,4 +458,10 @@ function loadsettings() { mysql_close($link); } +function getchatstyle() { + global $settings; + loadsettings(); + return $settings['chatstyle']; +} + ?> \ No newline at end of file diff --git a/src/messenger/webim/libs/expand.php b/src/messenger/webim/libs/expand.php index 84a25054..377e77e7 100644 --- a/src/messenger/webim/libs/expand.php +++ b/src/messenger/webim/libs/expand.php @@ -80,9 +80,15 @@ function expandtext($text) { return preg_replace_callback("/\\\${(\w+:)?([\w\.,]+)}/", "expand_var", $text); } -function expand($filename) { +function expand($basedir,$style,$filename) { start_html_output(); - $contents = @file_get_contents($filename) or die("illegal template"); + if(!is_dir("$basedir/$style")) { + $style = "default"; + } + $contents = @file_get_contents("$basedir/$style/$filename"); + if($contents === false) { + $contents = @file_get_contents("$basedir/default/$filename") or die("cannot load template"); + } echo expandtext($contents); } diff --git a/src/messenger/webim/mail.php b/src/messenger/webim/mail.php index 803a807e..6c764628 100644 --- a/src/messenger/webim/mail.php +++ b/src/messenger/webim/mail.php @@ -41,7 +41,7 @@ if( count($errors) > 0 ) { $page['ct.chatThreadId'] = $thread['threadid']; $page['ct.token'] = $thread['ltoken']; $page['level'] = ""; - expand("design/default/mail.tpl"); + expand("styles", getchatstyle(), "mail.tpl"); exit; } @@ -57,5 +57,5 @@ $body = getstring2("mail.user.history.body", array($thread['userName'],$history) webim_mail($email, $webim_from_email, $subject, $body); -expand("design/default/mailsent.tpl"); +expand("styles", getchatstyle(), "mailsent.tpl"); ?> \ No newline at end of file diff --git a/src/messenger/webim/operator/agent.php b/src/messenger/webim/operator/agent.php index c9bc5178..eefda164 100644 --- a/src/messenger/webim/operator/agent.php +++ b/src/messenger/webim/operator/agent.php @@ -79,9 +79,9 @@ if( $pparam == "redirect" ) { } $page['pagination_list'] = $agent_list; - expand("../design/default/redirect.tpl"); + expand("../styles", getchatstyle(), "redirect.tpl"); } else { - expand("../design/default/chat.tpl"); + expand("../styles", getchatstyle(), "chat.tpl"); } ?> \ No newline at end of file diff --git a/src/messenger/webim/operator/preview.php b/src/messenger/webim/operator/preview.php index b852e876..adced951 100644 --- a/src/messenger/webim/operator/preview.php +++ b/src/messenger/webim/operator/preview.php @@ -19,20 +19,20 @@ require_once('../libs/expand.php'); $operator = check_login(); -$designlist = array(); -$designfolder = "../design"; -if($handle = opendir($designfolder)) { +$stylelist = array(); +$stylesfolder = "../styles"; +if($handle = opendir($stylesfolder)) { while (false !== ($file = readdir($handle))) { - if (preg_match("/^\w+$/", $file) && is_dir("$designfolder/$file")) { - $designlist[] = $file; + if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) { + $stylelist[] = $file; } } closedir($handle); } $preview = verifyparam("preview","/^\w+$/", "default"); -if(!in_array($preview, $designlist)) { - $preview = $designlist[0]; +if(!in_array($preview, $stylelist)) { + $preview = $stylelist[0]; } $show = verifyparam("show", "/^(chat|chatsimple|nochat|mail|mailsent|leavemessage|leavemessagesent)$/", ""); @@ -40,12 +40,12 @@ $show = verifyparam("show", "/^(chat|chatsimple|nochat|mail|mailsent|leavemessag if($show == 'chat' || $show == 'mail' || $show == 'leavemessage' || $show == 'leavemessagesent' || $show == 'chatsimple' || $show == 'nochat') { setup_chatview_for_user(array('threadid' => 0,'userName' => getstring("chat.default.username"), 'ltoken' => 123), "ajaxed"); $page['mailLink'] = "$webimroot/operator/preview.php?preview=$preview&show=mail"; - expand("../design/$preview/$show.tpl"); + expand("../styles", "$preview", "$show.tpl"); exit; } if($show == 'mailsent') { $page['email'] = "admin@yourdomain.com"; - expand("../design/$preview/$show.tpl"); + expand("../styles", "$preview", "$show.tpl"); exit; } @@ -63,7 +63,7 @@ $template = verifyparam("template", "/^\w+$/", "chat"); $page['formpreview'] = $preview; $page['formtemplate'] = $template; -$page['availablePreviews'] = $designlist; +$page['availablePreviews'] = $stylelist; $page['availableTemplates'] = array("chat", "chatsimple", "nochat", "leavemessage", "leavemessagesent", "mail", "mailsent", "all"); $page['operator'] = topage(get_operator_name($operator)); $page['showlink'] = "$webimroot/operator/preview.php?preview=$preview&show="; diff --git a/src/messenger/webim/operator/redirect.php b/src/messenger/webim/operator/redirect.php index 060f2ea0..07d433c8 100644 --- a/src/messenger/webim/operator/redirect.php +++ b/src/messenger/webim/operator/redirect.php @@ -51,9 +51,9 @@ if( $nextOperator ) { } if( count($errors) > 0 ) { - expand("../design/default/error.tpl"); + expand("../styles", getchatstyle(), "error.tpl"); } else { - expand("../design/default/redirected.tpl"); + expand("../styles", getchatstyle(), "redirected.tpl"); } ?> \ No newline at end of file