2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								var  path  =  require ( 'path' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									fs  =  require ( 'fs' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									nconf  =  require ( 'nconf' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									express  =  require ( 'express' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									express _namespace  =  require ( 'express-namespace' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-22 15:17:41 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									WebServer  =  express ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									server , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-30 16:28:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									winston  =  require ( 'winston' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-04 01:46:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									validator  =  require ( 'validator' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-14 16:41:34 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									async  =  require ( 'async' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									S  =  require ( 'string' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 19:19:25 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									qs  =  require ( 'querystring' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									pkg  =  require ( '../package.json' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									utils  =  require ( '../public/src/utils' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									db  =  require ( './database' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									user  =  require ( './user' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									categories  =  require ( './categories' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-08 15:09:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									CategoryTools  =  require ( './categoryTools' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									posts  =  require ( './posts' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									topics  =  require ( './topics' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 21:42:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ThreadTools  =  require ( './threadTools' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									notifications  =  require ( './notifications' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									admin  =  require ( './routes/admin' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									userRoute  =  require ( './routes/user' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									apiRoute  =  require ( './routes/api' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 23:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									feedsRoute  =  require ( './routes/feeds' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									auth  =  require ( './routes/authentication' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									meta  =  require ( './meta' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									plugins  =  require ( './plugins' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 16:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									logger  =  require ( './logger' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									templates  =  require ( './../public/src/templates' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									translator  =  require ( './../public/src/translator' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-02 15:57:43 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								if ( nconf . get ( 'ssl' ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									server  =  require ( 'https' ) . createServer ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										key :  fs . readFileSync ( nconf . get ( 'ssl' ) . key ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:09:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										cert :  fs . readFileSync ( nconf . get ( 'ssl' ) . cert ) 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} ,  WebServer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									server  =  require ( 'http' ) . createServer ( WebServer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 16:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								module . exports . server  =  server ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:05:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								( function  ( app )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									"use strict" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 16:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									var 	clientScripts ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-25 16:28:07 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-25 12:35:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									plugins . ready ( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										// Minify client-side libraries
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										meta . js . get ( function  ( err ,  scripts )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											clientScripts  =  scripts . map ( function  ( script )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												script  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													script :  script 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  script ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-24 12:33:51 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 * 	` options `  object 	requires : 	req ,  res 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 20:28:31 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									 * 						accepts : 	metaTags ,  linkTags 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									 * / 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									app . build _header  =  function  ( options ,  callback )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 13:05:47 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										var  custom _header  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											'navigation' :  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 15:19:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 13:05:47 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										plugins . fireHook ( 'filter:header.build' ,  custom _header ,  function ( err ,  custom _header )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  defaultMetaTags  =  [ { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													name :  'viewport' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													content :  'width=device-width, initial-scale=1.0, user-scalable=no' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													name :  'content-type' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													content :  'text/html; charset=UTF-8' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													name :  'apple-mobile-web-app-capable' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													content :  'yes' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													property :  'og:site_name' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													content :  meta . config . title  ||  'NodeBB' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													property :  'keywords' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													content :  meta . config . keywords  ||  '' 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} ] , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 17:22:38 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												defaultLinkTags  =  [ / * { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 11:34:38 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													rel :  'apple-touch-icon' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													href :  meta . config [ 'brand:logo' ]  ||  nconf . get ( 'relative_path' )  +  '/logo.png' 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 17:22:38 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} * / ] , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 13:05:47 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												templateValues  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-18 16:13:01 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													bootswatchCSS :  meta . config [ 'theme:src' ] , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 09:20:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													pluginCSS :  plugins . cssFiles . map ( function ( file )  {  return  {  path :  nconf . get ( 'relative_path' )  +  file . replace ( /\\/g ,  '/' )  } ;  } ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:39:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													title :  meta . config . title  ||  '' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 17:27:23 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													description :  meta . config . description  ||  '' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:39:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													'brand:logo' :  meta . config [ 'brand:logo' ]  ||  '' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													'brand:logo:display' :  meta . config [ 'brand:logo' ] ? '' : 'hide' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 13:05:47 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													csrf :  options . res . locals . csrf _token , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													relative _path :  nconf . get ( 'relative_path' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													clientScripts :  clientScripts , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													navigation :  custom _header . navigation , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 15:58:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													'cache-buster' :  meta . config [ 'cache-buster' ]  ?  'v='  +  meta . config [ 'cache-buster' ]  :  '' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 21:03:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													allowRegistration :  meta . config . allowRegistration  ===  undefined  ||  parseInt ( meta . config . allowRegistration ,  10 )  ===  1 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 20:53:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												escapeList  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													'&' :  '&' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													'<' :  '<' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													'>' :  '>' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													"'" :  ''' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													'"' :  '"' 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 13:05:47 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-28 15:49:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											var  uid  =  '0' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 20:28:31 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											// Meta Tags
 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 09:20:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											templateValues . metaTags  =  defaultMetaTags . concat ( options . metaTags  ||  [ ] ) . map ( function ( tag )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 20:53:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												tag . content  =  tag . content . replace ( /[&<>'"]/g ,  function ( tag )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													return  escapeList [ tag ]  ||  tag ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 20:28:31 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												return  tag ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 09:20:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											// Link Tags
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											templateValues . linkTags  =  defaultLinkTags . concat ( options . linkTags  ||  [ ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											templateValues . linkTags . push ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												rel :  "icon" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												type :  "image/x-icon" , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-10 22:24:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												href :  nconf . get ( 'relative_path' )  +  '/favicon.ico' 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 09:20:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 20:28:31 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if ( options . req . user  &&  options . req . user . uid )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-28 15:49:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												uid  =  options . req . user . uid ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-28 15:49:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-31 13:17:28 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											// Custom CSS
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											templateValues . useCustomCSS  =  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( meta . config . useCustomCSS  ===  '1' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												templateValues . useCustomCSS  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												templateValues . customCSS  =  meta . config . customCSS ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-19 14:33:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											async . parallel ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													translator . get ( 'pages:'  +  path . basename ( options . req . url ) ,  function ( translated )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														var 	metaTitle  =  templateValues . metaTags . filter ( function ( tag )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																return  tag . name  ===  'title' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														if  ( translated )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															templateValues . browserTitle  =  translated ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														}  else  if  ( metaTitle . length  >  0  &&  metaTitle [ 0 ] . content )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															templateValues . browserTitle  =  metaTitle [ 0 ] . content ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															templateValues . browserTitle  =  meta . config . browserTitle  ||  'NodeBB' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user . isAdministrator ( uid ,  function ( err ,  isAdmin )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														templateValues . isAdmin  =  isAdmin  ||  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											] ,  function ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-28 15:49:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												translator . translate ( templates . header . parse ( templateValues ) ,  function ( template )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													callback ( null ,  template ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-24 14:14:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-06-20 16:04:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-22 16:51:32 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 17:37:17 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Cache static files on production
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( global . env  !==  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										app . enable ( 'cache' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 20:37:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . enable ( 'minification' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-10 22:20:11 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Configure cache-buster timestamp
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										require ( 'child_process' ) . exec ( 'git describe --tags' ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											cwd :  path . join ( _ _dirname ,  '../' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ,  function ( err ,  stdOut )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												meta . config [ 'cache-buster' ]  =  stdOut . trim ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 15:58:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// winston.info('[init] Cache buster value set to: ' + stdOut);
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-10 22:20:11 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 12:26:43 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												fs . stat ( path . join ( _ _dirname ,  '../package.json' ) ,  function ( err ,  stats )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													meta . config [ 'cache-buster' ]  =  new  Date ( stats . mtime ) . getTime ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-10 22:20:11 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-09 14:50:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-04-24 16:42:12 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									// Middlewares
 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									app . configure ( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										async . series ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// Pre-router middlewares
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( express . compress ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 00:25:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-04 01:46:50 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												logger . init ( app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-02 00:25:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-10 22:24:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												app . use ( express . favicon ( path . join ( _ _dirname ,  '../' ,  'public' ,  meta . config [ 'brand:favicon' ]  ?  meta . config [ 'brand:favicon' ]  :  'favicon.ico' ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												app . use ( require ( 'less-middleware' ) ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													src :  path . join ( _ _dirname ,  '../' ,  'public' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													prefix :  nconf . get ( 'relative_path' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 20:37:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													yuicompress :  app . enabled ( 'minification' )  ?  true  :  false 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( express . bodyParser ( ) ) ;  // Puts POST vars in request.body
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( express . cookieParser ( ) ) ;  // If you want to parse cookies (res.cookies)
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 22:33:55 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												app . use ( express . session ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													store :  db . sessionStore , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													secret :  nconf . get ( 'secret' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													key :  'express.sid' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													cookie :  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 21:06:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														maxAge :  1000  *  60  *  60  *  24  *  parseInt ( meta . configs . loginDays  ||  14 ,  10 ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												app . use ( express . csrf ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 10:34:56 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  ( nconf . get ( 'port' )  !=  80  &&  nconf . get ( 'port' )  !=  443  &&  nconf . get ( 'use_port' )  ===  false )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-23 20:35:53 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													winston . info ( 'Enabling \'trust proxy\'' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-20 13:23:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													app . enable ( 'trust proxy' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-29 12:42:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ( nconf . get ( 'port' )  ==  80  ||  nconf . get ( 'port' )  ==  443 )  &&  process . env . NODE _ENV  !==  'development' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-23 20:35:53 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													winston . info ( 'Using ports 80 and 443 is not recommend; use a proxy instead. See README.md' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-20 13:23:40 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// Local vars, other assorted setup
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( function  ( req ,  res ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													res . locals . csrf _token  =  req . session . _csrf ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-01 11:27:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-11 11:08:52 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													// Disable framing
 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-29 11:04:46 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													res . setHeader ( 'X-Frame-Options' ,  'SAMEORIGIN' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-01 11:27:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// Authentication Routes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												auth . initialize ( app ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											function ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												async . parallel ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													function ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														db . getObjectFields ( 'config' ,  [ 'theme:type' ,  'theme:id' ,  'theme:staticDir' ,  'theme:templates' ] ,  function ( err ,  themeData )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															var  themeId  =  ( themeData [ 'theme:id' ]  ||  'nodebb-theme-vanilla' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 17:41:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 12:07:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															// Detect if a theme has been selected, and handle appropriately
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															if  ( ! themeData [ 'theme:type' ]  ||  themeData [ 'theme:type' ]  ===  'local' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 12:07:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																// Local theme
 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	winston . info ( '[themes] Using theme '  +  themeId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 12:07:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																// Theme's static directory
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																if  ( themeData [ 'theme:staticDir' ] )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-14 17:11:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	app . use ( '/css/assets' ,  express . static ( path . join ( nconf . get ( 'themes_path' ) ,  themeData [ 'theme:id' ] ,  themeData [ 'theme:staticDir' ] ) ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 17:37:17 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		maxAge :  app . enabled ( 'cache' )  ?  5184000000  :  0 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 11:17:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	} ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 12:07:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		winston . info ( 'Static directory routed for theme: '  +  themeData [ 'theme:id' ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 12:07:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																if  ( themeData [ 'theme:templates' ] )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-14 17:11:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	app . use ( '/templates' ,  express . static ( path . join ( nconf . get ( 'themes_path' ) ,  themeData [ 'theme:id' ] ,  themeData [ 'theme:templates' ] ) ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 17:37:17 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		maxAge :  app . enabled ( 'cache' )  ?  5184000000  :  0 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 11:17:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	} ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 12:34:41 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 17:10:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		winston . info ( 'Custom templates directory routed for theme: '  +  themeData [ 'theme:id' ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-29 12:34:41 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																app . use ( require ( 'less-middleware' ) ( { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-14 17:11:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	src :  path . join ( nconf . get ( 'themes_path' ) ,  themeId ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	dest :  path . join ( _ _dirname ,  '../public/css' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	prefix :  nconf . get ( 'relative_path' )  +  '/css' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 20:37:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	yuicompress :  app . enabled ( 'minification' )  ?  true  :  false 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 17:41:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																// If not using a local theme (bootswatch, etc), drop back to vanilla
 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	winston . info ( '[themes] Using theme '  +  themeId ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 17:41:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																app . use ( require ( 'less-middleware' ) ( { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-14 17:11:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	src :  path . join ( nconf . get ( 'themes_path' ) ,  '/nodebb-theme-vanilla' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 17:41:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	dest :  path . join ( _ _dirname ,  '../public/css' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	prefix :  nconf . get ( 'relative_path' )  +  '/css' , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 20:37:13 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	yuicompress :  app . enabled ( 'minification' )  ?  true  :  false 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 17:41:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-01 11:27:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														// Route paths to screenshots for installed themes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														meta . themes . get ( function ( err ,  themes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															var 	screenshotPath ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															async . each ( themes ,  function ( themeObj ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																if  ( themeObj . screenshot )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-14 17:11:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	screenshotPath  =  path . join ( nconf . get ( 'themes_path' ) ,  themeObj . id ,  themeObj . screenshot ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-01 11:36:05 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	( function ( id ,  path )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																		fs . exists ( path ,  function ( exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																			if  ( exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																				app . get ( '/css/previews/'  +  id ,  function ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																					res . sendfile ( path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																				} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																			} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																		} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	} ) ( themeObj . id ,  screenshotPath ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-01 11:27:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	next ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												] ,  next ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												// Router & post-router middlewares
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( app . router ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// Static directory /public
 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 11:17:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												app . use ( nconf . get ( 'relative_path' ) ,  express . static ( path . join ( _ _dirname ,  '../' ,  'public' ) ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 17:37:17 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													maxAge :  app . enabled ( 'cache' )  ?  5184000000  :  0 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 11:17:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-19 16:24:33 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// 404 catch-all
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( function  ( req ,  res ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-12 14:38:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													var 	isLanguage  =  new  RegExp ( '^'  +  nconf . get ( 'relative_path' )  +  '/language/[\\w]{2,}/.*.json' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														isClientScript  =  new  RegExp ( '^'  +  nconf . get ( 'relative_path' )  +  '\\/src\\/forum(\\/admin)?\\/[\\w]+\\.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													res . status ( 404 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													if  ( isClientScript . test ( req . url ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-03 15:04:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														// Handle missing client-side scripts
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res . type ( 'text/javascript' ) . send ( 200 ,  '' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  if  ( isLanguage . test ( req . url ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														// Handle languages by sending an empty object
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res . json ( 200 ,  { } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-03 15:04:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  if  ( req . accepts ( 'html' ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														// respond with html page
 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															winston . warn ( 'Route requested but not found: '  +  req . url ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														res . redirect ( nconf . get ( 'relative_path' )  +  '/404' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-03 15:04:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  if  ( req . accepts ( 'json' ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														// respond with json
 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															winston . warn ( 'Route requested but not found: '  +  req . url ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-03 15:04:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														res . json ( { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															error :  'Not found' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-03 15:04:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														// default to plain-text. send()
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res . type ( 'txt' ) . send ( 'Not found' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . use ( function  ( err ,  req ,  res ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													// we may use properties of the error object
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													// here and next(err) appropriately, or if
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													// we possibly recovered from the error, simply next().
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													console . error ( err . stack ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 13:28:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													var  status  =  err . status  ||  500 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													res . status ( status ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 13:28:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													res . json ( status ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														error :  err . message 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										] ,  function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												winston . error ( 'Errors were encountered while attempting to initialise NodeBB.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-05 22:33:29 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												process . exit ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-29 20:27:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													winston . info ( 'Middlewares loaded.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-13 11:10:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									module . exports . init  =  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-24 14:14:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// translate all static templates served by webserver here. ex. footer, logout
 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-21 16:07:32 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										plugins . fireHook ( 'filter:footer.build' ,  '' ,  function ( err ,  appendHTML )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  footer  =  templates . footer . parse ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												footerHTML :  appendHTML 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											translator . translate ( footer ,  function ( parsedTemplate )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												templates . footer  =  parsedTemplate ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-21 15:05:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-24 14:14:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-21 16:07:32 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-23 17:08:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										plugins . fireHook ( 'action:app.load' ,  app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-22 11:42:42 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										translator . translate ( templates . logout . toString ( ) ,  function ( parsedTemplate )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											templates . logout  =  parsedTemplate ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-24 14:14:26 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 23:07:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										server . on ( "error" ,  function ( e ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( e . code  ===  'EADDRINUSE' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												winston . error ( 'NodeBB address in use, exiting...' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												process . exit ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												throw  e ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  port  =  nconf . get ( 'PORT' )  ||  nconf . get ( 'port' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										winston . info ( 'NodeBB attempting to listen on: '  +  ( ( nconf . get ( 'bind_address' )  ===  "0.0.0.0"  ||  ! nconf . get ( 'bind_address' ) )  ?  '0.0.0.0'  :  nconf . get ( 'bind_address' ) )  +  ':'  +  port ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										server . listen ( port ,  nconf . get ( 'bind_address' ) ,  function ( ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											winston . info ( 'NodeBB Ready' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-17 13:36:35 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									app . create _route  =  function  ( url ,  tpl )  {  // to remove
 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:00:57 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										var 	routerScript  =  ' < script >  \ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:09:28 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ajaxify . initialLoad  =  true ;  \ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:00:57 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												templates . ready ( function ( ) { ajaxify . go ( "' + url + '" ,  null ,  true ) ; } ) ;  \ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											< / s c r i p t > ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  routerScript ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-09 06:26:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									app . namespace ( nconf . get ( 'relative_path' ) ,  function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 11:13:03 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										auth . registerApp ( app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-12 12:41:16 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										admin . createRoutes ( app ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										userRoute . createRoutes ( app ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										apiRoute . createRoutes ( app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 23:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										feedsRoute . createRoutes ( app ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-09 21:29:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 21:31:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										( function  ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 19:46:25 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											var  routes  =  [ 'login' ,  'register' ,  'account' ,  'recent' ,  'popular' ,  '403' ,  '404' ,  '500' ] , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-11 22:50:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												loginRequired  =  [ 'unread' ,  'notifications' ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 14:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											async . each ( routes . concat ( loginRequired ) ,  function ( route ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												app . get ( '/'  +  route ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-31 11:37:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													if  ( ( route  ===  'register'  ||  route  ===  'login' )  &&  ( req . user  &&  req . user . uid  >  0 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 14:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														user . getUserField ( req . user . uid ,  'userslug' ,  function  ( err ,  userslug )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															res . redirect ( '/user/'  +  userslug ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 14:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														return ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 20:59:55 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  if ( route  ===  'register'  &&  meta . config . allowRegistration  !==  undefined  &&  parseInt ( meta . config . allowRegistration ,  10 )  ===  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 12:22:50 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														return  res . redirect ( '/403' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 14:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													}  else  if  ( loginRequired . indexOf ( route )  !==  - 1  &&  ! req . user )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														return  res . redirect ( '/403' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res :  res 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res . send ( ( isNaN ( parseInt ( route ,  10 ) )  ?  200  :  parseInt ( route ,  10 ) ) ,  header  +  app . create _route ( route )  +  templates . footer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 21:31:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 14:06:26 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 21:31:58 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											async . parallel ( { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												"header" :  function  ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-25 15:34:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res :  res , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														metaTags :  [ { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															name :  "title" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															content :  meta . config . title  ||  'NodeBB' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															name :  "description" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															content :  meta . config . description  ||  '' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															property :  'og:title' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															content :  'Index | '  +  ( meta . config . title  ||  'NodeBB' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															property :  "og:type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															content :  'website' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ] 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-25 15:34:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ,  next ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												"categories" :  function  ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-31 22:25:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													function  canSee ( category ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														CategoryTools . privileges ( category . cid ,  ( ( req . user )  ?  req . user . uid  ||  0  :  0 ) ,  function ( err ,  privileges )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															next ( ! err  &&  privileges . read ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 14:25:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													categories . getAllCategories ( 0 ,  function  ( err ,  returnData )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														returnData . categories  =  returnData . categories . filter ( function  ( category )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-19 15:33:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															return  ! category . disabled ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-20 20:43:02 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-31 22:25:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														async . filter ( returnData . categories ,  canSee ,  function ( visibleCategories )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															returnData . categories  =  visibleCategories ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															next ( null ,  returnData ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-26 14:25:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ,  function  ( err ,  data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res . send ( 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													data . header  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													'\n\t<noscript>\n'  +  templates [ 'noscript/header' ]  +  templates [ 'noscript/home' ] . parse ( data . categories )  +  '\n\t</noscript>'  + 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													app . create _route ( '' )  + 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													templates . footer 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 14:27:37 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/topic/:topic_id/:slug?' ,  function  ( req ,  res ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											var  tid  =  req . params . topic _id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												page  =  req . query . page  ||  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												uid  =  req . user  ?  req . user . uid  :  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-04 13:52:28 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											async . waterfall ( [ 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 21:42:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-08 15:09:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													ThreadTools . privileges ( tid ,  ( ( req . user )  ?  req . user . uid  ||  0  :  0 ) ,  function ( err ,  privileges )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 21:42:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  ( ! err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															if  ( ! privileges . read )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																next ( new  Error ( 'not-enough-privileges' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															next ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												function  ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													user . getSettings ( uid ,  function ( err ,  settings )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															return  next ( err ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-24 18:51:24 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-24 18:47:10 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														var  start  =  ( page  -  1 )  *  settings . topicsPerPage , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															end  =  start  +  settings . topicsPerPage  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														topics . getTopicWithPosts ( tid ,  uid ,  start ,  end ,  true ,  function  ( err ,  topicData )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															if  ( topicData )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																if  ( parseInt ( topicData . deleted ,  10 )  ===  1  &&  parseInt ( topicData . expose _tools ,  10 )  ===  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	return  next ( new  Error ( 'Topic deleted' ) ,  null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															next ( err ,  topicData ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												function  ( topicData ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-18 23:18:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													var  lastMod  =  topicData . timestamp , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														sanitize  =  validator . sanitize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														description  =  ( function ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-18 23:18:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															var 	content  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															if ( topicData . posts . length )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content  =  S ( topicData . posts [ 0 ] . content ) . stripTags ( ) . s ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															if  ( content . length  >  255 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content  =  content . substr ( 0 ,  255 )  +  '...' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															return  sanitize ( content ) . escape ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														timestamp ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-16 17:04:08 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													for  ( var  x  =  0 ,  numPosts  =  topicData . posts . length ;  x  <  numPosts ;  x ++ )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-25 15:34:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														timestamp  =  parseInt ( topicData . posts [ x ] . timestamp ,  10 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  ( timestamp  >  lastMod )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															lastMod  =  timestamp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-25 15:34:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 22:31:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													var  ogImageUrl  =  meta . config [ 'brand:logo' ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if ( ogImageUrl  &&  ogImageUrl . indexOf ( 'http' )  ===  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														ogImageUrl  =  nconf . get ( 'url' )  +  ogImageUrl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res :  res , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														metaTags :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																name :  "title" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  topicData . topic _name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																name :  "description" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  description 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  'og:title' , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 10:12:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																content :  topicData . topic _name 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  'og:description' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  description 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  "og:type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  'article' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  "og:url" , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 14:04:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																content :  nconf . get ( 'url' )  +  '/topic/'  +  topicData . slug 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  "og:image:url" , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-12 22:31:08 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																content :  ogImageUrl 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  'og:image' , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-18 23:18:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																content :  topicData . posts . length ? topicData . posts [ 0 ] . picture : '' 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  "article:published_time" , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-18 23:18:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																content :  utils . toISOString ( topicData . timestamp ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  'article:modified_time' , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-18 23:18:58 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																content :  utils . toISOString ( lastMod ) 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-26 20:37:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  'article:section' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  topicData . category _name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														] , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														linkTags :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																rel :  'alternate' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																type :  'application/rss+xml' , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 14:04:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																href :  nconf . get ( 'url' )  +  '/topic/'  +  tid  +  '.rss' 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																rel :  'up' , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 14:04:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																href :  nconf . get ( 'url' )  +  '/category/'  +  topicData . category _slug 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														] 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														next ( err ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															header :  header , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															posts :  topicData 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											] ,  function  ( err ,  data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-23 21:42:34 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													if  ( err . message  ===  'not-enough-privileges' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														return  res . redirect ( '403' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														return  res . redirect ( '404' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												var  topic _url  =  tid  +  ( req . params . slug  ?  '/'  +  req . params . slug  :  '' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 19:19:25 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												var  queryString  =  qs . stringify ( req . query ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if ( queryString . length )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													topic _url  +=  '?'  +  queryString ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// Paginator for noscript
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												data . posts . pages  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												for ( var  x = 1 ; x <= data . posts . pageCount ; x ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													data . posts . pages . push ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														page :  x , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														active :  x  ===  parseInt ( page ,  10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												translator . translate ( templates [ 'noscript/topic' ] . parse ( data . posts ) ,  function ( translatedHTML )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													res . send ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														data . header  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														'\n\t<noscript>\n'  +  templates [ 'noscript/header' ]  +  translatedHTML  +  '\n\t</noscript>'  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														'\n\t'  +  app . create _route ( 'topic/'  +  topic _url )  +  templates . footer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 14:27:37 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/category/:category_id/:slug?' ,  function  ( req ,  res ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											var  cid  =  req . params . category _id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												page  =  req . query . page  ||  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												uid  =  req . user  ?  req . user . uid  :  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											async . waterfall ( [ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-08 15:09:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													CategoryTools . privileges ( cid ,  uid ,  function ( err ,  privileges )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-08 15:09:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														if  ( ! err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															if  ( ! privileges . read )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																next ( new  Error ( 'not-enough-privileges' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															next ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												function  ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													user . getSettings ( uid ,  function ( err ,  settings )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															return  next ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														var  start  =  ( page  -  1 )  *  settings . topicsPerPage , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															end  =  start  +  settings . topicsPerPage  -  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:41:02 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														categories . getCategoryById ( cid ,  start ,  end ,  0 ,  function  ( err ,  categoryData )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-30 14:47:31 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															if  ( categoryData )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																if  ( parseInt ( categoryData . disabled ,  10 )  ===  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	return  next ( new  Error ( 'Category disabled' ) ,  null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															next ( err ,  categoryData ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												function  ( categoryData ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														res :  res , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 10:12:45 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														metaTags :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																name :  'title' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  categoryData . category _name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  'og:title' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  categoryData . category _name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																name :  'description' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  categoryData . category _description 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																property :  "og:type" , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																content :  'website' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														] , 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														linkTags :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																rel :  'alternate' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																type :  'application/rss+xml' , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 14:04:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																href :  nconf . get ( 'url' )  +  '/category/'  +  cid  +  '.rss' 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-22 12:23:07 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																rel :  'up' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																href :  nconf . get ( 'url' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														] 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														next ( err ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															header :  header , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
															topics :  categoryData 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											] ,  function  ( err ,  data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-08 15:09:24 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													if  ( err . message  ===  'not-enough-privileges' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														return  res . redirect ( '403' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														return  res . redirect ( '404' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if ( data . topics . link )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													return  res . redirect ( data . topics . link ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-05 01:39:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 19:27:25 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												var  category _url  =  cid  +  ( req . params . slug  ?  '/'  +  req . params . slug  :  '' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 19:19:25 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												var  queryString  =  qs . stringify ( req . query ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if ( queryString . length )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													category _url  +=  '?'  +  queryString ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-23 17:21:44 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-18 19:23:36 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												// Paginator for noscript
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												data . topics . pages  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												for ( var  x = 1 ; x <= data . topics . pageCount ; x ++ )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													data . topics . pages . push ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														page :  x , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														active :  x  ===  parseInt ( page ,  10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												translator . translate ( templates [ 'noscript/category' ] . parse ( data . topics ) ,  function ( translatedHTML )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													res . send ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														data . header  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														'\n\t<noscript>\n'  +  templates [ 'noscript/header' ]  +  translatedHTML  +  '\n\t</noscript>'  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														'\n\t'  +  app . create _route ( 'category/'  +  category _url )  +  templates . footer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-30 16:02:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-30 16:02:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/confirm/:code' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res :  res 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:00:57 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res . send ( header  +  app . create _route ( 'confirm/'  +  req . params . code )  +  templates . footer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-24 18:54:14 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-10 16:22:03 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-05-30 16:02:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/sitemap.xml' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											var  sitemap  =  require ( './sitemap.js' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-17 22:35:16 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											sitemap . render ( function  ( xml )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-17 18:58:38 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res . header ( 'Content-Type' ,  'application/xml' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res . send (  xml  ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-17 22:35:16 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/robots.txt' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-20 11:19:08 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											res . set ( 'Content-Type' ,  'text/plain' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-05 23:19:52 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( meta . config [ "robots.txt" ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res . send ( meta . config [ "robots.txt" ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res . send ( "User-agent: *\n"  + 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													"Disallow: /admin/\n"  + 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-22 14:04:04 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													"Sitemap: "  +  nconf . get ( 'url' )  +  "/sitemap.xml" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-05 23:19:52 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-20 11:19:08 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-11 14:57:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/recent/:term?' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											// TODO consolidate with /recent route as well -> that can be combined into this area. See "Basic Routes" near top.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res :  res 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res . send ( header  +  app . create _route ( 'recent/'  +  req . params . term ,  null ,  'recent' )  +  templates . footer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-11 14:57:17 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 19:52:32 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/popular/:term?' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res :  res 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res . send ( header  +  app . create _route ( 'popular/'  +  req . params . term ,  null ,  'popular' )  +  templates . footer ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/outgoing' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! req . query . url )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  res . redirect ( '/404' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-08 15:04:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res :  res 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-24 10:00:57 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res . send ( header  +  app . create _route ( 'outgoing?url='  +  encodeURIComponent ( req . query . url ) )  +  templates . footer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-08 15:04:22 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-03 20:54:16 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-21 00:07:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get ( '/search/:term?' ,  function  ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-12 22:51:17 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! req . user  &&  meta . config . allowGuestSearching  !==  '1' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 14:40:31 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												return  res . redirect ( '/403' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-21 00:07:00 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if ( ! req . params . term )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												req . params . term  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											app . build _header ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												req :  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												res :  res 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-23 12:50:27 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-18 02:39:08 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res . send ( header  +  app . create _route ( 'search/'  +  req . params . term ,  null ,  'search' )  +  templates . footer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-03 20:54:16 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-23 13:14:36 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-03 17:15:18 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Other routes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										require ( './routes/plugins' ) ( app ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-25 16:01:31 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										// Debug routes
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( process . env . NODE _ENV  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											require ( './routes/debug' ) ( app ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  custom _routes  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											'routes' :  [ ] , 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-30 16:19:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											'api' :  [ ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											'templates' :  [ ] 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-25 23:13:51 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										app . get _custom _templates  =  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  custom _routes . templates . map ( function ( tpl )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  tpl . template . split ( '.tpl' ) [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										plugins . ready ( function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											plugins . fireHook ( 'filter:server.create_routes' ,  custom _routes ,  function ( err ,  custom _routes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var  routes  =  custom _routes . routes ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												for  ( var  route  in  routes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( routes . hasOwnProperty ( route ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-04 23:59:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														( function ( route )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															app [ routes [ route ] . method  ||  'get' ] ( routes [ route ] . route ,  function ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																routes [ route ] . options ( req ,  res ,  function ( options )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	app . build _header ( { 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 17:00:52 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		req :  options . req  ||  req , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																		res :  options . res  ||  res 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-04 23:59:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	} ,  function  ( err ,  header )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-11 13:25:54 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																		res . send ( header  +  options . content  +  templates . footer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-04 23:59:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																	} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
																} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-04 23:59:33 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														} ( route ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:10:46 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var  apiRoutes  =  custom _routes . api ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												for  ( var  route  in  apiRoutes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( apiRoutes . hasOwnProperty ( route ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														( function ( route )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															app [ apiRoutes [ route ] . method  ||  'get' ] ( '/api'  +  apiRoutes [ route ] . route ,  function ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																apiRoutes [ route ] . callback ( req ,  res ,  function ( data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																	res . json ( data ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ( route ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-30 16:19:59 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												var  templateRoutes  =  custom _routes . templates ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												for  ( var  route  in  templateRoutes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( templateRoutes . hasOwnProperty ( route ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														( function ( route )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															app . get ( '/templates/'  +  templateRoutes [ route ] . template ,  function ( req ,  res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
																res . send ( templateRoutes [ route ] . content ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
															} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														} ( route ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-10-21 11:09:46 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-10-12 17:19:13 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-05-05 13:05:05 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-04-22 16:51:32 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} ( WebServer ) ) ;