From f0050f45b67b0ca6539e03b23848e977f47c0905 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Mon, 22 Mar 2010 00:23:01 +0100 Subject: Updated changes to adhere to new directory layout --- README.hooks | 24 ++ etherpad/src/etherpad/admin/plugins.js | 247 +++++++++++++++++++++ .../src/etherpad/control/admin/pluginmanager.js | 65 ++++++ etherpad/src/plugins/kafoo/main.js | 16 ++ .../plugins/testplugin/controllers/testplugin.js | 57 +++++ etherpad/src/plugins/testplugin/hooks.js | 15 ++ etherpad/src/plugins/testplugin/main.js | 23 ++ etherpad/src/plugins/testplugin/static/js/main.js | 11 + etherpad/src/plugins/testplugin/static/js/test.js | 1 + .../plugins/testplugin/templates/testplugin.ejs | 29 +++ etherpad/src/static/js/plugins.js | 19 ++ etherpad/src/templates/admin/pluginmanager.ejs | 126 +++++++++++ trunk/README.hooks | 24 -- trunk/etherpad/src/etherpad/admin/plugins.js | 247 --------------------- .../src/etherpad/control/admin/pluginmanager.js | 65 ------ trunk/etherpad/src/plugins/kafoo/main.js | 16 -- .../plugins/testplugin/controllers/testplugin.js | 57 ----- trunk/etherpad/src/plugins/testplugin/hooks.js | 15 -- trunk/etherpad/src/plugins/testplugin/main.js | 23 -- .../src/plugins/testplugin/static/js/main.js | 11 - .../src/plugins/testplugin/static/js/test.js | 1 - .../plugins/testplugin/templates/testplugin.ejs | 29 --- trunk/etherpad/src/static/js/plugins.js | 19 -- .../etherpad/src/templates/admin/pluginmanager.ejs | 126 ----------- 24 files changed, 633 insertions(+), 633 deletions(-) create mode 100644 README.hooks create mode 100644 etherpad/src/etherpad/admin/plugins.js create mode 100644 etherpad/src/etherpad/control/admin/pluginmanager.js create mode 100644 etherpad/src/plugins/kafoo/main.js create mode 100644 etherpad/src/plugins/testplugin/controllers/testplugin.js create mode 100644 etherpad/src/plugins/testplugin/hooks.js create mode 100644 etherpad/src/plugins/testplugin/main.js create mode 100644 etherpad/src/plugins/testplugin/static/js/main.js create mode 100644 etherpad/src/plugins/testplugin/static/js/test.js create mode 100644 etherpad/src/plugins/testplugin/templates/testplugin.ejs create mode 100644 etherpad/src/static/js/plugins.js create mode 100644 etherpad/src/templates/admin/pluginmanager.ejs delete mode 100644 trunk/README.hooks delete mode 100644 trunk/etherpad/src/etherpad/admin/plugins.js delete mode 100644 trunk/etherpad/src/etherpad/control/admin/pluginmanager.js delete mode 100644 trunk/etherpad/src/plugins/kafoo/main.js delete mode 100644 trunk/etherpad/src/plugins/testplugin/controllers/testplugin.js delete mode 100644 trunk/etherpad/src/plugins/testplugin/hooks.js delete mode 100644 trunk/etherpad/src/plugins/testplugin/main.js delete mode 100644 trunk/etherpad/src/plugins/testplugin/static/js/main.js delete mode 100644 trunk/etherpad/src/plugins/testplugin/static/js/test.js delete mode 100644 trunk/etherpad/src/plugins/testplugin/templates/testplugin.ejs delete mode 100644 trunk/etherpad/src/static/js/plugins.js delete mode 100644 trunk/etherpad/src/templates/admin/pluginmanager.ejs diff --git a/README.hooks b/README.hooks new file mode 100644 index 0000000..d15949c --- /dev/null +++ b/README.hooks @@ -0,0 +1,24 @@ +Hooks that plugins can provide + +All hooks must return either undefined/null or a list of return values. This might be an empty list or a list of just one value. + +handlePath + Registers new urls to serve + Parameters: None + Returns: Parameter suitable for Dispatcher +renderPageBodyPre + Adds extra html before the body of a page + Parameters: bodyFileName, data, plugin + Returns: String(s) of html +renderPageBodyPost + Adds extra html after the body of a page + Parameters: bodyFileName, data, plugin + Returns: String(s) of html +serverStartup + Run right after server startup + Parameters: None + Returns: None +serverShutdown + Run before server shutdown + Parameters: None + Returns: None diff --git a/etherpad/src/etherpad/admin/plugins.js b/etherpad/src/etherpad/admin/plugins.js new file mode 100644 index 0000000..41482fc --- /dev/null +++ b/etherpad/src/etherpad/admin/plugins.js @@ -0,0 +1,247 @@ +/** + * Copyright 2009 RedHog, Egil Möller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("faststatic"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); + +import("etherpad.utils.*"); +import("etherpad.collab.server_utils"); +import("etherpad.globals.*"); +import("etherpad.log"); +import("etherpad.pad.padusers"); +import("etherpad.pro.pro_utils"); +import("etherpad.helpers"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("sqlbase.sqlbase"); +import("sqlbase.sqlcommon"); +import("sqlbase.sqlobj"); +import("exceptionutils"); +import("execution"); + +jimport("java.io.File", + "java.io.DataInputStream", + "java.io.FileInputStream", + "java.lang.Byte", + "java.io.FileReader", + "java.io.BufferedReader", + "net.appjet.oui.JarVirtualFile"); + +pluginsLoaded = false; +pluginModules = {}; +plugins = {}; +hooks = {}; +clientHooks = {}; + +function loadAvailablePlugin(pluginName) { + if (plugins[pluginName] != undefined) + return plugins[pluginName]; + + var pluginsDir = new Packages.java.io.File("src/plugins"); + + var pluginFile = new Packages.java.io.File(pluginsDir, pluginName + '/main.js'); + if (pluginFile.exists()) { + var pluginModulePath = pluginFile.getPath().replace(new RegExp("src/\(.*\)\.js"), "$1").replace("/", ".", "g"); + var importStmt = "import('" + pluginModulePath + "')"; + try { + var res = execution.fancyAssEval(importStmt, "main;"); + res = new res.init(); + return res; + } catch (e) { + log.info({errorLoadingPlugin:exceptionutils.getStackTracePlain(e)}); + } + } + return null; +} + +function loadAvailablePlugins() { + var pluginsDir = new Packages.java.io.File("src/plugins"); + + var pluginNames = pluginsDir.list(); + + for (i = 0; i < pluginNames.length; i++) { + var plugin = loadAvailablePlugin(pluginNames[i]); + if (plugin != null) + pluginModules[pluginNames[i]] = plugin + } +} + +function loadPluginHooks(pluginName) { + function registerHookNames(hookSet, type) { + return function (hook) { + var row = {hook:hook, type:type, plugin:pluginName}; + if (hookSet[hook] == undefined) hookSet[hook] = []; + hookSet[hook].push(row); + return row; + } + } + plugins[pluginName] = pluginModules[pluginName].hooks.map(registerHookNames(hooks, 'server')); + if (pluginModules[pluginName].client != undefined && pluginModules[pluginName].client.hooks != undefined) + plugins[pluginName] = plugins[pluginName].concat(pluginModules[pluginName].client.hooks.map(registerHookNames(clientHooks, 'client'))); +} + +function unloadPluginHooks(pluginName) { + for (var hookSet in [hooks, clientHooks]) + for (var hookName in hookSet) { + var hook = hookSet[hookName]; + for (i = hook.length - 1; i >= 0; i--) + if (hook[i].plugin == pluginName) + hook.splice(i, 1); + } + delete plugins[pluginName]; +} + +function loadInstalledHooks() { + var sql = '' + + 'select ' + + ' hook.name as hook, ' + + ' hook_type.name as type, ' + + ' plugin.name as plugin, ' + + ' plugin_hook.original_name as original ' + + 'from ' + + ' plugin ' + + ' left outer join plugin_hook on ' + + ' plugin.id = plugin_hook.plugin_id ' + + ' left outer join hook on ' + + ' plugin_hook.hook_id = hook.id ' + + ' left outer join hook_type on ' + + ' hook.type_id = hook_type.id ' + + 'order by hook.name, plugin.name'; + + var rows = sqlobj.executeRaw(sql, {}); + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + + if (plugins[row.plugin] == undefined) + plugins[row.plugin] = []; + plugins[row.plugin].push(row); + + var hookSet; + + if (row.type == 'server') + hookSet = hooks; + else if (row.type == 'client') + hookSet = clientHooks; + + if (hookSet[row.hook] == undefined) + hookSet[row.hook] = []; + if (row.hook != 'null') + hookSet[row.hook].push(row); + } +} + +function selectOrInsert(table, columns) { + var res = sqlobj.selectSingle(table, columns); + if (res !== null) + return res; + sqlobj.insert(table, columns); + return sqlobj.selectSingle(table, columns); +} + +function saveInstalledHooks(pluginName) { + var plugin = sqlobj.selectSingle('plugin', {name:pluginName}); + + if (plugin !== null) { + sqlobj.deleteRows('plugin_hook', {plugin_id:plugin.id}); + if (plugins[pluginName] === undefined) + sqlobj.deleteRows('plugin', {name:pluginName}); + } + + if (plugins[pluginName] !== undefined) { + if (plugin === null) + plugin = selectOrInsert('plugin', {name:pluginName}); + + for (var i = 0; i < plugins[pluginName].length; i++) { + var row = plugins[pluginName][i]; + + var hook_type = selectOrInsert('hook_type', {name:row.type}); + var hook = selectOrInsert('hook', {name:row.hook, type_id:hook_type.id}); + + sqlobj.insert("plugin_hook", {plugin_id:plugin.id, hook_id:hook.id}); + } + } +} + + +function loadPlugins() { + if (pluginsLoaded) return; + pluginsLoaded = true; + loadAvailablePlugins(); + loadInstalledHooks(); +} + + +/* User API */ +function enablePlugin(pluginName) { + loadPlugins(); + loadPluginHooks(pluginName); + saveInstalledHooks(pluginName); + try { + pluginModules[pluginName].install(); + } catch (e) { + unloadPluginHooks(pluginName); + saveInstalledHooks(pluginName); + throw e; + } + log.info({PLUGINS:plugins, HOOKS:hooks}); +} + +function disablePlugin(pluginName) { + loadPlugins(); + try { + pluginModules[pluginName].uninstall(); + } catch (e) { + log.info({errorUninstallingPlugin:exceptionutils.getStackTracePlain(e)}); + } + unloadPluginHooks(pluginName); + saveInstalledHooks(pluginName); + log.info({PLUGINS:plugins, HOOKS:hooks}); +} + +function registerClientHandlerJS() { + loadPlugins(); + for (pluginName in plugins) { + var plugin = pluginModules[pluginName]; + if (plugin.client !== undefined) { + helpers.includeJs("plugins/" + pluginName + "/main.js"); + if (plugin.client.modules != undefined) + for (j = 0; j < client.modules.length; j++) + helpers.includeJs("plugins/" + pluginName + "/" + plugin.client.modules[j] + ".js"); + } + } + helpers.addClientVars({hooks:clientHooks}); + helpers.includeJs("plugins.js"); +} + +function callHook(hookName, args) { + loadPlugins(); + if (hooks[hookName] === undefined) + return []; + var res = []; + for (i = 0; i < hooks[hookName].length; i++) { + var plugin = hooks[hookName][i]; + var pluginRes = pluginModules[plugin.plugin][plugin.original || hookName](args); + if (pluginRes != undefined && pluginRes != null) + res = res.concat(pluginRes); + } + return res; +} + +function callHookStr(hookName, args, sep, pre, post) { + if (sep == undefined) sep = ''; + if (pre == undefined) pre = ''; + if (post == undefined) post = ''; + return callHook(hookName, args).map(function (x) { return pre + x + post}).join(sep || ""); +} diff --git a/etherpad/src/etherpad/control/admin/pluginmanager.js b/etherpad/src/etherpad/control/admin/pluginmanager.js new file mode 100644 index 0000000..3fb017c --- /dev/null +++ b/etherpad/src/etherpad/control/admin/pluginmanager.js @@ -0,0 +1,65 @@ +/** + * Copyright 2009 RedHog, Egil Möller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("faststatic"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); + +import("etherpad.utils.*"); +import("etherpad.collab.server_utils"); +import("etherpad.globals.*"); +import("etherpad.log"); +import("etherpad.pad.padusers"); +import("etherpad.pro.pro_utils"); +import("etherpad.helpers"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("etherpad.admin.plugins"); + + +function onRequest() { + plugins.loadPlugins(); + + if (request.params.action == 'install') { + plugins.enablePlugin(request.params.plugin); + } else if (request.params.action == 'uninstall') { + plugins.disablePlugin(request.params.plugin); + } else if (request.params.action == 'reinstall') { + plugins.disablePlugin(request.params.plugin); + plugins.enablePlugin(request.params.plugin); + } + + helpers.addClientVars({ + userAgent: request.headers["User-Agent"], + debugEnabled: request.params.djs, + clientIp: request.clientAddr, + colorPalette: COLOR_PALETTE, + serverTimestamp: +(new Date), + isProPad: pro_utils.isProDomainRequest(), + userIsGuest: padusers.isGuest(padusers.getUserId()), + userId: padusers.getUserId(), + }); + + renderHtml("admin/pluginmanager.ejs", + { + pluginModules: plugins.pluginModules, + plugins: plugins.plugins, + config: appjet.config, + bodyClass: 'nonpropad', + isPro: pro_utils.isProDomainRequest(), + isProAccountHolder: pro_utils.isProDomainRequest() && ! padusers.isGuest(padusers.getUserId()), + account: getSessionProAccount(), // may be falsy + }); + return true; +} diff --git a/etherpad/src/plugins/kafoo/main.js b/etherpad/src/plugins/kafoo/main.js new file mode 100644 index 0000000..f645576 --- /dev/null +++ b/etherpad/src/plugins/kafoo/main.js @@ -0,0 +1,16 @@ +import("etherpad.log"); + +function init() { + this.hooks = []; + this.description = 'KaBar plugin'; + this.install = install; + this.uninstall = uninstall; +} + +function install() { + log.info("Installing testplugin"); +} + +function uninstall() { + log.info("Uninstalling testplugin"); +} diff --git a/etherpad/src/plugins/testplugin/controllers/testplugin.js b/etherpad/src/plugins/testplugin/controllers/testplugin.js new file mode 100644 index 0000000..0c79e06 --- /dev/null +++ b/etherpad/src/plugins/testplugin/controllers/testplugin.js @@ -0,0 +1,57 @@ +/** + * Copyright 2009 RedHog, Egil Möller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("faststatic"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); + +import("etherpad.utils.*"); +import("etherpad.collab.server_utils"); +import("etherpad.globals.*"); +import("etherpad.log"); +import("etherpad.pad.padusers"); +import("etherpad.pro.pro_utils"); +import("etherpad.helpers"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("sqlbase.sqlbase"); +import("sqlbase.sqlcommon"); +import("sqlbase.sqlobj"); + + +function onRequest() { + var isPro = pro_utils.isProDomainRequest(); + var userId = padusers.getUserId(); + + helpers.addClientVars({ + userAgent: request.headers["User-Agent"], + debugEnabled: request.params.djs, + clientIp: request.clientAddr, + colorPalette: COLOR_PALETTE, + serverTimestamp: +(new Date), + isProPad: isPro, + userIsGuest: padusers.isGuest(userId), + userId: userId, + }); + + var isProUser = (isPro && ! padusers.isGuest(userId)); + + renderHtml("testplugin.ejs", + { + isPro: isPro, + isProAccountHolder: isProUser, + account: getSessionProAccount(), // may be falsy + }, 'testplugin'); + return true; +} diff --git a/etherpad/src/plugins/testplugin/hooks.js b/etherpad/src/plugins/testplugin/hooks.js new file mode 100644 index 0000000..493a2c2 --- /dev/null +++ b/etherpad/src/plugins/testplugin/hooks.js @@ -0,0 +1,15 @@ +import("etherpad.log"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); +import("plugins.testplugin.controllers.testplugin"); + +function serverStartup() { + log.info("Server startup for testplugin"); +} + +function serverShutdown() { + log.info("Server shutdown for testplugin"); +} + +function handlePath() { + return [[PrefixMatcher('/ep/testplugin/'), forward(testplugin)]]; +} diff --git a/etherpad/src/plugins/testplugin/main.js b/etherpad/src/plugins/testplugin/main.js new file mode 100644 index 0000000..49b447c --- /dev/null +++ b/etherpad/src/plugins/testplugin/main.js @@ -0,0 +1,23 @@ +import("etherpad.log"); +import("plugins.testplugin.hooks"); +import("plugins.testplugin.static.js.main"); + +function init() { + this.hooks = ['serverStartup', 'serverShutdown', 'handlePath']; + this.client = new main.init(); + this.description = 'Test Plugin'; + this.serverStartup = hooks.serverStartup; + this.serverShutdown = hooks.serverShutdown; + this.handlePath = hooks.handlePath; + this.install = install; + this.uninstall = uninstall; +} + +function install() { + log.info("Installing testplugin"); +} + +function uninstall() { + log.info("Uninstalling testplugin"); +} + diff --git a/etherpad/src/plugins/testplugin/static/js/main.js b/etherpad/src/plugins/testplugin/static/js/main.js new file mode 100644 index 0000000..f08b8f7 --- /dev/null +++ b/etherpad/src/plugins/testplugin/static/js/main.js @@ -0,0 +1,11 @@ +function init() { + this.hooks = ['kafoo']; + this.kafoo = kafoo; +} + +function kafoo() { + alert('hej'); +} + +/* used on the client side only */ +testplugin = new init(); diff --git a/etherpad/src/plugins/testplugin/static/js/test.js b/etherpad/src/plugins/testplugin/static/js/test.js new file mode 100644 index 0000000..0f30cd9 --- /dev/null +++ b/etherpad/src/plugins/testplugin/static/js/test.js @@ -0,0 +1 @@ +callHook("kafoo"); diff --git a/etherpad/src/plugins/testplugin/templates/testplugin.ejs b/etherpad/src/plugins/testplugin/templates/testplugin.ejs new file mode 100644 index 0000000..f70ca8d --- /dev/null +++ b/etherpad/src/plugins/testplugin/templates/testplugin.ejs @@ -0,0 +1,29 @@ +<% /* Copyright 2009 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS-IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ %> +<% + helpers.setHtmlTitle("Test plugin"); + helpers.setBodyId("padbody"); + helpers.addBodyClass("limwidth nonpropad nonprouser"); + helpers.includeCss("pad2_ejs.css"); + helpers.setRobotsPolicy({index: false, follow: false}) + helpers.includeJQuery(); + helpers.includeCometJs(); + helpers.includeJs("json2.js"); + helpers.includeJs("plugins/testplugin/test.js"); + helpers.addToHead('\n\n'); +%> + +
+ Welcome to the test plugin +
diff --git a/etherpad/src/static/js/plugins.js b/etherpad/src/static/js/plugins.js new file mode 100644 index 0000000..6d8804e --- /dev/null +++ b/etherpad/src/static/js/plugins.js @@ -0,0 +1,19 @@ +function callHook(hookName, args) { + if (clientVars.hooks[hookName] === undefined) + return []; + var res = []; + for (i = 0; i < clientVars.hooks[hookName].length; i++) { + var plugin = clientVars.hooks[hookName][i]; + var pluginRes = eval(plugin.plugin)[plugin.original || hookName](args); + if (pluginRes != undefined && pluginRes != null) + res = res.concat(pluginRes); + } + return res; +} + +function callHookStr(hookName, args, sep, pre, post) { + if (sep == undefined) sep = ''; + if (pre == undefined) pre = ''; + if (post == undefined) post = ''; + return callHook(hookName, args).map(function (x) { return pre + x + post}).join(sep || ""); +} diff --git a/etherpad/src/templates/admin/pluginmanager.ejs b/etherpad/src/templates/admin/pluginmanager.ejs new file mode 100644 index 0000000..4e08fc9 --- /dev/null +++ b/etherpad/src/templates/admin/pluginmanager.ejs @@ -0,0 +1,126 @@ +<% /* Copyright 2009 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS-IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ %> +<% + helpers.setHtmlTitle("Browse tags"); + helpers.setBodyId("padbody"); + helpers.addBodyClass("limwidth nonpropad nonprouser"); + helpers.includeCss("pad2_ejs.css"); + helpers.setRobotsPolicy({index: false, follow: false}) + helpers.includeJQuery(); + helpers.includeCometJs(); + helpers.includeJs("json2.js"); + helpers.addToHead('\n\n'); + + function inArray(item, arr) { + for (var i = 0; i < arr.length; i++) + if (arr[i] == item) + return true; + return false; + } +%> + +
+
+
+
+
+ + <% if (isProAccountHolder) { %> +
<%= toHTML(account.email) %>(sign out)
+ <% } else if (isPro) { %> + + <% } %> +
+
+
+
+
Browse tags
+ + + + + + +
+
+
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+ +
+   +   +   +   +   +   +   +   +   +   +   +
+
+
+
+

Plugin manager

+ + + + + + + <% for (var plugin in pluginModules) { %> + + + + + + <% } %> +
Module nameStatus
<%= pluginModules[plugin].description %> + <% if (plugins[plugin] !== undefined) { %> + Installed + <% } else { %> + Not installed + <% } %> + + <% if (plugins[plugin] !== undefined) { %> + Uninstall + Reinstall + <% } else { %> + Install + <% } %> +
+
+
+
+ +
+
+
+
+
+ diff --git a/trunk/README.hooks b/trunk/README.hooks deleted file mode 100644 index d15949c..0000000 --- a/trunk/README.hooks +++ /dev/null @@ -1,24 +0,0 @@ -Hooks that plugins can provide - -All hooks must return either undefined/null or a list of return values. This might be an empty list or a list of just one value. - -handlePath - Registers new urls to serve - Parameters: None - Returns: Parameter suitable for Dispatcher -renderPageBodyPre - Adds extra html before the body of a page - Parameters: bodyFileName, data, plugin - Returns: String(s) of html -renderPageBodyPost - Adds extra html after the body of a page - Parameters: bodyFileName, data, plugin - Returns: String(s) of html -serverStartup - Run right after server startup - Parameters: None - Returns: None -serverShutdown - Run before server shutdown - Parameters: None - Returns: None diff --git a/trunk/etherpad/src/etherpad/admin/plugins.js b/trunk/etherpad/src/etherpad/admin/plugins.js deleted file mode 100644 index 41482fc..0000000 --- a/trunk/etherpad/src/etherpad/admin/plugins.js +++ /dev/null @@ -1,247 +0,0 @@ -/** - * Copyright 2009 RedHog, Egil Möller - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import("faststatic"); -import("dispatch.{Dispatcher,PrefixMatcher,forward}"); - -import("etherpad.utils.*"); -import("etherpad.collab.server_utils"); -import("etherpad.globals.*"); -import("etherpad.log"); -import("etherpad.pad.padusers"); -import("etherpad.pro.pro_utils"); -import("etherpad.helpers"); -import("etherpad.pro.pro_accounts.getSessionProAccount"); -import("sqlbase.sqlbase"); -import("sqlbase.sqlcommon"); -import("sqlbase.sqlobj"); -import("exceptionutils"); -import("execution"); - -jimport("java.io.File", - "java.io.DataInputStream", - "java.io.FileInputStream", - "java.lang.Byte", - "java.io.FileReader", - "java.io.BufferedReader", - "net.appjet.oui.JarVirtualFile"); - -pluginsLoaded = false; -pluginModules = {}; -plugins = {}; -hooks = {}; -clientHooks = {}; - -function loadAvailablePlugin(pluginName) { - if (plugins[pluginName] != undefined) - return plugins[pluginName]; - - var pluginsDir = new Packages.java.io.File("src/plugins"); - - var pluginFile = new Packages.java.io.File(pluginsDir, pluginName + '/main.js'); - if (pluginFile.exists()) { - var pluginModulePath = pluginFile.getPath().replace(new RegExp("src/\(.*\)\.js"), "$1").replace("/", ".", "g"); - var importStmt = "import('" + pluginModulePath + "')"; - try { - var res = execution.fancyAssEval(importStmt, "main;"); - res = new res.init(); - return res; - } catch (e) { - log.info({errorLoadingPlugin:exceptionutils.getStackTracePlain(e)}); - } - } - return null; -} - -function loadAvailablePlugins() { - var pluginsDir = new Packages.java.io.File("src/plugins"); - - var pluginNames = pluginsDir.list(); - - for (i = 0; i < pluginNames.length; i++) { - var plugin = loadAvailablePlugin(pluginNames[i]); - if (plugin != null) - pluginModules[pluginNames[i]] = plugin - } -} - -function loadPluginHooks(pluginName) { - function registerHookNames(hookSet, type) { - return function (hook) { - var row = {hook:hook, type:type, plugin:pluginName}; - if (hookSet[hook] == undefined) hookSet[hook] = []; - hookSet[hook].push(row); - return row; - } - } - plugins[pluginName] = pluginModules[pluginName].hooks.map(registerHookNames(hooks, 'server')); - if (pluginModules[pluginName].client != undefined && pluginModules[pluginName].client.hooks != undefined) - plugins[pluginName] = plugins[pluginName].concat(pluginModules[pluginName].client.hooks.map(registerHookNames(clientHooks, 'client'))); -} - -function unloadPluginHooks(pluginName) { - for (var hookSet in [hooks, clientHooks]) - for (var hookName in hookSet) { - var hook = hookSet[hookName]; - for (i = hook.length - 1; i >= 0; i--) - if (hook[i].plugin == pluginName) - hook.splice(i, 1); - } - delete plugins[pluginName]; -} - -function loadInstalledHooks() { - var sql = '' + - 'select ' + - ' hook.name as hook, ' + - ' hook_type.name as type, ' + - ' plugin.name as plugin, ' + - ' plugin_hook.original_name as original ' + - 'from ' + - ' plugin ' + - ' left outer join plugin_hook on ' + - ' plugin.id = plugin_hook.plugin_id ' + - ' left outer join hook on ' + - ' plugin_hook.hook_id = hook.id ' + - ' left outer join hook_type on ' + - ' hook.type_id = hook_type.id ' + - 'order by hook.name, plugin.name'; - - var rows = sqlobj.executeRaw(sql, {}); - for (var i = 0; i < rows.length; i++) { - var row = rows[i]; - - if (plugins[row.plugin] == undefined) - plugins[row.plugin] = []; - plugins[row.plugin].push(row); - - var hookSet; - - if (row.type == 'server') - hookSet = hooks; - else if (row.type == 'client') - hookSet = clientHooks; - - if (hookSet[row.hook] == undefined) - hookSet[row.hook] = []; - if (row.hook != 'null') - hookSet[row.hook].push(row); - } -} - -function selectOrInsert(table, columns) { - var res = sqlobj.selectSingle(table, columns); - if (res !== null) - return res; - sqlobj.insert(table, columns); - return sqlobj.selectSingle(table, columns); -} - -function saveInstalledHooks(pluginName) { - var plugin = sqlobj.selectSingle('plugin', {name:pluginName}); - - if (plugin !== null) { - sqlobj.deleteRows('plugin_hook', {plugin_id:plugin.id}); - if (plugins[pluginName] === undefined) - sqlobj.deleteRows('plugin', {name:pluginName}); - } - - if (plugins[pluginName] !== undefined) { - if (plugin === null) - plugin = selectOrInsert('plugin', {name:pluginName}); - - for (var i = 0; i < plugins[pluginName].length; i++) { - var row = plugins[pluginName][i]; - - var hook_type = selectOrInsert('hook_type', {name:row.type}); - var hook = selectOrInsert('hook', {name:row.hook, type_id:hook_type.id}); - - sqlobj.insert("plugin_hook", {plugin_id:plugin.id, hook_id:hook.id}); - } - } -} - - -function loadPlugins() { - if (pluginsLoaded) return; - pluginsLoaded = true; - loadAvailablePlugins(); - loadInstalledHooks(); -} - - -/* User API */ -function enablePlugin(pluginName) { - loadPlugins(); - loadPluginHooks(pluginName); - saveInstalledHooks(pluginName); - try { - pluginModules[pluginName].install(); - } catch (e) { - unloadPluginHooks(pluginName); - saveInstalledHooks(pluginName); - throw e; - } - log.info({PLUGINS:plugins, HOOKS:hooks}); -} - -function disablePlugin(pluginName) { - loadPlugins(); - try { - pluginModules[pluginName].uninstall(); - } catch (e) { - log.info({errorUninstallingPlugin:exceptionutils.getStackTracePlain(e)}); - } - unloadPluginHooks(pluginName); - saveInstalledHooks(pluginName); - log.info({PLUGINS:plugins, HOOKS:hooks}); -} - -function registerClientHandlerJS() { - loadPlugins(); - for (pluginName in plugins) { - var plugin = pluginModules[pluginName]; - if (plugin.client !== undefined) { - helpers.includeJs("plugins/" + pluginName + "/main.js"); - if (plugin.client.modules != undefined) - for (j = 0; j < client.modules.length; j++) - helpers.includeJs("plugins/" + pluginName + "/" + plugin.client.modules[j] + ".js"); - } - } - helpers.addClientVars({hooks:clientHooks}); - helpers.includeJs("plugins.js"); -} - -function callHook(hookName, args) { - loadPlugins(); - if (hooks[hookName] === undefined) - return []; - var res = []; - for (i = 0; i < hooks[hookName].length; i++) { - var plugin = hooks[hookName][i]; - var pluginRes = pluginModules[plugin.plugin][plugin.original || hookName](args); - if (pluginRes != undefined && pluginRes != null) - res = res.concat(pluginRes); - } - return res; -} - -function callHookStr(hookName, args, sep, pre, post) { - if (sep == undefined) sep = ''; - if (pre == undefined) pre = ''; - if (post == undefined) post = ''; - return callHook(hookName, args).map(function (x) { return pre + x + post}).join(sep || ""); -} diff --git a/trunk/etherpad/src/etherpad/control/admin/pluginmanager.js b/trunk/etherpad/src/etherpad/control/admin/pluginmanager.js deleted file mode 100644 index 3fb017c..0000000 --- a/trunk/etherpad/src/etherpad/control/admin/pluginmanager.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2009 RedHog, Egil Möller - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import("faststatic"); -import("dispatch.{Dispatcher,PrefixMatcher,forward}"); - -import("etherpad.utils.*"); -import("etherpad.collab.server_utils"); -import("etherpad.globals.*"); -import("etherpad.log"); -import("etherpad.pad.padusers"); -import("etherpad.pro.pro_utils"); -import("etherpad.helpers"); -import("etherpad.pro.pro_accounts.getSessionProAccount"); -import("etherpad.admin.plugins"); - - -function onRequest() { - plugins.loadPlugins(); - - if (request.params.action == 'install') { - plugins.enablePlugin(request.params.plugin); - } else if (request.params.action == 'uninstall') { - plugins.disablePlugin(request.params.plugin); - } else if (request.params.action == 'reinstall') { - plugins.disablePlugin(request.params.plugin); - plugins.enablePlugin(request.params.plugin); - } - - helpers.addClientVars({ - userAgent: request.headers["User-Agent"], - debugEnabled: request.params.djs, - clientIp: request.clientAddr, - colorPalette: COLOR_PALETTE, - serverTimestamp: +(new Date), - isProPad: pro_utils.isProDomainRequest(), - userIsGuest: padusers.isGuest(padusers.getUserId()), - userId: padusers.getUserId(), - }); - - renderHtml("admin/pluginmanager.ejs", - { - pluginModules: plugins.pluginModules, - plugins: plugins.plugins, - config: appjet.config, - bodyClass: 'nonpropad', - isPro: pro_utils.isProDomainRequest(), - isProAccountHolder: pro_utils.isProDomainRequest() && ! padusers.isGuest(padusers.getUserId()), - account: getSessionProAccount(), // may be falsy - }); - return true; -} diff --git a/trunk/etherpad/src/plugins/kafoo/main.js b/trunk/etherpad/src/plugins/kafoo/main.js deleted file mode 100644 index f645576..0000000 --- a/trunk/etherpad/src/plugins/kafoo/main.js +++ /dev/null @@ -1,16 +0,0 @@ -import("etherpad.log"); - -function init() { - this.hooks = []; - this.description = 'KaBar plugin'; - this.install = install; - this.uninstall = uninstall; -} - -function install() { - log.info("Installing testplugin"); -} - -function uninstall() { - log.info("Uninstalling testplugin"); -} diff --git a/trunk/etherpad/src/plugins/testplugin/controllers/testplugin.js b/trunk/etherpad/src/plugins/testplugin/controllers/testplugin.js deleted file mode 100644 index 0c79e06..0000000 --- a/trunk/etherpad/src/plugins/testplugin/controllers/testplugin.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2009 RedHog, Egil Möller - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import("faststatic"); -import("dispatch.{Dispatcher,PrefixMatcher,forward}"); - -import("etherpad.utils.*"); -import("etherpad.collab.server_utils"); -import("etherpad.globals.*"); -import("etherpad.log"); -import("etherpad.pad.padusers"); -import("etherpad.pro.pro_utils"); -import("etherpad.helpers"); -import("etherpad.pro.pro_accounts.getSessionProAccount"); -import("sqlbase.sqlbase"); -import("sqlbase.sqlcommon"); -import("sqlbase.sqlobj"); - - -function onRequest() { - var isPro = pro_utils.isProDomainRequest(); - var userId = padusers.getUserId(); - - helpers.addClientVars({ - userAgent: request.headers["User-Agent"], - debugEnabled: request.params.djs, - clientIp: request.clientAddr, - colorPalette: COLOR_PALETTE, - serverTimestamp: +(new Date), - isProPad: isPro, - userIsGuest: padusers.isGuest(userId), - userId: userId, - }); - - var isProUser = (isPro && ! padusers.isGuest(userId)); - - renderHtml("testplugin.ejs", - { - isPro: isPro, - isProAccountHolder: isProUser, - account: getSessionProAccount(), // may be falsy - }, 'testplugin'); - return true; -} diff --git a/trunk/etherpad/src/plugins/testplugin/hooks.js b/trunk/etherpad/src/plugins/testplugin/hooks.js deleted file mode 100644 index 493a2c2..0000000 --- a/trunk/etherpad/src/plugins/testplugin/hooks.js +++ /dev/null @@ -1,15 +0,0 @@ -import("etherpad.log"); -import("dispatch.{Dispatcher,PrefixMatcher,forward}"); -import("plugins.testplugin.controllers.testplugin"); - -function serverStartup() { - log.info("Server startup for testplugin"); -} - -function serverShutdown() { - log.info("Server shutdown for testplugin"); -} - -function handlePath() { - return [[PrefixMatcher('/ep/testplugin/'), forward(testplugin)]]; -} diff --git a/trunk/etherpad/src/plugins/testplugin/main.js b/trunk/etherpad/src/plugins/testplugin/main.js deleted file mode 100644 index 49b447c..0000000 --- a/trunk/etherpad/src/plugins/testplugin/main.js +++ /dev/null @@ -1,23 +0,0 @@ -import("etherpad.log"); -import("plugins.testplugin.hooks"); -import("plugins.testplugin.static.js.main"); - -function init() { - this.hooks = ['serverStartup', 'serverShutdown', 'handlePath']; - this.client = new main.init(); - this.description = 'Test Plugin'; - this.serverStartup = hooks.serverStartup; - this.serverShutdown = hooks.serverShutdown; - this.handlePath = hooks.handlePath; - this.install = install; - this.uninstall = uninstall; -} - -function install() { - log.info("Installing testplugin"); -} - -function uninstall() { - log.info("Uninstalling testplugin"); -} - diff --git a/trunk/etherpad/src/plugins/testplugin/static/js/main.js b/trunk/etherpad/src/plugins/testplugin/static/js/main.js deleted file mode 100644 index f08b8f7..0000000 --- a/trunk/etherpad/src/plugins/testplugin/static/js/main.js +++ /dev/null @@ -1,11 +0,0 @@ -function init() { - this.hooks = ['kafoo']; - this.kafoo = kafoo; -} - -function kafoo() { - alert('hej'); -} - -/* used on the client side only */ -testplugin = new init(); diff --git a/trunk/etherpad/src/plugins/testplugin/static/js/test.js b/trunk/etherpad/src/plugins/testplugin/static/js/test.js deleted file mode 100644 index 0f30cd9..0000000 --- a/trunk/etherpad/src/plugins/testplugin/static/js/test.js +++ /dev/null @@ -1 +0,0 @@ -callHook("kafoo"); diff --git a/trunk/etherpad/src/plugins/testplugin/templates/testplugin.ejs b/trunk/etherpad/src/plugins/testplugin/templates/testplugin.ejs deleted file mode 100644 index f70ca8d..0000000 --- a/trunk/etherpad/src/plugins/testplugin/templates/testplugin.ejs +++ /dev/null @@ -1,29 +0,0 @@ -<% /* Copyright 2009 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS-IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ %> -<% - helpers.setHtmlTitle("Test plugin"); - helpers.setBodyId("padbody"); - helpers.addBodyClass("limwidth nonpropad nonprouser"); - helpers.includeCss("pad2_ejs.css"); - helpers.setRobotsPolicy({index: false, follow: false}) - helpers.includeJQuery(); - helpers.includeCometJs(); - helpers.includeJs("json2.js"); - helpers.includeJs("plugins/testplugin/test.js"); - helpers.addToHead('\n\n'); -%> - -
- Welcome to the test plugin -
diff --git a/trunk/etherpad/src/static/js/plugins.js b/trunk/etherpad/src/static/js/plugins.js deleted file mode 100644 index 6d8804e..0000000 --- a/trunk/etherpad/src/static/js/plugins.js +++ /dev/null @@ -1,19 +0,0 @@ -function callHook(hookName, args) { - if (clientVars.hooks[hookName] === undefined) - return []; - var res = []; - for (i = 0; i < clientVars.hooks[hookName].length; i++) { - var plugin = clientVars.hooks[hookName][i]; - var pluginRes = eval(plugin.plugin)[plugin.original || hookName](args); - if (pluginRes != undefined && pluginRes != null) - res = res.concat(pluginRes); - } - return res; -} - -function callHookStr(hookName, args, sep, pre, post) { - if (sep == undefined) sep = ''; - if (pre == undefined) pre = ''; - if (post == undefined) post = ''; - return callHook(hookName, args).map(function (x) { return pre + x + post}).join(sep || ""); -} diff --git a/trunk/etherpad/src/templates/admin/pluginmanager.ejs b/trunk/etherpad/src/templates/admin/pluginmanager.ejs deleted file mode 100644 index 4e08fc9..0000000 --- a/trunk/etherpad/src/templates/admin/pluginmanager.ejs +++ /dev/null @@ -1,126 +0,0 @@ -<% /* Copyright 2009 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS-IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ %> -<% - helpers.setHtmlTitle("Browse tags"); - helpers.setBodyId("padbody"); - helpers.addBodyClass("limwidth nonpropad nonprouser"); - helpers.includeCss("pad2_ejs.css"); - helpers.setRobotsPolicy({index: false, follow: false}) - helpers.includeJQuery(); - helpers.includeCometJs(); - helpers.includeJs("json2.js"); - helpers.addToHead('\n\n'); - - function inArray(item, arr) { - for (var i = 0; i < arr.length; i++) - if (arr[i] == item) - return true; - return false; - } -%> - -
-
-
-
-
- - <% if (isProAccountHolder) { %> -
<%= toHTML(account.email) %>(sign out)
- <% } else if (isPro) { %> - - <% } %> -
-
-
-
-
Browse tags
- - - - - - -
-
-
- -
-
-
- -
- -
-
- -
-
-
-
- -
-   -   -   -   -   -   -   -   -   -   -   -
-
-
-
-

Plugin manager

- - - - - - - <% for (var plugin in pluginModules) { %> - - - - - - <% } %> -
Module nameStatus
<%= pluginModules[plugin].description %> - <% if (plugins[plugin] !== undefined) { %> - Installed - <% } else { %> - Not installed - <% } %> - - <% if (plugins[plugin] !== undefined) { %> - Uninstall - Reinstall - <% } else { %> - Install - <% } %> -
-
-
-
- -
-
-
-
-
- -- cgit v1.2.3