| 
									
										
										
										
											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'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-22 19:03:49 -04:00
										 |  |  | var homePageController = module.exports; | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 				}; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-08-16 19:46:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-22 19:03:49 -04:00
										 |  |  | 			plugins.fireHook('filter:homepage.get', { routes: [ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					route: 'categories', | 
					
						
							|  |  |  | 					name: 'Categories', | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					route: 'recent', | 
					
						
							|  |  |  | 					name: 'Recent', | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2017-12-08 19:58:12 -05:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					route: 'top', | 
					
						
							|  |  |  | 					name: 'Top', | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2017-06-22 19:03:49 -04:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					route: 'popular', | 
					
						
							|  |  |  | 					name: 'Popular', | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			].concat(categoryData) }, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function (data) { | 
					
						
							| 
									
										
										
										
											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-06-22 19:03:49 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	], next); | 
					
						
							| 
									
										
										
										
											2015-09-17 16:25:15 -04:00
										 |  |  | }; |