diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php
index a1fe7347..8ce25924 100644
--- a/src/messenger/webim/client.php
+++ b/src/messenger/webim/client.php
@@ -175,6 +175,11 @@ $pparam = verifyparam( "act", "/^(mailthread)$/", "default");
if( $pparam == "mailthread" ) {
expand("styles/dialogs", getchatstyle(), "mail.tpl");
} else if( $level == "ajaxed" ) {
+ // Load JavaScript plugins and JavaScripts, CSS files required by them
+ $page['additional_css'] = get_additional_css('chatWindow');
+ $page['additional_js'] = get_additional_js('chatWindow');
+ $page['js_plugins'] = get_js_plugins('chatWindow');
+ // Expand page
expand("styles/dialogs", getchatstyle(), "chat.tpl");
} else if( $level == "simple" ) {
expand("styles/dialogs", getchatstyle(), "chatsimple.tpl");
diff --git a/src/messenger/webim/js/164/chat.js b/src/messenger/webim/js/164/chat.js
index d3d2926f..81577ef1 100644
--- a/src/messenger/webim/js/164/chat.js
+++ b/src/messenger/webim/js/164/chat.js
@@ -26,5 +26,6 @@ arguments:{references:{},"return":{closed:"closed"},threadId:this.thread.threadi
this.setStatus(a.errorMessage):this.setStatus("reconnecting")},showStatusDiv:function(a){$("engineinfo")&&($("engineinfo").style.display="inline",$("engineinfo").innerHTML=a)},setStatus:function(a){this.statusTimeout&&clearTimeout(this.statusTimeout);this.showStatusDiv(a);this.statusTimeout=setTimeout(this.clearStatus.bind(this),4E3)},clearStatus:function(){$("engineinfo").style.display="none"}};
var Chat={threadUpdater:{},applyName:function(){Chat.threadUpdater.changeName($("uname").value);$("changename1").style.display="none";$("changename2").style.display="inline";$("unamelink").innerHTML=htmlescape($("uname").value)},showNameField:function(){$("changename1").style.display="inline";$("changename2").style.display="none"}};
Behaviour.register({"#postmessage a":function(a){a.onclick=function(){var a=$("msgwnd");a&&Chat.threadUpdater.postMessage(a.value)}},"select#predefined":function(a){a.onchange=function(){var a=$("msgwnd");0!=this.selectedIndex&&(a.value=Chat.predefinedAnswers[this.selectedIndex-1]);this.selectedIndex=0;a.focus()}},"div#changename2 a":function(a){a.onclick=function(){Chat.showNameField();return!1}},"div#changename1 a":function(a){a.onclick=function(){Chat.applyName();return!1}},"div#changename1 input#uname":function(a){a.onkeydown=
-function(a){13==(a||event).keyCode&&Chat.applyName()}},"a#refresh":function(a){a.onclick=function(){Chat.threadUpdater.refresh()}},"a#togglesound":function(a){a.onclick=function(){var a=$("soundimg");a&&(a.className=a.className.match(/\bisound\b/)?"tplimage inosound":"tplimage isound",(a=$("msgwnd"))&&a.focus())}},"a.closethread":function(a){a.onclick=function(){Chat.threadUpdater.closeThread()}}});
-EventHelper.register(window,"onload",function(){Chat.cssfile=chatParams.cssfile;Chat.predefinedAnswers=chatParams.predefinedAnswers||[];Chat.localizedStrings=chatParams.localizedStrings;Chat.threadUpdater=new ChatThreadUpdater(new ChatServer(chatParams.serverParams),chatParams.threadParams,{ignorectrl:-1,container:"safari"==myRealAgent?self.frames[0]:$("chatwnd"),avatar:$("avatarwnd"),message:$("msgwnd")}.extend(chatParams.threadUpdaterParams||{}))});
+function(a){13==(a||event).keyCode&&Chat.applyName()}},"a#refresh":function(a){a.onclick=function(){Chat.threadUpdater.refresh()}},"a#togglesound":function(a){a.onclick=function(){var a=$("soundimg");a&&(a.className=a.className.match(/\bisound\b/)?"tplimage inosound":"tplimage isound",(a=$("msgwnd"))&&a.focus())}},"a.closethread":function(a){a.onclick=function(){Chat.threadUpdater.closeThread()}}});var pluginManager=new PluginManager;
+EventHelper.register(window,"onload",function(){var a=new ChatServer(chatParams.serverParams),b=chatParams.threadParams;chatParams.initPlugins(pluginManager,b,a);Chat.cssfile=chatParams.cssfile;Chat.predefinedAnswers=chatParams.predefinedAnswers||[];Chat.localizedStrings=chatParams.localizedStrings;Chat.threadUpdater=new ChatThreadUpdater(a,b,{ignorectrl:-1,container:"safari"==myRealAgent?self.frames[0]:$("chatwnd"),avatar:$("avatarwnd"),message:$("msgwnd")}.extend(chatParams.threadUpdaterParams||
+{}))});
\ No newline at end of file
diff --git a/src/messenger/webim/js/source/chat.js b/src/messenger/webim/js/source/chat.js
index 7c2bf912..c25c21b9 100644
--- a/src/messenger/webim/js/source/chat.js
+++ b/src/messenger/webim/js/source/chat.js
@@ -927,13 +927,18 @@ Behaviour.register({
}
});
+var pluginManager = new PluginManager();
+
EventHelper.register(window, 'onload', function(){
+ var chatServer = new ChatServer(chatParams.serverParams);
+ var thread = chatParams.threadParams;
+ chatParams.initPlugins(pluginManager, thread, chatServer);
Chat.cssfile = chatParams.cssfile;
Chat.predefinedAnswers = chatParams.predefinedAnswers || [];
Chat.localizedStrings = chatParams.localizedStrings;
Chat.threadUpdater = new ChatThreadUpdater(
- new ChatServer(chatParams.serverParams),
- chatParams.threadParams,
+ chatServer,
+ thread,
{
ignorectrl: -1,
container: myRealAgent=='safari'?self.frames[0]:$("chatwnd"),
diff --git a/src/messenger/webim/libs/common/response.php b/src/messenger/webim/libs/common/response.php
index 351436ce..e18c8427 100644
--- a/src/messenger/webim/libs/common/response.php
+++ b/src/messenger/webim/libs/common/response.php
@@ -64,6 +64,81 @@ function topage($text)
return myiconv($webim_encoding, getoutputenc(), $text);
}
+/**
+ * Load additional CSS files, required by plugins, and build HTML code to include them
+ *
+ * @param string $page_name CSS files load to this page
+ * @return string HTML block of 'link' tags
+ */
+function get_additional_css($page_name) {
+ $method = $page_name . 'AddCss';
+ $plugins = PluginManager::getAllPlugins();
+ $result = array();
+ // Check all plugins
+ foreach ($plugins as $plugin) {
+ if (is_callable(array($plugin, $method))) {
+ // Try to invoke '<$page_name>AddCss' method
+ $css_list = $plugin->$method();
+ foreach ($css_list as $css) {
+ // Add script tag for each javascript file
+ $result[] = '';
+ }
+ }
+ }
+ return implode("\n", $result);
+}
+
+/**
+ * Load additional JavaScript files, required by plugins, and build HTML code to include them
+ *
+ * @param string $page_name JavaScript files load to this page
+ * @return string HTML block of 'script' tags
+ */
+function get_additional_js($page_name) {
+ $method = $page_name . 'AddJs';
+ $plugins = PluginManager::getAllPlugins();
+ $result = array();
+ // Check all plugins
+ foreach ($plugins as $plugin) {
+ if (is_callable(array($plugin, $method))) {
+ // Try to invoke '<$page_name>AddJs' method
+ $js_list = $plugin->$method();
+ foreach ($js_list as $js) {
+ // Add script tag for each javascript file
+ $result[] = '';
+ }
+ }
+ }
+ return implode("\n", $result);
+}
+
+/**
+ * Build Javascript code that initialize JavaScript plugins
+ *
+ * @param string $page_name Plugins initialize at this page
+ * @return string JavaScript initialization block
+ */
+function get_js_plugins($page_name) {
+ $method = $page_name . 'AddJsPlugins';
+ $plugins = PluginManager::getAllPlugins();
+ $result = array();
+ // Check all plugins
+ foreach ($plugins as $plugin) {
+ if (is_callable(array($plugin, $method))) {
+ // Try to invoke '<$page_name>AddJsPlugins' method
+ $js_plugins = $plugin->$method();
+ foreach ($js_plugins as $js_plugin) {
+ // Add plugin's initialization code
+ $constructor = $js_plugin['constructor'];
+ array_unshift($js_plugin['init_values'], 'thread', 'chatServer');
+ $init_values = implode(', ', $js_plugin['init_values']);
+ $result[] = "pluginManager.addPlugin('{$constructor}', new {$constructor}({$init_values}));";
+ }
+ }
+ }
+ return implode("\n", $result);
+}
+
function no_field($key)
{
return getlocal2("errors.required", array(getlocal($key)));
diff --git a/src/messenger/webim/operator/agent.php b/src/messenger/webim/operator/agent.php
index a25f7b88..80095f6f 100644
--- a/src/messenger/webim/operator/agent.php
+++ b/src/messenger/webim/operator/agent.php
@@ -124,6 +124,11 @@ if ($pparam == "redirect") {
setup_redirect_links($threadid, $operator, $token);
expand("../styles/dialogs", getchatstyle(), "redirect.tpl");
} else {
+ // Load JavaScript plugins and JavaScripts, CSS files required by them
+ $page['additional_css'] = get_additional_css('chatWindow');
+ $page['additional_js'] = get_additional_js('chatWindow');
+ $page['js_plugins'] = get_js_plugins('chatWindow');
+ // Expand page
expand("../styles/dialogs", getchatstyle(), "chat.tpl");
}
diff --git a/src/messenger/webim/plugins/.htaccess b/src/messenger/webim/plugins/.htaccess
index 14249c50..84e03cb0 100644
--- a/src/messenger/webim/plugins/.htaccess
+++ b/src/messenger/webim/plugins/.htaccess
@@ -1 +1,4 @@
-Deny from all
\ No newline at end of file
+Order Allow,Deny
+