-
{main_posts.content}
+
{main_posts.content}
{main_posts.signature}
diff --git a/src/categories.js b/src/categories.js
index 34cc9430e8..b34eac86da 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -325,33 +325,40 @@ var RDB = require('./redis.js'),
return;
}
- var categories = [];
+ // var categories = [];
function getCategory(cid, callback) {
Categories.getCategoryData(cid, function(err, categoryData) {
-
if (err) {
- callback(err);
+ winston.warn('Attempted to retrieve cid ' + cid + ', but nothing was returned!');
+ callback(null, null);
return;
}
Categories.hasReadCategory(cid, current_user, function(hasRead) {
categoryData.badgeclass = (parseInt(categoryData.topic_count, 10) === 0 || (hasRead && current_user !== 0)) ? '' : 'badge-important';
- categories.push(categoryData);
- callback(null);
+ // categories.push(categoryData);
+ callback(null, categoryData);
});
});
}
- async.eachSeries(cids, getCategory, function(err) {
+ async.map(cids, getCategory, function(err, categories) {
if (err) {
winston.err(err);
callback(null);
return;
}
- categories = categories.sort(function(a, b) { return parseInt(a.order, 10) - parseInt(b.order, 10); });
+ categories = categories.filter(function(category) {
+ // Remove categories that have errored out
+ if (category) return true;
+ else return false;
+ }).sort(function(a, b) {
+ // Sort categories into their defined order
+ return parseInt(a.order, 10) - parseInt(b.order, 10);
+ });
callback({
'categories': categories
diff --git a/src/plugins.js b/src/plugins.js
index 75804e94c9..2fe845a56c 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -155,27 +155,21 @@ var fs = require('fs'),
var hookType = hook.split(':')[0];
switch (hookType) {
case 'filter':
- // Filters only take one argument, so only args[0] will be passed in
- var returnVal = (Array.isArray(args) ? args[0] : args);
-
- async.eachSeries(hookList, function(hookObj, next) {
- if (hookObj[2]) {
- _self.libraries[hookObj[0]][hookObj[1]](returnVal, function(err, afterVal) {
- returnVal = afterVal;
- next(err);
- });
- } else {
- returnVal = _self.libraries[hookObj[0]][hookObj[1]](returnVal);
- next();
+ async.reduce(hookList, args, function(value, hookObj, next) {
+ if (hookObj[2]) { // If a callback is present (asynchronous method)
+ _self.libraries[hookObj[0]][hookObj[1]](value, next);
+ } else { // Synchronous method
+ value = _self.libraries[hookObj[0]][hookObj[1]](value);
+ next(null, value);
}
- }, function(err) {
+ }, function(err, value) {
if (err) {
if (global.env === 'development') {
winston.info('[plugins] Problem executing hook: ' + hook);
}
}
- callback(err, returnVal);
+ callback.apply(plugins, arguments);
});
break;
case 'action':
@@ -197,7 +191,7 @@ var fs = require('fs'),
}
} else {
// Otherwise, this hook contains no methods
- var returnVal = (Array.isArray(args) ? args[0] : args);
+ var returnVal = args;
if (callback) callback(null, returnVal);
}
},
diff --git a/src/webserver.js b/src/webserver.js
index 2860aedef6..cd02aa289b 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -44,36 +44,43 @@ var express = require('express'),
* accepts: metaTags
*/
app.build_header = function (options, callback) {
- var defaultMetaTags = [{
- name: 'viewport',
- content: 'width=device-width, initial-scale=1.0, user-scalable=no'
- }, {
- name: 'content-type',
- content: 'text/html; charset=UTF-8'
- }, {
- name: 'apple-mobile-web-app-capable',
- content: 'yes'
- }, {
- property: 'og:site_name',
- content: meta.config.title || 'NodeBB'
- }, {
- property: 'keywords',
- content: meta.config['keywords'] || ''
- }],
- metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
- templateValues = {
- cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
- pluginCSS: plugins.cssFiles.map(function(file) { return { path: file } }),
- title: meta.config.title || 'NodeBB',
- browserTitle: meta.config.title || 'NodeBB',
- csrf: options.res.locals.csrf_token,
- relative_path: nconf.get('relative_path'),
- meta_tags: metaString,
- clientScripts: clientScripts
- };
-
- translator.translate(templates.header.parse(templateValues), function(template) {
- callback(null, template);
+ var custom_header = {
+ 'navigation': []
+ };
+
+ plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) {
+ var defaultMetaTags = [{
+ name: 'viewport',
+ content: 'width=device-width, initial-scale=1.0, user-scalable=no'
+ }, {
+ name: 'content-type',
+ content: 'text/html; charset=UTF-8'
+ }, {
+ name: 'apple-mobile-web-app-capable',
+ content: 'yes'
+ }, {
+ property: 'og:site_name',
+ content: meta.config.title || 'NodeBB'
+ }, {
+ property: 'keywords',
+ content: meta.config['keywords'] || ''
+ }],
+ metaString = utils.buildMetaTags(defaultMetaTags.concat(options.metaTags || [])),
+ templateValues = {
+ cssSrc: meta.config['theme:src'] || nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
+ pluginCSS: plugins.cssFiles.map(function(file) { return { path: file } }),
+ title: meta.config.title || 'NodeBB',
+ browserTitle: meta.config.title || 'NodeBB',
+ csrf: options.res.locals.csrf_token,
+ relative_path: nconf.get('relative_path'),
+ meta_tags: metaString,
+ clientScripts: clientScripts,
+ navigation: custom_header.navigation
+ };
+
+ translator.translate(templates.header.parse(templateValues), function(template) {
+ callback(null, template);
+ });
});
};
diff --git a/tests/categories.js b/tests/categories.js
new file mode 100644
index 0000000000..63be2f411d
--- /dev/null
+++ b/tests/categories.js
@@ -0,0 +1,54 @@
+var assert = require('assert'),
+ RDB = require('../src/redis'),
+ Categories = require('../src/categories');
+
+describe('Categories', function() {
+ var categoryObj;
+
+ describe('.create', function() {
+ it('should create a new category', function(done) {
+ Categories.create({
+ name: 'Test Category',
+ description: 'Test category created by testing script',
+ icon: 'icon-ok',
+ blockclass: 'category-blue',
+ order: '5'
+ }, function(err, category) {
+ categoryObj = category;
+ done.apply(this, arguments);
+ });
+ });
+ });
+
+ describe('.getCategoryById', function() {
+ it('should retrieve a newly created category by its ID', function(done) {
+ Categories.getCategoryById(categoryObj.cid, 0, function(err, categoryData) {
+ assert(categoryData);
+ assert.equal(categoryObj.name, categoryData.category_name);
+ assert.equal(categoryObj.description, categoryData.category_description);
+
+ done();
+ });
+ });
+ });
+
+ describe('.getCategoryTopics', function() {
+ it('should return a list of topics', function(done) {
+ Categories.getCategoryTopics(categoryObj.cid, 0, 10, 0, function(topics) {
+ assert(Array.isArray(topics));
+ assert(topics.every(function(topic) {
+ return topic instanceof Object;
+ }));
+
+ done();
+ });
+ });
+ });
+
+ after(function() {
+ RDB.multi()
+ .del('category:'+categoryObj.cid)
+ .rpop('categories:cid')
+ .exec();
+ });
+});
\ No newline at end of file