| @@ -23,1703 +23,1703 @@ | ||
| 23 | 23 | class EE_Registry implements ResettableInterface | 
| 24 | 24 |  { | 
| 25 | 25 | |
| 26 | - /** | |
| 27 | - * @var EE_Registry $_instance | |
| 28 | - */ | |
| 29 | - private static $_instance; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @var EE_Dependency_Map $_dependency_map | |
| 33 | - */ | |
| 34 | - protected $_dependency_map; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * @var Mirror | |
| 38 | - */ | |
| 39 | - private $mirror; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * @var ClassInterfaceCache $class_cache | |
| 43 | - */ | |
| 44 | - private $class_cache; | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * @var array $_class_abbreviations | |
| 48 | - */ | |
| 49 | - protected $_class_abbreviations = array(); | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @var CommandBusInterface $BUS | |
| 53 | - */ | |
| 54 | - public $BUS; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * @var EE_Cart $CART | |
| 58 | - */ | |
| 59 | - public $CART; | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @var EE_Config $CFG | |
| 63 | - */ | |
| 64 | - public $CFG; | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * @var EE_Network_Config $NET_CFG | |
| 68 | - */ | |
| 69 | - public $NET_CFG; | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * RegistryContainer for storing library classes in | |
| 73 | - * | |
| 74 | - * @var RegistryContainer $LIB | |
| 75 | - */ | |
| 76 | - public $LIB; | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * @var EE_Request_Handler $REQ | |
| 80 | - * @deprecated 4.10.14.p | |
| 81 | - */ | |
| 82 | - public $REQ; | |
| 83 | - | |
| 84 | - /** | |
| 85 | - * @var EE_Session $SSN | |
| 86 | - */ | |
| 87 | - public $SSN; | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * @since 4.5.0 | |
| 91 | - * @var EE_Capabilities $CAP | |
| 92 | - */ | |
| 93 | - public $CAP; | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * @since 4.9.0 | |
| 97 | - * @var EE_Message_Resource_Manager $MRM | |
| 98 | - */ | |
| 99 | - public $MRM; | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * @var Registry $AssetsRegistry | |
| 103 | - */ | |
| 104 | - public $AssetsRegistry; | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * RegistryContainer for holding addons which have registered themselves to work with EE core | |
| 108 | - * | |
| 109 | - * @var EE_Addon[] $addons | |
| 110 | - */ | |
| 111 | - public $addons; | |
| 112 | - | |
| 113 | - /** | |
| 114 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') | |
| 115 | - * | |
| 116 | - * @var EEM_Base[] $models | |
| 117 | - */ | |
| 118 | - public $models = array(); | |
| 119 | - | |
| 120 | - /** | |
| 121 | - * @var EED_Module[] $modules | |
| 122 | - */ | |
| 123 | - public $modules; | |
| 124 | - | |
| 125 | - /** | |
| 126 | - * @var EES_Shortcode[] $shortcodes | |
| 127 | - */ | |
| 128 | - public $shortcodes; | |
| 129 | - | |
| 130 | - /** | |
| 131 | - * @var WP_Widget[] $widgets | |
| 132 | - */ | |
| 133 | - public $widgets; | |
| 134 | - | |
| 135 | - /** | |
| 136 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models | |
| 137 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). | |
| 138 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are | |
| 139 | - * classnames (eg "EEM_Event") | |
| 140 | - * | |
| 141 | - * @var array $non_abstract_db_models | |
| 142 | - */ | |
| 143 | - public $non_abstract_db_models = array(); | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * internationalization for JS strings | |
| 147 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); | |
| 148 | - * in js file: var translatedString = eei18n.string_key; | |
| 149 | - * | |
| 150 | - * @var array $i18n_js_strings | |
| 151 | - */ | |
| 152 | - public static $i18n_js_strings = array(); | |
| 153 | - | |
| 154 | - /** | |
| 155 | - * $main_file - path to espresso.php | |
| 156 | - * | |
| 157 | - * @var array $main_file | |
| 158 | - */ | |
| 159 | - public $main_file; | |
| 160 | - | |
| 161 | - /** | |
| 162 | - * array of ReflectionClass objects where the key is the class name | |
| 163 | - * | |
| 164 | - * @deprecated 4.9.62.p | |
| 165 | - * @var ReflectionClass[] $_reflectors | |
| 166 | - */ | |
| 167 | - public $_reflectors; | |
| 168 | - | |
| 169 | - /** | |
| 170 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache | |
| 171 | - * | |
| 172 | - * @var boolean $_cache_on | |
| 173 | - */ | |
| 174 | - protected $_cache_on = true; | |
| 175 | - | |
| 176 | - /** | |
| 177 | - * @var ObjectIdentifier | |
| 178 | - */ | |
| 179 | - private $object_identifier; | |
| 180 | - | |
| 181 | - | |
| 182 | - /** | |
| 183 | - * @singleton method used to instantiate class object | |
| 184 | - * @param EE_Dependency_Map|null $dependency_map | |
| 185 | - * @param Mirror|null $mirror | |
| 186 | - * @param ClassInterfaceCache|null $class_cache | |
| 187 | - * @param ObjectIdentifier|null $object_identifier | |
| 188 | - * @return EE_Registry instance | |
| 189 | - */ | |
| 190 | - public static function instance( | |
| 191 | - EE_Dependency_Map $dependency_map = null, | |
| 192 | - Mirror $mirror = null, | |
| 193 | - ClassInterfaceCache $class_cache = null, | |
| 194 | - ObjectIdentifier $object_identifier = null | |
| 195 | -    ) { | |
| 196 | - // check if class object is instantiated | |
| 197 | - if ( | |
| 198 | - ! self::$_instance instanceof EE_Registry | |
| 199 | - && $dependency_map instanceof EE_Dependency_Map | |
| 200 | - && $mirror instanceof Mirror | |
| 201 | - && $class_cache instanceof ClassInterfaceCache | |
| 202 | - && $object_identifier instanceof ObjectIdentifier | |
| 203 | -        ) { | |
| 204 | - self::$_instance = new self( | |
| 205 | - $dependency_map, | |
| 206 | - $mirror, | |
| 207 | - $class_cache, | |
| 208 | - $object_identifier | |
| 209 | - ); | |
| 210 | - } | |
| 211 | - return self::$_instance; | |
| 212 | - } | |
| 213 | - | |
| 214 | - | |
| 215 | - /** | |
| 216 | - * protected constructor to prevent direct creation | |
| 217 | - * | |
| 218 | - * @Constructor | |
| 219 | - * @param EE_Dependency_Map $dependency_map | |
| 220 | - * @param Mirror $mirror | |
| 221 | - * @param ClassInterfaceCache $class_cache | |
| 222 | - * @param ObjectIdentifier $object_identifier | |
| 223 | - */ | |
| 224 | - protected function __construct( | |
| 225 | - EE_Dependency_Map $dependency_map, | |
| 226 | - Mirror $mirror, | |
| 227 | - ClassInterfaceCache $class_cache, | |
| 228 | - ObjectIdentifier $object_identifier | |
| 229 | -    ) { | |
| 230 | - $this->_dependency_map = $dependency_map; | |
| 231 | - $this->mirror = $mirror; | |
| 232 | - $this->class_cache = $class_cache; | |
| 233 | - $this->object_identifier = $object_identifier; | |
| 234 | - // $registry_container = new RegistryContainer(); | |
| 235 | - $this->LIB = new RegistryContainer(); | |
| 236 | - $this->addons = new RegistryContainer(); | |
| 237 | - $this->modules = new RegistryContainer(); | |
| 238 | - $this->shortcodes = new RegistryContainer(); | |
| 239 | - $this->widgets = new RegistryContainer(); | |
| 240 | -        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); | |
| 241 | - } | |
| 242 | - | |
| 243 | - | |
| 244 | - /** | |
| 245 | - * initialize | |
| 246 | - * | |
| 247 | - * @throws OutOfBoundsException | |
| 248 | - * @throws InvalidArgumentException | |
| 249 | - * @throws InvalidInterfaceException | |
| 250 | - * @throws InvalidDataTypeException | |
| 251 | - * @throws EE_Error | |
| 252 | - * @throws ReflectionException | |
| 253 | - */ | |
| 254 | - public function initialize() | |
| 255 | -    { | |
| 256 | - $this->_class_abbreviations = apply_filters( | |
| 257 | - 'FHEE__EE_Registry____construct___class_abbreviations', | |
| 258 | - array( | |
| 259 | - 'EE_Config' => 'CFG', | |
| 260 | - 'EE_Session' => 'SSN', | |
| 261 | - 'EE_Capabilities' => 'CAP', | |
| 262 | - 'EE_Cart' => 'CART', | |
| 263 | - 'EE_Network_Config' => 'NET_CFG', | |
| 264 | - 'EE_Request_Handler' => 'REQ', | |
| 265 | - 'EE_Message_Resource_Manager' => 'MRM', | |
| 266 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', | |
| 267 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', | |
| 268 | - ) | |
| 269 | - ); | |
| 270 | -        $this->load_core('Base', array(), true); | |
| 271 | - // add our request and response objects to the cache | |
| 272 | - $request_loader = $this->_dependency_map->class_loader( | |
| 273 | - 'EventEspresso\core\services\request\Request' | |
| 274 | - ); | |
| 275 | - $this->_set_cached_class( | |
| 276 | - $request_loader(), | |
| 277 | - 'EventEspresso\core\services\request\Request' | |
| 278 | - ); | |
| 279 | - $response_loader = $this->_dependency_map->class_loader( | |
| 280 | - 'EventEspresso\core\services\request\Response' | |
| 281 | - ); | |
| 282 | - $this->_set_cached_class( | |
| 283 | - $response_loader(), | |
| 284 | - 'EventEspresso\core\services\request\Response' | |
| 285 | - ); | |
| 286 | -        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); | |
| 287 | - } | |
| 288 | - | |
| 289 | - | |
| 290 | - /** | |
| 291 | - * @return void | |
| 292 | - */ | |
| 293 | - public function init() | |
| 294 | -    { | |
| 295 | - // Get current page protocol | |
| 296 | - $protocol = is_ssl() ? 'https://' : 'http://'; | |
| 297 | - // Output admin-ajax.php URL with same protocol as current page | |
| 298 | -        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); | |
| 299 | -        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') && WP_DEBUG; | |
| 300 | - } | |
| 301 | - | |
| 302 | - | |
| 303 | - /** | |
| 304 | - * @return array | |
| 305 | - */ | |
| 306 | - public static function sanitize_i18n_js_strings() | |
| 307 | -    { | |
| 308 | - $i18n_js_strings = (array) self::$i18n_js_strings; | |
| 309 | -        foreach ($i18n_js_strings as $key => $value) { | |
| 310 | -            if (is_scalar($value)) { | |
| 311 | - $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); | |
| 312 | - $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); | |
| 313 | - } | |
| 314 | - } | |
| 315 | - return $i18n_js_strings; | |
| 316 | - } | |
| 317 | - | |
| 318 | - | |
| 319 | - /** | |
| 320 | - * localize_i18n_js_strings | |
| 321 | - * | |
| 322 | - * @return string | |
| 323 | - */ | |
| 324 | - public static function localize_i18n_js_strings() | |
| 325 | -    { | |
| 326 | - $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); | |
| 327 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; | |
| 328 | - } | |
| 329 | - | |
| 330 | - | |
| 331 | - /** | |
| 332 | - * @param mixed string | EED_Module $module | |
| 333 | - * @throws OutOfBoundsException | |
| 334 | - * @throws InvalidArgumentException | |
| 335 | - * @throws InvalidInterfaceException | |
| 336 | - * @throws InvalidDataTypeException | |
| 337 | - * @throws EE_Error | |
| 338 | - * @throws ReflectionException | |
| 339 | - */ | |
| 340 | - public function add_module($module) | |
| 341 | -    { | |
| 342 | -        if ($module instanceof EED_Module) { | |
| 343 | - $module_class = get_class($module); | |
| 344 | - $this->modules->add($module_class, $module); | |
| 345 | -        } else { | |
| 346 | -            if (! class_exists('EE_Module_Request_Router', false)) { | |
| 347 | -                $this->load_core('Module_Request_Router'); | |
| 348 | - } | |
| 349 | - EE_Module_Request_Router::module_factory($module); | |
| 350 | - } | |
| 351 | - } | |
| 352 | - | |
| 353 | - | |
| 354 | - /** | |
| 355 | - * @param string $module_name | |
| 356 | - * @return mixed EED_Module | NULL | |
| 357 | - */ | |
| 358 | - public function get_module($module_name = '') | |
| 359 | -    { | |
| 360 | - return $this->modules->get($module_name); | |
| 361 | - } | |
| 362 | - | |
| 363 | - | |
| 364 | - /** | |
| 365 | - * loads core classes - must be singletons | |
| 366 | - * | |
| 367 | - * @param string $class_name - simple class name ie: session | |
| 368 | - * @param mixed $arguments | |
| 369 | - * @param bool $load_only | |
| 370 | - * @return mixed | |
| 371 | - * @throws InvalidInterfaceException | |
| 372 | - * @throws InvalidDataTypeException | |
| 373 | - * @throws EE_Error | |
| 374 | - * @throws ReflectionException | |
| 375 | - * @throws InvalidArgumentException | |
| 376 | - */ | |
| 377 | - public function load_core($class_name, $arguments = array(), $load_only = false) | |
| 378 | -    { | |
| 379 | - $core_paths = apply_filters( | |
| 380 | - 'FHEE__EE_Registry__load_core__core_paths', | |
| 381 | - array( | |
| 382 | - EE_CORE, | |
| 383 | - EE_ADMIN, | |
| 384 | - EE_CPTS, | |
| 385 | - EE_CORE . 'data_migration_scripts/', | |
| 386 | - EE_CORE . 'capabilities/', | |
| 387 | - EE_CORE . 'request_stack/', | |
| 388 | - EE_CORE . 'middleware/', | |
| 389 | - ) | |
| 390 | - ); | |
| 391 | - // retrieve instantiated class | |
| 392 | - return $this->_load( | |
| 393 | - $core_paths, | |
| 394 | - 'EE_', | |
| 395 | - $class_name, | |
| 396 | - 'core', | |
| 397 | - $arguments, | |
| 398 | - false, | |
| 399 | - true, | |
| 400 | - $load_only | |
| 401 | - ); | |
| 402 | - } | |
| 403 | - | |
| 404 | - | |
| 405 | - /** | |
| 406 | - * loads service classes | |
| 407 | - * | |
| 408 | - * @param string $class_name - simple class name ie: session | |
| 409 | - * @param mixed $arguments | |
| 410 | - * @param bool $load_only | |
| 411 | - * @return mixed | |
| 412 | - * @throws InvalidInterfaceException | |
| 413 | - * @throws InvalidDataTypeException | |
| 414 | - * @throws EE_Error | |
| 415 | - * @throws ReflectionException | |
| 416 | - * @throws InvalidArgumentException | |
| 417 | - */ | |
| 418 | - public function load_service($class_name, $arguments = array(), $load_only = false) | |
| 419 | -    { | |
| 420 | - $service_paths = apply_filters( | |
| 421 | - 'FHEE__EE_Registry__load_service__service_paths', | |
| 422 | - array( | |
| 423 | - EE_CORE . 'services/', | |
| 424 | - ) | |
| 425 | - ); | |
| 426 | - // retrieve instantiated class | |
| 427 | - return $this->_load( | |
| 428 | - $service_paths, | |
| 429 | - 'EE_', | |
| 430 | - $class_name, | |
| 431 | - 'class', | |
| 432 | - $arguments, | |
| 433 | - false, | |
| 434 | - true, | |
| 435 | - $load_only | |
| 436 | - ); | |
| 437 | - } | |
| 438 | - | |
| 439 | - | |
| 440 | - /** | |
| 441 | - * loads data_migration_scripts | |
| 442 | - * | |
| 443 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 | |
| 444 | - * @param mixed $arguments | |
| 445 | - * @return EE_Data_Migration_Script_Base|mixed | |
| 446 | - * @throws InvalidInterfaceException | |
| 447 | - * @throws InvalidDataTypeException | |
| 448 | - * @throws EE_Error | |
| 449 | - * @throws ReflectionException | |
| 450 | - * @throws InvalidArgumentException | |
| 451 | - */ | |
| 452 | - public function load_dms($class_name, $arguments = array()) | |
| 453 | -    { | |
| 454 | - // retrieve instantiated class | |
| 455 | - return $this->_load( | |
| 456 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), | |
| 457 | - 'EE_DMS_', | |
| 458 | - $class_name, | |
| 459 | - 'dms', | |
| 460 | - $arguments, | |
| 461 | - false, | |
| 462 | - false | |
| 463 | - ); | |
| 464 | - } | |
| 465 | - | |
| 466 | - | |
| 467 | - /** | |
| 468 | - * loads object creating classes - must be singletons | |
| 469 | - * | |
| 470 | - * @param string $class_name - simple class name ie: attendee | |
| 471 | - * @param mixed $arguments - an array of arguments to pass to the class | |
| 472 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to | |
| 473 | - * instantiate | |
| 474 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then | |
| 475 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) | |
| 476 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate | |
| 477 | - * (default) | |
| 478 | - * @return EE_Base_Class | bool | |
| 479 | - * @throws InvalidInterfaceException | |
| 480 | - * @throws InvalidDataTypeException | |
| 481 | - * @throws EE_Error | |
| 482 | - * @throws ReflectionException | |
| 483 | - * @throws InvalidArgumentException | |
| 484 | - */ | |
| 485 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) | |
| 486 | -    { | |
| 487 | - $paths = apply_filters( | |
| 488 | - 'FHEE__EE_Registry__load_class__paths', | |
| 489 | - array( | |
| 490 | - EE_CORE, | |
| 491 | - EE_CLASSES, | |
| 492 | - EE_BUSINESS, | |
| 493 | - ) | |
| 494 | - ); | |
| 495 | - // retrieve instantiated class | |
| 496 | - return $this->_load( | |
| 497 | - $paths, | |
| 498 | - 'EE_', | |
| 499 | - $class_name, | |
| 500 | - 'class', | |
| 501 | - $arguments, | |
| 502 | - $from_db, | |
| 503 | - $cache, | |
| 504 | - $load_only | |
| 505 | - ); | |
| 506 | - } | |
| 507 | - | |
| 508 | - | |
| 509 | - /** | |
| 510 | - * loads helper classes - must be singletons | |
| 511 | - * | |
| 512 | - * @param string $class_name - simple class name ie: price | |
| 513 | - * @param mixed $arguments | |
| 514 | - * @param bool $load_only | |
| 515 | - * @return EEH_Base | bool | |
| 516 | - * @throws InvalidInterfaceException | |
| 517 | - * @throws InvalidDataTypeException | |
| 518 | - * @throws EE_Error | |
| 519 | - * @throws ReflectionException | |
| 520 | - * @throws InvalidArgumentException | |
| 521 | - */ | |
| 522 | - public function load_helper($class_name, $arguments = array(), $load_only = true) | |
| 523 | -    { | |
| 524 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed | |
| 525 | -        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); | |
| 526 | - // retrieve instantiated class | |
| 527 | - return $this->_load( | |
| 528 | - $helper_paths, | |
| 529 | - 'EEH_', | |
| 530 | - $class_name, | |
| 531 | - 'helper', | |
| 532 | - $arguments, | |
| 533 | - false, | |
| 534 | - true, | |
| 535 | - $load_only | |
| 536 | - ); | |
| 537 | - } | |
| 538 | - | |
| 539 | - | |
| 540 | - /** | |
| 541 | - * loads core classes - must be singletons | |
| 542 | - * | |
| 543 | - * @param string $class_name - simple class name ie: session | |
| 544 | - * @param mixed $arguments | |
| 545 | - * @param bool $load_only | |
| 546 | - * @param bool $cache whether to cache the object or not. | |
| 547 | - * @return mixed | |
| 548 | - * @throws InvalidInterfaceException | |
| 549 | - * @throws InvalidDataTypeException | |
| 550 | - * @throws EE_Error | |
| 551 | - * @throws ReflectionException | |
| 552 | - * @throws InvalidArgumentException | |
| 553 | - */ | |
| 554 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) | |
| 555 | -    { | |
| 556 | - $paths = array( | |
| 557 | - EE_LIBRARIES, | |
| 558 | - EE_LIBRARIES . 'messages/', | |
| 559 | - EE_LIBRARIES . 'shortcodes/', | |
| 560 | - EE_LIBRARIES . 'qtips/', | |
| 561 | - EE_LIBRARIES . 'payment_methods/', | |
| 562 | - ); | |
| 563 | - // retrieve instantiated class | |
| 564 | - return $this->_load( | |
| 565 | - $paths, | |
| 566 | - 'EE_', | |
| 567 | - $class_name, | |
| 568 | - 'lib', | |
| 569 | - $arguments, | |
| 570 | - false, | |
| 571 | - $cache, | |
| 572 | - $load_only | |
| 573 | - ); | |
| 574 | - } | |
| 575 | - | |
| 576 | - | |
| 577 | - /** | |
| 578 | - * loads model classes - must be singletons | |
| 579 | - * | |
| 580 | - * @param string $class_name - simple class name ie: price | |
| 581 | - * @param mixed $arguments | |
| 582 | - * @param bool $load_only | |
| 583 | - * @return EEM_Base | bool | |
| 584 | - * @throws InvalidInterfaceException | |
| 585 | - * @throws InvalidDataTypeException | |
| 586 | - * @throws EE_Error | |
| 587 | - * @throws ReflectionException | |
| 588 | - * @throws InvalidArgumentException | |
| 589 | - */ | |
| 590 | - public function load_model($class_name, $arguments = array(), $load_only = false) | |
| 591 | -    { | |
| 592 | - $paths = apply_filters( | |
| 593 | - 'FHEE__EE_Registry__load_model__paths', | |
| 594 | - array( | |
| 595 | - EE_MODELS, | |
| 596 | - EE_CORE, | |
| 597 | - ) | |
| 598 | - ); | |
| 599 | - // retrieve instantiated class | |
| 600 | - return $this->_load( | |
| 601 | - $paths, | |
| 602 | - 'EEM_', | |
| 603 | - $class_name, | |
| 604 | - 'model', | |
| 605 | - $arguments, | |
| 606 | - false, | |
| 607 | - true, | |
| 608 | - $load_only | |
| 609 | - ); | |
| 610 | - } | |
| 611 | - | |
| 612 | - | |
| 613 | - /** | |
| 614 | - * loads model classes - must be singletons | |
| 615 | - * | |
| 616 | - * @param string $class_name - simple class name ie: price | |
| 617 | - * @param mixed $arguments | |
| 618 | - * @param bool $load_only | |
| 619 | - * @return mixed | bool | |
| 620 | - * @throws InvalidInterfaceException | |
| 621 | - * @throws InvalidDataTypeException | |
| 622 | - * @throws EE_Error | |
| 623 | - * @throws ReflectionException | |
| 624 | - * @throws InvalidArgumentException | |
| 625 | - */ | |
| 626 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) | |
| 627 | -    { | |
| 628 | - $paths = array( | |
| 629 | - EE_MODELS . 'fields/', | |
| 630 | - EE_MODELS . 'helpers/', | |
| 631 | - EE_MODELS . 'relations/', | |
| 632 | - EE_MODELS . 'strategies/', | |
| 633 | - ); | |
| 634 | - // retrieve instantiated class | |
| 635 | - return $this->_load( | |
| 636 | - $paths, | |
| 637 | - 'EE_', | |
| 638 | - $class_name, | |
| 639 | - '', | |
| 640 | - $arguments, | |
| 641 | - false, | |
| 642 | - true, | |
| 643 | - $load_only | |
| 644 | - ); | |
| 645 | - } | |
| 646 | - | |
| 647 | - | |
| 648 | - /** | |
| 649 | - * Determines if $model_name is the name of an actual EE model. | |
| 650 | - * | |
| 651 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. | |
| 652 | - * @return boolean | |
| 653 | - */ | |
| 654 | - public function is_model_name($model_name) | |
| 655 | -    { | |
| 656 | - return isset($this->models[ $model_name ]); | |
| 657 | - } | |
| 658 | - | |
| 659 | - | |
| 660 | - /** | |
| 661 | - * generic class loader | |
| 662 | - * | |
| 663 | - * @param string $path_to_file - directory path to file location, not including filename | |
| 664 | - * @param string $file_name - file name ie: my_file.php, including extension | |
| 665 | - * @param string $type - file type - core? class? helper? model? | |
| 666 | - * @param mixed $arguments | |
| 667 | - * @param bool $load_only | |
| 668 | - * @return mixed | |
| 669 | - * @throws InvalidInterfaceException | |
| 670 | - * @throws InvalidDataTypeException | |
| 671 | - * @throws EE_Error | |
| 672 | - * @throws ReflectionException | |
| 673 | - * @throws InvalidArgumentException | |
| 674 | - */ | |
| 675 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) | |
| 676 | -    { | |
| 677 | - // retrieve instantiated class | |
| 678 | - return $this->_load( | |
| 679 | - $path_to_file, | |
| 680 | - '', | |
| 681 | - $file_name, | |
| 682 | - $type, | |
| 683 | - $arguments, | |
| 684 | - false, | |
| 685 | - true, | |
| 686 | - $load_only | |
| 687 | - ); | |
| 688 | - } | |
| 689 | - | |
| 690 | - | |
| 691 | - /** | |
| 692 | - * @param string $path_to_file - directory path to file location, not including filename | |
| 693 | - * @param string $class_name - full class name ie: My_Class | |
| 694 | - * @param string $type - file type - core? class? helper? model? | |
| 695 | - * @param mixed $arguments | |
| 696 | - * @param bool $load_only | |
| 697 | - * @return bool|EE_Addon|object | |
| 698 | - * @throws InvalidInterfaceException | |
| 699 | - * @throws InvalidDataTypeException | |
| 700 | - * @throws EE_Error | |
| 701 | - * @throws ReflectionException | |
| 702 | - * @throws InvalidArgumentException | |
| 703 | - */ | |
| 704 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) | |
| 705 | -    { | |
| 706 | - // retrieve instantiated class | |
| 707 | - return $this->_load( | |
| 708 | - $path_to_file, | |
| 709 | - 'addon', | |
| 710 | - $class_name, | |
| 711 | - $type, | |
| 712 | - $arguments, | |
| 713 | - false, | |
| 714 | - true, | |
| 715 | - $load_only | |
| 716 | - ); | |
| 717 | - } | |
| 718 | - | |
| 719 | - | |
| 720 | - /** | |
| 721 | - * instantiates, caches, and automatically resolves dependencies | |
| 722 | - * for classes that use a Fully Qualified Class Name. | |
| 723 | - * if the class is not capable of being loaded using PSR-4 autoloading, | |
| 724 | - * then you need to use one of the existing load_*() methods | |
| 725 | - * which can resolve the classname and filepath from the passed arguments | |
| 726 | - * | |
| 727 | - * @param bool|string $class_name Fully Qualified Class Name | |
| 728 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation | |
| 729 | - * @param bool $cache whether to cache the instantiated object for reuse | |
| 730 | - * @param bool $from_db some classes are instantiated from the db | |
| 731 | - * and thus call a different method to instantiate | |
| 732 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object | |
| 733 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array | |
| 734 | - * @return bool|null|mixed null = failure to load or instantiate class object. | |
| 735 | - * object = class loaded and instantiated successfully. | |
| 736 | - * bool = fail or success when $load_only is true | |
| 737 | - * @throws InvalidInterfaceException | |
| 738 | - * @throws InvalidDataTypeException | |
| 739 | - * @throws EE_Error | |
| 740 | - * @throws ReflectionException | |
| 741 | - * @throws InvalidArgumentException | |
| 742 | - */ | |
| 743 | - public function create( | |
| 744 | - $class_name = false, | |
| 745 | - $arguments = array(), | |
| 746 | - $cache = false, | |
| 747 | - $from_db = false, | |
| 748 | - $load_only = false, | |
| 749 | - $addon = false | |
| 750 | -    ) { | |
| 751 | - $class_name = ltrim($class_name, '\\'); | |
| 752 | - $class_name = $this->class_cache->getFqnForAlias($class_name); | |
| 753 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); | |
| 754 | - // if a non-FQCN was passed, then | |
| 755 | - // verifyClassExists() might return an object | |
| 756 | - // or it could return null if the class just could not be found anywhere | |
| 757 | -        if ($class_exists instanceof $class_name || $class_exists === null) { | |
| 758 | - // either way, return the results | |
| 759 | - return $class_exists; | |
| 760 | - } | |
| 761 | - $class_name = $class_exists; | |
| 762 | - // if we're only loading the class and it already exists, then let's just return true immediately | |
| 763 | -        if ($load_only) { | |
| 764 | - return true; | |
| 765 | - } | |
| 766 | - $addon = $addon ? 'addon' : ''; | |
| 767 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection | |
| 768 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() | |
| 769 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() | |
| 770 | -        if ($this->_cache_on && $cache && ! $load_only) { | |
| 771 | - // return object if it's already cached | |
| 772 | - $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); | |
| 773 | -            if ($cached_class !== null) { | |
| 774 | - return $cached_class; | |
| 775 | - } | |
| 776 | - }// obtain the loader method from the dependency map | |
| 777 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object | |
| 778 | -        if ($loader instanceof Closure) { | |
| 779 | - $class_obj = $loader($arguments); | |
| 780 | -        } else { | |
| 781 | -            if ($loader && method_exists($this, $loader)) { | |
| 782 | -                $class_obj = $this->{$loader}($class_name, $arguments); | |
| 783 | -            } else { | |
| 784 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); | |
| 785 | - } | |
| 786 | - } | |
| 787 | -        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { | |
| 788 | -            // save it for later... kinda like gum  { : $ | |
| 789 | - $this->_set_cached_class( | |
| 790 | - $class_obj, | |
| 791 | - $class_name, | |
| 792 | - $addon, | |
| 793 | - $from_db, | |
| 794 | - $arguments | |
| 795 | - ); | |
| 796 | - } | |
| 797 | - $this->_cache_on = true; | |
| 798 | - return $class_obj; | |
| 799 | - } | |
| 800 | - | |
| 801 | - | |
| 802 | - /** | |
| 803 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs | |
| 804 | - * | |
| 805 | - * @param string|object $class_name | |
| 806 | - * @param array $arguments | |
| 807 | - * @param int $attempt | |
| 808 | - * @return mixed | |
| 809 | - */ | |
| 810 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) | |
| 811 | -    { | |
| 812 | -        if (is_object($class_name) || class_exists($class_name)) { | |
| 813 | - return $class_name; | |
| 814 | - } | |
| 815 | -        switch ($attempt) { | |
| 816 | - case 1: | |
| 817 | - // if it's a FQCN then maybe the class is registered with a preceding \ | |
| 818 | - $class_name = strpos($class_name, '\\') !== false | |
| 819 | - ? '\\' . ltrim($class_name, '\\') | |
| 820 | - : $class_name; | |
| 821 | - break; | |
| 822 | - case 2: | |
| 823 | - // | |
| 824 | - $loader = $this->_dependency_map->class_loader($class_name); | |
| 825 | -                if ($loader && method_exists($this, $loader)) { | |
| 826 | -                    return $this->{$loader}($class_name, $arguments); | |
| 827 | - } | |
| 828 | - break; | |
| 829 | - case 3: | |
| 830 | - default: | |
| 831 | - return null; | |
| 832 | - } | |
| 833 | - $attempt++; | |
| 834 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); | |
| 835 | - } | |
| 836 | - | |
| 837 | - | |
| 838 | - /** | |
| 839 | - * instantiates, caches, and injects dependencies for classes | |
| 840 | - * | |
| 841 | - * @param array $file_paths an array of paths to folders to look in | |
| 842 | - * @param string $class_prefix EE or EEM or... ??? | |
| 843 | - * @param bool|string $class_name $class name | |
| 844 | - * @param string $type file type - core? class? helper? model? | |
| 845 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation | |
| 846 | - * @param bool $from_db some classes are instantiated from the db | |
| 847 | - * and thus call a different method to instantiate | |
| 848 | - * @param bool $cache whether to cache the instantiated object for reuse | |
| 849 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object | |
| 850 | - * @return bool|null|object null = failure to load or instantiate class object. | |
| 851 | - * object = class loaded and instantiated successfully. | |
| 852 | - * bool = fail or success when $load_only is true | |
| 853 | - * @throws EE_Error | |
| 854 | - * @throws ReflectionException | |
| 855 | - * @throws InvalidInterfaceException | |
| 856 | - * @throws InvalidDataTypeException | |
| 857 | - * @throws InvalidArgumentException | |
| 858 | - */ | |
| 859 | - protected function _load( | |
| 860 | - $file_paths = array(), | |
| 861 | - $class_prefix = 'EE_', | |
| 862 | - $class_name = false, | |
| 863 | - $type = 'class', | |
| 864 | - $arguments = array(), | |
| 865 | - $from_db = false, | |
| 866 | - $cache = true, | |
| 867 | - $load_only = false | |
| 868 | -    ) { | |
| 869 | - $class_name = ltrim($class_name, '\\'); | |
| 870 | - // strip php file extension | |
| 871 | -        $class_name = str_replace('.php', '', trim($class_name)); | |
| 872 | - // does the class have a prefix ? | |
| 873 | -        if (! empty($class_prefix) && $class_prefix !== 'addon') { | |
| 874 | - // make sure $class_prefix is uppercase | |
| 875 | - $class_prefix = strtoupper(trim($class_prefix)); | |
| 876 | - // add class prefix ONCE!!! | |
| 877 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); | |
| 878 | - } | |
| 879 | - $class_name = $this->class_cache->getFqnForAlias($class_name); | |
| 880 | - $class_exists = class_exists($class_name, false); | |
| 881 | - // if we're only loading the class and it already exists, then let's just return true immediately | |
| 882 | -        if ($load_only && $class_exists) { | |
| 883 | - return true; | |
| 884 | - } | |
| 885 | - $arguments = is_array($arguments) ? $arguments : array($arguments); | |
| 886 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection | |
| 887 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() | |
| 888 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() | |
| 889 | -        if ($this->_cache_on && $cache && ! $load_only) { | |
| 890 | - // return object if it's already cached | |
| 891 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); | |
| 892 | -            if ($cached_class !== null) { | |
| 893 | - return $cached_class; | |
| 894 | - } | |
| 895 | - } | |
| 896 | - // if the class doesn't already exist.. then we need to try and find the file and load it | |
| 897 | -        if (! $class_exists) { | |
| 898 | - // get full path to file | |
| 899 | - $path = $this->_resolve_path($class_name, $type, $file_paths); | |
| 900 | - // load the file | |
| 901 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); | |
| 902 | - // if we are only loading a file but NOT instantiating an object | |
| 903 | - // then return boolean for whether class was loaded or not | |
| 904 | -            if ($load_only) { | |
| 905 | - return $loaded; | |
| 906 | - } | |
| 907 | - // if an object was expected but loading failed, then return nothing | |
| 908 | -            if (! $loaded) { | |
| 909 | - return null; | |
| 910 | - } | |
| 911 | - } | |
| 912 | - // instantiate the requested object | |
| 913 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); | |
| 914 | -        if ($this->_cache_on && $cache) { | |
| 915 | -            // save it for later... kinda like gum  { : $ | |
| 916 | - $this->_set_cached_class( | |
| 917 | - $class_obj, | |
| 918 | - $class_name, | |
| 919 | - $class_prefix, | |
| 920 | - $from_db, | |
| 921 | - $arguments | |
| 922 | - ); | |
| 923 | - } | |
| 924 | - $this->_cache_on = true; | |
| 925 | - return $class_obj; | |
| 926 | - } | |
| 927 | - | |
| 928 | - | |
| 929 | - /** | |
| 930 | - * @param string $class_name | |
| 931 | - * @param string $default have to specify something, but not anything that will conflict | |
| 932 | - * @return mixed|string | |
| 933 | - */ | |
| 934 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') | |
| 935 | -    { | |
| 936 | - return isset($this->_class_abbreviations[ $class_name ]) | |
| 937 | - ? $this->_class_abbreviations[ $class_name ] | |
| 938 | - : $default; | |
| 939 | - } | |
| 940 | - | |
| 941 | - | |
| 942 | - /** | |
| 943 | - * attempts to find a cached version of the requested class | |
| 944 | - * by looking in the following places: | |
| 945 | -     *        $this->{$class_abbreviation}            ie:    $this->CART | |
| 946 | -     *        $this->{$class_name}                        ie:    $this->Some_Class | |
| 947 | -     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class | |
| 948 | -     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class | |
| 949 | - * | |
| 950 | - * @param string $class_name | |
| 951 | - * @param string $class_prefix | |
| 952 | - * @param array $arguments | |
| 953 | - * @return mixed | |
| 954 | - */ | |
| 955 | - protected function _get_cached_class( | |
| 956 | - $class_name, | |
| 957 | - $class_prefix = '', | |
| 958 | - $arguments = array() | |
| 959 | -    ) { | |
| 960 | -        if ($class_name === 'EE_Registry') { | |
| 961 | - return $this; | |
| 962 | - } | |
| 963 | - $class_abbreviation = $this->get_class_abbreviation($class_name); | |
| 964 | - // check if class has already been loaded, and return it if it has been | |
| 965 | -        if (isset($this->{$class_abbreviation})) { | |
| 966 | -            return $this->{$class_abbreviation}; | |
| 967 | - } | |
| 968 | -        $class_name = str_replace('\\', '_', $class_name); | |
| 969 | -        if (isset($this->{$class_name})) { | |
| 970 | -            return $this->{$class_name}; | |
| 971 | - } | |
| 972 | -        if ($class_prefix === 'addon' && $this->addons->has($class_name)) { | |
| 973 | - return $this->addons->get($class_name); | |
| 974 | - } | |
| 975 | - $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); | |
| 976 | -        if ($this->LIB->has($object_identifier)) { | |
| 977 | - return $this->LIB->get($object_identifier); | |
| 978 | - } | |
| 979 | -        foreach ($this->LIB as $key => $object) { | |
| 980 | - if ( | |
| 26 | + /** | |
| 27 | + * @var EE_Registry $_instance | |
| 28 | + */ | |
| 29 | + private static $_instance; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @var EE_Dependency_Map $_dependency_map | |
| 33 | + */ | |
| 34 | + protected $_dependency_map; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * @var Mirror | |
| 38 | + */ | |
| 39 | + private $mirror; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @var ClassInterfaceCache $class_cache | |
| 43 | + */ | |
| 44 | + private $class_cache; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @var array $_class_abbreviations | |
| 48 | + */ | |
| 49 | + protected $_class_abbreviations = array(); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var CommandBusInterface $BUS | |
| 53 | + */ | |
| 54 | + public $BUS; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @var EE_Cart $CART | |
| 58 | + */ | |
| 59 | + public $CART; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @var EE_Config $CFG | |
| 63 | + */ | |
| 64 | + public $CFG; | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * @var EE_Network_Config $NET_CFG | |
| 68 | + */ | |
| 69 | + public $NET_CFG; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * RegistryContainer for storing library classes in | |
| 73 | + * | |
| 74 | + * @var RegistryContainer $LIB | |
| 75 | + */ | |
| 76 | + public $LIB; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * @var EE_Request_Handler $REQ | |
| 80 | + * @deprecated 4.10.14.p | |
| 81 | + */ | |
| 82 | + public $REQ; | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * @var EE_Session $SSN | |
| 86 | + */ | |
| 87 | + public $SSN; | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * @since 4.5.0 | |
| 91 | + * @var EE_Capabilities $CAP | |
| 92 | + */ | |
| 93 | + public $CAP; | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @since 4.9.0 | |
| 97 | + * @var EE_Message_Resource_Manager $MRM | |
| 98 | + */ | |
| 99 | + public $MRM; | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * @var Registry $AssetsRegistry | |
| 103 | + */ | |
| 104 | + public $AssetsRegistry; | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * RegistryContainer for holding addons which have registered themselves to work with EE core | |
| 108 | + * | |
| 109 | + * @var EE_Addon[] $addons | |
| 110 | + */ | |
| 111 | + public $addons; | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') | |
| 115 | + * | |
| 116 | + * @var EEM_Base[] $models | |
| 117 | + */ | |
| 118 | + public $models = array(); | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * @var EED_Module[] $modules | |
| 122 | + */ | |
| 123 | + public $modules; | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * @var EES_Shortcode[] $shortcodes | |
| 127 | + */ | |
| 128 | + public $shortcodes; | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * @var WP_Widget[] $widgets | |
| 132 | + */ | |
| 133 | + public $widgets; | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models | |
| 137 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). | |
| 138 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are | |
| 139 | + * classnames (eg "EEM_Event") | |
| 140 | + * | |
| 141 | + * @var array $non_abstract_db_models | |
| 142 | + */ | |
| 143 | + public $non_abstract_db_models = array(); | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * internationalization for JS strings | |
| 147 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); | |
| 148 | + * in js file: var translatedString = eei18n.string_key; | |
| 149 | + * | |
| 150 | + * @var array $i18n_js_strings | |
| 151 | + */ | |
| 152 | + public static $i18n_js_strings = array(); | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * $main_file - path to espresso.php | |
| 156 | + * | |
| 157 | + * @var array $main_file | |
| 158 | + */ | |
| 159 | + public $main_file; | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * array of ReflectionClass objects where the key is the class name | |
| 163 | + * | |
| 164 | + * @deprecated 4.9.62.p | |
| 165 | + * @var ReflectionClass[] $_reflectors | |
| 166 | + */ | |
| 167 | + public $_reflectors; | |
| 168 | + | |
| 169 | + /** | |
| 170 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache | |
| 171 | + * | |
| 172 | + * @var boolean $_cache_on | |
| 173 | + */ | |
| 174 | + protected $_cache_on = true; | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * @var ObjectIdentifier | |
| 178 | + */ | |
| 179 | + private $object_identifier; | |
| 180 | + | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * @singleton method used to instantiate class object | |
| 184 | + * @param EE_Dependency_Map|null $dependency_map | |
| 185 | + * @param Mirror|null $mirror | |
| 186 | + * @param ClassInterfaceCache|null $class_cache | |
| 187 | + * @param ObjectIdentifier|null $object_identifier | |
| 188 | + * @return EE_Registry instance | |
| 189 | + */ | |
| 190 | + public static function instance( | |
| 191 | + EE_Dependency_Map $dependency_map = null, | |
| 192 | + Mirror $mirror = null, | |
| 193 | + ClassInterfaceCache $class_cache = null, | |
| 194 | + ObjectIdentifier $object_identifier = null | |
| 195 | +	) { | |
| 196 | + // check if class object is instantiated | |
| 197 | + if ( | |
| 198 | + ! self::$_instance instanceof EE_Registry | |
| 199 | + && $dependency_map instanceof EE_Dependency_Map | |
| 200 | + && $mirror instanceof Mirror | |
| 201 | + && $class_cache instanceof ClassInterfaceCache | |
| 202 | + && $object_identifier instanceof ObjectIdentifier | |
| 203 | +		) { | |
| 204 | + self::$_instance = new self( | |
| 205 | + $dependency_map, | |
| 206 | + $mirror, | |
| 207 | + $class_cache, | |
| 208 | + $object_identifier | |
| 209 | + ); | |
| 210 | + } | |
| 211 | + return self::$_instance; | |
| 212 | + } | |
| 213 | + | |
| 214 | + | |
| 215 | + /** | |
| 216 | + * protected constructor to prevent direct creation | |
| 217 | + * | |
| 218 | + * @Constructor | |
| 219 | + * @param EE_Dependency_Map $dependency_map | |
| 220 | + * @param Mirror $mirror | |
| 221 | + * @param ClassInterfaceCache $class_cache | |
| 222 | + * @param ObjectIdentifier $object_identifier | |
| 223 | + */ | |
| 224 | + protected function __construct( | |
| 225 | + EE_Dependency_Map $dependency_map, | |
| 226 | + Mirror $mirror, | |
| 227 | + ClassInterfaceCache $class_cache, | |
| 228 | + ObjectIdentifier $object_identifier | |
| 229 | +	) { | |
| 230 | + $this->_dependency_map = $dependency_map; | |
| 231 | + $this->mirror = $mirror; | |
| 232 | + $this->class_cache = $class_cache; | |
| 233 | + $this->object_identifier = $object_identifier; | |
| 234 | + // $registry_container = new RegistryContainer(); | |
| 235 | + $this->LIB = new RegistryContainer(); | |
| 236 | + $this->addons = new RegistryContainer(); | |
| 237 | + $this->modules = new RegistryContainer(); | |
| 238 | + $this->shortcodes = new RegistryContainer(); | |
| 239 | + $this->widgets = new RegistryContainer(); | |
| 240 | +		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); | |
| 241 | + } | |
| 242 | + | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * initialize | |
| 246 | + * | |
| 247 | + * @throws OutOfBoundsException | |
| 248 | + * @throws InvalidArgumentException | |
| 249 | + * @throws InvalidInterfaceException | |
| 250 | + * @throws InvalidDataTypeException | |
| 251 | + * @throws EE_Error | |
| 252 | + * @throws ReflectionException | |
| 253 | + */ | |
| 254 | + public function initialize() | |
| 255 | +	{ | |
| 256 | + $this->_class_abbreviations = apply_filters( | |
| 257 | + 'FHEE__EE_Registry____construct___class_abbreviations', | |
| 258 | + array( | |
| 259 | + 'EE_Config' => 'CFG', | |
| 260 | + 'EE_Session' => 'SSN', | |
| 261 | + 'EE_Capabilities' => 'CAP', | |
| 262 | + 'EE_Cart' => 'CART', | |
| 263 | + 'EE_Network_Config' => 'NET_CFG', | |
| 264 | + 'EE_Request_Handler' => 'REQ', | |
| 265 | + 'EE_Message_Resource_Manager' => 'MRM', | |
| 266 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', | |
| 267 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', | |
| 268 | + ) | |
| 269 | + ); | |
| 270 | +		$this->load_core('Base', array(), true); | |
| 271 | + // add our request and response objects to the cache | |
| 272 | + $request_loader = $this->_dependency_map->class_loader( | |
| 273 | + 'EventEspresso\core\services\request\Request' | |
| 274 | + ); | |
| 275 | + $this->_set_cached_class( | |
| 276 | + $request_loader(), | |
| 277 | + 'EventEspresso\core\services\request\Request' | |
| 278 | + ); | |
| 279 | + $response_loader = $this->_dependency_map->class_loader( | |
| 280 | + 'EventEspresso\core\services\request\Response' | |
| 281 | + ); | |
| 282 | + $this->_set_cached_class( | |
| 283 | + $response_loader(), | |
| 284 | + 'EventEspresso\core\services\request\Response' | |
| 285 | + ); | |
| 286 | +		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); | |
| 287 | + } | |
| 288 | + | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * @return void | |
| 292 | + */ | |
| 293 | + public function init() | |
| 294 | +	{ | |
| 295 | + // Get current page protocol | |
| 296 | + $protocol = is_ssl() ? 'https://' : 'http://'; | |
| 297 | + // Output admin-ajax.php URL with same protocol as current page | |
| 298 | +		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); | |
| 299 | +		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') && WP_DEBUG; | |
| 300 | + } | |
| 301 | + | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * @return array | |
| 305 | + */ | |
| 306 | + public static function sanitize_i18n_js_strings() | |
| 307 | +	{ | |
| 308 | + $i18n_js_strings = (array) self::$i18n_js_strings; | |
| 309 | +		foreach ($i18n_js_strings as $key => $value) { | |
| 310 | +			if (is_scalar($value)) { | |
| 311 | + $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); | |
| 312 | + $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); | |
| 313 | + } | |
| 314 | + } | |
| 315 | + return $i18n_js_strings; | |
| 316 | + } | |
| 317 | + | |
| 318 | + | |
| 319 | + /** | |
| 320 | + * localize_i18n_js_strings | |
| 321 | + * | |
| 322 | + * @return string | |
| 323 | + */ | |
| 324 | + public static function localize_i18n_js_strings() | |
| 325 | +	{ | |
| 326 | + $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); | |
| 327 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; | |
| 328 | + } | |
| 329 | + | |
| 330 | + | |
| 331 | + /** | |
| 332 | + * @param mixed string | EED_Module $module | |
| 333 | + * @throws OutOfBoundsException | |
| 334 | + * @throws InvalidArgumentException | |
| 335 | + * @throws InvalidInterfaceException | |
| 336 | + * @throws InvalidDataTypeException | |
| 337 | + * @throws EE_Error | |
| 338 | + * @throws ReflectionException | |
| 339 | + */ | |
| 340 | + public function add_module($module) | |
| 341 | +	{ | |
| 342 | +		if ($module instanceof EED_Module) { | |
| 343 | + $module_class = get_class($module); | |
| 344 | + $this->modules->add($module_class, $module); | |
| 345 | +		} else { | |
| 346 | +			if (! class_exists('EE_Module_Request_Router', false)) { | |
| 347 | +				$this->load_core('Module_Request_Router'); | |
| 348 | + } | |
| 349 | + EE_Module_Request_Router::module_factory($module); | |
| 350 | + } | |
| 351 | + } | |
| 352 | + | |
| 353 | + | |
| 354 | + /** | |
| 355 | + * @param string $module_name | |
| 356 | + * @return mixed EED_Module | NULL | |
| 357 | + */ | |
| 358 | + public function get_module($module_name = '') | |
| 359 | +	{ | |
| 360 | + return $this->modules->get($module_name); | |
| 361 | + } | |
| 362 | + | |
| 363 | + | |
| 364 | + /** | |
| 365 | + * loads core classes - must be singletons | |
| 366 | + * | |
| 367 | + * @param string $class_name - simple class name ie: session | |
| 368 | + * @param mixed $arguments | |
| 369 | + * @param bool $load_only | |
| 370 | + * @return mixed | |
| 371 | + * @throws InvalidInterfaceException | |
| 372 | + * @throws InvalidDataTypeException | |
| 373 | + * @throws EE_Error | |
| 374 | + * @throws ReflectionException | |
| 375 | + * @throws InvalidArgumentException | |
| 376 | + */ | |
| 377 | + public function load_core($class_name, $arguments = array(), $load_only = false) | |
| 378 | +	{ | |
| 379 | + $core_paths = apply_filters( | |
| 380 | + 'FHEE__EE_Registry__load_core__core_paths', | |
| 381 | + array( | |
| 382 | + EE_CORE, | |
| 383 | + EE_ADMIN, | |
| 384 | + EE_CPTS, | |
| 385 | + EE_CORE . 'data_migration_scripts/', | |
| 386 | + EE_CORE . 'capabilities/', | |
| 387 | + EE_CORE . 'request_stack/', | |
| 388 | + EE_CORE . 'middleware/', | |
| 389 | + ) | |
| 390 | + ); | |
| 391 | + // retrieve instantiated class | |
| 392 | + return $this->_load( | |
| 393 | + $core_paths, | |
| 394 | + 'EE_', | |
| 395 | + $class_name, | |
| 396 | + 'core', | |
| 397 | + $arguments, | |
| 398 | + false, | |
| 399 | + true, | |
| 400 | + $load_only | |
| 401 | + ); | |
| 402 | + } | |
| 403 | + | |
| 404 | + | |
| 405 | + /** | |
| 406 | + * loads service classes | |
| 407 | + * | |
| 408 | + * @param string $class_name - simple class name ie: session | |
| 409 | + * @param mixed $arguments | |
| 410 | + * @param bool $load_only | |
| 411 | + * @return mixed | |
| 412 | + * @throws InvalidInterfaceException | |
| 413 | + * @throws InvalidDataTypeException | |
| 414 | + * @throws EE_Error | |
| 415 | + * @throws ReflectionException | |
| 416 | + * @throws InvalidArgumentException | |
| 417 | + */ | |
| 418 | + public function load_service($class_name, $arguments = array(), $load_only = false) | |
| 419 | +	{ | |
| 420 | + $service_paths = apply_filters( | |
| 421 | + 'FHEE__EE_Registry__load_service__service_paths', | |
| 422 | + array( | |
| 423 | + EE_CORE . 'services/', | |
| 424 | + ) | |
| 425 | + ); | |
| 426 | + // retrieve instantiated class | |
| 427 | + return $this->_load( | |
| 428 | + $service_paths, | |
| 429 | + 'EE_', | |
| 430 | + $class_name, | |
| 431 | + 'class', | |
| 432 | + $arguments, | |
| 433 | + false, | |
| 434 | + true, | |
| 435 | + $load_only | |
| 436 | + ); | |
| 437 | + } | |
| 438 | + | |
| 439 | + | |
| 440 | + /** | |
| 441 | + * loads data_migration_scripts | |
| 442 | + * | |
| 443 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 | |
| 444 | + * @param mixed $arguments | |
| 445 | + * @return EE_Data_Migration_Script_Base|mixed | |
| 446 | + * @throws InvalidInterfaceException | |
| 447 | + * @throws InvalidDataTypeException | |
| 448 | + * @throws EE_Error | |
| 449 | + * @throws ReflectionException | |
| 450 | + * @throws InvalidArgumentException | |
| 451 | + */ | |
| 452 | + public function load_dms($class_name, $arguments = array()) | |
| 453 | +	{ | |
| 454 | + // retrieve instantiated class | |
| 455 | + return $this->_load( | |
| 456 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), | |
| 457 | + 'EE_DMS_', | |
| 458 | + $class_name, | |
| 459 | + 'dms', | |
| 460 | + $arguments, | |
| 461 | + false, | |
| 462 | + false | |
| 463 | + ); | |
| 464 | + } | |
| 465 | + | |
| 466 | + | |
| 467 | + /** | |
| 468 | + * loads object creating classes - must be singletons | |
| 469 | + * | |
| 470 | + * @param string $class_name - simple class name ie: attendee | |
| 471 | + * @param mixed $arguments - an array of arguments to pass to the class | |
| 472 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to | |
| 473 | + * instantiate | |
| 474 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then | |
| 475 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) | |
| 476 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate | |
| 477 | + * (default) | |
| 478 | + * @return EE_Base_Class | bool | |
| 479 | + * @throws InvalidInterfaceException | |
| 480 | + * @throws InvalidDataTypeException | |
| 481 | + * @throws EE_Error | |
| 482 | + * @throws ReflectionException | |
| 483 | + * @throws InvalidArgumentException | |
| 484 | + */ | |
| 485 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) | |
| 486 | +	{ | |
| 487 | + $paths = apply_filters( | |
| 488 | + 'FHEE__EE_Registry__load_class__paths', | |
| 489 | + array( | |
| 490 | + EE_CORE, | |
| 491 | + EE_CLASSES, | |
| 492 | + EE_BUSINESS, | |
| 493 | + ) | |
| 494 | + ); | |
| 495 | + // retrieve instantiated class | |
| 496 | + return $this->_load( | |
| 497 | + $paths, | |
| 498 | + 'EE_', | |
| 499 | + $class_name, | |
| 500 | + 'class', | |
| 501 | + $arguments, | |
| 502 | + $from_db, | |
| 503 | + $cache, | |
| 504 | + $load_only | |
| 505 | + ); | |
| 506 | + } | |
| 507 | + | |
| 508 | + | |
| 509 | + /** | |
| 510 | + * loads helper classes - must be singletons | |
| 511 | + * | |
| 512 | + * @param string $class_name - simple class name ie: price | |
| 513 | + * @param mixed $arguments | |
| 514 | + * @param bool $load_only | |
| 515 | + * @return EEH_Base | bool | |
| 516 | + * @throws InvalidInterfaceException | |
| 517 | + * @throws InvalidDataTypeException | |
| 518 | + * @throws EE_Error | |
| 519 | + * @throws ReflectionException | |
| 520 | + * @throws InvalidArgumentException | |
| 521 | + */ | |
| 522 | + public function load_helper($class_name, $arguments = array(), $load_only = true) | |
| 523 | +	{ | |
| 524 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed | |
| 525 | +		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); | |
| 526 | + // retrieve instantiated class | |
| 527 | + return $this->_load( | |
| 528 | + $helper_paths, | |
| 529 | + 'EEH_', | |
| 530 | + $class_name, | |
| 531 | + 'helper', | |
| 532 | + $arguments, | |
| 533 | + false, | |
| 534 | + true, | |
| 535 | + $load_only | |
| 536 | + ); | |
| 537 | + } | |
| 538 | + | |
| 539 | + | |
| 540 | + /** | |
| 541 | + * loads core classes - must be singletons | |
| 542 | + * | |
| 543 | + * @param string $class_name - simple class name ie: session | |
| 544 | + * @param mixed $arguments | |
| 545 | + * @param bool $load_only | |
| 546 | + * @param bool $cache whether to cache the object or not. | |
| 547 | + * @return mixed | |
| 548 | + * @throws InvalidInterfaceException | |
| 549 | + * @throws InvalidDataTypeException | |
| 550 | + * @throws EE_Error | |
| 551 | + * @throws ReflectionException | |
| 552 | + * @throws InvalidArgumentException | |
| 553 | + */ | |
| 554 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) | |
| 555 | +	{ | |
| 556 | + $paths = array( | |
| 557 | + EE_LIBRARIES, | |
| 558 | + EE_LIBRARIES . 'messages/', | |
| 559 | + EE_LIBRARIES . 'shortcodes/', | |
| 560 | + EE_LIBRARIES . 'qtips/', | |
| 561 | + EE_LIBRARIES . 'payment_methods/', | |
| 562 | + ); | |
| 563 | + // retrieve instantiated class | |
| 564 | + return $this->_load( | |
| 565 | + $paths, | |
| 566 | + 'EE_', | |
| 567 | + $class_name, | |
| 568 | + 'lib', | |
| 569 | + $arguments, | |
| 570 | + false, | |
| 571 | + $cache, | |
| 572 | + $load_only | |
| 573 | + ); | |
| 574 | + } | |
| 575 | + | |
| 576 | + | |
| 577 | + /** | |
| 578 | + * loads model classes - must be singletons | |
| 579 | + * | |
| 580 | + * @param string $class_name - simple class name ie: price | |
| 581 | + * @param mixed $arguments | |
| 582 | + * @param bool $load_only | |
| 583 | + * @return EEM_Base | bool | |
| 584 | + * @throws InvalidInterfaceException | |
| 585 | + * @throws InvalidDataTypeException | |
| 586 | + * @throws EE_Error | |
| 587 | + * @throws ReflectionException | |
| 588 | + * @throws InvalidArgumentException | |
| 589 | + */ | |
| 590 | + public function load_model($class_name, $arguments = array(), $load_only = false) | |
| 591 | +	{ | |
| 592 | + $paths = apply_filters( | |
| 593 | + 'FHEE__EE_Registry__load_model__paths', | |
| 594 | + array( | |
| 595 | + EE_MODELS, | |
| 596 | + EE_CORE, | |
| 597 | + ) | |
| 598 | + ); | |
| 599 | + // retrieve instantiated class | |
| 600 | + return $this->_load( | |
| 601 | + $paths, | |
| 602 | + 'EEM_', | |
| 603 | + $class_name, | |
| 604 | + 'model', | |
| 605 | + $arguments, | |
| 606 | + false, | |
| 607 | + true, | |
| 608 | + $load_only | |
| 609 | + ); | |
| 610 | + } | |
| 611 | + | |
| 612 | + | |
| 613 | + /** | |
| 614 | + * loads model classes - must be singletons | |
| 615 | + * | |
| 616 | + * @param string $class_name - simple class name ie: price | |
| 617 | + * @param mixed $arguments | |
| 618 | + * @param bool $load_only | |
| 619 | + * @return mixed | bool | |
| 620 | + * @throws InvalidInterfaceException | |
| 621 | + * @throws InvalidDataTypeException | |
| 622 | + * @throws EE_Error | |
| 623 | + * @throws ReflectionException | |
| 624 | + * @throws InvalidArgumentException | |
| 625 | + */ | |
| 626 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) | |
| 627 | +	{ | |
| 628 | + $paths = array( | |
| 629 | + EE_MODELS . 'fields/', | |
| 630 | + EE_MODELS . 'helpers/', | |
| 631 | + EE_MODELS . 'relations/', | |
| 632 | + EE_MODELS . 'strategies/', | |
| 633 | + ); | |
| 634 | + // retrieve instantiated class | |
| 635 | + return $this->_load( | |
| 636 | + $paths, | |
| 637 | + 'EE_', | |
| 638 | + $class_name, | |
| 639 | + '', | |
| 640 | + $arguments, | |
| 641 | + false, | |
| 642 | + true, | |
| 643 | + $load_only | |
| 644 | + ); | |
| 645 | + } | |
| 646 | + | |
| 647 | + | |
| 648 | + /** | |
| 649 | + * Determines if $model_name is the name of an actual EE model. | |
| 650 | + * | |
| 651 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. | |
| 652 | + * @return boolean | |
| 653 | + */ | |
| 654 | + public function is_model_name($model_name) | |
| 655 | +	{ | |
| 656 | + return isset($this->models[ $model_name ]); | |
| 657 | + } | |
| 658 | + | |
| 659 | + | |
| 660 | + /** | |
| 661 | + * generic class loader | |
| 662 | + * | |
| 663 | + * @param string $path_to_file - directory path to file location, not including filename | |
| 664 | + * @param string $file_name - file name ie: my_file.php, including extension | |
| 665 | + * @param string $type - file type - core? class? helper? model? | |
| 666 | + * @param mixed $arguments | |
| 667 | + * @param bool $load_only | |
| 668 | + * @return mixed | |
| 669 | + * @throws InvalidInterfaceException | |
| 670 | + * @throws InvalidDataTypeException | |
| 671 | + * @throws EE_Error | |
| 672 | + * @throws ReflectionException | |
| 673 | + * @throws InvalidArgumentException | |
| 674 | + */ | |
| 675 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) | |
| 676 | +	{ | |
| 677 | + // retrieve instantiated class | |
| 678 | + return $this->_load( | |
| 679 | + $path_to_file, | |
| 680 | + '', | |
| 681 | + $file_name, | |
| 682 | + $type, | |
| 683 | + $arguments, | |
| 684 | + false, | |
| 685 | + true, | |
| 686 | + $load_only | |
| 687 | + ); | |
| 688 | + } | |
| 689 | + | |
| 690 | + | |
| 691 | + /** | |
| 692 | + * @param string $path_to_file - directory path to file location, not including filename | |
| 693 | + * @param string $class_name - full class name ie: My_Class | |
| 694 | + * @param string $type - file type - core? class? helper? model? | |
| 695 | + * @param mixed $arguments | |
| 696 | + * @param bool $load_only | |
| 697 | + * @return bool|EE_Addon|object | |
| 698 | + * @throws InvalidInterfaceException | |
| 699 | + * @throws InvalidDataTypeException | |
| 700 | + * @throws EE_Error | |
| 701 | + * @throws ReflectionException | |
| 702 | + * @throws InvalidArgumentException | |
| 703 | + */ | |
| 704 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) | |
| 705 | +	{ | |
| 706 | + // retrieve instantiated class | |
| 707 | + return $this->_load( | |
| 708 | + $path_to_file, | |
| 709 | + 'addon', | |
| 710 | + $class_name, | |
| 711 | + $type, | |
| 712 | + $arguments, | |
| 713 | + false, | |
| 714 | + true, | |
| 715 | + $load_only | |
| 716 | + ); | |
| 717 | + } | |
| 718 | + | |
| 719 | + | |
| 720 | + /** | |
| 721 | + * instantiates, caches, and automatically resolves dependencies | |
| 722 | + * for classes that use a Fully Qualified Class Name. | |
| 723 | + * if the class is not capable of being loaded using PSR-4 autoloading, | |
| 724 | + * then you need to use one of the existing load_*() methods | |
| 725 | + * which can resolve the classname and filepath from the passed arguments | |
| 726 | + * | |
| 727 | + * @param bool|string $class_name Fully Qualified Class Name | |
| 728 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation | |
| 729 | + * @param bool $cache whether to cache the instantiated object for reuse | |
| 730 | + * @param bool $from_db some classes are instantiated from the db | |
| 731 | + * and thus call a different method to instantiate | |
| 732 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object | |
| 733 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array | |
| 734 | + * @return bool|null|mixed null = failure to load or instantiate class object. | |
| 735 | + * object = class loaded and instantiated successfully. | |
| 736 | + * bool = fail or success when $load_only is true | |
| 737 | + * @throws InvalidInterfaceException | |
| 738 | + * @throws InvalidDataTypeException | |
| 739 | + * @throws EE_Error | |
| 740 | + * @throws ReflectionException | |
| 741 | + * @throws InvalidArgumentException | |
| 742 | + */ | |
| 743 | + public function create( | |
| 744 | + $class_name = false, | |
| 745 | + $arguments = array(), | |
| 746 | + $cache = false, | |
| 747 | + $from_db = false, | |
| 748 | + $load_only = false, | |
| 749 | + $addon = false | |
| 750 | +	) { | |
| 751 | + $class_name = ltrim($class_name, '\\'); | |
| 752 | + $class_name = $this->class_cache->getFqnForAlias($class_name); | |
| 753 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); | |
| 754 | + // if a non-FQCN was passed, then | |
| 755 | + // verifyClassExists() might return an object | |
| 756 | + // or it could return null if the class just could not be found anywhere | |
| 757 | +		if ($class_exists instanceof $class_name || $class_exists === null) { | |
| 758 | + // either way, return the results | |
| 759 | + return $class_exists; | |
| 760 | + } | |
| 761 | + $class_name = $class_exists; | |
| 762 | + // if we're only loading the class and it already exists, then let's just return true immediately | |
| 763 | +		if ($load_only) { | |
| 764 | + return true; | |
| 765 | + } | |
| 766 | + $addon = $addon ? 'addon' : ''; | |
| 767 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection | |
| 768 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() | |
| 769 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() | |
| 770 | +		if ($this->_cache_on && $cache && ! $load_only) { | |
| 771 | + // return object if it's already cached | |
| 772 | + $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); | |
| 773 | +			if ($cached_class !== null) { | |
| 774 | + return $cached_class; | |
| 775 | + } | |
| 776 | + }// obtain the loader method from the dependency map | |
| 777 | + $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object | |
| 778 | +		if ($loader instanceof Closure) { | |
| 779 | + $class_obj = $loader($arguments); | |
| 780 | +		} else { | |
| 781 | +			if ($loader && method_exists($this, $loader)) { | |
| 782 | +				$class_obj = $this->{$loader}($class_name, $arguments); | |
| 783 | +			} else { | |
| 784 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); | |
| 785 | + } | |
| 786 | + } | |
| 787 | +		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { | |
| 788 | +			// save it for later... kinda like gum  { : $ | |
| 789 | + $this->_set_cached_class( | |
| 790 | + $class_obj, | |
| 791 | + $class_name, | |
| 792 | + $addon, | |
| 793 | + $from_db, | |
| 794 | + $arguments | |
| 795 | + ); | |
| 796 | + } | |
| 797 | + $this->_cache_on = true; | |
| 798 | + return $class_obj; | |
| 799 | + } | |
| 800 | + | |
| 801 | + | |
| 802 | + /** | |
| 803 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs | |
| 804 | + * | |
| 805 | + * @param string|object $class_name | |
| 806 | + * @param array $arguments | |
| 807 | + * @param int $attempt | |
| 808 | + * @return mixed | |
| 809 | + */ | |
| 810 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) | |
| 811 | +	{ | |
| 812 | +		if (is_object($class_name) || class_exists($class_name)) { | |
| 813 | + return $class_name; | |
| 814 | + } | |
| 815 | +		switch ($attempt) { | |
| 816 | + case 1: | |
| 817 | + // if it's a FQCN then maybe the class is registered with a preceding \ | |
| 818 | + $class_name = strpos($class_name, '\\') !== false | |
| 819 | + ? '\\' . ltrim($class_name, '\\') | |
| 820 | + : $class_name; | |
| 821 | + break; | |
| 822 | + case 2: | |
| 823 | + // | |
| 824 | + $loader = $this->_dependency_map->class_loader($class_name); | |
| 825 | +				if ($loader && method_exists($this, $loader)) { | |
| 826 | +					return $this->{$loader}($class_name, $arguments); | |
| 827 | + } | |
| 828 | + break; | |
| 829 | + case 3: | |
| 830 | + default: | |
| 831 | + return null; | |
| 832 | + } | |
| 833 | + $attempt++; | |
| 834 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); | |
| 835 | + } | |
| 836 | + | |
| 837 | + | |
| 838 | + /** | |
| 839 | + * instantiates, caches, and injects dependencies for classes | |
| 840 | + * | |
| 841 | + * @param array $file_paths an array of paths to folders to look in | |
| 842 | + * @param string $class_prefix EE or EEM or... ??? | |
| 843 | + * @param bool|string $class_name $class name | |
| 844 | + * @param string $type file type - core? class? helper? model? | |
| 845 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation | |
| 846 | + * @param bool $from_db some classes are instantiated from the db | |
| 847 | + * and thus call a different method to instantiate | |
| 848 | + * @param bool $cache whether to cache the instantiated object for reuse | |
| 849 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object | |
| 850 | + * @return bool|null|object null = failure to load or instantiate class object. | |
| 851 | + * object = class loaded and instantiated successfully. | |
| 852 | + * bool = fail or success when $load_only is true | |
| 853 | + * @throws EE_Error | |
| 854 | + * @throws ReflectionException | |
| 855 | + * @throws InvalidInterfaceException | |
| 856 | + * @throws InvalidDataTypeException | |
| 857 | + * @throws InvalidArgumentException | |
| 858 | + */ | |
| 859 | + protected function _load( | |
| 860 | + $file_paths = array(), | |
| 861 | + $class_prefix = 'EE_', | |
| 862 | + $class_name = false, | |
| 863 | + $type = 'class', | |
| 864 | + $arguments = array(), | |
| 865 | + $from_db = false, | |
| 866 | + $cache = true, | |
| 867 | + $load_only = false | |
| 868 | +	) { | |
| 869 | + $class_name = ltrim($class_name, '\\'); | |
| 870 | + // strip php file extension | |
| 871 | +		$class_name = str_replace('.php', '', trim($class_name)); | |
| 872 | + // does the class have a prefix ? | |
| 873 | +		if (! empty($class_prefix) && $class_prefix !== 'addon') { | |
| 874 | + // make sure $class_prefix is uppercase | |
| 875 | + $class_prefix = strtoupper(trim($class_prefix)); | |
| 876 | + // add class prefix ONCE!!! | |
| 877 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); | |
| 878 | + } | |
| 879 | + $class_name = $this->class_cache->getFqnForAlias($class_name); | |
| 880 | + $class_exists = class_exists($class_name, false); | |
| 881 | + // if we're only loading the class and it already exists, then let's just return true immediately | |
| 882 | +		if ($load_only && $class_exists) { | |
| 883 | + return true; | |
| 884 | + } | |
| 885 | + $arguments = is_array($arguments) ? $arguments : array($arguments); | |
| 886 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection | |
| 887 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() | |
| 888 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() | |
| 889 | +		if ($this->_cache_on && $cache && ! $load_only) { | |
| 890 | + // return object if it's already cached | |
| 891 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); | |
| 892 | +			if ($cached_class !== null) { | |
| 893 | + return $cached_class; | |
| 894 | + } | |
| 895 | + } | |
| 896 | + // if the class doesn't already exist.. then we need to try and find the file and load it | |
| 897 | +		if (! $class_exists) { | |
| 898 | + // get full path to file | |
| 899 | + $path = $this->_resolve_path($class_name, $type, $file_paths); | |
| 900 | + // load the file | |
| 901 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); | |
| 902 | + // if we are only loading a file but NOT instantiating an object | |
| 903 | + // then return boolean for whether class was loaded or not | |
| 904 | +			if ($load_only) { | |
| 905 | + return $loaded; | |
| 906 | + } | |
| 907 | + // if an object was expected but loading failed, then return nothing | |
| 908 | +			if (! $loaded) { | |
| 909 | + return null; | |
| 910 | + } | |
| 911 | + } | |
| 912 | + // instantiate the requested object | |
| 913 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); | |
| 914 | +		if ($this->_cache_on && $cache) { | |
| 915 | +			// save it for later... kinda like gum  { : $ | |
| 916 | + $this->_set_cached_class( | |
| 917 | + $class_obj, | |
| 918 | + $class_name, | |
| 919 | + $class_prefix, | |
| 920 | + $from_db, | |
| 921 | + $arguments | |
| 922 | + ); | |
| 923 | + } | |
| 924 | + $this->_cache_on = true; | |
| 925 | + return $class_obj; | |
| 926 | + } | |
| 927 | + | |
| 928 | + | |
| 929 | + /** | |
| 930 | + * @param string $class_name | |
| 931 | + * @param string $default have to specify something, but not anything that will conflict | |
| 932 | + * @return mixed|string | |
| 933 | + */ | |
| 934 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') | |
| 935 | +	{ | |
| 936 | + return isset($this->_class_abbreviations[ $class_name ]) | |
| 937 | + ? $this->_class_abbreviations[ $class_name ] | |
| 938 | + : $default; | |
| 939 | + } | |
| 940 | + | |
| 941 | + | |
| 942 | + /** | |
| 943 | + * attempts to find a cached version of the requested class | |
| 944 | + * by looking in the following places: | |
| 945 | +	 *        $this->{$class_abbreviation}            ie:    $this->CART | |
| 946 | +	 *        $this->{$class_name}                        ie:    $this->Some_Class | |
| 947 | +	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class | |
| 948 | +	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class | |
| 949 | + * | |
| 950 | + * @param string $class_name | |
| 951 | + * @param string $class_prefix | |
| 952 | + * @param array $arguments | |
| 953 | + * @return mixed | |
| 954 | + */ | |
| 955 | + protected function _get_cached_class( | |
| 956 | + $class_name, | |
| 957 | + $class_prefix = '', | |
| 958 | + $arguments = array() | |
| 959 | +	) { | |
| 960 | +		if ($class_name === 'EE_Registry') { | |
| 961 | + return $this; | |
| 962 | + } | |
| 963 | + $class_abbreviation = $this->get_class_abbreviation($class_name); | |
| 964 | + // check if class has already been loaded, and return it if it has been | |
| 965 | +		if (isset($this->{$class_abbreviation})) { | |
| 966 | +			return $this->{$class_abbreviation}; | |
| 967 | + } | |
| 968 | +		$class_name = str_replace('\\', '_', $class_name); | |
| 969 | +		if (isset($this->{$class_name})) { | |
| 970 | +			return $this->{$class_name}; | |
| 971 | + } | |
| 972 | +		if ($class_prefix === 'addon' && $this->addons->has($class_name)) { | |
| 973 | + return $this->addons->get($class_name); | |
| 974 | + } | |
| 975 | + $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); | |
| 976 | +		if ($this->LIB->has($object_identifier)) { | |
| 977 | + return $this->LIB->get($object_identifier); | |
| 978 | + } | |
| 979 | +		foreach ($this->LIB as $key => $object) { | |
| 980 | + if ( | |
| 981 | 981 | // request does not contain new arguments and therefore no args identifier | 
| 982 | - ! $this->object_identifier->hasArguments($object_identifier) | |
| 983 | - // but previously cached class with args was found | |
| 984 | - && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) | |
| 985 | -            ) { | |
| 986 | - return $object; | |
| 987 | - } | |
| 988 | - } | |
| 989 | - return null; | |
| 990 | - } | |
| 991 | - | |
| 992 | - | |
| 993 | - /** | |
| 994 | - * removes a cached version of the requested class | |
| 995 | - * | |
| 996 | - * @param string $class_name | |
| 997 | - * @param boolean $addon | |
| 998 | - * @param array $arguments | |
| 999 | - * @return boolean | |
| 1000 | - */ | |
| 1001 | - public function clear_cached_class( | |
| 1002 | - $class_name, | |
| 1003 | - $addon = false, | |
| 1004 | - $arguments = array() | |
| 1005 | -    ) { | |
| 1006 | - $class_abbreviation = $this->get_class_abbreviation($class_name); | |
| 1007 | - // check if class has already been loaded, and return it if it has been | |
| 1008 | -        if (isset($this->{$class_abbreviation})) { | |
| 1009 | -            $this->{$class_abbreviation} = null; | |
| 1010 | - return true; | |
| 1011 | - } | |
| 1012 | -        $class_name = str_replace('\\', '_', $class_name); | |
| 1013 | -        if (isset($this->{$class_name})) { | |
| 1014 | -            $this->{$class_name} = null; | |
| 1015 | - return true; | |
| 1016 | - } | |
| 1017 | -        if ($addon && $this->addons->has($class_name)) { | |
| 1018 | - $this->addons->remove($class_name); | |
| 1019 | - return true; | |
| 1020 | - } | |
| 1021 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); | |
| 1022 | -        if ($this->LIB->has($class_name)) { | |
| 1023 | - $this->LIB->remove($class_name); | |
| 1024 | - return true; | |
| 1025 | - } | |
| 1026 | - return false; | |
| 1027 | - } | |
| 1028 | - | |
| 1029 | - | |
| 1030 | - /** | |
| 1031 | - * _set_cached_class | |
| 1032 | - * attempts to cache the instantiated class locally | |
| 1033 | - * in one of the following places, in the following order: | |
| 1034 | -     *        $this->{class_abbreviation}   ie:    $this->CART | |
| 1035 | -     *        $this->{$class_name}          ie:    $this->Some_Class | |
| 1036 | -     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class | |
| 1037 | -     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class | |
| 1038 | - * | |
| 1039 | - * @param object $class_obj | |
| 1040 | - * @param string $class_name | |
| 1041 | - * @param string $class_prefix | |
| 1042 | - * @param bool $from_db | |
| 1043 | - * @param array $arguments | |
| 1044 | - * @return void | |
| 1045 | - */ | |
| 1046 | - protected function _set_cached_class( | |
| 1047 | - $class_obj, | |
| 1048 | - $class_name, | |
| 1049 | - $class_prefix = '', | |
| 1050 | - $from_db = false, | |
| 1051 | - $arguments = array() | |
| 1052 | -    ) { | |
| 1053 | -        if ($class_name === 'EE_Registry' || empty($class_obj)) { | |
| 1054 | - return; | |
| 1055 | - } | |
| 1056 | - // return newly instantiated class | |
| 1057 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); | |
| 1058 | -        if ($class_abbreviation) { | |
| 1059 | -            $this->{$class_abbreviation} = $class_obj; | |
| 1060 | - return; | |
| 1061 | - } | |
| 1062 | -        $class_name = str_replace('\\', '_', $class_name); | |
| 1063 | -        if (property_exists($this, $class_name)) { | |
| 1064 | -            $this->{$class_name} = $class_obj; | |
| 1065 | - return; | |
| 1066 | - } | |
| 1067 | -        if ($class_prefix === 'addon') { | |
| 1068 | - $this->addons->add($class_name, $class_obj); | |
| 1069 | - return; | |
| 1070 | - } | |
| 1071 | -        if (! $from_db) { | |
| 1072 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); | |
| 1073 | - $this->LIB->add($class_name, $class_obj); | |
| 1074 | - } | |
| 1075 | - } | |
| 1076 | - | |
| 1077 | - | |
| 1078 | - /** | |
| 1079 | - * attempts to find a full valid filepath for the requested class. | |
| 1080 | -     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" | |
| 1081 | - * then returns that path if the target file has been found and is readable | |
| 1082 | - * | |
| 1083 | - * @param string $class_name | |
| 1084 | - * @param string $type | |
| 1085 | - * @param array $file_paths | |
| 1086 | - * @return string | bool | |
| 1087 | - */ | |
| 1088 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) | |
| 1089 | -    { | |
| 1090 | - // make sure $file_paths is an array | |
| 1091 | - $file_paths = is_array($file_paths) | |
| 1092 | - ? $file_paths | |
| 1093 | - : array($file_paths); | |
| 1094 | - // cycle thru paths | |
| 1095 | -        foreach ($file_paths as $key => $file_path) { | |
| 1096 | - // convert all separators to proper /, if no filepath, then use EE_CLASSES | |
| 1097 | - $file_path = $file_path | |
| 1098 | -                ? str_replace(array('/', '\\'), '/', $file_path) | |
| 1099 | - : EE_CLASSES; | |
| 1100 | - // prep file type | |
| 1101 | - $type = ! empty($type) | |
| 1102 | - ? trim($type, '.') . '.' | |
| 1103 | - : ''; | |
| 1104 | - // build full file path | |
| 1105 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; | |
| 1106 | - // does the file exist and can be read ? | |
| 1107 | -            if (is_readable($file_paths[ $key ])) { | |
| 1108 | - return $file_paths[ $key ]; | |
| 1109 | - } | |
| 1110 | - } | |
| 1111 | - return false; | |
| 1112 | - } | |
| 1113 | - | |
| 1114 | - | |
| 1115 | - /** | |
| 1116 | - * basically just performs a require_once() | |
| 1117 | - * but with some error handling | |
| 1118 | - * | |
| 1119 | - * @param string $path | |
| 1120 | - * @param string $class_name | |
| 1121 | - * @param string $type | |
| 1122 | - * @param array $file_paths | |
| 1123 | - * @return bool | |
| 1124 | - * @throws EE_Error | |
| 1125 | - * @throws ReflectionException | |
| 1126 | - */ | |
| 1127 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) | |
| 1128 | -    { | |
| 1129 | - $this->resolve_legacy_class_parent($class_name); | |
| 1130 | - // don't give up! you gotta... | |
| 1131 | -        try { | |
| 1132 | - // does the file exist and can it be read ? | |
| 1133 | -            if (! $path) { | |
| 1134 | - // just in case the file has already been autoloaded, | |
| 1135 | - // but discrepancies in the naming schema are preventing it from | |
| 1136 | - // being loaded via one of the EE_Registry::load_*() methods, | |
| 1137 | - // then let's try one last hail mary before throwing an exception | |
| 1138 | - // and call class_exists() again, but with autoloading turned ON | |
| 1139 | -                if (class_exists($class_name)) { | |
| 1140 | - return true; | |
| 1141 | - } | |
| 1142 | - // so sorry, can't find the file | |
| 1143 | - throw new EE_Error( | |
| 1144 | - sprintf( | |
| 1145 | - esc_html__( | |
| 1146 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', | |
| 1147 | - 'event_espresso' | |
| 1148 | - ), | |
| 1149 | - trim($type, '.'), | |
| 1150 | - $class_name, | |
| 1151 | -                        '<br />' . implode(',<br />', $file_paths) | |
| 1152 | - ) | |
| 1153 | - ); | |
| 1154 | - } | |
| 1155 | - // get the file | |
| 1156 | - require_once($path); | |
| 1157 | - // if the class isn't already declared somewhere | |
| 1158 | -            if (class_exists($class_name, false) === false) { | |
| 1159 | - // so sorry, not a class | |
| 1160 | - throw new EE_Error( | |
| 1161 | - sprintf( | |
| 1162 | - esc_html__( | |
| 1163 | - 'The %s file %s does not appear to contain the %s Class.', | |
| 1164 | - 'event_espresso' | |
| 1165 | - ), | |
| 1166 | - $type, | |
| 1167 | - $path, | |
| 1168 | - $class_name | |
| 1169 | - ) | |
| 1170 | - ); | |
| 1171 | - } | |
| 1172 | -        } catch (EE_Error $e) { | |
| 1173 | - $e->get_error(); | |
| 1174 | - return false; | |
| 1175 | - } | |
| 1176 | - return true; | |
| 1177 | - } | |
| 1178 | - | |
| 1179 | - | |
| 1180 | - /** | |
| 1181 | - * Some of our legacy classes that extended a parent class would simply use a require() statement | |
| 1182 | - * before their class declaration in order to ensure that the parent class was loaded. | |
| 1183 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, | |
| 1184 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. | |
| 1185 | - * | |
| 1186 | - * @param string $class_name | |
| 1187 | - */ | |
| 1188 | - protected function resolve_legacy_class_parent($class_name = '') | |
| 1189 | -    { | |
| 1190 | -        try { | |
| 1191 | - $legacy_parent_class_map = array( | |
| 1192 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', | |
| 1193 | - ); | |
| 1194 | -            if (isset($legacy_parent_class_map[ $class_name ])) { | |
| 1195 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; | |
| 1196 | - } | |
| 1197 | -        } catch (Exception $exception) { | |
| 1198 | - } | |
| 1199 | - } | |
| 1200 | - | |
| 1201 | - | |
| 1202 | - /** | |
| 1203 | - * _create_object | |
| 1204 | - * Attempts to instantiate the requested class via any of the | |
| 1205 | - * commonly used instantiation methods employed throughout EE. | |
| 1206 | - * The priority for instantiation is as follows: | |
| 1207 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) | |
| 1208 | - * - model objects via their 'new_instance_from_db' method | |
| 1209 | - * - model objects via their 'new_instance' method | |
| 1210 | - * - "singleton" classes" via their 'instance' method | |
| 1211 | - * - standard instantiable classes via their __constructor | |
| 1212 | - * Prior to instantiation, if the classname exists in the dependency_map, | |
| 1213 | - * then the constructor for the requested class will be examined to determine | |
| 1214 | - * if any dependencies exist, and if they can be injected. | |
| 1215 | - * If so, then those classes will be added to the array of arguments passed to the constructor | |
| 1216 | - * | |
| 1217 | - * @param string $class_name | |
| 1218 | - * @param array $arguments | |
| 1219 | - * @param string $type | |
| 1220 | - * @param bool $from_db | |
| 1221 | - * @return null|object|bool | |
| 1222 | - * @throws InvalidArgumentException | |
| 1223 | - * @throws InvalidInterfaceException | |
| 1224 | - * @throws EE_Error | |
| 1225 | - * @throws ReflectionException | |
| 1226 | - * @throws InvalidDataTypeException | |
| 1227 | - */ | |
| 1228 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) | |
| 1229 | -    { | |
| 1230 | - // create reflection | |
| 1231 | - $reflector = $this->mirror->getReflectionClass($class_name); | |
| 1232 | - // make sure arguments are an array | |
| 1233 | - $arguments = is_array($arguments) | |
| 1234 | - ? $arguments | |
| 1235 | - : array($arguments); | |
| 1236 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, | |
| 1237 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters | |
| 1238 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) | |
| 1239 | - ? $arguments | |
| 1240 | - : array($arguments); | |
| 1241 | - // attempt to inject dependencies ? | |
| 1242 | -        if ($this->_dependency_map->has($class_name)) { | |
| 1243 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); | |
| 1244 | - } | |
| 1245 | - // instantiate the class if possible | |
| 1246 | -        if ($reflector->isAbstract()) { | |
| 1247 | - // nothing to instantiate, loading file was enough | |
| 1248 | - // does not throw an exception so $instantiation_mode is unused | |
| 1249 | - // $instantiation_mode = "1) no constructor abstract class"; | |
| 1250 | - return true; | |
| 1251 | - } | |
| 1252 | - if ( | |
| 1253 | - empty($arguments) | |
| 1254 | - && $this->mirror->getConstructorFromReflection($reflector) === null | |
| 1255 | - && $reflector->isInstantiable() | |
| 1256 | -        ) { | |
| 1257 | - // no constructor = static methods only... nothing to instantiate, loading file was enough | |
| 1258 | - // $instantiation_mode = "2) no constructor but instantiable"; | |
| 1259 | - return $reflector->newInstance(); | |
| 1260 | - } | |
| 1261 | -        if ($from_db && method_exists($class_name, 'new_instance_from_db')) { | |
| 1262 | - // $instantiation_mode = "3) new_instance_from_db()"; | |
| 1263 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); | |
| 1264 | - } | |
| 1265 | -        if (method_exists($class_name, 'new_instance')) { | |
| 1266 | - // $instantiation_mode = "4) new_instance()"; | |
| 1267 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); | |
| 1268 | - } | |
| 1269 | -        if (method_exists($class_name, 'instance')) { | |
| 1270 | - // $instantiation_mode = "5) instance()"; | |
| 1271 | - return call_user_func_array(array($class_name, 'instance'), $arguments); | |
| 1272 | - } | |
| 1273 | -        if ($reflector->isInstantiable()) { | |
| 1274 | - // $instantiation_mode = "6) constructor"; | |
| 1275 | - return $reflector->newInstanceArgs($arguments); | |
| 1276 | - } | |
| 1277 | - // heh ? something's not right ! | |
| 1278 | - throw new EE_Error( | |
| 1279 | - sprintf( | |
| 1280 | -                esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), | |
| 1281 | - $type, | |
| 1282 | - $class_name | |
| 1283 | - ) | |
| 1284 | - ); | |
| 1285 | - } | |
| 1286 | - | |
| 1287 | - | |
| 1288 | - /** | |
| 1289 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential | |
| 1290 | - * @param array $array | |
| 1291 | - * @return bool | |
| 1292 | - */ | |
| 1293 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) | |
| 1294 | -    { | |
| 1295 | - return ! empty($array) | |
| 1296 | - ? array_keys($array) === range(0, count($array) - 1) | |
| 1297 | - : true; | |
| 1298 | - } | |
| 1299 | - | |
| 1300 | - | |
| 1301 | - /** | |
| 1302 | - * _resolve_dependencies | |
| 1303 | - * examines the constructor for the requested class to determine | |
| 1304 | - * if any dependencies exist, and if they can be injected. | |
| 1305 | - * If so, then those classes will be added to the array of arguments passed to the constructor | |
| 1306 | - * PLZ NOTE: this is achieved by type hinting the constructor params | |
| 1307 | - * For example: | |
| 1308 | - * if attempting to load a class "Foo" with the following constructor: | |
| 1309 | - * __construct( Bar $bar_class, Fighter $grohl_class ) | |
| 1310 | - * then $bar_class and $grohl_class will be added to the $arguments array, | |
| 1311 | - * but only IF they are NOT already present in the incoming arguments array, | |
| 1312 | - * and the correct classes can be loaded | |
| 1313 | - * | |
| 1314 | - * @param ReflectionClass $reflector | |
| 1315 | - * @param string $class_name | |
| 1316 | - * @param array $arguments | |
| 1317 | - * @return array | |
| 1318 | - * @throws InvalidArgumentException | |
| 1319 | - * @throws InvalidDataTypeException | |
| 1320 | - * @throws InvalidInterfaceException | |
| 1321 | - * @throws ReflectionException | |
| 1322 | - */ | |
| 1323 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) | |
| 1324 | -    { | |
| 1325 | - // let's examine the constructor | |
| 1326 | - $constructor = $this->mirror->getConstructorFromReflection($reflector); | |
| 1327 | - // whu? huh? nothing? | |
| 1328 | -        if (! $constructor) { | |
| 1329 | - return $arguments; | |
| 1330 | - } | |
| 1331 | - // get constructor parameters | |
| 1332 | - $params = $this->mirror->getParametersFromReflection($reflector); | |
| 1333 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected | |
| 1334 | - $argument_keys = array_keys($arguments); | |
| 1335 | - // now loop thru all of the constructors expected parameters | |
| 1336 | -        foreach ($params as $index => $param) { | |
| 1337 | -            try { | |
| 1338 | - // is this a dependency for a specific class ? | |
| 1339 | - $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); | |
| 1340 | -            } catch (ReflectionException $exception) { | |
| 1341 | - // uh-oh... most likely a legacy class that has not been autoloaded | |
| 1342 | - // let's try to derive the classname from what we have now | |
| 1343 | - // and hope that the property var name is close to the class name | |
| 1344 | - $param_class = $param->getName(); | |
| 1345 | -                $param_class = str_replace('_', ' ', $param_class); | |
| 1346 | - $param_class = ucwords($param_class); | |
| 1347 | -                $param_class = str_replace(' ', '_', $param_class); | |
| 1348 | - } | |
| 1349 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) | |
| 1350 | - $param_class = $this->class_cache->isAlias($param_class, $class_name) | |
| 1351 | - ? $this->class_cache->getFqnForAlias($param_class, $class_name) | |
| 1352 | - : $param_class; | |
| 1353 | - if ( | |
| 1354 | - // param is not even a class | |
| 1355 | - $param_class === null | |
| 1356 | - // and something already exists in the incoming arguments for this param | |
| 1357 | - && array_key_exists($index, $argument_keys) | |
| 1358 | - && array_key_exists($argument_keys[ $index ], $arguments) | |
| 1359 | -            ) { | |
| 1360 | - // so let's skip this argument and move on to the next | |
| 1361 | - continue; | |
| 1362 | - } | |
| 1363 | - if ( | |
| 1364 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class | |
| 1365 | - $param_class !== null | |
| 1366 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) | |
| 1367 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class | |
| 1368 | -            ) { | |
| 1369 | - // skip this argument and move on to the next | |
| 1370 | - continue; | |
| 1371 | - } | |
| 1372 | - if ( | |
| 1373 | - // parameter is type hinted as a class, and should be injected | |
| 1374 | - $param_class !== null | |
| 1375 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) | |
| 1376 | -            ) { | |
| 1377 | - $arguments = $this->_resolve_dependency( | |
| 1378 | - $class_name, | |
| 1379 | - $param_class, | |
| 1380 | - $arguments, | |
| 1381 | - $index | |
| 1382 | - ); | |
| 1383 | - } | |
| 1384 | -            if (empty($arguments[ $index ])) { | |
| 1385 | - $default_value = $this->mirror->getParameterDefaultValue( | |
| 1386 | - $param, | |
| 1387 | - $class_name, | |
| 1388 | - $index | |
| 1389 | - ); | |
| 1390 | - // if there's no default value, and the incoming argument is an array (albeit empty), then use that | |
| 1391 | - $arguments[ $index ] = $default_value === null | |
| 1392 | - && isset($arguments[ $index ]) | |
| 1393 | - && is_array($arguments[ $index ]) | |
| 1394 | - ? $arguments[ $index ] | |
| 1395 | - : $default_value; | |
| 1396 | - } | |
| 1397 | - } | |
| 1398 | - return $arguments; | |
| 1399 | - } | |
| 1400 | - | |
| 1401 | - | |
| 1402 | - /** | |
| 1403 | - * @param string $class_name | |
| 1404 | - * @param string $param_class | |
| 1405 | - * @param array $arguments | |
| 1406 | - * @param mixed $index | |
| 1407 | - * @return array | |
| 1408 | - * @throws InvalidArgumentException | |
| 1409 | - * @throws InvalidInterfaceException | |
| 1410 | - * @throws InvalidDataTypeException | |
| 1411 | - */ | |
| 1412 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) | |
| 1413 | -    { | |
| 1414 | - $dependency = null; | |
| 1415 | - // should dependency be loaded from cache ? | |
| 1416 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( | |
| 1417 | - $class_name, | |
| 1418 | - $param_class | |
| 1419 | - ); | |
| 1420 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; | |
| 1421 | - // we might have a dependency... | |
| 1422 | - // let's MAYBE try and find it in our cache if that's what's been requested | |
| 1423 | - $cached_class = $cache_on | |
| 1424 | - ? $this->_get_cached_class($param_class) | |
| 1425 | - : null; | |
| 1426 | - // and grab it if it exists | |
| 1427 | -        if ($cached_class instanceof $param_class) { | |
| 1428 | - $dependency = $cached_class; | |
| 1429 | -        } elseif ($param_class !== $class_name) { | |
| 1430 | - // obtain the loader method from the dependency map | |
| 1431 | - $loader = $this->_dependency_map->class_loader($param_class); | |
| 1432 | - // is loader a custom closure ? | |
| 1433 | -            if ($loader instanceof Closure) { | |
| 1434 | - $dependency = $loader($arguments); | |
| 1435 | -            } else { | |
| 1436 | - // set the cache on property for the recursive loading call | |
| 1437 | - $this->_cache_on = $cache_on; | |
| 1438 | - // if not, then let's try and load it via the registry | |
| 1439 | -                if ($loader && method_exists($this, $loader)) { | |
| 1440 | -                    $dependency = $this->{$loader}($param_class); | |
| 1441 | -                } else { | |
| 1442 | - $dependency = LoaderFactory::getLoader()->load( | |
| 1443 | - $param_class, | |
| 1444 | - array(), | |
| 1445 | - $cache_on | |
| 1446 | - ); | |
| 1447 | - } | |
| 1448 | - } | |
| 1449 | - } | |
| 1450 | - // did we successfully find the correct dependency ? | |
| 1451 | -        if ($dependency instanceof $param_class) { | |
| 1452 | - // then let's inject it into the incoming array of arguments at the correct location | |
| 1453 | - $arguments[ $index ] = $dependency; | |
| 1454 | - } | |
| 1455 | - return $arguments; | |
| 1456 | - } | |
| 1457 | - | |
| 1458 | - | |
| 1459 | - /** | |
| 1460 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array | |
| 1461 | - * | |
| 1462 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered | |
| 1463 | - * in the EE_Dependency_Map::$_class_loaders array, | |
| 1464 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc | |
| 1465 | - * @param array $arguments | |
| 1466 | - * @return object | |
| 1467 | - */ | |
| 1468 | - public static function factory($classname, $arguments = array()) | |
| 1469 | -    { | |
| 1470 | - $loader = self::instance()->_dependency_map->class_loader($classname); | |
| 1471 | -        if ($loader instanceof Closure) { | |
| 1472 | - return $loader($arguments); | |
| 1473 | - } | |
| 1474 | -        if (method_exists(self::instance(), $loader)) { | |
| 1475 | -            return self::instance()->{$loader}($classname, $arguments); | |
| 1476 | - } | |
| 1477 | - return null; | |
| 1478 | - } | |
| 1479 | - | |
| 1480 | - | |
| 1481 | - /** | |
| 1482 | - * Gets the addon by its class name | |
| 1483 | - * | |
| 1484 | - * @param string $class_name | |
| 1485 | - * @return EE_Addon | |
| 1486 | - */ | |
| 1487 | - public function getAddon($class_name) | |
| 1488 | -    { | |
| 1489 | -        $class_name = str_replace('\\', '_', $class_name); | |
| 1490 | -        if (isset($this->addons->{$class_name})) { | |
| 1491 | -            return $this->addons->{$class_name}; | |
| 1492 | -        } else { | |
| 1493 | - return null; | |
| 1494 | - } | |
| 1495 | - } | |
| 1496 | - | |
| 1497 | - | |
| 1498 | - /** | |
| 1499 | - * removes the addon from the internal cache | |
| 1500 | - * | |
| 1501 | - * @param string $class_name | |
| 1502 | - * @return void | |
| 1503 | - */ | |
| 1504 | - public function removeAddon($class_name) | |
| 1505 | -    { | |
| 1506 | -        $class_name = str_replace('\\', '_', $class_name); | |
| 1507 | - $this->addons->remove($class_name); | |
| 1508 | - } | |
| 1509 | - | |
| 1510 | - | |
| 1511 | - /** | |
| 1512 | - * Gets the addon by its name/slug (not classname. For that, just | |
| 1513 | - * use the get_addon() method above | |
| 1514 | - * | |
| 1515 | - * @param string $name | |
| 1516 | - * @return EE_Addon | |
| 1517 | - */ | |
| 1518 | - public function get_addon_by_name($name) | |
| 1519 | -    { | |
| 1520 | -        foreach ($this->addons as $addon) { | |
| 1521 | -            if ($addon->name() === $name) { | |
| 1522 | - return $addon; | |
| 1523 | - } | |
| 1524 | - } | |
| 1525 | - return null; | |
| 1526 | - } | |
| 1527 | - | |
| 1528 | - | |
| 1529 | - /** | |
| 1530 | - * Gets an array of all the registered addons, where the keys are their names. | |
| 1531 | - * (ie, what each returns for their name() function) | |
| 1532 | - * They're already available on EE_Registry::instance()->addons as properties, | |
| 1533 | - * where each property's name is the addon's classname, | |
| 1534 | - * So if you just want to get the addon by classname, | |
| 1535 | - * OR use the get_addon() method above. | |
| 1536 | - * PLEASE NOTE: | |
| 1537 | - * addons with Fully Qualified Class Names | |
| 1538 | - * have had the namespace separators converted to underscores, | |
| 1539 | - * so a classname like Fully\Qualified\ClassName | |
| 1540 | - * would have been converted to Fully_Qualified_ClassName | |
| 1541 | - * | |
| 1542 | - * @return EE_Addon[] where the KEYS are the addon's name() | |
| 1543 | - */ | |
| 1544 | - public function get_addons_by_name() | |
| 1545 | -    { | |
| 1546 | - $addons = array(); | |
| 1547 | -        foreach ($this->addons as $addon) { | |
| 1548 | - $addons[ $addon->name() ] = $addon; | |
| 1549 | - } | |
| 1550 | - return $addons; | |
| 1551 | - } | |
| 1552 | - | |
| 1553 | - | |
| 1554 | - /** | |
| 1555 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep | |
| 1556 | - * a stale copy of it around | |
| 1557 | - * | |
| 1558 | - * @param string $model_name | |
| 1559 | - * @return \EEM_Base | |
| 1560 | - * @throws \EE_Error | |
| 1561 | - */ | |
| 1562 | - public function reset_model($model_name) | |
| 1563 | -    { | |
| 1564 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 | |
| 1565 | -            ? "EEM_{$model_name}" | |
| 1566 | - : $model_name; | |
| 1567 | -        if (! $this->LIB->has($model_class_name)) { | |
| 1568 | - return null; | |
| 1569 | - } | |
| 1570 | - $model = $this->LIB->get($model_class_name); | |
| 1571 | -        if (! $model instanceof EEM_Base) { | |
| 1572 | - return null; | |
| 1573 | - } | |
| 1574 | - // get that model reset it and make sure we nuke the old reference to it | |
| 1575 | -        if ($model instanceof $model_class_name && is_callable([$model_class_name, 'reset'])) { | |
| 1576 | - $this->LIB->remove($model_class_name); | |
| 1577 | - $this->LIB->add($model_class_name, $model->reset()); | |
| 1578 | -        } else { | |
| 1579 | - throw new EE_Error( | |
| 1580 | - sprintf( | |
| 1581 | -                    esc_html__('Model %s does not have a method "reset"', 'event_espresso'), | |
| 1582 | - $model_name | |
| 1583 | - ) | |
| 1584 | - ); | |
| 1585 | - } | |
| 1586 | - return $model; | |
| 1587 | - } | |
| 1588 | - | |
| 1589 | - | |
| 1590 | - /** | |
| 1591 | - * Resets the registry. | |
| 1592 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when | |
| 1593 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. | |
| 1594 | - * - $_dependency_map | |
| 1595 | - * - $_class_abbreviations | |
| 1596 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. | |
| 1597 | - * - $REQ: Still on the same request so no need to change. | |
| 1598 | - * - $CAP: There is no site specific state in the EE_Capability class. | |
| 1599 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only | |
| 1600 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. | |
| 1601 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So | |
| 1602 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the | |
| 1603 | - * switch or on the restore. | |
| 1604 | - * - $modules | |
| 1605 | - * - $shortcodes | |
| 1606 | - * - $widgets | |
| 1607 | - * | |
| 1608 | - * @param boolean $hard [deprecated] | |
| 1609 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, | |
| 1610 | - * or just reset without re-instantiating (handy to set to FALSE if you're not | |
| 1611 | - * sure if you CAN currently reinstantiate the singletons at the moment) | |
| 1612 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so | |
| 1613 | - * client | |
| 1614 | - * code instead can just change the model context to a different blog id if | |
| 1615 | - * necessary | |
| 1616 | - * @return EE_Registry | |
| 1617 | - * @throws InvalidInterfaceException | |
| 1618 | - * @throws InvalidDataTypeException | |
| 1619 | - * @throws EE_Error | |
| 1620 | - * @throws ReflectionException | |
| 1621 | - * @throws InvalidArgumentException | |
| 1622 | - */ | |
| 1623 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) | |
| 1624 | -    { | |
| 1625 | - $instance = self::instance(); | |
| 1626 | - $instance->_cache_on = true; | |
| 1627 | - // reset some "special" classes | |
| 1628 | - EEH_Activation::reset(); | |
| 1629 | -        $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); | |
| 1630 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); | |
| 1631 | - $instance->CART = null; | |
| 1632 | - $instance->MRM = null; | |
| 1633 | - $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( | |
| 1634 | - 'EventEspresso\core\services\assets\Registry' | |
| 1635 | - ); | |
| 1636 | - // messages reset | |
| 1637 | - EED_Messages::reset(); | |
| 1638 | - // handle of objects cached on LIB | |
| 1639 | -        foreach (array('LIB', 'modules') as $cache) { | |
| 1640 | -            foreach ($instance->{$cache} as $class_name => $class) { | |
| 1641 | -                if (self::_reset_and_unset_object($class, $reset_models)) { | |
| 1642 | -                    unset($instance->{$cache}->{$class_name}); | |
| 1643 | - } | |
| 1644 | - } | |
| 1645 | - } | |
| 1646 | - return $instance; | |
| 1647 | - } | |
| 1648 | - | |
| 1649 | - | |
| 1650 | - /** | |
| 1651 | - * if passed object implements ResettableInterface, then call it's reset() method | |
| 1652 | - * if passed object implements InterminableInterface, then return false, | |
| 1653 | - * to indicate that it should NOT be cleared from the Registry cache | |
| 1654 | - * | |
| 1655 | - * @param $object | |
| 1656 | - * @param bool $reset_models | |
| 1657 | - * @return bool returns true if cached object should be unset | |
| 1658 | - */ | |
| 1659 | - private static function _reset_and_unset_object($object, $reset_models) | |
| 1660 | -    { | |
| 1661 | -        if (! is_object($object)) { | |
| 1662 | - // don't unset anything that's not an object | |
| 1663 | - return false; | |
| 1664 | - } | |
| 1665 | -        if ($object instanceof EED_Module) { | |
| 1666 | - $object::reset(); | |
| 1667 | - // don't unset modules | |
| 1668 | - return false; | |
| 1669 | - } | |
| 1670 | -        if ($object instanceof ResettableInterface) { | |
| 1671 | -            if ($object instanceof EEM_Base) { | |
| 1672 | -                if ($reset_models) { | |
| 1673 | - $object->reset(); | |
| 1674 | - return true; | |
| 1675 | - } | |
| 1676 | - return false; | |
| 1677 | - } | |
| 1678 | - $object->reset(); | |
| 1679 | - return true; | |
| 1680 | - } | |
| 1681 | -        if (! $object instanceof InterminableInterface) { | |
| 1682 | - return true; | |
| 1683 | - } | |
| 1684 | - return false; | |
| 1685 | - } | |
| 1686 | - | |
| 1687 | - | |
| 1688 | - /** | |
| 1689 | - * Gets all the custom post type models defined | |
| 1690 | - * | |
| 1691 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") | |
| 1692 | - */ | |
| 1693 | - public function cpt_models() | |
| 1694 | -    { | |
| 1695 | - $cpt_models = array(); | |
| 1696 | -        foreach ($this->non_abstract_db_models as $short_name => $classname) { | |
| 1697 | -            if (is_subclass_of($classname, 'EEM_CPT_Base')) { | |
| 1698 | - $cpt_models[ $short_name ] = $classname; | |
| 1699 | - } | |
| 1700 | - } | |
| 1701 | - return $cpt_models; | |
| 1702 | - } | |
| 1703 | - | |
| 1704 | - | |
| 1705 | - /** | |
| 1706 | - * @return \EE_Config | |
| 1707 | - */ | |
| 1708 | - public static function CFG() | |
| 1709 | -    { | |
| 1710 | - return self::instance()->CFG; | |
| 1711 | - } | |
| 1712 | - | |
| 1713 | - | |
| 1714 | - /** | |
| 1715 | - * @deprecated 4.9.62.p | |
| 1716 | - * @param string $class_name | |
| 1717 | - * @return ReflectionClass | |
| 1718 | - * @throws ReflectionException | |
| 1719 | - * @throws InvalidDataTypeException | |
| 1720 | - */ | |
| 1721 | - public function get_ReflectionClass($class_name) | |
| 1722 | -    { | |
| 1723 | - return $this->mirror->getReflectionClass($class_name); | |
| 1724 | - } | |
| 982 | + ! $this->object_identifier->hasArguments($object_identifier) | |
| 983 | + // but previously cached class with args was found | |
| 984 | + && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) | |
| 985 | +			) { | |
| 986 | + return $object; | |
| 987 | + } | |
| 988 | + } | |
| 989 | + return null; | |
| 990 | + } | |
| 991 | + | |
| 992 | + | |
| 993 | + /** | |
| 994 | + * removes a cached version of the requested class | |
| 995 | + * | |
| 996 | + * @param string $class_name | |
| 997 | + * @param boolean $addon | |
| 998 | + * @param array $arguments | |
| 999 | + * @return boolean | |
| 1000 | + */ | |
| 1001 | + public function clear_cached_class( | |
| 1002 | + $class_name, | |
| 1003 | + $addon = false, | |
| 1004 | + $arguments = array() | |
| 1005 | +	) { | |
| 1006 | + $class_abbreviation = $this->get_class_abbreviation($class_name); | |
| 1007 | + // check if class has already been loaded, and return it if it has been | |
| 1008 | +		if (isset($this->{$class_abbreviation})) { | |
| 1009 | +			$this->{$class_abbreviation} = null; | |
| 1010 | + return true; | |
| 1011 | + } | |
| 1012 | +		$class_name = str_replace('\\', '_', $class_name); | |
| 1013 | +		if (isset($this->{$class_name})) { | |
| 1014 | +			$this->{$class_name} = null; | |
| 1015 | + return true; | |
| 1016 | + } | |
| 1017 | +		if ($addon && $this->addons->has($class_name)) { | |
| 1018 | + $this->addons->remove($class_name); | |
| 1019 | + return true; | |
| 1020 | + } | |
| 1021 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); | |
| 1022 | +		if ($this->LIB->has($class_name)) { | |
| 1023 | + $this->LIB->remove($class_name); | |
| 1024 | + return true; | |
| 1025 | + } | |
| 1026 | + return false; | |
| 1027 | + } | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + /** | |
| 1031 | + * _set_cached_class | |
| 1032 | + * attempts to cache the instantiated class locally | |
| 1033 | + * in one of the following places, in the following order: | |
| 1034 | +	 *        $this->{class_abbreviation}   ie:    $this->CART | |
| 1035 | +	 *        $this->{$class_name}          ie:    $this->Some_Class | |
| 1036 | +	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class | |
| 1037 | +	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class | |
| 1038 | + * | |
| 1039 | + * @param object $class_obj | |
| 1040 | + * @param string $class_name | |
| 1041 | + * @param string $class_prefix | |
| 1042 | + * @param bool $from_db | |
| 1043 | + * @param array $arguments | |
| 1044 | + * @return void | |
| 1045 | + */ | |
| 1046 | + protected function _set_cached_class( | |
| 1047 | + $class_obj, | |
| 1048 | + $class_name, | |
| 1049 | + $class_prefix = '', | |
| 1050 | + $from_db = false, | |
| 1051 | + $arguments = array() | |
| 1052 | +	) { | |
| 1053 | +		if ($class_name === 'EE_Registry' || empty($class_obj)) { | |
| 1054 | + return; | |
| 1055 | + } | |
| 1056 | + // return newly instantiated class | |
| 1057 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); | |
| 1058 | +		if ($class_abbreviation) { | |
| 1059 | +			$this->{$class_abbreviation} = $class_obj; | |
| 1060 | + return; | |
| 1061 | + } | |
| 1062 | +		$class_name = str_replace('\\', '_', $class_name); | |
| 1063 | +		if (property_exists($this, $class_name)) { | |
| 1064 | +			$this->{$class_name} = $class_obj; | |
| 1065 | + return; | |
| 1066 | + } | |
| 1067 | +		if ($class_prefix === 'addon') { | |
| 1068 | + $this->addons->add($class_name, $class_obj); | |
| 1069 | + return; | |
| 1070 | + } | |
| 1071 | +		if (! $from_db) { | |
| 1072 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); | |
| 1073 | + $this->LIB->add($class_name, $class_obj); | |
| 1074 | + } | |
| 1075 | + } | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + /** | |
| 1079 | + * attempts to find a full valid filepath for the requested class. | |
| 1080 | +	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" | |
| 1081 | + * then returns that path if the target file has been found and is readable | |
| 1082 | + * | |
| 1083 | + * @param string $class_name | |
| 1084 | + * @param string $type | |
| 1085 | + * @param array $file_paths | |
| 1086 | + * @return string | bool | |
| 1087 | + */ | |
| 1088 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) | |
| 1089 | +	{ | |
| 1090 | + // make sure $file_paths is an array | |
| 1091 | + $file_paths = is_array($file_paths) | |
| 1092 | + ? $file_paths | |
| 1093 | + : array($file_paths); | |
| 1094 | + // cycle thru paths | |
| 1095 | +		foreach ($file_paths as $key => $file_path) { | |
| 1096 | + // convert all separators to proper /, if no filepath, then use EE_CLASSES | |
| 1097 | + $file_path = $file_path | |
| 1098 | +				? str_replace(array('/', '\\'), '/', $file_path) | |
| 1099 | + : EE_CLASSES; | |
| 1100 | + // prep file type | |
| 1101 | + $type = ! empty($type) | |
| 1102 | + ? trim($type, '.') . '.' | |
| 1103 | + : ''; | |
| 1104 | + // build full file path | |
| 1105 | + $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; | |
| 1106 | + // does the file exist and can be read ? | |
| 1107 | +			if (is_readable($file_paths[ $key ])) { | |
| 1108 | + return $file_paths[ $key ]; | |
| 1109 | + } | |
| 1110 | + } | |
| 1111 | + return false; | |
| 1112 | + } | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + /** | |
| 1116 | + * basically just performs a require_once() | |
| 1117 | + * but with some error handling | |
| 1118 | + * | |
| 1119 | + * @param string $path | |
| 1120 | + * @param string $class_name | |
| 1121 | + * @param string $type | |
| 1122 | + * @param array $file_paths | |
| 1123 | + * @return bool | |
| 1124 | + * @throws EE_Error | |
| 1125 | + * @throws ReflectionException | |
| 1126 | + */ | |
| 1127 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) | |
| 1128 | +	{ | |
| 1129 | + $this->resolve_legacy_class_parent($class_name); | |
| 1130 | + // don't give up! you gotta... | |
| 1131 | +		try { | |
| 1132 | + // does the file exist and can it be read ? | |
| 1133 | +			if (! $path) { | |
| 1134 | + // just in case the file has already been autoloaded, | |
| 1135 | + // but discrepancies in the naming schema are preventing it from | |
| 1136 | + // being loaded via one of the EE_Registry::load_*() methods, | |
| 1137 | + // then let's try one last hail mary before throwing an exception | |
| 1138 | + // and call class_exists() again, but with autoloading turned ON | |
| 1139 | +				if (class_exists($class_name)) { | |
| 1140 | + return true; | |
| 1141 | + } | |
| 1142 | + // so sorry, can't find the file | |
| 1143 | + throw new EE_Error( | |
| 1144 | + sprintf( | |
| 1145 | + esc_html__( | |
| 1146 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', | |
| 1147 | + 'event_espresso' | |
| 1148 | + ), | |
| 1149 | + trim($type, '.'), | |
| 1150 | + $class_name, | |
| 1151 | +						'<br />' . implode(',<br />', $file_paths) | |
| 1152 | + ) | |
| 1153 | + ); | |
| 1154 | + } | |
| 1155 | + // get the file | |
| 1156 | + require_once($path); | |
| 1157 | + // if the class isn't already declared somewhere | |
| 1158 | +			if (class_exists($class_name, false) === false) { | |
| 1159 | + // so sorry, not a class | |
| 1160 | + throw new EE_Error( | |
| 1161 | + sprintf( | |
| 1162 | + esc_html__( | |
| 1163 | + 'The %s file %s does not appear to contain the %s Class.', | |
| 1164 | + 'event_espresso' | |
| 1165 | + ), | |
| 1166 | + $type, | |
| 1167 | + $path, | |
| 1168 | + $class_name | |
| 1169 | + ) | |
| 1170 | + ); | |
| 1171 | + } | |
| 1172 | +		} catch (EE_Error $e) { | |
| 1173 | + $e->get_error(); | |
| 1174 | + return false; | |
| 1175 | + } | |
| 1176 | + return true; | |
| 1177 | + } | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + /** | |
| 1181 | + * Some of our legacy classes that extended a parent class would simply use a require() statement | |
| 1182 | + * before their class declaration in order to ensure that the parent class was loaded. | |
| 1183 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, | |
| 1184 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. | |
| 1185 | + * | |
| 1186 | + * @param string $class_name | |
| 1187 | + */ | |
| 1188 | + protected function resolve_legacy_class_parent($class_name = '') | |
| 1189 | +	{ | |
| 1190 | +		try { | |
| 1191 | + $legacy_parent_class_map = array( | |
| 1192 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', | |
| 1193 | + ); | |
| 1194 | +			if (isset($legacy_parent_class_map[ $class_name ])) { | |
| 1195 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; | |
| 1196 | + } | |
| 1197 | +		} catch (Exception $exception) { | |
| 1198 | + } | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + /** | |
| 1203 | + * _create_object | |
| 1204 | + * Attempts to instantiate the requested class via any of the | |
| 1205 | + * commonly used instantiation methods employed throughout EE. | |
| 1206 | + * The priority for instantiation is as follows: | |
| 1207 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) | |
| 1208 | + * - model objects via their 'new_instance_from_db' method | |
| 1209 | + * - model objects via their 'new_instance' method | |
| 1210 | + * - "singleton" classes" via their 'instance' method | |
| 1211 | + * - standard instantiable classes via their __constructor | |
| 1212 | + * Prior to instantiation, if the classname exists in the dependency_map, | |
| 1213 | + * then the constructor for the requested class will be examined to determine | |
| 1214 | + * if any dependencies exist, and if they can be injected. | |
| 1215 | + * If so, then those classes will be added to the array of arguments passed to the constructor | |
| 1216 | + * | |
| 1217 | + * @param string $class_name | |
| 1218 | + * @param array $arguments | |
| 1219 | + * @param string $type | |
| 1220 | + * @param bool $from_db | |
| 1221 | + * @return null|object|bool | |
| 1222 | + * @throws InvalidArgumentException | |
| 1223 | + * @throws InvalidInterfaceException | |
| 1224 | + * @throws EE_Error | |
| 1225 | + * @throws ReflectionException | |
| 1226 | + * @throws InvalidDataTypeException | |
| 1227 | + */ | |
| 1228 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) | |
| 1229 | +	{ | |
| 1230 | + // create reflection | |
| 1231 | + $reflector = $this->mirror->getReflectionClass($class_name); | |
| 1232 | + // make sure arguments are an array | |
| 1233 | + $arguments = is_array($arguments) | |
| 1234 | + ? $arguments | |
| 1235 | + : array($arguments); | |
| 1236 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, | |
| 1237 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters | |
| 1238 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) | |
| 1239 | + ? $arguments | |
| 1240 | + : array($arguments); | |
| 1241 | + // attempt to inject dependencies ? | |
| 1242 | +		if ($this->_dependency_map->has($class_name)) { | |
| 1243 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); | |
| 1244 | + } | |
| 1245 | + // instantiate the class if possible | |
| 1246 | +		if ($reflector->isAbstract()) { | |
| 1247 | + // nothing to instantiate, loading file was enough | |
| 1248 | + // does not throw an exception so $instantiation_mode is unused | |
| 1249 | + // $instantiation_mode = "1) no constructor abstract class"; | |
| 1250 | + return true; | |
| 1251 | + } | |
| 1252 | + if ( | |
| 1253 | + empty($arguments) | |
| 1254 | + && $this->mirror->getConstructorFromReflection($reflector) === null | |
| 1255 | + && $reflector->isInstantiable() | |
| 1256 | +		) { | |
| 1257 | + // no constructor = static methods only... nothing to instantiate, loading file was enough | |
| 1258 | + // $instantiation_mode = "2) no constructor but instantiable"; | |
| 1259 | + return $reflector->newInstance(); | |
| 1260 | + } | |
| 1261 | +		if ($from_db && method_exists($class_name, 'new_instance_from_db')) { | |
| 1262 | + // $instantiation_mode = "3) new_instance_from_db()"; | |
| 1263 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); | |
| 1264 | + } | |
| 1265 | +		if (method_exists($class_name, 'new_instance')) { | |
| 1266 | + // $instantiation_mode = "4) new_instance()"; | |
| 1267 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); | |
| 1268 | + } | |
| 1269 | +		if (method_exists($class_name, 'instance')) { | |
| 1270 | + // $instantiation_mode = "5) instance()"; | |
| 1271 | + return call_user_func_array(array($class_name, 'instance'), $arguments); | |
| 1272 | + } | |
| 1273 | +		if ($reflector->isInstantiable()) { | |
| 1274 | + // $instantiation_mode = "6) constructor"; | |
| 1275 | + return $reflector->newInstanceArgs($arguments); | |
| 1276 | + } | |
| 1277 | + // heh ? something's not right ! | |
| 1278 | + throw new EE_Error( | |
| 1279 | + sprintf( | |
| 1280 | +				esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), | |
| 1281 | + $type, | |
| 1282 | + $class_name | |
| 1283 | + ) | |
| 1284 | + ); | |
| 1285 | + } | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + /** | |
| 1289 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential | |
| 1290 | + * @param array $array | |
| 1291 | + * @return bool | |
| 1292 | + */ | |
| 1293 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) | |
| 1294 | +	{ | |
| 1295 | + return ! empty($array) | |
| 1296 | + ? array_keys($array) === range(0, count($array) - 1) | |
| 1297 | + : true; | |
| 1298 | + } | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + /** | |
| 1302 | + * _resolve_dependencies | |
| 1303 | + * examines the constructor for the requested class to determine | |
| 1304 | + * if any dependencies exist, and if they can be injected. | |
| 1305 | + * If so, then those classes will be added to the array of arguments passed to the constructor | |
| 1306 | + * PLZ NOTE: this is achieved by type hinting the constructor params | |
| 1307 | + * For example: | |
| 1308 | + * if attempting to load a class "Foo" with the following constructor: | |
| 1309 | + * __construct( Bar $bar_class, Fighter $grohl_class ) | |
| 1310 | + * then $bar_class and $grohl_class will be added to the $arguments array, | |
| 1311 | + * but only IF they are NOT already present in the incoming arguments array, | |
| 1312 | + * and the correct classes can be loaded | |
| 1313 | + * | |
| 1314 | + * @param ReflectionClass $reflector | |
| 1315 | + * @param string $class_name | |
| 1316 | + * @param array $arguments | |
| 1317 | + * @return array | |
| 1318 | + * @throws InvalidArgumentException | |
| 1319 | + * @throws InvalidDataTypeException | |
| 1320 | + * @throws InvalidInterfaceException | |
| 1321 | + * @throws ReflectionException | |
| 1322 | + */ | |
| 1323 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) | |
| 1324 | +	{ | |
| 1325 | + // let's examine the constructor | |
| 1326 | + $constructor = $this->mirror->getConstructorFromReflection($reflector); | |
| 1327 | + // whu? huh? nothing? | |
| 1328 | +		if (! $constructor) { | |
| 1329 | + return $arguments; | |
| 1330 | + } | |
| 1331 | + // get constructor parameters | |
| 1332 | + $params = $this->mirror->getParametersFromReflection($reflector); | |
| 1333 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected | |
| 1334 | + $argument_keys = array_keys($arguments); | |
| 1335 | + // now loop thru all of the constructors expected parameters | |
| 1336 | +		foreach ($params as $index => $param) { | |
| 1337 | +			try { | |
| 1338 | + // is this a dependency for a specific class ? | |
| 1339 | + $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); | |
| 1340 | +			} catch (ReflectionException $exception) { | |
| 1341 | + // uh-oh... most likely a legacy class that has not been autoloaded | |
| 1342 | + // let's try to derive the classname from what we have now | |
| 1343 | + // and hope that the property var name is close to the class name | |
| 1344 | + $param_class = $param->getName(); | |
| 1345 | +				$param_class = str_replace('_', ' ', $param_class); | |
| 1346 | + $param_class = ucwords($param_class); | |
| 1347 | +				$param_class = str_replace(' ', '_', $param_class); | |
| 1348 | + } | |
| 1349 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) | |
| 1350 | + $param_class = $this->class_cache->isAlias($param_class, $class_name) | |
| 1351 | + ? $this->class_cache->getFqnForAlias($param_class, $class_name) | |
| 1352 | + : $param_class; | |
| 1353 | + if ( | |
| 1354 | + // param is not even a class | |
| 1355 | + $param_class === null | |
| 1356 | + // and something already exists in the incoming arguments for this param | |
| 1357 | + && array_key_exists($index, $argument_keys) | |
| 1358 | + && array_key_exists($argument_keys[ $index ], $arguments) | |
| 1359 | +			) { | |
| 1360 | + // so let's skip this argument and move on to the next | |
| 1361 | + continue; | |
| 1362 | + } | |
| 1363 | + if ( | |
| 1364 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class | |
| 1365 | + $param_class !== null | |
| 1366 | + && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) | |
| 1367 | + && $arguments[ $argument_keys[ $index ] ] instanceof $param_class | |
| 1368 | +			) { | |
| 1369 | + // skip this argument and move on to the next | |
| 1370 | + continue; | |
| 1371 | + } | |
| 1372 | + if ( | |
| 1373 | + // parameter is type hinted as a class, and should be injected | |
| 1374 | + $param_class !== null | |
| 1375 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) | |
| 1376 | +			) { | |
| 1377 | + $arguments = $this->_resolve_dependency( | |
| 1378 | + $class_name, | |
| 1379 | + $param_class, | |
| 1380 | + $arguments, | |
| 1381 | + $index | |
| 1382 | + ); | |
| 1383 | + } | |
| 1384 | +			if (empty($arguments[ $index ])) { | |
| 1385 | + $default_value = $this->mirror->getParameterDefaultValue( | |
| 1386 | + $param, | |
| 1387 | + $class_name, | |
| 1388 | + $index | |
| 1389 | + ); | |
| 1390 | + // if there's no default value, and the incoming argument is an array (albeit empty), then use that | |
| 1391 | + $arguments[ $index ] = $default_value === null | |
| 1392 | + && isset($arguments[ $index ]) | |
| 1393 | + && is_array($arguments[ $index ]) | |
| 1394 | + ? $arguments[ $index ] | |
| 1395 | + : $default_value; | |
| 1396 | + } | |
| 1397 | + } | |
| 1398 | + return $arguments; | |
| 1399 | + } | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + /** | |
| 1403 | + * @param string $class_name | |
| 1404 | + * @param string $param_class | |
| 1405 | + * @param array $arguments | |
| 1406 | + * @param mixed $index | |
| 1407 | + * @return array | |
| 1408 | + * @throws InvalidArgumentException | |
| 1409 | + * @throws InvalidInterfaceException | |
| 1410 | + * @throws InvalidDataTypeException | |
| 1411 | + */ | |
| 1412 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) | |
| 1413 | +	{ | |
| 1414 | + $dependency = null; | |
| 1415 | + // should dependency be loaded from cache ? | |
| 1416 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( | |
| 1417 | + $class_name, | |
| 1418 | + $param_class | |
| 1419 | + ); | |
| 1420 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; | |
| 1421 | + // we might have a dependency... | |
| 1422 | + // let's MAYBE try and find it in our cache if that's what's been requested | |
| 1423 | + $cached_class = $cache_on | |
| 1424 | + ? $this->_get_cached_class($param_class) | |
| 1425 | + : null; | |
| 1426 | + // and grab it if it exists | |
| 1427 | +		if ($cached_class instanceof $param_class) { | |
| 1428 | + $dependency = $cached_class; | |
| 1429 | +		} elseif ($param_class !== $class_name) { | |
| 1430 | + // obtain the loader method from the dependency map | |
| 1431 | + $loader = $this->_dependency_map->class_loader($param_class); | |
| 1432 | + // is loader a custom closure ? | |
| 1433 | +			if ($loader instanceof Closure) { | |
| 1434 | + $dependency = $loader($arguments); | |
| 1435 | +			} else { | |
| 1436 | + // set the cache on property for the recursive loading call | |
| 1437 | + $this->_cache_on = $cache_on; | |
| 1438 | + // if not, then let's try and load it via the registry | |
| 1439 | +				if ($loader && method_exists($this, $loader)) { | |
| 1440 | +					$dependency = $this->{$loader}($param_class); | |
| 1441 | +				} else { | |
| 1442 | + $dependency = LoaderFactory::getLoader()->load( | |
| 1443 | + $param_class, | |
| 1444 | + array(), | |
| 1445 | + $cache_on | |
| 1446 | + ); | |
| 1447 | + } | |
| 1448 | + } | |
| 1449 | + } | |
| 1450 | + // did we successfully find the correct dependency ? | |
| 1451 | +		if ($dependency instanceof $param_class) { | |
| 1452 | + // then let's inject it into the incoming array of arguments at the correct location | |
| 1453 | + $arguments[ $index ] = $dependency; | |
| 1454 | + } | |
| 1455 | + return $arguments; | |
| 1456 | + } | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + /** | |
| 1460 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array | |
| 1461 | + * | |
| 1462 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered | |
| 1463 | + * in the EE_Dependency_Map::$_class_loaders array, | |
| 1464 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc | |
| 1465 | + * @param array $arguments | |
| 1466 | + * @return object | |
| 1467 | + */ | |
| 1468 | + public static function factory($classname, $arguments = array()) | |
| 1469 | +	{ | |
| 1470 | + $loader = self::instance()->_dependency_map->class_loader($classname); | |
| 1471 | +		if ($loader instanceof Closure) { | |
| 1472 | + return $loader($arguments); | |
| 1473 | + } | |
| 1474 | +		if (method_exists(self::instance(), $loader)) { | |
| 1475 | +			return self::instance()->{$loader}($classname, $arguments); | |
| 1476 | + } | |
| 1477 | + return null; | |
| 1478 | + } | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + /** | |
| 1482 | + * Gets the addon by its class name | |
| 1483 | + * | |
| 1484 | + * @param string $class_name | |
| 1485 | + * @return EE_Addon | |
| 1486 | + */ | |
| 1487 | + public function getAddon($class_name) | |
| 1488 | +	{ | |
| 1489 | +		$class_name = str_replace('\\', '_', $class_name); | |
| 1490 | +		if (isset($this->addons->{$class_name})) { | |
| 1491 | +			return $this->addons->{$class_name}; | |
| 1492 | +		} else { | |
| 1493 | + return null; | |
| 1494 | + } | |
| 1495 | + } | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + /** | |
| 1499 | + * removes the addon from the internal cache | |
| 1500 | + * | |
| 1501 | + * @param string $class_name | |
| 1502 | + * @return void | |
| 1503 | + */ | |
| 1504 | + public function removeAddon($class_name) | |
| 1505 | +	{ | |
| 1506 | +		$class_name = str_replace('\\', '_', $class_name); | |
| 1507 | + $this->addons->remove($class_name); | |
| 1508 | + } | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + /** | |
| 1512 | + * Gets the addon by its name/slug (not classname. For that, just | |
| 1513 | + * use the get_addon() method above | |
| 1514 | + * | |
| 1515 | + * @param string $name | |
| 1516 | + * @return EE_Addon | |
| 1517 | + */ | |
| 1518 | + public function get_addon_by_name($name) | |
| 1519 | +	{ | |
| 1520 | +		foreach ($this->addons as $addon) { | |
| 1521 | +			if ($addon->name() === $name) { | |
| 1522 | + return $addon; | |
| 1523 | + } | |
| 1524 | + } | |
| 1525 | + return null; | |
| 1526 | + } | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + /** | |
| 1530 | + * Gets an array of all the registered addons, where the keys are their names. | |
| 1531 | + * (ie, what each returns for their name() function) | |
| 1532 | + * They're already available on EE_Registry::instance()->addons as properties, | |
| 1533 | + * where each property's name is the addon's classname, | |
| 1534 | + * So if you just want to get the addon by classname, | |
| 1535 | + * OR use the get_addon() method above. | |
| 1536 | + * PLEASE NOTE: | |
| 1537 | + * addons with Fully Qualified Class Names | |
| 1538 | + * have had the namespace separators converted to underscores, | |
| 1539 | + * so a classname like Fully\Qualified\ClassName | |
| 1540 | + * would have been converted to Fully_Qualified_ClassName | |
| 1541 | + * | |
| 1542 | + * @return EE_Addon[] where the KEYS are the addon's name() | |
| 1543 | + */ | |
| 1544 | + public function get_addons_by_name() | |
| 1545 | +	{ | |
| 1546 | + $addons = array(); | |
| 1547 | +		foreach ($this->addons as $addon) { | |
| 1548 | + $addons[ $addon->name() ] = $addon; | |
| 1549 | + } | |
| 1550 | + return $addons; | |
| 1551 | + } | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + /** | |
| 1555 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep | |
| 1556 | + * a stale copy of it around | |
| 1557 | + * | |
| 1558 | + * @param string $model_name | |
| 1559 | + * @return \EEM_Base | |
| 1560 | + * @throws \EE_Error | |
| 1561 | + */ | |
| 1562 | + public function reset_model($model_name) | |
| 1563 | +	{ | |
| 1564 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 | |
| 1565 | +			? "EEM_{$model_name}" | |
| 1566 | + : $model_name; | |
| 1567 | +		if (! $this->LIB->has($model_class_name)) { | |
| 1568 | + return null; | |
| 1569 | + } | |
| 1570 | + $model = $this->LIB->get($model_class_name); | |
| 1571 | +		if (! $model instanceof EEM_Base) { | |
| 1572 | + return null; | |
| 1573 | + } | |
| 1574 | + // get that model reset it and make sure we nuke the old reference to it | |
| 1575 | +		if ($model instanceof $model_class_name && is_callable([$model_class_name, 'reset'])) { | |
| 1576 | + $this->LIB->remove($model_class_name); | |
| 1577 | + $this->LIB->add($model_class_name, $model->reset()); | |
| 1578 | +		} else { | |
| 1579 | + throw new EE_Error( | |
| 1580 | + sprintf( | |
| 1581 | +					esc_html__('Model %s does not have a method "reset"', 'event_espresso'), | |
| 1582 | + $model_name | |
| 1583 | + ) | |
| 1584 | + ); | |
| 1585 | + } | |
| 1586 | + return $model; | |
| 1587 | + } | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + /** | |
| 1591 | + * Resets the registry. | |
| 1592 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when | |
| 1593 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. | |
| 1594 | + * - $_dependency_map | |
| 1595 | + * - $_class_abbreviations | |
| 1596 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. | |
| 1597 | + * - $REQ: Still on the same request so no need to change. | |
| 1598 | + * - $CAP: There is no site specific state in the EE_Capability class. | |
| 1599 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only | |
| 1600 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. | |
| 1601 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So | |
| 1602 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the | |
| 1603 | + * switch or on the restore. | |
| 1604 | + * - $modules | |
| 1605 | + * - $shortcodes | |
| 1606 | + * - $widgets | |
| 1607 | + * | |
| 1608 | + * @param boolean $hard [deprecated] | |
| 1609 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, | |
| 1610 | + * or just reset without re-instantiating (handy to set to FALSE if you're not | |
| 1611 | + * sure if you CAN currently reinstantiate the singletons at the moment) | |
| 1612 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so | |
| 1613 | + * client | |
| 1614 | + * code instead can just change the model context to a different blog id if | |
| 1615 | + * necessary | |
| 1616 | + * @return EE_Registry | |
| 1617 | + * @throws InvalidInterfaceException | |
| 1618 | + * @throws InvalidDataTypeException | |
| 1619 | + * @throws EE_Error | |
| 1620 | + * @throws ReflectionException | |
| 1621 | + * @throws InvalidArgumentException | |
| 1622 | + */ | |
| 1623 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) | |
| 1624 | +	{ | |
| 1625 | + $instance = self::instance(); | |
| 1626 | + $instance->_cache_on = true; | |
| 1627 | + // reset some "special" classes | |
| 1628 | + EEH_Activation::reset(); | |
| 1629 | +		$hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); | |
| 1630 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); | |
| 1631 | + $instance->CART = null; | |
| 1632 | + $instance->MRM = null; | |
| 1633 | + $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( | |
| 1634 | + 'EventEspresso\core\services\assets\Registry' | |
| 1635 | + ); | |
| 1636 | + // messages reset | |
| 1637 | + EED_Messages::reset(); | |
| 1638 | + // handle of objects cached on LIB | |
| 1639 | +		foreach (array('LIB', 'modules') as $cache) { | |
| 1640 | +			foreach ($instance->{$cache} as $class_name => $class) { | |
| 1641 | +				if (self::_reset_and_unset_object($class, $reset_models)) { | |
| 1642 | +					unset($instance->{$cache}->{$class_name}); | |
| 1643 | + } | |
| 1644 | + } | |
| 1645 | + } | |
| 1646 | + return $instance; | |
| 1647 | + } | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + /** | |
| 1651 | + * if passed object implements ResettableInterface, then call it's reset() method | |
| 1652 | + * if passed object implements InterminableInterface, then return false, | |
| 1653 | + * to indicate that it should NOT be cleared from the Registry cache | |
| 1654 | + * | |
| 1655 | + * @param $object | |
| 1656 | + * @param bool $reset_models | |
| 1657 | + * @return bool returns true if cached object should be unset | |
| 1658 | + */ | |
| 1659 | + private static function _reset_and_unset_object($object, $reset_models) | |
| 1660 | +	{ | |
| 1661 | +		if (! is_object($object)) { | |
| 1662 | + // don't unset anything that's not an object | |
| 1663 | + return false; | |
| 1664 | + } | |
| 1665 | +		if ($object instanceof EED_Module) { | |
| 1666 | + $object::reset(); | |
| 1667 | + // don't unset modules | |
| 1668 | + return false; | |
| 1669 | + } | |
| 1670 | +		if ($object instanceof ResettableInterface) { | |
| 1671 | +			if ($object instanceof EEM_Base) { | |
| 1672 | +				if ($reset_models) { | |
| 1673 | + $object->reset(); | |
| 1674 | + return true; | |
| 1675 | + } | |
| 1676 | + return false; | |
| 1677 | + } | |
| 1678 | + $object->reset(); | |
| 1679 | + return true; | |
| 1680 | + } | |
| 1681 | +		if (! $object instanceof InterminableInterface) { | |
| 1682 | + return true; | |
| 1683 | + } | |
| 1684 | + return false; | |
| 1685 | + } | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + /** | |
| 1689 | + * Gets all the custom post type models defined | |
| 1690 | + * | |
| 1691 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") | |
| 1692 | + */ | |
| 1693 | + public function cpt_models() | |
| 1694 | +	{ | |
| 1695 | + $cpt_models = array(); | |
| 1696 | +		foreach ($this->non_abstract_db_models as $short_name => $classname) { | |
| 1697 | +			if (is_subclass_of($classname, 'EEM_CPT_Base')) { | |
| 1698 | + $cpt_models[ $short_name ] = $classname; | |
| 1699 | + } | |
| 1700 | + } | |
| 1701 | + return $cpt_models; | |
| 1702 | + } | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + /** | |
| 1706 | + * @return \EE_Config | |
| 1707 | + */ | |
| 1708 | + public static function CFG() | |
| 1709 | +	{ | |
| 1710 | + return self::instance()->CFG; | |
| 1711 | + } | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + /** | |
| 1715 | + * @deprecated 4.9.62.p | |
| 1716 | + * @param string $class_name | |
| 1717 | + * @return ReflectionClass | |
| 1718 | + * @throws ReflectionException | |
| 1719 | + * @throws InvalidDataTypeException | |
| 1720 | + */ | |
| 1721 | + public function get_ReflectionClass($class_name) | |
| 1722 | +	{ | |
| 1723 | + return $this->mirror->getReflectionClass($class_name); | |
| 1724 | + } | |
| 1725 | 1725 | } | 
| @@ -309,7 +309,7 @@ discard block | ||
| 309 | 309 |          foreach ($i18n_js_strings as $key => $value) { | 
| 310 | 310 |              if (is_scalar($value)) { | 
| 311 | 311 | $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); | 
| 312 | - $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); | |
| 312 | + $i18n_js_strings[$key] = wp_strip_all_tags($decoded_value); | |
| 313 | 313 | } | 
| 314 | 314 | } | 
| 315 | 315 | return $i18n_js_strings; | 
| @@ -324,7 +324,7 @@ discard block | ||
| 324 | 324 | public static function localize_i18n_js_strings() | 
| 325 | 325 |      { | 
| 326 | 326 | $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); | 
| 327 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; | |
| 327 | + return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */'; | |
| 328 | 328 | } | 
| 329 | 329 | |
| 330 | 330 | |
| @@ -343,7 +343,7 @@ discard block | ||
| 343 | 343 | $module_class = get_class($module); | 
| 344 | 344 | $this->modules->add($module_class, $module); | 
| 345 | 345 |          } else { | 
| 346 | -            if (! class_exists('EE_Module_Request_Router', false)) { | |
| 346 | +            if ( ! class_exists('EE_Module_Request_Router', false)) { | |
| 347 | 347 |                  $this->load_core('Module_Request_Router'); | 
| 348 | 348 | } | 
| 349 | 349 | EE_Module_Request_Router::module_factory($module); | 
| @@ -382,10 +382,10 @@ discard block | ||
| 382 | 382 | EE_CORE, | 
| 383 | 383 | EE_ADMIN, | 
| 384 | 384 | EE_CPTS, | 
| 385 | - EE_CORE . 'data_migration_scripts/', | |
| 386 | - EE_CORE . 'capabilities/', | |
| 387 | - EE_CORE . 'request_stack/', | |
| 388 | - EE_CORE . 'middleware/', | |
| 385 | + EE_CORE.'data_migration_scripts/', | |
| 386 | + EE_CORE.'capabilities/', | |
| 387 | + EE_CORE.'request_stack/', | |
| 388 | + EE_CORE.'middleware/', | |
| 389 | 389 | ) | 
| 390 | 390 | ); | 
| 391 | 391 | // retrieve instantiated class | 
| @@ -420,7 +420,7 @@ discard block | ||
| 420 | 420 | $service_paths = apply_filters( | 
| 421 | 421 | 'FHEE__EE_Registry__load_service__service_paths', | 
| 422 | 422 | array( | 
| 423 | - EE_CORE . 'services/', | |
| 423 | + EE_CORE.'services/', | |
| 424 | 424 | ) | 
| 425 | 425 | ); | 
| 426 | 426 | // retrieve instantiated class | 
| @@ -555,10 +555,10 @@ discard block | ||
| 555 | 555 |      { | 
| 556 | 556 | $paths = array( | 
| 557 | 557 | EE_LIBRARIES, | 
| 558 | - EE_LIBRARIES . 'messages/', | |
| 559 | - EE_LIBRARIES . 'shortcodes/', | |
| 560 | - EE_LIBRARIES . 'qtips/', | |
| 561 | - EE_LIBRARIES . 'payment_methods/', | |
| 558 | + EE_LIBRARIES.'messages/', | |
| 559 | + EE_LIBRARIES.'shortcodes/', | |
| 560 | + EE_LIBRARIES.'qtips/', | |
| 561 | + EE_LIBRARIES.'payment_methods/', | |
| 562 | 562 | ); | 
| 563 | 563 | // retrieve instantiated class | 
| 564 | 564 | return $this->_load( | 
| @@ -626,10 +626,10 @@ discard block | ||
| 626 | 626 | public function load_model_class($class_name, $arguments = array(), $load_only = true) | 
| 627 | 627 |      { | 
| 628 | 628 | $paths = array( | 
| 629 | - EE_MODELS . 'fields/', | |
| 630 | - EE_MODELS . 'helpers/', | |
| 631 | - EE_MODELS . 'relations/', | |
| 632 | - EE_MODELS . 'strategies/', | |
| 629 | + EE_MODELS.'fields/', | |
| 630 | + EE_MODELS.'helpers/', | |
| 631 | + EE_MODELS.'relations/', | |
| 632 | + EE_MODELS.'strategies/', | |
| 633 | 633 | ); | 
| 634 | 634 | // retrieve instantiated class | 
| 635 | 635 | return $this->_load( | 
| @@ -653,7 +653,7 @@ discard block | ||
| 653 | 653 | */ | 
| 654 | 654 | public function is_model_name($model_name) | 
| 655 | 655 |      { | 
| 656 | - return isset($this->models[ $model_name ]); | |
| 656 | + return isset($this->models[$model_name]); | |
| 657 | 657 | } | 
| 658 | 658 | |
| 659 | 659 | |
| @@ -774,7 +774,7 @@ discard block | ||
| 774 | 774 | return $cached_class; | 
| 775 | 775 | } | 
| 776 | 776 | }// obtain the loader method from the dependency map | 
| 777 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object | |
| 777 | + $loader = $this->_dependency_map->class_loader($class_name); // instantiate the requested object | |
| 778 | 778 |          if ($loader instanceof Closure) { | 
| 779 | 779 | $class_obj = $loader($arguments); | 
| 780 | 780 |          } else { | 
| @@ -816,7 +816,7 @@ discard block | ||
| 816 | 816 | case 1: | 
| 817 | 817 | // if it's a FQCN then maybe the class is registered with a preceding \ | 
| 818 | 818 | $class_name = strpos($class_name, '\\') !== false | 
| 819 | - ? '\\' . ltrim($class_name, '\\') | |
| 819 | + ? '\\'.ltrim($class_name, '\\') | |
| 820 | 820 | : $class_name; | 
| 821 | 821 | break; | 
| 822 | 822 | case 2: | 
| @@ -870,11 +870,11 @@ discard block | ||
| 870 | 870 | // strip php file extension | 
| 871 | 871 |          $class_name = str_replace('.php', '', trim($class_name)); | 
| 872 | 872 | // does the class have a prefix ? | 
| 873 | -        if (! empty($class_prefix) && $class_prefix !== 'addon') { | |
| 873 | +        if ( ! empty($class_prefix) && $class_prefix !== 'addon') { | |
| 874 | 874 | // make sure $class_prefix is uppercase | 
| 875 | 875 | $class_prefix = strtoupper(trim($class_prefix)); | 
| 876 | 876 | // add class prefix ONCE!!! | 
| 877 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); | |
| 877 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); | |
| 878 | 878 | } | 
| 879 | 879 | $class_name = $this->class_cache->getFqnForAlias($class_name); | 
| 880 | 880 | $class_exists = class_exists($class_name, false); | 
| @@ -894,7 +894,7 @@ discard block | ||
| 894 | 894 | } | 
| 895 | 895 | } | 
| 896 | 896 | // if the class doesn't already exist.. then we need to try and find the file and load it | 
| 897 | -        if (! $class_exists) { | |
| 897 | +        if ( ! $class_exists) { | |
| 898 | 898 | // get full path to file | 
| 899 | 899 | $path = $this->_resolve_path($class_name, $type, $file_paths); | 
| 900 | 900 | // load the file | 
| @@ -905,7 +905,7 @@ discard block | ||
| 905 | 905 | return $loaded; | 
| 906 | 906 | } | 
| 907 | 907 | // if an object was expected but loading failed, then return nothing | 
| 908 | -            if (! $loaded) { | |
| 908 | +            if ( ! $loaded) { | |
| 909 | 909 | return null; | 
| 910 | 910 | } | 
| 911 | 911 | } | 
| @@ -933,8 +933,8 @@ discard block | ||
| 933 | 933 | */ | 
| 934 | 934 | protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') | 
| 935 | 935 |      { | 
| 936 | - return isset($this->_class_abbreviations[ $class_name ]) | |
| 937 | - ? $this->_class_abbreviations[ $class_name ] | |
| 936 | + return isset($this->_class_abbreviations[$class_name]) | |
| 937 | + ? $this->_class_abbreviations[$class_name] | |
| 938 | 938 | : $default; | 
| 939 | 939 | } | 
| 940 | 940 | |
| @@ -1068,7 +1068,7 @@ discard block | ||
| 1068 | 1068 | $this->addons->add($class_name, $class_obj); | 
| 1069 | 1069 | return; | 
| 1070 | 1070 | } | 
| 1071 | -        if (! $from_db) { | |
| 1071 | +        if ( ! $from_db) { | |
| 1072 | 1072 | $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); | 
| 1073 | 1073 | $this->LIB->add($class_name, $class_obj); | 
| 1074 | 1074 | } | 
| @@ -1099,13 +1099,13 @@ discard block | ||
| 1099 | 1099 | : EE_CLASSES; | 
| 1100 | 1100 | // prep file type | 
| 1101 | 1101 | $type = ! empty($type) | 
| 1102 | - ? trim($type, '.') . '.' | |
| 1102 | + ? trim($type, '.').'.' | |
| 1103 | 1103 | : ''; | 
| 1104 | 1104 | // build full file path | 
| 1105 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; | |
| 1105 | + $file_paths[$key] = rtrim($file_path, '/').'/'.$class_name.'.'.$type.'php'; | |
| 1106 | 1106 | // does the file exist and can be read ? | 
| 1107 | -            if (is_readable($file_paths[ $key ])) { | |
| 1108 | - return $file_paths[ $key ]; | |
| 1107 | +            if (is_readable($file_paths[$key])) { | |
| 1108 | + return $file_paths[$key]; | |
| 1109 | 1109 | } | 
| 1110 | 1110 | } | 
| 1111 | 1111 | return false; | 
| @@ -1130,7 +1130,7 @@ discard block | ||
| 1130 | 1130 | // don't give up! you gotta... | 
| 1131 | 1131 |          try { | 
| 1132 | 1132 | // does the file exist and can it be read ? | 
| 1133 | -            if (! $path) { | |
| 1133 | +            if ( ! $path) { | |
| 1134 | 1134 | // just in case the file has already been autoloaded, | 
| 1135 | 1135 | // but discrepancies in the naming schema are preventing it from | 
| 1136 | 1136 | // being loaded via one of the EE_Registry::load_*() methods, | 
| @@ -1148,7 +1148,7 @@ discard block | ||
| 1148 | 1148 | ), | 
| 1149 | 1149 | trim($type, '.'), | 
| 1150 | 1150 | $class_name, | 
| 1151 | -                        '<br />' . implode(',<br />', $file_paths) | |
| 1151 | +                        '<br />'.implode(',<br />', $file_paths) | |
| 1152 | 1152 | ) | 
| 1153 | 1153 | ); | 
| 1154 | 1154 | } | 
| @@ -1191,8 +1191,8 @@ discard block | ||
| 1191 | 1191 | $legacy_parent_class_map = array( | 
| 1192 | 1192 | 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', | 
| 1193 | 1193 | ); | 
| 1194 | -            if (isset($legacy_parent_class_map[ $class_name ])) { | |
| 1195 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; | |
| 1194 | +            if (isset($legacy_parent_class_map[$class_name])) { | |
| 1195 | + require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name]; | |
| 1196 | 1196 | } | 
| 1197 | 1197 |          } catch (Exception $exception) { | 
| 1198 | 1198 | } | 
| @@ -1325,7 +1325,7 @@ discard block | ||
| 1325 | 1325 | // let's examine the constructor | 
| 1326 | 1326 | $constructor = $this->mirror->getConstructorFromReflection($reflector); | 
| 1327 | 1327 | // whu? huh? nothing? | 
| 1328 | -        if (! $constructor) { | |
| 1328 | +        if ( ! $constructor) { | |
| 1329 | 1329 | return $arguments; | 
| 1330 | 1330 | } | 
| 1331 | 1331 | // get constructor parameters | 
| @@ -1355,7 +1355,7 @@ discard block | ||
| 1355 | 1355 | $param_class === null | 
| 1356 | 1356 | // and something already exists in the incoming arguments for this param | 
| 1357 | 1357 | && array_key_exists($index, $argument_keys) | 
| 1358 | - && array_key_exists($argument_keys[ $index ], $arguments) | |
| 1358 | + && array_key_exists($argument_keys[$index], $arguments) | |
| 1359 | 1359 |              ) { | 
| 1360 | 1360 | // so let's skip this argument and move on to the next | 
| 1361 | 1361 | continue; | 
| @@ -1363,8 +1363,8 @@ discard block | ||
| 1363 | 1363 | if ( | 
| 1364 | 1364 | // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class | 
| 1365 | 1365 | $param_class !== null | 
| 1366 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) | |
| 1367 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class | |
| 1366 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) | |
| 1367 | + && $arguments[$argument_keys[$index]] instanceof $param_class | |
| 1368 | 1368 |              ) { | 
| 1369 | 1369 | // skip this argument and move on to the next | 
| 1370 | 1370 | continue; | 
| @@ -1381,17 +1381,17 @@ discard block | ||
| 1381 | 1381 | $index | 
| 1382 | 1382 | ); | 
| 1383 | 1383 | } | 
| 1384 | -            if (empty($arguments[ $index ])) { | |
| 1384 | +            if (empty($arguments[$index])) { | |
| 1385 | 1385 | $default_value = $this->mirror->getParameterDefaultValue( | 
| 1386 | 1386 | $param, | 
| 1387 | 1387 | $class_name, | 
| 1388 | 1388 | $index | 
| 1389 | 1389 | ); | 
| 1390 | 1390 | // if there's no default value, and the incoming argument is an array (albeit empty), then use that | 
| 1391 | - $arguments[ $index ] = $default_value === null | |
| 1392 | - && isset($arguments[ $index ]) | |
| 1393 | - && is_array($arguments[ $index ]) | |
| 1394 | - ? $arguments[ $index ] | |
| 1391 | + $arguments[$index] = $default_value === null | |
| 1392 | + && isset($arguments[$index]) | |
| 1393 | + && is_array($arguments[$index]) | |
| 1394 | + ? $arguments[$index] | |
| 1395 | 1395 | : $default_value; | 
| 1396 | 1396 | } | 
| 1397 | 1397 | } | 
| @@ -1450,7 +1450,7 @@ discard block | ||
| 1450 | 1450 | // did we successfully find the correct dependency ? | 
| 1451 | 1451 |          if ($dependency instanceof $param_class) { | 
| 1452 | 1452 | // then let's inject it into the incoming array of arguments at the correct location | 
| 1453 | - $arguments[ $index ] = $dependency; | |
| 1453 | + $arguments[$index] = $dependency; | |
| 1454 | 1454 | } | 
| 1455 | 1455 | return $arguments; | 
| 1456 | 1456 | } | 
| @@ -1545,7 +1545,7 @@ discard block | ||
| 1545 | 1545 |      { | 
| 1546 | 1546 | $addons = array(); | 
| 1547 | 1547 |          foreach ($this->addons as $addon) { | 
| 1548 | - $addons[ $addon->name() ] = $addon; | |
| 1548 | + $addons[$addon->name()] = $addon; | |
| 1549 | 1549 | } | 
| 1550 | 1550 | return $addons; | 
| 1551 | 1551 | } | 
| @@ -1564,11 +1564,11 @@ discard block | ||
| 1564 | 1564 | $model_class_name = strpos($model_name, 'EEM_') !== 0 | 
| 1565 | 1565 |              ? "EEM_{$model_name}" | 
| 1566 | 1566 | : $model_name; | 
| 1567 | -        if (! $this->LIB->has($model_class_name)) { | |
| 1567 | +        if ( ! $this->LIB->has($model_class_name)) { | |
| 1568 | 1568 | return null; | 
| 1569 | 1569 | } | 
| 1570 | 1570 | $model = $this->LIB->get($model_class_name); | 
| 1571 | -        if (! $model instanceof EEM_Base) { | |
| 1571 | +        if ( ! $model instanceof EEM_Base) { | |
| 1572 | 1572 | return null; | 
| 1573 | 1573 | } | 
| 1574 | 1574 | // get that model reset it and make sure we nuke the old reference to it | 
| @@ -1658,7 +1658,7 @@ discard block | ||
| 1658 | 1658 | */ | 
| 1659 | 1659 | private static function _reset_and_unset_object($object, $reset_models) | 
| 1660 | 1660 |      { | 
| 1661 | -        if (! is_object($object)) { | |
| 1661 | +        if ( ! is_object($object)) { | |
| 1662 | 1662 | // don't unset anything that's not an object | 
| 1663 | 1663 | return false; | 
| 1664 | 1664 | } | 
| @@ -1678,7 +1678,7 @@ discard block | ||
| 1678 | 1678 | $object->reset(); | 
| 1679 | 1679 | return true; | 
| 1680 | 1680 | } | 
| 1681 | -        if (! $object instanceof InterminableInterface) { | |
| 1681 | +        if ( ! $object instanceof InterminableInterface) { | |
| 1682 | 1682 | return true; | 
| 1683 | 1683 | } | 
| 1684 | 1684 | return false; | 
| @@ -1695,7 +1695,7 @@ discard block | ||
| 1695 | 1695 | $cpt_models = array(); | 
| 1696 | 1696 |          foreach ($this->non_abstract_db_models as $short_name => $classname) { | 
| 1697 | 1697 |              if (is_subclass_of($classname, 'EEM_CPT_Base')) { | 
| 1698 | - $cpt_models[ $short_name ] = $classname; | |
| 1698 | + $cpt_models[$short_name] = $classname; | |
| 1699 | 1699 | } | 
| 1700 | 1700 | } | 
| 1701 | 1701 | return $cpt_models; | 
| @@ -16,235 +16,235 @@ | ||
| 16 | 16 | class ProcessTicketSelectorPostData | 
| 17 | 17 |  { | 
| 18 | 18 | |
| 19 | - const DATA_KEY_EVENT_ID = 'id'; | |
| 20 | - | |
| 21 | - const DATA_KEY_MAX_ATNDZ = 'max_atndz'; | |
| 22 | - | |
| 23 | - const DATA_KEY_QUANTITY = 'qty'; | |
| 24 | - | |
| 25 | - const DATA_KEY_RETURN_URL = 'return_url'; | |
| 26 | - | |
| 27 | - const DATA_KEY_ROWS = 'rows'; | |
| 28 | - | |
| 29 | - const DATA_KEY_TICKET_ID = 'ticket_id'; | |
| 30 | - | |
| 31 | - const DATA_KEY_TOTAL_TICKETS = 'total_tickets'; | |
| 32 | - | |
| 33 | - const INPUT_KEY_EVENT_ID = 'tkt-slctr-event-id'; | |
| 34 | - | |
| 35 | - const INPUT_KEY_MAX_ATNDZ = 'tkt-slctr-max-atndz-'; | |
| 36 | - | |
| 37 | - const INPUT_KEY_ROWS = 'tkt-slctr-rows-'; | |
| 38 | - | |
| 39 | - const INPUT_KEY_QTY = 'tkt-slctr-qty-'; | |
| 40 | - | |
| 41 | - const INPUT_KEY_TICKET_ID = 'tkt-slctr-ticket-id-'; | |
| 42 | - | |
| 43 | - const INPUT_KEY_RETURN_URL = 'tkt-slctr-return-url-'; | |
| 44 | - | |
| 45 | - | |
| 46 | - /** | |
| 47 | - * @var int | |
| 48 | - */ | |
| 49 | - protected $event_id; | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @var array | |
| 53 | - */ | |
| 54 | - protected $inputs_to_clean = []; | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * @var array | |
| 58 | - */ | |
| 59 | - protected $valid_data = []; | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @var RequestInterface | |
| 63 | - */ | |
| 64 | - protected $request; | |
| 65 | - | |
| 66 | - | |
| 67 | - /** | |
| 68 | - * @param RequestInterface $request | |
| 69 | - */ | |
| 70 | - public function __construct(RequestInterface $request) | |
| 71 | -    { | |
| 72 | - $this->request = $request; | |
| 73 | - $this->inputs_to_clean = [ | |
| 74 | - self::DATA_KEY_MAX_ATNDZ => self::INPUT_KEY_MAX_ATNDZ, | |
| 75 | - self::DATA_KEY_ROWS => self::INPUT_KEY_ROWS, | |
| 76 | - self::DATA_KEY_QUANTITY => self::INPUT_KEY_QTY, | |
| 77 | - self::DATA_KEY_TOTAL_TICKETS => self::INPUT_KEY_TICKET_ID, | |
| 78 | - self::DATA_KEY_RETURN_URL => self::INPUT_KEY_RETURN_URL, | |
| 79 | - ]; | |
| 80 | - } | |
| 81 | - | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * @return int | |
| 85 | - * @throws DomainException | |
| 86 | - */ | |
| 87 | - public function getEventId() | |
| 88 | -    { | |
| 89 | - // do we have an event id? | |
| 90 | -        if ($this->event_id === null) { | |
| 91 | - $this->event_id = $this->request->getRequestParam(self::INPUT_KEY_EVENT_ID, 0, 'int'); | |
| 92 | -            if (! $this->event_id) { | |
| 93 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? | |
| 94 | - throw new DomainException( | |
| 95 | - sprintf( | |
| 96 | - esc_html__( | |
| 97 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', | |
| 98 | - 'event_espresso' | |
| 99 | - ), | |
| 100 | - '<br/>' | |
| 101 | - ) | |
| 102 | - ); | |
| 103 | - } | |
| 104 | - } | |
| 105 | - // event id is valid | |
| 106 | - return $this->event_id; | |
| 107 | - } | |
| 108 | - | |
| 109 | - | |
| 110 | - /** | |
| 111 | - * @return array | |
| 112 | - * @throws DomainException | |
| 113 | - */ | |
| 114 | - public function validatePostData() | |
| 115 | -    { | |
| 116 | - // grab valid id | |
| 117 | - $this->valid_data[ self::DATA_KEY_EVENT_ID ] = $this->getEventId(); | |
| 118 | - // let's track the total number of tickets ordered.' | |
| 119 | - $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] = 0; | |
| 120 | - // cycle through $inputs_to_clean array | |
| 121 | -        foreach ($this->inputs_to_clean as $what => $input_to_clean) { | |
| 122 | -            $input_key = "{$input_to_clean}{$this->event_id}"; | |
| 123 | - // check for POST data | |
| 124 | -            if ($this->request->requestParamIsSet($input_key)) { | |
| 125 | -                switch ($what) { | |
| 126 | - // integers | |
| 127 | - case self::DATA_KEY_ROWS: | |
| 128 | - case self::DATA_KEY_MAX_ATNDZ: | |
| 129 | - $this->processInteger($what, $input_key); | |
| 130 | - break; | |
| 131 | - // arrays of integers | |
| 132 | - case self::DATA_KEY_QUANTITY: | |
| 133 | - $this->processQuantity($input_key); | |
| 134 | - break; | |
| 135 | - // array of integers | |
| 136 | - case self::DATA_KEY_TOTAL_TICKETS: | |
| 137 | - $this->processTicketIDs($input_key); | |
| 138 | - break; | |
| 139 | - case self::DATA_KEY_RETURN_URL: | |
| 140 | - $this->processReturnURL($input_key); | |
| 141 | - break; | |
| 142 | - } | |
| 143 | - } | |
| 144 | - } | |
| 145 | - return $this->valid_data; | |
| 146 | - } | |
| 147 | - | |
| 148 | - | |
| 149 | - /** | |
| 150 | - * @param string $what | |
| 151 | - * @param string $input_key | |
| 152 | - */ | |
| 153 | - protected function processInteger($what, $input_key) | |
| 154 | -    { | |
| 155 | - $this->valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int'); | |
| 156 | - } | |
| 157 | - | |
| 158 | - | |
| 159 | - /** | |
| 160 | - * @param string $input_key | |
| 161 | - * @throws DomainException | |
| 162 | - */ | |
| 163 | - protected function processQuantity($input_key) | |
| 164 | -    { | |
| 165 | - // first get number of ticket option rows | |
| 166 | - $rows = $this->request->getRequestParam(self::INPUT_KEY_ROWS . $this->event_id, 1, 'int'); | |
| 167 | - $raw_qty = $this->request->getRequestParam($input_key); | |
| 168 | - // explode integers by the dash if qty is a string | |
| 169 | - $delimiter = is_string($raw_qty) && strpos($raw_qty, '-') ? '-' : ''; | |
| 170 | - /** @var array $row_qty */ | |
| 171 | - $row_qty = $this->request->getRequestParam($input_key, [], 'int', true, $delimiter); | |
| 172 | - // if qty is coming from a radio button input, then we need to assemble an array of rows | |
| 173 | -        if ($delimiter === '-') { | |
| 174 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; | |
| 175 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; | |
| 176 | - // restructure the row qty array so that $row is now the key instead of the first value | |
| 177 | - $row_qty = [$row => $qty]; | |
| 178 | -            for ($x = 1; $x <= $rows; $x++) { | |
| 179 | -                if (! isset($row_qty[ $x ])) { | |
| 180 | - $row_qty[ $x ] = 0; | |
| 181 | - } | |
| 182 | - } | |
| 183 | - } | |
| 184 | -        if (empty($row_qty) || ! is_array($row_qty) || $rows !== count($row_qty)) { | |
| 185 | - throw new DomainException( | |
| 186 | - sprintf( | |
| 187 | - esc_html__( | |
| 188 | - 'An error occurred while trying to retrieve the ticket selections for the event.%sPlease click the back button on your browser and try again.', | |
| 189 | - 'event_espresso' | |
| 190 | - ), | |
| 191 | - '<br/>' | |
| 192 | - ) | |
| 193 | - ); | |
| 194 | - } | |
| 195 | - ksort($row_qty); | |
| 196 | - // cycle thru values | |
| 197 | -        foreach ($row_qty as $qty) { | |
| 198 | - $qty = absint($qty); | |
| 199 | - // sanitize as integers | |
| 200 | - $this->valid_data[ self::DATA_KEY_QUANTITY ][] = $qty; | |
| 201 | - $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] += $qty; | |
| 202 | - } | |
| 203 | - } | |
| 204 | - | |
| 205 | - | |
| 206 | - /** | |
| 207 | - * @param string $input_key | |
| 208 | - */ | |
| 209 | - protected function processReturnURL($input_key) | |
| 210 | -    { | |
| 211 | - // grab and sanitize return-url | |
| 212 | - $input_value = $this->request->getRequestParam($input_key, '', 'url'); | |
| 213 | - // was the request coming from an iframe ? if so, then: | |
| 214 | -        if (strpos($input_value, 'event_list=iframe')) { | |
| 215 | - // get anchor fragment | |
| 216 | -            $input_value = explode('#', $input_value); | |
| 217 | - $input_value = end($input_value); | |
| 218 | - // use event list url instead, but append anchor | |
| 219 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; | |
| 220 | - } | |
| 221 | - $this->valid_data[ self::DATA_KEY_RETURN_URL ] = $input_value; | |
| 222 | - } | |
| 223 | - | |
| 224 | - | |
| 225 | - /** | |
| 226 | - * @param string $input_key | |
| 227 | - * @throws DomainException | |
| 228 | - */ | |
| 229 | - protected function processTicketIDs($input_key) | |
| 230 | -    { | |
| 231 | - $ticket_ids = (array) $this->request->getRequestParam($input_key, [], 'int', true); | |
| 232 | - $filtered_ticket_ids = array_filter($ticket_ids); | |
| 233 | -        if (empty($filtered_ticket_ids)) { | |
| 234 | - throw new DomainException( | |
| 235 | - sprintf( | |
| 236 | - esc_html__( | |
| 237 | - 'An error occurred while trying to retrieve the ticket IDs for the event.%sPlease click the back button on your browser and try again.', | |
| 238 | - 'event_espresso' | |
| 239 | - ), | |
| 240 | - '<br/>' | |
| 241 | - ) | |
| 242 | - ); | |
| 243 | - } | |
| 244 | - // cycle thru values | |
| 245 | -        foreach ($ticket_ids as $key => $value) { | |
| 246 | - // allow only integers | |
| 247 | - $this->valid_data[ self::DATA_KEY_TICKET_ID ][ $key ] = absint($value); | |
| 248 | - } | |
| 249 | - } | |
| 19 | + const DATA_KEY_EVENT_ID = 'id'; | |
| 20 | + | |
| 21 | + const DATA_KEY_MAX_ATNDZ = 'max_atndz'; | |
| 22 | + | |
| 23 | + const DATA_KEY_QUANTITY = 'qty'; | |
| 24 | + | |
| 25 | + const DATA_KEY_RETURN_URL = 'return_url'; | |
| 26 | + | |
| 27 | + const DATA_KEY_ROWS = 'rows'; | |
| 28 | + | |
| 29 | + const DATA_KEY_TICKET_ID = 'ticket_id'; | |
| 30 | + | |
| 31 | + const DATA_KEY_TOTAL_TICKETS = 'total_tickets'; | |
| 32 | + | |
| 33 | + const INPUT_KEY_EVENT_ID = 'tkt-slctr-event-id'; | |
| 34 | + | |
| 35 | + const INPUT_KEY_MAX_ATNDZ = 'tkt-slctr-max-atndz-'; | |
| 36 | + | |
| 37 | + const INPUT_KEY_ROWS = 'tkt-slctr-rows-'; | |
| 38 | + | |
| 39 | + const INPUT_KEY_QTY = 'tkt-slctr-qty-'; | |
| 40 | + | |
| 41 | + const INPUT_KEY_TICKET_ID = 'tkt-slctr-ticket-id-'; | |
| 42 | + | |
| 43 | + const INPUT_KEY_RETURN_URL = 'tkt-slctr-return-url-'; | |
| 44 | + | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @var int | |
| 48 | + */ | |
| 49 | + protected $event_id; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var array | |
| 53 | + */ | |
| 54 | + protected $inputs_to_clean = []; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @var array | |
| 58 | + */ | |
| 59 | + protected $valid_data = []; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @var RequestInterface | |
| 63 | + */ | |
| 64 | + protected $request; | |
| 65 | + | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * @param RequestInterface $request | |
| 69 | + */ | |
| 70 | + public function __construct(RequestInterface $request) | |
| 71 | +	{ | |
| 72 | + $this->request = $request; | |
| 73 | + $this->inputs_to_clean = [ | |
| 74 | + self::DATA_KEY_MAX_ATNDZ => self::INPUT_KEY_MAX_ATNDZ, | |
| 75 | + self::DATA_KEY_ROWS => self::INPUT_KEY_ROWS, | |
| 76 | + self::DATA_KEY_QUANTITY => self::INPUT_KEY_QTY, | |
| 77 | + self::DATA_KEY_TOTAL_TICKETS => self::INPUT_KEY_TICKET_ID, | |
| 78 | + self::DATA_KEY_RETURN_URL => self::INPUT_KEY_RETURN_URL, | |
| 79 | + ]; | |
| 80 | + } | |
| 81 | + | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * @return int | |
| 85 | + * @throws DomainException | |
| 86 | + */ | |
| 87 | + public function getEventId() | |
| 88 | +	{ | |
| 89 | + // do we have an event id? | |
| 90 | +		if ($this->event_id === null) { | |
| 91 | + $this->event_id = $this->request->getRequestParam(self::INPUT_KEY_EVENT_ID, 0, 'int'); | |
| 92 | +			if (! $this->event_id) { | |
| 93 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? | |
| 94 | + throw new DomainException( | |
| 95 | + sprintf( | |
| 96 | + esc_html__( | |
| 97 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', | |
| 98 | + 'event_espresso' | |
| 99 | + ), | |
| 100 | + '<br/>' | |
| 101 | + ) | |
| 102 | + ); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + // event id is valid | |
| 106 | + return $this->event_id; | |
| 107 | + } | |
| 108 | + | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * @return array | |
| 112 | + * @throws DomainException | |
| 113 | + */ | |
| 114 | + public function validatePostData() | |
| 115 | +	{ | |
| 116 | + // grab valid id | |
| 117 | + $this->valid_data[ self::DATA_KEY_EVENT_ID ] = $this->getEventId(); | |
| 118 | + // let's track the total number of tickets ordered.' | |
| 119 | + $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] = 0; | |
| 120 | + // cycle through $inputs_to_clean array | |
| 121 | +		foreach ($this->inputs_to_clean as $what => $input_to_clean) { | |
| 122 | +			$input_key = "{$input_to_clean}{$this->event_id}"; | |
| 123 | + // check for POST data | |
| 124 | +			if ($this->request->requestParamIsSet($input_key)) { | |
| 125 | +				switch ($what) { | |
| 126 | + // integers | |
| 127 | + case self::DATA_KEY_ROWS: | |
| 128 | + case self::DATA_KEY_MAX_ATNDZ: | |
| 129 | + $this->processInteger($what, $input_key); | |
| 130 | + break; | |
| 131 | + // arrays of integers | |
| 132 | + case self::DATA_KEY_QUANTITY: | |
| 133 | + $this->processQuantity($input_key); | |
| 134 | + break; | |
| 135 | + // array of integers | |
| 136 | + case self::DATA_KEY_TOTAL_TICKETS: | |
| 137 | + $this->processTicketIDs($input_key); | |
| 138 | + break; | |
| 139 | + case self::DATA_KEY_RETURN_URL: | |
| 140 | + $this->processReturnURL($input_key); | |
| 141 | + break; | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 145 | + return $this->valid_data; | |
| 146 | + } | |
| 147 | + | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * @param string $what | |
| 151 | + * @param string $input_key | |
| 152 | + */ | |
| 153 | + protected function processInteger($what, $input_key) | |
| 154 | +	{ | |
| 155 | + $this->valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int'); | |
| 156 | + } | |
| 157 | + | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * @param string $input_key | |
| 161 | + * @throws DomainException | |
| 162 | + */ | |
| 163 | + protected function processQuantity($input_key) | |
| 164 | +	{ | |
| 165 | + // first get number of ticket option rows | |
| 166 | + $rows = $this->request->getRequestParam(self::INPUT_KEY_ROWS . $this->event_id, 1, 'int'); | |
| 167 | + $raw_qty = $this->request->getRequestParam($input_key); | |
| 168 | + // explode integers by the dash if qty is a string | |
| 169 | + $delimiter = is_string($raw_qty) && strpos($raw_qty, '-') ? '-' : ''; | |
| 170 | + /** @var array $row_qty */ | |
| 171 | + $row_qty = $this->request->getRequestParam($input_key, [], 'int', true, $delimiter); | |
| 172 | + // if qty is coming from a radio button input, then we need to assemble an array of rows | |
| 173 | +		if ($delimiter === '-') { | |
| 174 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; | |
| 175 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; | |
| 176 | + // restructure the row qty array so that $row is now the key instead of the first value | |
| 177 | + $row_qty = [$row => $qty]; | |
| 178 | +			for ($x = 1; $x <= $rows; $x++) { | |
| 179 | +				if (! isset($row_qty[ $x ])) { | |
| 180 | + $row_qty[ $x ] = 0; | |
| 181 | + } | |
| 182 | + } | |
| 183 | + } | |
| 184 | +		if (empty($row_qty) || ! is_array($row_qty) || $rows !== count($row_qty)) { | |
| 185 | + throw new DomainException( | |
| 186 | + sprintf( | |
| 187 | + esc_html__( | |
| 188 | + 'An error occurred while trying to retrieve the ticket selections for the event.%sPlease click the back button on your browser and try again.', | |
| 189 | + 'event_espresso' | |
| 190 | + ), | |
| 191 | + '<br/>' | |
| 192 | + ) | |
| 193 | + ); | |
| 194 | + } | |
| 195 | + ksort($row_qty); | |
| 196 | + // cycle thru values | |
| 197 | +		foreach ($row_qty as $qty) { | |
| 198 | + $qty = absint($qty); | |
| 199 | + // sanitize as integers | |
| 200 | + $this->valid_data[ self::DATA_KEY_QUANTITY ][] = $qty; | |
| 201 | + $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] += $qty; | |
| 202 | + } | |
| 203 | + } | |
| 204 | + | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * @param string $input_key | |
| 208 | + */ | |
| 209 | + protected function processReturnURL($input_key) | |
| 210 | +	{ | |
| 211 | + // grab and sanitize return-url | |
| 212 | + $input_value = $this->request->getRequestParam($input_key, '', 'url'); | |
| 213 | + // was the request coming from an iframe ? if so, then: | |
| 214 | +		if (strpos($input_value, 'event_list=iframe')) { | |
| 215 | + // get anchor fragment | |
| 216 | +			$input_value = explode('#', $input_value); | |
| 217 | + $input_value = end($input_value); | |
| 218 | + // use event list url instead, but append anchor | |
| 219 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; | |
| 220 | + } | |
| 221 | + $this->valid_data[ self::DATA_KEY_RETURN_URL ] = $input_value; | |
| 222 | + } | |
| 223 | + | |
| 224 | + | |
| 225 | + /** | |
| 226 | + * @param string $input_key | |
| 227 | + * @throws DomainException | |
| 228 | + */ | |
| 229 | + protected function processTicketIDs($input_key) | |
| 230 | +	{ | |
| 231 | + $ticket_ids = (array) $this->request->getRequestParam($input_key, [], 'int', true); | |
| 232 | + $filtered_ticket_ids = array_filter($ticket_ids); | |
| 233 | +		if (empty($filtered_ticket_ids)) { | |
| 234 | + throw new DomainException( | |
| 235 | + sprintf( | |
| 236 | + esc_html__( | |
| 237 | + 'An error occurred while trying to retrieve the ticket IDs for the event.%sPlease click the back button on your browser and try again.', | |
| 238 | + 'event_espresso' | |
| 239 | + ), | |
| 240 | + '<br/>' | |
| 241 | + ) | |
| 242 | + ); | |
| 243 | + } | |
| 244 | + // cycle thru values | |
| 245 | +		foreach ($ticket_ids as $key => $value) { | |
| 246 | + // allow only integers | |
| 247 | + $this->valid_data[ self::DATA_KEY_TICKET_ID ][ $key ] = absint($value); | |
| 248 | + } | |
| 249 | + } | |
| 250 | 250 | } | 
| @@ -89,7 +89,7 @@ discard block | ||
| 89 | 89 | // do we have an event id? | 
| 90 | 90 |          if ($this->event_id === null) { | 
| 91 | 91 | $this->event_id = $this->request->getRequestParam(self::INPUT_KEY_EVENT_ID, 0, 'int'); | 
| 92 | -            if (! $this->event_id) { | |
| 92 | +            if ( ! $this->event_id) { | |
| 93 | 93 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? | 
| 94 | 94 | throw new DomainException( | 
| 95 | 95 | sprintf( | 
| @@ -114,9 +114,9 @@ discard block | ||
| 114 | 114 | public function validatePostData() | 
| 115 | 115 |      { | 
| 116 | 116 | // grab valid id | 
| 117 | - $this->valid_data[ self::DATA_KEY_EVENT_ID ] = $this->getEventId(); | |
| 117 | + $this->valid_data[self::DATA_KEY_EVENT_ID] = $this->getEventId(); | |
| 118 | 118 | // let's track the total number of tickets ordered.' | 
| 119 | - $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] = 0; | |
| 119 | + $this->valid_data[self:: DATA_KEY_TOTAL_TICKETS] = 0; | |
| 120 | 120 | // cycle through $inputs_to_clean array | 
| 121 | 121 |          foreach ($this->inputs_to_clean as $what => $input_to_clean) { | 
| 122 | 122 |              $input_key = "{$input_to_clean}{$this->event_id}"; | 
| @@ -152,7 +152,7 @@ discard block | ||
| 152 | 152 | */ | 
| 153 | 153 | protected function processInteger($what, $input_key) | 
| 154 | 154 |      { | 
| 155 | - $this->valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int'); | |
| 155 | + $this->valid_data[$what] = $this->request->getRequestParam($input_key, 0, 'int'); | |
| 156 | 156 | } | 
| 157 | 157 | |
| 158 | 158 | |
| @@ -163,7 +163,7 @@ discard block | ||
| 163 | 163 | protected function processQuantity($input_key) | 
| 164 | 164 |      { | 
| 165 | 165 | // first get number of ticket option rows | 
| 166 | - $rows = $this->request->getRequestParam(self::INPUT_KEY_ROWS . $this->event_id, 1, 'int'); | |
| 166 | + $rows = $this->request->getRequestParam(self::INPUT_KEY_ROWS.$this->event_id, 1, 'int'); | |
| 167 | 167 | $raw_qty = $this->request->getRequestParam($input_key); | 
| 168 | 168 | // explode integers by the dash if qty is a string | 
| 169 | 169 | $delimiter = is_string($raw_qty) && strpos($raw_qty, '-') ? '-' : ''; | 
| @@ -176,8 +176,8 @@ discard block | ||
| 176 | 176 | // restructure the row qty array so that $row is now the key instead of the first value | 
| 177 | 177 | $row_qty = [$row => $qty]; | 
| 178 | 178 |              for ($x = 1; $x <= $rows; $x++) { | 
| 179 | -                if (! isset($row_qty[ $x ])) { | |
| 180 | - $row_qty[ $x ] = 0; | |
| 179 | +                if ( ! isset($row_qty[$x])) { | |
| 180 | + $row_qty[$x] = 0; | |
| 181 | 181 | } | 
| 182 | 182 | } | 
| 183 | 183 | } | 
| @@ -197,8 +197,8 @@ discard block | ||
| 197 | 197 |          foreach ($row_qty as $qty) { | 
| 198 | 198 | $qty = absint($qty); | 
| 199 | 199 | // sanitize as integers | 
| 200 | - $this->valid_data[ self::DATA_KEY_QUANTITY ][] = $qty; | |
| 201 | - $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] += $qty; | |
| 200 | + $this->valid_data[self::DATA_KEY_QUANTITY][] = $qty; | |
| 201 | + $this->valid_data[self:: DATA_KEY_TOTAL_TICKETS] += $qty; | |
| 202 | 202 | } | 
| 203 | 203 | } | 
| 204 | 204 | |
| @@ -216,9 +216,9 @@ discard block | ||
| 216 | 216 |              $input_value = explode('#', $input_value); | 
| 217 | 217 | $input_value = end($input_value); | 
| 218 | 218 | // use event list url instead, but append anchor | 
| 219 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; | |
| 219 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; | |
| 220 | 220 | } | 
| 221 | - $this->valid_data[ self::DATA_KEY_RETURN_URL ] = $input_value; | |
| 221 | + $this->valid_data[self::DATA_KEY_RETURN_URL] = $input_value; | |
| 222 | 222 | } | 
| 223 | 223 | |
| 224 | 224 | |
| @@ -244,7 +244,7 @@ discard block | ||
| 244 | 244 | // cycle thru values | 
| 245 | 245 |          foreach ($ticket_ids as $key => $value) { | 
| 246 | 246 | // allow only integers | 
| 247 | - $this->valid_data[ self::DATA_KEY_TICKET_ID ][ $key ] = absint($value); | |
| 247 | + $this->valid_data[self::DATA_KEY_TICKET_ID][$key] = absint($value); | |
| 248 | 248 | } | 
| 249 | 249 | } | 
| 250 | 250 | } | 
| @@ -34,402 +34,402 @@ | ||
| 34 | 34 | class ProcessTicketSelector | 
| 35 | 35 |  { | 
| 36 | 36 | |
| 37 | - /** | |
| 38 | - * @var EE_Cart $cart | |
| 39 | - */ | |
| 40 | - private $cart; | |
| 37 | + /** | |
| 38 | + * @var EE_Cart $cart | |
| 39 | + */ | |
| 40 | + private $cart; | |
| 41 | 41 | |
| 42 | - /** | |
| 43 | - * @var EE_Core_Config $core_config | |
| 44 | - */ | |
| 45 | - private $core_config; | |
| 42 | + /** | |
| 43 | + * @var EE_Core_Config $core_config | |
| 44 | + */ | |
| 45 | + private $core_config; | |
| 46 | 46 | |
| 47 | - /** | |
| 48 | - * @var RequestInterface $request | |
| 49 | - */ | |
| 50 | - private $request; | |
| 47 | + /** | |
| 48 | + * @var RequestInterface $request | |
| 49 | + */ | |
| 50 | + private $request; | |
| 51 | 51 | |
| 52 | - /** | |
| 53 | - * @var EE_Session $session | |
| 54 | - */ | |
| 55 | - private $session; | |
| 52 | + /** | |
| 53 | + * @var EE_Session $session | |
| 54 | + */ | |
| 55 | + private $session; | |
| 56 | 56 | |
| 57 | - /** | |
| 58 | - * @var EEM_Ticket $ticket_model | |
| 59 | - */ | |
| 60 | - private $ticket_model; | |
| 57 | + /** | |
| 58 | + * @var EEM_Ticket $ticket_model | |
| 59 | + */ | |
| 60 | + private $ticket_model; | |
| 61 | 61 | |
| 62 | - /** | |
| 63 | - * @var TicketDatetimeAvailabilityTracker $tracker | |
| 64 | - */ | |
| 65 | - private $tracker; | |
| 62 | + /** | |
| 63 | + * @var TicketDatetimeAvailabilityTracker $tracker | |
| 64 | + */ | |
| 65 | + private $tracker; | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - /** | |
| 69 | - * ProcessTicketSelector constructor. | |
| 70 | - * NOTE: PLZ use the Loader to instantiate this class if need be | |
| 71 | - * so that all dependencies get injected correctly (which will happen automatically) | |
| 72 | - * Null values for parameters are only for backwards compatibility but will be removed later on. | |
| 73 | - * | |
| 74 | - * @param EE_Core_Config $core_config | |
| 75 | - * @param RequestInterface $request | |
| 76 | - * @param EE_Session $session | |
| 77 | - * @param EEM_Ticket $ticket_model | |
| 78 | - * @param TicketDatetimeAvailabilityTracker $tracker | |
| 79 | - * @throws InvalidArgumentException | |
| 80 | - * @throws InvalidDataTypeException | |
| 81 | - * @throws InvalidInterfaceException | |
| 82 | - */ | |
| 83 | - public function __construct( | |
| 84 | - EE_Core_Config $core_config = null, | |
| 85 | - RequestInterface $request = null, | |
| 86 | - EE_Session $session = null, | |
| 87 | - EEM_Ticket $ticket_model = null, | |
| 88 | - TicketDatetimeAvailabilityTracker $tracker = null | |
| 89 | -    ) { | |
| 90 | - $loader = LoaderFactory::getLoader(); | |
| 91 | - $this->core_config = $core_config instanceof EE_Core_Config | |
| 92 | - ? $core_config | |
| 93 | -            : $loader->getShared('EE_Core_Config'); | |
| 94 | - $this->request = $request instanceof RequestInterface | |
| 95 | - ? $request | |
| 96 | -            : $loader->getShared('EventEspresso\core\services\request\Request'); | |
| 97 | - $this->session = $session instanceof EE_Session | |
| 98 | - ? $session | |
| 99 | -            : $loader->getShared('EE_Session'); | |
| 100 | - $this->ticket_model = $ticket_model instanceof EEM_Ticket | |
| 101 | - ? $ticket_model | |
| 102 | -            : $loader->getShared('EEM_Ticket'); | |
| 103 | - $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker | |
| 104 | - ? $tracker | |
| 105 | -            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); | |
| 106 | - } | |
| 68 | + /** | |
| 69 | + * ProcessTicketSelector constructor. | |
| 70 | + * NOTE: PLZ use the Loader to instantiate this class if need be | |
| 71 | + * so that all dependencies get injected correctly (which will happen automatically) | |
| 72 | + * Null values for parameters are only for backwards compatibility but will be removed later on. | |
| 73 | + * | |
| 74 | + * @param EE_Core_Config $core_config | |
| 75 | + * @param RequestInterface $request | |
| 76 | + * @param EE_Session $session | |
| 77 | + * @param EEM_Ticket $ticket_model | |
| 78 | + * @param TicketDatetimeAvailabilityTracker $tracker | |
| 79 | + * @throws InvalidArgumentException | |
| 80 | + * @throws InvalidDataTypeException | |
| 81 | + * @throws InvalidInterfaceException | |
| 82 | + */ | |
| 83 | + public function __construct( | |
| 84 | + EE_Core_Config $core_config = null, | |
| 85 | + RequestInterface $request = null, | |
| 86 | + EE_Session $session = null, | |
| 87 | + EEM_Ticket $ticket_model = null, | |
| 88 | + TicketDatetimeAvailabilityTracker $tracker = null | |
| 89 | +	) { | |
| 90 | + $loader = LoaderFactory::getLoader(); | |
| 91 | + $this->core_config = $core_config instanceof EE_Core_Config | |
| 92 | + ? $core_config | |
| 93 | +			: $loader->getShared('EE_Core_Config'); | |
| 94 | + $this->request = $request instanceof RequestInterface | |
| 95 | + ? $request | |
| 96 | +			: $loader->getShared('EventEspresso\core\services\request\Request'); | |
| 97 | + $this->session = $session instanceof EE_Session | |
| 98 | + ? $session | |
| 99 | +			: $loader->getShared('EE_Session'); | |
| 100 | + $this->ticket_model = $ticket_model instanceof EEM_Ticket | |
| 101 | + ? $ticket_model | |
| 102 | +			: $loader->getShared('EEM_Ticket'); | |
| 103 | + $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker | |
| 104 | + ? $tracker | |
| 105 | +			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); | |
| 106 | + } | |
| 107 | 107 | |
| 108 | 108 | |
| 109 | - /** | |
| 110 | - * cancelTicketSelections | |
| 111 | - * | |
| 112 | - * @return bool | |
| 113 | - * @throws EE_Error | |
| 114 | - * @throws InvalidArgumentException | |
| 115 | - * @throws InvalidInterfaceException | |
| 116 | - * @throws InvalidDataTypeException | |
| 117 | - * @throws ReflectionException | |
| 118 | - */ | |
| 119 | - public function cancelTicketSelections() | |
| 120 | -    { | |
| 121 | - // check nonce | |
| 122 | -        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { | |
| 123 | - return false; | |
| 124 | - } | |
| 125 | - $this->session->clear_session(__CLASS__, __FUNCTION__); | |
| 126 | -        if ($this->request->requestParamIsSet('event_id')) { | |
| 127 | - EEH_URL::safeRedirectAndExit( | |
| 128 | - EEH_Event_View::event_link_url( | |
| 129 | -                    $this->request->getRequestParam('event_id', 0, 'int') | |
| 130 | - ) | |
| 131 | - ); | |
| 132 | - } | |
| 133 | - EEH_URL::safeRedirectAndExit( | |
| 134 | -            site_url('/' . $this->core_config->event_cpt_slug . '/') | |
| 135 | - ); | |
| 136 | - return true; | |
| 137 | - } | |
| 109 | + /** | |
| 110 | + * cancelTicketSelections | |
| 111 | + * | |
| 112 | + * @return bool | |
| 113 | + * @throws EE_Error | |
| 114 | + * @throws InvalidArgumentException | |
| 115 | + * @throws InvalidInterfaceException | |
| 116 | + * @throws InvalidDataTypeException | |
| 117 | + * @throws ReflectionException | |
| 118 | + */ | |
| 119 | + public function cancelTicketSelections() | |
| 120 | +	{ | |
| 121 | + // check nonce | |
| 122 | +		if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { | |
| 123 | + return false; | |
| 124 | + } | |
| 125 | + $this->session->clear_session(__CLASS__, __FUNCTION__); | |
| 126 | +		if ($this->request->requestParamIsSet('event_id')) { | |
| 127 | + EEH_URL::safeRedirectAndExit( | |
| 128 | + EEH_Event_View::event_link_url( | |
| 129 | +					$this->request->getRequestParam('event_id', 0, 'int') | |
| 130 | + ) | |
| 131 | + ); | |
| 132 | + } | |
| 133 | + EEH_URL::safeRedirectAndExit( | |
| 134 | +			site_url('/' . $this->core_config->event_cpt_slug . '/') | |
| 135 | + ); | |
| 136 | + return true; | |
| 137 | + } | |
| 138 | 138 | |
| 139 | 139 | |
| 140 | - /** | |
| 141 | - * processTicketSelectorNonce | |
| 142 | - * | |
| 143 | - * @param string $nonce_name | |
| 144 | - * @param string $id | |
| 145 | - * @return bool | |
| 146 | - */ | |
| 147 | - private function processTicketSelectorNonce($nonce_name, $id = '') | |
| 148 | -    { | |
| 149 | -        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; | |
| 150 | - if ( | |
| 151 | - ! $this->request->isAdmin() | |
| 152 | - && ( | |
| 153 | - ! $this->request->requestParamIsSet($nonce_name_with_id) | |
| 154 | - || ! wp_verify_nonce( | |
| 155 | - $this->request->getRequestParam($nonce_name_with_id), | |
| 156 | - $nonce_name | |
| 157 | - ) | |
| 158 | - ) | |
| 159 | -        ) { | |
| 160 | - EE_Error::add_error( | |
| 161 | - sprintf( | |
| 162 | - esc_html__( | |
| 163 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', | |
| 164 | - 'event_espresso' | |
| 165 | - ), | |
| 166 | - '<br/>' | |
| 167 | - ), | |
| 168 | - __FILE__, | |
| 169 | - __FUNCTION__, | |
| 170 | - __LINE__ | |
| 171 | - ); | |
| 172 | - return false; | |
| 173 | - } | |
| 174 | - return true; | |
| 175 | - } | |
| 140 | + /** | |
| 141 | + * processTicketSelectorNonce | |
| 142 | + * | |
| 143 | + * @param string $nonce_name | |
| 144 | + * @param string $id | |
| 145 | + * @return bool | |
| 146 | + */ | |
| 147 | + private function processTicketSelectorNonce($nonce_name, $id = '') | |
| 148 | +	{ | |
| 149 | +		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; | |
| 150 | + if ( | |
| 151 | + ! $this->request->isAdmin() | |
| 152 | + && ( | |
| 153 | + ! $this->request->requestParamIsSet($nonce_name_with_id) | |
| 154 | + || ! wp_verify_nonce( | |
| 155 | + $this->request->getRequestParam($nonce_name_with_id), | |
| 156 | + $nonce_name | |
| 157 | + ) | |
| 158 | + ) | |
| 159 | +		) { | |
| 160 | + EE_Error::add_error( | |
| 161 | + sprintf( | |
| 162 | + esc_html__( | |
| 163 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', | |
| 164 | + 'event_espresso' | |
| 165 | + ), | |
| 166 | + '<br/>' | |
| 167 | + ), | |
| 168 | + __FILE__, | |
| 169 | + __FUNCTION__, | |
| 170 | + __LINE__ | |
| 171 | + ); | |
| 172 | + return false; | |
| 173 | + } | |
| 174 | + return true; | |
| 175 | + } | |
| 176 | 176 | |
| 177 | 177 | |
| 178 | - /** | |
| 179 | - * process_ticket_selections | |
| 180 | - * | |
| 181 | - * @return bool | |
| 182 | - * @throws EE_Error | |
| 183 | - * @throws InvalidArgumentException | |
| 184 | - * @throws InvalidDataTypeException | |
| 185 | - * @throws InvalidInterfaceException | |
| 186 | - * @throws ReflectionException | |
| 187 | - */ | |
| 188 | - public function processTicketSelections() | |
| 189 | -    { | |
| 190 | -        do_action('EED_Ticket_Selector__process_ticket_selections__before'); | |
| 191 | -        if ($this->request->isBot()) { | |
| 192 | - EEH_URL::safeRedirectAndExit( | |
| 193 | - apply_filters( | |
| 194 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', | |
| 195 | - site_url() | |
| 196 | - ) | |
| 197 | - ); | |
| 198 | - } | |
| 199 | - // we should really only have 1 registration in the works now | |
| 200 | - // (ie, no MER) so unless otherwise requested, clear the session | |
| 201 | -        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { | |
| 202 | - $this->session->clear_session(__CLASS__, __FUNCTION__); | |
| 203 | - } | |
| 204 | - // validate/sanitize/filter data | |
| 205 | - $id = null; | |
| 206 | - $valid = []; | |
| 207 | -        try { | |
| 208 | - $post_data_validator = new ProcessTicketSelectorPostData($this->request); | |
| 209 | - $id = $post_data_validator->getEventId(); | |
| 210 | - $valid = apply_filters( | |
| 211 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', | |
| 212 | - $post_data_validator->validatePostData() | |
| 213 | - ); | |
| 214 | -        } catch (Exception $exception) { | |
| 215 | - EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 216 | - } | |
| 217 | - // check total tickets ordered vs max number of attendees that can register | |
| 218 | -        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { | |
| 219 | - $this->maxAttendeesViolation($valid); | |
| 220 | -        } else { | |
| 221 | - // all data appears to be valid | |
| 222 | -            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { | |
| 223 | - return true; | |
| 224 | - } | |
| 225 | - } | |
| 226 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT | |
| 227 | - // at this point, just return if registration is being made from admin | |
| 228 | -        if ($this->request->isAdmin() || $this->request->isFrontAjax()) { | |
| 229 | - return false; | |
| 230 | - } | |
| 231 | -        if (! empty($valid['return_url'])) { | |
| 232 | - EEH_URL::safeRedirectAndExit($valid['return_url']); | |
| 233 | - } | |
| 234 | - // do we have an event id? | |
| 235 | -        if ($id) { | |
| 236 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); | |
| 237 | - } | |
| 238 | - echo EE_Error::get_notices(); // already escaped | |
| 239 | - return false; | |
| 240 | - } | |
| 178 | + /** | |
| 179 | + * process_ticket_selections | |
| 180 | + * | |
| 181 | + * @return bool | |
| 182 | + * @throws EE_Error | |
| 183 | + * @throws InvalidArgumentException | |
| 184 | + * @throws InvalidDataTypeException | |
| 185 | + * @throws InvalidInterfaceException | |
| 186 | + * @throws ReflectionException | |
| 187 | + */ | |
| 188 | + public function processTicketSelections() | |
| 189 | +	{ | |
| 190 | +		do_action('EED_Ticket_Selector__process_ticket_selections__before'); | |
| 191 | +		if ($this->request->isBot()) { | |
| 192 | + EEH_URL::safeRedirectAndExit( | |
| 193 | + apply_filters( | |
| 194 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', | |
| 195 | + site_url() | |
| 196 | + ) | |
| 197 | + ); | |
| 198 | + } | |
| 199 | + // we should really only have 1 registration in the works now | |
| 200 | + // (ie, no MER) so unless otherwise requested, clear the session | |
| 201 | +		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { | |
| 202 | + $this->session->clear_session(__CLASS__, __FUNCTION__); | |
| 203 | + } | |
| 204 | + // validate/sanitize/filter data | |
| 205 | + $id = null; | |
| 206 | + $valid = []; | |
| 207 | +		try { | |
| 208 | + $post_data_validator = new ProcessTicketSelectorPostData($this->request); | |
| 209 | + $id = $post_data_validator->getEventId(); | |
| 210 | + $valid = apply_filters( | |
| 211 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', | |
| 212 | + $post_data_validator->validatePostData() | |
| 213 | + ); | |
| 214 | +		} catch (Exception $exception) { | |
| 215 | + EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 216 | + } | |
| 217 | + // check total tickets ordered vs max number of attendees that can register | |
| 218 | +		if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { | |
| 219 | + $this->maxAttendeesViolation($valid); | |
| 220 | +		} else { | |
| 221 | + // all data appears to be valid | |
| 222 | +			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { | |
| 223 | + return true; | |
| 224 | + } | |
| 225 | + } | |
| 226 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT | |
| 227 | + // at this point, just return if registration is being made from admin | |
| 228 | +		if ($this->request->isAdmin() || $this->request->isFrontAjax()) { | |
| 229 | + return false; | |
| 230 | + } | |
| 231 | +		if (! empty($valid['return_url'])) { | |
| 232 | + EEH_URL::safeRedirectAndExit($valid['return_url']); | |
| 233 | + } | |
| 234 | + // do we have an event id? | |
| 235 | +		if ($id) { | |
| 236 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); | |
| 237 | + } | |
| 238 | + echo EE_Error::get_notices(); // already escaped | |
| 239 | + return false; | |
| 240 | + } | |
| 241 | 241 | |
| 242 | 242 | |
| 243 | - /** | |
| 244 | - * @param array $valid | |
| 245 | - */ | |
| 246 | - private function maxAttendeesViolation(array $valid) | |
| 247 | -    { | |
| 248 | - // ordering too many tickets !!! | |
| 249 | - $total_tickets_string = esc_html( | |
| 250 | - _n( | |
| 251 | - 'You have attempted to purchase %s ticket.', | |
| 252 | - 'You have attempted to purchase %s tickets.', | |
| 253 | - $valid['total_tickets'], | |
| 254 | - 'event_espresso' | |
| 255 | - ) | |
| 256 | - ); | |
| 257 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); | |
| 258 | - // dev only message | |
| 259 | - $max_attendees_string = esc_html( | |
| 260 | - _n( | |
| 261 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', | |
| 262 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', | |
| 263 | - $valid['max_atndz'], | |
| 264 | - 'event_espresso' | |
| 265 | - ) | |
| 266 | - ); | |
| 267 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); | |
| 268 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); | |
| 269 | - } | |
| 243 | + /** | |
| 244 | + * @param array $valid | |
| 245 | + */ | |
| 246 | + private function maxAttendeesViolation(array $valid) | |
| 247 | +	{ | |
| 248 | + // ordering too many tickets !!! | |
| 249 | + $total_tickets_string = esc_html( | |
| 250 | + _n( | |
| 251 | + 'You have attempted to purchase %s ticket.', | |
| 252 | + 'You have attempted to purchase %s tickets.', | |
| 253 | + $valid['total_tickets'], | |
| 254 | + 'event_espresso' | |
| 255 | + ) | |
| 256 | + ); | |
| 257 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); | |
| 258 | + // dev only message | |
| 259 | + $max_attendees_string = esc_html( | |
| 260 | + _n( | |
| 261 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', | |
| 262 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', | |
| 263 | + $valid['max_atndz'], | |
| 264 | + 'event_espresso' | |
| 265 | + ) | |
| 266 | + ); | |
| 267 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); | |
| 268 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); | |
| 269 | + } | |
| 270 | 270 | |
| 271 | 271 | |
| 272 | - /** | |
| 273 | - * @param array $valid | |
| 274 | - * @return int | |
| 275 | - * @throws EE_Error | |
| 276 | - * @throws InvalidArgumentException | |
| 277 | - * @throws InvalidDataTypeException | |
| 278 | - * @throws InvalidInterfaceException | |
| 279 | - */ | |
| 280 | - private function addTicketsToCart(array $valid) | |
| 281 | -    { | |
| 282 | - $tickets_added = 0; | |
| 283 | - $tickets_selected = false; | |
| 284 | -        if (! empty($valid) && $valid['total_tickets'] > 0) { | |
| 285 | - // load cart using factory because we don't want to do so until actually needed | |
| 286 | - $this->cart = CartFactory::getCart(); | |
| 287 | - // if the user is an admin that can edit registrations, | |
| 288 | - // then we'll also allow them to add any tickets, even if they are expired | |
| 289 | -            $current_user_is_admin = current_user_can('ee_edit_registrations'); | |
| 290 | - // cycle thru the number of data rows sent from the event listing | |
| 291 | -            for ($x = 0; $x < $valid['rows']; $x++) { | |
| 292 | - // does this row actually contain a ticket quantity? | |
| 293 | -                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { | |
| 294 | - // YES we have a ticket quantity | |
| 295 | - $tickets_selected = true; | |
| 296 | - $valid_ticket = false; | |
| 297 | -                    if (isset($valid['ticket_id'][ $x ])) { | |
| 298 | - // get ticket via the ticket id we put in the form | |
| 299 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); | |
| 300 | -                        if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { | |
| 301 | - $valid_ticket = true; | |
| 302 | - $tickets_added += $this->addTicketToCart( | |
| 303 | - $ticket, | |
| 304 | - $valid['qty'][ $x ] | |
| 305 | - ); | |
| 306 | - } | |
| 307 | - } | |
| 308 | -                    if ($valid_ticket !== true) { | |
| 309 | - // nothing added to cart retrieved | |
| 310 | - EE_Error::add_error( | |
| 311 | - sprintf( | |
| 312 | - esc_html__( | |
| 313 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', | |
| 314 | - 'event_espresso' | |
| 315 | - ), | |
| 316 | - '<br/>' | |
| 317 | - ), | |
| 318 | - __FILE__, | |
| 319 | - __FUNCTION__, | |
| 320 | - __LINE__ | |
| 321 | - ); | |
| 322 | - } | |
| 323 | -                    if (EE_Error::has_error()) { | |
| 324 | - break; | |
| 325 | - } | |
| 326 | - } | |
| 327 | - } | |
| 328 | - } | |
| 329 | - do_action( | |
| 330 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', | |
| 331 | - $this->cart, | |
| 332 | - $this | |
| 333 | - ); | |
| 334 | -        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { | |
| 335 | - // no ticket quantities were selected | |
| 336 | - EE_Error::add_error( | |
| 337 | -                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), | |
| 338 | - __FILE__, | |
| 339 | - __FUNCTION__, | |
| 340 | - __LINE__ | |
| 341 | - ); | |
| 342 | - } | |
| 343 | - return $tickets_added; | |
| 344 | - } | |
| 272 | + /** | |
| 273 | + * @param array $valid | |
| 274 | + * @return int | |
| 275 | + * @throws EE_Error | |
| 276 | + * @throws InvalidArgumentException | |
| 277 | + * @throws InvalidDataTypeException | |
| 278 | + * @throws InvalidInterfaceException | |
| 279 | + */ | |
| 280 | + private function addTicketsToCart(array $valid) | |
| 281 | +	{ | |
| 282 | + $tickets_added = 0; | |
| 283 | + $tickets_selected = false; | |
| 284 | +		if (! empty($valid) && $valid['total_tickets'] > 0) { | |
| 285 | + // load cart using factory because we don't want to do so until actually needed | |
| 286 | + $this->cart = CartFactory::getCart(); | |
| 287 | + // if the user is an admin that can edit registrations, | |
| 288 | + // then we'll also allow them to add any tickets, even if they are expired | |
| 289 | +			$current_user_is_admin = current_user_can('ee_edit_registrations'); | |
| 290 | + // cycle thru the number of data rows sent from the event listing | |
| 291 | +			for ($x = 0; $x < $valid['rows']; $x++) { | |
| 292 | + // does this row actually contain a ticket quantity? | |
| 293 | +				if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { | |
| 294 | + // YES we have a ticket quantity | |
| 295 | + $tickets_selected = true; | |
| 296 | + $valid_ticket = false; | |
| 297 | +					if (isset($valid['ticket_id'][ $x ])) { | |
| 298 | + // get ticket via the ticket id we put in the form | |
| 299 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); | |
| 300 | +						if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { | |
| 301 | + $valid_ticket = true; | |
| 302 | + $tickets_added += $this->addTicketToCart( | |
| 303 | + $ticket, | |
| 304 | + $valid['qty'][ $x ] | |
| 305 | + ); | |
| 306 | + } | |
| 307 | + } | |
| 308 | +					if ($valid_ticket !== true) { | |
| 309 | + // nothing added to cart retrieved | |
| 310 | + EE_Error::add_error( | |
| 311 | + sprintf( | |
| 312 | + esc_html__( | |
| 313 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', | |
| 314 | + 'event_espresso' | |
| 315 | + ), | |
| 316 | + '<br/>' | |
| 317 | + ), | |
| 318 | + __FILE__, | |
| 319 | + __FUNCTION__, | |
| 320 | + __LINE__ | |
| 321 | + ); | |
| 322 | + } | |
| 323 | +					if (EE_Error::has_error()) { | |
| 324 | + break; | |
| 325 | + } | |
| 326 | + } | |
| 327 | + } | |
| 328 | + } | |
| 329 | + do_action( | |
| 330 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', | |
| 331 | + $this->cart, | |
| 332 | + $this | |
| 333 | + ); | |
| 334 | +		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { | |
| 335 | + // no ticket quantities were selected | |
| 336 | + EE_Error::add_error( | |
| 337 | +				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), | |
| 338 | + __FILE__, | |
| 339 | + __FUNCTION__, | |
| 340 | + __LINE__ | |
| 341 | + ); | |
| 342 | + } | |
| 343 | + return $tickets_added; | |
| 344 | + } | |
| 345 | 345 | |
| 346 | 346 | |
| 347 | - /** | |
| 348 | - * adds a ticket to the cart | |
| 349 | - * | |
| 350 | - * @param EE_Ticket $ticket | |
| 351 | - * @param int $qty | |
| 352 | - * @return bool TRUE on success, FALSE on fail | |
| 353 | - * @throws InvalidArgumentException | |
| 354 | - * @throws InvalidInterfaceException | |
| 355 | - * @throws InvalidDataTypeException | |
| 356 | - * @throws EE_Error | |
| 357 | - */ | |
| 358 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) | |
| 359 | -    { | |
| 360 | - // get the number of spaces left for this datetime ticket | |
| 361 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); | |
| 362 | - // compare available spaces against the number of tickets being purchased | |
| 363 | -        if ($available_spaces >= $qty) { | |
| 364 | - // allow addons to prevent a ticket from being added to cart | |
| 365 | - if ( | |
| 366 | - ! apply_filters( | |
| 367 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', | |
| 368 | - true, | |
| 369 | - $ticket, | |
| 370 | - $qty, | |
| 371 | - $available_spaces | |
| 372 | - ) | |
| 373 | -            ) { | |
| 374 | - return false; | |
| 375 | - } | |
| 376 | -            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); | |
| 377 | - // add event to cart | |
| 378 | -            if ($this->cart->add_ticket_to_cart($ticket, $qty)) { | |
| 379 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); | |
| 380 | - return true; | |
| 381 | - } | |
| 382 | - return false; | |
| 383 | - } | |
| 384 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); | |
| 385 | - return false; | |
| 386 | - } | |
| 347 | + /** | |
| 348 | + * adds a ticket to the cart | |
| 349 | + * | |
| 350 | + * @param EE_Ticket $ticket | |
| 351 | + * @param int $qty | |
| 352 | + * @return bool TRUE on success, FALSE on fail | |
| 353 | + * @throws InvalidArgumentException | |
| 354 | + * @throws InvalidInterfaceException | |
| 355 | + * @throws InvalidDataTypeException | |
| 356 | + * @throws EE_Error | |
| 357 | + */ | |
| 358 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) | |
| 359 | +	{ | |
| 360 | + // get the number of spaces left for this datetime ticket | |
| 361 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); | |
| 362 | + // compare available spaces against the number of tickets being purchased | |
| 363 | +		if ($available_spaces >= $qty) { | |
| 364 | + // allow addons to prevent a ticket from being added to cart | |
| 365 | + if ( | |
| 366 | + ! apply_filters( | |
| 367 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', | |
| 368 | + true, | |
| 369 | + $ticket, | |
| 370 | + $qty, | |
| 371 | + $available_spaces | |
| 372 | + ) | |
| 373 | +			) { | |
| 374 | + return false; | |
| 375 | + } | |
| 376 | +			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); | |
| 377 | + // add event to cart | |
| 378 | +			if ($this->cart->add_ticket_to_cart($ticket, $qty)) { | |
| 379 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); | |
| 380 | + return true; | |
| 381 | + } | |
| 382 | + return false; | |
| 383 | + } | |
| 384 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); | |
| 385 | + return false; | |
| 386 | + } | |
| 387 | 387 | |
| 388 | 388 | |
| 389 | - /** | |
| 390 | - * @param $tickets_added | |
| 391 | - * @return bool | |
| 392 | - * @throws InvalidInterfaceException | |
| 393 | - * @throws InvalidDataTypeException | |
| 394 | - * @throws EE_Error | |
| 395 | - * @throws InvalidArgumentException | |
| 396 | - */ | |
| 397 | - private function processSuccessfulCart($tickets_added) | |
| 398 | -    { | |
| 399 | -        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE | |
| 400 | -        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { | |
| 401 | - // make sure cart is loaded | |
| 402 | -            if (! $this->cart instanceof EE_Cart) { | |
| 403 | - $this->cart = CartFactory::getCart(); | |
| 404 | - } | |
| 405 | - do_action( | |
| 406 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', | |
| 407 | - $this->cart, | |
| 408 | - $this | |
| 409 | - ); | |
| 410 | - $this->cart->recalculate_all_cart_totals(); | |
| 411 | - $this->cart->save_cart(false); | |
| 412 | -            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE | |
| 413 | - // just return TRUE for registrations being made from admin | |
| 414 | -            if ($this->request->isAdmin() || $this->request->isFrontAjax()) { | |
| 415 | - return true; | |
| 416 | - } | |
| 417 | - EEH_URL::safeRedirectAndExit( | |
| 418 | - apply_filters( | |
| 419 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', | |
| 420 | - $this->core_config->reg_page_url() | |
| 421 | - ) | |
| 422 | - ); | |
| 423 | - } | |
| 424 | -        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { | |
| 425 | - // nothing added to cart | |
| 426 | - EE_Error::add_attention( | |
| 427 | -                esc_html__('No tickets were added for the event', 'event_espresso'), | |
| 428 | - __FILE__, | |
| 429 | - __FUNCTION__, | |
| 430 | - __LINE__ | |
| 431 | - ); | |
| 432 | - } | |
| 433 | - return false; | |
| 434 | - } | |
| 389 | + /** | |
| 390 | + * @param $tickets_added | |
| 391 | + * @return bool | |
| 392 | + * @throws InvalidInterfaceException | |
| 393 | + * @throws InvalidDataTypeException | |
| 394 | + * @throws EE_Error | |
| 395 | + * @throws InvalidArgumentException | |
| 396 | + */ | |
| 397 | + private function processSuccessfulCart($tickets_added) | |
| 398 | +	{ | |
| 399 | +		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE | |
| 400 | +		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { | |
| 401 | + // make sure cart is loaded | |
| 402 | +			if (! $this->cart instanceof EE_Cart) { | |
| 403 | + $this->cart = CartFactory::getCart(); | |
| 404 | + } | |
| 405 | + do_action( | |
| 406 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', | |
| 407 | + $this->cart, | |
| 408 | + $this | |
| 409 | + ); | |
| 410 | + $this->cart->recalculate_all_cart_totals(); | |
| 411 | + $this->cart->save_cart(false); | |
| 412 | +			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE | |
| 413 | + // just return TRUE for registrations being made from admin | |
| 414 | +			if ($this->request->isAdmin() || $this->request->isFrontAjax()) { | |
| 415 | + return true; | |
| 416 | + } | |
| 417 | + EEH_URL::safeRedirectAndExit( | |
| 418 | + apply_filters( | |
| 419 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', | |
| 420 | + $this->core_config->reg_page_url() | |
| 421 | + ) | |
| 422 | + ); | |
| 423 | + } | |
| 424 | +		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { | |
| 425 | + // nothing added to cart | |
| 426 | + EE_Error::add_attention( | |
| 427 | +				esc_html__('No tickets were added for the event', 'event_espresso'), | |
| 428 | + __FILE__, | |
| 429 | + __FUNCTION__, | |
| 430 | + __LINE__ | |
| 431 | + ); | |
| 432 | + } | |
| 433 | + return false; | |
| 434 | + } | |
| 435 | 435 | } | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 | public function cancelTicketSelections() | 
| 120 | 120 |      { | 
| 121 | 121 | // check nonce | 
| 122 | -        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { | |
| 122 | +        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { | |
| 123 | 123 | return false; | 
| 124 | 124 | } | 
| 125 | 125 | $this->session->clear_session(__CLASS__, __FUNCTION__); | 
| @@ -131,7 +131,7 @@ discard block | ||
| 131 | 131 | ); | 
| 132 | 132 | } | 
| 133 | 133 | EEH_URL::safeRedirectAndExit( | 
| 134 | -            site_url('/' . $this->core_config->event_cpt_slug . '/') | |
| 134 | +            site_url('/'.$this->core_config->event_cpt_slug.'/') | |
| 135 | 135 | ); | 
| 136 | 136 | return true; | 
| 137 | 137 | } | 
| @@ -215,7 +215,7 @@ discard block | ||
| 215 | 215 | EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); | 
| 216 | 216 | } | 
| 217 | 217 | // check total tickets ordered vs max number of attendees that can register | 
| 218 | -        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { | |
| 218 | +        if ( ! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { | |
| 219 | 219 | $this->maxAttendeesViolation($valid); | 
| 220 | 220 |          } else { | 
| 221 | 221 | // all data appears to be valid | 
| @@ -228,7 +228,7 @@ discard block | ||
| 228 | 228 |          if ($this->request->isAdmin() || $this->request->isFrontAjax()) { | 
| 229 | 229 | return false; | 
| 230 | 230 | } | 
| 231 | -        if (! empty($valid['return_url'])) { | |
| 231 | +        if ( ! empty($valid['return_url'])) { | |
| 232 | 232 | EEH_URL::safeRedirectAndExit($valid['return_url']); | 
| 233 | 233 | } | 
| 234 | 234 | // do we have an event id? | 
| @@ -265,7 +265,7 @@ discard block | ||
| 265 | 265 | ) | 
| 266 | 266 | ); | 
| 267 | 267 | $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); | 
| 268 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); | |
| 268 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); | |
| 269 | 269 | } | 
| 270 | 270 | |
| 271 | 271 | |
| @@ -281,7 +281,7 @@ discard block | ||
| 281 | 281 |      { | 
| 282 | 282 | $tickets_added = 0; | 
| 283 | 283 | $tickets_selected = false; | 
| 284 | -        if (! empty($valid) && $valid['total_tickets'] > 0) { | |
| 284 | +        if ( ! empty($valid) && $valid['total_tickets'] > 0) { | |
| 285 | 285 | // load cart using factory because we don't want to do so until actually needed | 
| 286 | 286 | $this->cart = CartFactory::getCart(); | 
| 287 | 287 | // if the user is an admin that can edit registrations, | 
| @@ -290,18 +290,18 @@ discard block | ||
| 290 | 290 | // cycle thru the number of data rows sent from the event listing | 
| 291 | 291 |              for ($x = 0; $x < $valid['rows']; $x++) { | 
| 292 | 292 | // does this row actually contain a ticket quantity? | 
| 293 | -                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { | |
| 293 | +                if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { | |
| 294 | 294 | // YES we have a ticket quantity | 
| 295 | 295 | $tickets_selected = true; | 
| 296 | 296 | $valid_ticket = false; | 
| 297 | -                    if (isset($valid['ticket_id'][ $x ])) { | |
| 297 | +                    if (isset($valid['ticket_id'][$x])) { | |
| 298 | 298 | // get ticket via the ticket id we put in the form | 
| 299 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); | |
| 299 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]); | |
| 300 | 300 |                          if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { | 
| 301 | 301 | $valid_ticket = true; | 
| 302 | 302 | $tickets_added += $this->addTicketToCart( | 
| 303 | 303 | $ticket, | 
| 304 | - $valid['qty'][ $x ] | |
| 304 | + $valid['qty'][$x] | |
| 305 | 305 | ); | 
| 306 | 306 | } | 
| 307 | 307 | } | 
| @@ -331,7 +331,7 @@ discard block | ||
| 331 | 331 | $this->cart, | 
| 332 | 332 | $this | 
| 333 | 333 | ); | 
| 334 | -        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { | |
| 334 | +        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { | |
| 335 | 335 | // no ticket quantities were selected | 
| 336 | 336 | EE_Error::add_error( | 
| 337 | 337 |                  esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), | 
| @@ -399,7 +399,7 @@ discard block | ||
| 399 | 399 |          // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE | 
| 400 | 400 |          if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { | 
| 401 | 401 | // make sure cart is loaded | 
| 402 | -            if (! $this->cart instanceof EE_Cart) { | |
| 402 | +            if ( ! $this->cart instanceof EE_Cart) { | |
| 403 | 403 | $this->cart = CartFactory::getCart(); | 
| 404 | 404 | } | 
| 405 | 405 | do_action( | 
| @@ -421,7 +421,7 @@ discard block | ||
| 421 | 421 | ) | 
| 422 | 422 | ); | 
| 423 | 423 | } | 
| 424 | -        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { | |
| 424 | +        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { | |
| 425 | 425 | // nothing added to cart | 
| 426 | 426 | EE_Error::add_attention( | 
| 427 | 427 |                  esc_html__('No tickets were added for the event', 'event_espresso'), | 
| @@ -36,25 +36,25 @@ discard block | ||
| 36 | 36 |                      <td><h3><?php esc_html_e('1', 'event_espresso'); ?></h3></td> | 
| 37 | 37 | <td> | 
| 38 | 38 | <?php echo apply_filters( | 
| 39 | - 'FHEE__ee_migration_page__option_1_main', | |
| 40 | - sprintf( | |
| 41 | - __( | |
| 42 | - '%1$sYes. I have backed up my database%2$s, %3$sunderstand the risks involved%4$s, and am ready to migrate my existing %5$s data to %6$s.', | |
| 43 | - "event_espresso" | |
| 44 | - ), | |
| 45 | - '<strong>', | |
| 46 | - '</strong>', | |
| 47 | - '<a id="migration-risks" class="" title="' | |
| 48 | -                                . esc_attr__('click for more details', "event_espresso") | |
| 49 | - . '">', | |
| 50 | - '</a>', | |
| 51 | - $current_db_state, | |
| 52 | - $next_db_state | |
| 53 | - ), | |
| 54 | - $current_db_state, | |
| 55 | - $next_db_state | |
| 56 | - ); | |
| 57 | - ?> | |
| 39 | + 'FHEE__ee_migration_page__option_1_main', | |
| 40 | + sprintf( | |
| 41 | + __( | |
| 42 | + '%1$sYes. I have backed up my database%2$s, %3$sunderstand the risks involved%4$s, and am ready to migrate my existing %5$s data to %6$s.', | |
| 43 | + "event_espresso" | |
| 44 | + ), | |
| 45 | + '<strong>', | |
| 46 | + '</strong>', | |
| 47 | + '<a id="migration-risks" class="" title="' | |
| 48 | +								. esc_attr__('click for more details', "event_espresso") | |
| 49 | + . '">', | |
| 50 | + '</a>', | |
| 51 | + $current_db_state, | |
| 52 | + $next_db_state | |
| 53 | + ), | |
| 54 | + $current_db_state, | |
| 55 | + $next_db_state | |
| 56 | + ); | |
| 57 | + ?> | |
| 58 | 58 | <a id="display-migration-details" | 
| 59 | 59 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" | 
| 60 | 60 | rel="migration-details" | 
| @@ -67,9 +67,9 @@ discard block | ||
| 67 | 67 | style="display:none;" | 
| 68 | 68 | > | 
| 69 | 69 | <?php printf( | 
| 70 | -                                esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), | |
| 71 | - ' ' | |
| 72 | - ); ?> | |
| 70 | +								esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), | |
| 71 | + ' ' | |
| 72 | + ); ?> | |
| 73 | 73 | </a> | 
| 74 | 74 | </td> | 
| 75 | 75 | <td> | 
| @@ -77,17 +77,17 @@ discard block | ||
| 77 | 77 | class="toggle-migration-monitor button-primary" | 
| 78 | 78 | > | 
| 79 | 79 | <?php echo esc_html( | 
| 80 | - apply_filters( | |
| 81 | - 'FHEE__ee_migration_page__option_1_button_text', | |
| 82 | - sprintf( | |
| 83 | -                                        __("Migrate My %s Data to %s", "event_espresso"), | |
| 84 | - $current_db_state, | |
| 85 | - $next_db_state | |
| 86 | - ), | |
| 87 | - $current_db_state, | |
| 88 | - $next_db_state | |
| 89 | - ) | |
| 90 | - ); ?> | |
| 80 | + apply_filters( | |
| 81 | + 'FHEE__ee_migration_page__option_1_button_text', | |
| 82 | + sprintf( | |
| 83 | +										__("Migrate My %s Data to %s", "event_espresso"), | |
| 84 | + $current_db_state, | |
| 85 | + $next_db_state | |
| 86 | + ), | |
| 87 | + $current_db_state, | |
| 88 | + $next_db_state | |
| 89 | + ) | |
| 90 | + ); ?> | |
| 91 | 91 | </a> | 
| 92 | 92 | </td> | 
| 93 | 93 | </tr> | 
| @@ -96,34 +96,34 @@ discard block | ||
| 96 | 96 | <div id="migration-details-dv" style="display: none; padding: 1em;"> | 
| 97 | 97 | <span class="reminder-spn"> | 
| 98 | 98 | <?php printf( | 
| 99 | - esc_html__( | |
| 100 | - "%s Important: %s Before migrating, please back up your database and files.", | |
| 101 | - "event_espresso" | |
| 102 | - ), | |
| 103 | - "<b>", | |
| 104 | - "</b>" | |
| 105 | - ); | |
| 99 | + esc_html__( | |
| 100 | + "%s Important: %s Before migrating, please back up your database and files.", | |
| 101 | + "event_espresso" | |
| 102 | + ), | |
| 103 | + "<b>", | |
| 104 | + "</b>" | |
| 105 | + ); | |
| 106 | 106 | ?> | 
| 107 | 107 | </span> | 
| 108 | 108 | <p> | 
| 109 | 109 | <?php printf( | 
| 110 | - esc_html__( | |
| 111 | - '%1$sNot sure how to backup your existing data?%2$s Here is %3$sWordPress\'s explanation%7$s, and here\'s %6$sour explanation%7$s.%8$sYou can also search the WordPress plugin database for %4$s database backup plugins %7$s,%8$sor have one of our dedicated support technicians help you by purchasing a %5$sPriority Support Token%7$s.', | |
| 112 | - "event_espresso" | |
| 113 | - ), | |
| 114 | - '<b>', | |
| 115 | - '</b>', | |
| 116 | - "<a href='https://codex.wordpress.org/Backing_Up_Your_Database'>", | |
| 117 | - "<a href='" | |
| 118 | - . admin_url( | |
| 119 | - 'plugin-install.php?tab=search&type=term&s=database+backup&plugin-search-input=Search+Plugins' | |
| 120 | - ) | |
| 121 | - . "'>", | |
| 122 | - "<a href='https://eventespresso.com/product/priority-support-tokens/'>", | |
| 123 | - '<a href="https://eventespresso.com/wiki/how-to-back-up-your-site/">', | |
| 124 | - "</a>", | |
| 125 | - '<br/>' | |
| 126 | - ); | |
| 110 | + esc_html__( | |
| 111 | + '%1$sNot sure how to backup your existing data?%2$s Here is %3$sWordPress\'s explanation%7$s, and here\'s %6$sour explanation%7$s.%8$sYou can also search the WordPress plugin database for %4$s database backup plugins %7$s,%8$sor have one of our dedicated support technicians help you by purchasing a %5$sPriority Support Token%7$s.', | |
| 112 | + "event_espresso" | |
| 113 | + ), | |
| 114 | + '<b>', | |
| 115 | + '</b>', | |
| 116 | + "<a href='https://codex.wordpress.org/Backing_Up_Your_Database'>", | |
| 117 | + "<a href='" | |
| 118 | + . admin_url( | |
| 119 | + 'plugin-install.php?tab=search&type=term&s=database+backup&plugin-search-input=Search+Plugins' | |
| 120 | + ) | |
| 121 | + . "'>", | |
| 122 | + "<a href='https://eventespresso.com/product/priority-support-tokens/'>", | |
| 123 | + '<a href="https://eventespresso.com/wiki/how-to-back-up-your-site/">', | |
| 124 | + "</a>", | |
| 125 | + '<br/>' | |
| 126 | + ); | |
| 127 | 127 | ?> | 
| 128 | 128 | </p> | 
| 129 | 129 |                              <?php do_action('AHEE__ee_migration_page__option_1_extra_details'); ?> | 
| @@ -136,29 +136,29 @@ discard block | ||
| 136 | 136 | </td> | 
| 137 | 137 | <td> | 
| 138 | 138 | <?php echo esc_html( | 
| 139 | - apply_filters( | |
| 140 | - 'FHEE__ee_migration_page__option_2_main', | |
| 141 | - sprintf( | |
| 142 | - __( | |
| 143 | - 'I do NOT want to migrate my %1$s data to %2$s at this time and just want to use %3$s without migrating data.', | |
| 144 | - "event_espresso" | |
| 145 | - ), | |
| 146 | - $current_db_state, | |
| 147 | - $next_db_state, | |
| 148 | - $ultimate_db_state | |
| 149 | - ), | |
| 150 | - $current_db_state, | |
| 151 | - $next_db_state, | |
| 152 | - $ultimate_db_state | |
| 153 | - ) | |
| 154 | - ); | |
| 155 | - ?> | |
| 139 | + apply_filters( | |
| 140 | + 'FHEE__ee_migration_page__option_2_main', | |
| 141 | + sprintf( | |
| 142 | + __( | |
| 143 | + 'I do NOT want to migrate my %1$s data to %2$s at this time and just want to use %3$s without migrating data.', | |
| 144 | + "event_espresso" | |
| 145 | + ), | |
| 146 | + $current_db_state, | |
| 147 | + $next_db_state, | |
| 148 | + $ultimate_db_state | |
| 149 | + ), | |
| 150 | + $current_db_state, | |
| 151 | + $next_db_state, | |
| 152 | + $ultimate_db_state | |
| 153 | + ) | |
| 154 | + ); | |
| 155 | + ?> | |
| 156 | 156 | <br /> | 
| 157 | 157 | <span class="reminder-spn"> | 
| 158 | 158 | <?php esc_html_e( | 
| 159 | - 'Please Note: In order to avoid errors, any existing Event Espresso data (events, ticket, registrations, etc) in your db will be erased! Regular WP data will NOT be affected.', | |
| 160 | - 'event_espresso' | |
| 161 | - ); ?> | |
| 159 | + 'Please Note: In order to avoid errors, any existing Event Espresso data (events, ticket, registrations, etc) in your db will be erased! Regular WP data will NOT be affected.', | |
| 160 | + 'event_espresso' | |
| 161 | + ); ?> | |
| 162 | 162 | </span> | 
| 163 | 163 | <a id="display-no-migration-details" | 
| 164 | 164 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" | 
| @@ -172,9 +172,9 @@ discard block | ||
| 172 | 172 | style="display:none;" | 
| 173 | 173 | > | 
| 174 | 174 | <?php printf( | 
| 175 | -                                esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), | |
| 176 | - ' ' | |
| 177 | - ); | |
| 175 | +								esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), | |
| 176 | + ' ' | |
| 177 | + ); | |
| 178 | 178 | ?> | 
| 179 | 179 | </a> | 
| 180 | 180 | </td> | 
| @@ -184,16 +184,16 @@ discard block | ||
| 184 | 184 | href="<?php echo esc_url_raw($reset_db_page_link); ?>" | 
| 185 | 185 | > | 
| 186 | 186 | <?php echo esc_html( | 
| 187 | - apply_filters( | |
| 188 | - 'FHEE__ee_migration_page__option_2_button_text', | |
| 189 | - sprintf( | |
| 190 | -                                        __("Just Start %s and Delete Existing Data", "event_espresso"), | |
| 191 | - $ultimate_db_state | |
| 192 | - ), | |
| 193 | - $ultimate_db_state | |
| 194 | - ) | |
| 195 | - ); | |
| 196 | - ?> | |
| 187 | + apply_filters( | |
| 188 | + 'FHEE__ee_migration_page__option_2_button_text', | |
| 189 | + sprintf( | |
| 190 | +										__("Just Start %s and Delete Existing Data", "event_espresso"), | |
| 191 | + $ultimate_db_state | |
| 192 | + ), | |
| 193 | + $ultimate_db_state | |
| 194 | + ) | |
| 195 | + ); | |
| 196 | + ?> | |
| 197 | 197 | </a> | 
| 198 | 198 | </td> | 
| 199 | 199 | </tr> | 
| @@ -202,18 +202,18 @@ discard block | ||
| 202 | 202 | <div id="no-migration-details-dv" style="display: none; padding: 1em;"> | 
| 203 | 203 | <p> | 
| 204 | 204 | <?php echo esc_html( | 
| 205 | - apply_filters( | |
| 206 | - 'FHEE__ee_migration_page__option_2_details', | |
| 207 | - sprintf( | |
| 208 | - __( | |
| 209 | - "If your existing Event and Registration Data is no longer relevant nor required, you can just start up %s without performing a data migration.", | |
| 210 | - "event_espresso" | |
| 211 | - ), | |
| 212 | - $ultimate_db_state | |
| 213 | - ), | |
| 214 | - $ultimate_db_state | |
| 215 | - ) | |
| 216 | - ); ?> | |
| 205 | + apply_filters( | |
| 206 | + 'FHEE__ee_migration_page__option_2_details', | |
| 207 | + sprintf( | |
| 208 | + __( | |
| 209 | + "If your existing Event and Registration Data is no longer relevant nor required, you can just start up %s without performing a data migration.", | |
| 210 | + "event_espresso" | |
| 211 | + ), | |
| 212 | + $ultimate_db_state | |
| 213 | + ), | |
| 214 | + $ultimate_db_state | |
| 215 | + ) | |
| 216 | + ); ?> | |
| 217 | 217 | </p> | 
| 218 | 218 | </div> | 
| 219 | 219 | </td> | 
| @@ -33,55 +33,55 @@ discard block | ||
| 33 | 33 | <h3 class="espresso-header"> | 
| 34 | 34 | <span class="dashicons dashicons-flag ee-icon-size-22"></span> | 
| 35 | 35 | <?php | 
| 36 | - echo esc_html( | |
| 37 | - apply_filters( | |
| 38 | - 'FHEE__ee_migration_page__header', | |
| 39 | - sprintf( | |
| 40 | -                            __("Your Event Espresso data needs to be updated.", "event_espresso"), | |
| 41 | - $current_db_state, | |
| 42 | - $next_db_state | |
| 43 | - ), | |
| 44 | - $current_db_state, | |
| 45 | - $next_db_state | |
| 46 | - ) | |
| 47 | - ); | |
| 48 | - ?> | |
| 36 | + echo esc_html( | |
| 37 | + apply_filters( | |
| 38 | + 'FHEE__ee_migration_page__header', | |
| 39 | + sprintf( | |
| 40 | +							__("Your Event Espresso data needs to be updated.", "event_espresso"), | |
| 41 | + $current_db_state, | |
| 42 | + $next_db_state | |
| 43 | + ), | |
| 44 | + $current_db_state, | |
| 45 | + $next_db_state | |
| 46 | + ) | |
| 47 | + ); | |
| 48 | + ?> | |
| 49 | 49 | </h3> | 
| 50 | 50 |          <?php } elseif ($show_most_recent_migration) { ?> | 
| 51 | 51 | <h3 class="espresso-header"> | 
| 52 | 52 | <span class="dashicons dashicons-awards ee-icon-size-22"></span> | 
| 53 | 53 | <?php echo esc_html( | 
| 54 | - apply_filters( | |
| 55 | - 'FHEE__ee_migration_page__done_migration_header', | |
| 56 | - sprintf( | |
| 57 | - __( | |
| 58 | - 'Congratulations! Your database is "up-to-date" and you are ready to begin using %s', | |
| 59 | - "event_espresso" | |
| 60 | - ), | |
| 61 | - $ultimate_db_state | |
| 62 | - ) | |
| 63 | - ) | |
| 64 | - ); ?> | |
| 54 | + apply_filters( | |
| 55 | + 'FHEE__ee_migration_page__done_migration_header', | |
| 56 | + sprintf( | |
| 57 | + __( | |
| 58 | + 'Congratulations! Your database is "up-to-date" and you are ready to begin using %s', | |
| 59 | + "event_espresso" | |
| 60 | + ), | |
| 61 | + $ultimate_db_state | |
| 62 | + ) | |
| 63 | + ) | |
| 64 | + ); ?> | |
| 65 | 65 | </h3> | 
| 66 | 66 | <p> | 
| 67 | 67 | <?php echo esc_html( | 
| 68 | - apply_filters( | |
| 69 | - 'FHEE__ee_migration_page__p_after_done_migration_header', | |
| 70 | - sprintf( | |
| 71 | - __( | |
| 72 | - "Time to find out about all the great new features %s has to offer.", | |
| 73 | - "event_espresso" | |
| 74 | - ), | |
| 75 | - $ultimate_db_state | |
| 76 | - ) | |
| 77 | - ) | |
| 78 | - ); ?>   | |
| 68 | + apply_filters( | |
| 69 | + 'FHEE__ee_migration_page__p_after_done_migration_header', | |
| 70 | + sprintf( | |
| 71 | + __( | |
| 72 | + "Time to find out about all the great new features %s has to offer.", | |
| 73 | + "event_espresso" | |
| 74 | + ), | |
| 75 | + $ultimate_db_state | |
| 76 | + ) | |
| 77 | + ) | |
| 78 | + ); ?>   | |
| 79 | 79 | <b> | 
| 80 | 80 | <a class="button-primary" | 
| 81 | 81 | id='get-started-after-migrate' | 
| 82 | 82 | href="<?php | 
| 83 | -                        echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php'))); | |
| 84 | - ?>" | |
| 83 | +						echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php'))); | |
| 84 | + ?>" | |
| 85 | 85 | > | 
| 86 | 86 |                          <?php esc_html_e("Let's Get Started", "event_espresso"); ?>  | 
| 87 | 87 | <span class="dashicons dashicons-arrow-right ee-icon-size-22" style="margin:0;"></span> | 
| @@ -92,46 +92,46 @@ discard block | ||
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | <?php | 
| 95 | -        if ($show_backup_db_text) { | |
| 96 | - echo $migration_options_html; | |
| 97 | - } ?> | |
| 95 | +		if ($show_backup_db_text) { | |
| 96 | + echo $migration_options_html; | |
| 97 | + } ?> | |
| 98 | 98 | |
| 99 | 99 | <?php | 
| 100 | -        if ($show_most_recent_migration) { | |
| 101 | -            if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) { | |
| 102 | -                if ($most_recent_migration->can_continue()) { | |
| 103 | - // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> | |
| 100 | +		if ($show_most_recent_migration) { | |
| 101 | +			if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) { | |
| 102 | +				if ($most_recent_migration->can_continue()) { | |
| 103 | + // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> | |
| 104 | 104 | <h3 class="espresso-header"> | 
| 105 | 105 | <span class="dashicons dashicons-star-half ee-icon-size-22"></span> | 
| 106 | 106 | <?php printf( | 
| 107 | - esc_html__( | |
| 108 | - "It appears that your previous Database Update (%s) is incomplete, and should be resumed", | |
| 109 | - "event_espresso" | |
| 110 | - ), | |
| 111 | - $most_recent_migration->pretty_name() | |
| 112 | - ); ?> | |
| 107 | + esc_html__( | |
| 108 | + "It appears that your previous Database Update (%s) is incomplete, and should be resumed", | |
| 109 | + "event_espresso" | |
| 110 | + ), | |
| 111 | + $most_recent_migration->pretty_name() | |
| 112 | + ); ?> | |
| 113 | 113 | </h3> | 
| 114 | 114 | <?php | 
| 115 | -                } elseif ($most_recent_migration->is_broken()) { | |
| 116 | - // tell the user the migration failed, and they should notify EE?> | |
| 115 | +				} elseif ($most_recent_migration->is_broken()) { | |
| 116 | + // tell the user the migration failed, and they should notify EE?> | |
| 117 | 117 | <h3 class="espresso-header"> | 
| 118 | 118 | <span class="dashicons dashicons-no ee-icon-size-22"></span> | 
| 119 | 119 | <?php echo esc_html($most_recent_migration->get_feedback_message()) ?> | 
| 120 | 120 | </h3> | 
| 121 | 121 | <?php | 
| 122 | - } | |
| 123 | - // display errors or not of the most recent migration ran | |
| 124 | -                if ($most_recent_migration->get_errors()) { | |
| 125 | - ?> | |
| 122 | + } | |
| 123 | + // display errors or not of the most recent migration ran | |
| 124 | +				if ($most_recent_migration->get_errors()) { | |
| 125 | + ?> | |
| 126 | 126 | <div class="ee-attention"> | 
| 127 | 127 | <strong> | 
| 128 | 128 | <?php printf( | 
| 129 | - esc_html__( | |
| 130 | - "Warnings occurred during your last Database Update (%s):", | |
| 131 | - 'event_espresso' | |
| 132 | - ), | |
| 133 | - $most_recent_migration->pretty_name() | |
| 134 | - ); ?> | |
| 129 | + esc_html__( | |
| 130 | + "Warnings occurred during your last Database Update (%s):", | |
| 131 | + 'event_espresso' | |
| 132 | + ), | |
| 133 | + $most_recent_migration->pretty_name() | |
| 134 | + ); ?> | |
| 135 | 135 | </strong> | 
| 136 | 136 | <a id="show-hide-migration-warnings" class="display-the-hidden"> | 
| 137 | 137 |                              <?php esc_html_e("Show Warnings", 'event_espresso'); ?> | 
| @@ -143,32 +143,32 @@ discard block | ||
| 143 | 143 | </ul> | 
| 144 | 144 | </div> | 
| 145 | 145 | <?php | 
| 146 | -                } else { | |
| 147 | - // there were no errors during the last migration, just say so?> | |
| 146 | +				} else { | |
| 147 | + // there were no errors during the last migration, just say so?> | |
| 148 | 148 | <h2> | 
| 149 | 149 | <?php printf( | 
| 150 | - esc_html__( | |
| 151 | - "The last Database Update (%s) ran successfully without errors.", | |
| 152 | - "event_espresso" | |
| 153 | - ), | |
| 154 | - $most_recent_migration->pretty_name() | |
| 155 | - ); ?> | |
| 150 | + esc_html__( | |
| 151 | + "The last Database Update (%s) ran successfully without errors.", | |
| 152 | + "event_espresso" | |
| 153 | + ), | |
| 154 | + $most_recent_migration->pretty_name() | |
| 155 | + ); ?> | |
| 156 | 156 | </h2> | 
| 157 | 157 | <?php | 
| 158 | - } | |
| 159 | - } | |
| 160 | - } | |
| 161 | - // end of: if ( $show_most_recent_migration ) | |
| 162 | - ?> | |
| 158 | + } | |
| 159 | + } | |
| 160 | + } | |
| 161 | + // end of: if ( $show_most_recent_migration ) | |
| 162 | + ?> | |
| 163 | 163 | |
| 164 | 164 | </div> | 
| 165 | 165 | <!--end of #migration-prep--> | 
| 166 | 166 | |
| 167 | 167 | <?php | 
| 168 | -    if ($show_migration_progress) { ?> | |
| 168 | +	if ($show_migration_progress) { ?> | |
| 169 | 169 | <div id='migration-monitor' <?php echo $show_backup_db_text ? "style='display:none'" : '' ?>> | 
| 170 | 170 | <?php | 
| 171 | -            if ($show_backup_db_text) { ?> | |
| 171 | +			if ($show_backup_db_text) { ?> | |
| 172 | 172 | <p> | 
| 173 | 173 | <a class="toggle-migration-monitor small-text" style="cursor: pointer;"> | 
| 174 | 174 | <span class="dashicons dashicons-arrow-left-alt2" style="top:0;"></span> | 
| @@ -178,19 +178,19 @@ discard block | ||
| 178 | 178 | |
| 179 | 179 | </p> | 
| 180 | 180 | <?php | 
| 181 | - } ?> | |
| 181 | + } ?> | |
| 182 | 182 | <div id='progress-area'> | 
| 183 | 183 | <h3 class="espresso-header"> | 
| 184 | 184 | <?php | 
| 185 | - echo sprintf( | |
| 186 | - _n( | |
| 187 | - "The following task needs to be performed:", | |
| 188 | - "The following %s tasks need to be performed:", | |
| 189 | - count($script_names), | |
| 190 | - "event_espresso" | |
| 191 | - ), | |
| 192 | - count($script_names) | |
| 193 | - ); ?> | |
| 185 | + echo sprintf( | |
| 186 | + _n( | |
| 187 | + "The following task needs to be performed:", | |
| 188 | + "The following %s tasks need to be performed:", | |
| 189 | + count($script_names), | |
| 190 | + "event_espresso" | |
| 191 | + ), | |
| 192 | + count($script_names) | |
| 193 | + ); ?> | |
| 194 | 194 | </h3> | 
| 195 | 195 | <ul style="list-style: inside;"> | 
| 196 | 196 |                      <?php foreach ($script_names as $script_name) { ?> | 
| @@ -201,9 +201,9 @@ discard block | ||
| 201 | 201 |                  <?php if (count($script_names) > 1) { ?> | 
| 202 | 202 | <p> | 
| 203 | 203 | <?php esc_html_e( | 
| 204 | - "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", | |
| 205 | - "event_espresso" | |
| 206 | - ); ?> | |
| 204 | + "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", | |
| 205 | + "event_espresso" | |
| 206 | + ); ?> | |
| 207 | 207 | </p> | 
| 208 | 208 | <?php } ?> | 
| 209 | 209 | |
| @@ -214,19 +214,19 @@ discard block | ||
| 214 | 214 | </span> | 
| 215 | 215 | <br /> | 
| 216 | 216 | <?php esc_html_e( | 
| 217 | - "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", | |
| 218 | - "event_espresso" | |
| 219 | - ); ?> | |
| 217 | + "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", | |
| 218 | + "event_espresso" | |
| 219 | + ); ?> | |
| 220 | 220 | </p> | 
| 221 | 221 | <p> | 
| 222 | 222 | <?php printf( | 
| 223 | - esc_html__( | |
| 224 | - "%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.", | |
| 225 | - "event_espresso" | |
| 226 | - ), | |
| 227 | - '<strong>', | |
| 228 | - '</strong>' | |
| 229 | - ); ?> | |
| 223 | + esc_html__( | |
| 224 | + "%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.", | |
| 225 | + "event_espresso" | |
| 226 | + ), | |
| 227 | + '<strong>', | |
| 228 | + '</strong>' | |
| 229 | + ); ?> | |
| 230 | 230 | </p> | 
| 231 | 231 | <p> | 
| 232 | 232 |                          <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?> | 
| @@ -242,8 +242,8 @@ discard block | ||
| 242 | 242 | |
| 243 | 243 | <button id='start-migration' class='button-primary'> | 
| 244 | 244 | <?php echo $show_continue_current_migration_script | 
| 245 | -                        ? esc_html__("Continue Database Update", "event_espresso") | |
| 246 | -                        : esc_html__("Begin Database Update", "event_espresso"); ?> | |
| 245 | +						? esc_html__("Continue Database Update", "event_espresso") | |
| 246 | +						: esc_html__("Begin Database Update", "event_espresso"); ?> | |
| 247 | 247 | </button> | 
| 248 | 248 | <br class="clear" /> | 
| 249 | 249 | |
| @@ -259,9 +259,9 @@ discard block | ||
| 259 | 259 | </div> | 
| 260 | 260 | |
| 261 | 261 | <?php | 
| 262 | - } | |
| 263 | -    if ($show_maintenance_switch) { | |
| 264 | - ?> | |
| 262 | + } | |
| 263 | +	if ($show_maintenance_switch) { | |
| 264 | + ?> | |
| 265 | 265 | <h2> | 
| 266 | 266 | <span class="dashicons dashicons-admin-tools"></span> | 
| 267 | 267 |              <?php esc_html_e('Set Event Espresso Maintenance Mode', 'event_espresso'); ?> | 
| @@ -276,9 +276,9 @@ discard block | ||
| 276 | 276 | type='radio' | 
| 277 | 277 | value="0" | 
| 278 | 278 | <?php echo $mMode_level === EE_Maintenance_Mode::level_0_not_in_maintenance | 
| 279 | - ? 'checked="checked"' | |
| 280 | - : '' | |
| 281 | - ?> | |
| 279 | + ? 'checked="checked"' | |
| 280 | + : '' | |
| 281 | + ?> | |
| 282 | 282 | /> | 
| 283 | 283 | </td> | 
| 284 | 284 | <th align="left"> | 
| @@ -287,9 +287,9 @@ discard block | ||
| 287 | 287 | </label> | 
| 288 | 288 | <p class='description' style="font-weight: normal;"> | 
| 289 | 289 | <?php esc_html_e( | 
| 290 | - "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", | |
| 291 | - "event_espresso" | |
| 292 | - ); ?> | |
| 290 | + "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", | |
| 291 | + "event_espresso" | |
| 292 | + ); ?> | |
| 293 | 293 | </p> | 
| 294 | 294 | </th> | 
| 295 | 295 | </tr> | 
| @@ -300,9 +300,9 @@ discard block | ||
| 300 | 300 | type='radio' | 
| 301 | 301 | value="1" | 
| 302 | 302 | <?php echo $mMode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance | 
| 303 | - ? 'checked="checked"' | |
| 304 | - : '' | |
| 305 | - ?> | |
| 303 | + ? 'checked="checked"' | |
| 304 | + : '' | |
| 305 | + ?> | |
| 306 | 306 | /> | 
| 307 | 307 | </td> | 
| 308 | 308 | <th align="left"> | 
| @@ -311,9 +311,9 @@ discard block | ||
| 311 | 311 | </label> | 
| 312 | 312 | <p class='description' style="font-weight: normal;"> | 
| 313 | 313 | <?php esc_html_e( | 
| 314 | - "This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.", | |
| 315 | - "event_espresso" | |
| 316 | - ); ?> | |
| 314 | + "This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.", | |
| 315 | + "event_espresso" | |
| 316 | + ); ?> | |
| 317 | 317 | </p> | 
| 318 | 318 | </th> | 
| 319 | 319 | </tr> | 
| @@ -327,6 +327,6 @@ discard block | ||
| 327 | 327 | </p> | 
| 328 | 328 | </form> | 
| 329 | 329 | <?php | 
| 330 | - } ?> | |
| 330 | + } ?> | |
| 331 | 331 | |
| 332 | 332 | </div> | 
| @@ -17,2656 +17,2656 @@ discard block | ||
| 17 | 17 | class Messages_Admin_Page extends EE_Admin_Page | 
| 18 | 18 |  { | 
| 19 | 19 | |
| 20 | - /** | |
| 21 | - * @type EE_Message_Resource_Manager $_message_resource_manager | |
| 22 | - */ | |
| 23 | - protected $_message_resource_manager; | |
| 20 | + /** | |
| 21 | + * @type EE_Message_Resource_Manager $_message_resource_manager | |
| 22 | + */ | |
| 23 | + protected $_message_resource_manager; | |
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * @type string $_active_message_type_name | |
| 27 | - */ | |
| 28 | - protected $_active_message_type_name = ''; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * @type EE_messenger $_active_messenger | |
| 32 | - */ | |
| 33 | - protected $_active_messenger; | |
| 34 | - | |
| 35 | - protected $_activate_state; | |
| 36 | - | |
| 37 | - protected $_activate_meta_box_type; | |
| 38 | - | |
| 39 | - protected $_current_message_meta_box; | |
| 40 | - | |
| 41 | - protected $_current_message_meta_box_object; | |
| 42 | - | |
| 43 | - protected $_context_switcher; | |
| 44 | - | |
| 45 | - protected $_shortcodes = []; | |
| 46 | - | |
| 47 | - protected $_active_messengers = []; | |
| 48 | - | |
| 49 | - protected $_active_message_types = []; | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @var EE_Message_Template_Group $_message_template_group | |
| 53 | - */ | |
| 54 | - protected $_message_template_group; | |
| 55 | - | |
| 56 | - protected $_m_mt_settings = []; | |
| 57 | - | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. | |
| 61 | - * IF there is no group then it gets automatically set to the Default template pack. | |
| 62 | - * | |
| 63 | - * @since 4.5.0 | |
| 64 | - * | |
| 65 | - * @var EE_Messages_Template_Pack | |
| 66 | - */ | |
| 67 | - protected $_template_pack; | |
| 68 | - | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the | |
| 72 | - * group is. If there is no group then it automatically gets set to default. | |
| 73 | - * | |
| 74 | - * @since 4.5.0 | |
| 75 | - * | |
| 76 | - * @var string | |
| 77 | - */ | |
| 78 | - protected $_variation; | |
| 79 | - | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * @param bool $routing | |
| 83 | - * @throws EE_Error | |
| 84 | - */ | |
| 85 | - public function __construct($routing = true) | |
| 86 | -    { | |
| 87 | - // make sure messages autoloader is running | |
| 88 | - EED_Messages::set_autoloaders(); | |
| 89 | - parent::__construct($routing); | |
| 90 | - } | |
| 91 | - | |
| 92 | - | |
| 93 | - protected function _init_page_props() | |
| 94 | -    { | |
| 95 | - $this->page_slug = EE_MSG_PG_SLUG; | |
| 96 | -        $this->page_label       = esc_html__('Messages Settings', 'event_espresso'); | |
| 97 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; | |
| 98 | - $this->_admin_base_path = EE_MSG_ADMIN; | |
| 99 | - | |
| 100 | - $this->_activate_state = isset($this->_req_data['activate_state']) | |
| 101 | - ? (array) $this->_req_data['activate_state'] | |
| 102 | - : []; | |
| 103 | - | |
| 104 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; | |
| 105 | - $this->_load_message_resource_manager(); | |
| 106 | - } | |
| 107 | - | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) | |
| 111 | - * | |
| 112 | - * @throws EE_Error | |
| 113 | - * @throws InvalidDataTypeException | |
| 114 | - * @throws InvalidInterfaceException | |
| 115 | - * @throws InvalidArgumentException | |
| 116 | - * @throws ReflectionException | |
| 117 | - */ | |
| 118 | - protected function _load_message_resource_manager() | |
| 119 | -    { | |
| 120 | -        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | |
| 121 | - } | |
| 122 | - | |
| 123 | - | |
| 124 | - /** | |
| 125 | - * @return array | |
| 126 | - * @throws EE_Error | |
| 127 | - * @throws InvalidArgumentException | |
| 128 | - * @throws InvalidDataTypeException | |
| 129 | - * @throws InvalidInterfaceException | |
| 130 | - * @deprecated 4.9.9.rc.014 | |
| 131 | - */ | |
| 132 | - public function get_messengers_for_list_table() | |
| 133 | -    { | |
| 134 | - EE_Error::doing_it_wrong( | |
| 135 | - __METHOD__, | |
| 136 | - sprintf( | |
| 137 | - esc_html__( | |
| 138 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', | |
| 139 | - 'event_espresso' | |
| 140 | - ), | |
| 141 | - 'Messages_Admin_Page::get_messengers_select_input()' | |
| 142 | - ), | |
| 143 | - '4.9.9.rc.014' | |
| 144 | - ); | |
| 145 | - | |
| 146 | - $m_values = []; | |
| 147 | - $active_messengers = EEM_Message::instance()->get_all(['group_by' => 'MSG_messenger']); | |
| 148 | - // setup messengers for selects | |
| 149 | - $i = 1; | |
| 150 | -        foreach ($active_messengers as $active_messenger) { | |
| 151 | -            if ($active_messenger instanceof EE_Message) { | |
| 152 | - $m_values[ $i ]['id'] = $active_messenger->messenger(); | |
| 153 | - $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label()); | |
| 154 | - $i++; | |
| 155 | - } | |
| 156 | - } | |
| 157 | - | |
| 158 | - return $m_values; | |
| 159 | - } | |
| 160 | - | |
| 161 | - | |
| 162 | - /** | |
| 163 | - * @return array | |
| 164 | - * @throws EE_Error | |
| 165 | - * @throws InvalidArgumentException | |
| 166 | - * @throws InvalidDataTypeException | |
| 167 | - * @throws InvalidInterfaceException | |
| 168 | - * @deprecated 4.9.9.rc.014 | |
| 169 | - */ | |
| 170 | - public function get_message_types_for_list_table() | |
| 171 | -    { | |
| 172 | - EE_Error::doing_it_wrong( | |
| 173 | - __METHOD__, | |
| 174 | - sprintf( | |
| 175 | - esc_html__( | |
| 176 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', | |
| 177 | - 'event_espresso' | |
| 178 | - ), | |
| 179 | - 'Messages_Admin_Page::get_message_types_select_input()' | |
| 180 | - ), | |
| 181 | - '4.9.9.rc.014' | |
| 182 | - ); | |
| 183 | - | |
| 184 | - $mt_values = []; | |
| 185 | - $active_messages = EEM_Message::instance()->get_all(['group_by' => 'MSG_message_type']); | |
| 186 | - $i = 1; | |
| 187 | -        foreach ($active_messages as $active_message) { | |
| 188 | -            if ($active_message instanceof EE_Message) { | |
| 189 | - $mt_values[ $i ]['id'] = $active_message->message_type(); | |
| 190 | - $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label()); | |
| 191 | - $i++; | |
| 192 | - } | |
| 193 | - } | |
| 194 | - | |
| 195 | - return $mt_values; | |
| 196 | - } | |
| 197 | - | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * @return array | |
| 201 | - * @throws EE_Error | |
| 202 | - * @throws InvalidArgumentException | |
| 203 | - * @throws InvalidDataTypeException | |
| 204 | - * @throws InvalidInterfaceException | |
| 205 | - * @deprecated 4.9.9.rc.014 | |
| 206 | - */ | |
| 207 | - public function get_contexts_for_message_types_for_list_table() | |
| 208 | -    { | |
| 209 | - EE_Error::doing_it_wrong( | |
| 210 | - __METHOD__, | |
| 211 | - sprintf( | |
| 212 | - esc_html__( | |
| 213 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', | |
| 214 | - 'event_espresso' | |
| 215 | - ), | |
| 216 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' | |
| 217 | - ), | |
| 218 | - '4.9.9.rc.014' | |
| 219 | - ); | |
| 220 | - | |
| 221 | - $contexts = []; | |
| 222 | - $active_message_contexts = EEM_Message::instance()->get_all(['group_by' => 'MSG_context']); | |
| 223 | -        foreach ($active_message_contexts as $active_message) { | |
| 224 | -            if ($active_message instanceof EE_Message) { | |
| 225 | - $message_type = $active_message->message_type_object(); | |
| 226 | -                if ($message_type instanceof EE_message_type) { | |
| 227 | - $message_type_contexts = $message_type->get_contexts(); | |
| 228 | -                    foreach ($message_type_contexts as $context => $context_details) { | |
| 229 | - $contexts[ $context ] = $context_details['label']; | |
| 230 | - } | |
| 231 | - } | |
| 232 | - } | |
| 233 | - } | |
| 234 | - | |
| 235 | - return $contexts; | |
| 236 | - } | |
| 237 | - | |
| 238 | - | |
| 239 | - /** | |
| 240 | - * Generate select input with provided messenger options array. | |
| 241 | - * | |
| 242 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger | |
| 243 | - * labels. | |
| 244 | - * @return string | |
| 245 | - * @throws EE_Error | |
| 246 | - */ | |
| 247 | - public function get_messengers_select_input($messenger_options) | |
| 248 | -    { | |
| 249 | - // if empty or just one value then just return an empty string | |
| 250 | - if ( | |
| 251 | - empty($messenger_options) | |
| 252 | - || ! is_array($messenger_options) | |
| 253 | - || count($messenger_options) === 1 | |
| 254 | -        ) { | |
| 255 | - return ''; | |
| 256 | - } | |
| 257 | - // merge in default | |
| 258 | - $messenger_options = array_merge( | |
| 259 | -            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')], | |
| 260 | - $messenger_options | |
| 261 | - ); | |
| 262 | - $input = new EE_Select_Input( | |
| 263 | - $messenger_options, | |
| 264 | - [ | |
| 265 | - 'html_name' => 'ee_messenger_filter_by', | |
| 266 | - 'html_id' => 'ee_messenger_filter_by', | |
| 267 | - 'html_class' => 'wide', | |
| 268 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) | |
| 269 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) | |
| 270 | - : 'none_selected', | |
| 271 | - ] | |
| 272 | - ); | |
| 273 | - | |
| 274 | - return $input->get_html_for_input(); | |
| 275 | - } | |
| 276 | - | |
| 277 | - | |
| 278 | - /** | |
| 279 | - * Generate select input with provided message type options array. | |
| 280 | - * | |
| 281 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the | |
| 282 | - * message type labels | |
| 283 | - * @return string | |
| 284 | - * @throws EE_Error | |
| 285 | - */ | |
| 286 | - public function get_message_types_select_input($message_type_options) | |
| 287 | -    { | |
| 288 | - // if empty or count of options is 1 then just return an empty string | |
| 289 | - if ( | |
| 290 | - empty($message_type_options) | |
| 291 | - || ! is_array($message_type_options) | |
| 292 | - || count($message_type_options) === 1 | |
| 293 | -        ) { | |
| 294 | - return ''; | |
| 295 | - } | |
| 296 | - // merge in default | |
| 297 | - $message_type_options = array_merge( | |
| 298 | -            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')], | |
| 299 | - $message_type_options | |
| 300 | - ); | |
| 301 | - $input = new EE_Select_Input( | |
| 302 | - $message_type_options, | |
| 303 | - [ | |
| 304 | - 'html_name' => 'ee_message_type_filter_by', | |
| 305 | - 'html_id' => 'ee_message_type_filter_by', | |
| 306 | - 'html_class' => 'wide', | |
| 307 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) | |
| 308 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) | |
| 309 | - : 'none_selected', | |
| 310 | - ] | |
| 311 | - ); | |
| 312 | - | |
| 313 | - return $input->get_html_for_input(); | |
| 314 | - } | |
| 315 | - | |
| 316 | - | |
| 317 | - /** | |
| 318 | - * Generate select input with provide message type contexts array. | |
| 319 | - * | |
| 320 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the | |
| 321 | - * context label. | |
| 322 | - * @return string | |
| 323 | - * @throws EE_Error | |
| 324 | - */ | |
| 325 | - public function get_contexts_for_message_types_select_input($context_options) | |
| 326 | -    { | |
| 327 | - // if empty or count of options is one then just return empty string | |
| 328 | - if ( | |
| 329 | - empty($context_options) | |
| 330 | - || ! is_array($context_options) | |
| 331 | - || count($context_options) === 1 | |
| 332 | -        ) { | |
| 333 | - return ''; | |
| 334 | - } | |
| 335 | - // merge in default | |
| 336 | - $context_options = array_merge( | |
| 337 | -            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')], | |
| 338 | - $context_options | |
| 339 | - ); | |
| 340 | - $input = new EE_Select_Input( | |
| 341 | - $context_options, | |
| 342 | - [ | |
| 343 | - 'html_name' => 'ee_context_filter_by', | |
| 344 | - 'html_id' => 'ee_context_filter_by', | |
| 345 | - 'html_class' => 'wide', | |
| 346 | - 'default' => isset($this->_req_data['ee_context_filter_by']) | |
| 347 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) | |
| 348 | - : 'none_selected', | |
| 349 | - ] | |
| 350 | - ); | |
| 351 | - | |
| 352 | - return $input->get_html_for_input(); | |
| 353 | - } | |
| 354 | - | |
| 355 | - | |
| 356 | - protected function _ajax_hooks() | |
| 357 | -    { | |
| 358 | -        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']); | |
| 359 | -        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']); | |
| 360 | -        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']); | |
| 361 | -        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']); | |
| 362 | -        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']); | |
| 363 | -        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']); | |
| 364 | - } | |
| 365 | - | |
| 366 | - | |
| 367 | - protected function _define_page_props() | |
| 368 | -    { | |
| 369 | - $this->_admin_page_title = $this->page_label; | |
| 370 | - $this->_labels = [ | |
| 371 | - 'buttons' => [ | |
| 372 | -                'add'    => esc_html__('Add New Message Template', 'event_espresso'), | |
| 373 | -                'edit'   => esc_html__('Edit Message Template', 'event_espresso'), | |
| 374 | -                'delete' => esc_html__('Delete Message Template', 'event_espresso'), | |
| 375 | - ], | |
| 376 | -            'publishbox' => esc_html__('Update Actions', 'event_espresso'), | |
| 377 | - ]; | |
| 378 | - } | |
| 379 | - | |
| 380 | - | |
| 381 | - /** | |
| 382 | - * an array for storing key => value pairs of request actions and their corresponding methods | |
| 383 | - * | |
| 384 | - * @access protected | |
| 385 | - * @return void | |
| 386 | - */ | |
| 387 | - protected function _set_page_routes() | |
| 388 | -    { | |
| 389 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) | |
| 390 | - ? $this->_req_data['GRP_ID'] | |
| 391 | - : 0; | |
| 392 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) | |
| 393 | - ? $this->_req_data['id'] | |
| 394 | - : $grp_id; | |
| 395 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) | |
| 396 | - ? $this->_req_data['MSG_ID'] | |
| 397 | - : 0; | |
| 398 | - | |
| 399 | - $this->_page_routes = [ | |
| 400 | - 'default' => [ | |
| 401 | - 'func' => '_message_queue_list_table', | |
| 402 | - 'capability' => 'ee_read_global_messages', | |
| 403 | - ], | |
| 404 | - 'global_mtps' => [ | |
| 405 | - 'func' => '_ee_default_messages_overview_list_table', | |
| 406 | - 'capability' => 'ee_read_global_messages', | |
| 407 | - ], | |
| 408 | - 'custom_mtps' => [ | |
| 409 | - 'func' => '_custom_mtps_preview', | |
| 410 | - 'capability' => 'ee_read_messages', | |
| 411 | - ], | |
| 412 | - 'add_new_message_template' => [ | |
| 413 | - 'func' => '_add_message_template', | |
| 414 | - 'capability' => 'ee_edit_messages', | |
| 415 | - 'noheader' => true, | |
| 416 | - ], | |
| 417 | - 'edit_message_template' => [ | |
| 418 | - 'func' => '_edit_message_template', | |
| 419 | - 'capability' => 'ee_edit_message', | |
| 420 | - 'obj_id' => $grp_id, | |
| 421 | - ], | |
| 422 | - 'preview_message' => [ | |
| 423 | - 'func' => '_preview_message', | |
| 424 | - 'capability' => 'ee_read_message', | |
| 425 | - 'obj_id' => $grp_id, | |
| 426 | - 'noheader' => true, | |
| 427 | - 'headers_sent_route' => 'display_preview_message', | |
| 428 | - ], | |
| 429 | - 'display_preview_message' => [ | |
| 430 | - 'func' => '_display_preview_message', | |
| 431 | - 'capability' => 'ee_read_message', | |
| 432 | - 'obj_id' => $grp_id, | |
| 433 | - ], | |
| 434 | - 'insert_message_template' => [ | |
| 435 | - 'func' => '_insert_or_update_message_template', | |
| 436 | - 'capability' => 'ee_edit_messages', | |
| 437 | - 'args' => ['new' => true], | |
| 438 | - 'noheader' => true, | |
| 439 | - ], | |
| 440 | - 'update_message_template' => [ | |
| 441 | - 'func' => '_insert_or_update_message_template', | |
| 442 | - 'capability' => 'ee_edit_message', | |
| 443 | - 'obj_id' => $grp_id, | |
| 444 | - 'args' => ['new' => false], | |
| 445 | - 'noheader' => true, | |
| 446 | - ], | |
| 447 | - 'trash_message_template' => [ | |
| 448 | - 'func' => '_trash_or_restore_message_template', | |
| 449 | - 'capability' => 'ee_delete_message', | |
| 450 | - 'obj_id' => $grp_id, | |
| 451 | - 'args' => ['trash' => true, 'all' => true], | |
| 452 | - 'noheader' => true, | |
| 453 | - ], | |
| 454 | - 'trash_message_template_context' => [ | |
| 455 | - 'func' => '_trash_or_restore_message_template', | |
| 456 | - 'capability' => 'ee_delete_message', | |
| 457 | - 'obj_id' => $grp_id, | |
| 458 | - 'args' => ['trash' => true], | |
| 459 | - 'noheader' => true, | |
| 460 | - ], | |
| 461 | - 'restore_message_template' => [ | |
| 462 | - 'func' => '_trash_or_restore_message_template', | |
| 463 | - 'capability' => 'ee_delete_message', | |
| 464 | - 'obj_id' => $grp_id, | |
| 465 | - 'args' => ['trash' => false, 'all' => true], | |
| 466 | - 'noheader' => true, | |
| 467 | - ], | |
| 468 | - 'restore_message_template_context' => [ | |
| 469 | - 'func' => '_trash_or_restore_message_template', | |
| 470 | - 'capability' => 'ee_delete_message', | |
| 471 | - 'obj_id' => $grp_id, | |
| 472 | - 'args' => ['trash' => false], | |
| 473 | - 'noheader' => true, | |
| 474 | - ], | |
| 475 | - 'delete_message_template' => [ | |
| 476 | - 'func' => '_delete_message_template', | |
| 477 | - 'capability' => 'ee_delete_message', | |
| 478 | - 'obj_id' => $grp_id, | |
| 479 | - 'noheader' => true, | |
| 480 | - ], | |
| 481 | - 'reset_to_default' => [ | |
| 482 | - 'func' => '_reset_to_default_template', | |
| 483 | - 'capability' => 'ee_edit_message', | |
| 484 | - 'obj_id' => $grp_id, | |
| 485 | - 'noheader' => true, | |
| 486 | - ], | |
| 487 | - 'settings' => [ | |
| 488 | - 'func' => '_settings', | |
| 489 | - 'capability' => 'manage_options', | |
| 490 | - ], | |
| 491 | - 'update_global_settings' => [ | |
| 492 | - 'func' => '_update_global_settings', | |
| 493 | - 'capability' => 'manage_options', | |
| 494 | - 'noheader' => true, | |
| 495 | - ], | |
| 496 | - 'generate_now' => [ | |
| 497 | - 'func' => '_generate_now', | |
| 498 | - 'capability' => 'ee_send_message', | |
| 499 | - 'noheader' => true, | |
| 500 | - ], | |
| 501 | - 'generate_and_send_now' => [ | |
| 502 | - 'func' => '_generate_and_send_now', | |
| 503 | - 'capability' => 'ee_send_message', | |
| 504 | - 'noheader' => true, | |
| 505 | - ], | |
| 506 | - 'queue_for_resending' => [ | |
| 507 | - 'func' => '_queue_for_resending', | |
| 508 | - 'capability' => 'ee_send_message', | |
| 509 | - 'noheader' => true, | |
| 510 | - ], | |
| 511 | - 'send_now' => [ | |
| 512 | - 'func' => '_send_now', | |
| 513 | - 'capability' => 'ee_send_message', | |
| 514 | - 'noheader' => true, | |
| 515 | - ], | |
| 516 | - 'delete_ee_message' => [ | |
| 517 | - 'func' => '_delete_ee_messages', | |
| 518 | - 'capability' => 'ee_delete_messages', | |
| 519 | - 'noheader' => true, | |
| 520 | - ], | |
| 521 | - 'delete_ee_messages' => [ | |
| 522 | - 'func' => '_delete_ee_messages', | |
| 523 | - 'capability' => 'ee_delete_messages', | |
| 524 | - 'noheader' => true, | |
| 525 | - 'obj_id' => $msg_id, | |
| 526 | - ], | |
| 527 | - ]; | |
| 528 | - } | |
| 529 | - | |
| 530 | - | |
| 531 | - protected function _set_page_config() | |
| 532 | -    { | |
| 533 | - $this->_page_config = [ | |
| 534 | - 'default' => [ | |
| 535 | - 'nav' => [ | |
| 536 | -                    'label' => esc_html__('Message Activity', 'event_espresso'), | |
| 537 | - 'order' => 10, | |
| 538 | - ], | |
| 539 | - 'list_table' => 'EE_Message_List_Table', | |
| 540 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), | |
| 541 | - 'require_nonce' => false, | |
| 542 | - ], | |
| 543 | - 'global_mtps' => [ | |
| 544 | - 'nav' => [ | |
| 545 | -                    'label' => esc_html__('Default Message Templates', 'event_espresso'), | |
| 546 | - 'order' => 20, | |
| 547 | - ], | |
| 548 | - 'list_table' => 'Messages_Template_List_Table', | |
| 549 | - 'help_tabs' => [ | |
| 550 | - 'messages_overview_help_tab' => [ | |
| 551 | -                        'title'    => esc_html__('Messages Overview', 'event_espresso'), | |
| 552 | - 'filename' => 'messages_overview', | |
| 553 | - ], | |
| 554 | - 'messages_overview_messages_table_column_headings_help_tab' => [ | |
| 555 | -                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'), | |
| 556 | - 'filename' => 'messages_overview_table_column_headings', | |
| 557 | - ], | |
| 558 | - 'messages_overview_messages_filters_help_tab' => [ | |
| 559 | -                        'title'    => esc_html__('Message Filters', 'event_espresso'), | |
| 560 | - 'filename' => 'messages_overview_filters', | |
| 561 | - ], | |
| 562 | - 'messages_overview_messages_views_help_tab' => [ | |
| 563 | -                        'title'    => esc_html__('Message Views', 'event_espresso'), | |
| 564 | - 'filename' => 'messages_overview_views', | |
| 565 | - ], | |
| 566 | - 'message_overview_message_types_help_tab' => [ | |
| 567 | -                        'title'    => esc_html__('Message Types', 'event_espresso'), | |
| 568 | - 'filename' => 'messages_overview_types', | |
| 569 | - ], | |
| 570 | - 'messages_overview_messengers_help_tab' => [ | |
| 571 | -                        'title'    => esc_html__('Messengers', 'event_espresso'), | |
| 572 | - 'filename' => 'messages_overview_messengers', | |
| 573 | - ], | |
| 574 | - ], | |
| 575 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 576 | -                // 'help_tour'     => array('Messages_Overview_Help_Tour'), | |
| 577 | - 'require_nonce' => false, | |
| 578 | - ], | |
| 579 | - 'custom_mtps' => [ | |
| 580 | - 'nav' => [ | |
| 581 | -                    'label' => esc_html__('Custom Message Templates', 'event_espresso'), | |
| 582 | - 'order' => 30, | |
| 583 | - ], | |
| 584 | - 'help_tabs' => [], | |
| 585 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 586 | - // 'help_tour' => array(), | |
| 587 | - 'require_nonce' => false, | |
| 588 | - ], | |
| 589 | - 'add_new_message_template' => [ | |
| 590 | - 'nav' => [ | |
| 591 | -                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'), | |
| 592 | - 'order' => 5, | |
| 593 | - 'persistent' => false, | |
| 594 | - ], | |
| 595 | - 'require_nonce' => false, | |
| 596 | - ], | |
| 597 | - 'edit_message_template' => [ | |
| 598 | - 'labels' => [ | |
| 599 | - 'buttons' => [ | |
| 600 | -                        'reset' => esc_html__('Reset Templates', 'event_espresso'), | |
| 601 | - ], | |
| 602 | -                    'publishbox' => esc_html__('Update Actions', 'event_espresso'), | |
| 603 | - ], | |
| 604 | - 'nav' => [ | |
| 605 | -                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'), | |
| 606 | - 'order' => 5, | |
| 607 | - 'persistent' => false, | |
| 608 | - 'url' => '', | |
| 609 | - ], | |
| 610 | - 'metaboxes' => ['_publish_post_box', '_register_edit_meta_boxes'], | |
| 611 | - 'has_metaboxes' => true, | |
| 612 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 613 | -                // 'help_tour'     => array('Message_Templates_Edit_Help_Tour'), | |
| 614 | - 'help_tabs' => [ | |
| 615 | - 'edit_message_template' => [ | |
| 616 | -                        'title'    => esc_html__('Message Template Editor', 'event_espresso'), | |
| 617 | - 'callback' => 'edit_message_template_help_tab', | |
| 618 | - ], | |
| 619 | - 'message_templates_help_tab' => [ | |
| 620 | -                        'title'    => esc_html__('Message Templates', 'event_espresso'), | |
| 621 | - 'filename' => 'messages_templates', | |
| 622 | - ], | |
| 623 | - 'message_template_shortcodes' => [ | |
| 624 | -                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'), | |
| 625 | - 'callback' => 'message_template_shortcodes_help_tab', | |
| 626 | - ], | |
| 627 | - 'message_preview_help_tab' => [ | |
| 628 | -                        'title'    => esc_html__('Message Preview', 'event_espresso'), | |
| 629 | - 'filename' => 'messages_preview', | |
| 630 | - ], | |
| 631 | - 'messages_overview_other_help_tab' => [ | |
| 632 | -                        'title'    => esc_html__('Messages Other', 'event_espresso'), | |
| 633 | - 'filename' => 'messages_overview_other', | |
| 634 | - ], | |
| 635 | - ], | |
| 636 | - 'require_nonce' => false, | |
| 637 | - ], | |
| 638 | - 'display_preview_message' => [ | |
| 639 | - 'nav' => [ | |
| 640 | -                    'label'      => esc_html__('Message Preview', 'event_espresso'), | |
| 641 | - 'order' => 5, | |
| 642 | - 'url' => '', | |
| 643 | - 'persistent' => false, | |
| 644 | - ], | |
| 645 | - 'help_tabs' => [ | |
| 646 | - 'preview_message' => [ | |
| 647 | -                        'title'    => esc_html__('About Previews', 'event_espresso'), | |
| 648 | - 'callback' => 'preview_message_help_tab', | |
| 649 | - ], | |
| 650 | - ], | |
| 651 | - 'require_nonce' => false, | |
| 652 | - ], | |
| 653 | - 'settings' => [ | |
| 654 | - 'nav' => [ | |
| 655 | -                    'label' => esc_html__('Settings', 'event_espresso'), | |
| 656 | - 'order' => 40, | |
| 657 | - ], | |
| 658 | - 'metaboxes' => ['_messages_settings_metaboxes'], | |
| 659 | - 'help_tabs' => [ | |
| 660 | - 'messages_settings_help_tab' => [ | |
| 661 | -                        'title'    => esc_html__('Messages Settings', 'event_espresso'), | |
| 662 | - 'filename' => 'messages_settings', | |
| 663 | - ], | |
| 664 | - 'messages_settings_message_types_help_tab' => [ | |
| 665 | -                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), | |
| 666 | - 'filename' => 'messages_settings_message_types', | |
| 667 | - ], | |
| 668 | - 'messages_settings_messengers_help_tab' => [ | |
| 669 | -                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), | |
| 670 | - 'filename' => 'messages_settings_messengers', | |
| 671 | - ], | |
| 672 | - ], | |
| 673 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 674 | -                // 'help_tour'     => array('Messages_Settings_Help_Tour'), | |
| 675 | - 'require_nonce' => false, | |
| 676 | - ], | |
| 677 | - ]; | |
| 678 | - } | |
| 679 | - | |
| 680 | - | |
| 681 | - protected function _add_screen_options() | |
| 682 | -    { | |
| 683 | - // todo | |
| 684 | - } | |
| 685 | - | |
| 686 | - | |
| 687 | - protected function _add_screen_options_global_mtps() | |
| 688 | -    { | |
| 689 | - /** | |
| 690 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options | |
| 691 | - * uses the $_admin_page_title property and we want different outputs in the different spots. | |
| 692 | - */ | |
| 693 | - $page_title = $this->_admin_page_title; | |
| 694 | -        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); | |
| 695 | - $this->_per_page_screen_option(); | |
| 696 | - $this->_admin_page_title = $page_title; | |
| 697 | - } | |
| 698 | - | |
| 699 | - | |
| 700 | - protected function _add_screen_options_default() | |
| 701 | -    { | |
| 702 | -        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); | |
| 703 | - $this->_per_page_screen_option(); | |
| 704 | - } | |
| 705 | - | |
| 706 | - | |
| 707 | - // none of the below group are currently used for Messages | |
| 708 | - protected function _add_feature_pointers() | |
| 709 | -    { | |
| 710 | - } | |
| 711 | - | |
| 712 | - | |
| 713 | - public function admin_init() | |
| 714 | -    { | |
| 715 | - } | |
| 716 | - | |
| 717 | - | |
| 718 | - public function admin_notices() | |
| 719 | -    { | |
| 720 | - } | |
| 721 | - | |
| 722 | - | |
| 723 | - public function admin_footer_scripts() | |
| 724 | -    { | |
| 725 | - } | |
| 726 | - | |
| 727 | - | |
| 728 | - public function messages_help_tab() | |
| 729 | -    { | |
| 730 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); | |
| 731 | - } | |
| 732 | - | |
| 733 | - | |
| 734 | - public function messengers_help_tab() | |
| 735 | -    { | |
| 736 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); | |
| 737 | - } | |
| 738 | - | |
| 739 | - | |
| 740 | - public function message_types_help_tab() | |
| 741 | -    { | |
| 742 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); | |
| 743 | - } | |
| 744 | - | |
| 745 | - | |
| 746 | - public function messages_overview_help_tab() | |
| 747 | -    { | |
| 748 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); | |
| 749 | - } | |
| 750 | - | |
| 751 | - | |
| 752 | - public function message_templates_help_tab() | |
| 753 | -    { | |
| 754 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); | |
| 755 | - } | |
| 756 | - | |
| 757 | - | |
| 758 | - public function edit_message_template_help_tab() | |
| 759 | -    { | |
| 760 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' | |
| 761 | -                        . esc_attr__('Editor Title', 'event_espresso') | |
| 762 | - . '" />'; | |
| 763 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' | |
| 764 | -                        . esc_attr__('Context Switcher and Preview', 'event_espresso') | |
| 765 | - . '" />'; | |
| 766 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' | |
| 767 | -                        . esc_attr__('Message Template Form Fields', 'event_espresso') | |
| 768 | - . '" />'; | |
| 769 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' | |
| 770 | -                        . esc_attr__('Shortcodes Metabox', 'event_espresso') | |
| 771 | - . '" />'; | |
| 772 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' | |
| 773 | -                        . esc_attr__('Publish Metabox', 'event_espresso') | |
| 774 | - . '" />'; | |
| 775 | - EEH_Template::display_template( | |
| 776 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', | |
| 777 | - $args | |
| 778 | - ); | |
| 779 | - } | |
| 780 | - | |
| 781 | - | |
| 782 | - public function message_template_shortcodes_help_tab() | |
| 783 | -    { | |
| 784 | - $this->_set_shortcodes(); | |
| 785 | - $args['shortcodes'] = $this->_shortcodes; | |
| 786 | - EEH_Template::display_template( | |
| 787 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', | |
| 788 | - $args | |
| 789 | - ); | |
| 790 | - } | |
| 791 | - | |
| 792 | - | |
| 793 | - public function preview_message_help_tab() | |
| 794 | -    { | |
| 795 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); | |
| 796 | - } | |
| 797 | - | |
| 798 | - | |
| 799 | - public function settings_help_tab() | |
| 800 | -    { | |
| 801 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' | |
| 802 | -                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; | |
| 803 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' | |
| 804 | -                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; | |
| 805 | - $args['img3'] = '<div class="switch">' | |
| 806 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' | |
| 807 | - . ' type="checkbox" checked="checked">' | |
| 808 | - . '<label for="ee-on-off-toggle-on"></label>' | |
| 809 | - . '</div>'; | |
| 810 | - $args['img4'] = '<div class="switch">' | |
| 811 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' | |
| 812 | - . ' type="checkbox">' | |
| 813 | - . '<label for="ee-on-off-toggle-on"></label>' | |
| 814 | - . '</div>'; | |
| 815 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); | |
| 816 | - } | |
| 817 | - | |
| 818 | - | |
| 819 | - public function load_scripts_styles() | |
| 820 | -    { | |
| 821 | -        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | |
| 822 | -        wp_enqueue_style('espresso_ee_msg'); | |
| 823 | - | |
| 824 | - wp_register_script( | |
| 825 | - 'ee-messages-settings', | |
| 826 | - EE_MSG_ASSETS_URL . 'ee-messages-settings.js', | |
| 827 | - ['jquery-ui-droppable', 'ee-serialize-full-array'], | |
| 828 | - EVENT_ESPRESSO_VERSION, | |
| 829 | - true | |
| 830 | - ); | |
| 831 | - wp_register_script( | |
| 832 | - 'ee-msg-list-table-js', | |
| 833 | - EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', | |
| 834 | - ['ee-dialog'], | |
| 835 | - EVENT_ESPRESSO_VERSION | |
| 836 | - ); | |
| 837 | - } | |
| 838 | - | |
| 839 | - | |
| 840 | - public function load_scripts_styles_default() | |
| 841 | -    { | |
| 842 | -        wp_enqueue_script('ee-msg-list-table-js'); | |
| 843 | - } | |
| 844 | - | |
| 845 | - | |
| 846 | - public function wp_editor_css($mce_css) | |
| 847 | -    { | |
| 848 | - // if we're on the edit_message_template route | |
| 849 | -        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { | |
| 850 | - $message_type_name = $this->_active_message_type_name; | |
| 851 | - | |
| 852 | - // we're going to REPLACE the existing mce css | |
| 853 | - // we need to get the css file location from the active messenger | |
| 854 | - $mce_css = $this->_active_messenger->get_variation( | |
| 855 | - $this->_template_pack, | |
| 856 | - $message_type_name, | |
| 857 | - true, | |
| 858 | - 'wpeditor', | |
| 859 | - $this->_variation | |
| 860 | - ); | |
| 861 | - } | |
| 862 | - | |
| 863 | - return $mce_css; | |
| 864 | - } | |
| 865 | - | |
| 866 | - | |
| 867 | - public function load_scripts_styles_edit_message_template() | |
| 868 | -    { | |
| 869 | - | |
| 870 | - $this->_set_shortcodes(); | |
| 871 | - | |
| 872 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( | |
| 873 | - esc_html__( | |
| 874 | - 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', | |
| 875 | - 'event_espresso' | |
| 876 | - ), | |
| 877 | - $this->_message_template_group->messenger_obj()->label['singular'], | |
| 878 | - $this->_message_template_group->message_type_obj()->label['singular'] | |
| 879 | - ); | |
| 880 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( | |
| 881 | - 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', | |
| 882 | - 'event_espresso' | |
| 883 | - ); | |
| 884 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( | |
| 885 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', | |
| 886 | - 'event_espresso' | |
| 887 | - ); | |
| 888 | - | |
| 889 | - wp_register_script( | |
| 890 | - 'ee_msgs_edit_js', | |
| 891 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', | |
| 892 | - ['jquery'], | |
| 893 | - EVENT_ESPRESSO_VERSION | |
| 894 | - ); | |
| 895 | - | |
| 896 | -        wp_enqueue_script('ee_admin_js'); | |
| 897 | -        wp_enqueue_script('ee_msgs_edit_js'); | |
| 898 | - | |
| 899 | - // add in special css for tiny_mce | |
| 900 | -        add_filter('mce_css', [$this, 'wp_editor_css']); | |
| 901 | - } | |
| 902 | - | |
| 903 | - | |
| 904 | - public function load_scripts_styles_display_preview_message() | |
| 905 | -    { | |
| 906 | - | |
| 907 | - $this->_set_message_template_group(); | |
| 908 | - | |
| 909 | -        if (isset($this->_req_data['messenger'])) { | |
| 910 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( | |
| 911 | - $this->_req_data['messenger'] | |
| 912 | - ); | |
| 913 | - } | |
| 914 | - | |
| 915 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; | |
| 916 | - | |
| 917 | - | |
| 918 | - wp_enqueue_style( | |
| 919 | - 'espresso_preview_css', | |
| 920 | - $this->_active_messenger->get_variation( | |
| 921 | - $this->_template_pack, | |
| 922 | - $message_type_name, | |
| 923 | - true, | |
| 924 | - 'preview', | |
| 925 | - $this->_variation | |
| 926 | - ) | |
| 927 | - ); | |
| 928 | - } | |
| 929 | - | |
| 930 | - | |
| 931 | - public function load_scripts_styles_settings() | |
| 932 | -    { | |
| 933 | - wp_register_style( | |
| 934 | - 'ee-message-settings', | |
| 935 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', | |
| 936 | - [], | |
| 937 | - EVENT_ESPRESSO_VERSION | |
| 938 | - ); | |
| 939 | -        wp_enqueue_style('ee-text-links'); | |
| 940 | -        wp_enqueue_style('ee-message-settings'); | |
| 941 | -        wp_enqueue_script('ee-messages-settings'); | |
| 942 | - } | |
| 943 | - | |
| 944 | - | |
| 945 | - /** | |
| 946 | - * set views array for List Table | |
| 947 | - */ | |
| 948 | - public function _set_list_table_views_global_mtps() | |
| 949 | -    { | |
| 950 | - $this->_views = [ | |
| 951 | - 'in_use' => [ | |
| 952 | - 'slug' => 'in_use', | |
| 953 | -                'label' => esc_html__('In Use', 'event_espresso'), | |
| 954 | - 'count' => 0, | |
| 955 | - ], | |
| 956 | - ]; | |
| 957 | - } | |
| 958 | - | |
| 959 | - | |
| 960 | - /** | |
| 961 | - * Set views array for the Custom Template List Table | |
| 962 | - */ | |
| 963 | - public function _set_list_table_views_custom_mtps() | |
| 964 | -    { | |
| 965 | - $this->_set_list_table_views_global_mtps(); | |
| 966 | - $this->_views['in_use']['bulk_action'] = [ | |
| 967 | -            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'), | |
| 968 | - ]; | |
| 969 | - } | |
| 970 | - | |
| 971 | - | |
| 972 | - /** | |
| 973 | - * set views array for message queue list table | |
| 974 | - * | |
| 975 | - * @throws InvalidDataTypeException | |
| 976 | - * @throws InvalidInterfaceException | |
| 977 | - * @throws InvalidArgumentException | |
| 978 | - * @throws EE_Error | |
| 979 | - * @throws ReflectionException | |
| 980 | - */ | |
| 981 | - public function _set_list_table_views_default() | |
| 982 | -    { | |
| 983 | -        EE_Registry::instance()->load_helper('Template'); | |
| 984 | - | |
| 985 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( | |
| 986 | - 'ee_send_message', | |
| 987 | - 'message_list_table_bulk_actions' | |
| 988 | - ) | |
| 989 | - ? [ | |
| 990 | -                'generate_now'          => esc_html__('Generate Now', 'event_espresso'), | |
| 991 | -                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), | |
| 992 | -                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'), | |
| 993 | -                'send_now'              => esc_html__('Send Now', 'event_espresso'), | |
| 994 | - ] | |
| 995 | - : []; | |
| 996 | - | |
| 997 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( | |
| 998 | - 'ee_delete_messages', | |
| 999 | - 'message_list_table_bulk_actions' | |
| 1000 | - ) | |
| 1001 | -            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')] | |
| 1002 | - : []; | |
| 1003 | - | |
| 1004 | - | |
| 1005 | - $this->_views = [ | |
| 1006 | - 'all' => [ | |
| 1007 | - 'slug' => 'all', | |
| 1008 | -                'label'       => esc_html__('All', 'event_espresso'), | |
| 1009 | - 'count' => 0, | |
| 1010 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action), | |
| 1011 | - ], | |
| 1012 | - ]; | |
| 1013 | - | |
| 1014 | - | |
| 1015 | -        foreach (EEM_Message::instance()->all_statuses() as $status) { | |
| 1016 | -            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { | |
| 1017 | - continue; | |
| 1018 | - } | |
| 1019 | - $status_bulk_actions = $common_bulk_actions; | |
| 1020 | - // unset bulk actions not applying to status | |
| 1021 | -            if (! empty($status_bulk_actions)) { | |
| 1022 | -                switch ($status) { | |
| 1023 | - case EEM_Message::status_idle: | |
| 1024 | - case EEM_Message::status_resend: | |
| 1025 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; | |
| 1026 | - break; | |
| 1027 | - | |
| 1028 | - case EEM_Message::status_failed: | |
| 1029 | - case EEM_Message::status_debug_only: | |
| 1030 | - case EEM_Message::status_messenger_executing: | |
| 1031 | - $status_bulk_actions = []; | |
| 1032 | - break; | |
| 1033 | - | |
| 1034 | - case EEM_Message::status_incomplete: | |
| 1035 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); | |
| 1036 | - break; | |
| 1037 | - | |
| 1038 | - case EEM_Message::status_retry: | |
| 1039 | - case EEM_Message::status_sent: | |
| 1040 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); | |
| 1041 | - break; | |
| 1042 | - } | |
| 1043 | - } | |
| 1044 | - | |
| 1045 | - // skip adding messenger executing status to views because it will be included with the Failed view. | |
| 1046 | -            if ($status === EEM_Message::status_messenger_executing) { | |
| 1047 | - continue; | |
| 1048 | - } | |
| 1049 | - | |
| 1050 | - $this->_views[ strtolower($status) ] = [ | |
| 1051 | - 'slug' => strtolower($status), | |
| 1052 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), | |
| 1053 | - 'count' => 0, | |
| 1054 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action), | |
| 1055 | - ]; | |
| 1056 | - } | |
| 1057 | - } | |
| 1058 | - | |
| 1059 | - | |
| 1060 | - protected function _ee_default_messages_overview_list_table() | |
| 1061 | -    { | |
| 1062 | -        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); | |
| 1063 | - $this->display_admin_list_table_page_with_no_sidebar(); | |
| 1064 | - } | |
| 1065 | - | |
| 1066 | - | |
| 1067 | - protected function _message_queue_list_table() | |
| 1068 | -    { | |
| 1069 | -        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso'); | |
| 1070 | - $this->_template_args['per_column'] = 6; | |
| 1071 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); | |
| 1072 | - $this->_template_args['before_list_table'] = '<h3>' | |
| 1073 | - . EEM_Message::instance()->get_pretty_label_for_results() | |
| 1074 | - . '</h3>'; | |
| 1075 | - $this->display_admin_list_table_page_with_no_sidebar(); | |
| 1076 | - } | |
| 1077 | - | |
| 1078 | - | |
| 1079 | - protected function _message_legend_items() | |
| 1080 | -    { | |
| 1081 | - | |
| 1082 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); | |
| 1083 | - $action_items = []; | |
| 1084 | - | |
| 1085 | -        foreach ($action_css_classes as $action_item => $action_details) { | |
| 1086 | -            if ($action_item === 'see_notifications_for') { | |
| 1087 | - continue; | |
| 1088 | - } | |
| 1089 | - $action_items[ $action_item ] = [ | |
| 1090 | - 'class' => $action_details['css_class'], | |
| 1091 | - 'desc' => $action_details['label'], | |
| 1092 | - ]; | |
| 1093 | - } | |
| 1094 | - | |
| 1095 | - /** @type array $status_items status legend setup */ | |
| 1096 | - $status_items = [ | |
| 1097 | - 'sent_status' => [ | |
| 1098 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, | |
| 1099 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'), | |
| 1100 | - ], | |
| 1101 | - 'idle_status' => [ | |
| 1102 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, | |
| 1103 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'), | |
| 1104 | - ], | |
| 1105 | - 'failed_status' => [ | |
| 1106 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, | |
| 1107 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'), | |
| 1108 | - ], | |
| 1109 | - 'messenger_executing_status' => [ | |
| 1110 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, | |
| 1111 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'), | |
| 1112 | - ], | |
| 1113 | - 'resend_status' => [ | |
| 1114 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, | |
| 1115 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'), | |
| 1116 | - ], | |
| 1117 | - 'incomplete_status' => [ | |
| 1118 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, | |
| 1119 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'), | |
| 1120 | - ], | |
| 1121 | - 'retry_status' => [ | |
| 1122 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, | |
| 1123 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'), | |
| 1124 | - ], | |
| 1125 | - ]; | |
| 1126 | -        if (EEM_Message::debug()) { | |
| 1127 | - $status_items['debug_only_status'] = [ | |
| 1128 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, | |
| 1129 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'), | |
| 1130 | - ]; | |
| 1131 | - } | |
| 1132 | - | |
| 1133 | - return array_merge($action_items, $status_items); | |
| 1134 | - } | |
| 1135 | - | |
| 1136 | - | |
| 1137 | - protected function _custom_mtps_preview() | |
| 1138 | -    { | |
| 1139 | -        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); | |
| 1140 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' | |
| 1141 | - . ' alt="' . esc_attr__( | |
| 1142 | - 'Preview Custom Message Templates screenshot', | |
| 1143 | - 'event_espresso' | |
| 1144 | - ) . '" />'; | |
| 1145 | - $this->_template_args['preview_text'] = '<strong>' | |
| 1146 | - . esc_html__( | |
| 1147 | - 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', | |
| 1148 | - 'event_espresso' | |
| 1149 | - ) | |
| 1150 | - . '</strong>'; | |
| 1151 | - | |
| 1152 | -        $this->display_admin_caf_preview_page('custom_message_types', false); | |
| 1153 | - } | |
| 1154 | - | |
| 1155 | - | |
| 1156 | - /** | |
| 1157 | - * get_message_templates | |
| 1158 | - * This gets all the message templates for listing on the overview list. | |
| 1159 | - * | |
| 1160 | - * @access public | |
| 1161 | - * @param int $perpage the amount of templates groups to show per page | |
| 1162 | - * @param string $type the current _view we're getting templates for | |
| 1163 | - * @param bool $count return count? | |
| 1164 | - * @param bool $all disregard any paging info (get all data); | |
| 1165 | - * @param bool $global whether to return just global (true) or custom templates (false) | |
| 1166 | - * @return array | |
| 1167 | - * @throws EE_Error | |
| 1168 | - * @throws InvalidArgumentException | |
| 1169 | - * @throws InvalidDataTypeException | |
| 1170 | - * @throws InvalidInterfaceException | |
| 1171 | - */ | |
| 1172 | - public function get_message_templates( | |
| 1173 | - $perpage = 10, | |
| 1174 | - $type = 'in_use', | |
| 1175 | - $count = false, | |
| 1176 | - $all = false, | |
| 1177 | - $global = true | |
| 1178 | -    ) { | |
| 1179 | - | |
| 1180 | - $MTP = EEM_Message_Template_Group::instance(); | |
| 1181 | - | |
| 1182 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; | |
| 1183 | - $orderby = $this->_req_data['orderby']; | |
| 1184 | - | |
| 1185 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) | |
| 1186 | - ? $this->_req_data['order'] | |
| 1187 | - : 'ASC'; | |
| 1188 | - | |
| 1189 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) | |
| 1190 | - ? $this->_req_data['paged'] | |
| 1191 | - : 1; | |
| 1192 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) | |
| 1193 | - ? $this->_req_data['perpage'] | |
| 1194 | - : $perpage; | |
| 1195 | - | |
| 1196 | - $offset = ($current_page - 1) * $per_page; | |
| 1197 | - $limit = $all ? null : [$offset, $per_page]; | |
| 1198 | - | |
| 1199 | - | |
| 1200 | - // options will match what is in the _views array property | |
| 1201 | -        switch ($type) { | |
| 1202 | - case 'in_use': | |
| 1203 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); | |
| 1204 | - break; | |
| 1205 | - default: | |
| 1206 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); | |
| 1207 | - } | |
| 1208 | - | |
| 1209 | - return $templates; | |
| 1210 | - } | |
| 1211 | - | |
| 1212 | - | |
| 1213 | - /** | |
| 1214 | - * filters etc might need a list of installed message_types | |
| 1215 | - * | |
| 1216 | - * @return array an array of message type objects | |
| 1217 | - */ | |
| 1218 | - public function get_installed_message_types() | |
| 1219 | -    { | |
| 1220 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); | |
| 1221 | - $installed = []; | |
| 1222 | - | |
| 1223 | -        foreach ($installed_message_types as $message_type) { | |
| 1224 | - $installed[ $message_type->name ] = $message_type; | |
| 1225 | - } | |
| 1226 | - | |
| 1227 | - return $installed; | |
| 1228 | - } | |
| 1229 | - | |
| 1230 | - | |
| 1231 | - /** | |
| 1232 | - * _add_message_template | |
| 1233 | - * | |
| 1234 | - * This is used when creating a custom template. All Custom Templates start based off another template. | |
| 1235 | - * | |
| 1236 | - * @param string $message_type | |
| 1237 | - * @param string $messenger | |
| 1238 | - * @param string $GRP_ID | |
| 1239 | - * | |
| 1240 | - * @throws EE_error | |
| 1241 | - */ | |
| 1242 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') | |
| 1243 | -    { | |
| 1244 | - // set values override any request data | |
| 1245 | -        $message_type = ! empty($message_type) ? $message_type : $this->request->getRequestParam('message_type'); | |
| 1246 | -        $messenger    = ! empty($messenger) ? $messenger : $this->request->getRequestParam('messenger'); | |
| 1247 | -        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int'); | |
| 1248 | - | |
| 1249 | - // we need messenger and message type. They should be coming from the event editor. If not here then return error | |
| 1250 | -        if (empty($message_type) || empty($messenger)) { | |
| 1251 | - throw new EE_Error( | |
| 1252 | - esc_html__( | |
| 1253 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', | |
| 1254 | - 'event_espresso' | |
| 1255 | - ) | |
| 1256 | - ); | |
| 1257 | - } | |
| 1258 | - | |
| 1259 | - // we need the GRP_ID for the template being used as the base for the new template | |
| 1260 | -        if (empty($GRP_ID)) { | |
| 1261 | - throw new EE_Error( | |
| 1262 | - esc_html__( | |
| 1263 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', | |
| 1264 | - 'event_espresso' | |
| 1265 | - ) | |
| 1266 | - ); | |
| 1267 | - } | |
| 1268 | - | |
| 1269 | - // let's just make sure the template gets generated! | |
| 1270 | - | |
| 1271 | - // we need to reassign some variables for what the insert is expecting | |
| 1272 | - $this->_req_data['MTP_messenger'] = $messenger; | |
| 1273 | - $this->_req_data['MTP_message_type'] = $message_type; | |
| 1274 | - $this->_req_data['GRP_ID'] = $GRP_ID; | |
| 1275 | - $this->_insert_or_update_message_template(true); | |
| 1276 | - } | |
| 1277 | - | |
| 1278 | - | |
| 1279 | - /** | |
| 1280 | - * public wrapper for the _add_message_template method | |
| 1281 | - * | |
| 1282 | - * @param string $message_type message type slug | |
| 1283 | - * @param string $messenger messenger slug | |
| 1284 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based | |
| 1285 | - * off of. | |
| 1286 | - * @throws EE_error | |
| 1287 | - */ | |
| 1288 | - public function add_message_template($message_type, $messenger, $GRP_ID) | |
| 1289 | -    { | |
| 1290 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); | |
| 1291 | - } | |
| 1292 | - | |
| 1293 | - | |
| 1294 | - /** | |
| 1295 | - * _edit_message_template | |
| 1296 | - * | |
| 1297 | - * @access protected | |
| 1298 | - * @return void | |
| 1299 | - * @throws InvalidIdentifierException | |
| 1300 | - * @throws DomainException | |
| 1301 | - * @throws EE_Error | |
| 1302 | - * @throws InvalidArgumentException | |
| 1303 | - * @throws ReflectionException | |
| 1304 | - * @throws InvalidDataTypeException | |
| 1305 | - * @throws InvalidInterfaceException | |
| 1306 | - */ | |
| 1307 | - protected function _edit_message_template() | |
| 1308 | -    { | |
| 1309 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 1310 | - $template_fields = ''; | |
| 1311 | - $sidebar_fields = ''; | |
| 1312 | - // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have | |
| 1313 | - // valid html in the templates. | |
| 1314 | -        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2); | |
| 1315 | - | |
| 1316 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) | |
| 1317 | - ? absint($this->_req_data['id']) | |
| 1318 | - : false; | |
| 1319 | - | |
| 1320 | - $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) | |
| 1321 | - ? absint($this->_req_data['evt_id']) | |
| 1322 | - : false; | |
| 1323 | - | |
| 1324 | - $this->_set_shortcodes(); // this also sets the _message_template property. | |
| 1325 | - $message_template_group = $this->_message_template_group; | |
| 1326 | - $c_label = $message_template_group->context_label(); | |
| 1327 | - $c_config = $message_template_group->contexts_config(); | |
| 1328 | - | |
| 1329 | - reset($c_config); | |
| 1330 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) | |
| 1331 | - ? strtolower($this->_req_data['context']) | |
| 1332 | - : key($c_config); | |
| 1333 | - | |
| 1334 | - | |
| 1335 | -        if (empty($GRP_ID)) { | |
| 1336 | - $action = 'insert_message_template'; | |
| 1337 | - $edit_message_template_form_url = add_query_arg( | |
| 1338 | - ['action' => $action, 'noheader' => true], | |
| 1339 | - EE_MSG_ADMIN_URL | |
| 1340 | - ); | |
| 1341 | -        } else { | |
| 1342 | - $action = 'update_message_template'; | |
| 1343 | - $edit_message_template_form_url = add_query_arg( | |
| 1344 | - ['action' => $action, 'noheader' => true], | |
| 1345 | - EE_MSG_ADMIN_URL | |
| 1346 | - ); | |
| 1347 | - } | |
| 1348 | - | |
| 1349 | - // set active messenger for this view | |
| 1350 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( | |
| 1351 | - $message_template_group->messenger() | |
| 1352 | - ); | |
| 1353 | - $this->_active_message_type_name = $message_template_group->message_type(); | |
| 1354 | - | |
| 1355 | - | |
| 1356 | - // Do we have any validation errors? | |
| 1357 | - $validators = $this->_get_transient(); | |
| 1358 | - $v_fields = ! empty($validators) ? array_keys($validators) : []; | |
| 1359 | - | |
| 1360 | - | |
| 1361 | - // we need to assemble the title from Various details | |
| 1362 | - $context_label = sprintf( | |
| 1363 | -            esc_html__('(%s %s)', 'event_espresso'), | |
| 1364 | - $c_config[ $context ]['label'], | |
| 1365 | - ucwords($c_label['label']) | |
| 1366 | - ); | |
| 1367 | - | |
| 1368 | - $title = sprintf( | |
| 1369 | -            esc_html__(' %s %s Template %s', 'event_espresso'), | |
| 1370 | - ucwords($message_template_group->messenger_obj()->label['singular']), | |
| 1371 | - ucwords($message_template_group->message_type_obj()->label['singular']), | |
| 1372 | - $context_label | |
| 1373 | - ); | |
| 1374 | - | |
| 1375 | - $this->_template_args['GRP_ID'] = $GRP_ID; | |
| 1376 | - $this->_template_args['message_template'] = $message_template_group; | |
| 1377 | - $this->_template_args['is_extra_fields'] = false; | |
| 1378 | - | |
| 1379 | - | |
| 1380 | - // let's get EEH_MSG_Template so we can get template form fields | |
| 1381 | - $template_field_structure = EEH_MSG_Template::get_fields( | |
| 1382 | - $message_template_group->messenger(), | |
| 1383 | - $message_template_group->message_type() | |
| 1384 | - ); | |
| 1385 | - | |
| 1386 | -        if (! $template_field_structure) { | |
| 1387 | - $template_field_structure = false; | |
| 1388 | - $template_fields = esc_html__( | |
| 1389 | - 'There was an error in assembling the fields for this display (you should see an error message)', | |
| 1390 | - 'event_espresso' | |
| 1391 | - ); | |
| 1392 | - } | |
| 1393 | - | |
| 1394 | - | |
| 1395 | - $message_templates = $message_template_group->context_templates(); | |
| 1396 | - | |
| 1397 | - | |
| 1398 | - // if we have the extra key.. then we need to remove the content index from the template_field_structure as it | |
| 1399 | - // will get handled in the "extra" array. | |
| 1400 | -        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { | |
| 1401 | -            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { | |
| 1402 | - unset($template_field_structure[ $context ][ $reference_field ]); | |
| 1403 | - } | |
| 1404 | - } | |
| 1405 | - | |
| 1406 | - // let's loop through the template_field_structure and actually assemble the input fields! | |
| 1407 | -        if (! empty($template_field_structure)) { | |
| 1408 | -            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { | |
| 1409 | - // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in | |
| 1410 | - // the extra array and reset them. | |
| 1411 | -                if ($template_field === 'extra') { | |
| 1412 | - $this->_template_args['is_extra_fields'] = true; | |
| 1413 | -                    foreach ($field_setup_array as $reference_field => $new_fields_array) { | |
| 1414 | - $message_template = $message_templates[ $context ][ $reference_field ]; | |
| 1415 | - $content = $message_template instanceof EE_Message_Template | |
| 1416 | -                            ? $message_template->get('MTP_content') | |
| 1417 | - : ''; | |
| 1418 | -                        foreach ($new_fields_array as $extra_field => $extra_array) { | |
| 1419 | - // let's verify if we need this extra field via the shortcodes parameter. | |
| 1420 | - $continue = false; | |
| 1421 | -                            if (isset($extra_array['shortcodes_required'])) { | |
| 1422 | -                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { | |
| 1423 | -                                    if (! array_key_exists($shortcode, $this->_shortcodes)) { | |
| 1424 | - $continue = true; | |
| 1425 | - } | |
| 1426 | - } | |
| 1427 | -                                if ($continue) { | |
| 1428 | - continue; | |
| 1429 | - } | |
| 1430 | - } | |
| 1431 | - | |
| 1432 | - $field_id = $reference_field | |
| 1433 | - . '-' | |
| 1434 | - . $extra_field | |
| 1435 | - . '-content'; | |
| 1436 | - $template_form_fields[ $field_id ] = $extra_array; | |
| 1437 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' | |
| 1438 | - . $reference_field | |
| 1439 | - . '][content][' | |
| 1440 | - . $extra_field . ']'; | |
| 1441 | - $css_class = isset($extra_array['css_class']) | |
| 1442 | - ? $extra_array['css_class'] | |
| 1443 | - : ''; | |
| 1444 | - | |
| 1445 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) | |
| 1446 | - && in_array($extra_field, $v_fields, true) | |
| 1447 | - && ( | |
| 1448 | - is_array($validators[ $extra_field ]) | |
| 1449 | - && isset($validators[ $extra_field ]['msg']) | |
| 1450 | - ) | |
| 1451 | - ? 'validate-error ' . $css_class | |
| 1452 | - : $css_class; | |
| 1453 | - | |
| 1454 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) | |
| 1455 | - && isset($content[ $extra_field ]) | |
| 1456 | - ? $content[ $extra_field ] | |
| 1457 | - : ''; | |
| 1458 | - | |
| 1459 | - // do we have a validation error? if we do then let's use that value instead | |
| 1460 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ]) | |
| 1461 | - ? $validators[ $extra_field ]['value'] | |
| 1462 | - : $template_form_fields[ $field_id ]['value']; | |
| 1463 | - | |
| 1464 | - | |
| 1465 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; | |
| 1466 | - | |
| 1467 | - // shortcode selector | |
| 1468 | - $field_name_to_use = $extra_field === 'main' | |
| 1469 | - ? 'content' | |
| 1470 | - : $extra_field; | |
| 1471 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( | |
| 1472 | - $field_name_to_use, | |
| 1473 | - $field_id | |
| 1474 | - ); | |
| 1475 | - | |
| 1476 | -                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { | |
| 1477 | - // we want to decode the entities | |
| 1478 | - $template_form_fields[ $field_id ]['value'] = | |
| 1479 | - $template_form_fields[ $field_id ]['value']; | |
| 1480 | - } | |
| 1481 | - } | |
| 1482 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; | |
| 1483 | - $templatefield_templatename_id = $reference_field . '-name'; | |
| 1484 | - | |
| 1485 | - $template_form_fields[ $templatefield_MTP_id ] = [ | |
| 1486 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', | |
| 1487 | - 'label' => null, | |
| 1488 | - 'input' => 'hidden', | |
| 1489 | - 'type' => 'int', | |
| 1490 | - 'required' => false, | |
| 1491 | - 'validation' => false, | |
| 1492 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', | |
| 1493 | - 'css_class' => '', | |
| 1494 | - 'format' => '%d', | |
| 1495 | - 'db-col' => 'MTP_ID', | |
| 1496 | - ]; | |
| 1497 | - | |
| 1498 | - $template_form_fields[ $templatefield_templatename_id ] = [ | |
| 1499 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', | |
| 1500 | - 'label' => null, | |
| 1501 | - 'input' => 'hidden', | |
| 1502 | - 'type' => 'string', | |
| 1503 | - 'required' => false, | |
| 1504 | - 'validation' => true, | |
| 1505 | - 'value' => $reference_field, | |
| 1506 | - 'css_class' => '', | |
| 1507 | - 'format' => '%s', | |
| 1508 | - 'db-col' => 'MTP_template_field', | |
| 1509 | - ]; | |
| 1510 | - } | |
| 1511 | - continue; // skip the next stuff, we got the necessary fields here for this dataset. | |
| 1512 | -                } else { | |
| 1513 | - $field_id = $template_field . '-content'; | |
| 1514 | - $template_form_fields[ $field_id ] = $field_setup_array; | |
| 1515 | - $template_form_fields[ $field_id ]['name'] = | |
| 1516 | - 'MTP_template_fields[' . $template_field . '][content]'; | |
| 1517 | - $message_template = | |
| 1518 | - isset($message_templates[ $context ][ $template_field ]) | |
| 1519 | - ? $message_templates[ $context ][ $template_field ] | |
| 1520 | - : null; | |
| 1521 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) | |
| 1522 | - && is_array($message_templates[ $context ]) | |
| 1523 | - && $message_template instanceof EE_Message_Template | |
| 1524 | -                        ? $message_template->get('MTP_content') | |
| 1525 | - : ''; | |
| 1526 | - | |
| 1527 | - // do we have a validator error for this field? if we do then we'll use that value instead | |
| 1528 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ]) | |
| 1529 | - ? $validators[ $template_field ]['value'] | |
| 1530 | - : $template_form_fields[ $field_id ]['value']; | |
| 1531 | - | |
| 1532 | - | |
| 1533 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; | |
| 1534 | - $css_class = isset($field_setup_array['css_class']) | |
| 1535 | - ? $field_setup_array['css_class'] | |
| 1536 | - : ''; | |
| 1537 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) | |
| 1538 | - && in_array($template_field, $v_fields, true) | |
| 1539 | - && isset($validators[ $template_field ]['msg']) | |
| 1540 | - ? 'validate-error ' . $css_class | |
| 1541 | - : $css_class; | |
| 1542 | - | |
| 1543 | - // shortcode selector | |
| 1544 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( | |
| 1545 | - $template_field, | |
| 1546 | - $field_id | |
| 1547 | - ); | |
| 1548 | - } | |
| 1549 | - | |
| 1550 | - // k took care of content field(s) now let's take care of others. | |
| 1551 | - | |
| 1552 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; | |
| 1553 | - $templatefield_field_templatename_id = $template_field . '-name'; | |
| 1554 | - | |
| 1555 | - // foreach template field there are actually two form fields created | |
| 1556 | - $template_form_fields[ $templatefield_MTP_id ] = [ | |
| 1557 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', | |
| 1558 | - 'label' => null, | |
| 1559 | - 'input' => 'hidden', | |
| 1560 | - 'type' => 'int', | |
| 1561 | - 'required' => false, | |
| 1562 | - 'validation' => true, | |
| 1563 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', | |
| 1564 | - 'css_class' => '', | |
| 1565 | - 'format' => '%d', | |
| 1566 | - 'db-col' => 'MTP_ID', | |
| 1567 | - ]; | |
| 1568 | - | |
| 1569 | - $template_form_fields[ $templatefield_field_templatename_id ] = [ | |
| 1570 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', | |
| 1571 | - 'label' => null, | |
| 1572 | - 'input' => 'hidden', | |
| 1573 | - 'type' => 'string', | |
| 1574 | - 'required' => false, | |
| 1575 | - 'validation' => true, | |
| 1576 | - 'value' => $template_field, | |
| 1577 | - 'css_class' => '', | |
| 1578 | - 'format' => '%s', | |
| 1579 | - 'db-col' => 'MTP_template_field', | |
| 1580 | - ]; | |
| 1581 | - } | |
| 1582 | - | |
| 1583 | - // add other fields | |
| 1584 | - $template_form_fields['ee-msg-current-context'] = [ | |
| 1585 | - 'name' => 'MTP_context', | |
| 1586 | - 'label' => null, | |
| 1587 | - 'input' => 'hidden', | |
| 1588 | - 'type' => 'string', | |
| 1589 | - 'required' => false, | |
| 1590 | - 'validation' => true, | |
| 1591 | - 'value' => $context, | |
| 1592 | - 'css_class' => '', | |
| 1593 | - 'format' => '%s', | |
| 1594 | - 'db-col' => 'MTP_context', | |
| 1595 | - ]; | |
| 1596 | - | |
| 1597 | - $template_form_fields['ee-msg-grp-id'] = [ | |
| 1598 | - 'name' => 'GRP_ID', | |
| 1599 | - 'label' => null, | |
| 1600 | - 'input' => 'hidden', | |
| 1601 | - 'type' => 'int', | |
| 1602 | - 'required' => false, | |
| 1603 | - 'validation' => true, | |
| 1604 | - 'value' => $GRP_ID, | |
| 1605 | - 'css_class' => '', | |
| 1606 | - 'format' => '%d', | |
| 1607 | - 'db-col' => 'GRP_ID', | |
| 1608 | - ]; | |
| 1609 | - | |
| 1610 | - $template_form_fields['ee-msg-messenger'] = [ | |
| 1611 | - 'name' => 'MTP_messenger', | |
| 1612 | - 'label' => null, | |
| 1613 | - 'input' => 'hidden', | |
| 1614 | - 'type' => 'string', | |
| 1615 | - 'required' => false, | |
| 1616 | - 'validation' => true, | |
| 1617 | - 'value' => $message_template_group->messenger(), | |
| 1618 | - 'css_class' => '', | |
| 1619 | - 'format' => '%s', | |
| 1620 | - 'db-col' => 'MTP_messenger', | |
| 1621 | - ]; | |
| 1622 | - | |
| 1623 | - $template_form_fields['ee-msg-message-type'] = [ | |
| 1624 | - 'name' => 'MTP_message_type', | |
| 1625 | - 'label' => null, | |
| 1626 | - 'input' => 'hidden', | |
| 1627 | - 'type' => 'string', | |
| 1628 | - 'required' => false, | |
| 1629 | - 'validation' => true, | |
| 1630 | - 'value' => $message_template_group->message_type(), | |
| 1631 | - 'css_class' => '', | |
| 1632 | - 'format' => '%s', | |
| 1633 | - 'db-col' => 'MTP_message_type', | |
| 1634 | - ]; | |
| 1635 | - | |
| 1636 | - $sidebar_form_fields['ee-msg-is-global'] = [ | |
| 1637 | - 'name' => 'MTP_is_global', | |
| 1638 | -                'label'      => esc_html__('Global Template', 'event_espresso'), | |
| 1639 | - 'input' => 'hidden', | |
| 1640 | - 'type' => 'int', | |
| 1641 | - 'required' => false, | |
| 1642 | - 'validation' => true, | |
| 1643 | -                'value'      => $message_template_group->get('MTP_is_global'), | |
| 1644 | - 'css_class' => '', | |
| 1645 | - 'format' => '%d', | |
| 1646 | - 'db-col' => 'MTP_is_global', | |
| 1647 | - ]; | |
| 1648 | - | |
| 1649 | - $sidebar_form_fields['ee-msg-is-override'] = [ | |
| 1650 | - 'name' => 'MTP_is_override', | |
| 1651 | -                'label'      => esc_html__('Override all custom', 'event_espresso'), | |
| 1652 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', | |
| 1653 | - 'type' => 'int', | |
| 1654 | - 'required' => false, | |
| 1655 | - 'validation' => true, | |
| 1656 | -                'value'      => $message_template_group->get('MTP_is_override'), | |
| 1657 | - 'css_class' => '', | |
| 1658 | - 'format' => '%d', | |
| 1659 | - 'db-col' => 'MTP_is_override', | |
| 1660 | - ]; | |
| 1661 | - | |
| 1662 | - $sidebar_form_fields['ee-msg-is-active'] = [ | |
| 1663 | - 'name' => 'MTP_is_active', | |
| 1664 | -                'label'      => esc_html__('Active Template', 'event_espresso'), | |
| 1665 | - 'input' => 'hidden', | |
| 1666 | - 'type' => 'int', | |
| 1667 | - 'required' => false, | |
| 1668 | - 'validation' => true, | |
| 1669 | - 'value' => $message_template_group->is_active(), | |
| 1670 | - 'css_class' => '', | |
| 1671 | - 'format' => '%d', | |
| 1672 | - 'db-col' => 'MTP_is_active', | |
| 1673 | - ]; | |
| 1674 | - | |
| 1675 | - $sidebar_form_fields['ee-msg-deleted'] = [ | |
| 1676 | - 'name' => 'MTP_deleted', | |
| 1677 | - 'label' => null, | |
| 1678 | - 'input' => 'hidden', | |
| 1679 | - 'type' => 'int', | |
| 1680 | - 'required' => false, | |
| 1681 | - 'validation' => true, | |
| 1682 | -                'value'      => $message_template_group->get('MTP_deleted'), | |
| 1683 | - 'css_class' => '', | |
| 1684 | - 'format' => '%d', | |
| 1685 | - 'db-col' => 'MTP_deleted', | |
| 1686 | - ]; | |
| 1687 | - $sidebar_form_fields['ee-msg-author'] = [ | |
| 1688 | - 'name' => 'MTP_user_id', | |
| 1689 | -                'label'      => esc_html__('Author', 'event_espresso'), | |
| 1690 | - 'input' => 'hidden', | |
| 1691 | - 'type' => 'int', | |
| 1692 | - 'required' => false, | |
| 1693 | - 'validation' => false, | |
| 1694 | - 'value' => $message_template_group->user(), | |
| 1695 | - 'format' => '%d', | |
| 1696 | - 'db-col' => 'MTP_user_id', | |
| 1697 | - ]; | |
| 1698 | - | |
| 1699 | - $sidebar_form_fields['ee-msg-route'] = [ | |
| 1700 | - 'name' => 'action', | |
| 1701 | - 'input' => 'hidden', | |
| 1702 | - 'type' => 'string', | |
| 1703 | - 'value' => $action, | |
| 1704 | - ]; | |
| 1705 | - | |
| 1706 | - $sidebar_form_fields['ee-msg-id'] = [ | |
| 1707 | - 'name' => 'id', | |
| 1708 | - 'input' => 'hidden', | |
| 1709 | - 'type' => 'int', | |
| 1710 | - 'value' => $GRP_ID, | |
| 1711 | - ]; | |
| 1712 | - $sidebar_form_fields['ee-msg-evt-nonce'] = [ | |
| 1713 | - 'name' => $action . '_nonce', | |
| 1714 | - 'input' => 'hidden', | |
| 1715 | - 'type' => 'string', | |
| 1716 | - 'value' => wp_create_nonce($action . '_nonce'), | |
| 1717 | - ]; | |
| 1718 | - | |
| 1719 | -            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { | |
| 1720 | - $sidebar_form_fields['ee-msg-template-switch'] = [ | |
| 1721 | - 'name' => 'template_switch', | |
| 1722 | - 'input' => 'hidden', | |
| 1723 | - 'type' => 'int', | |
| 1724 | - 'value' => 1, | |
| 1725 | - ]; | |
| 1726 | - } | |
| 1727 | - | |
| 1728 | - | |
| 1729 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); | |
| 1730 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); | |
| 1731 | - } //end if ( !empty($template_field_structure) ) | |
| 1732 | - | |
| 1733 | - // set extra content for publish box | |
| 1734 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; | |
| 1735 | - $this->_set_publish_post_box_vars( | |
| 1736 | - 'id', | |
| 1737 | - $GRP_ID, | |
| 1738 | - false, | |
| 1739 | - add_query_arg( | |
| 1740 | - ['action' => 'global_mtps'], | |
| 1741 | - $this->_admin_base_url | |
| 1742 | - ) | |
| 1743 | - ); | |
| 1744 | - | |
| 1745 | - // add preview button | |
| 1746 | - $preview_url = parent::add_query_args_and_nonce( | |
| 1747 | - [ | |
| 1748 | - 'message_type' => $message_template_group->message_type(), | |
| 1749 | - 'messenger' => $message_template_group->messenger(), | |
| 1750 | - 'context' => $context, | |
| 1751 | - 'GRP_ID' => $GRP_ID, | |
| 1752 | - 'evt_id' => $EVT_ID, | |
| 1753 | - 'action' => 'preview_message', | |
| 1754 | - ], | |
| 1755 | - $this->_admin_base_url | |
| 1756 | - ); | |
| 1757 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' | |
| 1758 | -                          . esc_html__('Preview', 'event_espresso') | |
| 1759 | - . '</a>'; | |
| 1760 | - | |
| 1761 | - | |
| 1762 | - // setup context switcher | |
| 1763 | - $context_switcher_args = [ | |
| 1764 | - 'page' => 'espresso_messages', | |
| 1765 | - 'action' => 'edit_message_template', | |
| 1766 | - 'id' => $GRP_ID, | |
| 1767 | - 'evt_id' => $EVT_ID, | |
| 1768 | - 'context' => $context, | |
| 1769 | - 'extra' => $preview_button, | |
| 1770 | - ]; | |
| 1771 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); | |
| 1772 | - | |
| 1773 | - | |
| 1774 | - // main box | |
| 1775 | - $this->_template_args['template_fields'] = $template_fields; | |
| 1776 | - $this->_template_args['sidebar_box_id'] = 'details'; | |
| 1777 | - $this->_template_args['action'] = $action; | |
| 1778 | - $this->_template_args['context'] = $context; | |
| 1779 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; | |
| 1780 | - $this->_template_args['learn_more_about_message_templates_link'] = | |
| 1781 | - $this->_learn_more_about_message_templates_link(); | |
| 1782 | - | |
| 1783 | - | |
| 1784 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); | |
| 1785 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( | |
| 1786 | - $message_template_group, | |
| 1787 | - $context, | |
| 1788 | - $context_label | |
| 1789 | - ); | |
| 1790 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); | |
| 1791 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); | |
| 1792 | - | |
| 1793 | - $this->_template_path = $this->_template_args['GRP_ID'] | |
| 1794 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' | |
| 1795 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; | |
| 1796 | - | |
| 1797 | - // send along EE_Message_Template_Group object for further template use. | |
| 1798 | - $this->_template_args['MTP'] = $message_template_group; | |
| 1799 | - | |
| 1800 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( | |
| 1801 | - $this->_template_path, | |
| 1802 | - $this->_template_args, | |
| 1803 | - true | |
| 1804 | - ); | |
| 1805 | - | |
| 1806 | - | |
| 1807 | - // finally, let's set the admin_page title | |
| 1808 | -        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title); | |
| 1809 | - | |
| 1810 | - | |
| 1811 | - // we need to take care of setting the shortcodes property for use elsewhere. | |
| 1812 | - $this->_set_shortcodes(); | |
| 1813 | - | |
| 1814 | - | |
| 1815 | - // final template wrapper | |
| 1816 | - $this->display_admin_page_with_sidebar(); | |
| 1817 | - } | |
| 1818 | - | |
| 1819 | - | |
| 1820 | - public function filter_tinymce_init($mceInit, $editor_id) | |
| 1821 | -    { | |
| 1822 | - return $mceInit; | |
| 1823 | - } | |
| 1824 | - | |
| 1825 | - | |
| 1826 | - public function add_context_switcher() | |
| 1827 | -    { | |
| 1828 | - return $this->_context_switcher; | |
| 1829 | - } | |
| 1830 | - | |
| 1831 | - | |
| 1832 | - /** | |
| 1833 | - * Adds the activation/deactivation toggle for the message template context. | |
| 1834 | - * | |
| 1835 | - * @param EE_Message_Template_Group $message_template_group | |
| 1836 | - * @param string $context | |
| 1837 | - * @param string $context_label | |
| 1838 | - * @return string | |
| 1839 | - * @throws DomainException | |
| 1840 | - * @throws EE_Error | |
| 1841 | - * @throws InvalidIdentifierException | |
| 1842 | - */ | |
| 1843 | - protected function add_active_context_element( | |
| 1844 | - EE_Message_Template_Group $message_template_group, | |
| 1845 | - $context, | |
| 1846 | - $context_label | |
| 1847 | -    ) { | |
| 1848 | - $template_args = [ | |
| 1849 | - 'context' => $context, | |
| 1850 | -            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'), | |
| 1851 | - 'is_active' => $message_template_group->is_context_active($context), | |
| 1852 | - 'on_off_action' => $message_template_group->is_context_active($context) | |
| 1853 | - ? 'context-off' | |
| 1854 | - : 'context-on', | |
| 1855 | -            'context_label'             => str_replace(['(', ')'], '', $context_label), | |
| 1856 | - 'message_template_group_id' => $message_template_group->ID(), | |
| 1857 | - ]; | |
| 1858 | - return EEH_Template::display_template( | |
| 1859 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', | |
| 1860 | - $template_args, | |
| 1861 | - true | |
| 1862 | - ); | |
| 1863 | - } | |
| 1864 | - | |
| 1865 | - | |
| 1866 | - /** | |
| 1867 | - * Ajax callback for `toggle_context_template` ajax action. | |
| 1868 | - * Handles toggling the message context on or off. | |
| 1869 | - * | |
| 1870 | - * @throws EE_Error | |
| 1871 | - * @throws InvalidArgumentException | |
| 1872 | - * @throws InvalidDataTypeException | |
| 1873 | - * @throws InvalidIdentifierException | |
| 1874 | - * @throws InvalidInterfaceException | |
| 1875 | - */ | |
| 1876 | - public function toggle_context_template() | |
| 1877 | -    { | |
| 1878 | - $success = true; | |
| 1879 | - // check for required data | |
| 1880 | - if ( | |
| 1881 | - ! isset( | |
| 1882 | - $this->_req_data['message_template_group_id'], | |
| 1883 | - $this->_req_data['context'], | |
| 1884 | - $this->_req_data['status'] | |
| 1885 | - ) | |
| 1886 | -        ) { | |
| 1887 | - EE_Error::add_error( | |
| 1888 | -                esc_html__('Required data for doing this action is not available.', 'event_espresso'), | |
| 1889 | - __FILE__, | |
| 1890 | - __FUNCTION__, | |
| 1891 | - __LINE__ | |
| 1892 | - ); | |
| 1893 | - $success = false; | |
| 1894 | - } | |
| 1895 | - | |
| 1896 | - $nonce = isset($this->_req_data['toggle_context_nonce']) | |
| 1897 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) | |
| 1898 | - : ''; | |
| 1899 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; | |
| 1900 | - $this->_verify_nonce($nonce, $nonce_ref); | |
| 1901 | - $status = $this->_req_data['status']; | |
| 1902 | -        if ($status !== 'off' && $status !== 'on') { | |
| 1903 | - EE_Error::add_error( | |
| 1904 | - sprintf( | |
| 1905 | -                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | |
| 1906 | - $this->_req_data['status'] | |
| 1907 | - ), | |
| 1908 | - __FILE__, | |
| 1909 | - __FUNCTION__, | |
| 1910 | - __LINE__ | |
| 1911 | - ); | |
| 1912 | - $success = false; | |
| 1913 | - } | |
| 1914 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( | |
| 1915 | - $this->_req_data['message_template_group_id'] | |
| 1916 | - ); | |
| 1917 | -        if (! $message_template_group instanceof EE_Message_Template_Group) { | |
| 1918 | - EE_Error::add_error( | |
| 1919 | - sprintf( | |
| 1920 | - esc_html__( | |
| 1921 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', | |
| 1922 | - 'event_espresso' | |
| 1923 | - ), | |
| 1924 | - $this->_req_data['message_template_group_id'], | |
| 1925 | - 'EE_Message_Template_Group' | |
| 1926 | - ), | |
| 1927 | - __FILE__, | |
| 1928 | - __FUNCTION__, | |
| 1929 | - __LINE__ | |
| 1930 | - ); | |
| 1931 | - $success = false; | |
| 1932 | - } | |
| 1933 | -        if ($success) { | |
| 1934 | - $success = $status === 'off' | |
| 1935 | - ? $message_template_group->deactivate_context($this->_req_data['context']) | |
| 1936 | - : $message_template_group->activate_context($this->_req_data['context']); | |
| 1937 | - } | |
| 1938 | - $this->_template_args['success'] = $success; | |
| 1939 | - $this->_return_json(); | |
| 1940 | - } | |
| 1941 | - | |
| 1942 | - | |
| 1943 | - public function _add_form_element_before() | |
| 1944 | -    { | |
| 1945 | - return '<form method="post" action="' | |
| 1946 | - . $this->_template_args['edit_message_template_form_url'] | |
| 1947 | - . '" id="ee-msg-edit-frm">'; | |
| 1948 | - } | |
| 1949 | - | |
| 1950 | - | |
| 1951 | - public function _add_form_element_after() | |
| 1952 | -    { | |
| 1953 | - return '</form>'; | |
| 1954 | - } | |
| 1955 | - | |
| 1956 | - | |
| 1957 | - /** | |
| 1958 | - * This executes switching the template pack for a message template. | |
| 1959 | - * | |
| 1960 | - * @throws EE_Error | |
| 1961 | - * @throws InvalidDataTypeException | |
| 1962 | - * @throws InvalidInterfaceException | |
| 1963 | - * @throws InvalidArgumentException | |
| 1964 | - * @throws ReflectionException | |
| 1965 | - * @since 4.5.0 | |
| 1966 | - */ | |
| 1967 | - public function switch_template_pack() | |
| 1968 | -    { | |
| 1969 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; | |
| 1970 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; | |
| 1971 | - | |
| 1972 | - // verify we have needed values. | |
| 1973 | -        if (empty($GRP_ID) || empty($template_pack)) { | |
| 1974 | - $this->_template_args['error'] = true; | |
| 1975 | - EE_Error::add_error( | |
| 1976 | -                esc_html__('The required date for switching templates is not available.', 'event_espresso'), | |
| 1977 | - __FILE__, | |
| 1978 | - __FUNCTION__, | |
| 1979 | - __LINE__ | |
| 1980 | - ); | |
| 1981 | -        } else { | |
| 1982 | - // get template, set the new template_pack and then reset to default | |
| 1983 | - /** @type EE_Message_Template_Group $message_template_group */ | |
| 1984 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); | |
| 1985 | - | |
| 1986 | - $message_template_group->set_template_pack_name($template_pack); | |
| 1987 | - $this->_req_data['msgr'] = $message_template_group->messenger(); | |
| 1988 | - $this->_req_data['mt'] = $message_template_group->message_type(); | |
| 1989 | - | |
| 1990 | - $query_args = $this->_reset_to_default_template(); | |
| 1991 | - | |
| 1992 | -            if (empty($query_args['id'])) { | |
| 1993 | - EE_Error::add_error( | |
| 1994 | - esc_html__( | |
| 1995 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', | |
| 1996 | - 'event_espresso' | |
| 1997 | - ), | |
| 1998 | - __FILE__, | |
| 1999 | - __FUNCTION__, | |
| 2000 | - __LINE__ | |
| 2001 | - ); | |
| 2002 | - $this->_template_args['error'] = true; | |
| 2003 | -            } else { | |
| 2004 | - $template_label = $message_template_group->get_template_pack()->label; | |
| 2005 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); | |
| 2006 | - EE_Error::add_success( | |
| 2007 | - sprintf( | |
| 2008 | - esc_html__( | |
| 2009 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', | |
| 2010 | - 'event_espresso' | |
| 2011 | - ), | |
| 2012 | - $template_label, | |
| 2013 | - $template_pack_labels->template_pack | |
| 2014 | - ) | |
| 2015 | - ); | |
| 2016 | - // generate the redirect url for js. | |
| 2017 | - $url = self::add_query_args_and_nonce( | |
| 2018 | - $query_args, | |
| 2019 | - $this->_admin_base_url | |
| 2020 | - ); | |
| 2021 | - $this->_template_args['data']['redirect_url'] = $url; | |
| 2022 | - $this->_template_args['success'] = true; | |
| 2023 | - } | |
| 2024 | - | |
| 2025 | - $this->_return_json(); | |
| 2026 | - } | |
| 2027 | - } | |
| 2028 | - | |
| 2029 | - | |
| 2030 | - /** | |
| 2031 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if | |
| 2032 | - * they want. | |
| 2033 | - * | |
| 2034 | - * @access protected | |
| 2035 | - * @return array|null | |
| 2036 | - * @throws EE_Error | |
| 2037 | - * @throws InvalidArgumentException | |
| 2038 | - * @throws InvalidDataTypeException | |
| 2039 | - * @throws InvalidInterfaceException | |
| 2040 | - */ | |
| 2041 | - protected function _reset_to_default_template() | |
| 2042 | -    { | |
| 2043 | - | |
| 2044 | - $templates = []; | |
| 2045 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; | |
| 2046 | - // we need to make sure we've got the info we need. | |
| 2047 | -        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { | |
| 2048 | - EE_Error::add_error( | |
| 2049 | - esc_html__( | |
| 2050 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', | |
| 2051 | - 'event_espresso' | |
| 2052 | - ), | |
| 2053 | - __FILE__, | |
| 2054 | - __FUNCTION__, | |
| 2055 | - __LINE__ | |
| 2056 | - ); | |
| 2057 | - } | |
| 2058 | - | |
| 2059 | - // all templates will be reset to whatever the defaults are | |
| 2060 | - // for the global template matching the messenger and message type. | |
| 2061 | - $success = ! empty($GRP_ID) ? true : false; | |
| 2062 | - | |
| 2063 | -        if ($success) { | |
| 2064 | - // let's first determine if the incoming template is a global template, | |
| 2065 | - // if it isn't then we need to get the global template matching messenger and message type. | |
| 2066 | - // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); | |
| 2067 | - | |
| 2068 | - | |
| 2069 | - // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. | |
| 2070 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); | |
| 2071 | - | |
| 2072 | -            if ($success) { | |
| 2073 | - // if successfully deleted, lets generate the new ones. | |
| 2074 | - // Note. We set GLOBAL to true, because resets on ANY template | |
| 2075 | - // will use the related global template defaults for regeneration. | |
| 2076 | - // This means that if a custom template is reset it resets to whatever the related global template is. | |
| 2077 | - // HOWEVER, we DO keep the template pack and template variation set | |
| 2078 | - // for the current custom template when resetting. | |
| 2079 | - $templates = $this->_generate_new_templates( | |
| 2080 | - $this->_req_data['msgr'], | |
| 2081 | - $this->_req_data['mt'], | |
| 2082 | - $GRP_ID, | |
| 2083 | - true | |
| 2084 | - ); | |
| 2085 | - } | |
| 2086 | - } | |
| 2087 | - | |
| 2088 | - // any error messages? | |
| 2089 | -        if (! $success) { | |
| 2090 | - EE_Error::add_error( | |
| 2091 | - esc_html__( | |
| 2092 | - 'Something went wrong with deleting existing templates. Unable to reset to default', | |
| 2093 | - 'event_espresso' | |
| 2094 | - ), | |
| 2095 | - __FILE__, | |
| 2096 | - __FUNCTION__, | |
| 2097 | - __LINE__ | |
| 2098 | - ); | |
| 2099 | - } | |
| 2100 | - | |
| 2101 | - // all good, let's add a success message! | |
| 2102 | -        if ($success && ! empty($templates)) { | |
| 2103 | - // the info for the template we generated is the first element in the returned array | |
| 2104 | - // $templates = $templates[0]; | |
| 2105 | - EE_Error::overwrite_success(); | |
| 2106 | -            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso')); | |
| 2107 | - } | |
| 2108 | - | |
| 2109 | - | |
| 2110 | - $query_args = [ | |
| 2111 | - 'id' => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null, | |
| 2112 | - 'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null, | |
| 2113 | - 'action' => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps', | |
| 2114 | - ]; | |
| 2115 | - | |
| 2116 | - // if called via ajax then we return query args otherwise redirect | |
| 2117 | -        if (defined('DOING_AJAX') && DOING_AJAX) { | |
| 2118 | - return $query_args; | |
| 2119 | -        } else { | |
| 2120 | - $this->_redirect_after_action(false, '', '', $query_args, true); | |
| 2121 | - | |
| 2122 | - return null; | |
| 2123 | - } | |
| 2124 | - } | |
| 2125 | - | |
| 2126 | - | |
| 2127 | - /** | |
| 2128 | - * Retrieve and set the message preview for display. | |
| 2129 | - * | |
| 2130 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. | |
| 2131 | - * @return string | |
| 2132 | - * @throws ReflectionException | |
| 2133 | - * @throws EE_Error | |
| 2134 | - * @throws InvalidArgumentException | |
| 2135 | - * @throws InvalidDataTypeException | |
| 2136 | - * @throws InvalidInterfaceException | |
| 2137 | - */ | |
| 2138 | - public function _preview_message($send = false) | |
| 2139 | -    { | |
| 2140 | - // first make sure we've got the necessary parameters | |
| 2141 | - if ( | |
| 2142 | - ! ( | |
| 2143 | - $this->_req_data['message_type'] | |
| 2144 | - && $this->_req_data['messenger'] | |
| 2145 | - && $this->_req_data['GRP_ID'] | |
| 2146 | - ) | |
| 2147 | -        ) { | |
| 2148 | - EE_Error::add_error( | |
| 2149 | -                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), | |
| 2150 | - __FILE__, | |
| 2151 | - __FUNCTION__, | |
| 2152 | - __LINE__ | |
| 2153 | - ); | |
| 2154 | - } | |
| 2155 | - | |
| 2156 | - // get the preview! | |
| 2157 | - $preview = EED_Messages::preview_message( | |
| 2158 | - $this->_req_data['message_type'], | |
| 2159 | - $this->_req_data['context'], | |
| 2160 | - $this->_req_data['messenger'], | |
| 2161 | - $send | |
| 2162 | - ); | |
| 2163 | - | |
| 2164 | -        if ($send) { | |
| 2165 | - return $preview; | |
| 2166 | - } | |
| 2167 | - | |
| 2168 | - // if we have an evt_id set on the request, use it. | |
| 2169 | - $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) | |
| 2170 | - ? absint($this->_req_data['evt_id']) | |
| 2171 | - : false; | |
| 2172 | - | |
| 2173 | - // let's add a button to go back to the edit view | |
| 2174 | - $query_args = [ | |
| 2175 | - 'id' => $this->_req_data['GRP_ID'], | |
| 2176 | - 'evt_id' => $EVT_ID, | |
| 2177 | - 'context' => $this->_req_data['context'], | |
| 2178 | - 'action' => 'edit_message_template', | |
| 2179 | - ]; | |
| 2180 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); | |
| 2181 | - $preview_button = '<a href="' | |
| 2182 | - . $go_back_url | |
| 2183 | - . '" class="button-secondary messages-preview-go-back-button">' | |
| 2184 | -                                  . esc_html__('Go Back to Edit', 'event_espresso') | |
| 2185 | - . '</a>'; | |
| 2186 | - $message_types = $this->get_installed_message_types(); | |
| 2187 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); | |
| 2188 | - $active_messenger_label = $active_messenger instanceof EE_messenger | |
| 2189 | - ? ucwords($active_messenger->label['singular']) | |
| 2190 | -            : esc_html__('Unknown Messenger', 'event_espresso'); | |
| 2191 | - // let's provide a helpful title for context | |
| 2192 | - $preview_title = sprintf( | |
| 2193 | -            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), | |
| 2194 | - $active_messenger_label, | |
| 2195 | - ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular']) | |
| 2196 | - ); | |
| 2197 | -        if (empty($preview)) { | |
| 2198 | - $this->noEventsErrorMessage(); | |
| 2199 | - } | |
| 2200 | - // setup display of preview. | |
| 2201 | - $this->_admin_page_title = $preview_title; | |
| 2202 | - $this->_template_args['admin_page_title'] = $preview_title; | |
| 2203 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; | |
| 2204 | - $this->_template_args['data']['force_json'] = true; | |
| 2205 | - | |
| 2206 | - return ''; | |
| 2207 | - } | |
| 2208 | - | |
| 2209 | - | |
| 2210 | - /** | |
| 2211 | - * Used to set an error if there are no events available for generating a preview/test send. | |
| 2212 | - * | |
| 2213 | - * @param bool $test_send Whether the error should be generated for the context of a test send. | |
| 2214 | - */ | |
| 2215 | - protected function noEventsErrorMessage($test_send = false) | |
| 2216 | -    { | |
| 2217 | - $events_url = parent::add_query_args_and_nonce( | |
| 2218 | - [ | |
| 2219 | - 'action' => 'default', | |
| 2220 | - 'page' => 'espresso_events', | |
| 2221 | - ], | |
| 2222 | -            admin_url('admin.php') | |
| 2223 | - ); | |
| 2224 | - $message = $test_send | |
| 2225 | - ? esc_html__( | |
| 2226 | - 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!', | |
| 2227 | - 'event_espresso' | |
| 2228 | - ) | |
| 2229 | - : esc_html__( | |
| 2230 | - 'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!', | |
| 2231 | - 'event_espresso' | |
| 2232 | - ); | |
| 2233 | - | |
| 2234 | - EE_Error::add_attention( | |
| 2235 | - sprintf( | |
| 2236 | - $message, | |
| 2237 | -                "<a href='{$events_url}'>", | |
| 2238 | - '</a>' | |
| 2239 | - ) | |
| 2240 | - ); | |
| 2241 | - } | |
| 2242 | - | |
| 2243 | - | |
| 2244 | - /** | |
| 2245 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it | |
| 2246 | - * gets called automatically. | |
| 2247 | - * | |
| 2248 | - * @return string | |
| 2249 | - * @since 4.5.0 | |
| 2250 | - * | |
| 2251 | - */ | |
| 2252 | - protected function _display_preview_message() | |
| 2253 | -    { | |
| 2254 | - $this->display_admin_page_with_no_sidebar(); | |
| 2255 | - } | |
| 2256 | - | |
| 2257 | - | |
| 2258 | - /** | |
| 2259 | - * registers metaboxes that should show up on the "edit_message_template" page | |
| 2260 | - * | |
| 2261 | - * @access protected | |
| 2262 | - * @return void | |
| 2263 | - */ | |
| 2264 | - protected function _register_edit_meta_boxes() | |
| 2265 | -    { | |
| 2266 | - add_meta_box( | |
| 2267 | - 'mtp_valid_shortcodes', | |
| 2268 | -            esc_html__('Valid Shortcodes', 'event_espresso'), | |
| 2269 | - [$this, 'shortcode_meta_box'], | |
| 2270 | - $this->_current_screen->id, | |
| 2271 | - 'side', | |
| 2272 | - 'default' | |
| 2273 | - ); | |
| 2274 | - add_meta_box( | |
| 2275 | - 'mtp_extra_actions', | |
| 2276 | -            esc_html__('Extra Actions', 'event_espresso'), | |
| 2277 | - [$this, 'extra_actions_meta_box'], | |
| 2278 | - $this->_current_screen->id, | |
| 2279 | - 'side', | |
| 2280 | - 'high' | |
| 2281 | - ); | |
| 2282 | - add_meta_box( | |
| 2283 | - 'mtp_templates', | |
| 2284 | -            esc_html__('Template Styles', 'event_espresso'), | |
| 2285 | - [$this, 'template_pack_meta_box'], | |
| 2286 | - $this->_current_screen->id, | |
| 2287 | - 'side', | |
| 2288 | - 'high' | |
| 2289 | - ); | |
| 2290 | - } | |
| 2291 | - | |
| 2292 | - | |
| 2293 | - /** | |
| 2294 | - * metabox content for all template pack and variation selection. | |
| 2295 | - * | |
| 2296 | - * @return string | |
| 2297 | - * @throws DomainException | |
| 2298 | - * @throws EE_Error | |
| 2299 | - * @throws InvalidArgumentException | |
| 2300 | - * @throws ReflectionException | |
| 2301 | - * @throws InvalidDataTypeException | |
| 2302 | - * @throws InvalidInterfaceException | |
| 2303 | - * @since 4.5.0 | |
| 2304 | - */ | |
| 2305 | - public function template_pack_meta_box() | |
| 2306 | -    { | |
| 2307 | - $this->_set_message_template_group(); | |
| 2308 | - | |
| 2309 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); | |
| 2310 | - | |
| 2311 | - $tp_select_values = []; | |
| 2312 | - | |
| 2313 | -        foreach ($tp_collection as $tp) { | |
| 2314 | - // only include template packs that support this messenger and message type! | |
| 2315 | - $supports = $tp->get_supports(); | |
| 2316 | - if ( | |
| 2317 | - ! isset($supports[ $this->_message_template_group->messenger() ]) | |
| 2318 | - || ! in_array( | |
| 2319 | - $this->_message_template_group->message_type(), | |
| 2320 | - $supports[ $this->_message_template_group->messenger() ], | |
| 2321 | - true | |
| 2322 | - ) | |
| 2323 | -            ) { | |
| 2324 | - // not supported | |
| 2325 | - continue; | |
| 2326 | - } | |
| 2327 | - | |
| 2328 | - $tp_select_values[] = [ | |
| 2329 | - 'text' => $tp->label, | |
| 2330 | - 'id' => $tp->dbref, | |
| 2331 | - ]; | |
| 2332 | - } | |
| 2333 | - | |
| 2334 | - // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by | |
| 2335 | - // the default template pack. This still allows for the odd template pack to override. | |
| 2336 | -        if (empty($tp_select_values)) { | |
| 2337 | - $tp_select_values[] = [ | |
| 2338 | -                'text' => esc_html__('Default', 'event_espresso'), | |
| 2339 | - 'id' => 'default', | |
| 2340 | - ]; | |
| 2341 | - } | |
| 2342 | - | |
| 2343 | - // setup variation select values for the currently selected template. | |
| 2344 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( | |
| 2345 | - $this->_message_template_group->messenger(), | |
| 2346 | - $this->_message_template_group->message_type() | |
| 2347 | - ); | |
| 2348 | - $variations_select_values = []; | |
| 2349 | -        foreach ($variations as $variation => $label) { | |
| 2350 | - $variations_select_values[] = [ | |
| 2351 | - 'text' => $label, | |
| 2352 | - 'id' => $variation, | |
| 2353 | - ]; | |
| 2354 | - } | |
| 2355 | - | |
| 2356 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); | |
| 2357 | - | |
| 2358 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( | |
| 2359 | - 'MTP_template_pack', | |
| 2360 | - $tp_select_values, | |
| 2361 | - $this->_message_template_group->get_template_pack_name() | |
| 2362 | - ); | |
| 2363 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( | |
| 2364 | - 'MTP_template_variation', | |
| 2365 | - $variations_select_values, | |
| 2366 | - $this->_message_template_group->get_template_pack_variation() | |
| 2367 | - ); | |
| 2368 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; | |
| 2369 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; | |
| 2370 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; | |
| 2371 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; | |
| 2372 | - | |
| 2373 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; | |
| 2374 | - | |
| 2375 | - EEH_Template::display_template($template, $template_args); | |
| 2376 | - } | |
| 2377 | - | |
| 2378 | - | |
| 2379 | - /** | |
| 2380 | - * This meta box holds any extra actions related to Message Templates | |
| 2381 | - * For now, this includes Resetting templates to defaults and sending a test email. | |
| 2382 | - * | |
| 2383 | - * @access public | |
| 2384 | - * @return void | |
| 2385 | - * @throws EE_Error | |
| 2386 | - */ | |
| 2387 | - public function extra_actions_meta_box() | |
| 2388 | -    { | |
| 2389 | - $template_form_fields = []; | |
| 2390 | - | |
| 2391 | - $extra_args = [ | |
| 2392 | - 'msgr' => $this->_message_template_group->messenger(), | |
| 2393 | - 'mt' => $this->_message_template_group->message_type(), | |
| 2394 | - 'GRP_ID' => $this->_message_template_group->GRP_ID(), | |
| 2395 | - ]; | |
| 2396 | - // first we need to see if there are any fields | |
| 2397 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); | |
| 2398 | - | |
| 2399 | -        if (! empty($fields)) { | |
| 2400 | - // yup there be fields | |
| 2401 | -            foreach ($fields as $field => $config) { | |
| 2402 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; | |
| 2403 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); | |
| 2404 | - $default = isset($config['default']) ? $config['default'] : ''; | |
| 2405 | - $default = isset($config['value']) ? $config['value'] : $default; | |
| 2406 | - | |
| 2407 | - // if type is hidden and the value is empty | |
| 2408 | - // something may have gone wrong so let's correct with the defaults | |
| 2409 | - $fix = $config['input'] === 'hidden' | |
| 2410 | - && isset($existing[ $field ]) | |
| 2411 | - && empty($existing[ $field ]) | |
| 2412 | - ? $default | |
| 2413 | - : ''; | |
| 2414 | - $existing[ $field ] = isset($existing[ $field ]) && empty($fix) | |
| 2415 | - ? $existing[ $field ] | |
| 2416 | - : $fix; | |
| 2417 | - | |
| 2418 | - $template_form_fields[ $field_id ] = [ | |
| 2419 | - 'name' => 'test_settings_fld[' . $field . ']', | |
| 2420 | - 'label' => $config['label'], | |
| 2421 | - 'input' => $config['input'], | |
| 2422 | - 'type' => $config['type'], | |
| 2423 | - 'required' => $config['required'], | |
| 2424 | - 'validation' => $config['validation'], | |
| 2425 | - 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default, | |
| 2426 | - 'css_class' => $config['css_class'], | |
| 2427 | - 'options' => isset($config['options']) ? $config['options'] : [], | |
| 2428 | - 'default' => $default, | |
| 2429 | - 'format' => $config['format'], | |
| 2430 | - ]; | |
| 2431 | - } | |
| 2432 | - } | |
| 2433 | - | |
| 2434 | - $test_settings_html = ! empty($template_form_fields) | |
| 2435 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') | |
| 2436 | - : ''; | |
| 2437 | - | |
| 2438 | - // print out $test_settings_fields | |
| 2439 | -        if (! empty($test_settings_html)) { | |
| 2440 | - $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" '; | |
| 2441 | - $test_settings_html .= 'name="test_button" value="'; | |
| 2442 | -            $test_settings_html .= esc_html__('Test Send', 'event_espresso'); | |
| 2443 | - $test_settings_html .= '" /><div style="clear:both"></div>'; | |
| 2444 | - } | |
| 2445 | - | |
| 2446 | - // and button | |
| 2447 | - $test_settings_html .= '<p>'; | |
| 2448 | -        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso'); | |
| 2449 | - $test_settings_html .= '</p>'; | |
| 2450 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; | |
| 2451 | - $test_settings_html .= $this->get_action_link_or_button( | |
| 2452 | - 'reset_to_default', | |
| 2453 | - 'reset', | |
| 2454 | - $extra_args, | |
| 2455 | - 'button-primary reset-default-button' | |
| 2456 | - ); | |
| 2457 | - $test_settings_html .= '</div><div style="clear:both"></div>'; | |
| 2458 | - echo $test_settings_html; // already escaped | |
| 2459 | - } | |
| 2460 | - | |
| 2461 | - | |
| 2462 | - /** | |
| 2463 | - * This returns the shortcode selector skeleton for a given context and field. | |
| 2464 | - * | |
| 2465 | - * @param string $field The name of the field retrieving shortcodes for. | |
| 2466 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. | |
| 2467 | - * @return string | |
| 2468 | - * @throws DomainException | |
| 2469 | - * @throws EE_Error | |
| 2470 | - * @throws InvalidArgumentException | |
| 2471 | - * @throws ReflectionException | |
| 2472 | - * @throws InvalidDataTypeException | |
| 2473 | - * @throws InvalidInterfaceException | |
| 2474 | - * @since 4.9.rc.000 | |
| 2475 | - */ | |
| 2476 | - protected function _get_shortcode_selector($field, $linked_input_id) | |
| 2477 | -    { | |
| 2478 | - $template_args = [ | |
| 2479 | - 'shortcodes' => $this->_get_shortcodes([$field], true), | |
| 2480 | - 'fieldname' => $field, | |
| 2481 | - 'linked_input_id' => $linked_input_id, | |
| 2482 | - ]; | |
| 2483 | - | |
| 2484 | - return EEH_Template::display_template( | |
| 2485 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', | |
| 2486 | - $template_args, | |
| 2487 | - true | |
| 2488 | - ); | |
| 2489 | - } | |
| 2490 | - | |
| 2491 | - | |
| 2492 | - /** | |
| 2493 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template | |
| 2494 | - * page) | |
| 2495 | - * | |
| 2496 | - * @access public | |
| 2497 | - * @return void | |
| 2498 | - * @throws EE_Error | |
| 2499 | - * @throws InvalidArgumentException | |
| 2500 | - * @throws ReflectionException | |
| 2501 | - * @throws InvalidDataTypeException | |
| 2502 | - * @throws InvalidInterfaceException | |
| 2503 | - */ | |
| 2504 | - public function shortcode_meta_box() | |
| 2505 | -    { | |
| 2506 | - $shortcodes = $this->_get_shortcodes([], false); | |
| 2507 | - // just make sure the shortcodes property is set | |
| 2508 | - // $messenger = $this->_message_template_group->messenger_obj(); | |
| 2509 | - // now let's set the content depending on the status of the shortcodes array | |
| 2510 | -        if (empty($shortcodes)) { | |
| 2511 | -            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; | |
| 2512 | - return; | |
| 2513 | - } | |
| 2514 | - ?> | |
| 25 | + /** | |
| 26 | + * @type string $_active_message_type_name | |
| 27 | + */ | |
| 28 | + protected $_active_message_type_name = ''; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @type EE_messenger $_active_messenger | |
| 32 | + */ | |
| 33 | + protected $_active_messenger; | |
| 34 | + | |
| 35 | + protected $_activate_state; | |
| 36 | + | |
| 37 | + protected $_activate_meta_box_type; | |
| 38 | + | |
| 39 | + protected $_current_message_meta_box; | |
| 40 | + | |
| 41 | + protected $_current_message_meta_box_object; | |
| 42 | + | |
| 43 | + protected $_context_switcher; | |
| 44 | + | |
| 45 | + protected $_shortcodes = []; | |
| 46 | + | |
| 47 | + protected $_active_messengers = []; | |
| 48 | + | |
| 49 | + protected $_active_message_types = []; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var EE_Message_Template_Group $_message_template_group | |
| 53 | + */ | |
| 54 | + protected $_message_template_group; | |
| 55 | + | |
| 56 | + protected $_m_mt_settings = []; | |
| 57 | + | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. | |
| 61 | + * IF there is no group then it gets automatically set to the Default template pack. | |
| 62 | + * | |
| 63 | + * @since 4.5.0 | |
| 64 | + * | |
| 65 | + * @var EE_Messages_Template_Pack | |
| 66 | + */ | |
| 67 | + protected $_template_pack; | |
| 68 | + | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the | |
| 72 | + * group is. If there is no group then it automatically gets set to default. | |
| 73 | + * | |
| 74 | + * @since 4.5.0 | |
| 75 | + * | |
| 76 | + * @var string | |
| 77 | + */ | |
| 78 | + protected $_variation; | |
| 79 | + | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @param bool $routing | |
| 83 | + * @throws EE_Error | |
| 84 | + */ | |
| 85 | + public function __construct($routing = true) | |
| 86 | +	{ | |
| 87 | + // make sure messages autoloader is running | |
| 88 | + EED_Messages::set_autoloaders(); | |
| 89 | + parent::__construct($routing); | |
| 90 | + } | |
| 91 | + | |
| 92 | + | |
| 93 | + protected function _init_page_props() | |
| 94 | +	{ | |
| 95 | + $this->page_slug = EE_MSG_PG_SLUG; | |
| 96 | +		$this->page_label       = esc_html__('Messages Settings', 'event_espresso'); | |
| 97 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; | |
| 98 | + $this->_admin_base_path = EE_MSG_ADMIN; | |
| 99 | + | |
| 100 | + $this->_activate_state = isset($this->_req_data['activate_state']) | |
| 101 | + ? (array) $this->_req_data['activate_state'] | |
| 102 | + : []; | |
| 103 | + | |
| 104 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; | |
| 105 | + $this->_load_message_resource_manager(); | |
| 106 | + } | |
| 107 | + | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) | |
| 111 | + * | |
| 112 | + * @throws EE_Error | |
| 113 | + * @throws InvalidDataTypeException | |
| 114 | + * @throws InvalidInterfaceException | |
| 115 | + * @throws InvalidArgumentException | |
| 116 | + * @throws ReflectionException | |
| 117 | + */ | |
| 118 | + protected function _load_message_resource_manager() | |
| 119 | +	{ | |
| 120 | +		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | |
| 121 | + } | |
| 122 | + | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * @return array | |
| 126 | + * @throws EE_Error | |
| 127 | + * @throws InvalidArgumentException | |
| 128 | + * @throws InvalidDataTypeException | |
| 129 | + * @throws InvalidInterfaceException | |
| 130 | + * @deprecated 4.9.9.rc.014 | |
| 131 | + */ | |
| 132 | + public function get_messengers_for_list_table() | |
| 133 | +	{ | |
| 134 | + EE_Error::doing_it_wrong( | |
| 135 | + __METHOD__, | |
| 136 | + sprintf( | |
| 137 | + esc_html__( | |
| 138 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', | |
| 139 | + 'event_espresso' | |
| 140 | + ), | |
| 141 | + 'Messages_Admin_Page::get_messengers_select_input()' | |
| 142 | + ), | |
| 143 | + '4.9.9.rc.014' | |
| 144 | + ); | |
| 145 | + | |
| 146 | + $m_values = []; | |
| 147 | + $active_messengers = EEM_Message::instance()->get_all(['group_by' => 'MSG_messenger']); | |
| 148 | + // setup messengers for selects | |
| 149 | + $i = 1; | |
| 150 | +		foreach ($active_messengers as $active_messenger) { | |
| 151 | +			if ($active_messenger instanceof EE_Message) { | |
| 152 | + $m_values[ $i ]['id'] = $active_messenger->messenger(); | |
| 153 | + $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label()); | |
| 154 | + $i++; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + | |
| 158 | + return $m_values; | |
| 159 | + } | |
| 160 | + | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * @return array | |
| 164 | + * @throws EE_Error | |
| 165 | + * @throws InvalidArgumentException | |
| 166 | + * @throws InvalidDataTypeException | |
| 167 | + * @throws InvalidInterfaceException | |
| 168 | + * @deprecated 4.9.9.rc.014 | |
| 169 | + */ | |
| 170 | + public function get_message_types_for_list_table() | |
| 171 | +	{ | |
| 172 | + EE_Error::doing_it_wrong( | |
| 173 | + __METHOD__, | |
| 174 | + sprintf( | |
| 175 | + esc_html__( | |
| 176 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', | |
| 177 | + 'event_espresso' | |
| 178 | + ), | |
| 179 | + 'Messages_Admin_Page::get_message_types_select_input()' | |
| 180 | + ), | |
| 181 | + '4.9.9.rc.014' | |
| 182 | + ); | |
| 183 | + | |
| 184 | + $mt_values = []; | |
| 185 | + $active_messages = EEM_Message::instance()->get_all(['group_by' => 'MSG_message_type']); | |
| 186 | + $i = 1; | |
| 187 | +		foreach ($active_messages as $active_message) { | |
| 188 | +			if ($active_message instanceof EE_Message) { | |
| 189 | + $mt_values[ $i ]['id'] = $active_message->message_type(); | |
| 190 | + $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label()); | |
| 191 | + $i++; | |
| 192 | + } | |
| 193 | + } | |
| 194 | + | |
| 195 | + return $mt_values; | |
| 196 | + } | |
| 197 | + | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * @return array | |
| 201 | + * @throws EE_Error | |
| 202 | + * @throws InvalidArgumentException | |
| 203 | + * @throws InvalidDataTypeException | |
| 204 | + * @throws InvalidInterfaceException | |
| 205 | + * @deprecated 4.9.9.rc.014 | |
| 206 | + */ | |
| 207 | + public function get_contexts_for_message_types_for_list_table() | |
| 208 | +	{ | |
| 209 | + EE_Error::doing_it_wrong( | |
| 210 | + __METHOD__, | |
| 211 | + sprintf( | |
| 212 | + esc_html__( | |
| 213 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', | |
| 214 | + 'event_espresso' | |
| 215 | + ), | |
| 216 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' | |
| 217 | + ), | |
| 218 | + '4.9.9.rc.014' | |
| 219 | + ); | |
| 220 | + | |
| 221 | + $contexts = []; | |
| 222 | + $active_message_contexts = EEM_Message::instance()->get_all(['group_by' => 'MSG_context']); | |
| 223 | +		foreach ($active_message_contexts as $active_message) { | |
| 224 | +			if ($active_message instanceof EE_Message) { | |
| 225 | + $message_type = $active_message->message_type_object(); | |
| 226 | +				if ($message_type instanceof EE_message_type) { | |
| 227 | + $message_type_contexts = $message_type->get_contexts(); | |
| 228 | +					foreach ($message_type_contexts as $context => $context_details) { | |
| 229 | + $contexts[ $context ] = $context_details['label']; | |
| 230 | + } | |
| 231 | + } | |
| 232 | + } | |
| 233 | + } | |
| 234 | + | |
| 235 | + return $contexts; | |
| 236 | + } | |
| 237 | + | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * Generate select input with provided messenger options array. | |
| 241 | + * | |
| 242 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger | |
| 243 | + * labels. | |
| 244 | + * @return string | |
| 245 | + * @throws EE_Error | |
| 246 | + */ | |
| 247 | + public function get_messengers_select_input($messenger_options) | |
| 248 | +	{ | |
| 249 | + // if empty or just one value then just return an empty string | |
| 250 | + if ( | |
| 251 | + empty($messenger_options) | |
| 252 | + || ! is_array($messenger_options) | |
| 253 | + || count($messenger_options) === 1 | |
| 254 | +		) { | |
| 255 | + return ''; | |
| 256 | + } | |
| 257 | + // merge in default | |
| 258 | + $messenger_options = array_merge( | |
| 259 | +			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')], | |
| 260 | + $messenger_options | |
| 261 | + ); | |
| 262 | + $input = new EE_Select_Input( | |
| 263 | + $messenger_options, | |
| 264 | + [ | |
| 265 | + 'html_name' => 'ee_messenger_filter_by', | |
| 266 | + 'html_id' => 'ee_messenger_filter_by', | |
| 267 | + 'html_class' => 'wide', | |
| 268 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) | |
| 269 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) | |
| 270 | + : 'none_selected', | |
| 271 | + ] | |
| 272 | + ); | |
| 273 | + | |
| 274 | + return $input->get_html_for_input(); | |
| 275 | + } | |
| 276 | + | |
| 277 | + | |
| 278 | + /** | |
| 279 | + * Generate select input with provided message type options array. | |
| 280 | + * | |
| 281 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the | |
| 282 | + * message type labels | |
| 283 | + * @return string | |
| 284 | + * @throws EE_Error | |
| 285 | + */ | |
| 286 | + public function get_message_types_select_input($message_type_options) | |
| 287 | +	{ | |
| 288 | + // if empty or count of options is 1 then just return an empty string | |
| 289 | + if ( | |
| 290 | + empty($message_type_options) | |
| 291 | + || ! is_array($message_type_options) | |
| 292 | + || count($message_type_options) === 1 | |
| 293 | +		) { | |
| 294 | + return ''; | |
| 295 | + } | |
| 296 | + // merge in default | |
| 297 | + $message_type_options = array_merge( | |
| 298 | +			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')], | |
| 299 | + $message_type_options | |
| 300 | + ); | |
| 301 | + $input = new EE_Select_Input( | |
| 302 | + $message_type_options, | |
| 303 | + [ | |
| 304 | + 'html_name' => 'ee_message_type_filter_by', | |
| 305 | + 'html_id' => 'ee_message_type_filter_by', | |
| 306 | + 'html_class' => 'wide', | |
| 307 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) | |
| 308 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) | |
| 309 | + : 'none_selected', | |
| 310 | + ] | |
| 311 | + ); | |
| 312 | + | |
| 313 | + return $input->get_html_for_input(); | |
| 314 | + } | |
| 315 | + | |
| 316 | + | |
| 317 | + /** | |
| 318 | + * Generate select input with provide message type contexts array. | |
| 319 | + * | |
| 320 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the | |
| 321 | + * context label. | |
| 322 | + * @return string | |
| 323 | + * @throws EE_Error | |
| 324 | + */ | |
| 325 | + public function get_contexts_for_message_types_select_input($context_options) | |
| 326 | +	{ | |
| 327 | + // if empty or count of options is one then just return empty string | |
| 328 | + if ( | |
| 329 | + empty($context_options) | |
| 330 | + || ! is_array($context_options) | |
| 331 | + || count($context_options) === 1 | |
| 332 | +		) { | |
| 333 | + return ''; | |
| 334 | + } | |
| 335 | + // merge in default | |
| 336 | + $context_options = array_merge( | |
| 337 | +			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')], | |
| 338 | + $context_options | |
| 339 | + ); | |
| 340 | + $input = new EE_Select_Input( | |
| 341 | + $context_options, | |
| 342 | + [ | |
| 343 | + 'html_name' => 'ee_context_filter_by', | |
| 344 | + 'html_id' => 'ee_context_filter_by', | |
| 345 | + 'html_class' => 'wide', | |
| 346 | + 'default' => isset($this->_req_data['ee_context_filter_by']) | |
| 347 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) | |
| 348 | + : 'none_selected', | |
| 349 | + ] | |
| 350 | + ); | |
| 351 | + | |
| 352 | + return $input->get_html_for_input(); | |
| 353 | + } | |
| 354 | + | |
| 355 | + | |
| 356 | + protected function _ajax_hooks() | |
| 357 | +	{ | |
| 358 | +		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']); | |
| 359 | +		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']); | |
| 360 | +		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']); | |
| 361 | +		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']); | |
| 362 | +		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']); | |
| 363 | +		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']); | |
| 364 | + } | |
| 365 | + | |
| 366 | + | |
| 367 | + protected function _define_page_props() | |
| 368 | +	{ | |
| 369 | + $this->_admin_page_title = $this->page_label; | |
| 370 | + $this->_labels = [ | |
| 371 | + 'buttons' => [ | |
| 372 | +				'add'    => esc_html__('Add New Message Template', 'event_espresso'), | |
| 373 | +				'edit'   => esc_html__('Edit Message Template', 'event_espresso'), | |
| 374 | +				'delete' => esc_html__('Delete Message Template', 'event_espresso'), | |
| 375 | + ], | |
| 376 | +			'publishbox' => esc_html__('Update Actions', 'event_espresso'), | |
| 377 | + ]; | |
| 378 | + } | |
| 379 | + | |
| 380 | + | |
| 381 | + /** | |
| 382 | + * an array for storing key => value pairs of request actions and their corresponding methods | |
| 383 | + * | |
| 384 | + * @access protected | |
| 385 | + * @return void | |
| 386 | + */ | |
| 387 | + protected function _set_page_routes() | |
| 388 | +	{ | |
| 389 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) | |
| 390 | + ? $this->_req_data['GRP_ID'] | |
| 391 | + : 0; | |
| 392 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) | |
| 393 | + ? $this->_req_data['id'] | |
| 394 | + : $grp_id; | |
| 395 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) | |
| 396 | + ? $this->_req_data['MSG_ID'] | |
| 397 | + : 0; | |
| 398 | + | |
| 399 | + $this->_page_routes = [ | |
| 400 | + 'default' => [ | |
| 401 | + 'func' => '_message_queue_list_table', | |
| 402 | + 'capability' => 'ee_read_global_messages', | |
| 403 | + ], | |
| 404 | + 'global_mtps' => [ | |
| 405 | + 'func' => '_ee_default_messages_overview_list_table', | |
| 406 | + 'capability' => 'ee_read_global_messages', | |
| 407 | + ], | |
| 408 | + 'custom_mtps' => [ | |
| 409 | + 'func' => '_custom_mtps_preview', | |
| 410 | + 'capability' => 'ee_read_messages', | |
| 411 | + ], | |
| 412 | + 'add_new_message_template' => [ | |
| 413 | + 'func' => '_add_message_template', | |
| 414 | + 'capability' => 'ee_edit_messages', | |
| 415 | + 'noheader' => true, | |
| 416 | + ], | |
| 417 | + 'edit_message_template' => [ | |
| 418 | + 'func' => '_edit_message_template', | |
| 419 | + 'capability' => 'ee_edit_message', | |
| 420 | + 'obj_id' => $grp_id, | |
| 421 | + ], | |
| 422 | + 'preview_message' => [ | |
| 423 | + 'func' => '_preview_message', | |
| 424 | + 'capability' => 'ee_read_message', | |
| 425 | + 'obj_id' => $grp_id, | |
| 426 | + 'noheader' => true, | |
| 427 | + 'headers_sent_route' => 'display_preview_message', | |
| 428 | + ], | |
| 429 | + 'display_preview_message' => [ | |
| 430 | + 'func' => '_display_preview_message', | |
| 431 | + 'capability' => 'ee_read_message', | |
| 432 | + 'obj_id' => $grp_id, | |
| 433 | + ], | |
| 434 | + 'insert_message_template' => [ | |
| 435 | + 'func' => '_insert_or_update_message_template', | |
| 436 | + 'capability' => 'ee_edit_messages', | |
| 437 | + 'args' => ['new' => true], | |
| 438 | + 'noheader' => true, | |
| 439 | + ], | |
| 440 | + 'update_message_template' => [ | |
| 441 | + 'func' => '_insert_or_update_message_template', | |
| 442 | + 'capability' => 'ee_edit_message', | |
| 443 | + 'obj_id' => $grp_id, | |
| 444 | + 'args' => ['new' => false], | |
| 445 | + 'noheader' => true, | |
| 446 | + ], | |
| 447 | + 'trash_message_template' => [ | |
| 448 | + 'func' => '_trash_or_restore_message_template', | |
| 449 | + 'capability' => 'ee_delete_message', | |
| 450 | + 'obj_id' => $grp_id, | |
| 451 | + 'args' => ['trash' => true, 'all' => true], | |
| 452 | + 'noheader' => true, | |
| 453 | + ], | |
| 454 | + 'trash_message_template_context' => [ | |
| 455 | + 'func' => '_trash_or_restore_message_template', | |
| 456 | + 'capability' => 'ee_delete_message', | |
| 457 | + 'obj_id' => $grp_id, | |
| 458 | + 'args' => ['trash' => true], | |
| 459 | + 'noheader' => true, | |
| 460 | + ], | |
| 461 | + 'restore_message_template' => [ | |
| 462 | + 'func' => '_trash_or_restore_message_template', | |
| 463 | + 'capability' => 'ee_delete_message', | |
| 464 | + 'obj_id' => $grp_id, | |
| 465 | + 'args' => ['trash' => false, 'all' => true], | |
| 466 | + 'noheader' => true, | |
| 467 | + ], | |
| 468 | + 'restore_message_template_context' => [ | |
| 469 | + 'func' => '_trash_or_restore_message_template', | |
| 470 | + 'capability' => 'ee_delete_message', | |
| 471 | + 'obj_id' => $grp_id, | |
| 472 | + 'args' => ['trash' => false], | |
| 473 | + 'noheader' => true, | |
| 474 | + ], | |
| 475 | + 'delete_message_template' => [ | |
| 476 | + 'func' => '_delete_message_template', | |
| 477 | + 'capability' => 'ee_delete_message', | |
| 478 | + 'obj_id' => $grp_id, | |
| 479 | + 'noheader' => true, | |
| 480 | + ], | |
| 481 | + 'reset_to_default' => [ | |
| 482 | + 'func' => '_reset_to_default_template', | |
| 483 | + 'capability' => 'ee_edit_message', | |
| 484 | + 'obj_id' => $grp_id, | |
| 485 | + 'noheader' => true, | |
| 486 | + ], | |
| 487 | + 'settings' => [ | |
| 488 | + 'func' => '_settings', | |
| 489 | + 'capability' => 'manage_options', | |
| 490 | + ], | |
| 491 | + 'update_global_settings' => [ | |
| 492 | + 'func' => '_update_global_settings', | |
| 493 | + 'capability' => 'manage_options', | |
| 494 | + 'noheader' => true, | |
| 495 | + ], | |
| 496 | + 'generate_now' => [ | |
| 497 | + 'func' => '_generate_now', | |
| 498 | + 'capability' => 'ee_send_message', | |
| 499 | + 'noheader' => true, | |
| 500 | + ], | |
| 501 | + 'generate_and_send_now' => [ | |
| 502 | + 'func' => '_generate_and_send_now', | |
| 503 | + 'capability' => 'ee_send_message', | |
| 504 | + 'noheader' => true, | |
| 505 | + ], | |
| 506 | + 'queue_for_resending' => [ | |
| 507 | + 'func' => '_queue_for_resending', | |
| 508 | + 'capability' => 'ee_send_message', | |
| 509 | + 'noheader' => true, | |
| 510 | + ], | |
| 511 | + 'send_now' => [ | |
| 512 | + 'func' => '_send_now', | |
| 513 | + 'capability' => 'ee_send_message', | |
| 514 | + 'noheader' => true, | |
| 515 | + ], | |
| 516 | + 'delete_ee_message' => [ | |
| 517 | + 'func' => '_delete_ee_messages', | |
| 518 | + 'capability' => 'ee_delete_messages', | |
| 519 | + 'noheader' => true, | |
| 520 | + ], | |
| 521 | + 'delete_ee_messages' => [ | |
| 522 | + 'func' => '_delete_ee_messages', | |
| 523 | + 'capability' => 'ee_delete_messages', | |
| 524 | + 'noheader' => true, | |
| 525 | + 'obj_id' => $msg_id, | |
| 526 | + ], | |
| 527 | + ]; | |
| 528 | + } | |
| 529 | + | |
| 530 | + | |
| 531 | + protected function _set_page_config() | |
| 532 | +	{ | |
| 533 | + $this->_page_config = [ | |
| 534 | + 'default' => [ | |
| 535 | + 'nav' => [ | |
| 536 | +					'label' => esc_html__('Message Activity', 'event_espresso'), | |
| 537 | + 'order' => 10, | |
| 538 | + ], | |
| 539 | + 'list_table' => 'EE_Message_List_Table', | |
| 540 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), | |
| 541 | + 'require_nonce' => false, | |
| 542 | + ], | |
| 543 | + 'global_mtps' => [ | |
| 544 | + 'nav' => [ | |
| 545 | +					'label' => esc_html__('Default Message Templates', 'event_espresso'), | |
| 546 | + 'order' => 20, | |
| 547 | + ], | |
| 548 | + 'list_table' => 'Messages_Template_List_Table', | |
| 549 | + 'help_tabs' => [ | |
| 550 | + 'messages_overview_help_tab' => [ | |
| 551 | +						'title'    => esc_html__('Messages Overview', 'event_espresso'), | |
| 552 | + 'filename' => 'messages_overview', | |
| 553 | + ], | |
| 554 | + 'messages_overview_messages_table_column_headings_help_tab' => [ | |
| 555 | +						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'), | |
| 556 | + 'filename' => 'messages_overview_table_column_headings', | |
| 557 | + ], | |
| 558 | + 'messages_overview_messages_filters_help_tab' => [ | |
| 559 | +						'title'    => esc_html__('Message Filters', 'event_espresso'), | |
| 560 | + 'filename' => 'messages_overview_filters', | |
| 561 | + ], | |
| 562 | + 'messages_overview_messages_views_help_tab' => [ | |
| 563 | +						'title'    => esc_html__('Message Views', 'event_espresso'), | |
| 564 | + 'filename' => 'messages_overview_views', | |
| 565 | + ], | |
| 566 | + 'message_overview_message_types_help_tab' => [ | |
| 567 | +						'title'    => esc_html__('Message Types', 'event_espresso'), | |
| 568 | + 'filename' => 'messages_overview_types', | |
| 569 | + ], | |
| 570 | + 'messages_overview_messengers_help_tab' => [ | |
| 571 | +						'title'    => esc_html__('Messengers', 'event_espresso'), | |
| 572 | + 'filename' => 'messages_overview_messengers', | |
| 573 | + ], | |
| 574 | + ], | |
| 575 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 576 | +				// 'help_tour'     => array('Messages_Overview_Help_Tour'), | |
| 577 | + 'require_nonce' => false, | |
| 578 | + ], | |
| 579 | + 'custom_mtps' => [ | |
| 580 | + 'nav' => [ | |
| 581 | +					'label' => esc_html__('Custom Message Templates', 'event_espresso'), | |
| 582 | + 'order' => 30, | |
| 583 | + ], | |
| 584 | + 'help_tabs' => [], | |
| 585 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 586 | + // 'help_tour' => array(), | |
| 587 | + 'require_nonce' => false, | |
| 588 | + ], | |
| 589 | + 'add_new_message_template' => [ | |
| 590 | + 'nav' => [ | |
| 591 | +					'label'      => esc_html__('Add New Message Templates', 'event_espresso'), | |
| 592 | + 'order' => 5, | |
| 593 | + 'persistent' => false, | |
| 594 | + ], | |
| 595 | + 'require_nonce' => false, | |
| 596 | + ], | |
| 597 | + 'edit_message_template' => [ | |
| 598 | + 'labels' => [ | |
| 599 | + 'buttons' => [ | |
| 600 | +						'reset' => esc_html__('Reset Templates', 'event_espresso'), | |
| 601 | + ], | |
| 602 | +					'publishbox' => esc_html__('Update Actions', 'event_espresso'), | |
| 603 | + ], | |
| 604 | + 'nav' => [ | |
| 605 | +					'label'      => esc_html__('Edit Message Templates', 'event_espresso'), | |
| 606 | + 'order' => 5, | |
| 607 | + 'persistent' => false, | |
| 608 | + 'url' => '', | |
| 609 | + ], | |
| 610 | + 'metaboxes' => ['_publish_post_box', '_register_edit_meta_boxes'], | |
| 611 | + 'has_metaboxes' => true, | |
| 612 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 613 | +				// 'help_tour'     => array('Message_Templates_Edit_Help_Tour'), | |
| 614 | + 'help_tabs' => [ | |
| 615 | + 'edit_message_template' => [ | |
| 616 | +						'title'    => esc_html__('Message Template Editor', 'event_espresso'), | |
| 617 | + 'callback' => 'edit_message_template_help_tab', | |
| 618 | + ], | |
| 619 | + 'message_templates_help_tab' => [ | |
| 620 | +						'title'    => esc_html__('Message Templates', 'event_espresso'), | |
| 621 | + 'filename' => 'messages_templates', | |
| 622 | + ], | |
| 623 | + 'message_template_shortcodes' => [ | |
| 624 | +						'title'    => esc_html__('Message Shortcodes', 'event_espresso'), | |
| 625 | + 'callback' => 'message_template_shortcodes_help_tab', | |
| 626 | + ], | |
| 627 | + 'message_preview_help_tab' => [ | |
| 628 | +						'title'    => esc_html__('Message Preview', 'event_espresso'), | |
| 629 | + 'filename' => 'messages_preview', | |
| 630 | + ], | |
| 631 | + 'messages_overview_other_help_tab' => [ | |
| 632 | +						'title'    => esc_html__('Messages Other', 'event_espresso'), | |
| 633 | + 'filename' => 'messages_overview_other', | |
| 634 | + ], | |
| 635 | + ], | |
| 636 | + 'require_nonce' => false, | |
| 637 | + ], | |
| 638 | + 'display_preview_message' => [ | |
| 639 | + 'nav' => [ | |
| 640 | +					'label'      => esc_html__('Message Preview', 'event_espresso'), | |
| 641 | + 'order' => 5, | |
| 642 | + 'url' => '', | |
| 643 | + 'persistent' => false, | |
| 644 | + ], | |
| 645 | + 'help_tabs' => [ | |
| 646 | + 'preview_message' => [ | |
| 647 | +						'title'    => esc_html__('About Previews', 'event_espresso'), | |
| 648 | + 'callback' => 'preview_message_help_tab', | |
| 649 | + ], | |
| 650 | + ], | |
| 651 | + 'require_nonce' => false, | |
| 652 | + ], | |
| 653 | + 'settings' => [ | |
| 654 | + 'nav' => [ | |
| 655 | +					'label' => esc_html__('Settings', 'event_espresso'), | |
| 656 | + 'order' => 40, | |
| 657 | + ], | |
| 658 | + 'metaboxes' => ['_messages_settings_metaboxes'], | |
| 659 | + 'help_tabs' => [ | |
| 660 | + 'messages_settings_help_tab' => [ | |
| 661 | +						'title'    => esc_html__('Messages Settings', 'event_espresso'), | |
| 662 | + 'filename' => 'messages_settings', | |
| 663 | + ], | |
| 664 | + 'messages_settings_message_types_help_tab' => [ | |
| 665 | +						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), | |
| 666 | + 'filename' => 'messages_settings_message_types', | |
| 667 | + ], | |
| 668 | + 'messages_settings_messengers_help_tab' => [ | |
| 669 | +						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), | |
| 670 | + 'filename' => 'messages_settings_messengers', | |
| 671 | + ], | |
| 672 | + ], | |
| 673 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 | |
| 674 | +				// 'help_tour'     => array('Messages_Settings_Help_Tour'), | |
| 675 | + 'require_nonce' => false, | |
| 676 | + ], | |
| 677 | + ]; | |
| 678 | + } | |
| 679 | + | |
| 680 | + | |
| 681 | + protected function _add_screen_options() | |
| 682 | +	{ | |
| 683 | + // todo | |
| 684 | + } | |
| 685 | + | |
| 686 | + | |
| 687 | + protected function _add_screen_options_global_mtps() | |
| 688 | +	{ | |
| 689 | + /** | |
| 690 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options | |
| 691 | + * uses the $_admin_page_title property and we want different outputs in the different spots. | |
| 692 | + */ | |
| 693 | + $page_title = $this->_admin_page_title; | |
| 694 | +		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); | |
| 695 | + $this->_per_page_screen_option(); | |
| 696 | + $this->_admin_page_title = $page_title; | |
| 697 | + } | |
| 698 | + | |
| 699 | + | |
| 700 | + protected function _add_screen_options_default() | |
| 701 | +	{ | |
| 702 | +		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); | |
| 703 | + $this->_per_page_screen_option(); | |
| 704 | + } | |
| 705 | + | |
| 706 | + | |
| 707 | + // none of the below group are currently used for Messages | |
| 708 | + protected function _add_feature_pointers() | |
| 709 | +	{ | |
| 710 | + } | |
| 711 | + | |
| 712 | + | |
| 713 | + public function admin_init() | |
| 714 | +	{ | |
| 715 | + } | |
| 716 | + | |
| 717 | + | |
| 718 | + public function admin_notices() | |
| 719 | +	{ | |
| 720 | + } | |
| 721 | + | |
| 722 | + | |
| 723 | + public function admin_footer_scripts() | |
| 724 | +	{ | |
| 725 | + } | |
| 726 | + | |
| 727 | + | |
| 728 | + public function messages_help_tab() | |
| 729 | +	{ | |
| 730 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); | |
| 731 | + } | |
| 732 | + | |
| 733 | + | |
| 734 | + public function messengers_help_tab() | |
| 735 | +	{ | |
| 736 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); | |
| 737 | + } | |
| 738 | + | |
| 739 | + | |
| 740 | + public function message_types_help_tab() | |
| 741 | +	{ | |
| 742 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); | |
| 743 | + } | |
| 744 | + | |
| 745 | + | |
| 746 | + public function messages_overview_help_tab() | |
| 747 | +	{ | |
| 748 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); | |
| 749 | + } | |
| 750 | + | |
| 751 | + | |
| 752 | + public function message_templates_help_tab() | |
| 753 | +	{ | |
| 754 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); | |
| 755 | + } | |
| 756 | + | |
| 757 | + | |
| 758 | + public function edit_message_template_help_tab() | |
| 759 | +	{ | |
| 760 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' | |
| 761 | +						. esc_attr__('Editor Title', 'event_espresso') | |
| 762 | + . '" />'; | |
| 763 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' | |
| 764 | +						. esc_attr__('Context Switcher and Preview', 'event_espresso') | |
| 765 | + . '" />'; | |
| 766 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' | |
| 767 | +						. esc_attr__('Message Template Form Fields', 'event_espresso') | |
| 768 | + . '" />'; | |
| 769 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' | |
| 770 | +						. esc_attr__('Shortcodes Metabox', 'event_espresso') | |
| 771 | + . '" />'; | |
| 772 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' | |
| 773 | +						. esc_attr__('Publish Metabox', 'event_espresso') | |
| 774 | + . '" />'; | |
| 775 | + EEH_Template::display_template( | |
| 776 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', | |
| 777 | + $args | |
| 778 | + ); | |
| 779 | + } | |
| 780 | + | |
| 781 | + | |
| 782 | + public function message_template_shortcodes_help_tab() | |
| 783 | +	{ | |
| 784 | + $this->_set_shortcodes(); | |
| 785 | + $args['shortcodes'] = $this->_shortcodes; | |
| 786 | + EEH_Template::display_template( | |
| 787 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', | |
| 788 | + $args | |
| 789 | + ); | |
| 790 | + } | |
| 791 | + | |
| 792 | + | |
| 793 | + public function preview_message_help_tab() | |
| 794 | +	{ | |
| 795 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); | |
| 796 | + } | |
| 797 | + | |
| 798 | + | |
| 799 | + public function settings_help_tab() | |
| 800 | +	{ | |
| 801 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' | |
| 802 | +						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; | |
| 803 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' | |
| 804 | +						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; | |
| 805 | + $args['img3'] = '<div class="switch">' | |
| 806 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' | |
| 807 | + . ' type="checkbox" checked="checked">' | |
| 808 | + . '<label for="ee-on-off-toggle-on"></label>' | |
| 809 | + . '</div>'; | |
| 810 | + $args['img4'] = '<div class="switch">' | |
| 811 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' | |
| 812 | + . ' type="checkbox">' | |
| 813 | + . '<label for="ee-on-off-toggle-on"></label>' | |
| 814 | + . '</div>'; | |
| 815 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); | |
| 816 | + } | |
| 817 | + | |
| 818 | + | |
| 819 | + public function load_scripts_styles() | |
| 820 | +	{ | |
| 821 | +		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | |
| 822 | +		wp_enqueue_style('espresso_ee_msg'); | |
| 823 | + | |
| 824 | + wp_register_script( | |
| 825 | + 'ee-messages-settings', | |
| 826 | + EE_MSG_ASSETS_URL . 'ee-messages-settings.js', | |
| 827 | + ['jquery-ui-droppable', 'ee-serialize-full-array'], | |
| 828 | + EVENT_ESPRESSO_VERSION, | |
| 829 | + true | |
| 830 | + ); | |
| 831 | + wp_register_script( | |
| 832 | + 'ee-msg-list-table-js', | |
| 833 | + EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', | |
| 834 | + ['ee-dialog'], | |
| 835 | + EVENT_ESPRESSO_VERSION | |
| 836 | + ); | |
| 837 | + } | |
| 838 | + | |
| 839 | + | |
| 840 | + public function load_scripts_styles_default() | |
| 841 | +	{ | |
| 842 | +		wp_enqueue_script('ee-msg-list-table-js'); | |
| 843 | + } | |
| 844 | + | |
| 845 | + | |
| 846 | + public function wp_editor_css($mce_css) | |
| 847 | +	{ | |
| 848 | + // if we're on the edit_message_template route | |
| 849 | +		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { | |
| 850 | + $message_type_name = $this->_active_message_type_name; | |
| 851 | + | |
| 852 | + // we're going to REPLACE the existing mce css | |
| 853 | + // we need to get the css file location from the active messenger | |
| 854 | + $mce_css = $this->_active_messenger->get_variation( | |
| 855 | + $this->_template_pack, | |
| 856 | + $message_type_name, | |
| 857 | + true, | |
| 858 | + 'wpeditor', | |
| 859 | + $this->_variation | |
| 860 | + ); | |
| 861 | + } | |
| 862 | + | |
| 863 | + return $mce_css; | |
| 864 | + } | |
| 865 | + | |
| 866 | + | |
| 867 | + public function load_scripts_styles_edit_message_template() | |
| 868 | +	{ | |
| 869 | + | |
| 870 | + $this->_set_shortcodes(); | |
| 871 | + | |
| 872 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( | |
| 873 | + esc_html__( | |
| 874 | + 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', | |
| 875 | + 'event_espresso' | |
| 876 | + ), | |
| 877 | + $this->_message_template_group->messenger_obj()->label['singular'], | |
| 878 | + $this->_message_template_group->message_type_obj()->label['singular'] | |
| 879 | + ); | |
| 880 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( | |
| 881 | + 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', | |
| 882 | + 'event_espresso' | |
| 883 | + ); | |
| 884 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( | |
| 885 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', | |
| 886 | + 'event_espresso' | |
| 887 | + ); | |
| 888 | + | |
| 889 | + wp_register_script( | |
| 890 | + 'ee_msgs_edit_js', | |
| 891 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', | |
| 892 | + ['jquery'], | |
| 893 | + EVENT_ESPRESSO_VERSION | |
| 894 | + ); | |
| 895 | + | |
| 896 | +		wp_enqueue_script('ee_admin_js'); | |
| 897 | +		wp_enqueue_script('ee_msgs_edit_js'); | |
| 898 | + | |
| 899 | + // add in special css for tiny_mce | |
| 900 | +		add_filter('mce_css', [$this, 'wp_editor_css']); | |
| 901 | + } | |
| 902 | + | |
| 903 | + | |
| 904 | + public function load_scripts_styles_display_preview_message() | |
| 905 | +	{ | |
| 906 | + | |
| 907 | + $this->_set_message_template_group(); | |
| 908 | + | |
| 909 | +		if (isset($this->_req_data['messenger'])) { | |
| 910 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( | |
| 911 | + $this->_req_data['messenger'] | |
| 912 | + ); | |
| 913 | + } | |
| 914 | + | |
| 915 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; | |
| 916 | + | |
| 917 | + | |
| 918 | + wp_enqueue_style( | |
| 919 | + 'espresso_preview_css', | |
| 920 | + $this->_active_messenger->get_variation( | |
| 921 | + $this->_template_pack, | |
| 922 | + $message_type_name, | |
| 923 | + true, | |
| 924 | + 'preview', | |
| 925 | + $this->_variation | |
| 926 | + ) | |
| 927 | + ); | |
| 928 | + } | |
| 929 | + | |
| 930 | + | |
| 931 | + public function load_scripts_styles_settings() | |
| 932 | +	{ | |
| 933 | + wp_register_style( | |
| 934 | + 'ee-message-settings', | |
| 935 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', | |
| 936 | + [], | |
| 937 | + EVENT_ESPRESSO_VERSION | |
| 938 | + ); | |
| 939 | +		wp_enqueue_style('ee-text-links'); | |
| 940 | +		wp_enqueue_style('ee-message-settings'); | |
| 941 | +		wp_enqueue_script('ee-messages-settings'); | |
| 942 | + } | |
| 943 | + | |
| 944 | + | |
| 945 | + /** | |
| 946 | + * set views array for List Table | |
| 947 | + */ | |
| 948 | + public function _set_list_table_views_global_mtps() | |
| 949 | +	{ | |
| 950 | + $this->_views = [ | |
| 951 | + 'in_use' => [ | |
| 952 | + 'slug' => 'in_use', | |
| 953 | +				'label' => esc_html__('In Use', 'event_espresso'), | |
| 954 | + 'count' => 0, | |
| 955 | + ], | |
| 956 | + ]; | |
| 957 | + } | |
| 958 | + | |
| 959 | + | |
| 960 | + /** | |
| 961 | + * Set views array for the Custom Template List Table | |
| 962 | + */ | |
| 963 | + public function _set_list_table_views_custom_mtps() | |
| 964 | +	{ | |
| 965 | + $this->_set_list_table_views_global_mtps(); | |
| 966 | + $this->_views['in_use']['bulk_action'] = [ | |
| 967 | +			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'), | |
| 968 | + ]; | |
| 969 | + } | |
| 970 | + | |
| 971 | + | |
| 972 | + /** | |
| 973 | + * set views array for message queue list table | |
| 974 | + * | |
| 975 | + * @throws InvalidDataTypeException | |
| 976 | + * @throws InvalidInterfaceException | |
| 977 | + * @throws InvalidArgumentException | |
| 978 | + * @throws EE_Error | |
| 979 | + * @throws ReflectionException | |
| 980 | + */ | |
| 981 | + public function _set_list_table_views_default() | |
| 982 | +	{ | |
| 983 | +		EE_Registry::instance()->load_helper('Template'); | |
| 984 | + | |
| 985 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( | |
| 986 | + 'ee_send_message', | |
| 987 | + 'message_list_table_bulk_actions' | |
| 988 | + ) | |
| 989 | + ? [ | |
| 990 | +				'generate_now'          => esc_html__('Generate Now', 'event_espresso'), | |
| 991 | +				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), | |
| 992 | +				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'), | |
| 993 | +				'send_now'              => esc_html__('Send Now', 'event_espresso'), | |
| 994 | + ] | |
| 995 | + : []; | |
| 996 | + | |
| 997 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( | |
| 998 | + 'ee_delete_messages', | |
| 999 | + 'message_list_table_bulk_actions' | |
| 1000 | + ) | |
| 1001 | +			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')] | |
| 1002 | + : []; | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + $this->_views = [ | |
| 1006 | + 'all' => [ | |
| 1007 | + 'slug' => 'all', | |
| 1008 | +				'label'       => esc_html__('All', 'event_espresso'), | |
| 1009 | + 'count' => 0, | |
| 1010 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action), | |
| 1011 | + ], | |
| 1012 | + ]; | |
| 1013 | + | |
| 1014 | + | |
| 1015 | +		foreach (EEM_Message::instance()->all_statuses() as $status) { | |
| 1016 | +			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { | |
| 1017 | + continue; | |
| 1018 | + } | |
| 1019 | + $status_bulk_actions = $common_bulk_actions; | |
| 1020 | + // unset bulk actions not applying to status | |
| 1021 | +			if (! empty($status_bulk_actions)) { | |
| 1022 | +				switch ($status) { | |
| 1023 | + case EEM_Message::status_idle: | |
| 1024 | + case EEM_Message::status_resend: | |
| 1025 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; | |
| 1026 | + break; | |
| 1027 | + | |
| 1028 | + case EEM_Message::status_failed: | |
| 1029 | + case EEM_Message::status_debug_only: | |
| 1030 | + case EEM_Message::status_messenger_executing: | |
| 1031 | + $status_bulk_actions = []; | |
| 1032 | + break; | |
| 1033 | + | |
| 1034 | + case EEM_Message::status_incomplete: | |
| 1035 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); | |
| 1036 | + break; | |
| 1037 | + | |
| 1038 | + case EEM_Message::status_retry: | |
| 1039 | + case EEM_Message::status_sent: | |
| 1040 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); | |
| 1041 | + break; | |
| 1042 | + } | |
| 1043 | + } | |
| 1044 | + | |
| 1045 | + // skip adding messenger executing status to views because it will be included with the Failed view. | |
| 1046 | +			if ($status === EEM_Message::status_messenger_executing) { | |
| 1047 | + continue; | |
| 1048 | + } | |
| 1049 | + | |
| 1050 | + $this->_views[ strtolower($status) ] = [ | |
| 1051 | + 'slug' => strtolower($status), | |
| 1052 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), | |
| 1053 | + 'count' => 0, | |
| 1054 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action), | |
| 1055 | + ]; | |
| 1056 | + } | |
| 1057 | + } | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + protected function _ee_default_messages_overview_list_table() | |
| 1061 | +	{ | |
| 1062 | +		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); | |
| 1063 | + $this->display_admin_list_table_page_with_no_sidebar(); | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + protected function _message_queue_list_table() | |
| 1068 | +	{ | |
| 1069 | +		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso'); | |
| 1070 | + $this->_template_args['per_column'] = 6; | |
| 1071 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); | |
| 1072 | + $this->_template_args['before_list_table'] = '<h3>' | |
| 1073 | + . EEM_Message::instance()->get_pretty_label_for_results() | |
| 1074 | + . '</h3>'; | |
| 1075 | + $this->display_admin_list_table_page_with_no_sidebar(); | |
| 1076 | + } | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + protected function _message_legend_items() | |
| 1080 | +	{ | |
| 1081 | + | |
| 1082 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); | |
| 1083 | + $action_items = []; | |
| 1084 | + | |
| 1085 | +		foreach ($action_css_classes as $action_item => $action_details) { | |
| 1086 | +			if ($action_item === 'see_notifications_for') { | |
| 1087 | + continue; | |
| 1088 | + } | |
| 1089 | + $action_items[ $action_item ] = [ | |
| 1090 | + 'class' => $action_details['css_class'], | |
| 1091 | + 'desc' => $action_details['label'], | |
| 1092 | + ]; | |
| 1093 | + } | |
| 1094 | + | |
| 1095 | + /** @type array $status_items status legend setup */ | |
| 1096 | + $status_items = [ | |
| 1097 | + 'sent_status' => [ | |
| 1098 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, | |
| 1099 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'), | |
| 1100 | + ], | |
| 1101 | + 'idle_status' => [ | |
| 1102 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, | |
| 1103 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'), | |
| 1104 | + ], | |
| 1105 | + 'failed_status' => [ | |
| 1106 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, | |
| 1107 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'), | |
| 1108 | + ], | |
| 1109 | + 'messenger_executing_status' => [ | |
| 1110 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, | |
| 1111 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'), | |
| 1112 | + ], | |
| 1113 | + 'resend_status' => [ | |
| 1114 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, | |
| 1115 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'), | |
| 1116 | + ], | |
| 1117 | + 'incomplete_status' => [ | |
| 1118 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, | |
| 1119 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'), | |
| 1120 | + ], | |
| 1121 | + 'retry_status' => [ | |
| 1122 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, | |
| 1123 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'), | |
| 1124 | + ], | |
| 1125 | + ]; | |
| 1126 | +		if (EEM_Message::debug()) { | |
| 1127 | + $status_items['debug_only_status'] = [ | |
| 1128 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, | |
| 1129 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'), | |
| 1130 | + ]; | |
| 1131 | + } | |
| 1132 | + | |
| 1133 | + return array_merge($action_items, $status_items); | |
| 1134 | + } | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + protected function _custom_mtps_preview() | |
| 1138 | +	{ | |
| 1139 | +		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); | |
| 1140 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' | |
| 1141 | + . ' alt="' . esc_attr__( | |
| 1142 | + 'Preview Custom Message Templates screenshot', | |
| 1143 | + 'event_espresso' | |
| 1144 | + ) . '" />'; | |
| 1145 | + $this->_template_args['preview_text'] = '<strong>' | |
| 1146 | + . esc_html__( | |
| 1147 | + 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', | |
| 1148 | + 'event_espresso' | |
| 1149 | + ) | |
| 1150 | + . '</strong>'; | |
| 1151 | + | |
| 1152 | +		$this->display_admin_caf_preview_page('custom_message_types', false); | |
| 1153 | + } | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + /** | |
| 1157 | + * get_message_templates | |
| 1158 | + * This gets all the message templates for listing on the overview list. | |
| 1159 | + * | |
| 1160 | + * @access public | |
| 1161 | + * @param int $perpage the amount of templates groups to show per page | |
| 1162 | + * @param string $type the current _view we're getting templates for | |
| 1163 | + * @param bool $count return count? | |
| 1164 | + * @param bool $all disregard any paging info (get all data); | |
| 1165 | + * @param bool $global whether to return just global (true) or custom templates (false) | |
| 1166 | + * @return array | |
| 1167 | + * @throws EE_Error | |
| 1168 | + * @throws InvalidArgumentException | |
| 1169 | + * @throws InvalidDataTypeException | |
| 1170 | + * @throws InvalidInterfaceException | |
| 1171 | + */ | |
| 1172 | + public function get_message_templates( | |
| 1173 | + $perpage = 10, | |
| 1174 | + $type = 'in_use', | |
| 1175 | + $count = false, | |
| 1176 | + $all = false, | |
| 1177 | + $global = true | |
| 1178 | +	) { | |
| 1179 | + | |
| 1180 | + $MTP = EEM_Message_Template_Group::instance(); | |
| 1181 | + | |
| 1182 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; | |
| 1183 | + $orderby = $this->_req_data['orderby']; | |
| 1184 | + | |
| 1185 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) | |
| 1186 | + ? $this->_req_data['order'] | |
| 1187 | + : 'ASC'; | |
| 1188 | + | |
| 1189 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) | |
| 1190 | + ? $this->_req_data['paged'] | |
| 1191 | + : 1; | |
| 1192 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) | |
| 1193 | + ? $this->_req_data['perpage'] | |
| 1194 | + : $perpage; | |
| 1195 | + | |
| 1196 | + $offset = ($current_page - 1) * $per_page; | |
| 1197 | + $limit = $all ? null : [$offset, $per_page]; | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + // options will match what is in the _views array property | |
| 1201 | +		switch ($type) { | |
| 1202 | + case 'in_use': | |
| 1203 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); | |
| 1204 | + break; | |
| 1205 | + default: | |
| 1206 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); | |
| 1207 | + } | |
| 1208 | + | |
| 1209 | + return $templates; | |
| 1210 | + } | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + /** | |
| 1214 | + * filters etc might need a list of installed message_types | |
| 1215 | + * | |
| 1216 | + * @return array an array of message type objects | |
| 1217 | + */ | |
| 1218 | + public function get_installed_message_types() | |
| 1219 | +	{ | |
| 1220 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); | |
| 1221 | + $installed = []; | |
| 1222 | + | |
| 1223 | +		foreach ($installed_message_types as $message_type) { | |
| 1224 | + $installed[ $message_type->name ] = $message_type; | |
| 1225 | + } | |
| 1226 | + | |
| 1227 | + return $installed; | |
| 1228 | + } | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + /** | |
| 1232 | + * _add_message_template | |
| 1233 | + * | |
| 1234 | + * This is used when creating a custom template. All Custom Templates start based off another template. | |
| 1235 | + * | |
| 1236 | + * @param string $message_type | |
| 1237 | + * @param string $messenger | |
| 1238 | + * @param string $GRP_ID | |
| 1239 | + * | |
| 1240 | + * @throws EE_error | |
| 1241 | + */ | |
| 1242 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') | |
| 1243 | +	{ | |
| 1244 | + // set values override any request data | |
| 1245 | +		$message_type = ! empty($message_type) ? $message_type : $this->request->getRequestParam('message_type'); | |
| 1246 | +		$messenger    = ! empty($messenger) ? $messenger : $this->request->getRequestParam('messenger'); | |
| 1247 | +		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int'); | |
| 1248 | + | |
| 1249 | + // we need messenger and message type. They should be coming from the event editor. If not here then return error | |
| 1250 | +		if (empty($message_type) || empty($messenger)) { | |
| 1251 | + throw new EE_Error( | |
| 1252 | + esc_html__( | |
| 1253 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', | |
| 1254 | + 'event_espresso' | |
| 1255 | + ) | |
| 1256 | + ); | |
| 1257 | + } | |
| 1258 | + | |
| 1259 | + // we need the GRP_ID for the template being used as the base for the new template | |
| 1260 | +		if (empty($GRP_ID)) { | |
| 1261 | + throw new EE_Error( | |
| 1262 | + esc_html__( | |
| 1263 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', | |
| 1264 | + 'event_espresso' | |
| 1265 | + ) | |
| 1266 | + ); | |
| 1267 | + } | |
| 1268 | + | |
| 1269 | + // let's just make sure the template gets generated! | |
| 1270 | + | |
| 1271 | + // we need to reassign some variables for what the insert is expecting | |
| 1272 | + $this->_req_data['MTP_messenger'] = $messenger; | |
| 1273 | + $this->_req_data['MTP_message_type'] = $message_type; | |
| 1274 | + $this->_req_data['GRP_ID'] = $GRP_ID; | |
| 1275 | + $this->_insert_or_update_message_template(true); | |
| 1276 | + } | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + /** | |
| 1280 | + * public wrapper for the _add_message_template method | |
| 1281 | + * | |
| 1282 | + * @param string $message_type message type slug | |
| 1283 | + * @param string $messenger messenger slug | |
| 1284 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based | |
| 1285 | + * off of. | |
| 1286 | + * @throws EE_error | |
| 1287 | + */ | |
| 1288 | + public function add_message_template($message_type, $messenger, $GRP_ID) | |
| 1289 | +	{ | |
| 1290 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); | |
| 1291 | + } | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + /** | |
| 1295 | + * _edit_message_template | |
| 1296 | + * | |
| 1297 | + * @access protected | |
| 1298 | + * @return void | |
| 1299 | + * @throws InvalidIdentifierException | |
| 1300 | + * @throws DomainException | |
| 1301 | + * @throws EE_Error | |
| 1302 | + * @throws InvalidArgumentException | |
| 1303 | + * @throws ReflectionException | |
| 1304 | + * @throws InvalidDataTypeException | |
| 1305 | + * @throws InvalidInterfaceException | |
| 1306 | + */ | |
| 1307 | + protected function _edit_message_template() | |
| 1308 | +	{ | |
| 1309 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 1310 | + $template_fields = ''; | |
| 1311 | + $sidebar_fields = ''; | |
| 1312 | + // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have | |
| 1313 | + // valid html in the templates. | |
| 1314 | +		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2); | |
| 1315 | + | |
| 1316 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) | |
| 1317 | + ? absint($this->_req_data['id']) | |
| 1318 | + : false; | |
| 1319 | + | |
| 1320 | + $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) | |
| 1321 | + ? absint($this->_req_data['evt_id']) | |
| 1322 | + : false; | |
| 1323 | + | |
| 1324 | + $this->_set_shortcodes(); // this also sets the _message_template property. | |
| 1325 | + $message_template_group = $this->_message_template_group; | |
| 1326 | + $c_label = $message_template_group->context_label(); | |
| 1327 | + $c_config = $message_template_group->contexts_config(); | |
| 1328 | + | |
| 1329 | + reset($c_config); | |
| 1330 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) | |
| 1331 | + ? strtolower($this->_req_data['context']) | |
| 1332 | + : key($c_config); | |
| 1333 | + | |
| 1334 | + | |
| 1335 | +		if (empty($GRP_ID)) { | |
| 1336 | + $action = 'insert_message_template'; | |
| 1337 | + $edit_message_template_form_url = add_query_arg( | |
| 1338 | + ['action' => $action, 'noheader' => true], | |
| 1339 | + EE_MSG_ADMIN_URL | |
| 1340 | + ); | |
| 1341 | +		} else { | |
| 1342 | + $action = 'update_message_template'; | |
| 1343 | + $edit_message_template_form_url = add_query_arg( | |
| 1344 | + ['action' => $action, 'noheader' => true], | |
| 1345 | + EE_MSG_ADMIN_URL | |
| 1346 | + ); | |
| 1347 | + } | |
| 1348 | + | |
| 1349 | + // set active messenger for this view | |
| 1350 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( | |
| 1351 | + $message_template_group->messenger() | |
| 1352 | + ); | |
| 1353 | + $this->_active_message_type_name = $message_template_group->message_type(); | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + // Do we have any validation errors? | |
| 1357 | + $validators = $this->_get_transient(); | |
| 1358 | + $v_fields = ! empty($validators) ? array_keys($validators) : []; | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + // we need to assemble the title from Various details | |
| 1362 | + $context_label = sprintf( | |
| 1363 | +			esc_html__('(%s %s)', 'event_espresso'), | |
| 1364 | + $c_config[ $context ]['label'], | |
| 1365 | + ucwords($c_label['label']) | |
| 1366 | + ); | |
| 1367 | + | |
| 1368 | + $title = sprintf( | |
| 1369 | +			esc_html__(' %s %s Template %s', 'event_espresso'), | |
| 1370 | + ucwords($message_template_group->messenger_obj()->label['singular']), | |
| 1371 | + ucwords($message_template_group->message_type_obj()->label['singular']), | |
| 1372 | + $context_label | |
| 1373 | + ); | |
| 1374 | + | |
| 1375 | + $this->_template_args['GRP_ID'] = $GRP_ID; | |
| 1376 | + $this->_template_args['message_template'] = $message_template_group; | |
| 1377 | + $this->_template_args['is_extra_fields'] = false; | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + // let's get EEH_MSG_Template so we can get template form fields | |
| 1381 | + $template_field_structure = EEH_MSG_Template::get_fields( | |
| 1382 | + $message_template_group->messenger(), | |
| 1383 | + $message_template_group->message_type() | |
| 1384 | + ); | |
| 1385 | + | |
| 1386 | +		if (! $template_field_structure) { | |
| 1387 | + $template_field_structure = false; | |
| 1388 | + $template_fields = esc_html__( | |
| 1389 | + 'There was an error in assembling the fields for this display (you should see an error message)', | |
| 1390 | + 'event_espresso' | |
| 1391 | + ); | |
| 1392 | + } | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + $message_templates = $message_template_group->context_templates(); | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + // if we have the extra key.. then we need to remove the content index from the template_field_structure as it | |
| 1399 | + // will get handled in the "extra" array. | |
| 1400 | +		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { | |
| 1401 | +			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { | |
| 1402 | + unset($template_field_structure[ $context ][ $reference_field ]); | |
| 1403 | + } | |
| 1404 | + } | |
| 1405 | + | |
| 1406 | + // let's loop through the template_field_structure and actually assemble the input fields! | |
| 1407 | +		if (! empty($template_field_structure)) { | |
| 1408 | +			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { | |
| 1409 | + // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in | |
| 1410 | + // the extra array and reset them. | |
| 1411 | +				if ($template_field === 'extra') { | |
| 1412 | + $this->_template_args['is_extra_fields'] = true; | |
| 1413 | +					foreach ($field_setup_array as $reference_field => $new_fields_array) { | |
| 1414 | + $message_template = $message_templates[ $context ][ $reference_field ]; | |
| 1415 | + $content = $message_template instanceof EE_Message_Template | |
| 1416 | +							? $message_template->get('MTP_content') | |
| 1417 | + : ''; | |
| 1418 | +						foreach ($new_fields_array as $extra_field => $extra_array) { | |
| 1419 | + // let's verify if we need this extra field via the shortcodes parameter. | |
| 1420 | + $continue = false; | |
| 1421 | +							if (isset($extra_array['shortcodes_required'])) { | |
| 1422 | +								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { | |
| 1423 | +									if (! array_key_exists($shortcode, $this->_shortcodes)) { | |
| 1424 | + $continue = true; | |
| 1425 | + } | |
| 1426 | + } | |
| 1427 | +								if ($continue) { | |
| 1428 | + continue; | |
| 1429 | + } | |
| 1430 | + } | |
| 1431 | + | |
| 1432 | + $field_id = $reference_field | |
| 1433 | + . '-' | |
| 1434 | + . $extra_field | |
| 1435 | + . '-content'; | |
| 1436 | + $template_form_fields[ $field_id ] = $extra_array; | |
| 1437 | + $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' | |
| 1438 | + . $reference_field | |
| 1439 | + . '][content][' | |
| 1440 | + . $extra_field . ']'; | |
| 1441 | + $css_class = isset($extra_array['css_class']) | |
| 1442 | + ? $extra_array['css_class'] | |
| 1443 | + : ''; | |
| 1444 | + | |
| 1445 | + $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) | |
| 1446 | + && in_array($extra_field, $v_fields, true) | |
| 1447 | + && ( | |
| 1448 | + is_array($validators[ $extra_field ]) | |
| 1449 | + && isset($validators[ $extra_field ]['msg']) | |
| 1450 | + ) | |
| 1451 | + ? 'validate-error ' . $css_class | |
| 1452 | + : $css_class; | |
| 1453 | + | |
| 1454 | + $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) | |
| 1455 | + && isset($content[ $extra_field ]) | |
| 1456 | + ? $content[ $extra_field ] | |
| 1457 | + : ''; | |
| 1458 | + | |
| 1459 | + // do we have a validation error? if we do then let's use that value instead | |
| 1460 | + $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ]) | |
| 1461 | + ? $validators[ $extra_field ]['value'] | |
| 1462 | + : $template_form_fields[ $field_id ]['value']; | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; | |
| 1466 | + | |
| 1467 | + // shortcode selector | |
| 1468 | + $field_name_to_use = $extra_field === 'main' | |
| 1469 | + ? 'content' | |
| 1470 | + : $extra_field; | |
| 1471 | + $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( | |
| 1472 | + $field_name_to_use, | |
| 1473 | + $field_id | |
| 1474 | + ); | |
| 1475 | + | |
| 1476 | +							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { | |
| 1477 | + // we want to decode the entities | |
| 1478 | + $template_form_fields[ $field_id ]['value'] = | |
| 1479 | + $template_form_fields[ $field_id ]['value']; | |
| 1480 | + } | |
| 1481 | + } | |
| 1482 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; | |
| 1483 | + $templatefield_templatename_id = $reference_field . '-name'; | |
| 1484 | + | |
| 1485 | + $template_form_fields[ $templatefield_MTP_id ] = [ | |
| 1486 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', | |
| 1487 | + 'label' => null, | |
| 1488 | + 'input' => 'hidden', | |
| 1489 | + 'type' => 'int', | |
| 1490 | + 'required' => false, | |
| 1491 | + 'validation' => false, | |
| 1492 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', | |
| 1493 | + 'css_class' => '', | |
| 1494 | + 'format' => '%d', | |
| 1495 | + 'db-col' => 'MTP_ID', | |
| 1496 | + ]; | |
| 1497 | + | |
| 1498 | + $template_form_fields[ $templatefield_templatename_id ] = [ | |
| 1499 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', | |
| 1500 | + 'label' => null, | |
| 1501 | + 'input' => 'hidden', | |
| 1502 | + 'type' => 'string', | |
| 1503 | + 'required' => false, | |
| 1504 | + 'validation' => true, | |
| 1505 | + 'value' => $reference_field, | |
| 1506 | + 'css_class' => '', | |
| 1507 | + 'format' => '%s', | |
| 1508 | + 'db-col' => 'MTP_template_field', | |
| 1509 | + ]; | |
| 1510 | + } | |
| 1511 | + continue; // skip the next stuff, we got the necessary fields here for this dataset. | |
| 1512 | +				} else { | |
| 1513 | + $field_id = $template_field . '-content'; | |
| 1514 | + $template_form_fields[ $field_id ] = $field_setup_array; | |
| 1515 | + $template_form_fields[ $field_id ]['name'] = | |
| 1516 | + 'MTP_template_fields[' . $template_field . '][content]'; | |
| 1517 | + $message_template = | |
| 1518 | + isset($message_templates[ $context ][ $template_field ]) | |
| 1519 | + ? $message_templates[ $context ][ $template_field ] | |
| 1520 | + : null; | |
| 1521 | + $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) | |
| 1522 | + && is_array($message_templates[ $context ]) | |
| 1523 | + && $message_template instanceof EE_Message_Template | |
| 1524 | +						? $message_template->get('MTP_content') | |
| 1525 | + : ''; | |
| 1526 | + | |
| 1527 | + // do we have a validator error for this field? if we do then we'll use that value instead | |
| 1528 | + $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ]) | |
| 1529 | + ? $validators[ $template_field ]['value'] | |
| 1530 | + : $template_form_fields[ $field_id ]['value']; | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; | |
| 1534 | + $css_class = isset($field_setup_array['css_class']) | |
| 1535 | + ? $field_setup_array['css_class'] | |
| 1536 | + : ''; | |
| 1537 | + $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) | |
| 1538 | + && in_array($template_field, $v_fields, true) | |
| 1539 | + && isset($validators[ $template_field ]['msg']) | |
| 1540 | + ? 'validate-error ' . $css_class | |
| 1541 | + : $css_class; | |
| 1542 | + | |
| 1543 | + // shortcode selector | |
| 1544 | + $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( | |
| 1545 | + $template_field, | |
| 1546 | + $field_id | |
| 1547 | + ); | |
| 1548 | + } | |
| 1549 | + | |
| 1550 | + // k took care of content field(s) now let's take care of others. | |
| 1551 | + | |
| 1552 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; | |
| 1553 | + $templatefield_field_templatename_id = $template_field . '-name'; | |
| 1554 | + | |
| 1555 | + // foreach template field there are actually two form fields created | |
| 1556 | + $template_form_fields[ $templatefield_MTP_id ] = [ | |
| 1557 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', | |
| 1558 | + 'label' => null, | |
| 1559 | + 'input' => 'hidden', | |
| 1560 | + 'type' => 'int', | |
| 1561 | + 'required' => false, | |
| 1562 | + 'validation' => true, | |
| 1563 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', | |
| 1564 | + 'css_class' => '', | |
| 1565 | + 'format' => '%d', | |
| 1566 | + 'db-col' => 'MTP_ID', | |
| 1567 | + ]; | |
| 1568 | + | |
| 1569 | + $template_form_fields[ $templatefield_field_templatename_id ] = [ | |
| 1570 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', | |
| 1571 | + 'label' => null, | |
| 1572 | + 'input' => 'hidden', | |
| 1573 | + 'type' => 'string', | |
| 1574 | + 'required' => false, | |
| 1575 | + 'validation' => true, | |
| 1576 | + 'value' => $template_field, | |
| 1577 | + 'css_class' => '', | |
| 1578 | + 'format' => '%s', | |
| 1579 | + 'db-col' => 'MTP_template_field', | |
| 1580 | + ]; | |
| 1581 | + } | |
| 1582 | + | |
| 1583 | + // add other fields | |
| 1584 | + $template_form_fields['ee-msg-current-context'] = [ | |
| 1585 | + 'name' => 'MTP_context', | |
| 1586 | + 'label' => null, | |
| 1587 | + 'input' => 'hidden', | |
| 1588 | + 'type' => 'string', | |
| 1589 | + 'required' => false, | |
| 1590 | + 'validation' => true, | |
| 1591 | + 'value' => $context, | |
| 1592 | + 'css_class' => '', | |
| 1593 | + 'format' => '%s', | |
| 1594 | + 'db-col' => 'MTP_context', | |
| 1595 | + ]; | |
| 1596 | + | |
| 1597 | + $template_form_fields['ee-msg-grp-id'] = [ | |
| 1598 | + 'name' => 'GRP_ID', | |
| 1599 | + 'label' => null, | |
| 1600 | + 'input' => 'hidden', | |
| 1601 | + 'type' => 'int', | |
| 1602 | + 'required' => false, | |
| 1603 | + 'validation' => true, | |
| 1604 | + 'value' => $GRP_ID, | |
| 1605 | + 'css_class' => '', | |
| 1606 | + 'format' => '%d', | |
| 1607 | + 'db-col' => 'GRP_ID', | |
| 1608 | + ]; | |
| 1609 | + | |
| 1610 | + $template_form_fields['ee-msg-messenger'] = [ | |
| 1611 | + 'name' => 'MTP_messenger', | |
| 1612 | + 'label' => null, | |
| 1613 | + 'input' => 'hidden', | |
| 1614 | + 'type' => 'string', | |
| 1615 | + 'required' => false, | |
| 1616 | + 'validation' => true, | |
| 1617 | + 'value' => $message_template_group->messenger(), | |
| 1618 | + 'css_class' => '', | |
| 1619 | + 'format' => '%s', | |
| 1620 | + 'db-col' => 'MTP_messenger', | |
| 1621 | + ]; | |
| 1622 | + | |
| 1623 | + $template_form_fields['ee-msg-message-type'] = [ | |
| 1624 | + 'name' => 'MTP_message_type', | |
| 1625 | + 'label' => null, | |
| 1626 | + 'input' => 'hidden', | |
| 1627 | + 'type' => 'string', | |
| 1628 | + 'required' => false, | |
| 1629 | + 'validation' => true, | |
| 1630 | + 'value' => $message_template_group->message_type(), | |
| 1631 | + 'css_class' => '', | |
| 1632 | + 'format' => '%s', | |
| 1633 | + 'db-col' => 'MTP_message_type', | |
| 1634 | + ]; | |
| 1635 | + | |
| 1636 | + $sidebar_form_fields['ee-msg-is-global'] = [ | |
| 1637 | + 'name' => 'MTP_is_global', | |
| 1638 | +				'label'      => esc_html__('Global Template', 'event_espresso'), | |
| 1639 | + 'input' => 'hidden', | |
| 1640 | + 'type' => 'int', | |
| 1641 | + 'required' => false, | |
| 1642 | + 'validation' => true, | |
| 1643 | +				'value'      => $message_template_group->get('MTP_is_global'), | |
| 1644 | + 'css_class' => '', | |
| 1645 | + 'format' => '%d', | |
| 1646 | + 'db-col' => 'MTP_is_global', | |
| 1647 | + ]; | |
| 1648 | + | |
| 1649 | + $sidebar_form_fields['ee-msg-is-override'] = [ | |
| 1650 | + 'name' => 'MTP_is_override', | |
| 1651 | +				'label'      => esc_html__('Override all custom', 'event_espresso'), | |
| 1652 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', | |
| 1653 | + 'type' => 'int', | |
| 1654 | + 'required' => false, | |
| 1655 | + 'validation' => true, | |
| 1656 | +				'value'      => $message_template_group->get('MTP_is_override'), | |
| 1657 | + 'css_class' => '', | |
| 1658 | + 'format' => '%d', | |
| 1659 | + 'db-col' => 'MTP_is_override', | |
| 1660 | + ]; | |
| 1661 | + | |
| 1662 | + $sidebar_form_fields['ee-msg-is-active'] = [ | |
| 1663 | + 'name' => 'MTP_is_active', | |
| 1664 | +				'label'      => esc_html__('Active Template', 'event_espresso'), | |
| 1665 | + 'input' => 'hidden', | |
| 1666 | + 'type' => 'int', | |
| 1667 | + 'required' => false, | |
| 1668 | + 'validation' => true, | |
| 1669 | + 'value' => $message_template_group->is_active(), | |
| 1670 | + 'css_class' => '', | |
| 1671 | + 'format' => '%d', | |
| 1672 | + 'db-col' => 'MTP_is_active', | |
| 1673 | + ]; | |
| 1674 | + | |
| 1675 | + $sidebar_form_fields['ee-msg-deleted'] = [ | |
| 1676 | + 'name' => 'MTP_deleted', | |
| 1677 | + 'label' => null, | |
| 1678 | + 'input' => 'hidden', | |
| 1679 | + 'type' => 'int', | |
| 1680 | + 'required' => false, | |
| 1681 | + 'validation' => true, | |
| 1682 | +				'value'      => $message_template_group->get('MTP_deleted'), | |
| 1683 | + 'css_class' => '', | |
| 1684 | + 'format' => '%d', | |
| 1685 | + 'db-col' => 'MTP_deleted', | |
| 1686 | + ]; | |
| 1687 | + $sidebar_form_fields['ee-msg-author'] = [ | |
| 1688 | + 'name' => 'MTP_user_id', | |
| 1689 | +				'label'      => esc_html__('Author', 'event_espresso'), | |
| 1690 | + 'input' => 'hidden', | |
| 1691 | + 'type' => 'int', | |
| 1692 | + 'required' => false, | |
| 1693 | + 'validation' => false, | |
| 1694 | + 'value' => $message_template_group->user(), | |
| 1695 | + 'format' => '%d', | |
| 1696 | + 'db-col' => 'MTP_user_id', | |
| 1697 | + ]; | |
| 1698 | + | |
| 1699 | + $sidebar_form_fields['ee-msg-route'] = [ | |
| 1700 | + 'name' => 'action', | |
| 1701 | + 'input' => 'hidden', | |
| 1702 | + 'type' => 'string', | |
| 1703 | + 'value' => $action, | |
| 1704 | + ]; | |
| 1705 | + | |
| 1706 | + $sidebar_form_fields['ee-msg-id'] = [ | |
| 1707 | + 'name' => 'id', | |
| 1708 | + 'input' => 'hidden', | |
| 1709 | + 'type' => 'int', | |
| 1710 | + 'value' => $GRP_ID, | |
| 1711 | + ]; | |
| 1712 | + $sidebar_form_fields['ee-msg-evt-nonce'] = [ | |
| 1713 | + 'name' => $action . '_nonce', | |
| 1714 | + 'input' => 'hidden', | |
| 1715 | + 'type' => 'string', | |
| 1716 | + 'value' => wp_create_nonce($action . '_nonce'), | |
| 1717 | + ]; | |
| 1718 | + | |
| 1719 | +			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { | |
| 1720 | + $sidebar_form_fields['ee-msg-template-switch'] = [ | |
| 1721 | + 'name' => 'template_switch', | |
| 1722 | + 'input' => 'hidden', | |
| 1723 | + 'type' => 'int', | |
| 1724 | + 'value' => 1, | |
| 1725 | + ]; | |
| 1726 | + } | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); | |
| 1730 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); | |
| 1731 | + } //end if ( !empty($template_field_structure) ) | |
| 1732 | + | |
| 1733 | + // set extra content for publish box | |
| 1734 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; | |
| 1735 | + $this->_set_publish_post_box_vars( | |
| 1736 | + 'id', | |
| 1737 | + $GRP_ID, | |
| 1738 | + false, | |
| 1739 | + add_query_arg( | |
| 1740 | + ['action' => 'global_mtps'], | |
| 1741 | + $this->_admin_base_url | |
| 1742 | + ) | |
| 1743 | + ); | |
| 1744 | + | |
| 1745 | + // add preview button | |
| 1746 | + $preview_url = parent::add_query_args_and_nonce( | |
| 1747 | + [ | |
| 1748 | + 'message_type' => $message_template_group->message_type(), | |
| 1749 | + 'messenger' => $message_template_group->messenger(), | |
| 1750 | + 'context' => $context, | |
| 1751 | + 'GRP_ID' => $GRP_ID, | |
| 1752 | + 'evt_id' => $EVT_ID, | |
| 1753 | + 'action' => 'preview_message', | |
| 1754 | + ], | |
| 1755 | + $this->_admin_base_url | |
| 1756 | + ); | |
| 1757 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' | |
| 1758 | +						  . esc_html__('Preview', 'event_espresso') | |
| 1759 | + . '</a>'; | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + // setup context switcher | |
| 1763 | + $context_switcher_args = [ | |
| 1764 | + 'page' => 'espresso_messages', | |
| 1765 | + 'action' => 'edit_message_template', | |
| 1766 | + 'id' => $GRP_ID, | |
| 1767 | + 'evt_id' => $EVT_ID, | |
| 1768 | + 'context' => $context, | |
| 1769 | + 'extra' => $preview_button, | |
| 1770 | + ]; | |
| 1771 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + // main box | |
| 1775 | + $this->_template_args['template_fields'] = $template_fields; | |
| 1776 | + $this->_template_args['sidebar_box_id'] = 'details'; | |
| 1777 | + $this->_template_args['action'] = $action; | |
| 1778 | + $this->_template_args['context'] = $context; | |
| 1779 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; | |
| 1780 | + $this->_template_args['learn_more_about_message_templates_link'] = | |
| 1781 | + $this->_learn_more_about_message_templates_link(); | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); | |
| 1785 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( | |
| 1786 | + $message_template_group, | |
| 1787 | + $context, | |
| 1788 | + $context_label | |
| 1789 | + ); | |
| 1790 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); | |
| 1791 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); | |
| 1792 | + | |
| 1793 | + $this->_template_path = $this->_template_args['GRP_ID'] | |
| 1794 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' | |
| 1795 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; | |
| 1796 | + | |
| 1797 | + // send along EE_Message_Template_Group object for further template use. | |
| 1798 | + $this->_template_args['MTP'] = $message_template_group; | |
| 1799 | + | |
| 1800 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( | |
| 1801 | + $this->_template_path, | |
| 1802 | + $this->_template_args, | |
| 1803 | + true | |
| 1804 | + ); | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + // finally, let's set the admin_page title | |
| 1808 | +		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title); | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + // we need to take care of setting the shortcodes property for use elsewhere. | |
| 1812 | + $this->_set_shortcodes(); | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + // final template wrapper | |
| 1816 | + $this->display_admin_page_with_sidebar(); | |
| 1817 | + } | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + public function filter_tinymce_init($mceInit, $editor_id) | |
| 1821 | +	{ | |
| 1822 | + return $mceInit; | |
| 1823 | + } | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + public function add_context_switcher() | |
| 1827 | +	{ | |
| 1828 | + return $this->_context_switcher; | |
| 1829 | + } | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + /** | |
| 1833 | + * Adds the activation/deactivation toggle for the message template context. | |
| 1834 | + * | |
| 1835 | + * @param EE_Message_Template_Group $message_template_group | |
| 1836 | + * @param string $context | |
| 1837 | + * @param string $context_label | |
| 1838 | + * @return string | |
| 1839 | + * @throws DomainException | |
| 1840 | + * @throws EE_Error | |
| 1841 | + * @throws InvalidIdentifierException | |
| 1842 | + */ | |
| 1843 | + protected function add_active_context_element( | |
| 1844 | + EE_Message_Template_Group $message_template_group, | |
| 1845 | + $context, | |
| 1846 | + $context_label | |
| 1847 | +	) { | |
| 1848 | + $template_args = [ | |
| 1849 | + 'context' => $context, | |
| 1850 | +			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'), | |
| 1851 | + 'is_active' => $message_template_group->is_context_active($context), | |
| 1852 | + 'on_off_action' => $message_template_group->is_context_active($context) | |
| 1853 | + ? 'context-off' | |
| 1854 | + : 'context-on', | |
| 1855 | +			'context_label'             => str_replace(['(', ')'], '', $context_label), | |
| 1856 | + 'message_template_group_id' => $message_template_group->ID(), | |
| 1857 | + ]; | |
| 1858 | + return EEH_Template::display_template( | |
| 1859 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', | |
| 1860 | + $template_args, | |
| 1861 | + true | |
| 1862 | + ); | |
| 1863 | + } | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + /** | |
| 1867 | + * Ajax callback for `toggle_context_template` ajax action. | |
| 1868 | + * Handles toggling the message context on or off. | |
| 1869 | + * | |
| 1870 | + * @throws EE_Error | |
| 1871 | + * @throws InvalidArgumentException | |
| 1872 | + * @throws InvalidDataTypeException | |
| 1873 | + * @throws InvalidIdentifierException | |
| 1874 | + * @throws InvalidInterfaceException | |
| 1875 | + */ | |
| 1876 | + public function toggle_context_template() | |
| 1877 | +	{ | |
| 1878 | + $success = true; | |
| 1879 | + // check for required data | |
| 1880 | + if ( | |
| 1881 | + ! isset( | |
| 1882 | + $this->_req_data['message_template_group_id'], | |
| 1883 | + $this->_req_data['context'], | |
| 1884 | + $this->_req_data['status'] | |
| 1885 | + ) | |
| 1886 | +		) { | |
| 1887 | + EE_Error::add_error( | |
| 1888 | +				esc_html__('Required data for doing this action is not available.', 'event_espresso'), | |
| 1889 | + __FILE__, | |
| 1890 | + __FUNCTION__, | |
| 1891 | + __LINE__ | |
| 1892 | + ); | |
| 1893 | + $success = false; | |
| 1894 | + } | |
| 1895 | + | |
| 1896 | + $nonce = isset($this->_req_data['toggle_context_nonce']) | |
| 1897 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) | |
| 1898 | + : ''; | |
| 1899 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; | |
| 1900 | + $this->_verify_nonce($nonce, $nonce_ref); | |
| 1901 | + $status = $this->_req_data['status']; | |
| 1902 | +		if ($status !== 'off' && $status !== 'on') { | |
| 1903 | + EE_Error::add_error( | |
| 1904 | + sprintf( | |
| 1905 | +					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | |
| 1906 | + $this->_req_data['status'] | |
| 1907 | + ), | |
| 1908 | + __FILE__, | |
| 1909 | + __FUNCTION__, | |
| 1910 | + __LINE__ | |
| 1911 | + ); | |
| 1912 | + $success = false; | |
| 1913 | + } | |
| 1914 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( | |
| 1915 | + $this->_req_data['message_template_group_id'] | |
| 1916 | + ); | |
| 1917 | +		if (! $message_template_group instanceof EE_Message_Template_Group) { | |
| 1918 | + EE_Error::add_error( | |
| 1919 | + sprintf( | |
| 1920 | + esc_html__( | |
| 1921 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', | |
| 1922 | + 'event_espresso' | |
| 1923 | + ), | |
| 1924 | + $this->_req_data['message_template_group_id'], | |
| 1925 | + 'EE_Message_Template_Group' | |
| 1926 | + ), | |
| 1927 | + __FILE__, | |
| 1928 | + __FUNCTION__, | |
| 1929 | + __LINE__ | |
| 1930 | + ); | |
| 1931 | + $success = false; | |
| 1932 | + } | |
| 1933 | +		if ($success) { | |
| 1934 | + $success = $status === 'off' | |
| 1935 | + ? $message_template_group->deactivate_context($this->_req_data['context']) | |
| 1936 | + : $message_template_group->activate_context($this->_req_data['context']); | |
| 1937 | + } | |
| 1938 | + $this->_template_args['success'] = $success; | |
| 1939 | + $this->_return_json(); | |
| 1940 | + } | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + public function _add_form_element_before() | |
| 1944 | +	{ | |
| 1945 | + return '<form method="post" action="' | |
| 1946 | + . $this->_template_args['edit_message_template_form_url'] | |
| 1947 | + . '" id="ee-msg-edit-frm">'; | |
| 1948 | + } | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + public function _add_form_element_after() | |
| 1952 | +	{ | |
| 1953 | + return '</form>'; | |
| 1954 | + } | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + /** | |
| 1958 | + * This executes switching the template pack for a message template. | |
| 1959 | + * | |
| 1960 | + * @throws EE_Error | |
| 1961 | + * @throws InvalidDataTypeException | |
| 1962 | + * @throws InvalidInterfaceException | |
| 1963 | + * @throws InvalidArgumentException | |
| 1964 | + * @throws ReflectionException | |
| 1965 | + * @since 4.5.0 | |
| 1966 | + */ | |
| 1967 | + public function switch_template_pack() | |
| 1968 | +	{ | |
| 1969 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; | |
| 1970 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; | |
| 1971 | + | |
| 1972 | + // verify we have needed values. | |
| 1973 | +		if (empty($GRP_ID) || empty($template_pack)) { | |
| 1974 | + $this->_template_args['error'] = true; | |
| 1975 | + EE_Error::add_error( | |
| 1976 | +				esc_html__('The required date for switching templates is not available.', 'event_espresso'), | |
| 1977 | + __FILE__, | |
| 1978 | + __FUNCTION__, | |
| 1979 | + __LINE__ | |
| 1980 | + ); | |
| 1981 | +		} else { | |
| 1982 | + // get template, set the new template_pack and then reset to default | |
| 1983 | + /** @type EE_Message_Template_Group $message_template_group */ | |
| 1984 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); | |
| 1985 | + | |
| 1986 | + $message_template_group->set_template_pack_name($template_pack); | |
| 1987 | + $this->_req_data['msgr'] = $message_template_group->messenger(); | |
| 1988 | + $this->_req_data['mt'] = $message_template_group->message_type(); | |
| 1989 | + | |
| 1990 | + $query_args = $this->_reset_to_default_template(); | |
| 1991 | + | |
| 1992 | +			if (empty($query_args['id'])) { | |
| 1993 | + EE_Error::add_error( | |
| 1994 | + esc_html__( | |
| 1995 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', | |
| 1996 | + 'event_espresso' | |
| 1997 | + ), | |
| 1998 | + __FILE__, | |
| 1999 | + __FUNCTION__, | |
| 2000 | + __LINE__ | |
| 2001 | + ); | |
| 2002 | + $this->_template_args['error'] = true; | |
| 2003 | +			} else { | |
| 2004 | + $template_label = $message_template_group->get_template_pack()->label; | |
| 2005 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); | |
| 2006 | + EE_Error::add_success( | |
| 2007 | + sprintf( | |
| 2008 | + esc_html__( | |
| 2009 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', | |
| 2010 | + 'event_espresso' | |
| 2011 | + ), | |
| 2012 | + $template_label, | |
| 2013 | + $template_pack_labels->template_pack | |
| 2014 | + ) | |
| 2015 | + ); | |
| 2016 | + // generate the redirect url for js. | |
| 2017 | + $url = self::add_query_args_and_nonce( | |
| 2018 | + $query_args, | |
| 2019 | + $this->_admin_base_url | |
| 2020 | + ); | |
| 2021 | + $this->_template_args['data']['redirect_url'] = $url; | |
| 2022 | + $this->_template_args['success'] = true; | |
| 2023 | + } | |
| 2024 | + | |
| 2025 | + $this->_return_json(); | |
| 2026 | + } | |
| 2027 | + } | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + /** | |
| 2031 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if | |
| 2032 | + * they want. | |
| 2033 | + * | |
| 2034 | + * @access protected | |
| 2035 | + * @return array|null | |
| 2036 | + * @throws EE_Error | |
| 2037 | + * @throws InvalidArgumentException | |
| 2038 | + * @throws InvalidDataTypeException | |
| 2039 | + * @throws InvalidInterfaceException | |
| 2040 | + */ | |
| 2041 | + protected function _reset_to_default_template() | |
| 2042 | +	{ | |
| 2043 | + | |
| 2044 | + $templates = []; | |
| 2045 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; | |
| 2046 | + // we need to make sure we've got the info we need. | |
| 2047 | +		if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { | |
| 2048 | + EE_Error::add_error( | |
| 2049 | + esc_html__( | |
| 2050 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', | |
| 2051 | + 'event_espresso' | |
| 2052 | + ), | |
| 2053 | + __FILE__, | |
| 2054 | + __FUNCTION__, | |
| 2055 | + __LINE__ | |
| 2056 | + ); | |
| 2057 | + } | |
| 2058 | + | |
| 2059 | + // all templates will be reset to whatever the defaults are | |
| 2060 | + // for the global template matching the messenger and message type. | |
| 2061 | + $success = ! empty($GRP_ID) ? true : false; | |
| 2062 | + | |
| 2063 | +		if ($success) { | |
| 2064 | + // let's first determine if the incoming template is a global template, | |
| 2065 | + // if it isn't then we need to get the global template matching messenger and message type. | |
| 2066 | + // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. | |
| 2070 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); | |
| 2071 | + | |
| 2072 | +			if ($success) { | |
| 2073 | + // if successfully deleted, lets generate the new ones. | |
| 2074 | + // Note. We set GLOBAL to true, because resets on ANY template | |
| 2075 | + // will use the related global template defaults for regeneration. | |
| 2076 | + // This means that if a custom template is reset it resets to whatever the related global template is. | |
| 2077 | + // HOWEVER, we DO keep the template pack and template variation set | |
| 2078 | + // for the current custom template when resetting. | |
| 2079 | + $templates = $this->_generate_new_templates( | |
| 2080 | + $this->_req_data['msgr'], | |
| 2081 | + $this->_req_data['mt'], | |
| 2082 | + $GRP_ID, | |
| 2083 | + true | |
| 2084 | + ); | |
| 2085 | + } | |
| 2086 | + } | |
| 2087 | + | |
| 2088 | + // any error messages? | |
| 2089 | +		if (! $success) { | |
| 2090 | + EE_Error::add_error( | |
| 2091 | + esc_html__( | |
| 2092 | + 'Something went wrong with deleting existing templates. Unable to reset to default', | |
| 2093 | + 'event_espresso' | |
| 2094 | + ), | |
| 2095 | + __FILE__, | |
| 2096 | + __FUNCTION__, | |
| 2097 | + __LINE__ | |
| 2098 | + ); | |
| 2099 | + } | |
| 2100 | + | |
| 2101 | + // all good, let's add a success message! | |
| 2102 | +		if ($success && ! empty($templates)) { | |
| 2103 | + // the info for the template we generated is the first element in the returned array | |
| 2104 | + // $templates = $templates[0]; | |
| 2105 | + EE_Error::overwrite_success(); | |
| 2106 | +			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso')); | |
| 2107 | + } | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + $query_args = [ | |
| 2111 | + 'id' => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null, | |
| 2112 | + 'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null, | |
| 2113 | + 'action' => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps', | |
| 2114 | + ]; | |
| 2115 | + | |
| 2116 | + // if called via ajax then we return query args otherwise redirect | |
| 2117 | +		if (defined('DOING_AJAX') && DOING_AJAX) { | |
| 2118 | + return $query_args; | |
| 2119 | +		} else { | |
| 2120 | + $this->_redirect_after_action(false, '', '', $query_args, true); | |
| 2121 | + | |
| 2122 | + return null; | |
| 2123 | + } | |
| 2124 | + } | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + /** | |
| 2128 | + * Retrieve and set the message preview for display. | |
| 2129 | + * | |
| 2130 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. | |
| 2131 | + * @return string | |
| 2132 | + * @throws ReflectionException | |
| 2133 | + * @throws EE_Error | |
| 2134 | + * @throws InvalidArgumentException | |
| 2135 | + * @throws InvalidDataTypeException | |
| 2136 | + * @throws InvalidInterfaceException | |
| 2137 | + */ | |
| 2138 | + public function _preview_message($send = false) | |
| 2139 | +	{ | |
| 2140 | + // first make sure we've got the necessary parameters | |
| 2141 | + if ( | |
| 2142 | + ! ( | |
| 2143 | + $this->_req_data['message_type'] | |
| 2144 | + && $this->_req_data['messenger'] | |
| 2145 | + && $this->_req_data['GRP_ID'] | |
| 2146 | + ) | |
| 2147 | +		) { | |
| 2148 | + EE_Error::add_error( | |
| 2149 | +				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), | |
| 2150 | + __FILE__, | |
| 2151 | + __FUNCTION__, | |
| 2152 | + __LINE__ | |
| 2153 | + ); | |
| 2154 | + } | |
| 2155 | + | |
| 2156 | + // get the preview! | |
| 2157 | + $preview = EED_Messages::preview_message( | |
| 2158 | + $this->_req_data['message_type'], | |
| 2159 | + $this->_req_data['context'], | |
| 2160 | + $this->_req_data['messenger'], | |
| 2161 | + $send | |
| 2162 | + ); | |
| 2163 | + | |
| 2164 | +		if ($send) { | |
| 2165 | + return $preview; | |
| 2166 | + } | |
| 2167 | + | |
| 2168 | + // if we have an evt_id set on the request, use it. | |
| 2169 | + $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) | |
| 2170 | + ? absint($this->_req_data['evt_id']) | |
| 2171 | + : false; | |
| 2172 | + | |
| 2173 | + // let's add a button to go back to the edit view | |
| 2174 | + $query_args = [ | |
| 2175 | + 'id' => $this->_req_data['GRP_ID'], | |
| 2176 | + 'evt_id' => $EVT_ID, | |
| 2177 | + 'context' => $this->_req_data['context'], | |
| 2178 | + 'action' => 'edit_message_template', | |
| 2179 | + ]; | |
| 2180 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); | |
| 2181 | + $preview_button = '<a href="' | |
| 2182 | + . $go_back_url | |
| 2183 | + . '" class="button-secondary messages-preview-go-back-button">' | |
| 2184 | +								  . esc_html__('Go Back to Edit', 'event_espresso') | |
| 2185 | + . '</a>'; | |
| 2186 | + $message_types = $this->get_installed_message_types(); | |
| 2187 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); | |
| 2188 | + $active_messenger_label = $active_messenger instanceof EE_messenger | |
| 2189 | + ? ucwords($active_messenger->label['singular']) | |
| 2190 | +			: esc_html__('Unknown Messenger', 'event_espresso'); | |
| 2191 | + // let's provide a helpful title for context | |
| 2192 | + $preview_title = sprintf( | |
| 2193 | +			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), | |
| 2194 | + $active_messenger_label, | |
| 2195 | + ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular']) | |
| 2196 | + ); | |
| 2197 | +		if (empty($preview)) { | |
| 2198 | + $this->noEventsErrorMessage(); | |
| 2199 | + } | |
| 2200 | + // setup display of preview. | |
| 2201 | + $this->_admin_page_title = $preview_title; | |
| 2202 | + $this->_template_args['admin_page_title'] = $preview_title; | |
| 2203 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; | |
| 2204 | + $this->_template_args['data']['force_json'] = true; | |
| 2205 | + | |
| 2206 | + return ''; | |
| 2207 | + } | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + /** | |
| 2211 | + * Used to set an error if there are no events available for generating a preview/test send. | |
| 2212 | + * | |
| 2213 | + * @param bool $test_send Whether the error should be generated for the context of a test send. | |
| 2214 | + */ | |
| 2215 | + protected function noEventsErrorMessage($test_send = false) | |
| 2216 | +	{ | |
| 2217 | + $events_url = parent::add_query_args_and_nonce( | |
| 2218 | + [ | |
| 2219 | + 'action' => 'default', | |
| 2220 | + 'page' => 'espresso_events', | |
| 2221 | + ], | |
| 2222 | +			admin_url('admin.php') | |
| 2223 | + ); | |
| 2224 | + $message = $test_send | |
| 2225 | + ? esc_html__( | |
| 2226 | + 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!', | |
| 2227 | + 'event_espresso' | |
| 2228 | + ) | |
| 2229 | + : esc_html__( | |
| 2230 | + 'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!', | |
| 2231 | + 'event_espresso' | |
| 2232 | + ); | |
| 2233 | + | |
| 2234 | + EE_Error::add_attention( | |
| 2235 | + sprintf( | |
| 2236 | + $message, | |
| 2237 | +				"<a href='{$events_url}'>", | |
| 2238 | + '</a>' | |
| 2239 | + ) | |
| 2240 | + ); | |
| 2241 | + } | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + /** | |
| 2245 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it | |
| 2246 | + * gets called automatically. | |
| 2247 | + * | |
| 2248 | + * @return string | |
| 2249 | + * @since 4.5.0 | |
| 2250 | + * | |
| 2251 | + */ | |
| 2252 | + protected function _display_preview_message() | |
| 2253 | +	{ | |
| 2254 | + $this->display_admin_page_with_no_sidebar(); | |
| 2255 | + } | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + /** | |
| 2259 | + * registers metaboxes that should show up on the "edit_message_template" page | |
| 2260 | + * | |
| 2261 | + * @access protected | |
| 2262 | + * @return void | |
| 2263 | + */ | |
| 2264 | + protected function _register_edit_meta_boxes() | |
| 2265 | +	{ | |
| 2266 | + add_meta_box( | |
| 2267 | + 'mtp_valid_shortcodes', | |
| 2268 | +			esc_html__('Valid Shortcodes', 'event_espresso'), | |
| 2269 | + [$this, 'shortcode_meta_box'], | |
| 2270 | + $this->_current_screen->id, | |
| 2271 | + 'side', | |
| 2272 | + 'default' | |
| 2273 | + ); | |
| 2274 | + add_meta_box( | |
| 2275 | + 'mtp_extra_actions', | |
| 2276 | +			esc_html__('Extra Actions', 'event_espresso'), | |
| 2277 | + [$this, 'extra_actions_meta_box'], | |
| 2278 | + $this->_current_screen->id, | |
| 2279 | + 'side', | |
| 2280 | + 'high' | |
| 2281 | + ); | |
| 2282 | + add_meta_box( | |
| 2283 | + 'mtp_templates', | |
| 2284 | +			esc_html__('Template Styles', 'event_espresso'), | |
| 2285 | + [$this, 'template_pack_meta_box'], | |
| 2286 | + $this->_current_screen->id, | |
| 2287 | + 'side', | |
| 2288 | + 'high' | |
| 2289 | + ); | |
| 2290 | + } | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + /** | |
| 2294 | + * metabox content for all template pack and variation selection. | |
| 2295 | + * | |
| 2296 | + * @return string | |
| 2297 | + * @throws DomainException | |
| 2298 | + * @throws EE_Error | |
| 2299 | + * @throws InvalidArgumentException | |
| 2300 | + * @throws ReflectionException | |
| 2301 | + * @throws InvalidDataTypeException | |
| 2302 | + * @throws InvalidInterfaceException | |
| 2303 | + * @since 4.5.0 | |
| 2304 | + */ | |
| 2305 | + public function template_pack_meta_box() | |
| 2306 | +	{ | |
| 2307 | + $this->_set_message_template_group(); | |
| 2308 | + | |
| 2309 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); | |
| 2310 | + | |
| 2311 | + $tp_select_values = []; | |
| 2312 | + | |
| 2313 | +		foreach ($tp_collection as $tp) { | |
| 2314 | + // only include template packs that support this messenger and message type! | |
| 2315 | + $supports = $tp->get_supports(); | |
| 2316 | + if ( | |
| 2317 | + ! isset($supports[ $this->_message_template_group->messenger() ]) | |
| 2318 | + || ! in_array( | |
| 2319 | + $this->_message_template_group->message_type(), | |
| 2320 | + $supports[ $this->_message_template_group->messenger() ], | |
| 2321 | + true | |
| 2322 | + ) | |
| 2323 | +			) { | |
| 2324 | + // not supported | |
| 2325 | + continue; | |
| 2326 | + } | |
| 2327 | + | |
| 2328 | + $tp_select_values[] = [ | |
| 2329 | + 'text' => $tp->label, | |
| 2330 | + 'id' => $tp->dbref, | |
| 2331 | + ]; | |
| 2332 | + } | |
| 2333 | + | |
| 2334 | + // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by | |
| 2335 | + // the default template pack. This still allows for the odd template pack to override. | |
| 2336 | +		if (empty($tp_select_values)) { | |
| 2337 | + $tp_select_values[] = [ | |
| 2338 | +				'text' => esc_html__('Default', 'event_espresso'), | |
| 2339 | + 'id' => 'default', | |
| 2340 | + ]; | |
| 2341 | + } | |
| 2342 | + | |
| 2343 | + // setup variation select values for the currently selected template. | |
| 2344 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( | |
| 2345 | + $this->_message_template_group->messenger(), | |
| 2346 | + $this->_message_template_group->message_type() | |
| 2347 | + ); | |
| 2348 | + $variations_select_values = []; | |
| 2349 | +		foreach ($variations as $variation => $label) { | |
| 2350 | + $variations_select_values[] = [ | |
| 2351 | + 'text' => $label, | |
| 2352 | + 'id' => $variation, | |
| 2353 | + ]; | |
| 2354 | + } | |
| 2355 | + | |
| 2356 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); | |
| 2357 | + | |
| 2358 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( | |
| 2359 | + 'MTP_template_pack', | |
| 2360 | + $tp_select_values, | |
| 2361 | + $this->_message_template_group->get_template_pack_name() | |
| 2362 | + ); | |
| 2363 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( | |
| 2364 | + 'MTP_template_variation', | |
| 2365 | + $variations_select_values, | |
| 2366 | + $this->_message_template_group->get_template_pack_variation() | |
| 2367 | + ); | |
| 2368 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; | |
| 2369 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; | |
| 2370 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; | |
| 2371 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; | |
| 2372 | + | |
| 2373 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; | |
| 2374 | + | |
| 2375 | + EEH_Template::display_template($template, $template_args); | |
| 2376 | + } | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + /** | |
| 2380 | + * This meta box holds any extra actions related to Message Templates | |
| 2381 | + * For now, this includes Resetting templates to defaults and sending a test email. | |
| 2382 | + * | |
| 2383 | + * @access public | |
| 2384 | + * @return void | |
| 2385 | + * @throws EE_Error | |
| 2386 | + */ | |
| 2387 | + public function extra_actions_meta_box() | |
| 2388 | +	{ | |
| 2389 | + $template_form_fields = []; | |
| 2390 | + | |
| 2391 | + $extra_args = [ | |
| 2392 | + 'msgr' => $this->_message_template_group->messenger(), | |
| 2393 | + 'mt' => $this->_message_template_group->message_type(), | |
| 2394 | + 'GRP_ID' => $this->_message_template_group->GRP_ID(), | |
| 2395 | + ]; | |
| 2396 | + // first we need to see if there are any fields | |
| 2397 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); | |
| 2398 | + | |
| 2399 | +		if (! empty($fields)) { | |
| 2400 | + // yup there be fields | |
| 2401 | +			foreach ($fields as $field => $config) { | |
| 2402 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; | |
| 2403 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); | |
| 2404 | + $default = isset($config['default']) ? $config['default'] : ''; | |
| 2405 | + $default = isset($config['value']) ? $config['value'] : $default; | |
| 2406 | + | |
| 2407 | + // if type is hidden and the value is empty | |
| 2408 | + // something may have gone wrong so let's correct with the defaults | |
| 2409 | + $fix = $config['input'] === 'hidden' | |
| 2410 | + && isset($existing[ $field ]) | |
| 2411 | + && empty($existing[ $field ]) | |
| 2412 | + ? $default | |
| 2413 | + : ''; | |
| 2414 | + $existing[ $field ] = isset($existing[ $field ]) && empty($fix) | |
| 2415 | + ? $existing[ $field ] | |
| 2416 | + : $fix; | |
| 2417 | + | |
| 2418 | + $template_form_fields[ $field_id ] = [ | |
| 2419 | + 'name' => 'test_settings_fld[' . $field . ']', | |
| 2420 | + 'label' => $config['label'], | |
| 2421 | + 'input' => $config['input'], | |
| 2422 | + 'type' => $config['type'], | |
| 2423 | + 'required' => $config['required'], | |
| 2424 | + 'validation' => $config['validation'], | |
| 2425 | + 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default, | |
| 2426 | + 'css_class' => $config['css_class'], | |
| 2427 | + 'options' => isset($config['options']) ? $config['options'] : [], | |
| 2428 | + 'default' => $default, | |
| 2429 | + 'format' => $config['format'], | |
| 2430 | + ]; | |
| 2431 | + } | |
| 2432 | + } | |
| 2433 | + | |
| 2434 | + $test_settings_html = ! empty($template_form_fields) | |
| 2435 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') | |
| 2436 | + : ''; | |
| 2437 | + | |
| 2438 | + // print out $test_settings_fields | |
| 2439 | +		if (! empty($test_settings_html)) { | |
| 2440 | + $test_settings_html .= '<input type="submit" class="button-primary mtp-test-button alignright" '; | |
| 2441 | + $test_settings_html .= 'name="test_button" value="'; | |
| 2442 | +			$test_settings_html .= esc_html__('Test Send', 'event_espresso'); | |
| 2443 | + $test_settings_html .= '" /><div style="clear:both"></div>'; | |
| 2444 | + } | |
| 2445 | + | |
| 2446 | + // and button | |
| 2447 | + $test_settings_html .= '<p>'; | |
| 2448 | +		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso'); | |
| 2449 | + $test_settings_html .= '</p>'; | |
| 2450 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; | |
| 2451 | + $test_settings_html .= $this->get_action_link_or_button( | |
| 2452 | + 'reset_to_default', | |
| 2453 | + 'reset', | |
| 2454 | + $extra_args, | |
| 2455 | + 'button-primary reset-default-button' | |
| 2456 | + ); | |
| 2457 | + $test_settings_html .= '</div><div style="clear:both"></div>'; | |
| 2458 | + echo $test_settings_html; // already escaped | |
| 2459 | + } | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + /** | |
| 2463 | + * This returns the shortcode selector skeleton for a given context and field. | |
| 2464 | + * | |
| 2465 | + * @param string $field The name of the field retrieving shortcodes for. | |
| 2466 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. | |
| 2467 | + * @return string | |
| 2468 | + * @throws DomainException | |
| 2469 | + * @throws EE_Error | |
| 2470 | + * @throws InvalidArgumentException | |
| 2471 | + * @throws ReflectionException | |
| 2472 | + * @throws InvalidDataTypeException | |
| 2473 | + * @throws InvalidInterfaceException | |
| 2474 | + * @since 4.9.rc.000 | |
| 2475 | + */ | |
| 2476 | + protected function _get_shortcode_selector($field, $linked_input_id) | |
| 2477 | +	{ | |
| 2478 | + $template_args = [ | |
| 2479 | + 'shortcodes' => $this->_get_shortcodes([$field], true), | |
| 2480 | + 'fieldname' => $field, | |
| 2481 | + 'linked_input_id' => $linked_input_id, | |
| 2482 | + ]; | |
| 2483 | + | |
| 2484 | + return EEH_Template::display_template( | |
| 2485 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', | |
| 2486 | + $template_args, | |
| 2487 | + true | |
| 2488 | + ); | |
| 2489 | + } | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + /** | |
| 2493 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template | |
| 2494 | + * page) | |
| 2495 | + * | |
| 2496 | + * @access public | |
| 2497 | + * @return void | |
| 2498 | + * @throws EE_Error | |
| 2499 | + * @throws InvalidArgumentException | |
| 2500 | + * @throws ReflectionException | |
| 2501 | + * @throws InvalidDataTypeException | |
| 2502 | + * @throws InvalidInterfaceException | |
| 2503 | + */ | |
| 2504 | + public function shortcode_meta_box() | |
| 2505 | +	{ | |
| 2506 | + $shortcodes = $this->_get_shortcodes([], false); | |
| 2507 | + // just make sure the shortcodes property is set | |
| 2508 | + // $messenger = $this->_message_template_group->messenger_obj(); | |
| 2509 | + // now let's set the content depending on the status of the shortcodes array | |
| 2510 | +		if (empty($shortcodes)) { | |
| 2511 | +			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; | |
| 2512 | + return; | |
| 2513 | + } | |
| 2514 | + ?> | |
| 2515 | 2515 | <div style="float:right; margin-top:10px"> | 
| 2516 | 2516 |              <?php echo $this->_get_help_tab_link('message_template_shortcodes'); // already escaped ?> | 
| 2517 | 2517 | </div> | 
| 2518 | 2518 | <p class="small-text"> | 
| 2519 | 2519 | <?php printf( | 
| 2520 | - esc_html__( | |
| 2521 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', | |
| 2522 | - 'event_espresso' | |
| 2523 | - ), | |
| 2524 | - '<span class="dashicons dashicons-menu"></span>' | |
| 2525 | - ); ?> | |
| 2520 | + esc_html__( | |
| 2521 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', | |
| 2522 | + 'event_espresso' | |
| 2523 | + ), | |
| 2524 | + '<span class="dashicons dashicons-menu"></span>' | |
| 2525 | + ); ?> | |
| 2526 | 2526 | </p> | 
| 2527 | 2527 | <?php | 
| 2528 | - } | |
| 2529 | - | |
| 2530 | - | |
| 2531 | - /** | |
| 2532 | - * used to set the $_shortcodes property for when its needed elsewhere. | |
| 2533 | - * | |
| 2534 | - * @access protected | |
| 2535 | - * @return void | |
| 2536 | - * @throws EE_Error | |
| 2537 | - * @throws InvalidArgumentException | |
| 2538 | - * @throws ReflectionException | |
| 2539 | - * @throws InvalidDataTypeException | |
| 2540 | - * @throws InvalidInterfaceException | |
| 2541 | - */ | |
| 2542 | - protected function _set_shortcodes() | |
| 2543 | -    { | |
| 2544 | - | |
| 2545 | - // no need to run this if the property is already set | |
| 2546 | -        if (! empty($this->_shortcodes)) { | |
| 2547 | - return; | |
| 2548 | - } | |
| 2549 | - | |
| 2550 | - $this->_shortcodes = $this->_get_shortcodes(); | |
| 2551 | - } | |
| 2552 | - | |
| 2553 | - | |
| 2554 | - /** | |
| 2555 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes | |
| 2556 | - * property) | |
| 2557 | - * | |
| 2558 | - * @access protected | |
| 2559 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes | |
| 2560 | - * for. Defaults to all (for the given context) | |
| 2561 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes | |
| 2562 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is | |
| 2563 | - * true just an array of shortcode/label pairs. | |
| 2564 | - * @throws EE_Error | |
| 2565 | - * @throws InvalidArgumentException | |
| 2566 | - * @throws ReflectionException | |
| 2567 | - * @throws InvalidDataTypeException | |
| 2568 | - * @throws InvalidInterfaceException | |
| 2569 | - */ | |
| 2570 | - protected function _get_shortcodes($fields = [], $merged = true) | |
| 2571 | -    { | |
| 2572 | - $this->_set_message_template_group(); | |
| 2573 | - | |
| 2574 | - // we need the messenger and message template to retrieve the valid shortcodes array. | |
| 2575 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) | |
| 2576 | - ? absint($this->_req_data['id']) | |
| 2577 | - : false; | |
| 2578 | - $context = isset($this->_req_data['context']) | |
| 2579 | - ? $this->_req_data['context'] | |
| 2580 | - : key($this->_message_template_group->contexts_config()); | |
| 2581 | - | |
| 2582 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : []; | |
| 2583 | - } | |
| 2584 | - | |
| 2585 | - | |
| 2586 | - /** | |
| 2587 | - * This sets the _message_template property (containing the called message_template object) | |
| 2588 | - * | |
| 2589 | - * @access protected | |
| 2590 | - * @return void | |
| 2591 | - * @throws EE_Error | |
| 2592 | - * @throws InvalidArgumentException | |
| 2593 | - * @throws ReflectionException | |
| 2594 | - * @throws InvalidDataTypeException | |
| 2595 | - * @throws InvalidInterfaceException | |
| 2596 | - */ | |
| 2597 | - protected function _set_message_template_group() | |
| 2598 | -    { | |
| 2599 | - | |
| 2600 | -        if (! empty($this->_message_template_group)) { | |
| 2601 | - return; | |
| 2602 | - } //get out if this is already set. | |
| 2603 | - | |
| 2604 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; | |
| 2605 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; | |
| 2606 | - | |
| 2607 | - // let's get the message templates | |
| 2608 | - $MTP = EEM_Message_Template_Group::instance(); | |
| 2609 | - | |
| 2610 | -        if (empty($GRP_ID)) { | |
| 2611 | - $this->_message_template_group = $MTP->create_default_object(); | |
| 2612 | -        } else { | |
| 2613 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); | |
| 2614 | - } | |
| 2615 | - | |
| 2616 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); | |
| 2617 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); | |
| 2618 | - } | |
| 2619 | - | |
| 2620 | - | |
| 2621 | - /** | |
| 2622 | - * sets up a context switcher for edit forms | |
| 2623 | - * | |
| 2624 | - * @access protected | |
| 2625 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form | |
| 2626 | - * @param array $args various things the context switcher needs. | |
| 2627 | - * @throws EE_Error | |
| 2628 | - */ | |
| 2629 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) | |
| 2630 | -    { | |
| 2631 | - $context_details = $template_group_object->contexts_config(); | |
| 2632 | - $context_label = $template_group_object->context_label(); | |
| 2633 | - ob_start(); | |
| 2634 | - ?> | |
| 2528 | + } | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + /** | |
| 2532 | + * used to set the $_shortcodes property for when its needed elsewhere. | |
| 2533 | + * | |
| 2534 | + * @access protected | |
| 2535 | + * @return void | |
| 2536 | + * @throws EE_Error | |
| 2537 | + * @throws InvalidArgumentException | |
| 2538 | + * @throws ReflectionException | |
| 2539 | + * @throws InvalidDataTypeException | |
| 2540 | + * @throws InvalidInterfaceException | |
| 2541 | + */ | |
| 2542 | + protected function _set_shortcodes() | |
| 2543 | +	{ | |
| 2544 | + | |
| 2545 | + // no need to run this if the property is already set | |
| 2546 | +		if (! empty($this->_shortcodes)) { | |
| 2547 | + return; | |
| 2548 | + } | |
| 2549 | + | |
| 2550 | + $this->_shortcodes = $this->_get_shortcodes(); | |
| 2551 | + } | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + /** | |
| 2555 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes | |
| 2556 | + * property) | |
| 2557 | + * | |
| 2558 | + * @access protected | |
| 2559 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes | |
| 2560 | + * for. Defaults to all (for the given context) | |
| 2561 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes | |
| 2562 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is | |
| 2563 | + * true just an array of shortcode/label pairs. | |
| 2564 | + * @throws EE_Error | |
| 2565 | + * @throws InvalidArgumentException | |
| 2566 | + * @throws ReflectionException | |
| 2567 | + * @throws InvalidDataTypeException | |
| 2568 | + * @throws InvalidInterfaceException | |
| 2569 | + */ | |
| 2570 | + protected function _get_shortcodes($fields = [], $merged = true) | |
| 2571 | +	{ | |
| 2572 | + $this->_set_message_template_group(); | |
| 2573 | + | |
| 2574 | + // we need the messenger and message template to retrieve the valid shortcodes array. | |
| 2575 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) | |
| 2576 | + ? absint($this->_req_data['id']) | |
| 2577 | + : false; | |
| 2578 | + $context = isset($this->_req_data['context']) | |
| 2579 | + ? $this->_req_data['context'] | |
| 2580 | + : key($this->_message_template_group->contexts_config()); | |
| 2581 | + | |
| 2582 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : []; | |
| 2583 | + } | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + /** | |
| 2587 | + * This sets the _message_template property (containing the called message_template object) | |
| 2588 | + * | |
| 2589 | + * @access protected | |
| 2590 | + * @return void | |
| 2591 | + * @throws EE_Error | |
| 2592 | + * @throws InvalidArgumentException | |
| 2593 | + * @throws ReflectionException | |
| 2594 | + * @throws InvalidDataTypeException | |
| 2595 | + * @throws InvalidInterfaceException | |
| 2596 | + */ | |
| 2597 | + protected function _set_message_template_group() | |
| 2598 | +	{ | |
| 2599 | + | |
| 2600 | +		if (! empty($this->_message_template_group)) { | |
| 2601 | + return; | |
| 2602 | + } //get out if this is already set. | |
| 2603 | + | |
| 2604 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; | |
| 2605 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; | |
| 2606 | + | |
| 2607 | + // let's get the message templates | |
| 2608 | + $MTP = EEM_Message_Template_Group::instance(); | |
| 2609 | + | |
| 2610 | +		if (empty($GRP_ID)) { | |
| 2611 | + $this->_message_template_group = $MTP->create_default_object(); | |
| 2612 | +		} else { | |
| 2613 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); | |
| 2614 | + } | |
| 2615 | + | |
| 2616 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); | |
| 2617 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); | |
| 2618 | + } | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + /** | |
| 2622 | + * sets up a context switcher for edit forms | |
| 2623 | + * | |
| 2624 | + * @access protected | |
| 2625 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form | |
| 2626 | + * @param array $args various things the context switcher needs. | |
| 2627 | + * @throws EE_Error | |
| 2628 | + */ | |
| 2629 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) | |
| 2630 | +	{ | |
| 2631 | + $context_details = $template_group_object->contexts_config(); | |
| 2632 | + $context_label = $template_group_object->context_label(); | |
| 2633 | + ob_start(); | |
| 2634 | + ?> | |
| 2635 | 2635 | <div class="ee-msg-switcher-container"> | 
| 2636 | 2636 | <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm"> | 
| 2637 | 2637 | <?php | 
| 2638 | -                foreach ($args as $name => $value) { | |
| 2639 | -                    if ($name === 'context' || empty($value) || $name === 'extra') { | |
| 2640 | - continue; | |
| 2641 | - } | |
| 2642 | - ?> | |
| 2638 | +				foreach ($args as $name => $value) { | |
| 2639 | +					if ($name === 'context' || empty($value) || $name === 'extra') { | |
| 2640 | + continue; | |
| 2641 | + } | |
| 2642 | + ?> | |
| 2643 | 2643 | <input type="hidden" | 
| 2644 | 2644 | name="<?php echo esc_attr($name); ?>" | 
| 2645 | 2645 | value="<?php echo esc_attr($value); ?>" | 
| 2646 | 2646 | /> | 
| 2647 | 2647 | <?php | 
| 2648 | - } | |
| 2649 | - // setup nonce_url | |
| 2650 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); | |
| 2651 | - ?> | |
| 2648 | + } | |
| 2649 | + // setup nonce_url | |
| 2650 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); | |
| 2651 | + ?> | |
| 2652 | 2652 | <select name="context"> | 
| 2653 | 2653 | <?php | 
| 2654 | - $context_templates = $template_group_object->context_templates(); | |
| 2655 | - if (is_array($context_templates)) : | |
| 2656 | - foreach ($context_templates as $context => $template_fields) : | |
| 2657 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; | |
| 2658 | - ?> | |
| 2654 | + $context_templates = $template_group_object->context_templates(); | |
| 2655 | + if (is_array($context_templates)) : | |
| 2656 | + foreach ($context_templates as $context => $template_fields) : | |
| 2657 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; | |
| 2658 | + ?> | |
| 2659 | 2659 | <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>> | 
| 2660 | 2660 | <?php echo $context_details[ $context ]['label']; // already escaped | 
| 2661 | - ?> | |
| 2661 | + ?> | |
| 2662 | 2662 | </option> | 
| 2663 | 2663 | <?php endforeach; | 
| 2664 | - endif; ?> | |
| 2664 | + endif; ?> | |
| 2665 | 2665 | </select> | 
| 2666 | 2666 | <?php $button_text = sprintf( | 
| 2667 | -                    esc_html__('Switch %s', 'event_espresso'), | |
| 2668 | - ucwords($context_label['label']) | |
| 2669 | - ); ?> | |
| 2667 | +					esc_html__('Switch %s', 'event_espresso'), | |
| 2668 | + ucwords($context_label['label']) | |
| 2669 | + ); ?> | |
| 2670 | 2670 | <input class='button-secondary' | 
| 2671 | 2671 | id="submit-msg-context-switcher-sbmt" | 
| 2672 | 2672 | type="submit" | 
| @@ -2674,1932 +2674,1932 @@ discard block | ||
| 2674 | 2674 | /> | 
| 2675 | 2675 | </form> | 
| 2676 | 2676 | <?php echo $args['extra']; // already escaped | 
| 2677 | - ?> | |
| 2677 | + ?> | |
| 2678 | 2678 | </div> <!-- end .ee-msg-switcher-container --> | 
| 2679 | 2679 | <?php | 
| 2680 | - $this->_context_switcher = ob_get_clean(); | |
| 2681 | - } | |
| 2682 | - | |
| 2683 | - | |
| 2684 | - /** | |
| 2685 | - * utility for sanitizing new values coming in. | |
| 2686 | - * Note: this is only used when updating a context. | |
| 2687 | - * | |
| 2688 | - * @access protected | |
| 2689 | - * | |
| 2690 | - * @param int $index This helps us know which template field to select from the request array. | |
| 2691 | - * | |
| 2692 | - * @return array | |
| 2693 | - */ | |
| 2694 | - protected function _set_message_template_column_values($index) | |
| 2695 | -    { | |
| 2696 | -        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) { | |
| 2697 | -            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) { | |
| 2698 | - $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value; | |
| 2699 | - } | |
| 2700 | - } | |
| 2701 | - | |
| 2702 | - | |
| 2703 | - $set_column_values = [ | |
| 2704 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']), | |
| 2705 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), | |
| 2706 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), | |
| 2707 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), | |
| 2708 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), | |
| 2709 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']), | |
| 2710 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), | |
| 2711 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][ $index ]['content'], | |
| 2712 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) | |
| 2713 | - ? absint($this->_req_data['MTP_is_global']) | |
| 2714 | - : 0, | |
| 2715 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) | |
| 2716 | - ? absint($this->_req_data['MTP_is_override']) | |
| 2717 | - : 0, | |
| 2718 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), | |
| 2719 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']), | |
| 2720 | - ]; | |
| 2721 | - | |
| 2722 | - | |
| 2723 | - return $set_column_values; | |
| 2724 | - } | |
| 2725 | - | |
| 2726 | - | |
| 2727 | - protected function _insert_or_update_message_template($new = false) | |
| 2728 | -    { | |
| 2729 | - | |
| 2730 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 2731 | - $success = 0; | |
| 2732 | - $override = false; | |
| 2733 | - | |
| 2734 | - // setup notices description | |
| 2735 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; | |
| 2736 | - | |
| 2737 | - // need the message type and messenger objects to be able to use the labels for the notices | |
| 2738 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); | |
| 2739 | - $messenger_label = $messenger_object instanceof EE_messenger | |
| 2740 | - ? ucwords($messenger_object->label['singular']) | |
| 2741 | - : ''; | |
| 2742 | - | |
| 2743 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) | |
| 2744 | - ? $this->_req_data['MTP_message_type'] | |
| 2745 | - : ''; | |
| 2746 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); | |
| 2747 | - | |
| 2748 | - $message_type_label = $message_type_object instanceof EE_message_type | |
| 2749 | - ? ucwords($message_type_object->label['singular']) | |
| 2750 | - : ''; | |
| 2751 | - | |
| 2752 | - $context_slug = ! empty($this->_req_data['MTP_context']) | |
| 2753 | - ? $this->_req_data['MTP_context'] | |
| 2754 | - : ''; | |
| 2755 | -        $context      = ucwords(str_replace('_', ' ', $context_slug)); | |
| 2756 | - | |
| 2757 | - $item_desc = $messenger_label && $message_type_label | |
| 2758 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' | |
| 2759 | - : ''; | |
| 2760 | - $item_desc .= 'Message Template'; | |
| 2761 | - $query_args = []; | |
| 2762 | - $edit_array = []; | |
| 2763 | - $action_desc = ''; | |
| 2764 | - | |
| 2765 | - // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for | |
| 2766 | - // user to edit. | |
| 2767 | -        if ($new) { | |
| 2768 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; | |
| 2769 | -            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { | |
| 2770 | -                if (empty($edit_array)) { | |
| 2771 | - $success = 0; | |
| 2772 | -                } else { | |
| 2773 | - $success = 1; | |
| 2774 | - $edit_array = $edit_array[0]; | |
| 2775 | - $query_args = [ | |
| 2776 | - 'id' => $edit_array['GRP_ID'], | |
| 2777 | - 'context' => $edit_array['MTP_context'], | |
| 2778 | - 'action' => 'edit_message_template', | |
| 2779 | - ]; | |
| 2780 | - } | |
| 2781 | - } | |
| 2782 | - $action_desc = 'created'; | |
| 2783 | -        } else { | |
| 2784 | - $MTPG = EEM_Message_Template_Group::instance(); | |
| 2785 | - $MTP = EEM_Message_Template::instance(); | |
| 2786 | - | |
| 2787 | - | |
| 2788 | - // run update for each template field in displayed context | |
| 2789 | -            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { | |
| 2790 | - EE_Error::add_error( | |
| 2791 | - esc_html__( | |
| 2792 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', | |
| 2793 | - 'event_espresso' | |
| 2794 | - ), | |
| 2795 | - __FILE__, | |
| 2796 | - __FUNCTION__, | |
| 2797 | - __LINE__ | |
| 2798 | - ); | |
| 2799 | - $success = 0; | |
| 2800 | -            } else { | |
| 2801 | - // first validate all fields! | |
| 2802 | - // this filter allows client code to add its own validation to the template fields as well. | |
| 2803 | - // returning an empty array means everything passed validation. | |
| 2804 | - // errors in validation should be represented in an array with the following shape: | |
| 2805 | - // array( | |
| 2806 | - // 'fieldname' => array( | |
| 2807 | - // 'msg' => 'error message' | |
| 2808 | - // 'value' => 'value for field producing error' | |
| 2809 | - // ) | |
| 2810 | - $custom_validation = (array) apply_filters( | |
| 2811 | - 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', | |
| 2812 | - [], | |
| 2813 | - $this->_req_data['MTP_template_fields'], | |
| 2814 | - $context_slug, | |
| 2815 | - $messenger_slug, | |
| 2816 | - $message_type_slug | |
| 2817 | - ); | |
| 2818 | - | |
| 2819 | - $system_validation = $MTPG->validate( | |
| 2820 | - $this->_req_data['MTP_template_fields'], | |
| 2821 | - $context_slug, | |
| 2822 | - $messenger_slug, | |
| 2823 | - $message_type_slug | |
| 2824 | - ); | |
| 2825 | - | |
| 2826 | - $system_validation = ! is_array($system_validation) && $system_validation ? [] | |
| 2827 | - : $system_validation; | |
| 2828 | - $validates = array_merge($custom_validation, $system_validation); | |
| 2829 | - | |
| 2830 | - // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an | |
| 2831 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. | |
| 2832 | - // WE need to make sure there is no actual error messages in validates. | |
| 2833 | -                if (is_array($validates) && ! empty($validates)) { | |
| 2834 | - // add the transient so when the form loads we know which fields to highlight | |
| 2835 | -                    $this->_add_transient('edit_message_template', $validates); | |
| 2836 | - | |
| 2837 | - $success = 0; | |
| 2838 | - | |
| 2839 | - // setup notices | |
| 2840 | -                    foreach ($validates as $field => $error) { | |
| 2841 | -                        if (isset($error['msg'])) { | |
| 2842 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); | |
| 2843 | - } | |
| 2844 | - } | |
| 2845 | -                } else { | |
| 2846 | - $set_column_values = []; | |
| 2847 | -                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { | |
| 2848 | - $set_column_values = $this->_set_message_template_column_values($template_field); | |
| 2849 | - | |
| 2850 | - $where_cols_n_values = [ | |
| 2851 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'], | |
| 2852 | - ]; | |
| 2853 | - // if they aren't allowed to use all JS, restrict them to just posty-y tags | |
| 2854 | -                        if (! current_user_can('unfiltered_html')) { | |
| 2855 | -                            if (is_array($set_column_values['MTP_content'])) { | |
| 2856 | -                                foreach ($set_column_values['MTP_content'] as $key => $value) { | |
| 2857 | - // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function | |
| 2858 | - // only removes slashes from double-quotes, so attributes using single quotes always | |
| 2859 | - // appear invalid.) But currently the models expect slashed data, so after wp_kses | |
| 2860 | - // runs we need to re-slash the data. Sheesh. See | |
| 2861 | - // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 | |
| 2862 | - $set_column_values['MTP_content'][ $key ] = addslashes( | |
| 2863 | - wp_kses( | |
| 2864 | - stripslashes($value), | |
| 2865 | -                                            wp_kses_allowed_html('post') | |
| 2866 | - ) | |
| 2867 | - ); | |
| 2868 | - } | |
| 2869 | -                            } else { | |
| 2870 | - $set_column_values['MTP_content'] = wp_kses( | |
| 2871 | - $set_column_values['MTP_content'], | |
| 2872 | -                                    wp_kses_allowed_html('post') | |
| 2873 | - ); | |
| 2874 | - } | |
| 2875 | - } | |
| 2876 | - $message_template_fields = [ | |
| 2877 | - 'GRP_ID' => $set_column_values['GRP_ID'], | |
| 2878 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], | |
| 2879 | - 'MTP_context' => $set_column_values['MTP_context'], | |
| 2880 | - 'MTP_content' => $set_column_values['MTP_content'], | |
| 2881 | - ]; | |
| 2882 | -                        if ($updated = $MTP->update($message_template_fields, [$where_cols_n_values])) { | |
| 2883 | -                            if ($updated === false) { | |
| 2884 | - EE_Error::add_error( | |
| 2885 | - sprintf( | |
| 2886 | -                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'), | |
| 2887 | - $template_field | |
| 2888 | - ), | |
| 2889 | - __FILE__, | |
| 2890 | - __FUNCTION__, | |
| 2891 | - __LINE__ | |
| 2892 | - ); | |
| 2893 | -                            } else { | |
| 2894 | - $success = 1; | |
| 2895 | - } | |
| 2896 | -                        } else { | |
| 2897 | - // only do this logic if we don't have a MTP_ID for this field | |
| 2898 | -                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) { | |
| 2899 | - // this has already been through the template field validator and sanitized, so it will be | |
| 2900 | - // safe to insert this field. Why insert? This typically happens when we introduce a new | |
| 2901 | - // message template field in a messenger/message type and existing users don't have the | |
| 2902 | - // default setup for it. | |
| 2903 | - // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 | |
| 2904 | - $updated = $MTP->insert($message_template_fields); | |
| 2905 | -                                if (! $updated || is_wp_error($updated)) { | |
| 2906 | - EE_Error::add_error( | |
| 2907 | - sprintf( | |
| 2908 | -                                            esc_html__('%s field could not be updated.', 'event_espresso'), | |
| 2909 | - $template_field | |
| 2910 | - ), | |
| 2911 | - __FILE__, | |
| 2912 | - __FUNCTION__, | |
| 2913 | - __LINE__ | |
| 2914 | - ); | |
| 2915 | - $success = 0; | |
| 2916 | -                                } else { | |
| 2917 | - $success = 1; | |
| 2918 | - } | |
| 2919 | - } | |
| 2920 | - } | |
| 2921 | - $action_desc = 'updated'; | |
| 2922 | - } | |
| 2923 | - | |
| 2924 | - // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) | |
| 2925 | - $mtpg_fields = [ | |
| 2926 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], | |
| 2927 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], | |
| 2928 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], | |
| 2929 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], | |
| 2930 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], | |
| 2931 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], | |
| 2932 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], | |
| 2933 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) | |
| 2934 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] | |
| 2935 | - : '', | |
| 2936 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) | |
| 2937 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] | |
| 2938 | - : '', | |
| 2939 | - ]; | |
| 2940 | - | |
| 2941 | - $mtpg_where = ['GRP_ID' => $set_column_values['GRP_ID']]; | |
| 2942 | - $updated = $MTPG->update($mtpg_fields, [$mtpg_where]); | |
| 2943 | - | |
| 2944 | -                    if ($updated === false) { | |
| 2945 | - EE_Error::add_error( | |
| 2946 | - sprintf( | |
| 2947 | - esc_html__( | |
| 2948 | - 'The Message Template Group (%d) was NOT updated for some reason', | |
| 2949 | - 'event_espresso' | |
| 2950 | - ), | |
| 2951 | - $set_column_values['GRP_ID'] | |
| 2952 | - ), | |
| 2953 | - __FILE__, | |
| 2954 | - __FUNCTION__, | |
| 2955 | - __LINE__ | |
| 2956 | - ); | |
| 2957 | -                    } else { | |
| 2958 | - // k now we need to ensure the template_pack and template_variation fields are set. | |
| 2959 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) | |
| 2960 | - ? $this->_req_data['MTP_template_pack'] | |
| 2961 | - : 'default'; | |
| 2962 | - | |
| 2963 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) | |
| 2964 | - ? $this->_req_data['MTP_template_variation'] | |
| 2965 | - : 'default'; | |
| 2966 | - | |
| 2967 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); | |
| 2968 | -                        if ($mtpg_obj instanceof EE_Message_Template_Group) { | |
| 2969 | - $mtpg_obj->set_template_pack_name($template_pack); | |
| 2970 | - $mtpg_obj->set_template_pack_variation($template_variation); | |
| 2971 | - } | |
| 2972 | - $success = 1; | |
| 2973 | - } | |
| 2974 | - } | |
| 2975 | - } | |
| 2976 | - } | |
| 2977 | - | |
| 2978 | - // we return things differently if doing ajax | |
| 2979 | -        if (defined('DOING_AJAX') && DOING_AJAX) { | |
| 2980 | - $this->_template_args['success'] = $success; | |
| 2981 | - $this->_template_args['error'] = ! $success ? true : false; | |
| 2982 | - $this->_template_args['content'] = ''; | |
| 2983 | - $this->_template_args['data'] = [ | |
| 2984 | - 'grpID' => $edit_array['GRP_ID'], | |
| 2985 | - 'templateName' => $edit_array['template_name'], | |
| 2986 | - ]; | |
| 2987 | -            if ($success) { | |
| 2988 | - EE_Error::overwrite_success(); | |
| 2989 | - EE_Error::add_success( | |
| 2990 | - esc_html__( | |
| 2991 | - 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', | |
| 2992 | - 'event_espresso' | |
| 2993 | - ) | |
| 2994 | - ); | |
| 2995 | - } | |
| 2996 | - | |
| 2997 | - $this->_return_json(); | |
| 2998 | - } | |
| 2999 | - | |
| 3000 | - | |
| 3001 | - // was a test send triggered? | |
| 3002 | -        if (isset($this->_req_data['test_button'])) { | |
| 3003 | - EE_Error::overwrite_success(); | |
| 3004 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); | |
| 3005 | - $override = true; | |
| 3006 | - } | |
| 3007 | - | |
| 3008 | -        if (empty($query_args)) { | |
| 3009 | - $query_args = [ | |
| 3010 | - 'id' => $this->_req_data['GRP_ID'], | |
| 3011 | - 'context' => $context_slug, | |
| 3012 | - 'action' => 'edit_message_template', | |
| 3013 | - ]; | |
| 3014 | - } | |
| 3015 | - | |
| 3016 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); | |
| 3017 | - } | |
| 3018 | - | |
| 3019 | - | |
| 3020 | - /** | |
| 3021 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested | |
| 3022 | - * | |
| 3023 | - * @param string $context what context being tested | |
| 3024 | - * @param string $messenger messenger being tested | |
| 3025 | - * @param string $message_type message type being tested | |
| 3026 | - * @throws EE_Error | |
| 3027 | - * @throws InvalidArgumentException | |
| 3028 | - * @throws InvalidDataTypeException | |
| 3029 | - * @throws InvalidInterfaceException | |
| 3030 | - */ | |
| 3031 | - protected function _do_test_send($context, $messenger, $message_type) | |
| 3032 | -    { | |
| 3033 | - // set things up for preview | |
| 3034 | - $this->_req_data['messenger'] = $messenger; | |
| 3035 | - $this->_req_data['message_type'] = $message_type; | |
| 3036 | - $this->_req_data['context'] = $context; | |
| 3037 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; | |
| 3038 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); | |
| 3039 | - | |
| 3040 | - // let's save any existing fields that might be required by the messenger | |
| 3041 | - if ( | |
| 3042 | - isset($this->_req_data['test_settings_fld']) | |
| 3043 | - && $active_messenger instanceof EE_messenger | |
| 3044 | - && apply_filters( | |
| 3045 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', | |
| 3046 | - true, | |
| 3047 | - $this->_req_data['test_settings_fld'], | |
| 3048 | - $active_messenger | |
| 3049 | - ) | |
| 3050 | -        ) { | |
| 3051 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); | |
| 3052 | - } | |
| 3053 | - | |
| 3054 | - /** | |
| 3055 | - * Use filter to add additional controls on whether message can send or not | |
| 3056 | - */ | |
| 3057 | - if ( | |
| 3058 | - apply_filters( | |
| 3059 | - 'FHEE__Messages_Admin_Page__do_test_send__can_send', | |
| 3060 | - true, | |
| 3061 | - $context, | |
| 3062 | - $this->_req_data, | |
| 3063 | - $messenger, | |
| 3064 | - $message_type | |
| 3065 | - ) | |
| 3066 | -        ) { | |
| 3067 | -            if (EEM_Event::instance()->count() > 0) { | |
| 3068 | - $success = $this->_preview_message(true); | |
| 3069 | -                if ($success) { | |
| 3070 | -                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso')); | |
| 3071 | -                } else { | |
| 3072 | - EE_Error::add_error( | |
| 3073 | -                        esc_html__('The test message was not sent', 'event_espresso'), | |
| 3074 | - __FILE__, | |
| 3075 | - __FUNCTION__, | |
| 3076 | - __LINE__ | |
| 3077 | - ); | |
| 3078 | - } | |
| 3079 | -            } else { | |
| 3080 | - $this->noEventsErrorMessage(true); | |
| 3081 | - } | |
| 3082 | - } | |
| 3083 | - } | |
| 3084 | - | |
| 3085 | - | |
| 3086 | - /** | |
| 3087 | - * _generate_new_templates | |
| 3088 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will | |
| 3089 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context | |
| 3090 | - * for the event. | |
| 3091 | - * | |
| 3092 | - * | |
| 3093 | - * @param string $messenger the messenger we are generating templates for | |
| 3094 | - * @param array $message_types array of message types that the templates are generated for. | |
| 3095 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to | |
| 3096 | - * indicate the message_template_group being used as the base. | |
| 3097 | - * | |
| 3098 | - * @param bool $global | |
| 3099 | - * | |
| 3100 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if | |
| 3101 | - * encountering problems. | |
| 3102 | - * @throws EE_Error | |
| 3103 | - */ | |
| 3104 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) | |
| 3105 | -    { | |
| 3106 | - | |
| 3107 | - // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we | |
| 3108 | - // just don't generate any templates. | |
| 3109 | -        if (empty($message_types)) { | |
| 3110 | - return true; | |
| 3111 | - } | |
| 3112 | - | |
| 3113 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); | |
| 3114 | - } | |
| 3115 | - | |
| 3116 | - | |
| 3117 | - /** | |
| 3118 | - * [_trash_or_restore_message_template] | |
| 3119 | - * | |
| 3120 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) | |
| 3121 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just | |
| 3122 | - * an individual context (FALSE). | |
| 3123 | - * @return void | |
| 3124 | - * @throws EE_Error | |
| 3125 | - * @throws InvalidArgumentException | |
| 3126 | - * @throws InvalidDataTypeException | |
| 3127 | - * @throws InvalidInterfaceException | |
| 3128 | - */ | |
| 3129 | - protected function _trash_or_restore_message_template($trash = true, $all = false) | |
| 3130 | -    { | |
| 3131 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 3132 | - $MTP = EEM_Message_Template_Group::instance(); | |
| 3133 | - | |
| 3134 | - $success = 1; | |
| 3135 | - | |
| 3136 | - // incoming GRP_IDs | |
| 3137 | -        if ($all) { | |
| 3138 | - // Checkboxes | |
| 3139 | -            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | |
| 3140 | - // if array has more than one element then success message should be plural. | |
| 3141 | - // todo: what about nonce? | |
| 3142 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; | |
| 3143 | - | |
| 3144 | - // cycle through checkboxes | |
| 3145 | -                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | |
| 3146 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); | |
| 3147 | -                    if (! $trashed_or_restored) { | |
| 3148 | - $success = 0; | |
| 3149 | - } | |
| 3150 | - } | |
| 3151 | -            } else { | |
| 3152 | - // grab single GRP_ID and handle | |
| 3153 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; | |
| 3154 | -                if (! empty($GRP_ID)) { | |
| 3155 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); | |
| 3156 | -                    if (! $trashed_or_restored) { | |
| 3157 | - $success = 0; | |
| 3158 | - } | |
| 3159 | -                } else { | |
| 3160 | - $success = 0; | |
| 3161 | - } | |
| 3162 | - } | |
| 3163 | - } | |
| 3164 | - | |
| 3165 | - $action_desc = $trash | |
| 3166 | -            ? esc_html__('moved to the trash', 'event_espresso') | |
| 3167 | -            : esc_html__('restored', 'event_espresso'); | |
| 3168 | - | |
| 3169 | - $action_desc = | |
| 3170 | -            ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc; | |
| 3171 | - | |
| 3172 | - $item_desc = $all ? _n( | |
| 3173 | - 'Message Template Group', | |
| 3174 | - 'Message Template Groups', | |
| 3175 | - $success, | |
| 3176 | - 'event_espresso' | |
| 3177 | -        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); | |
| 3178 | - | |
| 3179 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n( | |
| 3180 | - 'template', | |
| 3181 | - 'templates', | |
| 3182 | - $success, | |
| 3183 | - 'event_espresso' | |
| 3184 | - ) : $item_desc; | |
| 3185 | - | |
| 3186 | - $this->_redirect_after_action($success, $item_desc, $action_desc, []); | |
| 3187 | - } | |
| 3188 | - | |
| 3189 | - | |
| 3190 | - /** | |
| 3191 | - * [_delete_message_template] | |
| 3192 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. | |
| 3193 | - * | |
| 3194 | - * @return void | |
| 3195 | - * @throws EE_Error | |
| 3196 | - * @throws InvalidArgumentException | |
| 3197 | - * @throws InvalidDataTypeException | |
| 3198 | - * @throws InvalidInterfaceException | |
| 3199 | - */ | |
| 3200 | - protected function _delete_message_template() | |
| 3201 | -    { | |
| 3202 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 3203 | - | |
| 3204 | - // checkboxes | |
| 3205 | -        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | |
| 3206 | - // if array has more than one element then success message should be plural | |
| 3207 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; | |
| 3208 | - | |
| 3209 | - // cycle through bulk action checkboxes | |
| 3210 | -            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | |
| 3211 | - $success = $this->_delete_mtp_permanently($GRP_ID); | |
| 3212 | - } | |
| 3213 | -        } else { | |
| 3214 | - // grab single grp_id and delete | |
| 3215 | - $GRP_ID = absint($this->_req_data['id']); | |
| 3216 | - $success = $this->_delete_mtp_permanently($GRP_ID); | |
| 3217 | - } | |
| 3218 | - | |
| 3219 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', []); | |
| 3220 | - } | |
| 3221 | - | |
| 3222 | - | |
| 3223 | - /** | |
| 3224 | - * helper for permanently deleting a mtP group and all related message_templates | |
| 3225 | - * | |
| 3226 | - * @param int $GRP_ID The group being deleted | |
| 3227 | - * @param bool $include_group whether to delete the Message Template Group as well. | |
| 3228 | - * @return bool boolean to indicate the success of the deletes or not. | |
| 3229 | - * @throws EE_Error | |
| 3230 | - * @throws InvalidArgumentException | |
| 3231 | - * @throws InvalidDataTypeException | |
| 3232 | - * @throws InvalidInterfaceException | |
| 3233 | - */ | |
| 3234 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) | |
| 3235 | -    { | |
| 3236 | - $success = 1; | |
| 3237 | - $MTPG = EEM_Message_Template_Group::instance(); | |
| 3238 | - // first let's GET this group | |
| 3239 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); | |
| 3240 | - // then delete permanently all the related Message Templates | |
| 3241 | -        $deleted = $MTG->delete_related_permanently('Message_Template'); | |
| 3242 | - | |
| 3243 | -        if ($deleted === 0) { | |
| 3244 | - $success = 0; | |
| 3245 | - } | |
| 3246 | - | |
| 3247 | - // now delete permanently this particular group | |
| 3248 | - | |
| 3249 | -        if ($include_group && ! $MTG->delete_permanently()) { | |
| 3250 | - $success = 0; | |
| 3251 | - } | |
| 3252 | - | |
| 3253 | - return $success; | |
| 3254 | - } | |
| 3255 | - | |
| 3256 | - | |
| 3257 | - /** | |
| 3258 | - * _learn_more_about_message_templates_link | |
| 3259 | - * | |
| 3260 | - * @access protected | |
| 3261 | - * @return string | |
| 3262 | - */ | |
| 3263 | - protected function _learn_more_about_message_templates_link() | |
| 3264 | -    { | |
| 3265 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' | |
| 3266 | -               . esc_html__('learn more about how message templates works', 'event_espresso') | |
| 3267 | - . '</a>'; | |
| 3268 | - } | |
| 3269 | - | |
| 3270 | - | |
| 3271 | - /** | |
| 3272 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by | |
| 3273 | - * ajax and other routes. | |
| 3274 | - * | |
| 3275 | - * @return void | |
| 3276 | - * @throws DomainException | |
| 3277 | - */ | |
| 3278 | - protected function _settings() | |
| 3279 | -    { | |
| 3280 | - | |
| 3281 | - | |
| 3282 | - $this->_set_m_mt_settings(); | |
| 3283 | - | |
| 3284 | - $selected_messenger = isset($this->_req_data['selected_messenger']) | |
| 3285 | - ? $this->_req_data['selected_messenger'] | |
| 3286 | - : 'email'; | |
| 3287 | - | |
| 3288 | - // let's setup the messenger tabs | |
| 3289 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( | |
| 3290 | - $this->_m_mt_settings['messenger_tabs'], | |
| 3291 | - 'messenger_links', | |
| 3292 | - '|', | |
| 3293 | - $selected_messenger | |
| 3294 | - ); | |
| 3295 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; | |
| 3296 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; | |
| 3297 | - | |
| 3298 | - $this->display_admin_page_with_sidebar(); | |
| 3299 | - } | |
| 3300 | - | |
| 3301 | - | |
| 3302 | - /** | |
| 3303 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) | |
| 3304 | - * | |
| 3305 | - * @access protected | |
| 3306 | - * @return void | |
| 3307 | - * @throws DomainException | |
| 3308 | - */ | |
| 3309 | - protected function _set_m_mt_settings() | |
| 3310 | -    { | |
| 3311 | - // first if this is already set then lets get out no need to regenerate data. | |
| 3312 | -        if (! empty($this->_m_mt_settings)) { | |
| 3313 | - return; | |
| 3314 | - } | |
| 3315 | - | |
| 3316 | - // get all installed messengers and message_types | |
| 3317 | - /** @type EE_messenger[] $messengers */ | |
| 3318 | - $messengers = $this->_message_resource_manager->installed_messengers(); | |
| 3319 | - /** @type EE_message_type[] $message_types */ | |
| 3320 | - $message_types = $this->_message_resource_manager->installed_message_types(); | |
| 3321 | - | |
| 3322 | - | |
| 3323 | - // assemble the array for the _tab_text_links helper | |
| 3324 | - | |
| 3325 | -        foreach ($messengers as $messenger) { | |
| 3326 | - $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [ | |
| 3327 | - 'label' => ucwords($messenger->label['singular']), | |
| 3328 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) | |
| 3329 | - ? 'messenger-active' | |
| 3330 | - : '', | |
| 3331 | - 'href' => $messenger->name, | |
| 3332 | -                'title' => esc_html__('Modify this Messenger', 'event_espresso'), | |
| 3333 | - 'slug' => $messenger->name, | |
| 3334 | - 'obj' => $messenger, | |
| 3335 | - ]; | |
| 3336 | - | |
| 3337 | - | |
| 3338 | - $message_types_for_messenger = $messenger->get_valid_message_types(); | |
| 3339 | - | |
| 3340 | -            foreach ($message_types as $message_type) { | |
| 3341 | - // first we need to verify that this message type is valid with this messenger. Cause if it isn't then | |
| 3342 | - // it shouldn't show in either the inactive OR active metabox. | |
| 3343 | -                if (! in_array($message_type->name, $message_types_for_messenger, true)) { | |
| 3344 | - continue; | |
| 3345 | - } | |
| 3346 | - | |
| 3347 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( | |
| 3348 | - $messenger->name, | |
| 3349 | - $message_type->name | |
| 3350 | - ) | |
| 3351 | - ? 'active' | |
| 3352 | - : 'inactive'; | |
| 3353 | - | |
| 3354 | - $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [ | |
| 3355 | - 'label' => ucwords($message_type->label['singular']), | |
| 3356 | - 'class' => 'message-type-' . $a_or_i, | |
| 3357 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, | |
| 3358 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), | |
| 3359 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', | |
| 3360 | - 'title' => $a_or_i === 'active' | |
| 3361 | -                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') | |
| 3362 | -                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), | |
| 3363 | - 'content' => $a_or_i === 'active' | |
| 3364 | - ? $this->_message_type_settings_content($message_type, $messenger, true) | |
| 3365 | - : $this->_message_type_settings_content($message_type, $messenger), | |
| 3366 | - 'slug' => $message_type->name, | |
| 3367 | - 'active' => $a_or_i === 'active', | |
| 3368 | - 'obj' => $message_type, | |
| 3369 | - ]; | |
| 3370 | - } | |
| 3371 | - } | |
| 3372 | - } | |
| 3373 | - | |
| 3374 | - | |
| 3375 | - /** | |
| 3376 | - * This just prepares the content for the message type settings | |
| 3377 | - * | |
| 3378 | - * @param EE_message_type $message_type The message type object | |
| 3379 | - * @param EE_messenger $messenger The messenger object | |
| 3380 | - * @param boolean $active Whether the message type is active or not | |
| 3381 | - * @return string html output for the content | |
| 3382 | - * @throws DomainException | |
| 3383 | - */ | |
| 3384 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) | |
| 3385 | -    { | |
| 3386 | - // get message type fields | |
| 3387 | - $fields = $message_type->get_admin_settings_fields(); | |
| 3388 | - $settings_template_args['template_form_fields'] = ''; | |
| 3389 | - | |
| 3390 | -        if (! empty($fields) && $active) { | |
| 3391 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); | |
| 3392 | -            foreach ($fields as $fldname => $fldprops) { | |
| 3393 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; | |
| 3394 | - $template_form_field[ $field_id ] = [ | |
| 3395 | - 'name' => 'message_type_settings[' . $fldname . ']', | |
| 3396 | - 'label' => $fldprops['label'], | |
| 3397 | - 'input' => $fldprops['field_type'], | |
| 3398 | - 'type' => $fldprops['value_type'], | |
| 3399 | - 'required' => $fldprops['required'], | |
| 3400 | - 'validation' => $fldprops['validation'], | |
| 3401 | - 'value' => isset($existing_settings[ $fldname ]) | |
| 3402 | - ? $existing_settings[ $fldname ] | |
| 3403 | - : $fldprops['default'], | |
| 3404 | - 'options' => isset($fldprops['options']) | |
| 3405 | - ? $fldprops['options'] | |
| 3406 | - : [], | |
| 3407 | - 'default' => isset($existing_settings[ $fldname ]) | |
| 3408 | - ? $existing_settings[ $fldname ] | |
| 3409 | - : $fldprops['default'], | |
| 3410 | - 'css_class' => 'no-drag', | |
| 3411 | - 'format' => $fldprops['format'], | |
| 3412 | - ]; | |
| 3413 | - } | |
| 3414 | - | |
| 3415 | - | |
| 3416 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) | |
| 3417 | - ? $this->_generate_admin_form_fields( | |
| 3418 | - $template_form_field, | |
| 3419 | - 'string', | |
| 3420 | - 'ee_mt_activate_form' | |
| 3421 | - ) | |
| 3422 | - : ''; | |
| 3423 | - } | |
| 3424 | - | |
| 3425 | - $settings_template_args['description'] = $message_type->description; | |
| 3426 | - // we also need some hidden fields | |
| 3427 | - $hidden_fields = [ | |
| 3428 | - 'message_type_settings[messenger]' . $message_type->name => [ | |
| 3429 | - 'type' => 'hidden', | |
| 3430 | - 'value' => $messenger->name, | |
| 3431 | - ], | |
| 3432 | - 'message_type_settings[message_type]' . $message_type->name => [ | |
| 3433 | - 'type' => 'hidden', | |
| 3434 | - 'value' => $message_type->name, | |
| 3435 | - ], | |
| 3436 | - 'type' . $message_type->name => [ | |
| 3437 | - 'type' => 'hidden', | |
| 3438 | - 'value' => 'message_type', | |
| 3439 | - ], | |
| 3440 | - ]; | |
| 3441 | - | |
| 3442 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( | |
| 3443 | - $hidden_fields, | |
| 3444 | - 'array' | |
| 3445 | - ); | |
| 3446 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) | |
| 3447 | - ? ' hidden' | |
| 3448 | - : ''; | |
| 3449 | - | |
| 3450 | - | |
| 3451 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; | |
| 3452 | - $content = EEH_Template::display_template($template, $settings_template_args, true); | |
| 3453 | - | |
| 3454 | - return $content; | |
| 3455 | - } | |
| 3456 | - | |
| 3457 | - | |
| 3458 | - /** | |
| 3459 | - * Generate all the metaboxes for the message types and register them for the messages settings page. | |
| 3460 | - * | |
| 3461 | - * @access protected | |
| 3462 | - * @return void | |
| 3463 | - * @throws DomainException | |
| 3464 | - */ | |
| 3465 | - protected function _messages_settings_metaboxes() | |
| 3466 | -    { | |
| 3467 | - $this->_set_m_mt_settings(); | |
| 3468 | - $m_boxes = $mt_boxes = []; | |
| 3469 | - $m_template_args = $mt_template_args = []; | |
| 3470 | - | |
| 3471 | - $selected_messenger = isset($this->_req_data['selected_messenger']) | |
| 3472 | - ? $this->_req_data['selected_messenger'] | |
| 3473 | - : 'email'; | |
| 3474 | - | |
| 3475 | -        if (isset($this->_m_mt_settings['messenger_tabs'])) { | |
| 3476 | -            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { | |
| 3477 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; | |
| 3478 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; | |
| 3479 | - // messenger meta boxes | |
| 3480 | - $active = $selected_messenger === $messenger; | |
| 3481 | - $active_mt_tabs = isset( | |
| 3482 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] | |
| 3483 | - ) | |
| 3484 | - ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] | |
| 3485 | - : ''; | |
| 3486 | - $m_boxes[ $messenger . '_a_box' ] = sprintf( | |
| 3487 | -                    esc_html__('%s Settings', 'event_espresso'), | |
| 3488 | - $tab_array['label'] | |
| 3489 | - ); | |
| 3490 | - $m_template_args[ $messenger . '_a_box' ] = [ | |
| 3491 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', | |
| 3492 | - 'inactive_message_types' => isset( | |
| 3493 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] | |
| 3494 | - ) | |
| 3495 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) | |
| 3496 | - : '', | |
| 3497 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), | |
| 3498 | - 'hidden' => $active ? '' : ' hidden', | |
| 3499 | - 'hide_on_message' => $hide_on_message, | |
| 3500 | - 'messenger' => $messenger, | |
| 3501 | - 'active' => $active, | |
| 3502 | - ]; | |
| 3503 | - // message type meta boxes | |
| 3504 | - // (which is really just the inactive container for each messenger | |
| 3505 | - // showing inactive message types for that messenger) | |
| 3506 | -                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso'); | |
| 3507 | - $mt_template_args[ $messenger . '_i_box' ] = [ | |
| 3508 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', | |
| 3509 | - 'inactive_message_types' => isset( | |
| 3510 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] | |
| 3511 | - ) | |
| 3512 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) | |
| 3513 | - : '', | |
| 3514 | - 'hidden' => $active ? '' : ' hidden', | |
| 3515 | - 'hide_on_message' => $hide_on_message, | |
| 3516 | - 'hide_off_message' => $hide_off_message, | |
| 3517 | - 'messenger' => $messenger, | |
| 3518 | - 'active' => $active, | |
| 3519 | - ]; | |
| 3520 | - } | |
| 3521 | - } | |
| 3522 | - | |
| 3523 | - | |
| 3524 | - // register messenger metaboxes | |
| 3525 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; | |
| 3526 | -        foreach ($m_boxes as $box => $label) { | |
| 3527 | - $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]]; | |
| 3528 | -            $msgr          = str_replace('_a_box', '', $box); | |
| 3529 | - add_meta_box( | |
| 3530 | - 'espresso_' . $msgr . '_settings', | |
| 3531 | - $label, | |
| 3532 | -                function ($post, $metabox) { | |
| 3533 | - EEH_Template::display_template( | |
| 3534 | - $metabox['args']['template_path'], | |
| 3535 | - $metabox['args']['template_args'] | |
| 3536 | - ); | |
| 3537 | - }, | |
| 3538 | - $this->_current_screen->id, | |
| 3539 | - 'normal', | |
| 3540 | - 'high', | |
| 3541 | - $callback_args | |
| 3542 | - ); | |
| 3543 | - } | |
| 3544 | - | |
| 3545 | - // register message type metaboxes | |
| 3546 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; | |
| 3547 | -        foreach ($mt_boxes as $box => $label) { | |
| 3548 | - $callback_args = [ | |
| 3549 | - 'template_path' => $mt_template_path, | |
| 3550 | - 'template_args' => $mt_template_args[ $box ], | |
| 3551 | - ]; | |
| 3552 | -            $mt            = str_replace('_i_box', '', $box); | |
| 3553 | - add_meta_box( | |
| 3554 | - 'espresso_' . $mt . '_inactive_mts', | |
| 3555 | - $label, | |
| 3556 | -                function ($post, $metabox) { | |
| 3557 | - EEH_Template::display_template( | |
| 3558 | - $metabox['args']['template_path'], | |
| 3559 | - $metabox['args']['template_args'] | |
| 3560 | - ); | |
| 3561 | - }, | |
| 3562 | - $this->_current_screen->id, | |
| 3563 | - 'side', | |
| 3564 | - 'high', | |
| 3565 | - $callback_args | |
| 3566 | - ); | |
| 3567 | - } | |
| 3568 | - | |
| 3569 | - // register metabox for global messages settings but only when on the main site. On single site installs this | |
| 3570 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. | |
| 3571 | -        if (is_main_site()) { | |
| 3572 | - add_meta_box( | |
| 3573 | - 'espresso_global_message_settings', | |
| 3574 | -                esc_html__('Global Message Settings', 'event_espresso'), | |
| 3575 | - [$this, 'global_messages_settings_metabox_content'], | |
| 3576 | - $this->_current_screen->id, | |
| 3577 | - 'normal', | |
| 3578 | - 'low', | |
| 3579 | - [] | |
| 3580 | - ); | |
| 3581 | - } | |
| 3582 | - } | |
| 3583 | - | |
| 3584 | - | |
| 3585 | - /** | |
| 3586 | - * This generates the content for the global messages settings metabox. | |
| 3587 | - * | |
| 3588 | - * @return void | |
| 3589 | - * @throws EE_Error | |
| 3590 | - * @throws InvalidArgumentException | |
| 3591 | - * @throws ReflectionException | |
| 3592 | - * @throws InvalidDataTypeException | |
| 3593 | - * @throws InvalidInterfaceException | |
| 3594 | - */ | |
| 3595 | - public function global_messages_settings_metabox_content() | |
| 3596 | -    { | |
| 3597 | - $form = $this->_generate_global_settings_form(); | |
| 3598 | - // already escaped | |
| 3599 | - echo $form->form_open( | |
| 3600 | - $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL), | |
| 3601 | - 'POST' | |
| 3602 | - ); | |
| 3603 | - echo $form->get_html(); | |
| 3604 | - echo $form->form_close(); | |
| 3605 | - } | |
| 3606 | - | |
| 3607 | - | |
| 3608 | - /** | |
| 3609 | - * This generates and returns the form object for the global messages settings. | |
| 3610 | - * | |
| 3611 | - * @return EE_Form_Section_Proper | |
| 3612 | - * @throws EE_Error | |
| 3613 | - * @throws InvalidArgumentException | |
| 3614 | - * @throws ReflectionException | |
| 3615 | - * @throws InvalidDataTypeException | |
| 3616 | - * @throws InvalidInterfaceException | |
| 3617 | - */ | |
| 3618 | - protected function _generate_global_settings_form() | |
| 3619 | -    { | |
| 3620 | -        EE_Registry::instance()->load_helper('HTML'); | |
| 3621 | - /** @var EE_Network_Core_Config $network_config */ | |
| 3622 | - $network_config = EE_Registry::instance()->NET_CFG->core; | |
| 3623 | - | |
| 3624 | - return new EE_Form_Section_Proper( | |
| 3625 | - [ | |
| 3626 | - 'name' => 'global_messages_settings', | |
| 3627 | - 'html_id' => 'global_messages_settings', | |
| 3628 | - 'html_class' => 'form-table', | |
| 3629 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), | |
| 3630 | - 'subsections' => apply_filters( | |
| 3631 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', | |
| 3632 | - [ | |
| 3633 | - 'do_messages_on_same_request' => new EE_Select_Input( | |
| 3634 | - [ | |
| 3635 | -                                true  => esc_html__('On the same request', 'event_espresso'), | |
| 3636 | -                                false => esc_html__('On a separate request', 'event_espresso'), | |
| 3637 | - ], | |
| 3638 | - [ | |
| 3639 | - 'default' => $network_config->do_messages_on_same_request, | |
| 3640 | - 'html_label_text' => esc_html__( | |
| 3641 | - 'Generate and send all messages:', | |
| 3642 | - 'event_espresso' | |
| 3643 | - ), | |
| 3644 | - 'html_help_text' => esc_html__( | |
| 3645 | - 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', | |
| 3646 | - 'event_espresso' | |
| 3647 | - ), | |
| 3648 | - ] | |
| 3649 | - ), | |
| 3650 | - 'delete_threshold' => new EE_Select_Input( | |
| 3651 | - [ | |
| 3652 | -                                0  => esc_html__('Forever', 'event_espresso'), | |
| 3653 | -                                3  => esc_html__('3 Months', 'event_espresso'), | |
| 3654 | -                                6  => esc_html__('6 Months', 'event_espresso'), | |
| 3655 | -                                9  => esc_html__('9 Months', 'event_espresso'), | |
| 3656 | -                                12 => esc_html__('12 Months', 'event_espresso'), | |
| 3657 | -                                24 => esc_html__('24 Months', 'event_espresso'), | |
| 3658 | -                                36 => esc_html__('36 Months', 'event_espresso'), | |
| 3659 | - ], | |
| 3660 | - [ | |
| 3661 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, | |
| 3662 | -                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), | |
| 3663 | - 'html_help_text' => esc_html__( | |
| 3664 | - 'You can control how long a record of processed messages is kept via this option.', | |
| 3665 | - 'event_espresso' | |
| 3666 | - ), | |
| 3667 | - ] | |
| 3668 | - ), | |
| 3669 | - 'update_settings' => new EE_Submit_Input( | |
| 3670 | - [ | |
| 3671 | -                                'default'         => esc_html__('Update', 'event_espresso'), | |
| 3672 | - 'html_label_text' => ' ', | |
| 3673 | - ] | |
| 3674 | - ), | |
| 3675 | - ] | |
| 3676 | - ), | |
| 3677 | - ] | |
| 3678 | - ); | |
| 3679 | - } | |
| 3680 | - | |
| 3681 | - | |
| 3682 | - /** | |
| 3683 | - * This handles updating the global settings set on the admin page. | |
| 3684 | - * | |
| 3685 | - * @throws EE_Error | |
| 3686 | - * @throws InvalidDataTypeException | |
| 3687 | - * @throws InvalidInterfaceException | |
| 3688 | - * @throws InvalidArgumentException | |
| 3689 | - * @throws ReflectionException | |
| 3690 | - */ | |
| 3691 | - protected function _update_global_settings() | |
| 3692 | -    { | |
| 3693 | - /** @var EE_Network_Core_Config $network_config */ | |
| 3694 | - $network_config = EE_Registry::instance()->NET_CFG->core; | |
| 3695 | - $messages_config = EE_Registry::instance()->CFG->messages; | |
| 3696 | - $form = $this->_generate_global_settings_form(); | |
| 3697 | -        if ($form->was_submitted()) { | |
| 3698 | - $form->receive_form_submission(); | |
| 3699 | -            if ($form->is_valid()) { | |
| 3700 | - $valid_data = $form->valid_data(); | |
| 3701 | -                foreach ($valid_data as $property => $value) { | |
| 3702 | - $setter = 'set_' . $property; | |
| 3703 | -                    if (method_exists($network_config, $setter)) { | |
| 3704 | -                        $network_config->{$setter}($value); | |
| 3705 | - } elseif ( | |
| 3706 | - property_exists($network_config, $property) | |
| 3707 | -                        && $network_config->{$property} !== $value | |
| 3708 | -                    ) { | |
| 3709 | -                        $network_config->{$property} = $value; | |
| 3710 | - } elseif ( | |
| 3711 | - property_exists($messages_config, $property) | |
| 3712 | -                        && $messages_config->{$property} !== $value | |
| 3713 | -                    ) { | |
| 3714 | -                        $messages_config->{$property} = $value; | |
| 3715 | - } | |
| 3716 | - } | |
| 3717 | - // only update if the form submission was valid! | |
| 3718 | - EE_Registry::instance()->NET_CFG->update_config(true, false); | |
| 3719 | - EE_Registry::instance()->CFG->update_espresso_config(); | |
| 3720 | - EE_Error::overwrite_success(); | |
| 3721 | -                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso')); | |
| 3722 | - } | |
| 3723 | - } | |
| 3724 | - $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true); | |
| 3725 | - } | |
| 3726 | - | |
| 3727 | - | |
| 3728 | - /** | |
| 3729 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate | |
| 3730 | - * | |
| 3731 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs | |
| 3732 | - * @return string html formatted tabs | |
| 3733 | - * @throws DomainException | |
| 3734 | - */ | |
| 3735 | - protected function _get_mt_tabs($tab_array) | |
| 3736 | -    { | |
| 3737 | - $tab_array = (array) $tab_array; | |
| 3738 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; | |
| 3739 | - $tabs = ''; | |
| 3740 | - | |
| 3741 | -        foreach ($tab_array as $tab) { | |
| 3742 | - $tabs .= EEH_Template::display_template($template, $tab, true); | |
| 3743 | - } | |
| 3744 | - | |
| 3745 | - return $tabs; | |
| 3746 | - } | |
| 3747 | - | |
| 3748 | - | |
| 3749 | - /** | |
| 3750 | - * This prepares the content of the messenger meta box admin settings | |
| 3751 | - * | |
| 3752 | - * @param EE_messenger $messenger The messenger we're setting up content for | |
| 3753 | - * @return string html formatted content | |
| 3754 | - * @throws DomainException | |
| 3755 | - */ | |
| 3756 | - protected function _get_messenger_box_content(EE_messenger $messenger) | |
| 3757 | -    { | |
| 3758 | - | |
| 3759 | - $fields = $messenger->get_admin_settings_fields(); | |
| 3760 | - $settings_template_args['template_form_fields'] = ''; | |
| 3761 | - | |
| 3762 | - // is $messenger active? | |
| 3763 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); | |
| 3764 | - | |
| 3765 | - | |
| 3766 | -        if (! empty($fields)) { | |
| 3767 | - $existing_settings = $messenger->get_existing_admin_settings(); | |
| 3768 | - | |
| 3769 | -            foreach ($fields as $fldname => $fldprops) { | |
| 3770 | - $field_id = $messenger->name . '-' . $fldname; | |
| 3771 | - $template_form_field[ $field_id ] = [ | |
| 3772 | - 'name' => 'messenger_settings[' . $field_id . ']', | |
| 3773 | - 'label' => $fldprops['label'], | |
| 3774 | - 'input' => $fldprops['field_type'], | |
| 3775 | - 'type' => $fldprops['value_type'], | |
| 3776 | - 'required' => $fldprops['required'], | |
| 3777 | - 'validation' => $fldprops['validation'], | |
| 3778 | - 'value' => isset($existing_settings[ $field_id ]) | |
| 3779 | - ? $existing_settings[ $field_id ] | |
| 3780 | - : $fldprops['default'], | |
| 3781 | - 'css_class' => '', | |
| 3782 | - 'format' => $fldprops['format'], | |
| 3783 | - ]; | |
| 3784 | - } | |
| 3785 | - | |
| 3786 | - | |
| 3787 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) | |
| 3788 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') | |
| 3789 | - : ''; | |
| 3790 | - } | |
| 3791 | - | |
| 3792 | - // we also need some hidden fields | |
| 3793 | - $settings_template_args['hidden_fields'] = [ | |
| 3794 | - 'messenger_settings[messenger]' . $messenger->name => [ | |
| 3795 | - 'type' => 'hidden', | |
| 3796 | - 'value' => $messenger->name, | |
| 3797 | - ], | |
| 3798 | - 'type' . $messenger->name => [ | |
| 3799 | - 'type' => 'hidden', | |
| 3800 | - 'value' => 'messenger', | |
| 3801 | - ], | |
| 3802 | - ]; | |
| 3803 | - | |
| 3804 | - // make sure any active message types that are existing are included in the hidden fields | |
| 3805 | -        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { | |
| 3806 | -            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { | |
| 3807 | - $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [ | |
| 3808 | - 'type' => 'hidden', | |
| 3809 | - 'value' => $mt, | |
| 3810 | - ]; | |
| 3811 | - } | |
| 3812 | - } | |
| 3813 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( | |
| 3814 | - $settings_template_args['hidden_fields'], | |
| 3815 | - 'array' | |
| 3816 | - ); | |
| 3817 | - $active = | |
| 3818 | - $this->_message_resource_manager->is_messenger_active($messenger->name); | |
| 3819 | - | |
| 3820 | - $settings_template_args['messenger'] = $messenger->name; | |
| 3821 | - $settings_template_args['description'] = $messenger->description; | |
| 3822 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; | |
| 3823 | - | |
| 3824 | - | |
| 3825 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( | |
| 3826 | - $messenger->name | |
| 3827 | - ) | |
| 3828 | - ? $settings_template_args['show_hide_edit_form'] | |
| 3829 | - : ' hidden'; | |
| 3830 | - | |
| 3831 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) | |
| 3832 | - ? ' hidden' | |
| 3833 | - : $settings_template_args['show_hide_edit_form']; | |
| 3834 | - | |
| 3835 | - | |
| 3836 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; | |
| 3837 | -        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | |
| 3838 | - $settings_template_args['on_off_status'] = $active; | |
| 3839 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; | |
| 3840 | - return EEH_Template::display_template( | |
| 3841 | - $template, | |
| 3842 | - $settings_template_args, | |
| 3843 | - true | |
| 3844 | - ); | |
| 3845 | - } | |
| 3846 | - | |
| 3847 | - | |
| 3848 | - /** | |
| 3849 | - * used by ajax on the messages settings page to activate|deactivate the messenger | |
| 3850 | - * | |
| 3851 | - * @throws DomainException | |
| 3852 | - * @throws EE_Error | |
| 3853 | - * @throws InvalidDataTypeException | |
| 3854 | - * @throws InvalidInterfaceException | |
| 3855 | - * @throws InvalidArgumentException | |
| 3856 | - * @throws ReflectionException | |
| 3857 | - */ | |
| 3858 | - public function activate_messenger_toggle() | |
| 3859 | -    { | |
| 3860 | - $success = true; | |
| 3861 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); | |
| 3862 | - // let's check that we have required data | |
| 3863 | -        if (! isset($this->_req_data['messenger'])) { | |
| 3864 | - EE_Error::add_error( | |
| 3865 | -                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | |
| 3866 | - __FILE__, | |
| 3867 | - __FUNCTION__, | |
| 3868 | - __LINE__ | |
| 3869 | - ); | |
| 3870 | - $success = false; | |
| 3871 | - } | |
| 3872 | - | |
| 3873 | - // do a nonce check here since we're not arriving via a normal route | |
| 3874 | - $nonce = isset($this->_req_data['activate_nonce']) | |
| 3875 | - ? sanitize_text_field($this->_req_data['activate_nonce']) | |
| 3876 | - : ''; | |
| 3877 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; | |
| 3878 | - | |
| 3879 | - $this->_verify_nonce($nonce, $nonce_ref); | |
| 3880 | - | |
| 3881 | - | |
| 3882 | -        if (! isset($this->_req_data['status'])) { | |
| 3883 | - EE_Error::add_error( | |
| 3884 | - esc_html__( | |
| 3885 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', | |
| 3886 | - 'event_espresso' | |
| 3887 | - ), | |
| 3888 | - __FILE__, | |
| 3889 | - __FUNCTION__, | |
| 3890 | - __LINE__ | |
| 3891 | - ); | |
| 3892 | - $success = false; | |
| 3893 | - } | |
| 3894 | - | |
| 3895 | - // do check to verify we have a valid status. | |
| 3896 | - $status = $this->_req_data['status']; | |
| 3897 | - | |
| 3898 | -        if ($status !== 'off' && $status !== 'on') { | |
| 3899 | - EE_Error::add_error( | |
| 3900 | - sprintf( | |
| 3901 | -                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | |
| 3902 | - $this->_req_data['status'] | |
| 3903 | - ), | |
| 3904 | - __FILE__, | |
| 3905 | - __FUNCTION__, | |
| 3906 | - __LINE__ | |
| 3907 | - ); | |
| 3908 | - $success = false; | |
| 3909 | - } | |
| 3910 | - | |
| 3911 | -        if ($success) { | |
| 3912 | - // made it here? Stop dawdling then!! | |
| 3913 | - $success = $status === 'off' | |
| 3914 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) | |
| 3915 | - : $this->_activate_messenger($this->_req_data['messenger']); | |
| 3916 | - } | |
| 3917 | - | |
| 3918 | - $this->_template_args['success'] = $success; | |
| 3919 | - | |
| 3920 | - // no special instructions so let's just do the json return (which should automatically do all the special stuff). | |
| 3921 | - $this->_return_json(); | |
| 3922 | - } | |
| 3923 | - | |
| 3924 | - | |
| 3925 | - /** | |
| 3926 | - * used by ajax from the messages settings page to activate|deactivate a message type | |
| 3927 | - * | |
| 3928 | - * @throws DomainException | |
| 3929 | - * @throws EE_Error | |
| 3930 | - * @throws ReflectionException | |
| 3931 | - * @throws InvalidDataTypeException | |
| 3932 | - * @throws InvalidInterfaceException | |
| 3933 | - * @throws InvalidArgumentException | |
| 3934 | - */ | |
| 3935 | - public function activate_mt_toggle() | |
| 3936 | -    { | |
| 3937 | - $success = true; | |
| 3938 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); | |
| 3939 | - | |
| 3940 | - // let's make sure we have the necessary data | |
| 3941 | -        if (! isset($this->_req_data['message_type'])) { | |
| 3942 | - EE_Error::add_error( | |
| 3943 | -                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), | |
| 3944 | - __FILE__, | |
| 3945 | - __FUNCTION__, | |
| 3946 | - __LINE__ | |
| 3947 | - ); | |
| 3948 | - $success = false; | |
| 3949 | - } | |
| 3950 | - | |
| 3951 | -        if (! isset($this->_req_data['messenger'])) { | |
| 3952 | - EE_Error::add_error( | |
| 3953 | -                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | |
| 3954 | - __FILE__, | |
| 3955 | - __FUNCTION__, | |
| 3956 | - __LINE__ | |
| 3957 | - ); | |
| 3958 | - $success = false; | |
| 3959 | - } | |
| 3960 | - | |
| 3961 | -        if (! isset($this->_req_data['status'])) { | |
| 3962 | - EE_Error::add_error( | |
| 3963 | - esc_html__( | |
| 3964 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', | |
| 3965 | - 'event_espresso' | |
| 3966 | - ), | |
| 3967 | - __FILE__, | |
| 3968 | - __FUNCTION__, | |
| 3969 | - __LINE__ | |
| 3970 | - ); | |
| 3971 | - $success = false; | |
| 3972 | - } | |
| 3973 | - | |
| 3974 | - | |
| 3975 | - // do check to verify we have a valid status. | |
| 3976 | - $status = $this->_req_data['status']; | |
| 3977 | - | |
| 3978 | -        if ($status !== 'activate' && $status !== 'deactivate') { | |
| 3979 | - EE_Error::add_error( | |
| 3980 | - sprintf( | |
| 3981 | -                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), | |
| 3982 | - $this->_req_data['status'] | |
| 3983 | - ), | |
| 3984 | - __FILE__, | |
| 3985 | - __FUNCTION__, | |
| 3986 | - __LINE__ | |
| 3987 | - ); | |
| 3988 | - $success = false; | |
| 3989 | - } | |
| 3990 | - | |
| 3991 | - | |
| 3992 | - // do a nonce check here since we're not arriving via a normal route | |
| 3993 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; | |
| 3994 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; | |
| 3995 | - | |
| 3996 | - $this->_verify_nonce($nonce, $nonce_ref); | |
| 3997 | - | |
| 3998 | -        if ($success) { | |
| 3999 | - // made it here? um, what are you waiting for then? | |
| 4000 | - $success = $status === 'deactivate' | |
| 4001 | - ? $this->_deactivate_message_type_for_messenger( | |
| 4002 | - $this->_req_data['messenger'], | |
| 4003 | - $this->_req_data['message_type'] | |
| 4004 | - ) | |
| 4005 | - : $this->_activate_message_type_for_messenger( | |
| 4006 | - $this->_req_data['messenger'], | |
| 4007 | - $this->_req_data['message_type'] | |
| 4008 | - ); | |
| 4009 | - } | |
| 4010 | - | |
| 4011 | - $this->_template_args['success'] = $success; | |
| 4012 | - $this->_return_json(); | |
| 4013 | - } | |
| 4014 | - | |
| 4015 | - | |
| 4016 | - /** | |
| 4017 | - * Takes care of processing activating a messenger and preparing the appropriate response. | |
| 4018 | - * | |
| 4019 | - * @param string $messenger_name The name of the messenger being activated | |
| 4020 | - * @return bool | |
| 4021 | - * @throws DomainException | |
| 4022 | - * @throws EE_Error | |
| 4023 | - * @throws InvalidArgumentException | |
| 4024 | - * @throws ReflectionException | |
| 4025 | - * @throws InvalidDataTypeException | |
| 4026 | - * @throws InvalidInterfaceException | |
| 4027 | - */ | |
| 4028 | - protected function _activate_messenger($messenger_name) | |
| 4029 | -    { | |
| 4030 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4031 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4032 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger | |
| 4033 | - ? $active_messenger->get_default_message_types() | |
| 4034 | - : []; | |
| 4035 | - | |
| 4036 | - // ensure is active | |
| 4037 | - $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate); | |
| 4038 | - | |
| 4039 | - // set response_data for reload | |
| 4040 | -        foreach ($message_types_to_activate as $message_type_name) { | |
| 4041 | - /** @var EE_message_type $message_type */ | |
| 4042 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); | |
| 4043 | - if ( | |
| 4044 | - $this->_message_resource_manager->is_message_type_active_for_messenger( | |
| 4045 | - $messenger_name, | |
| 4046 | - $message_type_name | |
| 4047 | - ) | |
| 4048 | - && $message_type instanceof EE_message_type | |
| 4049 | -            ) { | |
| 4050 | - $this->_template_args['data']['active_mts'][] = $message_type_name; | |
| 4051 | -                if ($message_type->get_admin_settings_fields()) { | |
| 4052 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; | |
| 4053 | - } | |
| 4054 | - } | |
| 4055 | - } | |
| 4056 | - | |
| 4057 | - // add success message for activating messenger | |
| 4058 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); | |
| 4059 | - } | |
| 4060 | - | |
| 4061 | - | |
| 4062 | - /** | |
| 4063 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. | |
| 4064 | - * | |
| 4065 | - * @param string $messenger_name The name of the messenger being activated | |
| 4066 | - * @return bool | |
| 4067 | - * @throws DomainException | |
| 4068 | - * @throws EE_Error | |
| 4069 | - * @throws InvalidArgumentException | |
| 4070 | - * @throws ReflectionException | |
| 4071 | - * @throws InvalidDataTypeException | |
| 4072 | - * @throws InvalidInterfaceException | |
| 4073 | - */ | |
| 4074 | - protected function _deactivate_messenger($messenger_name) | |
| 4075 | -    { | |
| 4076 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4077 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4078 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); | |
| 4079 | - | |
| 4080 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); | |
| 4081 | - } | |
| 4082 | - | |
| 4083 | - | |
| 4084 | - /** | |
| 4085 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. | |
| 4086 | - * | |
| 4087 | - * @param string $messenger_name The name of the messenger the message type is being activated for. | |
| 4088 | - * @param string $message_type_name The name of the message type being activated for the messenger | |
| 4089 | - * @return bool | |
| 4090 | - * @throws DomainException | |
| 4091 | - * @throws EE_Error | |
| 4092 | - * @throws InvalidArgumentException | |
| 4093 | - * @throws ReflectionException | |
| 4094 | - * @throws InvalidDataTypeException | |
| 4095 | - * @throws InvalidInterfaceException | |
| 4096 | - */ | |
| 4097 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) | |
| 4098 | -    { | |
| 4099 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4100 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4101 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ | |
| 4102 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); | |
| 4103 | - | |
| 4104 | - // ensure is active | |
| 4105 | - $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name); | |
| 4106 | - | |
| 4107 | - // set response for load | |
| 4108 | - if ( | |
| 4109 | - $this->_message_resource_manager->is_message_type_active_for_messenger( | |
| 4110 | - $messenger_name, | |
| 4111 | - $message_type_name | |
| 4112 | - ) | |
| 4113 | -        ) { | |
| 4114 | - $this->_template_args['data']['active_mts'][] = $message_type_name; | |
| 4115 | -            if ($message_type_to_activate->get_admin_settings_fields()) { | |
| 4116 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; | |
| 4117 | - } | |
| 4118 | - } | |
| 4119 | - | |
| 4120 | - return $this->_setup_response_message_for_activating_messenger_with_message_types( | |
| 4121 | - $active_messenger, | |
| 4122 | - $message_type_to_activate | |
| 4123 | - ); | |
| 4124 | - } | |
| 4125 | - | |
| 4126 | - | |
| 4127 | - /** | |
| 4128 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. | |
| 4129 | - * | |
| 4130 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. | |
| 4131 | - * @param string $message_type_name The name of the message type being deactivated for the messenger | |
| 4132 | - * @return bool | |
| 4133 | - * @throws DomainException | |
| 4134 | - * @throws EE_Error | |
| 4135 | - * @throws InvalidArgumentException | |
| 4136 | - * @throws ReflectionException | |
| 4137 | - * @throws InvalidDataTypeException | |
| 4138 | - * @throws InvalidInterfaceException | |
| 4139 | - */ | |
| 4140 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) | |
| 4141 | -    { | |
| 4142 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4143 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4144 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ | |
| 4145 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); | |
| 4146 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); | |
| 4147 | - | |
| 4148 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types( | |
| 4149 | - $active_messenger, | |
| 4150 | - $message_type_to_deactivate | |
| 4151 | - ); | |
| 4152 | - } | |
| 4153 | - | |
| 4154 | - | |
| 4155 | - /** | |
| 4156 | - * This just initializes the defaults for activating messenger and message type responses. | |
| 4157 | - */ | |
| 4158 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() | |
| 4159 | -    { | |
| 4160 | - $this->_template_args['data']['active_mts'] = []; | |
| 4161 | - $this->_template_args['data']['mt_reload'] = []; | |
| 4162 | - } | |
| 4163 | - | |
| 4164 | - | |
| 4165 | - /** | |
| 4166 | - * Setup appropriate response for activating a messenger and/or message types | |
| 4167 | - * | |
| 4168 | - * @param EE_messenger $messenger | |
| 4169 | - * @param EE_message_type|null $message_type | |
| 4170 | - * @return bool | |
| 4171 | - * @throws DomainException | |
| 4172 | - * @throws EE_Error | |
| 4173 | - * @throws InvalidArgumentException | |
| 4174 | - * @throws ReflectionException | |
| 4175 | - * @throws InvalidDataTypeException | |
| 4176 | - * @throws InvalidInterfaceException | |
| 4177 | - */ | |
| 4178 | - protected function _setup_response_message_for_activating_messenger_with_message_types( | |
| 4179 | - $messenger, | |
| 4180 | - EE_Message_Type $message_type = null | |
| 4181 | -    ) { | |
| 4182 | - // if $messenger isn't a valid messenger object then get out. | |
| 4183 | -        if (! $messenger instanceof EE_Messenger) { | |
| 4184 | - EE_Error::add_error( | |
| 4185 | -                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), | |
| 4186 | - __FILE__, | |
| 4187 | - __FUNCTION__, | |
| 4188 | - __LINE__ | |
| 4189 | - ); | |
| 4190 | - | |
| 4191 | - return false; | |
| 4192 | - } | |
| 4193 | - // activated | |
| 4194 | -        if ($this->_template_args['data']['active_mts']) { | |
| 4195 | - EE_Error::overwrite_success(); | |
| 4196 | - // activated a message type with the messenger | |
| 4197 | -            if ($message_type instanceof EE_message_type) { | |
| 4198 | - EE_Error::add_success( | |
| 4199 | - sprintf( | |
| 4200 | - esc_html__( | |
| 4201 | - '%s message type has been successfully activated with the %s messenger', | |
| 4202 | - 'event_espresso' | |
| 4203 | - ), | |
| 4204 | - ucwords($message_type->label['singular']), | |
| 4205 | - ucwords($messenger->label['singular']) | |
| 4206 | - ) | |
| 4207 | - ); | |
| 4208 | - | |
| 4209 | - // if message type was invoice then let's make sure we activate the invoice payment method. | |
| 4210 | -                if ($message_type->name === 'invoice') { | |
| 4211 | -                    EE_Registry::instance()->load_lib('Payment_Method_Manager'); | |
| 4212 | -                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); | |
| 4213 | -                    if ($pm instanceof EE_Payment_Method) { | |
| 4214 | - EE_Error::add_attention( | |
| 4215 | - esc_html__( | |
| 4216 | - 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', | |
| 4217 | - 'event_espresso' | |
| 4218 | - ) | |
| 4219 | - ); | |
| 4220 | - } | |
| 4221 | - } | |
| 4222 | - // just toggles the entire messenger | |
| 4223 | -            } else { | |
| 4224 | - EE_Error::add_success( | |
| 4225 | - sprintf( | |
| 4226 | -                        esc_html__('%s messenger has been successfully activated', 'event_espresso'), | |
| 4227 | - ucwords($messenger->label['singular']) | |
| 4228 | - ) | |
| 4229 | - ); | |
| 4230 | - } | |
| 4231 | - | |
| 4232 | - return true; | |
| 4233 | - | |
| 4234 | - // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active | |
| 4235 | - // message types after the activation process. However its possible some messengers don't HAVE any default_message_types | |
| 4236 | - // in which case we just give a success message for the messenger being successfully activated. | |
| 4237 | -        } else { | |
| 4238 | -            if (! $messenger->get_default_message_types()) { | |
| 4239 | - // messenger doesn't have any default message types so still a success. | |
| 4240 | - EE_Error::add_success( | |
| 4241 | - sprintf( | |
| 4242 | -                        esc_html__('%s messenger was successfully activated.', 'event_espresso'), | |
| 4243 | - ucwords($messenger->label['singular']) | |
| 4244 | - ) | |
| 4245 | - ); | |
| 4246 | - | |
| 4247 | - return true; | |
| 4248 | -            } else { | |
| 4249 | - EE_Error::add_error( | |
| 4250 | - $message_type instanceof EE_message_type | |
| 4251 | - ? sprintf( | |
| 4252 | - esc_html__( | |
| 4253 | - '%s message type was not successfully activated with the %s messenger', | |
| 4254 | - 'event_espresso' | |
| 4255 | - ), | |
| 4256 | - ucwords($message_type->label['singular']), | |
| 4257 | - ucwords($messenger->label['singular']) | |
| 4258 | - ) | |
| 4259 | - : sprintf( | |
| 4260 | -                            esc_html__('%s messenger was not successfully activated', 'event_espresso'), | |
| 4261 | - ucwords($messenger->label['singular']) | |
| 4262 | - ), | |
| 4263 | - __FILE__, | |
| 4264 | - __FUNCTION__, | |
| 4265 | - __LINE__ | |
| 4266 | - ); | |
| 4267 | - | |
| 4268 | - return false; | |
| 4269 | - } | |
| 4270 | - } | |
| 4271 | - } | |
| 4272 | - | |
| 4273 | - | |
| 4274 | - /** | |
| 4275 | - * This sets up the appropriate response for deactivating a messenger and/or message type. | |
| 4276 | - * | |
| 4277 | - * @param EE_messenger $messenger | |
| 4278 | - * @param EE_message_type|null $message_type | |
| 4279 | - * @return bool | |
| 4280 | - * @throws DomainException | |
| 4281 | - * @throws EE_Error | |
| 4282 | - * @throws InvalidArgumentException | |
| 4283 | - * @throws ReflectionException | |
| 4284 | - * @throws InvalidDataTypeException | |
| 4285 | - * @throws InvalidInterfaceException | |
| 4286 | - */ | |
| 4287 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( | |
| 4288 | - $messenger, | |
| 4289 | - EE_message_type $message_type = null | |
| 4290 | -    ) { | |
| 4291 | - EE_Error::overwrite_success(); | |
| 4292 | - | |
| 4293 | - // if $messenger isn't a valid messenger object then get out. | |
| 4294 | -        if (! $messenger instanceof EE_Messenger) { | |
| 4295 | - EE_Error::add_error( | |
| 4296 | -                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), | |
| 4297 | - __FILE__, | |
| 4298 | - __FUNCTION__, | |
| 4299 | - __LINE__ | |
| 4300 | - ); | |
| 4301 | - | |
| 4302 | - return false; | |
| 4303 | - } | |
| 4304 | - | |
| 4305 | -        if ($message_type instanceof EE_message_type) { | |
| 4306 | - $message_type_name = $message_type->name; | |
| 4307 | - EE_Error::add_success( | |
| 4308 | - sprintf( | |
| 4309 | - esc_html__( | |
| 4310 | - '%s message type has been successfully deactivated for the %s messenger.', | |
| 4311 | - 'event_espresso' | |
| 4312 | - ), | |
| 4313 | - ucwords($message_type->label['singular']), | |
| 4314 | - ucwords($messenger->label['singular']) | |
| 4315 | - ) | |
| 4316 | - ); | |
| 4317 | -        } else { | |
| 4318 | - $message_type_name = ''; | |
| 4319 | - EE_Error::add_success( | |
| 4320 | - sprintf( | |
| 4321 | -                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), | |
| 4322 | - ucwords($messenger->label['singular']) | |
| 4323 | - ) | |
| 4324 | - ); | |
| 4325 | - } | |
| 4326 | - | |
| 4327 | - // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. | |
| 4328 | -        if ($messenger->name === 'html' || $message_type_name === 'invoice') { | |
| 4329 | -            EE_Registry::instance()->load_lib('Payment_Method_Manager'); | |
| 4330 | -            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); | |
| 4331 | -            if ($count_updated > 0) { | |
| 4332 | - $msg = $message_type_name === 'invoice' | |
| 4333 | - ? esc_html__( | |
| 4334 | - 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', | |
| 4335 | - 'event_espresso' | |
| 4336 | - ) | |
| 4337 | - : esc_html__( | |
| 4338 | - 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', | |
| 4339 | - 'event_espresso' | |
| 4340 | - ); | |
| 4341 | - EE_Error::add_attention($msg); | |
| 4342 | - } | |
| 4343 | - } | |
| 4344 | - | |
| 4345 | - return true; | |
| 4346 | - } | |
| 4347 | - | |
| 4348 | - | |
| 4349 | - /** | |
| 4350 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) | |
| 4351 | - * | |
| 4352 | - * @throws DomainException | |
| 4353 | - */ | |
| 4354 | - public function update_mt_form() | |
| 4355 | -    { | |
| 4356 | -        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { | |
| 4357 | - EE_Error::add_error( | |
| 4358 | -                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), | |
| 4359 | - __FILE__, | |
| 4360 | - __FUNCTION__, | |
| 4361 | - __LINE__ | |
| 4362 | - ); | |
| 4363 | - $this->_return_json(); | |
| 4364 | - } | |
| 4365 | - | |
| 4366 | - $message_types = $this->get_installed_message_types(); | |
| 4367 | - | |
| 4368 | - $message_type = $message_types[ $this->_req_data['message_type'] ]; | |
| 4369 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); | |
| 4370 | - | |
| 4371 | - $content = $this->_message_type_settings_content( | |
| 4372 | - $message_type, | |
| 4373 | - $messenger, | |
| 4374 | - true | |
| 4375 | - ); | |
| 4376 | - $this->_template_args['success'] = true; | |
| 4377 | - $this->_template_args['content'] = $content; | |
| 4378 | - $this->_return_json(); | |
| 4379 | - } | |
| 4380 | - | |
| 4381 | - | |
| 4382 | - /** | |
| 4383 | - * this handles saving the settings for a messenger or message type | |
| 4384 | - * | |
| 4385 | - */ | |
| 4386 | - public function save_settings() | |
| 4387 | -    { | |
| 4388 | -        if (! isset($this->_req_data['type'])) { | |
| 4389 | - EE_Error::add_error( | |
| 4390 | - esc_html__( | |
| 4391 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', | |
| 4392 | - 'event_espresso' | |
| 4393 | - ), | |
| 4394 | - __FILE__, | |
| 4395 | - __FUNCTION__, | |
| 4396 | - __LINE__ | |
| 4397 | - ); | |
| 4398 | - $this->_template_args['error'] = true; | |
| 4399 | - $this->_return_json(); | |
| 4400 | - } | |
| 4401 | - | |
| 4402 | - | |
| 4403 | -        if ($this->_req_data['type'] === 'messenger') { | |
| 4404 | - // this should be an array. | |
| 4405 | - $settings = $this->_req_data['messenger_settings']; | |
| 4406 | - $messenger = $settings['messenger']; | |
| 4407 | - // let's setup the settings data | |
| 4408 | -            foreach ($settings as $key => $value) { | |
| 4409 | -                switch ($key) { | |
| 4410 | - case 'messenger': | |
| 4411 | - unset($settings['messenger']); | |
| 4412 | - break; | |
| 4413 | - case 'message_types': | |
| 4414 | - unset($settings['message_types']); | |
| 4415 | - break; | |
| 4416 | - default: | |
| 4417 | - $settings[ $key ] = $value; | |
| 4418 | - break; | |
| 4419 | - } | |
| 4420 | - } | |
| 4421 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); | |
| 4422 | -        } elseif ($this->_req_data['type'] === 'message_type') { | |
| 4423 | - $settings = $this->_req_data['message_type_settings']; | |
| 4424 | - $messenger = $settings['messenger']; | |
| 4425 | - $message_type = $settings['message_type']; | |
| 4426 | - | |
| 4427 | -            foreach ($settings as $key => $value) { | |
| 4428 | -                switch ($key) { | |
| 4429 | - case 'messenger': | |
| 4430 | - unset($settings['messenger']); | |
| 4431 | - break; | |
| 4432 | - case 'message_type': | |
| 4433 | - unset($settings['message_type']); | |
| 4434 | - break; | |
| 4435 | - default: | |
| 4436 | - $settings[ $key ] = $value; | |
| 4437 | - break; | |
| 4438 | - } | |
| 4439 | - } | |
| 4440 | - | |
| 4441 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); | |
| 4442 | - } | |
| 4443 | - | |
| 4444 | - // okay we should have the data all setup. Now we just update! | |
| 4445 | - $success = $this->_message_resource_manager->update_active_messengers_option(); | |
| 4446 | - | |
| 4447 | -        if ($success) { | |
| 4448 | -            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso')); | |
| 4449 | -        } else { | |
| 4450 | - EE_Error::add_error( | |
| 4451 | - esc_html__( | |
| 4452 | - 'Settings did not get updated', | |
| 4453 | - 'event_espresso' | |
| 4454 | - ), | |
| 4455 | - __FILE__, | |
| 4456 | - __FUNCTION__, | |
| 4457 | - __LINE__ | |
| 4458 | - ); | |
| 4459 | - } | |
| 4460 | - | |
| 4461 | - $this->_template_args['success'] = $success; | |
| 4462 | - $this->_return_json(); | |
| 4463 | - } | |
| 4464 | - | |
| 4465 | - | |
| 4466 | - | |
| 4467 | - | |
| 4468 | - /** EE MESSAGE PROCESSING ACTIONS **/ | |
| 4469 | - | |
| 4470 | - | |
| 4471 | - /** | |
| 4472 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete | |
| 4473 | - * However, this does not send immediately, it just queues for sending. | |
| 4474 | - * | |
| 4475 | - * @throws EE_Error | |
| 4476 | - * @throws InvalidDataTypeException | |
| 4477 | - * @throws InvalidInterfaceException | |
| 4478 | - * @throws InvalidArgumentException | |
| 4479 | - * @throws ReflectionException | |
| 4480 | - * @since 4.9.0 | |
| 4481 | - */ | |
| 4482 | - protected function _generate_now() | |
| 4483 | -    { | |
| 4484 | - EED_Messages::generate_now($this->_get_msg_ids_from_request()); | |
| 4485 | - $this->_redirect_after_action(false, '', '', [], true); | |
| 4486 | - } | |
| 4487 | - | |
| 4488 | - | |
| 4489 | - /** | |
| 4490 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that | |
| 4491 | - * are EEM_Message::status_resend or EEM_Message::status_idle | |
| 4492 | - * | |
| 4493 | - * @throws EE_Error | |
| 4494 | - * @throws InvalidDataTypeException | |
| 4495 | - * @throws InvalidInterfaceException | |
| 4496 | - * @throws InvalidArgumentException | |
| 4497 | - * @throws ReflectionException | |
| 4498 | - * @since 4.9.0 | |
| 4499 | - */ | |
| 4500 | - protected function _generate_and_send_now() | |
| 4501 | -    { | |
| 4502 | - EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); | |
| 4503 | - $this->_redirect_after_action(false, '', '', [], true); | |
| 4504 | - } | |
| 4505 | - | |
| 4506 | - | |
| 4507 | - /** | |
| 4508 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. | |
| 4509 | - * | |
| 4510 | - * @throws EE_Error | |
| 4511 | - * @throws InvalidDataTypeException | |
| 4512 | - * @throws InvalidInterfaceException | |
| 4513 | - * @throws InvalidArgumentException | |
| 4514 | - * @throws ReflectionException | |
| 4515 | - * @since 4.9.0 | |
| 4516 | - */ | |
| 4517 | - protected function _queue_for_resending() | |
| 4518 | -    { | |
| 4519 | - EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); | |
| 4520 | - $this->_redirect_after_action(false, '', '', [], true); | |
| 4521 | - } | |
| 4522 | - | |
| 4523 | - | |
| 4524 | - /** | |
| 4525 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue | |
| 4526 | - * | |
| 4527 | - * @throws EE_Error | |
| 4528 | - * @throws InvalidDataTypeException | |
| 4529 | - * @throws InvalidInterfaceException | |
| 4530 | - * @throws InvalidArgumentException | |
| 4531 | - * @throws ReflectionException | |
| 4532 | - * @since 4.9.0 | |
| 4533 | - */ | |
| 4534 | - protected function _send_now() | |
| 4535 | -    { | |
| 4536 | - EED_Messages::send_now($this->_get_msg_ids_from_request()); | |
| 4537 | - $this->_redirect_after_action(false, '', '', [], true); | |
| 4538 | - } | |
| 4539 | - | |
| 4540 | - | |
| 4541 | - /** | |
| 4542 | - * Deletes EE_messages for IDs in the request. | |
| 4543 | - * | |
| 4544 | - * @throws EE_Error | |
| 4545 | - * @throws InvalidDataTypeException | |
| 4546 | - * @throws InvalidInterfaceException | |
| 4547 | - * @throws InvalidArgumentException | |
| 4548 | - * @since 4.9.0 | |
| 4549 | - */ | |
| 4550 | - protected function _delete_ee_messages() | |
| 4551 | -    { | |
| 4552 | - $msg_ids = $this->_get_msg_ids_from_request(); | |
| 4553 | - $deleted_count = 0; | |
| 4554 | -        foreach ($msg_ids as $msg_id) { | |
| 4555 | -            if (EEM_Message::instance()->delete_by_ID($msg_id)) { | |
| 4556 | - $deleted_count++; | |
| 4557 | - } | |
| 4558 | - } | |
| 4559 | -        if ($deleted_count) { | |
| 4560 | - EE_Error::add_success( | |
| 4561 | - esc_html( | |
| 4562 | - _n( | |
| 4563 | - 'Message successfully deleted', | |
| 4564 | - 'Messages successfully deleted', | |
| 4565 | - $deleted_count, | |
| 4566 | - 'event_espresso' | |
| 4567 | - ) | |
| 4568 | - ) | |
| 4569 | - ); | |
| 4570 | - $this->_redirect_after_action( | |
| 4571 | - false, | |
| 4572 | - '', | |
| 4573 | - '', | |
| 4574 | - [], | |
| 4575 | - true | |
| 4576 | - ); | |
| 4577 | -        } else { | |
| 4578 | - EE_Error::add_error( | |
| 4579 | -                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), | |
| 4580 | - __FILE__, | |
| 4581 | - __FUNCTION__, | |
| 4582 | - __LINE__ | |
| 4583 | - ); | |
| 4584 | - $this->_redirect_after_action(false, '', '', [], true); | |
| 4585 | - } | |
| 4586 | - } | |
| 4587 | - | |
| 4588 | - | |
| 4589 | - /** | |
| 4590 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. | |
| 4591 | - * | |
| 4592 | - * @return array | |
| 4593 | - * @since 4.9.0 | |
| 4594 | - */ | |
| 4595 | - protected function _get_msg_ids_from_request() | |
| 4596 | -    { | |
| 4597 | -        if (! isset($this->_req_data['MSG_ID'])) { | |
| 4598 | - return []; | |
| 4599 | - } | |
| 4600 | - | |
| 4601 | - return is_array($this->_req_data['MSG_ID']) | |
| 4602 | - ? array_keys($this->_req_data['MSG_ID']) | |
| 4603 | - : [$this->_req_data['MSG_ID']]; | |
| 4604 | - } | |
| 2680 | + $this->_context_switcher = ob_get_clean(); | |
| 2681 | + } | |
| 2682 | + | |
| 2683 | + | |
| 2684 | + /** | |
| 2685 | + * utility for sanitizing new values coming in. | |
| 2686 | + * Note: this is only used when updating a context. | |
| 2687 | + * | |
| 2688 | + * @access protected | |
| 2689 | + * | |
| 2690 | + * @param int $index This helps us know which template field to select from the request array. | |
| 2691 | + * | |
| 2692 | + * @return array | |
| 2693 | + */ | |
| 2694 | + protected function _set_message_template_column_values($index) | |
| 2695 | +	{ | |
| 2696 | +		if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) { | |
| 2697 | +			foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) { | |
| 2698 | + $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value; | |
| 2699 | + } | |
| 2700 | + } | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + $set_column_values = [ | |
| 2704 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']), | |
| 2705 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), | |
| 2706 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), | |
| 2707 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), | |
| 2708 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), | |
| 2709 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']), | |
| 2710 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), | |
| 2711 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][ $index ]['content'], | |
| 2712 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) | |
| 2713 | + ? absint($this->_req_data['MTP_is_global']) | |
| 2714 | + : 0, | |
| 2715 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) | |
| 2716 | + ? absint($this->_req_data['MTP_is_override']) | |
| 2717 | + : 0, | |
| 2718 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), | |
| 2719 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']), | |
| 2720 | + ]; | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + return $set_column_values; | |
| 2724 | + } | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + protected function _insert_or_update_message_template($new = false) | |
| 2728 | +	{ | |
| 2729 | + | |
| 2730 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 2731 | + $success = 0; | |
| 2732 | + $override = false; | |
| 2733 | + | |
| 2734 | + // setup notices description | |
| 2735 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; | |
| 2736 | + | |
| 2737 | + // need the message type and messenger objects to be able to use the labels for the notices | |
| 2738 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); | |
| 2739 | + $messenger_label = $messenger_object instanceof EE_messenger | |
| 2740 | + ? ucwords($messenger_object->label['singular']) | |
| 2741 | + : ''; | |
| 2742 | + | |
| 2743 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) | |
| 2744 | + ? $this->_req_data['MTP_message_type'] | |
| 2745 | + : ''; | |
| 2746 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); | |
| 2747 | + | |
| 2748 | + $message_type_label = $message_type_object instanceof EE_message_type | |
| 2749 | + ? ucwords($message_type_object->label['singular']) | |
| 2750 | + : ''; | |
| 2751 | + | |
| 2752 | + $context_slug = ! empty($this->_req_data['MTP_context']) | |
| 2753 | + ? $this->_req_data['MTP_context'] | |
| 2754 | + : ''; | |
| 2755 | +		$context      = ucwords(str_replace('_', ' ', $context_slug)); | |
| 2756 | + | |
| 2757 | + $item_desc = $messenger_label && $message_type_label | |
| 2758 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' | |
| 2759 | + : ''; | |
| 2760 | + $item_desc .= 'Message Template'; | |
| 2761 | + $query_args = []; | |
| 2762 | + $edit_array = []; | |
| 2763 | + $action_desc = ''; | |
| 2764 | + | |
| 2765 | + // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for | |
| 2766 | + // user to edit. | |
| 2767 | +		if ($new) { | |
| 2768 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; | |
| 2769 | +			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { | |
| 2770 | +				if (empty($edit_array)) { | |
| 2771 | + $success = 0; | |
| 2772 | +				} else { | |
| 2773 | + $success = 1; | |
| 2774 | + $edit_array = $edit_array[0]; | |
| 2775 | + $query_args = [ | |
| 2776 | + 'id' => $edit_array['GRP_ID'], | |
| 2777 | + 'context' => $edit_array['MTP_context'], | |
| 2778 | + 'action' => 'edit_message_template', | |
| 2779 | + ]; | |
| 2780 | + } | |
| 2781 | + } | |
| 2782 | + $action_desc = 'created'; | |
| 2783 | +		} else { | |
| 2784 | + $MTPG = EEM_Message_Template_Group::instance(); | |
| 2785 | + $MTP = EEM_Message_Template::instance(); | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + // run update for each template field in displayed context | |
| 2789 | +			if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { | |
| 2790 | + EE_Error::add_error( | |
| 2791 | + esc_html__( | |
| 2792 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', | |
| 2793 | + 'event_espresso' | |
| 2794 | + ), | |
| 2795 | + __FILE__, | |
| 2796 | + __FUNCTION__, | |
| 2797 | + __LINE__ | |
| 2798 | + ); | |
| 2799 | + $success = 0; | |
| 2800 | +			} else { | |
| 2801 | + // first validate all fields! | |
| 2802 | + // this filter allows client code to add its own validation to the template fields as well. | |
| 2803 | + // returning an empty array means everything passed validation. | |
| 2804 | + // errors in validation should be represented in an array with the following shape: | |
| 2805 | + // array( | |
| 2806 | + // 'fieldname' => array( | |
| 2807 | + // 'msg' => 'error message' | |
| 2808 | + // 'value' => 'value for field producing error' | |
| 2809 | + // ) | |
| 2810 | + $custom_validation = (array) apply_filters( | |
| 2811 | + 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', | |
| 2812 | + [], | |
| 2813 | + $this->_req_data['MTP_template_fields'], | |
| 2814 | + $context_slug, | |
| 2815 | + $messenger_slug, | |
| 2816 | + $message_type_slug | |
| 2817 | + ); | |
| 2818 | + | |
| 2819 | + $system_validation = $MTPG->validate( | |
| 2820 | + $this->_req_data['MTP_template_fields'], | |
| 2821 | + $context_slug, | |
| 2822 | + $messenger_slug, | |
| 2823 | + $message_type_slug | |
| 2824 | + ); | |
| 2825 | + | |
| 2826 | + $system_validation = ! is_array($system_validation) && $system_validation ? [] | |
| 2827 | + : $system_validation; | |
| 2828 | + $validates = array_merge($custom_validation, $system_validation); | |
| 2829 | + | |
| 2830 | + // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an | |
| 2831 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. | |
| 2832 | + // WE need to make sure there is no actual error messages in validates. | |
| 2833 | +				if (is_array($validates) && ! empty($validates)) { | |
| 2834 | + // add the transient so when the form loads we know which fields to highlight | |
| 2835 | +					$this->_add_transient('edit_message_template', $validates); | |
| 2836 | + | |
| 2837 | + $success = 0; | |
| 2838 | + | |
| 2839 | + // setup notices | |
| 2840 | +					foreach ($validates as $field => $error) { | |
| 2841 | +						if (isset($error['msg'])) { | |
| 2842 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); | |
| 2843 | + } | |
| 2844 | + } | |
| 2845 | +				} else { | |
| 2846 | + $set_column_values = []; | |
| 2847 | +					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { | |
| 2848 | + $set_column_values = $this->_set_message_template_column_values($template_field); | |
| 2849 | + | |
| 2850 | + $where_cols_n_values = [ | |
| 2851 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'], | |
| 2852 | + ]; | |
| 2853 | + // if they aren't allowed to use all JS, restrict them to just posty-y tags | |
| 2854 | +						if (! current_user_can('unfiltered_html')) { | |
| 2855 | +							if (is_array($set_column_values['MTP_content'])) { | |
| 2856 | +								foreach ($set_column_values['MTP_content'] as $key => $value) { | |
| 2857 | + // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function | |
| 2858 | + // only removes slashes from double-quotes, so attributes using single quotes always | |
| 2859 | + // appear invalid.) But currently the models expect slashed data, so after wp_kses | |
| 2860 | + // runs we need to re-slash the data. Sheesh. See | |
| 2861 | + // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 | |
| 2862 | + $set_column_values['MTP_content'][ $key ] = addslashes( | |
| 2863 | + wp_kses( | |
| 2864 | + stripslashes($value), | |
| 2865 | +											wp_kses_allowed_html('post') | |
| 2866 | + ) | |
| 2867 | + ); | |
| 2868 | + } | |
| 2869 | +							} else { | |
| 2870 | + $set_column_values['MTP_content'] = wp_kses( | |
| 2871 | + $set_column_values['MTP_content'], | |
| 2872 | +									wp_kses_allowed_html('post') | |
| 2873 | + ); | |
| 2874 | + } | |
| 2875 | + } | |
| 2876 | + $message_template_fields = [ | |
| 2877 | + 'GRP_ID' => $set_column_values['GRP_ID'], | |
| 2878 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], | |
| 2879 | + 'MTP_context' => $set_column_values['MTP_context'], | |
| 2880 | + 'MTP_content' => $set_column_values['MTP_content'], | |
| 2881 | + ]; | |
| 2882 | +						if ($updated = $MTP->update($message_template_fields, [$where_cols_n_values])) { | |
| 2883 | +							if ($updated === false) { | |
| 2884 | + EE_Error::add_error( | |
| 2885 | + sprintf( | |
| 2886 | +										esc_html__('%s field was NOT updated for some reason', 'event_espresso'), | |
| 2887 | + $template_field | |
| 2888 | + ), | |
| 2889 | + __FILE__, | |
| 2890 | + __FUNCTION__, | |
| 2891 | + __LINE__ | |
| 2892 | + ); | |
| 2893 | +							} else { | |
| 2894 | + $success = 1; | |
| 2895 | + } | |
| 2896 | +						} else { | |
| 2897 | + // only do this logic if we don't have a MTP_ID for this field | |
| 2898 | +							if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) { | |
| 2899 | + // this has already been through the template field validator and sanitized, so it will be | |
| 2900 | + // safe to insert this field. Why insert? This typically happens when we introduce a new | |
| 2901 | + // message template field in a messenger/message type and existing users don't have the | |
| 2902 | + // default setup for it. | |
| 2903 | + // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 | |
| 2904 | + $updated = $MTP->insert($message_template_fields); | |
| 2905 | +								if (! $updated || is_wp_error($updated)) { | |
| 2906 | + EE_Error::add_error( | |
| 2907 | + sprintf( | |
| 2908 | +											esc_html__('%s field could not be updated.', 'event_espresso'), | |
| 2909 | + $template_field | |
| 2910 | + ), | |
| 2911 | + __FILE__, | |
| 2912 | + __FUNCTION__, | |
| 2913 | + __LINE__ | |
| 2914 | + ); | |
| 2915 | + $success = 0; | |
| 2916 | +								} else { | |
| 2917 | + $success = 1; | |
| 2918 | + } | |
| 2919 | + } | |
| 2920 | + } | |
| 2921 | + $action_desc = 'updated'; | |
| 2922 | + } | |
| 2923 | + | |
| 2924 | + // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) | |
| 2925 | + $mtpg_fields = [ | |
| 2926 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], | |
| 2927 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], | |
| 2928 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], | |
| 2929 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], | |
| 2930 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], | |
| 2931 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], | |
| 2932 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], | |
| 2933 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) | |
| 2934 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] | |
| 2935 | + : '', | |
| 2936 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) | |
| 2937 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] | |
| 2938 | + : '', | |
| 2939 | + ]; | |
| 2940 | + | |
| 2941 | + $mtpg_where = ['GRP_ID' => $set_column_values['GRP_ID']]; | |
| 2942 | + $updated = $MTPG->update($mtpg_fields, [$mtpg_where]); | |
| 2943 | + | |
| 2944 | +					if ($updated === false) { | |
| 2945 | + EE_Error::add_error( | |
| 2946 | + sprintf( | |
| 2947 | + esc_html__( | |
| 2948 | + 'The Message Template Group (%d) was NOT updated for some reason', | |
| 2949 | + 'event_espresso' | |
| 2950 | + ), | |
| 2951 | + $set_column_values['GRP_ID'] | |
| 2952 | + ), | |
| 2953 | + __FILE__, | |
| 2954 | + __FUNCTION__, | |
| 2955 | + __LINE__ | |
| 2956 | + ); | |
| 2957 | +					} else { | |
| 2958 | + // k now we need to ensure the template_pack and template_variation fields are set. | |
| 2959 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) | |
| 2960 | + ? $this->_req_data['MTP_template_pack'] | |
| 2961 | + : 'default'; | |
| 2962 | + | |
| 2963 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) | |
| 2964 | + ? $this->_req_data['MTP_template_variation'] | |
| 2965 | + : 'default'; | |
| 2966 | + | |
| 2967 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); | |
| 2968 | +						if ($mtpg_obj instanceof EE_Message_Template_Group) { | |
| 2969 | + $mtpg_obj->set_template_pack_name($template_pack); | |
| 2970 | + $mtpg_obj->set_template_pack_variation($template_variation); | |
| 2971 | + } | |
| 2972 | + $success = 1; | |
| 2973 | + } | |
| 2974 | + } | |
| 2975 | + } | |
| 2976 | + } | |
| 2977 | + | |
| 2978 | + // we return things differently if doing ajax | |
| 2979 | +		if (defined('DOING_AJAX') && DOING_AJAX) { | |
| 2980 | + $this->_template_args['success'] = $success; | |
| 2981 | + $this->_template_args['error'] = ! $success ? true : false; | |
| 2982 | + $this->_template_args['content'] = ''; | |
| 2983 | + $this->_template_args['data'] = [ | |
| 2984 | + 'grpID' => $edit_array['GRP_ID'], | |
| 2985 | + 'templateName' => $edit_array['template_name'], | |
| 2986 | + ]; | |
| 2987 | +			if ($success) { | |
| 2988 | + EE_Error::overwrite_success(); | |
| 2989 | + EE_Error::add_success( | |
| 2990 | + esc_html__( | |
| 2991 | + 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', | |
| 2992 | + 'event_espresso' | |
| 2993 | + ) | |
| 2994 | + ); | |
| 2995 | + } | |
| 2996 | + | |
| 2997 | + $this->_return_json(); | |
| 2998 | + } | |
| 2999 | + | |
| 3000 | + | |
| 3001 | + // was a test send triggered? | |
| 3002 | +		if (isset($this->_req_data['test_button'])) { | |
| 3003 | + EE_Error::overwrite_success(); | |
| 3004 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); | |
| 3005 | + $override = true; | |
| 3006 | + } | |
| 3007 | + | |
| 3008 | +		if (empty($query_args)) { | |
| 3009 | + $query_args = [ | |
| 3010 | + 'id' => $this->_req_data['GRP_ID'], | |
| 3011 | + 'context' => $context_slug, | |
| 3012 | + 'action' => 'edit_message_template', | |
| 3013 | + ]; | |
| 3014 | + } | |
| 3015 | + | |
| 3016 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); | |
| 3017 | + } | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + /** | |
| 3021 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested | |
| 3022 | + * | |
| 3023 | + * @param string $context what context being tested | |
| 3024 | + * @param string $messenger messenger being tested | |
| 3025 | + * @param string $message_type message type being tested | |
| 3026 | + * @throws EE_Error | |
| 3027 | + * @throws InvalidArgumentException | |
| 3028 | + * @throws InvalidDataTypeException | |
| 3029 | + * @throws InvalidInterfaceException | |
| 3030 | + */ | |
| 3031 | + protected function _do_test_send($context, $messenger, $message_type) | |
| 3032 | +	{ | |
| 3033 | + // set things up for preview | |
| 3034 | + $this->_req_data['messenger'] = $messenger; | |
| 3035 | + $this->_req_data['message_type'] = $message_type; | |
| 3036 | + $this->_req_data['context'] = $context; | |
| 3037 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; | |
| 3038 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); | |
| 3039 | + | |
| 3040 | + // let's save any existing fields that might be required by the messenger | |
| 3041 | + if ( | |
| 3042 | + isset($this->_req_data['test_settings_fld']) | |
| 3043 | + && $active_messenger instanceof EE_messenger | |
| 3044 | + && apply_filters( | |
| 3045 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', | |
| 3046 | + true, | |
| 3047 | + $this->_req_data['test_settings_fld'], | |
| 3048 | + $active_messenger | |
| 3049 | + ) | |
| 3050 | +		) { | |
| 3051 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); | |
| 3052 | + } | |
| 3053 | + | |
| 3054 | + /** | |
| 3055 | + * Use filter to add additional controls on whether message can send or not | |
| 3056 | + */ | |
| 3057 | + if ( | |
| 3058 | + apply_filters( | |
| 3059 | + 'FHEE__Messages_Admin_Page__do_test_send__can_send', | |
| 3060 | + true, | |
| 3061 | + $context, | |
| 3062 | + $this->_req_data, | |
| 3063 | + $messenger, | |
| 3064 | + $message_type | |
| 3065 | + ) | |
| 3066 | +		) { | |
| 3067 | +			if (EEM_Event::instance()->count() > 0) { | |
| 3068 | + $success = $this->_preview_message(true); | |
| 3069 | +				if ($success) { | |
| 3070 | +					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso')); | |
| 3071 | +				} else { | |
| 3072 | + EE_Error::add_error( | |
| 3073 | +						esc_html__('The test message was not sent', 'event_espresso'), | |
| 3074 | + __FILE__, | |
| 3075 | + __FUNCTION__, | |
| 3076 | + __LINE__ | |
| 3077 | + ); | |
| 3078 | + } | |
| 3079 | +			} else { | |
| 3080 | + $this->noEventsErrorMessage(true); | |
| 3081 | + } | |
| 3082 | + } | |
| 3083 | + } | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + /** | |
| 3087 | + * _generate_new_templates | |
| 3088 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will | |
| 3089 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context | |
| 3090 | + * for the event. | |
| 3091 | + * | |
| 3092 | + * | |
| 3093 | + * @param string $messenger the messenger we are generating templates for | |
| 3094 | + * @param array $message_types array of message types that the templates are generated for. | |
| 3095 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to | |
| 3096 | + * indicate the message_template_group being used as the base. | |
| 3097 | + * | |
| 3098 | + * @param bool $global | |
| 3099 | + * | |
| 3100 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if | |
| 3101 | + * encountering problems. | |
| 3102 | + * @throws EE_Error | |
| 3103 | + */ | |
| 3104 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) | |
| 3105 | +	{ | |
| 3106 | + | |
| 3107 | + // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we | |
| 3108 | + // just don't generate any templates. | |
| 3109 | +		if (empty($message_types)) { | |
| 3110 | + return true; | |
| 3111 | + } | |
| 3112 | + | |
| 3113 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); | |
| 3114 | + } | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + /** | |
| 3118 | + * [_trash_or_restore_message_template] | |
| 3119 | + * | |
| 3120 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) | |
| 3121 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just | |
| 3122 | + * an individual context (FALSE). | |
| 3123 | + * @return void | |
| 3124 | + * @throws EE_Error | |
| 3125 | + * @throws InvalidArgumentException | |
| 3126 | + * @throws InvalidDataTypeException | |
| 3127 | + * @throws InvalidInterfaceException | |
| 3128 | + */ | |
| 3129 | + protected function _trash_or_restore_message_template($trash = true, $all = false) | |
| 3130 | +	{ | |
| 3131 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 3132 | + $MTP = EEM_Message_Template_Group::instance(); | |
| 3133 | + | |
| 3134 | + $success = 1; | |
| 3135 | + | |
| 3136 | + // incoming GRP_IDs | |
| 3137 | +		if ($all) { | |
| 3138 | + // Checkboxes | |
| 3139 | +			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | |
| 3140 | + // if array has more than one element then success message should be plural. | |
| 3141 | + // todo: what about nonce? | |
| 3142 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; | |
| 3143 | + | |
| 3144 | + // cycle through checkboxes | |
| 3145 | +				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | |
| 3146 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); | |
| 3147 | +					if (! $trashed_or_restored) { | |
| 3148 | + $success = 0; | |
| 3149 | + } | |
| 3150 | + } | |
| 3151 | +			} else { | |
| 3152 | + // grab single GRP_ID and handle | |
| 3153 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; | |
| 3154 | +				if (! empty($GRP_ID)) { | |
| 3155 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); | |
| 3156 | +					if (! $trashed_or_restored) { | |
| 3157 | + $success = 0; | |
| 3158 | + } | |
| 3159 | +				} else { | |
| 3160 | + $success = 0; | |
| 3161 | + } | |
| 3162 | + } | |
| 3163 | + } | |
| 3164 | + | |
| 3165 | + $action_desc = $trash | |
| 3166 | +			? esc_html__('moved to the trash', 'event_espresso') | |
| 3167 | +			: esc_html__('restored', 'event_espresso'); | |
| 3168 | + | |
| 3169 | + $action_desc = | |
| 3170 | +			! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc; | |
| 3171 | + | |
| 3172 | + $item_desc = $all ? _n( | |
| 3173 | + 'Message Template Group', | |
| 3174 | + 'Message Template Groups', | |
| 3175 | + $success, | |
| 3176 | + 'event_espresso' | |
| 3177 | +		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); | |
| 3178 | + | |
| 3179 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n( | |
| 3180 | + 'template', | |
| 3181 | + 'templates', | |
| 3182 | + $success, | |
| 3183 | + 'event_espresso' | |
| 3184 | + ) : $item_desc; | |
| 3185 | + | |
| 3186 | + $this->_redirect_after_action($success, $item_desc, $action_desc, []); | |
| 3187 | + } | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + /** | |
| 3191 | + * [_delete_message_template] | |
| 3192 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. | |
| 3193 | + * | |
| 3194 | + * @return void | |
| 3195 | + * @throws EE_Error | |
| 3196 | + * @throws InvalidArgumentException | |
| 3197 | + * @throws InvalidDataTypeException | |
| 3198 | + * @throws InvalidInterfaceException | |
| 3199 | + */ | |
| 3200 | + protected function _delete_message_template() | |
| 3201 | +	{ | |
| 3202 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | |
| 3203 | + | |
| 3204 | + // checkboxes | |
| 3205 | +		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { | |
| 3206 | + // if array has more than one element then success message should be plural | |
| 3207 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; | |
| 3208 | + | |
| 3209 | + // cycle through bulk action checkboxes | |
| 3210 | +			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { | |
| 3211 | + $success = $this->_delete_mtp_permanently($GRP_ID); | |
| 3212 | + } | |
| 3213 | +		} else { | |
| 3214 | + // grab single grp_id and delete | |
| 3215 | + $GRP_ID = absint($this->_req_data['id']); | |
| 3216 | + $success = $this->_delete_mtp_permanently($GRP_ID); | |
| 3217 | + } | |
| 3218 | + | |
| 3219 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', []); | |
| 3220 | + } | |
| 3221 | + | |
| 3222 | + | |
| 3223 | + /** | |
| 3224 | + * helper for permanently deleting a mtP group and all related message_templates | |
| 3225 | + * | |
| 3226 | + * @param int $GRP_ID The group being deleted | |
| 3227 | + * @param bool $include_group whether to delete the Message Template Group as well. | |
| 3228 | + * @return bool boolean to indicate the success of the deletes or not. | |
| 3229 | + * @throws EE_Error | |
| 3230 | + * @throws InvalidArgumentException | |
| 3231 | + * @throws InvalidDataTypeException | |
| 3232 | + * @throws InvalidInterfaceException | |
| 3233 | + */ | |
| 3234 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) | |
| 3235 | +	{ | |
| 3236 | + $success = 1; | |
| 3237 | + $MTPG = EEM_Message_Template_Group::instance(); | |
| 3238 | + // first let's GET this group | |
| 3239 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); | |
| 3240 | + // then delete permanently all the related Message Templates | |
| 3241 | +		$deleted = $MTG->delete_related_permanently('Message_Template'); | |
| 3242 | + | |
| 3243 | +		if ($deleted === 0) { | |
| 3244 | + $success = 0; | |
| 3245 | + } | |
| 3246 | + | |
| 3247 | + // now delete permanently this particular group | |
| 3248 | + | |
| 3249 | +		if ($include_group && ! $MTG->delete_permanently()) { | |
| 3250 | + $success = 0; | |
| 3251 | + } | |
| 3252 | + | |
| 3253 | + return $success; | |
| 3254 | + } | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + /** | |
| 3258 | + * _learn_more_about_message_templates_link | |
| 3259 | + * | |
| 3260 | + * @access protected | |
| 3261 | + * @return string | |
| 3262 | + */ | |
| 3263 | + protected function _learn_more_about_message_templates_link() | |
| 3264 | +	{ | |
| 3265 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' | |
| 3266 | +			   . esc_html__('learn more about how message templates works', 'event_espresso') | |
| 3267 | + . '</a>'; | |
| 3268 | + } | |
| 3269 | + | |
| 3270 | + | |
| 3271 | + /** | |
| 3272 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by | |
| 3273 | + * ajax and other routes. | |
| 3274 | + * | |
| 3275 | + * @return void | |
| 3276 | + * @throws DomainException | |
| 3277 | + */ | |
| 3278 | + protected function _settings() | |
| 3279 | +	{ | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + $this->_set_m_mt_settings(); | |
| 3283 | + | |
| 3284 | + $selected_messenger = isset($this->_req_data['selected_messenger']) | |
| 3285 | + ? $this->_req_data['selected_messenger'] | |
| 3286 | + : 'email'; | |
| 3287 | + | |
| 3288 | + // let's setup the messenger tabs | |
| 3289 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( | |
| 3290 | + $this->_m_mt_settings['messenger_tabs'], | |
| 3291 | + 'messenger_links', | |
| 3292 | + '|', | |
| 3293 | + $selected_messenger | |
| 3294 | + ); | |
| 3295 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; | |
| 3296 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; | |
| 3297 | + | |
| 3298 | + $this->display_admin_page_with_sidebar(); | |
| 3299 | + } | |
| 3300 | + | |
| 3301 | + | |
| 3302 | + /** | |
| 3303 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) | |
| 3304 | + * | |
| 3305 | + * @access protected | |
| 3306 | + * @return void | |
| 3307 | + * @throws DomainException | |
| 3308 | + */ | |
| 3309 | + protected function _set_m_mt_settings() | |
| 3310 | +	{ | |
| 3311 | + // first if this is already set then lets get out no need to regenerate data. | |
| 3312 | +		if (! empty($this->_m_mt_settings)) { | |
| 3313 | + return; | |
| 3314 | + } | |
| 3315 | + | |
| 3316 | + // get all installed messengers and message_types | |
| 3317 | + /** @type EE_messenger[] $messengers */ | |
| 3318 | + $messengers = $this->_message_resource_manager->installed_messengers(); | |
| 3319 | + /** @type EE_message_type[] $message_types */ | |
| 3320 | + $message_types = $this->_message_resource_manager->installed_message_types(); | |
| 3321 | + | |
| 3322 | + | |
| 3323 | + // assemble the array for the _tab_text_links helper | |
| 3324 | + | |
| 3325 | +		foreach ($messengers as $messenger) { | |
| 3326 | + $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [ | |
| 3327 | + 'label' => ucwords($messenger->label['singular']), | |
| 3328 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) | |
| 3329 | + ? 'messenger-active' | |
| 3330 | + : '', | |
| 3331 | + 'href' => $messenger->name, | |
| 3332 | +				'title' => esc_html__('Modify this Messenger', 'event_espresso'), | |
| 3333 | + 'slug' => $messenger->name, | |
| 3334 | + 'obj' => $messenger, | |
| 3335 | + ]; | |
| 3336 | + | |
| 3337 | + | |
| 3338 | + $message_types_for_messenger = $messenger->get_valid_message_types(); | |
| 3339 | + | |
| 3340 | +			foreach ($message_types as $message_type) { | |
| 3341 | + // first we need to verify that this message type is valid with this messenger. Cause if it isn't then | |
| 3342 | + // it shouldn't show in either the inactive OR active metabox. | |
| 3343 | +				if (! in_array($message_type->name, $message_types_for_messenger, true)) { | |
| 3344 | + continue; | |
| 3345 | + } | |
| 3346 | + | |
| 3347 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( | |
| 3348 | + $messenger->name, | |
| 3349 | + $message_type->name | |
| 3350 | + ) | |
| 3351 | + ? 'active' | |
| 3352 | + : 'inactive'; | |
| 3353 | + | |
| 3354 | + $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [ | |
| 3355 | + 'label' => ucwords($message_type->label['singular']), | |
| 3356 | + 'class' => 'message-type-' . $a_or_i, | |
| 3357 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, | |
| 3358 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), | |
| 3359 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', | |
| 3360 | + 'title' => $a_or_i === 'active' | |
| 3361 | +						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') | |
| 3362 | +						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), | |
| 3363 | + 'content' => $a_or_i === 'active' | |
| 3364 | + ? $this->_message_type_settings_content($message_type, $messenger, true) | |
| 3365 | + : $this->_message_type_settings_content($message_type, $messenger), | |
| 3366 | + 'slug' => $message_type->name, | |
| 3367 | + 'active' => $a_or_i === 'active', | |
| 3368 | + 'obj' => $message_type, | |
| 3369 | + ]; | |
| 3370 | + } | |
| 3371 | + } | |
| 3372 | + } | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + /** | |
| 3376 | + * This just prepares the content for the message type settings | |
| 3377 | + * | |
| 3378 | + * @param EE_message_type $message_type The message type object | |
| 3379 | + * @param EE_messenger $messenger The messenger object | |
| 3380 | + * @param boolean $active Whether the message type is active or not | |
| 3381 | + * @return string html output for the content | |
| 3382 | + * @throws DomainException | |
| 3383 | + */ | |
| 3384 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) | |
| 3385 | +	{ | |
| 3386 | + // get message type fields | |
| 3387 | + $fields = $message_type->get_admin_settings_fields(); | |
| 3388 | + $settings_template_args['template_form_fields'] = ''; | |
| 3389 | + | |
| 3390 | +		if (! empty($fields) && $active) { | |
| 3391 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); | |
| 3392 | +			foreach ($fields as $fldname => $fldprops) { | |
| 3393 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; | |
| 3394 | + $template_form_field[ $field_id ] = [ | |
| 3395 | + 'name' => 'message_type_settings[' . $fldname . ']', | |
| 3396 | + 'label' => $fldprops['label'], | |
| 3397 | + 'input' => $fldprops['field_type'], | |
| 3398 | + 'type' => $fldprops['value_type'], | |
| 3399 | + 'required' => $fldprops['required'], | |
| 3400 | + 'validation' => $fldprops['validation'], | |
| 3401 | + 'value' => isset($existing_settings[ $fldname ]) | |
| 3402 | + ? $existing_settings[ $fldname ] | |
| 3403 | + : $fldprops['default'], | |
| 3404 | + 'options' => isset($fldprops['options']) | |
| 3405 | + ? $fldprops['options'] | |
| 3406 | + : [], | |
| 3407 | + 'default' => isset($existing_settings[ $fldname ]) | |
| 3408 | + ? $existing_settings[ $fldname ] | |
| 3409 | + : $fldprops['default'], | |
| 3410 | + 'css_class' => 'no-drag', | |
| 3411 | + 'format' => $fldprops['format'], | |
| 3412 | + ]; | |
| 3413 | + } | |
| 3414 | + | |
| 3415 | + | |
| 3416 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) | |
| 3417 | + ? $this->_generate_admin_form_fields( | |
| 3418 | + $template_form_field, | |
| 3419 | + 'string', | |
| 3420 | + 'ee_mt_activate_form' | |
| 3421 | + ) | |
| 3422 | + : ''; | |
| 3423 | + } | |
| 3424 | + | |
| 3425 | + $settings_template_args['description'] = $message_type->description; | |
| 3426 | + // we also need some hidden fields | |
| 3427 | + $hidden_fields = [ | |
| 3428 | + 'message_type_settings[messenger]' . $message_type->name => [ | |
| 3429 | + 'type' => 'hidden', | |
| 3430 | + 'value' => $messenger->name, | |
| 3431 | + ], | |
| 3432 | + 'message_type_settings[message_type]' . $message_type->name => [ | |
| 3433 | + 'type' => 'hidden', | |
| 3434 | + 'value' => $message_type->name, | |
| 3435 | + ], | |
| 3436 | + 'type' . $message_type->name => [ | |
| 3437 | + 'type' => 'hidden', | |
| 3438 | + 'value' => 'message_type', | |
| 3439 | + ], | |
| 3440 | + ]; | |
| 3441 | + | |
| 3442 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( | |
| 3443 | + $hidden_fields, | |
| 3444 | + 'array' | |
| 3445 | + ); | |
| 3446 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) | |
| 3447 | + ? ' hidden' | |
| 3448 | + : ''; | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; | |
| 3452 | + $content = EEH_Template::display_template($template, $settings_template_args, true); | |
| 3453 | + | |
| 3454 | + return $content; | |
| 3455 | + } | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + /** | |
| 3459 | + * Generate all the metaboxes for the message types and register them for the messages settings page. | |
| 3460 | + * | |
| 3461 | + * @access protected | |
| 3462 | + * @return void | |
| 3463 | + * @throws DomainException | |
| 3464 | + */ | |
| 3465 | + protected function _messages_settings_metaboxes() | |
| 3466 | +	{ | |
| 3467 | + $this->_set_m_mt_settings(); | |
| 3468 | + $m_boxes = $mt_boxes = []; | |
| 3469 | + $m_template_args = $mt_template_args = []; | |
| 3470 | + | |
| 3471 | + $selected_messenger = isset($this->_req_data['selected_messenger']) | |
| 3472 | + ? $this->_req_data['selected_messenger'] | |
| 3473 | + : 'email'; | |
| 3474 | + | |
| 3475 | +		if (isset($this->_m_mt_settings['messenger_tabs'])) { | |
| 3476 | +			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { | |
| 3477 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; | |
| 3478 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; | |
| 3479 | + // messenger meta boxes | |
| 3480 | + $active = $selected_messenger === $messenger; | |
| 3481 | + $active_mt_tabs = isset( | |
| 3482 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] | |
| 3483 | + ) | |
| 3484 | + ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] | |
| 3485 | + : ''; | |
| 3486 | + $m_boxes[ $messenger . '_a_box' ] = sprintf( | |
| 3487 | +					esc_html__('%s Settings', 'event_espresso'), | |
| 3488 | + $tab_array['label'] | |
| 3489 | + ); | |
| 3490 | + $m_template_args[ $messenger . '_a_box' ] = [ | |
| 3491 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', | |
| 3492 | + 'inactive_message_types' => isset( | |
| 3493 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] | |
| 3494 | + ) | |
| 3495 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) | |
| 3496 | + : '', | |
| 3497 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), | |
| 3498 | + 'hidden' => $active ? '' : ' hidden', | |
| 3499 | + 'hide_on_message' => $hide_on_message, | |
| 3500 | + 'messenger' => $messenger, | |
| 3501 | + 'active' => $active, | |
| 3502 | + ]; | |
| 3503 | + // message type meta boxes | |
| 3504 | + // (which is really just the inactive container for each messenger | |
| 3505 | + // showing inactive message types for that messenger) | |
| 3506 | +				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso'); | |
| 3507 | + $mt_template_args[ $messenger . '_i_box' ] = [ | |
| 3508 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', | |
| 3509 | + 'inactive_message_types' => isset( | |
| 3510 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] | |
| 3511 | + ) | |
| 3512 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) | |
| 3513 | + : '', | |
| 3514 | + 'hidden' => $active ? '' : ' hidden', | |
| 3515 | + 'hide_on_message' => $hide_on_message, | |
| 3516 | + 'hide_off_message' => $hide_off_message, | |
| 3517 | + 'messenger' => $messenger, | |
| 3518 | + 'active' => $active, | |
| 3519 | + ]; | |
| 3520 | + } | |
| 3521 | + } | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + // register messenger metaboxes | |
| 3525 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; | |
| 3526 | +		foreach ($m_boxes as $box => $label) { | |
| 3527 | + $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]]; | |
| 3528 | +			$msgr          = str_replace('_a_box', '', $box); | |
| 3529 | + add_meta_box( | |
| 3530 | + 'espresso_' . $msgr . '_settings', | |
| 3531 | + $label, | |
| 3532 | +				function ($post, $metabox) { | |
| 3533 | + EEH_Template::display_template( | |
| 3534 | + $metabox['args']['template_path'], | |
| 3535 | + $metabox['args']['template_args'] | |
| 3536 | + ); | |
| 3537 | + }, | |
| 3538 | + $this->_current_screen->id, | |
| 3539 | + 'normal', | |
| 3540 | + 'high', | |
| 3541 | + $callback_args | |
| 3542 | + ); | |
| 3543 | + } | |
| 3544 | + | |
| 3545 | + // register message type metaboxes | |
| 3546 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; | |
| 3547 | +		foreach ($mt_boxes as $box => $label) { | |
| 3548 | + $callback_args = [ | |
| 3549 | + 'template_path' => $mt_template_path, | |
| 3550 | + 'template_args' => $mt_template_args[ $box ], | |
| 3551 | + ]; | |
| 3552 | +			$mt            = str_replace('_i_box', '', $box); | |
| 3553 | + add_meta_box( | |
| 3554 | + 'espresso_' . $mt . '_inactive_mts', | |
| 3555 | + $label, | |
| 3556 | +				function ($post, $metabox) { | |
| 3557 | + EEH_Template::display_template( | |
| 3558 | + $metabox['args']['template_path'], | |
| 3559 | + $metabox['args']['template_args'] | |
| 3560 | + ); | |
| 3561 | + }, | |
| 3562 | + $this->_current_screen->id, | |
| 3563 | + 'side', | |
| 3564 | + 'high', | |
| 3565 | + $callback_args | |
| 3566 | + ); | |
| 3567 | + } | |
| 3568 | + | |
| 3569 | + // register metabox for global messages settings but only when on the main site. On single site installs this | |
| 3570 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. | |
| 3571 | +		if (is_main_site()) { | |
| 3572 | + add_meta_box( | |
| 3573 | + 'espresso_global_message_settings', | |
| 3574 | +				esc_html__('Global Message Settings', 'event_espresso'), | |
| 3575 | + [$this, 'global_messages_settings_metabox_content'], | |
| 3576 | + $this->_current_screen->id, | |
| 3577 | + 'normal', | |
| 3578 | + 'low', | |
| 3579 | + [] | |
| 3580 | + ); | |
| 3581 | + } | |
| 3582 | + } | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + /** | |
| 3586 | + * This generates the content for the global messages settings metabox. | |
| 3587 | + * | |
| 3588 | + * @return void | |
| 3589 | + * @throws EE_Error | |
| 3590 | + * @throws InvalidArgumentException | |
| 3591 | + * @throws ReflectionException | |
| 3592 | + * @throws InvalidDataTypeException | |
| 3593 | + * @throws InvalidInterfaceException | |
| 3594 | + */ | |
| 3595 | + public function global_messages_settings_metabox_content() | |
| 3596 | +	{ | |
| 3597 | + $form = $this->_generate_global_settings_form(); | |
| 3598 | + // already escaped | |
| 3599 | + echo $form->form_open( | |
| 3600 | + $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL), | |
| 3601 | + 'POST' | |
| 3602 | + ); | |
| 3603 | + echo $form->get_html(); | |
| 3604 | + echo $form->form_close(); | |
| 3605 | + } | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + /** | |
| 3609 | + * This generates and returns the form object for the global messages settings. | |
| 3610 | + * | |
| 3611 | + * @return EE_Form_Section_Proper | |
| 3612 | + * @throws EE_Error | |
| 3613 | + * @throws InvalidArgumentException | |
| 3614 | + * @throws ReflectionException | |
| 3615 | + * @throws InvalidDataTypeException | |
| 3616 | + * @throws InvalidInterfaceException | |
| 3617 | + */ | |
| 3618 | + protected function _generate_global_settings_form() | |
| 3619 | +	{ | |
| 3620 | +		EE_Registry::instance()->load_helper('HTML'); | |
| 3621 | + /** @var EE_Network_Core_Config $network_config */ | |
| 3622 | + $network_config = EE_Registry::instance()->NET_CFG->core; | |
| 3623 | + | |
| 3624 | + return new EE_Form_Section_Proper( | |
| 3625 | + [ | |
| 3626 | + 'name' => 'global_messages_settings', | |
| 3627 | + 'html_id' => 'global_messages_settings', | |
| 3628 | + 'html_class' => 'form-table', | |
| 3629 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), | |
| 3630 | + 'subsections' => apply_filters( | |
| 3631 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', | |
| 3632 | + [ | |
| 3633 | + 'do_messages_on_same_request' => new EE_Select_Input( | |
| 3634 | + [ | |
| 3635 | +								true  => esc_html__('On the same request', 'event_espresso'), | |
| 3636 | +								false => esc_html__('On a separate request', 'event_espresso'), | |
| 3637 | + ], | |
| 3638 | + [ | |
| 3639 | + 'default' => $network_config->do_messages_on_same_request, | |
| 3640 | + 'html_label_text' => esc_html__( | |
| 3641 | + 'Generate and send all messages:', | |
| 3642 | + 'event_espresso' | |
| 3643 | + ), | |
| 3644 | + 'html_help_text' => esc_html__( | |
| 3645 | + 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', | |
| 3646 | + 'event_espresso' | |
| 3647 | + ), | |
| 3648 | + ] | |
| 3649 | + ), | |
| 3650 | + 'delete_threshold' => new EE_Select_Input( | |
| 3651 | + [ | |
| 3652 | +								0  => esc_html__('Forever', 'event_espresso'), | |
| 3653 | +								3  => esc_html__('3 Months', 'event_espresso'), | |
| 3654 | +								6  => esc_html__('6 Months', 'event_espresso'), | |
| 3655 | +								9  => esc_html__('9 Months', 'event_espresso'), | |
| 3656 | +								12 => esc_html__('12 Months', 'event_espresso'), | |
| 3657 | +								24 => esc_html__('24 Months', 'event_espresso'), | |
| 3658 | +								36 => esc_html__('36 Months', 'event_espresso'), | |
| 3659 | + ], | |
| 3660 | + [ | |
| 3661 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, | |
| 3662 | +								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), | |
| 3663 | + 'html_help_text' => esc_html__( | |
| 3664 | + 'You can control how long a record of processed messages is kept via this option.', | |
| 3665 | + 'event_espresso' | |
| 3666 | + ), | |
| 3667 | + ] | |
| 3668 | + ), | |
| 3669 | + 'update_settings' => new EE_Submit_Input( | |
| 3670 | + [ | |
| 3671 | +								'default'         => esc_html__('Update', 'event_espresso'), | |
| 3672 | + 'html_label_text' => ' ', | |
| 3673 | + ] | |
| 3674 | + ), | |
| 3675 | + ] | |
| 3676 | + ), | |
| 3677 | + ] | |
| 3678 | + ); | |
| 3679 | + } | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + /** | |
| 3683 | + * This handles updating the global settings set on the admin page. | |
| 3684 | + * | |
| 3685 | + * @throws EE_Error | |
| 3686 | + * @throws InvalidDataTypeException | |
| 3687 | + * @throws InvalidInterfaceException | |
| 3688 | + * @throws InvalidArgumentException | |
| 3689 | + * @throws ReflectionException | |
| 3690 | + */ | |
| 3691 | + protected function _update_global_settings() | |
| 3692 | +	{ | |
| 3693 | + /** @var EE_Network_Core_Config $network_config */ | |
| 3694 | + $network_config = EE_Registry::instance()->NET_CFG->core; | |
| 3695 | + $messages_config = EE_Registry::instance()->CFG->messages; | |
| 3696 | + $form = $this->_generate_global_settings_form(); | |
| 3697 | +		if ($form->was_submitted()) { | |
| 3698 | + $form->receive_form_submission(); | |
| 3699 | +			if ($form->is_valid()) { | |
| 3700 | + $valid_data = $form->valid_data(); | |
| 3701 | +				foreach ($valid_data as $property => $value) { | |
| 3702 | + $setter = 'set_' . $property; | |
| 3703 | +					if (method_exists($network_config, $setter)) { | |
| 3704 | +						$network_config->{$setter}($value); | |
| 3705 | + } elseif ( | |
| 3706 | + property_exists($network_config, $property) | |
| 3707 | +						&& $network_config->{$property} !== $value | |
| 3708 | +					) { | |
| 3709 | +						$network_config->{$property} = $value; | |
| 3710 | + } elseif ( | |
| 3711 | + property_exists($messages_config, $property) | |
| 3712 | +						&& $messages_config->{$property} !== $value | |
| 3713 | +					) { | |
| 3714 | +						$messages_config->{$property} = $value; | |
| 3715 | + } | |
| 3716 | + } | |
| 3717 | + // only update if the form submission was valid! | |
| 3718 | + EE_Registry::instance()->NET_CFG->update_config(true, false); | |
| 3719 | + EE_Registry::instance()->CFG->update_espresso_config(); | |
| 3720 | + EE_Error::overwrite_success(); | |
| 3721 | +				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso')); | |
| 3722 | + } | |
| 3723 | + } | |
| 3724 | + $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true); | |
| 3725 | + } | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + /** | |
| 3729 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate | |
| 3730 | + * | |
| 3731 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs | |
| 3732 | + * @return string html formatted tabs | |
| 3733 | + * @throws DomainException | |
| 3734 | + */ | |
| 3735 | + protected function _get_mt_tabs($tab_array) | |
| 3736 | +	{ | |
| 3737 | + $tab_array = (array) $tab_array; | |
| 3738 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; | |
| 3739 | + $tabs = ''; | |
| 3740 | + | |
| 3741 | +		foreach ($tab_array as $tab) { | |
| 3742 | + $tabs .= EEH_Template::display_template($template, $tab, true); | |
| 3743 | + } | |
| 3744 | + | |
| 3745 | + return $tabs; | |
| 3746 | + } | |
| 3747 | + | |
| 3748 | + | |
| 3749 | + /** | |
| 3750 | + * This prepares the content of the messenger meta box admin settings | |
| 3751 | + * | |
| 3752 | + * @param EE_messenger $messenger The messenger we're setting up content for | |
| 3753 | + * @return string html formatted content | |
| 3754 | + * @throws DomainException | |
| 3755 | + */ | |
| 3756 | + protected function _get_messenger_box_content(EE_messenger $messenger) | |
| 3757 | +	{ | |
| 3758 | + | |
| 3759 | + $fields = $messenger->get_admin_settings_fields(); | |
| 3760 | + $settings_template_args['template_form_fields'] = ''; | |
| 3761 | + | |
| 3762 | + // is $messenger active? | |
| 3763 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); | |
| 3764 | + | |
| 3765 | + | |
| 3766 | +		if (! empty($fields)) { | |
| 3767 | + $existing_settings = $messenger->get_existing_admin_settings(); | |
| 3768 | + | |
| 3769 | +			foreach ($fields as $fldname => $fldprops) { | |
| 3770 | + $field_id = $messenger->name . '-' . $fldname; | |
| 3771 | + $template_form_field[ $field_id ] = [ | |
| 3772 | + 'name' => 'messenger_settings[' . $field_id . ']', | |
| 3773 | + 'label' => $fldprops['label'], | |
| 3774 | + 'input' => $fldprops['field_type'], | |
| 3775 | + 'type' => $fldprops['value_type'], | |
| 3776 | + 'required' => $fldprops['required'], | |
| 3777 | + 'validation' => $fldprops['validation'], | |
| 3778 | + 'value' => isset($existing_settings[ $field_id ]) | |
| 3779 | + ? $existing_settings[ $field_id ] | |
| 3780 | + : $fldprops['default'], | |
| 3781 | + 'css_class' => '', | |
| 3782 | + 'format' => $fldprops['format'], | |
| 3783 | + ]; | |
| 3784 | + } | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) | |
| 3788 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') | |
| 3789 | + : ''; | |
| 3790 | + } | |
| 3791 | + | |
| 3792 | + // we also need some hidden fields | |
| 3793 | + $settings_template_args['hidden_fields'] = [ | |
| 3794 | + 'messenger_settings[messenger]' . $messenger->name => [ | |
| 3795 | + 'type' => 'hidden', | |
| 3796 | + 'value' => $messenger->name, | |
| 3797 | + ], | |
| 3798 | + 'type' . $messenger->name => [ | |
| 3799 | + 'type' => 'hidden', | |
| 3800 | + 'value' => 'messenger', | |
| 3801 | + ], | |
| 3802 | + ]; | |
| 3803 | + | |
| 3804 | + // make sure any active message types that are existing are included in the hidden fields | |
| 3805 | +		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { | |
| 3806 | +			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { | |
| 3807 | + $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [ | |
| 3808 | + 'type' => 'hidden', | |
| 3809 | + 'value' => $mt, | |
| 3810 | + ]; | |
| 3811 | + } | |
| 3812 | + } | |
| 3813 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( | |
| 3814 | + $settings_template_args['hidden_fields'], | |
| 3815 | + 'array' | |
| 3816 | + ); | |
| 3817 | + $active = | |
| 3818 | + $this->_message_resource_manager->is_messenger_active($messenger->name); | |
| 3819 | + | |
| 3820 | + $settings_template_args['messenger'] = $messenger->name; | |
| 3821 | + $settings_template_args['description'] = $messenger->description; | |
| 3822 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( | |
| 3826 | + $messenger->name | |
| 3827 | + ) | |
| 3828 | + ? $settings_template_args['show_hide_edit_form'] | |
| 3829 | + : ' hidden'; | |
| 3830 | + | |
| 3831 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) | |
| 3832 | + ? ' hidden' | |
| 3833 | + : $settings_template_args['show_hide_edit_form']; | |
| 3834 | + | |
| 3835 | + | |
| 3836 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; | |
| 3837 | +		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | |
| 3838 | + $settings_template_args['on_off_status'] = $active; | |
| 3839 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; | |
| 3840 | + return EEH_Template::display_template( | |
| 3841 | + $template, | |
| 3842 | + $settings_template_args, | |
| 3843 | + true | |
| 3844 | + ); | |
| 3845 | + } | |
| 3846 | + | |
| 3847 | + | |
| 3848 | + /** | |
| 3849 | + * used by ajax on the messages settings page to activate|deactivate the messenger | |
| 3850 | + * | |
| 3851 | + * @throws DomainException | |
| 3852 | + * @throws EE_Error | |
| 3853 | + * @throws InvalidDataTypeException | |
| 3854 | + * @throws InvalidInterfaceException | |
| 3855 | + * @throws InvalidArgumentException | |
| 3856 | + * @throws ReflectionException | |
| 3857 | + */ | |
| 3858 | + public function activate_messenger_toggle() | |
| 3859 | +	{ | |
| 3860 | + $success = true; | |
| 3861 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); | |
| 3862 | + // let's check that we have required data | |
| 3863 | +		if (! isset($this->_req_data['messenger'])) { | |
| 3864 | + EE_Error::add_error( | |
| 3865 | +				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | |
| 3866 | + __FILE__, | |
| 3867 | + __FUNCTION__, | |
| 3868 | + __LINE__ | |
| 3869 | + ); | |
| 3870 | + $success = false; | |
| 3871 | + } | |
| 3872 | + | |
| 3873 | + // do a nonce check here since we're not arriving via a normal route | |
| 3874 | + $nonce = isset($this->_req_data['activate_nonce']) | |
| 3875 | + ? sanitize_text_field($this->_req_data['activate_nonce']) | |
| 3876 | + : ''; | |
| 3877 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; | |
| 3878 | + | |
| 3879 | + $this->_verify_nonce($nonce, $nonce_ref); | |
| 3880 | + | |
| 3881 | + | |
| 3882 | +		if (! isset($this->_req_data['status'])) { | |
| 3883 | + EE_Error::add_error( | |
| 3884 | + esc_html__( | |
| 3885 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', | |
| 3886 | + 'event_espresso' | |
| 3887 | + ), | |
| 3888 | + __FILE__, | |
| 3889 | + __FUNCTION__, | |
| 3890 | + __LINE__ | |
| 3891 | + ); | |
| 3892 | + $success = false; | |
| 3893 | + } | |
| 3894 | + | |
| 3895 | + // do check to verify we have a valid status. | |
| 3896 | + $status = $this->_req_data['status']; | |
| 3897 | + | |
| 3898 | +		if ($status !== 'off' && $status !== 'on') { | |
| 3899 | + EE_Error::add_error( | |
| 3900 | + sprintf( | |
| 3901 | +					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | |
| 3902 | + $this->_req_data['status'] | |
| 3903 | + ), | |
| 3904 | + __FILE__, | |
| 3905 | + __FUNCTION__, | |
| 3906 | + __LINE__ | |
| 3907 | + ); | |
| 3908 | + $success = false; | |
| 3909 | + } | |
| 3910 | + | |
| 3911 | +		if ($success) { | |
| 3912 | + // made it here? Stop dawdling then!! | |
| 3913 | + $success = $status === 'off' | |
| 3914 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) | |
| 3915 | + : $this->_activate_messenger($this->_req_data['messenger']); | |
| 3916 | + } | |
| 3917 | + | |
| 3918 | + $this->_template_args['success'] = $success; | |
| 3919 | + | |
| 3920 | + // no special instructions so let's just do the json return (which should automatically do all the special stuff). | |
| 3921 | + $this->_return_json(); | |
| 3922 | + } | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + /** | |
| 3926 | + * used by ajax from the messages settings page to activate|deactivate a message type | |
| 3927 | + * | |
| 3928 | + * @throws DomainException | |
| 3929 | + * @throws EE_Error | |
| 3930 | + * @throws ReflectionException | |
| 3931 | + * @throws InvalidDataTypeException | |
| 3932 | + * @throws InvalidInterfaceException | |
| 3933 | + * @throws InvalidArgumentException | |
| 3934 | + */ | |
| 3935 | + public function activate_mt_toggle() | |
| 3936 | +	{ | |
| 3937 | + $success = true; | |
| 3938 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); | |
| 3939 | + | |
| 3940 | + // let's make sure we have the necessary data | |
| 3941 | +		if (! isset($this->_req_data['message_type'])) { | |
| 3942 | + EE_Error::add_error( | |
| 3943 | +				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), | |
| 3944 | + __FILE__, | |
| 3945 | + __FUNCTION__, | |
| 3946 | + __LINE__ | |
| 3947 | + ); | |
| 3948 | + $success = false; | |
| 3949 | + } | |
| 3950 | + | |
| 3951 | +		if (! isset($this->_req_data['messenger'])) { | |
| 3952 | + EE_Error::add_error( | |
| 3953 | +				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | |
| 3954 | + __FILE__, | |
| 3955 | + __FUNCTION__, | |
| 3956 | + __LINE__ | |
| 3957 | + ); | |
| 3958 | + $success = false; | |
| 3959 | + } | |
| 3960 | + | |
| 3961 | +		if (! isset($this->_req_data['status'])) { | |
| 3962 | + EE_Error::add_error( | |
| 3963 | + esc_html__( | |
| 3964 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', | |
| 3965 | + 'event_espresso' | |
| 3966 | + ), | |
| 3967 | + __FILE__, | |
| 3968 | + __FUNCTION__, | |
| 3969 | + __LINE__ | |
| 3970 | + ); | |
| 3971 | + $success = false; | |
| 3972 | + } | |
| 3973 | + | |
| 3974 | + | |
| 3975 | + // do check to verify we have a valid status. | |
| 3976 | + $status = $this->_req_data['status']; | |
| 3977 | + | |
| 3978 | +		if ($status !== 'activate' && $status !== 'deactivate') { | |
| 3979 | + EE_Error::add_error( | |
| 3980 | + sprintf( | |
| 3981 | +					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), | |
| 3982 | + $this->_req_data['status'] | |
| 3983 | + ), | |
| 3984 | + __FILE__, | |
| 3985 | + __FUNCTION__, | |
| 3986 | + __LINE__ | |
| 3987 | + ); | |
| 3988 | + $success = false; | |
| 3989 | + } | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + // do a nonce check here since we're not arriving via a normal route | |
| 3993 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; | |
| 3994 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; | |
| 3995 | + | |
| 3996 | + $this->_verify_nonce($nonce, $nonce_ref); | |
| 3997 | + | |
| 3998 | +		if ($success) { | |
| 3999 | + // made it here? um, what are you waiting for then? | |
| 4000 | + $success = $status === 'deactivate' | |
| 4001 | + ? $this->_deactivate_message_type_for_messenger( | |
| 4002 | + $this->_req_data['messenger'], | |
| 4003 | + $this->_req_data['message_type'] | |
| 4004 | + ) | |
| 4005 | + : $this->_activate_message_type_for_messenger( | |
| 4006 | + $this->_req_data['messenger'], | |
| 4007 | + $this->_req_data['message_type'] | |
| 4008 | + ); | |
| 4009 | + } | |
| 4010 | + | |
| 4011 | + $this->_template_args['success'] = $success; | |
| 4012 | + $this->_return_json(); | |
| 4013 | + } | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + /** | |
| 4017 | + * Takes care of processing activating a messenger and preparing the appropriate response. | |
| 4018 | + * | |
| 4019 | + * @param string $messenger_name The name of the messenger being activated | |
| 4020 | + * @return bool | |
| 4021 | + * @throws DomainException | |
| 4022 | + * @throws EE_Error | |
| 4023 | + * @throws InvalidArgumentException | |
| 4024 | + * @throws ReflectionException | |
| 4025 | + * @throws InvalidDataTypeException | |
| 4026 | + * @throws InvalidInterfaceException | |
| 4027 | + */ | |
| 4028 | + protected function _activate_messenger($messenger_name) | |
| 4029 | +	{ | |
| 4030 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4031 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4032 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger | |
| 4033 | + ? $active_messenger->get_default_message_types() | |
| 4034 | + : []; | |
| 4035 | + | |
| 4036 | + // ensure is active | |
| 4037 | + $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate); | |
| 4038 | + | |
| 4039 | + // set response_data for reload | |
| 4040 | +		foreach ($message_types_to_activate as $message_type_name) { | |
| 4041 | + /** @var EE_message_type $message_type */ | |
| 4042 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); | |
| 4043 | + if ( | |
| 4044 | + $this->_message_resource_manager->is_message_type_active_for_messenger( | |
| 4045 | + $messenger_name, | |
| 4046 | + $message_type_name | |
| 4047 | + ) | |
| 4048 | + && $message_type instanceof EE_message_type | |
| 4049 | +			) { | |
| 4050 | + $this->_template_args['data']['active_mts'][] = $message_type_name; | |
| 4051 | +				if ($message_type->get_admin_settings_fields()) { | |
| 4052 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; | |
| 4053 | + } | |
| 4054 | + } | |
| 4055 | + } | |
| 4056 | + | |
| 4057 | + // add success message for activating messenger | |
| 4058 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); | |
| 4059 | + } | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + /** | |
| 4063 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. | |
| 4064 | + * | |
| 4065 | + * @param string $messenger_name The name of the messenger being activated | |
| 4066 | + * @return bool | |
| 4067 | + * @throws DomainException | |
| 4068 | + * @throws EE_Error | |
| 4069 | + * @throws InvalidArgumentException | |
| 4070 | + * @throws ReflectionException | |
| 4071 | + * @throws InvalidDataTypeException | |
| 4072 | + * @throws InvalidInterfaceException | |
| 4073 | + */ | |
| 4074 | + protected function _deactivate_messenger($messenger_name) | |
| 4075 | +	{ | |
| 4076 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4077 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4078 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); | |
| 4079 | + | |
| 4080 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); | |
| 4081 | + } | |
| 4082 | + | |
| 4083 | + | |
| 4084 | + /** | |
| 4085 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. | |
| 4086 | + * | |
| 4087 | + * @param string $messenger_name The name of the messenger the message type is being activated for. | |
| 4088 | + * @param string $message_type_name The name of the message type being activated for the messenger | |
| 4089 | + * @return bool | |
| 4090 | + * @throws DomainException | |
| 4091 | + * @throws EE_Error | |
| 4092 | + * @throws InvalidArgumentException | |
| 4093 | + * @throws ReflectionException | |
| 4094 | + * @throws InvalidDataTypeException | |
| 4095 | + * @throws InvalidInterfaceException | |
| 4096 | + */ | |
| 4097 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) | |
| 4098 | +	{ | |
| 4099 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4100 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4101 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ | |
| 4102 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); | |
| 4103 | + | |
| 4104 | + // ensure is active | |
| 4105 | + $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name); | |
| 4106 | + | |
| 4107 | + // set response for load | |
| 4108 | + if ( | |
| 4109 | + $this->_message_resource_manager->is_message_type_active_for_messenger( | |
| 4110 | + $messenger_name, | |
| 4111 | + $message_type_name | |
| 4112 | + ) | |
| 4113 | +		) { | |
| 4114 | + $this->_template_args['data']['active_mts'][] = $message_type_name; | |
| 4115 | +			if ($message_type_to_activate->get_admin_settings_fields()) { | |
| 4116 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; | |
| 4117 | + } | |
| 4118 | + } | |
| 4119 | + | |
| 4120 | + return $this->_setup_response_message_for_activating_messenger_with_message_types( | |
| 4121 | + $active_messenger, | |
| 4122 | + $message_type_to_activate | |
| 4123 | + ); | |
| 4124 | + } | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + /** | |
| 4128 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. | |
| 4129 | + * | |
| 4130 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. | |
| 4131 | + * @param string $message_type_name The name of the message type being deactivated for the messenger | |
| 4132 | + * @return bool | |
| 4133 | + * @throws DomainException | |
| 4134 | + * @throws EE_Error | |
| 4135 | + * @throws InvalidArgumentException | |
| 4136 | + * @throws ReflectionException | |
| 4137 | + * @throws InvalidDataTypeException | |
| 4138 | + * @throws InvalidInterfaceException | |
| 4139 | + */ | |
| 4140 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) | |
| 4141 | +	{ | |
| 4142 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ | |
| 4143 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); | |
| 4144 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ | |
| 4145 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); | |
| 4146 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); | |
| 4147 | + | |
| 4148 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types( | |
| 4149 | + $active_messenger, | |
| 4150 | + $message_type_to_deactivate | |
| 4151 | + ); | |
| 4152 | + } | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + /** | |
| 4156 | + * This just initializes the defaults for activating messenger and message type responses. | |
| 4157 | + */ | |
| 4158 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() | |
| 4159 | +	{ | |
| 4160 | + $this->_template_args['data']['active_mts'] = []; | |
| 4161 | + $this->_template_args['data']['mt_reload'] = []; | |
| 4162 | + } | |
| 4163 | + | |
| 4164 | + | |
| 4165 | + /** | |
| 4166 | + * Setup appropriate response for activating a messenger and/or message types | |
| 4167 | + * | |
| 4168 | + * @param EE_messenger $messenger | |
| 4169 | + * @param EE_message_type|null $message_type | |
| 4170 | + * @return bool | |
| 4171 | + * @throws DomainException | |
| 4172 | + * @throws EE_Error | |
| 4173 | + * @throws InvalidArgumentException | |
| 4174 | + * @throws ReflectionException | |
| 4175 | + * @throws InvalidDataTypeException | |
| 4176 | + * @throws InvalidInterfaceException | |
| 4177 | + */ | |
| 4178 | + protected function _setup_response_message_for_activating_messenger_with_message_types( | |
| 4179 | + $messenger, | |
| 4180 | + EE_Message_Type $message_type = null | |
| 4181 | +	) { | |
| 4182 | + // if $messenger isn't a valid messenger object then get out. | |
| 4183 | +		if (! $messenger instanceof EE_Messenger) { | |
| 4184 | + EE_Error::add_error( | |
| 4185 | +				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), | |
| 4186 | + __FILE__, | |
| 4187 | + __FUNCTION__, | |
| 4188 | + __LINE__ | |
| 4189 | + ); | |
| 4190 | + | |
| 4191 | + return false; | |
| 4192 | + } | |
| 4193 | + // activated | |
| 4194 | +		if ($this->_template_args['data']['active_mts']) { | |
| 4195 | + EE_Error::overwrite_success(); | |
| 4196 | + // activated a message type with the messenger | |
| 4197 | +			if ($message_type instanceof EE_message_type) { | |
| 4198 | + EE_Error::add_success( | |
| 4199 | + sprintf( | |
| 4200 | + esc_html__( | |
| 4201 | + '%s message type has been successfully activated with the %s messenger', | |
| 4202 | + 'event_espresso' | |
| 4203 | + ), | |
| 4204 | + ucwords($message_type->label['singular']), | |
| 4205 | + ucwords($messenger->label['singular']) | |
| 4206 | + ) | |
| 4207 | + ); | |
| 4208 | + | |
| 4209 | + // if message type was invoice then let's make sure we activate the invoice payment method. | |
| 4210 | +				if ($message_type->name === 'invoice') { | |
| 4211 | +					EE_Registry::instance()->load_lib('Payment_Method_Manager'); | |
| 4212 | +					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); | |
| 4213 | +					if ($pm instanceof EE_Payment_Method) { | |
| 4214 | + EE_Error::add_attention( | |
| 4215 | + esc_html__( | |
| 4216 | + 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', | |
| 4217 | + 'event_espresso' | |
| 4218 | + ) | |
| 4219 | + ); | |
| 4220 | + } | |
| 4221 | + } | |
| 4222 | + // just toggles the entire messenger | |
| 4223 | +			} else { | |
| 4224 | + EE_Error::add_success( | |
| 4225 | + sprintf( | |
| 4226 | +						esc_html__('%s messenger has been successfully activated', 'event_espresso'), | |
| 4227 | + ucwords($messenger->label['singular']) | |
| 4228 | + ) | |
| 4229 | + ); | |
| 4230 | + } | |
| 4231 | + | |
| 4232 | + return true; | |
| 4233 | + | |
| 4234 | + // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active | |
| 4235 | + // message types after the activation process. However its possible some messengers don't HAVE any default_message_types | |
| 4236 | + // in which case we just give a success message for the messenger being successfully activated. | |
| 4237 | +		} else { | |
| 4238 | +			if (! $messenger->get_default_message_types()) { | |
| 4239 | + // messenger doesn't have any default message types so still a success. | |
| 4240 | + EE_Error::add_success( | |
| 4241 | + sprintf( | |
| 4242 | +						esc_html__('%s messenger was successfully activated.', 'event_espresso'), | |
| 4243 | + ucwords($messenger->label['singular']) | |
| 4244 | + ) | |
| 4245 | + ); | |
| 4246 | + | |
| 4247 | + return true; | |
| 4248 | +			} else { | |
| 4249 | + EE_Error::add_error( | |
| 4250 | + $message_type instanceof EE_message_type | |
| 4251 | + ? sprintf( | |
| 4252 | + esc_html__( | |
| 4253 | + '%s message type was not successfully activated with the %s messenger', | |
| 4254 | + 'event_espresso' | |
| 4255 | + ), | |
| 4256 | + ucwords($message_type->label['singular']), | |
| 4257 | + ucwords($messenger->label['singular']) | |
| 4258 | + ) | |
| 4259 | + : sprintf( | |
| 4260 | +							esc_html__('%s messenger was not successfully activated', 'event_espresso'), | |
| 4261 | + ucwords($messenger->label['singular']) | |
| 4262 | + ), | |
| 4263 | + __FILE__, | |
| 4264 | + __FUNCTION__, | |
| 4265 | + __LINE__ | |
| 4266 | + ); | |
| 4267 | + | |
| 4268 | + return false; | |
| 4269 | + } | |
| 4270 | + } | |
| 4271 | + } | |
| 4272 | + | |
| 4273 | + | |
| 4274 | + /** | |
| 4275 | + * This sets up the appropriate response for deactivating a messenger and/or message type. | |
| 4276 | + * | |
| 4277 | + * @param EE_messenger $messenger | |
| 4278 | + * @param EE_message_type|null $message_type | |
| 4279 | + * @return bool | |
| 4280 | + * @throws DomainException | |
| 4281 | + * @throws EE_Error | |
| 4282 | + * @throws InvalidArgumentException | |
| 4283 | + * @throws ReflectionException | |
| 4284 | + * @throws InvalidDataTypeException | |
| 4285 | + * @throws InvalidInterfaceException | |
| 4286 | + */ | |
| 4287 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( | |
| 4288 | + $messenger, | |
| 4289 | + EE_message_type $message_type = null | |
| 4290 | +	) { | |
| 4291 | + EE_Error::overwrite_success(); | |
| 4292 | + | |
| 4293 | + // if $messenger isn't a valid messenger object then get out. | |
| 4294 | +		if (! $messenger instanceof EE_Messenger) { | |
| 4295 | + EE_Error::add_error( | |
| 4296 | +				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), | |
| 4297 | + __FILE__, | |
| 4298 | + __FUNCTION__, | |
| 4299 | + __LINE__ | |
| 4300 | + ); | |
| 4301 | + | |
| 4302 | + return false; | |
| 4303 | + } | |
| 4304 | + | |
| 4305 | +		if ($message_type instanceof EE_message_type) { | |
| 4306 | + $message_type_name = $message_type->name; | |
| 4307 | + EE_Error::add_success( | |
| 4308 | + sprintf( | |
| 4309 | + esc_html__( | |
| 4310 | + '%s message type has been successfully deactivated for the %s messenger.', | |
| 4311 | + 'event_espresso' | |
| 4312 | + ), | |
| 4313 | + ucwords($message_type->label['singular']), | |
| 4314 | + ucwords($messenger->label['singular']) | |
| 4315 | + ) | |
| 4316 | + ); | |
| 4317 | +		} else { | |
| 4318 | + $message_type_name = ''; | |
| 4319 | + EE_Error::add_success( | |
| 4320 | + sprintf( | |
| 4321 | +					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), | |
| 4322 | + ucwords($messenger->label['singular']) | |
| 4323 | + ) | |
| 4324 | + ); | |
| 4325 | + } | |
| 4326 | + | |
| 4327 | + // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. | |
| 4328 | +		if ($messenger->name === 'html' || $message_type_name === 'invoice') { | |
| 4329 | +			EE_Registry::instance()->load_lib('Payment_Method_Manager'); | |
| 4330 | +			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); | |
| 4331 | +			if ($count_updated > 0) { | |
| 4332 | + $msg = $message_type_name === 'invoice' | |
| 4333 | + ? esc_html__( | |
| 4334 | + 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', | |
| 4335 | + 'event_espresso' | |
| 4336 | + ) | |
| 4337 | + : esc_html__( | |
| 4338 | + 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', | |
| 4339 | + 'event_espresso' | |
| 4340 | + ); | |
| 4341 | + EE_Error::add_attention($msg); | |
| 4342 | + } | |
| 4343 | + } | |
| 4344 | + | |
| 4345 | + return true; | |
| 4346 | + } | |
| 4347 | + | |
| 4348 | + | |
| 4349 | + /** | |
| 4350 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) | |
| 4351 | + * | |
| 4352 | + * @throws DomainException | |
| 4353 | + */ | |
| 4354 | + public function update_mt_form() | |
| 4355 | +	{ | |
| 4356 | +		if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { | |
| 4357 | + EE_Error::add_error( | |
| 4358 | +				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), | |
| 4359 | + __FILE__, | |
| 4360 | + __FUNCTION__, | |
| 4361 | + __LINE__ | |
| 4362 | + ); | |
| 4363 | + $this->_return_json(); | |
| 4364 | + } | |
| 4365 | + | |
| 4366 | + $message_types = $this->get_installed_message_types(); | |
| 4367 | + | |
| 4368 | + $message_type = $message_types[ $this->_req_data['message_type'] ]; | |
| 4369 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); | |
| 4370 | + | |
| 4371 | + $content = $this->_message_type_settings_content( | |
| 4372 | + $message_type, | |
| 4373 | + $messenger, | |
| 4374 | + true | |
| 4375 | + ); | |
| 4376 | + $this->_template_args['success'] = true; | |
| 4377 | + $this->_template_args['content'] = $content; | |
| 4378 | + $this->_return_json(); | |
| 4379 | + } | |
| 4380 | + | |
| 4381 | + | |
| 4382 | + /** | |
| 4383 | + * this handles saving the settings for a messenger or message type | |
| 4384 | + * | |
| 4385 | + */ | |
| 4386 | + public function save_settings() | |
| 4387 | +	{ | |
| 4388 | +		if (! isset($this->_req_data['type'])) { | |
| 4389 | + EE_Error::add_error( | |
| 4390 | + esc_html__( | |
| 4391 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', | |
| 4392 | + 'event_espresso' | |
| 4393 | + ), | |
| 4394 | + __FILE__, | |
| 4395 | + __FUNCTION__, | |
| 4396 | + __LINE__ | |
| 4397 | + ); | |
| 4398 | + $this->_template_args['error'] = true; | |
| 4399 | + $this->_return_json(); | |
| 4400 | + } | |
| 4401 | + | |
| 4402 | + | |
| 4403 | +		if ($this->_req_data['type'] === 'messenger') { | |
| 4404 | + // this should be an array. | |
| 4405 | + $settings = $this->_req_data['messenger_settings']; | |
| 4406 | + $messenger = $settings['messenger']; | |
| 4407 | + // let's setup the settings data | |
| 4408 | +			foreach ($settings as $key => $value) { | |
| 4409 | +				switch ($key) { | |
| 4410 | + case 'messenger': | |
| 4411 | + unset($settings['messenger']); | |
| 4412 | + break; | |
| 4413 | + case 'message_types': | |
| 4414 | + unset($settings['message_types']); | |
| 4415 | + break; | |
| 4416 | + default: | |
| 4417 | + $settings[ $key ] = $value; | |
| 4418 | + break; | |
| 4419 | + } | |
| 4420 | + } | |
| 4421 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); | |
| 4422 | +		} elseif ($this->_req_data['type'] === 'message_type') { | |
| 4423 | + $settings = $this->_req_data['message_type_settings']; | |
| 4424 | + $messenger = $settings['messenger']; | |
| 4425 | + $message_type = $settings['message_type']; | |
| 4426 | + | |
| 4427 | +			foreach ($settings as $key => $value) { | |
| 4428 | +				switch ($key) { | |
| 4429 | + case 'messenger': | |
| 4430 | + unset($settings['messenger']); | |
| 4431 | + break; | |
| 4432 | + case 'message_type': | |
| 4433 | + unset($settings['message_type']); | |
| 4434 | + break; | |
| 4435 | + default: | |
| 4436 | + $settings[ $key ] = $value; | |
| 4437 | + break; | |
| 4438 | + } | |
| 4439 | + } | |
| 4440 | + | |
| 4441 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); | |
| 4442 | + } | |
| 4443 | + | |
| 4444 | + // okay we should have the data all setup. Now we just update! | |
| 4445 | + $success = $this->_message_resource_manager->update_active_messengers_option(); | |
| 4446 | + | |
| 4447 | +		if ($success) { | |
| 4448 | +			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso')); | |
| 4449 | +		} else { | |
| 4450 | + EE_Error::add_error( | |
| 4451 | + esc_html__( | |
| 4452 | + 'Settings did not get updated', | |
| 4453 | + 'event_espresso' | |
| 4454 | + ), | |
| 4455 | + __FILE__, | |
| 4456 | + __FUNCTION__, | |
| 4457 | + __LINE__ | |
| 4458 | + ); | |
| 4459 | + } | |
| 4460 | + | |
| 4461 | + $this->_template_args['success'] = $success; | |
| 4462 | + $this->_return_json(); | |
| 4463 | + } | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + /** EE MESSAGE PROCESSING ACTIONS **/ | |
| 4469 | + | |
| 4470 | + | |
| 4471 | + /** | |
| 4472 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete | |
| 4473 | + * However, this does not send immediately, it just queues for sending. | |
| 4474 | + * | |
| 4475 | + * @throws EE_Error | |
| 4476 | + * @throws InvalidDataTypeException | |
| 4477 | + * @throws InvalidInterfaceException | |
| 4478 | + * @throws InvalidArgumentException | |
| 4479 | + * @throws ReflectionException | |
| 4480 | + * @since 4.9.0 | |
| 4481 | + */ | |
| 4482 | + protected function _generate_now() | |
| 4483 | +	{ | |
| 4484 | + EED_Messages::generate_now($this->_get_msg_ids_from_request()); | |
| 4485 | + $this->_redirect_after_action(false, '', '', [], true); | |
| 4486 | + } | |
| 4487 | + | |
| 4488 | + | |
| 4489 | + /** | |
| 4490 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that | |
| 4491 | + * are EEM_Message::status_resend or EEM_Message::status_idle | |
| 4492 | + * | |
| 4493 | + * @throws EE_Error | |
| 4494 | + * @throws InvalidDataTypeException | |
| 4495 | + * @throws InvalidInterfaceException | |
| 4496 | + * @throws InvalidArgumentException | |
| 4497 | + * @throws ReflectionException | |
| 4498 | + * @since 4.9.0 | |
| 4499 | + */ | |
| 4500 | + protected function _generate_and_send_now() | |
| 4501 | +	{ | |
| 4502 | + EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); | |
| 4503 | + $this->_redirect_after_action(false, '', '', [], true); | |
| 4504 | + } | |
| 4505 | + | |
| 4506 | + | |
| 4507 | + /** | |
| 4508 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. | |
| 4509 | + * | |
| 4510 | + * @throws EE_Error | |
| 4511 | + * @throws InvalidDataTypeException | |
| 4512 | + * @throws InvalidInterfaceException | |
| 4513 | + * @throws InvalidArgumentException | |
| 4514 | + * @throws ReflectionException | |
| 4515 | + * @since 4.9.0 | |
| 4516 | + */ | |
| 4517 | + protected function _queue_for_resending() | |
| 4518 | +	{ | |
| 4519 | + EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); | |
| 4520 | + $this->_redirect_after_action(false, '', '', [], true); | |
| 4521 | + } | |
| 4522 | + | |
| 4523 | + | |
| 4524 | + /** | |
| 4525 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue | |
| 4526 | + * | |
| 4527 | + * @throws EE_Error | |
| 4528 | + * @throws InvalidDataTypeException | |
| 4529 | + * @throws InvalidInterfaceException | |
| 4530 | + * @throws InvalidArgumentException | |
| 4531 | + * @throws ReflectionException | |
| 4532 | + * @since 4.9.0 | |
| 4533 | + */ | |
| 4534 | + protected function _send_now() | |
| 4535 | +	{ | |
| 4536 | + EED_Messages::send_now($this->_get_msg_ids_from_request()); | |
| 4537 | + $this->_redirect_after_action(false, '', '', [], true); | |
| 4538 | + } | |
| 4539 | + | |
| 4540 | + | |
| 4541 | + /** | |
| 4542 | + * Deletes EE_messages for IDs in the request. | |
| 4543 | + * | |
| 4544 | + * @throws EE_Error | |
| 4545 | + * @throws InvalidDataTypeException | |
| 4546 | + * @throws InvalidInterfaceException | |
| 4547 | + * @throws InvalidArgumentException | |
| 4548 | + * @since 4.9.0 | |
| 4549 | + */ | |
| 4550 | + protected function _delete_ee_messages() | |
| 4551 | +	{ | |
| 4552 | + $msg_ids = $this->_get_msg_ids_from_request(); | |
| 4553 | + $deleted_count = 0; | |
| 4554 | +		foreach ($msg_ids as $msg_id) { | |
| 4555 | +			if (EEM_Message::instance()->delete_by_ID($msg_id)) { | |
| 4556 | + $deleted_count++; | |
| 4557 | + } | |
| 4558 | + } | |
| 4559 | +		if ($deleted_count) { | |
| 4560 | + EE_Error::add_success( | |
| 4561 | + esc_html( | |
| 4562 | + _n( | |
| 4563 | + 'Message successfully deleted', | |
| 4564 | + 'Messages successfully deleted', | |
| 4565 | + $deleted_count, | |
| 4566 | + 'event_espresso' | |
| 4567 | + ) | |
| 4568 | + ) | |
| 4569 | + ); | |
| 4570 | + $this->_redirect_after_action( | |
| 4571 | + false, | |
| 4572 | + '', | |
| 4573 | + '', | |
| 4574 | + [], | |
| 4575 | + true | |
| 4576 | + ); | |
| 4577 | +		} else { | |
| 4578 | + EE_Error::add_error( | |
| 4579 | +				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), | |
| 4580 | + __FILE__, | |
| 4581 | + __FUNCTION__, | |
| 4582 | + __LINE__ | |
| 4583 | + ); | |
| 4584 | + $this->_redirect_after_action(false, '', '', [], true); | |
| 4585 | + } | |
| 4586 | + } | |
| 4587 | + | |
| 4588 | + | |
| 4589 | + /** | |
| 4590 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. | |
| 4591 | + * | |
| 4592 | + * @return array | |
| 4593 | + * @since 4.9.0 | |
| 4594 | + */ | |
| 4595 | + protected function _get_msg_ids_from_request() | |
| 4596 | +	{ | |
| 4597 | +		if (! isset($this->_req_data['MSG_ID'])) { | |
| 4598 | + return []; | |
| 4599 | + } | |
| 4600 | + | |
| 4601 | + return is_array($this->_req_data['MSG_ID']) | |
| 4602 | + ? array_keys($this->_req_data['MSG_ID']) | |
| 4603 | + : [$this->_req_data['MSG_ID']]; | |
| 4604 | + } | |
| 4605 | 4605 | } | 
| @@ -4,61 +4,61 @@ | ||
| 4 | 4 | |
| 5 | 5 | class RequestSanitizer | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * Will sanitize the supplied request parameter based on the specified data type | |
| 9 | - * | |
| 10 | - * @param mixed $param the supplied request parameter | |
| 11 | - * @param string $type the specified data type (default: "string") | |
| 12 | - * valid values: "bool", "float", "int", "key", "url", or "string" | |
| 13 | - * @param bool $is_array if true, then $param will be treated as an array of $type | |
| 14 | - * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator | |
| 15 | - * @return array|bool|float|int|string | |
| 16 | - * @since 4.10.14.p | |
| 17 | - */ | |
| 18 | - public function clean($param, $type = 'string', $is_array = false, $delimiter = '') | |
| 19 | -    { | |
| 20 | -        if ($delimiter !== '' && is_string($param)) { | |
| 21 | - $param = explode($delimiter, $param); | |
| 22 | - // unset the delimiter else this function will recurse forever when we loop over the array of results | |
| 23 | - $delimiter = ''; | |
| 24 | - } | |
| 25 | - // check if we are getting an improperly typed array and correct | |
| 26 | - $is_array = $is_array || is_array($param); | |
| 27 | -        if ($is_array) { | |
| 28 | - $values = []; | |
| 29 | -            foreach ((array) $param as $key => $value) { | |
| 30 | - $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); | |
| 31 | - } | |
| 32 | - return $values; | |
| 33 | - } | |
| 34 | - return $this->sanitizeParam($param, $type); | |
| 35 | - } | |
| 7 | + /** | |
| 8 | + * Will sanitize the supplied request parameter based on the specified data type | |
| 9 | + * | |
| 10 | + * @param mixed $param the supplied request parameter | |
| 11 | + * @param string $type the specified data type (default: "string") | |
| 12 | + * valid values: "bool", "float", "int", "key", "url", or "string" | |
| 13 | + * @param bool $is_array if true, then $param will be treated as an array of $type | |
| 14 | + * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator | |
| 15 | + * @return array|bool|float|int|string | |
| 16 | + * @since 4.10.14.p | |
| 17 | + */ | |
| 18 | + public function clean($param, $type = 'string', $is_array = false, $delimiter = '') | |
| 19 | +	{ | |
| 20 | +		if ($delimiter !== '' && is_string($param)) { | |
| 21 | + $param = explode($delimiter, $param); | |
| 22 | + // unset the delimiter else this function will recurse forever when we loop over the array of results | |
| 23 | + $delimiter = ''; | |
| 24 | + } | |
| 25 | + // check if we are getting an improperly typed array and correct | |
| 26 | + $is_array = $is_array || is_array($param); | |
| 27 | +		if ($is_array) { | |
| 28 | + $values = []; | |
| 29 | +			foreach ((array) $param as $key => $value) { | |
| 30 | + $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); | |
| 31 | + } | |
| 32 | + return $values; | |
| 33 | + } | |
| 34 | + return $this->sanitizeParam($param, $type); | |
| 35 | + } | |
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * @param mixed $param | |
| 40 | - * @param string $type | |
| 41 | - * @return array|float|int|mixed|string|string[]|null | |
| 42 | - * @since 4.10.20.p | |
| 43 | - */ | |
| 44 | - public function sanitizeParam($param, $type = 'string') | |
| 45 | -    { | |
| 46 | -        switch ($type) { | |
| 47 | - case 'bool': | |
| 48 | - return filter_var($param, FILTER_VALIDATE_BOOLEAN); | |
| 49 | - case 'float': | |
| 50 | - return (float) $param; | |
| 51 | - case 'fqcn': | |
| 52 | -                return preg_replace('[^\\\w\d]', '', $param); | |
| 53 | - case 'int': | |
| 54 | - return (int) $param; | |
| 55 | - case 'key': | |
| 56 | - return sanitize_key($param); | |
| 57 | - case 'url': | |
| 58 | - return esc_url_raw($param); | |
| 59 | - case 'string': | |
| 60 | - default: | |
| 61 | - return sanitize_text_field($param); | |
| 62 | - } | |
| 63 | - } | |
| 38 | + /** | |
| 39 | + * @param mixed $param | |
| 40 | + * @param string $type | |
| 41 | + * @return array|float|int|mixed|string|string[]|null | |
| 42 | + * @since 4.10.20.p | |
| 43 | + */ | |
| 44 | + public function sanitizeParam($param, $type = 'string') | |
| 45 | +	{ | |
| 46 | +		switch ($type) { | |
| 47 | + case 'bool': | |
| 48 | + return filter_var($param, FILTER_VALIDATE_BOOLEAN); | |
| 49 | + case 'float': | |
| 50 | + return (float) $param; | |
| 51 | + case 'fqcn': | |
| 52 | +				return preg_replace('[^\\\w\d]', '', $param); | |
| 53 | + case 'int': | |
| 54 | + return (int) $param; | |
| 55 | + case 'key': | |
| 56 | + return sanitize_key($param); | |
| 57 | + case 'url': | |
| 58 | + return esc_url_raw($param); | |
| 59 | + case 'string': | |
| 60 | + default: | |
| 61 | + return sanitize_text_field($param); | |
| 62 | + } | |
| 63 | + } | |
| 64 | 64 | } | 
| @@ -12,109 +12,109 @@ discard block | ||
| 12 | 12 | class EEW_Upcoming_Events extends EspressoWidget | 
| 13 | 13 |  { | 
| 14 | 14 | |
| 15 | - /** | |
| 16 | - * @var string | |
| 17 | - */ | |
| 18 | - private $title; | |
| 19 | - /** | |
| 20 | - * @var string | |
| 21 | - */ | |
| 22 | - private $events_category; | |
| 23 | - | |
| 24 | - /** | |
| 25 | - * @var bool | |
| 26 | - */ | |
| 27 | - private $show_expired; | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @var string | |
| 31 | - */ | |
| 32 | - private $image_size; | |
| 33 | - | |
| 34 | - /** | |
| 35 | - * @var bool | |
| 36 | - */ | |
| 37 | - private $show_desc; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * @var bool | |
| 41 | - */ | |
| 42 | - private $show_dates; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * @var string | |
| 46 | - */ | |
| 47 | - private $date_limit; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * @var string | |
| 51 | - */ | |
| 52 | - private $date_range; | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * @var string | |
| 56 | - */ | |
| 57 | - private $limit; | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * @var string | |
| 61 | - */ | |
| 62 | - private $order; | |
| 63 | - | |
| 64 | - | |
| 65 | - /** | |
| 66 | - * Register widget with WordPress. | |
| 67 | - */ | |
| 68 | - public function __construct() | |
| 69 | -    { | |
| 70 | - parent::__construct( | |
| 71 | -            esc_html__('Event Espresso Upcoming Events', 'event_espresso'), | |
| 72 | -            ['description' => esc_html__('A widget to display your upcoming events.', 'event_espresso')] | |
| 73 | - ); | |
| 74 | - } | |
| 75 | - | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * Back-end widget form. | |
| 79 | - * | |
| 80 | - * @param array $instance Previously saved values from database. | |
| 81 | - * @return void | |
| 82 | - * @throws EE_Error | |
| 83 | - * @throws ReflectionException | |
| 84 | - * @see WP_Widget::form() | |
| 85 | - */ | |
| 86 | - public function form($instance) | |
| 87 | -    { | |
| 88 | - | |
| 89 | -        EE_Registry::instance()->load_class('Question_Option', [], false, false, true); | |
| 90 | - // Set up some default widget settings. | |
| 91 | - $defaults = [ | |
| 92 | -            'title'           => esc_html__('Upcoming Events', 'event_espresso'), | |
| 93 | - 'category_name' => '', | |
| 94 | - 'show_expired' => 0, | |
| 95 | - 'show_desc' => true, | |
| 96 | - 'show_dates' => true, | |
| 97 | - 'show_everywhere' => false, | |
| 98 | - 'date_limit' => 2, | |
| 99 | - 'limit' => 10, | |
| 100 | - 'sort' => 'ASC', | |
| 101 | - 'date_range' => false, | |
| 102 | - 'image_size' => 'medium', | |
| 103 | - ]; | |
| 104 | - | |
| 105 | - $instance = wp_parse_args((array) $instance, $defaults); | |
| 106 | - // don't add HTML labels for EE_Form_Fields generated inputs | |
| 107 | -        add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); | |
| 108 | - $yes_no_values = [ | |
| 109 | -            EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]), | |
| 110 | -            EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]), | |
| 111 | - ]; | |
| 112 | - $sort_values = [ | |
| 113 | -            EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]), | |
| 114 | -            EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]), | |
| 115 | - ]; | |
| 116 | - | |
| 117 | - ?> | |
| 15 | + /** | |
| 16 | + * @var string | |
| 17 | + */ | |
| 18 | + private $title; | |
| 19 | + /** | |
| 20 | + * @var string | |
| 21 | + */ | |
| 22 | + private $events_category; | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * @var bool | |
| 26 | + */ | |
| 27 | + private $show_expired; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * @var string | |
| 31 | + */ | |
| 32 | + private $image_size; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @var bool | |
| 36 | + */ | |
| 37 | + private $show_desc; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @var bool | |
| 41 | + */ | |
| 42 | + private $show_dates; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @var string | |
| 46 | + */ | |
| 47 | + private $date_limit; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * @var string | |
| 51 | + */ | |
| 52 | + private $date_range; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @var string | |
| 56 | + */ | |
| 57 | + private $limit; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @var string | |
| 61 | + */ | |
| 62 | + private $order; | |
| 63 | + | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Register widget with WordPress. | |
| 67 | + */ | |
| 68 | + public function __construct() | |
| 69 | +	{ | |
| 70 | + parent::__construct( | |
| 71 | +			esc_html__('Event Espresso Upcoming Events', 'event_espresso'), | |
| 72 | +			['description' => esc_html__('A widget to display your upcoming events.', 'event_espresso')] | |
| 73 | + ); | |
| 74 | + } | |
| 75 | + | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Back-end widget form. | |
| 79 | + * | |
| 80 | + * @param array $instance Previously saved values from database. | |
| 81 | + * @return void | |
| 82 | + * @throws EE_Error | |
| 83 | + * @throws ReflectionException | |
| 84 | + * @see WP_Widget::form() | |
| 85 | + */ | |
| 86 | + public function form($instance) | |
| 87 | +	{ | |
| 88 | + | |
| 89 | +		EE_Registry::instance()->load_class('Question_Option', [], false, false, true); | |
| 90 | + // Set up some default widget settings. | |
| 91 | + $defaults = [ | |
| 92 | +			'title'           => esc_html__('Upcoming Events', 'event_espresso'), | |
| 93 | + 'category_name' => '', | |
| 94 | + 'show_expired' => 0, | |
| 95 | + 'show_desc' => true, | |
| 96 | + 'show_dates' => true, | |
| 97 | + 'show_everywhere' => false, | |
| 98 | + 'date_limit' => 2, | |
| 99 | + 'limit' => 10, | |
| 100 | + 'sort' => 'ASC', | |
| 101 | + 'date_range' => false, | |
| 102 | + 'image_size' => 'medium', | |
| 103 | + ]; | |
| 104 | + | |
| 105 | + $instance = wp_parse_args((array) $instance, $defaults); | |
| 106 | + // don't add HTML labels for EE_Form_Fields generated inputs | |
| 107 | +		add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); | |
| 108 | + $yes_no_values = [ | |
| 109 | +			EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]), | |
| 110 | +			EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]), | |
| 111 | + ]; | |
| 112 | + $sort_values = [ | |
| 113 | +			EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]), | |
| 114 | +			EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]), | |
| 115 | + ]; | |
| 116 | + | |
| 117 | + ?> | |
| 118 | 118 | |
| 119 | 119 | <!-- Widget Title: Text Input --> | 
| 120 | 120 | |
| @@ -151,32 +151,32 @@ discard block | ||
| 151 | 151 |                  <?php esc_html_e('Show Expired Events:', 'event_espresso'); ?> | 
| 152 | 152 | </label> | 
| 153 | 153 | <?php | 
| 154 | - $show_expired_options = $yes_no_values; | |
| 155 | - $show_expired_options[] = EE_Question_Option::new_instance( | |
| 156 | -                ['QSO_value' => 2, 'QSO_desc' => esc_html__('Show Only Expired', 'event_espresso')] | |
| 157 | - ); | |
| 158 | - echo EEH_Form_Fields::select( | |
| 159 | -                esc_html__('Show Expired Events:', 'event_espresso'), | |
| 160 | - $instance['show_expired'], | |
| 161 | - $show_expired_options, | |
| 162 | -                $this->fieldName('show_expired'), | |
| 163 | -                $this->fieldID('show_expired') | |
| 164 | - ); | |
| 165 | - ?> | |
| 154 | + $show_expired_options = $yes_no_values; | |
| 155 | + $show_expired_options[] = EE_Question_Option::new_instance( | |
| 156 | +				['QSO_value' => 2, 'QSO_desc' => esc_html__('Show Only Expired', 'event_espresso')] | |
| 157 | + ); | |
| 158 | + echo EEH_Form_Fields::select( | |
| 159 | +				esc_html__('Show Expired Events:', 'event_espresso'), | |
| 160 | + $instance['show_expired'], | |
| 161 | + $show_expired_options, | |
| 162 | +				$this->fieldName('show_expired'), | |
| 163 | +				$this->fieldID('show_expired') | |
| 164 | + ); | |
| 165 | + ?> | |
| 166 | 166 | </p> | 
| 167 | 167 | <p> | 
| 168 | 168 |              <label for="<?php echo $this->fieldID('sort'); ?>"> | 
| 169 | 169 |                  <?php esc_html_e('Sort Events:', 'event_espresso'); ?> | 
| 170 | 170 | </label> | 
| 171 | 171 | <?php | 
| 172 | - echo EEH_Form_Fields::select( | |
| 173 | -                esc_html__('Sort Events:', 'event_espresso'), | |
| 174 | - $instance['sort'], | |
| 175 | - $sort_values, | |
| 176 | -                $this->fieldName('sort'), | |
| 177 | -                $this->fieldID('sort') | |
| 178 | - ); | |
| 179 | - ?> | |
| 172 | + echo EEH_Form_Fields::select( | |
| 173 | +				esc_html__('Sort Events:', 'event_espresso'), | |
| 174 | + $instance['sort'], | |
| 175 | + $sort_values, | |
| 176 | +				$this->fieldName('sort'), | |
| 177 | +				$this->fieldID('sort') | |
| 178 | + ); | |
| 179 | + ?> | |
| 180 | 180 | </p> | 
| 181 | 181 | <p> | 
| 182 | 182 |              <label for="<?php echo $this->fieldID('image_size'); ?>"> | 
| @@ -190,42 +190,42 @@ discard block | ||
| 190 | 190 |                  <?php esc_html_e('Show Description:', 'event_espresso'); ?> | 
| 191 | 191 | </label> | 
| 192 | 192 | <?php | 
| 193 | - echo EEH_Form_Fields::select( | |
| 194 | -                esc_html__('Show Description:', 'event_espresso'), | |
| 195 | - $instance['show_desc'], | |
| 196 | - $yes_no_values, | |
| 197 | -                $this->fieldName('show_desc'), | |
| 198 | -                $this->fieldID('show_desc') | |
| 199 | - ); | |
| 200 | - ?> | |
| 193 | + echo EEH_Form_Fields::select( | |
| 194 | +				esc_html__('Show Description:', 'event_espresso'), | |
| 195 | + $instance['show_desc'], | |
| 196 | + $yes_no_values, | |
| 197 | +				$this->fieldName('show_desc'), | |
| 198 | +				$this->fieldID('show_desc') | |
| 199 | + ); | |
| 200 | + ?> | |
| 201 | 201 | </p> | 
| 202 | 202 | <p> | 
| 203 | 203 |              <label for="<?php echo $this->fieldID('show_dates'); ?>"> | 
| 204 | 204 |                  <?php esc_html_e('Show Dates:', 'event_espresso'); ?> | 
| 205 | 205 | </label> | 
| 206 | 206 | <?php | 
| 207 | - echo EEH_Form_Fields::select( | |
| 208 | -                esc_html__('Show Dates:', 'event_espresso'), | |
| 209 | - $instance['show_dates'], | |
| 210 | - $yes_no_values, | |
| 211 | -                $this->fieldName('show_dates'), | |
| 212 | -                $this->fieldID('show_dates') | |
| 213 | - ); | |
| 214 | - ?> | |
| 207 | + echo EEH_Form_Fields::select( | |
| 208 | +				esc_html__('Show Dates:', 'event_espresso'), | |
| 209 | + $instance['show_dates'], | |
| 210 | + $yes_no_values, | |
| 211 | +				$this->fieldName('show_dates'), | |
| 212 | +				$this->fieldID('show_dates') | |
| 213 | + ); | |
| 214 | + ?> | |
| 215 | 215 | </p> | 
| 216 | 216 | <p> | 
| 217 | 217 |              <label for="<?php echo $this->fieldID('show_everywhere'); ?>"> | 
| 218 | 218 |                  <?php esc_html_e('Show on all Pages:', 'event_espresso'); ?> | 
| 219 | 219 | </label> | 
| 220 | 220 | <?php | 
| 221 | - echo EEH_Form_Fields::select( | |
| 222 | -                esc_html__('Show on all Pages:', 'event_espresso'), | |
| 223 | - $instance['show_everywhere'], | |
| 224 | - $yes_no_values, | |
| 225 | -                $this->fieldName('show_everywhere'), | |
| 226 | -                $this->fieldID('show_everywhere') | |
| 227 | - ); | |
| 228 | - ?> | |
| 221 | + echo EEH_Form_Fields::select( | |
| 222 | +				esc_html__('Show on all Pages:', 'event_espresso'), | |
| 223 | + $instance['show_everywhere'], | |
| 224 | + $yes_no_values, | |
| 225 | +				$this->fieldName('show_everywhere'), | |
| 226 | +				$this->fieldID('show_everywhere') | |
| 227 | + ); | |
| 228 | + ?> | |
| 229 | 229 | </p> | 
| 230 | 230 | <p> | 
| 231 | 231 |              <label for="<?php echo $this->fieldID('date_limit'); ?>"> | 
| @@ -243,278 +243,278 @@ discard block | ||
| 243 | 243 |                  <?php esc_html_e('Show Date Range:', 'event_espresso'); ?> | 
| 244 | 244 | </label> | 
| 245 | 245 | <?php | 
| 246 | - echo EEH_Form_Fields::select( | |
| 247 | -                esc_html__('Show Date Range:', 'event_espresso'), | |
| 248 | - $instance['date_range'], | |
| 249 | - $yes_no_values, | |
| 250 | -                $this->fieldName('date_range'), | |
| 251 | -                $this->fieldID('date_range') | |
| 252 | - ); | |
| 253 | - ?> | |
| 246 | + echo EEH_Form_Fields::select( | |
| 247 | +				esc_html__('Show Date Range:', 'event_espresso'), | |
| 248 | + $instance['date_range'], | |
| 249 | + $yes_no_values, | |
| 250 | +				$this->fieldName('date_range'), | |
| 251 | +				$this->fieldID('date_range') | |
| 252 | + ); | |
| 253 | + ?> | |
| 254 | 254 | <span class="description"> | 
| 255 | 255 | <br /> | 
| 256 | 256 | <?php esc_html_e( | 
| 257 | - 'This setting will replace the list of dates in the widget.', | |
| 258 | - 'event_espresso' | |
| 259 | - ); ?> | |
| 257 | + 'This setting will replace the list of dates in the widget.', | |
| 258 | + 'event_espresso' | |
| 259 | + ); ?> | |
| 260 | 260 | </span> | 
| 261 | 261 | </p> | 
| 262 | 262 | |
| 263 | 263 | <?php | 
| 264 | - } | |
| 265 | - | |
| 266 | - | |
| 267 | - /** | |
| 268 | - * Sanitize widget form values as they are saved. | |
| 269 | - * | |
| 270 | - * @param array $new_instance Values just sent to be saved. | |
| 271 | - * @param array $old_instance Previously saved values from database. | |
| 272 | - * | |
| 273 | - * @return array Updated safe values to be saved. | |
| 274 | - * @see WP_Widget::update() | |
| 275 | - * | |
| 276 | - */ | |
| 277 | - public function update($new_instance, $old_instance) | |
| 278 | -    { | |
| 279 | - $instance = $old_instance; | |
| 280 | - $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; | |
| 281 | - $instance['category_name'] = $new_instance['category_name']; | |
| 282 | - $instance['show_expired'] = $new_instance['show_expired']; | |
| 283 | - $instance['limit'] = $new_instance['limit']; | |
| 284 | - $instance['sort'] = $new_instance['sort']; | |
| 285 | - $instance['image_size'] = $new_instance['image_size']; | |
| 286 | - $instance['show_desc'] = $new_instance['show_desc']; | |
| 287 | - $instance['show_dates'] = $new_instance['show_dates']; | |
| 288 | - $instance['show_everywhere'] = $new_instance['show_everywhere']; | |
| 289 | - $instance['date_limit'] = $new_instance['date_limit']; | |
| 290 | - $instance['date_range'] = $new_instance['date_range']; | |
| 291 | - return $instance; | |
| 292 | - } | |
| 293 | - | |
| 294 | - | |
| 295 | - /** | |
| 296 | - * Front-end display of widget. | |
| 297 | - * | |
| 298 | - * @param array $args Widget arguments. | |
| 299 | - * @param array $instance Saved values from database. | |
| 300 | - * @throws EE_Error | |
| 301 | - * @throws ReflectionException | |
| 302 | - * @see WP_Widget::widget() | |
| 303 | - * | |
| 304 | - */ | |
| 305 | - public function widget($args, $instance) | |
| 306 | -    { | |
| 307 | - | |
| 308 | - global $post; | |
| 309 | - // make sure there is some kinda post object | |
| 310 | -        if ($post instanceof WP_Post) { | |
| 311 | - $before_widget = ''; | |
| 312 | - $before_title = ''; | |
| 313 | - $after_title = ''; | |
| 314 | - $after_widget = ''; | |
| 315 | - // but NOT an events archives page, cuz that would be like two event lists on the same page | |
| 316 | - $show_everywhere = ! isset($instance['show_everywhere']) || absint($instance['show_everywhere']); | |
| 317 | -            if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { | |
| 318 | - // let's use some of the event helper functions' | |
| 319 | - // make separate vars out of attributes | |
| 320 | - extract($args); | |
| 321 | - | |
| 322 | - // grab widget settings | |
| 323 | - $this->parseWidgetSettings($instance); | |
| 324 | - $title = $this->widgetTitle(); | |
| 325 | - | |
| 326 | - // Before widget (defined by themes). | |
| 327 | - echo $before_widget; | |
| 328 | - // Display the widget title if one was input (before and after defined by themes). | |
| 329 | -                if (! empty($title)) { | |
| 330 | - echo $before_title . $title . $after_title; | |
| 331 | - } | |
| 332 | - echo $this->widgetContent($post); | |
| 333 | - // After widget (defined by themes). | |
| 334 | - echo $after_widget; | |
| 335 | - } | |
| 336 | - } | |
| 337 | - } | |
| 338 | - | |
| 339 | - | |
| 340 | - /** | |
| 341 | - * make_the_title_a_link | |
| 342 | - * callback for widget_title filter | |
| 343 | - * | |
| 344 | - * @param $title | |
| 345 | - * @return string | |
| 346 | - */ | |
| 347 | - public function make_the_title_a_link($title) | |
| 348 | -    { | |
| 349 | - return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; | |
| 350 | - } | |
| 351 | - | |
| 352 | - | |
| 353 | - /** | |
| 354 | - * @param string $field_name | |
| 355 | - * @return string | |
| 356 | - * @since 4.10.14.p | |
| 357 | - */ | |
| 358 | - public function fieldID($field_name) | |
| 359 | -    { | |
| 360 | - return esc_attr(parent::get_field_id($field_name)); | |
| 361 | - } | |
| 362 | - | |
| 363 | - | |
| 364 | - /** | |
| 365 | - * @param string $field_name | |
| 366 | - * @return string | |
| 367 | - * @since 4.10.14.p | |
| 368 | - */ | |
| 369 | - public function fieldName($field_name) | |
| 370 | -    { | |
| 371 | - return esc_attr(parent::get_field_name($field_name)); | |
| 372 | - } | |
| 373 | - | |
| 374 | - | |
| 375 | - /** | |
| 376 | - * @param array $instance | |
| 377 | - * @throws EE_Error | |
| 378 | - * @throws ReflectionException | |
| 379 | - * @since 4.10.14.p | |
| 380 | - */ | |
| 381 | - private function eventCategoriesSelector(array $instance) | |
| 382 | -    { | |
| 383 | - $event_categories = []; | |
| 384 | - $categories = EEM_Term::instance()->get_all_ee_categories(true); | |
| 385 | -        if ($categories) { | |
| 386 | -            foreach ($categories as $category) { | |
| 387 | -                if ($category instanceof EE_Term) { | |
| 388 | - $event_categories[] = | |
| 389 | - EE_Question_Option::new_instance( | |
| 390 | - [ | |
| 391 | -                                'QSO_value' => $category->get('slug'), | |
| 392 | -                                'QSO_desc'  => $category->get('name'), | |
| 393 | - ] | |
| 394 | - ); | |
| 395 | - } | |
| 396 | - } | |
| 397 | - } | |
| 398 | - array_unshift( | |
| 399 | - $event_categories, | |
| 400 | - EE_Question_Option::new_instance( | |
| 401 | - [ | |
| 402 | - 'QSO_value' => '', | |
| 403 | -                    'QSO_desc'  => esc_html__(' - display all - ', 'event_espresso'), | |
| 404 | - ] | |
| 405 | - ) | |
| 406 | - ); | |
| 407 | - echo EEH_Form_Fields::select( | |
| 408 | -            esc_html__('Event Category:', 'event_espresso'), | |
| 409 | - $instance['category_name'], | |
| 410 | - $event_categories, | |
| 411 | -            $this->fieldName('category_name'), | |
| 412 | -            $this->fieldID('category_name') | |
| 413 | - ); | |
| 414 | - } | |
| 415 | - | |
| 416 | - | |
| 417 | - /** | |
| 418 | - * @param array $instance | |
| 419 | - * @since 4.10.14.p | |
| 420 | - */ | |
| 421 | - private function imageSizeSelector(array $instance) | |
| 422 | -    { | |
| 423 | - $image_sizes = []; | |
| 424 | - $sizes = get_intermediate_image_sizes(); | |
| 425 | -        if ($sizes) { | |
| 426 | - // loop thru images and create option objects out of them | |
| 427 | -            foreach ($sizes as $image_size) { | |
| 428 | - $image_size = trim($image_size); | |
| 429 | - // no big images plz | |
| 430 | -                if (! in_array($image_size, ['large', 'post-thumbnail'])) { | |
| 431 | - $image_sizes[] = | |
| 432 | - EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]); | |
| 433 | - } | |
| 434 | - } | |
| 435 | - $image_sizes[] = | |
| 436 | - EE_Question_Option::new_instance( | |
| 437 | -                    ['QSO_value' => 'none', 'QSO_desc' => esc_html__('don\'t show images', 'event_espresso')] | |
| 438 | - ); | |
| 439 | - } | |
| 440 | - echo EEH_Form_Fields::select( | |
| 441 | -            esc_html__('Image Size:', 'event_espresso'), | |
| 442 | - $instance['image_size'], | |
| 443 | - $image_sizes, | |
| 444 | -            $this->fieldName('image_size'), | |
| 445 | -            $this->fieldID('image_size') | |
| 446 | - ); | |
| 447 | - } | |
| 448 | - | |
| 449 | - | |
| 450 | - /** | |
| 451 | - * @param array $instance | |
| 452 | - * @since 4.10.14.p | |
| 453 | - */ | |
| 454 | - private function parseWidgetSettings(array $instance) | |
| 455 | -    { | |
| 456 | - $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : ''; | |
| 457 | - $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name']) | |
| 458 | - ? $instance['category_name'] | |
| 459 | - : false; | |
| 460 | - $this->show_expired = isset($instance['show_expired']) | |
| 461 | - ? filter_var($instance['show_expired'], FILTER_VALIDATE_BOOLEAN) | |
| 462 | - : 0; | |
| 463 | - $this->image_size = isset($instance['image_size']) && ! empty($instance['image_size']) | |
| 464 | - ? $instance['image_size'] | |
| 465 | - : 'medium'; | |
| 466 | - $this->show_desc = ! isset($instance['show_desc']) | |
| 467 | - || filter_var($instance['show_desc'], FILTER_VALIDATE_BOOLEAN); | |
| 468 | - $this->show_dates = ! isset($instance['show_dates']) | |
| 469 | - || filter_var($instance['show_dates'], FILTER_VALIDATE_BOOLEAN); | |
| 470 | - $this->date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) | |
| 471 | - ? $instance['date_limit'] | |
| 472 | - : null; | |
| 473 | - $this->date_range = isset($instance['date_range']) && ! empty($instance['date_range']) | |
| 474 | - ? $instance['date_range'] | |
| 475 | - : false; | |
| 476 | - $this->limit = isset($instance['limit']) ? absint($instance['limit']) : 10; | |
| 477 | - $this->order = isset($instance['order']) && $instance['order'] === 'DESC' | |
| 478 | - ? 'DESC' | |
| 479 | - : 'ASC'; | |
| 480 | - } | |
| 481 | - | |
| 482 | - | |
| 483 | - /** | |
| 484 | - * @return mixed|void | |
| 485 | - * @since 4.10.14.p | |
| 486 | - */ | |
| 487 | - private function widgetTitle() | |
| 488 | -    { | |
| 489 | - // add function to make the title a link | |
| 490 | -        add_filter('widget_title', [$this, 'make_the_title_a_link'], 15); | |
| 491 | - // filter the title | |
| 492 | -        $title = apply_filters('widget_title', $this->title); | |
| 493 | - // remove the function from the filter, so it does not affect other widgets | |
| 494 | -        remove_filter('widget_title', [$this, 'make_the_title_a_link'], 15); | |
| 495 | - return $title; | |
| 496 | - } | |
| 497 | - | |
| 498 | - | |
| 499 | - /** | |
| 500 | - * @param WP_Post $post | |
| 501 | - * @return string | |
| 502 | - * @throws EE_Error | |
| 503 | - * @throws ReflectionException | |
| 504 | - * @since 4.10.14.p | |
| 505 | - */ | |
| 506 | - private function widgetContent(WP_Post $post) | |
| 507 | -    { | |
| 508 | - // run the query | |
| 509 | - $events = $this->getUpcomingEvents(); | |
| 510 | -        if (empty($events)) { | |
| 511 | - return ''; | |
| 512 | - } | |
| 513 | - $list_items = ''; | |
| 514 | -        foreach ($events as $event) { | |
| 515 | -            if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) { | |
| 516 | - $event_url = $this->eventUrl($event); | |
| 517 | - $list_items .= ' | |
| 264 | + } | |
| 265 | + | |
| 266 | + | |
| 267 | + /** | |
| 268 | + * Sanitize widget form values as they are saved. | |
| 269 | + * | |
| 270 | + * @param array $new_instance Values just sent to be saved. | |
| 271 | + * @param array $old_instance Previously saved values from database. | |
| 272 | + * | |
| 273 | + * @return array Updated safe values to be saved. | |
| 274 | + * @see WP_Widget::update() | |
| 275 | + * | |
| 276 | + */ | |
| 277 | + public function update($new_instance, $old_instance) | |
| 278 | +	{ | |
| 279 | + $instance = $old_instance; | |
| 280 | + $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; | |
| 281 | + $instance['category_name'] = $new_instance['category_name']; | |
| 282 | + $instance['show_expired'] = $new_instance['show_expired']; | |
| 283 | + $instance['limit'] = $new_instance['limit']; | |
| 284 | + $instance['sort'] = $new_instance['sort']; | |
| 285 | + $instance['image_size'] = $new_instance['image_size']; | |
| 286 | + $instance['show_desc'] = $new_instance['show_desc']; | |
| 287 | + $instance['show_dates'] = $new_instance['show_dates']; | |
| 288 | + $instance['show_everywhere'] = $new_instance['show_everywhere']; | |
| 289 | + $instance['date_limit'] = $new_instance['date_limit']; | |
| 290 | + $instance['date_range'] = $new_instance['date_range']; | |
| 291 | + return $instance; | |
| 292 | + } | |
| 293 | + | |
| 294 | + | |
| 295 | + /** | |
| 296 | + * Front-end display of widget. | |
| 297 | + * | |
| 298 | + * @param array $args Widget arguments. | |
| 299 | + * @param array $instance Saved values from database. | |
| 300 | + * @throws EE_Error | |
| 301 | + * @throws ReflectionException | |
| 302 | + * @see WP_Widget::widget() | |
| 303 | + * | |
| 304 | + */ | |
| 305 | + public function widget($args, $instance) | |
| 306 | +	{ | |
| 307 | + | |
| 308 | + global $post; | |
| 309 | + // make sure there is some kinda post object | |
| 310 | +		if ($post instanceof WP_Post) { | |
| 311 | + $before_widget = ''; | |
| 312 | + $before_title = ''; | |
| 313 | + $after_title = ''; | |
| 314 | + $after_widget = ''; | |
| 315 | + // but NOT an events archives page, cuz that would be like two event lists on the same page | |
| 316 | + $show_everywhere = ! isset($instance['show_everywhere']) || absint($instance['show_everywhere']); | |
| 317 | +			if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { | |
| 318 | + // let's use some of the event helper functions' | |
| 319 | + // make separate vars out of attributes | |
| 320 | + extract($args); | |
| 321 | + | |
| 322 | + // grab widget settings | |
| 323 | + $this->parseWidgetSettings($instance); | |
| 324 | + $title = $this->widgetTitle(); | |
| 325 | + | |
| 326 | + // Before widget (defined by themes). | |
| 327 | + echo $before_widget; | |
| 328 | + // Display the widget title if one was input (before and after defined by themes). | |
| 329 | +				if (! empty($title)) { | |
| 330 | + echo $before_title . $title . $after_title; | |
| 331 | + } | |
| 332 | + echo $this->widgetContent($post); | |
| 333 | + // After widget (defined by themes). | |
| 334 | + echo $after_widget; | |
| 335 | + } | |
| 336 | + } | |
| 337 | + } | |
| 338 | + | |
| 339 | + | |
| 340 | + /** | |
| 341 | + * make_the_title_a_link | |
| 342 | + * callback for widget_title filter | |
| 343 | + * | |
| 344 | + * @param $title | |
| 345 | + * @return string | |
| 346 | + */ | |
| 347 | + public function make_the_title_a_link($title) | |
| 348 | +	{ | |
| 349 | + return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; | |
| 350 | + } | |
| 351 | + | |
| 352 | + | |
| 353 | + /** | |
| 354 | + * @param string $field_name | |
| 355 | + * @return string | |
| 356 | + * @since 4.10.14.p | |
| 357 | + */ | |
| 358 | + public function fieldID($field_name) | |
| 359 | +	{ | |
| 360 | + return esc_attr(parent::get_field_id($field_name)); | |
| 361 | + } | |
| 362 | + | |
| 363 | + | |
| 364 | + /** | |
| 365 | + * @param string $field_name | |
| 366 | + * @return string | |
| 367 | + * @since 4.10.14.p | |
| 368 | + */ | |
| 369 | + public function fieldName($field_name) | |
| 370 | +	{ | |
| 371 | + return esc_attr(parent::get_field_name($field_name)); | |
| 372 | + } | |
| 373 | + | |
| 374 | + | |
| 375 | + /** | |
| 376 | + * @param array $instance | |
| 377 | + * @throws EE_Error | |
| 378 | + * @throws ReflectionException | |
| 379 | + * @since 4.10.14.p | |
| 380 | + */ | |
| 381 | + private function eventCategoriesSelector(array $instance) | |
| 382 | +	{ | |
| 383 | + $event_categories = []; | |
| 384 | + $categories = EEM_Term::instance()->get_all_ee_categories(true); | |
| 385 | +		if ($categories) { | |
| 386 | +			foreach ($categories as $category) { | |
| 387 | +				if ($category instanceof EE_Term) { | |
| 388 | + $event_categories[] = | |
| 389 | + EE_Question_Option::new_instance( | |
| 390 | + [ | |
| 391 | +								'QSO_value' => $category->get('slug'), | |
| 392 | +								'QSO_desc'  => $category->get('name'), | |
| 393 | + ] | |
| 394 | + ); | |
| 395 | + } | |
| 396 | + } | |
| 397 | + } | |
| 398 | + array_unshift( | |
| 399 | + $event_categories, | |
| 400 | + EE_Question_Option::new_instance( | |
| 401 | + [ | |
| 402 | + 'QSO_value' => '', | |
| 403 | +					'QSO_desc'  => esc_html__(' - display all - ', 'event_espresso'), | |
| 404 | + ] | |
| 405 | + ) | |
| 406 | + ); | |
| 407 | + echo EEH_Form_Fields::select( | |
| 408 | +			esc_html__('Event Category:', 'event_espresso'), | |
| 409 | + $instance['category_name'], | |
| 410 | + $event_categories, | |
| 411 | +			$this->fieldName('category_name'), | |
| 412 | +			$this->fieldID('category_name') | |
| 413 | + ); | |
| 414 | + } | |
| 415 | + | |
| 416 | + | |
| 417 | + /** | |
| 418 | + * @param array $instance | |
| 419 | + * @since 4.10.14.p | |
| 420 | + */ | |
| 421 | + private function imageSizeSelector(array $instance) | |
| 422 | +	{ | |
| 423 | + $image_sizes = []; | |
| 424 | + $sizes = get_intermediate_image_sizes(); | |
| 425 | +		if ($sizes) { | |
| 426 | + // loop thru images and create option objects out of them | |
| 427 | +			foreach ($sizes as $image_size) { | |
| 428 | + $image_size = trim($image_size); | |
| 429 | + // no big images plz | |
| 430 | +				if (! in_array($image_size, ['large', 'post-thumbnail'])) { | |
| 431 | + $image_sizes[] = | |
| 432 | + EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]); | |
| 433 | + } | |
| 434 | + } | |
| 435 | + $image_sizes[] = | |
| 436 | + EE_Question_Option::new_instance( | |
| 437 | +					['QSO_value' => 'none', 'QSO_desc' => esc_html__('don\'t show images', 'event_espresso')] | |
| 438 | + ); | |
| 439 | + } | |
| 440 | + echo EEH_Form_Fields::select( | |
| 441 | +			esc_html__('Image Size:', 'event_espresso'), | |
| 442 | + $instance['image_size'], | |
| 443 | + $image_sizes, | |
| 444 | +			$this->fieldName('image_size'), | |
| 445 | +			$this->fieldID('image_size') | |
| 446 | + ); | |
| 447 | + } | |
| 448 | + | |
| 449 | + | |
| 450 | + /** | |
| 451 | + * @param array $instance | |
| 452 | + * @since 4.10.14.p | |
| 453 | + */ | |
| 454 | + private function parseWidgetSettings(array $instance) | |
| 455 | +	{ | |
| 456 | + $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : ''; | |
| 457 | + $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name']) | |
| 458 | + ? $instance['category_name'] | |
| 459 | + : false; | |
| 460 | + $this->show_expired = isset($instance['show_expired']) | |
| 461 | + ? filter_var($instance['show_expired'], FILTER_VALIDATE_BOOLEAN) | |
| 462 | + : 0; | |
| 463 | + $this->image_size = isset($instance['image_size']) && ! empty($instance['image_size']) | |
| 464 | + ? $instance['image_size'] | |
| 465 | + : 'medium'; | |
| 466 | + $this->show_desc = ! isset($instance['show_desc']) | |
| 467 | + || filter_var($instance['show_desc'], FILTER_VALIDATE_BOOLEAN); | |
| 468 | + $this->show_dates = ! isset($instance['show_dates']) | |
| 469 | + || filter_var($instance['show_dates'], FILTER_VALIDATE_BOOLEAN); | |
| 470 | + $this->date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) | |
| 471 | + ? $instance['date_limit'] | |
| 472 | + : null; | |
| 473 | + $this->date_range = isset($instance['date_range']) && ! empty($instance['date_range']) | |
| 474 | + ? $instance['date_range'] | |
| 475 | + : false; | |
| 476 | + $this->limit = isset($instance['limit']) ? absint($instance['limit']) : 10; | |
| 477 | + $this->order = isset($instance['order']) && $instance['order'] === 'DESC' | |
| 478 | + ? 'DESC' | |
| 479 | + : 'ASC'; | |
| 480 | + } | |
| 481 | + | |
| 482 | + | |
| 483 | + /** | |
| 484 | + * @return mixed|void | |
| 485 | + * @since 4.10.14.p | |
| 486 | + */ | |
| 487 | + private function widgetTitle() | |
| 488 | +	{ | |
| 489 | + // add function to make the title a link | |
| 490 | +		add_filter('widget_title', [$this, 'make_the_title_a_link'], 15); | |
| 491 | + // filter the title | |
| 492 | +		$title = apply_filters('widget_title', $this->title); | |
| 493 | + // remove the function from the filter, so it does not affect other widgets | |
| 494 | +		remove_filter('widget_title', [$this, 'make_the_title_a_link'], 15); | |
| 495 | + return $title; | |
| 496 | + } | |
| 497 | + | |
| 498 | + | |
| 499 | + /** | |
| 500 | + * @param WP_Post $post | |
| 501 | + * @return string | |
| 502 | + * @throws EE_Error | |
| 503 | + * @throws ReflectionException | |
| 504 | + * @since 4.10.14.p | |
| 505 | + */ | |
| 506 | + private function widgetContent(WP_Post $post) | |
| 507 | +	{ | |
| 508 | + // run the query | |
| 509 | + $events = $this->getUpcomingEvents(); | |
| 510 | +		if (empty($events)) { | |
| 511 | + return ''; | |
| 512 | + } | |
| 513 | + $list_items = ''; | |
| 514 | +		foreach ($events as $event) { | |
| 515 | +			if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) { | |
| 516 | + $event_url = $this->eventUrl($event); | |
| 517 | + $list_items .= ' | |
| 518 | 518 | <li id="ee-upcoming-events-widget-li-' . esc_attr($event->ID()) . '" | 
| 519 | 519 | class="ee-upcoming-events-widget-li" | 
| 520 | 520 | > | 
| @@ -525,194 +525,194 @@ discard block | ||
| 525 | 525 | </h5> | 
| 526 | 526 | ' . $this->eventWidgetContent($event, $event_url) . ' | 
| 527 | 527 | </li>'; | 
| 528 | - } | |
| 529 | - } | |
| 530 | - return ' | |
| 528 | + } | |
| 529 | + } | |
| 530 | + return ' | |
| 531 | 531 | <ul class="ee-upcoming-events-widget-ul"> | 
| 532 | 532 | ' . $list_items . ' | 
| 533 | 533 | </ul>'; | 
| 534 | - } | |
| 535 | - | |
| 536 | - | |
| 537 | - /** | |
| 538 | - * @param EE_Event $event | |
| 539 | - * @return string|null | |
| 540 | - * @throws EE_Error | |
| 541 | - * @since 4.10.14.p | |
| 542 | - */ | |
| 543 | - private function eventUrl(EE_Event $event) | |
| 544 | -    { | |
| 545 | - return esc_url_raw( | |
| 546 | - apply_filters( | |
| 547 | - 'FHEE_EEW_Upcoming_Events__widget__event_url', | |
| 548 | - $event->get_permalink(), | |
| 549 | - $event | |
| 550 | - ) | |
| 551 | - ); | |
| 552 | - } | |
| 553 | - | |
| 554 | - | |
| 555 | - /** | |
| 556 | - * @return EE_Base_Class[] | |
| 557 | - * @throws EE_Error | |
| 558 | - */ | |
| 559 | - private function getUpcomingEvents() | |
| 560 | -    { | |
| 561 | - return EEM_Event::instance()->get_all( | |
| 562 | - [ | |
| 563 | - $this->queryWhereParams(), | |
| 564 | - 'limit' => '0,' . $this->limit, | |
| 565 | - 'order_by' => 'Datetime.DTT_EVT_start', | |
| 566 | - 'order' => $this->order, | |
| 567 | - 'group_by' => 'EVT_ID', | |
| 568 | - ] | |
| 569 | - ); | |
| 570 | - } | |
| 571 | - | |
| 572 | - | |
| 573 | - /** | |
| 574 | - * @return mixed|void | |
| 575 | - * @throws EE_Error | |
| 576 | - * @since 4.10.14.p | |
| 577 | - */ | |
| 578 | - private function queryWhereParams() | |
| 579 | -    { | |
| 580 | - // start to build our where clause | |
| 581 | - $where = [ | |
| 582 | - 'status' => ['IN', ['publish', 'sold_out']], | |
| 583 | - ]; | |
| 584 | - // add category | |
| 585 | -        if ($this->events_category) { | |
| 586 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; | |
| 587 | - $where['Term_Taxonomy.Term.slug'] = $this->events_category; | |
| 588 | - } | |
| 589 | - // if NOT expired then we want events that start today or in the future | |
| 590 | - // if NOT show expired then we want events that start today or in the future | |
| 591 | -        if ($this->show_expired == 0) { | |
| 592 | - $where['Datetime.DTT_EVT_end'] = [ | |
| 593 | - '>=', | |
| 594 | -                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), | |
| 595 | - ]; | |
| 596 | - } | |
| 597 | - // if show ONLY expired we want events that ended prior to today | |
| 598 | -        if ($this->show_expired == 2) { | |
| 599 | - $where['Datetime.DTT_EVT_end'] = [ | |
| 600 | - '<=', | |
| 601 | -                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), | |
| 602 | - ]; | |
| 603 | - } | |
| 604 | - // allow $where to be filtered | |
| 605 | -        return apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $this->events_category, $this->show_expired); | |
| 606 | - } | |
| 607 | - | |
| 608 | - | |
| 609 | - /** | |
| 610 | - * @param EE_Event $event | |
| 611 | - * @return string | |
| 612 | - * @throws EE_Error | |
| 613 | - * @throws ReflectionException | |
| 614 | - * @since 4.10.14.p | |
| 615 | - */ | |
| 616 | - private function linkClass(EE_Event $event) | |
| 617 | -    { | |
| 618 | - // how big is the event name ? | |
| 619 | - $name_length = strlen($event->name()); | |
| 620 | -        switch ($name_length) { | |
| 621 | - case $name_length > 70: | |
| 622 | - return ' three-line'; | |
| 623 | - case $name_length > 35: | |
| 624 | - return ' two-line'; | |
| 625 | - } | |
| 626 | - return ' one-line'; | |
| 627 | - } | |
| 628 | - | |
| 629 | - | |
| 630 | - /** | |
| 631 | - * @param EE_Event $event | |
| 632 | - * @param string $event_url | |
| 633 | - * @return mixed|string|void | |
| 634 | - * @throws EE_Error | |
| 635 | - * @throws ReflectionException | |
| 636 | - * @since 4.10.14.p | |
| 637 | - */ | |
| 638 | - private function eventWidgetContent(EE_Event $event, $event_url = '') | |
| 639 | -    { | |
| 640 | -        if (post_password_required($event->ID())) { | |
| 641 | - return apply_filters( | |
| 642 | - 'FHEE_EEW_Upcoming_Events__widget__password_form', | |
| 643 | - get_the_password_form($event->ID()), | |
| 644 | - $event | |
| 645 | - ); | |
| 646 | - } | |
| 647 | - | |
| 648 | - $content = ''; | |
| 649 | -        if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') { | |
| 650 | - $content .= ' | |
| 534 | + } | |
| 535 | + | |
| 536 | + | |
| 537 | + /** | |
| 538 | + * @param EE_Event $event | |
| 539 | + * @return string|null | |
| 540 | + * @throws EE_Error | |
| 541 | + * @since 4.10.14.p | |
| 542 | + */ | |
| 543 | + private function eventUrl(EE_Event $event) | |
| 544 | +	{ | |
| 545 | + return esc_url_raw( | |
| 546 | + apply_filters( | |
| 547 | + 'FHEE_EEW_Upcoming_Events__widget__event_url', | |
| 548 | + $event->get_permalink(), | |
| 549 | + $event | |
| 550 | + ) | |
| 551 | + ); | |
| 552 | + } | |
| 553 | + | |
| 554 | + | |
| 555 | + /** | |
| 556 | + * @return EE_Base_Class[] | |
| 557 | + * @throws EE_Error | |
| 558 | + */ | |
| 559 | + private function getUpcomingEvents() | |
| 560 | +	{ | |
| 561 | + return EEM_Event::instance()->get_all( | |
| 562 | + [ | |
| 563 | + $this->queryWhereParams(), | |
| 564 | + 'limit' => '0,' . $this->limit, | |
| 565 | + 'order_by' => 'Datetime.DTT_EVT_start', | |
| 566 | + 'order' => $this->order, | |
| 567 | + 'group_by' => 'EVT_ID', | |
| 568 | + ] | |
| 569 | + ); | |
| 570 | + } | |
| 571 | + | |
| 572 | + | |
| 573 | + /** | |
| 574 | + * @return mixed|void | |
| 575 | + * @throws EE_Error | |
| 576 | + * @since 4.10.14.p | |
| 577 | + */ | |
| 578 | + private function queryWhereParams() | |
| 579 | +	{ | |
| 580 | + // start to build our where clause | |
| 581 | + $where = [ | |
| 582 | + 'status' => ['IN', ['publish', 'sold_out']], | |
| 583 | + ]; | |
| 584 | + // add category | |
| 585 | +		if ($this->events_category) { | |
| 586 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; | |
| 587 | + $where['Term_Taxonomy.Term.slug'] = $this->events_category; | |
| 588 | + } | |
| 589 | + // if NOT expired then we want events that start today or in the future | |
| 590 | + // if NOT show expired then we want events that start today or in the future | |
| 591 | +		if ($this->show_expired == 0) { | |
| 592 | + $where['Datetime.DTT_EVT_end'] = [ | |
| 593 | + '>=', | |
| 594 | +				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), | |
| 595 | + ]; | |
| 596 | + } | |
| 597 | + // if show ONLY expired we want events that ended prior to today | |
| 598 | +		if ($this->show_expired == 2) { | |
| 599 | + $where['Datetime.DTT_EVT_end'] = [ | |
| 600 | + '<=', | |
| 601 | +				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), | |
| 602 | + ]; | |
| 603 | + } | |
| 604 | + // allow $where to be filtered | |
| 605 | +		return apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $this->events_category, $this->show_expired); | |
| 606 | + } | |
| 607 | + | |
| 608 | + | |
| 609 | + /** | |
| 610 | + * @param EE_Event $event | |
| 611 | + * @return string | |
| 612 | + * @throws EE_Error | |
| 613 | + * @throws ReflectionException | |
| 614 | + * @since 4.10.14.p | |
| 615 | + */ | |
| 616 | + private function linkClass(EE_Event $event) | |
| 617 | +	{ | |
| 618 | + // how big is the event name ? | |
| 619 | + $name_length = strlen($event->name()); | |
| 620 | +		switch ($name_length) { | |
| 621 | + case $name_length > 70: | |
| 622 | + return ' three-line'; | |
| 623 | + case $name_length > 35: | |
| 624 | + return ' two-line'; | |
| 625 | + } | |
| 626 | + return ' one-line'; | |
| 627 | + } | |
| 628 | + | |
| 629 | + | |
| 630 | + /** | |
| 631 | + * @param EE_Event $event | |
| 632 | + * @param string $event_url | |
| 633 | + * @return mixed|string|void | |
| 634 | + * @throws EE_Error | |
| 635 | + * @throws ReflectionException | |
| 636 | + * @since 4.10.14.p | |
| 637 | + */ | |
| 638 | + private function eventWidgetContent(EE_Event $event, $event_url = '') | |
| 639 | +	{ | |
| 640 | +		if (post_password_required($event->ID())) { | |
| 641 | + return apply_filters( | |
| 642 | + 'FHEE_EEW_Upcoming_Events__widget__password_form', | |
| 643 | + get_the_password_form($event->ID()), | |
| 644 | + $event | |
| 645 | + ); | |
| 646 | + } | |
| 647 | + | |
| 648 | + $content = ''; | |
| 649 | +		if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') { | |
| 650 | + $content .= ' | |
| 651 | 651 | <div class="ee-upcoming-events-widget-img-dv"> | 
| 652 | 652 | <a class="ee-upcoming-events-widget-img" href="' . $event_url . '"> | 
| 653 | 653 | ' . get_the_post_thumbnail($event->ID(), $this->image_size) . ' | 
| 654 | 654 | </a> | 
| 655 | 655 | </div>'; | 
| 656 | - } | |
| 657 | - | |
| 658 | -        if ($this->show_dates) { | |
| 659 | - $content .= $this->eventDates($event); | |
| 660 | - } | |
| 661 | - | |
| 662 | -        if ($this->show_desc) { | |
| 663 | - global $allowedtags; | |
| 664 | - $desc = $event->short_description(25); | |
| 665 | - $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : ''; | |
| 666 | - } | |
| 667 | - | |
| 668 | - return $content; | |
| 669 | - } | |
| 670 | - | |
| 671 | - | |
| 672 | - /** | |
| 673 | - * @param EE_Event $event | |
| 674 | - * @return string | |
| 675 | - * @throws EE_Error | |
| 676 | - * @throws ReflectionException | |
| 677 | - * @since 4.10.14.p | |
| 678 | - */ | |
| 679 | - private function eventDates(EE_Event $event) | |
| 680 | -    { | |
| 681 | - $date_format = apply_filters( | |
| 682 | - 'FHEE__espresso_event_date_range__date_format', | |
| 683 | -            get_option('date_format') | |
| 684 | - ); | |
| 685 | - $time_format = apply_filters( | |
| 686 | - 'FHEE__espresso_event_date_range__time_format', | |
| 687 | -            get_option('time_format') | |
| 688 | - ); | |
| 689 | - $single_date_format = apply_filters( | |
| 690 | - 'FHEE__espresso_event_date_range__single_date_format', | |
| 691 | -            get_option('date_format') | |
| 692 | - ); | |
| 693 | - $single_time_format = apply_filters( | |
| 694 | - 'FHEE__espresso_event_date_range__single_time_format', | |
| 695 | -            get_option('time_format') | |
| 696 | - ); | |
| 697 | -        if ($this->date_range == true) { | |
| 698 | - return espresso_event_date_range( | |
| 699 | - $date_format, | |
| 700 | - $time_format, | |
| 701 | - $single_date_format, | |
| 702 | - $single_time_format, | |
| 703 | - $event->ID(), | |
| 704 | - false | |
| 705 | - ); | |
| 706 | - } | |
| 707 | - return espresso_list_of_event_dates( | |
| 708 | - $event->ID(), | |
| 709 | - $date_format, | |
| 710 | - $time_format, | |
| 711 | - false, | |
| 712 | - null, | |
| 713 | - true, | |
| 714 | - true, | |
| 715 | - $this->date_limit | |
| 716 | - ); | |
| 717 | - } | |
| 656 | + } | |
| 657 | + | |
| 658 | +		if ($this->show_dates) { | |
| 659 | + $content .= $this->eventDates($event); | |
| 660 | + } | |
| 661 | + | |
| 662 | +		if ($this->show_desc) { | |
| 663 | + global $allowedtags; | |
| 664 | + $desc = $event->short_description(25); | |
| 665 | + $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : ''; | |
| 666 | + } | |
| 667 | + | |
| 668 | + return $content; | |
| 669 | + } | |
| 670 | + | |
| 671 | + | |
| 672 | + /** | |
| 673 | + * @param EE_Event $event | |
| 674 | + * @return string | |
| 675 | + * @throws EE_Error | |
| 676 | + * @throws ReflectionException | |
| 677 | + * @since 4.10.14.p | |
| 678 | + */ | |
| 679 | + private function eventDates(EE_Event $event) | |
| 680 | +	{ | |
| 681 | + $date_format = apply_filters( | |
| 682 | + 'FHEE__espresso_event_date_range__date_format', | |
| 683 | +			get_option('date_format') | |
| 684 | + ); | |
| 685 | + $time_format = apply_filters( | |
| 686 | + 'FHEE__espresso_event_date_range__time_format', | |
| 687 | +			get_option('time_format') | |
| 688 | + ); | |
| 689 | + $single_date_format = apply_filters( | |
| 690 | + 'FHEE__espresso_event_date_range__single_date_format', | |
| 691 | +			get_option('date_format') | |
| 692 | + ); | |
| 693 | + $single_time_format = apply_filters( | |
| 694 | + 'FHEE__espresso_event_date_range__single_time_format', | |
| 695 | +			get_option('time_format') | |
| 696 | + ); | |
| 697 | +		if ($this->date_range == true) { | |
| 698 | + return espresso_event_date_range( | |
| 699 | + $date_format, | |
| 700 | + $time_format, | |
| 701 | + $single_date_format, | |
| 702 | + $single_time_format, | |
| 703 | + $event->ID(), | |
| 704 | + false | |
| 705 | + ); | |
| 706 | + } | |
| 707 | + return espresso_list_of_event_dates( | |
| 708 | + $event->ID(), | |
| 709 | + $date_format, | |
| 710 | + $time_format, | |
| 711 | + false, | |
| 712 | + null, | |
| 713 | + true, | |
| 714 | + true, | |
| 715 | + $this->date_limit | |
| 716 | + ); | |
| 717 | + } | |
| 718 | 718 | } | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 |              EE_Question_Option::new_instance(['QSO_value' => false, 'QSO_desc' => esc_html__('No', 'event_espresso')]), | 
| 110 | 110 |              EE_Question_Option::new_instance(['QSO_value' => true, 'QSO_desc' => esc_html__('Yes', 'event_espresso')]), | 
| 111 | 111 | ]; | 
| 112 | - $sort_values = [ | |
| 112 | + $sort_values = [ | |
| 113 | 113 |              EE_Question_Option::new_instance(['QSO_value' => 'ASC', 'QSO_desc' => esc_html__('ASC', 'event_espresso')]), | 
| 114 | 114 |              EE_Question_Option::new_instance(['QSO_value' => 'DESC', 'QSO_desc' => esc_html__('DESC', 'event_espresso')]), | 
| 115 | 115 | ]; | 
| @@ -326,8 +326,8 @@ discard block | ||
| 326 | 326 | // Before widget (defined by themes). | 
| 327 | 327 | echo $before_widget; | 
| 328 | 328 | // Display the widget title if one was input (before and after defined by themes). | 
| 329 | -                if (! empty($title)) { | |
| 330 | - echo $before_title . $title . $after_title; | |
| 329 | +                if ( ! empty($title)) { | |
| 330 | + echo $before_title.$title.$after_title; | |
| 331 | 331 | } | 
| 332 | 332 | echo $this->widgetContent($post); | 
| 333 | 333 | // After widget (defined by themes). | 
| @@ -346,7 +346,7 @@ discard block | ||
| 346 | 346 | */ | 
| 347 | 347 | public function make_the_title_a_link($title) | 
| 348 | 348 |      { | 
| 349 | - return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; | |
| 349 | + return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>'; | |
| 350 | 350 | } | 
| 351 | 351 | |
| 352 | 352 | |
| @@ -427,7 +427,7 @@ discard block | ||
| 427 | 427 |              foreach ($sizes as $image_size) { | 
| 428 | 428 | $image_size = trim($image_size); | 
| 429 | 429 | // no big images plz | 
| 430 | -                if (! in_array($image_size, ['large', 'post-thumbnail'])) { | |
| 430 | +                if ( ! in_array($image_size, ['large', 'post-thumbnail'])) { | |
| 431 | 431 | $image_sizes[] = | 
| 432 | 432 | EE_Question_Option::new_instance(['QSO_value' => $image_size, 'QSO_desc' => $image_size]); | 
| 433 | 433 | } | 
| @@ -454,7 +454,7 @@ discard block | ||
| 454 | 454 | private function parseWidgetSettings(array $instance) | 
| 455 | 455 |      { | 
| 456 | 456 | $this->title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : ''; | 
| 457 | - $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name']) | |
| 457 | + $this->events_category = isset($instance['category_name']) && ! empty($instance['category_name']) | |
| 458 | 458 | ? $instance['category_name'] | 
| 459 | 459 | : false; | 
| 460 | 460 | $this->show_expired = isset($instance['show_expired']) | 
| @@ -512,24 +512,24 @@ discard block | ||
| 512 | 512 | } | 
| 513 | 513 | $list_items = ''; | 
| 514 | 514 |          foreach ($events as $event) { | 
| 515 | -            if ($event instanceof EE_Event && (! is_single() || $post->ID != $event->ID())) { | |
| 515 | +            if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) { | |
| 516 | 516 | $event_url = $this->eventUrl($event); | 
| 517 | 517 | $list_items .= ' | 
| 518 | - <li id="ee-upcoming-events-widget-li-' . esc_attr($event->ID()) . '" | |
| 518 | + <li id="ee-upcoming-events-widget-li-' . esc_attr($event->ID()).'" | |
| 519 | 519 | class="ee-upcoming-events-widget-li" | 
| 520 | 520 | > | 
| 521 | 521 | <h5 class="ee-upcoming-events-widget-title-h5"> | 
| 522 | - <a class="ee-widget-event-name-a' . $this->linkClass($event) . '" href="' . $event_url . '"> | |
| 523 | - ' . esc_html($event->name()) . ' | |
| 522 | + <a class="ee-widget-event-name-a' . $this->linkClass($event).'" href="'.$event_url.'"> | |
| 523 | + ' . esc_html($event->name()).' | |
| 524 | 524 | </a> | 
| 525 | 525 | </h5> | 
| 526 | - ' . $this->eventWidgetContent($event, $event_url) . ' | |
| 526 | + ' . $this->eventWidgetContent($event, $event_url).' | |
| 527 | 527 | </li>'; | 
| 528 | 528 | } | 
| 529 | 529 | } | 
| 530 | 530 | return ' | 
| 531 | 531 | <ul class="ee-upcoming-events-widget-ul"> | 
| 532 | - ' . $list_items . ' | |
| 532 | + ' . $list_items.' | |
| 533 | 533 | </ul>'; | 
| 534 | 534 | } | 
| 535 | 535 | |
| @@ -561,7 +561,7 @@ discard block | ||
| 561 | 561 | return EEM_Event::instance()->get_all( | 
| 562 | 562 | [ | 
| 563 | 563 | $this->queryWhereParams(), | 
| 564 | - 'limit' => '0,' . $this->limit, | |
| 564 | + 'limit' => '0,'.$this->limit, | |
| 565 | 565 | 'order_by' => 'Datetime.DTT_EVT_start', | 
| 566 | 566 | 'order' => $this->order, | 
| 567 | 567 | 'group_by' => 'EVT_ID', | 
| @@ -649,8 +649,8 @@ discard block | ||
| 649 | 649 |          if (has_post_thumbnail($event->ID()) && $this->image_size != 'none') { | 
| 650 | 650 | $content .= ' | 
| 651 | 651 | <div class="ee-upcoming-events-widget-img-dv"> | 
| 652 | - <a class="ee-upcoming-events-widget-img" href="' . $event_url . '"> | |
| 653 | - ' . get_the_post_thumbnail($event->ID(), $this->image_size) . ' | |
| 652 | + <a class="ee-upcoming-events-widget-img" href="' . $event_url.'"> | |
| 653 | + ' . get_the_post_thumbnail($event->ID(), $this->image_size).' | |
| 654 | 654 | </a> | 
| 655 | 655 | </div>'; | 
| 656 | 656 | } | 
| @@ -661,8 +661,8 @@ discard block | ||
| 661 | 661 | |
| 662 | 662 |          if ($this->show_desc) { | 
| 663 | 663 | global $allowedtags; | 
| 664 | - $desc = $event->short_description(25); | |
| 665 | - $content .= $desc ? '<p style="margin-top: .5em">' . wp_kses($desc, $allowedtags) . '</p>' : ''; | |
| 664 | + $desc = $event->short_description(25); | |
| 665 | + $content .= $desc ? '<p style="margin-top: .5em">'.wp_kses($desc, $allowedtags).'</p>' : ''; | |
| 666 | 666 | } | 
| 667 | 667 | |
| 668 | 668 | return $content; | 
| @@ -678,11 +678,11 @@ discard block | ||
| 678 | 678 | */ | 
| 679 | 679 | private function eventDates(EE_Event $event) | 
| 680 | 680 |      { | 
| 681 | - $date_format = apply_filters( | |
| 681 | + $date_format = apply_filters( | |
| 682 | 682 | 'FHEE__espresso_event_date_range__date_format', | 
| 683 | 683 |              get_option('date_format') | 
| 684 | 684 | ); | 
| 685 | - $time_format = apply_filters( | |
| 685 | + $time_format = apply_filters( | |
| 686 | 686 | 'FHEE__espresso_event_date_range__time_format', | 
| 687 | 687 |              get_option('time_format') | 
| 688 | 688 | ); | 
| @@ -26,21 +26,21 @@ discard block | ||
| 26 | 26 | $has_answers = $question->has_answers(); | 
| 27 | 27 | |
| 28 | 28 |  if ($QST_system === 'country') { | 
| 29 | - // already escaped | |
| 30 | - echo EEH_HTML::div( | |
| 31 | - EEH_HTML::h4( | |
| 32 | - '<span class="dashicons dashicons-info"></span>' | |
| 33 | -            . esc_html__('Did you know...', 'event_espresso') | |
| 34 | - ) . | |
| 35 | - EEH_HTML::p( | |
| 36 | - esc_html__( | |
| 37 | - 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', | |
| 38 | - 'event_espresso' | |
| 39 | - ) | |
| 40 | - ), | |
| 41 | - '', | |
| 42 | - 'ee-info-box' | |
| 43 | - ); | |
| 29 | + // already escaped | |
| 30 | + echo EEH_HTML::div( | |
| 31 | + EEH_HTML::h4( | |
| 32 | + '<span class="dashicons dashicons-info"></span>' | |
| 33 | +			. esc_html__('Did you know...', 'event_espresso') | |
| 34 | + ) . | |
| 35 | + EEH_HTML::p( | |
| 36 | + esc_html__( | |
| 37 | + 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', | |
| 38 | + 'event_espresso' | |
| 39 | + ) | |
| 40 | + ), | |
| 41 | + '', | |
| 42 | + 'ee-info-box' | |
| 43 | + ); | |
| 44 | 44 | } | 
| 45 | 45 | ?> | 
| 46 | 46 | |
| @@ -76,9 +76,9 @@ discard block | ||
| 76 | 76 | </th> | 
| 77 | 77 | <td> | 
| 78 | 78 | <?php | 
| 79 | - $id = ! empty($QST_system) ? '_disabled' : ''; | |
| 80 | - $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; | |
| 81 | - ?> | |
| 79 | + $id = ! empty($QST_system) ? '_disabled' : ''; | |
| 80 | + $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; | |
| 81 | + ?> | |
| 82 | 82 | <input class='regular-text' | 
| 83 | 83 | id="QST_admin_label<?php echo $id; // escape not needed ?>" | 
| 84 | 84 | name="QST_admin_label<?php echo $id; // escape not needed ?>" | 
| @@ -120,30 +120,30 @@ discard block | ||
| 120 | 120 | </th> | 
| 121 | 121 | <td> | 
| 122 | 122 | <?php | 
| 123 | - $id = ! empty($QST_system) ? '_disabled' : ''; | |
| 124 | - $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; | |
| 125 | -                        $admin_only    = $question->get('QST_admin_only'); | |
| 126 | - $checked = ! empty($admin_only) ? ' checked="checked"' : ''; | |
| 127 | - ?> | |
| 123 | + $id = ! empty($QST_system) ? '_disabled' : ''; | |
| 124 | + $disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : ''; | |
| 125 | +						$admin_only    = $question->get('QST_admin_only'); | |
| 126 | + $checked = ! empty($admin_only) ? ' checked="checked"' : ''; | |
| 127 | + ?> | |
| 128 | 128 | <input class="QST_admin_only" | 
| 129 | 129 | id="QST_admin_only<?php echo $id; // escape not needed ?>" | 
| 130 | 130 | name="QST_admin_only<?php echo $id; // escape not needed ?>" | 
| 131 | 131 | type="checkbox" | 
| 132 | 132 | value="1" | 
| 133 | 133 | <?php | 
| 134 | - echo $disabled_attr; // escape not needed | |
| 135 | - echo $checked; // escape not needed | |
| 136 | - ?> | |
| 134 | + echo $disabled_attr; // escape not needed | |
| 135 | + echo $checked; // escape not needed | |
| 136 | + ?> | |
| 137 | 137 | /> | 
| 138 | 138 | <br /> | 
| 139 | 139 | <p class="description"> | 
| 140 | 140 | <?php | 
| 141 | -                            if (! empty($QST_system)) { ?> | |
| 141 | +							if (! empty($QST_system)) { ?> | |
| 142 | 142 | <span class="description" style="color:#D54E21;"> | 
| 143 | 143 | <?php esc_html_e( | 
| 144 | - 'System question! This field cannot be changed.', | |
| 145 | - 'event_espresso' | |
| 146 | - ); ?> | |
| 144 | + 'System question! This field cannot be changed.', | |
| 145 | + 'event_espresso' | |
| 146 | + ); ?> | |
| 147 | 147 | </span> | 
| 148 | 148 | <?php } ?> | 
| 149 | 149 | </p> | 
| @@ -159,44 +159,44 @@ discard block | ||
| 159 | 159 | </th> | 
| 160 | 160 | <td> | 
| 161 | 161 | <?php | 
| 162 | - $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone; | |
| 163 | -                        if ($disabled) { | |
| 164 | - $disabled_attr = 'disabled="disabled"'; | |
| 165 | - $id = '_disabled'; | |
| 166 | -                        } else { | |
| 167 | - $disabled_attr = ''; | |
| 168 | - $id = ''; | |
| 169 | - } | |
| 162 | + $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone; | |
| 163 | +						if ($disabled) { | |
| 164 | + $disabled_attr = 'disabled="disabled"'; | |
| 165 | + $id = '_disabled'; | |
| 166 | +						} else { | |
| 167 | + $disabled_attr = ''; | |
| 168 | + $id = ''; | |
| 169 | + } | |
| 170 | 170 | |
| 171 | - // Only display Confirm email for | |
| 172 | -                        if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) { | |
| 173 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); | |
| 174 | - } | |
| 171 | + // Only display Confirm email for | |
| 172 | +						if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) { | |
| 173 | + unset($question_types[ EEM_Question::QST_type_email_confirm ]); | |
| 174 | + } | |
| 175 | 175 | |
| 176 | - echo EEH_Form_Fields::select_input( | |
| 177 | - 'QST_type' . $id, | |
| 178 | - $question_types, | |
| 179 | - $question->type(), | |
| 180 | - 'id="QST_type' . $id . '"' . $disabled_attr | |
| 181 | - ); // already escaped | |
| 182 | -                        if ($disabled) { ?> | |
| 176 | + echo EEH_Form_Fields::select_input( | |
| 177 | + 'QST_type' . $id, | |
| 178 | + $question_types, | |
| 179 | + $question->type(), | |
| 180 | + 'id="QST_type' . $id . '"' . $disabled_attr | |
| 181 | + ); // already escaped | |
| 182 | +						if ($disabled) { ?> | |
| 183 | 183 | <input id='QST_type' | 
| 184 | 184 | name="QST_type" | 
| 185 | 185 | type="hidden" | 
| 186 | 186 | value="<?php echo $question->type(); ?>" | 
| 187 | 187 | /> | 
| 188 | 188 | <?php | 
| 189 | - $explanatory_text = esc_html__( | |
| 190 | - 'System question! This field cannot be changed.', | |
| 191 | - 'event_espresso' | |
| 192 | - ); | |
| 193 | -                        } else { | |
| 194 | - $explanatory_text = esc_html__( | |
| 195 | - 'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', | |
| 196 | - 'event_espresso' | |
| 197 | - ); | |
| 198 | - } | |
| 199 | -                        if ($disabled || $has_answers) { ?> | |
| 189 | + $explanatory_text = esc_html__( | |
| 190 | + 'System question! This field cannot be changed.', | |
| 191 | + 'event_espresso' | |
| 192 | + ); | |
| 193 | +						} else { | |
| 194 | + $explanatory_text = esc_html__( | |
| 195 | + 'Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', | |
| 196 | + 'event_espresso' | |
| 197 | + ); | |
| 198 | + } | |
| 199 | +						if ($disabled || $has_answers) { ?> | |
| 200 | 200 | <p> | 
| 201 | 201 | <span class="description" style="color:#D54E21;"> | 
| 202 | 202 | <?php echo esc_html($explanatory_text); ?> | 
| @@ -225,21 +225,21 @@ discard block | ||
| 225 | 225 | <p> | 
| 226 | 226 | <span class="description"> | 
| 227 | 227 | <?php esc_html_e( | 
| 228 | - 'Maximum number of characters allowed when answering this question', | |
| 229 | - 'event_espresso' | |
| 230 | - ); ?> | |
| 228 | + 'Maximum number of characters allowed when answering this question', | |
| 229 | + 'event_espresso' | |
| 230 | + ); ?> | |
| 231 | 231 | </span> | 
| 232 | 232 | </p> | 
| 233 | 233 |                          <?php if ($QST_system) { ?> | 
| 234 | 234 | <p> | 
| 235 | 235 | <span class="description" style="color:#D54E21;"> | 
| 236 | 236 | <?php printf( | 
| 237 | - esc_html__( | |
| 238 | - 'System question! The maximum number of characters that can be used for this question is %1$s', | |
| 239 | - 'event_espresso' | |
| 240 | - ), | |
| 241 | - $max_max | |
| 242 | - ); ?> | |
| 237 | + esc_html__( | |
| 238 | + 'System question! The maximum number of characters that can be used for this question is %1$s', | |
| 239 | + 'event_espresso' | |
| 240 | + ), | |
| 241 | + $max_max | |
| 242 | + ); ?> | |
| 243 | 243 | </span> | 
| 244 | 244 | </p> | 
| 245 | 245 | <?php } ?> | 
| @@ -261,9 +261,9 @@ discard block | ||
| 261 | 261 | </th> | 
| 262 | 262 | <th class="option-desc-header"> | 
| 263 | 263 | <?php esc_html_e( | 
| 264 | - 'Description (optional, only shown on registration form)', | |
| 265 | - 'event_espresso' | |
| 266 | - ) ?> | |
| 264 | + 'Description (optional, only shown on registration form)', | |
| 265 | + 'event_espresso' | |
| 266 | + ) ?> | |
| 267 | 267 | </th> | 
| 268 | 268 | <th> | 
| 269 | 269 | </th> | 
| @@ -298,14 +298,14 @@ discard block | ||
| 298 | 298 | </tr> | 
| 299 | 299 | |
| 300 | 300 | <?php | 
| 301 | - $count = 0; | |
| 302 | - $question_options = $question->options(); | |
| 303 | -                                if (! empty($question_options)) { | |
| 304 | -                                    foreach ($question_options as $option_id => $option) { | |
| 305 | -                                        $disabled_attr = $has_answers || $option->get('QSO_system') | |
| 306 | - ? ' disabled="disabled"' | |
| 307 | - : ''; | |
| 308 | - ?> | |
| 301 | + $count = 0; | |
| 302 | + $question_options = $question->options(); | |
| 303 | +								if (! empty($question_options)) { | |
| 304 | +									foreach ($question_options as $option_id => $option) { | |
| 305 | +										$disabled_attr = $has_answers || $option->get('QSO_system') | |
| 306 | + ? ' disabled="disabled"' | |
| 307 | + : ''; | |
| 308 | + ?> | |
| 309 | 309 | <tr class="question-option ee-options-sortable"> | 
| 310 | 310 | <td class="option-value-cell"> | 
| 311 | 311 | <input type="hidden" | 
| @@ -342,21 +342,21 @@ discard block | ||
| 342 | 342 | </span> | 
| 343 | 343 | </td> | 
| 344 | 344 | <?php | 
| 345 | - echo EEH_Form_Fields::hidden_input( | |
| 346 | -                                                "question_options[{$count}][QST_ID])", | |
| 347 | - $option->question_ID() | |
| 348 | - ); // already escaped | |
| 349 | - echo EEH_Form_Fields::hidden_input( | |
| 350 | -                                                "question_options[{$count}][QSO_ID])", | |
| 351 | - $option->ID() | |
| 352 | - ); // already escaped | |
| 353 | - $count++; | |
| 354 | - ?> | |
| 345 | + echo EEH_Form_Fields::hidden_input( | |
| 346 | +												"question_options[{$count}][QST_ID])", | |
| 347 | + $option->question_ID() | |
| 348 | + ); // already escaped | |
| 349 | + echo EEH_Form_Fields::hidden_input( | |
| 350 | +												"question_options[{$count}][QSO_ID])", | |
| 351 | + $option->ID() | |
| 352 | + ); // already escaped | |
| 353 | + $count++; | |
| 354 | + ?> | |
| 355 | 355 | </tr> | 
| 356 | 356 | <?php | 
| 357 | - } | |
| 358 | -                                } else { | |
| 359 | - ?> | |
| 357 | + } | |
| 358 | +								} else { | |
| 359 | + ?> | |
| 360 | 360 | <tr class="question-option ee-options-sortable"> | 
| 361 | 361 | <td class="option-value-cell"> | 
| 362 | 362 | <input type="hidden" | 
| @@ -380,8 +380,8 @@ discard block | ||
| 380 | 380 | </td> | 
| 381 | 381 | </tr> | 
| 382 | 382 | <?php | 
| 383 | - } | |
| 384 | - ?> | |
| 383 | + } | |
| 384 | + ?> | |
| 385 | 385 | <tr style="display:none"> | 
| 386 | 386 | <td colspan="3"> | 
| 387 | 387 |                                          <?php echo EEH_Form_Fields::hidden_input("question_options_count", $count); // already escaped ?> | 
| @@ -400,16 +400,16 @@ discard block | ||
| 400 | 400 | |
| 401 | 401 | <p class="description"> | 
| 402 | 402 | <?php esc_html_e( | 
| 403 | - 'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', | |
| 404 | - 'event_espresso' | |
| 405 | - ) ?> | |
| 403 | + 'Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', | |
| 404 | + 'event_espresso' | |
| 405 | + ) ?> | |
| 406 | 406 | </p> | 
| 407 | 407 | <?php if ($has_answers) : ?> | 
| 408 | 408 | <p class="description" style="color:#D54E21;"> | 
| 409 | 409 | <?php esc_html_e( | 
| 410 | - 'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', | |
| 411 | - 'event_espresso' | |
| 412 | - ); ?> | |
| 410 | + 'Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', | |
| 411 | + 'event_espresso' | |
| 412 | + ); ?> | |
| 413 | 413 | </p> | 
| 414 | 414 | |
| 415 | 415 | <?php endif; ?> | 
| @@ -425,40 +425,40 @@ discard block | ||
| 425 | 425 | </th> | 
| 426 | 426 | <td> | 
| 427 | 427 | <?php | 
| 428 | - $system_required = ['fname', 'email']; | |
| 429 | - $disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; | |
| 430 | -                        $required_on       = $question->get('QST_admin_only'); | |
| 431 | - $show_required_msg = $required_on ? '' : ' display:none;'; | |
| 432 | - $disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : ''; | |
| 433 | - $id = | |
| 434 | - ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : ''; | |
| 435 | - $requiredOptions = [ | |
| 436 | -                            ['text' => esc_html__('Optional', 'event_espresso'), 'id' => 0], | |
| 437 | -                            ['text' => esc_html__('Required', 'event_espresso'), 'id' => 1], | |
| 438 | - ]; | |
| 439 | - echo EEH_Form_Fields::select_input( | |
| 440 | - 'QST_required' . $id, | |
| 441 | - $requiredOptions, | |
| 442 | - $question->required(), | |
| 443 | - 'id="QST_required' . $id . '"' . $disabled_attr | |
| 444 | - ); // already escaped | |
| 445 | - ?> | |
| 428 | + $system_required = ['fname', 'email']; | |
| 429 | + $disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; | |
| 430 | +						$required_on       = $question->get('QST_admin_only'); | |
| 431 | + $show_required_msg = $required_on ? '' : ' display:none;'; | |
| 432 | + $disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : ''; | |
| 433 | + $id = | |
| 434 | + ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : ''; | |
| 435 | + $requiredOptions = [ | |
| 436 | +							['text' => esc_html__('Optional', 'event_espresso'), 'id' => 0], | |
| 437 | +							['text' => esc_html__('Required', 'event_espresso'), 'id' => 1], | |
| 438 | + ]; | |
| 439 | + echo EEH_Form_Fields::select_input( | |
| 440 | + 'QST_required' . $id, | |
| 441 | + $requiredOptions, | |
| 442 | + $question->required(), | |
| 443 | + 'id="QST_required' . $id . '"' . $disabled_attr | |
| 444 | + ); // already escaped | |
| 445 | + ?> | |
| 446 | 446 | <p> | 
| 447 | 447 | <span id="required_toggled_on" class="description" | 
| 448 | 448 | style="color:#D54E21;<?php echo $show_required_msg; ?>" | 
| 449 | 449 | > | 
| 450 | 450 | <?php esc_html_e( | 
| 451 | - 'Required is set to optional, and this field is disabled, because the question is Admin-Only.', | |
| 452 | - 'event_espresso' | |
| 453 | - ) ?> | |
| 451 | + 'Required is set to optional, and this field is disabled, because the question is Admin-Only.', | |
| 452 | + 'event_espresso' | |
| 453 | + ) ?> | |
| 454 | 454 | </span | 
| 455 | 455 | </p> | 
| 456 | 456 | <p> | 
| 457 | 457 | <span id="required_toggled_off" class="description" style="color:#D54E21; display: none;"> | 
| 458 | 458 | <?php esc_html_e( | 
| 459 | - 'Required option field is no longer disabled because the question is not Admin-Only', | |
| 460 | - 'event_espresso' | |
| 461 | - ) ?> | |
| 459 | + 'Required option field is no longer disabled because the question is not Admin-Only', | |
| 460 | + 'event_espresso' | |
| 461 | + ) ?> | |
| 462 | 462 | </span> | 
| 463 | 463 | </p> | 
| 464 | 464 |                          <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> | 
| @@ -491,8 +491,8 @@ discard block | ||
| 491 | 491 | </td> | 
| 492 | 492 | </tr> | 
| 493 | 493 | <?php | 
| 494 | -                do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question); | |
| 495 | - ?> | |
| 494 | +				do_action('AHEE__questions_main_meta_box__template__after_table_form_table', $question); | |
| 495 | + ?> | |
| 496 | 496 | </tbody> | 
| 497 | 497 | </table> | 
| 498 | 498 | |
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | EEH_HTML::h4( | 
| 32 | 32 | '<span class="dashicons dashicons-info"></span>' | 
| 33 | 33 |              . esc_html__('Did you know...', 'event_espresso') | 
| 34 | - ) . | |
| 34 | + ). | |
| 35 | 35 | EEH_HTML::p( | 
| 36 | 36 | esc_html__( | 
| 37 | 37 | 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', | 
| @@ -92,7 +92,7 @@ discard block | ||
| 92 | 92 | type="hidden" | 
| 93 | 93 |                                 value="<?php echo $question->get('QST_order'); ?>" | 
| 94 | 94 | /> | 
| 95 | -                        <?php if (! empty($QST_system)) { ?> | |
| 95 | +                        <?php if ( ! empty($QST_system)) { ?> | |
| 96 | 96 | <input id='QST_admin_label' | 
| 97 | 97 | name="QST_admin_label" | 
| 98 | 98 | type="hidden" | 
| @@ -101,7 +101,7 @@ discard block | ||
| 101 | 101 | <?php } ?> | 
| 102 | 102 | <br /> | 
| 103 | 103 | <p class="description"> | 
| 104 | -                            <?php if (! empty($QST_system)) { ?> | |
| 104 | +                            <?php if ( ! empty($QST_system)) { ?> | |
| 105 | 105 | <span class="description" style="color:#D54E21;"> | 
| 106 | 106 |                                  <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso') ?> | 
| 107 | 107 | </span> | 
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | <br /> | 
| 139 | 139 | <p class="description"> | 
| 140 | 140 | <?php | 
| 141 | -                            if (! empty($QST_system)) { ?> | |
| 141 | +                            if ( ! empty($QST_system)) { ?> | |
| 142 | 142 | <span class="description" style="color:#D54E21;"> | 
| 143 | 143 | <?php esc_html_e( | 
| 144 | 144 | 'System question! This field cannot be changed.', | 
| @@ -170,14 +170,14 @@ discard block | ||
| 170 | 170 | |
| 171 | 171 | // Only display Confirm email for | 
| 172 | 172 |                          if (empty($QST_system) || $QST_system !== EEM_Attendee::system_question_email_confirm) { | 
| 173 | - unset($question_types[ EEM_Question::QST_type_email_confirm ]); | |
| 173 | + unset($question_types[EEM_Question::QST_type_email_confirm]); | |
| 174 | 174 | } | 
| 175 | 175 | |
| 176 | 176 | echo EEH_Form_Fields::select_input( | 
| 177 | - 'QST_type' . $id, | |
| 177 | + 'QST_type'.$id, | |
| 178 | 178 | $question_types, | 
| 179 | 179 | $question->type(), | 
| 180 | - 'id="QST_type' . $id . '"' . $disabled_attr | |
| 180 | + 'id="QST_type'.$id.'"'.$disabled_attr | |
| 181 | 181 | ); // already escaped | 
| 182 | 182 |                          if ($disabled) { ?> | 
| 183 | 183 | <input id='QST_type' | 
| @@ -216,7 +216,7 @@ discard block | ||
| 216 | 216 | </th> | 
| 217 | 217 | <td> | 
| 218 | 218 | <input id="QST_max" | 
| 219 | - <?php echo $max_max === EE_INF ? '' : 'max="' . esc_attr($max_max) . '"'; ?> | |
| 219 | + <?php echo $max_max === EE_INF ? '' : 'max="'.esc_attr($max_max).'"'; ?> | |
| 220 | 220 | min="1" | 
| 221 | 221 | name="QST_max" | 
| 222 | 222 | type="number" | 
| @@ -300,7 +300,7 @@ discard block | ||
| 300 | 300 | <?php | 
| 301 | 301 | $count = 0; | 
| 302 | 302 | $question_options = $question->options(); | 
| 303 | -                                if (! empty($question_options)) { | |
| 303 | +                                if ( ! empty($question_options)) { | |
| 304 | 304 |                                      foreach ($question_options as $option_id => $option) { | 
| 305 | 305 |                                          $disabled_attr = $has_answers || $option->get('QSO_system') | 
| 306 | 306 | ? ' disabled="disabled"' | 
| @@ -334,7 +334,7 @@ discard block | ||
| 334 | 334 | /> | 
| 335 | 335 | </td> | 
| 336 | 336 | <td> | 
| 337 | -                                                <?php if (! $option->system()) { ?> | |
| 337 | +                                                <?php if ( ! $option->system()) { ?> | |
| 338 | 338 | <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"> | 
| 339 | 339 | </span> | 
| 340 | 340 | <?php } ?> | 
| @@ -437,10 +437,10 @@ discard block | ||
| 437 | 437 |                              ['text' => esc_html__('Required', 'event_espresso'), 'id' => 1], | 
| 438 | 438 | ]; | 
| 439 | 439 | echo EEH_Form_Fields::select_input( | 
| 440 | - 'QST_required' . $id, | |
| 440 | + 'QST_required'.$id, | |
| 441 | 441 | $requiredOptions, | 
| 442 | 442 | $question->required(), | 
| 443 | - 'id="QST_required' . $id . '"' . $disabled_attr | |
| 443 | + 'id="QST_required'.$id.'"'.$disabled_attr | |
| 444 | 444 | ); // already escaped | 
| 445 | 445 | ?> | 
| 446 | 446 | <p> | 
| @@ -461,7 +461,7 @@ discard block | ||
| 461 | 461 | ) ?> | 
| 462 | 462 | </span> | 
| 463 | 463 | </p> | 
| 464 | -                        <?php if (! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> | |
| 464 | +                        <?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?> | |
| 465 | 465 | <input type="hidden" id="QST_required" name="QST_required" value="1" /> | 
| 466 | 466 | <p> | 
| 467 | 467 | <span class="description" style="color:#D54E21;"> |