v1.18.x
barisusakli 9 years ago
parent 5ff5a01c4f
commit 25f3a31ff1

@ -34,5 +34,6 @@
"teaserPost": "last-reply", "teaserPost": "last-reply",
"allowPrivateGroups": 1, "allowPrivateGroups": 1,
"unreadCutoff": 2, "unreadCutoff": 2,
"bookmarkThreshold": 5 "bookmarkThreshold": 5,
"topicsPerList": 20
} }

@ -1,14 +1,11 @@
"use strict"; "use strict";
var async = require('async'); var async = require('async');
var nconf = require('nconf'); var nconf = require('nconf');
var validator = require('validator'); var validator = require('validator');
var categories = require('../categories'); var categories = require('../categories');
var meta = require('../meta'); var meta = require('../meta');
var plugins = require('../plugins');
var helpers = require('./helpers'); var helpers = require('./helpers');
var categoriesController = {}; var categoriesController = {};
@ -51,34 +48,32 @@ categoriesController.list = function(req, res, next) {
categories.flattenCategories(allCategories, categoryData); categories.flattenCategories(allCategories, categoryData);
categories.getRecentTopicReplies(allCategories, req.uid, next); categories.getRecentTopicReplies(allCategories, req.uid, next);
},
function (next) {
var data = {
title: '[[pages:categories]]',
categories: categoryData
};
if (req.path.startsWith('/api/categories') || req.path.startsWith('/categories')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{text: data.title}]);
}
data.categories.forEach(function(category) {
if (category && Array.isArray(category.posts) && category.posts.length) {
category.teaser = {
url: nconf.get('relative_path') + '/topic/' + category.posts[0].topic.slug + '/' + category.posts[0].index,
timestampISO: category.posts[0].timestampISO,
pid: category.posts[0].pid
};
}
});
plugins.fireHook('filter:categories.build', {req: req, res: res, templateData: data}, next);
} }
], function(err, data) { ], function(err) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.render('categories', data.templateData);
var data = {
title: '[[pages:categories]]',
categories: categoryData
};
if (req.path.startsWith('/api/categories') || req.path.startsWith('/categories')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{text: data.title}]);
}
data.categories.forEach(function(category) {
if (category && Array.isArray(category.posts) && category.posts.length) {
category.teaser = {
url: nconf.get('relative_path') + '/topic/' + category.posts[0].topic.slug + '/' + category.posts[0].index,
timestampISO: category.posts[0].timestampISO,
pid: category.posts[0].pid
};
}
});
res.render('categories', data);
}); });
}; };

@ -9,7 +9,6 @@ var privileges = require('../privileges');
var user = require('../user'); var user = require('../user');
var categories = require('../categories'); var categories = require('../categories');
var meta = require('../meta'); var meta = require('../meta');
var plugins = require('../plugins');
var pagination = require('../pagination'); var pagination = require('../pagination');
var helpers = require('./helpers'); var helpers = require('./helpers');
var utils = require('../../public/src/utils'); var utils = require('../../public/src/utils');
@ -143,65 +142,63 @@ categoryController.get = function(req, res, callback) {
categories.getRecentTopicReplies(allCategories, req.uid, function(err) { categories.getRecentTopicReplies(allCategories, req.uid, function(err) {
next(err, categoryData); next(err, categoryData);
}); });
}, }
function (categoryData, next) { ], function (err, categoryData) {
categoryData.privileges = userPrivileges; if (err) {
categoryData.showSelect = categoryData.privileges.editable; return callback(err);
}
res.locals.metaTags = [
{
name: 'title',
content: categoryData.name
},
{
property: 'og:title',
content: categoryData.name
},
{
name: 'description',
content: categoryData.description
},
{
property: "og:type",
content: 'website'
}
];
if (categoryData.backgroundImage) { categoryData.privileges = userPrivileges;
res.locals.metaTags.push({ categoryData.showSelect = categoryData.privileges.editable;
name: 'og:image',
content: categoryData.backgroundImage res.locals.metaTags = [
}); {
name: 'title',
content: categoryData.name
},
{
property: 'og:title',
content: categoryData.name
},
{
name: 'description',
content: categoryData.description
},
{
property: "og:type",
content: 'website'
} }
];
res.locals.linkTags = [ if (categoryData.backgroundImage) {
{ res.locals.metaTags.push({
rel: 'alternate', name: 'og:image',
type: 'application/rss+xml', content: categoryData.backgroundImage
href: nconf.get('url') + '/category/' + cid + '.rss'
},
{
rel: 'up',
href: nconf.get('url')
}
];
categoryData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
categoryData.rssFeedUrl = nconf.get('relative_path') + '/category/' + categoryData.cid + '.rss';
categoryData.title = categoryData.name;
categoryData.pagination = pagination.create(currentPage, pageCount);
categoryData.pagination.rel.forEach(function(rel) {
rel.href = nconf.get('url') + '/category/' + categoryData.slug + rel.href;
res.locals.linkTags.push(rel);
}); });
plugins.fireHook('filter:category.build', {req: req, res: res, templateData: categoryData}, next);
} }
], function (err, data) {
if (err) { res.locals.linkTags = [
return callback(err); {
} rel: 'alternate',
res.render('category', data.templateData); type: 'application/rss+xml',
href: nconf.get('url') + '/category/' + cid + '.rss'
},
{
rel: 'up',
href: nconf.get('url')
}
];
categoryData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
categoryData.rssFeedUrl = nconf.get('relative_path') + '/category/' + categoryData.cid + '.rss';
categoryData.title = categoryData.name;
categoryData.pagination = pagination.create(currentPage, pageCount);
categoryData.pagination.rel.forEach(function(rel) {
rel.href = nconf.get('url') + '/category/' + categoryData.slug + rel.href;
res.locals.linkTags.push(rel);
});
res.render('category', categoryData);
}); });
}; };

