| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * PayPal Donation extension for the phpBB Forum Software package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright (c) 2015 Skouat | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license GNU General Public License, version 2 (GPL-2.0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace skouat\ppde; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * Extension class for custom enable/disable/purge actions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * NOTE TO EXTENSION DEVELOPERS: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * Normally it is not necessary to define any functions inside the ext class below. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * The ext class may contain special (un)installation commands in the methods | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * enable_step(), disable_step() and purge_step(). As it is, these methods are defined | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * in phpbb_extension_base, which this class extends, but you can overwrite them to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * give special instructions for those cases. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | class ext extends \phpbb\extension\base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	 * Check whether or not the extension can be enabled. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * The current phpBB version should meet or exceed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * the minimum version required by this extension: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * Requires phpBB 3.1.3 due to usage of container aware migrations. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * @access public | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 	public function is_enableable() | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 		$config = $this->container->get('config'); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 		return phpbb_version_compare($config['version'], '3.1.3', '>='); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 * Overwrite enable_step to enable extension notifications before any included migrations are installed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * @param mixed $old_state State returned by previous call of this method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * @return mixed Returns false after last step, otherwise temporary state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	public function enable_step($old_state) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		switch ($old_state) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			case '': // Empty means nothing has run yet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				// Enable notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 				return $this->notification_handler('enable', $this->notification_types()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 				// Run parent enable step method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 				return parent::enable_step($old_state); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * Overwrite disable_step to disable extension notifications before the extension is disabled. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * @param mixed $old_state State returned by previous call of this method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @return mixed Returns false after last step, otherwise temporary state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	public function disable_step($old_state) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		switch ($old_state) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			case '': // Empty means nothing has run yet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 				// Disable notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 				return $this->notification_handler('disable', $this->notification_types()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 				// Run parent disable step method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 				return parent::disable_step($old_state); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * Overwrite purge_step to purge extension notifications before any included and installed migrations are reverted. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * @param mixed $old_state State returned by previous call of this method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	 * @return mixed Returns false after last step, otherwise temporary state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	public function purge_step($old_state) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		switch ($old_state) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			case '': // Empty means nothing has run yet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 				// Purge notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 				return $this->notification_handler('purge', $this->notification_types()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 				// Run parent purge step method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 				return parent::purge_step($old_state); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	 * Notification handler to call notification enable/disable/purge steps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * @author        VSEphpbb (Matt Friedman) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 * @license       GNU General Public License, version 2 (GPL-2.0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 * @param string $step               The step (enable, disable, purge) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	 * @param array  $notification_types The notification type names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * @return string Return notifications as temporary state | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 * @access        protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	protected function notification_handler($step, $notification_types) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		/** @type \phpbb\notification\manager $phpbb_notifications */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		$phpbb_notifications = $this->container->get('notification_manager'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		foreach ($notification_types as $notification_type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 			call_user_func(array($phpbb_notifications, $step . '_notifications'), $notification_type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		return 'notifications'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	 * Returns the list of notification types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 	 * @return array | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	 * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	protected function notification_types() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 			'skouat.ppde.notification.type.admin_donation_received', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			'skouat.ppde.notification.type.donor_donation_received', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 144 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 145 |  |  |  | 
            
                        
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.