| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-10 23:52:53 -05:00
										 |  |  | const validator = require('validator'); | 
					
						
							| 
									
										
										
										
											2019-08-14 16:27:58 -04:00
										 |  |  | const plugins = require('../../plugins'); | 
					
						
							| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 16:27:58 -04:00
										 |  |  | const hooksController = module.exports; | 
					
						
							| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | hooksController.get = function (req, res) { | 
					
						
							| 
									
										
										
										
											2019-08-14 16:27:58 -04:00
										 |  |  | 	const hooks = []; | 
					
						
							| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 	Object.keys(plugins.loadedHooks).forEach(function (key, hookIndex) { | 
					
						
							| 
									
										
										
										
											2019-08-14 16:27:58 -04:00
										 |  |  | 		const current = { | 
					
						
							| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 			hookName: key, | 
					
						
							|  |  |  | 			methods: [], | 
					
						
							| 
									
										
										
										
											2021-02-03 23:59:08 -07:00
										 |  |  | 			index: `hook-${hookIndex}`, | 
					
						
							| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 			count: plugins.loadedHooks[key].length, | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		plugins.loadedHooks[key].forEach(function (hookData, methodIndex) { | 
					
						
							|  |  |  | 			current.methods.push({ | 
					
						
							|  |  |  | 				id: hookData.id, | 
					
						
							|  |  |  | 				priority: hookData.priority, | 
					
						
							| 
									
										
										
										
											2019-01-10 23:52:53 -05:00
										 |  |  | 				method: hookData.method ? validator.escape(hookData.method.toString()) : 'No plugin function!', | 
					
						
							| 
									
										
										
										
											2021-02-03 23:59:08 -07:00
										 |  |  | 				index: `${hookIndex}-code-${methodIndex}`, | 
					
						
							| 
									
										
										
										
											2018-10-22 07:30:48 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		hooks.push(current); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hooks.sort((a, b) => b.count - a.count); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res.render('admin/advanced/hooks', { hooks: hooks }); | 
					
						
							|  |  |  | }; |