| 
									
										
										
										
											2014-03-01 16:59:04 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 |  |  | var db = require('./database'), | 
					
						
							|  |  |  | 	posts = require('./posts'), | 
					
						
							|  |  |  | 	utils = require('./../public/src/utils'), | 
					
						
							|  |  |  | 	user = require('./user'), | 
					
						
							| 
									
										
										
										
											2014-02-07 11:21:23 -05:00
										 |  |  | 	Groups = require('./groups'), | 
					
						
							| 
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 |  |  | 	topics = require('./topics'), | 
					
						
							| 
									
										
										
										
											2013-10-15 15:01:12 -04:00
										 |  |  | 	plugins = require('./plugins'), | 
					
						
							| 
									
										
										
										
											2014-01-25 01:34:56 -05:00
										 |  |  | 	meta = require('./meta'), | 
					
						
							| 
									
										
										
										
											2014-03-25 12:23:55 -04:00
										 |  |  | 	validator = require('validator'), | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 	privileges = require('./privileges'), | 
					
						
							| 
									
										
										
										
											2014-01-08 21:50:19 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	async = require('async'), | 
					
						
							| 
									
										
										
										
											2013-09-17 15:38:50 -04:00
										 |  |  | 	winston = require('winston'), | 
					
						
							|  |  |  | 	nconf = require('nconf'); | 
					
						
							| 
									
										
										
										
											2013-05-09 01:04:15 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(Categories) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 17:48:48 -04:00
										 |  |  | 	require('./categories/delete')(Categories); | 
					
						
							| 
									
										
										
										
											2014-03-12 21:41:53 -04:00
										 |  |  | 	require('./categories/activeusers')(Categories); | 
					
						
							|  |  |  | 	require('./categories/recentreplies')(Categories); | 
					
						
							| 
									
										
										
										
											2014-04-01 17:12:03 -04:00
										 |  |  | 	require('./categories/update')(Categories); | 
					
						
							| 
									
										
										
										
											2014-03-12 21:41:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 	Categories.create = function(data, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-02 21:20:55 -05:00
										 |  |  | 		db.incrObjectField('global', 'nextCid', function(err, cid) { | 
					
						
							| 
									
										
										
										
											2013-09-17 15:54:08 -04:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2013-09-17 15:54:08 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var slug = cid + '/' + utils.slugify(data.name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var category = { | 
					
						
							|  |  |  | 				cid: cid, | 
					
						
							|  |  |  | 				name: data.name, | 
					
						
							|  |  |  | 				description: data.description, | 
					
						
							|  |  |  | 				icon: data.icon, | 
					
						
							| 
									
										
										
										
											2013-12-08 14:20:57 -05:00
										 |  |  | 				bgColor: data.bgColor, | 
					
						
							| 
									
										
										
										
											2013-11-26 15:14:12 -05:00
										 |  |  | 				color: data.color, | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 				slug: slug, | 
					
						
							| 
									
										
										
										
											2014-09-19 18:42:26 -04:00
										 |  |  | 				parentCid: 0, | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 				topic_count: 0, | 
					
						
							| 
									
										
										
										
											2014-06-17 13:11:09 -04:00
										 |  |  | 				post_count: 0, | 
					
						
							| 
									
										
										
										
											2013-10-07 17:48:11 -04:00
										 |  |  | 				disabled: 0, | 
					
						
							| 
									
										
										
										
											2014-01-09 11:50:24 -05:00
										 |  |  | 				order: data.order, | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 				link: '', | 
					
						
							| 
									
										
										
										
											2014-09-19 20:14:20 -04:00
										 |  |  | 				numRecentReplies: 1, | 
					
						
							| 
									
										
										
										
											2014-01-22 11:46:50 -05:00
										 |  |  | 				class: 'col-md-3 col-xs-6', | 
					
						
							| 
									
										
										
										
											2014-03-13 18:11:37 -04:00
										 |  |  | 				imageClass: 'auto' | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 13:22:42 -04:00
										 |  |  | 			async.series([ | 
					
						
							|  |  |  | 				async.apply(db.setObject, 'category:' + cid, category), | 
					
						
							|  |  |  | 				async.apply(db.sortedSetAdd, 'categories:cid', data.order, cid) | 
					
						
							|  |  |  | 			], function(err) { | 
					
						
							|  |  |  | 				if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				callback(null, category); | 
					
						
							| 
									
										
										
										
											2013-10-15 15:20:12 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-09-11 16:04:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-15 20:49:47 -04:00
										 |  |  | 	Categories.exists = function(cid, callback) { | 
					
						
							|  |  |  | 		db.isSortedSetMember('categories:cid', cid, callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 	Categories.getCategoryById = function(data, callback) { | 
					
						
							|  |  |  | 		Categories.getCategories([data.cid], data.uid, function(err, categories) { | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 			if (err || !Array.isArray(categories) || !categories[0]) { | 
					
						
							| 
									
										
										
										
											2014-04-09 21:56:30 -04:00
										 |  |  | 				return callback(err || new Error('[[error:invalid-cid]]')); | 
					
						
							| 
									
										
										
										
											2014-02-26 16:43:21 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 			var category = categories[0]; | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 			if (parseInt(data.uid, 10)) { | 
					
						
							|  |  |  | 				Categories.markAsRead([data.cid], data.uid); | 
					
						
							| 
									
										
										
										
											2014-02-07 20:30:10 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-07-19 16:13:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 			async.parallel({ | 
					
						
							|  |  |  | 				topics: function(next) { | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 					Categories.getCategoryTopics({ | 
					
						
							|  |  |  | 						cid: data.cid, | 
					
						
							|  |  |  | 						start: data.start, | 
					
						
							|  |  |  | 						stop: data.end, | 
					
						
							|  |  |  | 						uid: data.uid, | 
					
						
							|  |  |  | 						targetUid: data.targetUid | 
					
						
							|  |  |  | 					}, next); | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				pageCount: function(next) { | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 					Categories.getPageCount(data.cid, data.uid, next); | 
					
						
							| 
									
										
										
										
											2014-08-29 15:57:20 -04:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				isIgnored: function(next) { | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 					Categories.isIgnored([data.cid], data.uid, next); | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}, function(err, results) { | 
					
						
							|  |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				category.topics = results.topics.topics; | 
					
						
							|  |  |  | 				category.nextStart = results.topics.nextStart; | 
					
						
							|  |  |  | 				category.pageCount = results.pageCount; | 
					
						
							| 
									
										
										
										
											2014-08-29 15:57:20 -04:00
										 |  |  | 				category.isIgnored = results.isIgnored[0]; | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 				category.topic_row_size = 'col-md-9'; | 
					
						
							| 
									
										
										
										
											2013-05-24 07:52:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-08 14:21:53 -05:00
										 |  |  | 				plugins.fireHook('filter:category.get', {category: category, uid: data.uid}, function(err, data) { | 
					
						
							|  |  |  | 					callback(err, data ? data.category : null); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-03-12 20:53:42 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-05-23 16:53:19 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-23 16:53:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 	Categories.getCategoryTopics = function(data, callback) { | 
					
						
							| 
									
										
										
										
											2014-02-27 23:45:12 -05:00
										 |  |  | 		var tids; | 
					
						
							| 
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function(next) { | 
					
						
							| 
									
										
										
										
											2014-11-07 17:15:01 -05:00
										 |  |  | 				Categories.getTopicIds(data.targetUid ? 'cid:' + data.cid + ':uid:' + data.targetUid + ':tids' : 'cid:' + data.cid + ':tids', data.start, data.stop, next); | 
					
						
							| 
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2014-02-27 23:45:12 -05:00
										 |  |  | 			function(topicIds, next) { | 
					
						
							|  |  |  | 				tids = topicIds; | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 				topics.getTopicsByTids(tids, data.uid, next); | 
					
						
							| 
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			function(topics, next) { | 
					
						
							| 
									
										
										
										
											2014-10-02 17:46:39 -04:00
										 |  |  | 				if (!Array.isArray(topics) || !topics.length) { | 
					
						
							| 
									
										
										
										
											2014-02-26 17:34:02 -05:00
										 |  |  | 					return next(null, { | 
					
						
							|  |  |  | 						topics: [], | 
					
						
							|  |  |  | 						nextStart: 1 | 
					
						
							| 
									
										
										
										
											2014-01-27 09:09:55 -05:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2014-02-26 17:34:02 -05:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-01 17:36:29 -05:00
										 |  |  | 				var indices = {}, | 
					
						
							|  |  |  | 					i = 0; | 
					
						
							|  |  |  | 				for(i=0; i<tids.length; ++i) { | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 					indices[tids[i]] = data.start + i; | 
					
						
							| 
									
										
										
										
											2014-02-27 23:45:12 -05:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-01 17:36:29 -05:00
										 |  |  | 				for(i=0; i<topics.length; ++i) { | 
					
						
							| 
									
										
										
										
											2014-02-27 23:45:12 -05:00
										 |  |  | 					topics[i].index = indices[topics[i].tid]; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-02 17:46:39 -04:00
										 |  |  | 				next(null, { | 
					
						
							|  |  |  | 					topics: topics, | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 					nextStart: data.stop + 1 | 
					
						
							| 
									
										
										
										
											2014-02-26 17:34:02 -05:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-01-17 12:49:21 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-01-26 17:17:34 -05:00
										 |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-08-09 20:03:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-29 15:57:20 -04:00
										 |  |  | 	Categories.isIgnored = function(cids, uid, callback) { | 
					
						
							|  |  |  | 		user.getIgnoredCategories(uid, function(err, ignoredCids) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			cids = cids.map(function(cid) { | 
					
						
							|  |  |  | 				return ignoredCids.indexOf(cid.toString()) !== -1; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			callback(null, cids); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-06 18:14:07 -05:00
										 |  |  | 	Categories.getTopicIds = function(set, start, stop, callback) { | 
					
						
							|  |  |  | 		db.getSortedSetRevRange(set, start, stop, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-07-19 16:13:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 23:45:12 -05:00
										 |  |  | 	Categories.getTopicIndex = function(tid, callback) { | 
					
						
							|  |  |  | 		topics.getTopicField(tid, 'cid', function(err, cid) { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 17:15:01 -05:00
										 |  |  | 			db.sortedSetRevRank('cid:' + cid + ':tids', tid, callback); | 
					
						
							| 
									
										
										
										
											2014-02-27 23:45:12 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 14:15:54 -05:00
										 |  |  | 	Categories.getPageCount = function(cid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-10-14 23:36:59 -04:00
										 |  |  | 		Categories.getCategoryField(cid, 'topic_count', function(err, topicCount) { | 
					
						
							| 
									
										
										
										
											2014-10-14 23:12:47 -04:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-01-24 22:26:11 -05:00
										 |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 			if (parseInt(topicCount, 10) === 0) { | 
					
						
							|  |  |  | 				return callback(null, 1); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 14:15:54 -05:00
										 |  |  | 			user.getSettings(uid, function(err, settings) { | 
					
						
							| 
									
										
										
										
											2014-10-14 23:12:47 -04:00
										 |  |  | 				if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-10 14:15:54 -05:00
										 |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-01-24 22:26:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 14:15:54 -05:00
										 |  |  | 				callback(null, Math.ceil(parseInt(topicCount, 10) / settings.topicsPerPage)); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-01-24 22:26:11 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-01-04 01:15:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 	Categories.getAllCategories = function(uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 		db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) { | 
					
						
							| 
									
										
										
										
											2014-03-01 16:59:04 -05:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2013-11-26 19:09:32 -05:00
										 |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-19 15:33:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 			if (!Array.isArray(cids) || !cids.length) { | 
					
						
							| 
									
										
										
										
											2014-05-31 22:24:17 -04:00
										 |  |  | 				return callback(null, []); | 
					
						
							| 
									
										
										
										
											2013-11-26 19:09:32 -05:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-11-27 15:02:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 			Categories.getCategories(cids, uid, callback); | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-15 15:45:01 -04:00
										 |  |  | 	Categories.getCategoriesByPrivilege = function(uid, privilege, callback) { | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 		db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!Array.isArray(cids) || !cids.length) { | 
					
						
							| 
									
										
										
										
											2014-05-31 22:24:17 -04:00
										 |  |  | 				return callback(null, []); | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-09 15:19:57 -04:00
										 |  |  | 			privileges.categories.filterCids(privilege, cids, uid, function(err, cids) { | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 				if (err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				Categories.getCategories(cids, uid, function(err, categories) { | 
					
						
							|  |  |  | 					if (err) { | 
					
						
							|  |  |  | 						return callback(err); | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					categories = categories.filter(function(category) { | 
					
						
							|  |  |  | 						return !category.disabled; | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					callback(null, categories); | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-05-09 01:04:15 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-09 01:04:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-16 12:49:39 -04:00
										 |  |  | 	Categories.getModerators = function(cid, callback) { | 
					
						
							| 
									
										
										
										
											2014-03-20 09:12:49 -04:00
										 |  |  | 		Groups.get('cid:' + cid + ':privileges:mods', {}, function(err, groupObj) { | 
					
						
							| 
									
										
										
										
											2014-09-21 18:56:36 -04:00
										 |  |  | 			if (err && err === 'group-not-found') { | 
					
						
							|  |  |  | 				return callback(null, []); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2013-07-19 16:13:00 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (!Array.isArray(groupObj) || !groupObj.members.length) { | 
					
						
							|  |  |  | 				return callback(null, []); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			user.getMultipleUserFields(groupObj.members, ['uid', 'username', 'userslug', 'picture'], callback); | 
					
						
							| 
									
										
										
										
											2013-05-16 12:49:39 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-06-28 12:40:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-10 21:44:19 -04:00
										 |  |  | 	Categories.markAsRead = function(cids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-10-14 13:29:23 -04:00
										 |  |  | 		callback = callback || function() {}; | 
					
						
							| 
									
										
										
										
											2014-09-10 21:44:19 -04:00
										 |  |  | 		if (!Array.isArray(cids) || !cids.length) { | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		var keys = cids.map(function(cid) { | 
					
						
							|  |  |  | 			return 'cid:' + cid + ':read_by_uid'; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-10-14 13:29:23 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		db.isMemberOfSets(keys, uid, function(err, hasRead) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			keys = keys.filter(function(key, index) { | 
					
						
							|  |  |  | 				return !hasRead[index]; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!keys.length) { | 
					
						
							|  |  |  | 				return callback(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			db.setsAdd(keys, uid, callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-24 11:18:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 15:46:39 -05:00
										 |  |  | 	Categories.markAsUnreadForAll = function(cid, callback) { | 
					
						
							| 
									
										
										
										
											2014-08-05 22:52:33 -04:00
										 |  |  | 		callback = callback || function() {}; | 
					
						
							| 
									
										
										
										
											2014-08-05 23:10:45 -04:00
										 |  |  | 		db.delete('cid:' + cid + ':read_by_uid', function(err) { | 
					
						
							|  |  |  | 			callback(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-01-23 15:46:39 -05:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-21 18:12:39 -04:00
										 |  |  | 	Categories.hasReadCategories = function(cids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-04 15:13:43 -05:00
										 |  |  | 		var sets = []; | 
					
						
							| 
									
										
										
										
											2013-05-21 18:12:39 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 13:09:37 -04:00
										 |  |  | 		for (var i = 0, ii = cids.length; i < ii; i++) { | 
					
						
							| 
									
										
										
										
											2013-12-04 15:13:43 -05:00
										 |  |  | 			sets.push('cid:' + cids[i] + ':read_by_uid'); | 
					
						
							| 
									
										
										
										
											2013-05-21 18:12:39 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 		db.isMemberOfSets(sets, uid, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-21 18:12:39 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 12:59:45 -04:00
										 |  |  | 	Categories.hasReadCategory = function(cid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-03-11 14:43:08 -04:00
										 |  |  | 		db.isSetMember('cid:' + cid + ':read_by_uid', uid, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-07-03 12:59:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 	Categories.getCategoryData = function(cid, callback) { | 
					
						
							|  |  |  | 		Categories.getCategoriesData([cid], function(err, categories) { | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 			callback(err, categories ? categories[0] : null); | 
					
						
							| 
									
										
										
										
											2013-07-22 20:29:51 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 	Categories.getCategoriesData = function(cids, callback) { | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 		var keys = cids.map(function(cid) { | 
					
						
							| 
									
										
										
										
											2014-05-19 19:24:06 -04:00
										 |  |  | 			return 'category:' + cid; | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		db.getObjects(keys, function(err, categories) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-02 21:55:05 -04:00
										 |  |  | 			if (!Array.isArray(categories) || !categories.length) { | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 				return callback(null, []); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 18:04:45 -04:00
										 |  |  | 			async.map(categories, modifyCategory, callback); | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-03-10 00:17:06 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 18:04:45 -04:00
										 |  |  | 	function modifyCategory(category, callback) { | 
					
						
							|  |  |  | 		if (!category || !parseInt(category.cid, 10)) { | 
					
						
							|  |  |  | 			return callback(null, null); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		category.name = validator.escape(category.name); | 
					
						
							|  |  |  | 		category.disabled = parseInt(category.disabled, 10) === 1; | 
					
						
							|  |  |  | 		category.icon = category.icon || 'hidden'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (category.description) { | 
					
						
							|  |  |  | 			category.description = validator.escape(category.description); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (category.image) { | 
					
						
							|  |  |  | 			category.backgroundImage = category.image ? nconf.get('relative_path') + category.image : ''; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		callback(null, category); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-11 16:12:20 -04:00
										 |  |  | 	Categories.getCategoryField = function(cid, field, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-02 21:20:55 -05:00
										 |  |  | 		db.getObjectField('category:' + cid, field, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-08-11 16:12:20 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-06 21:30:06 -04:00
										 |  |  | 	Categories.getMultipleCategoryFields = function(cids, fields, callback) { | 
					
						
							|  |  |  | 		var keys = cids.map(function(cid) { | 
					
						
							|  |  |  | 			return 'category:' + cid; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-10-30 18:04:45 -04:00
										 |  |  | 		db.getObjectsFields(keys, fields, function(err, categories) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			async.map(categories, modifyCategory, callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-08-06 21:30:06 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-22 16:47:41 -04:00
										 |  |  | 	Categories.getCategoryFields = function(cid, fields, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-02 21:20:55 -05:00
										 |  |  | 		db.getObjectFields('category:' + cid, fields, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-27 15:02:09 -05:00
										 |  |  | 	Categories.setCategoryField = function(cid, field, value, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-02 21:20:55 -05:00
										 |  |  | 		db.setObjectField('category:' + cid, field, value, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-07-04 13:29:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-27 15:02:09 -05:00
										 |  |  | 	Categories.incrementCategoryFieldBy = function(cid, field, value, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-02 21:20:55 -05:00
										 |  |  | 		db.incrObjectFieldBy('category:' + cid, field, value, callback); | 
					
						
							| 
									
										
										
										
											2013-09-12 14:07:24 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-07-03 12:59:45 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-26 14:25:46 -05:00
										 |  |  | 	Categories.getCategories = function(cids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 		if (!Array.isArray(cids)) { | 
					
						
							| 
									
										
										
										
											2014-04-09 21:56:30 -04:00
										 |  |  | 			return callback(new Error('[[error:invalid-cid]]')); | 
					
						
							| 
									
										
										
										
											2013-07-22 16:57:18 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 		if (!cids.length) { | 
					
						
							|  |  |  | 			 return callback(null, []); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 		async.parallel({ | 
					
						
							|  |  |  | 			categories: function(next) { | 
					
						
							|  |  |  | 				Categories.getCategoriesData(cids, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 			children: function(next) { | 
					
						
							|  |  |  | 				Categories.getChildren(cids, uid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			parents: function(next) { | 
					
						
							|  |  |  | 				Categories.getParents(cids, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 			hasRead: function(next) { | 
					
						
							|  |  |  | 				Categories.hasReadCategories(cids, uid, next); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}, function(err, results) { | 
					
						
							| 
									
										
										
										
											2013-09-17 13:09:37 -04:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-02-22 18:56:37 -05:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2013-07-22 16:57:18 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 			var categories = results.categories; | 
					
						
							|  |  |  | 			var hasRead = results.hasRead; | 
					
						
							|  |  |  | 			uid = parseInt(uid, 10); | 
					
						
							|  |  |  | 			for(var i=0; i<results.categories.length; ++i) { | 
					
						
							| 
									
										
										
										
											2014-09-01 18:46:42 -04:00
										 |  |  | 				if (categories[i]) { | 
					
						
							|  |  |  | 					categories[i]['unread-class'] = (parseInt(categories[i].topic_count, 10) === 0 || (hasRead[i] && uid !== 0)) ? '' : 'unread'; | 
					
						
							|  |  |  | 					categories[i].children = results.children[i]; | 
					
						
							| 
									
										
										
										
											2014-09-15 10:47:25 -04:00
										 |  |  | 					categories[i].parent = results.parents[i] && !results.parents[i].disabled ? results.parents[i] : null; | 
					
						
							| 
									
										
										
										
											2014-09-01 18:46:42 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-03-09 23:09:08 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-10-07 17:48:11 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-27 12:44:28 -04:00
										 |  |  | 			callback(null, categories); | 
					
						
							| 
									
										
										
										
											2013-07-22 16:57:18 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-08-20 12:11:17 -04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-07-22 16:57:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 	Categories.getParents = function(cids, callback) { | 
					
						
							|  |  |  | 		var keys = cids.map(function(cid) { | 
					
						
							|  |  |  | 			return 'category:' + cid; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		db.getObjectsFields(keys, ['parentCid'], function(err, data) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var parentCids = data.map(function(category) { | 
					
						
							|  |  |  | 				return category && category.parentCid; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Categories.getCategoriesData(parentCids, callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Categories.getChildren = function(cids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-08-21 09:52:21 -04:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			async.apply(db.getSortedSetRange, 'categories:cid', 0, -1), | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 			function(cids, next) { | 
					
						
							| 
									
										
										
										
											2014-09-09 15:19:57 -04:00
										 |  |  | 				privileges.categories.filterCids('find', cids, uid, next); | 
					
						
							| 
									
										
										
										
											2014-08-21 09:52:21 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			function (cids, next) { | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 				Categories.getCategoriesData(cids, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (categories, next) { | 
					
						
							| 
									
										
										
										
											2014-09-14 21:25:01 -04:00
										 |  |  | 				// Filter categories to isolate children, and remove disabled categories
 | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 				async.map(cids, function(cid, next) { | 
					
						
							|  |  |  | 					next(null, categories.filter(function(category) { | 
					
						
							| 
									
										
										
										
											2014-09-14 21:25:01 -04:00
										 |  |  | 						return parseInt(category.parentCid, 10) === parseInt(cid, 10) && !category.disabled; | 
					
						
							| 
									
										
										
										
											2014-08-22 19:10:26 -04:00
										 |  |  | 					})); | 
					
						
							|  |  |  | 				}, next); | 
					
						
							| 
									
										
										
										
											2014-08-21 09:52:21 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		], callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 	Categories.onNewPostMade = function(postData, callback) { | 
					
						
							| 
									
										
										
										
											2014-03-17 17:27:42 -04:00
										 |  |  | 		topics.getTopicFields(postData.tid, ['cid', 'pinned'], function(err, topicData) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2014-09-05 13:44:58 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 18:40:48 -04:00
										 |  |  | 			if (!topicData || !topicData.cid) { | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 				return callback(); | 
					
						
							| 
									
										
										
										
											2014-03-17 17:27:42 -04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-29 23:33:28 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var cid = topicData.cid; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 			async.parallel([ | 
					
						
							|  |  |  | 				function(next) { | 
					
						
							| 
									
										
										
										
											2014-11-07 17:15:01 -05:00
										 |  |  | 					db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, postData.pid, next); | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				function(next) { | 
					
						
							|  |  |  | 					db.incrObjectField('category:' + cid, 'post_count', next); | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				function(next) { | 
					
						
							| 
									
										
										
										
											2014-10-10 22:53:01 -04:00
										 |  |  | 					if (parseInt(topicData.pinned, 10) === 1) { | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 						next(); | 
					
						
							| 
									
										
										
										
											2014-10-10 22:53:01 -04:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2014-11-07 17:15:01 -05:00
										 |  |  | 						db.sortedSetAdd('cid:' + cid + ':tids', postData.timestamp, postData.tid, next); | 
					
						
							| 
									
										
										
										
											2014-09-19 15:54:13 -04:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			], callback); | 
					
						
							| 
									
										
										
										
											2013-12-29 23:33:28 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-02-26 15:32:32 -05:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-12-29 23:33:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-17 17:27:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | }(exports)); |