@ -1,14 +1,15 @@
"use strict"; "use strict";
var async = require('async'), var async = require('async');
nconf = require('nconf'), var nconf = require('nconf');
validator = require('validator'), var validator = require('validator');
meta = require('../meta'),
groups = require('../groups'), var meta = require('../meta');
user = require('../user'), var groups = require('../groups');
helpers = require('./helpers'), var user = require('../user');
plugins = require('../plugins'), var helpers = require('./helpers');
groupsController = {};
var groupsController = {};
groupsController.list = function(req, res, next) { groupsController.list = function(req, res, next) {
var sort = req.query.sort || 'alpha'; var sort = req.query.sort || 'alpha';
@ -83,22 +84,20 @@ groupsController.details = function(req, res, callback) {
}, },
isAdmin: async.apply(user.isAdministrator, req.uid) isAdmin: async.apply(user.isAdministrator, req.uid)
}, next); }, next);
},
function (results, next) {
if (!results.group) {
return callback();
}
results.title = '[[pages:group, ' + results.group.displayName + ']]';
results.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:groups]]', url: '/groups' }, {text: results.group.displayName}]);
results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
plugins.fireHook('filter:group.build', {req: req, res: res, templateData: results}, next);
} }
], function(err, results) { ], function(err, results) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
res.render('groups/details', results.templateData); if (!results.group) {
return callback();
}
results.title = '[[pages:group, ' + results.group.displayName + ']]';
results.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:groups]]', url: '/groups' }, {text: results.group.displayName}]);
results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
res.render('groups/details', results);
}); });
}; };

@ -134,32 +134,29 @@ Controllers.register = function(req, res, next) {
}, },
function(next) { function(next) {
plugins.fireHook('filter:parse.post', {postData: {content: meta.config.termsOfUse || ''}}, next); plugins.fireHook('filter:parse.post', {postData: {content: meta.config.termsOfUse || ''}}, next);
},
function(tos, next) {
var loginStrategies = require('../routes/authentication').getLoginStrategies();
var data = {
'register_window:spansize': loginStrategies.length ? 'col-md-6' : 'col-md-12',
'alternate_logins': !!loginStrategies.length
};
data.authentication = loginStrategies;
data.minimumUsernameLength = parseInt(meta.config.minimumUsernameLength, 10);
data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10);
data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
data.termsOfUse = tos.postData.content;
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]);
data.regFormEntry = [];
data.error = req.flash('error')[0];
data.title = '[[pages:register]]';
plugins.fireHook('filter:register.build', {req: req, res: res, templateData: data}, next);
} }
], function(err, data) { ], function(err, termsOfUse) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.render('register', data.templateData); var loginStrategies = require('../routes/authentication').getLoginStrategies();
var data = {
'register_window:spansize': loginStrategies.length ? 'col-md-6' : 'col-md-12',
'alternate_logins': !!loginStrategies.length
};
data.authentication = loginStrategies;
data.minimumUsernameLength = parseInt(meta.config.minimumUsernameLength, 10);
data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10);
data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
data.termsOfUse = termsOfUse.postData.content;
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[register:register]]'}]);
data.regFormEntry = [];
data.error = req.flash('error')[0];
data.title = '[[pages:register]]';
res.render('register', data);
}); });
}; };

