2013-09-17 13:09:37 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var  fs  =  require ( 'fs' ) ,  
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									path  =  require ( 'path' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 02:24:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									async  =  require ( 'async' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-13 14:45:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									winston  =  require ( 'winston' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-06 23:44:32 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									nconf  =  require ( 'nconf' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-13 11:10:17 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									eventEmitter  =  require ( 'events' ) . EventEmitter , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 22:38:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									semver  =  require ( 'semver' ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 11:57:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									db  =  require ( './database' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 22:38:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									meta  =  require ( './meta' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 12:06:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									utils  =  require ( './../public/src/utils' ) , 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 22:38:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									pkg  =  require ( '../package.json' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-02 16:19:30 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								( function ( Plugins )  {  
						 
					
						
							
								
									
										
										
										
											2013-09-13 11:10:17 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . libraries  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . loadedHooks  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . staticDirs  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . cssFiles  =  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-25 14:13:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . lessFiles  =  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 13:28:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . clientScripts  =  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-13 11:10:17 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . initialized  =  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// Events
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . readyEvent  =  new  eventEmitter ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . init  =  function ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( Plugins . initialized )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . info ( '[plugins] Initializing plugins system' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . reload ( function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													winston . info ( '[plugins] NodeBB encountered a problem while loading plugins' ,  err . message ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-03 17:15:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-03 17:15:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												winston . info ( '[plugins] Plugins OK' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Plugins . initialized  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 14:21:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Plugins . readyEvent . emit ( 'ready' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . ready  =  function ( callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! Plugins . initialized )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Plugins . readyEvent . once ( 'ready' ,  callback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											callback ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . reload  =  function ( callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Resetting all local plugin data
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . loadedHooks  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . staticDirs  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . cssFiles . length  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 17:50:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Plugins . lessFiles . length  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . clientScripts . length  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Read the list of activated plugins and require their libraries
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . waterfall ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												db . getSetMembers ( 'plugins:active' ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											function ( plugins ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( ! plugins  ||  ! Array . isArray ( plugins ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-30 11:57:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												plugins . push ( meta . config [ 'theme:id' ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-03 20:41:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												plugins  =  plugins . filter ( function ( plugin ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  plugin  &&  typeof  plugin  ===  'string' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) . map ( function ( plugin ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  path . join ( _ _dirname ,  '../node_modules/' ,  plugin ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												async . filter ( plugins ,  fs . exists ,  function ( plugins ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													async . each ( plugins ,  Plugins . loadPlugin ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( global . env  ===  'development' )  winston . info ( '[plugins] Sorting hooks to fire in priority sequence' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Object . keys ( Plugins . loadedHooks ) . forEach ( function ( hook )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													var  hooks  =  Plugins . loadedHooks [ hook ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													hooks  =  hooks . sort ( function ( a ,  b )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														return  a . priority  -  b . priority ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-03 17:15:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										] ,  callback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . loadPlugin  =  function ( pluginPath ,  callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fs . readFile ( path . join ( pluginPath ,  'plugin.json' ) ,  function ( err ,  data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-24 15:35:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return  callback ( pluginPath . match ( 'nodebb-theme' )  ?  null  :  err ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  pluginData  =  JSON . parse ( data ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												libraryPath ,  staticDir ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 22:38:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( pluginData . minver  &&  semver . validRange ( pluginData . minver ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-18 12:43:32 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( ! semver . gt ( pkg . version ,  pluginData . minver ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 22:38:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// If NodeBB is not new enough to run this plugin
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-27 10:28:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													winston . warn ( '[plugins/'  +  pluginData . id  +  '] This plugin may not be compatible with your version of NodeBB. This may cause unintended behaviour or crashing.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-13 22:38:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											async . parallel ( [ 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( pluginData . library )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														libraryPath  =  path . join ( pluginPath ,  pluginData . library ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														fs . exists ( libraryPath ,  function ( exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															if  ( exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																if  ( ! Plugins . libraries [ pluginData . id ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	Plugins . libraries [ pluginData . id ]  =  require ( libraryPath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																// Register hooks for this plugin
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																if  ( pluginData . hooks  &&  Array . isArray ( pluginData . hooks )  &&  pluginData . hooks . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	async . each ( pluginData . hooks ,  function ( hook ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																		Plugins . registerHook ( pluginData . id ,  hook ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	} ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	next ( null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																winston . warn ( '[plugins.reload] Library not found for plugin: '  +  pluginData . id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																next ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-01 15:27:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														winston . warn ( '[plugins.reload] Library not found for plugin: '  +  pluginData . id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-09-02 21:53:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// Static Directories for Plugins
 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-02 13:02:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													var 	realPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														validMappedPath  =  /^[\w\-_]+$/ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													pluginData . staticDirs  =  pluginData . staticDirs  ||  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Deprecated, to be removed v0.5
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( pluginData . staticDir )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-02 13:02:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														winston . warn ( '[plugins/'  +  pluginData . id  +  '] staticDir is deprecated, use staticDirs instead' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . staticDirs [ pluginData . id ]  =  path . join ( pluginPath ,  pluginData . staticDir ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-24 15:35:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													for ( var  key  in  pluginData . staticDirs )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-02 13:02:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														( function ( mappedPath )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															if  ( pluginData . staticDirs . hasOwnProperty ( mappedPath ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																if  ( Plugins . staticDirs [ mappedPath ] )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	winston . warn ( '[plugins/'  +  pluginData . id  +  '] Mapped path ('  +  mappedPath  +  ') already specified!' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																}  else  if  ( ! validMappedPath . test ( mappedPath ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	winston . warn ( '[plugins/'  +  pluginData . id  +  '] Invalid mapped path specified: '  +  mappedPath  +  '. Path must adhere to: '  +  validMappedPath . toString ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	realPath  =  pluginData . staticDirs [ mappedPath ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	staticDir  =  path . join ( pluginPath ,  realPath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	( function ( staticDir )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																		fs . exists ( staticDir ,  function ( exists )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																			if  ( exists )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-03 16:31:50 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																				Plugins . staticDirs [ pluginData . id  +  '/'  +  mappedPath ]  =  staticDir ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-06 16:02:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																			}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																				winston . warn ( '[plugins/'  +  pluginData . id  +  '] Mapped path \''  +  mappedPath  +  ' => '  +  staticDir  +  '\' not found.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-02 13:02:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																			} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																		} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	} ( staticDir ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} ( key ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// CSS Files for plugins
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( pluginData . css  &&  pluginData . css  instanceof  Array )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															winston . info ( '[plugins] Found '  +  pluginData . css . length  +  ' CSS file(s) for plugin '  +  pluginData . id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-03 17:15:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 17:37:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 17:50:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														Plugins . cssFiles  =  Plugins . cssFiles . concat ( pluginData . css . map ( function ( file )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 20:36:05 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															if  ( fs . existsSync ( path . join ( _ _dirname ,  '../node_modules' ,  pluginData . id ,  file ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																return  path . join ( pluginData . id ,  file ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																// Backwards compatibility with < v0.4.0, remove this for v0.5.0
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																if  ( pluginData . staticDir )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	return  path . join ( pluginData . id ,  pluginData . staticDir ,  file ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	winston . error ( '[plugins/'  +  pluginData . id  +  '] This plugin\'s CSS is incorrectly configured, please contact the plugin author.' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	return  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} ) . filter ( function ( path )  {  return  path  } ) ) ; 	// Filter out nulls, remove this for v0.5.0
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 17:43:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 17:50:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-25 14:13:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// LESS files for plugins
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( pluginData . less  &&  pluginData . less  instanceof  Array )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															winston . info ( '[plugins] Found '  +  pluginData . less . length  +  ' LESS file(s) for plugin '  +  pluginData . id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . lessFiles  =  Plugins . lessFiles . concat ( pluginData . less . map ( function ( file )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															return  path . join ( pluginData . id ,  file ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 13:31:13 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Client-side scripts
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( pluginData . scripts  &&  pluginData . scripts  instanceof  Array )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															winston . info ( '[plugins] Found '  +  pluginData . scripts . length  +  ' js file(s) for plugin '  +  pluginData . id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . clientScripts  =  Plugins . clientScripts . concat ( pluginData . scripts . map ( function ( file )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 16:44:41 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															return  path . join ( _ _dirname ,  '../node_modules/' ,  pluginData . id ,  file ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-02 13:31:13 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-25 14:13:09 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											] ,  function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( ! err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 17:43:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														winston . info ( '[plugins] Loaded plugin: '  +  pluginData . id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													callback ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 17:43:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													callback ( new  Error ( 'Could not load plugin system' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-22 09:50:29 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . registerHook  =  function ( id ,  data ,  callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											` data `  is  an  object  consisting  of  ( *  is  required ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												` data.hook ` * ,  the  name  of  the  NodeBB  hook 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												` data.method ` * ,  the  method  called  in  that  plugin 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												` data.callbacked ` ,  whether  or  not  the  hook  expects  a  callback  ( true ) ,  or  a  return  ( false ) .  Only  used  for  filters .  ( Default :  false ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												` data.priority ` ,  the  relative  priority  of  the  method  when  it  is  eventually  called  ( default :  10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										* / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-28 20:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  method ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-28 20:05:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( data . hook  &&  data . method  &&  typeof  data . method  ===  'string'  &&  data . method . length  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											data . id  =  id ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! data . priority )  data . priority  =  10 ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-28 20:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											method  =  data . method . split ( '.' ) . reduce ( function ( memo ,  prop )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( memo  !==  null  &&  memo [ prop ] )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													return  memo [ prop ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-28 20:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// Couldn't find method by path, aborting
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  null ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  Plugins . libraries [ data . id ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-28 20:39:27 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( method  ===  null )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												winston . warn ( '[plugins/'  +  id  +  '] Hook method mismatch: '  +  data . hook  +  ' => '  +  data . method ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  callback ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Write the actual method reference to the hookObj
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											data . method  =  method ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											Plugins . loadedHooks [ data . hook ]  =  Plugins . loadedHooks [ data . hook ]  ||  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											Plugins . loadedHooks [ data . hook ] . push ( data ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											callback ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-26 13:21:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . hasListeners  =  function ( hook )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  ( Plugins . loadedHooks [ hook ]  &&  Plugins . loadedHooks [ hook ] . length  >  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-26 13:10:39 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . fireHook  =  function ( hook )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  callback  =  typeof  arguments [ arguments . length - 1 ]  ===  "function"  ?  arguments [ arguments . length - 1 ]  :  null , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											args  =  arguments . length  ?  Array . prototype . slice . call ( arguments ,  1 )  :  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											args . pop ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 21:54:30 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										hookList  =  Plugins . loadedHooks [ hook ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( hookList  &&  Array . isArray ( hookList ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 21:54:30 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// if (global.env === 'development') winston.info('[plugins] Firing hook: \'' + hook + '\'');
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											var  hookType  =  hook . split ( ':' ) [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											switch  ( hookType )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  'filter' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													async . reduce ( hookList ,  args ,  function ( value ,  hookObj ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( hookObj . method )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 16:58:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															if  ( ! hookObj . hasOwnProperty ( 'callbacked' )  ||  hookObj . callbacked  ===  true )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																var 	value  =  hookObj . method . apply ( Plugins ,  value . concat ( function ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																	next ( arguments [ 0 ] ,  Array . prototype . slice . call ( arguments ,  1 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 16:58:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 17:32:50 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																if  ( value  !==  undefined  &&  value  !==  callback )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 16:58:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																	winston . warn ( '[plugins/'  +  hookObj . id  +  '] "callbacked" deprecated as of 0.4x. Use asynchronous method instead for hook: '  +  hook ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	next ( null ,  [ value ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-10 16:58:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																winston . warn ( '[plugins/'  +  hookObj . id  +  '] "callbacked" deprecated as of 0.4x. Use asynchronous method instead for hook: '  +  hook ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																value  =  hookObj . method . apply ( Plugins ,  value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:23:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																next ( null ,  [ value ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 17:43:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-31 17:19:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																winston . info ( '[plugins] Expected method for hook \''  +  hook  +  '\' in plugin \''  +  hookObj . id  +  '\' not found, skipping.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 17:43:12 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:23:48 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															next ( null ,  [ value ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													} ,  function ( err ,  values )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																winston . info ( '[plugins] Problem executing hook: '  +  hook ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														callback . apply ( Plugins ,  [ err ] . concat ( values ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												case  'action' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													async . each ( hookList ,  function ( hookObj )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( hookObj . method )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															hookObj . method . apply ( Plugins ,  args ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																winston . info ( '[plugins] Expected method \''  +  hookObj . method  +  '\' in plugin \''  +  hookObj . id  +  '\' not found, skipping.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 14:24:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												default : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Do nothing...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Otherwise, this hook contains no methods
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( callback )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												callback . apply ( this ,  [ null ] . concat ( args ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 14:07:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  args [ 0 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . isActive  =  function ( id ,  callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										db . isSetMember ( 'plugins:active' ,  id ,  callback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . toggleActive  =  function ( id ,  callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . isActive ( id ,  function ( err ,  active )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													winston . info ( '[plugins] Could not toggle active state on plugin \''  +  id  +  '\'' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  callback ( err ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											db [ ( active  ?  'setRemove'  :  'setAdd' ) ] ( 'plugins:active' ,  id ,  function ( err ,  success )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-29 15:15:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( err )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( global . env  ===  'development' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														winston . info ( '[plugins] Could not toggle active state on plugin \''  +  id  +  '\'' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  callback ( err ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-29 15:15:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-16 15:11:00 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												meta . restartRequired  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 15:32:38 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( active )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 15:32:38 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													Plugins . fireHook ( 'action:plugin.deactivate' ,  id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// Reload meta data
 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 17:57:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												Plugins . reload ( function ( )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-18 15:32:38 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if ( ! active )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . fireHook ( 'action:plugin.activate' ,  id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-29 15:15:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( typeof  callback  ===  'function' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														callback ( null ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															id :  id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															active :  ! active 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-29 15:15:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 12:06:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . toggleInstall  =  function ( id ,  callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . isInstalled ( id ,  function ( err ,  installed )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  callback ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  npm  =  require ( 'npm' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											async . waterfall ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Plugins . isActive ( id ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( active ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( active )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . toggleActive ( id ,  function ( err ,  status )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															next ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													npm . load ( { } ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												function ( res ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													npm . commands [ installed  ?  'uninstall'  :  'install' ] ( installed  ?  id  :  [ id ] ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											] ,  function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												callback ( err ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													id :  id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													installed :  ! installed 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 12:06:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . getTemplates  =  function ( callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  templates  =  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										Plugins . showInstalled ( function ( err ,  plugins )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											async . each ( plugins ,  function ( plugin ,  next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-09 20:45:37 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( plugin . templates  &&  plugin . id  &&  plugin . active )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 12:06:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													var  templatesPath  =  path . join ( _ _dirname ,  '../node_modules' ,  plugin . id ,  plugin . templates ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													utils . walk ( templatesPath ,  function ( err ,  pluginTemplates )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														pluginTemplates . forEach ( function ( pluginTemplate )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-12 20:45:07 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															templates [ "/"  +  pluginTemplate . replace ( templatesPath ,  '' ) . substring ( 1 ) ]  =  pluginTemplate ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 12:06:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														next ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												callback ( err ,  templates ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-08-22 10:47:24 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . getAll  =  function ( callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  request  =  require ( 'request' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										request ( 'http://npm.aws.af.cm/api/v1/plugins' ,  function ( err ,  res ,  body )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  callback ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var  plugins  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												plugins  =  JSON . parse ( body ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}  catch ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												winston . error ( 'Error parsing plugins : '  +  err . message ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  callback ( null ,  [ ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											async . map ( plugins ,  function ( plugin ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												plugin . id  =  plugin . name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												async . parallel ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													active :  function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . isActive ( plugin . id ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													installed :  function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														Plugins . isInstalled ( plugin . id ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ,  function ( err ,  results )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														return  next ( err ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													plugin . active  =  results . active ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													plugin . installed  =  results . installed ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( null ,  plugin ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  callback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Plugins . isInstalled  =  function ( id ,  callback )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										var  pluginDir  =  path . join ( _ _dirname ,  '../node_modules' ,  id ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										fs . stat ( pluginDir ,  function ( err ,  stats )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											callback ( null ,  err  ?  false  :  stats . isDirectory ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									Plugins . showInstalled  =  function ( callback )  { 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										var  npmPluginPath  =  path . join ( _ _dirname ,  '../node_modules' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										async . waterfall ( [ 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											async . apply ( fs . readdir ,  npmPluginPath ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											function ( dirs ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												dirs  =  dirs . filter ( function ( dir ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  dir . substr ( 0 ,  14 )  ===  'nodebb-plugin-'  ||  dir . substr ( 0 ,  14 )  ===  'nodebb-widget-' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) . map ( function ( dir ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  path . join ( npmPluginPath ,  dir ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												async . filter ( dirs ,  function ( dir ,  callback ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													fs . stat ( dir ,  function ( err ,  stats ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															return  callback ( false ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-02-23 22:44:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 12:52:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														callback ( stats . isDirectory ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ,  function ( plugins ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( null ,  plugins ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} , 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-08 21:36:18 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											function ( files ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												var  plugins  =  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												async . each ( files ,  function ( file ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													var  configPath ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													async . waterfall ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														function ( next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															fs . readFile ( path . join ( file ,  'plugin.json' ) ,  next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														function ( configJSON ,  next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																var  config  =  JSON . parse ( configJSON ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															}  catch  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																winston . warn ( "Plugin: "  +  file  +  " is corrupted or invalid. Please check plugin.json for errors." ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																return  next ( err ,  null ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-29 15:15:49 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															Plugins . isActive ( config . id ,  function ( err ,  active )  { 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-04 17:57:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																if  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																	next ( new  Error ( 'no-active-state' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																} 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																delete  config . library ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																delete  config . hooks ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																config . active  =  active ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-04-22 21:02:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																config . installed  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
																next ( null ,  config ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													] ,  function ( err ,  config )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if  ( err )  return  next ( ) ;  // Silently fail
 
							 
						 
					
						
							
								
									
										
										
										
											2013-07-28 01:16:21 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														plugins . push ( config ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														next ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ,  function ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													next ( null ,  plugins ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										] ,  function ( err ,  plugins )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											callback ( err ,  plugins ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-06 12:06:19 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
									
										
										
										
											2013-12-03 13:36:44 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ( exports ) ) ;