@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | 7 | exit('No direct script access allowed'); |
| 8 | 8 | } |
| 9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
| 117 | 117 | { |
| 118 | 118 | // check if class object is instantiated, and instantiated properly |
| 119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
| 121 | 121 | } |
| 122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public static function register_dependencies($class, $dependencies) |
| 143 | 143 | { |
| 144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | 145 | // we need to make sure that any aliases used when registering a dependency |
| 146 | 146 | // get resolved to the correct class name |
| 147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
| 148 | 148 | $alias = self::$_instance->get_alias($dependency); |
| 149 | 149 | unset($dependencies[$dependency]); |
| 150 | 150 | $dependencies[$alias] = $load_source; |
| 151 | 151 | } |
| 152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
| 153 | 153 | return true; |
| 154 | 154 | } |
| 155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
| 184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
| 186 | 186 | return true; |
| 187 | 187 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | public function add_alias($class_name, $alias, $for_class = '') |
| 280 | 280 | { |
| 281 | 281 | if ($for_class !== '') { |
| 282 | - if (! isset($this->_aliases[$for_class])) { |
|
| 282 | + if ( ! isset($this->_aliases[$for_class])) { |
|
| 283 | 283 | $this->_aliases[$for_class] = array(); |
| 284 | 284 | } |
| 285 | 285 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | public function get_alias($class_name = '', $for_class = '') |
| 327 | 327 | { |
| 328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 328 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
| 329 | 329 | return $class_name; |
| 330 | 330 | } |
| 331 | 331 | if ($for_class !== '') { |
@@ -560,10 +560,10 @@ discard block |
||
| 560 | 560 | 'EE_Front_Controller' => 'load_core', |
| 561 | 561 | 'EE_Module_Request_Router' => 'load_core', |
| 562 | 562 | 'EE_Registry' => 'load_core', |
| 563 | - 'EE_Request' => function () use (&$request) { |
|
| 563 | + 'EE_Request' => function() use (&$request) { |
|
| 564 | 564 | return $request; |
| 565 | 565 | }, |
| 566 | - 'EE_Response' => function () use (&$response) { |
|
| 566 | + 'EE_Response' => function() use (&$response) { |
|
| 567 | 567 | return $response; |
| 568 | 568 | }, |
| 569 | 569 | 'EE_Request_Handler' => 'load_core', |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | 'EE_Messages_Queue' => 'load_lib', |
| 581 | 581 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
| 582 | 582 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
| 583 | - 'EE_Messages_Generator' => function () { |
|
| 583 | + 'EE_Messages_Generator' => function() { |
|
| 584 | 584 | return EE_Registry::instance()->load_lib( |
| 585 | 585 | 'Messages_Generator', |
| 586 | 586 | array(), |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | false |
| 589 | 589 | ); |
| 590 | 590 | }, |
| 591 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 591 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
| 592 | 592 | return EE_Registry::instance()->load_lib( |
| 593 | 593 | 'Messages_Template_Defaults', |
| 594 | 594 | $arguments, |
@@ -600,19 +600,19 @@ discard block |
||
| 600 | 600 | 'EEM_Message_Template_Group' => 'load_model', |
| 601 | 601 | 'EEM_Message_Template' => 'load_model', |
| 602 | 602 | //load_helper |
| 603 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 603 | + 'EEH_Parse_Shortcodes' => function() { |
|
| 604 | 604 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
| 605 | 605 | return new EEH_Parse_Shortcodes(); |
| 606 | 606 | } |
| 607 | 607 | return null; |
| 608 | 608 | }, |
| 609 | - 'EE_Template_Config' => function () { |
|
| 609 | + 'EE_Template_Config' => function() { |
|
| 610 | 610 | return EE_Config::instance()->template_settings; |
| 611 | 611 | }, |
| 612 | - 'EE_Currency_Config' => function () { |
|
| 612 | + 'EE_Currency_Config' => function() { |
|
| 613 | 613 | return EE_Config::instance()->currency; |
| 614 | 614 | }, |
| 615 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 615 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
| 616 | 616 | return $loader; |
| 617 | 617 | }, |
| 618 | 618 | ); |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 5 | 5 | |
| 6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -22,652 +22,652 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 33 | - */ |
|
| 34 | - const load_new_object = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 39 | - */ |
|
| 40 | - const load_from_cache = 2; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @type EE_Dependency_Map $_instance |
|
| 44 | - */ |
|
| 45 | - protected static $_instance; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @type EE_Request $request |
|
| 49 | - */ |
|
| 50 | - protected $_request; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @type EE_Response $response |
|
| 54 | - */ |
|
| 55 | - protected $_response; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @type LoaderInterface $loader |
|
| 59 | - */ |
|
| 60 | - protected $loader; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @type array $_dependency_map |
|
| 64 | - */ |
|
| 65 | - protected $_dependency_map = array(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @type array $_class_loaders |
|
| 69 | - */ |
|
| 70 | - protected $_class_loaders = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @type array $_aliases |
|
| 74 | - */ |
|
| 75 | - protected $_aliases = array(); |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * EE_Dependency_Map constructor. |
|
| 81 | - * |
|
| 82 | - * @param EE_Request $request |
|
| 83 | - * @param EE_Response $response |
|
| 84 | - */ |
|
| 85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 86 | - { |
|
| 87 | - $this->_request = $request; |
|
| 88 | - $this->_response = $response; |
|
| 89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 90 | - do_action('EE_Dependency_Map____construct'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @throws InvalidDataTypeException |
|
| 97 | - * @throws InvalidInterfaceException |
|
| 98 | - * @throws InvalidArgumentException |
|
| 99 | - */ |
|
| 100 | - public function initialize() |
|
| 101 | - { |
|
| 102 | - $this->_register_core_dependencies(); |
|
| 103 | - $this->_register_core_class_loaders(); |
|
| 104 | - $this->_register_core_aliases(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @singleton method used to instantiate class object |
|
| 111 | - * @access public |
|
| 112 | - * @param EE_Request $request |
|
| 113 | - * @param EE_Response $response |
|
| 114 | - * @return EE_Dependency_Map |
|
| 115 | - */ |
|
| 116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 117 | - { |
|
| 118 | - // check if class object is instantiated, and instantiated properly |
|
| 119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 121 | - } |
|
| 122 | - return self::$_instance; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param LoaderInterface $loader |
|
| 129 | - */ |
|
| 130 | - public function setLoader(LoaderInterface $loader) |
|
| 131 | - { |
|
| 132 | - $this->loader = $loader; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param string $class |
|
| 139 | - * @param array $dependencies |
|
| 140 | - * @return boolean |
|
| 141 | - */ |
|
| 142 | - public static function register_dependencies($class, $dependencies) |
|
| 143 | - { |
|
| 144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | - // we need to make sure that any aliases used when registering a dependency |
|
| 146 | - // get resolved to the correct class name |
|
| 147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 148 | - $alias = self::$_instance->get_alias($dependency); |
|
| 149 | - unset($dependencies[$dependency]); |
|
| 150 | - $dependencies[$alias] = $load_source; |
|
| 151 | - } |
|
| 152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 153 | - return true; |
|
| 154 | - } |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * @param string $class_name |
|
| 162 | - * @param string $loader |
|
| 163 | - * @return bool |
|
| 164 | - * @throws EE_Error |
|
| 165 | - */ |
|
| 166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 167 | - { |
|
| 168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 169 | - if ( |
|
| 170 | - ! is_callable($loader) |
|
| 171 | - && ( |
|
| 172 | - strpos($loader, 'load_') !== 0 |
|
| 173 | - || ! method_exists('EE_Registry', $loader) |
|
| 174 | - ) |
|
| 175 | - ) { |
|
| 176 | - throw new EE_Error( |
|
| 177 | - sprintf( |
|
| 178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 179 | - $loader |
|
| 180 | - ) |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function dependency_map() |
|
| 197 | - { |
|
| 198 | - return $this->_dependency_map; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 205 | - * |
|
| 206 | - * @param string $class_name |
|
| 207 | - * @return boolean |
|
| 208 | - */ |
|
| 209 | - public function has($class_name = '') |
|
| 210 | - { |
|
| 211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 218 | - * |
|
| 219 | - * @param string $class_name |
|
| 220 | - * @param string $dependency |
|
| 221 | - * @return bool |
|
| 222 | - */ |
|
| 223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 224 | - { |
|
| 225 | - $dependency = $this->get_alias($dependency); |
|
| 226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 227 | - ? true |
|
| 228 | - : false; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 235 | - * |
|
| 236 | - * @param string $class_name |
|
| 237 | - * @param string $dependency |
|
| 238 | - * @return int |
|
| 239 | - */ |
|
| 240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 241 | - { |
|
| 242 | - $dependency = $this->get_alias($dependency); |
|
| 243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 245 | - : EE_Dependency_Map::not_registered; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param string $class_name |
|
| 252 | - * @return string | Closure |
|
| 253 | - */ |
|
| 254 | - public function class_loader($class_name) |
|
| 255 | - { |
|
| 256 | - $class_name = $this->get_alias($class_name); |
|
| 257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @return array |
|
| 264 | - */ |
|
| 265 | - public function class_loaders() |
|
| 266 | - { |
|
| 267 | - return $this->_class_loaders; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * adds an alias for a classname |
|
| 274 | - * |
|
| 275 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 276 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 277 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 278 | - */ |
|
| 279 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 280 | - { |
|
| 281 | - if ($for_class !== '') { |
|
| 282 | - if (! isset($this->_aliases[$for_class])) { |
|
| 283 | - $this->_aliases[$for_class] = array(); |
|
| 284 | - } |
|
| 285 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 286 | - } |
|
| 287 | - $this->_aliases[$class_name] = $alias; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * returns TRUE if the provided class name has an alias |
|
| 294 | - * |
|
| 295 | - * @param string $class_name |
|
| 296 | - * @param string $for_class |
|
| 297 | - * @return bool |
|
| 298 | - */ |
|
| 299 | - public function has_alias($class_name = '', $for_class = '') |
|
| 300 | - { |
|
| 301 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 302 | - || ( |
|
| 303 | - isset($this->_aliases[$class_name]) |
|
| 304 | - && ! is_array($this->_aliases[$class_name]) |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 312 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 313 | - * for example: |
|
| 314 | - * if the following two entries were added to the _aliases array: |
|
| 315 | - * array( |
|
| 316 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 317 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 318 | - * ) |
|
| 319 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 320 | - * to load an instance of 'some\namespace\classname' |
|
| 321 | - * |
|
| 322 | - * @param string $class_name |
|
| 323 | - * @param string $for_class |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function get_alias($class_name = '', $for_class = '') |
|
| 327 | - { |
|
| 328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 329 | - return $class_name; |
|
| 330 | - } |
|
| 331 | - if ($for_class !== '') { |
|
| 332 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 333 | - } |
|
| 334 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 341 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 342 | - * This is done by using the following class constants: |
|
| 343 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 344 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 345 | - */ |
|
| 346 | - protected function _register_core_dependencies() |
|
| 347 | - { |
|
| 348 | - $this->_dependency_map = array( |
|
| 349 | - 'EE_Request_Handler' => array( |
|
| 350 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 351 | - ), |
|
| 352 | - 'EE_System' => array( |
|
| 353 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 354 | - ), |
|
| 355 | - 'EE_Session' => array( |
|
| 356 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 357 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 358 | - ), |
|
| 359 | - 'EE_Cart' => array( |
|
| 360 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 361 | - ), |
|
| 362 | - 'EE_Front_Controller' => array( |
|
| 363 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 365 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 366 | - ), |
|
| 367 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 368 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 369 | - ), |
|
| 370 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 371 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 372 | - ), |
|
| 373 | - 'EE_Message_Resource_Manager' => array( |
|
| 374 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 375 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 376 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 377 | - ), |
|
| 378 | - 'EE_Message_Factory' => array( |
|
| 379 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | - ), |
|
| 381 | - 'EE_messages' => array( |
|
| 382 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 383 | - ), |
|
| 384 | - 'EE_Messages_Generator' => array( |
|
| 385 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 386 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 387 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 388 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 389 | - ), |
|
| 390 | - 'EE_Messages_Processor' => array( |
|
| 391 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 392 | - ), |
|
| 393 | - 'EE_Messages_Queue' => array( |
|
| 394 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 395 | - ), |
|
| 396 | - 'EE_Messages_Template_Defaults' => array( |
|
| 397 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 398 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 399 | - ), |
|
| 400 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 401 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 403 | - ), |
|
| 404 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 405 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | - ), |
|
| 407 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 408 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 409 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 410 | - ), |
|
| 411 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 412 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 413 | - ), |
|
| 414 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 415 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 416 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 417 | - ), |
|
| 418 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 419 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 420 | - ), |
|
| 421 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 422 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 423 | - ), |
|
| 424 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 425 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 426 | - ), |
|
| 427 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 428 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 429 | - ), |
|
| 430 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 431 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 432 | - ), |
|
| 433 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 434 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 435 | - ), |
|
| 436 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 437 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 438 | - ), |
|
| 439 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 440 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 443 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - ), |
|
| 445 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 446 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - ), |
|
| 448 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 449 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 450 | - ), |
|
| 451 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 452 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - ), |
|
| 454 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 455 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 456 | - ), |
|
| 457 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 458 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - ), |
|
| 461 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 464 | - ), |
|
| 465 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 466 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - ), |
|
| 469 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 470 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 472 | - ), |
|
| 473 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 474 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 475 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 476 | - ), |
|
| 477 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 478 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 479 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 480 | - ), |
|
| 481 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 482 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 484 | - ), |
|
| 485 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 486 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 487 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 488 | - ), |
|
| 489 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 490 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 491 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - ), |
|
| 493 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 494 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 495 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - ), |
|
| 497 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 498 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 499 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 502 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - ), |
|
| 504 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 505 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 506 | - ), |
|
| 507 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 508 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | - ), |
|
| 510 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 511 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - ), |
|
| 513 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 514 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | - ), |
|
| 516 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 517 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | - ), |
|
| 519 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 520 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 521 | - ), |
|
| 522 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 523 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 524 | - ), |
|
| 525 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 526 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 527 | - ), |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Registers how core classes are loaded. |
|
| 535 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 536 | - * 'EE_Request_Handler' => 'load_core' |
|
| 537 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 538 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 539 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 540 | - * 'Some_Class' => function () { |
|
| 541 | - * return new Some_Class(); |
|
| 542 | - * }, |
|
| 543 | - * This is required for instantiating dependencies |
|
| 544 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 545 | - * 'Required_Interface' => function () { |
|
| 546 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 547 | - * }, |
|
| 548 | - */ |
|
| 549 | - protected function _register_core_class_loaders() |
|
| 550 | - { |
|
| 551 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 552 | - //be used in a closure. |
|
| 553 | - $request = &$this->_request; |
|
| 554 | - $response = &$this->_response; |
|
| 555 | - $loader = &$this->loader; |
|
| 556 | - $this->_class_loaders = array( |
|
| 557 | - //load_core |
|
| 558 | - 'EE_Capabilities' => 'load_core', |
|
| 559 | - 'EE_Encryption' => 'load_core', |
|
| 560 | - 'EE_Front_Controller' => 'load_core', |
|
| 561 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 562 | - 'EE_Registry' => 'load_core', |
|
| 563 | - 'EE_Request' => function () use (&$request) { |
|
| 564 | - return $request; |
|
| 565 | - }, |
|
| 566 | - 'EE_Response' => function () use (&$response) { |
|
| 567 | - return $response; |
|
| 568 | - }, |
|
| 569 | - 'EE_Request_Handler' => 'load_core', |
|
| 570 | - 'EE_Session' => 'load_core', |
|
| 571 | - //load_lib |
|
| 572 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 573 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 574 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 575 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 576 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 577 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 578 | - 'EE_Message_Repository' => 'load_lib', |
|
| 579 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 580 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 581 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 582 | - 'EE_Messages_Generator' => function () { |
|
| 583 | - return EE_Registry::instance()->load_lib( |
|
| 584 | - 'Messages_Generator', |
|
| 585 | - array(), |
|
| 586 | - false, |
|
| 587 | - false |
|
| 588 | - ); |
|
| 589 | - }, |
|
| 590 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 591 | - return EE_Registry::instance()->load_lib( |
|
| 592 | - 'Messages_Template_Defaults', |
|
| 593 | - $arguments, |
|
| 594 | - false, |
|
| 595 | - false |
|
| 596 | - ); |
|
| 597 | - }, |
|
| 598 | - //load_model |
|
| 599 | - 'EEM_Message_Template_Group' => 'load_model', |
|
| 600 | - 'EEM_Message_Template' => 'load_model', |
|
| 601 | - //load_helper |
|
| 602 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 603 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 604 | - return new EEH_Parse_Shortcodes(); |
|
| 605 | - } |
|
| 606 | - return null; |
|
| 607 | - }, |
|
| 608 | - 'EE_Template_Config' => function () { |
|
| 609 | - return EE_Config::instance()->template_settings; |
|
| 610 | - }, |
|
| 611 | - 'EE_Currency_Config' => function () { |
|
| 612 | - return EE_Config::instance()->currency; |
|
| 613 | - }, |
|
| 614 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 615 | - return $loader; |
|
| 616 | - }, |
|
| 617 | - ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * can be used for supplying alternate names for classes, |
|
| 624 | - * or for connecting interface names to instantiable classes |
|
| 625 | - */ |
|
| 626 | - protected function _register_core_aliases() |
|
| 627 | - { |
|
| 628 | - $this->_aliases = array( |
|
| 629 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 630 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 631 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 632 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 633 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 634 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 635 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 636 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 637 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 638 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 639 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 640 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 641 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 642 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 643 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 644 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 645 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 646 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 647 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 648 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 649 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 650 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 651 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 652 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 653 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 654 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 655 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 656 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 657 | - ); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 664 | - * request Primarily used by unit tests. |
|
| 665 | - */ |
|
| 666 | - public function reset() |
|
| 667 | - { |
|
| 668 | - $this->_register_core_class_loaders(); |
|
| 669 | - $this->_register_core_dependencies(); |
|
| 670 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 33 | + */ |
|
| 34 | + const load_new_object = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 39 | + */ |
|
| 40 | + const load_from_cache = 2; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @type EE_Dependency_Map $_instance |
|
| 44 | + */ |
|
| 45 | + protected static $_instance; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @type EE_Request $request |
|
| 49 | + */ |
|
| 50 | + protected $_request; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @type EE_Response $response |
|
| 54 | + */ |
|
| 55 | + protected $_response; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @type LoaderInterface $loader |
|
| 59 | + */ |
|
| 60 | + protected $loader; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @type array $_dependency_map |
|
| 64 | + */ |
|
| 65 | + protected $_dependency_map = array(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @type array $_class_loaders |
|
| 69 | + */ |
|
| 70 | + protected $_class_loaders = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @type array $_aliases |
|
| 74 | + */ |
|
| 75 | + protected $_aliases = array(); |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * EE_Dependency_Map constructor. |
|
| 81 | + * |
|
| 82 | + * @param EE_Request $request |
|
| 83 | + * @param EE_Response $response |
|
| 84 | + */ |
|
| 85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 86 | + { |
|
| 87 | + $this->_request = $request; |
|
| 88 | + $this->_response = $response; |
|
| 89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 90 | + do_action('EE_Dependency_Map____construct'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @throws InvalidDataTypeException |
|
| 97 | + * @throws InvalidInterfaceException |
|
| 98 | + * @throws InvalidArgumentException |
|
| 99 | + */ |
|
| 100 | + public function initialize() |
|
| 101 | + { |
|
| 102 | + $this->_register_core_dependencies(); |
|
| 103 | + $this->_register_core_class_loaders(); |
|
| 104 | + $this->_register_core_aliases(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @singleton method used to instantiate class object |
|
| 111 | + * @access public |
|
| 112 | + * @param EE_Request $request |
|
| 113 | + * @param EE_Response $response |
|
| 114 | + * @return EE_Dependency_Map |
|
| 115 | + */ |
|
| 116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 117 | + { |
|
| 118 | + // check if class object is instantiated, and instantiated properly |
|
| 119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 121 | + } |
|
| 122 | + return self::$_instance; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param LoaderInterface $loader |
|
| 129 | + */ |
|
| 130 | + public function setLoader(LoaderInterface $loader) |
|
| 131 | + { |
|
| 132 | + $this->loader = $loader; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param string $class |
|
| 139 | + * @param array $dependencies |
|
| 140 | + * @return boolean |
|
| 141 | + */ |
|
| 142 | + public static function register_dependencies($class, $dependencies) |
|
| 143 | + { |
|
| 144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
| 145 | + // we need to make sure that any aliases used when registering a dependency |
|
| 146 | + // get resolved to the correct class name |
|
| 147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 148 | + $alias = self::$_instance->get_alias($dependency); |
|
| 149 | + unset($dependencies[$dependency]); |
|
| 150 | + $dependencies[$alias] = $load_source; |
|
| 151 | + } |
|
| 152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * @param string $class_name |
|
| 162 | + * @param string $loader |
|
| 163 | + * @return bool |
|
| 164 | + * @throws EE_Error |
|
| 165 | + */ |
|
| 166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 167 | + { |
|
| 168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 169 | + if ( |
|
| 170 | + ! is_callable($loader) |
|
| 171 | + && ( |
|
| 172 | + strpos($loader, 'load_') !== 0 |
|
| 173 | + || ! method_exists('EE_Registry', $loader) |
|
| 174 | + ) |
|
| 175 | + ) { |
|
| 176 | + throw new EE_Error( |
|
| 177 | + sprintf( |
|
| 178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
| 179 | + $loader |
|
| 180 | + ) |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function dependency_map() |
|
| 197 | + { |
|
| 198 | + return $this->_dependency_map; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 205 | + * |
|
| 206 | + * @param string $class_name |
|
| 207 | + * @return boolean |
|
| 208 | + */ |
|
| 209 | + public function has($class_name = '') |
|
| 210 | + { |
|
| 211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 218 | + * |
|
| 219 | + * @param string $class_name |
|
| 220 | + * @param string $dependency |
|
| 221 | + * @return bool |
|
| 222 | + */ |
|
| 223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 224 | + { |
|
| 225 | + $dependency = $this->get_alias($dependency); |
|
| 226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 227 | + ? true |
|
| 228 | + : false; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 235 | + * |
|
| 236 | + * @param string $class_name |
|
| 237 | + * @param string $dependency |
|
| 238 | + * @return int |
|
| 239 | + */ |
|
| 240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 241 | + { |
|
| 242 | + $dependency = $this->get_alias($dependency); |
|
| 243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 245 | + : EE_Dependency_Map::not_registered; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param string $class_name |
|
| 252 | + * @return string | Closure |
|
| 253 | + */ |
|
| 254 | + public function class_loader($class_name) |
|
| 255 | + { |
|
| 256 | + $class_name = $this->get_alias($class_name); |
|
| 257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @return array |
|
| 264 | + */ |
|
| 265 | + public function class_loaders() |
|
| 266 | + { |
|
| 267 | + return $this->_class_loaders; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * adds an alias for a classname |
|
| 274 | + * |
|
| 275 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 276 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 277 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 278 | + */ |
|
| 279 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 280 | + { |
|
| 281 | + if ($for_class !== '') { |
|
| 282 | + if (! isset($this->_aliases[$for_class])) { |
|
| 283 | + $this->_aliases[$for_class] = array(); |
|
| 284 | + } |
|
| 285 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 286 | + } |
|
| 287 | + $this->_aliases[$class_name] = $alias; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * returns TRUE if the provided class name has an alias |
|
| 294 | + * |
|
| 295 | + * @param string $class_name |
|
| 296 | + * @param string $for_class |
|
| 297 | + * @return bool |
|
| 298 | + */ |
|
| 299 | + public function has_alias($class_name = '', $for_class = '') |
|
| 300 | + { |
|
| 301 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 302 | + || ( |
|
| 303 | + isset($this->_aliases[$class_name]) |
|
| 304 | + && ! is_array($this->_aliases[$class_name]) |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 312 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 313 | + * for example: |
|
| 314 | + * if the following two entries were added to the _aliases array: |
|
| 315 | + * array( |
|
| 316 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 317 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 318 | + * ) |
|
| 319 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 320 | + * to load an instance of 'some\namespace\classname' |
|
| 321 | + * |
|
| 322 | + * @param string $class_name |
|
| 323 | + * @param string $for_class |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function get_alias($class_name = '', $for_class = '') |
|
| 327 | + { |
|
| 328 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 329 | + return $class_name; |
|
| 330 | + } |
|
| 331 | + if ($for_class !== '') { |
|
| 332 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 333 | + } |
|
| 334 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 341 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 342 | + * This is done by using the following class constants: |
|
| 343 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 344 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 345 | + */ |
|
| 346 | + protected function _register_core_dependencies() |
|
| 347 | + { |
|
| 348 | + $this->_dependency_map = array( |
|
| 349 | + 'EE_Request_Handler' => array( |
|
| 350 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 351 | + ), |
|
| 352 | + 'EE_System' => array( |
|
| 353 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 354 | + ), |
|
| 355 | + 'EE_Session' => array( |
|
| 356 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 357 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 358 | + ), |
|
| 359 | + 'EE_Cart' => array( |
|
| 360 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 361 | + ), |
|
| 362 | + 'EE_Front_Controller' => array( |
|
| 363 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 364 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 365 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 366 | + ), |
|
| 367 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 368 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 369 | + ), |
|
| 370 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 371 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 372 | + ), |
|
| 373 | + 'EE_Message_Resource_Manager' => array( |
|
| 374 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 375 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 376 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 377 | + ), |
|
| 378 | + 'EE_Message_Factory' => array( |
|
| 379 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 380 | + ), |
|
| 381 | + 'EE_messages' => array( |
|
| 382 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 383 | + ), |
|
| 384 | + 'EE_Messages_Generator' => array( |
|
| 385 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 386 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 387 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 388 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 389 | + ), |
|
| 390 | + 'EE_Messages_Processor' => array( |
|
| 391 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 392 | + ), |
|
| 393 | + 'EE_Messages_Queue' => array( |
|
| 394 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 395 | + ), |
|
| 396 | + 'EE_Messages_Template_Defaults' => array( |
|
| 397 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 398 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 399 | + ), |
|
| 400 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 401 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 403 | + ), |
|
| 404 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 405 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | + ), |
|
| 407 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 408 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 409 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 410 | + ), |
|
| 411 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 412 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 413 | + ), |
|
| 414 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 415 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 416 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 417 | + ), |
|
| 418 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 419 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 420 | + ), |
|
| 421 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 422 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 423 | + ), |
|
| 424 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 425 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 426 | + ), |
|
| 427 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 428 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 429 | + ), |
|
| 430 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 431 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 432 | + ), |
|
| 433 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 434 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 435 | + ), |
|
| 436 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 437 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 438 | + ), |
|
| 439 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 440 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 443 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + ), |
|
| 445 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 446 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + ), |
|
| 448 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 449 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 450 | + ), |
|
| 451 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 452 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + ), |
|
| 454 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 455 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 456 | + ), |
|
| 457 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 458 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + ), |
|
| 461 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 464 | + ), |
|
| 465 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 466 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + ), |
|
| 469 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 470 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 472 | + ), |
|
| 473 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 474 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 475 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 476 | + ), |
|
| 477 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 478 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 479 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 480 | + ), |
|
| 481 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 482 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 484 | + ), |
|
| 485 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 486 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 487 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 488 | + ), |
|
| 489 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 490 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 491 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + ), |
|
| 493 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 494 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 495 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + ), |
|
| 497 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 498 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 499 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 502 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + ), |
|
| 504 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 505 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 506 | + ), |
|
| 507 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 508 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | + ), |
|
| 510 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 511 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + ), |
|
| 513 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 514 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 515 | + ), |
|
| 516 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 517 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 518 | + ), |
|
| 519 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 520 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 521 | + ), |
|
| 522 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 523 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 524 | + ), |
|
| 525 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 526 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 527 | + ), |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Registers how core classes are loaded. |
|
| 535 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 536 | + * 'EE_Request_Handler' => 'load_core' |
|
| 537 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 538 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 539 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 540 | + * 'Some_Class' => function () { |
|
| 541 | + * return new Some_Class(); |
|
| 542 | + * }, |
|
| 543 | + * This is required for instantiating dependencies |
|
| 544 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 545 | + * 'Required_Interface' => function () { |
|
| 546 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 547 | + * }, |
|
| 548 | + */ |
|
| 549 | + protected function _register_core_class_loaders() |
|
| 550 | + { |
|
| 551 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 552 | + //be used in a closure. |
|
| 553 | + $request = &$this->_request; |
|
| 554 | + $response = &$this->_response; |
|
| 555 | + $loader = &$this->loader; |
|
| 556 | + $this->_class_loaders = array( |
|
| 557 | + //load_core |
|
| 558 | + 'EE_Capabilities' => 'load_core', |
|
| 559 | + 'EE_Encryption' => 'load_core', |
|
| 560 | + 'EE_Front_Controller' => 'load_core', |
|
| 561 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 562 | + 'EE_Registry' => 'load_core', |
|
| 563 | + 'EE_Request' => function () use (&$request) { |
|
| 564 | + return $request; |
|
| 565 | + }, |
|
| 566 | + 'EE_Response' => function () use (&$response) { |
|
| 567 | + return $response; |
|
| 568 | + }, |
|
| 569 | + 'EE_Request_Handler' => 'load_core', |
|
| 570 | + 'EE_Session' => 'load_core', |
|
| 571 | + //load_lib |
|
| 572 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 573 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 574 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 575 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 576 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 577 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 578 | + 'EE_Message_Repository' => 'load_lib', |
|
| 579 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 580 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 581 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 582 | + 'EE_Messages_Generator' => function () { |
|
| 583 | + return EE_Registry::instance()->load_lib( |
|
| 584 | + 'Messages_Generator', |
|
| 585 | + array(), |
|
| 586 | + false, |
|
| 587 | + false |
|
| 588 | + ); |
|
| 589 | + }, |
|
| 590 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 591 | + return EE_Registry::instance()->load_lib( |
|
| 592 | + 'Messages_Template_Defaults', |
|
| 593 | + $arguments, |
|
| 594 | + false, |
|
| 595 | + false |
|
| 596 | + ); |
|
| 597 | + }, |
|
| 598 | + //load_model |
|
| 599 | + 'EEM_Message_Template_Group' => 'load_model', |
|
| 600 | + 'EEM_Message_Template' => 'load_model', |
|
| 601 | + //load_helper |
|
| 602 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 603 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 604 | + return new EEH_Parse_Shortcodes(); |
|
| 605 | + } |
|
| 606 | + return null; |
|
| 607 | + }, |
|
| 608 | + 'EE_Template_Config' => function () { |
|
| 609 | + return EE_Config::instance()->template_settings; |
|
| 610 | + }, |
|
| 611 | + 'EE_Currency_Config' => function () { |
|
| 612 | + return EE_Config::instance()->currency; |
|
| 613 | + }, |
|
| 614 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
| 615 | + return $loader; |
|
| 616 | + }, |
|
| 617 | + ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * can be used for supplying alternate names for classes, |
|
| 624 | + * or for connecting interface names to instantiable classes |
|
| 625 | + */ |
|
| 626 | + protected function _register_core_aliases() |
|
| 627 | + { |
|
| 628 | + $this->_aliases = array( |
|
| 629 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 630 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 631 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 632 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 633 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 634 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 635 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 636 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 637 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 638 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 639 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 640 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 641 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 642 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 643 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 644 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 645 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 646 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 647 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 648 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 649 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 650 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 651 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 652 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 653 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 654 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 655 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 656 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 657 | + ); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 664 | + * request Primarily used by unit tests. |
|
| 665 | + */ |
|
| 666 | + public function reset() |
|
| 667 | + { |
|
| 668 | + $this->_register_core_class_loaders(); |
|
| 669 | + $this->_register_core_dependencies(); |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | 672 | |
| 673 | 673 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | global $wp_version; |
| 72 | 72 | wp_register_script( |
| 73 | 73 | 'eejs-core', |
| 74 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 74 | + EE_PLUGIN_DIR_URL.'core/services/assets/core_assets/eejs-core.js', |
|
| 75 | 75 | array(), |
| 76 | 76 | EVENT_ESPRESSO_VERSION, |
| 77 | 77 | true |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | //js.api |
| 82 | 82 | wp_register_script( |
| 83 | 83 | 'eejs-api', |
| 84 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 84 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
| 85 | 85 | array('underscore', 'eejs-core'), |
| 86 | 86 | EVENT_ESPRESSO_VERSION, |
| 87 | 87 | true |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
| 90 | 90 | $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
| 91 | 91 | } |
| 92 | - if (! is_admin()) { |
|
| 92 | + if ( ! is_admin()) { |
|
| 93 | 93 | $this->loadCoreCss(); |
| 94 | 94 | } |
| 95 | 95 | $this->loadCoreJs(); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function addTemplate($template_reference, $template_content) |
| 184 | 184 | { |
| 185 | - if (! isset($this->jsdata['templates'])) { |
|
| 185 | + if ( ! isset($this->jsdata['templates'])) { |
|
| 186 | 186 | $this->jsdata['templates'] = array(); |
| 187 | 187 | } |
| 188 | 188 | //no overrides allowed. |
@@ -279,9 +279,9 @@ discard block |
||
| 279 | 279 | private function loadCoreCss() |
| 280 | 280 | { |
| 281 | 281 | if ($this->template_config->enable_default_style) { |
| 282 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 283 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 284 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 282 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 283 | + ? EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css' |
|
| 284 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css'; |
|
| 285 | 285 | wp_register_style( |
| 286 | 286 | 'espresso_default', |
| 287 | 287 | $default_stylesheet_path, |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | if ($this->template_config->custom_style_sheet !== null) { |
| 293 | 293 | wp_register_style( |
| 294 | 294 | 'espresso_custom_css', |
| 295 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 295 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 296 | 296 | array('espresso_default'), |
| 297 | 297 | EVENT_ESPRESSO_VERSION |
| 298 | 298 | ); |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | // load core js |
| 311 | 311 | wp_register_script( |
| 312 | 312 | 'espresso_core', |
| 313 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 313 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 314 | 314 | array('jquery'), |
| 315 | 315 | EVENT_ESPRESSO_VERSION, |
| 316 | 316 | true |
@@ -328,14 +328,14 @@ discard block |
||
| 328 | 328 | // register jQuery Validate and additional methods |
| 329 | 329 | wp_register_script( |
| 330 | 330 | 'jquery-validate', |
| 331 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 331 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 332 | 332 | array('jquery'), |
| 333 | 333 | '1.15.0', |
| 334 | 334 | true |
| 335 | 335 | ); |
| 336 | 336 | wp_register_script( |
| 337 | 337 | 'jquery-validate-extra-methods', |
| 338 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 338 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 339 | 339 | array('jquery', 'jquery-validate'), |
| 340 | 340 | '1.15.0', |
| 341 | 341 | true |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 354 | 354 | wp_register_script( |
| 355 | 355 | 'ee-accounting-core', |
| 356 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 356 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 357 | 357 | array('underscore'), |
| 358 | 358 | '0.3.2', |
| 359 | 359 | true |
| 360 | 360 | ); |
| 361 | 361 | wp_register_script( |
| 362 | 362 | 'ee-accounting', |
| 363 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 363 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 364 | 364 | array('ee-accounting-core'), |
| 365 | 365 | EVENT_ESPRESSO_VERSION, |
| 366 | 366 | true |
@@ -23,394 +23,394 @@ |
||
| 23 | 23 | class Registry |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Template_Config $template_config |
|
| 28 | - */ |
|
| 29 | - protected $template_config; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Currency_Config $currency_config |
|
| 33 | - */ |
|
| 34 | - protected $currency_config; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $jsdata = array(); |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Registry constructor. |
|
| 47 | - * Hooking into WP actions for script registry. |
|
| 48 | - * |
|
| 49 | - * @param EE_Template_Config $template_config |
|
| 50 | - * @param EE_Currency_Config $currency_config |
|
| 51 | - */ |
|
| 52 | - public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config) |
|
| 53 | - { |
|
| 54 | - $this->template_config = $template_config; |
|
| 55 | - $this->currency_config = $currency_config; |
|
| 56 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 57 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 58 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 59 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Callback for the WP script actions. |
|
| 66 | - * Used to register globally accessible core scripts. |
|
| 67 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 68 | - */ |
|
| 69 | - public function scripts() |
|
| 70 | - { |
|
| 71 | - global $wp_version; |
|
| 72 | - wp_register_script( |
|
| 73 | - 'eejs-core', |
|
| 74 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 75 | - array(), |
|
| 76 | - EVENT_ESPRESSO_VERSION, |
|
| 77 | - true |
|
| 78 | - ); |
|
| 79 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 80 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 81 | - //js.api |
|
| 82 | - wp_register_script( |
|
| 83 | - 'eejs-api', |
|
| 84 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 85 | - array('underscore', 'eejs-core'), |
|
| 86 | - EVENT_ESPRESSO_VERSION, |
|
| 87 | - true |
|
| 88 | - ); |
|
| 89 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 90 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 91 | - } |
|
| 92 | - if (! is_admin()) { |
|
| 93 | - $this->loadCoreCss(); |
|
| 94 | - } |
|
| 95 | - $this->loadCoreJs(); |
|
| 96 | - $this->loadJqueryValidate(); |
|
| 97 | - $this->loadAccountingJs(); |
|
| 98 | - $this->loadQtipJs(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Call back for the script print in frontend and backend. |
|
| 105 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 106 | - * |
|
| 107 | - * @since 4.9.31.rc.015 |
|
| 108 | - */ |
|
| 109 | - public function enqueueData() |
|
| 110 | - { |
|
| 111 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 112 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 113 | - $this->localizeAccountingJs(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Used to add data to eejs.data object. |
|
| 120 | - * Note: Overriding existing data is not allowed. |
|
| 121 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 122 | - * If the data you add is something like this: |
|
| 123 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 124 | - * It will be exposed in the page source as: |
|
| 125 | - * eejs.data.my_plugin_data.foo == gar |
|
| 126 | - * |
|
| 127 | - * @param string $key Key used to access your data |
|
| 128 | - * @param string|array $value Value to attach to key |
|
| 129 | - * @throws InvalidArgumentException |
|
| 130 | - */ |
|
| 131 | - public function addData($key, $value) |
|
| 132 | - { |
|
| 133 | - if ($this->verifyDataNotExisting($key)) { |
|
| 134 | - $this->jsdata[$key] = $value; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 142 | - * elements in an array. |
|
| 143 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 144 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 145 | - * object like this, eejs.data.test = [ my_data, |
|
| 146 | - * ] |
|
| 147 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 148 | - * this will throw an exception. |
|
| 149 | - * |
|
| 150 | - * @param string $key Key to attach data to. |
|
| 151 | - * @param string|array $value Value being registered. |
|
| 152 | - * @throws InvalidArgumentException |
|
| 153 | - */ |
|
| 154 | - public function pushData($key, $value) |
|
| 155 | - { |
|
| 156 | - if (isset($this->jsdata[$key]) |
|
| 157 | - && ! is_array($this->jsdata[$key]) |
|
| 158 | - ) { |
|
| 159 | - throw new invalidArgumentException( |
|
| 160 | - sprintf( |
|
| 161 | - __( |
|
| 162 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 26 | + /** |
|
| 27 | + * @var EE_Template_Config $template_config |
|
| 28 | + */ |
|
| 29 | + protected $template_config; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Currency_Config $currency_config |
|
| 33 | + */ |
|
| 34 | + protected $currency_config; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $jsdata = array(); |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Registry constructor. |
|
| 47 | + * Hooking into WP actions for script registry. |
|
| 48 | + * |
|
| 49 | + * @param EE_Template_Config $template_config |
|
| 50 | + * @param EE_Currency_Config $currency_config |
|
| 51 | + */ |
|
| 52 | + public function __construct(EE_Template_Config $template_config, EE_Currency_Config $currency_config) |
|
| 53 | + { |
|
| 54 | + $this->template_config = $template_config; |
|
| 55 | + $this->currency_config = $currency_config; |
|
| 56 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 57 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
| 58 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 59 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Callback for the WP script actions. |
|
| 66 | + * Used to register globally accessible core scripts. |
|
| 67 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 68 | + */ |
|
| 69 | + public function scripts() |
|
| 70 | + { |
|
| 71 | + global $wp_version; |
|
| 72 | + wp_register_script( |
|
| 73 | + 'eejs-core', |
|
| 74 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 75 | + array(), |
|
| 76 | + EVENT_ESPRESSO_VERSION, |
|
| 77 | + true |
|
| 78 | + ); |
|
| 79 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 80 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 81 | + //js.api |
|
| 82 | + wp_register_script( |
|
| 83 | + 'eejs-api', |
|
| 84 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 85 | + array('underscore', 'eejs-core'), |
|
| 86 | + EVENT_ESPRESSO_VERSION, |
|
| 87 | + true |
|
| 88 | + ); |
|
| 89 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
| 90 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 91 | + } |
|
| 92 | + if (! is_admin()) { |
|
| 93 | + $this->loadCoreCss(); |
|
| 94 | + } |
|
| 95 | + $this->loadCoreJs(); |
|
| 96 | + $this->loadJqueryValidate(); |
|
| 97 | + $this->loadAccountingJs(); |
|
| 98 | + $this->loadQtipJs(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Call back for the script print in frontend and backend. |
|
| 105 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
| 106 | + * |
|
| 107 | + * @since 4.9.31.rc.015 |
|
| 108 | + */ |
|
| 109 | + public function enqueueData() |
|
| 110 | + { |
|
| 111 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 112 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 113 | + $this->localizeAccountingJs(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Used to add data to eejs.data object. |
|
| 120 | + * Note: Overriding existing data is not allowed. |
|
| 121 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 122 | + * If the data you add is something like this: |
|
| 123 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 124 | + * It will be exposed in the page source as: |
|
| 125 | + * eejs.data.my_plugin_data.foo == gar |
|
| 126 | + * |
|
| 127 | + * @param string $key Key used to access your data |
|
| 128 | + * @param string|array $value Value to attach to key |
|
| 129 | + * @throws InvalidArgumentException |
|
| 130 | + */ |
|
| 131 | + public function addData($key, $value) |
|
| 132 | + { |
|
| 133 | + if ($this->verifyDataNotExisting($key)) { |
|
| 134 | + $this->jsdata[$key] = $value; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 142 | + * elements in an array. |
|
| 143 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 144 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
| 145 | + * object like this, eejs.data.test = [ my_data, |
|
| 146 | + * ] |
|
| 147 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 148 | + * this will throw an exception. |
|
| 149 | + * |
|
| 150 | + * @param string $key Key to attach data to. |
|
| 151 | + * @param string|array $value Value being registered. |
|
| 152 | + * @throws InvalidArgumentException |
|
| 153 | + */ |
|
| 154 | + public function pushData($key, $value) |
|
| 155 | + { |
|
| 156 | + if (isset($this->jsdata[$key]) |
|
| 157 | + && ! is_array($this->jsdata[$key]) |
|
| 158 | + ) { |
|
| 159 | + throw new invalidArgumentException( |
|
| 160 | + sprintf( |
|
| 161 | + __( |
|
| 162 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 163 | 163 | push values to this data element when it is an array.', |
| 164 | - 'event_espresso' |
|
| 165 | - ), |
|
| 166 | - $key, |
|
| 167 | - __METHOD__ |
|
| 168 | - ) |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - $this->jsdata[$key][] = $value; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Used to set content used by javascript for a template. |
|
| 178 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 179 | - * |
|
| 180 | - * @param string $template_reference |
|
| 181 | - * @param string $template_content |
|
| 182 | - * @throws InvalidArgumentException |
|
| 183 | - */ |
|
| 184 | - public function addTemplate($template_reference, $template_content) |
|
| 185 | - { |
|
| 186 | - if (! isset($this->jsdata['templates'])) { |
|
| 187 | - $this->jsdata['templates'] = array(); |
|
| 188 | - } |
|
| 189 | - //no overrides allowed. |
|
| 190 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 191 | - throw new invalidArgumentException( |
|
| 192 | - sprintf( |
|
| 193 | - __( |
|
| 194 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 195 | - 'event_espresso' |
|
| 196 | - ), |
|
| 197 | - $template_reference |
|
| 198 | - ) |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Retrieve the template content already registered for the given reference. |
|
| 208 | - * |
|
| 209 | - * @param string $template_reference |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public function getTemplate($template_reference) |
|
| 213 | - { |
|
| 214 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 215 | - ? $this->jsdata['templates'][$template_reference] |
|
| 216 | - : ''; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Retrieve registered data. |
|
| 223 | - * |
|
| 224 | - * @param string $key Name of key to attach data to. |
|
| 225 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 226 | - */ |
|
| 227 | - public function getData($key) |
|
| 228 | - { |
|
| 229 | - return isset($this->jsdata[$key]) |
|
| 230 | - ? $this->jsdata[$key] |
|
| 231 | - : false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 238 | - * Overriding data is not allowed. |
|
| 239 | - * |
|
| 240 | - * @param string $key Index for data. |
|
| 241 | - * @return bool If valid then return true. |
|
| 242 | - * @throws InvalidArgumentException if data already exists. |
|
| 243 | - */ |
|
| 244 | - protected function verifyDataNotExisting($key) |
|
| 245 | - { |
|
| 246 | - if (isset($this->jsdata[$key])) { |
|
| 247 | - if (is_array($this->jsdata[$key])) { |
|
| 248 | - throw new InvalidArgumentException( |
|
| 249 | - sprintf( |
|
| 250 | - __( |
|
| 251 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 164 | + 'event_espresso' |
|
| 165 | + ), |
|
| 166 | + $key, |
|
| 167 | + __METHOD__ |
|
| 168 | + ) |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + $this->jsdata[$key][] = $value; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Used to set content used by javascript for a template. |
|
| 178 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 179 | + * |
|
| 180 | + * @param string $template_reference |
|
| 181 | + * @param string $template_content |
|
| 182 | + * @throws InvalidArgumentException |
|
| 183 | + */ |
|
| 184 | + public function addTemplate($template_reference, $template_content) |
|
| 185 | + { |
|
| 186 | + if (! isset($this->jsdata['templates'])) { |
|
| 187 | + $this->jsdata['templates'] = array(); |
|
| 188 | + } |
|
| 189 | + //no overrides allowed. |
|
| 190 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 191 | + throw new invalidArgumentException( |
|
| 192 | + sprintf( |
|
| 193 | + __( |
|
| 194 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 195 | + 'event_espresso' |
|
| 196 | + ), |
|
| 197 | + $template_reference |
|
| 198 | + ) |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Retrieve the template content already registered for the given reference. |
|
| 208 | + * |
|
| 209 | + * @param string $template_reference |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + public function getTemplate($template_reference) |
|
| 213 | + { |
|
| 214 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 215 | + ? $this->jsdata['templates'][$template_reference] |
|
| 216 | + : ''; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Retrieve registered data. |
|
| 223 | + * |
|
| 224 | + * @param string $key Name of key to attach data to. |
|
| 225 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 226 | + */ |
|
| 227 | + public function getData($key) |
|
| 228 | + { |
|
| 229 | + return isset($this->jsdata[$key]) |
|
| 230 | + ? $this->jsdata[$key] |
|
| 231 | + : false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 238 | + * Overriding data is not allowed. |
|
| 239 | + * |
|
| 240 | + * @param string $key Index for data. |
|
| 241 | + * @return bool If valid then return true. |
|
| 242 | + * @throws InvalidArgumentException if data already exists. |
|
| 243 | + */ |
|
| 244 | + protected function verifyDataNotExisting($key) |
|
| 245 | + { |
|
| 246 | + if (isset($this->jsdata[$key])) { |
|
| 247 | + if (is_array($this->jsdata[$key])) { |
|
| 248 | + throw new InvalidArgumentException( |
|
| 249 | + sprintf( |
|
| 250 | + __( |
|
| 251 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 252 | 252 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 253 | 253 | %2$s method to push your value to the array.', |
| 254 | - 'event_espresso' |
|
| 255 | - ), |
|
| 256 | - $key, |
|
| 257 | - 'pushData()' |
|
| 258 | - ) |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - throw new InvalidArgumentException( |
|
| 262 | - sprintf( |
|
| 263 | - __( |
|
| 264 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 254 | + 'event_espresso' |
|
| 255 | + ), |
|
| 256 | + $key, |
|
| 257 | + 'pushData()' |
|
| 258 | + ) |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + throw new InvalidArgumentException( |
|
| 262 | + sprintf( |
|
| 263 | + __( |
|
| 264 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 265 | 265 | allowed. Consider attaching your value to a different key', |
| 266 | - 'event_espresso' |
|
| 267 | - ), |
|
| 268 | - $key |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - return true; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * registers core default stylesheets |
|
| 279 | - */ |
|
| 280 | - private function loadCoreCss() |
|
| 281 | - { |
|
| 282 | - if ($this->template_config->enable_default_style) { |
|
| 283 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 284 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 285 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 286 | - wp_register_style( |
|
| 287 | - 'espresso_default', |
|
| 288 | - $default_stylesheet_path, |
|
| 289 | - array('dashicons'), |
|
| 290 | - EVENT_ESPRESSO_VERSION |
|
| 291 | - ); |
|
| 292 | - //Load custom style sheet if available |
|
| 293 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 294 | - wp_register_style( |
|
| 295 | - 'espresso_custom_css', |
|
| 296 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 297 | - array('espresso_default'), |
|
| 298 | - EVENT_ESPRESSO_VERSION |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * registers core default javascript |
|
| 308 | - */ |
|
| 309 | - private function loadCoreJs() |
|
| 310 | - { |
|
| 311 | - // load core js |
|
| 312 | - wp_register_script( |
|
| 313 | - 'espresso_core', |
|
| 314 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 315 | - array('jquery'), |
|
| 316 | - EVENT_ESPRESSO_VERSION, |
|
| 317 | - true |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * registers jQuery Validate for form validation |
|
| 325 | - */ |
|
| 326 | - private function loadJqueryValidate() |
|
| 327 | - { |
|
| 328 | - // register jQuery Validate and additional methods |
|
| 329 | - wp_register_script( |
|
| 330 | - 'jquery-validate', |
|
| 331 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 332 | - array('jquery'), |
|
| 333 | - '1.15.0', |
|
| 334 | - true |
|
| 335 | - ); |
|
| 336 | - wp_register_script( |
|
| 337 | - 'jquery-validate-extra-methods', |
|
| 338 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 339 | - array('jquery', 'jquery-validate'), |
|
| 340 | - '1.15.0', |
|
| 341 | - true |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * registers accounting.js for performing client-side calculations |
|
| 349 | - */ |
|
| 350 | - private function loadAccountingJs() |
|
| 351 | - { |
|
| 352 | - //accounting.js library |
|
| 353 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 354 | - wp_register_script( |
|
| 355 | - 'ee-accounting-core', |
|
| 356 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 357 | - array('underscore'), |
|
| 358 | - '0.3.2', |
|
| 359 | - true |
|
| 360 | - ); |
|
| 361 | - wp_register_script( |
|
| 362 | - 'ee-accounting', |
|
| 363 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 364 | - array('ee-accounting-core'), |
|
| 365 | - EVENT_ESPRESSO_VERSION, |
|
| 366 | - true |
|
| 367 | - ); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * registers accounting.js for performing client-side calculations |
|
| 374 | - */ |
|
| 375 | - private function localizeAccountingJs() |
|
| 376 | - { |
|
| 377 | - wp_localize_script( |
|
| 378 | - 'ee-accounting', |
|
| 379 | - 'EE_ACCOUNTING_CFG', |
|
| 380 | - array( |
|
| 381 | - 'currency' => array( |
|
| 382 | - 'symbol' => $this->currency_config->sign, |
|
| 383 | - 'format' => array( |
|
| 384 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 385 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 386 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 387 | - ), |
|
| 388 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 389 | - 'thousand' => $this->currency_config->thsnds, |
|
| 390 | - 'precision' => $this->currency_config->dec_plc, |
|
| 391 | - ), |
|
| 392 | - 'number' => array( |
|
| 393 | - 'precision' => 0, |
|
| 394 | - 'thousand' => $this->currency_config->thsnds, |
|
| 395 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 396 | - ), |
|
| 397 | - ) |
|
| 398 | - ); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * registers assets for cleaning your ears |
|
| 405 | - */ |
|
| 406 | - private function loadQtipJs() |
|
| 407 | - { |
|
| 408 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 409 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 410 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 411 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 412 | - } |
|
| 413 | - } |
|
| 266 | + 'event_espresso' |
|
| 267 | + ), |
|
| 268 | + $key |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * registers core default stylesheets |
|
| 279 | + */ |
|
| 280 | + private function loadCoreCss() |
|
| 281 | + { |
|
| 282 | + if ($this->template_config->enable_default_style) { |
|
| 283 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 284 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 285 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
| 286 | + wp_register_style( |
|
| 287 | + 'espresso_default', |
|
| 288 | + $default_stylesheet_path, |
|
| 289 | + array('dashicons'), |
|
| 290 | + EVENT_ESPRESSO_VERSION |
|
| 291 | + ); |
|
| 292 | + //Load custom style sheet if available |
|
| 293 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 294 | + wp_register_style( |
|
| 295 | + 'espresso_custom_css', |
|
| 296 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 297 | + array('espresso_default'), |
|
| 298 | + EVENT_ESPRESSO_VERSION |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * registers core default javascript |
|
| 308 | + */ |
|
| 309 | + private function loadCoreJs() |
|
| 310 | + { |
|
| 311 | + // load core js |
|
| 312 | + wp_register_script( |
|
| 313 | + 'espresso_core', |
|
| 314 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 315 | + array('jquery'), |
|
| 316 | + EVENT_ESPRESSO_VERSION, |
|
| 317 | + true |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * registers jQuery Validate for form validation |
|
| 325 | + */ |
|
| 326 | + private function loadJqueryValidate() |
|
| 327 | + { |
|
| 328 | + // register jQuery Validate and additional methods |
|
| 329 | + wp_register_script( |
|
| 330 | + 'jquery-validate', |
|
| 331 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 332 | + array('jquery'), |
|
| 333 | + '1.15.0', |
|
| 334 | + true |
|
| 335 | + ); |
|
| 336 | + wp_register_script( |
|
| 337 | + 'jquery-validate-extra-methods', |
|
| 338 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 339 | + array('jquery', 'jquery-validate'), |
|
| 340 | + '1.15.0', |
|
| 341 | + true |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * registers accounting.js for performing client-side calculations |
|
| 349 | + */ |
|
| 350 | + private function loadAccountingJs() |
|
| 351 | + { |
|
| 352 | + //accounting.js library |
|
| 353 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 354 | + wp_register_script( |
|
| 355 | + 'ee-accounting-core', |
|
| 356 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 357 | + array('underscore'), |
|
| 358 | + '0.3.2', |
|
| 359 | + true |
|
| 360 | + ); |
|
| 361 | + wp_register_script( |
|
| 362 | + 'ee-accounting', |
|
| 363 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 364 | + array('ee-accounting-core'), |
|
| 365 | + EVENT_ESPRESSO_VERSION, |
|
| 366 | + true |
|
| 367 | + ); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * registers accounting.js for performing client-side calculations |
|
| 374 | + */ |
|
| 375 | + private function localizeAccountingJs() |
|
| 376 | + { |
|
| 377 | + wp_localize_script( |
|
| 378 | + 'ee-accounting', |
|
| 379 | + 'EE_ACCOUNTING_CFG', |
|
| 380 | + array( |
|
| 381 | + 'currency' => array( |
|
| 382 | + 'symbol' => $this->currency_config->sign, |
|
| 383 | + 'format' => array( |
|
| 384 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 385 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 386 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 387 | + ), |
|
| 388 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 389 | + 'thousand' => $this->currency_config->thsnds, |
|
| 390 | + 'precision' => $this->currency_config->dec_plc, |
|
| 391 | + ), |
|
| 392 | + 'number' => array( |
|
| 393 | + 'precision' => 0, |
|
| 394 | + 'thousand' => $this->currency_config->thsnds, |
|
| 395 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 396 | + ), |
|
| 397 | + ) |
|
| 398 | + ); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * registers assets for cleaning your ears |
|
| 405 | + */ |
|
| 406 | + private function loadQtipJs() |
|
| 407 | + { |
|
| 408 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 409 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 410 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 411 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | 415 | |
| 416 | 416 | |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidEntityException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('No direct script access allowed'); |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | |
@@ -20,1854 +20,1854 @@ discard block |
||
| 20 | 20 | class EED_Single_Page_Checkout extends EED_Module |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * $_initialized - has the SPCO controller already been initialized ? |
|
| 25 | - * |
|
| 26 | - * @access private |
|
| 27 | - * @var bool $_initialized |
|
| 28 | - */ |
|
| 29 | - private static $_initialized = false; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 34 | - * |
|
| 35 | - * @access private |
|
| 36 | - * @var bool $_valid_checkout |
|
| 37 | - */ |
|
| 38 | - private static $_checkout_verified = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * $_reg_steps_array - holds initial array of reg steps |
|
| 42 | - * |
|
| 43 | - * @access private |
|
| 44 | - * @var array $_reg_steps_array |
|
| 45 | - */ |
|
| 46 | - private static $_reg_steps_array = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 50 | - * |
|
| 51 | - * @access public |
|
| 52 | - * @var EE_Checkout $checkout |
|
| 53 | - */ |
|
| 54 | - public $checkout; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return EED_Module|EED_Single_Page_Checkout |
|
| 60 | - */ |
|
| 61 | - public static function instance() |
|
| 62 | - { |
|
| 63 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 64 | - return parent::get_instance(__CLASS__); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return EE_CART |
|
| 71 | - */ |
|
| 72 | - public function cart() |
|
| 73 | - { |
|
| 74 | - return $this->checkout->cart; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return EE_Transaction |
|
| 81 | - */ |
|
| 82 | - public function transaction() |
|
| 83 | - { |
|
| 84 | - return $this->checkout->transaction; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return void |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - public static function set_hooks() |
|
| 97 | - { |
|
| 98 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return void |
|
| 108 | - * @throws EE_Error |
|
| 109 | - */ |
|
| 110 | - public static function set_hooks_admin() |
|
| 111 | - { |
|
| 112 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 113 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - // going to start an output buffer in case anything gets accidentally output |
|
| 117 | - // that might disrupt our JSON response |
|
| 118 | - ob_start(); |
|
| 119 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 120 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 121 | - // set ajax hooks |
|
| 122 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 123 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 124 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 125 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 126 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 127 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * process ajax request |
|
| 134 | - * |
|
| 135 | - * @param string $ajax_action |
|
| 136 | - * @throws EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function process_ajax_request($ajax_action) |
|
| 139 | - { |
|
| 140 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 141 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * ajax display registration step |
|
| 148 | - * |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - public static function display_reg_step() |
|
| 152 | - { |
|
| 153 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * ajax process registration step |
|
| 160 | - * |
|
| 161 | - * @throws EE_Error |
|
| 162 | - */ |
|
| 163 | - public static function process_reg_step() |
|
| 164 | - { |
|
| 165 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * ajax process registration step |
|
| 172 | - * |
|
| 173 | - * @throws EE_Error |
|
| 174 | - */ |
|
| 175 | - public static function update_reg_step() |
|
| 176 | - { |
|
| 177 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * update_checkout |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @return void |
|
| 187 | - * @throws EE_Error |
|
| 188 | - */ |
|
| 189 | - public static function update_checkout() |
|
| 190 | - { |
|
| 191 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * load_request_handler |
|
| 198 | - * |
|
| 199 | - * @access public |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - public static function load_request_handler() |
|
| 203 | - { |
|
| 204 | - // load core Request_Handler class |
|
| 205 | - if (EE_Registry::instance()->REQ !== null) { |
|
| 206 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * set_definitions |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @return void |
|
| 217 | - * @throws EE_Error |
|
| 218 | - */ |
|
| 219 | - public static function set_definitions() |
|
| 220 | - { |
|
| 221 | - if(defined('SPCO_BASE_PATH')) { |
|
| 222 | - return; |
|
| 223 | - } |
|
| 224 | - define( |
|
| 225 | - 'SPCO_BASE_PATH', |
|
| 226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
| 227 | - ); |
|
| 228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 235 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 236 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 237 | - 'event_espresso'), |
|
| 238 | - '<h4 class="important-notice">', |
|
| 239 | - '</h4>', |
|
| 240 | - '<br />', |
|
| 241 | - '<p>', |
|
| 242 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 243 | - '">', |
|
| 244 | - '</a>', |
|
| 245 | - '</p>' |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * load_reg_steps |
|
| 253 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 254 | - * |
|
| 255 | - * @access private |
|
| 256 | - * @throws EE_Error |
|
| 257 | - */ |
|
| 258 | - public static function load_reg_steps() |
|
| 259 | - { |
|
| 260 | - static $reg_steps_loaded = false; |
|
| 261 | - if ($reg_steps_loaded) { |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - // filter list of reg_steps |
|
| 265 | - $reg_steps_to_load = (array)apply_filters( |
|
| 266 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 267 | - EED_Single_Page_Checkout::get_reg_steps() |
|
| 268 | - ); |
|
| 269 | - // sort by key (order) |
|
| 270 | - ksort($reg_steps_to_load); |
|
| 271 | - // loop through folders |
|
| 272 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 273 | - // we need a |
|
| 274 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 275 | - // copy over to the reg_steps_array |
|
| 276 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 277 | - // register custom key route for each reg step |
|
| 278 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 279 | - EE_Config::register_route( |
|
| 280 | - $reg_step['slug'], |
|
| 281 | - 'EED_Single_Page_Checkout', |
|
| 282 | - 'run', |
|
| 283 | - 'step' |
|
| 284 | - ); |
|
| 285 | - // add AJAX or other hooks |
|
| 286 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 287 | - // setup autoloaders if necessary |
|
| 288 | - if ( ! class_exists($reg_step['class_name'])) { |
|
| 289 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
| 290 | - $reg_step['file_path'], |
|
| 291 | - true |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 295 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - $reg_steps_loaded = true; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * get_reg_steps |
|
| 307 | - * |
|
| 308 | - * @access public |
|
| 309 | - * @return array |
|
| 310 | - */ |
|
| 311 | - public static function get_reg_steps() |
|
| 312 | - { |
|
| 313 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 314 | - if (empty($reg_steps)) { |
|
| 315 | - $reg_steps = array( |
|
| 316 | - 10 => array( |
|
| 317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 318 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 319 | - 'slug' => 'attendee_information', |
|
| 320 | - 'has_hooks' => false, |
|
| 321 | - ), |
|
| 322 | - 20 => array( |
|
| 323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 324 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
| 325 | - 'slug' => 'registration_confirmation', |
|
| 326 | - 'has_hooks' => false, |
|
| 327 | - ), |
|
| 328 | - 30 => array( |
|
| 329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 330 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 331 | - 'slug' => 'payment_options', |
|
| 332 | - 'has_hooks' => true, |
|
| 333 | - ), |
|
| 334 | - 999 => array( |
|
| 335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 336 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 337 | - 'slug' => 'finalize_registration', |
|
| 338 | - 'has_hooks' => false, |
|
| 339 | - ), |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - return $reg_steps; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * registration_checkout_for_admin |
|
| 349 | - * |
|
| 350 | - * @access public |
|
| 351 | - * @return string |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public static function registration_checkout_for_admin() |
|
| 355 | - { |
|
| 356 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 357 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 358 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 359 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 360 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 361 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 362 | - return EE_Registry::instance()->REQ->get_output(); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * process_registration_from_admin |
|
| 369 | - * |
|
| 370 | - * @access public |
|
| 371 | - * @return \EE_Transaction |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public static function process_registration_from_admin() |
|
| 375 | - { |
|
| 376 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 377 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 378 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 379 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 380 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 381 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 382 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 383 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 384 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 385 | - if ($final_reg_step->process_reg_step()) { |
|
| 386 | - $final_reg_step->set_completed(); |
|
| 387 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 388 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * run |
|
| 399 | - * |
|
| 400 | - * @access public |
|
| 401 | - * @param WP_Query $WP_Query |
|
| 402 | - * @return void |
|
| 403 | - * @throws EE_Error |
|
| 404 | - */ |
|
| 405 | - public function run($WP_Query) |
|
| 406 | - { |
|
| 407 | - if ( |
|
| 408 | - $WP_Query instanceof WP_Query |
|
| 409 | - && $WP_Query->is_main_query() |
|
| 410 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 411 | - && $this->_is_reg_checkout() |
|
| 412 | - ) { |
|
| 413 | - $this->_initialize(); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * determines whether current url matches reg page url |
|
| 421 | - * |
|
| 422 | - * @return bool |
|
| 423 | - */ |
|
| 424 | - protected function _is_reg_checkout() |
|
| 425 | - { |
|
| 426 | - // get current permalink for reg page without any extra query args |
|
| 427 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 428 | - // get request URI for current request, but without the scheme or host |
|
| 429 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 430 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
| 431 | - // get array of query args from the current request URI |
|
| 432 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 433 | - // grab page id if it is set |
|
| 434 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 435 | - // and remove the page id from the query args (we will re-add it later) |
|
| 436 | - unset($query_args['page_id']); |
|
| 437 | - // now strip all query args from current request URI |
|
| 438 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
| 439 | - // and re-add the page id if it was set |
|
| 440 | - if ($page_id) { |
|
| 441 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 442 | - } |
|
| 443 | - // remove slashes and ? |
|
| 444 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
| 445 | - // is current request URI part of the known full reg page URL ? |
|
| 446 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @param WP_Query $wp_query |
|
| 453 | - * @return void |
|
| 454 | - * @throws EE_Error |
|
| 455 | - */ |
|
| 456 | - public static function init($wp_query) |
|
| 457 | - { |
|
| 458 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * _initialize - initial module setup |
|
| 465 | - * |
|
| 466 | - * @access private |
|
| 467 | - * @throws EE_Error |
|
| 468 | - * @return void |
|
| 469 | - */ |
|
| 470 | - private function _initialize() |
|
| 471 | - { |
|
| 472 | - // ensure SPCO doesn't run twice |
|
| 473 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
| 474 | - return; |
|
| 475 | - } |
|
| 476 | - try { |
|
| 477 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 478 | - $this->_verify_session(); |
|
| 479 | - // setup the EE_Checkout object |
|
| 480 | - $this->checkout = $this->_initialize_checkout(); |
|
| 481 | - // filter checkout |
|
| 482 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 483 | - // get the $_GET |
|
| 484 | - $this->_get_request_vars(); |
|
| 485 | - if ($this->_block_bots()) { |
|
| 486 | - return; |
|
| 487 | - } |
|
| 488 | - // filter continue_reg |
|
| 489 | - $this->checkout->continue_reg = apply_filters( |
|
| 490 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
| 491 | - true, |
|
| 492 | - $this->checkout |
|
| 493 | - ); |
|
| 494 | - // load the reg steps array |
|
| 495 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 496 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 497 | - return; |
|
| 498 | - } |
|
| 499 | - // set the current step |
|
| 500 | - $this->checkout->set_current_step($this->checkout->step); |
|
| 501 | - // and the next step |
|
| 502 | - $this->checkout->set_next_step(); |
|
| 503 | - // verify that everything has been setup correctly |
|
| 504 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 505 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 506 | - return; |
|
| 507 | - } |
|
| 508 | - // lock the transaction |
|
| 509 | - $this->checkout->transaction->lock(); |
|
| 510 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
| 511 | - $this->checkout->refresh_all_entities(); |
|
| 512 | - // set amount owing |
|
| 513 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 514 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 515 | - $this->_initialize_reg_steps(); |
|
| 516 | - // DEBUG LOG |
|
| 517 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 518 | - // get reg form |
|
| 519 | - if( ! $this->_check_form_submission()) { |
|
| 520 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 521 | - return; |
|
| 522 | - } |
|
| 523 | - // checkout the action!!! |
|
| 524 | - $this->_process_form_action(); |
|
| 525 | - // add some style and make it dance |
|
| 526 | - $this->add_styles_and_scripts(); |
|
| 527 | - // kk... SPCO has successfully run |
|
| 528 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 529 | - // set no cache headers and constants |
|
| 530 | - EE_System::do_not_cache(); |
|
| 531 | - // add anchor |
|
| 532 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 533 | - // remove transaction lock |
|
| 534 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
| 535 | - } catch (Exception $e) { |
|
| 536 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * _verify_session |
|
| 544 | - * checks that the session is valid and not expired |
|
| 545 | - * |
|
| 546 | - * @access private |
|
| 547 | - * @throws EE_Error |
|
| 548 | - */ |
|
| 549 | - private function _verify_session() |
|
| 550 | - { |
|
| 551 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 552 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
| 553 | - } |
|
| 554 | - // is session still valid ? |
|
| 555 | - if ( |
|
| 556 | - EE_Registry::instance()->SSN->expired() |
|
| 557 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
| 558 | - ) { |
|
| 559 | - $this->checkout = new EE_Checkout(); |
|
| 560 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 561 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
| 562 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
| 563 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
| 564 | - EE_Error::add_attention( |
|
| 565 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
| 566 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 567 | - ); |
|
| 568 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * _initialize_checkout |
|
| 576 | - * loads and instantiates EE_Checkout |
|
| 577 | - * |
|
| 578 | - * @access private |
|
| 579 | - * @throws EE_Error |
|
| 580 | - * @return EE_Checkout |
|
| 581 | - */ |
|
| 582 | - private function _initialize_checkout() |
|
| 583 | - { |
|
| 584 | - // look in session for existing checkout |
|
| 585 | - /** @type EE_Checkout $checkout */ |
|
| 586 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 587 | - // verify |
|
| 588 | - if ( ! $checkout instanceof EE_Checkout) { |
|
| 589 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 590 | - $checkout = EE_Registry::instance()->load_file( |
|
| 591 | - SPCO_INC_PATH, |
|
| 592 | - 'EE_Checkout', |
|
| 593 | - 'class', array(), |
|
| 594 | - false |
|
| 595 | - ); |
|
| 596 | - } else { |
|
| 597 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 598 | - $this->unlock_transaction(); |
|
| 599 | - wp_safe_redirect($checkout->redirect_url); |
|
| 600 | - exit(); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 604 | - // verify again |
|
| 605 | - if ( ! $checkout instanceof EE_Checkout) { |
|
| 606 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 607 | - } |
|
| 608 | - // reset anything that needs a clean slate for each request |
|
| 609 | - $checkout->reset_for_current_request(); |
|
| 610 | - return $checkout; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * _get_request_vars |
|
| 617 | - * |
|
| 618 | - * @access private |
|
| 619 | - * @return void |
|
| 620 | - * @throws EE_Error |
|
| 621 | - */ |
|
| 622 | - private function _get_request_vars() |
|
| 623 | - { |
|
| 624 | - // load classes |
|
| 625 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 626 | - //make sure this request is marked as belonging to EE |
|
| 627 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 628 | - // which step is being requested ? |
|
| 629 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 630 | - // which step is being edited ? |
|
| 631 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 632 | - // and what we're doing on the current step |
|
| 633 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 634 | - // timestamp |
|
| 635 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 636 | - // returning to edit ? |
|
| 637 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 638 | - // or some other kind of revisit ? |
|
| 639 | - $this->checkout->revisit = filter_var( |
|
| 640 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
| 641 | - FILTER_VALIDATE_BOOLEAN |
|
| 642 | - ); |
|
| 643 | - // and whether or not to generate a reg form for this request |
|
| 644 | - $this->checkout->generate_reg_form = filter_var( |
|
| 645 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
| 646 | - FILTER_VALIDATE_BOOLEAN |
|
| 647 | - ); |
|
| 648 | - // and whether or not to process a reg form submission for this request |
|
| 649 | - $this->checkout->process_form_submission = filter_var( |
|
| 650 | - EE_Registry::instance()->REQ->get( |
|
| 651 | - 'process_form_submission', |
|
| 652 | - $this->checkout->action === 'process_reg_step' |
|
| 653 | - ), |
|
| 654 | - FILTER_VALIDATE_BOOLEAN |
|
| 655 | - ); |
|
| 656 | - $this->checkout->process_form_submission = filter_var( |
|
| 657 | - $this->checkout->action !== 'display_spco_reg_step' |
|
| 658 | - ? $this->checkout->process_form_submission |
|
| 659 | - : false, |
|
| 660 | - FILTER_VALIDATE_BOOLEAN |
|
| 661 | - ); |
|
| 662 | - // $this->_display_request_vars(); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * _display_request_vars |
|
| 669 | - * |
|
| 670 | - * @access protected |
|
| 671 | - * @return void |
|
| 672 | - */ |
|
| 673 | - protected function _display_request_vars() |
|
| 674 | - { |
|
| 675 | - if ( ! WP_DEBUG) { |
|
| 676 | - return; |
|
| 677 | - } |
|
| 678 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 679 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 680 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 681 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 682 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 683 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 684 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 685 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * _block_bots |
|
| 692 | - * checks that the incoming request has either of the following set: |
|
| 693 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 694 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 695 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 696 | - * then where you coming from man? |
|
| 697 | - * |
|
| 698 | - * @return boolean |
|
| 699 | - */ |
|
| 700 | - private function _block_bots() |
|
| 701 | - { |
|
| 702 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 703 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 704 | - return true; |
|
| 705 | - } |
|
| 706 | - return false; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * _get_first_step |
|
| 713 | - * gets slug for first step in $_reg_steps_array |
|
| 714 | - * |
|
| 715 | - * @access private |
|
| 716 | - * @throws EE_Error |
|
| 717 | - * @return string |
|
| 718 | - */ |
|
| 719 | - private function _get_first_step() |
|
| 720 | - { |
|
| 721 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 722 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * _load_and_instantiate_reg_steps |
|
| 729 | - * instantiates each reg step based on the loaded reg_steps array |
|
| 730 | - * |
|
| 731 | - * @access private |
|
| 732 | - * @throws EE_Error |
|
| 733 | - * @return bool |
|
| 734 | - */ |
|
| 735 | - private function _load_and_instantiate_reg_steps() |
|
| 736 | - { |
|
| 737 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
| 738 | - // have reg_steps already been instantiated ? |
|
| 739 | - if ( |
|
| 740 | - empty($this->checkout->reg_steps) |
|
| 741 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 742 | - ) { |
|
| 743 | - // if not, then loop through raw reg steps array |
|
| 744 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 745 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 746 | - return false; |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
| 750 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
| 751 | - // skip the registration_confirmation page ? |
|
| 752 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 753 | - // just remove it from the reg steps array |
|
| 754 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 755 | - } else if ( |
|
| 756 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 757 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 758 | - ) { |
|
| 759 | - // set the order to something big like 100 |
|
| 760 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 761 | - } |
|
| 762 | - // filter the array for good luck |
|
| 763 | - $this->checkout->reg_steps = apply_filters( |
|
| 764 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 765 | - $this->checkout->reg_steps |
|
| 766 | - ); |
|
| 767 | - // finally re-sort based on the reg step class order properties |
|
| 768 | - $this->checkout->sort_reg_steps(); |
|
| 769 | - } else { |
|
| 770 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 771 | - // set all current step stati to FALSE |
|
| 772 | - $reg_step->set_is_current_step(false); |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - if (empty($this->checkout->reg_steps)) { |
|
| 776 | - EE_Error::add_error( |
|
| 777 | - __('No Reg Steps were loaded..', 'event_espresso'), |
|
| 778 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 779 | - ); |
|
| 780 | - return false; |
|
| 781 | - } |
|
| 782 | - // make reg step details available to JS |
|
| 783 | - $this->checkout->set_reg_step_JSON_info(); |
|
| 784 | - return true; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * _load_and_instantiate_reg_step |
|
| 791 | - * |
|
| 792 | - * @access private |
|
| 793 | - * @param array $reg_step |
|
| 794 | - * @param int $order |
|
| 795 | - * @return bool |
|
| 796 | - */ |
|
| 797 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 798 | - { |
|
| 799 | - // we need a file_path, class_name, and slug to add a reg step |
|
| 800 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 801 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 802 | - if ( |
|
| 803 | - $this->checkout->reg_url_link |
|
| 804 | - && $this->checkout->step !== $reg_step['slug'] |
|
| 805 | - && $reg_step['slug'] !== 'finalize_registration' |
|
| 806 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
| 807 | - && apply_filters( |
|
| 808 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
| 809 | - true, |
|
| 810 | - $reg_step, |
|
| 811 | - $this->checkout |
|
| 812 | - ) |
|
| 813 | - ) { |
|
| 814 | - return true; |
|
| 815 | - } |
|
| 816 | - // instantiate step class using file path and class name |
|
| 817 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 818 | - $reg_step['file_path'], |
|
| 819 | - $reg_step['class_name'], |
|
| 820 | - 'class', |
|
| 821 | - $this->checkout, |
|
| 822 | - false |
|
| 823 | - ); |
|
| 824 | - // did we gets the goods ? |
|
| 825 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 826 | - // set reg step order based on config |
|
| 827 | - $reg_step_obj->set_order($order); |
|
| 828 | - // add instantiated reg step object to the master reg steps array |
|
| 829 | - $this->checkout->add_reg_step($reg_step_obj); |
|
| 830 | - } else { |
|
| 831 | - EE_Error::add_error( |
|
| 832 | - __('The current step could not be set.', 'event_espresso'), |
|
| 833 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 834 | - ); |
|
| 835 | - return false; |
|
| 836 | - } |
|
| 837 | - } else { |
|
| 838 | - if (WP_DEBUG) { |
|
| 839 | - EE_Error::add_error( |
|
| 840 | - sprintf( |
|
| 841 | - __( |
|
| 842 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
| 843 | - 'event_espresso' |
|
| 844 | - ), |
|
| 845 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 846 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 847 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 848 | - '<ul>', |
|
| 849 | - '<li>', |
|
| 850 | - '</li>', |
|
| 851 | - '</ul>' |
|
| 852 | - ), |
|
| 853 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 854 | - ); |
|
| 855 | - } |
|
| 856 | - return false; |
|
| 857 | - } |
|
| 858 | - return true; |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * _verify_transaction_and_get_registrations |
|
| 864 | - * |
|
| 865 | - * @access private |
|
| 866 | - * @return bool |
|
| 867 | - * @throws InvalidDataTypeException |
|
| 868 | - * @throws InvalidEntityException |
|
| 869 | - * @throws EE_Error |
|
| 870 | - */ |
|
| 871 | - private function _verify_transaction_and_get_registrations() |
|
| 872 | - { |
|
| 873 | - // was there already a valid transaction in the checkout from the session ? |
|
| 874 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 875 | - // get transaction from db or session |
|
| 876 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 877 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 878 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 879 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 880 | - EE_Error::add_error( |
|
| 881 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
| 882 | - 'event_espresso'), |
|
| 883 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 884 | - ); |
|
| 885 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 886 | - // add some style and make it dance |
|
| 887 | - $this->add_styles_and_scripts(); |
|
| 888 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 889 | - return false; |
|
| 890 | - } |
|
| 891 | - // and the registrations for the transaction |
|
| 892 | - $this->_get_registrations($this->checkout->transaction); |
|
| 893 | - } |
|
| 894 | - return true; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * _get_transaction_and_cart_for_previous_visit |
|
| 901 | - * |
|
| 902 | - * @access private |
|
| 903 | - * @return mixed EE_Transaction|NULL |
|
| 904 | - */ |
|
| 905 | - private function _get_transaction_and_cart_for_previous_visit() |
|
| 906 | - { |
|
| 907 | - /** @var $TXN_model EEM_Transaction */ |
|
| 908 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 909 | - // because the reg_url_link is present in the request, |
|
| 910 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 911 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 912 | - // verify transaction |
|
| 913 | - if ($transaction instanceof EE_Transaction) { |
|
| 914 | - // and get the cart that was used for that transaction |
|
| 915 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 916 | - return $transaction; |
|
| 917 | - } |
|
| 918 | - EE_Error::add_error( |
|
| 919 | - __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
| 920 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 921 | - ); |
|
| 922 | - return null; |
|
| 923 | - |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * _get_cart_for_transaction |
|
| 930 | - * |
|
| 931 | - * @access private |
|
| 932 | - * @param EE_Transaction $transaction |
|
| 933 | - * @return EE_Cart |
|
| 934 | - */ |
|
| 935 | - private function _get_cart_for_transaction($transaction) |
|
| 936 | - { |
|
| 937 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * get_cart_for_transaction |
|
| 944 | - * |
|
| 945 | - * @access public |
|
| 946 | - * @param EE_Transaction $transaction |
|
| 947 | - * @return EE_Cart |
|
| 948 | - */ |
|
| 949 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 950 | - { |
|
| 951 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - /** |
|
| 957 | - * _get_transaction_and_cart_for_current_session |
|
| 958 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 959 | - * |
|
| 960 | - * @access private |
|
| 961 | - * @return EE_Transaction |
|
| 962 | - * @throws EE_Error |
|
| 963 | - */ |
|
| 964 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 965 | - { |
|
| 966 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 967 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 968 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 969 | - // and then create a new transaction |
|
| 970 | - $transaction = $this->_initialize_transaction(); |
|
| 971 | - // verify transaction |
|
| 972 | - if ($transaction instanceof EE_Transaction) { |
|
| 973 | - // save it so that we have an ID for other objects to use |
|
| 974 | - $transaction->save(); |
|
| 975 | - // and save TXN data to the cart |
|
| 976 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 977 | - } else { |
|
| 978 | - EE_Error::add_error( |
|
| 979 | - __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
| 980 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 981 | - ); |
|
| 982 | - } |
|
| 983 | - return $transaction; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 990 | - * |
|
| 991 | - * @access private |
|
| 992 | - * @return mixed EE_Transaction|NULL |
|
| 993 | - */ |
|
| 994 | - private function _initialize_transaction() |
|
| 995 | - { |
|
| 996 | - try { |
|
| 997 | - // ensure cart totals have been calculated |
|
| 998 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 999 | - // grab the cart grand total |
|
| 1000 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 1001 | - // create new TXN |
|
| 1002 | - $transaction = EE_Transaction::new_instance( |
|
| 1003 | - array( |
|
| 1004 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 1005 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 1006 | - 'TXN_paid' => 0, |
|
| 1007 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 1008 | - ) |
|
| 1009 | - ); |
|
| 1010 | - // save it so that we have an ID for other objects to use |
|
| 1011 | - $transaction->save(); |
|
| 1012 | - // set cron job for following up on TXNs after their session has expired |
|
| 1013 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
| 1014 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
| 1015 | - $transaction->ID() |
|
| 1016 | - ); |
|
| 1017 | - return $transaction; |
|
| 1018 | - } catch (Exception $e) { |
|
| 1019 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1020 | - } |
|
| 1021 | - return null; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * _get_registrations |
|
| 1027 | - * |
|
| 1028 | - * @access private |
|
| 1029 | - * @param EE_Transaction $transaction |
|
| 1030 | - * @return void |
|
| 1031 | - * @throws InvalidDataTypeException |
|
| 1032 | - * @throws InvalidEntityException |
|
| 1033 | - * @throws EE_Error |
|
| 1034 | - */ |
|
| 1035 | - private function _get_registrations(EE_Transaction $transaction) |
|
| 1036 | - { |
|
| 1037 | - // first step: grab the registrants { : o |
|
| 1038 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
| 1039 | - // verify registrations have been set |
|
| 1040 | - if (empty($registrations)) { |
|
| 1041 | - // if no cached registrations, then check the db |
|
| 1042 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1043 | - // still nothing ? well as long as this isn't a revisit |
|
| 1044 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 1045 | - // generate new registrations from scratch |
|
| 1046 | - $registrations = $this->_initialize_registrations($transaction); |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - // sort by their original registration order |
|
| 1050 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 1051 | - // then loop thru the array |
|
| 1052 | - foreach ($registrations as $registration) { |
|
| 1053 | - // verify each registration |
|
| 1054 | - if ($registration instanceof EE_Registration) { |
|
| 1055 | - // we display all attendee info for the primary registrant |
|
| 1056 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 1057 | - && $registration->is_primary_registrant() |
|
| 1058 | - ) { |
|
| 1059 | - $this->checkout->primary_revisit = true; |
|
| 1060 | - break; |
|
| 1061 | - } |
|
| 1062 | - if ($this->checkout->revisit |
|
| 1063 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
| 1064 | - ) { |
|
| 1065 | - // but hide info if it doesn't belong to you |
|
| 1066 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
| 1067 | - } |
|
| 1068 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 1076 | - * |
|
| 1077 | - * @access private |
|
| 1078 | - * @param EE_Transaction $transaction |
|
| 1079 | - * @return array |
|
| 1080 | - * @throws InvalidDataTypeException |
|
| 1081 | - * @throws InvalidEntityException |
|
| 1082 | - * @throws EE_Error |
|
| 1083 | - */ |
|
| 1084 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
| 1085 | - { |
|
| 1086 | - $att_nmbr = 0; |
|
| 1087 | - $registrations = array(); |
|
| 1088 | - if ($transaction instanceof EE_Transaction) { |
|
| 1089 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 1090 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1091 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 1092 | - // now let's add the cart items to the $transaction |
|
| 1093 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 1094 | - //do the following for each ticket of this type they selected |
|
| 1095 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 1096 | - $att_nmbr++; |
|
| 1097 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 1098 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
| 1099 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1100 | - array( |
|
| 1101 | - $transaction, |
|
| 1102 | - $line_item, |
|
| 1103 | - $att_nmbr, |
|
| 1104 | - $this->checkout->total_ticket_count, |
|
| 1105 | - ) |
|
| 1106 | - ); |
|
| 1107 | - // override capabilities for frontend registrations |
|
| 1108 | - if ( ! is_admin()) { |
|
| 1109 | - $CreateRegistrationCommand->setCapCheck( |
|
| 1110 | - new PublicCapabilities('', 'create_new_registration') |
|
| 1111 | - ); |
|
| 1112 | - } |
|
| 1113 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 1114 | - if ( ! $registration instanceof EE_Registration) { |
|
| 1115 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 1116 | - } |
|
| 1117 | - $registrations[ $registration->ID() ] = $registration; |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 1121 | - } |
|
| 1122 | - return $registrations; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * sorts registrations by REG_count |
|
| 1129 | - * |
|
| 1130 | - * @access public |
|
| 1131 | - * @param EE_Registration $reg_A |
|
| 1132 | - * @param EE_Registration $reg_B |
|
| 1133 | - * @return int |
|
| 1134 | - */ |
|
| 1135 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1136 | - { |
|
| 1137 | - // this shouldn't ever happen within the same TXN, but oh well |
|
| 1138 | - if ($reg_A->count() === $reg_B->count()) { |
|
| 1139 | - return 0; |
|
| 1140 | - } |
|
| 1141 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * _final_verifications |
|
| 1148 | - * just makes sure that everything is set up correctly before proceeding |
|
| 1149 | - * |
|
| 1150 | - * @access private |
|
| 1151 | - * @return bool |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - */ |
|
| 1154 | - private function _final_verifications() |
|
| 1155 | - { |
|
| 1156 | - // filter checkout |
|
| 1157 | - $this->checkout = apply_filters( |
|
| 1158 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
| 1159 | - $this->checkout |
|
| 1160 | - ); |
|
| 1161 | - //verify that current step is still set correctly |
|
| 1162 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1163 | - EE_Error::add_error( |
|
| 1164 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1165 | - __FILE__, |
|
| 1166 | - __FUNCTION__, |
|
| 1167 | - __LINE__ |
|
| 1168 | - ); |
|
| 1169 | - return false; |
|
| 1170 | - } |
|
| 1171 | - // if returning to SPCO, then verify that primary registrant is set |
|
| 1172 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1173 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1174 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1175 | - EE_Error::add_error( |
|
| 1176 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1177 | - __FILE__, |
|
| 1178 | - __FUNCTION__, |
|
| 1179 | - __LINE__ |
|
| 1180 | - ); |
|
| 1181 | - return false; |
|
| 1182 | - } |
|
| 1183 | - $valid_registrant = null; |
|
| 1184 | - foreach ( |
|
| 1185 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
| 1186 | - ) { |
|
| 1187 | - if ( |
|
| 1188 | - $registration instanceof EE_Registration |
|
| 1189 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1190 | - ) { |
|
| 1191 | - $valid_registrant = $registration; |
|
| 1192 | - } |
|
| 1193 | - } |
|
| 1194 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1195 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1196 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1197 | - // clear the session, mark the checkout as unverified, and try again |
|
| 1198 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 1199 | - EED_Single_Page_Checkout::$_initialized = false; |
|
| 1200 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1201 | - $this->_initialize(); |
|
| 1202 | - EE_Error::reset_notices(); |
|
| 1203 | - return false; |
|
| 1204 | - } |
|
| 1205 | - EE_Error::add_error( |
|
| 1206 | - __( |
|
| 1207 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
| 1208 | - 'event_espresso' |
|
| 1209 | - ), |
|
| 1210 | - __FILE__, |
|
| 1211 | - __FUNCTION__, |
|
| 1212 | - __LINE__ |
|
| 1213 | - ); |
|
| 1214 | - return false; |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - // now that things have been kinda sufficiently verified, |
|
| 1218 | - // let's add the checkout to the session so that it's available to other systems |
|
| 1219 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1220 | - return true; |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - |
|
| 1224 | - |
|
| 1225 | - /** |
|
| 1226 | - * _initialize_reg_steps |
|
| 1227 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1228 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1229 | - * |
|
| 1230 | - * @access private |
|
| 1231 | - * @param bool $reinitializing |
|
| 1232 | - * @throws EE_Error |
|
| 1233 | - */ |
|
| 1234 | - private function _initialize_reg_steps($reinitializing = false) |
|
| 1235 | - { |
|
| 1236 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1237 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1238 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1239 | - if ( ! $reg_step->initialize_reg_step()) { |
|
| 1240 | - // if not initialized then maybe this step is being removed... |
|
| 1241 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1242 | - // if it was the current step, then we need to start over here |
|
| 1243 | - $this->_initialize_reg_steps(true); |
|
| 1244 | - return; |
|
| 1245 | - } |
|
| 1246 | - continue; |
|
| 1247 | - } |
|
| 1248 | - // add css and JS for current step |
|
| 1249 | - $reg_step->enqueue_styles_and_scripts(); |
|
| 1250 | - // i18n |
|
| 1251 | - $reg_step->translate_js_strings(); |
|
| 1252 | - if ($reg_step->is_current_step()) { |
|
| 1253 | - // the text that appears on the reg step form submit button |
|
| 1254 | - $reg_step->set_submit_button_text(); |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1258 | - do_action( |
|
| 1259 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
| 1260 | - $this->checkout->current_step |
|
| 1261 | - ); |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - |
|
| 1265 | - |
|
| 1266 | - /** |
|
| 1267 | - * _check_form_submission |
|
| 1268 | - * |
|
| 1269 | - * @access private |
|
| 1270 | - * @return boolean |
|
| 1271 | - */ |
|
| 1272 | - private function _check_form_submission() |
|
| 1273 | - { |
|
| 1274 | - //does this request require the reg form to be generated ? |
|
| 1275 | - if ($this->checkout->generate_reg_form) { |
|
| 1276 | - // ever heard that song by Blue Rodeo ? |
|
| 1277 | - try { |
|
| 1278 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1279 | - // if not displaying a form, then check for form submission |
|
| 1280 | - if ( |
|
| 1281 | - $this->checkout->process_form_submission |
|
| 1282 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
| 1283 | - ) { |
|
| 1284 | - // clear out any old data in case this step is being run again |
|
| 1285 | - $this->checkout->current_step->set_valid_data(array()); |
|
| 1286 | - // capture submitted form data |
|
| 1287 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1288 | - apply_filters( |
|
| 1289 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
| 1290 | - EE_Registry::instance()->REQ->params(), |
|
| 1291 | - $this->checkout |
|
| 1292 | - ) |
|
| 1293 | - ); |
|
| 1294 | - // validate submitted form data |
|
| 1295 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1296 | - // thou shall not pass !!! |
|
| 1297 | - $this->checkout->continue_reg = false; |
|
| 1298 | - // any form validation errors? |
|
| 1299 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1300 | - $submission_error_messages = array(); |
|
| 1301 | - // bad, bad, bad registrant |
|
| 1302 | - foreach ( |
|
| 1303 | - $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
| 1304 | - as $validation_error |
|
| 1305 | - ) { |
|
| 1306 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1307 | - $submission_error_messages[] = sprintf( |
|
| 1308 | - __('%s : %s', 'event_espresso'), |
|
| 1309 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1310 | - $validation_error->getMessage() |
|
| 1311 | - ); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - EE_Error::add_error( |
|
| 1315 | - implode('<br />', $submission_error_messages), |
|
| 1316 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1317 | - ); |
|
| 1318 | - } |
|
| 1319 | - // well not really... what will happen is |
|
| 1320 | - // we'll just get redirected back to redo the current step |
|
| 1321 | - $this->go_to_next_step(); |
|
| 1322 | - return false; |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - } catch (EE_Error $e) { |
|
| 1326 | - $e->get_error(); |
|
| 1327 | - } |
|
| 1328 | - } |
|
| 1329 | - return true; |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * _process_action |
|
| 1336 | - * |
|
| 1337 | - * @access private |
|
| 1338 | - * @return void |
|
| 1339 | - * @throws EE_Error |
|
| 1340 | - */ |
|
| 1341 | - private function _process_form_action() |
|
| 1342 | - { |
|
| 1343 | - // what cha wanna do? |
|
| 1344 | - switch ($this->checkout->action) { |
|
| 1345 | - // AJAX next step reg form |
|
| 1346 | - case 'display_spco_reg_step' : |
|
| 1347 | - $this->checkout->redirect = false; |
|
| 1348 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1349 | - $this->checkout->json_response->set_reg_step_html( |
|
| 1350 | - $this->checkout->current_step->display_reg_form() |
|
| 1351 | - ); |
|
| 1352 | - } |
|
| 1353 | - break; |
|
| 1354 | - default : |
|
| 1355 | - // meh... do one of those other steps first |
|
| 1356 | - if ( |
|
| 1357 | - ! empty($this->checkout->action) |
|
| 1358 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
| 1359 | - ) { |
|
| 1360 | - // dynamically creates hook point like: |
|
| 1361 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1362 | - do_action( |
|
| 1363 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1364 | - $this->checkout->current_step |
|
| 1365 | - ); |
|
| 1366 | - // call action on current step |
|
| 1367 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1368 | - // good registrant, you get to proceed |
|
| 1369 | - if ( |
|
| 1370 | - $this->checkout->current_step->success_message() !== '' |
|
| 1371 | - && apply_filters( |
|
| 1372 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1373 | - false |
|
| 1374 | - ) |
|
| 1375 | - ) { |
|
| 1376 | - EE_Error::add_success( |
|
| 1377 | - $this->checkout->current_step->success_message() |
|
| 1378 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1379 | - ); |
|
| 1380 | - } |
|
| 1381 | - // pack it up, pack it in... |
|
| 1382 | - $this->_setup_redirect(); |
|
| 1383 | - } |
|
| 1384 | - // dynamically creates hook point like: |
|
| 1385 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1386 | - do_action( |
|
| 1387 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1388 | - $this->checkout->current_step |
|
| 1389 | - ); |
|
| 1390 | - } else { |
|
| 1391 | - EE_Error::add_error( |
|
| 1392 | - sprintf( |
|
| 1393 | - __( |
|
| 1394 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
| 1395 | - 'event_espresso' |
|
| 1396 | - ), |
|
| 1397 | - $this->checkout->action, |
|
| 1398 | - $this->checkout->current_step->name() |
|
| 1399 | - ), |
|
| 1400 | - __FILE__, |
|
| 1401 | - __FUNCTION__, |
|
| 1402 | - __LINE__ |
|
| 1403 | - ); |
|
| 1404 | - } |
|
| 1405 | - // end default |
|
| 1406 | - } |
|
| 1407 | - // store our progress so far |
|
| 1408 | - $this->checkout->stash_transaction_and_checkout(); |
|
| 1409 | - // advance to the next step! If you pass GO, collect $200 |
|
| 1410 | - $this->go_to_next_step(); |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - |
|
| 1414 | - |
|
| 1415 | - /** |
|
| 1416 | - * add_styles_and_scripts |
|
| 1417 | - * |
|
| 1418 | - * @access public |
|
| 1419 | - * @return void |
|
| 1420 | - */ |
|
| 1421 | - public function add_styles_and_scripts() |
|
| 1422 | - { |
|
| 1423 | - // i18n |
|
| 1424 | - $this->translate_js_strings(); |
|
| 1425 | - if ($this->checkout->admin_request) { |
|
| 1426 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1427 | - } else { |
|
| 1428 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1429 | - } |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * translate_js_strings |
|
| 1436 | - * |
|
| 1437 | - * @access public |
|
| 1438 | - * @return void |
|
| 1439 | - */ |
|
| 1440 | - public function translate_js_strings() |
|
| 1441 | - { |
|
| 1442 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1443 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1444 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
| 1445 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1446 | - 'event_espresso' |
|
| 1447 | - ); |
|
| 1448 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
| 1449 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1450 | - 'event_espresso' |
|
| 1451 | - ); |
|
| 1452 | - EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
| 1453 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
| 1454 | - 'event_espresso' |
|
| 1455 | - ); |
|
| 1456 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
| 1457 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
| 1458 | - 'event_espresso' |
|
| 1459 | - ); |
|
| 1460 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
| 1461 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
| 1462 | - 'event_espresso' |
|
| 1463 | - ); |
|
| 1464 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
| 1465 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
| 1466 | - 'event_espresso' |
|
| 1467 | - ); |
|
| 1468 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1469 | - __( |
|
| 1470 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
| 1471 | - 'event_espresso' |
|
| 1472 | - ), |
|
| 1473 | - '<br/>', |
|
| 1474 | - '<br/>' |
|
| 1475 | - ); |
|
| 1476 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1477 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1478 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1479 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1480 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1481 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1482 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1483 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1484 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1485 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1486 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1487 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1488 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1489 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1490 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1491 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1492 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1493 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1494 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 1495 | - __( |
|
| 1496 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 1497 | - 'event_espresso' |
|
| 1498 | - ), |
|
| 1499 | - '<h4 class="important-notice">', |
|
| 1500 | - '</h4>', |
|
| 1501 | - '<br />', |
|
| 1502 | - '<p>', |
|
| 1503 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1504 | - '">', |
|
| 1505 | - '</a>', |
|
| 1506 | - '</p>' |
|
| 1507 | - ); |
|
| 1508 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
| 1509 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
| 1510 | - true |
|
| 1511 | - ); |
|
| 1512 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
| 1513 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
| 1514 | - ); |
|
| 1515 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
| 1516 | - 'M d, Y H:i:s', |
|
| 1517 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1518 | - ); |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * enqueue_styles_and_scripts |
|
| 1525 | - * |
|
| 1526 | - * @access public |
|
| 1527 | - * @return void |
|
| 1528 | - * @throws EE_Error |
|
| 1529 | - */ |
|
| 1530 | - public function enqueue_styles_and_scripts() |
|
| 1531 | - { |
|
| 1532 | - // load css |
|
| 1533 | - wp_register_style( |
|
| 1534 | - 'single_page_checkout', |
|
| 1535 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1536 | - array('espresso_default'), |
|
| 1537 | - EVENT_ESPRESSO_VERSION |
|
| 1538 | - ); |
|
| 1539 | - wp_enqueue_style('single_page_checkout'); |
|
| 1540 | - // load JS |
|
| 1541 | - wp_register_script( |
|
| 1542 | - 'jquery_plugin', |
|
| 1543 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1544 | - array('jquery'), |
|
| 1545 | - '1.0.1', |
|
| 1546 | - true |
|
| 1547 | - ); |
|
| 1548 | - wp_register_script( |
|
| 1549 | - 'jquery_countdown', |
|
| 1550 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1551 | - array('jquery_plugin'), |
|
| 1552 | - '2.0.2', |
|
| 1553 | - true |
|
| 1554 | - ); |
|
| 1555 | - wp_register_script( |
|
| 1556 | - 'single_page_checkout', |
|
| 1557 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1558 | - array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
| 1559 | - EVENT_ESPRESSO_VERSION, |
|
| 1560 | - true |
|
| 1561 | - ); |
|
| 1562 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
| 1563 | - $this->checkout->registration_form->enqueue_js(); |
|
| 1564 | - } |
|
| 1565 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
| 1566 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1567 | - } |
|
| 1568 | - wp_enqueue_script('single_page_checkout'); |
|
| 1569 | - /** |
|
| 1570 | - * global action hook for enqueueing styles and scripts with |
|
| 1571 | - * spco calls. |
|
| 1572 | - */ |
|
| 1573 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1574 | - /** |
|
| 1575 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1576 | - * The hook will end up being something like: |
|
| 1577 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1578 | - */ |
|
| 1579 | - do_action( |
|
| 1580 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1581 | - $this |
|
| 1582 | - ); |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - |
|
| 1586 | - |
|
| 1587 | - /** |
|
| 1588 | - * display the Registration Single Page Checkout Form |
|
| 1589 | - * |
|
| 1590 | - * @access private |
|
| 1591 | - * @return void |
|
| 1592 | - * @throws EE_Error |
|
| 1593 | - */ |
|
| 1594 | - private function _display_spco_reg_form() |
|
| 1595 | - { |
|
| 1596 | - // if registering via the admin, just display the reg form for the current step |
|
| 1597 | - if ($this->checkout->admin_request) { |
|
| 1598 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1599 | - } else { |
|
| 1600 | - // add powered by EE msg |
|
| 1601 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1602 | - $empty_cart = count( |
|
| 1603 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
| 1604 | - ) < 1; |
|
| 1605 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
| 1606 | - $cookies_not_set_msg = ''; |
|
| 1607 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
| 1608 | - $cookies_not_set_msg = apply_filters( |
|
| 1609 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1610 | - sprintf( |
|
| 1611 | - __( |
|
| 1612 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1613 | - 'event_espresso' |
|
| 1614 | - ), |
|
| 1615 | - '<div class="ee-attention">', |
|
| 1616 | - '</div>', |
|
| 1617 | - '<h6 class="important-notice">', |
|
| 1618 | - '</h6>', |
|
| 1619 | - '<p>', |
|
| 1620 | - '</p>', |
|
| 1621 | - '<br />', |
|
| 1622 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
| 1623 | - '</a>' |
|
| 1624 | - ) |
|
| 1625 | - ); |
|
| 1626 | - } |
|
| 1627 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1628 | - array( |
|
| 1629 | - 'name' => 'single-page-checkout', |
|
| 1630 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1631 | - 'layout_strategy' => |
|
| 1632 | - new EE_Template_Layout( |
|
| 1633 | - array( |
|
| 1634 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1635 | - 'template_args' => array( |
|
| 1636 | - 'empty_cart' => $empty_cart, |
|
| 1637 | - 'revisit' => $this->checkout->revisit, |
|
| 1638 | - 'reg_steps' => $this->checkout->reg_steps, |
|
| 1639 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
| 1640 | - ? $this->checkout->next_step->slug() |
|
| 1641 | - : '', |
|
| 1642 | - 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
| 1643 | - 'empty_msg' => apply_filters( |
|
| 1644 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1645 | - sprintf( |
|
| 1646 | - __( |
|
| 1647 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
| 1648 | - 'event_espresso' |
|
| 1649 | - ), |
|
| 1650 | - '<a href="' |
|
| 1651 | - . get_post_type_archive_link('espresso_events') |
|
| 1652 | - . '" title="', |
|
| 1653 | - '">', |
|
| 1654 | - '</a>' |
|
| 1655 | - ) |
|
| 1656 | - ), |
|
| 1657 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1658 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1659 | - 'session_expiration' => gmdate( |
|
| 1660 | - 'M d, Y H:i:s', |
|
| 1661 | - EE_Registry::instance()->SSN->expiration() |
|
| 1662 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1663 | - ), |
|
| 1664 | - ), |
|
| 1665 | - ) |
|
| 1666 | - ), |
|
| 1667 | - ) |
|
| 1668 | - ); |
|
| 1669 | - // load template and add to output sent that gets filtered into the_content() |
|
| 1670 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1671 | - } |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * add_extra_finalize_registration_inputs |
|
| 1678 | - * |
|
| 1679 | - * @access public |
|
| 1680 | - * @param $next_step |
|
| 1681 | - * @internal param string $label |
|
| 1682 | - * @return void |
|
| 1683 | - */ |
|
| 1684 | - public function add_extra_finalize_registration_inputs($next_step) |
|
| 1685 | - { |
|
| 1686 | - if ($next_step === 'finalize_registration') { |
|
| 1687 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1688 | - } |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - |
|
| 1692 | - |
|
| 1693 | - /** |
|
| 1694 | - * display_registration_footer |
|
| 1695 | - * |
|
| 1696 | - * @access public |
|
| 1697 | - * @return string |
|
| 1698 | - */ |
|
| 1699 | - public static function display_registration_footer() |
|
| 1700 | - { |
|
| 1701 | - if ( |
|
| 1702 | - apply_filters( |
|
| 1703 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1704 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1705 | - ) |
|
| 1706 | - ) { |
|
| 1707 | - add_filter( |
|
| 1708 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1709 | - function ($url) { |
|
| 1710 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1711 | - } |
|
| 1712 | - ); |
|
| 1713 | - echo apply_filters( |
|
| 1714 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1715 | - \EEH_Template::powered_by_event_espresso( |
|
| 1716 | - '', |
|
| 1717 | - 'espresso-registration-footer-dv', |
|
| 1718 | - array('utm_content' => 'registration_checkout') |
|
| 1719 | - ) |
|
| 1720 | - ); |
|
| 1721 | - } |
|
| 1722 | - return ''; |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - |
|
| 1727 | - /** |
|
| 1728 | - * unlock_transaction |
|
| 1729 | - * |
|
| 1730 | - * @access public |
|
| 1731 | - * @return void |
|
| 1732 | - * @throws EE_Error |
|
| 1733 | - */ |
|
| 1734 | - public function unlock_transaction() |
|
| 1735 | - { |
|
| 1736 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1737 | - $this->checkout->transaction->unlock(); |
|
| 1738 | - } |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - |
|
| 1742 | - |
|
| 1743 | - /** |
|
| 1744 | - * _setup_redirect |
|
| 1745 | - * |
|
| 1746 | - * @access private |
|
| 1747 | - * @return void |
|
| 1748 | - */ |
|
| 1749 | - private function _setup_redirect() |
|
| 1750 | - { |
|
| 1751 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1752 | - $this->checkout->redirect = true; |
|
| 1753 | - if (empty($this->checkout->redirect_url)) { |
|
| 1754 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1755 | - } |
|
| 1756 | - $this->checkout->redirect_url = apply_filters( |
|
| 1757 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1758 | - $this->checkout->redirect_url, |
|
| 1759 | - $this->checkout |
|
| 1760 | - ); |
|
| 1761 | - } |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - /** |
|
| 1767 | - * handle ajax message responses and redirects |
|
| 1768 | - * |
|
| 1769 | - * @access public |
|
| 1770 | - * @return void |
|
| 1771 | - * @throws EE_Error |
|
| 1772 | - */ |
|
| 1773 | - public function go_to_next_step() |
|
| 1774 | - { |
|
| 1775 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1776 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1777 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1778 | - } |
|
| 1779 | - $this->unlock_transaction(); |
|
| 1780 | - // just return for these conditions |
|
| 1781 | - if ( |
|
| 1782 | - $this->checkout->admin_request |
|
| 1783 | - || $this->checkout->action === 'redirect_form' |
|
| 1784 | - || $this->checkout->action === 'update_checkout' |
|
| 1785 | - ) { |
|
| 1786 | - return; |
|
| 1787 | - } |
|
| 1788 | - // AJAX response |
|
| 1789 | - $this->_handle_json_response(); |
|
| 1790 | - // redirect to next step or the Thank You page |
|
| 1791 | - $this->_handle_html_redirects(); |
|
| 1792 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1793 | - $this->_display_spco_reg_form(); |
|
| 1794 | - } |
|
| 1795 | - |
|
| 1796 | - |
|
| 1797 | - |
|
| 1798 | - /** |
|
| 1799 | - * _handle_json_response |
|
| 1800 | - * |
|
| 1801 | - * @access protected |
|
| 1802 | - * @return void |
|
| 1803 | - */ |
|
| 1804 | - protected function _handle_json_response() |
|
| 1805 | - { |
|
| 1806 | - // if this is an ajax request |
|
| 1807 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1808 | - // DEBUG LOG |
|
| 1809 | - //$this->checkout->log( |
|
| 1810 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1811 | - // array( |
|
| 1812 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
| 1813 | - // 'redirect' => $this->checkout->redirect, |
|
| 1814 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
| 1815 | - // ) |
|
| 1816 | - //); |
|
| 1817 | - $this->checkout->json_response->set_registration_time_limit( |
|
| 1818 | - $this->checkout->get_registration_time_limit() |
|
| 1819 | - ); |
|
| 1820 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1821 | - // just send the ajax ( |
|
| 1822 | - $json_response = apply_filters( |
|
| 1823 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1824 | - $this->checkout->json_response |
|
| 1825 | - ); |
|
| 1826 | - echo $json_response; |
|
| 1827 | - exit(); |
|
| 1828 | - } |
|
| 1829 | - } |
|
| 1830 | - |
|
| 1831 | - |
|
| 1832 | - |
|
| 1833 | - /** |
|
| 1834 | - * _handle_redirects |
|
| 1835 | - * |
|
| 1836 | - * @access protected |
|
| 1837 | - * @return void |
|
| 1838 | - */ |
|
| 1839 | - protected function _handle_html_redirects() |
|
| 1840 | - { |
|
| 1841 | - // going somewhere ? |
|
| 1842 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1843 | - // store notices in a transient |
|
| 1844 | - EE_Error::get_notices(false, true, true); |
|
| 1845 | - // DEBUG LOG |
|
| 1846 | - //$this->checkout->log( |
|
| 1847 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1848 | - // array( |
|
| 1849 | - // 'headers_sent' => headers_sent(), |
|
| 1850 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
| 1851 | - // 'headers_list' => headers_list(), |
|
| 1852 | - // ) |
|
| 1853 | - //); |
|
| 1854 | - wp_safe_redirect($this->checkout->redirect_url); |
|
| 1855 | - exit(); |
|
| 1856 | - } |
|
| 1857 | - } |
|
| 1858 | - |
|
| 1859 | - |
|
| 1860 | - |
|
| 1861 | - /** |
|
| 1862 | - * set_checkout_anchor |
|
| 1863 | - * |
|
| 1864 | - * @access public |
|
| 1865 | - * @return void |
|
| 1866 | - */ |
|
| 1867 | - public function set_checkout_anchor() |
|
| 1868 | - { |
|
| 1869 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1870 | - } |
|
| 23 | + /** |
|
| 24 | + * $_initialized - has the SPCO controller already been initialized ? |
|
| 25 | + * |
|
| 26 | + * @access private |
|
| 27 | + * @var bool $_initialized |
|
| 28 | + */ |
|
| 29 | + private static $_initialized = false; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 34 | + * |
|
| 35 | + * @access private |
|
| 36 | + * @var bool $_valid_checkout |
|
| 37 | + */ |
|
| 38 | + private static $_checkout_verified = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * $_reg_steps_array - holds initial array of reg steps |
|
| 42 | + * |
|
| 43 | + * @access private |
|
| 44 | + * @var array $_reg_steps_array |
|
| 45 | + */ |
|
| 46 | + private static $_reg_steps_array = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 50 | + * |
|
| 51 | + * @access public |
|
| 52 | + * @var EE_Checkout $checkout |
|
| 53 | + */ |
|
| 54 | + public $checkout; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return EED_Module|EED_Single_Page_Checkout |
|
| 60 | + */ |
|
| 61 | + public static function instance() |
|
| 62 | + { |
|
| 63 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 64 | + return parent::get_instance(__CLASS__); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return EE_CART |
|
| 71 | + */ |
|
| 72 | + public function cart() |
|
| 73 | + { |
|
| 74 | + return $this->checkout->cart; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return EE_Transaction |
|
| 81 | + */ |
|
| 82 | + public function transaction() |
|
| 83 | + { |
|
| 84 | + return $this->checkout->transaction; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return void |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + public static function set_hooks() |
|
| 97 | + { |
|
| 98 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return void |
|
| 108 | + * @throws EE_Error |
|
| 109 | + */ |
|
| 110 | + public static function set_hooks_admin() |
|
| 111 | + { |
|
| 112 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 113 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + // going to start an output buffer in case anything gets accidentally output |
|
| 117 | + // that might disrupt our JSON response |
|
| 118 | + ob_start(); |
|
| 119 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 120 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 121 | + // set ajax hooks |
|
| 122 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 123 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 124 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 125 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 126 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 127 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * process ajax request |
|
| 134 | + * |
|
| 135 | + * @param string $ajax_action |
|
| 136 | + * @throws EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function process_ajax_request($ajax_action) |
|
| 139 | + { |
|
| 140 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 141 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * ajax display registration step |
|
| 148 | + * |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + public static function display_reg_step() |
|
| 152 | + { |
|
| 153 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * ajax process registration step |
|
| 160 | + * |
|
| 161 | + * @throws EE_Error |
|
| 162 | + */ |
|
| 163 | + public static function process_reg_step() |
|
| 164 | + { |
|
| 165 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * ajax process registration step |
|
| 172 | + * |
|
| 173 | + * @throws EE_Error |
|
| 174 | + */ |
|
| 175 | + public static function update_reg_step() |
|
| 176 | + { |
|
| 177 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * update_checkout |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @return void |
|
| 187 | + * @throws EE_Error |
|
| 188 | + */ |
|
| 189 | + public static function update_checkout() |
|
| 190 | + { |
|
| 191 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * load_request_handler |
|
| 198 | + * |
|
| 199 | + * @access public |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + public static function load_request_handler() |
|
| 203 | + { |
|
| 204 | + // load core Request_Handler class |
|
| 205 | + if (EE_Registry::instance()->REQ !== null) { |
|
| 206 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * set_definitions |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @return void |
|
| 217 | + * @throws EE_Error |
|
| 218 | + */ |
|
| 219 | + public static function set_definitions() |
|
| 220 | + { |
|
| 221 | + if(defined('SPCO_BASE_PATH')) { |
|
| 222 | + return; |
|
| 223 | + } |
|
| 224 | + define( |
|
| 225 | + 'SPCO_BASE_PATH', |
|
| 226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
| 227 | + ); |
|
| 228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 235 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 236 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 237 | + 'event_espresso'), |
|
| 238 | + '<h4 class="important-notice">', |
|
| 239 | + '</h4>', |
|
| 240 | + '<br />', |
|
| 241 | + '<p>', |
|
| 242 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 243 | + '">', |
|
| 244 | + '</a>', |
|
| 245 | + '</p>' |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * load_reg_steps |
|
| 253 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 254 | + * |
|
| 255 | + * @access private |
|
| 256 | + * @throws EE_Error |
|
| 257 | + */ |
|
| 258 | + public static function load_reg_steps() |
|
| 259 | + { |
|
| 260 | + static $reg_steps_loaded = false; |
|
| 261 | + if ($reg_steps_loaded) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + // filter list of reg_steps |
|
| 265 | + $reg_steps_to_load = (array)apply_filters( |
|
| 266 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 267 | + EED_Single_Page_Checkout::get_reg_steps() |
|
| 268 | + ); |
|
| 269 | + // sort by key (order) |
|
| 270 | + ksort($reg_steps_to_load); |
|
| 271 | + // loop through folders |
|
| 272 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 273 | + // we need a |
|
| 274 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 275 | + // copy over to the reg_steps_array |
|
| 276 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 277 | + // register custom key route for each reg step |
|
| 278 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 279 | + EE_Config::register_route( |
|
| 280 | + $reg_step['slug'], |
|
| 281 | + 'EED_Single_Page_Checkout', |
|
| 282 | + 'run', |
|
| 283 | + 'step' |
|
| 284 | + ); |
|
| 285 | + // add AJAX or other hooks |
|
| 286 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 287 | + // setup autoloaders if necessary |
|
| 288 | + if ( ! class_exists($reg_step['class_name'])) { |
|
| 289 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
| 290 | + $reg_step['file_path'], |
|
| 291 | + true |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 295 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + $reg_steps_loaded = true; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * get_reg_steps |
|
| 307 | + * |
|
| 308 | + * @access public |
|
| 309 | + * @return array |
|
| 310 | + */ |
|
| 311 | + public static function get_reg_steps() |
|
| 312 | + { |
|
| 313 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 314 | + if (empty($reg_steps)) { |
|
| 315 | + $reg_steps = array( |
|
| 316 | + 10 => array( |
|
| 317 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 318 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 319 | + 'slug' => 'attendee_information', |
|
| 320 | + 'has_hooks' => false, |
|
| 321 | + ), |
|
| 322 | + 20 => array( |
|
| 323 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 324 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
| 325 | + 'slug' => 'registration_confirmation', |
|
| 326 | + 'has_hooks' => false, |
|
| 327 | + ), |
|
| 328 | + 30 => array( |
|
| 329 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 330 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 331 | + 'slug' => 'payment_options', |
|
| 332 | + 'has_hooks' => true, |
|
| 333 | + ), |
|
| 334 | + 999 => array( |
|
| 335 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 336 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 337 | + 'slug' => 'finalize_registration', |
|
| 338 | + 'has_hooks' => false, |
|
| 339 | + ), |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + return $reg_steps; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * registration_checkout_for_admin |
|
| 349 | + * |
|
| 350 | + * @access public |
|
| 351 | + * @return string |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public static function registration_checkout_for_admin() |
|
| 355 | + { |
|
| 356 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 357 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 358 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 359 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 360 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 361 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 362 | + return EE_Registry::instance()->REQ->get_output(); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * process_registration_from_admin |
|
| 369 | + * |
|
| 370 | + * @access public |
|
| 371 | + * @return \EE_Transaction |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public static function process_registration_from_admin() |
|
| 375 | + { |
|
| 376 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 377 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 378 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 379 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 380 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 381 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 382 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 383 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 384 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 385 | + if ($final_reg_step->process_reg_step()) { |
|
| 386 | + $final_reg_step->set_completed(); |
|
| 387 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 388 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * run |
|
| 399 | + * |
|
| 400 | + * @access public |
|
| 401 | + * @param WP_Query $WP_Query |
|
| 402 | + * @return void |
|
| 403 | + * @throws EE_Error |
|
| 404 | + */ |
|
| 405 | + public function run($WP_Query) |
|
| 406 | + { |
|
| 407 | + if ( |
|
| 408 | + $WP_Query instanceof WP_Query |
|
| 409 | + && $WP_Query->is_main_query() |
|
| 410 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 411 | + && $this->_is_reg_checkout() |
|
| 412 | + ) { |
|
| 413 | + $this->_initialize(); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * determines whether current url matches reg page url |
|
| 421 | + * |
|
| 422 | + * @return bool |
|
| 423 | + */ |
|
| 424 | + protected function _is_reg_checkout() |
|
| 425 | + { |
|
| 426 | + // get current permalink for reg page without any extra query args |
|
| 427 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 428 | + // get request URI for current request, but without the scheme or host |
|
| 429 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 430 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
| 431 | + // get array of query args from the current request URI |
|
| 432 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 433 | + // grab page id if it is set |
|
| 434 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 435 | + // and remove the page id from the query args (we will re-add it later) |
|
| 436 | + unset($query_args['page_id']); |
|
| 437 | + // now strip all query args from current request URI |
|
| 438 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
| 439 | + // and re-add the page id if it was set |
|
| 440 | + if ($page_id) { |
|
| 441 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 442 | + } |
|
| 443 | + // remove slashes and ? |
|
| 444 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
| 445 | + // is current request URI part of the known full reg page URL ? |
|
| 446 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @param WP_Query $wp_query |
|
| 453 | + * @return void |
|
| 454 | + * @throws EE_Error |
|
| 455 | + */ |
|
| 456 | + public static function init($wp_query) |
|
| 457 | + { |
|
| 458 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * _initialize - initial module setup |
|
| 465 | + * |
|
| 466 | + * @access private |
|
| 467 | + * @throws EE_Error |
|
| 468 | + * @return void |
|
| 469 | + */ |
|
| 470 | + private function _initialize() |
|
| 471 | + { |
|
| 472 | + // ensure SPCO doesn't run twice |
|
| 473 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
| 474 | + return; |
|
| 475 | + } |
|
| 476 | + try { |
|
| 477 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 478 | + $this->_verify_session(); |
|
| 479 | + // setup the EE_Checkout object |
|
| 480 | + $this->checkout = $this->_initialize_checkout(); |
|
| 481 | + // filter checkout |
|
| 482 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 483 | + // get the $_GET |
|
| 484 | + $this->_get_request_vars(); |
|
| 485 | + if ($this->_block_bots()) { |
|
| 486 | + return; |
|
| 487 | + } |
|
| 488 | + // filter continue_reg |
|
| 489 | + $this->checkout->continue_reg = apply_filters( |
|
| 490 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
| 491 | + true, |
|
| 492 | + $this->checkout |
|
| 493 | + ); |
|
| 494 | + // load the reg steps array |
|
| 495 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 496 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 497 | + return; |
|
| 498 | + } |
|
| 499 | + // set the current step |
|
| 500 | + $this->checkout->set_current_step($this->checkout->step); |
|
| 501 | + // and the next step |
|
| 502 | + $this->checkout->set_next_step(); |
|
| 503 | + // verify that everything has been setup correctly |
|
| 504 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 505 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 506 | + return; |
|
| 507 | + } |
|
| 508 | + // lock the transaction |
|
| 509 | + $this->checkout->transaction->lock(); |
|
| 510 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
| 511 | + $this->checkout->refresh_all_entities(); |
|
| 512 | + // set amount owing |
|
| 513 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 514 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 515 | + $this->_initialize_reg_steps(); |
|
| 516 | + // DEBUG LOG |
|
| 517 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 518 | + // get reg form |
|
| 519 | + if( ! $this->_check_form_submission()) { |
|
| 520 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 521 | + return; |
|
| 522 | + } |
|
| 523 | + // checkout the action!!! |
|
| 524 | + $this->_process_form_action(); |
|
| 525 | + // add some style and make it dance |
|
| 526 | + $this->add_styles_and_scripts(); |
|
| 527 | + // kk... SPCO has successfully run |
|
| 528 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 529 | + // set no cache headers and constants |
|
| 530 | + EE_System::do_not_cache(); |
|
| 531 | + // add anchor |
|
| 532 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 533 | + // remove transaction lock |
|
| 534 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
| 535 | + } catch (Exception $e) { |
|
| 536 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * _verify_session |
|
| 544 | + * checks that the session is valid and not expired |
|
| 545 | + * |
|
| 546 | + * @access private |
|
| 547 | + * @throws EE_Error |
|
| 548 | + */ |
|
| 549 | + private function _verify_session() |
|
| 550 | + { |
|
| 551 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 552 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
| 553 | + } |
|
| 554 | + // is session still valid ? |
|
| 555 | + if ( |
|
| 556 | + EE_Registry::instance()->SSN->expired() |
|
| 557 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
| 558 | + ) { |
|
| 559 | + $this->checkout = new EE_Checkout(); |
|
| 560 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 561 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
| 562 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
| 563 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
| 564 | + EE_Error::add_attention( |
|
| 565 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
| 566 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 567 | + ); |
|
| 568 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * _initialize_checkout |
|
| 576 | + * loads and instantiates EE_Checkout |
|
| 577 | + * |
|
| 578 | + * @access private |
|
| 579 | + * @throws EE_Error |
|
| 580 | + * @return EE_Checkout |
|
| 581 | + */ |
|
| 582 | + private function _initialize_checkout() |
|
| 583 | + { |
|
| 584 | + // look in session for existing checkout |
|
| 585 | + /** @type EE_Checkout $checkout */ |
|
| 586 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 587 | + // verify |
|
| 588 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 589 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 590 | + $checkout = EE_Registry::instance()->load_file( |
|
| 591 | + SPCO_INC_PATH, |
|
| 592 | + 'EE_Checkout', |
|
| 593 | + 'class', array(), |
|
| 594 | + false |
|
| 595 | + ); |
|
| 596 | + } else { |
|
| 597 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 598 | + $this->unlock_transaction(); |
|
| 599 | + wp_safe_redirect($checkout->redirect_url); |
|
| 600 | + exit(); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 604 | + // verify again |
|
| 605 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 606 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 607 | + } |
|
| 608 | + // reset anything that needs a clean slate for each request |
|
| 609 | + $checkout->reset_for_current_request(); |
|
| 610 | + return $checkout; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * _get_request_vars |
|
| 617 | + * |
|
| 618 | + * @access private |
|
| 619 | + * @return void |
|
| 620 | + * @throws EE_Error |
|
| 621 | + */ |
|
| 622 | + private function _get_request_vars() |
|
| 623 | + { |
|
| 624 | + // load classes |
|
| 625 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 626 | + //make sure this request is marked as belonging to EE |
|
| 627 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 628 | + // which step is being requested ? |
|
| 629 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 630 | + // which step is being edited ? |
|
| 631 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 632 | + // and what we're doing on the current step |
|
| 633 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 634 | + // timestamp |
|
| 635 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 636 | + // returning to edit ? |
|
| 637 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 638 | + // or some other kind of revisit ? |
|
| 639 | + $this->checkout->revisit = filter_var( |
|
| 640 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
| 641 | + FILTER_VALIDATE_BOOLEAN |
|
| 642 | + ); |
|
| 643 | + // and whether or not to generate a reg form for this request |
|
| 644 | + $this->checkout->generate_reg_form = filter_var( |
|
| 645 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
| 646 | + FILTER_VALIDATE_BOOLEAN |
|
| 647 | + ); |
|
| 648 | + // and whether or not to process a reg form submission for this request |
|
| 649 | + $this->checkout->process_form_submission = filter_var( |
|
| 650 | + EE_Registry::instance()->REQ->get( |
|
| 651 | + 'process_form_submission', |
|
| 652 | + $this->checkout->action === 'process_reg_step' |
|
| 653 | + ), |
|
| 654 | + FILTER_VALIDATE_BOOLEAN |
|
| 655 | + ); |
|
| 656 | + $this->checkout->process_form_submission = filter_var( |
|
| 657 | + $this->checkout->action !== 'display_spco_reg_step' |
|
| 658 | + ? $this->checkout->process_form_submission |
|
| 659 | + : false, |
|
| 660 | + FILTER_VALIDATE_BOOLEAN |
|
| 661 | + ); |
|
| 662 | + // $this->_display_request_vars(); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * _display_request_vars |
|
| 669 | + * |
|
| 670 | + * @access protected |
|
| 671 | + * @return void |
|
| 672 | + */ |
|
| 673 | + protected function _display_request_vars() |
|
| 674 | + { |
|
| 675 | + if ( ! WP_DEBUG) { |
|
| 676 | + return; |
|
| 677 | + } |
|
| 678 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 679 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 680 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 681 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 682 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 683 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 684 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 685 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * _block_bots |
|
| 692 | + * checks that the incoming request has either of the following set: |
|
| 693 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 694 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 695 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 696 | + * then where you coming from man? |
|
| 697 | + * |
|
| 698 | + * @return boolean |
|
| 699 | + */ |
|
| 700 | + private function _block_bots() |
|
| 701 | + { |
|
| 702 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 703 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 704 | + return true; |
|
| 705 | + } |
|
| 706 | + return false; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * _get_first_step |
|
| 713 | + * gets slug for first step in $_reg_steps_array |
|
| 714 | + * |
|
| 715 | + * @access private |
|
| 716 | + * @throws EE_Error |
|
| 717 | + * @return string |
|
| 718 | + */ |
|
| 719 | + private function _get_first_step() |
|
| 720 | + { |
|
| 721 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 722 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * _load_and_instantiate_reg_steps |
|
| 729 | + * instantiates each reg step based on the loaded reg_steps array |
|
| 730 | + * |
|
| 731 | + * @access private |
|
| 732 | + * @throws EE_Error |
|
| 733 | + * @return bool |
|
| 734 | + */ |
|
| 735 | + private function _load_and_instantiate_reg_steps() |
|
| 736 | + { |
|
| 737 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
| 738 | + // have reg_steps already been instantiated ? |
|
| 739 | + if ( |
|
| 740 | + empty($this->checkout->reg_steps) |
|
| 741 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 742 | + ) { |
|
| 743 | + // if not, then loop through raw reg steps array |
|
| 744 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 745 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 746 | + return false; |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
| 750 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
| 751 | + // skip the registration_confirmation page ? |
|
| 752 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 753 | + // just remove it from the reg steps array |
|
| 754 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 755 | + } else if ( |
|
| 756 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 757 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 758 | + ) { |
|
| 759 | + // set the order to something big like 100 |
|
| 760 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 761 | + } |
|
| 762 | + // filter the array for good luck |
|
| 763 | + $this->checkout->reg_steps = apply_filters( |
|
| 764 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 765 | + $this->checkout->reg_steps |
|
| 766 | + ); |
|
| 767 | + // finally re-sort based on the reg step class order properties |
|
| 768 | + $this->checkout->sort_reg_steps(); |
|
| 769 | + } else { |
|
| 770 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 771 | + // set all current step stati to FALSE |
|
| 772 | + $reg_step->set_is_current_step(false); |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + if (empty($this->checkout->reg_steps)) { |
|
| 776 | + EE_Error::add_error( |
|
| 777 | + __('No Reg Steps were loaded..', 'event_espresso'), |
|
| 778 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 779 | + ); |
|
| 780 | + return false; |
|
| 781 | + } |
|
| 782 | + // make reg step details available to JS |
|
| 783 | + $this->checkout->set_reg_step_JSON_info(); |
|
| 784 | + return true; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * _load_and_instantiate_reg_step |
|
| 791 | + * |
|
| 792 | + * @access private |
|
| 793 | + * @param array $reg_step |
|
| 794 | + * @param int $order |
|
| 795 | + * @return bool |
|
| 796 | + */ |
|
| 797 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 798 | + { |
|
| 799 | + // we need a file_path, class_name, and slug to add a reg step |
|
| 800 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 801 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 802 | + if ( |
|
| 803 | + $this->checkout->reg_url_link |
|
| 804 | + && $this->checkout->step !== $reg_step['slug'] |
|
| 805 | + && $reg_step['slug'] !== 'finalize_registration' |
|
| 806 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
| 807 | + && apply_filters( |
|
| 808 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
| 809 | + true, |
|
| 810 | + $reg_step, |
|
| 811 | + $this->checkout |
|
| 812 | + ) |
|
| 813 | + ) { |
|
| 814 | + return true; |
|
| 815 | + } |
|
| 816 | + // instantiate step class using file path and class name |
|
| 817 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 818 | + $reg_step['file_path'], |
|
| 819 | + $reg_step['class_name'], |
|
| 820 | + 'class', |
|
| 821 | + $this->checkout, |
|
| 822 | + false |
|
| 823 | + ); |
|
| 824 | + // did we gets the goods ? |
|
| 825 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 826 | + // set reg step order based on config |
|
| 827 | + $reg_step_obj->set_order($order); |
|
| 828 | + // add instantiated reg step object to the master reg steps array |
|
| 829 | + $this->checkout->add_reg_step($reg_step_obj); |
|
| 830 | + } else { |
|
| 831 | + EE_Error::add_error( |
|
| 832 | + __('The current step could not be set.', 'event_espresso'), |
|
| 833 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 834 | + ); |
|
| 835 | + return false; |
|
| 836 | + } |
|
| 837 | + } else { |
|
| 838 | + if (WP_DEBUG) { |
|
| 839 | + EE_Error::add_error( |
|
| 840 | + sprintf( |
|
| 841 | + __( |
|
| 842 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
| 843 | + 'event_espresso' |
|
| 844 | + ), |
|
| 845 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 846 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 847 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 848 | + '<ul>', |
|
| 849 | + '<li>', |
|
| 850 | + '</li>', |
|
| 851 | + '</ul>' |
|
| 852 | + ), |
|
| 853 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 854 | + ); |
|
| 855 | + } |
|
| 856 | + return false; |
|
| 857 | + } |
|
| 858 | + return true; |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * _verify_transaction_and_get_registrations |
|
| 864 | + * |
|
| 865 | + * @access private |
|
| 866 | + * @return bool |
|
| 867 | + * @throws InvalidDataTypeException |
|
| 868 | + * @throws InvalidEntityException |
|
| 869 | + * @throws EE_Error |
|
| 870 | + */ |
|
| 871 | + private function _verify_transaction_and_get_registrations() |
|
| 872 | + { |
|
| 873 | + // was there already a valid transaction in the checkout from the session ? |
|
| 874 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 875 | + // get transaction from db or session |
|
| 876 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 877 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 878 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 879 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 880 | + EE_Error::add_error( |
|
| 881 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
| 882 | + 'event_espresso'), |
|
| 883 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 884 | + ); |
|
| 885 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 886 | + // add some style and make it dance |
|
| 887 | + $this->add_styles_and_scripts(); |
|
| 888 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 889 | + return false; |
|
| 890 | + } |
|
| 891 | + // and the registrations for the transaction |
|
| 892 | + $this->_get_registrations($this->checkout->transaction); |
|
| 893 | + } |
|
| 894 | + return true; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * _get_transaction_and_cart_for_previous_visit |
|
| 901 | + * |
|
| 902 | + * @access private |
|
| 903 | + * @return mixed EE_Transaction|NULL |
|
| 904 | + */ |
|
| 905 | + private function _get_transaction_and_cart_for_previous_visit() |
|
| 906 | + { |
|
| 907 | + /** @var $TXN_model EEM_Transaction */ |
|
| 908 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 909 | + // because the reg_url_link is present in the request, |
|
| 910 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 911 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 912 | + // verify transaction |
|
| 913 | + if ($transaction instanceof EE_Transaction) { |
|
| 914 | + // and get the cart that was used for that transaction |
|
| 915 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 916 | + return $transaction; |
|
| 917 | + } |
|
| 918 | + EE_Error::add_error( |
|
| 919 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
| 920 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 921 | + ); |
|
| 922 | + return null; |
|
| 923 | + |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * _get_cart_for_transaction |
|
| 930 | + * |
|
| 931 | + * @access private |
|
| 932 | + * @param EE_Transaction $transaction |
|
| 933 | + * @return EE_Cart |
|
| 934 | + */ |
|
| 935 | + private function _get_cart_for_transaction($transaction) |
|
| 936 | + { |
|
| 937 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * get_cart_for_transaction |
|
| 944 | + * |
|
| 945 | + * @access public |
|
| 946 | + * @param EE_Transaction $transaction |
|
| 947 | + * @return EE_Cart |
|
| 948 | + */ |
|
| 949 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 950 | + { |
|
| 951 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + /** |
|
| 957 | + * _get_transaction_and_cart_for_current_session |
|
| 958 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 959 | + * |
|
| 960 | + * @access private |
|
| 961 | + * @return EE_Transaction |
|
| 962 | + * @throws EE_Error |
|
| 963 | + */ |
|
| 964 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 965 | + { |
|
| 966 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 967 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 968 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 969 | + // and then create a new transaction |
|
| 970 | + $transaction = $this->_initialize_transaction(); |
|
| 971 | + // verify transaction |
|
| 972 | + if ($transaction instanceof EE_Transaction) { |
|
| 973 | + // save it so that we have an ID for other objects to use |
|
| 974 | + $transaction->save(); |
|
| 975 | + // and save TXN data to the cart |
|
| 976 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 977 | + } else { |
|
| 978 | + EE_Error::add_error( |
|
| 979 | + __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
| 980 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 981 | + ); |
|
| 982 | + } |
|
| 983 | + return $transaction; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 990 | + * |
|
| 991 | + * @access private |
|
| 992 | + * @return mixed EE_Transaction|NULL |
|
| 993 | + */ |
|
| 994 | + private function _initialize_transaction() |
|
| 995 | + { |
|
| 996 | + try { |
|
| 997 | + // ensure cart totals have been calculated |
|
| 998 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 999 | + // grab the cart grand total |
|
| 1000 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 1001 | + // create new TXN |
|
| 1002 | + $transaction = EE_Transaction::new_instance( |
|
| 1003 | + array( |
|
| 1004 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 1005 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 1006 | + 'TXN_paid' => 0, |
|
| 1007 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 1008 | + ) |
|
| 1009 | + ); |
|
| 1010 | + // save it so that we have an ID for other objects to use |
|
| 1011 | + $transaction->save(); |
|
| 1012 | + // set cron job for following up on TXNs after their session has expired |
|
| 1013 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
| 1014 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
| 1015 | + $transaction->ID() |
|
| 1016 | + ); |
|
| 1017 | + return $transaction; |
|
| 1018 | + } catch (Exception $e) { |
|
| 1019 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1020 | + } |
|
| 1021 | + return null; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * _get_registrations |
|
| 1027 | + * |
|
| 1028 | + * @access private |
|
| 1029 | + * @param EE_Transaction $transaction |
|
| 1030 | + * @return void |
|
| 1031 | + * @throws InvalidDataTypeException |
|
| 1032 | + * @throws InvalidEntityException |
|
| 1033 | + * @throws EE_Error |
|
| 1034 | + */ |
|
| 1035 | + private function _get_registrations(EE_Transaction $transaction) |
|
| 1036 | + { |
|
| 1037 | + // first step: grab the registrants { : o |
|
| 1038 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
| 1039 | + // verify registrations have been set |
|
| 1040 | + if (empty($registrations)) { |
|
| 1041 | + // if no cached registrations, then check the db |
|
| 1042 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1043 | + // still nothing ? well as long as this isn't a revisit |
|
| 1044 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 1045 | + // generate new registrations from scratch |
|
| 1046 | + $registrations = $this->_initialize_registrations($transaction); |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + // sort by their original registration order |
|
| 1050 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 1051 | + // then loop thru the array |
|
| 1052 | + foreach ($registrations as $registration) { |
|
| 1053 | + // verify each registration |
|
| 1054 | + if ($registration instanceof EE_Registration) { |
|
| 1055 | + // we display all attendee info for the primary registrant |
|
| 1056 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 1057 | + && $registration->is_primary_registrant() |
|
| 1058 | + ) { |
|
| 1059 | + $this->checkout->primary_revisit = true; |
|
| 1060 | + break; |
|
| 1061 | + } |
|
| 1062 | + if ($this->checkout->revisit |
|
| 1063 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
| 1064 | + ) { |
|
| 1065 | + // but hide info if it doesn't belong to you |
|
| 1066 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
| 1067 | + } |
|
| 1068 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 1076 | + * |
|
| 1077 | + * @access private |
|
| 1078 | + * @param EE_Transaction $transaction |
|
| 1079 | + * @return array |
|
| 1080 | + * @throws InvalidDataTypeException |
|
| 1081 | + * @throws InvalidEntityException |
|
| 1082 | + * @throws EE_Error |
|
| 1083 | + */ |
|
| 1084 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
| 1085 | + { |
|
| 1086 | + $att_nmbr = 0; |
|
| 1087 | + $registrations = array(); |
|
| 1088 | + if ($transaction instanceof EE_Transaction) { |
|
| 1089 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 1090 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1091 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 1092 | + // now let's add the cart items to the $transaction |
|
| 1093 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 1094 | + //do the following for each ticket of this type they selected |
|
| 1095 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 1096 | + $att_nmbr++; |
|
| 1097 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 1098 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
| 1099 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1100 | + array( |
|
| 1101 | + $transaction, |
|
| 1102 | + $line_item, |
|
| 1103 | + $att_nmbr, |
|
| 1104 | + $this->checkout->total_ticket_count, |
|
| 1105 | + ) |
|
| 1106 | + ); |
|
| 1107 | + // override capabilities for frontend registrations |
|
| 1108 | + if ( ! is_admin()) { |
|
| 1109 | + $CreateRegistrationCommand->setCapCheck( |
|
| 1110 | + new PublicCapabilities('', 'create_new_registration') |
|
| 1111 | + ); |
|
| 1112 | + } |
|
| 1113 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 1114 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1115 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 1116 | + } |
|
| 1117 | + $registrations[ $registration->ID() ] = $registration; |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 1120 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 1121 | + } |
|
| 1122 | + return $registrations; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * sorts registrations by REG_count |
|
| 1129 | + * |
|
| 1130 | + * @access public |
|
| 1131 | + * @param EE_Registration $reg_A |
|
| 1132 | + * @param EE_Registration $reg_B |
|
| 1133 | + * @return int |
|
| 1134 | + */ |
|
| 1135 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1136 | + { |
|
| 1137 | + // this shouldn't ever happen within the same TXN, but oh well |
|
| 1138 | + if ($reg_A->count() === $reg_B->count()) { |
|
| 1139 | + return 0; |
|
| 1140 | + } |
|
| 1141 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * _final_verifications |
|
| 1148 | + * just makes sure that everything is set up correctly before proceeding |
|
| 1149 | + * |
|
| 1150 | + * @access private |
|
| 1151 | + * @return bool |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + */ |
|
| 1154 | + private function _final_verifications() |
|
| 1155 | + { |
|
| 1156 | + // filter checkout |
|
| 1157 | + $this->checkout = apply_filters( |
|
| 1158 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
| 1159 | + $this->checkout |
|
| 1160 | + ); |
|
| 1161 | + //verify that current step is still set correctly |
|
| 1162 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1163 | + EE_Error::add_error( |
|
| 1164 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1165 | + __FILE__, |
|
| 1166 | + __FUNCTION__, |
|
| 1167 | + __LINE__ |
|
| 1168 | + ); |
|
| 1169 | + return false; |
|
| 1170 | + } |
|
| 1171 | + // if returning to SPCO, then verify that primary registrant is set |
|
| 1172 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1173 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1174 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1175 | + EE_Error::add_error( |
|
| 1176 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1177 | + __FILE__, |
|
| 1178 | + __FUNCTION__, |
|
| 1179 | + __LINE__ |
|
| 1180 | + ); |
|
| 1181 | + return false; |
|
| 1182 | + } |
|
| 1183 | + $valid_registrant = null; |
|
| 1184 | + foreach ( |
|
| 1185 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
| 1186 | + ) { |
|
| 1187 | + if ( |
|
| 1188 | + $registration instanceof EE_Registration |
|
| 1189 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1190 | + ) { |
|
| 1191 | + $valid_registrant = $registration; |
|
| 1192 | + } |
|
| 1193 | + } |
|
| 1194 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1195 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1196 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1197 | + // clear the session, mark the checkout as unverified, and try again |
|
| 1198 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 1199 | + EED_Single_Page_Checkout::$_initialized = false; |
|
| 1200 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1201 | + $this->_initialize(); |
|
| 1202 | + EE_Error::reset_notices(); |
|
| 1203 | + return false; |
|
| 1204 | + } |
|
| 1205 | + EE_Error::add_error( |
|
| 1206 | + __( |
|
| 1207 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
| 1208 | + 'event_espresso' |
|
| 1209 | + ), |
|
| 1210 | + __FILE__, |
|
| 1211 | + __FUNCTION__, |
|
| 1212 | + __LINE__ |
|
| 1213 | + ); |
|
| 1214 | + return false; |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + // now that things have been kinda sufficiently verified, |
|
| 1218 | + // let's add the checkout to the session so that it's available to other systems |
|
| 1219 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1220 | + return true; |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + |
|
| 1224 | + |
|
| 1225 | + /** |
|
| 1226 | + * _initialize_reg_steps |
|
| 1227 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1228 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1229 | + * |
|
| 1230 | + * @access private |
|
| 1231 | + * @param bool $reinitializing |
|
| 1232 | + * @throws EE_Error |
|
| 1233 | + */ |
|
| 1234 | + private function _initialize_reg_steps($reinitializing = false) |
|
| 1235 | + { |
|
| 1236 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1237 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1238 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1239 | + if ( ! $reg_step->initialize_reg_step()) { |
|
| 1240 | + // if not initialized then maybe this step is being removed... |
|
| 1241 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1242 | + // if it was the current step, then we need to start over here |
|
| 1243 | + $this->_initialize_reg_steps(true); |
|
| 1244 | + return; |
|
| 1245 | + } |
|
| 1246 | + continue; |
|
| 1247 | + } |
|
| 1248 | + // add css and JS for current step |
|
| 1249 | + $reg_step->enqueue_styles_and_scripts(); |
|
| 1250 | + // i18n |
|
| 1251 | + $reg_step->translate_js_strings(); |
|
| 1252 | + if ($reg_step->is_current_step()) { |
|
| 1253 | + // the text that appears on the reg step form submit button |
|
| 1254 | + $reg_step->set_submit_button_text(); |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1258 | + do_action( |
|
| 1259 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
| 1260 | + $this->checkout->current_step |
|
| 1261 | + ); |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + |
|
| 1265 | + |
|
| 1266 | + /** |
|
| 1267 | + * _check_form_submission |
|
| 1268 | + * |
|
| 1269 | + * @access private |
|
| 1270 | + * @return boolean |
|
| 1271 | + */ |
|
| 1272 | + private function _check_form_submission() |
|
| 1273 | + { |
|
| 1274 | + //does this request require the reg form to be generated ? |
|
| 1275 | + if ($this->checkout->generate_reg_form) { |
|
| 1276 | + // ever heard that song by Blue Rodeo ? |
|
| 1277 | + try { |
|
| 1278 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1279 | + // if not displaying a form, then check for form submission |
|
| 1280 | + if ( |
|
| 1281 | + $this->checkout->process_form_submission |
|
| 1282 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
| 1283 | + ) { |
|
| 1284 | + // clear out any old data in case this step is being run again |
|
| 1285 | + $this->checkout->current_step->set_valid_data(array()); |
|
| 1286 | + // capture submitted form data |
|
| 1287 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1288 | + apply_filters( |
|
| 1289 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
| 1290 | + EE_Registry::instance()->REQ->params(), |
|
| 1291 | + $this->checkout |
|
| 1292 | + ) |
|
| 1293 | + ); |
|
| 1294 | + // validate submitted form data |
|
| 1295 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1296 | + // thou shall not pass !!! |
|
| 1297 | + $this->checkout->continue_reg = false; |
|
| 1298 | + // any form validation errors? |
|
| 1299 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1300 | + $submission_error_messages = array(); |
|
| 1301 | + // bad, bad, bad registrant |
|
| 1302 | + foreach ( |
|
| 1303 | + $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
| 1304 | + as $validation_error |
|
| 1305 | + ) { |
|
| 1306 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1307 | + $submission_error_messages[] = sprintf( |
|
| 1308 | + __('%s : %s', 'event_espresso'), |
|
| 1309 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1310 | + $validation_error->getMessage() |
|
| 1311 | + ); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + EE_Error::add_error( |
|
| 1315 | + implode('<br />', $submission_error_messages), |
|
| 1316 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1317 | + ); |
|
| 1318 | + } |
|
| 1319 | + // well not really... what will happen is |
|
| 1320 | + // we'll just get redirected back to redo the current step |
|
| 1321 | + $this->go_to_next_step(); |
|
| 1322 | + return false; |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + } catch (EE_Error $e) { |
|
| 1326 | + $e->get_error(); |
|
| 1327 | + } |
|
| 1328 | + } |
|
| 1329 | + return true; |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * _process_action |
|
| 1336 | + * |
|
| 1337 | + * @access private |
|
| 1338 | + * @return void |
|
| 1339 | + * @throws EE_Error |
|
| 1340 | + */ |
|
| 1341 | + private function _process_form_action() |
|
| 1342 | + { |
|
| 1343 | + // what cha wanna do? |
|
| 1344 | + switch ($this->checkout->action) { |
|
| 1345 | + // AJAX next step reg form |
|
| 1346 | + case 'display_spco_reg_step' : |
|
| 1347 | + $this->checkout->redirect = false; |
|
| 1348 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1349 | + $this->checkout->json_response->set_reg_step_html( |
|
| 1350 | + $this->checkout->current_step->display_reg_form() |
|
| 1351 | + ); |
|
| 1352 | + } |
|
| 1353 | + break; |
|
| 1354 | + default : |
|
| 1355 | + // meh... do one of those other steps first |
|
| 1356 | + if ( |
|
| 1357 | + ! empty($this->checkout->action) |
|
| 1358 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
| 1359 | + ) { |
|
| 1360 | + // dynamically creates hook point like: |
|
| 1361 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1362 | + do_action( |
|
| 1363 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1364 | + $this->checkout->current_step |
|
| 1365 | + ); |
|
| 1366 | + // call action on current step |
|
| 1367 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1368 | + // good registrant, you get to proceed |
|
| 1369 | + if ( |
|
| 1370 | + $this->checkout->current_step->success_message() !== '' |
|
| 1371 | + && apply_filters( |
|
| 1372 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1373 | + false |
|
| 1374 | + ) |
|
| 1375 | + ) { |
|
| 1376 | + EE_Error::add_success( |
|
| 1377 | + $this->checkout->current_step->success_message() |
|
| 1378 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1379 | + ); |
|
| 1380 | + } |
|
| 1381 | + // pack it up, pack it in... |
|
| 1382 | + $this->_setup_redirect(); |
|
| 1383 | + } |
|
| 1384 | + // dynamically creates hook point like: |
|
| 1385 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1386 | + do_action( |
|
| 1387 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1388 | + $this->checkout->current_step |
|
| 1389 | + ); |
|
| 1390 | + } else { |
|
| 1391 | + EE_Error::add_error( |
|
| 1392 | + sprintf( |
|
| 1393 | + __( |
|
| 1394 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
| 1395 | + 'event_espresso' |
|
| 1396 | + ), |
|
| 1397 | + $this->checkout->action, |
|
| 1398 | + $this->checkout->current_step->name() |
|
| 1399 | + ), |
|
| 1400 | + __FILE__, |
|
| 1401 | + __FUNCTION__, |
|
| 1402 | + __LINE__ |
|
| 1403 | + ); |
|
| 1404 | + } |
|
| 1405 | + // end default |
|
| 1406 | + } |
|
| 1407 | + // store our progress so far |
|
| 1408 | + $this->checkout->stash_transaction_and_checkout(); |
|
| 1409 | + // advance to the next step! If you pass GO, collect $200 |
|
| 1410 | + $this->go_to_next_step(); |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + |
|
| 1414 | + |
|
| 1415 | + /** |
|
| 1416 | + * add_styles_and_scripts |
|
| 1417 | + * |
|
| 1418 | + * @access public |
|
| 1419 | + * @return void |
|
| 1420 | + */ |
|
| 1421 | + public function add_styles_and_scripts() |
|
| 1422 | + { |
|
| 1423 | + // i18n |
|
| 1424 | + $this->translate_js_strings(); |
|
| 1425 | + if ($this->checkout->admin_request) { |
|
| 1426 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1427 | + } else { |
|
| 1428 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1429 | + } |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * translate_js_strings |
|
| 1436 | + * |
|
| 1437 | + * @access public |
|
| 1438 | + * @return void |
|
| 1439 | + */ |
|
| 1440 | + public function translate_js_strings() |
|
| 1441 | + { |
|
| 1442 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1443 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1444 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
| 1445 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1446 | + 'event_espresso' |
|
| 1447 | + ); |
|
| 1448 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
| 1449 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1450 | + 'event_espresso' |
|
| 1451 | + ); |
|
| 1452 | + EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
| 1453 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
| 1454 | + 'event_espresso' |
|
| 1455 | + ); |
|
| 1456 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
| 1457 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
| 1458 | + 'event_espresso' |
|
| 1459 | + ); |
|
| 1460 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
| 1461 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
| 1462 | + 'event_espresso' |
|
| 1463 | + ); |
|
| 1464 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
| 1465 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
| 1466 | + 'event_espresso' |
|
| 1467 | + ); |
|
| 1468 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1469 | + __( |
|
| 1470 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
| 1471 | + 'event_espresso' |
|
| 1472 | + ), |
|
| 1473 | + '<br/>', |
|
| 1474 | + '<br/>' |
|
| 1475 | + ); |
|
| 1476 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1477 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1478 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1479 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1480 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1481 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1482 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1483 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1484 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1485 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1486 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1487 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1488 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1489 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1490 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1491 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1492 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1493 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1494 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 1495 | + __( |
|
| 1496 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 1497 | + 'event_espresso' |
|
| 1498 | + ), |
|
| 1499 | + '<h4 class="important-notice">', |
|
| 1500 | + '</h4>', |
|
| 1501 | + '<br />', |
|
| 1502 | + '<p>', |
|
| 1503 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1504 | + '">', |
|
| 1505 | + '</a>', |
|
| 1506 | + '</p>' |
|
| 1507 | + ); |
|
| 1508 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
| 1509 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
| 1510 | + true |
|
| 1511 | + ); |
|
| 1512 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
| 1513 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
| 1514 | + ); |
|
| 1515 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
| 1516 | + 'M d, Y H:i:s', |
|
| 1517 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1518 | + ); |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * enqueue_styles_and_scripts |
|
| 1525 | + * |
|
| 1526 | + * @access public |
|
| 1527 | + * @return void |
|
| 1528 | + * @throws EE_Error |
|
| 1529 | + */ |
|
| 1530 | + public function enqueue_styles_and_scripts() |
|
| 1531 | + { |
|
| 1532 | + // load css |
|
| 1533 | + wp_register_style( |
|
| 1534 | + 'single_page_checkout', |
|
| 1535 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1536 | + array('espresso_default'), |
|
| 1537 | + EVENT_ESPRESSO_VERSION |
|
| 1538 | + ); |
|
| 1539 | + wp_enqueue_style('single_page_checkout'); |
|
| 1540 | + // load JS |
|
| 1541 | + wp_register_script( |
|
| 1542 | + 'jquery_plugin', |
|
| 1543 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1544 | + array('jquery'), |
|
| 1545 | + '1.0.1', |
|
| 1546 | + true |
|
| 1547 | + ); |
|
| 1548 | + wp_register_script( |
|
| 1549 | + 'jquery_countdown', |
|
| 1550 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1551 | + array('jquery_plugin'), |
|
| 1552 | + '2.0.2', |
|
| 1553 | + true |
|
| 1554 | + ); |
|
| 1555 | + wp_register_script( |
|
| 1556 | + 'single_page_checkout', |
|
| 1557 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1558 | + array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
| 1559 | + EVENT_ESPRESSO_VERSION, |
|
| 1560 | + true |
|
| 1561 | + ); |
|
| 1562 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
| 1563 | + $this->checkout->registration_form->enqueue_js(); |
|
| 1564 | + } |
|
| 1565 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
| 1566 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1567 | + } |
|
| 1568 | + wp_enqueue_script('single_page_checkout'); |
|
| 1569 | + /** |
|
| 1570 | + * global action hook for enqueueing styles and scripts with |
|
| 1571 | + * spco calls. |
|
| 1572 | + */ |
|
| 1573 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1574 | + /** |
|
| 1575 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1576 | + * The hook will end up being something like: |
|
| 1577 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1578 | + */ |
|
| 1579 | + do_action( |
|
| 1580 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1581 | + $this |
|
| 1582 | + ); |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + |
|
| 1586 | + |
|
| 1587 | + /** |
|
| 1588 | + * display the Registration Single Page Checkout Form |
|
| 1589 | + * |
|
| 1590 | + * @access private |
|
| 1591 | + * @return void |
|
| 1592 | + * @throws EE_Error |
|
| 1593 | + */ |
|
| 1594 | + private function _display_spco_reg_form() |
|
| 1595 | + { |
|
| 1596 | + // if registering via the admin, just display the reg form for the current step |
|
| 1597 | + if ($this->checkout->admin_request) { |
|
| 1598 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1599 | + } else { |
|
| 1600 | + // add powered by EE msg |
|
| 1601 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1602 | + $empty_cart = count( |
|
| 1603 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
| 1604 | + ) < 1; |
|
| 1605 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
| 1606 | + $cookies_not_set_msg = ''; |
|
| 1607 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
| 1608 | + $cookies_not_set_msg = apply_filters( |
|
| 1609 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1610 | + sprintf( |
|
| 1611 | + __( |
|
| 1612 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1613 | + 'event_espresso' |
|
| 1614 | + ), |
|
| 1615 | + '<div class="ee-attention">', |
|
| 1616 | + '</div>', |
|
| 1617 | + '<h6 class="important-notice">', |
|
| 1618 | + '</h6>', |
|
| 1619 | + '<p>', |
|
| 1620 | + '</p>', |
|
| 1621 | + '<br />', |
|
| 1622 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
| 1623 | + '</a>' |
|
| 1624 | + ) |
|
| 1625 | + ); |
|
| 1626 | + } |
|
| 1627 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1628 | + array( |
|
| 1629 | + 'name' => 'single-page-checkout', |
|
| 1630 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1631 | + 'layout_strategy' => |
|
| 1632 | + new EE_Template_Layout( |
|
| 1633 | + array( |
|
| 1634 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1635 | + 'template_args' => array( |
|
| 1636 | + 'empty_cart' => $empty_cart, |
|
| 1637 | + 'revisit' => $this->checkout->revisit, |
|
| 1638 | + 'reg_steps' => $this->checkout->reg_steps, |
|
| 1639 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
| 1640 | + ? $this->checkout->next_step->slug() |
|
| 1641 | + : '', |
|
| 1642 | + 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
| 1643 | + 'empty_msg' => apply_filters( |
|
| 1644 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1645 | + sprintf( |
|
| 1646 | + __( |
|
| 1647 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
| 1648 | + 'event_espresso' |
|
| 1649 | + ), |
|
| 1650 | + '<a href="' |
|
| 1651 | + . get_post_type_archive_link('espresso_events') |
|
| 1652 | + . '" title="', |
|
| 1653 | + '">', |
|
| 1654 | + '</a>' |
|
| 1655 | + ) |
|
| 1656 | + ), |
|
| 1657 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1658 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1659 | + 'session_expiration' => gmdate( |
|
| 1660 | + 'M d, Y H:i:s', |
|
| 1661 | + EE_Registry::instance()->SSN->expiration() |
|
| 1662 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1663 | + ), |
|
| 1664 | + ), |
|
| 1665 | + ) |
|
| 1666 | + ), |
|
| 1667 | + ) |
|
| 1668 | + ); |
|
| 1669 | + // load template and add to output sent that gets filtered into the_content() |
|
| 1670 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * add_extra_finalize_registration_inputs |
|
| 1678 | + * |
|
| 1679 | + * @access public |
|
| 1680 | + * @param $next_step |
|
| 1681 | + * @internal param string $label |
|
| 1682 | + * @return void |
|
| 1683 | + */ |
|
| 1684 | + public function add_extra_finalize_registration_inputs($next_step) |
|
| 1685 | + { |
|
| 1686 | + if ($next_step === 'finalize_registration') { |
|
| 1687 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1688 | + } |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + |
|
| 1692 | + |
|
| 1693 | + /** |
|
| 1694 | + * display_registration_footer |
|
| 1695 | + * |
|
| 1696 | + * @access public |
|
| 1697 | + * @return string |
|
| 1698 | + */ |
|
| 1699 | + public static function display_registration_footer() |
|
| 1700 | + { |
|
| 1701 | + if ( |
|
| 1702 | + apply_filters( |
|
| 1703 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1704 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1705 | + ) |
|
| 1706 | + ) { |
|
| 1707 | + add_filter( |
|
| 1708 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1709 | + function ($url) { |
|
| 1710 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1711 | + } |
|
| 1712 | + ); |
|
| 1713 | + echo apply_filters( |
|
| 1714 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1715 | + \EEH_Template::powered_by_event_espresso( |
|
| 1716 | + '', |
|
| 1717 | + 'espresso-registration-footer-dv', |
|
| 1718 | + array('utm_content' => 'registration_checkout') |
|
| 1719 | + ) |
|
| 1720 | + ); |
|
| 1721 | + } |
|
| 1722 | + return ''; |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + |
|
| 1727 | + /** |
|
| 1728 | + * unlock_transaction |
|
| 1729 | + * |
|
| 1730 | + * @access public |
|
| 1731 | + * @return void |
|
| 1732 | + * @throws EE_Error |
|
| 1733 | + */ |
|
| 1734 | + public function unlock_transaction() |
|
| 1735 | + { |
|
| 1736 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1737 | + $this->checkout->transaction->unlock(); |
|
| 1738 | + } |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + |
|
| 1742 | + |
|
| 1743 | + /** |
|
| 1744 | + * _setup_redirect |
|
| 1745 | + * |
|
| 1746 | + * @access private |
|
| 1747 | + * @return void |
|
| 1748 | + */ |
|
| 1749 | + private function _setup_redirect() |
|
| 1750 | + { |
|
| 1751 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1752 | + $this->checkout->redirect = true; |
|
| 1753 | + if (empty($this->checkout->redirect_url)) { |
|
| 1754 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1755 | + } |
|
| 1756 | + $this->checkout->redirect_url = apply_filters( |
|
| 1757 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1758 | + $this->checkout->redirect_url, |
|
| 1759 | + $this->checkout |
|
| 1760 | + ); |
|
| 1761 | + } |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + /** |
|
| 1767 | + * handle ajax message responses and redirects |
|
| 1768 | + * |
|
| 1769 | + * @access public |
|
| 1770 | + * @return void |
|
| 1771 | + * @throws EE_Error |
|
| 1772 | + */ |
|
| 1773 | + public function go_to_next_step() |
|
| 1774 | + { |
|
| 1775 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1776 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1777 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1778 | + } |
|
| 1779 | + $this->unlock_transaction(); |
|
| 1780 | + // just return for these conditions |
|
| 1781 | + if ( |
|
| 1782 | + $this->checkout->admin_request |
|
| 1783 | + || $this->checkout->action === 'redirect_form' |
|
| 1784 | + || $this->checkout->action === 'update_checkout' |
|
| 1785 | + ) { |
|
| 1786 | + return; |
|
| 1787 | + } |
|
| 1788 | + // AJAX response |
|
| 1789 | + $this->_handle_json_response(); |
|
| 1790 | + // redirect to next step or the Thank You page |
|
| 1791 | + $this->_handle_html_redirects(); |
|
| 1792 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1793 | + $this->_display_spco_reg_form(); |
|
| 1794 | + } |
|
| 1795 | + |
|
| 1796 | + |
|
| 1797 | + |
|
| 1798 | + /** |
|
| 1799 | + * _handle_json_response |
|
| 1800 | + * |
|
| 1801 | + * @access protected |
|
| 1802 | + * @return void |
|
| 1803 | + */ |
|
| 1804 | + protected function _handle_json_response() |
|
| 1805 | + { |
|
| 1806 | + // if this is an ajax request |
|
| 1807 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1808 | + // DEBUG LOG |
|
| 1809 | + //$this->checkout->log( |
|
| 1810 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1811 | + // array( |
|
| 1812 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
| 1813 | + // 'redirect' => $this->checkout->redirect, |
|
| 1814 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
| 1815 | + // ) |
|
| 1816 | + //); |
|
| 1817 | + $this->checkout->json_response->set_registration_time_limit( |
|
| 1818 | + $this->checkout->get_registration_time_limit() |
|
| 1819 | + ); |
|
| 1820 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1821 | + // just send the ajax ( |
|
| 1822 | + $json_response = apply_filters( |
|
| 1823 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1824 | + $this->checkout->json_response |
|
| 1825 | + ); |
|
| 1826 | + echo $json_response; |
|
| 1827 | + exit(); |
|
| 1828 | + } |
|
| 1829 | + } |
|
| 1830 | + |
|
| 1831 | + |
|
| 1832 | + |
|
| 1833 | + /** |
|
| 1834 | + * _handle_redirects |
|
| 1835 | + * |
|
| 1836 | + * @access protected |
|
| 1837 | + * @return void |
|
| 1838 | + */ |
|
| 1839 | + protected function _handle_html_redirects() |
|
| 1840 | + { |
|
| 1841 | + // going somewhere ? |
|
| 1842 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1843 | + // store notices in a transient |
|
| 1844 | + EE_Error::get_notices(false, true, true); |
|
| 1845 | + // DEBUG LOG |
|
| 1846 | + //$this->checkout->log( |
|
| 1847 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1848 | + // array( |
|
| 1849 | + // 'headers_sent' => headers_sent(), |
|
| 1850 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
| 1851 | + // 'headers_list' => headers_list(), |
|
| 1852 | + // ) |
|
| 1853 | + //); |
|
| 1854 | + wp_safe_redirect($this->checkout->redirect_url); |
|
| 1855 | + exit(); |
|
| 1856 | + } |
|
| 1857 | + } |
|
| 1858 | + |
|
| 1859 | + |
|
| 1860 | + |
|
| 1861 | + /** |
|
| 1862 | + * set_checkout_anchor |
|
| 1863 | + * |
|
| 1864 | + * @access public |
|
| 1865 | + * @return void |
|
| 1866 | + */ |
|
| 1867 | + public function set_checkout_anchor() |
|
| 1868 | + { |
|
| 1869 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1870 | + } |
|
| 1871 | 1871 | |
| 1872 | 1872 | |
| 1873 | 1873 | |
@@ -218,19 +218,19 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public static function set_definitions() |
| 220 | 220 | { |
| 221 | - if(defined('SPCO_BASE_PATH')) { |
|
| 221 | + if (defined('SPCO_BASE_PATH')) { |
|
| 222 | 222 | return; |
| 223 | 223 | } |
| 224 | 224 | define( |
| 225 | 225 | 'SPCO_BASE_PATH', |
| 226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
| 226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS |
|
| 227 | 227 | ); |
| 228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
| 229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
| 230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
| 231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
| 232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
| 233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
| 234 | 234 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
| 235 | 235 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
| 236 | 236 | __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | '</h4>', |
| 240 | 240 | '<br />', |
| 241 | 241 | '<p>', |
| 242 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 242 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 243 | 243 | '">', |
| 244 | 244 | '</a>', |
| 245 | 245 | '</p>' |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | // filter list of reg_steps |
| 265 | - $reg_steps_to_load = (array)apply_filters( |
|
| 265 | + $reg_steps_to_load = (array) apply_filters( |
|
| 266 | 266 | 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
| 267 | 267 | EED_Single_Page_Checkout::get_reg_steps() |
| 268 | 268 | ); |
@@ -314,25 +314,25 @@ discard block |
||
| 314 | 314 | if (empty($reg_steps)) { |
| 315 | 315 | $reg_steps = array( |
| 316 | 316 | 10 => array( |
| 317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 317 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
| 318 | 318 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
| 319 | 319 | 'slug' => 'attendee_information', |
| 320 | 320 | 'has_hooks' => false, |
| 321 | 321 | ), |
| 322 | 322 | 20 => array( |
| 323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 323 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
| 324 | 324 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
| 325 | 325 | 'slug' => 'registration_confirmation', |
| 326 | 326 | 'has_hooks' => false, |
| 327 | 327 | ), |
| 328 | 328 | 30 => array( |
| 329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 329 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
| 330 | 330 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
| 331 | 331 | 'slug' => 'payment_options', |
| 332 | 332 | 'has_hooks' => true, |
| 333 | 333 | ), |
| 334 | 334 | 999 => array( |
| 335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 335 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
| 336 | 336 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
| 337 | 337 | 'slug' => 'finalize_registration', |
| 338 | 338 | 'has_hooks' => false, |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | // DEBUG LOG |
| 517 | 517 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
| 518 | 518 | // get reg form |
| 519 | - if( ! $this->_check_form_submission()) { |
|
| 519 | + if ( ! $this->_check_form_submission()) { |
|
| 520 | 520 | EED_Single_Page_Checkout::$_initialized = true; |
| 521 | 521 | return; |
| 522 | 522 | } |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | if ( ! $registration instanceof EE_Registration) { |
| 1115 | 1115 | throw new InvalidEntityException($registration, 'EE_Registration'); |
| 1116 | 1116 | } |
| 1117 | - $registrations[ $registration->ID() ] = $registration; |
|
| 1117 | + $registrations[$registration->ID()] = $registration; |
|
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| 1120 | 1120 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1375,7 +1375,7 @@ discard block |
||
| 1375 | 1375 | ) { |
| 1376 | 1376 | EE_Error::add_success( |
| 1377 | 1377 | $this->checkout->current_step->success_message() |
| 1378 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1378 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
| 1379 | 1379 | ); |
| 1380 | 1380 | } |
| 1381 | 1381 | // pack it up, pack it in... |
@@ -1500,7 +1500,7 @@ discard block |
||
| 1500 | 1500 | '</h4>', |
| 1501 | 1501 | '<br />', |
| 1502 | 1502 | '<p>', |
| 1503 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1503 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
| 1504 | 1504 | '">', |
| 1505 | 1505 | '</a>', |
| 1506 | 1506 | '</p>' |
@@ -1532,7 +1532,7 @@ discard block |
||
| 1532 | 1532 | // load css |
| 1533 | 1533 | wp_register_style( |
| 1534 | 1534 | 'single_page_checkout', |
| 1535 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1535 | + SPCO_CSS_URL.'single_page_checkout.css', |
|
| 1536 | 1536 | array('espresso_default'), |
| 1537 | 1537 | EVENT_ESPRESSO_VERSION |
| 1538 | 1538 | ); |
@@ -1540,21 +1540,21 @@ discard block |
||
| 1540 | 1540 | // load JS |
| 1541 | 1541 | wp_register_script( |
| 1542 | 1542 | 'jquery_plugin', |
| 1543 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1543 | + EE_THIRD_PARTY_URL.'jquery .plugin.min.js', |
|
| 1544 | 1544 | array('jquery'), |
| 1545 | 1545 | '1.0.1', |
| 1546 | 1546 | true |
| 1547 | 1547 | ); |
| 1548 | 1548 | wp_register_script( |
| 1549 | 1549 | 'jquery_countdown', |
| 1550 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1550 | + EE_THIRD_PARTY_URL.'jquery .countdown.min.js', |
|
| 1551 | 1551 | array('jquery_plugin'), |
| 1552 | 1552 | '2.0.2', |
| 1553 | 1553 | true |
| 1554 | 1554 | ); |
| 1555 | 1555 | wp_register_script( |
| 1556 | 1556 | 'single_page_checkout', |
| 1557 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1557 | + SPCO_JS_URL.'single_page_checkout.js', |
|
| 1558 | 1558 | array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
| 1559 | 1559 | EVENT_ESPRESSO_VERSION, |
| 1560 | 1560 | true |
@@ -1577,7 +1577,7 @@ discard block |
||
| 1577 | 1577 | * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
| 1578 | 1578 | */ |
| 1579 | 1579 | do_action( |
| 1580 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1580 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), |
|
| 1581 | 1581 | $this |
| 1582 | 1582 | ); |
| 1583 | 1583 | } |
@@ -1631,7 +1631,7 @@ discard block |
||
| 1631 | 1631 | 'layout_strategy' => |
| 1632 | 1632 | new EE_Template_Layout( |
| 1633 | 1633 | array( |
| 1634 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1634 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
| 1635 | 1635 | 'template_args' => array( |
| 1636 | 1636 | 'empty_cart' => $empty_cart, |
| 1637 | 1637 | 'revisit' => $this->checkout->revisit, |
@@ -1706,7 +1706,7 @@ discard block |
||
| 1706 | 1706 | ) { |
| 1707 | 1707 | add_filter( |
| 1708 | 1708 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
| 1709 | - function ($url) { |
|
| 1709 | + function($url) { |
|
| 1710 | 1710 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
| 1711 | 1711 | } |
| 1712 | 1712 | ); |
@@ -14,757 +14,757 @@ discard block |
||
| 14 | 14 | class EED_Thank_You_Page extends EED_Module |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
| 19 | - */ |
|
| 20 | - const IPN_wait_time = 1200; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
| 24 | - * |
|
| 25 | - * @var EE_Transaction $_current_txn |
|
| 26 | - */ |
|
| 27 | - private $_current_txn; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var EE_Registration $_primary_registrant |
|
| 31 | - */ |
|
| 32 | - private $_primary_registrant; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * The reg_url_link passed from the Request, or from the Session |
|
| 36 | - * |
|
| 37 | - * @var string $_reg_url_link |
|
| 38 | - */ |
|
| 39 | - private $_reg_url_link; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * whether the incoming reg_url_link is for the primary registrant or not |
|
| 43 | - * |
|
| 44 | - * @var boolean $_is_primary |
|
| 45 | - */ |
|
| 46 | - private $_is_primary; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The URL for revisiting the SPCO attendee information step |
|
| 50 | - * |
|
| 51 | - * @var string $_SPCO_attendee_information_url |
|
| 52 | - */ |
|
| 53 | - private $_SPCO_attendee_information_url; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The URL for revisiting the SPCO payment options step |
|
| 57 | - * |
|
| 58 | - * @var string $_SPCO_payment_options_url |
|
| 59 | - */ |
|
| 60 | - private $_SPCO_payment_options_url; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * whether to display the Payment Options link |
|
| 64 | - * |
|
| 65 | - * @var boolean $_show_try_pay_again_link |
|
| 66 | - */ |
|
| 67 | - private $_show_try_pay_again_link = false; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * whether payments are allowed at this time |
|
| 71 | - * |
|
| 72 | - * @var boolean $_payments_closed |
|
| 73 | - */ |
|
| 74 | - private $_payments_closed = false; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * whether the selected payment method is Bank, Check , Invoice, etc |
|
| 78 | - * |
|
| 79 | - * @var boolean $_is_offline_payment_method |
|
| 80 | - */ |
|
| 81 | - private $_is_offline_payment_method = true; |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return EED_Module|EED_Thank_You_Page |
|
| 87 | - */ |
|
| 88 | - public static function instance() |
|
| 89 | - { |
|
| 90 | - return parent::get_instance(__CLASS__); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * set_hooks - for hooking into EE Core, modules, etc |
|
| 96 | - * |
|
| 97 | - * @return void |
|
| 98 | - */ |
|
| 99 | - public static function set_hooks() |
|
| 100 | - { |
|
| 101 | - add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
| 108 | - * |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public static function set_hooks_admin() |
|
| 112 | - { |
|
| 113 | - // AJAX for IPN monitoring |
|
| 114 | - add_filter('heartbeat_received', array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'), 10, 3); |
|
| 115 | - add_filter( |
|
| 116 | - 'heartbeat_nopriv_received', |
|
| 117 | - array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'), |
|
| 118 | - 10, |
|
| 119 | - 3 |
|
| 120 | - ); |
|
| 121 | - add_action( |
|
| 122 | - 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
| 123 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
| 124 | - 10, |
|
| 125 | - 2 |
|
| 126 | - ); |
|
| 127 | - add_action( |
|
| 128 | - 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
| 129 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
| 130 | - 10, |
|
| 131 | - 2 |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * set_definitions |
|
| 139 | - * |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - public static function set_definitions() |
|
| 143 | - { |
|
| 144 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 145 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * get_txn |
|
| 152 | - * |
|
| 153 | - * @return EE_Transaction |
|
| 154 | - */ |
|
| 155 | - public function get_txn() |
|
| 156 | - { |
|
| 157 | - if ($this->_current_txn instanceof EE_Transaction) { |
|
| 158 | - return $this->_current_txn; |
|
| 159 | - } |
|
| 160 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 161 | - if ( ! $TXN_model instanceof EEM_Transaction) { |
|
| 162 | - EE_Error::add_error( |
|
| 163 | - __('The transaction model could not be established.', 'event_espresso'), |
|
| 164 | - __FILE__, |
|
| 165 | - __FUNCTION__, |
|
| 166 | - __LINE__ |
|
| 167 | - ); |
|
| 168 | - return null; |
|
| 169 | - } |
|
| 170 | - //get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
| 171 | - $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
| 172 | - // verify TXN |
|
| 173 | - if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
| 174 | - EE_Error::add_error( |
|
| 175 | - __( |
|
| 176 | - 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
| 177 | - 'event_espresso' |
|
| 178 | - ), |
|
| 179 | - __FILE__, |
|
| 180 | - __FUNCTION__, |
|
| 181 | - __LINE__ |
|
| 182 | - ); |
|
| 183 | - return null; |
|
| 184 | - } |
|
| 185 | - return $this->_current_txn; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * get_txn_payments |
|
| 192 | - * |
|
| 193 | - * @param int $since |
|
| 194 | - * @return mixed array of EE_Payment || FALSE |
|
| 195 | - * @throws \EE_Error |
|
| 196 | - */ |
|
| 197 | - public function get_txn_payments($since = 0) |
|
| 198 | - { |
|
| 199 | - if ( ! $this->get_txn()) { |
|
| 200 | - return false; |
|
| 201 | - } |
|
| 202 | - $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
| 203 | - if ($since > 0) { |
|
| 204 | - $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
| 205 | - } |
|
| 206 | - // get array of payments with most recent first |
|
| 207 | - return $this->_current_txn->payments($args); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * get_reg_url_link |
|
| 214 | - * |
|
| 215 | - * @return void |
|
| 216 | - */ |
|
| 217 | - private function _get_reg_url_link() |
|
| 218 | - { |
|
| 219 | - if ( ! empty($this->_reg_url_link)) { |
|
| 220 | - return; |
|
| 221 | - } |
|
| 222 | - // only do thank you page stuff if we have a REG_url_link in the url |
|
| 223 | - if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
| 224 | - EE_Error::add_error( |
|
| 225 | - __( |
|
| 226 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
| 227 | - 'event_espresso' |
|
| 228 | - ), |
|
| 229 | - __FILE__, |
|
| 230 | - __FUNCTION__, |
|
| 231 | - __LINE__ |
|
| 232 | - ); |
|
| 233 | - return; |
|
| 234 | - } |
|
| 235 | - // check for reg_url_link |
|
| 236 | - $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * set_reg_url_link |
|
| 243 | - * |
|
| 244 | - * @param string $reg_url_link |
|
| 245 | - */ |
|
| 246 | - public function set_reg_url_link($reg_url_link = null) |
|
| 247 | - { |
|
| 248 | - $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * run - initial module setup |
|
| 255 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
| 256 | - * |
|
| 257 | - * @param WP $WP |
|
| 258 | - * @return void |
|
| 259 | - * @throws \EE_Error |
|
| 260 | - */ |
|
| 261 | - public function run($WP) |
|
| 262 | - { |
|
| 263 | - |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * load_resources |
|
| 270 | - * |
|
| 271 | - * @return void |
|
| 272 | - * @throws \EE_Error |
|
| 273 | - */ |
|
| 274 | - public function load_resources() { |
|
| 275 | - $this->_get_reg_url_link(); |
|
| 276 | - // resend_reg_confirmation_email ? |
|
| 277 | - if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
| 278 | - EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
| 279 | - } |
|
| 280 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 281 | - $this->_translate_strings(); |
|
| 282 | - // load assets |
|
| 283 | - add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * load_js |
|
| 290 | - * |
|
| 291 | - * @return void |
|
| 292 | - */ |
|
| 293 | - protected function _translate_strings() |
|
| 294 | - { |
|
| 295 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
| 296 | - EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
| 297 | - EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
| 298 | - EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
| 299 | - EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
| 300 | - EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
| 301 | - 'checking for new payments...', |
|
| 302 | - 'event_espresso' |
|
| 303 | - ); |
|
| 304 | - EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
| 305 | - 'loading payment information...', |
|
| 306 | - 'event_espresso' |
|
| 307 | - ); |
|
| 308 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
| 309 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
| 310 | - 'event_espresso' |
|
| 311 | - ); |
|
| 312 | - EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
| 313 | - 'EED_Thank_You_Page__load_js__slow_IPN', |
|
| 314 | - sprintf( |
|
| 315 | - __( |
|
| 316 | - '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
| 317 | - 'event_espresso' |
|
| 318 | - ), |
|
| 319 | - '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
| 320 | - '</div>' |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * load_js |
|
| 329 | - * |
|
| 330 | - * @return void |
|
| 331 | - */ |
|
| 332 | - public function load_js() |
|
| 333 | - { |
|
| 334 | - wp_register_script( |
|
| 335 | - 'thank_you_page', |
|
| 336 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
| 337 | - array('espresso_core', 'heartbeat'), |
|
| 338 | - EVENT_ESPRESSO_VERSION, |
|
| 339 | - true |
|
| 340 | - ); |
|
| 341 | - wp_enqueue_script('thank_you_page'); |
|
| 342 | - wp_enqueue_style('espresso_default'); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * init |
|
| 349 | - * |
|
| 350 | - * @return void |
|
| 351 | - * @throws \EE_Error |
|
| 352 | - */ |
|
| 353 | - public function init() |
|
| 354 | - { |
|
| 355 | - $this->_get_reg_url_link(); |
|
| 356 | - if ( ! $this->get_txn()) { |
|
| 357 | - echo EEH_HTML::div( |
|
| 358 | - EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
| 359 | - sprintf( |
|
| 360 | - __( |
|
| 361 | - 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
| 362 | - 'event_espresso' |
|
| 363 | - ), |
|
| 364 | - '<br/>' |
|
| 365 | - ), |
|
| 366 | - '', |
|
| 367 | - 'ee-attention' |
|
| 368 | - ); |
|
| 369 | - return null; |
|
| 370 | - } |
|
| 371 | - // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
| 372 | - if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
| 373 | - $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
| 374 | - $this->_current_txn->save(); |
|
| 375 | - } |
|
| 376 | - $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
| 377 | - ? $this->_current_txn->primary_registration() |
|
| 378 | - : null; |
|
| 379 | - $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false; |
|
| 380 | - $show_try_pay_again_link_default = apply_filters( |
|
| 381 | - 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
| 382 | - true |
|
| 383 | - ); |
|
| 384 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
| 385 | - // txn status ? |
|
| 386 | - if ($this->_current_txn->is_completed()) { |
|
| 387 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
| 388 | - } else if ( |
|
| 389 | - $this->_current_txn->is_incomplete() |
|
| 390 | - && ($this->_primary_registrant->is_approved() |
|
| 391 | - || $this->_primary_registrant->is_pending_payment()) |
|
| 392 | - ) { |
|
| 393 | - $this->_show_try_pay_again_link = true; |
|
| 394 | - } else if ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
| 395 | - // its pending |
|
| 396 | - $this->_show_try_pay_again_link = isset( |
|
| 397 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
| 398 | - ) |
|
| 399 | - && EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
| 400 | - ? true |
|
| 401 | - : $show_try_pay_again_link_default; |
|
| 402 | - } |
|
| 403 | - $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
| 404 | - ? true |
|
| 405 | - : false; |
|
| 406 | - $this->_is_offline_payment_method = false; |
|
| 407 | - if ( |
|
| 408 | - // if payment method is unknown |
|
| 409 | - ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
| 410 | - || ( |
|
| 411 | - // or is an offline payment method |
|
| 412 | - $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
| 413 | - && $this->_current_txn->payment_method()->is_off_line() |
|
| 414 | - ) |
|
| 415 | - ) { |
|
| 416 | - $this->_is_offline_payment_method = true; |
|
| 417 | - } |
|
| 418 | - // link to SPCO |
|
| 419 | - $revisit_spco_url = add_query_arg( |
|
| 420 | - array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
| 421 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 422 | - ); |
|
| 423 | - // link to SPCO payment_options |
|
| 424 | - $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
| 425 | - ? $this->_primary_registrant->payment_overview_url() |
|
| 426 | - : add_query_arg( |
|
| 427 | - array('step' => 'payment_options'), |
|
| 428 | - $revisit_spco_url |
|
| 429 | - ); |
|
| 430 | - // link to SPCO attendee_information |
|
| 431 | - $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
| 432 | - ? $this->_primary_registrant->edit_attendee_information_url() |
|
| 433 | - : false; |
|
| 434 | - do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
| 435 | - // set no cache headers and constants |
|
| 436 | - EE_System::do_not_cache(); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * display_thank_you_page_results |
|
| 443 | - * |
|
| 444 | - * @return string |
|
| 445 | - * @throws \EE_Error |
|
| 446 | - */ |
|
| 447 | - public function thank_you_page_results() |
|
| 448 | - { |
|
| 449 | - $this->init(); |
|
| 450 | - if ( ! $this->_current_txn instanceof EE_Transaction) { |
|
| 451 | - return EE_Error::get_notices(); |
|
| 452 | - } |
|
| 453 | - // link to receipt |
|
| 454 | - $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
| 455 | - if ( ! empty($template_args['TXN_receipt_url'])) { |
|
| 456 | - $template_args['order_conf_desc'] = __( |
|
| 457 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
| 458 | - 'event_espresso' |
|
| 459 | - ); |
|
| 460 | - } else { |
|
| 461 | - $template_args['order_conf_desc'] = __( |
|
| 462 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
| 463 | - 'event_espresso' |
|
| 464 | - ); |
|
| 465 | - } |
|
| 466 | - $template_args['transaction'] = $this->_current_txn; |
|
| 467 | - $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
| 468 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
| 469 | - if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
| 470 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
| 471 | - } |
|
| 472 | - return EEH_Template::locate_template( |
|
| 473 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
| 474 | - $template_args, |
|
| 475 | - true, |
|
| 476 | - true |
|
| 477 | - ); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * thank_you_page_IPN_monitor |
|
| 484 | - * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
| 485 | - * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
| 486 | - * it also calculates the IPN wait time since the Thank You page was first loaded |
|
| 487 | - * |
|
| 488 | - * @param array $response |
|
| 489 | - * @param array $data |
|
| 490 | - * @return array |
|
| 491 | - * @throws \EE_Error |
|
| 492 | - */ |
|
| 493 | - public static function thank_you_page_IPN_monitor($response = array(), $data = array()) |
|
| 494 | - { |
|
| 495 | - // does this heartbeat contain our data ? |
|
| 496 | - if ( ! isset($data['espresso_thank_you_page'])) { |
|
| 497 | - return $response; |
|
| 498 | - } |
|
| 499 | - // check for reg_url_link in the incoming heartbeat data |
|
| 500 | - if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
| 501 | - $response['espresso_thank_you_page'] = array( |
|
| 502 | - 'errors' => ! empty($notices['errors']) |
|
| 503 | - ? $notices['errors'] |
|
| 504 | - : __( |
|
| 505 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
| 506 | - 'event_espresso' |
|
| 507 | - ) |
|
| 508 | - ); |
|
| 509 | - return $response; |
|
| 510 | - } |
|
| 511 | - // kk heartbeat has our data |
|
| 512 | - $response['espresso_thank_you_page'] = array(); |
|
| 513 | - // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
| 514 | - EED_Thank_You_Page::set_definitions(); |
|
| 515 | - /** @var $espresso_thank_you_page EED_Thank_You_Page */ |
|
| 516 | - $espresso_thank_you_page = EED_Thank_You_Page::instance(); |
|
| 517 | - $espresso_thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']); |
|
| 518 | - $espresso_thank_you_page->init(); |
|
| 519 | - //get TXN |
|
| 520 | - $TXN = $espresso_thank_you_page->get_txn(); |
|
| 521 | - // no TXN? then get out |
|
| 522 | - if ( ! $TXN instanceof EE_Transaction) { |
|
| 523 | - $notices = EE_Error::get_notices(); |
|
| 524 | - $response['espresso_thank_you_page'] = array( |
|
| 525 | - 'errors' => ! empty($notices['errors']) |
|
| 526 | - ? $notices['errors'] |
|
| 527 | - : sprintf( |
|
| 528 | - __( |
|
| 529 | - 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
| 530 | - 'event_espresso' |
|
| 531 | - ), |
|
| 532 | - __LINE__ |
|
| 533 | - ) |
|
| 534 | - ); |
|
| 535 | - return $response; |
|
| 536 | - } |
|
| 537 | - // grab transient of TXN's status |
|
| 538 | - $txn_status = isset($data['espresso_thank_you_page']['txn_status']) |
|
| 539 | - ? $data['espresso_thank_you_page']['txn_status'] |
|
| 540 | - : null; |
|
| 541 | - // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
| 542 | - if ($txn_status !== $TXN->status_ID()) { |
|
| 543 | - // switch between two possible basic outcomes |
|
| 544 | - switch ($TXN->status_ID()) { |
|
| 545 | - // TXN has been updated in some way |
|
| 546 | - case EEM_Transaction::overpaid_status_code: |
|
| 547 | - case EEM_Transaction::complete_status_code: |
|
| 548 | - case EEM_Transaction::incomplete_status_code: |
|
| 549 | - // send updated TXN results back to client, |
|
| 550 | - $response['espresso_thank_you_page'] = array( |
|
| 551 | - 'transaction_details' => $espresso_thank_you_page->get_transaction_details(), |
|
| 552 | - 'txn_status' => $TXN->status_ID() |
|
| 553 | - ); |
|
| 554 | - break; |
|
| 555 | - // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
| 556 | - case EEM_Transaction::failed_status_code: |
|
| 557 | - default: |
|
| 558 | - // keep on waiting... |
|
| 559 | - return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']); |
|
| 560 | - } |
|
| 561 | - // or is the TXN still failed (never been updated) ??? |
|
| 562 | - } else if ($TXN->failed()) { |
|
| 563 | - // keep on waiting... |
|
| 564 | - return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']); |
|
| 565 | - } |
|
| 566 | - // TXN is happening so let's get the payments now |
|
| 567 | - // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
| 568 | - $since = isset($data['espresso_thank_you_page']['get_payments_since']) |
|
| 569 | - ? $data['espresso_thank_you_page']['get_payments_since'] |
|
| 570 | - : 0; |
|
| 571 | - // then check for payments |
|
| 572 | - $payments = $espresso_thank_you_page->get_txn_payments($since); |
|
| 573 | - // has a payment been processed ? |
|
| 574 | - if ( ! empty($payments) || $espresso_thank_you_page->_is_offline_payment_method) { |
|
| 575 | - if ($since) { |
|
| 576 | - $response['espresso_thank_you_page'] = array( |
|
| 577 | - 'new_payments' => $espresso_thank_you_page->get_new_payments($payments), |
|
| 578 | - 'transaction_details' => $espresso_thank_you_page->get_transaction_details(), |
|
| 579 | - 'txn_status' => $TXN->status_ID() |
|
| 580 | - ); |
|
| 581 | - } else { |
|
| 582 | - $response['espresso_thank_you_page']['payment_details'] = $espresso_thank_you_page->get_payment_details( |
|
| 583 | - $payments |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - // reset time to check for payments |
|
| 587 | - $response['espresso_thank_you_page']['get_payments_since'] = time(); |
|
| 588 | - } else { |
|
| 589 | - $response['espresso_thank_you_page']['get_payments_since'] = $since; |
|
| 590 | - } |
|
| 591 | - return $response; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * _update_server_wait_time |
|
| 598 | - * |
|
| 599 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
| 600 | - * @return array |
|
| 601 | - * @throws \EE_Error |
|
| 602 | - */ |
|
| 603 | - private function _update_server_wait_time($thank_you_page_data = array()) |
|
| 604 | - { |
|
| 605 | - $response['espresso_thank_you_page'] = array( |
|
| 606 | - 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
| 607 | - ? time() - $thank_you_page_data['initial_access'] |
|
| 608 | - : 0, |
|
| 609 | - 'txn_status' => $this->_current_txn->status_ID() |
|
| 610 | - ); |
|
| 611 | - return $response; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * get_registration_details |
|
| 618 | - * |
|
| 619 | - * @throws \EE_Error |
|
| 620 | - */ |
|
| 621 | - public function get_registration_details() |
|
| 622 | - { |
|
| 623 | - //prepare variables for displaying |
|
| 624 | - $template_args = array(); |
|
| 625 | - $template_args['transaction'] = $this->_current_txn; |
|
| 626 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
| 627 | - $template_args['is_primary'] = $this->_is_primary; |
|
| 628 | - $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
| 629 | - $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
| 630 | - array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
| 631 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
| 632 | - ); |
|
| 633 | - // verify template arguments |
|
| 634 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
| 635 | - EEH_Template_Validator::verify_isnt_null( |
|
| 636 | - $template_args['SPCO_attendee_information_url'], |
|
| 637 | - '$SPCO_attendee_information_url' |
|
| 638 | - ); |
|
| 639 | - echo EEH_Template::locate_template( |
|
| 640 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
| 641 | - $template_args, |
|
| 642 | - true, |
|
| 643 | - true |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * resend_reg_confirmation_email |
|
| 651 | - * |
|
| 652 | - * @throws \EE_Error |
|
| 653 | - */ |
|
| 654 | - public static function resend_reg_confirmation_email() |
|
| 655 | - { |
|
| 656 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 657 | - $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
| 658 | - // was a REG_ID passed ? |
|
| 659 | - if ($reg_url_link) { |
|
| 660 | - $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
| 661 | - array(array('REG_url_link' => $reg_url_link)) |
|
| 662 | - ); |
|
| 663 | - if ($registration instanceof EE_Registration) { |
|
| 664 | - // resend email |
|
| 665 | - EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
| 666 | - } else { |
|
| 667 | - EE_Error::add_error( |
|
| 668 | - __( |
|
| 669 | - 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
| 670 | - 'event_espresso' |
|
| 671 | - ), |
|
| 672 | - __FILE__, |
|
| 673 | - __FUNCTION__, |
|
| 674 | - __LINE__ |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - } else { |
|
| 678 | - EE_Error::add_error( |
|
| 679 | - __( |
|
| 680 | - 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
| 681 | - 'event_espresso' |
|
| 682 | - ), |
|
| 683 | - __FILE__, |
|
| 684 | - __FUNCTION__, |
|
| 685 | - __LINE__ |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - // request sent via AJAX ? |
|
| 689 | - if (EE_FRONT_AJAX) { |
|
| 690 | - echo wp_json_encode(EE_Error::get_notices(false)); |
|
| 691 | - die(); |
|
| 692 | - // or was JS disabled ? |
|
| 693 | - } else { |
|
| 694 | - // save errors so that they get picked up on the next request |
|
| 695 | - EE_Error::get_notices(true, true); |
|
| 696 | - wp_safe_redirect( |
|
| 697 | - add_query_arg( |
|
| 698 | - array('e_reg_url_link' => $reg_url_link), |
|
| 699 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
| 700 | - ) |
|
| 701 | - ); |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * get_ajax_content |
|
| 709 | - * |
|
| 710 | - * @return void |
|
| 711 | - * @throws \EE_Error |
|
| 712 | - */ |
|
| 713 | - public function get_ajax_content() |
|
| 714 | - { |
|
| 715 | - if ( ! $this->get_txn()) { |
|
| 716 | - return; |
|
| 717 | - } |
|
| 718 | - // first determine which event(s) require pre-approval or not |
|
| 719 | - $events = array(); |
|
| 720 | - $events_requiring_pre_approval = array(); |
|
| 721 | - foreach ($this->_current_txn->registrations() as $registration) { |
|
| 722 | - if ($registration instanceof EE_Registration) { |
|
| 723 | - $event = $registration->event(); |
|
| 724 | - if ($event instanceof EE_Event) { |
|
| 725 | - if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
| 726 | - $events_requiring_pre_approval[$event->ID()] = $event; |
|
| 727 | - } else { |
|
| 728 | - $events[$event->ID()] = $event; |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
| 734 | - $this->display_details_for_events($events); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * display_details_for_events |
|
| 741 | - * |
|
| 742 | - * @param EE_Event[] $events |
|
| 743 | - * @return void |
|
| 744 | - */ |
|
| 745 | - public function display_details_for_events($events = array()) |
|
| 746 | - { |
|
| 747 | - if ( ! empty($events)) { |
|
| 748 | - ?> |
|
| 17 | + /** |
|
| 18 | + * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
| 19 | + */ |
|
| 20 | + const IPN_wait_time = 1200; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
| 24 | + * |
|
| 25 | + * @var EE_Transaction $_current_txn |
|
| 26 | + */ |
|
| 27 | + private $_current_txn; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var EE_Registration $_primary_registrant |
|
| 31 | + */ |
|
| 32 | + private $_primary_registrant; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * The reg_url_link passed from the Request, or from the Session |
|
| 36 | + * |
|
| 37 | + * @var string $_reg_url_link |
|
| 38 | + */ |
|
| 39 | + private $_reg_url_link; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * whether the incoming reg_url_link is for the primary registrant or not |
|
| 43 | + * |
|
| 44 | + * @var boolean $_is_primary |
|
| 45 | + */ |
|
| 46 | + private $_is_primary; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The URL for revisiting the SPCO attendee information step |
|
| 50 | + * |
|
| 51 | + * @var string $_SPCO_attendee_information_url |
|
| 52 | + */ |
|
| 53 | + private $_SPCO_attendee_information_url; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The URL for revisiting the SPCO payment options step |
|
| 57 | + * |
|
| 58 | + * @var string $_SPCO_payment_options_url |
|
| 59 | + */ |
|
| 60 | + private $_SPCO_payment_options_url; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * whether to display the Payment Options link |
|
| 64 | + * |
|
| 65 | + * @var boolean $_show_try_pay_again_link |
|
| 66 | + */ |
|
| 67 | + private $_show_try_pay_again_link = false; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * whether payments are allowed at this time |
|
| 71 | + * |
|
| 72 | + * @var boolean $_payments_closed |
|
| 73 | + */ |
|
| 74 | + private $_payments_closed = false; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * whether the selected payment method is Bank, Check , Invoice, etc |
|
| 78 | + * |
|
| 79 | + * @var boolean $_is_offline_payment_method |
|
| 80 | + */ |
|
| 81 | + private $_is_offline_payment_method = true; |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return EED_Module|EED_Thank_You_Page |
|
| 87 | + */ |
|
| 88 | + public static function instance() |
|
| 89 | + { |
|
| 90 | + return parent::get_instance(__CLASS__); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * set_hooks - for hooking into EE Core, modules, etc |
|
| 96 | + * |
|
| 97 | + * @return void |
|
| 98 | + */ |
|
| 99 | + public static function set_hooks() |
|
| 100 | + { |
|
| 101 | + add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
| 108 | + * |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public static function set_hooks_admin() |
|
| 112 | + { |
|
| 113 | + // AJAX for IPN monitoring |
|
| 114 | + add_filter('heartbeat_received', array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'), 10, 3); |
|
| 115 | + add_filter( |
|
| 116 | + 'heartbeat_nopriv_received', |
|
| 117 | + array('EED_Thank_You_Page', 'thank_you_page_IPN_monitor'), |
|
| 118 | + 10, |
|
| 119 | + 3 |
|
| 120 | + ); |
|
| 121 | + add_action( |
|
| 122 | + 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
| 123 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
| 124 | + 10, |
|
| 125 | + 2 |
|
| 126 | + ); |
|
| 127 | + add_action( |
|
| 128 | + 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
| 129 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
| 130 | + 10, |
|
| 131 | + 2 |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * set_definitions |
|
| 139 | + * |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + public static function set_definitions() |
|
| 143 | + { |
|
| 144 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 145 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * get_txn |
|
| 152 | + * |
|
| 153 | + * @return EE_Transaction |
|
| 154 | + */ |
|
| 155 | + public function get_txn() |
|
| 156 | + { |
|
| 157 | + if ($this->_current_txn instanceof EE_Transaction) { |
|
| 158 | + return $this->_current_txn; |
|
| 159 | + } |
|
| 160 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 161 | + if ( ! $TXN_model instanceof EEM_Transaction) { |
|
| 162 | + EE_Error::add_error( |
|
| 163 | + __('The transaction model could not be established.', 'event_espresso'), |
|
| 164 | + __FILE__, |
|
| 165 | + __FUNCTION__, |
|
| 166 | + __LINE__ |
|
| 167 | + ); |
|
| 168 | + return null; |
|
| 169 | + } |
|
| 170 | + //get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
| 171 | + $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
| 172 | + // verify TXN |
|
| 173 | + if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
| 174 | + EE_Error::add_error( |
|
| 175 | + __( |
|
| 176 | + 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
| 177 | + 'event_espresso' |
|
| 178 | + ), |
|
| 179 | + __FILE__, |
|
| 180 | + __FUNCTION__, |
|
| 181 | + __LINE__ |
|
| 182 | + ); |
|
| 183 | + return null; |
|
| 184 | + } |
|
| 185 | + return $this->_current_txn; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * get_txn_payments |
|
| 192 | + * |
|
| 193 | + * @param int $since |
|
| 194 | + * @return mixed array of EE_Payment || FALSE |
|
| 195 | + * @throws \EE_Error |
|
| 196 | + */ |
|
| 197 | + public function get_txn_payments($since = 0) |
|
| 198 | + { |
|
| 199 | + if ( ! $this->get_txn()) { |
|
| 200 | + return false; |
|
| 201 | + } |
|
| 202 | + $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
| 203 | + if ($since > 0) { |
|
| 204 | + $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
| 205 | + } |
|
| 206 | + // get array of payments with most recent first |
|
| 207 | + return $this->_current_txn->payments($args); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * get_reg_url_link |
|
| 214 | + * |
|
| 215 | + * @return void |
|
| 216 | + */ |
|
| 217 | + private function _get_reg_url_link() |
|
| 218 | + { |
|
| 219 | + if ( ! empty($this->_reg_url_link)) { |
|
| 220 | + return; |
|
| 221 | + } |
|
| 222 | + // only do thank you page stuff if we have a REG_url_link in the url |
|
| 223 | + if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
| 224 | + EE_Error::add_error( |
|
| 225 | + __( |
|
| 226 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
| 227 | + 'event_espresso' |
|
| 228 | + ), |
|
| 229 | + __FILE__, |
|
| 230 | + __FUNCTION__, |
|
| 231 | + __LINE__ |
|
| 232 | + ); |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | + // check for reg_url_link |
|
| 236 | + $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * set_reg_url_link |
|
| 243 | + * |
|
| 244 | + * @param string $reg_url_link |
|
| 245 | + */ |
|
| 246 | + public function set_reg_url_link($reg_url_link = null) |
|
| 247 | + { |
|
| 248 | + $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * run - initial module setup |
|
| 255 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
| 256 | + * |
|
| 257 | + * @param WP $WP |
|
| 258 | + * @return void |
|
| 259 | + * @throws \EE_Error |
|
| 260 | + */ |
|
| 261 | + public function run($WP) |
|
| 262 | + { |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * load_resources |
|
| 270 | + * |
|
| 271 | + * @return void |
|
| 272 | + * @throws \EE_Error |
|
| 273 | + */ |
|
| 274 | + public function load_resources() { |
|
| 275 | + $this->_get_reg_url_link(); |
|
| 276 | + // resend_reg_confirmation_email ? |
|
| 277 | + if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
| 278 | + EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
| 279 | + } |
|
| 280 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 281 | + $this->_translate_strings(); |
|
| 282 | + // load assets |
|
| 283 | + add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * load_js |
|
| 290 | + * |
|
| 291 | + * @return void |
|
| 292 | + */ |
|
| 293 | + protected function _translate_strings() |
|
| 294 | + { |
|
| 295 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
| 296 | + EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
| 297 | + EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
| 298 | + EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
| 299 | + EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
| 300 | + EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
| 301 | + 'checking for new payments...', |
|
| 302 | + 'event_espresso' |
|
| 303 | + ); |
|
| 304 | + EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
| 305 | + 'loading payment information...', |
|
| 306 | + 'event_espresso' |
|
| 307 | + ); |
|
| 308 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
| 309 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
| 310 | + 'event_espresso' |
|
| 311 | + ); |
|
| 312 | + EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
| 313 | + 'EED_Thank_You_Page__load_js__slow_IPN', |
|
| 314 | + sprintf( |
|
| 315 | + __( |
|
| 316 | + '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
| 317 | + 'event_espresso' |
|
| 318 | + ), |
|
| 319 | + '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
| 320 | + '</div>' |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * load_js |
|
| 329 | + * |
|
| 330 | + * @return void |
|
| 331 | + */ |
|
| 332 | + public function load_js() |
|
| 333 | + { |
|
| 334 | + wp_register_script( |
|
| 335 | + 'thank_you_page', |
|
| 336 | + THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
| 337 | + array('espresso_core', 'heartbeat'), |
|
| 338 | + EVENT_ESPRESSO_VERSION, |
|
| 339 | + true |
|
| 340 | + ); |
|
| 341 | + wp_enqueue_script('thank_you_page'); |
|
| 342 | + wp_enqueue_style('espresso_default'); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * init |
|
| 349 | + * |
|
| 350 | + * @return void |
|
| 351 | + * @throws \EE_Error |
|
| 352 | + */ |
|
| 353 | + public function init() |
|
| 354 | + { |
|
| 355 | + $this->_get_reg_url_link(); |
|
| 356 | + if ( ! $this->get_txn()) { |
|
| 357 | + echo EEH_HTML::div( |
|
| 358 | + EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
| 359 | + sprintf( |
|
| 360 | + __( |
|
| 361 | + 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
| 362 | + 'event_espresso' |
|
| 363 | + ), |
|
| 364 | + '<br/>' |
|
| 365 | + ), |
|
| 366 | + '', |
|
| 367 | + 'ee-attention' |
|
| 368 | + ); |
|
| 369 | + return null; |
|
| 370 | + } |
|
| 371 | + // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
| 372 | + if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
| 373 | + $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
| 374 | + $this->_current_txn->save(); |
|
| 375 | + } |
|
| 376 | + $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
| 377 | + ? $this->_current_txn->primary_registration() |
|
| 378 | + : null; |
|
| 379 | + $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false; |
|
| 380 | + $show_try_pay_again_link_default = apply_filters( |
|
| 381 | + 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
| 382 | + true |
|
| 383 | + ); |
|
| 384 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
| 385 | + // txn status ? |
|
| 386 | + if ($this->_current_txn->is_completed()) { |
|
| 387 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
| 388 | + } else if ( |
|
| 389 | + $this->_current_txn->is_incomplete() |
|
| 390 | + && ($this->_primary_registrant->is_approved() |
|
| 391 | + || $this->_primary_registrant->is_pending_payment()) |
|
| 392 | + ) { |
|
| 393 | + $this->_show_try_pay_again_link = true; |
|
| 394 | + } else if ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
| 395 | + // its pending |
|
| 396 | + $this->_show_try_pay_again_link = isset( |
|
| 397 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
| 398 | + ) |
|
| 399 | + && EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
| 400 | + ? true |
|
| 401 | + : $show_try_pay_again_link_default; |
|
| 402 | + } |
|
| 403 | + $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
| 404 | + ? true |
|
| 405 | + : false; |
|
| 406 | + $this->_is_offline_payment_method = false; |
|
| 407 | + if ( |
|
| 408 | + // if payment method is unknown |
|
| 409 | + ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
| 410 | + || ( |
|
| 411 | + // or is an offline payment method |
|
| 412 | + $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
| 413 | + && $this->_current_txn->payment_method()->is_off_line() |
|
| 414 | + ) |
|
| 415 | + ) { |
|
| 416 | + $this->_is_offline_payment_method = true; |
|
| 417 | + } |
|
| 418 | + // link to SPCO |
|
| 419 | + $revisit_spco_url = add_query_arg( |
|
| 420 | + array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
| 421 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 422 | + ); |
|
| 423 | + // link to SPCO payment_options |
|
| 424 | + $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
| 425 | + ? $this->_primary_registrant->payment_overview_url() |
|
| 426 | + : add_query_arg( |
|
| 427 | + array('step' => 'payment_options'), |
|
| 428 | + $revisit_spco_url |
|
| 429 | + ); |
|
| 430 | + // link to SPCO attendee_information |
|
| 431 | + $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
| 432 | + ? $this->_primary_registrant->edit_attendee_information_url() |
|
| 433 | + : false; |
|
| 434 | + do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
| 435 | + // set no cache headers and constants |
|
| 436 | + EE_System::do_not_cache(); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * display_thank_you_page_results |
|
| 443 | + * |
|
| 444 | + * @return string |
|
| 445 | + * @throws \EE_Error |
|
| 446 | + */ |
|
| 447 | + public function thank_you_page_results() |
|
| 448 | + { |
|
| 449 | + $this->init(); |
|
| 450 | + if ( ! $this->_current_txn instanceof EE_Transaction) { |
|
| 451 | + return EE_Error::get_notices(); |
|
| 452 | + } |
|
| 453 | + // link to receipt |
|
| 454 | + $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
| 455 | + if ( ! empty($template_args['TXN_receipt_url'])) { |
|
| 456 | + $template_args['order_conf_desc'] = __( |
|
| 457 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
| 458 | + 'event_espresso' |
|
| 459 | + ); |
|
| 460 | + } else { |
|
| 461 | + $template_args['order_conf_desc'] = __( |
|
| 462 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
| 463 | + 'event_espresso' |
|
| 464 | + ); |
|
| 465 | + } |
|
| 466 | + $template_args['transaction'] = $this->_current_txn; |
|
| 467 | + $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
| 468 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
| 469 | + if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
| 470 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
| 471 | + } |
|
| 472 | + return EEH_Template::locate_template( |
|
| 473 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
| 474 | + $template_args, |
|
| 475 | + true, |
|
| 476 | + true |
|
| 477 | + ); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * thank_you_page_IPN_monitor |
|
| 484 | + * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
| 485 | + * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
| 486 | + * it also calculates the IPN wait time since the Thank You page was first loaded |
|
| 487 | + * |
|
| 488 | + * @param array $response |
|
| 489 | + * @param array $data |
|
| 490 | + * @return array |
|
| 491 | + * @throws \EE_Error |
|
| 492 | + */ |
|
| 493 | + public static function thank_you_page_IPN_monitor($response = array(), $data = array()) |
|
| 494 | + { |
|
| 495 | + // does this heartbeat contain our data ? |
|
| 496 | + if ( ! isset($data['espresso_thank_you_page'])) { |
|
| 497 | + return $response; |
|
| 498 | + } |
|
| 499 | + // check for reg_url_link in the incoming heartbeat data |
|
| 500 | + if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) { |
|
| 501 | + $response['espresso_thank_you_page'] = array( |
|
| 502 | + 'errors' => ! empty($notices['errors']) |
|
| 503 | + ? $notices['errors'] |
|
| 504 | + : __( |
|
| 505 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
| 506 | + 'event_espresso' |
|
| 507 | + ) |
|
| 508 | + ); |
|
| 509 | + return $response; |
|
| 510 | + } |
|
| 511 | + // kk heartbeat has our data |
|
| 512 | + $response['espresso_thank_you_page'] = array(); |
|
| 513 | + // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
| 514 | + EED_Thank_You_Page::set_definitions(); |
|
| 515 | + /** @var $espresso_thank_you_page EED_Thank_You_Page */ |
|
| 516 | + $espresso_thank_you_page = EED_Thank_You_Page::instance(); |
|
| 517 | + $espresso_thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']); |
|
| 518 | + $espresso_thank_you_page->init(); |
|
| 519 | + //get TXN |
|
| 520 | + $TXN = $espresso_thank_you_page->get_txn(); |
|
| 521 | + // no TXN? then get out |
|
| 522 | + if ( ! $TXN instanceof EE_Transaction) { |
|
| 523 | + $notices = EE_Error::get_notices(); |
|
| 524 | + $response['espresso_thank_you_page'] = array( |
|
| 525 | + 'errors' => ! empty($notices['errors']) |
|
| 526 | + ? $notices['errors'] |
|
| 527 | + : sprintf( |
|
| 528 | + __( |
|
| 529 | + 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
| 530 | + 'event_espresso' |
|
| 531 | + ), |
|
| 532 | + __LINE__ |
|
| 533 | + ) |
|
| 534 | + ); |
|
| 535 | + return $response; |
|
| 536 | + } |
|
| 537 | + // grab transient of TXN's status |
|
| 538 | + $txn_status = isset($data['espresso_thank_you_page']['txn_status']) |
|
| 539 | + ? $data['espresso_thank_you_page']['txn_status'] |
|
| 540 | + : null; |
|
| 541 | + // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
| 542 | + if ($txn_status !== $TXN->status_ID()) { |
|
| 543 | + // switch between two possible basic outcomes |
|
| 544 | + switch ($TXN->status_ID()) { |
|
| 545 | + // TXN has been updated in some way |
|
| 546 | + case EEM_Transaction::overpaid_status_code: |
|
| 547 | + case EEM_Transaction::complete_status_code: |
|
| 548 | + case EEM_Transaction::incomplete_status_code: |
|
| 549 | + // send updated TXN results back to client, |
|
| 550 | + $response['espresso_thank_you_page'] = array( |
|
| 551 | + 'transaction_details' => $espresso_thank_you_page->get_transaction_details(), |
|
| 552 | + 'txn_status' => $TXN->status_ID() |
|
| 553 | + ); |
|
| 554 | + break; |
|
| 555 | + // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
| 556 | + case EEM_Transaction::failed_status_code: |
|
| 557 | + default: |
|
| 558 | + // keep on waiting... |
|
| 559 | + return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']); |
|
| 560 | + } |
|
| 561 | + // or is the TXN still failed (never been updated) ??? |
|
| 562 | + } else if ($TXN->failed()) { |
|
| 563 | + // keep on waiting... |
|
| 564 | + return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']); |
|
| 565 | + } |
|
| 566 | + // TXN is happening so let's get the payments now |
|
| 567 | + // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
| 568 | + $since = isset($data['espresso_thank_you_page']['get_payments_since']) |
|
| 569 | + ? $data['espresso_thank_you_page']['get_payments_since'] |
|
| 570 | + : 0; |
|
| 571 | + // then check for payments |
|
| 572 | + $payments = $espresso_thank_you_page->get_txn_payments($since); |
|
| 573 | + // has a payment been processed ? |
|
| 574 | + if ( ! empty($payments) || $espresso_thank_you_page->_is_offline_payment_method) { |
|
| 575 | + if ($since) { |
|
| 576 | + $response['espresso_thank_you_page'] = array( |
|
| 577 | + 'new_payments' => $espresso_thank_you_page->get_new_payments($payments), |
|
| 578 | + 'transaction_details' => $espresso_thank_you_page->get_transaction_details(), |
|
| 579 | + 'txn_status' => $TXN->status_ID() |
|
| 580 | + ); |
|
| 581 | + } else { |
|
| 582 | + $response['espresso_thank_you_page']['payment_details'] = $espresso_thank_you_page->get_payment_details( |
|
| 583 | + $payments |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + // reset time to check for payments |
|
| 587 | + $response['espresso_thank_you_page']['get_payments_since'] = time(); |
|
| 588 | + } else { |
|
| 589 | + $response['espresso_thank_you_page']['get_payments_since'] = $since; |
|
| 590 | + } |
|
| 591 | + return $response; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * _update_server_wait_time |
|
| 598 | + * |
|
| 599 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
| 600 | + * @return array |
|
| 601 | + * @throws \EE_Error |
|
| 602 | + */ |
|
| 603 | + private function _update_server_wait_time($thank_you_page_data = array()) |
|
| 604 | + { |
|
| 605 | + $response['espresso_thank_you_page'] = array( |
|
| 606 | + 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
| 607 | + ? time() - $thank_you_page_data['initial_access'] |
|
| 608 | + : 0, |
|
| 609 | + 'txn_status' => $this->_current_txn->status_ID() |
|
| 610 | + ); |
|
| 611 | + return $response; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * get_registration_details |
|
| 618 | + * |
|
| 619 | + * @throws \EE_Error |
|
| 620 | + */ |
|
| 621 | + public function get_registration_details() |
|
| 622 | + { |
|
| 623 | + //prepare variables for displaying |
|
| 624 | + $template_args = array(); |
|
| 625 | + $template_args['transaction'] = $this->_current_txn; |
|
| 626 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
| 627 | + $template_args['is_primary'] = $this->_is_primary; |
|
| 628 | + $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
| 629 | + $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
| 630 | + array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
| 631 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
| 632 | + ); |
|
| 633 | + // verify template arguments |
|
| 634 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
| 635 | + EEH_Template_Validator::verify_isnt_null( |
|
| 636 | + $template_args['SPCO_attendee_information_url'], |
|
| 637 | + '$SPCO_attendee_information_url' |
|
| 638 | + ); |
|
| 639 | + echo EEH_Template::locate_template( |
|
| 640 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
| 641 | + $template_args, |
|
| 642 | + true, |
|
| 643 | + true |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * resend_reg_confirmation_email |
|
| 651 | + * |
|
| 652 | + * @throws \EE_Error |
|
| 653 | + */ |
|
| 654 | + public static function resend_reg_confirmation_email() |
|
| 655 | + { |
|
| 656 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 657 | + $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
| 658 | + // was a REG_ID passed ? |
|
| 659 | + if ($reg_url_link) { |
|
| 660 | + $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
| 661 | + array(array('REG_url_link' => $reg_url_link)) |
|
| 662 | + ); |
|
| 663 | + if ($registration instanceof EE_Registration) { |
|
| 664 | + // resend email |
|
| 665 | + EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
| 666 | + } else { |
|
| 667 | + EE_Error::add_error( |
|
| 668 | + __( |
|
| 669 | + 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
| 670 | + 'event_espresso' |
|
| 671 | + ), |
|
| 672 | + __FILE__, |
|
| 673 | + __FUNCTION__, |
|
| 674 | + __LINE__ |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + } else { |
|
| 678 | + EE_Error::add_error( |
|
| 679 | + __( |
|
| 680 | + 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
| 681 | + 'event_espresso' |
|
| 682 | + ), |
|
| 683 | + __FILE__, |
|
| 684 | + __FUNCTION__, |
|
| 685 | + __LINE__ |
|
| 686 | + ); |
|
| 687 | + } |
|
| 688 | + // request sent via AJAX ? |
|
| 689 | + if (EE_FRONT_AJAX) { |
|
| 690 | + echo wp_json_encode(EE_Error::get_notices(false)); |
|
| 691 | + die(); |
|
| 692 | + // or was JS disabled ? |
|
| 693 | + } else { |
|
| 694 | + // save errors so that they get picked up on the next request |
|
| 695 | + EE_Error::get_notices(true, true); |
|
| 696 | + wp_safe_redirect( |
|
| 697 | + add_query_arg( |
|
| 698 | + array('e_reg_url_link' => $reg_url_link), |
|
| 699 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
| 700 | + ) |
|
| 701 | + ); |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * get_ajax_content |
|
| 709 | + * |
|
| 710 | + * @return void |
|
| 711 | + * @throws \EE_Error |
|
| 712 | + */ |
|
| 713 | + public function get_ajax_content() |
|
| 714 | + { |
|
| 715 | + if ( ! $this->get_txn()) { |
|
| 716 | + return; |
|
| 717 | + } |
|
| 718 | + // first determine which event(s) require pre-approval or not |
|
| 719 | + $events = array(); |
|
| 720 | + $events_requiring_pre_approval = array(); |
|
| 721 | + foreach ($this->_current_txn->registrations() as $registration) { |
|
| 722 | + if ($registration instanceof EE_Registration) { |
|
| 723 | + $event = $registration->event(); |
|
| 724 | + if ($event instanceof EE_Event) { |
|
| 725 | + if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
| 726 | + $events_requiring_pre_approval[$event->ID()] = $event; |
|
| 727 | + } else { |
|
| 728 | + $events[$event->ID()] = $event; |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
| 734 | + $this->display_details_for_events($events); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * display_details_for_events |
|
| 741 | + * |
|
| 742 | + * @param EE_Event[] $events |
|
| 743 | + * @return void |
|
| 744 | + */ |
|
| 745 | + public function display_details_for_events($events = array()) |
|
| 746 | + { |
|
| 747 | + if ( ! empty($events)) { |
|
| 748 | + ?> |
|
| 749 | 749 | <div id="espresso-thank-you-page-ajax-content-dv"> |
| 750 | 750 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
| 751 | 751 | <div id="espresso-thank-you-page-ajax-payment-dv"></div> |
| 752 | 752 | <div id="espresso-thank-you-page-ajax-loading-dv"> |
| 753 | 753 | <div id="ee-ajax-loading-dv" class="float-left lt-blue-text"> |
| 754 | 754 | <span class="dashicons dashicons-upload"></span><span id="ee-ajax-loading-msg-spn"><?php _e( |
| 755 | - 'loading transaction and payment information...', |
|
| 756 | - 'event_espresso' |
|
| 757 | - ); ?></span> |
|
| 755 | + 'loading transaction and payment information...', |
|
| 756 | + 'event_espresso' |
|
| 757 | + ); ?></span> |
|
| 758 | 758 | </div> |
| 759 | 759 | <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
| 760 | 760 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
| 761 | 761 | <?php echo apply_filters( |
| 762 | - 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
| 763 | - __( |
|
| 764 | - 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
| 765 | - 'event_espresso' |
|
| 766 | - ) |
|
| 767 | - ); ?> |
|
| 762 | + 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
| 763 | + __( |
|
| 764 | + 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
| 765 | + 'event_espresso' |
|
| 766 | + ) |
|
| 767 | + ); ?> |
|
| 768 | 768 | <br/> |
| 769 | 769 | <span class="jst-rght ee-block small-text lt-grey-text"> |
| 770 | 770 | <?php _e('current wait time ', 'event_espresso'); ?> |
@@ -775,120 +775,120 @@ discard block |
||
| 775 | 775 | <div class="clear"></div> |
| 776 | 776 | </div> |
| 777 | 777 | <?php |
| 778 | - } |
|
| 779 | - } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | 781 | |
| 782 | 782 | |
| 783 | - /** |
|
| 784 | - * display_details_for_events_requiring_pre_approval |
|
| 785 | - * |
|
| 786 | - * @param EE_Event[] $events |
|
| 787 | - * @return void |
|
| 788 | - */ |
|
| 789 | - public function display_details_for_events_requiring_pre_approval($events = array()) |
|
| 790 | - { |
|
| 791 | - if ( ! empty($events)) { |
|
| 792 | - ?> |
|
| 783 | + /** |
|
| 784 | + * display_details_for_events_requiring_pre_approval |
|
| 785 | + * |
|
| 786 | + * @param EE_Event[] $events |
|
| 787 | + * @return void |
|
| 788 | + */ |
|
| 789 | + public function display_details_for_events_requiring_pre_approval($events = array()) |
|
| 790 | + { |
|
| 791 | + if ( ! empty($events)) { |
|
| 792 | + ?> |
|
| 793 | 793 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
| 794 | 794 | <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4> |
| 795 | 795 | <p id="events-requiring-pre-approval-pg" class="small-text"> |
| 796 | 796 | <?php echo apply_filters( |
| 797 | - 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
| 798 | - __( |
|
| 799 | - 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 800 | - 'event_espresso' |
|
| 801 | - ) |
|
| 802 | - ); ?> |
|
| 797 | + 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
| 798 | + __( |
|
| 799 | + 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 800 | + 'event_espresso' |
|
| 801 | + ) |
|
| 802 | + ); ?> |
|
| 803 | 803 | </p> |
| 804 | 804 | <ul class="events-requiring-pre-approval-ul"> |
| 805 | 805 | <?php foreach ($events as $event) { |
| 806 | - if ($event instanceof EE_Event) { |
|
| 807 | - echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
| 808 | - $event->name(), |
|
| 809 | - '</li>'; |
|
| 810 | - } |
|
| 811 | - } ?> |
|
| 806 | + if ($event instanceof EE_Event) { |
|
| 807 | + echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
| 808 | + $event->name(), |
|
| 809 | + '</li>'; |
|
| 810 | + } |
|
| 811 | + } ?> |
|
| 812 | 812 | </ul> |
| 813 | 813 | <div class="clear"></div> |
| 814 | 814 | </div> |
| 815 | 815 | <?php |
| 816 | - } |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * get_transaction_details |
|
| 823 | - * |
|
| 824 | - * @return string |
|
| 825 | - * @throws \EE_Error |
|
| 826 | - */ |
|
| 827 | - public function get_transaction_details() |
|
| 828 | - { |
|
| 829 | - //prepare variables for displaying |
|
| 830 | - $template_args = array(); |
|
| 831 | - $template_args['transaction'] = $this->_current_txn; |
|
| 832 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
| 833 | - $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
| 834 | - // link to SPCO payment_options |
|
| 835 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
| 836 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
| 837 | - // verify template arguments |
|
| 838 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
| 839 | - EEH_Template_Validator::verify_isnt_null( |
|
| 840 | - $template_args['show_try_pay_again_link'], |
|
| 841 | - '$show_try_pay_again_link' |
|
| 842 | - ); |
|
| 843 | - EEH_Template_Validator::verify_isnt_null( |
|
| 844 | - $template_args['SPCO_payment_options_url'], |
|
| 845 | - '$SPCO_payment_options_url' |
|
| 846 | - ); |
|
| 847 | - return EEH_Template::locate_template( |
|
| 848 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
| 849 | - $template_args, |
|
| 850 | - true, |
|
| 851 | - true |
|
| 852 | - ); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * get_payment_row_html |
|
| 859 | - * |
|
| 860 | - * @param EE_Payment $payment |
|
| 861 | - * @return string |
|
| 862 | - * @throws \EE_Error |
|
| 863 | - */ |
|
| 864 | - public function get_payment_row_html($payment = null) |
|
| 865 | - { |
|
| 866 | - $html = ''; |
|
| 867 | - if ($payment instanceof EE_Payment) { |
|
| 868 | - if ( |
|
| 869 | - $payment->payment_method() instanceof EE_Payment_Method |
|
| 870 | - && $payment->status() === EEM_Payment::status_id_failed |
|
| 871 | - && $payment->payment_method()->is_off_site() |
|
| 872 | - ) { |
|
| 873 | - // considering the registrant has made it to the Thank You page, |
|
| 874 | - // any failed payments may actually be pending and the IPN is just slow |
|
| 875 | - // so let's |
|
| 876 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
| 877 | - } |
|
| 878 | - $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
| 879 | - ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
| 880 | - : ''; |
|
| 881 | - $html .= ' |
|
| 816 | + } |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * get_transaction_details |
|
| 823 | + * |
|
| 824 | + * @return string |
|
| 825 | + * @throws \EE_Error |
|
| 826 | + */ |
|
| 827 | + public function get_transaction_details() |
|
| 828 | + { |
|
| 829 | + //prepare variables for displaying |
|
| 830 | + $template_args = array(); |
|
| 831 | + $template_args['transaction'] = $this->_current_txn; |
|
| 832 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
| 833 | + $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
| 834 | + // link to SPCO payment_options |
|
| 835 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
| 836 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
| 837 | + // verify template arguments |
|
| 838 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
| 839 | + EEH_Template_Validator::verify_isnt_null( |
|
| 840 | + $template_args['show_try_pay_again_link'], |
|
| 841 | + '$show_try_pay_again_link' |
|
| 842 | + ); |
|
| 843 | + EEH_Template_Validator::verify_isnt_null( |
|
| 844 | + $template_args['SPCO_payment_options_url'], |
|
| 845 | + '$SPCO_payment_options_url' |
|
| 846 | + ); |
|
| 847 | + return EEH_Template::locate_template( |
|
| 848 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
| 849 | + $template_args, |
|
| 850 | + true, |
|
| 851 | + true |
|
| 852 | + ); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * get_payment_row_html |
|
| 859 | + * |
|
| 860 | + * @param EE_Payment $payment |
|
| 861 | + * @return string |
|
| 862 | + * @throws \EE_Error |
|
| 863 | + */ |
|
| 864 | + public function get_payment_row_html($payment = null) |
|
| 865 | + { |
|
| 866 | + $html = ''; |
|
| 867 | + if ($payment instanceof EE_Payment) { |
|
| 868 | + if ( |
|
| 869 | + $payment->payment_method() instanceof EE_Payment_Method |
|
| 870 | + && $payment->status() === EEM_Payment::status_id_failed |
|
| 871 | + && $payment->payment_method()->is_off_site() |
|
| 872 | + ) { |
|
| 873 | + // considering the registrant has made it to the Thank You page, |
|
| 874 | + // any failed payments may actually be pending and the IPN is just slow |
|
| 875 | + // so let's |
|
| 876 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
| 877 | + } |
|
| 878 | + $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
| 879 | + ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
| 880 | + : ''; |
|
| 881 | + $html .= ' |
|
| 882 | 882 | <tr> |
| 883 | 883 | <td> |
| 884 | 884 | ' . $payment->timestamp() . ' |
| 885 | 885 | </td> |
| 886 | 886 | <td> |
| 887 | 887 | ' . ( |
| 888 | - $payment->payment_method() instanceof EE_Payment_Method |
|
| 889 | - ? $payment->payment_method()->name() |
|
| 890 | - : __('Unknown', 'event_espresso') |
|
| 891 | - ) . ' |
|
| 888 | + $payment->payment_method() instanceof EE_Payment_Method |
|
| 889 | + ? $payment->payment_method()->name() |
|
| 890 | + : __('Unknown', 'event_espresso') |
|
| 891 | + ) . ' |
|
| 892 | 892 | </td> |
| 893 | 893 | <td class="jst-rght"> |
| 894 | 894 | ' . EEH_Template::format_currency($payment->amount()) . ' |
@@ -897,87 +897,87 @@ discard block |
||
| 897 | 897 | ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
| 898 | 898 | </td> |
| 899 | 899 | </tr>'; |
| 900 | - do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
| 901 | - } |
|
| 902 | - return $html; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * get_payment_details |
|
| 909 | - * |
|
| 910 | - * @param array $payments |
|
| 911 | - * @return string |
|
| 912 | - * @throws \EE_Error |
|
| 913 | - */ |
|
| 914 | - public function get_payment_details($payments = array()) |
|
| 915 | - { |
|
| 916 | - //prepare variables for displaying |
|
| 917 | - $template_args = array(); |
|
| 918 | - $template_args['transaction'] = $this->_current_txn; |
|
| 919 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
| 920 | - $template_args['payments'] = array(); |
|
| 921 | - foreach ($payments as $payment) { |
|
| 922 | - $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
| 923 | - } |
|
| 924 | - //create a hacky payment object, but dont save it |
|
| 925 | - $payment = EE_Payment::new_instance( |
|
| 926 | - array( |
|
| 927 | - 'TXN_ID' => $this->_current_txn->ID(), |
|
| 928 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 929 | - 'PAY_timestamp' => time(), |
|
| 930 | - 'PAY_amount' => $this->_current_txn->total(), |
|
| 931 | - 'PMD_ID' => $this->_current_txn->payment_method_ID() |
|
| 932 | - ) |
|
| 933 | - ); |
|
| 934 | - $payment_method = $this->_current_txn->payment_method(); |
|
| 935 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 936 | - $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
| 937 | - } else { |
|
| 938 | - $template_args['gateway_content'] = ''; |
|
| 939 | - } |
|
| 940 | - // link to SPCO payment_options |
|
| 941 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
| 942 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
| 943 | - // verify template arguments |
|
| 944 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
| 945 | - EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
| 946 | - EEH_Template_Validator::verify_isnt_null( |
|
| 947 | - $template_args['show_try_pay_again_link'], |
|
| 948 | - '$show_try_pay_again_link' |
|
| 949 | - ); |
|
| 950 | - EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
| 951 | - EEH_Template_Validator::verify_isnt_null( |
|
| 952 | - $template_args['SPCO_payment_options_url'], |
|
| 953 | - '$SPCO_payment_options_url' |
|
| 954 | - ); |
|
| 955 | - return EEH_Template::locate_template( |
|
| 956 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
| 957 | - $template_args, |
|
| 958 | - true, |
|
| 959 | - true |
|
| 960 | - ); |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * get_payment_details |
|
| 967 | - * |
|
| 968 | - * @param array $payments |
|
| 969 | - * @return string |
|
| 970 | - * @throws \EE_Error |
|
| 971 | - */ |
|
| 972 | - public function get_new_payments($payments = array()) |
|
| 973 | - { |
|
| 974 | - $payments_html = ''; |
|
| 975 | - //prepare variables for displaying |
|
| 976 | - foreach ($payments as $payment) { |
|
| 977 | - $payments_html .= $this->get_payment_row_html($payment); |
|
| 978 | - } |
|
| 979 | - return $payments_html; |
|
| 980 | - } |
|
| 900 | + do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
| 901 | + } |
|
| 902 | + return $html; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * get_payment_details |
|
| 909 | + * |
|
| 910 | + * @param array $payments |
|
| 911 | + * @return string |
|
| 912 | + * @throws \EE_Error |
|
| 913 | + */ |
|
| 914 | + public function get_payment_details($payments = array()) |
|
| 915 | + { |
|
| 916 | + //prepare variables for displaying |
|
| 917 | + $template_args = array(); |
|
| 918 | + $template_args['transaction'] = $this->_current_txn; |
|
| 919 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
| 920 | + $template_args['payments'] = array(); |
|
| 921 | + foreach ($payments as $payment) { |
|
| 922 | + $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
| 923 | + } |
|
| 924 | + //create a hacky payment object, but dont save it |
|
| 925 | + $payment = EE_Payment::new_instance( |
|
| 926 | + array( |
|
| 927 | + 'TXN_ID' => $this->_current_txn->ID(), |
|
| 928 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 929 | + 'PAY_timestamp' => time(), |
|
| 930 | + 'PAY_amount' => $this->_current_txn->total(), |
|
| 931 | + 'PMD_ID' => $this->_current_txn->payment_method_ID() |
|
| 932 | + ) |
|
| 933 | + ); |
|
| 934 | + $payment_method = $this->_current_txn->payment_method(); |
|
| 935 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 936 | + $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
| 937 | + } else { |
|
| 938 | + $template_args['gateway_content'] = ''; |
|
| 939 | + } |
|
| 940 | + // link to SPCO payment_options |
|
| 941 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
| 942 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
| 943 | + // verify template arguments |
|
| 944 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
| 945 | + EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
| 946 | + EEH_Template_Validator::verify_isnt_null( |
|
| 947 | + $template_args['show_try_pay_again_link'], |
|
| 948 | + '$show_try_pay_again_link' |
|
| 949 | + ); |
|
| 950 | + EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
| 951 | + EEH_Template_Validator::verify_isnt_null( |
|
| 952 | + $template_args['SPCO_payment_options_url'], |
|
| 953 | + '$SPCO_payment_options_url' |
|
| 954 | + ); |
|
| 955 | + return EEH_Template::locate_template( |
|
| 956 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
| 957 | + $template_args, |
|
| 958 | + true, |
|
| 959 | + true |
|
| 960 | + ); |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * get_payment_details |
|
| 967 | + * |
|
| 968 | + * @param array $payments |
|
| 969 | + * @return string |
|
| 970 | + * @throws \EE_Error |
|
| 971 | + */ |
|
| 972 | + public function get_new_payments($payments = array()) |
|
| 973 | + { |
|
| 974 | + $payments_html = ''; |
|
| 975 | + //prepare variables for displaying |
|
| 976 | + foreach ($payments as $payment) { |
|
| 977 | + $payments_html .= $this->get_payment_row_html($payment); |
|
| 978 | + } |
|
| 979 | + return $payments_html; |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | 982 | |
| 983 | 983 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\services\database\TableAnalysis; |
| 5 | 5 | |
| 6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | /** |
| 10 | 10 | * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE |
@@ -29,277 +29,277 @@ discard block |
||
| 29 | 29 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 34 | - */ |
|
| 35 | - protected $_table_analysis; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * EE_Brewing_Regular constructor. |
|
| 41 | - */ |
|
| 42 | - public function __construct(TableAnalysis $table_analysis) |
|
| 43 | - { |
|
| 44 | - $this->_table_analysis = $table_analysis; |
|
| 45 | - if (defined('EE_CAFF_PATH')) { |
|
| 46 | - // activation |
|
| 47 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
| 48 | - // load caff init |
|
| 49 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
| 50 | - // remove the "powered by" credit link from receipts and invoices |
|
| 51 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
| 52 | - // add caffeinated modules |
|
| 53 | - add_filter( |
|
| 54 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 55 | - array($this, 'caffeinated_modules_to_register') |
|
| 56 | - ); |
|
| 57 | - // load caff scripts |
|
| 58 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
| 59 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
| 60 | - add_filter( |
|
| 61 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 62 | - array($this, 'caf_payment_methods') |
|
| 63 | - ); |
|
| 64 | - // caffeinated constructed |
|
| 65 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
| 66 | - //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
| 67 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
| 75 | - * |
|
| 76 | - * @param array $paths original helper paths array |
|
| 77 | - * @return array new array of paths |
|
| 78 | - */ |
|
| 79 | - public function caf_helper_paths($paths) |
|
| 80 | - { |
|
| 81 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
| 82 | - return $paths; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
| 89 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
| 90 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
| 91 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
| 92 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
| 93 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
| 94 | - * Right now, we ASSUME the only price types in the system are default ones |
|
| 95 | - * |
|
| 96 | - * @global wpdb $wpdb |
|
| 97 | - */ |
|
| 98 | - public function initialize_caf_db_content() |
|
| 99 | - { |
|
| 100 | - global $wpdb; |
|
| 101 | - //use same method of getting creator id as the version introducing the change |
|
| 102 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
| 103 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 104 | - $price_table = $wpdb->prefix . "esp_price"; |
|
| 105 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 106 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
| 107 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
| 108 | - if ($tax_price_type_count <= 1) { |
|
| 109 | - $wpdb->insert( |
|
| 110 | - $price_type_table, |
|
| 111 | - array( |
|
| 112 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
| 113 | - 'PBT_ID' => 4, |
|
| 114 | - 'PRT_is_percent' => true, |
|
| 115 | - 'PRT_order' => 60, |
|
| 116 | - 'PRT_deleted' => false, |
|
| 117 | - 'PRT_wp_user' => $default_creator_id, |
|
| 118 | - ), |
|
| 119 | - array( |
|
| 120 | - '%s',//PRT_name |
|
| 121 | - '%d',//PBT_id |
|
| 122 | - '%d',//PRT_is_percent |
|
| 123 | - '%d',//PRT_order |
|
| 124 | - '%d',//PRT_deleted |
|
| 125 | - '%d', //PRT_wp_user |
|
| 126 | - ) |
|
| 127 | - ); |
|
| 128 | - //federal tax |
|
| 129 | - $result = $wpdb->insert( |
|
| 130 | - $price_type_table, |
|
| 131 | - array( |
|
| 132 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
| 133 | - 'PBT_ID' => 4, |
|
| 134 | - 'PRT_is_percent' => true, |
|
| 135 | - 'PRT_order' => 70, |
|
| 136 | - 'PRT_deleted' => false, |
|
| 137 | - 'PRT_wp_user' => $default_creator_id, |
|
| 138 | - ), |
|
| 139 | - array( |
|
| 140 | - '%s',//PRT_name |
|
| 141 | - '%d',//PBT_id |
|
| 142 | - '%d',//PRT_is_percent |
|
| 143 | - '%d',//PRT_order |
|
| 144 | - '%d',//PRT_deleted |
|
| 145 | - '%d' //PRT_wp_user |
|
| 146 | - ) |
|
| 147 | - ); |
|
| 148 | - if ($result) { |
|
| 149 | - $wpdb->insert( |
|
| 150 | - $price_table, |
|
| 151 | - array( |
|
| 152 | - 'PRT_ID' => $wpdb->insert_id, |
|
| 153 | - 'PRC_amount' => 15.00, |
|
| 154 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
| 155 | - 'PRC_desc' => '', |
|
| 156 | - 'PRC_is_default' => true, |
|
| 157 | - 'PRC_overrides' => null, |
|
| 158 | - 'PRC_deleted' => false, |
|
| 159 | - 'PRC_order' => 50, |
|
| 160 | - 'PRC_parent' => null, |
|
| 161 | - 'PRC_wp_user' => $default_creator_id, |
|
| 162 | - ), |
|
| 163 | - array( |
|
| 164 | - '%d',//PRT_id |
|
| 165 | - '%f',//PRC_amount |
|
| 166 | - '%s',//PRC_name |
|
| 167 | - '%s',//PRC_desc |
|
| 168 | - '%d',//PRC_is_default |
|
| 169 | - '%d',//PRC_overrides |
|
| 170 | - '%d',//PRC_deleted |
|
| 171 | - '%d',//PRC_order |
|
| 172 | - '%d',//PRC_parent |
|
| 173 | - '%d' //PRC_wp_user |
|
| 174 | - ) |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * caffeinated_modules_to_register |
|
| 185 | - * |
|
| 186 | - * @access public |
|
| 187 | - * @param array $modules_to_register |
|
| 188 | - * @return array |
|
| 189 | - */ |
|
| 190 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
| 191 | - { |
|
| 192 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
| 193 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
| 194 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
| 195 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - return $modules_to_register; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - public function caffeinated_init() |
|
| 204 | - { |
|
| 205 | - // EE_Register_CPTs hooks |
|
| 206 | - add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
| 207 | - add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
| 208 | - add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
| 209 | - EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
| 210 | - // caffeinated_init__complete hook |
|
| 211 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - public function enqueue_caffeinated_scripts() |
|
| 217 | - { |
|
| 218 | - // sound of crickets... |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * callbacks below here |
|
| 225 | - * |
|
| 226 | - * @param array $taxonomy_array |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - public function filter_taxonomies(array $taxonomy_array) |
|
| 230 | - { |
|
| 231 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
| 232 | - return $taxonomy_array; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @param array $cpt_array |
|
| 239 | - * @return mixed |
|
| 240 | - */ |
|
| 241 | - public function filter_cpts(array $cpt_array) |
|
| 242 | - { |
|
| 243 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
| 244 | - return $cpt_array; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param array $menuitems |
|
| 251 | - * @return array |
|
| 252 | - */ |
|
| 253 | - public function nav_metabox_items(array $menuitems) |
|
| 254 | - { |
|
| 255 | - $menuitems[] = array( |
|
| 256 | - 'title' => __('Venue List', 'event_espresso'), |
|
| 257 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
| 258 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
| 259 | - ); |
|
| 260 | - return $menuitems; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
| 267 | - * |
|
| 268 | - * @param array $payment_method_paths |
|
| 269 | - * @return array values are folder paths to payment method folders |
|
| 270 | - */ |
|
| 271 | - public function caf_payment_methods($payment_method_paths) |
|
| 272 | - { |
|
| 273 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 274 | - $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
| 275 | - return $payment_method_paths; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Gets the injected table analyzer, or throws an exception |
|
| 282 | - * |
|
| 283 | - * @return TableAnalysis |
|
| 284 | - * @throws \EE_Error |
|
| 285 | - */ |
|
| 286 | - protected function _get_table_analysis() |
|
| 287 | - { |
|
| 288 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 289 | - return $this->_table_analysis; |
|
| 290 | - } else { |
|
| 291 | - throw new \EE_Error( |
|
| 292 | - sprintf( |
|
| 293 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 294 | - get_class($this) |
|
| 295 | - ) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - } |
|
| 32 | + /** |
|
| 33 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 34 | + */ |
|
| 35 | + protected $_table_analysis; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * EE_Brewing_Regular constructor. |
|
| 41 | + */ |
|
| 42 | + public function __construct(TableAnalysis $table_analysis) |
|
| 43 | + { |
|
| 44 | + $this->_table_analysis = $table_analysis; |
|
| 45 | + if (defined('EE_CAFF_PATH')) { |
|
| 46 | + // activation |
|
| 47 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
| 48 | + // load caff init |
|
| 49 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
| 50 | + // remove the "powered by" credit link from receipts and invoices |
|
| 51 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
| 52 | + // add caffeinated modules |
|
| 53 | + add_filter( |
|
| 54 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 55 | + array($this, 'caffeinated_modules_to_register') |
|
| 56 | + ); |
|
| 57 | + // load caff scripts |
|
| 58 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
| 59 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
| 60 | + add_filter( |
|
| 61 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 62 | + array($this, 'caf_payment_methods') |
|
| 63 | + ); |
|
| 64 | + // caffeinated constructed |
|
| 65 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
| 66 | + //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
| 67 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
| 75 | + * |
|
| 76 | + * @param array $paths original helper paths array |
|
| 77 | + * @return array new array of paths |
|
| 78 | + */ |
|
| 79 | + public function caf_helper_paths($paths) |
|
| 80 | + { |
|
| 81 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
| 82 | + return $paths; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
| 89 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
| 90 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
| 91 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
| 92 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
| 93 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
| 94 | + * Right now, we ASSUME the only price types in the system are default ones |
|
| 95 | + * |
|
| 96 | + * @global wpdb $wpdb |
|
| 97 | + */ |
|
| 98 | + public function initialize_caf_db_content() |
|
| 99 | + { |
|
| 100 | + global $wpdb; |
|
| 101 | + //use same method of getting creator id as the version introducing the change |
|
| 102 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
| 103 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
| 104 | + $price_table = $wpdb->prefix . "esp_price"; |
|
| 105 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
| 106 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
| 107 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
| 108 | + if ($tax_price_type_count <= 1) { |
|
| 109 | + $wpdb->insert( |
|
| 110 | + $price_type_table, |
|
| 111 | + array( |
|
| 112 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
| 113 | + 'PBT_ID' => 4, |
|
| 114 | + 'PRT_is_percent' => true, |
|
| 115 | + 'PRT_order' => 60, |
|
| 116 | + 'PRT_deleted' => false, |
|
| 117 | + 'PRT_wp_user' => $default_creator_id, |
|
| 118 | + ), |
|
| 119 | + array( |
|
| 120 | + '%s',//PRT_name |
|
| 121 | + '%d',//PBT_id |
|
| 122 | + '%d',//PRT_is_percent |
|
| 123 | + '%d',//PRT_order |
|
| 124 | + '%d',//PRT_deleted |
|
| 125 | + '%d', //PRT_wp_user |
|
| 126 | + ) |
|
| 127 | + ); |
|
| 128 | + //federal tax |
|
| 129 | + $result = $wpdb->insert( |
|
| 130 | + $price_type_table, |
|
| 131 | + array( |
|
| 132 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
| 133 | + 'PBT_ID' => 4, |
|
| 134 | + 'PRT_is_percent' => true, |
|
| 135 | + 'PRT_order' => 70, |
|
| 136 | + 'PRT_deleted' => false, |
|
| 137 | + 'PRT_wp_user' => $default_creator_id, |
|
| 138 | + ), |
|
| 139 | + array( |
|
| 140 | + '%s',//PRT_name |
|
| 141 | + '%d',//PBT_id |
|
| 142 | + '%d',//PRT_is_percent |
|
| 143 | + '%d',//PRT_order |
|
| 144 | + '%d',//PRT_deleted |
|
| 145 | + '%d' //PRT_wp_user |
|
| 146 | + ) |
|
| 147 | + ); |
|
| 148 | + if ($result) { |
|
| 149 | + $wpdb->insert( |
|
| 150 | + $price_table, |
|
| 151 | + array( |
|
| 152 | + 'PRT_ID' => $wpdb->insert_id, |
|
| 153 | + 'PRC_amount' => 15.00, |
|
| 154 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
| 155 | + 'PRC_desc' => '', |
|
| 156 | + 'PRC_is_default' => true, |
|
| 157 | + 'PRC_overrides' => null, |
|
| 158 | + 'PRC_deleted' => false, |
|
| 159 | + 'PRC_order' => 50, |
|
| 160 | + 'PRC_parent' => null, |
|
| 161 | + 'PRC_wp_user' => $default_creator_id, |
|
| 162 | + ), |
|
| 163 | + array( |
|
| 164 | + '%d',//PRT_id |
|
| 165 | + '%f',//PRC_amount |
|
| 166 | + '%s',//PRC_name |
|
| 167 | + '%s',//PRC_desc |
|
| 168 | + '%d',//PRC_is_default |
|
| 169 | + '%d',//PRC_overrides |
|
| 170 | + '%d',//PRC_deleted |
|
| 171 | + '%d',//PRC_order |
|
| 172 | + '%d',//PRC_parent |
|
| 173 | + '%d' //PRC_wp_user |
|
| 174 | + ) |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * caffeinated_modules_to_register |
|
| 185 | + * |
|
| 186 | + * @access public |
|
| 187 | + * @param array $modules_to_register |
|
| 188 | + * @return array |
|
| 189 | + */ |
|
| 190 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
| 191 | + { |
|
| 192 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
| 193 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
| 194 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
| 195 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + return $modules_to_register; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + public function caffeinated_init() |
|
| 204 | + { |
|
| 205 | + // EE_Register_CPTs hooks |
|
| 206 | + add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
| 207 | + add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
| 208 | + add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
| 209 | + EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
| 210 | + // caffeinated_init__complete hook |
|
| 211 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + public function enqueue_caffeinated_scripts() |
|
| 217 | + { |
|
| 218 | + // sound of crickets... |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * callbacks below here |
|
| 225 | + * |
|
| 226 | + * @param array $taxonomy_array |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + public function filter_taxonomies(array $taxonomy_array) |
|
| 230 | + { |
|
| 231 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
| 232 | + return $taxonomy_array; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @param array $cpt_array |
|
| 239 | + * @return mixed |
|
| 240 | + */ |
|
| 241 | + public function filter_cpts(array $cpt_array) |
|
| 242 | + { |
|
| 243 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
| 244 | + return $cpt_array; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param array $menuitems |
|
| 251 | + * @return array |
|
| 252 | + */ |
|
| 253 | + public function nav_metabox_items(array $menuitems) |
|
| 254 | + { |
|
| 255 | + $menuitems[] = array( |
|
| 256 | + 'title' => __('Venue List', 'event_espresso'), |
|
| 257 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
| 258 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
| 259 | + ); |
|
| 260 | + return $menuitems; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
| 267 | + * |
|
| 268 | + * @param array $payment_method_paths |
|
| 269 | + * @return array values are folder paths to payment method folders |
|
| 270 | + */ |
|
| 271 | + public function caf_payment_methods($payment_method_paths) |
|
| 272 | + { |
|
| 273 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 274 | + $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
| 275 | + return $payment_method_paths; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Gets the injected table analyzer, or throws an exception |
|
| 282 | + * |
|
| 283 | + * @return TableAnalysis |
|
| 284 | + * @throws \EE_Error |
|
| 285 | + */ |
|
| 286 | + protected function _get_table_analysis() |
|
| 287 | + { |
|
| 288 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 289 | + return $this->_table_analysis; |
|
| 290 | + } else { |
|
| 291 | + throw new \EE_Error( |
|
| 292 | + sprintf( |
|
| 293 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 294 | + get_class($this) |
|
| 295 | + ) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
| 302 | 302 | |
| 303 | 303 | $brewing = new EE_Brewing_Regular( |
| 304 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
| 304 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
| 305 | 305 | ); |
| 306 | 306 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
| 2 | 2 | |
| 3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -19,407 +19,407 @@ discard block |
||
| 19 | 19 | class EE_Payment_Method_Manager implements ResettableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * instance of the EE_Payment_Method_Manager object |
|
| 24 | - * |
|
| 25 | - * @var $_instance |
|
| 26 | - * @access private |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
| 32 | - */ |
|
| 33 | - protected $_payment_method_types = array(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @singleton method used to instantiate class object |
|
| 39 | - * @access public |
|
| 40 | - * @return EE_Payment_Method_Manager instance |
|
| 41 | - */ |
|
| 42 | - public static function instance() |
|
| 43 | - { |
|
| 44 | - // check if class object is instantiated, and instantiated properly |
|
| 45 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 46 | - self::$_instance = new self(); |
|
| 47 | - } |
|
| 48 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
| 49 | - return self::$_instance; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Resets the instance and returns a new one |
|
| 56 | - * |
|
| 57 | - * @return EE_Payment_Method_Manager |
|
| 58 | - */ |
|
| 59 | - public static function reset() |
|
| 60 | - { |
|
| 61 | - self::$_instance = null; |
|
| 62 | - return self::instance(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * If necessary, re-register payment methods |
|
| 69 | - * |
|
| 70 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
| 71 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
| 72 | - * we have not yet checked during this request, then we need to check anyways) |
|
| 73 | - */ |
|
| 74 | - public function maybe_register_payment_methods($force_recheck = false) |
|
| 75 | - { |
|
| 76 | - if ( ! $this->_payment_method_types || $force_recheck) { |
|
| 77 | - $this->_register_payment_methods(); |
|
| 78 | - //if in admin lets ensure caps are set. |
|
| 79 | - if (is_admin()) { |
|
| 80 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
| 81 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * register_payment_methods |
|
| 90 | - * |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - protected function _register_payment_methods() |
|
| 94 | - { |
|
| 95 | - // grab list of installed modules |
|
| 96 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 97 | - // filter list of modules to register |
|
| 98 | - $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 99 | - $pm_to_register); |
|
| 100 | - // loop through folders |
|
| 101 | - foreach ($pm_to_register as $pm_path) { |
|
| 102 | - $this->register_payment_method($pm_path); |
|
| 103 | - } |
|
| 104 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
| 105 | - // filter list of installed modules |
|
| 106 | - //keep them organized alphabetically by the payment method type's name |
|
| 107 | - ksort($this->_payment_method_types); |
|
| 108 | - return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
| 109 | - $this->_payment_method_types); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * register_payment_method- makes core aware of this payment method |
|
| 116 | - * |
|
| 117 | - * @access public |
|
| 118 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
| 119 | - * @return boolean |
|
| 120 | - */ |
|
| 121 | - public function register_payment_method($payment_method_path = '') |
|
| 122 | - { |
|
| 123 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
| 124 | - $module_ext = '.pm.php'; |
|
| 125 | - // make all separators match |
|
| 126 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
| 127 | - // grab and sanitize module name |
|
| 128 | - $module_dir = basename($payment_method_path); |
|
| 129 | - // create classname from module directory name |
|
| 130 | - $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
| 131 | - // add class prefix |
|
| 132 | - $module_class = 'EE_PMT_' . $module; |
|
| 133 | - // does the module exist ? |
|
| 134 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 135 | - $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
| 136 | - 'event_espresso'), $module); |
|
| 137 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - if (WP_DEBUG === true) { |
|
| 141 | - EEH_Debug_Tools::instance()->start_timer(); |
|
| 142 | - } |
|
| 143 | - // load the module class file |
|
| 144 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 145 | - if (WP_DEBUG === true) { |
|
| 146 | - EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
| 147 | - } |
|
| 148 | - // verify that class exists |
|
| 149 | - if ( ! class_exists($module_class)) { |
|
| 150 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 154 | - // add to array of registered modules |
|
| 155 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 156 | - return true; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Checks if a payment method has been registered, and if so includes it |
|
| 163 | - * |
|
| 164 | - * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
| 165 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 166 | - * @return boolean |
|
| 167 | - */ |
|
| 168 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
| 169 | - { |
|
| 170 | - if ( |
|
| 171 | - $force_recheck |
|
| 172 | - || ! is_array($this->_payment_method_types) |
|
| 173 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
| 174 | - ) { |
|
| 175 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 176 | - } |
|
| 177 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
| 178 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
| 179 | - return true; |
|
| 180 | - } else { |
|
| 181 | - return false; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Returns all the classnames of the various payment method types |
|
| 189 | - * |
|
| 190 | - * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
| 191 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
| 192 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 193 | - * @return array |
|
| 194 | - */ |
|
| 195 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
| 196 | - { |
|
| 197 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 198 | - if ($with_prefixes) { |
|
| 199 | - $classnames = array_keys($this->_payment_method_types); |
|
| 200 | - $payment_methods = array(); |
|
| 201 | - foreach ($classnames as $classname) { |
|
| 202 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
| 203 | - } |
|
| 204 | - return $payment_methods; |
|
| 205 | - } else { |
|
| 206 | - return array_keys($this->_payment_method_types); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Gets an object of each payment method type, none of which are bound to a |
|
| 214 | - * payment method instance |
|
| 215 | - * |
|
| 216 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 217 | - * @return EE_PMT_Base[] |
|
| 218 | - */ |
|
| 219 | - public function payment_method_types($force_recheck = false) |
|
| 220 | - { |
|
| 221 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 222 | - $pmt_objs = array(); |
|
| 223 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
| 224 | - $pmt_objs[] = new $classname; |
|
| 225 | - } |
|
| 226 | - return $pmt_objs; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Changes the payment method's classname into the payment method type's name |
|
| 233 | - * (as used on the payment method's table's PMD_type field) |
|
| 234 | - * |
|
| 235 | - * @param string $classname |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function payment_method_type_sans_class_prefix($classname) |
|
| 239 | - { |
|
| 240 | - return str_replace("EE_PMT_", "", $classname); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Does the opposite of payment-method_type_sans_prefix |
|
| 247 | - * |
|
| 248 | - * @param string $type |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function payment_method_class_from_type($type) |
|
| 252 | - { |
|
| 253 | - $this->maybe_register_payment_methods(); |
|
| 254 | - return "EE_PMT_" . $type; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Activates a payment method of the given type. |
|
| 261 | - * |
|
| 262 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
| 263 | - * @return \EE_Payment_Method |
|
| 264 | - * @throws \EE_Error |
|
| 265 | - */ |
|
| 266 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
| 267 | - { |
|
| 268 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
| 269 | - if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 270 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
| 271 | - if (class_exists($pm_type_class)) { |
|
| 272 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
| 273 | - $pm_type_obj = new $pm_type_class; |
|
| 274 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
| 275 | - if ( ! $payment_method) { |
|
| 276 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
| 277 | - } |
|
| 278 | - $payment_method->set_type($payment_method_type); |
|
| 279 | - $this->initialize_payment_method($payment_method); |
|
| 280 | - } else { |
|
| 281 | - throw new EE_Error( |
|
| 282 | - sprintf( |
|
| 283 | - __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
| 284 | - $pm_type_class) |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - $payment_method->set_active(); |
|
| 289 | - $payment_method->save(); |
|
| 290 | - $this->set_usable_currencies_on_payment_method($payment_method); |
|
| 291 | - if ($payment_method->type() === 'Invoice') { |
|
| 292 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 293 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 294 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
| 295 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
| 296 | - EE_Error::add_persistent_admin_notice( |
|
| 297 | - 'invoice_pm_requirements_notice', |
|
| 298 | - sprintf( |
|
| 299 | - __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
| 300 | - 'event_espresso'), |
|
| 301 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 302 | - '</a>' |
|
| 303 | - ), |
|
| 304 | - true |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - return $payment_method; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Creates a payment method of the specified type. Does not save it. |
|
| 314 | - * |
|
| 315 | - * @global WP_User $current_user |
|
| 316 | - * @param EE_PMT_Base $pm_type_obj |
|
| 317 | - * @return EE_Payment_Method |
|
| 318 | - * @throws \EE_Error |
|
| 319 | - */ |
|
| 320 | - public function create_payment_method_of_type($pm_type_obj) |
|
| 321 | - { |
|
| 322 | - global $current_user; |
|
| 323 | - $payment_method = EE_Payment_Method::new_instance( |
|
| 324 | - array( |
|
| 325 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
| 326 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
| 327 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
| 328 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 329 | - 'PMD_wp_user' => $current_user->ID, |
|
| 330 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
| 331 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
| 332 | - ) * 10, |
|
| 333 | - ) |
|
| 334 | - ); |
|
| 335 | - return $payment_method; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Sets the initial payment method properties (including extra meta) |
|
| 342 | - * |
|
| 343 | - * @param EE_Payment_Method $payment_method |
|
| 344 | - * @return EE_Payment_Method |
|
| 345 | - * @throws \EE_Error |
|
| 346 | - */ |
|
| 347 | - public function initialize_payment_method($payment_method) |
|
| 348 | - { |
|
| 349 | - $pm_type_obj = $payment_method->type_obj(); |
|
| 350 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
| 351 | - if ( ! $payment_method->button_url()) { |
|
| 352 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
| 353 | - } |
|
| 354 | - //now add setup its default extra meta properties |
|
| 355 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
| 356 | - if ( ! empty($extra_metas)) { |
|
| 357 | - //verify the payment method has an ID before adding extra meta |
|
| 358 | - if ( ! $payment_method->ID()) { |
|
| 359 | - $payment_method->save(); |
|
| 360 | - } |
|
| 361 | - foreach ($extra_metas as $meta_name => $input) { |
|
| 362 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - return $payment_method; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Makes sure the payment method is related to the specified payment method |
|
| 372 | - * |
|
| 373 | - * @param EE_Payment_Method $payment_method |
|
| 374 | - * @return EE_Payment_Method |
|
| 375 | - * @throws \EE_Error |
|
| 376 | - */ |
|
| 377 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
| 378 | - { |
|
| 379 | - foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { |
|
| 380 | - $payment_method->_add_relation_to($currency_obj, 'Currency'); |
|
| 381 | - } |
|
| 382 | - return $payment_method; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Deactivates a payment method of the given payment method slug. |
|
| 389 | - * |
|
| 390 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
| 391 | - * @return int count of rows updated. |
|
| 392 | - */ |
|
| 393 | - public function deactivate_payment_method($payment_method_slug) |
|
| 394 | - { |
|
| 395 | - EE_Log::instance()->log( |
|
| 396 | - __FILE__, |
|
| 397 | - __FUNCTION__, |
|
| 398 | - sprintf( |
|
| 399 | - __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
| 400 | - $payment_method_slug |
|
| 401 | - ), |
|
| 402 | - 'payment_method_change' |
|
| 403 | - ); |
|
| 404 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
| 405 | - array('PMD_scope' => array()), |
|
| 406 | - array(array('PMD_slug' => $payment_method_slug)) |
|
| 407 | - ); |
|
| 408 | - return $count_updated; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
| 415 | - * access caps. |
|
| 416 | - * |
|
| 417 | - * @param array $caps capabilities being filtered |
|
| 418 | - * @return array |
|
| 419 | - */ |
|
| 420 | - public function add_payment_method_caps($caps) |
|
| 421 | - { |
|
| 422 | - /* add dynamic caps from payment methods |
|
| 22 | + /** |
|
| 23 | + * instance of the EE_Payment_Method_Manager object |
|
| 24 | + * |
|
| 25 | + * @var $_instance |
|
| 26 | + * @access private |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
| 32 | + */ |
|
| 33 | + protected $_payment_method_types = array(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @singleton method used to instantiate class object |
|
| 39 | + * @access public |
|
| 40 | + * @return EE_Payment_Method_Manager instance |
|
| 41 | + */ |
|
| 42 | + public static function instance() |
|
| 43 | + { |
|
| 44 | + // check if class object is instantiated, and instantiated properly |
|
| 45 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 46 | + self::$_instance = new self(); |
|
| 47 | + } |
|
| 48 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
| 49 | + return self::$_instance; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Resets the instance and returns a new one |
|
| 56 | + * |
|
| 57 | + * @return EE_Payment_Method_Manager |
|
| 58 | + */ |
|
| 59 | + public static function reset() |
|
| 60 | + { |
|
| 61 | + self::$_instance = null; |
|
| 62 | + return self::instance(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * If necessary, re-register payment methods |
|
| 69 | + * |
|
| 70 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
| 71 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
| 72 | + * we have not yet checked during this request, then we need to check anyways) |
|
| 73 | + */ |
|
| 74 | + public function maybe_register_payment_methods($force_recheck = false) |
|
| 75 | + { |
|
| 76 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
| 77 | + $this->_register_payment_methods(); |
|
| 78 | + //if in admin lets ensure caps are set. |
|
| 79 | + if (is_admin()) { |
|
| 80 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
| 81 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * register_payment_methods |
|
| 90 | + * |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + protected function _register_payment_methods() |
|
| 94 | + { |
|
| 95 | + // grab list of installed modules |
|
| 96 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 97 | + // filter list of modules to register |
|
| 98 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 99 | + $pm_to_register); |
|
| 100 | + // loop through folders |
|
| 101 | + foreach ($pm_to_register as $pm_path) { |
|
| 102 | + $this->register_payment_method($pm_path); |
|
| 103 | + } |
|
| 104 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
| 105 | + // filter list of installed modules |
|
| 106 | + //keep them organized alphabetically by the payment method type's name |
|
| 107 | + ksort($this->_payment_method_types); |
|
| 108 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
| 109 | + $this->_payment_method_types); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * register_payment_method- makes core aware of this payment method |
|
| 116 | + * |
|
| 117 | + * @access public |
|
| 118 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
| 119 | + * @return boolean |
|
| 120 | + */ |
|
| 121 | + public function register_payment_method($payment_method_path = '') |
|
| 122 | + { |
|
| 123 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
| 124 | + $module_ext = '.pm.php'; |
|
| 125 | + // make all separators match |
|
| 126 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
| 127 | + // grab and sanitize module name |
|
| 128 | + $module_dir = basename($payment_method_path); |
|
| 129 | + // create classname from module directory name |
|
| 130 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
| 131 | + // add class prefix |
|
| 132 | + $module_class = 'EE_PMT_' . $module; |
|
| 133 | + // does the module exist ? |
|
| 134 | + if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 135 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
| 136 | + 'event_espresso'), $module); |
|
| 137 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + if (WP_DEBUG === true) { |
|
| 141 | + EEH_Debug_Tools::instance()->start_timer(); |
|
| 142 | + } |
|
| 143 | + // load the module class file |
|
| 144 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 145 | + if (WP_DEBUG === true) { |
|
| 146 | + EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
| 147 | + } |
|
| 148 | + // verify that class exists |
|
| 149 | + if ( ! class_exists($module_class)) { |
|
| 150 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 151 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | + // add to array of registered modules |
|
| 155 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 156 | + return true; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Checks if a payment method has been registered, and if so includes it |
|
| 163 | + * |
|
| 164 | + * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
| 165 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 166 | + * @return boolean |
|
| 167 | + */ |
|
| 168 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
| 169 | + { |
|
| 170 | + if ( |
|
| 171 | + $force_recheck |
|
| 172 | + || ! is_array($this->_payment_method_types) |
|
| 173 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
| 174 | + ) { |
|
| 175 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 176 | + } |
|
| 177 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
| 178 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
| 179 | + return true; |
|
| 180 | + } else { |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Returns all the classnames of the various payment method types |
|
| 189 | + * |
|
| 190 | + * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
| 191 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
| 192 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 193 | + * @return array |
|
| 194 | + */ |
|
| 195 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
| 196 | + { |
|
| 197 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 198 | + if ($with_prefixes) { |
|
| 199 | + $classnames = array_keys($this->_payment_method_types); |
|
| 200 | + $payment_methods = array(); |
|
| 201 | + foreach ($classnames as $classname) { |
|
| 202 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
| 203 | + } |
|
| 204 | + return $payment_methods; |
|
| 205 | + } else { |
|
| 206 | + return array_keys($this->_payment_method_types); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Gets an object of each payment method type, none of which are bound to a |
|
| 214 | + * payment method instance |
|
| 215 | + * |
|
| 216 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 217 | + * @return EE_PMT_Base[] |
|
| 218 | + */ |
|
| 219 | + public function payment_method_types($force_recheck = false) |
|
| 220 | + { |
|
| 221 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 222 | + $pmt_objs = array(); |
|
| 223 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
| 224 | + $pmt_objs[] = new $classname; |
|
| 225 | + } |
|
| 226 | + return $pmt_objs; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Changes the payment method's classname into the payment method type's name |
|
| 233 | + * (as used on the payment method's table's PMD_type field) |
|
| 234 | + * |
|
| 235 | + * @param string $classname |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function payment_method_type_sans_class_prefix($classname) |
|
| 239 | + { |
|
| 240 | + return str_replace("EE_PMT_", "", $classname); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Does the opposite of payment-method_type_sans_prefix |
|
| 247 | + * |
|
| 248 | + * @param string $type |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function payment_method_class_from_type($type) |
|
| 252 | + { |
|
| 253 | + $this->maybe_register_payment_methods(); |
|
| 254 | + return "EE_PMT_" . $type; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Activates a payment method of the given type. |
|
| 261 | + * |
|
| 262 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
| 263 | + * @return \EE_Payment_Method |
|
| 264 | + * @throws \EE_Error |
|
| 265 | + */ |
|
| 266 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
| 267 | + { |
|
| 268 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
| 269 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 270 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
| 271 | + if (class_exists($pm_type_class)) { |
|
| 272 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
| 273 | + $pm_type_obj = new $pm_type_class; |
|
| 274 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
| 275 | + if ( ! $payment_method) { |
|
| 276 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
| 277 | + } |
|
| 278 | + $payment_method->set_type($payment_method_type); |
|
| 279 | + $this->initialize_payment_method($payment_method); |
|
| 280 | + } else { |
|
| 281 | + throw new EE_Error( |
|
| 282 | + sprintf( |
|
| 283 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
| 284 | + $pm_type_class) |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + $payment_method->set_active(); |
|
| 289 | + $payment_method->save(); |
|
| 290 | + $this->set_usable_currencies_on_payment_method($payment_method); |
|
| 291 | + if ($payment_method->type() === 'Invoice') { |
|
| 292 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 293 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 294 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
| 295 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
| 296 | + EE_Error::add_persistent_admin_notice( |
|
| 297 | + 'invoice_pm_requirements_notice', |
|
| 298 | + sprintf( |
|
| 299 | + __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
| 300 | + 'event_espresso'), |
|
| 301 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 302 | + '</a>' |
|
| 303 | + ), |
|
| 304 | + true |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + return $payment_method; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Creates a payment method of the specified type. Does not save it. |
|
| 314 | + * |
|
| 315 | + * @global WP_User $current_user |
|
| 316 | + * @param EE_PMT_Base $pm_type_obj |
|
| 317 | + * @return EE_Payment_Method |
|
| 318 | + * @throws \EE_Error |
|
| 319 | + */ |
|
| 320 | + public function create_payment_method_of_type($pm_type_obj) |
|
| 321 | + { |
|
| 322 | + global $current_user; |
|
| 323 | + $payment_method = EE_Payment_Method::new_instance( |
|
| 324 | + array( |
|
| 325 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
| 326 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
| 327 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
| 328 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 329 | + 'PMD_wp_user' => $current_user->ID, |
|
| 330 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
| 331 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
| 332 | + ) * 10, |
|
| 333 | + ) |
|
| 334 | + ); |
|
| 335 | + return $payment_method; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Sets the initial payment method properties (including extra meta) |
|
| 342 | + * |
|
| 343 | + * @param EE_Payment_Method $payment_method |
|
| 344 | + * @return EE_Payment_Method |
|
| 345 | + * @throws \EE_Error |
|
| 346 | + */ |
|
| 347 | + public function initialize_payment_method($payment_method) |
|
| 348 | + { |
|
| 349 | + $pm_type_obj = $payment_method->type_obj(); |
|
| 350 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
| 351 | + if ( ! $payment_method->button_url()) { |
|
| 352 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
| 353 | + } |
|
| 354 | + //now add setup its default extra meta properties |
|
| 355 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
| 356 | + if ( ! empty($extra_metas)) { |
|
| 357 | + //verify the payment method has an ID before adding extra meta |
|
| 358 | + if ( ! $payment_method->ID()) { |
|
| 359 | + $payment_method->save(); |
|
| 360 | + } |
|
| 361 | + foreach ($extra_metas as $meta_name => $input) { |
|
| 362 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + return $payment_method; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Makes sure the payment method is related to the specified payment method |
|
| 372 | + * |
|
| 373 | + * @param EE_Payment_Method $payment_method |
|
| 374 | + * @return EE_Payment_Method |
|
| 375 | + * @throws \EE_Error |
|
| 376 | + */ |
|
| 377 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
| 378 | + { |
|
| 379 | + foreach ($payment_method->get_all_usable_currencies() as $currency_obj) { |
|
| 380 | + $payment_method->_add_relation_to($currency_obj, 'Currency'); |
|
| 381 | + } |
|
| 382 | + return $payment_method; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Deactivates a payment method of the given payment method slug. |
|
| 389 | + * |
|
| 390 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
| 391 | + * @return int count of rows updated. |
|
| 392 | + */ |
|
| 393 | + public function deactivate_payment_method($payment_method_slug) |
|
| 394 | + { |
|
| 395 | + EE_Log::instance()->log( |
|
| 396 | + __FILE__, |
|
| 397 | + __FUNCTION__, |
|
| 398 | + sprintf( |
|
| 399 | + __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
| 400 | + $payment_method_slug |
|
| 401 | + ), |
|
| 402 | + 'payment_method_change' |
|
| 403 | + ); |
|
| 404 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
| 405 | + array('PMD_scope' => array()), |
|
| 406 | + array(array('PMD_slug' => $payment_method_slug)) |
|
| 407 | + ); |
|
| 408 | + return $count_updated; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
| 415 | + * access caps. |
|
| 416 | + * |
|
| 417 | + * @param array $caps capabilities being filtered |
|
| 418 | + * @return array |
|
| 419 | + */ |
|
| 420 | + public function add_payment_method_caps($caps) |
|
| 421 | + { |
|
| 422 | + /* add dynamic caps from payment methods |
|
| 423 | 423 | * at the time of writing, october 20 2014, these are the caps added: |
| 424 | 424 | * ee_payment_method_admin_only |
| 425 | 425 | * ee_payment_method_aim |
@@ -433,10 +433,10 @@ discard block |
||
| 433 | 433 | * their related capability automatically added too, so long as they are |
| 434 | 434 | * registered properly using EE_Register_Payment_Method::register() |
| 435 | 435 | */ |
| 436 | - foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
| 437 | - $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
| 438 | - } |
|
| 439 | - return $caps; |
|
| 440 | - } |
|
| 436 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
| 437 | + $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
| 438 | + } |
|
| 439 | + return $caps; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -17,244 +17,244 @@ discard block |
||
| 17 | 17 | class EEH_Activation implements ResettableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * constant used to indicate a cron task is no longer in use |
|
| 22 | - */ |
|
| 23 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * option name that will indicate whether or not we still |
|
| 27 | - * need to create EE's folders in the uploads directory |
|
| 28 | - * (because if EE was installed without file system access, |
|
| 29 | - * we need to request credentials before we can create them) |
|
| 30 | - */ |
|
| 31 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * WP_User->ID |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - private static $_default_creator_id; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 42 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 43 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 44 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 45 | - * This prevents doing that for EVERY single addon. |
|
| 46 | - * |
|
| 47 | - * @var boolean |
|
| 48 | - */ |
|
| 49 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 53 | - */ |
|
| 54 | - private static $table_analysis; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 58 | - */ |
|
| 59 | - private static $table_manager; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 64 | - */ |
|
| 65 | - public static function getTableAnalysis() |
|
| 66 | - { |
|
| 67 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 68 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 69 | - } |
|
| 70 | - return self::$table_analysis; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 76 | - */ |
|
| 77 | - public static function getTableManager() |
|
| 78 | - { |
|
| 79 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 80 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 81 | - } |
|
| 82 | - return self::$table_manager; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * _ensure_table_name_has_prefix |
|
| 88 | - * |
|
| 89 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 90 | - * @access public |
|
| 91 | - * @static |
|
| 92 | - * @param $table_name |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 96 | - { |
|
| 97 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * system_initialization |
|
| 103 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 104 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @static |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public static function system_initialization() |
|
| 111 | - { |
|
| 112 | - EEH_Activation::reset_and_update_config(); |
|
| 113 | - //which is fired BEFORE activation of plugin anyways |
|
| 114 | - EEH_Activation::verify_default_pages_exist(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets the database schema and creates folders. This should |
|
| 120 | - * be called on plugin activation and reactivation |
|
| 121 | - * |
|
| 122 | - * @return boolean success, whether the database and folders are setup properly |
|
| 123 | - * @throws \EE_Error |
|
| 124 | - */ |
|
| 125 | - public static function initialize_db_and_folders() |
|
| 126 | - { |
|
| 127 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 128 | - $good_db = EEH_Activation::create_database_tables(); |
|
| 129 | - return $good_filesystem && $good_db; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 135 | - * with default and initial data. This should be called |
|
| 136 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 137 | - * of running migration scripts |
|
| 138 | - * |
|
| 139 | - * @throws \EE_Error |
|
| 140 | - */ |
|
| 141 | - public static function initialize_db_content() |
|
| 142 | - { |
|
| 143 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 144 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 145 | - return; |
|
| 146 | - } |
|
| 147 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 148 | - |
|
| 149 | - EEH_Activation::initialize_system_questions(); |
|
| 150 | - EEH_Activation::insert_default_status_codes(); |
|
| 151 | - EEH_Activation::generate_default_message_templates(); |
|
| 152 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 153 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 154 | - |
|
| 155 | - EEH_Activation::validate_messages_system(); |
|
| 156 | - EEH_Activation::insert_default_payment_methods(); |
|
| 157 | - //in case we've |
|
| 158 | - EEH_Activation::remove_cron_tasks(); |
|
| 159 | - EEH_Activation::create_cron_tasks(); |
|
| 160 | - // remove all TXN locks since that is being done via extra meta now |
|
| 161 | - delete_option('ee_locked_transactions'); |
|
| 162 | - //also, check for CAF default db content |
|
| 163 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 164 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 165 | - //which users really won't care about on initial activation |
|
| 166 | - EE_Error::overwrite_success(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 172 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 173 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 174 | - * (null) |
|
| 175 | - * |
|
| 176 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 177 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 178 | - * @return array |
|
| 179 | - * @throws \EE_Error |
|
| 180 | - */ |
|
| 181 | - public static function get_cron_tasks($which_to_include) |
|
| 182 | - { |
|
| 183 | - $cron_tasks = apply_filters( |
|
| 184 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 185 | - array( |
|
| 186 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 20 | + /** |
|
| 21 | + * constant used to indicate a cron task is no longer in use |
|
| 22 | + */ |
|
| 23 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * option name that will indicate whether or not we still |
|
| 27 | + * need to create EE's folders in the uploads directory |
|
| 28 | + * (because if EE was installed without file system access, |
|
| 29 | + * we need to request credentials before we can create them) |
|
| 30 | + */ |
|
| 31 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * WP_User->ID |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + private static $_default_creator_id; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 42 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 43 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 44 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 45 | + * This prevents doing that for EVERY single addon. |
|
| 46 | + * |
|
| 47 | + * @var boolean |
|
| 48 | + */ |
|
| 49 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 53 | + */ |
|
| 54 | + private static $table_analysis; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 58 | + */ |
|
| 59 | + private static $table_manager; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 64 | + */ |
|
| 65 | + public static function getTableAnalysis() |
|
| 66 | + { |
|
| 67 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 68 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 69 | + } |
|
| 70 | + return self::$table_analysis; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 76 | + */ |
|
| 77 | + public static function getTableManager() |
|
| 78 | + { |
|
| 79 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 80 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 81 | + } |
|
| 82 | + return self::$table_manager; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * _ensure_table_name_has_prefix |
|
| 88 | + * |
|
| 89 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 90 | + * @access public |
|
| 91 | + * @static |
|
| 92 | + * @param $table_name |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 96 | + { |
|
| 97 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * system_initialization |
|
| 103 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 104 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @static |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public static function system_initialization() |
|
| 111 | + { |
|
| 112 | + EEH_Activation::reset_and_update_config(); |
|
| 113 | + //which is fired BEFORE activation of plugin anyways |
|
| 114 | + EEH_Activation::verify_default_pages_exist(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets the database schema and creates folders. This should |
|
| 120 | + * be called on plugin activation and reactivation |
|
| 121 | + * |
|
| 122 | + * @return boolean success, whether the database and folders are setup properly |
|
| 123 | + * @throws \EE_Error |
|
| 124 | + */ |
|
| 125 | + public static function initialize_db_and_folders() |
|
| 126 | + { |
|
| 127 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 128 | + $good_db = EEH_Activation::create_database_tables(); |
|
| 129 | + return $good_filesystem && $good_db; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 135 | + * with default and initial data. This should be called |
|
| 136 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 137 | + * of running migration scripts |
|
| 138 | + * |
|
| 139 | + * @throws \EE_Error |
|
| 140 | + */ |
|
| 141 | + public static function initialize_db_content() |
|
| 142 | + { |
|
| 143 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 144 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 147 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 148 | + |
|
| 149 | + EEH_Activation::initialize_system_questions(); |
|
| 150 | + EEH_Activation::insert_default_status_codes(); |
|
| 151 | + EEH_Activation::generate_default_message_templates(); |
|
| 152 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 153 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 154 | + |
|
| 155 | + EEH_Activation::validate_messages_system(); |
|
| 156 | + EEH_Activation::insert_default_payment_methods(); |
|
| 157 | + //in case we've |
|
| 158 | + EEH_Activation::remove_cron_tasks(); |
|
| 159 | + EEH_Activation::create_cron_tasks(); |
|
| 160 | + // remove all TXN locks since that is being done via extra meta now |
|
| 161 | + delete_option('ee_locked_transactions'); |
|
| 162 | + //also, check for CAF default db content |
|
| 163 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 164 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 165 | + //which users really won't care about on initial activation |
|
| 166 | + EE_Error::overwrite_success(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 172 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 173 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 174 | + * (null) |
|
| 175 | + * |
|
| 176 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 177 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 178 | + * @return array |
|
| 179 | + * @throws \EE_Error |
|
| 180 | + */ |
|
| 181 | + public static function get_cron_tasks($which_to_include) |
|
| 182 | + { |
|
| 183 | + $cron_tasks = apply_filters( |
|
| 184 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 185 | + array( |
|
| 186 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 187 | 187 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
| 188 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 189 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 190 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - if ($which_to_include === 'old') { |
|
| 194 | - $cron_tasks = array_filter( |
|
| 195 | - $cron_tasks, |
|
| 196 | - function ($value) { |
|
| 197 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 198 | - } |
|
| 199 | - ); |
|
| 200 | - } elseif ($which_to_include === 'current') { |
|
| 201 | - $cron_tasks = array_filter($cron_tasks); |
|
| 202 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 203 | - throw new EE_Error( |
|
| 204 | - sprintf( |
|
| 205 | - __( |
|
| 206 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 207 | - 'event_espresso' |
|
| 208 | - ), |
|
| 209 | - $which_to_include |
|
| 210 | - ) |
|
| 211 | - ); |
|
| 212 | - } |
|
| 213 | - return $cron_tasks; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 219 | - * |
|
| 220 | - * @throws \EE_Error |
|
| 221 | - */ |
|
| 222 | - public static function create_cron_tasks() |
|
| 223 | - { |
|
| 224 | - |
|
| 225 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 226 | - if (! wp_next_scheduled($hook_name)) { |
|
| 227 | - /** |
|
| 228 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 229 | - */ |
|
| 230 | - if (is_array($frequency) |
|
| 231 | - && count($frequency) === 2 |
|
| 232 | - && isset($frequency[0], $frequency[1]) |
|
| 233 | - ) { |
|
| 234 | - $start_timestamp = $frequency[0]; |
|
| 235 | - $frequency = $frequency[1]; |
|
| 236 | - } else { |
|
| 237 | - $start_timestamp = time(); |
|
| 238 | - } |
|
| 239 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 248 | - * |
|
| 249 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 250 | - * @throws \EE_Error |
|
| 251 | - */ |
|
| 252 | - public static function remove_cron_tasks($remove_all = true) |
|
| 253 | - { |
|
| 254 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 255 | - $crons = _get_cron_array(); |
|
| 256 | - $crons = is_array($crons) ? $crons : array(); |
|
| 257 | - /* reminder of what $crons look like: |
|
| 188 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 189 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 190 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + if ($which_to_include === 'old') { |
|
| 194 | + $cron_tasks = array_filter( |
|
| 195 | + $cron_tasks, |
|
| 196 | + function ($value) { |
|
| 197 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 198 | + } |
|
| 199 | + ); |
|
| 200 | + } elseif ($which_to_include === 'current') { |
|
| 201 | + $cron_tasks = array_filter($cron_tasks); |
|
| 202 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 203 | + throw new EE_Error( |
|
| 204 | + sprintf( |
|
| 205 | + __( |
|
| 206 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 207 | + 'event_espresso' |
|
| 208 | + ), |
|
| 209 | + $which_to_include |
|
| 210 | + ) |
|
| 211 | + ); |
|
| 212 | + } |
|
| 213 | + return $cron_tasks; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 219 | + * |
|
| 220 | + * @throws \EE_Error |
|
| 221 | + */ |
|
| 222 | + public static function create_cron_tasks() |
|
| 223 | + { |
|
| 224 | + |
|
| 225 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 226 | + if (! wp_next_scheduled($hook_name)) { |
|
| 227 | + /** |
|
| 228 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 229 | + */ |
|
| 230 | + if (is_array($frequency) |
|
| 231 | + && count($frequency) === 2 |
|
| 232 | + && isset($frequency[0], $frequency[1]) |
|
| 233 | + ) { |
|
| 234 | + $start_timestamp = $frequency[0]; |
|
| 235 | + $frequency = $frequency[1]; |
|
| 236 | + } else { |
|
| 237 | + $start_timestamp = time(); |
|
| 238 | + } |
|
| 239 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 248 | + * |
|
| 249 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 250 | + * @throws \EE_Error |
|
| 251 | + */ |
|
| 252 | + public static function remove_cron_tasks($remove_all = true) |
|
| 253 | + { |
|
| 254 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 255 | + $crons = _get_cron_array(); |
|
| 256 | + $crons = is_array($crons) ? $crons : array(); |
|
| 257 | + /* reminder of what $crons look like: |
|
| 258 | 258 | * Top-level keys are timestamps, and their values are arrays. |
| 259 | 259 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 260 | 260 | * and their values are arrays. |
@@ -271,912 +271,912 @@ discard block |
||
| 271 | 271 | * ... |
| 272 | 272 | * ... |
| 273 | 273 | */ |
| 274 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 275 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 276 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 277 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 278 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 279 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 280 | - ) { |
|
| 281 | - unset($crons[$timestamp][$hook_name]); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - //also take care of any empty cron timestamps. |
|
| 285 | - if (empty($hooks_to_fire_at_time)) { |
|
| 286 | - unset($crons[$timestamp]); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - _set_cron_array($crons); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * CPT_initialization |
|
| 296 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 297 | - * |
|
| 298 | - * @access public |
|
| 299 | - * @static |
|
| 300 | - * @return void |
|
| 301 | - */ |
|
| 302 | - public static function CPT_initialization() |
|
| 303 | - { |
|
| 304 | - // register Custom Post Types |
|
| 305 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 306 | - flush_rewrite_rules(); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * reset_and_update_config |
|
| 313 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 314 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 315 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 316 | - * |
|
| 317 | - * @access public |
|
| 318 | - * @static |
|
| 319 | - * @return void |
|
| 320 | - */ |
|
| 321 | - public static function reset_and_update_config() |
|
| 322 | - { |
|
| 323 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 324 | - add_filter( |
|
| 325 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 326 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 327 | - 10, |
|
| 328 | - 3 |
|
| 329 | - ); |
|
| 330 | - //EE_Config::reset(); |
|
| 331 | - if (! EE_Config::logging_enabled()) { |
|
| 332 | - delete_option(EE_Config::LOG_NAME); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * load_calendar_config |
|
| 339 | - * |
|
| 340 | - * @access public |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - public static function load_calendar_config() |
|
| 344 | - { |
|
| 345 | - // grab array of all plugin folders and loop thru it |
|
| 346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 347 | - if (empty($plugins)) { |
|
| 348 | - return; |
|
| 349 | - } |
|
| 350 | - foreach ($plugins as $plugin_path) { |
|
| 351 | - // grab plugin folder name from path |
|
| 352 | - $plugin = basename($plugin_path); |
|
| 353 | - // drill down to Espresso plugins |
|
| 354 | - // then to calendar related plugins |
|
| 355 | - if ( |
|
| 356 | - strpos($plugin, 'espresso') !== false |
|
| 357 | - || strpos($plugin, 'Espresso') !== false |
|
| 358 | - || strpos($plugin, 'ee4') !== false |
|
| 359 | - || strpos($plugin, 'EE4') !== false |
|
| 360 | - || strpos($plugin, 'calendar') !== false |
|
| 361 | - ) { |
|
| 362 | - // this is what we are looking for |
|
| 363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 364 | - // does it exist in this folder ? |
|
| 365 | - if (is_readable($calendar_config)) { |
|
| 366 | - // YEAH! let's load it |
|
| 367 | - require_once($calendar_config); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * _migrate_old_config_data |
|
| 377 | - * |
|
| 378 | - * @access public |
|
| 379 | - * @param array|stdClass $settings |
|
| 380 | - * @param string $config |
|
| 381 | - * @param \EE_Config $EE_Config |
|
| 382 | - * @return \stdClass |
|
| 383 | - */ |
|
| 384 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 385 | - { |
|
| 386 | - $convert_from_array = array('addons'); |
|
| 387 | - // in case old settings were saved as an array |
|
| 388 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 389 | - // convert existing settings to an object |
|
| 390 | - $config_array = $settings; |
|
| 391 | - $settings = new stdClass(); |
|
| 392 | - foreach ($config_array as $key => $value) { |
|
| 393 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 394 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 395 | - } else { |
|
| 396 | - $settings->{$key} = $value; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 400 | - } |
|
| 401 | - return $settings; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * deactivate_event_espresso |
|
| 407 | - * |
|
| 408 | - * @access public |
|
| 409 | - * @static |
|
| 410 | - * @return void |
|
| 411 | - */ |
|
| 412 | - public static function deactivate_event_espresso() |
|
| 413 | - { |
|
| 414 | - // check permissions |
|
| 415 | - if (current_user_can('activate_plugins')) { |
|
| 416 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * verify_default_pages_exist |
|
| 426 | - * |
|
| 427 | - * @access public |
|
| 428 | - * @static |
|
| 429 | - * @return void |
|
| 430 | - */ |
|
| 431 | - public static function verify_default_pages_exist() |
|
| 432 | - { |
|
| 433 | - $critical_page_problem = false; |
|
| 434 | - $critical_pages = array( |
|
| 435 | - array( |
|
| 436 | - 'id' => 'reg_page_id', |
|
| 437 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 438 | - 'post' => null, |
|
| 439 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 440 | - ), |
|
| 441 | - array( |
|
| 442 | - 'id' => 'txn_page_id', |
|
| 443 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 444 | - 'post' => null, |
|
| 445 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 446 | - ), |
|
| 447 | - array( |
|
| 448 | - 'id' => 'thank_you_page_id', |
|
| 449 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 450 | - 'post' => null, |
|
| 451 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 452 | - ), |
|
| 453 | - array( |
|
| 454 | - 'id' => 'cancel_page_id', |
|
| 455 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 456 | - 'post' => null, |
|
| 457 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 458 | - ), |
|
| 459 | - ); |
|
| 460 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 461 | - foreach ($critical_pages as $critical_page) { |
|
| 462 | - // is critical page ID set in config ? |
|
| 463 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 464 | - // attempt to find post by ID |
|
| 465 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 466 | - } |
|
| 467 | - // no dice? |
|
| 468 | - if ($critical_page['post'] === null) { |
|
| 469 | - // attempt to find post by title |
|
| 470 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 471 | - // still nothing? |
|
| 472 | - if ($critical_page['post'] === null) { |
|
| 473 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 474 | - // REALLY? Still nothing ??!?!? |
|
| 475 | - if ($critical_page['post'] === null) { |
|
| 476 | - $msg = __( |
|
| 477 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 478 | - 'event_espresso' |
|
| 479 | - ); |
|
| 480 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | - break; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - // check that Post ID matches critical page ID in config |
|
| 486 | - if ( |
|
| 487 | - isset($critical_page['post']->ID) |
|
| 488 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 489 | - ) { |
|
| 490 | - //update Config with post ID |
|
| 491 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 492 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 493 | - $msg = __( |
|
| 494 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 495 | - 'event_espresso' |
|
| 496 | - ); |
|
| 497 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - $critical_page_problem = |
|
| 501 | - ! isset($critical_page['post']->post_status) |
|
| 502 | - || $critical_page['post']->post_status !== 'publish' |
|
| 503 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 504 | - ? true |
|
| 505 | - : $critical_page_problem; |
|
| 506 | - } |
|
| 507 | - if ($critical_page_problem) { |
|
| 508 | - $msg = sprintf( |
|
| 509 | - __( |
|
| 510 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 511 | - 'event_espresso' |
|
| 512 | - ), |
|
| 513 | - '<a href="' |
|
| 514 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 515 | - . '">' |
|
| 516 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 517 | - . '</a>' |
|
| 518 | - ); |
|
| 519 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 520 | - } |
|
| 521 | - if (EE_Error::has_notices()) { |
|
| 522 | - EE_Error::get_notices(false, true, true); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Returns the first post which uses the specified shortcode |
|
| 530 | - * |
|
| 531 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 532 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 533 | - * "[ESPRESSO_THANK_YOU" |
|
| 534 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 535 | - * parameter to the shortcode |
|
| 536 | - * @return WP_Post or NULl |
|
| 537 | - */ |
|
| 538 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 539 | - { |
|
| 540 | - global $wpdb; |
|
| 541 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 542 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 543 | - if ($post_id) { |
|
| 544 | - return get_post($post_id); |
|
| 545 | - } else { |
|
| 546 | - return null; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * This function generates a post for critical espresso pages |
|
| 553 | - * |
|
| 554 | - * @access public |
|
| 555 | - * @static |
|
| 556 | - * @param array $critical_page |
|
| 557 | - * @return array |
|
| 558 | - */ |
|
| 559 | - public static function create_critical_page($critical_page) |
|
| 560 | - { |
|
| 561 | - |
|
| 562 | - $post_args = array( |
|
| 563 | - 'post_title' => $critical_page['name'], |
|
| 564 | - 'post_status' => 'publish', |
|
| 565 | - 'post_type' => 'page', |
|
| 566 | - 'comment_status' => 'closed', |
|
| 567 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 568 | - ); |
|
| 569 | - |
|
| 570 | - $post_id = wp_insert_post($post_args); |
|
| 571 | - if (! $post_id) { |
|
| 572 | - $msg = sprintf( |
|
| 573 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 574 | - $critical_page['name'] |
|
| 575 | - ); |
|
| 576 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 577 | - return $critical_page; |
|
| 578 | - } |
|
| 579 | - // get newly created post's details |
|
| 580 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 581 | - $msg = sprintf( |
|
| 582 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 583 | - $critical_page['name'] |
|
| 584 | - ); |
|
| 585 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - return $critical_page; |
|
| 589 | - |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 597 | - * The role being used to check is filterable. |
|
| 598 | - * |
|
| 599 | - * @since 4.6.0 |
|
| 600 | - * @global WPDB $wpdb |
|
| 601 | - * @return mixed null|int WP_user ID or NULL |
|
| 602 | - */ |
|
| 603 | - public static function get_default_creator_id() |
|
| 604 | - { |
|
| 605 | - global $wpdb; |
|
| 606 | - if ( ! empty(self::$_default_creator_id)) { |
|
| 607 | - return self::$_default_creator_id; |
|
| 608 | - }/**/ |
|
| 609 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 610 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 611 | - $pre_filtered_id = apply_filters( |
|
| 612 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 613 | - false, |
|
| 614 | - $role_to_check |
|
| 615 | - ); |
|
| 616 | - if ($pre_filtered_id !== false) { |
|
| 617 | - return (int)$pre_filtered_id; |
|
| 618 | - } |
|
| 619 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 620 | - $query = $wpdb->prepare( |
|
| 621 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 622 | - '%' . $role_to_check . '%' |
|
| 623 | - ); |
|
| 624 | - $user_id = $wpdb->get_var($query); |
|
| 625 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 626 | - if ($user_id && (int)$user_id) { |
|
| 627 | - self::$_default_creator_id = (int)$user_id; |
|
| 628 | - return self::$_default_creator_id; |
|
| 629 | - } else { |
|
| 630 | - return null; |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 638 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 639 | - * but includes extra logic regarding activations. |
|
| 640 | - * |
|
| 641 | - * @access public |
|
| 642 | - * @static |
|
| 643 | - * @param string $table_name without the $wpdb->prefix |
|
| 644 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 645 | - * table query) |
|
| 646 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 647 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 648 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 649 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 650 | - * you just want to verify the table exists and matches this definition |
|
| 651 | - * (and if it HAS data in it you want to leave it be) |
|
| 652 | - * @return void |
|
| 653 | - * @throws EE_Error if there are database errors |
|
| 654 | - */ |
|
| 655 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 656 | - { |
|
| 657 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 658 | - return; |
|
| 659 | - } |
|
| 660 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 661 | - if ( ! function_exists('dbDelta')) { |
|
| 662 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 663 | - } |
|
| 664 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 665 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 666 | - // do we need to first delete an existing version of this table ? |
|
| 667 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 668 | - // ok, delete the table... but ONLY if it's empty |
|
| 669 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 670 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 671 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 672 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 673 | - } else if ( ! $deleted_safely) { |
|
| 674 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 675 | - error_log( |
|
| 676 | - sprintf( |
|
| 677 | - __( |
|
| 678 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 679 | - 'event_espresso' |
|
| 680 | - ), |
|
| 681 | - $wp_table_name, |
|
| 682 | - '<br/>', |
|
| 683 | - 'espresso_db_update' |
|
| 684 | - ) |
|
| 685 | - ); |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 689 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * add_column_if_it_doesn't_exist |
|
| 696 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 697 | - * |
|
| 698 | - * @access public |
|
| 699 | - * @static |
|
| 700 | - * @deprecated instead use TableManager::addColumn() |
|
| 701 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 702 | - * @param string $column_name |
|
| 703 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 704 | - * 'VARCHAR(10)' |
|
| 705 | - * @return bool|int |
|
| 706 | - */ |
|
| 707 | - public static function add_column_if_it_doesnt_exist( |
|
| 708 | - $table_name, |
|
| 709 | - $column_name, |
|
| 710 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 711 | - ) { |
|
| 712 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * get_fields_on_table |
|
| 718 | - * Gets all the fields on the database table. |
|
| 719 | - * |
|
| 720 | - * @access public |
|
| 721 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 722 | - * @static |
|
| 723 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 724 | - * @return array of database column names |
|
| 725 | - */ |
|
| 726 | - public static function get_fields_on_table($table_name = null) |
|
| 727 | - { |
|
| 728 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * db_table_is_empty |
|
| 734 | - * |
|
| 735 | - * @access public\ |
|
| 736 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 737 | - * @static |
|
| 738 | - * @param string $table_name |
|
| 739 | - * @return bool |
|
| 740 | - */ |
|
| 741 | - public static function db_table_is_empty($table_name) |
|
| 742 | - { |
|
| 743 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * delete_db_table_if_empty |
|
| 749 | - * |
|
| 750 | - * @access public |
|
| 751 | - * @static |
|
| 752 | - * @param string $table_name |
|
| 753 | - * @return bool | int |
|
| 754 | - */ |
|
| 755 | - public static function delete_db_table_if_empty($table_name) |
|
| 756 | - { |
|
| 757 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 758 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 759 | - } |
|
| 760 | - return false; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * delete_unused_db_table |
|
| 766 | - * |
|
| 767 | - * @access public |
|
| 768 | - * @static |
|
| 769 | - * @deprecated instead use TableManager::dropTable() |
|
| 770 | - * @param string $table_name |
|
| 771 | - * @return bool | int |
|
| 772 | - */ |
|
| 773 | - public static function delete_unused_db_table($table_name) |
|
| 774 | - { |
|
| 775 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * drop_index |
|
| 781 | - * |
|
| 782 | - * @access public |
|
| 783 | - * @static |
|
| 784 | - * @deprecated instead use TableManager::dropIndex() |
|
| 785 | - * @param string $table_name |
|
| 786 | - * @param string $index_name |
|
| 787 | - * @return bool | int |
|
| 788 | - */ |
|
| 789 | - public static function drop_index($table_name, $index_name) |
|
| 790 | - { |
|
| 791 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * create_database_tables |
|
| 798 | - * |
|
| 799 | - * @access public |
|
| 800 | - * @static |
|
| 801 | - * @throws EE_Error |
|
| 802 | - * @return boolean success (whether database is setup properly or not) |
|
| 803 | - */ |
|
| 804 | - public static function create_database_tables() |
|
| 805 | - { |
|
| 806 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 807 | - //find the migration script that sets the database to be compatible with the code |
|
| 808 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 809 | - if ($dms_name) { |
|
| 810 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 811 | - $current_data_migration_script->set_migrating(false); |
|
| 812 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 813 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 814 | - if ($current_data_migration_script->get_errors()) { |
|
| 815 | - if (WP_DEBUG) { |
|
| 816 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 817 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 818 | - } |
|
| 819 | - } else { |
|
| 820 | - EE_Error::add_error( |
|
| 821 | - __( |
|
| 822 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 274 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 275 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 276 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 277 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 278 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 279 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 280 | + ) { |
|
| 281 | + unset($crons[$timestamp][$hook_name]); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + //also take care of any empty cron timestamps. |
|
| 285 | + if (empty($hooks_to_fire_at_time)) { |
|
| 286 | + unset($crons[$timestamp]); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + _set_cron_array($crons); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * CPT_initialization |
|
| 296 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 297 | + * |
|
| 298 | + * @access public |
|
| 299 | + * @static |
|
| 300 | + * @return void |
|
| 301 | + */ |
|
| 302 | + public static function CPT_initialization() |
|
| 303 | + { |
|
| 304 | + // register Custom Post Types |
|
| 305 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 306 | + flush_rewrite_rules(); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * reset_and_update_config |
|
| 313 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 314 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 315 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 316 | + * |
|
| 317 | + * @access public |
|
| 318 | + * @static |
|
| 319 | + * @return void |
|
| 320 | + */ |
|
| 321 | + public static function reset_and_update_config() |
|
| 322 | + { |
|
| 323 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 324 | + add_filter( |
|
| 325 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 326 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 327 | + 10, |
|
| 328 | + 3 |
|
| 329 | + ); |
|
| 330 | + //EE_Config::reset(); |
|
| 331 | + if (! EE_Config::logging_enabled()) { |
|
| 332 | + delete_option(EE_Config::LOG_NAME); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * load_calendar_config |
|
| 339 | + * |
|
| 340 | + * @access public |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + public static function load_calendar_config() |
|
| 344 | + { |
|
| 345 | + // grab array of all plugin folders and loop thru it |
|
| 346 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 347 | + if (empty($plugins)) { |
|
| 348 | + return; |
|
| 349 | + } |
|
| 350 | + foreach ($plugins as $plugin_path) { |
|
| 351 | + // grab plugin folder name from path |
|
| 352 | + $plugin = basename($plugin_path); |
|
| 353 | + // drill down to Espresso plugins |
|
| 354 | + // then to calendar related plugins |
|
| 355 | + if ( |
|
| 356 | + strpos($plugin, 'espresso') !== false |
|
| 357 | + || strpos($plugin, 'Espresso') !== false |
|
| 358 | + || strpos($plugin, 'ee4') !== false |
|
| 359 | + || strpos($plugin, 'EE4') !== false |
|
| 360 | + || strpos($plugin, 'calendar') !== false |
|
| 361 | + ) { |
|
| 362 | + // this is what we are looking for |
|
| 363 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 364 | + // does it exist in this folder ? |
|
| 365 | + if (is_readable($calendar_config)) { |
|
| 366 | + // YEAH! let's load it |
|
| 367 | + require_once($calendar_config); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * _migrate_old_config_data |
|
| 377 | + * |
|
| 378 | + * @access public |
|
| 379 | + * @param array|stdClass $settings |
|
| 380 | + * @param string $config |
|
| 381 | + * @param \EE_Config $EE_Config |
|
| 382 | + * @return \stdClass |
|
| 383 | + */ |
|
| 384 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 385 | + { |
|
| 386 | + $convert_from_array = array('addons'); |
|
| 387 | + // in case old settings were saved as an array |
|
| 388 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 389 | + // convert existing settings to an object |
|
| 390 | + $config_array = $settings; |
|
| 391 | + $settings = new stdClass(); |
|
| 392 | + foreach ($config_array as $key => $value) { |
|
| 393 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 394 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 395 | + } else { |
|
| 396 | + $settings->{$key} = $value; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 400 | + } |
|
| 401 | + return $settings; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * deactivate_event_espresso |
|
| 407 | + * |
|
| 408 | + * @access public |
|
| 409 | + * @static |
|
| 410 | + * @return void |
|
| 411 | + */ |
|
| 412 | + public static function deactivate_event_espresso() |
|
| 413 | + { |
|
| 414 | + // check permissions |
|
| 415 | + if (current_user_can('activate_plugins')) { |
|
| 416 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * verify_default_pages_exist |
|
| 426 | + * |
|
| 427 | + * @access public |
|
| 428 | + * @static |
|
| 429 | + * @return void |
|
| 430 | + */ |
|
| 431 | + public static function verify_default_pages_exist() |
|
| 432 | + { |
|
| 433 | + $critical_page_problem = false; |
|
| 434 | + $critical_pages = array( |
|
| 435 | + array( |
|
| 436 | + 'id' => 'reg_page_id', |
|
| 437 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 438 | + 'post' => null, |
|
| 439 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 440 | + ), |
|
| 441 | + array( |
|
| 442 | + 'id' => 'txn_page_id', |
|
| 443 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 444 | + 'post' => null, |
|
| 445 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 446 | + ), |
|
| 447 | + array( |
|
| 448 | + 'id' => 'thank_you_page_id', |
|
| 449 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 450 | + 'post' => null, |
|
| 451 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 452 | + ), |
|
| 453 | + array( |
|
| 454 | + 'id' => 'cancel_page_id', |
|
| 455 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 456 | + 'post' => null, |
|
| 457 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 458 | + ), |
|
| 459 | + ); |
|
| 460 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 461 | + foreach ($critical_pages as $critical_page) { |
|
| 462 | + // is critical page ID set in config ? |
|
| 463 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 464 | + // attempt to find post by ID |
|
| 465 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 466 | + } |
|
| 467 | + // no dice? |
|
| 468 | + if ($critical_page['post'] === null) { |
|
| 469 | + // attempt to find post by title |
|
| 470 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 471 | + // still nothing? |
|
| 472 | + if ($critical_page['post'] === null) { |
|
| 473 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 474 | + // REALLY? Still nothing ??!?!? |
|
| 475 | + if ($critical_page['post'] === null) { |
|
| 476 | + $msg = __( |
|
| 477 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 478 | + 'event_espresso' |
|
| 479 | + ); |
|
| 480 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | + break; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + // check that Post ID matches critical page ID in config |
|
| 486 | + if ( |
|
| 487 | + isset($critical_page['post']->ID) |
|
| 488 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 489 | + ) { |
|
| 490 | + //update Config with post ID |
|
| 491 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 492 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 493 | + $msg = __( |
|
| 494 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 495 | + 'event_espresso' |
|
| 496 | + ); |
|
| 497 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + $critical_page_problem = |
|
| 501 | + ! isset($critical_page['post']->post_status) |
|
| 502 | + || $critical_page['post']->post_status !== 'publish' |
|
| 503 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 504 | + ? true |
|
| 505 | + : $critical_page_problem; |
|
| 506 | + } |
|
| 507 | + if ($critical_page_problem) { |
|
| 508 | + $msg = sprintf( |
|
| 509 | + __( |
|
| 510 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 511 | + 'event_espresso' |
|
| 512 | + ), |
|
| 513 | + '<a href="' |
|
| 514 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 515 | + . '">' |
|
| 516 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 517 | + . '</a>' |
|
| 518 | + ); |
|
| 519 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 520 | + } |
|
| 521 | + if (EE_Error::has_notices()) { |
|
| 522 | + EE_Error::get_notices(false, true, true); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Returns the first post which uses the specified shortcode |
|
| 530 | + * |
|
| 531 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 532 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 533 | + * "[ESPRESSO_THANK_YOU" |
|
| 534 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 535 | + * parameter to the shortcode |
|
| 536 | + * @return WP_Post or NULl |
|
| 537 | + */ |
|
| 538 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 539 | + { |
|
| 540 | + global $wpdb; |
|
| 541 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 542 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 543 | + if ($post_id) { |
|
| 544 | + return get_post($post_id); |
|
| 545 | + } else { |
|
| 546 | + return null; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * This function generates a post for critical espresso pages |
|
| 553 | + * |
|
| 554 | + * @access public |
|
| 555 | + * @static |
|
| 556 | + * @param array $critical_page |
|
| 557 | + * @return array |
|
| 558 | + */ |
|
| 559 | + public static function create_critical_page($critical_page) |
|
| 560 | + { |
|
| 561 | + |
|
| 562 | + $post_args = array( |
|
| 563 | + 'post_title' => $critical_page['name'], |
|
| 564 | + 'post_status' => 'publish', |
|
| 565 | + 'post_type' => 'page', |
|
| 566 | + 'comment_status' => 'closed', |
|
| 567 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 568 | + ); |
|
| 569 | + |
|
| 570 | + $post_id = wp_insert_post($post_args); |
|
| 571 | + if (! $post_id) { |
|
| 572 | + $msg = sprintf( |
|
| 573 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 574 | + $critical_page['name'] |
|
| 575 | + ); |
|
| 576 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 577 | + return $critical_page; |
|
| 578 | + } |
|
| 579 | + // get newly created post's details |
|
| 580 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 581 | + $msg = sprintf( |
|
| 582 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 583 | + $critical_page['name'] |
|
| 584 | + ); |
|
| 585 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + return $critical_page; |
|
| 589 | + |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 597 | + * The role being used to check is filterable. |
|
| 598 | + * |
|
| 599 | + * @since 4.6.0 |
|
| 600 | + * @global WPDB $wpdb |
|
| 601 | + * @return mixed null|int WP_user ID or NULL |
|
| 602 | + */ |
|
| 603 | + public static function get_default_creator_id() |
|
| 604 | + { |
|
| 605 | + global $wpdb; |
|
| 606 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 607 | + return self::$_default_creator_id; |
|
| 608 | + }/**/ |
|
| 609 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 610 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 611 | + $pre_filtered_id = apply_filters( |
|
| 612 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 613 | + false, |
|
| 614 | + $role_to_check |
|
| 615 | + ); |
|
| 616 | + if ($pre_filtered_id !== false) { |
|
| 617 | + return (int)$pre_filtered_id; |
|
| 618 | + } |
|
| 619 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 620 | + $query = $wpdb->prepare( |
|
| 621 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 622 | + '%' . $role_to_check . '%' |
|
| 623 | + ); |
|
| 624 | + $user_id = $wpdb->get_var($query); |
|
| 625 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 626 | + if ($user_id && (int)$user_id) { |
|
| 627 | + self::$_default_creator_id = (int)$user_id; |
|
| 628 | + return self::$_default_creator_id; |
|
| 629 | + } else { |
|
| 630 | + return null; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 638 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 639 | + * but includes extra logic regarding activations. |
|
| 640 | + * |
|
| 641 | + * @access public |
|
| 642 | + * @static |
|
| 643 | + * @param string $table_name without the $wpdb->prefix |
|
| 644 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 645 | + * table query) |
|
| 646 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 647 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 648 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 649 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 650 | + * you just want to verify the table exists and matches this definition |
|
| 651 | + * (and if it HAS data in it you want to leave it be) |
|
| 652 | + * @return void |
|
| 653 | + * @throws EE_Error if there are database errors |
|
| 654 | + */ |
|
| 655 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 656 | + { |
|
| 657 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 658 | + return; |
|
| 659 | + } |
|
| 660 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 661 | + if ( ! function_exists('dbDelta')) { |
|
| 662 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 663 | + } |
|
| 664 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 665 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 666 | + // do we need to first delete an existing version of this table ? |
|
| 667 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 668 | + // ok, delete the table... but ONLY if it's empty |
|
| 669 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 670 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 671 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 672 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 673 | + } else if ( ! $deleted_safely) { |
|
| 674 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 675 | + error_log( |
|
| 676 | + sprintf( |
|
| 677 | + __( |
|
| 678 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 679 | + 'event_espresso' |
|
| 680 | + ), |
|
| 681 | + $wp_table_name, |
|
| 682 | + '<br/>', |
|
| 683 | + 'espresso_db_update' |
|
| 684 | + ) |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 689 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * add_column_if_it_doesn't_exist |
|
| 696 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 697 | + * |
|
| 698 | + * @access public |
|
| 699 | + * @static |
|
| 700 | + * @deprecated instead use TableManager::addColumn() |
|
| 701 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 702 | + * @param string $column_name |
|
| 703 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 704 | + * 'VARCHAR(10)' |
|
| 705 | + * @return bool|int |
|
| 706 | + */ |
|
| 707 | + public static function add_column_if_it_doesnt_exist( |
|
| 708 | + $table_name, |
|
| 709 | + $column_name, |
|
| 710 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 711 | + ) { |
|
| 712 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * get_fields_on_table |
|
| 718 | + * Gets all the fields on the database table. |
|
| 719 | + * |
|
| 720 | + * @access public |
|
| 721 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 722 | + * @static |
|
| 723 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 724 | + * @return array of database column names |
|
| 725 | + */ |
|
| 726 | + public static function get_fields_on_table($table_name = null) |
|
| 727 | + { |
|
| 728 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * db_table_is_empty |
|
| 734 | + * |
|
| 735 | + * @access public\ |
|
| 736 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 737 | + * @static |
|
| 738 | + * @param string $table_name |
|
| 739 | + * @return bool |
|
| 740 | + */ |
|
| 741 | + public static function db_table_is_empty($table_name) |
|
| 742 | + { |
|
| 743 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * delete_db_table_if_empty |
|
| 749 | + * |
|
| 750 | + * @access public |
|
| 751 | + * @static |
|
| 752 | + * @param string $table_name |
|
| 753 | + * @return bool | int |
|
| 754 | + */ |
|
| 755 | + public static function delete_db_table_if_empty($table_name) |
|
| 756 | + { |
|
| 757 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 758 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 759 | + } |
|
| 760 | + return false; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * delete_unused_db_table |
|
| 766 | + * |
|
| 767 | + * @access public |
|
| 768 | + * @static |
|
| 769 | + * @deprecated instead use TableManager::dropTable() |
|
| 770 | + * @param string $table_name |
|
| 771 | + * @return bool | int |
|
| 772 | + */ |
|
| 773 | + public static function delete_unused_db_table($table_name) |
|
| 774 | + { |
|
| 775 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * drop_index |
|
| 781 | + * |
|
| 782 | + * @access public |
|
| 783 | + * @static |
|
| 784 | + * @deprecated instead use TableManager::dropIndex() |
|
| 785 | + * @param string $table_name |
|
| 786 | + * @param string $index_name |
|
| 787 | + * @return bool | int |
|
| 788 | + */ |
|
| 789 | + public static function drop_index($table_name, $index_name) |
|
| 790 | + { |
|
| 791 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * create_database_tables |
|
| 798 | + * |
|
| 799 | + * @access public |
|
| 800 | + * @static |
|
| 801 | + * @throws EE_Error |
|
| 802 | + * @return boolean success (whether database is setup properly or not) |
|
| 803 | + */ |
|
| 804 | + public static function create_database_tables() |
|
| 805 | + { |
|
| 806 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 807 | + //find the migration script that sets the database to be compatible with the code |
|
| 808 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 809 | + if ($dms_name) { |
|
| 810 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 811 | + $current_data_migration_script->set_migrating(false); |
|
| 812 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 813 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 814 | + if ($current_data_migration_script->get_errors()) { |
|
| 815 | + if (WP_DEBUG) { |
|
| 816 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 817 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 818 | + } |
|
| 819 | + } else { |
|
| 820 | + EE_Error::add_error( |
|
| 821 | + __( |
|
| 822 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 823 | 823 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 824 | - 'event_espresso' |
|
| 825 | - ) |
|
| 826 | - ); |
|
| 827 | - } |
|
| 828 | - return false; |
|
| 829 | - } |
|
| 830 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 831 | - } else { |
|
| 832 | - EE_Error::add_error( |
|
| 833 | - __( |
|
| 834 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 824 | + 'event_espresso' |
|
| 825 | + ) |
|
| 826 | + ); |
|
| 827 | + } |
|
| 828 | + return false; |
|
| 829 | + } |
|
| 830 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 831 | + } else { |
|
| 832 | + EE_Error::add_error( |
|
| 833 | + __( |
|
| 834 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 835 | 835 | structure. So database is probably not setup properly', |
| 836 | - 'event_espresso' |
|
| 837 | - ), |
|
| 838 | - __FILE__, |
|
| 839 | - __FUNCTION__, |
|
| 840 | - __LINE__ |
|
| 841 | - ); |
|
| 842 | - return false; |
|
| 843 | - } |
|
| 844 | - return true; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * initialize_system_questions |
|
| 851 | - * |
|
| 852 | - * @access public |
|
| 853 | - * @static |
|
| 854 | - * @return void |
|
| 855 | - */ |
|
| 856 | - public static function initialize_system_questions() |
|
| 857 | - { |
|
| 858 | - // QUESTION GROUPS |
|
| 859 | - global $wpdb; |
|
| 860 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 861 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 862 | - // what we have |
|
| 863 | - $question_groups = $wpdb->get_col($SQL); |
|
| 864 | - // check the response |
|
| 865 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 866 | - // what we should have |
|
| 867 | - $QSG_systems = array(1, 2); |
|
| 868 | - // loop thru what we should have and compare to what we have |
|
| 869 | - foreach ($QSG_systems as $QSG_system) { |
|
| 870 | - // reset values array |
|
| 871 | - $QSG_values = array(); |
|
| 872 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 873 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 874 | - // add it |
|
| 875 | - switch ($QSG_system) { |
|
| 876 | - case 1: |
|
| 877 | - $QSG_values = array( |
|
| 878 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 879 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 880 | - 'QSG_desc' => '', |
|
| 881 | - 'QSG_order' => 1, |
|
| 882 | - 'QSG_show_group_name' => 1, |
|
| 883 | - 'QSG_show_group_desc' => 1, |
|
| 884 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 885 | - 'QSG_deleted' => 0, |
|
| 886 | - ); |
|
| 887 | - break; |
|
| 888 | - case 2: |
|
| 889 | - $QSG_values = array( |
|
| 890 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 891 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 892 | - 'QSG_desc' => '', |
|
| 893 | - 'QSG_order' => 2, |
|
| 894 | - 'QSG_show_group_name' => 1, |
|
| 895 | - 'QSG_show_group_desc' => 1, |
|
| 896 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 897 | - 'QSG_deleted' => 0, |
|
| 898 | - ); |
|
| 899 | - break; |
|
| 900 | - } |
|
| 901 | - // make sure we have some values before inserting them |
|
| 902 | - if (! empty($QSG_values)) { |
|
| 903 | - // insert system question |
|
| 904 | - $wpdb->insert( |
|
| 905 | - $table_name, |
|
| 906 | - $QSG_values, |
|
| 907 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 908 | - ); |
|
| 909 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - // QUESTIONS |
|
| 914 | - global $wpdb; |
|
| 915 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 916 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 917 | - // what we have |
|
| 918 | - $questions = $wpdb->get_col($SQL); |
|
| 919 | - // what we should have |
|
| 920 | - $QST_systems = array( |
|
| 921 | - 'fname', |
|
| 922 | - 'lname', |
|
| 923 | - 'email', |
|
| 924 | - 'address', |
|
| 925 | - 'address2', |
|
| 926 | - 'city', |
|
| 927 | - 'country', |
|
| 928 | - 'state', |
|
| 929 | - 'zip', |
|
| 930 | - 'phone', |
|
| 931 | - ); |
|
| 932 | - $order_for_group_1 = 1; |
|
| 933 | - $order_for_group_2 = 1; |
|
| 934 | - // loop thru what we should have and compare to what we have |
|
| 935 | - foreach ($QST_systems as $QST_system) { |
|
| 936 | - // reset values array |
|
| 937 | - $QST_values = array(); |
|
| 938 | - // if we don't have what we should have |
|
| 939 | - if (! in_array($QST_system, $questions)) { |
|
| 940 | - // add it |
|
| 941 | - switch ($QST_system) { |
|
| 942 | - case 'fname': |
|
| 943 | - $QST_values = array( |
|
| 944 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 945 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 946 | - 'QST_system' => 'fname', |
|
| 947 | - 'QST_type' => 'TEXT', |
|
| 948 | - 'QST_required' => 1, |
|
| 949 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 950 | - 'QST_order' => 1, |
|
| 951 | - 'QST_admin_only' => 0, |
|
| 952 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 953 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 954 | - 'QST_deleted' => 0, |
|
| 955 | - ); |
|
| 956 | - break; |
|
| 957 | - case 'lname': |
|
| 958 | - $QST_values = array( |
|
| 959 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 960 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 961 | - 'QST_system' => 'lname', |
|
| 962 | - 'QST_type' => 'TEXT', |
|
| 963 | - 'QST_required' => 1, |
|
| 964 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 965 | - 'QST_order' => 2, |
|
| 966 | - 'QST_admin_only' => 0, |
|
| 967 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 968 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 969 | - 'QST_deleted' => 0, |
|
| 970 | - ); |
|
| 971 | - break; |
|
| 972 | - case 'email': |
|
| 973 | - $QST_values = array( |
|
| 974 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 975 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 976 | - 'QST_system' => 'email', |
|
| 977 | - 'QST_type' => 'EMAIL', |
|
| 978 | - 'QST_required' => 1, |
|
| 979 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 980 | - 'QST_order' => 3, |
|
| 981 | - 'QST_admin_only' => 0, |
|
| 982 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 983 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 984 | - 'QST_deleted' => 0, |
|
| 985 | - ); |
|
| 986 | - break; |
|
| 987 | - case 'address': |
|
| 988 | - $QST_values = array( |
|
| 989 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 990 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 991 | - 'QST_system' => 'address', |
|
| 992 | - 'QST_type' => 'TEXT', |
|
| 993 | - 'QST_required' => 0, |
|
| 994 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 995 | - 'QST_order' => 4, |
|
| 996 | - 'QST_admin_only' => 0, |
|
| 997 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 998 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 999 | - 'QST_deleted' => 0, |
|
| 1000 | - ); |
|
| 1001 | - break; |
|
| 1002 | - case 'address2': |
|
| 1003 | - $QST_values = array( |
|
| 1004 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1005 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1006 | - 'QST_system' => 'address2', |
|
| 1007 | - 'QST_type' => 'TEXT', |
|
| 1008 | - 'QST_required' => 0, |
|
| 1009 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1010 | - 'QST_order' => 5, |
|
| 1011 | - 'QST_admin_only' => 0, |
|
| 1012 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1013 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1014 | - 'QST_deleted' => 0, |
|
| 1015 | - ); |
|
| 1016 | - break; |
|
| 1017 | - case 'city': |
|
| 1018 | - $QST_values = array( |
|
| 1019 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1020 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1021 | - 'QST_system' => 'city', |
|
| 1022 | - 'QST_type' => 'TEXT', |
|
| 1023 | - 'QST_required' => 0, |
|
| 1024 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1025 | - 'QST_order' => 6, |
|
| 1026 | - 'QST_admin_only' => 0, |
|
| 1027 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1028 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1029 | - 'QST_deleted' => 0, |
|
| 1030 | - ); |
|
| 1031 | - break; |
|
| 1032 | - case 'country': |
|
| 1033 | - $QST_values = array( |
|
| 1034 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1035 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1036 | - 'QST_system' => 'country', |
|
| 1037 | - 'QST_type' => 'COUNTRY', |
|
| 1038 | - 'QST_required' => 0, |
|
| 1039 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1040 | - 'QST_order' => 7, |
|
| 1041 | - 'QST_admin_only' => 0, |
|
| 1042 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1043 | - 'QST_deleted' => 0, |
|
| 1044 | - ); |
|
| 1045 | - break; |
|
| 1046 | - case 'state': |
|
| 1047 | - $QST_values = array( |
|
| 1048 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1049 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1050 | - 'QST_system' => 'state', |
|
| 1051 | - 'QST_type' => 'STATE', |
|
| 1052 | - 'QST_required' => 0, |
|
| 1053 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1054 | - 'QST_order' => 8, |
|
| 1055 | - 'QST_admin_only' => 0, |
|
| 1056 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1057 | - 'QST_deleted' => 0, |
|
| 1058 | - ); |
|
| 1059 | - break; |
|
| 1060 | - case 'zip': |
|
| 1061 | - $QST_values = array( |
|
| 1062 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1063 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1064 | - 'QST_system' => 'zip', |
|
| 1065 | - 'QST_type' => 'TEXT', |
|
| 1066 | - 'QST_required' => 0, |
|
| 1067 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1068 | - 'QST_order' => 9, |
|
| 1069 | - 'QST_admin_only' => 0, |
|
| 1070 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1071 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1072 | - 'QST_deleted' => 0, |
|
| 1073 | - ); |
|
| 1074 | - break; |
|
| 1075 | - case 'phone': |
|
| 1076 | - $QST_values = array( |
|
| 1077 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1078 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1079 | - 'QST_system' => 'phone', |
|
| 1080 | - 'QST_type' => 'TEXT', |
|
| 1081 | - 'QST_required' => 0, |
|
| 1082 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1083 | - 'QST_order' => 10, |
|
| 1084 | - 'QST_admin_only' => 0, |
|
| 1085 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1086 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1087 | - 'QST_deleted' => 0, |
|
| 1088 | - ); |
|
| 1089 | - break; |
|
| 1090 | - } |
|
| 1091 | - if (! empty($QST_values)) { |
|
| 1092 | - // insert system question |
|
| 1093 | - $wpdb->insert( |
|
| 1094 | - $table_name, |
|
| 1095 | - $QST_values, |
|
| 1096 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1097 | - ); |
|
| 1098 | - $QST_ID = $wpdb->insert_id; |
|
| 1099 | - // QUESTION GROUP QUESTIONS |
|
| 1100 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1101 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1102 | - } else { |
|
| 1103 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1104 | - } |
|
| 1105 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1106 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1107 | - } else { |
|
| 1108 | - $id_col = EEM_Question_Group::instance() |
|
| 1109 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1110 | - if (is_array($id_col)) { |
|
| 1111 | - $QSG_ID = reset($id_col); |
|
| 1112 | - } else { |
|
| 1113 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1114 | - EE_Log::instance()->log( |
|
| 1115 | - __FILE__, |
|
| 1116 | - __FUNCTION__, |
|
| 1117 | - sprintf( |
|
| 1118 | - __( |
|
| 1119 | - 'Could not associate question %1$s to a question group because no system question |
|
| 836 | + 'event_espresso' |
|
| 837 | + ), |
|
| 838 | + __FILE__, |
|
| 839 | + __FUNCTION__, |
|
| 840 | + __LINE__ |
|
| 841 | + ); |
|
| 842 | + return false; |
|
| 843 | + } |
|
| 844 | + return true; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * initialize_system_questions |
|
| 851 | + * |
|
| 852 | + * @access public |
|
| 853 | + * @static |
|
| 854 | + * @return void |
|
| 855 | + */ |
|
| 856 | + public static function initialize_system_questions() |
|
| 857 | + { |
|
| 858 | + // QUESTION GROUPS |
|
| 859 | + global $wpdb; |
|
| 860 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 861 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 862 | + // what we have |
|
| 863 | + $question_groups = $wpdb->get_col($SQL); |
|
| 864 | + // check the response |
|
| 865 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 866 | + // what we should have |
|
| 867 | + $QSG_systems = array(1, 2); |
|
| 868 | + // loop thru what we should have and compare to what we have |
|
| 869 | + foreach ($QSG_systems as $QSG_system) { |
|
| 870 | + // reset values array |
|
| 871 | + $QSG_values = array(); |
|
| 872 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 873 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 874 | + // add it |
|
| 875 | + switch ($QSG_system) { |
|
| 876 | + case 1: |
|
| 877 | + $QSG_values = array( |
|
| 878 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 879 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 880 | + 'QSG_desc' => '', |
|
| 881 | + 'QSG_order' => 1, |
|
| 882 | + 'QSG_show_group_name' => 1, |
|
| 883 | + 'QSG_show_group_desc' => 1, |
|
| 884 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 885 | + 'QSG_deleted' => 0, |
|
| 886 | + ); |
|
| 887 | + break; |
|
| 888 | + case 2: |
|
| 889 | + $QSG_values = array( |
|
| 890 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 891 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 892 | + 'QSG_desc' => '', |
|
| 893 | + 'QSG_order' => 2, |
|
| 894 | + 'QSG_show_group_name' => 1, |
|
| 895 | + 'QSG_show_group_desc' => 1, |
|
| 896 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 897 | + 'QSG_deleted' => 0, |
|
| 898 | + ); |
|
| 899 | + break; |
|
| 900 | + } |
|
| 901 | + // make sure we have some values before inserting them |
|
| 902 | + if (! empty($QSG_values)) { |
|
| 903 | + // insert system question |
|
| 904 | + $wpdb->insert( |
|
| 905 | + $table_name, |
|
| 906 | + $QSG_values, |
|
| 907 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 908 | + ); |
|
| 909 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + // QUESTIONS |
|
| 914 | + global $wpdb; |
|
| 915 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 916 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 917 | + // what we have |
|
| 918 | + $questions = $wpdb->get_col($SQL); |
|
| 919 | + // what we should have |
|
| 920 | + $QST_systems = array( |
|
| 921 | + 'fname', |
|
| 922 | + 'lname', |
|
| 923 | + 'email', |
|
| 924 | + 'address', |
|
| 925 | + 'address2', |
|
| 926 | + 'city', |
|
| 927 | + 'country', |
|
| 928 | + 'state', |
|
| 929 | + 'zip', |
|
| 930 | + 'phone', |
|
| 931 | + ); |
|
| 932 | + $order_for_group_1 = 1; |
|
| 933 | + $order_for_group_2 = 1; |
|
| 934 | + // loop thru what we should have and compare to what we have |
|
| 935 | + foreach ($QST_systems as $QST_system) { |
|
| 936 | + // reset values array |
|
| 937 | + $QST_values = array(); |
|
| 938 | + // if we don't have what we should have |
|
| 939 | + if (! in_array($QST_system, $questions)) { |
|
| 940 | + // add it |
|
| 941 | + switch ($QST_system) { |
|
| 942 | + case 'fname': |
|
| 943 | + $QST_values = array( |
|
| 944 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 945 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 946 | + 'QST_system' => 'fname', |
|
| 947 | + 'QST_type' => 'TEXT', |
|
| 948 | + 'QST_required' => 1, |
|
| 949 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 950 | + 'QST_order' => 1, |
|
| 951 | + 'QST_admin_only' => 0, |
|
| 952 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 953 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 954 | + 'QST_deleted' => 0, |
|
| 955 | + ); |
|
| 956 | + break; |
|
| 957 | + case 'lname': |
|
| 958 | + $QST_values = array( |
|
| 959 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 960 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 961 | + 'QST_system' => 'lname', |
|
| 962 | + 'QST_type' => 'TEXT', |
|
| 963 | + 'QST_required' => 1, |
|
| 964 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 965 | + 'QST_order' => 2, |
|
| 966 | + 'QST_admin_only' => 0, |
|
| 967 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 968 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 969 | + 'QST_deleted' => 0, |
|
| 970 | + ); |
|
| 971 | + break; |
|
| 972 | + case 'email': |
|
| 973 | + $QST_values = array( |
|
| 974 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 975 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 976 | + 'QST_system' => 'email', |
|
| 977 | + 'QST_type' => 'EMAIL', |
|
| 978 | + 'QST_required' => 1, |
|
| 979 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 980 | + 'QST_order' => 3, |
|
| 981 | + 'QST_admin_only' => 0, |
|
| 982 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 983 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 984 | + 'QST_deleted' => 0, |
|
| 985 | + ); |
|
| 986 | + break; |
|
| 987 | + case 'address': |
|
| 988 | + $QST_values = array( |
|
| 989 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 990 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 991 | + 'QST_system' => 'address', |
|
| 992 | + 'QST_type' => 'TEXT', |
|
| 993 | + 'QST_required' => 0, |
|
| 994 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 995 | + 'QST_order' => 4, |
|
| 996 | + 'QST_admin_only' => 0, |
|
| 997 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 998 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 999 | + 'QST_deleted' => 0, |
|
| 1000 | + ); |
|
| 1001 | + break; |
|
| 1002 | + case 'address2': |
|
| 1003 | + $QST_values = array( |
|
| 1004 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1005 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1006 | + 'QST_system' => 'address2', |
|
| 1007 | + 'QST_type' => 'TEXT', |
|
| 1008 | + 'QST_required' => 0, |
|
| 1009 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1010 | + 'QST_order' => 5, |
|
| 1011 | + 'QST_admin_only' => 0, |
|
| 1012 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1013 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1014 | + 'QST_deleted' => 0, |
|
| 1015 | + ); |
|
| 1016 | + break; |
|
| 1017 | + case 'city': |
|
| 1018 | + $QST_values = array( |
|
| 1019 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1020 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1021 | + 'QST_system' => 'city', |
|
| 1022 | + 'QST_type' => 'TEXT', |
|
| 1023 | + 'QST_required' => 0, |
|
| 1024 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1025 | + 'QST_order' => 6, |
|
| 1026 | + 'QST_admin_only' => 0, |
|
| 1027 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1028 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1029 | + 'QST_deleted' => 0, |
|
| 1030 | + ); |
|
| 1031 | + break; |
|
| 1032 | + case 'country': |
|
| 1033 | + $QST_values = array( |
|
| 1034 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1035 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1036 | + 'QST_system' => 'country', |
|
| 1037 | + 'QST_type' => 'COUNTRY', |
|
| 1038 | + 'QST_required' => 0, |
|
| 1039 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1040 | + 'QST_order' => 7, |
|
| 1041 | + 'QST_admin_only' => 0, |
|
| 1042 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1043 | + 'QST_deleted' => 0, |
|
| 1044 | + ); |
|
| 1045 | + break; |
|
| 1046 | + case 'state': |
|
| 1047 | + $QST_values = array( |
|
| 1048 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1049 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1050 | + 'QST_system' => 'state', |
|
| 1051 | + 'QST_type' => 'STATE', |
|
| 1052 | + 'QST_required' => 0, |
|
| 1053 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1054 | + 'QST_order' => 8, |
|
| 1055 | + 'QST_admin_only' => 0, |
|
| 1056 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1057 | + 'QST_deleted' => 0, |
|
| 1058 | + ); |
|
| 1059 | + break; |
|
| 1060 | + case 'zip': |
|
| 1061 | + $QST_values = array( |
|
| 1062 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1063 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1064 | + 'QST_system' => 'zip', |
|
| 1065 | + 'QST_type' => 'TEXT', |
|
| 1066 | + 'QST_required' => 0, |
|
| 1067 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1068 | + 'QST_order' => 9, |
|
| 1069 | + 'QST_admin_only' => 0, |
|
| 1070 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1071 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1072 | + 'QST_deleted' => 0, |
|
| 1073 | + ); |
|
| 1074 | + break; |
|
| 1075 | + case 'phone': |
|
| 1076 | + $QST_values = array( |
|
| 1077 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1078 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1079 | + 'QST_system' => 'phone', |
|
| 1080 | + 'QST_type' => 'TEXT', |
|
| 1081 | + 'QST_required' => 0, |
|
| 1082 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1083 | + 'QST_order' => 10, |
|
| 1084 | + 'QST_admin_only' => 0, |
|
| 1085 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1086 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1087 | + 'QST_deleted' => 0, |
|
| 1088 | + ); |
|
| 1089 | + break; |
|
| 1090 | + } |
|
| 1091 | + if (! empty($QST_values)) { |
|
| 1092 | + // insert system question |
|
| 1093 | + $wpdb->insert( |
|
| 1094 | + $table_name, |
|
| 1095 | + $QST_values, |
|
| 1096 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1097 | + ); |
|
| 1098 | + $QST_ID = $wpdb->insert_id; |
|
| 1099 | + // QUESTION GROUP QUESTIONS |
|
| 1100 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1101 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1102 | + } else { |
|
| 1103 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1104 | + } |
|
| 1105 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1106 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1107 | + } else { |
|
| 1108 | + $id_col = EEM_Question_Group::instance() |
|
| 1109 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1110 | + if (is_array($id_col)) { |
|
| 1111 | + $QSG_ID = reset($id_col); |
|
| 1112 | + } else { |
|
| 1113 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1114 | + EE_Log::instance()->log( |
|
| 1115 | + __FILE__, |
|
| 1116 | + __FUNCTION__, |
|
| 1117 | + sprintf( |
|
| 1118 | + __( |
|
| 1119 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1120 | 1120 | group existed', |
| 1121 | - 'event_espresso' |
|
| 1122 | - ), |
|
| 1123 | - $QST_ID), |
|
| 1124 | - 'error'); |
|
| 1125 | - continue; |
|
| 1126 | - } |
|
| 1127 | - } |
|
| 1128 | - // add system questions to groups |
|
| 1129 | - $wpdb->insert( |
|
| 1130 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1131 | - array( |
|
| 1132 | - 'QSG_ID' => $QSG_ID, |
|
| 1133 | - 'QST_ID' => $QST_ID, |
|
| 1134 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1135 | - ), |
|
| 1136 | - array('%d', '%d', '%d') |
|
| 1137 | - ); |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1146 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1147 | - * |
|
| 1148 | - * @throws \EE_Error |
|
| 1149 | - */ |
|
| 1150 | - public static function insert_default_payment_methods() |
|
| 1151 | - { |
|
| 1152 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1153 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1154 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1155 | - } else { |
|
| 1156 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - /** |
|
| 1161 | - * insert_default_status_codes |
|
| 1162 | - * |
|
| 1163 | - * @access public |
|
| 1164 | - * @static |
|
| 1165 | - * @return void |
|
| 1166 | - */ |
|
| 1167 | - public static function insert_default_status_codes() |
|
| 1168 | - { |
|
| 1169 | - |
|
| 1170 | - global $wpdb; |
|
| 1171 | - |
|
| 1172 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1173 | - |
|
| 1174 | - $table_name = EEM_Status::instance()->table(); |
|
| 1175 | - |
|
| 1176 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1177 | - $wpdb->query($SQL); |
|
| 1178 | - |
|
| 1179 | - $SQL = "INSERT INTO $table_name |
|
| 1121 | + 'event_espresso' |
|
| 1122 | + ), |
|
| 1123 | + $QST_ID), |
|
| 1124 | + 'error'); |
|
| 1125 | + continue; |
|
| 1126 | + } |
|
| 1127 | + } |
|
| 1128 | + // add system questions to groups |
|
| 1129 | + $wpdb->insert( |
|
| 1130 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1131 | + array( |
|
| 1132 | + 'QSG_ID' => $QSG_ID, |
|
| 1133 | + 'QST_ID' => $QST_ID, |
|
| 1134 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1135 | + ), |
|
| 1136 | + array('%d', '%d', '%d') |
|
| 1137 | + ); |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1146 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1147 | + * |
|
| 1148 | + * @throws \EE_Error |
|
| 1149 | + */ |
|
| 1150 | + public static function insert_default_payment_methods() |
|
| 1151 | + { |
|
| 1152 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1153 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1154 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1155 | + } else { |
|
| 1156 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + /** |
|
| 1161 | + * insert_default_status_codes |
|
| 1162 | + * |
|
| 1163 | + * @access public |
|
| 1164 | + * @static |
|
| 1165 | + * @return void |
|
| 1166 | + */ |
|
| 1167 | + public static function insert_default_status_codes() |
|
| 1168 | + { |
|
| 1169 | + |
|
| 1170 | + global $wpdb; |
|
| 1171 | + |
|
| 1172 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1173 | + |
|
| 1174 | + $table_name = EEM_Status::instance()->table(); |
|
| 1175 | + |
|
| 1176 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1177 | + $wpdb->query($SQL); |
|
| 1178 | + |
|
| 1179 | + $SQL = "INSERT INTO $table_name |
|
| 1180 | 1180 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1181 | 1181 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1182 | 1182 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1216,521 +1216,521 @@ discard block |
||
| 1216 | 1216 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1217 | 1217 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1218 | 1218 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1219 | - $wpdb->query($SQL); |
|
| 1220 | - |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - |
|
| 1226 | - /** |
|
| 1227 | - * create_upload_directories |
|
| 1228 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1229 | - * |
|
| 1230 | - * @access public |
|
| 1231 | - * @static |
|
| 1232 | - * @return boolean success of verifying upload directories exist |
|
| 1233 | - */ |
|
| 1234 | - public static function create_upload_directories() |
|
| 1235 | - { |
|
| 1236 | - // Create the required folders |
|
| 1237 | - $folders = array( |
|
| 1238 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1239 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1242 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1243 | - ); |
|
| 1244 | - foreach ($folders as $folder) { |
|
| 1245 | - try { |
|
| 1246 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1247 | - @ chmod($folder, 0755); |
|
| 1248 | - } catch (EE_Error $e) { |
|
| 1249 | - EE_Error::add_error( |
|
| 1250 | - sprintf( |
|
| 1251 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1252 | - $folder, |
|
| 1253 | - '<br />' . $e->getMessage() |
|
| 1254 | - ), |
|
| 1255 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1256 | - ); |
|
| 1257 | - //indicate we'll need to fix this later |
|
| 1258 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1259 | - return false; |
|
| 1260 | - } |
|
| 1261 | - } |
|
| 1262 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1263 | - //is disabled, there might be activation errors recorded in there |
|
| 1264 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1265 | - //remember EE's folders are all good |
|
| 1266 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1267 | - return true; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * Whether the upload directories need to be fixed or not. |
|
| 1272 | - * If EE is installed but filesystem access isn't initially available, |
|
| 1273 | - * we need to get the user's filesystem credentials and THEN create them, |
|
| 1274 | - * so there might be period of time when EE is installed but its |
|
| 1275 | - * upload directories aren't available. This indicates such a state |
|
| 1276 | - * |
|
| 1277 | - * @return boolean |
|
| 1278 | - */ |
|
| 1279 | - public static function upload_directories_incomplete() |
|
| 1280 | - { |
|
| 1281 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * generate_default_message_templates |
|
| 1287 | - * |
|
| 1288 | - * @static |
|
| 1289 | - * @throws EE_Error |
|
| 1290 | - * @return bool true means new templates were created. |
|
| 1291 | - * false means no templates were created. |
|
| 1292 | - * This is NOT an error flag. To check for errors you will want |
|
| 1293 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1294 | - */ |
|
| 1295 | - public static function generate_default_message_templates() |
|
| 1296 | - { |
|
| 1297 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1298 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1299 | - /* |
|
| 1219 | + $wpdb->query($SQL); |
|
| 1220 | + |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + |
|
| 1226 | + /** |
|
| 1227 | + * create_upload_directories |
|
| 1228 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1229 | + * |
|
| 1230 | + * @access public |
|
| 1231 | + * @static |
|
| 1232 | + * @return boolean success of verifying upload directories exist |
|
| 1233 | + */ |
|
| 1234 | + public static function create_upload_directories() |
|
| 1235 | + { |
|
| 1236 | + // Create the required folders |
|
| 1237 | + $folders = array( |
|
| 1238 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1239 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1240 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1241 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1242 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1243 | + ); |
|
| 1244 | + foreach ($folders as $folder) { |
|
| 1245 | + try { |
|
| 1246 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1247 | + @ chmod($folder, 0755); |
|
| 1248 | + } catch (EE_Error $e) { |
|
| 1249 | + EE_Error::add_error( |
|
| 1250 | + sprintf( |
|
| 1251 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1252 | + $folder, |
|
| 1253 | + '<br />' . $e->getMessage() |
|
| 1254 | + ), |
|
| 1255 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1256 | + ); |
|
| 1257 | + //indicate we'll need to fix this later |
|
| 1258 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1259 | + return false; |
|
| 1260 | + } |
|
| 1261 | + } |
|
| 1262 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1263 | + //is disabled, there might be activation errors recorded in there |
|
| 1264 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1265 | + //remember EE's folders are all good |
|
| 1266 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1267 | + return true; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * Whether the upload directories need to be fixed or not. |
|
| 1272 | + * If EE is installed but filesystem access isn't initially available, |
|
| 1273 | + * we need to get the user's filesystem credentials and THEN create them, |
|
| 1274 | + * so there might be period of time when EE is installed but its |
|
| 1275 | + * upload directories aren't available. This indicates such a state |
|
| 1276 | + * |
|
| 1277 | + * @return boolean |
|
| 1278 | + */ |
|
| 1279 | + public static function upload_directories_incomplete() |
|
| 1280 | + { |
|
| 1281 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * generate_default_message_templates |
|
| 1287 | + * |
|
| 1288 | + * @static |
|
| 1289 | + * @throws EE_Error |
|
| 1290 | + * @return bool true means new templates were created. |
|
| 1291 | + * false means no templates were created. |
|
| 1292 | + * This is NOT an error flag. To check for errors you will want |
|
| 1293 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1294 | + */ |
|
| 1295 | + public static function generate_default_message_templates() |
|
| 1296 | + { |
|
| 1297 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1298 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1299 | + /* |
|
| 1300 | 1300 | * This first method is taking care of ensuring any default messengers |
| 1301 | 1301 | * that should be made active and have templates generated are done. |
| 1302 | 1302 | */ |
| 1303 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1304 | - $message_resource_manager |
|
| 1305 | - ); |
|
| 1306 | - /** |
|
| 1307 | - * This method is verifying there are no NEW default message types |
|
| 1308 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1309 | - */ |
|
| 1310 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1311 | - $message_resource_manager |
|
| 1312 | - ); |
|
| 1313 | - //after all is done, let's persist these changes to the db. |
|
| 1314 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1315 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1316 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1317 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1324 | - * @return array|bool |
|
| 1325 | - * @throws \EE_Error |
|
| 1326 | - */ |
|
| 1327 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1328 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1329 | - ) { |
|
| 1330 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1331 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1332 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1333 | - $templates_created = false; |
|
| 1334 | - foreach ($active_messengers as $active_messenger) { |
|
| 1335 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1336 | - $default_message_type_names_to_activate = array(); |
|
| 1337 | - // looping through each default message type reported by the messenger |
|
| 1338 | - // and setup the actual message types to activate. |
|
| 1339 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1340 | - // if already active or has already been activated before we skip |
|
| 1341 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1342 | - // we also skip if the message type is not installed. |
|
| 1343 | - if ( |
|
| 1344 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1345 | - $default_message_type_name_for_messenger, |
|
| 1346 | - $active_messenger->name |
|
| 1347 | - ) |
|
| 1348 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1349 | - $active_messenger->name, |
|
| 1350 | - $default_message_type_name_for_messenger |
|
| 1351 | - ) |
|
| 1352 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1353 | - ) { |
|
| 1354 | - continue; |
|
| 1355 | - } |
|
| 1356 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1357 | - } |
|
| 1358 | - //let's activate! |
|
| 1359 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1360 | - $default_message_type_names_to_activate, |
|
| 1361 | - $active_messenger->name, |
|
| 1362 | - false |
|
| 1363 | - ); |
|
| 1364 | - //activate the templates for these message types |
|
| 1365 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1366 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1367 | - $active_messenger->name, |
|
| 1368 | - $default_message_type_names_for_messenger, |
|
| 1369 | - '', |
|
| 1370 | - true |
|
| 1371 | - ); |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - return $templates_created; |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1381 | - * |
|
| 1382 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1383 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1384 | - * False means that there were no templates generated |
|
| 1385 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1386 | - * @throws EE_Error |
|
| 1387 | - */ |
|
| 1388 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1389 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1390 | - ) { |
|
| 1391 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1392 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1393 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1394 | - $templates_generated = false; |
|
| 1395 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1396 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1397 | - //verify the default message types match an installed message type. |
|
| 1398 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1399 | - if ( |
|
| 1400 | - ! isset($installed_message_types[$name]) |
|
| 1401 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1402 | - $name, |
|
| 1403 | - $messenger_to_generate->name |
|
| 1404 | - ) |
|
| 1405 | - ) { |
|
| 1406 | - unset($default_message_type_names_for_messenger[$key]); |
|
| 1407 | - } |
|
| 1408 | - } |
|
| 1409 | - // in previous iterations, the active_messengers option in the db |
|
| 1410 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1411 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1412 | - // passing off to create templates (after the refactor is done). |
|
| 1413 | - // @todo remove this comment when determined not necessary. |
|
| 1414 | - $message_resource_manager->activate_messenger( |
|
| 1415 | - $messenger_to_generate->name, |
|
| 1416 | - $default_message_type_names_for_messenger, |
|
| 1417 | - false |
|
| 1418 | - ); |
|
| 1419 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1420 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1421 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1422 | - $messenger_to_generate->name, |
|
| 1423 | - $default_message_type_names_for_messenger, |
|
| 1424 | - '', |
|
| 1425 | - true |
|
| 1426 | - ); |
|
| 1427 | - } |
|
| 1428 | - } |
|
| 1429 | - return $templates_generated; |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - |
|
| 1433 | - /** |
|
| 1434 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1435 | - * It considers: |
|
| 1436 | - * - whether a messenger is already active in the db. |
|
| 1437 | - * - whether a messenger has been made active at any time in the past. |
|
| 1438 | - * |
|
| 1439 | - * @static |
|
| 1440 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1441 | - * @return EE_messenger[] |
|
| 1442 | - */ |
|
| 1443 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1444 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1445 | - ) { |
|
| 1446 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1447 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1448 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1449 | - |
|
| 1450 | - $messengers_to_generate = array(); |
|
| 1451 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1452 | - //if installed messenger is a messenger that should be activated on install |
|
| 1453 | - //and is not already active |
|
| 1454 | - //and has never been activated |
|
| 1455 | - if ( |
|
| 1456 | - ! $installed_messenger->activate_on_install |
|
| 1457 | - || isset($active_messengers[$installed_messenger->name]) |
|
| 1458 | - || isset($has_activated[$installed_messenger->name]) |
|
| 1459 | - ) { |
|
| 1460 | - continue; |
|
| 1461 | - } |
|
| 1462 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1463 | - } |
|
| 1464 | - return $messengers_to_generate; |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - |
|
| 1468 | - /** |
|
| 1469 | - * This simply validates active message types to ensure they actually match installed |
|
| 1470 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1471 | - * rows are set inactive. |
|
| 1472 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1473 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1474 | - * are still handled in here. |
|
| 1475 | - * |
|
| 1476 | - * @since 4.3.1 |
|
| 1477 | - * @return void |
|
| 1478 | - */ |
|
| 1479 | - public static function validate_messages_system() |
|
| 1480 | - { |
|
| 1481 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1482 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1483 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1484 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - |
|
| 1488 | - /** |
|
| 1489 | - * create_no_ticket_prices_array |
|
| 1490 | - * |
|
| 1491 | - * @access public |
|
| 1492 | - * @static |
|
| 1493 | - * @return void |
|
| 1494 | - */ |
|
| 1495 | - public static function create_no_ticket_prices_array() |
|
| 1496 | - { |
|
| 1497 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1498 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1499 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1500 | - if (! $espresso_no_ticket_prices) { |
|
| 1501 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1502 | - } |
|
| 1503 | - } |
|
| 1504 | - |
|
| 1505 | - |
|
| 1506 | - /** |
|
| 1507 | - * plugin_deactivation |
|
| 1508 | - * |
|
| 1509 | - * @access public |
|
| 1510 | - * @static |
|
| 1511 | - * @return void |
|
| 1512 | - */ |
|
| 1513 | - public static function plugin_deactivation() |
|
| 1514 | - { |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - |
|
| 1518 | - /** |
|
| 1519 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1520 | - * (like post meta or term relations) |
|
| 1521 | - * |
|
| 1522 | - * @global wpdb $wpdb |
|
| 1523 | - * @throws \EE_Error |
|
| 1524 | - */ |
|
| 1525 | - public static function delete_all_espresso_cpt_data() |
|
| 1526 | - { |
|
| 1527 | - global $wpdb; |
|
| 1528 | - //get all the CPT post_types |
|
| 1529 | - $ee_post_types = array(); |
|
| 1530 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1531 | - if (method_exists($model_name, 'instance')) { |
|
| 1532 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1533 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1534 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1535 | - } |
|
| 1536 | - } |
|
| 1537 | - } |
|
| 1538 | - //get all our CPTs |
|
| 1539 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1540 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1541 | - //delete each post meta and term relations too |
|
| 1542 | - foreach ($cpt_ids as $post_id) { |
|
| 1543 | - wp_delete_post($post_id, true); |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - /** |
|
| 1548 | - * Deletes all EE custom tables |
|
| 1549 | - * |
|
| 1550 | - * @return array |
|
| 1551 | - */ |
|
| 1552 | - public static function drop_espresso_tables() |
|
| 1553 | - { |
|
| 1554 | - $tables = array(); |
|
| 1555 | - // load registry |
|
| 1556 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1557 | - if (method_exists($model_name, 'instance')) { |
|
| 1558 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1559 | - if ($model_obj instanceof EEM_Base) { |
|
| 1560 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1561 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1562 | - && |
|
| 1563 | - ( |
|
| 1564 | - is_main_site()//main site? nuke them all |
|
| 1565 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1566 | - ) |
|
| 1567 | - ) { |
|
| 1568 | - $tables[] = $table->get_table_name(); |
|
| 1569 | - } |
|
| 1570 | - } |
|
| 1571 | - } |
|
| 1572 | - } |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - //there are some tables whose models were removed. |
|
| 1576 | - //they should be removed when removing all EE core's data |
|
| 1577 | - $tables_without_models = array( |
|
| 1578 | - 'esp_promotion', |
|
| 1579 | - 'esp_promotion_applied', |
|
| 1580 | - 'esp_promotion_object', |
|
| 1581 | - 'esp_promotion_rule', |
|
| 1582 | - 'esp_rule', |
|
| 1583 | - ); |
|
| 1584 | - foreach ($tables_without_models as $table) { |
|
| 1585 | - $tables[] = $table; |
|
| 1586 | - } |
|
| 1587 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1594 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1595 | - * Returns the list actually deleted |
|
| 1596 | - * |
|
| 1597 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1598 | - * @global WPDB $wpdb |
|
| 1599 | - * @param array $table_names |
|
| 1600 | - * @return array of table names which we deleted |
|
| 1601 | - */ |
|
| 1602 | - public static function drop_tables($table_names) |
|
| 1603 | - { |
|
| 1604 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * plugin_uninstall |
|
| 1611 | - * |
|
| 1612 | - * @access public |
|
| 1613 | - * @static |
|
| 1614 | - * @param bool $remove_all |
|
| 1615 | - * @return void |
|
| 1616 | - */ |
|
| 1617 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1618 | - { |
|
| 1619 | - global $wpdb; |
|
| 1620 | - self::drop_espresso_tables(); |
|
| 1621 | - $wp_options_to_delete = array( |
|
| 1622 | - 'ee_no_ticket_prices' => true, |
|
| 1623 | - 'ee_active_messengers' => true, |
|
| 1624 | - 'ee_has_activated_messenger' => true, |
|
| 1625 | - 'ee_flush_rewrite_rules' => true, |
|
| 1626 | - 'ee_config' => false, |
|
| 1627 | - 'ee_data_migration_current_db_state' => true, |
|
| 1628 | - 'ee_data_migration_mapping_' => false, |
|
| 1629 | - 'ee_data_migration_script_' => false, |
|
| 1630 | - 'ee_data_migrations' => true, |
|
| 1631 | - 'ee_dms_map' => false, |
|
| 1632 | - 'ee_notices' => true, |
|
| 1633 | - 'lang_file_check_' => false, |
|
| 1634 | - 'ee_maintenance_mode' => true, |
|
| 1635 | - 'ee_ueip_optin' => true, |
|
| 1636 | - 'ee_ueip_has_notified' => true, |
|
| 1637 | - 'ee_plugin_activation_errors' => true, |
|
| 1638 | - 'ee_id_mapping_from' => false, |
|
| 1639 | - 'espresso_persistent_admin_notices' => true, |
|
| 1640 | - 'ee_encryption_key' => true, |
|
| 1641 | - 'pue_force_upgrade_' => false, |
|
| 1642 | - 'pue_json_error_' => false, |
|
| 1643 | - 'pue_install_key_' => false, |
|
| 1644 | - 'pue_verification_error_' => false, |
|
| 1645 | - 'pu_dismissed_upgrade_' => false, |
|
| 1646 | - 'external_updates-' => false, |
|
| 1647 | - 'ee_extra_data' => true, |
|
| 1648 | - 'ee_ssn_' => false, |
|
| 1649 | - 'ee_rss_' => false, |
|
| 1650 | - 'ee_rte_n_tx_' => false, |
|
| 1651 | - 'ee_pers_admin_notices' => true, |
|
| 1652 | - 'ee_job_parameters_' => false, |
|
| 1653 | - 'ee_upload_directories_incomplete' => true, |
|
| 1654 | - 'ee_verified_db_collations' => true, |
|
| 1655 | - ); |
|
| 1656 | - if (is_main_site()) { |
|
| 1657 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1658 | - } |
|
| 1659 | - $undeleted_options = array(); |
|
| 1660 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1661 | - if ($no_wildcard) { |
|
| 1662 | - if ( ! delete_option($option_name)) { |
|
| 1663 | - $undeleted_options[] = $option_name; |
|
| 1664 | - } |
|
| 1665 | - } else { |
|
| 1666 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1667 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1668 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1669 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1670 | - } |
|
| 1671 | - } |
|
| 1672 | - } |
|
| 1673 | - } |
|
| 1674 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1675 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1676 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1677 | - $db_update_sans_ee4 = array(); |
|
| 1678 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1679 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1680 | - $db_update_sans_ee4[$version] = $times_activated; |
|
| 1681 | - } |
|
| 1682 | - } |
|
| 1683 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1684 | - } |
|
| 1685 | - $errors = ''; |
|
| 1686 | - if ( ! empty($undeleted_options)) { |
|
| 1687 | - $errors .= sprintf( |
|
| 1688 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1689 | - '<br/>', |
|
| 1690 | - implode(',<br/>', $undeleted_options) |
|
| 1691 | - ); |
|
| 1692 | - } |
|
| 1693 | - if ( ! empty($errors)) { |
|
| 1694 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1695 | - } |
|
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - /** |
|
| 1699 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1700 | - * |
|
| 1701 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1702 | - */ |
|
| 1703 | - public static function last_wpdb_error_code() |
|
| 1704 | - { |
|
| 1705 | - global $wpdb; |
|
| 1706 | - if ($wpdb->use_mysqli) { |
|
| 1707 | - return mysqli_errno($wpdb->dbh); |
|
| 1708 | - } else { |
|
| 1709 | - return mysql_errno($wpdb->dbh); |
|
| 1710 | - } |
|
| 1711 | - } |
|
| 1712 | - |
|
| 1713 | - /** |
|
| 1714 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1715 | - * |
|
| 1716 | - * @global wpdb $wpdb |
|
| 1717 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1718 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1719 | - * @return boolean |
|
| 1720 | - */ |
|
| 1721 | - public static function table_exists($table_name) |
|
| 1722 | - { |
|
| 1723 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * Resets the cache on EEH_Activation |
|
| 1728 | - */ |
|
| 1729 | - public static function reset() |
|
| 1730 | - { |
|
| 1731 | - self::$_default_creator_id = null; |
|
| 1732 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1733 | - } |
|
| 1303 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1304 | + $message_resource_manager |
|
| 1305 | + ); |
|
| 1306 | + /** |
|
| 1307 | + * This method is verifying there are no NEW default message types |
|
| 1308 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1309 | + */ |
|
| 1310 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1311 | + $message_resource_manager |
|
| 1312 | + ); |
|
| 1313 | + //after all is done, let's persist these changes to the db. |
|
| 1314 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1315 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1316 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1317 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1324 | + * @return array|bool |
|
| 1325 | + * @throws \EE_Error |
|
| 1326 | + */ |
|
| 1327 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1328 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1329 | + ) { |
|
| 1330 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1331 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1332 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1333 | + $templates_created = false; |
|
| 1334 | + foreach ($active_messengers as $active_messenger) { |
|
| 1335 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1336 | + $default_message_type_names_to_activate = array(); |
|
| 1337 | + // looping through each default message type reported by the messenger |
|
| 1338 | + // and setup the actual message types to activate. |
|
| 1339 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1340 | + // if already active or has already been activated before we skip |
|
| 1341 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1342 | + // we also skip if the message type is not installed. |
|
| 1343 | + if ( |
|
| 1344 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1345 | + $default_message_type_name_for_messenger, |
|
| 1346 | + $active_messenger->name |
|
| 1347 | + ) |
|
| 1348 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1349 | + $active_messenger->name, |
|
| 1350 | + $default_message_type_name_for_messenger |
|
| 1351 | + ) |
|
| 1352 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1353 | + ) { |
|
| 1354 | + continue; |
|
| 1355 | + } |
|
| 1356 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1357 | + } |
|
| 1358 | + //let's activate! |
|
| 1359 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1360 | + $default_message_type_names_to_activate, |
|
| 1361 | + $active_messenger->name, |
|
| 1362 | + false |
|
| 1363 | + ); |
|
| 1364 | + //activate the templates for these message types |
|
| 1365 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1366 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1367 | + $active_messenger->name, |
|
| 1368 | + $default_message_type_names_for_messenger, |
|
| 1369 | + '', |
|
| 1370 | + true |
|
| 1371 | + ); |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + return $templates_created; |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1381 | + * |
|
| 1382 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1383 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1384 | + * False means that there were no templates generated |
|
| 1385 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1386 | + * @throws EE_Error |
|
| 1387 | + */ |
|
| 1388 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1389 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1390 | + ) { |
|
| 1391 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1392 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1393 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1394 | + $templates_generated = false; |
|
| 1395 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1396 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1397 | + //verify the default message types match an installed message type. |
|
| 1398 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1399 | + if ( |
|
| 1400 | + ! isset($installed_message_types[$name]) |
|
| 1401 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1402 | + $name, |
|
| 1403 | + $messenger_to_generate->name |
|
| 1404 | + ) |
|
| 1405 | + ) { |
|
| 1406 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1407 | + } |
|
| 1408 | + } |
|
| 1409 | + // in previous iterations, the active_messengers option in the db |
|
| 1410 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1411 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1412 | + // passing off to create templates (after the refactor is done). |
|
| 1413 | + // @todo remove this comment when determined not necessary. |
|
| 1414 | + $message_resource_manager->activate_messenger( |
|
| 1415 | + $messenger_to_generate->name, |
|
| 1416 | + $default_message_type_names_for_messenger, |
|
| 1417 | + false |
|
| 1418 | + ); |
|
| 1419 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1420 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1421 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1422 | + $messenger_to_generate->name, |
|
| 1423 | + $default_message_type_names_for_messenger, |
|
| 1424 | + '', |
|
| 1425 | + true |
|
| 1426 | + ); |
|
| 1427 | + } |
|
| 1428 | + } |
|
| 1429 | + return $templates_generated; |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + |
|
| 1433 | + /** |
|
| 1434 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1435 | + * It considers: |
|
| 1436 | + * - whether a messenger is already active in the db. |
|
| 1437 | + * - whether a messenger has been made active at any time in the past. |
|
| 1438 | + * |
|
| 1439 | + * @static |
|
| 1440 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1441 | + * @return EE_messenger[] |
|
| 1442 | + */ |
|
| 1443 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1444 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1445 | + ) { |
|
| 1446 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1447 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1448 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1449 | + |
|
| 1450 | + $messengers_to_generate = array(); |
|
| 1451 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1452 | + //if installed messenger is a messenger that should be activated on install |
|
| 1453 | + //and is not already active |
|
| 1454 | + //and has never been activated |
|
| 1455 | + if ( |
|
| 1456 | + ! $installed_messenger->activate_on_install |
|
| 1457 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1458 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1459 | + ) { |
|
| 1460 | + continue; |
|
| 1461 | + } |
|
| 1462 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1463 | + } |
|
| 1464 | + return $messengers_to_generate; |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + |
|
| 1468 | + /** |
|
| 1469 | + * This simply validates active message types to ensure they actually match installed |
|
| 1470 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1471 | + * rows are set inactive. |
|
| 1472 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1473 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1474 | + * are still handled in here. |
|
| 1475 | + * |
|
| 1476 | + * @since 4.3.1 |
|
| 1477 | + * @return void |
|
| 1478 | + */ |
|
| 1479 | + public static function validate_messages_system() |
|
| 1480 | + { |
|
| 1481 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1482 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1483 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1484 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + |
|
| 1488 | + /** |
|
| 1489 | + * create_no_ticket_prices_array |
|
| 1490 | + * |
|
| 1491 | + * @access public |
|
| 1492 | + * @static |
|
| 1493 | + * @return void |
|
| 1494 | + */ |
|
| 1495 | + public static function create_no_ticket_prices_array() |
|
| 1496 | + { |
|
| 1497 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1498 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1499 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1500 | + if (! $espresso_no_ticket_prices) { |
|
| 1501 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1502 | + } |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + |
|
| 1506 | + /** |
|
| 1507 | + * plugin_deactivation |
|
| 1508 | + * |
|
| 1509 | + * @access public |
|
| 1510 | + * @static |
|
| 1511 | + * @return void |
|
| 1512 | + */ |
|
| 1513 | + public static function plugin_deactivation() |
|
| 1514 | + { |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + |
|
| 1518 | + /** |
|
| 1519 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1520 | + * (like post meta or term relations) |
|
| 1521 | + * |
|
| 1522 | + * @global wpdb $wpdb |
|
| 1523 | + * @throws \EE_Error |
|
| 1524 | + */ |
|
| 1525 | + public static function delete_all_espresso_cpt_data() |
|
| 1526 | + { |
|
| 1527 | + global $wpdb; |
|
| 1528 | + //get all the CPT post_types |
|
| 1529 | + $ee_post_types = array(); |
|
| 1530 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1531 | + if (method_exists($model_name, 'instance')) { |
|
| 1532 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1533 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1534 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1535 | + } |
|
| 1536 | + } |
|
| 1537 | + } |
|
| 1538 | + //get all our CPTs |
|
| 1539 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1540 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1541 | + //delete each post meta and term relations too |
|
| 1542 | + foreach ($cpt_ids as $post_id) { |
|
| 1543 | + wp_delete_post($post_id, true); |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + /** |
|
| 1548 | + * Deletes all EE custom tables |
|
| 1549 | + * |
|
| 1550 | + * @return array |
|
| 1551 | + */ |
|
| 1552 | + public static function drop_espresso_tables() |
|
| 1553 | + { |
|
| 1554 | + $tables = array(); |
|
| 1555 | + // load registry |
|
| 1556 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1557 | + if (method_exists($model_name, 'instance')) { |
|
| 1558 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1559 | + if ($model_obj instanceof EEM_Base) { |
|
| 1560 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1561 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1562 | + && |
|
| 1563 | + ( |
|
| 1564 | + is_main_site()//main site? nuke them all |
|
| 1565 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1566 | + ) |
|
| 1567 | + ) { |
|
| 1568 | + $tables[] = $table->get_table_name(); |
|
| 1569 | + } |
|
| 1570 | + } |
|
| 1571 | + } |
|
| 1572 | + } |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + //there are some tables whose models were removed. |
|
| 1576 | + //they should be removed when removing all EE core's data |
|
| 1577 | + $tables_without_models = array( |
|
| 1578 | + 'esp_promotion', |
|
| 1579 | + 'esp_promotion_applied', |
|
| 1580 | + 'esp_promotion_object', |
|
| 1581 | + 'esp_promotion_rule', |
|
| 1582 | + 'esp_rule', |
|
| 1583 | + ); |
|
| 1584 | + foreach ($tables_without_models as $table) { |
|
| 1585 | + $tables[] = $table; |
|
| 1586 | + } |
|
| 1587 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1594 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1595 | + * Returns the list actually deleted |
|
| 1596 | + * |
|
| 1597 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1598 | + * @global WPDB $wpdb |
|
| 1599 | + * @param array $table_names |
|
| 1600 | + * @return array of table names which we deleted |
|
| 1601 | + */ |
|
| 1602 | + public static function drop_tables($table_names) |
|
| 1603 | + { |
|
| 1604 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * plugin_uninstall |
|
| 1611 | + * |
|
| 1612 | + * @access public |
|
| 1613 | + * @static |
|
| 1614 | + * @param bool $remove_all |
|
| 1615 | + * @return void |
|
| 1616 | + */ |
|
| 1617 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1618 | + { |
|
| 1619 | + global $wpdb; |
|
| 1620 | + self::drop_espresso_tables(); |
|
| 1621 | + $wp_options_to_delete = array( |
|
| 1622 | + 'ee_no_ticket_prices' => true, |
|
| 1623 | + 'ee_active_messengers' => true, |
|
| 1624 | + 'ee_has_activated_messenger' => true, |
|
| 1625 | + 'ee_flush_rewrite_rules' => true, |
|
| 1626 | + 'ee_config' => false, |
|
| 1627 | + 'ee_data_migration_current_db_state' => true, |
|
| 1628 | + 'ee_data_migration_mapping_' => false, |
|
| 1629 | + 'ee_data_migration_script_' => false, |
|
| 1630 | + 'ee_data_migrations' => true, |
|
| 1631 | + 'ee_dms_map' => false, |
|
| 1632 | + 'ee_notices' => true, |
|
| 1633 | + 'lang_file_check_' => false, |
|
| 1634 | + 'ee_maintenance_mode' => true, |
|
| 1635 | + 'ee_ueip_optin' => true, |
|
| 1636 | + 'ee_ueip_has_notified' => true, |
|
| 1637 | + 'ee_plugin_activation_errors' => true, |
|
| 1638 | + 'ee_id_mapping_from' => false, |
|
| 1639 | + 'espresso_persistent_admin_notices' => true, |
|
| 1640 | + 'ee_encryption_key' => true, |
|
| 1641 | + 'pue_force_upgrade_' => false, |
|
| 1642 | + 'pue_json_error_' => false, |
|
| 1643 | + 'pue_install_key_' => false, |
|
| 1644 | + 'pue_verification_error_' => false, |
|
| 1645 | + 'pu_dismissed_upgrade_' => false, |
|
| 1646 | + 'external_updates-' => false, |
|
| 1647 | + 'ee_extra_data' => true, |
|
| 1648 | + 'ee_ssn_' => false, |
|
| 1649 | + 'ee_rss_' => false, |
|
| 1650 | + 'ee_rte_n_tx_' => false, |
|
| 1651 | + 'ee_pers_admin_notices' => true, |
|
| 1652 | + 'ee_job_parameters_' => false, |
|
| 1653 | + 'ee_upload_directories_incomplete' => true, |
|
| 1654 | + 'ee_verified_db_collations' => true, |
|
| 1655 | + ); |
|
| 1656 | + if (is_main_site()) { |
|
| 1657 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1658 | + } |
|
| 1659 | + $undeleted_options = array(); |
|
| 1660 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1661 | + if ($no_wildcard) { |
|
| 1662 | + if ( ! delete_option($option_name)) { |
|
| 1663 | + $undeleted_options[] = $option_name; |
|
| 1664 | + } |
|
| 1665 | + } else { |
|
| 1666 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1667 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1668 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1669 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1670 | + } |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + } |
|
| 1674 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1675 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1676 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1677 | + $db_update_sans_ee4 = array(); |
|
| 1678 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1679 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1680 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1681 | + } |
|
| 1682 | + } |
|
| 1683 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1684 | + } |
|
| 1685 | + $errors = ''; |
|
| 1686 | + if ( ! empty($undeleted_options)) { |
|
| 1687 | + $errors .= sprintf( |
|
| 1688 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1689 | + '<br/>', |
|
| 1690 | + implode(',<br/>', $undeleted_options) |
|
| 1691 | + ); |
|
| 1692 | + } |
|
| 1693 | + if ( ! empty($errors)) { |
|
| 1694 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1695 | + } |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1700 | + * |
|
| 1701 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1702 | + */ |
|
| 1703 | + public static function last_wpdb_error_code() |
|
| 1704 | + { |
|
| 1705 | + global $wpdb; |
|
| 1706 | + if ($wpdb->use_mysqli) { |
|
| 1707 | + return mysqli_errno($wpdb->dbh); |
|
| 1708 | + } else { |
|
| 1709 | + return mysql_errno($wpdb->dbh); |
|
| 1710 | + } |
|
| 1711 | + } |
|
| 1712 | + |
|
| 1713 | + /** |
|
| 1714 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1715 | + * |
|
| 1716 | + * @global wpdb $wpdb |
|
| 1717 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1718 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1719 | + * @return boolean |
|
| 1720 | + */ |
|
| 1721 | + public static function table_exists($table_name) |
|
| 1722 | + { |
|
| 1723 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1724 | + } |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * Resets the cache on EEH_Activation |
|
| 1728 | + */ |
|
| 1729 | + public static function reset() |
|
| 1730 | + { |
|
| 1731 | + self::$_default_creator_id = null; |
|
| 1732 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1733 | + } |
|
| 1734 | 1734 | } |
| 1735 | 1735 | // End of file EEH_Activation.helper.php |
| 1736 | 1736 | // Location: /helpers/EEH_Activation.core.php |
@@ -13,1084 +13,1084 @@ |
||
| 13 | 13 | class EED_Messages extends EED_Module |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * This holds the EE_messages controller |
|
| 18 | - * |
|
| 19 | - * @deprecated 4.9.0 |
|
| 20 | - * @var EE_messages $_EEMSG |
|
| 21 | - */ |
|
| 22 | - protected static $_EEMSG; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 26 | - */ |
|
| 27 | - protected static $_message_resource_manager; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This holds the EE_Messages_Processor business class. |
|
| 31 | - * |
|
| 32 | - * @type EE_Messages_Processor |
|
| 33 | - */ |
|
| 34 | - protected static $_MSG_PROCESSOR; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * holds all the paths for various messages components. |
|
| 38 | - * Utilized by autoloader registry |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected static $_MSG_PATHS; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 47 | - * Format is: |
|
| 48 | - * array( |
|
| 49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 50 | - * ) |
|
| 51 | - * |
|
| 52 | - * @var EE_Messages_Template_Pack[] |
|
| 53 | - */ |
|
| 54 | - protected static $_TMP_PACKS = array(); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return EED_Messages |
|
| 59 | - */ |
|
| 60 | - public static function instance() |
|
| 61 | - { |
|
| 62 | - return parent::get_instance(__CLASS__); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 68 | - * |
|
| 69 | - * @since 4.5.0 |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public static function set_hooks() |
|
| 73 | - { |
|
| 74 | - //actions |
|
| 75 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 76 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 77 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 78 | - //filters |
|
| 79 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 80 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 81 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 82 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 83 | - //register routes |
|
| 84 | - self::_register_routes(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - public static function set_hooks_admin() |
|
| 94 | - { |
|
| 95 | - //actions |
|
| 96 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 97 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 98 | - array('EED_Messages', 'payment_reminder'), 10); |
|
| 99 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 100 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 101 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 102 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 103 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 104 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
| 105 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 106 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 107 | - //filters |
|
| 108 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 109 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
| 110 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 111 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 112 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 113 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * All the message triggers done by route go in here. |
|
| 119 | - * |
|
| 120 | - * @since 4.5.0 |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - protected static function _register_routes() |
|
| 124 | - { |
|
| 125 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 126 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 127 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 128 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 129 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * This is called when a browser display trigger is executed. |
|
| 135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 136 | - * browser. |
|
| 137 | - * |
|
| 138 | - * @since 4.9.0 |
|
| 139 | - * @param WP $WP |
|
| 140 | - */ |
|
| 141 | - public function browser_trigger($WP) |
|
| 142 | - { |
|
| 143 | - //ensure controller is loaded |
|
| 144 | - self::_load_controller(); |
|
| 145 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 146 | - try { |
|
| 147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 149 | - } catch (EE_Error $e) { |
|
| 150 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 151 | - 'event_espresso'); |
|
| 152 | - // add specific message for developers if WP_DEBUG in on |
|
| 153 | - $error_msg .= '||' . $e->getMessage(); |
|
| 154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * This is called when a browser error trigger is executed. |
|
| 161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 162 | - * message and display it. |
|
| 163 | - * |
|
| 164 | - * @since 4.9.0 |
|
| 165 | - * @param $WP |
|
| 166 | - */ |
|
| 167 | - public function browser_error_trigger($WP) |
|
| 168 | - { |
|
| 169 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 170 | - if ($token) { |
|
| 171 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 172 | - if ($message instanceof EE_Message) { |
|
| 173 | - header('HTTP/1.1 200 OK'); |
|
| 174 | - $error_msg = nl2br($message->error_message()); |
|
| 175 | - ?> |
|
| 16 | + /** |
|
| 17 | + * This holds the EE_messages controller |
|
| 18 | + * |
|
| 19 | + * @deprecated 4.9.0 |
|
| 20 | + * @var EE_messages $_EEMSG |
|
| 21 | + */ |
|
| 22 | + protected static $_EEMSG; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 26 | + */ |
|
| 27 | + protected static $_message_resource_manager; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This holds the EE_Messages_Processor business class. |
|
| 31 | + * |
|
| 32 | + * @type EE_Messages_Processor |
|
| 33 | + */ |
|
| 34 | + protected static $_MSG_PROCESSOR; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * holds all the paths for various messages components. |
|
| 38 | + * Utilized by autoloader registry |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected static $_MSG_PATHS; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 47 | + * Format is: |
|
| 48 | + * array( |
|
| 49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 50 | + * ) |
|
| 51 | + * |
|
| 52 | + * @var EE_Messages_Template_Pack[] |
|
| 53 | + */ |
|
| 54 | + protected static $_TMP_PACKS = array(); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return EED_Messages |
|
| 59 | + */ |
|
| 60 | + public static function instance() |
|
| 61 | + { |
|
| 62 | + return parent::get_instance(__CLASS__); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 68 | + * |
|
| 69 | + * @since 4.5.0 |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public static function set_hooks() |
|
| 73 | + { |
|
| 74 | + //actions |
|
| 75 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 76 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 77 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 78 | + //filters |
|
| 79 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 80 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 81 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 82 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 83 | + //register routes |
|
| 84 | + self::_register_routes(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + public static function set_hooks_admin() |
|
| 94 | + { |
|
| 95 | + //actions |
|
| 96 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 97 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 98 | + array('EED_Messages', 'payment_reminder'), 10); |
|
| 99 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 100 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 101 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 102 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 103 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 104 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
| 105 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 106 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 107 | + //filters |
|
| 108 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 109 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
| 110 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 111 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 112 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 113 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * All the message triggers done by route go in here. |
|
| 119 | + * |
|
| 120 | + * @since 4.5.0 |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + protected static function _register_routes() |
|
| 124 | + { |
|
| 125 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 126 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 127 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 128 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 129 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * This is called when a browser display trigger is executed. |
|
| 135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 136 | + * browser. |
|
| 137 | + * |
|
| 138 | + * @since 4.9.0 |
|
| 139 | + * @param WP $WP |
|
| 140 | + */ |
|
| 141 | + public function browser_trigger($WP) |
|
| 142 | + { |
|
| 143 | + //ensure controller is loaded |
|
| 144 | + self::_load_controller(); |
|
| 145 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 146 | + try { |
|
| 147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 149 | + } catch (EE_Error $e) { |
|
| 150 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 151 | + 'event_espresso'); |
|
| 152 | + // add specific message for developers if WP_DEBUG in on |
|
| 153 | + $error_msg .= '||' . $e->getMessage(); |
|
| 154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * This is called when a browser error trigger is executed. |
|
| 161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 162 | + * message and display it. |
|
| 163 | + * |
|
| 164 | + * @since 4.9.0 |
|
| 165 | + * @param $WP |
|
| 166 | + */ |
|
| 167 | + public function browser_error_trigger($WP) |
|
| 168 | + { |
|
| 169 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 170 | + if ($token) { |
|
| 171 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 172 | + if ($message instanceof EE_Message) { |
|
| 173 | + header('HTTP/1.1 200 OK'); |
|
| 174 | + $error_msg = nl2br($message->error_message()); |
|
| 175 | + ?> |
|
| 176 | 176 | <!DOCTYPE html> |
| 177 | 177 | <html> |
| 178 | 178 | <head></head> |
| 179 | 179 | <body> |
| 180 | 180 | <?php echo empty($error_msg) |
| 181 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 182 | - 'event_espresso') |
|
| 183 | - : wp_kses( |
|
| 184 | - $error_msg, |
|
| 185 | - array( |
|
| 186 | - 'a' => array( |
|
| 187 | - 'href' => array(), |
|
| 188 | - 'title' => array(), |
|
| 189 | - ), |
|
| 190 | - 'span' => array(), |
|
| 191 | - 'div' => array(), |
|
| 192 | - 'p' => array(), |
|
| 193 | - 'strong' => array(), |
|
| 194 | - 'em' => array(), |
|
| 195 | - 'br' => array(), |
|
| 196 | - ) |
|
| 197 | - ); ?> |
|
| 181 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 182 | + 'event_espresso') |
|
| 183 | + : wp_kses( |
|
| 184 | + $error_msg, |
|
| 185 | + array( |
|
| 186 | + 'a' => array( |
|
| 187 | + 'href' => array(), |
|
| 188 | + 'title' => array(), |
|
| 189 | + ), |
|
| 190 | + 'span' => array(), |
|
| 191 | + 'div' => array(), |
|
| 192 | + 'p' => array(), |
|
| 193 | + 'strong' => array(), |
|
| 194 | + 'em' => array(), |
|
| 195 | + 'br' => array(), |
|
| 196 | + ) |
|
| 197 | + ); ?> |
|
| 198 | 198 | </body> |
| 199 | 199 | </html> |
| 200 | 200 | <?php |
| 201 | - exit; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * This runs when the msg_url_trigger route has initiated. |
|
| 210 | - * |
|
| 211 | - * @since 4.5.0 |
|
| 212 | - * @param WP $WP |
|
| 213 | - * @throws EE_Error |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public function run($WP) |
|
| 217 | - { |
|
| 218 | - //ensure controller is loaded |
|
| 219 | - self::_load_controller(); |
|
| 220 | - // attempt to process message |
|
| 221 | - try { |
|
| 222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 223 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 225 | - } catch (EE_Error $e) { |
|
| 226 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 227 | - 'event_espresso'); |
|
| 228 | - // add specific message for developers if WP_DEBUG in on |
|
| 229 | - $error_msg .= '||' . $e->getMessage(); |
|
| 230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 237 | - * |
|
| 238 | - * @param WP $WP |
|
| 239 | - */ |
|
| 240 | - public function execute_batch_request($WP) |
|
| 241 | - { |
|
| 242 | - $this->run_cron(); |
|
| 243 | - header('HTTP/1.1 200 OK'); |
|
| 244 | - exit(); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 250 | - * request. |
|
| 251 | - */ |
|
| 252 | - public function run_cron() |
|
| 253 | - { |
|
| 254 | - self::_load_controller(); |
|
| 255 | - //get required vars |
|
| 256 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 257 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 258 | - |
|
| 259 | - //now let's verify transient, if not valid exit immediately |
|
| 260 | - if (! get_transient($transient_key)) { |
|
| 261 | - /** |
|
| 262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
| 263 | - */ |
|
| 264 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - //if made it here, lets' delete the transient to keep the db clean |
|
| 268 | - delete_transient($transient_key); |
|
| 269 | - |
|
| 270 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 271 | - |
|
| 272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 273 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 274 | - self::$_MSG_PROCESSOR->$method(); |
|
| 275 | - } else { |
|
| 276 | - //no matching task |
|
| 277 | - /** |
|
| 278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
| 279 | - */ |
|
| 280 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 281 | - $cron_type))); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This is used to retrieve the template pack for the given name. |
|
| 291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 292 | - * the default template pack is returned. |
|
| 293 | - * |
|
| 294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 296 | - * in generating the Pack class name). |
|
| 297 | - * @return EE_Messages_Template_Pack |
|
| 298 | - */ |
|
| 299 | - public static function get_template_pack($template_pack_name) |
|
| 300 | - { |
|
| 301 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 302 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Retrieves an array of all template packs. |
|
| 308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 309 | - * |
|
| 310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 311 | - * @return EE_Messages_Template_Pack[] |
|
| 312 | - */ |
|
| 313 | - public static function get_template_packs() |
|
| 314 | - { |
|
| 315 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 316 | - |
|
| 317 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
| 318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 319 | - $template_pack_collection->rewind(); |
|
| 320 | - $template_packs = array(); |
|
| 321 | - while ($template_pack_collection->valid()) { |
|
| 322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 323 | - $template_pack_collection->next(); |
|
| 324 | - } |
|
| 325 | - return $template_packs; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 331 | - * |
|
| 332 | - * @since 4.5.0 |
|
| 333 | - * @return void |
|
| 334 | - */ |
|
| 335 | - public static function set_autoloaders() |
|
| 336 | - { |
|
| 337 | - if (empty(self::$_MSG_PATHS)) { |
|
| 338 | - self::_set_messages_paths(); |
|
| 339 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 341 | - } |
|
| 342 | - // add aliases |
|
| 343 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 344 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 351 | - * for use by the Messages Autoloaders |
|
| 352 | - * |
|
| 353 | - * @since 4.5.0 |
|
| 354 | - * @return void. |
|
| 355 | - */ |
|
| 356 | - protected static function _set_messages_paths() |
|
| 357 | - { |
|
| 358 | - $dir_ref = array( |
|
| 359 | - 'messages/message_type', |
|
| 360 | - 'messages/messenger', |
|
| 361 | - 'messages/defaults', |
|
| 362 | - 'messages/defaults/email', |
|
| 363 | - 'messages/data_class', |
|
| 364 | - 'messages/validators', |
|
| 365 | - 'messages/validators/email', |
|
| 366 | - 'messages/validators/html', |
|
| 367 | - 'shortcodes', |
|
| 368 | - ); |
|
| 369 | - $paths = array(); |
|
| 370 | - foreach ($dir_ref as $index => $dir) { |
|
| 371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
| 372 | - } |
|
| 373 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Takes care of loading dependencies |
|
| 379 | - * |
|
| 380 | - * @since 4.5.0 |
|
| 381 | - * @return void |
|
| 382 | - */ |
|
| 383 | - protected static function _load_controller() |
|
| 384 | - { |
|
| 385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 386 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 387 | - self::set_autoloaders(); |
|
| 388 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 389 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 390 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param EE_Transaction $transaction |
|
| 397 | - */ |
|
| 398 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 399 | - { |
|
| 400 | - self::_load_controller(); |
|
| 401 | - $data = array($transaction, null); |
|
| 402 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 408 | - * |
|
| 409 | - * @param EE_Transaction object |
|
| 410 | - * @param EE_Payment object |
|
| 411 | - * @return void |
|
| 412 | - */ |
|
| 413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 414 | - { |
|
| 415 | - self::_load_controller(); |
|
| 416 | - $data = array($transaction, $payment); |
|
| 417 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 419 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @param EE_Transaction $transaction |
|
| 427 | - */ |
|
| 428 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 429 | - { |
|
| 430 | - self::_load_controller(); |
|
| 431 | - $data = array($transaction, null); |
|
| 432 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Trigger for Registration messages |
|
| 438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 439 | - * incoming transaction. |
|
| 440 | - * |
|
| 441 | - * @param EE_Registration $registration |
|
| 442 | - * @param array $extra_details |
|
| 443 | - * @return void |
|
| 444 | - */ |
|
| 445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 446 | - { |
|
| 447 | - |
|
| 448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 449 | - //no messages please |
|
| 450 | - return; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - //get all registrations so we make sure we send messages for the right status. |
|
| 455 | - $all_registrations = $registration->transaction()->registrations(); |
|
| 456 | - |
|
| 457 | - //cached array of statuses so we only trigger messages once per status. |
|
| 458 | - $statuses_sent = array(); |
|
| 459 | - self::_load_controller(); |
|
| 460 | - $mtgs = array(); |
|
| 461 | - |
|
| 462 | - //loop through registrations and trigger messages once per status. |
|
| 463 | - foreach ($all_registrations as $reg) { |
|
| 464 | - |
|
| 465 | - //already triggered? |
|
| 466 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 467 | - continue; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 471 | - $mtgs = array_merge( |
|
| 472 | - $mtgs, |
|
| 473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 474 | - $message_type, |
|
| 475 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 476 | - ) |
|
| 477 | - ); |
|
| 478 | - $statuses_sent[] = $reg->status_ID(); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - $mtgs = array_merge( |
|
| 482 | - $mtgs, |
|
| 483 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 484 | - 'registration_summary', |
|
| 485 | - array($registration->transaction(), null) |
|
| 486 | - ) |
|
| 487 | - ); |
|
| 488 | - |
|
| 489 | - //batch queue and initiate request |
|
| 490 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 491 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 497 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 498 | - * |
|
| 499 | - * @param EE_Registration $registration [description] |
|
| 500 | - * @param array $extra_details [description] |
|
| 501 | - * @return bool true = send away, false = nope halt the presses. |
|
| 502 | - */ |
|
| 503 | - protected static function _verify_registration_notification_send( |
|
| 504 | - EE_Registration $registration, |
|
| 505 | - $extra_details = array() |
|
| 506 | - ) { |
|
| 507 | - //self::log( |
|
| 508 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 509 | - // $registration->transaction(), |
|
| 510 | - // array( '$extra_details' => $extra_details ) |
|
| 511 | - //); |
|
| 512 | - // currently only using this to send messages for the primary registrant |
|
| 513 | - if (! $registration->is_primary_registrant()) { |
|
| 514 | - return false; |
|
| 515 | - } |
|
| 516 | - // first we check if we're in admin and not doing front ajax |
|
| 517 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 518 | - //make sure appropriate admin params are set for sending messages |
|
| 519 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 520 | - //no messages sent please. |
|
| 521 | - return false; |
|
| 522 | - } |
|
| 523 | - } else { |
|
| 524 | - // frontend request (either regular or via AJAX) |
|
| 525 | - // TXN is NOT finalized ? |
|
| 526 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 527 | - return false; |
|
| 528 | - } |
|
| 529 | - // return visit but nothing changed ??? |
|
| 530 | - if ( |
|
| 531 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 532 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 533 | - ) { |
|
| 534 | - return false; |
|
| 535 | - } |
|
| 536 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 537 | - if ( |
|
| 538 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 539 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 540 | - ) { |
|
| 541 | - return false; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - // release the kraken |
|
| 545 | - return true; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 551 | - * status id. |
|
| 552 | - * |
|
| 553 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 554 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 555 | - * @param string $reg_status |
|
| 556 | - * @return array |
|
| 557 | - */ |
|
| 558 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 559 | - { |
|
| 560 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 561 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 562 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 563 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Simply returns the payment message type for the given payment status. |
|
| 569 | - * |
|
| 570 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 571 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 572 | - * @param string $payment_status The payment status being matched. |
|
| 573 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
| 574 | - */ |
|
| 575 | - protected static function _get_payment_message_type($payment_status) |
|
| 576 | - { |
|
| 577 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 578 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 579 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 580 | - : false; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 586 | - * |
|
| 587 | - * @access public |
|
| 588 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 589 | - * @return bool success/fail |
|
| 590 | - */ |
|
| 591 | - public static function process_resend($req_data) |
|
| 592 | - { |
|
| 593 | - self::_load_controller(); |
|
| 594 | - |
|
| 595 | - //if $msgID in this request then skip to the new resend_message |
|
| 596 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 597 | - return self::resend_message(); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 601 | - $req_data = (array)$req_data; |
|
| 602 | - foreach ($req_data as $request_key => $request_value) { |
|
| 603 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 607 | - return false; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - try { |
|
| 611 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 612 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 613 | - } catch (EE_Error $e) { |
|
| 614 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 615 | - return false; |
|
| 616 | - } |
|
| 617 | - EE_Error::add_success( |
|
| 618 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 619 | - ); |
|
| 620 | - return true; //everything got queued. |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 626 | - * |
|
| 627 | - * @return bool |
|
| 628 | - */ |
|
| 629 | - public static function resend_message() |
|
| 630 | - { |
|
| 631 | - self::_load_controller(); |
|
| 632 | - |
|
| 633 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 634 | - if (! $msgID) { |
|
| 635 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 636 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 637 | - return false; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 641 | - |
|
| 642 | - //setup success message. |
|
| 643 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 644 | - EE_Error::add_success(sprintf( |
|
| 645 | - _n( |
|
| 646 | - 'There was %d message queued for resending.', |
|
| 647 | - 'There were %d messages queued for resending.', |
|
| 648 | - $count_ready_for_resend, |
|
| 649 | - 'event_espresso' |
|
| 650 | - ), |
|
| 651 | - $count_ready_for_resend |
|
| 652 | - )); |
|
| 653 | - return true; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Message triggers for manual payment applied by admin |
|
| 659 | - * |
|
| 660 | - * @param EE_Payment $payment EE_payment object |
|
| 661 | - * @return bool success/fail |
|
| 662 | - */ |
|
| 663 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 664 | - { |
|
| 665 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 666 | - //we need to get the transaction object |
|
| 667 | - $transaction = $payment->transaction(); |
|
| 668 | - if ($transaction instanceof EE_Transaction) { |
|
| 669 | - $data = array($transaction, $payment); |
|
| 670 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 671 | - |
|
| 672 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 673 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 674 | - |
|
| 675 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 676 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 677 | - |
|
| 678 | - self::_load_controller(); |
|
| 679 | - |
|
| 680 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 681 | - |
|
| 682 | - //get count of queued for generation |
|
| 683 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 684 | - EEM_Message::status_incomplete, |
|
| 685 | - EEM_Message::status_idle, |
|
| 686 | - )); |
|
| 687 | - |
|
| 688 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 689 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 690 | - return true; |
|
| 691 | - } else { |
|
| 692 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 693 | - /** |
|
| 694 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 695 | - * IMMEDIATE generation. |
|
| 696 | - */ |
|
| 697 | - if ($count_failed > 0) { |
|
| 698 | - EE_Error::add_error(sprintf( |
|
| 699 | - _n( |
|
| 700 | - 'The payment notification generation failed.', |
|
| 701 | - '%d payment notifications failed being sent.', |
|
| 702 | - $count_failed, |
|
| 703 | - 'event_espresso' |
|
| 704 | - ), |
|
| 705 | - $count_failed |
|
| 706 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
| 707 | - |
|
| 708 | - return false; |
|
| 709 | - } else { |
|
| 710 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 711 | - return true; |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - } else { |
|
| 715 | - EE_Error::add_error( |
|
| 716 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 717 | - 'event_espresso' |
|
| 718 | - ); |
|
| 719 | - return false; |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 726 | - * |
|
| 727 | - * @since 4.3.0 |
|
| 728 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 729 | - * @param int $grp_id a specific message template group id. |
|
| 730 | - * @return void |
|
| 731 | - */ |
|
| 732 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 733 | - { |
|
| 734 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 735 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 736 | - self::_load_controller(); |
|
| 737 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 743 | - * |
|
| 744 | - * @since 4.3.0 |
|
| 745 | - * @param string $registration_message_trigger_url |
|
| 746 | - * @param EE_Registration $registration |
|
| 747 | - * @param string $messenger |
|
| 748 | - * @param string $message_type |
|
| 749 | - * @return string |
|
| 750 | - */ |
|
| 751 | - public static function registration_message_trigger_url( |
|
| 752 | - $registration_message_trigger_url, |
|
| 753 | - EE_Registration $registration, |
|
| 754 | - $messenger = 'html', |
|
| 755 | - $message_type = 'invoice' |
|
| 756 | - ) { |
|
| 757 | - // whitelist $messenger |
|
| 758 | - switch ($messenger) { |
|
| 759 | - case 'pdf' : |
|
| 760 | - $sending_messenger = 'pdf'; |
|
| 761 | - $generating_messenger = 'html'; |
|
| 762 | - break; |
|
| 763 | - case 'html' : |
|
| 764 | - default : |
|
| 765 | - $sending_messenger = 'html'; |
|
| 766 | - $generating_messenger = 'html'; |
|
| 767 | - break; |
|
| 768 | - } |
|
| 769 | - // whitelist $message_type |
|
| 770 | - switch ($message_type) { |
|
| 771 | - case 'receipt' : |
|
| 772 | - $message_type = 'receipt'; |
|
| 773 | - break; |
|
| 774 | - case 'invoice' : |
|
| 775 | - default : |
|
| 776 | - $message_type = 'invoice'; |
|
| 777 | - break; |
|
| 778 | - } |
|
| 779 | - // verify that both the messenger AND the message type are active |
|
| 780 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 781 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 782 | - $template_query_params = array( |
|
| 783 | - 'MTP_is_active' => true, |
|
| 784 | - 'MTP_messenger' => $generating_messenger, |
|
| 785 | - 'MTP_message_type' => $message_type, |
|
| 786 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 787 | - ); |
|
| 788 | - //get the message template group. |
|
| 789 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 790 | - //if we don't have an EE_Message_Template_Group then return |
|
| 791 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 792 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 793 | - unset($template_query_params['Event.EVT_ID']); |
|
| 794 | - //get global template as the fallback |
|
| 795 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 796 | - } |
|
| 797 | - //if we don't have an EE_Message_Template_Group then return |
|
| 798 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 799 | - return ''; |
|
| 800 | - } |
|
| 801 | - // generate the URL |
|
| 802 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 803 | - $sending_messenger, |
|
| 804 | - $generating_messenger, |
|
| 805 | - 'purchaser', |
|
| 806 | - $message_type, |
|
| 807 | - $registration, |
|
| 808 | - $msg_template_group->ID(), |
|
| 809 | - $registration->transaction_ID() |
|
| 810 | - ); |
|
| 811 | - |
|
| 812 | - } |
|
| 813 | - return $registration_message_trigger_url; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - /** |
|
| 818 | - * Use to generate and return a message preview! |
|
| 819 | - * |
|
| 820 | - * @param string $type This should correspond with a valid message type |
|
| 821 | - * @param string $context This should correspond with a valid context for the message type |
|
| 822 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 823 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 824 | - * preview |
|
| 825 | - * @return string|bool The body of the message or if send is requested, sends. |
|
| 826 | - */ |
|
| 827 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 828 | - { |
|
| 829 | - self::_load_controller(); |
|
| 830 | - $mtg = new EE_Message_To_Generate( |
|
| 831 | - $messenger, |
|
| 832 | - $type, |
|
| 833 | - array(), |
|
| 834 | - $context, |
|
| 835 | - true |
|
| 836 | - ); |
|
| 837 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 838 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 839 | - return $generated_preview_queue->get_message_repository()->current()->content(); |
|
| 840 | - } else { |
|
| 841 | - return $generated_preview_queue; |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 848 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 849 | - * content found in the EE_Message objects in the queue. |
|
| 850 | - * |
|
| 851 | - * @since 4.9.0 |
|
| 852 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 853 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 854 | - * type name is still required to send along the message type to the |
|
| 855 | - * messenger because this is used for determining what specific |
|
| 856 | - * variations might be loaded for the generated message. |
|
| 857 | - * @param EE_Messages_Queue $queue |
|
| 858 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 859 | - * aggregate EE_Message object. |
|
| 860 | - * @return bool success or fail. |
|
| 861 | - */ |
|
| 862 | - public static function send_message_with_messenger_only( |
|
| 863 | - $messenger, |
|
| 864 | - $message_type, |
|
| 865 | - EE_Messages_Queue $queue, |
|
| 866 | - $custom_subject = '' |
|
| 867 | - ) { |
|
| 868 | - self::_load_controller(); |
|
| 869 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 870 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 871 | - 'Message_To_Generate_From_Queue', |
|
| 872 | - array( |
|
| 873 | - $messenger, |
|
| 874 | - $message_type, |
|
| 875 | - $queue, |
|
| 876 | - $custom_subject, |
|
| 877 | - ) |
|
| 878 | - ); |
|
| 879 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 885 | - * |
|
| 886 | - * @since 4.9.0 |
|
| 887 | - * @param array $message_ids An array of message ids |
|
| 888 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 889 | - * messages. |
|
| 890 | - */ |
|
| 891 | - public static function generate_now($message_ids) |
|
| 892 | - { |
|
| 893 | - self::_load_controller(); |
|
| 894 | - $messages = EEM_Message::instance()->get_all( |
|
| 895 | - array( |
|
| 896 | - 0 => array( |
|
| 897 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 898 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 899 | - ), |
|
| 900 | - ) |
|
| 901 | - ); |
|
| 902 | - $generated_queue = false; |
|
| 903 | - if ($messages) { |
|
| 904 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 908 | - EE_Error::add_error( |
|
| 909 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 910 | - 'event_espresso'), |
|
| 911 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - return $generated_queue; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 920 | - * EEM_Message::status_idle |
|
| 921 | - * |
|
| 922 | - * @since 4.9.0 |
|
| 923 | - * @param $message_ids |
|
| 924 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
| 925 | - */ |
|
| 926 | - public static function send_now($message_ids) |
|
| 927 | - { |
|
| 928 | - self::_load_controller(); |
|
| 929 | - $messages = EEM_Message::instance()->get_all( |
|
| 930 | - array( |
|
| 931 | - 0 => array( |
|
| 932 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 933 | - 'STS_ID' => array( |
|
| 934 | - 'IN', |
|
| 935 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 936 | - ), |
|
| 937 | - ), |
|
| 938 | - ) |
|
| 939 | - ); |
|
| 940 | - $sent_queue = false; |
|
| 941 | - if ($messages) { |
|
| 942 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 946 | - EE_Error::add_error( |
|
| 947 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 948 | - 'event_espresso'), |
|
| 949 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 950 | - ); |
|
| 951 | - } else { |
|
| 952 | - //can count how many sent by using the messages in the queue |
|
| 953 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 954 | - if ($sent_count > 0) { |
|
| 955 | - EE_Error::add_success( |
|
| 956 | - sprintf( |
|
| 957 | - _n( |
|
| 958 | - 'There was %d message successfully sent.', |
|
| 959 | - 'There were %d messages successfully sent.', |
|
| 960 | - $sent_count, |
|
| 961 | - 'event_espresso' |
|
| 962 | - ), |
|
| 963 | - $sent_count |
|
| 964 | - ) |
|
| 965 | - ); |
|
| 966 | - } else { |
|
| 967 | - EE_Error::overwrite_errors(); |
|
| 968 | - EE_Error::add_error( |
|
| 969 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 201 | + exit; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * This runs when the msg_url_trigger route has initiated. |
|
| 210 | + * |
|
| 211 | + * @since 4.5.0 |
|
| 212 | + * @param WP $WP |
|
| 213 | + * @throws EE_Error |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public function run($WP) |
|
| 217 | + { |
|
| 218 | + //ensure controller is loaded |
|
| 219 | + self::_load_controller(); |
|
| 220 | + // attempt to process message |
|
| 221 | + try { |
|
| 222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 223 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 225 | + } catch (EE_Error $e) { |
|
| 226 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 227 | + 'event_espresso'); |
|
| 228 | + // add specific message for developers if WP_DEBUG in on |
|
| 229 | + $error_msg .= '||' . $e->getMessage(); |
|
| 230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 237 | + * |
|
| 238 | + * @param WP $WP |
|
| 239 | + */ |
|
| 240 | + public function execute_batch_request($WP) |
|
| 241 | + { |
|
| 242 | + $this->run_cron(); |
|
| 243 | + header('HTTP/1.1 200 OK'); |
|
| 244 | + exit(); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 250 | + * request. |
|
| 251 | + */ |
|
| 252 | + public function run_cron() |
|
| 253 | + { |
|
| 254 | + self::_load_controller(); |
|
| 255 | + //get required vars |
|
| 256 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 257 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 258 | + |
|
| 259 | + //now let's verify transient, if not valid exit immediately |
|
| 260 | + if (! get_transient($transient_key)) { |
|
| 261 | + /** |
|
| 262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
| 263 | + */ |
|
| 264 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + //if made it here, lets' delete the transient to keep the db clean |
|
| 268 | + delete_transient($transient_key); |
|
| 269 | + |
|
| 270 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 271 | + |
|
| 272 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 273 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 274 | + self::$_MSG_PROCESSOR->$method(); |
|
| 275 | + } else { |
|
| 276 | + //no matching task |
|
| 277 | + /** |
|
| 278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
| 279 | + */ |
|
| 280 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 281 | + $cron_type))); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This is used to retrieve the template pack for the given name. |
|
| 291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 292 | + * the default template pack is returned. |
|
| 293 | + * |
|
| 294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 296 | + * in generating the Pack class name). |
|
| 297 | + * @return EE_Messages_Template_Pack |
|
| 298 | + */ |
|
| 299 | + public static function get_template_pack($template_pack_name) |
|
| 300 | + { |
|
| 301 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 302 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Retrieves an array of all template packs. |
|
| 308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 309 | + * |
|
| 310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 311 | + * @return EE_Messages_Template_Pack[] |
|
| 312 | + */ |
|
| 313 | + public static function get_template_packs() |
|
| 314 | + { |
|
| 315 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 316 | + |
|
| 317 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
| 318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 319 | + $template_pack_collection->rewind(); |
|
| 320 | + $template_packs = array(); |
|
| 321 | + while ($template_pack_collection->valid()) { |
|
| 322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 323 | + $template_pack_collection->next(); |
|
| 324 | + } |
|
| 325 | + return $template_packs; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 331 | + * |
|
| 332 | + * @since 4.5.0 |
|
| 333 | + * @return void |
|
| 334 | + */ |
|
| 335 | + public static function set_autoloaders() |
|
| 336 | + { |
|
| 337 | + if (empty(self::$_MSG_PATHS)) { |
|
| 338 | + self::_set_messages_paths(); |
|
| 339 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 341 | + } |
|
| 342 | + // add aliases |
|
| 343 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 344 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 351 | + * for use by the Messages Autoloaders |
|
| 352 | + * |
|
| 353 | + * @since 4.5.0 |
|
| 354 | + * @return void. |
|
| 355 | + */ |
|
| 356 | + protected static function _set_messages_paths() |
|
| 357 | + { |
|
| 358 | + $dir_ref = array( |
|
| 359 | + 'messages/message_type', |
|
| 360 | + 'messages/messenger', |
|
| 361 | + 'messages/defaults', |
|
| 362 | + 'messages/defaults/email', |
|
| 363 | + 'messages/data_class', |
|
| 364 | + 'messages/validators', |
|
| 365 | + 'messages/validators/email', |
|
| 366 | + 'messages/validators/html', |
|
| 367 | + 'shortcodes', |
|
| 368 | + ); |
|
| 369 | + $paths = array(); |
|
| 370 | + foreach ($dir_ref as $index => $dir) { |
|
| 371 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
| 372 | + } |
|
| 373 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Takes care of loading dependencies |
|
| 379 | + * |
|
| 380 | + * @since 4.5.0 |
|
| 381 | + * @return void |
|
| 382 | + */ |
|
| 383 | + protected static function _load_controller() |
|
| 384 | + { |
|
| 385 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 386 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 387 | + self::set_autoloaders(); |
|
| 388 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 389 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 390 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param EE_Transaction $transaction |
|
| 397 | + */ |
|
| 398 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 399 | + { |
|
| 400 | + self::_load_controller(); |
|
| 401 | + $data = array($transaction, null); |
|
| 402 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 408 | + * |
|
| 409 | + * @param EE_Transaction object |
|
| 410 | + * @param EE_Payment object |
|
| 411 | + * @return void |
|
| 412 | + */ |
|
| 413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 414 | + { |
|
| 415 | + self::_load_controller(); |
|
| 416 | + $data = array($transaction, $payment); |
|
| 417 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 419 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @param EE_Transaction $transaction |
|
| 427 | + */ |
|
| 428 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 429 | + { |
|
| 430 | + self::_load_controller(); |
|
| 431 | + $data = array($transaction, null); |
|
| 432 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Trigger for Registration messages |
|
| 438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 439 | + * incoming transaction. |
|
| 440 | + * |
|
| 441 | + * @param EE_Registration $registration |
|
| 442 | + * @param array $extra_details |
|
| 443 | + * @return void |
|
| 444 | + */ |
|
| 445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 446 | + { |
|
| 447 | + |
|
| 448 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 449 | + //no messages please |
|
| 450 | + return; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + //get all registrations so we make sure we send messages for the right status. |
|
| 455 | + $all_registrations = $registration->transaction()->registrations(); |
|
| 456 | + |
|
| 457 | + //cached array of statuses so we only trigger messages once per status. |
|
| 458 | + $statuses_sent = array(); |
|
| 459 | + self::_load_controller(); |
|
| 460 | + $mtgs = array(); |
|
| 461 | + |
|
| 462 | + //loop through registrations and trigger messages once per status. |
|
| 463 | + foreach ($all_registrations as $reg) { |
|
| 464 | + |
|
| 465 | + //already triggered? |
|
| 466 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 467 | + continue; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 471 | + $mtgs = array_merge( |
|
| 472 | + $mtgs, |
|
| 473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 474 | + $message_type, |
|
| 475 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 476 | + ) |
|
| 477 | + ); |
|
| 478 | + $statuses_sent[] = $reg->status_ID(); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + $mtgs = array_merge( |
|
| 482 | + $mtgs, |
|
| 483 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 484 | + 'registration_summary', |
|
| 485 | + array($registration->transaction(), null) |
|
| 486 | + ) |
|
| 487 | + ); |
|
| 488 | + |
|
| 489 | + //batch queue and initiate request |
|
| 490 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 491 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 497 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 498 | + * |
|
| 499 | + * @param EE_Registration $registration [description] |
|
| 500 | + * @param array $extra_details [description] |
|
| 501 | + * @return bool true = send away, false = nope halt the presses. |
|
| 502 | + */ |
|
| 503 | + protected static function _verify_registration_notification_send( |
|
| 504 | + EE_Registration $registration, |
|
| 505 | + $extra_details = array() |
|
| 506 | + ) { |
|
| 507 | + //self::log( |
|
| 508 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 509 | + // $registration->transaction(), |
|
| 510 | + // array( '$extra_details' => $extra_details ) |
|
| 511 | + //); |
|
| 512 | + // currently only using this to send messages for the primary registrant |
|
| 513 | + if (! $registration->is_primary_registrant()) { |
|
| 514 | + return false; |
|
| 515 | + } |
|
| 516 | + // first we check if we're in admin and not doing front ajax |
|
| 517 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 518 | + //make sure appropriate admin params are set for sending messages |
|
| 519 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 520 | + //no messages sent please. |
|
| 521 | + return false; |
|
| 522 | + } |
|
| 523 | + } else { |
|
| 524 | + // frontend request (either regular or via AJAX) |
|
| 525 | + // TXN is NOT finalized ? |
|
| 526 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 527 | + return false; |
|
| 528 | + } |
|
| 529 | + // return visit but nothing changed ??? |
|
| 530 | + if ( |
|
| 531 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 532 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 533 | + ) { |
|
| 534 | + return false; |
|
| 535 | + } |
|
| 536 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 537 | + if ( |
|
| 538 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 539 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 540 | + ) { |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + // release the kraken |
|
| 545 | + return true; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 551 | + * status id. |
|
| 552 | + * |
|
| 553 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 554 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 555 | + * @param string $reg_status |
|
| 556 | + * @return array |
|
| 557 | + */ |
|
| 558 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 559 | + { |
|
| 560 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 561 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 562 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 563 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Simply returns the payment message type for the given payment status. |
|
| 569 | + * |
|
| 570 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 571 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 572 | + * @param string $payment_status The payment status being matched. |
|
| 573 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
| 574 | + */ |
|
| 575 | + protected static function _get_payment_message_type($payment_status) |
|
| 576 | + { |
|
| 577 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 578 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 579 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 580 | + : false; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 586 | + * |
|
| 587 | + * @access public |
|
| 588 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 589 | + * @return bool success/fail |
|
| 590 | + */ |
|
| 591 | + public static function process_resend($req_data) |
|
| 592 | + { |
|
| 593 | + self::_load_controller(); |
|
| 594 | + |
|
| 595 | + //if $msgID in this request then skip to the new resend_message |
|
| 596 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 597 | + return self::resend_message(); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 601 | + $req_data = (array)$req_data; |
|
| 602 | + foreach ($req_data as $request_key => $request_value) { |
|
| 603 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + try { |
|
| 611 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 612 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 613 | + } catch (EE_Error $e) { |
|
| 614 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 615 | + return false; |
|
| 616 | + } |
|
| 617 | + EE_Error::add_success( |
|
| 618 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 619 | + ); |
|
| 620 | + return true; //everything got queued. |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 626 | + * |
|
| 627 | + * @return bool |
|
| 628 | + */ |
|
| 629 | + public static function resend_message() |
|
| 630 | + { |
|
| 631 | + self::_load_controller(); |
|
| 632 | + |
|
| 633 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 634 | + if (! $msgID) { |
|
| 635 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 636 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 637 | + return false; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 641 | + |
|
| 642 | + //setup success message. |
|
| 643 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 644 | + EE_Error::add_success(sprintf( |
|
| 645 | + _n( |
|
| 646 | + 'There was %d message queued for resending.', |
|
| 647 | + 'There were %d messages queued for resending.', |
|
| 648 | + $count_ready_for_resend, |
|
| 649 | + 'event_espresso' |
|
| 650 | + ), |
|
| 651 | + $count_ready_for_resend |
|
| 652 | + )); |
|
| 653 | + return true; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Message triggers for manual payment applied by admin |
|
| 659 | + * |
|
| 660 | + * @param EE_Payment $payment EE_payment object |
|
| 661 | + * @return bool success/fail |
|
| 662 | + */ |
|
| 663 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 664 | + { |
|
| 665 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 666 | + //we need to get the transaction object |
|
| 667 | + $transaction = $payment->transaction(); |
|
| 668 | + if ($transaction instanceof EE_Transaction) { |
|
| 669 | + $data = array($transaction, $payment); |
|
| 670 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 671 | + |
|
| 672 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 673 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 674 | + |
|
| 675 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 676 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 677 | + |
|
| 678 | + self::_load_controller(); |
|
| 679 | + |
|
| 680 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 681 | + |
|
| 682 | + //get count of queued for generation |
|
| 683 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 684 | + EEM_Message::status_incomplete, |
|
| 685 | + EEM_Message::status_idle, |
|
| 686 | + )); |
|
| 687 | + |
|
| 688 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 689 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 690 | + return true; |
|
| 691 | + } else { |
|
| 692 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 693 | + /** |
|
| 694 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 695 | + * IMMEDIATE generation. |
|
| 696 | + */ |
|
| 697 | + if ($count_failed > 0) { |
|
| 698 | + EE_Error::add_error(sprintf( |
|
| 699 | + _n( |
|
| 700 | + 'The payment notification generation failed.', |
|
| 701 | + '%d payment notifications failed being sent.', |
|
| 702 | + $count_failed, |
|
| 703 | + 'event_espresso' |
|
| 704 | + ), |
|
| 705 | + $count_failed |
|
| 706 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
| 707 | + |
|
| 708 | + return false; |
|
| 709 | + } else { |
|
| 710 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 711 | + return true; |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + } else { |
|
| 715 | + EE_Error::add_error( |
|
| 716 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 717 | + 'event_espresso' |
|
| 718 | + ); |
|
| 719 | + return false; |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 726 | + * |
|
| 727 | + * @since 4.3.0 |
|
| 728 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 729 | + * @param int $grp_id a specific message template group id. |
|
| 730 | + * @return void |
|
| 731 | + */ |
|
| 732 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 733 | + { |
|
| 734 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 735 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 736 | + self::_load_controller(); |
|
| 737 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 743 | + * |
|
| 744 | + * @since 4.3.0 |
|
| 745 | + * @param string $registration_message_trigger_url |
|
| 746 | + * @param EE_Registration $registration |
|
| 747 | + * @param string $messenger |
|
| 748 | + * @param string $message_type |
|
| 749 | + * @return string |
|
| 750 | + */ |
|
| 751 | + public static function registration_message_trigger_url( |
|
| 752 | + $registration_message_trigger_url, |
|
| 753 | + EE_Registration $registration, |
|
| 754 | + $messenger = 'html', |
|
| 755 | + $message_type = 'invoice' |
|
| 756 | + ) { |
|
| 757 | + // whitelist $messenger |
|
| 758 | + switch ($messenger) { |
|
| 759 | + case 'pdf' : |
|
| 760 | + $sending_messenger = 'pdf'; |
|
| 761 | + $generating_messenger = 'html'; |
|
| 762 | + break; |
|
| 763 | + case 'html' : |
|
| 764 | + default : |
|
| 765 | + $sending_messenger = 'html'; |
|
| 766 | + $generating_messenger = 'html'; |
|
| 767 | + break; |
|
| 768 | + } |
|
| 769 | + // whitelist $message_type |
|
| 770 | + switch ($message_type) { |
|
| 771 | + case 'receipt' : |
|
| 772 | + $message_type = 'receipt'; |
|
| 773 | + break; |
|
| 774 | + case 'invoice' : |
|
| 775 | + default : |
|
| 776 | + $message_type = 'invoice'; |
|
| 777 | + break; |
|
| 778 | + } |
|
| 779 | + // verify that both the messenger AND the message type are active |
|
| 780 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 781 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 782 | + $template_query_params = array( |
|
| 783 | + 'MTP_is_active' => true, |
|
| 784 | + 'MTP_messenger' => $generating_messenger, |
|
| 785 | + 'MTP_message_type' => $message_type, |
|
| 786 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 787 | + ); |
|
| 788 | + //get the message template group. |
|
| 789 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 790 | + //if we don't have an EE_Message_Template_Group then return |
|
| 791 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 792 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 793 | + unset($template_query_params['Event.EVT_ID']); |
|
| 794 | + //get global template as the fallback |
|
| 795 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 796 | + } |
|
| 797 | + //if we don't have an EE_Message_Template_Group then return |
|
| 798 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 799 | + return ''; |
|
| 800 | + } |
|
| 801 | + // generate the URL |
|
| 802 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 803 | + $sending_messenger, |
|
| 804 | + $generating_messenger, |
|
| 805 | + 'purchaser', |
|
| 806 | + $message_type, |
|
| 807 | + $registration, |
|
| 808 | + $msg_template_group->ID(), |
|
| 809 | + $registration->transaction_ID() |
|
| 810 | + ); |
|
| 811 | + |
|
| 812 | + } |
|
| 813 | + return $registration_message_trigger_url; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + /** |
|
| 818 | + * Use to generate and return a message preview! |
|
| 819 | + * |
|
| 820 | + * @param string $type This should correspond with a valid message type |
|
| 821 | + * @param string $context This should correspond with a valid context for the message type |
|
| 822 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 823 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 824 | + * preview |
|
| 825 | + * @return string|bool The body of the message or if send is requested, sends. |
|
| 826 | + */ |
|
| 827 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 828 | + { |
|
| 829 | + self::_load_controller(); |
|
| 830 | + $mtg = new EE_Message_To_Generate( |
|
| 831 | + $messenger, |
|
| 832 | + $type, |
|
| 833 | + array(), |
|
| 834 | + $context, |
|
| 835 | + true |
|
| 836 | + ); |
|
| 837 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 838 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 839 | + return $generated_preview_queue->get_message_repository()->current()->content(); |
|
| 840 | + } else { |
|
| 841 | + return $generated_preview_queue; |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 848 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 849 | + * content found in the EE_Message objects in the queue. |
|
| 850 | + * |
|
| 851 | + * @since 4.9.0 |
|
| 852 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 853 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 854 | + * type name is still required to send along the message type to the |
|
| 855 | + * messenger because this is used for determining what specific |
|
| 856 | + * variations might be loaded for the generated message. |
|
| 857 | + * @param EE_Messages_Queue $queue |
|
| 858 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 859 | + * aggregate EE_Message object. |
|
| 860 | + * @return bool success or fail. |
|
| 861 | + */ |
|
| 862 | + public static function send_message_with_messenger_only( |
|
| 863 | + $messenger, |
|
| 864 | + $message_type, |
|
| 865 | + EE_Messages_Queue $queue, |
|
| 866 | + $custom_subject = '' |
|
| 867 | + ) { |
|
| 868 | + self::_load_controller(); |
|
| 869 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 870 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 871 | + 'Message_To_Generate_From_Queue', |
|
| 872 | + array( |
|
| 873 | + $messenger, |
|
| 874 | + $message_type, |
|
| 875 | + $queue, |
|
| 876 | + $custom_subject, |
|
| 877 | + ) |
|
| 878 | + ); |
|
| 879 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 885 | + * |
|
| 886 | + * @since 4.9.0 |
|
| 887 | + * @param array $message_ids An array of message ids |
|
| 888 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 889 | + * messages. |
|
| 890 | + */ |
|
| 891 | + public static function generate_now($message_ids) |
|
| 892 | + { |
|
| 893 | + self::_load_controller(); |
|
| 894 | + $messages = EEM_Message::instance()->get_all( |
|
| 895 | + array( |
|
| 896 | + 0 => array( |
|
| 897 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 898 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 899 | + ), |
|
| 900 | + ) |
|
| 901 | + ); |
|
| 902 | + $generated_queue = false; |
|
| 903 | + if ($messages) { |
|
| 904 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 908 | + EE_Error::add_error( |
|
| 909 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 910 | + 'event_espresso'), |
|
| 911 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + return $generated_queue; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 920 | + * EEM_Message::status_idle |
|
| 921 | + * |
|
| 922 | + * @since 4.9.0 |
|
| 923 | + * @param $message_ids |
|
| 924 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
| 925 | + */ |
|
| 926 | + public static function send_now($message_ids) |
|
| 927 | + { |
|
| 928 | + self::_load_controller(); |
|
| 929 | + $messages = EEM_Message::instance()->get_all( |
|
| 930 | + array( |
|
| 931 | + 0 => array( |
|
| 932 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 933 | + 'STS_ID' => array( |
|
| 934 | + 'IN', |
|
| 935 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 936 | + ), |
|
| 937 | + ), |
|
| 938 | + ) |
|
| 939 | + ); |
|
| 940 | + $sent_queue = false; |
|
| 941 | + if ($messages) { |
|
| 942 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 946 | + EE_Error::add_error( |
|
| 947 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 948 | + 'event_espresso'), |
|
| 949 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 950 | + ); |
|
| 951 | + } else { |
|
| 952 | + //can count how many sent by using the messages in the queue |
|
| 953 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 954 | + if ($sent_count > 0) { |
|
| 955 | + EE_Error::add_success( |
|
| 956 | + sprintf( |
|
| 957 | + _n( |
|
| 958 | + 'There was %d message successfully sent.', |
|
| 959 | + 'There were %d messages successfully sent.', |
|
| 960 | + $sent_count, |
|
| 961 | + 'event_espresso' |
|
| 962 | + ), |
|
| 963 | + $sent_count |
|
| 964 | + ) |
|
| 965 | + ); |
|
| 966 | + } else { |
|
| 967 | + EE_Error::overwrite_errors(); |
|
| 968 | + EE_Error::add_error( |
|
| 969 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 970 | 970 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 971 | - 'event_espresso'), |
|
| 972 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 973 | - ); |
|
| 974 | - } |
|
| 975 | - } |
|
| 976 | - return $sent_queue; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * This will queue the incoming message ids for resending. |
|
| 982 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 983 | - * |
|
| 984 | - * @since 4.9.0 |
|
| 985 | - * @param array $message_ids An array of EE_Message IDs |
|
| 986 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 987 | - * resending. |
|
| 988 | - */ |
|
| 989 | - public static function queue_for_resending($message_ids) |
|
| 990 | - { |
|
| 991 | - self::_load_controller(); |
|
| 992 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 993 | - |
|
| 994 | - //get queue and count |
|
| 995 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 996 | - |
|
| 997 | - if ( |
|
| 998 | - $queue_count > 0 |
|
| 999 | - ) { |
|
| 1000 | - EE_Error::add_success( |
|
| 1001 | - sprintf( |
|
| 1002 | - _n( |
|
| 1003 | - '%d message successfully queued for resending.', |
|
| 1004 | - '%d messages successfully queued for resending.', |
|
| 1005 | - $queue_count, |
|
| 1006 | - 'event_espresso' |
|
| 1007 | - ), |
|
| 1008 | - $queue_count |
|
| 1009 | - ) |
|
| 1010 | - ); |
|
| 1011 | - /** |
|
| 1012 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1013 | - */ |
|
| 1014 | - } elseif ( |
|
| 1015 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1016 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1017 | - ) { |
|
| 1018 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1019 | - if ($queue_count > 0) { |
|
| 1020 | - EE_Error::add_success( |
|
| 1021 | - sprintf( |
|
| 1022 | - _n( |
|
| 1023 | - '%d message successfully sent.', |
|
| 1024 | - '%d messages successfully sent.', |
|
| 1025 | - $queue_count, |
|
| 1026 | - 'event_espresso' |
|
| 1027 | - ), |
|
| 1028 | - $queue_count |
|
| 1029 | - ) |
|
| 1030 | - ); |
|
| 1031 | - } else { |
|
| 1032 | - EE_Error::add_error( |
|
| 1033 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1034 | - 'event_espresso'), |
|
| 1035 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1036 | - ); |
|
| 1037 | - } |
|
| 1038 | - } else { |
|
| 1039 | - EE_Error::add_error( |
|
| 1040 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1041 | - 'event_espresso'), |
|
| 1042 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1043 | - ); |
|
| 1044 | - } |
|
| 1045 | - return (bool)$queue_count; |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * debug |
|
| 1051 | - * |
|
| 1052 | - * @param string $class |
|
| 1053 | - * @param string $func |
|
| 1054 | - * @param string $line |
|
| 1055 | - * @param \EE_Transaction $transaction |
|
| 1056 | - * @param array $info |
|
| 1057 | - * @param bool $display_request |
|
| 1058 | - */ |
|
| 1059 | - protected static function log( |
|
| 1060 | - $class = '', |
|
| 1061 | - $func = '', |
|
| 1062 | - $line = '', |
|
| 1063 | - EE_Transaction $transaction, |
|
| 1064 | - $info = array(), |
|
| 1065 | - $display_request = false |
|
| 1066 | - ) { |
|
| 1067 | - if (WP_DEBUG && false) { |
|
| 1068 | - if ($transaction instanceof EE_Transaction) { |
|
| 1069 | - // don't serialize objects |
|
| 1070 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1071 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1072 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1073 | - if ($transaction->ID()) { |
|
| 1074 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1075 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1076 | - } |
|
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * Resets all the static properties in this class when called. |
|
| 1085 | - */ |
|
| 1086 | - public static function reset() |
|
| 1087 | - { |
|
| 1088 | - self::$_EEMSG = null; |
|
| 1089 | - self::$_message_resource_manager = null; |
|
| 1090 | - self::$_MSG_PROCESSOR = null; |
|
| 1091 | - self::$_MSG_PATHS = null; |
|
| 1092 | - self::$_TMP_PACKS = array(); |
|
| 1093 | - } |
|
| 971 | + 'event_espresso'), |
|
| 972 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | + } |
|
| 976 | + return $sent_queue; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * This will queue the incoming message ids for resending. |
|
| 982 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 983 | + * |
|
| 984 | + * @since 4.9.0 |
|
| 985 | + * @param array $message_ids An array of EE_Message IDs |
|
| 986 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 987 | + * resending. |
|
| 988 | + */ |
|
| 989 | + public static function queue_for_resending($message_ids) |
|
| 990 | + { |
|
| 991 | + self::_load_controller(); |
|
| 992 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 993 | + |
|
| 994 | + //get queue and count |
|
| 995 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 996 | + |
|
| 997 | + if ( |
|
| 998 | + $queue_count > 0 |
|
| 999 | + ) { |
|
| 1000 | + EE_Error::add_success( |
|
| 1001 | + sprintf( |
|
| 1002 | + _n( |
|
| 1003 | + '%d message successfully queued for resending.', |
|
| 1004 | + '%d messages successfully queued for resending.', |
|
| 1005 | + $queue_count, |
|
| 1006 | + 'event_espresso' |
|
| 1007 | + ), |
|
| 1008 | + $queue_count |
|
| 1009 | + ) |
|
| 1010 | + ); |
|
| 1011 | + /** |
|
| 1012 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1013 | + */ |
|
| 1014 | + } elseif ( |
|
| 1015 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1016 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1017 | + ) { |
|
| 1018 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1019 | + if ($queue_count > 0) { |
|
| 1020 | + EE_Error::add_success( |
|
| 1021 | + sprintf( |
|
| 1022 | + _n( |
|
| 1023 | + '%d message successfully sent.', |
|
| 1024 | + '%d messages successfully sent.', |
|
| 1025 | + $queue_count, |
|
| 1026 | + 'event_espresso' |
|
| 1027 | + ), |
|
| 1028 | + $queue_count |
|
| 1029 | + ) |
|
| 1030 | + ); |
|
| 1031 | + } else { |
|
| 1032 | + EE_Error::add_error( |
|
| 1033 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1034 | + 'event_espresso'), |
|
| 1035 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1036 | + ); |
|
| 1037 | + } |
|
| 1038 | + } else { |
|
| 1039 | + EE_Error::add_error( |
|
| 1040 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1041 | + 'event_espresso'), |
|
| 1042 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1043 | + ); |
|
| 1044 | + } |
|
| 1045 | + return (bool)$queue_count; |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * debug |
|
| 1051 | + * |
|
| 1052 | + * @param string $class |
|
| 1053 | + * @param string $func |
|
| 1054 | + * @param string $line |
|
| 1055 | + * @param \EE_Transaction $transaction |
|
| 1056 | + * @param array $info |
|
| 1057 | + * @param bool $display_request |
|
| 1058 | + */ |
|
| 1059 | + protected static function log( |
|
| 1060 | + $class = '', |
|
| 1061 | + $func = '', |
|
| 1062 | + $line = '', |
|
| 1063 | + EE_Transaction $transaction, |
|
| 1064 | + $info = array(), |
|
| 1065 | + $display_request = false |
|
| 1066 | + ) { |
|
| 1067 | + if (WP_DEBUG && false) { |
|
| 1068 | + if ($transaction instanceof EE_Transaction) { |
|
| 1069 | + // don't serialize objects |
|
| 1070 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1071 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1072 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1073 | + if ($transaction->ID()) { |
|
| 1074 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1075 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1076 | + } |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * Resets all the static properties in this class when called. |
|
| 1085 | + */ |
|
| 1086 | + public static function reset() |
|
| 1087 | + { |
|
| 1088 | + self::$_EEMSG = null; |
|
| 1089 | + self::$_message_resource_manager = null; |
|
| 1090 | + self::$_MSG_PROCESSOR = null; |
|
| 1091 | + self::$_MSG_PATHS = null; |
|
| 1092 | + self::$_TMP_PACKS = array(); |
|
| 1093 | + } |
|
| 1094 | 1094 | |
| 1095 | 1095 | } |
| 1096 | 1096 | // End of file EED_Messages.module.php |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | //need the MER plugin active for this test (we'll deactivate it after). |
| 16 | 16 | $I->ensurePluginActive( |
| 17 | - 'event-espresso-mer-multi-event-registration', |
|
| 18 | - 'activated' |
|
| 17 | + 'event-espresso-mer-multi-event-registration', |
|
| 18 | + 'activated' |
|
| 19 | 19 | ); |
| 20 | 20 | |
| 21 | 21 | //k now we need to make sure the registration multi-status message type is active because it isn't by default |
@@ -68,42 +68,42 @@ discard block |
||
| 68 | 68 | $I->loginAsAdmin(); |
| 69 | 69 | $I->amOnMessagesActivityListTablePage(); |
| 70 | 70 | $I->see( |
| 71 | - '[email protected]', |
|
| 72 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 73 | - 'to', |
|
| 74 | - 'Registration Multi-status Summary', |
|
| 75 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 76 | - '', |
|
| 77 | - 'Primary Registrant' |
|
| 78 | - ) |
|
| 71 | + '[email protected]', |
|
| 72 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 73 | + 'to', |
|
| 74 | + 'Registration Multi-status Summary', |
|
| 75 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 76 | + '', |
|
| 77 | + 'Primary Registrant' |
|
| 78 | + ) |
|
| 79 | 79 | ); |
| 80 | 80 | $I->see( |
| 81 | - '[email protected]', |
|
| 82 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 83 | - 'to', |
|
| 84 | - 'Registration Multi-status Summary', |
|
| 85 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 86 | - ) |
|
| 81 | + '[email protected]', |
|
| 82 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 83 | + 'to', |
|
| 84 | + 'Registration Multi-status Summary', |
|
| 85 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 86 | + ) |
|
| 87 | 87 | ); |
| 88 | 88 | //verify count |
| 89 | 89 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 90 | - 1, |
|
| 91 | - '[email protected]', |
|
| 92 | - 'to', |
|
| 93 | - 'Registration Multi-status Summary', |
|
| 94 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 95 | - 'Email', |
|
| 96 | - 'Primary Registrant' |
|
| 90 | + 1, |
|
| 91 | + '[email protected]', |
|
| 92 | + 'to', |
|
| 93 | + 'Registration Multi-status Summary', |
|
| 94 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 95 | + 'Email', |
|
| 96 | + 'Primary Registrant' |
|
| 97 | 97 | ); |
| 98 | 98 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 99 | - 1, |
|
| 100 | - '[email protected]', |
|
| 101 | - 'to', |
|
| 102 | - 'Registration Multi-status Summary' |
|
| 99 | + 1, |
|
| 100 | + '[email protected]', |
|
| 101 | + 'to', |
|
| 102 | + 'Registration Multi-status Summary' |
|
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | 105 | //deactivate MER plugin so its not active for future tests |
| 106 | 106 | $I->ensurePluginDeactivated( |
| 107 | - 'event-espresso-mer-multi-event-registration', |
|
| 108 | - 'Plugin deactivated' |
|
| 107 | + 'event-espresso-mer-multi-event-registration', |
|
| 108 | + 'Plugin deactivated' |
|
| 109 | 109 | ); |
| 110 | 110 | \ No newline at end of file |