@ -1,15 +1,15 @@
'use strict'; 'use strict';
var nconf = require('nconf'), var nconf = require('nconf');
topics = require('../topics'), var topics = require('../topics');
plugins = require('../plugins'), var meta = require('../meta');
meta = require('../meta'), var helpers = require('./helpers');
helpers = require('./helpers');
var popularController = {}; var popularController = {};
var anonCache = {}, lastUpdateTime = 0; var anonCache = {};
var lastUpdateTime = 0;
var terms = { var terms = {
daily: 'day', daily: 'day',
@ -48,7 +48,8 @@ popularController.get = function(req, res, next) {
topics: topics, topics: topics,
'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1, 'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1,
rssFeedUrl: nconf.get('relative_path') + '/popular/' + (req.params.term || 'daily') + '.rss', rssFeedUrl: nconf.get('relative_path') + '/popular/' + (req.params.term || 'daily') + '.rss',
title: '[[pages:popular-' + term + ']]' title: '[[pages:popular-' + term + ']]',
term: term
}; };
if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) { if (req.path.startsWith('/api/popular') || req.path.startsWith('/popular')) {
@ -66,12 +67,7 @@ popularController.get = function(req, res, next) {
lastUpdateTime = Date.now(); lastUpdateTime = Date.now();
} }
plugins.fireHook('filter:popular.build', {req: req, res: res, term: term, templateData: data}, function(err, data) { res.render('popular', data);
if (err) {
return next(err);
}
res.render('popular', data.templateData);
});
}); });
}; };

@ -2,11 +2,10 @@
'use strict'; 'use strict';
var nconf = require('nconf'); var nconf = require('nconf');
var async = require('async');
var topics = require('../topics'); var topics = require('../topics');
var meta = require('../meta'); var meta = require('../meta');
var helpers = require('./helpers'); var helpers = require('./helpers');
var plugins = require('../plugins');
var recentController = {}; var recentController = {};
@ -14,25 +13,19 @@ recentController.get = function(req, res, next) {
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
async.waterfall([ topics.getTopicsFromSet('topics:recent', req.uid, 0, stop, function(err, data) {
function (next) {
topics.getTopicsFromSet('topics:recent', req.uid, 0, stop, next);
},
function (data, next) {
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
data.rssFeedUrl = nconf.get('relative_path') + '/recent.rss';
data.title = '[[pages:recent]]';
if (req.path.startsWith('/api/recent') || req.path.startsWith('/recent')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[recent:title]]'}]);
}
plugins.fireHook('filter:recent.build', {req: req, res: res, templateData: data}, next);
}
], function(err, data) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.render('recent', data.templateData);
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
data.rssFeedUrl = nconf.get('relative_path') + '/recent.rss';
data.title = '[[pages:recent]]';
if (req.path.startsWith('/api/recent') || req.path.startsWith('/recent')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[recent:title]]'}]);
}
res.render('recent', data);
}); });
}; };

@ -1,14 +1,14 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
meta = require('../meta'), var meta = require('../meta');
plugins = require('../plugins'), var plugins = require('../plugins');
search = require('../search'), var search = require('../search');
categories = require('../categories'), var categories = require('../categories');
pagination = require('../pagination'), var pagination = require('../pagination');
helpers = require('./helpers'); var helpers = require('./helpers');
var searchController = {}; var searchController = {};
@ -61,12 +61,7 @@ searchController.search = function(req, res, next) {
searchData.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]); searchData.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]);
searchData.expandSearch = !req.params.term; searchData.expandSearch = !req.params.term;
plugins.fireHook('filter:search.build', {data: data, results: searchData}, function(err, data) { res.render('search', searchData);
if (err) {
return next(err);
}
res.render('search', data.results);
});
}); });
}; };

@ -288,12 +288,7 @@ topicsController.get = function(req, res, callback) {
}); });
} }
plugins.fireHook('filter:topic.build', {req: req, res: res, templateData: data}, function(err, data) { res.render('topic', data);
if (err) {
return callback(err);
}
res.render('topic', data.templateData);
});
}); });
}; };

