From 853aa37cd235fde52c8035233bd243f6e355f041 Mon Sep 17 00:00:00 2001 From: yariplus Date: Thu, 17 Sep 2015 15:31:05 -0400 Subject: [PATCH 1/4] Add user home pages. #3616 --- install/data/defaults.json | 1 + public/src/client/account/settings.js | 13 +++++++++++ src/controllers/accounts.js | 1 - src/controllers/api.js | 1 + src/controllers/index.js | 31 ++++++++++++++++----------- src/user/settings.js | 3 ++- src/views/admin/general/homepage.tpl | 9 +++++++- 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 3274c8ec4e..6d81fdbc82 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -15,6 +15,7 @@ "allowLocalLogin": 1, "allowAccountDelete": 1, "allowFileUploads": 0, + "allowUserHomePage": 1, "maximumFileSize": 2048, "minimumTitleLength": 3, "maximumTitleLength": 255, diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js index bf535d8ec0..840f498259 100644 --- a/public/src/client/account/settings.js +++ b/public/src/client/account/settings.js @@ -68,7 +68,20 @@ define('forum/account/settings', ['forum/account/header'], function(header) { css.attr('href', val); }); + + $('[data-property="homePageRoute"]').on('change', toggleCustomRoute); + + toggleCustomRoute(); }; + function toggleCustomRoute() { + $('[data-property="homePageCustom"]').val(''); + if ($('[data-property="homePageRoute"]').val() === 'custom') { + $('#homePageCustom').show(); + }else{ + $('#homePageCustom').hide(); + } + } + return AccountSettings; }); diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 8384b4e9b8..65116b26da 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -11,5 +11,4 @@ var accountsController = { chats: require('./accounts/chats') }; - module.exports = accountsController; diff --git a/src/controllers/api.js b/src/controllers/api.js index 9a6fbee238..5ccedc5aeb 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -57,6 +57,7 @@ apiController.getConfig = function(req, res, next) { config.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads) === 1; config.allowTopicsThumbnail = parseInt(meta.config.allowTopicsThumbnail, 10) === 1; config.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1; + config.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1; config.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1; config.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1; config.usePagination = parseInt(meta.config.usePagination, 10) === 1; diff --git a/src/controllers/index.js b/src/controllers/index.js index ccb8ece26a..4df1455c89 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -33,22 +33,27 @@ var Controllers = { Controllers.home = function(req, res, next) { - var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories', - hook = 'action:homepage.get:' + route; + var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories'; - if (plugins.hasListeners(hook)) { - plugins.fireHook(hook, {req: req, res: res, next: next}); - } else { - if (route === 'categories' || route === '/') { - Controllers.categories.list(req, res, next); - } else if (route === 'recent') { - Controllers.recent.get(req, res, next); - } else if (route === 'popular') { - Controllers.popular.get(req, res, next); + user.getSettings(req.uid, function(err, settings) { + if (!err) route = settings.homePageRoute || route; + + var hook = 'action:homepage.get:' + route; + + if (plugins.hasListeners(hook)) { + plugins.fireHook(hook, {req: req, res: res, next: next}); } else { - res.redirect(route); + if (route === 'categories' || route === '/') { + Controllers.categories.list(req, res, next); + } else if (route === 'recent') { + Controllers.recent.get(req, res, next); + } else if (route === 'popular') { + Controllers.popular.get(req, res, next); + } else { + res.redirect(route); + } } - } + }); }; Controllers.reset = function(req, res, next) { diff --git a/src/user/settings.js b/src/user/settings.js index 17e524bcb7..a2d83e89eb 100644 --- a/src/user/settings.js +++ b/src/user/settings.js @@ -115,7 +115,8 @@ module.exports = function(User) { sendPostNotifications: data.sendPostNotifications, restrictChat: data.restrictChat, topicSearchEnabled: data.topicSearchEnabled, - groupTitle: data.groupTitle + groupTitle: data.groupTitle, + homePageRoute: data.homePageCustom || data.homePageRoute }; if (data.bootswatchSkin) { diff --git a/src/views/admin/general/homepage.tpl b/src/views/admin/general/homepage.tpl index 5148d79da9..bfdc086b11 100644 --- a/src/views/admin/general/homepage.tpl +++ b/src/views/admin/general/homepage.tpl @@ -12,11 +12,18 @@ -
+
+
+ +
From f815f2d9810531069ee8ae6808e12efa788db0ea Mon Sep 17 00:00:00 2001 From: yariplus Date: Wed, 4 Nov 2015 05:55:02 -0500 Subject: [PATCH 2/4] 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; From 82f78d910d90f53e0a5aa8c04171940be59e3bef Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 5 Nov 2015 14:00:01 -0500 Subject: [PATCH 3/4] tweaks to language and updating theme minvers --- package.json | 4 ++-- public/language/en_GB/user.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ccf4ecb694..8260ad823d 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "nodebb-plugin-spam-be-gone": "0.4.2", "nodebb-rewards-essentials": "0.0.5", "nodebb-theme-lavender": "2.0.13", - "nodebb-theme-persona": "4.0.21", - "nodebb-theme-vanilla": "5.0.6", + "nodebb-theme-persona": "4.0.22", + "nodebb-theme-vanilla": "5.0.7", "nodebb-widget-essentials": "2.0.3", "npm": "^2.1.4", "passport": "^0.3.0", diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index c4920dad00..15cf8d7405 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -107,10 +107,11 @@ "select-skin": "Select a Skin", - "select-homepage": "Select a Custom Homepage", + "select-homepage": "Select a 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", + "custom_route_help": "Enter a route name here, without any preceding slash (e.g. \"recent\", or \"popular\")", "sso.title": "Single Sign-on Services", "sso.associated": "Associated with", From 040783d5c4060477a1216ebee23f460f267e14fe Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 5 Nov 2015 14:15:22 -0500 Subject: [PATCH 4/4] up'd persona --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8260ad823d..4a951ba247 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "nodebb-plugin-spam-be-gone": "0.4.2", "nodebb-rewards-essentials": "0.0.5", "nodebb-theme-lavender": "2.0.13", - "nodebb-theme-persona": "4.0.22", + "nodebb-theme-persona": "4.0.23", "nodebb-theme-vanilla": "5.0.7", "nodebb-widget-essentials": "2.0.3", "npm": "^2.1.4",