From f815f2d9810531069ee8ae6808e12efa788db0ea Mon Sep 17 00:00:00 2001 From: yariplus Date: Wed, 4 Nov 2015 05:55:02 -0500 Subject: [PATCH] Fix userhomepage derps --- public/language/en_GB/user.json | 5 +++ src/controllers/accounts/settings.js | 52 ++++++++++++++++++++++++++++ src/controllers/index.js | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index 32040e49c8..c4920dad00 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -107,6 +107,11 @@ "select-skin": "Select a Skin", + "select-homepage": "Select a Custom Homepage", + "homepage": "Homepage", + "homepage_description": "Select a page to use as the forum homepage or 'None' to use the default homepage.", + "custom_route": "Custom Homepage Route", + "sso.title": "Single Sign-on Services", "sso.associated": "Associated with", "sso.not-associated": "Click here to associate with" diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js index 451711b166..1e18d4a4a4 100644 --- a/src/controllers/accounts/settings.js +++ b/src/controllers/accounts/settings.js @@ -7,6 +7,9 @@ var async = require('async'), languages = require('../../languages'), meta = require('../../meta'), plugins = require('../../plugins'), + privileges = require('../../privileges'), + categories = require('../../categories'), + db = require('../../database'), helpers = require('../helpers'), accountHelpers = require('./helpers'); @@ -34,6 +37,52 @@ settingsController.get = function(req, res, callback) { }, languages: function(next) { languages.list(next); + }, + homePageRoutes: function(next) { + async.waterfall([ + function(next) { + db.getSortedSetRange('cid:0:children', 0, -1, next); + }, + function(cids, next) { + privileges.categories.filterCids('find', cids, 0, next); + }, + function(cids, next) { + categories.getMultipleCategoryFields(cids, ['name', 'slug'], next); + }, + function(categoryData, next) { + categoryData = categoryData.map(function(category) { + return { + route: 'category/' + category.slug, + name: 'Category: ' + category.name + }; + }); + next(null, categoryData); + } + ], function(err, categoryData) { + if (err || !categoryData) categoryData = []; + + plugins.fireHook('filter:homepage.get', {routes: [ + { + route: 'categories', + name: 'Categories' + }, + { + route: 'recent', + name: 'Recent' + }, + { + route: 'popular', + name: 'Popular' + } + ].concat(categoryData)}, function(err, data) { + data.routes.push({ + route: 'custom', + name: 'Custom' + }); + + next(null, data.routes); + }); + }); } }, next); }, @@ -41,6 +90,7 @@ settingsController.get = function(req, res, callback) { userData.settings = results.settings; userData.languages = results.languages; userData.userGroups = results.userGroups[0]; + userData.homePageRoutes = results.homePageRoutes; plugins.fireHook('filter:user.customSettings', {settings: results.settings, customSettings: [], uid: req.uid}, next); }, function(data, next) { @@ -95,6 +145,8 @@ settingsController.get = function(req, res, callback) { userData.disableCustomUserSkins = parseInt(meta.config.disableCustomUserSkins, 10) === 1; + userData.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1; + userData.title = '[[pages:account/settings]]'; userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:settings]]'}]); diff --git a/src/controllers/index.js b/src/controllers/index.js index 4df1455c89..5d776780cf 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -36,7 +36,7 @@ Controllers.home = function(req, res, next) { var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories'; user.getSettings(req.uid, function(err, settings) { - if (!err) route = settings.homePageRoute || route; + if (!err && settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') route = settings.homePageRoute || route; var hook = 'action:homepage.get:' + route;