@ -8,7 +8,6 @@ var privileges = require('../privileges');
var user = require('../user'); var user = require('../user');
var topics = require('../topics'); var topics = require('../topics');
var helpers = require('./helpers'); var helpers = require('./helpers');
var plugins = require('../plugins');
var unreadController = {}; var unreadController = {};
@ -42,47 +41,44 @@ unreadController.get = function(req, res, next) {
}, },
function(cids, next) { function(cids, next) {
categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor'], next); categories.getCategoriesFields(cids, ['cid', 'name', 'slug', 'icon', 'link', 'color', 'bgColor'], next);
},
function(categories, next) {
categories = categories.filter(function(category) {
return category && !category.link;
});
categories.forEach(function(category) {
category.selected = parseInt(category.cid, 10) === parseInt(cid, 10);
if (category.selected) {
results.unreadTopics.selectedCategory = category;
}
});
results.unreadTopics.categories = categories;
results.unreadTopics.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]);
results.unreadTopics.title = '[[pages:unread]]';
results.unreadTopics.filters = [{
name: '[[unread:all-topics]]',
url: 'unread',
selected: filter === ''
}, {
name: '[[unread:new-topics]]',
url: 'unread/new',
selected: filter === 'new'
}, {
name: '[[unread:watched-topics]]',
url: 'unread/watched',
selected: filter === 'watched'
}];
results.unreadTopics.selectedFilter = results.unreadTopics.filters.filter(function(filter) {
return filter && filter.selected;
})[0];
plugins.fireHook('filter:unread.build', {req: req, res: res, templateData: results.unreadTopics}, next);
} }
], function(err, data) { ], function(err, categories) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.render('unread', data.templateData); categories = categories.filter(function(category) {
return category && !category.link;
});
categories.forEach(function(category) {
category.selected = parseInt(category.cid, 10) === parseInt(cid, 10);
if (category.selected) {
results.unreadTopics.selectedCategory = category;
}
});
results.unreadTopics.categories = categories;
results.unreadTopics.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[unread:title]]'}]);
results.unreadTopics.title = '[[pages:unread]]';
results.unreadTopics.filters = [{
name: '[[unread:all-topics]]',
url: 'unread',
selected: filter === ''
}, {
name: '[[unread:new-topics]]',
url: 'unread/new',
selected: filter === 'new'
}, {
name: '[[unread:watched-topics]]',
url: 'unread/watched',
selected: filter === 'watched'
}];
results.unreadTopics.selectedFilter = results.unreadTopics.filters.filter(function(filter) {
return filter && filter.selected;
})[0];
res.render('unread', results.unreadTopics);
}); });
}; };

@ -5,7 +5,6 @@ var user = require('../user');
var meta = require('../meta'); var meta = require('../meta');
var pagination = require('../pagination'); var pagination = require('../pagination');
var plugins = require('../plugins');
var db = require('../database'); var db = require('../database');
var helpers = require('./helpers'); var helpers = require('./helpers');
@ -165,26 +164,20 @@ usersController.getUsersAndCount = function(set, uid, start, stop, callback) {
}; };
function render(req, res, data, next) { function render(req, res, data, next) {
plugins.fireHook('filter:users.build', {req: req, res: res, templateData: data }, function(err, data) { var registrationType = meta.config.registrationType;
data.maximumInvites = meta.config.maximumInvites;
data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
data.adminInviteOnly = registrationType === 'admin-invite-only';
data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
user.getInvitesNumber(req.uid, function(err, num) {
if (err) { if (err) {
return next(err); return next(err);
} }
var registrationType = meta.config.registrationType; data.invites = num;
res.render('users', data);
data.templateData.maximumInvites = meta.config.maximumInvites;
data.templateData.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
data.templateData.adminInviteOnly = registrationType === 'admin-invite-only';
data.templateData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
user.getInvitesNumber(req.uid, function(err, num) {
if (err) {
return next(err);
}
data.templateData.invites = num;
res.render('users', data.templateData);
});
}); });
} }

