diff --git a/package.json b/package.json index c725b71130..b795e260e3 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "nodebb-plugin-spam-be-gone": "^0.3.0", "nodebb-theme-lavender": "~0.1.0", "nodebb-theme-vanilla": "~0.1.0", - "nodebb-widget-essentials": "~0.1.1", + "nodebb-widget-essentials": "~0.2.0", "npm": "^2.1.4", "passport": "^0.2.1", "passport-local": "1.0.0", diff --git a/public/src/client/register.js b/public/src/client/register.js index a332aa7c6f..6780faae59 100644 --- a/public/src/client/register.js +++ b/public/src/client/register.js @@ -146,7 +146,7 @@ define('forum/register', function() { }); username.on('keyup', function() { - $('#yourUsername').html(this.value.length > 0 ? this.value : 'username'); + $('#yourUsername').text(this.value.length > 0 ? this.value : 'username'); }); username.on('blur', function() { diff --git a/src/categories.js b/src/categories.js index 4ccad2bb74..6b5705b33f 100644 --- a/src/categories.js +++ b/src/categories.js @@ -1,68 +1,26 @@ 'use strict'; -var db = require('./database'), - posts = require('./posts'), - utils = require('./../public/src/utils'), +var async = require('async'), + nconf = require('nconf'), + + db = require('./database'), user = require('./user'), Groups = require('./groups'), - topics = require('./topics'), plugins = require('./plugins'), - meta = require('./meta'), validator = require('validator'), - privileges = require('./privileges'), - - async = require('async'), - winston = require('winston'), - nconf = require('nconf'); + privileges = require('./privileges'); (function(Categories) { + require('./categories/create')(Categories); require('./categories/delete')(Categories); + require('./categories/topics')(Categories); + require('./categories/unread')(Categories); require('./categories/activeusers')(Categories); require('./categories/recentreplies')(Categories); require('./categories/update')(Categories); - Categories.create = function(data, callback) { - db.incrObjectField('global', 'nextCid', function(err, cid) { - if (err) { - return callback(err); - } - - var slug = cid + '/' + utils.slugify(data.name); - - var category = { - cid: cid, - name: data.name, - description: data.description, - icon: data.icon, - bgColor: data.bgColor, - color: data.color, - slug: slug, - parentCid: 0, - topic_count: 0, - post_count: 0, - disabled: 0, - order: data.order, - link: '', - numRecentReplies: 1, - class: 'col-md-3 col-xs-6', - imageClass: 'auto' - }; - - async.series([ - async.apply(db.setObject, 'category:' + cid, category), - async.apply(db.sortedSetAdd, 'categories:cid', data.order, cid) - ], function(err) { - if (err) { - return callback(err); - } - - callback(null, category); - }); - }); - }; - Categories.exists = function(cid, callback) { db.isSortedSetMember('categories:cid', cid, callback); }; @@ -112,42 +70,6 @@ var db = require('./database'), }); }; - Categories.getCategoryTopics = function(data, callback) { - var tids; - async.waterfall([ - function(next) { - Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next); - }, - function(topicIds, next) { - tids = topicIds; - topics.getTopicsByTids(tids, data.uid, next); - }, - function(topics, next) { - if (!Array.isArray(topics) || !topics.length) { - return next(null, { - topics: [], - nextStart: 1 - }); - } - - var indices = {}, - i = 0; - for(i=0; i topicCount) { + var url = '/category/' + cid + '/' + req.params.slug + (topicIndex > topicCount ? '/' + topicCount : ''); + return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); + } + userPrivileges = results.privileges; var settings = results.userSettings; - var topicIndex = 0; if (!settings.usePagination) { - topicIndex = Math.max((req.params.topic_index || 1) - (settings.topicsPerPage - 1), 0); + topicIndex = Math.max((topicIndex || 1) - (settings.topicsPerPage - 1), 0); } else if (!req.query.page) { - var index = Math.max(parseInt((req.params.topic_index || 0), 10), 0); + var index = Math.max(parseInt((topicIndex || 0), 10), 0); page = Math.ceil((index + 1) / settings.topicsPerPage); } diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 8596803ca2..d2ff101636 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -60,11 +60,8 @@ topicsController.get = function(req, res, next) { if (utils.isNumber(req.params.post_index)) { var url = ''; - if (req.params.post_index > postCount) { - url = '/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount; - return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); - } else if (req.params.post_index < 1) { - url = '/topic/' + req.params.topic_id + '/' + req.params.slug; + if (req.params.post_index < 1 || req.params.post_index > postCount) { + url = '/topic/' + req.params.topic_id + '/' + req.params.slug + (req.params.post_index > postCount ? '/' + postCount : ''); return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); } } diff --git a/src/groups.js b/src/groups.js index 4f007f1eec..cbdc55c32b 100644 --- a/src/groups.js +++ b/src/groups.js @@ -140,6 +140,10 @@ var async = require('async'), }); }; + Groups.getMembers = function(groupName, callback) { + db.getSetMembers('group:' + groupName + ':members', callback); + }; + Groups.search = function(query, options, callback) { if (!query) { return callback(null, []); diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 6d0b06b7dc..422805a391 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -127,26 +127,6 @@ middleware.addSlug = function(req, res, next) { next(); }; -middleware.checkTopicIndex = function(req, res, next) { - categories.getCategoryField(req.params.category_id, 'topic_count', function(err, topicCount) { - if (err) { - return next(err); - } - var topicIndex = parseInt(req.params.topic_index, 10); - topicCount = parseInt(topicCount, 10) + 1; - var url = ''; - - if (topicIndex > topicCount) { - url = '/category/' + req.params.category_id + '/' + req.params.slug + '/' + topicCount; - return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); - } else if (topicIndex < 1) { - url = '/category/' + req.params.category_id + '/' + req.params.slug; - return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url); - } - next(); - }); -}; - middleware.prepareAPI = function(req, res, next) { res.locals.isAPI = true; next(); diff --git a/src/plugins.js b/src/plugins.js index f9f275c0a7..bdcdb5f387 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -129,9 +129,6 @@ var fs = require('fs'), app.render.apply(app, arguments); }; - // Deprecated as of v0.5.0, remove this hook call for NodeBB v0.6.0-1 - Plugins.fireHook('action:app.load', router, middleware, controllers); - Plugins.fireHook('static:app.load', {app: app, router: router, middleware: middleware, controllers: controllers}, function() { hotswap.replace('plugins', router); winston.info('[plugins] All plugins reloaded and rerouted'); @@ -391,121 +388,78 @@ var fs = require('fs'), return !!(Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0); }; - Plugins.fireHook = function(hook) { - var callback = typeof arguments[arguments.length-1] === 'function' ? arguments[arguments.length-1] : null, - args = arguments.length ? Array.prototype.slice.call(arguments, 1) : []; - - if (callback) { - args.pop(); - } + Plugins.fireHook = function(hook, params, callback) { + callback = typeof callback === 'function' ? callback : function() {}; var hookList = Plugins.loadedHooks[hook]; - if (Array.isArray(hookList)) { - // if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\''); - var hookType = hook.split(':')[0]; - switch (hookType) { - case 'filter': - async.reduce(hookList, args, function(value, hookObj, next) { - if (hookObj.method) { - if (!hookObj.hasOwnProperty('callbacked') || hookObj.callbacked === true) { - // omg, after 6 months I finally realised what this does... - // It adds the callback to the arguments passed-in, since the callback - // is defined in *this* file (the async cb), and not the hooks themselves. - value = hookObj.method.apply(Plugins, value.concat(function() { - next(arguments[0], Array.prototype.slice.call(arguments, 1)); - })); + if (!Array.isArray(hookList) || !hookList.length) { + return callback(null, params); + } - /* - Backwards compatibility block for v0.5.0 - Remove this once NodeBB enters v0.5.0-1 - */ - if (value !== undefined && value !== callback) { - winston.warn('[plugins/' + hookObj.id + '] "callbacked" deprecated as of 0.4x. Use asynchronous method instead for hook: ' + hook); - next(null, [value]); - } - } else { - winston.warn('[plugins/' + hookObj.id + '] "callbacked" deprecated as of 0.4x. Use asynchronous method instead for hook: ' + hook); - value = hookObj.method.apply(Plugins, value); - next(null, [value]); - } - /* End backwards compatibility block */ - } else { - if (global.env === 'development') { - winston.info('[plugins] Expected method for hook \'' + hook + '\' in plugin \'' + hookObj.id + '\' not found, skipping.'); - } - next(null, [value]); - } - }, function(err, values) { - if (err) { - if (global.env === 'development') { - winston.info('[plugins] Problem executing hook: ' + hook + ' err: ' + JSON.stringify(err)); - } - } - - if (callback) { - callback.apply(Plugins, [err].concat(values)); - } - }); - break; - case 'action': - var deprecationWarn = []; - async.each(hookList, function(hookObj, next) { - /* - Backwards compatibility block for v0.5.0 - Remove this once NodeBB enters v0.6.0-1 - */ - if (hook === 'action:app.load') { - deprecationWarn.push(hookObj.id); - } - /* End backwards compatibility block */ - - if (hookObj.method) { - hookObj.method.apply(Plugins, args); - } else { - if (global.env === 'development') { - winston.info('[plugins] Expected method \'' + hookObj.method + '\' in plugin \'' + hookObj.id + '\' not found, skipping.'); - } - } - - next(); - }, function() { - /* - Backwards compatibility block for v0.5.0 - Remove this once NodeBB enters v0.6.0-1 - */ - if (deprecationWarn.length) { - winston.warn('[plugins] The `action:app.load` hook is deprecated in favour of `static:app.load`, please notify the developers of the following plugins:'); - for(var x=0,numDeprec=deprecationWarn.length;x