From 2b07917020c9181ff15e6096012144f4a9c201d4 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sun, 13 Oct 2013 13:34:15 -0400 Subject: [PATCH 1/8] plugins - filter:admin.header.build allows you to add plugins to navigation in ACP --- public/templates/admin/header.tpl | 69 +++++++++++++++++++------------ src/routes/admin.js | 31 ++++++++++---- 2 files changed, 66 insertions(+), 34 deletions(-) diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl index 4135e135b0..f34839359a 100644 --- a/public/templates/admin/header.tpl +++ b/public/templates/admin/header.tpl @@ -76,35 +76,52 @@ + + + diff --git a/src/routes/admin.js b/src/routes/admin.js index 0fa581018c..c0ad93387e 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -18,10 +18,17 @@ var user = require('./../user.js'), }); } - Admin.build_header = function (res) { - return templates['admin/header'].parse({ - csrf: res.locals.csrf_token, - relative_path: nconf.get('relative_path') + Admin.build_header = function (res, callback) { + var custom_header = { + 'plugins': [] + }; + + plugins.fireHook('filter:admin.header.build', custom_header, function(err, custom_header) { + callback(err, templates['admin/header'].parse({ + csrf: res.locals.csrf_token, + relative_path: nconf.get('relative_path'), + plugins: custom_header.plugins + })); }); } @@ -38,7 +45,9 @@ var user = require('./../user.js'), for (var i = 0, ii = routes.length; i < ii; i++) { (function (route) { app.get('/admin/' + route, Admin.isAdmin, function (req, res) { - res.send(Admin.build_header(res) + app.create_route('admin/' + route) + templates['admin/footer']); + Admin.build_header(res, function(err, header) { + res.send(header + app.create_route('admin/' + route) + templates['admin/footer']); + }); }); }(routes[i])); } @@ -48,7 +57,9 @@ var user = require('./../user.js'), for (var i = 0, ii = unit_tests.length; i < ii; i++) { (function (route) { app.get('/admin/testing/' + route, Admin.isAdmin, function (req, res) { - res.send(Admin.build_header(res) + app.create_route('admin/testing/' + route) + templates['admin/footer']); + Admin.build_header(res, function(err, header) { + res.send(header + app.create_route('admin/testing/' + route) + templates['admin/footer']); + }); }); }(unit_tests[i])); } @@ -57,11 +68,15 @@ var user = require('./../user.js'), app.namespace('/admin', function () { app.get('/', Admin.isAdmin, function (req, res) { - res.send(Admin.build_header(res) + app.create_route('admin/index') + templates['admin/footer']); + Admin.build_header(res, function(err, header) { + res.send(header + app.create_route('admin/index') + templates['admin/footer']); + }); }); app.get('/index', Admin.isAdmin, function (req, res) { - res.send(Admin.build_header(res) + app.create_route('admin/index') + templates['admin/footer']); + Admin.build_header(res, function(err, header) { + res.send(header + app.create_route('admin/index') + templates['admin/footer']); + }); }); }); From 4b5bae4f9b099bb335a4a39534e8b36a5fffb3c3 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sun, 13 Oct 2013 13:52:33 -0400 Subject: [PATCH 2/8] fixed plugin path in admin header --- public/templates/admin/header.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl index f34839359a..0a0a8ba69a 100644 --- a/public/templates/admin/header.tpl +++ b/public/templates/admin/header.tpl @@ -104,7 +104,7 @@
  • - {plugins.name} + {plugins.name}
  • From 32990794ce7f1304655151eb1f11b169e525f901 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sun, 13 Oct 2013 14:30:39 -0400 Subject: [PATCH 3/8] fixed admin bug (on f5 was not populating fields); plugins - filter:admin.create_routes allows you to create path to custom admin page --- public/src/forum/admin/footer.js | 4 +--- public/src/forum/admin/settings.js | 16 +++++++--------- public/templates/admin/header.tpl | 2 +- src/routes/admin.js | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/public/src/forum/admin/footer.js b/public/src/forum/admin/footer.js index 22990fcf7b..8a99da7a74 100644 --- a/public/src/forum/admin/footer.js +++ b/public/src/forum/admin/footer.js @@ -16,9 +16,7 @@ jQuery('document').ready(function() { }); socket.once('api:config.get', function(config) { - require(['forum/admin/settings'], function(Settings) { - Settings.config = config; - }); + app.config = config; }); socket.emit('api:config.get'); diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index 75f1a78c83..b6017af47e 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -1,18 +1,16 @@ define(function() { var Settings = {}; - Settings.config = {}; - Settings.init = function() { Settings.prepare(); }; Settings.prepare = function() { - // Come back in 500ms if the config isn't ready yet - if (Settings.config === undefined) { + // Come back in 125ms if the config isn't ready yet + if (!app.config) { setTimeout(function() { Settings.prepare(); - }, 500); + }, 125); return; } @@ -25,21 +23,21 @@ define(function() { key = fields[x].getAttribute('data-field'); inputType = fields[x].getAttribute('type'); if (fields[x].nodeName === 'INPUT') { - if (Settings.config[key]) { + if (app.config[key]) { switch (inputType) { case 'text': case 'textarea': case 'number': - fields[x].value = Settings.config[key]; + fields[x].value = app.config[key]; break; case 'checkbox': - fields[x].checked = Settings.config[key] === '1' ? true : false; + fields[x].checked = app.config[key] === '1' ? true : false; break; } } } else if (fields[x].nodeName === 'TEXTAREA') { - if (Settings.config[key]) fields[x].value = Settings.config[key]; + if (app.config[key]) fields[x].value = app.config[key]; } } diff --git a/public/templates/admin/header.tpl b/public/templates/admin/header.tpl index 0a0a8ba69a..ba2cdf32c7 100644 --- a/public/templates/admin/header.tpl +++ b/public/templates/admin/header.tpl @@ -104,7 +104,7 @@
  • - {plugins.name} + {plugins.name}
  • diff --git a/src/routes/admin.js b/src/routes/admin.js index c0ad93387e..28d0044849 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -80,6 +80,30 @@ var user = require('./../user.js'), }); }); + + var custom_routes = { + 'routes': [], + 'api_methods': [] + }; + + plugins.ready(function() { + plugins.fireHook('filter:admin.create_routes', custom_routes, function(err, custom_routes) { + var routes = custom_routes.routes; + + for (var route in routes) { + if (routes.hasOwnProperty(route)) { + app[routes[route].method || 'get']('/admin' + routes[route].route, function(req, res) { + routes[route].options(req, res, function(options) { + Admin.build_header(res, function (err, header) { + res.send(header + options.content + templates['admin/footer']); + }); + }); + }); + } + } + }); + }); + app.namespace('/api/admin', function () { app.get('/index', function (req, res) { res.json({ From fd89f71fc0d85cc4ab81d79f84ffab488864ad91 Mon Sep 17 00:00:00 2001 From: Noah Chase Date: Sun, 13 Oct 2013 18:39:42 -0400 Subject: [PATCH 4/8] fix typo that was causing topic variables to leak into global namespace --- src/topics.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/topics.js b/src/topics.js index 98a53ae51e..7b87ae6325 100644 --- a/src/topics.js +++ b/src/topics.js @@ -1,5 +1,5 @@ -var RDB = require('./redis.js') -schema = require('./schema.js'), +var RDB = require('./redis.js'), + schema = require('./schema.js'), posts = require('./posts.js'), utils = require('./../public/src/utils.js'), user = require('./user.js'), From bf677522a93ec4c48f6b0fa27ab1388f9eedba4c Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sun, 13 Oct 2013 19:16:48 -0400 Subject: [PATCH 5/8] added additional_profile_info footer in posts view; plugins - filter:posts.custom_profile_info hook lets you add info to post block footer also fixed app.alert - if title is not set then do not show title. --- app.js | 1 + public/src/app.js | 5 +++-- public/templates/topic.tpl | 6 ++++++ src/posts.js | 29 ++++++++++++++++++++--------- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index 492faf9609..05ba01c22f 100644 --- a/app.js +++ b/app.js @@ -86,6 +86,7 @@ webserver = require('./src/webserver.js'), SocketIO = require('socket.io').listen(global.server, { log: false, transports: ['websocket', 'xhr-polling', 'jsonp-polling', 'flashsocket']}), websockets = require('./src/websockets.js'), + posts = require('./src/posts.js'), plugins = require('./src/plugins'); // Don't remove this - plugins initializes itself websockets.init(SocketIO); diff --git a/public/src/app.js b/public/src/app.js index 9681e293f3..9098cce749 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -136,6 +136,7 @@ var socket, var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime()); var alert = $('#' + alert_id); + var title = params.title || ''; function startTimeout(div, timeout) { var timeoutId = setTimeout(function () { @@ -148,7 +149,7 @@ var socket, } if (alert.length > 0) { - alert.find('strong').html(params.title); + alert.find('strong').html(title); alert.find('p').html(params.message); alert.attr('class', "alert toaster-alert " + "alert-" + params.type); @@ -161,7 +162,7 @@ var socket, p = document.createElement('p'); p.innerHTML = params.message; - strong.innerHTML = params.title; + strong.innerHTML = title; div.className = "alert toaster-alert " + "alert-" + params.type; diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl index 1488af1e3a..5db4ea3fd2 100644 --- a/public/templates/topic.tpl +++ b/public/templates/topic.tpl @@ -66,6 +66,9 @@
    {main_posts.content}
    {main_posts.signature}
    + + + diff --git a/src/categories.js b/src/categories.js index b34eac86da..9ea879e140 100644 --- a/src/categories.js +++ b/src/categories.js @@ -55,9 +55,16 @@ var RDB = require('./redis.js'), Categories.getActiveUsers(category_id, next); } - async.parallel([getTopicIds, getActiveUsers], function(err, results) { + function getSidebars(next) { + plugins.fireHook('filter:category.build_sidebars', [], function(err, sidebars) { + next(err, sidebars); + }); + } + + async.parallel([getTopicIds, getActiveUsers, getSidebars], function(err, results) { var tids = results[0], - active_users = results[1]; + active_users = results[1], + sidebars = results[2]; var categoryData = { 'category_name': category_name, @@ -72,7 +79,8 @@ var RDB = require('./redis.js'), 'topics': [], 'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug) + '&text=' + encodeURIComponent(category_name), 'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug), - 'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug) + 'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'category/' + category_slug), + 'sidebars': sidebars }; function getTopics(next) { From 37450ff00c7400ec757ec472cb653be872e07d6a Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 14 Oct 2013 14:26:20 -0400 Subject: [PATCH 8/8] optimized ajaxify to only recurse through script tags; updated so it looks deeper for embedded scripts (ie. within plugin subtemplates) --- public/src/ajaxify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 2887b4a301..01b438b7b0 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -176,7 +176,7 @@ var ajaxify = {}; var scripts = [], script, - children_nodes = $(body_el).children(), + children_nodes = $(body_el).find('script'), child, i;