@ -1,6 +1,8 @@
'use strict'; 'use strict';
var nconf = require('nconf'); var nconf = require('nconf');
var plugins = require('../plugins');
var translator = require('../../public/src/modules/translator'); var translator = require('../../public/src/modules/translator');
module.exports = function(middleware) { module.exports = function(middleware) {
@ -9,78 +11,86 @@ module.exports = function(middleware) {
// res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687 // res.render post-processing, modified from here: https://gist.github.com/mrlannigan/5051687
var render = res.render; var render = res.render;
res.render = function(template, options, fn) { res.render = function(template, options, fn) {
var self = this, var self = this;
req = this.req, var req = this.req;
defaultFn = function(err, str){ var defaultFn = function(err, str) {
if (err) { if (err) {
return next(err); return next(err);
} }
self.send(str); self.send(str);
}; };
options = options || {};
options = options || {};
if ('function' === typeof options) { if ('function' === typeof options) {
fn = options; fn = options;
options = {}; options = {};
} }
options.loggedIn = !!req.uid; plugins.fireHook('filter:' + template + '.build', {req: req, res: res, templateData: options}, function(err, data) {
options.relative_path = nconf.get('relative_path'); if (err) {
options.template = {name: template}; return next(err);
options.template[template] = true; }
options.bodyClass = buildBodyClass(req);
res.locals.template = template; options = data.templateData;
options._locals = undefined;
if (res.locals.isAPI) { options.loggedIn = !!req.uid;
if (req.route && req.route.path === '/api/') { options.relative_path = nconf.get('relative_path');
options.title = '[[pages:home]]'; options.template = {name: template};
} options.template[template] = true;
options.bodyClass = buildBodyClass(req);
return res.json(options); res.locals.template = template;
} options._locals = undefined;
if ('function' !== typeof fn) { if (res.locals.isAPI) {
fn = defaultFn; if (req.route && req.route.path === '/api/') {
} options.title = '[[pages:home]]';
}
var ajaxifyData = JSON.stringify(options); return res.json(options);
ajaxifyData = ajaxifyData.replace(/<\//g, '<\\/'); }
render.call(self, template, options, function(err, str) { if ('function' !== typeof fn) {
if (err) { fn = defaultFn;
return fn(err);
} }
str = (res.locals.postHeader ? res.locals.postHeader : '') + str + (res.locals.preFooter ? res.locals.preFooter : ''); var ajaxifyData = JSON.stringify(options);
ajaxifyData = ajaxifyData.replace(/<\//g, '<\\/');
if (res.locals.footer) { render.call(self, template, options, function(err, str) {
str = str + res.locals.footer; if (err) {
} else if (res.locals.adminFooter) { return fn(err);
str = str + res.locals.adminFooter; }
}
if (res.locals.renderHeader || res.locals.renderAdminHeader) { str = (res.locals.postHeader ? res.locals.postHeader : '') + str + (res.locals.preFooter ? res.locals.preFooter : '');
var method = res.locals.renderHeader ? middleware.renderHeader : middleware.admin.renderHeader;
method(req, res, options, function(err, template) { if (res.locals.footer) {
if (err) { str = str + res.locals.footer;
return fn(err); } else if (res.locals.adminFooter) {
} str = str + res.locals.adminFooter;
str = template + str; }
var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB';
language = req.query.lang || language; if (res.locals.renderHeader || res.locals.renderAdminHeader) {
translator.translate(str, language, function(translated) { var method = res.locals.renderHeader ? middleware.renderHeader : middleware.admin.renderHeader;
translated = translator.unescape(translated); method(req, res, options, function(err, template) {
translated = translated + '<script id="ajaxify-data" type="application/json">' + ajaxifyData + '</script>'; if (err) {
fn(err, translated); return fn(err);
}
str = template + str;
var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB';
language = req.query.lang || language;
translator.translate(str, language, function(translated) {
translated = translator.unescape(translated);
translated = translated + '<script id="ajaxify-data" type="application/json">' + ajaxifyData + '</script>';
fn(err, translated);
});
}); });
}); } else {
} else { str = str + '<script id="ajaxify-data" type="application/json">' + ajaxifyData + '</script>';
str = str + '<script id="ajaxify-data" type="application/json">' + ajaxifyData + '</script>'; fn(err, str);
fn(err, str); }
} });
}); });
}; };

@ -62,12 +62,7 @@ function getAvailable(callback) {
return item; return item;
}); });
// DEPRECATION: backwards compatibility for filter:header.build, will be removed soon. plugins.fireHook('filter:navigation.available', core, callback);
plugins.fireHook('filter:header.build', {navigation: []}, function(err, data) {
core = core.concat(data.navigation);
plugins.fireHook('filter:navigation.available', core, callback);
});
} }
module.exports = admin; module.exports = admin;

@ -1,10 +1,8 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
db = require('../database'), var privileges = require('../privileges');
privileges = require('../privileges');
module.exports = function(Topics) { module.exports = function(Topics) {

Loading…
Cancel
Save