| 
									
										
										
										
											2014-03-02 22:12:08 -05:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | var async = require('async'); | 
					
						
							|  |  |  | var nconf = require('nconf'); | 
					
						
							|  |  |  | var validator = require('validator'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var meta = require('../meta'); | 
					
						
							|  |  |  | var user = require('../user'); | 
					
						
							|  |  |  | var plugins = require('../plugins'); | 
					
						
							|  |  |  | var sitemap = require('../sitemap'); | 
					
						
							|  |  |  | var helpers = require('./helpers'); | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-02 22:12:08 -05:00
										 |  |  | var Controllers = { | 
					
						
							| 
									
										
										
										
											2015-02-13 18:16:36 -05:00
										 |  |  | 	topics: require('./topics'), | 
					
						
							| 
									
										
										
										
											2016-05-05 20:24:03 +03:00
										 |  |  | 	posts: require('./posts'), | 
					
						
							| 
									
										
										
										
											2015-02-13 18:16:36 -05:00
										 |  |  | 	categories: require('./categories'), | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 	category: require('./category'), | 
					
						
							| 
									
										
										
										
											2015-07-13 14:47:09 -04:00
										 |  |  | 	unread: require('./unread'), | 
					
						
							| 
									
										
										
										
											2015-08-17 16:38:05 -04:00
										 |  |  | 	recent: require('./recent'), | 
					
						
							|  |  |  | 	popular: require('./popular'), | 
					
						
							| 
									
										
										
										
											2015-02-13 18:16:36 -05:00
										 |  |  | 	tags: require('./tags'), | 
					
						
							|  |  |  | 	search: require('./search'), | 
					
						
							|  |  |  | 	users: require('./users'), | 
					
						
							|  |  |  | 	groups: require('./groups'), | 
					
						
							|  |  |  | 	accounts: require('./accounts'), | 
					
						
							| 
									
										
										
										
											2015-06-17 14:13:29 -04:00
										 |  |  | 	authentication: require('./authentication'), | 
					
						
							| 
									
										
										
										
											2015-02-13 18:16:36 -05:00
										 |  |  | 	api: require('./api'), | 
					
						
							| 
									
										
										
										
											2016-03-15 12:13:35 +02:00
										 |  |  | 	admin: require('./admin'), | 
					
						
							|  |  |  | 	globalMods: require('./globalmods') | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Controllers.home = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-04-20 16:12:55 -04:00
										 |  |  | 	var route = meta.config.homePageRoute || (meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories'; | 
					
						
							| 
									
										
										
										
											2015-02-27 15:00:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 	user.getSettings(req.uid, function(err, settings) { | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-07 18:55:30 +00:00
										 |  |  | 		if (parseInt(meta.config.allowUserHomePage, 10) === 1 && settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') { | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 			route = settings.homePageRoute || route; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var hook = 'action:homepage.get:' + route; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (plugins.hasListeners(hook)) { | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 			return plugins.fireHook(hook, {req: req, res: res, next: next}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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); | 
					
						
							| 
									
										
										
										
											2015-02-27 15:00:38 -05:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 			var match = /^category\/(\d+)\/(.*)$/.exec(route); | 
					
						
							| 
									
										
										
										
											2015-12-01 12:59:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-13 09:25:49 +02:00
										 |  |  | 			if (match) { | 
					
						
							|  |  |  | 				req.params.topic_index = "1"; | 
					
						
							|  |  |  | 				req.params.category_id = match[1]; | 
					
						
							|  |  |  | 				req.params.slug = match[2]; | 
					
						
							|  |  |  | 				Controllers.category.get(req, res, next); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				res.redirect(route); | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-02-27 15:00:38 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-17 15:31:05 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-03 17:16:53 -05:00
										 |  |  | Controllers.reset = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 	if (req.params.code) { | 
					
						
							| 
									
										
										
										
											2015-02-08 21:06:38 -05:00
										 |  |  | 		user.reset.validate(req.params.code, function(err, valid) { | 
					
						
							| 
									
										
										
										
											2015-03-17 15:53:05 -04:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return next(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-02-08 21:06:38 -05:00
										 |  |  | 			res.render('reset_code', { | 
					
						
							|  |  |  | 				valid: valid, | 
					
						
							| 
									
										
										
										
											2015-04-01 17:26:22 -04:00
										 |  |  | 				displayExpiryNotice: req.session.passwordExpired, | 
					
						
							| 
									
										
										
										
											2015-03-17 15:53:05 -04:00
										 |  |  | 				code: req.params.code ? req.params.code : null, | 
					
						
							| 
									
										
										
										
											2016-02-10 12:53:39 +02:00
										 |  |  | 				minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10), | 
					
						
							| 
									
										
										
										
											2015-08-26 15:54:54 -04:00
										 |  |  | 				breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]', url: '/reset'}, {text: '[[reset_password:update_password]]'}]), | 
					
						
							|  |  |  | 				title: '[[pages:reset]]' | 
					
						
							| 
									
										
										
										
											2015-02-08 21:06:38 -05:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-04-01 17:26:22 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			delete req.session.passwordExpired; | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		res.render('reset', { | 
					
						
							| 
									
										
										
										
											2015-03-17 15:53:05 -04:00
										 |  |  | 			code: req.params.code ? req.params.code : null, | 
					
						
							| 
									
										
										
										
											2015-08-26 15:54:54 -04:00
										 |  |  | 			breadcrumbs: helpers.buildBreadcrumbs([{text: '[[reset_password:reset_password]]'}]), | 
					
						
							|  |  |  | 			title: '[[pages:reset]]' | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-03 17:16:53 -05:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-27 14:56:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 17:04:41 -05:00
										 |  |  | Controllers.login = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 	var data = {}; | 
					
						
							|  |  |  | 	var loginStrategies = require('../routes/authentication').getLoginStrategies(); | 
					
						
							|  |  |  | 	var registrationType = meta.config.registrationType || 'normal'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var allowLoginWith = (meta.config.allowLoginWith || 'username-email'); | 
					
						
							| 
									
										
										
										
											2015-06-27 21:26:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	var errorText; | 
					
						
							|  |  |  | 	if (req.query.error === 'csrf-invalid') { | 
					
						
							|  |  |  | 		errorText = '[[error:csrf-invalid]]'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-12 16:15:44 -05:00
										 |  |  | 	data.alternate_logins = loginStrategies.length > 0; | 
					
						
							|  |  |  | 	data.authentication = loginStrategies; | 
					
						
							| 
									
										
										
										
											2015-04-22 12:13:14 -04:00
										 |  |  | 	data.allowLocalLogin = parseInt(meta.config.allowLocalLogin, 10) === 1 || parseInt(req.query.local, 10) === 1; | 
					
						
							| 
									
										
										
										
											2015-06-27 21:26:19 -04:00
										 |  |  | 	data.allowRegistration = registrationType === 'normal' || registrationType === 'admin-approval'; | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 	data.allowLoginWith = '[[login:' + allowLoginWith + ']]'; | 
					
						
							| 
									
										
										
										
											2015-01-29 01:06:48 -05:00
										 |  |  | 	data.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:login]]'}]); | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	data.error = req.flash('error')[0] || errorText; | 
					
						
							| 
									
										
										
										
											2015-08-26 15:54:54 -04:00
										 |  |  | 	data.title = '[[pages:login]]'; | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 11:58:14 -04:00
										 |  |  | 	if (!data.allowLocalLogin && !data.allowRegistration && data.alternate_logins && data.authentication.length === 1) { | 
					
						
							|  |  |  | 		return helpers.redirect(res, { | 
					
						
							|  |  |  | 			external: data.authentication[0].url | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-03 19:13:10 +03:00
										 |  |  | 	if (req.uid) { | 
					
						
							|  |  |  | 		user.getUserFields(req.uid, ['username', 'email'], function(err, user) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return next(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			data.username = allowLoginWith === 'email' ? user.email : user.username; | 
					
						
							|  |  |  | 			res.render('login', data); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		res.render('login', data); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-04-13 11:58:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 17:04:41 -05:00
										 |  |  | Controllers.register = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2015-06-27 21:26:19 -04:00
										 |  |  | 	var registrationType = meta.config.registrationType || 'normal'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (registrationType === 'disabled') { | 
					
						
							| 
									
										
										
										
											2015-08-28 14:31:35 -04:00
										 |  |  | 		return next(); | 
					
						
							| 
									
										
										
										
											2014-09-25 11:29:53 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-11 04:10:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 	var errorText; | 
					
						
							|  |  |  | 	if (req.query.error === 'csrf-invalid') { | 
					
						
							|  |  |  | 		errorText = '[[error:csrf-invalid]]'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 	async.waterfall([ | 
					
						
							|  |  |  | 		function(next) { | 
					
						
							| 
									
										
										
										
											2015-11-28 15:33:17 -07:00
										 |  |  | 			if (registrationType === 'invite-only' || registrationType === 'admin-invite-only') { | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 				user.verifyInvitation(req.query, next); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				next(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function(next) { | 
					
						
							| 
									
										
										
										
											2015-11-05 19:57:21 -05:00
										 |  |  | 			plugins.fireHook('filter:parse.post', {postData: {content: meta.config.termsOfUse || ''}}, next); | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 	], function(err, termsOfUse) { | 
					
						
							| 
									
										
										
										
											2015-06-28 21:54:21 -04:00
										 |  |  | 		if (err) { | 
					
						
							| 
									
										
										
										
											2014-11-08 14:51:05 -05:00
										 |  |  | 			return next(err); | 
					
						
							| 
									
										
										
										
											2014-05-15 03:06:47 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		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 = []; | 
					
						
							| 
									
										
										
										
											2016-05-09 11:40:42 -04:00
										 |  |  | 		data.error = req.flash('error')[0] || errorText; | 
					
						
							| 
									
										
										
										
											2016-04-30 10:47:28 +03:00
										 |  |  | 		data.title = '[[pages:register]]'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		res.render('register', data); | 
					
						
							| 
									
										
										
										
											2014-05-15 03:06:47 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 16:24:40 -04:00
										 |  |  | Controllers.compose = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 	plugins.fireHook('filter:composer.build', { | 
					
						
							|  |  |  | 		req: req, | 
					
						
							|  |  |  | 		res: res, | 
					
						
							|  |  |  | 		next: next, | 
					
						
							|  |  |  | 		templateData: {} | 
					
						
							|  |  |  | 	}, function(err, data) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							| 
									
										
										
										
											2015-07-03 17:21:14 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-06-10 15:56:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 		if (data.templateData.disabled) { | 
					
						
							| 
									
										
										
										
											2016-01-12 12:01:17 -05:00
										 |  |  | 			res.render('', { | 
					
						
							|  |  |  | 				title: '[[modules:composer.compose]]' | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-01-12 12:01:17 -05:00
										 |  |  | 			data.templateData.title = '[[modules:composer.compose]]'; | 
					
						
							| 
									
										
										
										
											2016-01-11 15:11:42 -05:00
										 |  |  | 			res.render('compose', data.templateData); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-05-21 16:24:40 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-27 16:52:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 17:04:41 -05:00
										 |  |  | Controllers.confirmEmail = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2015-02-25 14:10:00 -05:00
										 |  |  | 	user.email.confirm(req.params.code, function (err) { | 
					
						
							|  |  |  | 		res.render('confirm', { | 
					
						
							| 
									
										
										
										
											2016-02-25 23:04:19 -05:00
										 |  |  | 			error: err ? err.message : '', | 
					
						
							|  |  |  | 			title: '[[pages:confirm]]', | 
					
						
							| 
									
										
										
										
											2015-02-25 14:10:00 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-02-27 17:04:41 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-27 15:06:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-27 05:25:14 -04:00
										 |  |  | Controllers.sitemap = {}; | 
					
						
							|  |  |  | Controllers.sitemap.render = function(req, res, next) { | 
					
						
							|  |  |  | 	sitemap.render(function(err, tplData) { | 
					
						
							|  |  |  | 		Controllers.render('sitemap', tplData, function(err, xml) { | 
					
						
							|  |  |  | 			res.header('Content-Type', 'application/xml'); | 
					
						
							|  |  |  | 			res.send(xml); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-10-27 05:25:14 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Controllers.sitemap.getPages = function(req, res, next) { | 
					
						
							|  |  |  | 	if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) { | 
					
						
							|  |  |  | 		return next(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sitemap.getPages(function(err, xml) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		res.header('Content-Type', 'application/xml'); | 
					
						
							|  |  |  | 		res.send(xml); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Controllers.sitemap.getCategories = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2014-12-01 20:28:36 -05:00
										 |  |  | 	if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) { | 
					
						
							| 
									
										
										
										
											2015-08-28 14:31:35 -04:00
										 |  |  | 		return next(); | 
					
						
							| 
									
										
										
										
											2014-07-17 01:38:20 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-27 05:25:14 -04:00
										 |  |  | 	sitemap.getCategories(function(err, xml) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		res.header('Content-Type', 'application/xml'); | 
					
						
							|  |  |  | 		res.send(xml); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Controllers.sitemap.getTopicPage = function(req, res, next) { | 
					
						
							|  |  |  | 	if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) { | 
					
						
							|  |  |  | 		return next(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sitemap.getTopicPage(parseInt(req.params[0], 10), function(err, xml) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return next(err); | 
					
						
							|  |  |  | 		} else if (!xml) { | 
					
						
							|  |  |  | 			return next(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-27 17:16:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		res.header('Content-Type', 'application/xml'); | 
					
						
							|  |  |  | 		res.send(xml); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Controllers.robots = function (req, res) { | 
					
						
							|  |  |  | 	res.set('Content-Type', 'text/plain'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (meta.config["robots.txt"]) { | 
					
						
							|  |  |  | 		res.send(meta.config["robots.txt"]); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		res.send("User-agent: *\n" + | 
					
						
							| 
									
										
										
										
											2014-03-11 19:44:48 -04:00
										 |  |  | 			"Disallow: " + nconf.get('relative_path') + "/admin/\n" + | 
					
						
							| 
									
										
										
										
											2014-02-27 17:16:06 -05:00
										 |  |  | 			"Sitemap: " + nconf.get('url') + "/sitemap.xml"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | Controllers.manifest = function(req, res) { | 
					
						
							|  |  |  | 	var manifest = { | 
					
						
							|  |  |  | 			name: meta.config.title || 'NodeBB', | 
					
						
							|  |  |  | 			start_url: nconf.get('relative_path') + '/', | 
					
						
							|  |  |  | 			display: 'standalone', | 
					
						
							|  |  |  | 			orientation: 'portrait', | 
					
						
							|  |  |  | 			icons: [] | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (meta.config['brand:touchIcon']) { | 
					
						
							|  |  |  | 		manifest.icons.push({ | 
					
						
							|  |  |  | 			src: nconf.get('relative_path') + '/uploads/system/touchicon-36.png', | 
					
						
							|  |  |  | 			sizes: '36x36', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							|  |  |  | 			density: 0.75 | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			src: nconf.get('relative_path') + '/uploads/system/touchicon-48.png', | 
					
						
							|  |  |  | 			sizes: '48x48', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							|  |  |  | 			density: 1.0 | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			src: nconf.get('relative_path') + '/uploads/system/touchicon-72.png', | 
					
						
							|  |  |  | 			sizes: '72x72', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							|  |  |  | 			density: 1.5 | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			src: nconf.get('relative_path') + '/uploads/system/touchicon-96.png', | 
					
						
							|  |  |  | 			sizes: '96x96', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							|  |  |  | 			density: 2.0 | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			src: nconf.get('relative_path') + '/uploads/system/touchicon-144.png', | 
					
						
							|  |  |  | 			sizes: '144x144', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							|  |  |  | 			density: 3.0 | 
					
						
							|  |  |  | 		}, { | 
					
						
							|  |  |  | 			src: nconf.get('relative_path') + '/uploads/system/touchicon-192.png', | 
					
						
							|  |  |  | 			sizes: '192x192', | 
					
						
							|  |  |  | 			type: 'image/png', | 
					
						
							|  |  |  | 			density: 4.0 | 
					
						
							| 
									
										
										
										
											2016-01-06 12:49:14 +02:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-09-24 12:04:24 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res.status(200).json(manifest); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 14:04:21 -05:00
										 |  |  | Controllers.outgoing = function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2016-04-25 21:53:56 +03:00
										 |  |  | 	var url = req.query.url; | 
					
						
							|  |  |  | 	var data = { | 
					
						
							|  |  |  | 		url: validator.escape(String(url)), | 
					
						
							|  |  |  | 		title: meta.config.title, | 
					
						
							|  |  |  | 		breadcrumbs: helpers.buildBreadcrumbs([{text: '[[notifications:outgoing_link]]'}]) | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-02-28 14:04:21 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (url) { | 
					
						
							| 
									
										
										
										
											2014-03-09 20:05:14 -04:00
										 |  |  | 		res.render('outgoing', data); | 
					
						
							| 
									
										
										
										
											2014-02-28 14:04:21 -05:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-11-16 00:01:20 -05:00
										 |  |  | 		res.status(404).redirect(nconf.get('relative_path') + '/404'); | 
					
						
							| 
									
										
										
										
											2014-02-28 14:04:21 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 12:17:24 -05:00
										 |  |  | Controllers.termsOfUse = function(req, res, next) { | 
					
						
							|  |  |  | 	if (!meta.config.termsOfUse) { | 
					
						
							| 
									
										
										
										
											2015-08-28 14:31:35 -04:00
										 |  |  | 		return next(); | 
					
						
							| 
									
										
										
										
											2014-11-14 12:17:24 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	res.render('tos', {termsOfUse: meta.config.termsOfUse}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | module.exports = Controllers; |