| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var async = require('async'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var db = require('../../database'); | 
					
						
							|  |  |  | var categories = require('../../categories'); | 
					
						
							|  |  |  | var privileges = require('../../privileges'); | 
					
						
							|  |  |  | var plugins = require('../../plugins'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var homePageController = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | homePageController.get = function (req, res, next) { | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 	async.waterfall([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (next) { | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			db.getSortedSetRange('categories:cid', 0, -1, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (cids, next) { | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			privileges.categories.filterCids('find', cids, 0, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (cids, next) { | 
					
						
							| 
									
										
										
										
											2015-09-25 17:38:58 -04:00
										 |  |  | 			categories.getCategoriesFields(cids, ['name', 'slug'], next); | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		function (categoryData, next) { | 
					
						
							|  |  |  | 			categoryData = categoryData.map(function (category) { | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					route: 'category/' + category.slug, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					name: 'Category: ' + category.name, | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			next(null, categoryData); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	], function (err, categoryData) { | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 		if (err || !categoryData) { | 
					
						
							|  |  |  | 			categoryData = []; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		plugins.fireHook('filter:homepage.get', { routes: [ | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				route: 'categories', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				name: 'Categories', | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				route: 'recent', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				name: 'Recent', | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				route: 'popular', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				name: 'Popular', | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		].concat(categoryData) }, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return next(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			data.routes.push({ | 
					
						
							|  |  |  | 				route: '', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				name: 'Custom', | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			res.render('admin/general/homepage', data); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 02:30:48 -07:00
										 |  |  | module.exports = homePageController; |