@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | public static function instance() |
| 146 | 146 | { |
| 147 | 147 | // check if class object is instantiated, and instantiated properly |
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 148 | + if ( ! self::$_instance instanceof EE_Config) { |
|
| 149 | 149 | self::$_instance = new self(); |
| 150 | 150 | } |
| 151 | 151 | return self::$_instance; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | $this |
| 284 | 284 | ); |
| 285 | 285 | if (is_object($settings) && property_exists($this, $config)) { |
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings); |
|
| 287 | 287 | // call configs populate method to ensure any defaults are set for empty values. |
| 288 | 288 | if (method_exists($settings, 'populate')) { |
| 289 | 289 | $this->{$config}->populate(); |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | break; |
| 557 | 557 | // TEST #2 : check that settings section exists |
| 558 | 558 | case 2: |
| 559 | - if (! isset($this->{$section})) { |
|
| 559 | + if ( ! isset($this->{$section})) { |
|
| 560 | 560 | if ($display_errors) { |
| 561 | 561 | throw new EE_Error( |
| 562 | 562 | sprintf( |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | break; |
| 571 | 571 | // TEST #3 : check that section is the proper format |
| 572 | 572 | case 3: |
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 573 | + if ( ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | 574 | ) { |
| 575 | 575 | if ($display_errors) { |
| 576 | 576 | throw new EE_Error( |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | break; |
| 617 | 617 | // TEST #6 : verify config class is accessible |
| 618 | 618 | case 6: |
| 619 | - if (! class_exists($config_class)) { |
|
| 619 | + if ( ! class_exists($config_class)) { |
|
| 620 | 620 | if ($display_errors) { |
| 621 | 621 | throw new EE_Error( |
| 622 | 622 | sprintf( |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | break; |
| 634 | 634 | // TEST #7 : check that config has even been set |
| 635 | 635 | case 7: |
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 636 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 637 | 637 | if ($display_errors) { |
| 638 | 638 | throw new EE_Error( |
| 639 | 639 | sprintf( |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | break; |
| 652 | 652 | // TEST #8 : check that config is the requested type |
| 653 | 653 | case 8: |
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 654 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | 655 | if ($display_errors) { |
| 656 | 656 | throw new EE_Error( |
| 657 | 657 | sprintf( |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | break; |
| 671 | 671 | // TEST #9 : verify config object |
| 672 | 672 | case 9: |
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 673 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 674 | 674 | if ($display_errors) { |
| 675 | 675 | throw new EE_Error( |
| 676 | 676 | sprintf( |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | private function _generate_config_option_name($section = '', $name = '') |
| 704 | 704 | { |
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 705 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | { |
| 720 | 720 | return ! empty($config_class) |
| 721 | 721 | ? $config_class |
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | |
@@ -738,17 +738,17 @@ discard block |
||
| 738 | 738 | // ensure config class is set to something |
| 739 | 739 | $config_class = $this->_set_config_class($config_class, $name); |
| 740 | 740 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 741 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | 742 | return null; |
| 743 | 743 | } |
| 744 | 744 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 745 | 745 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 746 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 747 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 748 | 748 | $this->update_addon_option_names(); |
| 749 | 749 | } |
| 750 | 750 | // verify the incoming config object but suppress errors |
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 751 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | 752 | $config_obj = new $config_class(); |
| 753 | 753 | } |
| 754 | 754 | if (get_option($config_option_name)) { |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | // get class name of the incoming object |
| 796 | 796 | $config_class = get_class($config_obj); |
| 797 | 797 | // run tests 1-5 and 9 to verify config |
| 798 | - if (! $this->_verify_config_params( |
|
| 798 | + if ( ! $this->_verify_config_params( |
|
| 799 | 799 | $section, |
| 800 | 800 | $name, |
| 801 | 801 | $config_class, |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | } |
| 808 | 808 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 809 | 809 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 810 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 811 | 811 | // save new config to db |
| 812 | 812 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 813 | 813 | return true; |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | 'event_espresso' |
| 834 | 834 | ), |
| 835 | 835 | $config_class, |
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 836 | + 'EE_Config->'.$section.'->'.$name |
|
| 837 | 837 | ), |
| 838 | 838 | __FILE__, |
| 839 | 839 | __FUNCTION__, |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | // ensure config class is set to something |
| 860 | 860 | $config_class = $this->_set_config_class($config_class, $name); |
| 861 | 861 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 862 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | 863 | return null; |
| 864 | 864 | } |
| 865 | 865 | // now test if the requested config object exists, but suppress errors |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | // retrieve the wp-option for this config class. |
| 905 | 905 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 906 | 906 | if (empty($config_option)) { |
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 907 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 908 | 908 | } |
| 909 | 909 | return $config_option; |
| 910 | 910 | } |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | // copy incoming $_REQUEST and sanitize it so we can save it |
| 923 | 923 | $_request = $_REQUEST; |
| 924 | 924 | array_walk_recursive($_request, 'sanitize_text_field'); |
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 925 | + $config_log[(string) microtime(true)] = array( |
|
| 926 | 926 | 'config_name' => $config_option_name, |
| 927 | 927 | 'request' => $_request, |
| 928 | 928 | ); |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | */ |
| 938 | 938 | public static function trim_log() |
| 939 | 939 | { |
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 940 | + if ( ! EE_Config::logging_enabled()) { |
|
| 941 | 941 | return; |
| 942 | 942 | } |
| 943 | 943 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | public static function get_page_for_posts() |
| 962 | 962 | { |
| 963 | 963 | $page_for_posts = get_option('page_for_posts'); |
| 964 | - if (! $page_for_posts) { |
|
| 964 | + if ( ! $page_for_posts) { |
|
| 965 | 965 | return 'posts'; |
| 966 | 966 | } |
| 967 | 967 | /** @type WPDB $wpdb */ |
@@ -1011,20 +1011,20 @@ discard block |
||
| 1011 | 1011 | { |
| 1012 | 1012 | // only init widgets on admin pages when not in complete maintenance, and |
| 1013 | 1013 | // on frontend when not in any maintenance mode |
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1014 | + if ( ! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | 1015 | || ( |
| 1016 | 1016 | is_admin() |
| 1017 | 1017 | && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
| 1018 | 1018 | ) |
| 1019 | 1019 | ) { |
| 1020 | 1020 | // grab list of installed widgets |
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 1022 | 1022 | // filter list of modules to register |
| 1023 | 1023 | $widgets_to_register = apply_filters( |
| 1024 | 1024 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1025 | 1025 | $widgets_to_register |
| 1026 | 1026 | ); |
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1027 | + if ( ! empty($widgets_to_register)) { |
|
| 1028 | 1028 | // cycle thru widget folders |
| 1029 | 1029 | foreach ($widgets_to_register as $widget_path) { |
| 1030 | 1030 | // add to list of installed widget modules |
@@ -1074,31 +1074,31 @@ discard block |
||
| 1074 | 1074 | // create classname from widget directory name |
| 1075 | 1075 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1076 | 1076 | // add class prefix |
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1077 | + $widget_class = 'EEW_'.$widget; |
|
| 1078 | 1078 | // does the widget exist ? |
| 1079 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1079 | + if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) { |
|
| 1080 | 1080 | $msg = sprintf( |
| 1081 | 1081 | __( |
| 1082 | 1082 | 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
| 1083 | 1083 | 'event_espresso' |
| 1084 | 1084 | ), |
| 1085 | 1085 | $widget_class, |
| 1086 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1086 | + $widget_path.DS.$widget_class.$widget_ext |
|
| 1087 | 1087 | ); |
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1088 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | 1089 | return; |
| 1090 | 1090 | } |
| 1091 | 1091 | // load the widget class file |
| 1092 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1092 | + require_once($widget_path.DS.$widget_class.$widget_ext); |
|
| 1093 | 1093 | // verify that class exists |
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1094 | + if ( ! class_exists($widget_class)) { |
|
| 1095 | 1095 | $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1096 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | 1097 | return; |
| 1098 | 1098 | } |
| 1099 | 1099 | register_widget($widget_class); |
| 1100 | 1100 | // add to array of registered widgets |
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext; |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1111,18 +1111,18 @@ discard block |
||
| 1111 | 1111 | private function _register_modules() |
| 1112 | 1112 | { |
| 1113 | 1113 | // grab list of installed modules |
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1114 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1115 | 1115 | // filter list of modules to register |
| 1116 | 1116 | $modules_to_register = apply_filters( |
| 1117 | 1117 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1118 | 1118 | $modules_to_register |
| 1119 | 1119 | ); |
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1120 | + if ( ! empty($modules_to_register)) { |
|
| 1121 | 1121 | // loop through folders |
| 1122 | 1122 | foreach ($modules_to_register as $module_path) { |
| 1123 | 1123 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1124 | + if ($module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1126 | 1126 | ) { |
| 1127 | 1127 | // add to list of installed modules |
| 1128 | 1128 | EE_Config::register_module($module_path); |
@@ -1159,25 +1159,25 @@ discard block |
||
| 1159 | 1159 | // remove last segment |
| 1160 | 1160 | array_pop($module_path); |
| 1161 | 1161 | // glue it back together |
| 1162 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1162 | + $module_path = implode(DS, $module_path).DS; |
|
| 1163 | 1163 | // take first segment from file name pieces and sanitize it |
| 1164 | 1164 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1165 | 1165 | // ensure class prefix is added |
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1167 | 1167 | } else { |
| 1168 | 1168 | // we need to generate the filename based off of the folder name |
| 1169 | 1169 | // grab and sanitize module name |
| 1170 | 1170 | $module = strtolower(basename($module_path)); |
| 1171 | 1171 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1172 | 1172 | // like trailingslashit() |
| 1173 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1173 | + $module_path = rtrim($module_path, DS).DS; |
|
| 1174 | 1174 | // create classname from module directory name |
| 1175 | 1175 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1176 | 1176 | // add class prefix |
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1177 | + $module_class = 'EED_'.$module; |
|
| 1178 | 1178 | } |
| 1179 | 1179 | // does the module exist ? |
| 1180 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1180 | + if ( ! is_readable($module_path.DS.$module_class.$module_ext)) { |
|
| 1181 | 1181 | $msg = sprintf( |
| 1182 | 1182 | __( |
| 1183 | 1183 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1185,19 +1185,19 @@ discard block |
||
| 1185 | 1185 | ), |
| 1186 | 1186 | $module |
| 1187 | 1187 | ); |
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1188 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | 1189 | return false; |
| 1190 | 1190 | } |
| 1191 | 1191 | // load the module class file |
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1192 | + require_once($module_path.$module_class.$module_ext); |
|
| 1193 | 1193 | // verify that class exists |
| 1194 | - if (! class_exists($module_class)) { |
|
| 1194 | + if ( ! class_exists($module_class)) { |
|
| 1195 | 1195 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1196 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | 1197 | return false; |
| 1198 | 1198 | } |
| 1199 | 1199 | // add to array of registered modules |
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1201 | 1201 | do_action( |
| 1202 | 1202 | 'AHEE__EE_Config__register_module__complete', |
| 1203 | 1203 | $module_class, |
@@ -1248,26 +1248,26 @@ discard block |
||
| 1248 | 1248 | { |
| 1249 | 1249 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1250 | 1250 | $module = str_replace('EED_', '', $module); |
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1251 | + $module_class = 'EED_'.$module; |
|
| 1252 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | 1253 | $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1254 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | 1255 | return false; |
| 1256 | 1256 | } |
| 1257 | 1257 | if (empty($route)) { |
| 1258 | 1258 | $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | 1260 | return false; |
| 1261 | 1261 | } |
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1262 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1263 | 1263 | $msg = sprintf( |
| 1264 | 1264 | __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1265 | 1265 | $route |
| 1266 | 1266 | ); |
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1267 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | 1268 | return false; |
| 1269 | 1269 | } |
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1270 | + EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name); |
|
| 1271 | 1271 | return true; |
| 1272 | 1272 | } |
| 1273 | 1273 | |
@@ -1284,8 +1284,8 @@ discard block |
||
| 1284 | 1284 | { |
| 1285 | 1285 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1286 | 1286 | $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1288 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1289 | 1289 | } |
| 1290 | 1290 | return null; |
| 1291 | 1291 | } |
@@ -1317,47 +1317,47 @@ discard block |
||
| 1317 | 1317 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1318 | 1318 | { |
| 1319 | 1319 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1320 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1321 | 1321 | $msg = sprintf( |
| 1322 | 1322 | __('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1323 | 1323 | $route |
| 1324 | 1324 | ); |
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | 1326 | return false; |
| 1327 | 1327 | } |
| 1328 | 1328 | if (empty($forward)) { |
| 1329 | 1329 | $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | 1331 | return false; |
| 1332 | 1332 | } |
| 1333 | 1333 | if (is_array($forward)) { |
| 1334 | - if (! isset($forward[1])) { |
|
| 1334 | + if ( ! isset($forward[1])) { |
|
| 1335 | 1335 | $msg = sprintf( |
| 1336 | 1336 | __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1337 | 1337 | $route |
| 1338 | 1338 | ); |
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1339 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | 1340 | return false; |
| 1341 | 1341 | } |
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1342 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1343 | 1343 | $msg = sprintf( |
| 1344 | 1344 | __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1345 | 1345 | $forward[1], |
| 1346 | 1346 | $route |
| 1347 | 1347 | ); |
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1348 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | 1349 | return false; |
| 1350 | 1350 | } |
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1351 | + } elseif ( ! function_exists($forward)) { |
|
| 1352 | 1352 | $msg = sprintf( |
| 1353 | 1353 | __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1354 | 1354 | $forward, |
| 1355 | 1355 | $route |
| 1356 | 1356 | ); |
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1357 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | 1358 | return false; |
| 1359 | 1359 | } |
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1360 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1361 | 1361 | return true; |
| 1362 | 1362 | } |
| 1363 | 1363 | |
@@ -1375,10 +1375,10 @@ discard block |
||
| 1375 | 1375 | public static function get_forward($route = null, $status = 0, $key = 'ee') |
| 1376 | 1376 | { |
| 1377 | 1377 | do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1379 | 1379 | return apply_filters( |
| 1380 | 1380 | 'FHEE__EE_Config__get_forward', |
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1381 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1382 | 1382 | $route, |
| 1383 | 1383 | $status |
| 1384 | 1384 | ); |
@@ -1402,15 +1402,15 @@ discard block |
||
| 1402 | 1402 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1403 | 1403 | { |
| 1404 | 1404 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1405 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1406 | 1406 | $msg = sprintf( |
| 1407 | 1407 | __('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1408 | 1408 | $route |
| 1409 | 1409 | ); |
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1410 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | 1411 | return false; |
| 1412 | 1412 | } |
| 1413 | - if (! is_readable($view)) { |
|
| 1413 | + if ( ! is_readable($view)) { |
|
| 1414 | 1414 | $msg = sprintf( |
| 1415 | 1415 | __( |
| 1416 | 1416 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1418,10 +1418,10 @@ discard block |
||
| 1418 | 1418 | ), |
| 1419 | 1419 | $view |
| 1420 | 1420 | ); |
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1421 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | 1422 | return false; |
| 1423 | 1423 | } |
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1424 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1425 | 1425 | return true; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
@@ -1439,10 +1439,10 @@ discard block |
||
| 1439 | 1439 | public static function get_view($route = null, $status = 0, $key = 'ee') |
| 1440 | 1440 | { |
| 1441 | 1441 | do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1443 | 1443 | return apply_filters( |
| 1444 | 1444 | 'FHEE__EE_Config__get_view', |
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1445 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1446 | 1446 | $route, |
| 1447 | 1447 | $status |
| 1448 | 1448 | ); |
@@ -1469,7 +1469,7 @@ discard block |
||
| 1469 | 1469 | public static function getLegacyShortcodesManager() |
| 1470 | 1470 | { |
| 1471 | 1471 | |
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1472 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | 1473 | EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
| 1474 | 1474 | EE_Registry::instance() |
| 1475 | 1475 | ); |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | */ |
| 1517 | 1517 | public function get_pretty($property) |
| 1518 | 1518 | { |
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1519 | + if ( ! property_exists($this, $property)) { |
|
| 1520 | 1520 | throw new EE_Error( |
| 1521 | 1521 | sprintf( |
| 1522 | 1522 | __( |
@@ -1745,11 +1745,11 @@ discard block |
||
| 1745 | 1745 | */ |
| 1746 | 1746 | public function reg_page_url() |
| 1747 | 1747 | { |
| 1748 | - if (! $this->reg_page_url) { |
|
| 1748 | + if ( ! $this->reg_page_url) { |
|
| 1749 | 1749 | $this->reg_page_url = add_query_arg( |
| 1750 | 1750 | array('uts' => time()), |
| 1751 | 1751 | get_permalink($this->reg_page_id) |
| 1752 | - ) . '#checkout'; |
|
| 1752 | + ).'#checkout'; |
|
| 1753 | 1753 | } |
| 1754 | 1754 | return $this->reg_page_url; |
| 1755 | 1755 | } |
@@ -1765,7 +1765,7 @@ discard block |
||
| 1765 | 1765 | */ |
| 1766 | 1766 | public function txn_page_url($query_args = array()) |
| 1767 | 1767 | { |
| 1768 | - if (! $this->txn_page_url) { |
|
| 1768 | + if ( ! $this->txn_page_url) { |
|
| 1769 | 1769 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1770 | 1770 | } |
| 1771 | 1771 | if ($query_args) { |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | */ |
| 1787 | 1787 | public function thank_you_page_url($query_args = array()) |
| 1788 | 1788 | { |
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1789 | + if ( ! $this->thank_you_page_url) { |
|
| 1790 | 1790 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1791 | 1791 | } |
| 1792 | 1792 | if ($query_args) { |
@@ -1805,7 +1805,7 @@ discard block |
||
| 1805 | 1805 | */ |
| 1806 | 1806 | public function cancel_page_url() |
| 1807 | 1807 | { |
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1808 | + if ( ! $this->cancel_page_url) { |
|
| 1809 | 1809 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1810 | 1810 | } |
| 1811 | 1811 | return $this->cancel_page_url; |
@@ -1848,13 +1848,13 @@ discard block |
||
| 1848 | 1848 | $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
| 1849 | 1849 | $option = self::OPTION_NAME_UXIP; |
| 1850 | 1850 | // set correct table for query |
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1852 | 1852 | // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
| 1853 | 1853 | // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
| 1854 | 1854 | // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1855 | 1855 | // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1856 | 1856 | // for the purpose of caching. |
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1857 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1858 | 1858 | if (false !== $pre) { |
| 1859 | 1859 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1860 | 1860 | return EE_Core_Config::$ee_ueip_option; |
@@ -1868,10 +1868,10 @@ discard block |
||
| 1868 | 1868 | if (is_object($row)) { |
| 1869 | 1869 | $value = $row->option_value; |
| 1870 | 1870 | } else { // option does not exist so use default. |
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option); |
|
| 1872 | 1872 | return EE_Core_Config::$ee_ueip_option; |
| 1873 | 1873 | } |
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1875 | 1875 | return EE_Core_Config::$ee_ueip_option; |
| 1876 | 1876 | } |
| 1877 | 1877 | |
@@ -2140,37 +2140,37 @@ discard block |
||
| 2140 | 2140 | // but override if requested |
| 2141 | 2141 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
| 2142 | 2142 | // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
| 2143 | - if (! empty($CNT_ISO) |
|
| 2143 | + if ( ! empty($CNT_ISO) |
|
| 2144 | 2144 | && EE_Maintenance_Mode::instance()->models_can_query() |
| 2145 | 2145 | && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
| 2146 | 2146 | ) { |
| 2147 | 2147 | // retrieve the country settings from the db, just in case they have been customized |
| 2148 | 2148 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2149 | 2149 | if ($country instanceof EE_Country) { |
| 2150 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2151 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2152 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2153 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2150 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2151 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2152 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2153 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2154 | 2154 | $this->sign_b4 = $country->currency_sign_before( |
| 2155 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2155 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | 2157 | $this->dec_mrk = $country->currency_decimal_mark( |
| 2158 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2159 | 2159 | $this->thsnds = $country->currency_thousands_separator( |
| 2160 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2160 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2161 | 2161 | } |
| 2162 | 2162 | } |
| 2163 | 2163 | // fallback to hardcoded defaults, in case the above failed |
| 2164 | 2164 | if (empty($this->code)) { |
| 2165 | 2165 | // set default currency settings |
| 2166 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2167 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2168 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2169 | - $this->sign = '$'; // currency sign: $ |
|
| 2170 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2171 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2172 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2173 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2166 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2167 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2168 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2169 | + $this->sign = '$'; // currency sign: $ |
|
| 2170 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2171 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2172 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2173 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2174 | 2174 | } |
| 2175 | 2175 | } |
| 2176 | 2176 | } |
@@ -2429,8 +2429,8 @@ discard block |
||
| 2429 | 2429 | $closing_a_tag = ''; |
| 2430 | 2430 | if (function_exists('get_privacy_policy_url')) { |
| 2431 | 2431 | $privacy_page_url = get_privacy_policy_url(); |
| 2432 | - if (! empty($privacy_page_url)) { |
|
| 2433 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2432 | + if ( ! empty($privacy_page_url)) { |
|
| 2433 | + $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">'; |
|
| 2434 | 2434 | $closing_a_tag = '</a>'; |
| 2435 | 2435 | } |
| 2436 | 2436 | } |
@@ -2642,7 +2642,7 @@ discard block |
||
| 2642 | 2642 | public function log_file_name($reset = false) |
| 2643 | 2643 | { |
| 2644 | 2644 | if (empty($this->log_file_name) || $reset) { |
| 2645 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2645 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2646 | 2646 | EE_Config::instance()->update_espresso_config(false, false); |
| 2647 | 2647 | } |
| 2648 | 2648 | return $this->log_file_name; |
@@ -2656,7 +2656,7 @@ discard block |
||
| 2656 | 2656 | public function debug_file_name($reset = false) |
| 2657 | 2657 | { |
| 2658 | 2658 | if (empty($this->debug_file_name) || $reset) { |
| 2659 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2659 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2660 | 2660 | EE_Config::instance()->update_espresso_config(false, false); |
| 2661 | 2661 | } |
| 2662 | 2662 | return $this->debug_file_name; |
@@ -2860,21 +2860,21 @@ discard block |
||
| 2860 | 2860 | $this->use_google_maps = true; |
| 2861 | 2861 | $this->google_map_api_key = ''; |
| 2862 | 2862 | // for event details pages (reg page) |
| 2863 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2864 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2865 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2866 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2867 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2868 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2869 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2863 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2864 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2865 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2866 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2867 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2868 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2869 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2870 | 2870 | // for event list pages |
| 2871 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2872 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2873 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2874 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2875 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2876 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2877 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2871 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2872 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2873 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2874 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2875 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2876 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2877 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2878 | 2878 | } |
| 2879 | 2879 | } |
| 2880 | 2880 | |
@@ -3166,7 +3166,7 @@ discard block |
||
| 3166 | 3166 | */ |
| 3167 | 3167 | public function max_input_vars_limit_check($input_count = 0) |
| 3168 | 3168 | { |
| 3169 | - if (! empty($this->php->max_input_vars) |
|
| 3169 | + if ( ! empty($this->php->max_input_vars) |
|
| 3170 | 3170 | && ($input_count >= $this->php->max_input_vars) |
| 3171 | 3171 | && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
| 3172 | 3172 | ) { |
@@ -14,2509 +14,2509 @@ discard block |
||
| 14 | 14 | final class EE_Config implements ResettableInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const OPTION_NAME = 'ee_config'; |
|
| 18 | - |
|
| 19 | - const LOG_NAME = 'ee_config_log'; |
|
| 20 | - |
|
| 21 | - const LOG_LENGTH = 100; |
|
| 22 | - |
|
| 23 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * instance of the EE_Config object |
|
| 27 | - * |
|
| 28 | - * @var EE_Config $_instance |
|
| 29 | - * @access private |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var boolean $_logging_enabled |
|
| 35 | - */ |
|
| 36 | - private static $_logging_enabled = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | - */ |
|
| 41 | - private $legacy_shortcodes_manager; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * An StdClass whose property names are addon slugs, |
|
| 45 | - * and values are their config classes |
|
| 46 | - * |
|
| 47 | - * @var StdClass |
|
| 48 | - */ |
|
| 49 | - public $addons; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Admin_Config |
|
| 53 | - */ |
|
| 54 | - public $admin; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Core_Config |
|
| 58 | - */ |
|
| 59 | - public $core; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var EE_Currency_Config |
|
| 63 | - */ |
|
| 64 | - public $currency; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var EE_Organization_Config |
|
| 68 | - */ |
|
| 69 | - public $organization; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var EE_Registration_Config |
|
| 73 | - */ |
|
| 74 | - public $registration; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var EE_Template_Config |
|
| 78 | - */ |
|
| 79 | - public $template_settings; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Holds EE environment values. |
|
| 83 | - * |
|
| 84 | - * @var EE_Environment_Config |
|
| 85 | - */ |
|
| 86 | - public $environment; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * settings pertaining to Google maps |
|
| 90 | - * |
|
| 91 | - * @var EE_Map_Config |
|
| 92 | - */ |
|
| 93 | - public $map_settings; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Taxes |
|
| 97 | - * |
|
| 98 | - * @var EE_Tax_Config |
|
| 99 | - */ |
|
| 100 | - public $tax_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Settings pertaining to global messages settings. |
|
| 104 | - * |
|
| 105 | - * @var EE_Messages_Config |
|
| 106 | - */ |
|
| 107 | - public $messages; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @deprecated |
|
| 111 | - * @var EE_Gateway_Config |
|
| 112 | - */ |
|
| 113 | - public $gateway; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var array $_addon_option_names |
|
| 117 | - * @access private |
|
| 118 | - */ |
|
| 119 | - private $_addon_option_names = array(); |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @var array $_module_route_map |
|
| 123 | - * @access private |
|
| 124 | - */ |
|
| 125 | - private static $_module_route_map = array(); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array $_module_forward_map |
|
| 129 | - * @access private |
|
| 130 | - */ |
|
| 131 | - private static $_module_forward_map = array(); |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @var array $_module_view_map |
|
| 135 | - * @access private |
|
| 136 | - */ |
|
| 137 | - private static $_module_view_map = array(); |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @singleton method used to instantiate class object |
|
| 142 | - * @access public |
|
| 143 | - * @return EE_Config instance |
|
| 144 | - */ |
|
| 145 | - public static function instance() |
|
| 146 | - { |
|
| 147 | - // check if class object is instantiated, and instantiated properly |
|
| 148 | - if (! self::$_instance instanceof EE_Config) { |
|
| 149 | - self::$_instance = new self(); |
|
| 150 | - } |
|
| 151 | - return self::$_instance; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Resets the config |
|
| 157 | - * |
|
| 158 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | - * reflect its state in the database |
|
| 161 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | - * site was put into maintenance mode) |
|
| 165 | - * @return EE_Config |
|
| 166 | - */ |
|
| 167 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | - { |
|
| 169 | - if (self::$_instance instanceof EE_Config) { |
|
| 170 | - if ($hard_reset) { |
|
| 171 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | - self::$_instance->_addon_option_names = array(); |
|
| 173 | - self::$_instance->_initialize_config(); |
|
| 174 | - self::$_instance->update_espresso_config(); |
|
| 175 | - } |
|
| 176 | - self::$_instance->update_addon_option_names(); |
|
| 177 | - } |
|
| 178 | - self::$_instance = null; |
|
| 179 | - // we don't need to reset the static properties imo because those should |
|
| 180 | - // only change when a module is added or removed. Currently we don't |
|
| 181 | - // support removing a module during a request when it previously existed |
|
| 182 | - if ($reinstantiate) { |
|
| 183 | - return self::instance(); |
|
| 184 | - } else { |
|
| 185 | - return null; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * class constructor |
|
| 192 | - * |
|
| 193 | - * @access private |
|
| 194 | - */ |
|
| 195 | - private function __construct() |
|
| 196 | - { |
|
| 197 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | - // setup empty config classes |
|
| 200 | - $this->_initialize_config(); |
|
| 201 | - // load existing EE site settings |
|
| 202 | - $this->_load_core_config(); |
|
| 203 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | - $this->_verify_config(); |
|
| 205 | - // register shortcodes and modules |
|
| 206 | - add_action( |
|
| 207 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | - array($this, 'register_shortcodes_and_modules'), |
|
| 209 | - 999 |
|
| 210 | - ); |
|
| 211 | - // initialize shortcodes and modules |
|
| 212 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | - // register widgets |
|
| 214 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | - // shutdown |
|
| 216 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | - // construct__end hook |
|
| 218 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | - // hardcoded hack |
|
| 220 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return boolean |
|
| 226 | - */ |
|
| 227 | - public static function logging_enabled() |
|
| 228 | - { |
|
| 229 | - return self::$_logging_enabled; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * use to get the current theme if needed from static context |
|
| 235 | - * |
|
| 236 | - * @return string current theme set. |
|
| 237 | - */ |
|
| 238 | - public static function get_current_theme() |
|
| 239 | - { |
|
| 240 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * _initialize_config |
|
| 247 | - * |
|
| 248 | - * @access private |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - private function _initialize_config() |
|
| 252 | - { |
|
| 253 | - EE_Config::trim_log(); |
|
| 254 | - // set defaults |
|
| 255 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | - $this->addons = new stdClass(); |
|
| 257 | - // set _module_route_map |
|
| 258 | - EE_Config::$_module_route_map = array(); |
|
| 259 | - // set _module_forward_map |
|
| 260 | - EE_Config::$_module_forward_map = array(); |
|
| 261 | - // set _module_view_map |
|
| 262 | - EE_Config::$_module_view_map = array(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * load core plugin configuration |
|
| 268 | - * |
|
| 269 | - * @access private |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - private function _load_core_config() |
|
| 273 | - { |
|
| 274 | - // load_core_config__start hook |
|
| 275 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | - $espresso_config = $this->get_espresso_config(); |
|
| 277 | - foreach ($espresso_config as $config => $settings) { |
|
| 278 | - // load_core_config__start hook |
|
| 279 | - $settings = apply_filters( |
|
| 280 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | - $settings, |
|
| 282 | - $config, |
|
| 283 | - $this |
|
| 284 | - ); |
|
| 285 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | - // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | - if (method_exists($settings, 'populate')) { |
|
| 289 | - $this->{$config}->populate(); |
|
| 290 | - } |
|
| 291 | - if (method_exists($settings, 'do_hooks')) { |
|
| 292 | - $this->{$config}->do_hooks(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | - $this->update_espresso_config(); |
|
| 298 | - } |
|
| 299 | - // load_core_config__end hook |
|
| 300 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * _verify_config |
|
| 306 | - * |
|
| 307 | - * @access protected |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - protected function _verify_config() |
|
| 311 | - { |
|
| 312 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | - ? $this->core |
|
| 314 | - : new EE_Core_Config(); |
|
| 315 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | - ? $this->organization |
|
| 318 | - : new EE_Organization_Config(); |
|
| 319 | - $this->organization = apply_filters( |
|
| 320 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | - $this->organization |
|
| 322 | - ); |
|
| 323 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | - ? $this->currency |
|
| 325 | - : new EE_Currency_Config(); |
|
| 326 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | - ? $this->registration |
|
| 329 | - : new EE_Registration_Config(); |
|
| 330 | - $this->registration = apply_filters( |
|
| 331 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | - $this->registration |
|
| 333 | - ); |
|
| 334 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | - ? $this->admin |
|
| 336 | - : new EE_Admin_Config(); |
|
| 337 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | - ? $this->template_settings |
|
| 340 | - : new EE_Template_Config(); |
|
| 341 | - $this->template_settings = apply_filters( |
|
| 342 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | - $this->template_settings |
|
| 344 | - ); |
|
| 345 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | - ? $this->map_settings |
|
| 347 | - : new EE_Map_Config(); |
|
| 348 | - $this->map_settings = apply_filters( |
|
| 349 | - 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | - $this->map_settings |
|
| 351 | - ); |
|
| 352 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | - ? $this->environment |
|
| 354 | - : new EE_Environment_Config(); |
|
| 355 | - $this->environment = apply_filters( |
|
| 356 | - 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | - $this->environment |
|
| 358 | - ); |
|
| 359 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | - ? $this->tax_settings |
|
| 361 | - : new EE_Tax_Config(); |
|
| 362 | - $this->tax_settings = apply_filters( |
|
| 363 | - 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | - $this->tax_settings |
|
| 365 | - ); |
|
| 366 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | - ? $this->messages |
|
| 369 | - : new EE_Messages_Config(); |
|
| 370 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | - ? $this->gateway |
|
| 372 | - : new EE_Gateway_Config(); |
|
| 373 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | - $this->legacy_shortcodes_manager = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * get_espresso_config |
|
| 380 | - * |
|
| 381 | - * @access public |
|
| 382 | - * @return array of espresso config stuff |
|
| 383 | - */ |
|
| 384 | - public function get_espresso_config() |
|
| 385 | - { |
|
| 386 | - // grab espresso configuration |
|
| 387 | - return apply_filters( |
|
| 388 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * double_check_config_comparison |
|
| 396 | - * |
|
| 397 | - * @access public |
|
| 398 | - * @param string $option |
|
| 399 | - * @param $old_value |
|
| 400 | - * @param $value |
|
| 401 | - */ |
|
| 402 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | - { |
|
| 404 | - // make sure we're checking the ee config |
|
| 405 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | - if ($value != $old_value) { |
|
| 409 | - // if they are NOT the same, then remove the hook, |
|
| 410 | - // which means the subsequent update results will be based solely on the update query results |
|
| 411 | - // the reason we do this is because, as stated above, |
|
| 412 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | - // If values are found to match their previous old value, |
|
| 415 | - // then WP bails before performing any update. |
|
| 416 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | - // MySQL MAY ALSO NOT perform the update because |
|
| 420 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * update_espresso_config |
|
| 431 | - * |
|
| 432 | - * @access public |
|
| 433 | - */ |
|
| 434 | - protected function _reset_espresso_addon_config() |
|
| 435 | - { |
|
| 436 | - $this->_addon_option_names = array(); |
|
| 437 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | - if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | - } |
|
| 442 | - $this->addons->{$addon_name} = null; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * update_espresso_config |
|
| 449 | - * |
|
| 450 | - * @access public |
|
| 451 | - * @param bool $add_success |
|
| 452 | - * @param bool $add_error |
|
| 453 | - * @return bool |
|
| 454 | - */ |
|
| 455 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | - { |
|
| 457 | - // don't allow config updates during WP heartbeats |
|
| 458 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | - // $clone = clone( self::$_instance ); |
|
| 463 | - // self::$_instance = NULL; |
|
| 464 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | - $this->_reset_espresso_addon_config(); |
|
| 466 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | - // but BEFORE the actual update occurs |
|
| 468 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | - $this->legacy_shortcodes_manager = null; |
|
| 472 | - // now update "ee_config" |
|
| 473 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | - // if not saved... check if the hook we just added still exists; |
|
| 477 | - // if it does, it means one of two things: |
|
| 478 | - // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | - // or... |
|
| 480 | - // the db update query returned 0 rows affected |
|
| 481 | - // (probably because the data value was the same from it's perspective) |
|
| 482 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | - // but just means no update occurred, so don't display an error to the user. |
|
| 484 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | - // then it means that something truly went wrong |
|
| 486 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | - // remove our action since we don't want it in the system anymore |
|
| 488 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | - // self::$_instance = $clone; |
|
| 491 | - // unset( $clone ); |
|
| 492 | - // if config remains the same or was updated successfully |
|
| 493 | - if ($saved) { |
|
| 494 | - if ($add_success) { |
|
| 495 | - EE_Error::add_success( |
|
| 496 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | - __FILE__, |
|
| 498 | - __FUNCTION__, |
|
| 499 | - __LINE__ |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - return true; |
|
| 503 | - } else { |
|
| 504 | - if ($add_error) { |
|
| 505 | - EE_Error::add_error( |
|
| 506 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | - __FILE__, |
|
| 508 | - __FUNCTION__, |
|
| 509 | - __LINE__ |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * _verify_config_params |
|
| 519 | - * |
|
| 520 | - * @access private |
|
| 521 | - * @param string $section |
|
| 522 | - * @param string $name |
|
| 523 | - * @param string $config_class |
|
| 524 | - * @param EE_Config_Base $config_obj |
|
| 525 | - * @param array $tests_to_run |
|
| 526 | - * @param bool $display_errors |
|
| 527 | - * @return bool TRUE on success, FALSE on fail |
|
| 528 | - */ |
|
| 529 | - private function _verify_config_params( |
|
| 530 | - $section = '', |
|
| 531 | - $name = '', |
|
| 532 | - $config_class = '', |
|
| 533 | - $config_obj = null, |
|
| 534 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | - $display_errors = true |
|
| 536 | - ) { |
|
| 537 | - try { |
|
| 538 | - foreach ($tests_to_run as $test) { |
|
| 539 | - switch ($test) { |
|
| 540 | - // TEST #1 : check that section was set |
|
| 541 | - case 1: |
|
| 542 | - if (empty($section)) { |
|
| 543 | - if ($display_errors) { |
|
| 544 | - throw new EE_Error( |
|
| 545 | - sprintf( |
|
| 546 | - __( |
|
| 547 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ), |
|
| 550 | - $config_class |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - break; |
|
| 557 | - // TEST #2 : check that settings section exists |
|
| 558 | - case 2: |
|
| 559 | - if (! isset($this->{$section})) { |
|
| 560 | - if ($display_errors) { |
|
| 561 | - throw new EE_Error( |
|
| 562 | - sprintf( |
|
| 563 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | - $section |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - } |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - break; |
|
| 571 | - // TEST #3 : check that section is the proper format |
|
| 572 | - case 3: |
|
| 573 | - if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | - ) { |
|
| 575 | - if ($display_errors) { |
|
| 576 | - throw new EE_Error( |
|
| 577 | - sprintf( |
|
| 578 | - __( |
|
| 579 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $section |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - return false; |
|
| 587 | - } |
|
| 588 | - break; |
|
| 589 | - // TEST #4 : check that config section name has been set |
|
| 590 | - case 4: |
|
| 591 | - if (empty($name)) { |
|
| 592 | - if ($display_errors) { |
|
| 593 | - throw new EE_Error( |
|
| 594 | - __( |
|
| 595 | - 'No name has been provided for the specific configuration section.', |
|
| 596 | - 'event_espresso' |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - break; |
|
| 603 | - // TEST #5 : check that a config class name has been set |
|
| 604 | - case 5: |
|
| 605 | - if (empty($config_class)) { |
|
| 606 | - if ($display_errors) { |
|
| 607 | - throw new EE_Error( |
|
| 608 | - __( |
|
| 609 | - 'No class name has been provided for the specific configuration section.', |
|
| 610 | - 'event_espresso' |
|
| 611 | - ) |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - return false; |
|
| 615 | - } |
|
| 616 | - break; |
|
| 617 | - // TEST #6 : verify config class is accessible |
|
| 618 | - case 6: |
|
| 619 | - if (! class_exists($config_class)) { |
|
| 620 | - if ($display_errors) { |
|
| 621 | - throw new EE_Error( |
|
| 622 | - sprintf( |
|
| 623 | - __( |
|
| 624 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | - 'event_espresso' |
|
| 626 | - ), |
|
| 627 | - $config_class |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - // TEST #7 : check that config has even been set |
|
| 635 | - case 7: |
|
| 636 | - if (! isset($this->{$section}->{$name})) { |
|
| 637 | - if ($display_errors) { |
|
| 638 | - throw new EE_Error( |
|
| 639 | - sprintf( |
|
| 640 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | - $section, |
|
| 642 | - $name |
|
| 643 | - ) |
|
| 644 | - ); |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } else { |
|
| 648 | - // and make sure it's not serialized |
|
| 649 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | - } |
|
| 651 | - break; |
|
| 652 | - // TEST #8 : check that config is the requested type |
|
| 653 | - case 8: |
|
| 654 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | - if ($display_errors) { |
|
| 656 | - throw new EE_Error( |
|
| 657 | - sprintf( |
|
| 658 | - __( |
|
| 659 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | - 'event_espresso' |
|
| 661 | - ), |
|
| 662 | - $section, |
|
| 663 | - $name, |
|
| 664 | - $config_class |
|
| 665 | - ) |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - break; |
|
| 671 | - // TEST #9 : verify config object |
|
| 672 | - case 9: |
|
| 673 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | - if ($display_errors) { |
|
| 675 | - throw new EE_Error( |
|
| 676 | - sprintf( |
|
| 677 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | - print_r($config_obj, true) |
|
| 679 | - ) |
|
| 680 | - ); |
|
| 681 | - } |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - break; |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } catch (EE_Error $e) { |
|
| 688 | - $e->get_error(); |
|
| 689 | - } |
|
| 690 | - // you have successfully run the gauntlet |
|
| 691 | - return true; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * _generate_config_option_name |
|
| 697 | - * |
|
| 698 | - * @access protected |
|
| 699 | - * @param string $section |
|
| 700 | - * @param string $name |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | - { |
|
| 705 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * _set_config_class |
|
| 711 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | - * |
|
| 713 | - * @access private |
|
| 714 | - * @param string $config_class |
|
| 715 | - * @param string $name |
|
| 716 | - * @return string |
|
| 717 | - */ |
|
| 718 | - private function _set_config_class($config_class = '', $name = '') |
|
| 719 | - { |
|
| 720 | - return ! empty($config_class) |
|
| 721 | - ? $config_class |
|
| 722 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * set_config |
|
| 728 | - * |
|
| 729 | - * @access protected |
|
| 730 | - * @param string $section |
|
| 731 | - * @param string $name |
|
| 732 | - * @param string $config_class |
|
| 733 | - * @param EE_Config_Base $config_obj |
|
| 734 | - * @return EE_Config_Base |
|
| 735 | - */ |
|
| 736 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | - { |
|
| 738 | - // ensure config class is set to something |
|
| 739 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | - return null; |
|
| 743 | - } |
|
| 744 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | - $this->update_addon_option_names(); |
|
| 749 | - } |
|
| 750 | - // verify the incoming config object but suppress errors |
|
| 751 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | - $config_obj = new $config_class(); |
|
| 753 | - } |
|
| 754 | - if (get_option($config_option_name)) { |
|
| 755 | - EE_Config::log($config_option_name); |
|
| 756 | - update_option($config_option_name, $config_obj); |
|
| 757 | - $this->{$section}->{$name} = $config_obj; |
|
| 758 | - return $this->{$section}->{$name}; |
|
| 759 | - } else { |
|
| 760 | - // create a wp-option for this config |
|
| 761 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | - return $this->{$section}->{$name}; |
|
| 764 | - } else { |
|
| 765 | - EE_Error::add_error( |
|
| 766 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | - __FILE__, |
|
| 768 | - __FUNCTION__, |
|
| 769 | - __LINE__ |
|
| 770 | - ); |
|
| 771 | - return null; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * update_config |
|
| 779 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @param string $section |
|
| 783 | - * @param string $name |
|
| 784 | - * @param EE_Config_Base|string $config_obj |
|
| 785 | - * @param bool $throw_errors |
|
| 786 | - * @return bool |
|
| 787 | - */ |
|
| 788 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | - { |
|
| 790 | - // don't allow config updates during WP heartbeats |
|
| 791 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - $config_obj = maybe_unserialize($config_obj); |
|
| 795 | - // get class name of the incoming object |
|
| 796 | - $config_class = get_class($config_obj); |
|
| 797 | - // run tests 1-5 and 9 to verify config |
|
| 798 | - if (! $this->_verify_config_params( |
|
| 799 | - $section, |
|
| 800 | - $name, |
|
| 801 | - $config_class, |
|
| 802 | - $config_obj, |
|
| 803 | - array(1, 2, 3, 4, 7, 9) |
|
| 804 | - ) |
|
| 805 | - ) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | - // save new config to db |
|
| 812 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | - return true; |
|
| 814 | - } |
|
| 815 | - } else { |
|
| 816 | - // first check if the record already exists |
|
| 817 | - $existing_config = get_option($config_option_name); |
|
| 818 | - $config_obj = serialize($config_obj); |
|
| 819 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | - if ($existing_config == $config_obj) { |
|
| 821 | - $this->{$section}->{$name} = $config_obj; |
|
| 822 | - return true; |
|
| 823 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | - EE_Config::log($config_option_name); |
|
| 825 | - // update wp-option for this config class |
|
| 826 | - $this->{$section}->{$name} = $config_obj; |
|
| 827 | - return true; |
|
| 828 | - } elseif ($throw_errors) { |
|
| 829 | - EE_Error::add_error( |
|
| 830 | - sprintf( |
|
| 831 | - __( |
|
| 832 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | - 'event_espresso' |
|
| 834 | - ), |
|
| 835 | - $config_class, |
|
| 836 | - 'EE_Config->' . $section . '->' . $name |
|
| 837 | - ), |
|
| 838 | - __FILE__, |
|
| 839 | - __FUNCTION__, |
|
| 840 | - __LINE__ |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - return false; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * get_config |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @param string $section |
|
| 853 | - * @param string $name |
|
| 854 | - * @param string $config_class |
|
| 855 | - * @return mixed EE_Config_Base | NULL |
|
| 856 | - */ |
|
| 857 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | - { |
|
| 859 | - // ensure config class is set to something |
|
| 860 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | - return null; |
|
| 864 | - } |
|
| 865 | - // now test if the requested config object exists, but suppress errors |
|
| 866 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | - // config already exists, so pass it back |
|
| 868 | - return $this->{$section}->{$name}; |
|
| 869 | - } |
|
| 870 | - // load config option from db if it exists |
|
| 871 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | - // verify the newly retrieved config object, but suppress errors |
|
| 873 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | - // config is good, so set it and pass it back |
|
| 875 | - $this->{$section}->{$name} = $config_obj; |
|
| 876 | - return $this->{$section}->{$name}; |
|
| 877 | - } |
|
| 878 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | - // verify the newly created config object |
|
| 881 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | - return $this->{$section}->{$name}; |
|
| 883 | - } else { |
|
| 884 | - EE_Error::add_error( |
|
| 885 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | - __FILE__, |
|
| 887 | - __FUNCTION__, |
|
| 888 | - __LINE__ |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - return null; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * get_config_option |
|
| 897 | - * |
|
| 898 | - * @access public |
|
| 899 | - * @param string $config_option_name |
|
| 900 | - * @return mixed EE_Config_Base | FALSE |
|
| 901 | - */ |
|
| 902 | - public function get_config_option($config_option_name = '') |
|
| 903 | - { |
|
| 904 | - // retrieve the wp-option for this config class. |
|
| 905 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | - if (empty($config_option)) { |
|
| 907 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | - } |
|
| 909 | - return $config_option; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * log |
|
| 915 | - * |
|
| 916 | - * @param string $config_option_name |
|
| 917 | - */ |
|
| 918 | - public static function log($config_option_name = '') |
|
| 919 | - { |
|
| 920 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | - $_request = $_REQUEST; |
|
| 924 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | - $config_log[ (string) microtime(true) ] = array( |
|
| 926 | - 'config_name' => $config_option_name, |
|
| 927 | - 'request' => $_request, |
|
| 928 | - ); |
|
| 929 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * trim_log |
|
| 936 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | - */ |
|
| 938 | - public static function trim_log() |
|
| 939 | - { |
|
| 940 | - if (! EE_Config::logging_enabled()) { |
|
| 941 | - return; |
|
| 942 | - } |
|
| 943 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | - $log_length = count($config_log); |
|
| 945 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | - ksort($config_log); |
|
| 947 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * get_page_for_posts |
|
| 955 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | - * |
|
| 958 | - * @access public |
|
| 959 | - * @return string |
|
| 960 | - */ |
|
| 961 | - public static function get_page_for_posts() |
|
| 962 | - { |
|
| 963 | - $page_for_posts = get_option('page_for_posts'); |
|
| 964 | - if (! $page_for_posts) { |
|
| 965 | - return 'posts'; |
|
| 966 | - } |
|
| 967 | - /** @type WPDB $wpdb */ |
|
| 968 | - global $wpdb; |
|
| 969 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * register_shortcodes_and_modules. |
|
| 976 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | - * so they can help trigger maintenance mode if it's needed |
|
| 979 | - * |
|
| 980 | - * @access public |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - public function register_shortcodes_and_modules() |
|
| 984 | - { |
|
| 985 | - // allow modules to set hooks for the rest of the system |
|
| 986 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * initialize_shortcodes_and_modules |
|
| 992 | - * meaning they can start adding their hooks to get stuff done |
|
| 993 | - * |
|
| 994 | - * @access public |
|
| 995 | - * @return void |
|
| 996 | - */ |
|
| 997 | - public function initialize_shortcodes_and_modules() |
|
| 998 | - { |
|
| 999 | - // allow modules to set hooks for the rest of the system |
|
| 1000 | - $this->_initialize_modules(); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * widgets_init |
|
| 1006 | - * |
|
| 1007 | - * @access private |
|
| 1008 | - * @return void |
|
| 1009 | - */ |
|
| 1010 | - public function widgets_init() |
|
| 1011 | - { |
|
| 1012 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | - // on frontend when not in any maintenance mode |
|
| 1014 | - if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | - || ( |
|
| 1016 | - is_admin() |
|
| 1017 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | - ) |
|
| 1019 | - ) { |
|
| 1020 | - // grab list of installed widgets |
|
| 1021 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | - // filter list of modules to register |
|
| 1023 | - $widgets_to_register = apply_filters( |
|
| 1024 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | - $widgets_to_register |
|
| 1026 | - ); |
|
| 1027 | - if (! empty($widgets_to_register)) { |
|
| 1028 | - // cycle thru widget folders |
|
| 1029 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | - // add to list of installed widget modules |
|
| 1031 | - EE_Config::register_ee_widget($widget_path); |
|
| 1032 | - } |
|
| 1033 | - } |
|
| 1034 | - // filter list of installed modules |
|
| 1035 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | - EE_Registry::instance()->widgets |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * register_ee_widget - makes core aware of this widget |
|
| 1045 | - * |
|
| 1046 | - * @access public |
|
| 1047 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public static function register_ee_widget($widget_path = null) |
|
| 1051 | - { |
|
| 1052 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | - $widget_ext = '.widget.php'; |
|
| 1054 | - // make all separators match |
|
| 1055 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | - $file_name = explode('.', basename($widget_path)); |
|
| 1060 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | - // sanitize shortcode directory name |
|
| 1063 | - $widget = sanitize_key($widget); |
|
| 1064 | - // now we need to rebuild the shortcode path |
|
| 1065 | - $widget_path = explode(DS, $widget_path); |
|
| 1066 | - // remove last segment |
|
| 1067 | - array_pop($widget_path); |
|
| 1068 | - // glue it back together |
|
| 1069 | - $widget_path = implode(DS, $widget_path); |
|
| 1070 | - } else { |
|
| 1071 | - // grab and sanitize widget directory name |
|
| 1072 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | - } |
|
| 1074 | - // create classname from widget directory name |
|
| 1075 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | - // add class prefix |
|
| 1077 | - $widget_class = 'EEW_' . $widget; |
|
| 1078 | - // does the widget exist ? |
|
| 1079 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1080 | - $msg = sprintf( |
|
| 1081 | - __( |
|
| 1082 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | - 'event_espresso' |
|
| 1084 | - ), |
|
| 1085 | - $widget_class, |
|
| 1086 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1087 | - ); |
|
| 1088 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | - return; |
|
| 1090 | - } |
|
| 1091 | - // load the widget class file |
|
| 1092 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1093 | - // verify that class exists |
|
| 1094 | - if (! class_exists($widget_class)) { |
|
| 1095 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | - return; |
|
| 1098 | - } |
|
| 1099 | - register_widget($widget_class); |
|
| 1100 | - // add to array of registered widgets |
|
| 1101 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * _register_modules |
|
| 1107 | - * |
|
| 1108 | - * @access private |
|
| 1109 | - * @return array |
|
| 1110 | - */ |
|
| 1111 | - private function _register_modules() |
|
| 1112 | - { |
|
| 1113 | - // grab list of installed modules |
|
| 1114 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | - // filter list of modules to register |
|
| 1116 | - $modules_to_register = apply_filters( |
|
| 1117 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | - $modules_to_register |
|
| 1119 | - ); |
|
| 1120 | - if (! empty($modules_to_register)) { |
|
| 1121 | - // loop through folders |
|
| 1122 | - foreach ($modules_to_register as $module_path) { |
|
| 1123 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | - if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | - ) { |
|
| 1127 | - // add to list of installed modules |
|
| 1128 | - EE_Config::register_module($module_path); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - // filter list of installed modules |
|
| 1133 | - return apply_filters( |
|
| 1134 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | - EE_Registry::instance()->modules |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * register_module - makes core aware of this module |
|
| 1142 | - * |
|
| 1143 | - * @access public |
|
| 1144 | - * @param string $module_path - full path up to and including module folder |
|
| 1145 | - * @return bool |
|
| 1146 | - */ |
|
| 1147 | - public static function register_module($module_path = null) |
|
| 1148 | - { |
|
| 1149 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | - $module_ext = '.module.php'; |
|
| 1151 | - // make all separators match |
|
| 1152 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1153 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | - $module_file = explode('.', basename($module_path)); |
|
| 1157 | - // now we need to rebuild the shortcode path |
|
| 1158 | - $module_path = explode(DS, $module_path); |
|
| 1159 | - // remove last segment |
|
| 1160 | - array_pop($module_path); |
|
| 1161 | - // glue it back together |
|
| 1162 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1163 | - // take first segment from file name pieces and sanitize it |
|
| 1164 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | - // ensure class prefix is added |
|
| 1166 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | - } else { |
|
| 1168 | - // we need to generate the filename based off of the folder name |
|
| 1169 | - // grab and sanitize module name |
|
| 1170 | - $module = strtolower(basename($module_path)); |
|
| 1171 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | - // like trailingslashit() |
|
| 1173 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1174 | - // create classname from module directory name |
|
| 1175 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | - // add class prefix |
|
| 1177 | - $module_class = 'EED_' . $module; |
|
| 1178 | - } |
|
| 1179 | - // does the module exist ? |
|
| 1180 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1181 | - $msg = sprintf( |
|
| 1182 | - __( |
|
| 1183 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | - 'event_espresso' |
|
| 1185 | - ), |
|
| 1186 | - $module |
|
| 1187 | - ); |
|
| 1188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | - return false; |
|
| 1190 | - } |
|
| 1191 | - // load the module class file |
|
| 1192 | - require_once($module_path . $module_class . $module_ext); |
|
| 1193 | - // verify that class exists |
|
| 1194 | - if (! class_exists($module_class)) { |
|
| 1195 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | - return false; |
|
| 1198 | - } |
|
| 1199 | - // add to array of registered modules |
|
| 1200 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | - do_action( |
|
| 1202 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | - $module_class, |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | - ); |
|
| 1206 | - return true; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * _initialize_modules |
|
| 1212 | - * allow modules to set hooks for the rest of the system |
|
| 1213 | - * |
|
| 1214 | - * @access private |
|
| 1215 | - * @return void |
|
| 1216 | - */ |
|
| 1217 | - private function _initialize_modules() |
|
| 1218 | - { |
|
| 1219 | - // cycle thru shortcode folders |
|
| 1220 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | - // which set hooks ? |
|
| 1223 | - if (is_admin()) { |
|
| 1224 | - // fire immediately |
|
| 1225 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | - } else { |
|
| 1227 | - // delay until other systems are online |
|
| 1228 | - add_action( |
|
| 1229 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | - array($module_class, 'set_hooks') |
|
| 1231 | - ); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * register_route - adds module method routes to route_map |
|
| 1239 | - * |
|
| 1240 | - * @access public |
|
| 1241 | - * @param string $route - "pretty" public alias for module method |
|
| 1242 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | - * @param string $method_name - the actual module method to be routed to |
|
| 1244 | - * @param string $key - url param key indicating a route is being called |
|
| 1245 | - * @return bool |
|
| 1246 | - */ |
|
| 1247 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | - { |
|
| 1249 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | - $module = str_replace('EED_', '', $module); |
|
| 1251 | - $module_class = 'EED_' . $module; |
|
| 1252 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | - return false; |
|
| 1256 | - } |
|
| 1257 | - if (empty($route)) { |
|
| 1258 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | - return false; |
|
| 1261 | - } |
|
| 1262 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | - $msg = sprintf( |
|
| 1264 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | - $route |
|
| 1266 | - ); |
|
| 1267 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | - return true; |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * get_route - get module method route |
|
| 1277 | - * |
|
| 1278 | - * @access public |
|
| 1279 | - * @param string $route - "pretty" public alias for module method |
|
| 1280 | - * @param string $key - url param key indicating a route is being called |
|
| 1281 | - * @return string |
|
| 1282 | - */ |
|
| 1283 | - public static function get_route($route = null, $key = 'ee') |
|
| 1284 | - { |
|
| 1285 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | - } |
|
| 1290 | - return null; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * get_routes - get ALL module method routes |
|
| 1296 | - * |
|
| 1297 | - * @access public |
|
| 1298 | - * @return array |
|
| 1299 | - */ |
|
| 1300 | - public static function get_routes() |
|
| 1301 | - { |
|
| 1302 | - return EE_Config::$_module_route_map; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | - * |
|
| 1309 | - * @access public |
|
| 1310 | - * @param string $route - "pretty" public alias for module method |
|
| 1311 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | - * class, allows different forwards to be served based on status |
|
| 1313 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | - * @param string $key - url param key indicating a route is being called |
|
| 1315 | - * @return bool |
|
| 1316 | - */ |
|
| 1317 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | - { |
|
| 1319 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | - $msg = sprintf( |
|
| 1322 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | - $route |
|
| 1324 | - ); |
|
| 1325 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | - return false; |
|
| 1327 | - } |
|
| 1328 | - if (empty($forward)) { |
|
| 1329 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | - return false; |
|
| 1332 | - } |
|
| 1333 | - if (is_array($forward)) { |
|
| 1334 | - if (! isset($forward[1])) { |
|
| 1335 | - $msg = sprintf( |
|
| 1336 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | - $route |
|
| 1338 | - ); |
|
| 1339 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | - return false; |
|
| 1341 | - } |
|
| 1342 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | - $msg = sprintf( |
|
| 1344 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | - $forward[1], |
|
| 1346 | - $route |
|
| 1347 | - ); |
|
| 1348 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | - return false; |
|
| 1350 | - } |
|
| 1351 | - } elseif (! function_exists($forward)) { |
|
| 1352 | - $msg = sprintf( |
|
| 1353 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | - $forward, |
|
| 1355 | - $route |
|
| 1356 | - ); |
|
| 1357 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | - return false; |
|
| 1359 | - } |
|
| 1360 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | - return true; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - /** |
|
| 1366 | - * get_forward - get forwarding route |
|
| 1367 | - * |
|
| 1368 | - * @access public |
|
| 1369 | - * @param string $route - "pretty" public alias for module method |
|
| 1370 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | - * allows different forwards to be served based on status |
|
| 1372 | - * @param string $key - url param key indicating a route is being called |
|
| 1373 | - * @return string |
|
| 1374 | - */ |
|
| 1375 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | - { |
|
| 1377 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | - return apply_filters( |
|
| 1380 | - 'FHEE__EE_Config__get_forward', |
|
| 1381 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | - $route, |
|
| 1383 | - $status |
|
| 1384 | - ); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | - * results |
|
| 1393 | - * |
|
| 1394 | - * @access public |
|
| 1395 | - * @param string $route - "pretty" public alias for module method |
|
| 1396 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | - * allows different views to be served based on status |
|
| 1398 | - * @param string $view |
|
| 1399 | - * @param string $key - url param key indicating a route is being called |
|
| 1400 | - * @return bool |
|
| 1401 | - */ |
|
| 1402 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | - { |
|
| 1404 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | - $msg = sprintf( |
|
| 1407 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | - $route |
|
| 1409 | - ); |
|
| 1410 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | - return false; |
|
| 1412 | - } |
|
| 1413 | - if (! is_readable($view)) { |
|
| 1414 | - $msg = sprintf( |
|
| 1415 | - __( |
|
| 1416 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | - 'event_espresso' |
|
| 1418 | - ), |
|
| 1419 | - $view |
|
| 1420 | - ); |
|
| 1421 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | - return false; |
|
| 1423 | - } |
|
| 1424 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | - return true; |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * get_view - get view for route and status |
|
| 1431 | - * |
|
| 1432 | - * @access public |
|
| 1433 | - * @param string $route - "pretty" public alias for module method |
|
| 1434 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | - * allows different views to be served based on status |
|
| 1436 | - * @param string $key - url param key indicating a route is being called |
|
| 1437 | - * @return string |
|
| 1438 | - */ |
|
| 1439 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | - { |
|
| 1441 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | - return apply_filters( |
|
| 1444 | - 'FHEE__EE_Config__get_view', |
|
| 1445 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | - $route, |
|
| 1447 | - $status |
|
| 1448 | - ); |
|
| 1449 | - } |
|
| 1450 | - return null; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - |
|
| 1454 | - public function update_addon_option_names() |
|
| 1455 | - { |
|
| 1456 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - public function shutdown() |
|
| 1461 | - { |
|
| 1462 | - $this->update_addon_option_names(); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * @return LegacyShortcodesManager |
|
| 1468 | - */ |
|
| 1469 | - public static function getLegacyShortcodesManager() |
|
| 1470 | - { |
|
| 1471 | - |
|
| 1472 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | - EE_Registry::instance() |
|
| 1475 | - ); |
|
| 1476 | - } |
|
| 1477 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * register_shortcode - makes core aware of this shortcode |
|
| 1483 | - * |
|
| 1484 | - * @deprecated 4.9.26 |
|
| 1485 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | - * @return bool |
|
| 1487 | - */ |
|
| 1488 | - public static function register_shortcode($shortcode_path = null) |
|
| 1489 | - { |
|
| 1490 | - EE_Error::doing_it_wrong( |
|
| 1491 | - __METHOD__, |
|
| 1492 | - __( |
|
| 1493 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | - 'event_espresso' |
|
| 1495 | - ), |
|
| 1496 | - '4.9.26' |
|
| 1497 | - ); |
|
| 1498 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | - } |
|
| 1500 | -} |
|
| 1501 | - |
|
| 1502 | -/** |
|
| 1503 | - * Base class used for config classes. These classes should generally not have |
|
| 1504 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | - * basically, they should just be well-defined stdClasses |
|
| 1506 | - */ |
|
| 1507 | -class EE_Config_Base |
|
| 1508 | -{ |
|
| 1509 | - |
|
| 1510 | - /** |
|
| 1511 | - * Utility function for escaping the value of a property and returning. |
|
| 1512 | - * |
|
| 1513 | - * @param string $property property name (checks to see if exists). |
|
| 1514 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | - * @throws \EE_Error |
|
| 1516 | - */ |
|
| 1517 | - public function get_pretty($property) |
|
| 1518 | - { |
|
| 1519 | - if (! property_exists($this, $property)) { |
|
| 1520 | - throw new EE_Error( |
|
| 1521 | - sprintf( |
|
| 1522 | - __( |
|
| 1523 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | - 'event_espresso' |
|
| 1525 | - ), |
|
| 1526 | - get_class($this), |
|
| 1527 | - $property |
|
| 1528 | - ) |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - // just handling escaping of strings for now. |
|
| 1532 | - if (is_string($this->{$property})) { |
|
| 1533 | - return stripslashes($this->{$property}); |
|
| 1534 | - } |
|
| 1535 | - return $this->{$property}; |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - public function populate() |
|
| 1540 | - { |
|
| 1541 | - // grab defaults via a new instance of this class. |
|
| 1542 | - $class_name = get_class($this); |
|
| 1543 | - $defaults = new $class_name; |
|
| 1544 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | - // default from our $defaults object. |
|
| 1546 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | - if ($this->{$property} === null) { |
|
| 1548 | - $this->{$property} = $value; |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - // cleanup |
|
| 1552 | - unset($defaults); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * __isset |
|
| 1558 | - * |
|
| 1559 | - * @param $a |
|
| 1560 | - * @return bool |
|
| 1561 | - */ |
|
| 1562 | - public function __isset($a) |
|
| 1563 | - { |
|
| 1564 | - return false; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * __unset |
|
| 1570 | - * |
|
| 1571 | - * @param $a |
|
| 1572 | - * @return bool |
|
| 1573 | - */ |
|
| 1574 | - public function __unset($a) |
|
| 1575 | - { |
|
| 1576 | - return false; |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - |
|
| 1580 | - /** |
|
| 1581 | - * __clone |
|
| 1582 | - */ |
|
| 1583 | - public function __clone() |
|
| 1584 | - { |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * __wakeup |
|
| 1590 | - */ |
|
| 1591 | - public function __wakeup() |
|
| 1592 | - { |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * __destruct |
|
| 1598 | - */ |
|
| 1599 | - public function __destruct() |
|
| 1600 | - { |
|
| 1601 | - } |
|
| 1602 | -} |
|
| 1603 | - |
|
| 1604 | -/** |
|
| 1605 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | - */ |
|
| 1607 | -class EE_Core_Config extends EE_Config_Base |
|
| 1608 | -{ |
|
| 1609 | - |
|
| 1610 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | - |
|
| 1612 | - |
|
| 1613 | - public $current_blog_id; |
|
| 1614 | - |
|
| 1615 | - public $ee_ueip_optin; |
|
| 1616 | - |
|
| 1617 | - public $ee_ueip_has_notified; |
|
| 1618 | - |
|
| 1619 | - /** |
|
| 1620 | - * Not to be confused with the 4 critical page variables (See |
|
| 1621 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | - * |
|
| 1625 | - * @var array |
|
| 1626 | - */ |
|
| 1627 | - public $post_shortcodes; |
|
| 1628 | - |
|
| 1629 | - public $module_route_map; |
|
| 1630 | - |
|
| 1631 | - public $module_forward_map; |
|
| 1632 | - |
|
| 1633 | - public $module_view_map; |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | - * |
|
| 1638 | - * @var int |
|
| 1639 | - */ |
|
| 1640 | - public $reg_page_id; |
|
| 1641 | - |
|
| 1642 | - public $txn_page_id; |
|
| 1643 | - |
|
| 1644 | - public $thank_you_page_id; |
|
| 1645 | - |
|
| 1646 | - public $cancel_page_id; |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | - * |
|
| 1651 | - * @var int |
|
| 1652 | - */ |
|
| 1653 | - public $reg_page_url; |
|
| 1654 | - |
|
| 1655 | - public $txn_page_url; |
|
| 1656 | - |
|
| 1657 | - public $thank_you_page_url; |
|
| 1658 | - |
|
| 1659 | - public $cancel_page_url; |
|
| 1660 | - |
|
| 1661 | - /** |
|
| 1662 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | - */ |
|
| 1664 | - public $event_cpt_slug; |
|
| 1665 | - |
|
| 1666 | - /** |
|
| 1667 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | - * request across blog switches in a multisite context. |
|
| 1669 | - * Avoids extra queries to the db for this option. |
|
| 1670 | - * |
|
| 1671 | - * @var bool |
|
| 1672 | - */ |
|
| 1673 | - public static $ee_ueip_option; |
|
| 1674 | - |
|
| 1675 | - |
|
| 1676 | - /** |
|
| 1677 | - * class constructor |
|
| 1678 | - * |
|
| 1679 | - * @access public |
|
| 1680 | - */ |
|
| 1681 | - public function __construct() |
|
| 1682 | - { |
|
| 1683 | - // set default organization settings |
|
| 1684 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | - $this->post_shortcodes = array(); |
|
| 1689 | - $this->module_route_map = array(); |
|
| 1690 | - $this->module_forward_map = array(); |
|
| 1691 | - $this->module_view_map = array(); |
|
| 1692 | - // critical EE page IDs |
|
| 1693 | - $this->reg_page_id = 0; |
|
| 1694 | - $this->txn_page_id = 0; |
|
| 1695 | - $this->thank_you_page_id = 0; |
|
| 1696 | - $this->cancel_page_id = 0; |
|
| 1697 | - // critical EE page URLs |
|
| 1698 | - $this->reg_page_url = ''; |
|
| 1699 | - $this->txn_page_url = ''; |
|
| 1700 | - $this->thank_you_page_url = ''; |
|
| 1701 | - $this->cancel_page_url = ''; |
|
| 1702 | - // cpt slugs |
|
| 1703 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | - // ueip constant check |
|
| 1705 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | - $this->ee_ueip_optin = false; |
|
| 1707 | - $this->ee_ueip_has_notified = true; |
|
| 1708 | - } |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * @return array |
|
| 1714 | - */ |
|
| 1715 | - public function get_critical_pages_array() |
|
| 1716 | - { |
|
| 1717 | - return array( |
|
| 1718 | - $this->reg_page_id, |
|
| 1719 | - $this->txn_page_id, |
|
| 1720 | - $this->thank_you_page_id, |
|
| 1721 | - $this->cancel_page_id, |
|
| 1722 | - ); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * @return array |
|
| 1728 | - */ |
|
| 1729 | - public function get_critical_pages_shortcodes_array() |
|
| 1730 | - { |
|
| 1731 | - return array( |
|
| 1732 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | - ); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * gets/returns URL for EE reg_page |
|
| 1742 | - * |
|
| 1743 | - * @access public |
|
| 1744 | - * @return string |
|
| 1745 | - */ |
|
| 1746 | - public function reg_page_url() |
|
| 1747 | - { |
|
| 1748 | - if (! $this->reg_page_url) { |
|
| 1749 | - $this->reg_page_url = add_query_arg( |
|
| 1750 | - array('uts' => time()), |
|
| 1751 | - get_permalink($this->reg_page_id) |
|
| 1752 | - ) . '#checkout'; |
|
| 1753 | - } |
|
| 1754 | - return $this->reg_page_url; |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - |
|
| 1758 | - /** |
|
| 1759 | - * gets/returns URL for EE txn_page |
|
| 1760 | - * |
|
| 1761 | - * @param array $query_args like what gets passed to |
|
| 1762 | - * add_query_arg() as the first argument |
|
| 1763 | - * @access public |
|
| 1764 | - * @return string |
|
| 1765 | - */ |
|
| 1766 | - public function txn_page_url($query_args = array()) |
|
| 1767 | - { |
|
| 1768 | - if (! $this->txn_page_url) { |
|
| 1769 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | - } |
|
| 1771 | - if ($query_args) { |
|
| 1772 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | - } else { |
|
| 1774 | - return $this->txn_page_url; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * gets/returns URL for EE thank_you_page |
|
| 1781 | - * |
|
| 1782 | - * @param array $query_args like what gets passed to |
|
| 1783 | - * add_query_arg() as the first argument |
|
| 1784 | - * @access public |
|
| 1785 | - * @return string |
|
| 1786 | - */ |
|
| 1787 | - public function thank_you_page_url($query_args = array()) |
|
| 1788 | - { |
|
| 1789 | - if (! $this->thank_you_page_url) { |
|
| 1790 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | - } |
|
| 1792 | - if ($query_args) { |
|
| 1793 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | - } else { |
|
| 1795 | - return $this->thank_you_page_url; |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * gets/returns URL for EE cancel_page |
|
| 1802 | - * |
|
| 1803 | - * @access public |
|
| 1804 | - * @return string |
|
| 1805 | - */ |
|
| 1806 | - public function cancel_page_url() |
|
| 1807 | - { |
|
| 1808 | - if (! $this->cancel_page_url) { |
|
| 1809 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | - } |
|
| 1811 | - return $this->cancel_page_url; |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - /** |
|
| 1816 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | - * |
|
| 1818 | - * @since 4.7.5 |
|
| 1819 | - */ |
|
| 1820 | - protected function _reset_urls() |
|
| 1821 | - { |
|
| 1822 | - $this->reg_page_url = ''; |
|
| 1823 | - $this->txn_page_url = ''; |
|
| 1824 | - $this->cancel_page_url = ''; |
|
| 1825 | - $this->thank_you_page_url = ''; |
|
| 1826 | - } |
|
| 1827 | - |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | - * on the main site only. |
|
| 1833 | - * |
|
| 1834 | - * @return bool |
|
| 1835 | - */ |
|
| 1836 | - protected function _get_main_ee_ueip_optin() |
|
| 1837 | - { |
|
| 1838 | - // if this is the main site then we can just bypass our direct query. |
|
| 1839 | - if (is_main_site()) { |
|
| 1840 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | - } |
|
| 1842 | - // is this already cached for this request? If so use it. |
|
| 1843 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | - } |
|
| 1846 | - global $wpdb; |
|
| 1847 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | - $option = self::OPTION_NAME_UXIP; |
|
| 1850 | - // set correct table for query |
|
| 1851 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | - // for the purpose of caching. |
|
| 1857 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | - if (false !== $pre) { |
|
| 1859 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | - } |
|
| 1862 | - $row = $wpdb->get_row( |
|
| 1863 | - $wpdb->prepare( |
|
| 1864 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | - $option |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - if (is_object($row)) { |
|
| 1869 | - $value = $row->option_value; |
|
| 1870 | - } else { // option does not exist so use default. |
|
| 1871 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | - } |
|
| 1874 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * Utility function for escaping the value of a property and returning. |
|
| 1881 | - * |
|
| 1882 | - * @param string $property property name (checks to see if exists). |
|
| 1883 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | - * @throws \EE_Error |
|
| 1885 | - */ |
|
| 1886 | - public function get_pretty($property) |
|
| 1887 | - { |
|
| 1888 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | - } |
|
| 1891 | - return parent::get_pretty($property); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | - * on the object. |
|
| 1898 | - * |
|
| 1899 | - * @return array |
|
| 1900 | - */ |
|
| 1901 | - public function __sleep() |
|
| 1902 | - { |
|
| 1903 | - // reset all url properties |
|
| 1904 | - $this->_reset_urls(); |
|
| 1905 | - // return what to save to db |
|
| 1906 | - return array_keys(get_object_vars($this)); |
|
| 1907 | - } |
|
| 1908 | -} |
|
| 1909 | - |
|
| 1910 | -/** |
|
| 1911 | - * Config class for storing info on the Organization |
|
| 1912 | - */ |
|
| 1913 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | -{ |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * @var string $name |
|
| 1918 | - * eg EE4.1 |
|
| 1919 | - */ |
|
| 1920 | - public $name; |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * @var string $address_1 |
|
| 1924 | - * eg 123 Onna Road |
|
| 1925 | - */ |
|
| 1926 | - public $address_1 = ''; |
|
| 1927 | - |
|
| 1928 | - /** |
|
| 1929 | - * @var string $address_2 |
|
| 1930 | - * eg PO Box 123 |
|
| 1931 | - */ |
|
| 1932 | - public $address_2 = ''; |
|
| 1933 | - |
|
| 1934 | - /** |
|
| 1935 | - * @var string $city |
|
| 1936 | - * eg Inna City |
|
| 1937 | - */ |
|
| 1938 | - public $city = ''; |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * @var int $STA_ID |
|
| 1942 | - * eg 4 |
|
| 1943 | - */ |
|
| 1944 | - public $STA_ID = 0; |
|
| 1945 | - |
|
| 1946 | - /** |
|
| 1947 | - * @var string $CNT_ISO |
|
| 1948 | - * eg US |
|
| 1949 | - */ |
|
| 1950 | - public $CNT_ISO = ''; |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @var string $zip |
|
| 1954 | - * eg 12345 or V1A 2B3 |
|
| 1955 | - */ |
|
| 1956 | - public $zip = ''; |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * @var string $email |
|
| 1960 | - * eg [email protected] |
|
| 1961 | - */ |
|
| 1962 | - public $email; |
|
| 1963 | - |
|
| 1964 | - /** |
|
| 1965 | - * @var string $phone |
|
| 1966 | - * eg. 111-111-1111 |
|
| 1967 | - */ |
|
| 1968 | - public $phone = ''; |
|
| 1969 | - |
|
| 1970 | - /** |
|
| 1971 | - * @var string $vat |
|
| 1972 | - * VAT/Tax Number |
|
| 1973 | - */ |
|
| 1974 | - public $vat = ''; |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @var string $logo_url |
|
| 1978 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | - */ |
|
| 1980 | - public $logo_url = ''; |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | - * |
|
| 1985 | - * @var string |
|
| 1986 | - */ |
|
| 1987 | - /** |
|
| 1988 | - * facebook (facebook.com/profile.name) |
|
| 1989 | - * |
|
| 1990 | - * @var string |
|
| 1991 | - */ |
|
| 1992 | - public $facebook = ''; |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * twitter (twitter.com/twitter_handle) |
|
| 1996 | - * |
|
| 1997 | - * @var string |
|
| 1998 | - */ |
|
| 1999 | - public $twitter = ''; |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | - * |
|
| 2004 | - * @var string |
|
| 2005 | - */ |
|
| 2006 | - public $linkedin = ''; |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | - * |
|
| 2011 | - * @var string |
|
| 2012 | - */ |
|
| 2013 | - public $pinterest = ''; |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * google+ (google.com/+profileName) |
|
| 2017 | - * |
|
| 2018 | - * @var string |
|
| 2019 | - */ |
|
| 2020 | - public $google = ''; |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * instagram (instagram.com/handle) |
|
| 2024 | - * |
|
| 2025 | - * @var string |
|
| 2026 | - */ |
|
| 2027 | - public $instagram = ''; |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * class constructor |
|
| 2032 | - * |
|
| 2033 | - * @access public |
|
| 2034 | - */ |
|
| 2035 | - public function __construct() |
|
| 2036 | - { |
|
| 2037 | - // set default organization settings |
|
| 2038 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | - $this->email = get_bloginfo('admin_email'); |
|
| 2041 | - } |
|
| 2042 | -} |
|
| 2043 | - |
|
| 2044 | -/** |
|
| 2045 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | - */ |
|
| 2047 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | -{ |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * @var string $code |
|
| 2052 | - * eg 'US' |
|
| 2053 | - */ |
|
| 2054 | - public $code; |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * @var string $name |
|
| 2058 | - * eg 'Dollar' |
|
| 2059 | - */ |
|
| 2060 | - public $name; |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * plural name |
|
| 2064 | - * |
|
| 2065 | - * @var string $plural |
|
| 2066 | - * eg 'Dollars' |
|
| 2067 | - */ |
|
| 2068 | - public $plural; |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * currency sign |
|
| 2072 | - * |
|
| 2073 | - * @var string $sign |
|
| 2074 | - * eg '$' |
|
| 2075 | - */ |
|
| 2076 | - public $sign; |
|
| 2077 | - |
|
| 2078 | - /** |
|
| 2079 | - * Whether the currency sign should come before the number or not |
|
| 2080 | - * |
|
| 2081 | - * @var boolean $sign_b4 |
|
| 2082 | - */ |
|
| 2083 | - public $sign_b4; |
|
| 2084 | - |
|
| 2085 | - /** |
|
| 2086 | - * How many digits should come after the decimal place |
|
| 2087 | - * |
|
| 2088 | - * @var int $dec_plc |
|
| 2089 | - */ |
|
| 2090 | - public $dec_plc; |
|
| 2091 | - |
|
| 2092 | - /** |
|
| 2093 | - * Symbol to use for decimal mark |
|
| 2094 | - * |
|
| 2095 | - * @var string $dec_mrk |
|
| 2096 | - * eg '.' |
|
| 2097 | - */ |
|
| 2098 | - public $dec_mrk; |
|
| 2099 | - |
|
| 2100 | - /** |
|
| 2101 | - * Symbol to use for thousands |
|
| 2102 | - * |
|
| 2103 | - * @var string $thsnds |
|
| 2104 | - * eg ',' |
|
| 2105 | - */ |
|
| 2106 | - public $thsnds; |
|
| 2107 | - |
|
| 2108 | - |
|
| 2109 | - /** |
|
| 2110 | - * class constructor |
|
| 2111 | - * |
|
| 2112 | - * @access public |
|
| 2113 | - * @param string $CNT_ISO |
|
| 2114 | - * @throws \EE_Error |
|
| 2115 | - */ |
|
| 2116 | - public function __construct($CNT_ISO = '') |
|
| 2117 | - { |
|
| 2118 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | - // get country code from organization settings or use default |
|
| 2121 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | - : ''; |
|
| 2125 | - // but override if requested |
|
| 2126 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | - if (! empty($CNT_ISO) |
|
| 2129 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | - ) { |
|
| 2132 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | - if ($country instanceof EE_Country) { |
|
| 2135 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | - if (empty($this->code)) { |
|
| 2150 | - // set default currency settings |
|
| 2151 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | - $this->sign = '$'; // currency sign: $ |
|
| 2155 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | -} |
|
| 2162 | - |
|
| 2163 | -/** |
|
| 2164 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | - */ |
|
| 2166 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | -{ |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * Default registration status |
|
| 2171 | - * |
|
| 2172 | - * @var string $default_STS_ID |
|
| 2173 | - * eg 'RPP' |
|
| 2174 | - */ |
|
| 2175 | - public $default_STS_ID; |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | - * registrations) |
|
| 2180 | - * |
|
| 2181 | - * @var int |
|
| 2182 | - */ |
|
| 2183 | - public $default_maximum_number_of_tickets; |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * level of validation to apply to email addresses |
|
| 2187 | - * |
|
| 2188 | - * @var string $email_validation_level |
|
| 2189 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | - */ |
|
| 2191 | - public $email_validation_level; |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | - * |
|
| 2196 | - * @var boolean $show_pending_payment_options |
|
| 2197 | - */ |
|
| 2198 | - public $show_pending_payment_options; |
|
| 2199 | - |
|
| 2200 | - /** |
|
| 2201 | - * Whether to skip the registration confirmation page |
|
| 2202 | - * |
|
| 2203 | - * @var boolean $skip_reg_confirmation |
|
| 2204 | - */ |
|
| 2205 | - public $skip_reg_confirmation; |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * an array of SPCO reg steps where: |
|
| 2209 | - * the keys denotes the reg step order |
|
| 2210 | - * each element consists of an array with the following elements: |
|
| 2211 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | - * "slug" => the URL param used to trigger the reg step |
|
| 2214 | - * |
|
| 2215 | - * @var array $reg_steps |
|
| 2216 | - */ |
|
| 2217 | - public $reg_steps; |
|
| 2218 | - |
|
| 2219 | - /** |
|
| 2220 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | - * |
|
| 2222 | - * @var boolean $reg_confirmation_last |
|
| 2223 | - */ |
|
| 2224 | - public $reg_confirmation_last; |
|
| 2225 | - |
|
| 2226 | - /** |
|
| 2227 | - * Whether or not to enable the EE Bot Trap |
|
| 2228 | - * |
|
| 2229 | - * @var boolean $use_bot_trap |
|
| 2230 | - */ |
|
| 2231 | - public $use_bot_trap; |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | - * |
|
| 2236 | - * @var boolean $use_encryption |
|
| 2237 | - */ |
|
| 2238 | - public $use_encryption; |
|
| 2239 | - |
|
| 2240 | - /** |
|
| 2241 | - * Whether or not to use ReCaptcha |
|
| 2242 | - * |
|
| 2243 | - * @var boolean $use_captcha |
|
| 2244 | - */ |
|
| 2245 | - public $use_captcha; |
|
| 2246 | - |
|
| 2247 | - /** |
|
| 2248 | - * ReCaptcha Theme |
|
| 2249 | - * |
|
| 2250 | - * @var string $recaptcha_theme |
|
| 2251 | - * options: 'dark', 'light', 'invisible' |
|
| 2252 | - */ |
|
| 2253 | - public $recaptcha_theme; |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | - * |
|
| 2258 | - * @var string $recaptcha_badge |
|
| 2259 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | - */ |
|
| 2261 | - public $recaptcha_badge; |
|
| 17 | + const OPTION_NAME = 'ee_config'; |
|
| 18 | + |
|
| 19 | + const LOG_NAME = 'ee_config_log'; |
|
| 20 | + |
|
| 21 | + const LOG_LENGTH = 100; |
|
| 22 | + |
|
| 23 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * instance of the EE_Config object |
|
| 27 | + * |
|
| 28 | + * @var EE_Config $_instance |
|
| 29 | + * @access private |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var boolean $_logging_enabled |
|
| 35 | + */ |
|
| 36 | + private static $_logging_enabled = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 40 | + */ |
|
| 41 | + private $legacy_shortcodes_manager; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * An StdClass whose property names are addon slugs, |
|
| 45 | + * and values are their config classes |
|
| 46 | + * |
|
| 47 | + * @var StdClass |
|
| 48 | + */ |
|
| 49 | + public $addons; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Admin_Config |
|
| 53 | + */ |
|
| 54 | + public $admin; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Core_Config |
|
| 58 | + */ |
|
| 59 | + public $core; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var EE_Currency_Config |
|
| 63 | + */ |
|
| 64 | + public $currency; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var EE_Organization_Config |
|
| 68 | + */ |
|
| 69 | + public $organization; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var EE_Registration_Config |
|
| 73 | + */ |
|
| 74 | + public $registration; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var EE_Template_Config |
|
| 78 | + */ |
|
| 79 | + public $template_settings; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Holds EE environment values. |
|
| 83 | + * |
|
| 84 | + * @var EE_Environment_Config |
|
| 85 | + */ |
|
| 86 | + public $environment; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * settings pertaining to Google maps |
|
| 90 | + * |
|
| 91 | + * @var EE_Map_Config |
|
| 92 | + */ |
|
| 93 | + public $map_settings; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Taxes |
|
| 97 | + * |
|
| 98 | + * @var EE_Tax_Config |
|
| 99 | + */ |
|
| 100 | + public $tax_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Settings pertaining to global messages settings. |
|
| 104 | + * |
|
| 105 | + * @var EE_Messages_Config |
|
| 106 | + */ |
|
| 107 | + public $messages; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @deprecated |
|
| 111 | + * @var EE_Gateway_Config |
|
| 112 | + */ |
|
| 113 | + public $gateway; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var array $_addon_option_names |
|
| 117 | + * @access private |
|
| 118 | + */ |
|
| 119 | + private $_addon_option_names = array(); |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @var array $_module_route_map |
|
| 123 | + * @access private |
|
| 124 | + */ |
|
| 125 | + private static $_module_route_map = array(); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array $_module_forward_map |
|
| 129 | + * @access private |
|
| 130 | + */ |
|
| 131 | + private static $_module_forward_map = array(); |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @var array $_module_view_map |
|
| 135 | + * @access private |
|
| 136 | + */ |
|
| 137 | + private static $_module_view_map = array(); |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @singleton method used to instantiate class object |
|
| 142 | + * @access public |
|
| 143 | + * @return EE_Config instance |
|
| 144 | + */ |
|
| 145 | + public static function instance() |
|
| 146 | + { |
|
| 147 | + // check if class object is instantiated, and instantiated properly |
|
| 148 | + if (! self::$_instance instanceof EE_Config) { |
|
| 149 | + self::$_instance = new self(); |
|
| 150 | + } |
|
| 151 | + return self::$_instance; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Resets the config |
|
| 157 | + * |
|
| 158 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 159 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 160 | + * reflect its state in the database |
|
| 161 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 162 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 163 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 164 | + * site was put into maintenance mode) |
|
| 165 | + * @return EE_Config |
|
| 166 | + */ |
|
| 167 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 168 | + { |
|
| 169 | + if (self::$_instance instanceof EE_Config) { |
|
| 170 | + if ($hard_reset) { |
|
| 171 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 172 | + self::$_instance->_addon_option_names = array(); |
|
| 173 | + self::$_instance->_initialize_config(); |
|
| 174 | + self::$_instance->update_espresso_config(); |
|
| 175 | + } |
|
| 176 | + self::$_instance->update_addon_option_names(); |
|
| 177 | + } |
|
| 178 | + self::$_instance = null; |
|
| 179 | + // we don't need to reset the static properties imo because those should |
|
| 180 | + // only change when a module is added or removed. Currently we don't |
|
| 181 | + // support removing a module during a request when it previously existed |
|
| 182 | + if ($reinstantiate) { |
|
| 183 | + return self::instance(); |
|
| 184 | + } else { |
|
| 185 | + return null; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * class constructor |
|
| 192 | + * |
|
| 193 | + * @access private |
|
| 194 | + */ |
|
| 195 | + private function __construct() |
|
| 196 | + { |
|
| 197 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 198 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 199 | + // setup empty config classes |
|
| 200 | + $this->_initialize_config(); |
|
| 201 | + // load existing EE site settings |
|
| 202 | + $this->_load_core_config(); |
|
| 203 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 204 | + $this->_verify_config(); |
|
| 205 | + // register shortcodes and modules |
|
| 206 | + add_action( |
|
| 207 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 208 | + array($this, 'register_shortcodes_and_modules'), |
|
| 209 | + 999 |
|
| 210 | + ); |
|
| 211 | + // initialize shortcodes and modules |
|
| 212 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 213 | + // register widgets |
|
| 214 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 215 | + // shutdown |
|
| 216 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 217 | + // construct__end hook |
|
| 218 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 219 | + // hardcoded hack |
|
| 220 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return boolean |
|
| 226 | + */ |
|
| 227 | + public static function logging_enabled() |
|
| 228 | + { |
|
| 229 | + return self::$_logging_enabled; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * use to get the current theme if needed from static context |
|
| 235 | + * |
|
| 236 | + * @return string current theme set. |
|
| 237 | + */ |
|
| 238 | + public static function get_current_theme() |
|
| 239 | + { |
|
| 240 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 241 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * _initialize_config |
|
| 247 | + * |
|
| 248 | + * @access private |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + private function _initialize_config() |
|
| 252 | + { |
|
| 253 | + EE_Config::trim_log(); |
|
| 254 | + // set defaults |
|
| 255 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 256 | + $this->addons = new stdClass(); |
|
| 257 | + // set _module_route_map |
|
| 258 | + EE_Config::$_module_route_map = array(); |
|
| 259 | + // set _module_forward_map |
|
| 260 | + EE_Config::$_module_forward_map = array(); |
|
| 261 | + // set _module_view_map |
|
| 262 | + EE_Config::$_module_view_map = array(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * load core plugin configuration |
|
| 268 | + * |
|
| 269 | + * @access private |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + private function _load_core_config() |
|
| 273 | + { |
|
| 274 | + // load_core_config__start hook |
|
| 275 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 276 | + $espresso_config = $this->get_espresso_config(); |
|
| 277 | + foreach ($espresso_config as $config => $settings) { |
|
| 278 | + // load_core_config__start hook |
|
| 279 | + $settings = apply_filters( |
|
| 280 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 281 | + $settings, |
|
| 282 | + $config, |
|
| 283 | + $this |
|
| 284 | + ); |
|
| 285 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 286 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 287 | + // call configs populate method to ensure any defaults are set for empty values. |
|
| 288 | + if (method_exists($settings, 'populate')) { |
|
| 289 | + $this->{$config}->populate(); |
|
| 290 | + } |
|
| 291 | + if (method_exists($settings, 'do_hooks')) { |
|
| 292 | + $this->{$config}->do_hooks(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 297 | + $this->update_espresso_config(); |
|
| 298 | + } |
|
| 299 | + // load_core_config__end hook |
|
| 300 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * _verify_config |
|
| 306 | + * |
|
| 307 | + * @access protected |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + protected function _verify_config() |
|
| 311 | + { |
|
| 312 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 313 | + ? $this->core |
|
| 314 | + : new EE_Core_Config(); |
|
| 315 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 316 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 317 | + ? $this->organization |
|
| 318 | + : new EE_Organization_Config(); |
|
| 319 | + $this->organization = apply_filters( |
|
| 320 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 321 | + $this->organization |
|
| 322 | + ); |
|
| 323 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 324 | + ? $this->currency |
|
| 325 | + : new EE_Currency_Config(); |
|
| 326 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 327 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 328 | + ? $this->registration |
|
| 329 | + : new EE_Registration_Config(); |
|
| 330 | + $this->registration = apply_filters( |
|
| 331 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 332 | + $this->registration |
|
| 333 | + ); |
|
| 334 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 335 | + ? $this->admin |
|
| 336 | + : new EE_Admin_Config(); |
|
| 337 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 338 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 339 | + ? $this->template_settings |
|
| 340 | + : new EE_Template_Config(); |
|
| 341 | + $this->template_settings = apply_filters( |
|
| 342 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 343 | + $this->template_settings |
|
| 344 | + ); |
|
| 345 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 346 | + ? $this->map_settings |
|
| 347 | + : new EE_Map_Config(); |
|
| 348 | + $this->map_settings = apply_filters( |
|
| 349 | + 'FHEE__EE_Config___initialize_config__map_settings', |
|
| 350 | + $this->map_settings |
|
| 351 | + ); |
|
| 352 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 353 | + ? $this->environment |
|
| 354 | + : new EE_Environment_Config(); |
|
| 355 | + $this->environment = apply_filters( |
|
| 356 | + 'FHEE__EE_Config___initialize_config__environment', |
|
| 357 | + $this->environment |
|
| 358 | + ); |
|
| 359 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 360 | + ? $this->tax_settings |
|
| 361 | + : new EE_Tax_Config(); |
|
| 362 | + $this->tax_settings = apply_filters( |
|
| 363 | + 'FHEE__EE_Config___initialize_config__tax_settings', |
|
| 364 | + $this->tax_settings |
|
| 365 | + ); |
|
| 366 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 367 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 368 | + ? $this->messages |
|
| 369 | + : new EE_Messages_Config(); |
|
| 370 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 371 | + ? $this->gateway |
|
| 372 | + : new EE_Gateway_Config(); |
|
| 373 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 374 | + $this->legacy_shortcodes_manager = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * get_espresso_config |
|
| 380 | + * |
|
| 381 | + * @access public |
|
| 382 | + * @return array of espresso config stuff |
|
| 383 | + */ |
|
| 384 | + public function get_espresso_config() |
|
| 385 | + { |
|
| 386 | + // grab espresso configuration |
|
| 387 | + return apply_filters( |
|
| 388 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 389 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * double_check_config_comparison |
|
| 396 | + * |
|
| 397 | + * @access public |
|
| 398 | + * @param string $option |
|
| 399 | + * @param $old_value |
|
| 400 | + * @param $value |
|
| 401 | + */ |
|
| 402 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 403 | + { |
|
| 404 | + // make sure we're checking the ee config |
|
| 405 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 406 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 407 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 408 | + if ($value != $old_value) { |
|
| 409 | + // if they are NOT the same, then remove the hook, |
|
| 410 | + // which means the subsequent update results will be based solely on the update query results |
|
| 411 | + // the reason we do this is because, as stated above, |
|
| 412 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 413 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 414 | + // If values are found to match their previous old value, |
|
| 415 | + // then WP bails before performing any update. |
|
| 416 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 417 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 418 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 419 | + // MySQL MAY ALSO NOT perform the update because |
|
| 420 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 421 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 422 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 423 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * update_espresso_config |
|
| 431 | + * |
|
| 432 | + * @access public |
|
| 433 | + */ |
|
| 434 | + protected function _reset_espresso_addon_config() |
|
| 435 | + { |
|
| 436 | + $this->_addon_option_names = array(); |
|
| 437 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 438 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 439 | + if ($addon_config_obj instanceof EE_Config_Base) { |
|
| 440 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 441 | + } |
|
| 442 | + $this->addons->{$addon_name} = null; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * update_espresso_config |
|
| 449 | + * |
|
| 450 | + * @access public |
|
| 451 | + * @param bool $add_success |
|
| 452 | + * @param bool $add_error |
|
| 453 | + * @return bool |
|
| 454 | + */ |
|
| 455 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 456 | + { |
|
| 457 | + // don't allow config updates during WP heartbeats |
|
| 458 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 462 | + // $clone = clone( self::$_instance ); |
|
| 463 | + // self::$_instance = NULL; |
|
| 464 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 465 | + $this->_reset_espresso_addon_config(); |
|
| 466 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 467 | + // but BEFORE the actual update occurs |
|
| 468 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 469 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 470 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 471 | + $this->legacy_shortcodes_manager = null; |
|
| 472 | + // now update "ee_config" |
|
| 473 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 474 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 475 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 476 | + // if not saved... check if the hook we just added still exists; |
|
| 477 | + // if it does, it means one of two things: |
|
| 478 | + // that update_option bailed at the($value === $old_value) conditional, |
|
| 479 | + // or... |
|
| 480 | + // the db update query returned 0 rows affected |
|
| 481 | + // (probably because the data value was the same from it's perspective) |
|
| 482 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 483 | + // but just means no update occurred, so don't display an error to the user. |
|
| 484 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 485 | + // then it means that something truly went wrong |
|
| 486 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 487 | + // remove our action since we don't want it in the system anymore |
|
| 488 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 489 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 490 | + // self::$_instance = $clone; |
|
| 491 | + // unset( $clone ); |
|
| 492 | + // if config remains the same or was updated successfully |
|
| 493 | + if ($saved) { |
|
| 494 | + if ($add_success) { |
|
| 495 | + EE_Error::add_success( |
|
| 496 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 497 | + __FILE__, |
|
| 498 | + __FUNCTION__, |
|
| 499 | + __LINE__ |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + return true; |
|
| 503 | + } else { |
|
| 504 | + if ($add_error) { |
|
| 505 | + EE_Error::add_error( |
|
| 506 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 507 | + __FILE__, |
|
| 508 | + __FUNCTION__, |
|
| 509 | + __LINE__ |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * _verify_config_params |
|
| 519 | + * |
|
| 520 | + * @access private |
|
| 521 | + * @param string $section |
|
| 522 | + * @param string $name |
|
| 523 | + * @param string $config_class |
|
| 524 | + * @param EE_Config_Base $config_obj |
|
| 525 | + * @param array $tests_to_run |
|
| 526 | + * @param bool $display_errors |
|
| 527 | + * @return bool TRUE on success, FALSE on fail |
|
| 528 | + */ |
|
| 529 | + private function _verify_config_params( |
|
| 530 | + $section = '', |
|
| 531 | + $name = '', |
|
| 532 | + $config_class = '', |
|
| 533 | + $config_obj = null, |
|
| 534 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 535 | + $display_errors = true |
|
| 536 | + ) { |
|
| 537 | + try { |
|
| 538 | + foreach ($tests_to_run as $test) { |
|
| 539 | + switch ($test) { |
|
| 540 | + // TEST #1 : check that section was set |
|
| 541 | + case 1: |
|
| 542 | + if (empty($section)) { |
|
| 543 | + if ($display_errors) { |
|
| 544 | + throw new EE_Error( |
|
| 545 | + sprintf( |
|
| 546 | + __( |
|
| 547 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ), |
|
| 550 | + $config_class |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + break; |
|
| 557 | + // TEST #2 : check that settings section exists |
|
| 558 | + case 2: |
|
| 559 | + if (! isset($this->{$section})) { |
|
| 560 | + if ($display_errors) { |
|
| 561 | + throw new EE_Error( |
|
| 562 | + sprintf( |
|
| 563 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 564 | + $section |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + } |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + break; |
|
| 571 | + // TEST #3 : check that section is the proper format |
|
| 572 | + case 3: |
|
| 573 | + if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 574 | + ) { |
|
| 575 | + if ($display_errors) { |
|
| 576 | + throw new EE_Error( |
|
| 577 | + sprintf( |
|
| 578 | + __( |
|
| 579 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $section |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + return false; |
|
| 587 | + } |
|
| 588 | + break; |
|
| 589 | + // TEST #4 : check that config section name has been set |
|
| 590 | + case 4: |
|
| 591 | + if (empty($name)) { |
|
| 592 | + if ($display_errors) { |
|
| 593 | + throw new EE_Error( |
|
| 594 | + __( |
|
| 595 | + 'No name has been provided for the specific configuration section.', |
|
| 596 | + 'event_espresso' |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + break; |
|
| 603 | + // TEST #5 : check that a config class name has been set |
|
| 604 | + case 5: |
|
| 605 | + if (empty($config_class)) { |
|
| 606 | + if ($display_errors) { |
|
| 607 | + throw new EE_Error( |
|
| 608 | + __( |
|
| 609 | + 'No class name has been provided for the specific configuration section.', |
|
| 610 | + 'event_espresso' |
|
| 611 | + ) |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 616 | + break; |
|
| 617 | + // TEST #6 : verify config class is accessible |
|
| 618 | + case 6: |
|
| 619 | + if (! class_exists($config_class)) { |
|
| 620 | + if ($display_errors) { |
|
| 621 | + throw new EE_Error( |
|
| 622 | + sprintf( |
|
| 623 | + __( |
|
| 624 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 625 | + 'event_espresso' |
|
| 626 | + ), |
|
| 627 | + $config_class |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + // TEST #7 : check that config has even been set |
|
| 635 | + case 7: |
|
| 636 | + if (! isset($this->{$section}->{$name})) { |
|
| 637 | + if ($display_errors) { |
|
| 638 | + throw new EE_Error( |
|
| 639 | + sprintf( |
|
| 640 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 641 | + $section, |
|
| 642 | + $name |
|
| 643 | + ) |
|
| 644 | + ); |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } else { |
|
| 648 | + // and make sure it's not serialized |
|
| 649 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 650 | + } |
|
| 651 | + break; |
|
| 652 | + // TEST #8 : check that config is the requested type |
|
| 653 | + case 8: |
|
| 654 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | + if ($display_errors) { |
|
| 656 | + throw new EE_Error( |
|
| 657 | + sprintf( |
|
| 658 | + __( |
|
| 659 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 660 | + 'event_espresso' |
|
| 661 | + ), |
|
| 662 | + $section, |
|
| 663 | + $name, |
|
| 664 | + $config_class |
|
| 665 | + ) |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + break; |
|
| 671 | + // TEST #9 : verify config object |
|
| 672 | + case 9: |
|
| 673 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | + if ($display_errors) { |
|
| 675 | + throw new EE_Error( |
|
| 676 | + sprintf( |
|
| 677 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 678 | + print_r($config_obj, true) |
|
| 679 | + ) |
|
| 680 | + ); |
|
| 681 | + } |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + break; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } catch (EE_Error $e) { |
|
| 688 | + $e->get_error(); |
|
| 689 | + } |
|
| 690 | + // you have successfully run the gauntlet |
|
| 691 | + return true; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * _generate_config_option_name |
|
| 697 | + * |
|
| 698 | + * @access protected |
|
| 699 | + * @param string $section |
|
| 700 | + * @param string $name |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 704 | + { |
|
| 705 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * _set_config_class |
|
| 711 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 712 | + * |
|
| 713 | + * @access private |
|
| 714 | + * @param string $config_class |
|
| 715 | + * @param string $name |
|
| 716 | + * @return string |
|
| 717 | + */ |
|
| 718 | + private function _set_config_class($config_class = '', $name = '') |
|
| 719 | + { |
|
| 720 | + return ! empty($config_class) |
|
| 721 | + ? $config_class |
|
| 722 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * set_config |
|
| 728 | + * |
|
| 729 | + * @access protected |
|
| 730 | + * @param string $section |
|
| 731 | + * @param string $name |
|
| 732 | + * @param string $config_class |
|
| 733 | + * @param EE_Config_Base $config_obj |
|
| 734 | + * @return EE_Config_Base |
|
| 735 | + */ |
|
| 736 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 737 | + { |
|
| 738 | + // ensure config class is set to something |
|
| 739 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 740 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 741 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | + return null; |
|
| 743 | + } |
|
| 744 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 745 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 746 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 747 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 748 | + $this->update_addon_option_names(); |
|
| 749 | + } |
|
| 750 | + // verify the incoming config object but suppress errors |
|
| 751 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | + $config_obj = new $config_class(); |
|
| 753 | + } |
|
| 754 | + if (get_option($config_option_name)) { |
|
| 755 | + EE_Config::log($config_option_name); |
|
| 756 | + update_option($config_option_name, $config_obj); |
|
| 757 | + $this->{$section}->{$name} = $config_obj; |
|
| 758 | + return $this->{$section}->{$name}; |
|
| 759 | + } else { |
|
| 760 | + // create a wp-option for this config |
|
| 761 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 762 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 763 | + return $this->{$section}->{$name}; |
|
| 764 | + } else { |
|
| 765 | + EE_Error::add_error( |
|
| 766 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 767 | + __FILE__, |
|
| 768 | + __FUNCTION__, |
|
| 769 | + __LINE__ |
|
| 770 | + ); |
|
| 771 | + return null; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * update_config |
|
| 779 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @param string $section |
|
| 783 | + * @param string $name |
|
| 784 | + * @param EE_Config_Base|string $config_obj |
|
| 785 | + * @param bool $throw_errors |
|
| 786 | + * @return bool |
|
| 787 | + */ |
|
| 788 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 789 | + { |
|
| 790 | + // don't allow config updates during WP heartbeats |
|
| 791 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + $config_obj = maybe_unserialize($config_obj); |
|
| 795 | + // get class name of the incoming object |
|
| 796 | + $config_class = get_class($config_obj); |
|
| 797 | + // run tests 1-5 and 9 to verify config |
|
| 798 | + if (! $this->_verify_config_params( |
|
| 799 | + $section, |
|
| 800 | + $name, |
|
| 801 | + $config_class, |
|
| 802 | + $config_obj, |
|
| 803 | + array(1, 2, 3, 4, 7, 9) |
|
| 804 | + ) |
|
| 805 | + ) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 809 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 810 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 811 | + // save new config to db |
|
| 812 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 813 | + return true; |
|
| 814 | + } |
|
| 815 | + } else { |
|
| 816 | + // first check if the record already exists |
|
| 817 | + $existing_config = get_option($config_option_name); |
|
| 818 | + $config_obj = serialize($config_obj); |
|
| 819 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 820 | + if ($existing_config == $config_obj) { |
|
| 821 | + $this->{$section}->{$name} = $config_obj; |
|
| 822 | + return true; |
|
| 823 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 824 | + EE_Config::log($config_option_name); |
|
| 825 | + // update wp-option for this config class |
|
| 826 | + $this->{$section}->{$name} = $config_obj; |
|
| 827 | + return true; |
|
| 828 | + } elseif ($throw_errors) { |
|
| 829 | + EE_Error::add_error( |
|
| 830 | + sprintf( |
|
| 831 | + __( |
|
| 832 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 833 | + 'event_espresso' |
|
| 834 | + ), |
|
| 835 | + $config_class, |
|
| 836 | + 'EE_Config->' . $section . '->' . $name |
|
| 837 | + ), |
|
| 838 | + __FILE__, |
|
| 839 | + __FUNCTION__, |
|
| 840 | + __LINE__ |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + return false; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * get_config |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @param string $section |
|
| 853 | + * @param string $name |
|
| 854 | + * @param string $config_class |
|
| 855 | + * @return mixed EE_Config_Base | NULL |
|
| 856 | + */ |
|
| 857 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 858 | + { |
|
| 859 | + // ensure config class is set to something |
|
| 860 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 861 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 862 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 863 | + return null; |
|
| 864 | + } |
|
| 865 | + // now test if the requested config object exists, but suppress errors |
|
| 866 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 867 | + // config already exists, so pass it back |
|
| 868 | + return $this->{$section}->{$name}; |
|
| 869 | + } |
|
| 870 | + // load config option from db if it exists |
|
| 871 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 872 | + // verify the newly retrieved config object, but suppress errors |
|
| 873 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 874 | + // config is good, so set it and pass it back |
|
| 875 | + $this->{$section}->{$name} = $config_obj; |
|
| 876 | + return $this->{$section}->{$name}; |
|
| 877 | + } |
|
| 878 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 879 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 880 | + // verify the newly created config object |
|
| 881 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 882 | + return $this->{$section}->{$name}; |
|
| 883 | + } else { |
|
| 884 | + EE_Error::add_error( |
|
| 885 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 886 | + __FILE__, |
|
| 887 | + __FUNCTION__, |
|
| 888 | + __LINE__ |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + return null; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * get_config_option |
|
| 897 | + * |
|
| 898 | + * @access public |
|
| 899 | + * @param string $config_option_name |
|
| 900 | + * @return mixed EE_Config_Base | FALSE |
|
| 901 | + */ |
|
| 902 | + public function get_config_option($config_option_name = '') |
|
| 903 | + { |
|
| 904 | + // retrieve the wp-option for this config class. |
|
| 905 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 906 | + if (empty($config_option)) { |
|
| 907 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 908 | + } |
|
| 909 | + return $config_option; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * log |
|
| 915 | + * |
|
| 916 | + * @param string $config_option_name |
|
| 917 | + */ |
|
| 918 | + public static function log($config_option_name = '') |
|
| 919 | + { |
|
| 920 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 921 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 922 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 923 | + $_request = $_REQUEST; |
|
| 924 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 925 | + $config_log[ (string) microtime(true) ] = array( |
|
| 926 | + 'config_name' => $config_option_name, |
|
| 927 | + 'request' => $_request, |
|
| 928 | + ); |
|
| 929 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * trim_log |
|
| 936 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 937 | + */ |
|
| 938 | + public static function trim_log() |
|
| 939 | + { |
|
| 940 | + if (! EE_Config::logging_enabled()) { |
|
| 941 | + return; |
|
| 942 | + } |
|
| 943 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 944 | + $log_length = count($config_log); |
|
| 945 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 946 | + ksort($config_log); |
|
| 947 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 948 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * get_page_for_posts |
|
| 955 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 956 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 957 | + * |
|
| 958 | + * @access public |
|
| 959 | + * @return string |
|
| 960 | + */ |
|
| 961 | + public static function get_page_for_posts() |
|
| 962 | + { |
|
| 963 | + $page_for_posts = get_option('page_for_posts'); |
|
| 964 | + if (! $page_for_posts) { |
|
| 965 | + return 'posts'; |
|
| 966 | + } |
|
| 967 | + /** @type WPDB $wpdb */ |
|
| 968 | + global $wpdb; |
|
| 969 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 970 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * register_shortcodes_and_modules. |
|
| 976 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 977 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 978 | + * so they can help trigger maintenance mode if it's needed |
|
| 979 | + * |
|
| 980 | + * @access public |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + public function register_shortcodes_and_modules() |
|
| 984 | + { |
|
| 985 | + // allow modules to set hooks for the rest of the system |
|
| 986 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * initialize_shortcodes_and_modules |
|
| 992 | + * meaning they can start adding their hooks to get stuff done |
|
| 993 | + * |
|
| 994 | + * @access public |
|
| 995 | + * @return void |
|
| 996 | + */ |
|
| 997 | + public function initialize_shortcodes_and_modules() |
|
| 998 | + { |
|
| 999 | + // allow modules to set hooks for the rest of the system |
|
| 1000 | + $this->_initialize_modules(); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * widgets_init |
|
| 1006 | + * |
|
| 1007 | + * @access private |
|
| 1008 | + * @return void |
|
| 1009 | + */ |
|
| 1010 | + public function widgets_init() |
|
| 1011 | + { |
|
| 1012 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1013 | + // on frontend when not in any maintenance mode |
|
| 1014 | + if (! EE_Maintenance_Mode::instance()->level() |
|
| 1015 | + || ( |
|
| 1016 | + is_admin() |
|
| 1017 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1018 | + ) |
|
| 1019 | + ) { |
|
| 1020 | + // grab list of installed widgets |
|
| 1021 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1022 | + // filter list of modules to register |
|
| 1023 | + $widgets_to_register = apply_filters( |
|
| 1024 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1025 | + $widgets_to_register |
|
| 1026 | + ); |
|
| 1027 | + if (! empty($widgets_to_register)) { |
|
| 1028 | + // cycle thru widget folders |
|
| 1029 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1030 | + // add to list of installed widget modules |
|
| 1031 | + EE_Config::register_ee_widget($widget_path); |
|
| 1032 | + } |
|
| 1033 | + } |
|
| 1034 | + // filter list of installed modules |
|
| 1035 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1036 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1037 | + EE_Registry::instance()->widgets |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * register_ee_widget - makes core aware of this widget |
|
| 1045 | + * |
|
| 1046 | + * @access public |
|
| 1047 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public static function register_ee_widget($widget_path = null) |
|
| 1051 | + { |
|
| 1052 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1053 | + $widget_ext = '.widget.php'; |
|
| 1054 | + // make all separators match |
|
| 1055 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1056 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1057 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1058 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1059 | + $file_name = explode('.', basename($widget_path)); |
|
| 1060 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1061 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1062 | + // sanitize shortcode directory name |
|
| 1063 | + $widget = sanitize_key($widget); |
|
| 1064 | + // now we need to rebuild the shortcode path |
|
| 1065 | + $widget_path = explode(DS, $widget_path); |
|
| 1066 | + // remove last segment |
|
| 1067 | + array_pop($widget_path); |
|
| 1068 | + // glue it back together |
|
| 1069 | + $widget_path = implode(DS, $widget_path); |
|
| 1070 | + } else { |
|
| 1071 | + // grab and sanitize widget directory name |
|
| 1072 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1073 | + } |
|
| 1074 | + // create classname from widget directory name |
|
| 1075 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1076 | + // add class prefix |
|
| 1077 | + $widget_class = 'EEW_' . $widget; |
|
| 1078 | + // does the widget exist ? |
|
| 1079 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1080 | + $msg = sprintf( |
|
| 1081 | + __( |
|
| 1082 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1083 | + 'event_espresso' |
|
| 1084 | + ), |
|
| 1085 | + $widget_class, |
|
| 1086 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1087 | + ); |
|
| 1088 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1089 | + return; |
|
| 1090 | + } |
|
| 1091 | + // load the widget class file |
|
| 1092 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1093 | + // verify that class exists |
|
| 1094 | + if (! class_exists($widget_class)) { |
|
| 1095 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1096 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1097 | + return; |
|
| 1098 | + } |
|
| 1099 | + register_widget($widget_class); |
|
| 1100 | + // add to array of registered widgets |
|
| 1101 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * _register_modules |
|
| 1107 | + * |
|
| 1108 | + * @access private |
|
| 1109 | + * @return array |
|
| 1110 | + */ |
|
| 1111 | + private function _register_modules() |
|
| 1112 | + { |
|
| 1113 | + // grab list of installed modules |
|
| 1114 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1115 | + // filter list of modules to register |
|
| 1116 | + $modules_to_register = apply_filters( |
|
| 1117 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1118 | + $modules_to_register |
|
| 1119 | + ); |
|
| 1120 | + if (! empty($modules_to_register)) { |
|
| 1121 | + // loop through folders |
|
| 1122 | + foreach ($modules_to_register as $module_path) { |
|
| 1123 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1124 | + if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1125 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1126 | + ) { |
|
| 1127 | + // add to list of installed modules |
|
| 1128 | + EE_Config::register_module($module_path); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + // filter list of installed modules |
|
| 1133 | + return apply_filters( |
|
| 1134 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1135 | + EE_Registry::instance()->modules |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * register_module - makes core aware of this module |
|
| 1142 | + * |
|
| 1143 | + * @access public |
|
| 1144 | + * @param string $module_path - full path up to and including module folder |
|
| 1145 | + * @return bool |
|
| 1146 | + */ |
|
| 1147 | + public static function register_module($module_path = null) |
|
| 1148 | + { |
|
| 1149 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1150 | + $module_ext = '.module.php'; |
|
| 1151 | + // make all separators match |
|
| 1152 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1153 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1154 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1155 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1156 | + $module_file = explode('.', basename($module_path)); |
|
| 1157 | + // now we need to rebuild the shortcode path |
|
| 1158 | + $module_path = explode(DS, $module_path); |
|
| 1159 | + // remove last segment |
|
| 1160 | + array_pop($module_path); |
|
| 1161 | + // glue it back together |
|
| 1162 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1163 | + // take first segment from file name pieces and sanitize it |
|
| 1164 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1165 | + // ensure class prefix is added |
|
| 1166 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1167 | + } else { |
|
| 1168 | + // we need to generate the filename based off of the folder name |
|
| 1169 | + // grab and sanitize module name |
|
| 1170 | + $module = strtolower(basename($module_path)); |
|
| 1171 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1172 | + // like trailingslashit() |
|
| 1173 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1174 | + // create classname from module directory name |
|
| 1175 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1176 | + // add class prefix |
|
| 1177 | + $module_class = 'EED_' . $module; |
|
| 1178 | + } |
|
| 1179 | + // does the module exist ? |
|
| 1180 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1181 | + $msg = sprintf( |
|
| 1182 | + __( |
|
| 1183 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1184 | + 'event_espresso' |
|
| 1185 | + ), |
|
| 1186 | + $module |
|
| 1187 | + ); |
|
| 1188 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1189 | + return false; |
|
| 1190 | + } |
|
| 1191 | + // load the module class file |
|
| 1192 | + require_once($module_path . $module_class . $module_ext); |
|
| 1193 | + // verify that class exists |
|
| 1194 | + if (! class_exists($module_class)) { |
|
| 1195 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1196 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1197 | + return false; |
|
| 1198 | + } |
|
| 1199 | + // add to array of registered modules |
|
| 1200 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1201 | + do_action( |
|
| 1202 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1203 | + $module_class, |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1205 | + ); |
|
| 1206 | + return true; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * _initialize_modules |
|
| 1212 | + * allow modules to set hooks for the rest of the system |
|
| 1213 | + * |
|
| 1214 | + * @access private |
|
| 1215 | + * @return void |
|
| 1216 | + */ |
|
| 1217 | + private function _initialize_modules() |
|
| 1218 | + { |
|
| 1219 | + // cycle thru shortcode folders |
|
| 1220 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1221 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1222 | + // which set hooks ? |
|
| 1223 | + if (is_admin()) { |
|
| 1224 | + // fire immediately |
|
| 1225 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1226 | + } else { |
|
| 1227 | + // delay until other systems are online |
|
| 1228 | + add_action( |
|
| 1229 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1230 | + array($module_class, 'set_hooks') |
|
| 1231 | + ); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * register_route - adds module method routes to route_map |
|
| 1239 | + * |
|
| 1240 | + * @access public |
|
| 1241 | + * @param string $route - "pretty" public alias for module method |
|
| 1242 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1243 | + * @param string $method_name - the actual module method to be routed to |
|
| 1244 | + * @param string $key - url param key indicating a route is being called |
|
| 1245 | + * @return bool |
|
| 1246 | + */ |
|
| 1247 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1248 | + { |
|
| 1249 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1250 | + $module = str_replace('EED_', '', $module); |
|
| 1251 | + $module_class = 'EED_' . $module; |
|
| 1252 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1253 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1254 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1255 | + return false; |
|
| 1256 | + } |
|
| 1257 | + if (empty($route)) { |
|
| 1258 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1259 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1260 | + return false; |
|
| 1261 | + } |
|
| 1262 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1263 | + $msg = sprintf( |
|
| 1264 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1265 | + $route |
|
| 1266 | + ); |
|
| 1267 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1271 | + return true; |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * get_route - get module method route |
|
| 1277 | + * |
|
| 1278 | + * @access public |
|
| 1279 | + * @param string $route - "pretty" public alias for module method |
|
| 1280 | + * @param string $key - url param key indicating a route is being called |
|
| 1281 | + * @return string |
|
| 1282 | + */ |
|
| 1283 | + public static function get_route($route = null, $key = 'ee') |
|
| 1284 | + { |
|
| 1285 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1286 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1287 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1288 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1289 | + } |
|
| 1290 | + return null; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * get_routes - get ALL module method routes |
|
| 1296 | + * |
|
| 1297 | + * @access public |
|
| 1298 | + * @return array |
|
| 1299 | + */ |
|
| 1300 | + public static function get_routes() |
|
| 1301 | + { |
|
| 1302 | + return EE_Config::$_module_route_map; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + |
|
| 1306 | + /** |
|
| 1307 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1308 | + * |
|
| 1309 | + * @access public |
|
| 1310 | + * @param string $route - "pretty" public alias for module method |
|
| 1311 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1312 | + * class, allows different forwards to be served based on status |
|
| 1313 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1314 | + * @param string $key - url param key indicating a route is being called |
|
| 1315 | + * @return bool |
|
| 1316 | + */ |
|
| 1317 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1318 | + { |
|
| 1319 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1320 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1321 | + $msg = sprintf( |
|
| 1322 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1323 | + $route |
|
| 1324 | + ); |
|
| 1325 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1326 | + return false; |
|
| 1327 | + } |
|
| 1328 | + if (empty($forward)) { |
|
| 1329 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1330 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1331 | + return false; |
|
| 1332 | + } |
|
| 1333 | + if (is_array($forward)) { |
|
| 1334 | + if (! isset($forward[1])) { |
|
| 1335 | + $msg = sprintf( |
|
| 1336 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1337 | + $route |
|
| 1338 | + ); |
|
| 1339 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1340 | + return false; |
|
| 1341 | + } |
|
| 1342 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1343 | + $msg = sprintf( |
|
| 1344 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1345 | + $forward[1], |
|
| 1346 | + $route |
|
| 1347 | + ); |
|
| 1348 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1349 | + return false; |
|
| 1350 | + } |
|
| 1351 | + } elseif (! function_exists($forward)) { |
|
| 1352 | + $msg = sprintf( |
|
| 1353 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1354 | + $forward, |
|
| 1355 | + $route |
|
| 1356 | + ); |
|
| 1357 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1358 | + return false; |
|
| 1359 | + } |
|
| 1360 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1361 | + return true; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + /** |
|
| 1366 | + * get_forward - get forwarding route |
|
| 1367 | + * |
|
| 1368 | + * @access public |
|
| 1369 | + * @param string $route - "pretty" public alias for module method |
|
| 1370 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1371 | + * allows different forwards to be served based on status |
|
| 1372 | + * @param string $key - url param key indicating a route is being called |
|
| 1373 | + * @return string |
|
| 1374 | + */ |
|
| 1375 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1376 | + { |
|
| 1377 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1378 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1379 | + return apply_filters( |
|
| 1380 | + 'FHEE__EE_Config__get_forward', |
|
| 1381 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1382 | + $route, |
|
| 1383 | + $status |
|
| 1384 | + ); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1392 | + * results |
|
| 1393 | + * |
|
| 1394 | + * @access public |
|
| 1395 | + * @param string $route - "pretty" public alias for module method |
|
| 1396 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1397 | + * allows different views to be served based on status |
|
| 1398 | + * @param string $view |
|
| 1399 | + * @param string $key - url param key indicating a route is being called |
|
| 1400 | + * @return bool |
|
| 1401 | + */ |
|
| 1402 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1403 | + { |
|
| 1404 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1405 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1406 | + $msg = sprintf( |
|
| 1407 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1408 | + $route |
|
| 1409 | + ); |
|
| 1410 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1411 | + return false; |
|
| 1412 | + } |
|
| 1413 | + if (! is_readable($view)) { |
|
| 1414 | + $msg = sprintf( |
|
| 1415 | + __( |
|
| 1416 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1417 | + 'event_espresso' |
|
| 1418 | + ), |
|
| 1419 | + $view |
|
| 1420 | + ); |
|
| 1421 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1422 | + return false; |
|
| 1423 | + } |
|
| 1424 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1425 | + return true; |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * get_view - get view for route and status |
|
| 1431 | + * |
|
| 1432 | + * @access public |
|
| 1433 | + * @param string $route - "pretty" public alias for module method |
|
| 1434 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1435 | + * allows different views to be served based on status |
|
| 1436 | + * @param string $key - url param key indicating a route is being called |
|
| 1437 | + * @return string |
|
| 1438 | + */ |
|
| 1439 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1440 | + { |
|
| 1441 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1442 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1443 | + return apply_filters( |
|
| 1444 | + 'FHEE__EE_Config__get_view', |
|
| 1445 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1446 | + $route, |
|
| 1447 | + $status |
|
| 1448 | + ); |
|
| 1449 | + } |
|
| 1450 | + return null; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + |
|
| 1454 | + public function update_addon_option_names() |
|
| 1455 | + { |
|
| 1456 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + public function shutdown() |
|
| 1461 | + { |
|
| 1462 | + $this->update_addon_option_names(); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * @return LegacyShortcodesManager |
|
| 1468 | + */ |
|
| 1469 | + public static function getLegacyShortcodesManager() |
|
| 1470 | + { |
|
| 1471 | + |
|
| 1472 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1473 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1474 | + EE_Registry::instance() |
|
| 1475 | + ); |
|
| 1476 | + } |
|
| 1477 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * register_shortcode - makes core aware of this shortcode |
|
| 1483 | + * |
|
| 1484 | + * @deprecated 4.9.26 |
|
| 1485 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1486 | + * @return bool |
|
| 1487 | + */ |
|
| 1488 | + public static function register_shortcode($shortcode_path = null) |
|
| 1489 | + { |
|
| 1490 | + EE_Error::doing_it_wrong( |
|
| 1491 | + __METHOD__, |
|
| 1492 | + __( |
|
| 1493 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1494 | + 'event_espresso' |
|
| 1495 | + ), |
|
| 1496 | + '4.9.26' |
|
| 1497 | + ); |
|
| 1498 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1499 | + } |
|
| 1500 | +} |
|
| 2262 | 1501 | |
| 2263 | - /** |
|
| 2264 | - * ReCaptcha Type |
|
| 2265 | - * |
|
| 2266 | - * @var string $recaptcha_type |
|
| 2267 | - * options: 'audio', 'image' |
|
| 2268 | - */ |
|
| 2269 | - public $recaptcha_type; |
|
| 1502 | +/** |
|
| 1503 | + * Base class used for config classes. These classes should generally not have |
|
| 1504 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1505 | + * basically, they should just be well-defined stdClasses |
|
| 1506 | + */ |
|
| 1507 | +class EE_Config_Base |
|
| 1508 | +{ |
|
| 2270 | 1509 | |
| 2271 | - /** |
|
| 2272 | - * ReCaptcha language |
|
| 2273 | - * |
|
| 2274 | - * @var string $recaptcha_language |
|
| 2275 | - * eg 'en' |
|
| 2276 | - */ |
|
| 2277 | - public $recaptcha_language; |
|
| 1510 | + /** |
|
| 1511 | + * Utility function for escaping the value of a property and returning. |
|
| 1512 | + * |
|
| 1513 | + * @param string $property property name (checks to see if exists). |
|
| 1514 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1515 | + * @throws \EE_Error |
|
| 1516 | + */ |
|
| 1517 | + public function get_pretty($property) |
|
| 1518 | + { |
|
| 1519 | + if (! property_exists($this, $property)) { |
|
| 1520 | + throw new EE_Error( |
|
| 1521 | + sprintf( |
|
| 1522 | + __( |
|
| 1523 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1524 | + 'event_espresso' |
|
| 1525 | + ), |
|
| 1526 | + get_class($this), |
|
| 1527 | + $property |
|
| 1528 | + ) |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + // just handling escaping of strings for now. |
|
| 1532 | + if (is_string($this->{$property})) { |
|
| 1533 | + return stripslashes($this->{$property}); |
|
| 1534 | + } |
|
| 1535 | + return $this->{$property}; |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + public function populate() |
|
| 1540 | + { |
|
| 1541 | + // grab defaults via a new instance of this class. |
|
| 1542 | + $class_name = get_class($this); |
|
| 1543 | + $defaults = new $class_name; |
|
| 1544 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1545 | + // default from our $defaults object. |
|
| 1546 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1547 | + if ($this->{$property} === null) { |
|
| 1548 | + $this->{$property} = $value; |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + // cleanup |
|
| 1552 | + unset($defaults); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * __isset |
|
| 1558 | + * |
|
| 1559 | + * @param $a |
|
| 1560 | + * @return bool |
|
| 1561 | + */ |
|
| 1562 | + public function __isset($a) |
|
| 1563 | + { |
|
| 1564 | + return false; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * __unset |
|
| 1570 | + * |
|
| 1571 | + * @param $a |
|
| 1572 | + * @return bool |
|
| 1573 | + */ |
|
| 1574 | + public function __unset($a) |
|
| 1575 | + { |
|
| 1576 | + return false; |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + |
|
| 1580 | + /** |
|
| 1581 | + * __clone |
|
| 1582 | + */ |
|
| 1583 | + public function __clone() |
|
| 1584 | + { |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * __wakeup |
|
| 1590 | + */ |
|
| 1591 | + public function __wakeup() |
|
| 1592 | + { |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * __destruct |
|
| 1598 | + */ |
|
| 1599 | + public function __destruct() |
|
| 1600 | + { |
|
| 1601 | + } |
|
| 1602 | +} |
|
| 2278 | 1603 | |
| 2279 | - /** |
|
| 2280 | - * ReCaptcha public key |
|
| 2281 | - * |
|
| 2282 | - * @var string $recaptcha_publickey |
|
| 2283 | - */ |
|
| 2284 | - public $recaptcha_publickey; |
|
| 1604 | +/** |
|
| 1605 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1606 | + */ |
|
| 1607 | +class EE_Core_Config extends EE_Config_Base |
|
| 1608 | +{ |
|
| 2285 | 1609 | |
| 2286 | - /** |
|
| 2287 | - * ReCaptcha private key |
|
| 2288 | - * |
|
| 2289 | - * @var string $recaptcha_privatekey |
|
| 2290 | - */ |
|
| 2291 | - public $recaptcha_privatekey; |
|
| 1610 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1611 | + |
|
| 1612 | + |
|
| 1613 | + public $current_blog_id; |
|
| 1614 | + |
|
| 1615 | + public $ee_ueip_optin; |
|
| 1616 | + |
|
| 1617 | + public $ee_ueip_has_notified; |
|
| 1618 | + |
|
| 1619 | + /** |
|
| 1620 | + * Not to be confused with the 4 critical page variables (See |
|
| 1621 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1622 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1623 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1624 | + * |
|
| 1625 | + * @var array |
|
| 1626 | + */ |
|
| 1627 | + public $post_shortcodes; |
|
| 1628 | + |
|
| 1629 | + public $module_route_map; |
|
| 1630 | + |
|
| 1631 | + public $module_forward_map; |
|
| 1632 | + |
|
| 1633 | + public $module_view_map; |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1637 | + * |
|
| 1638 | + * @var int |
|
| 1639 | + */ |
|
| 1640 | + public $reg_page_id; |
|
| 1641 | + |
|
| 1642 | + public $txn_page_id; |
|
| 1643 | + |
|
| 1644 | + public $thank_you_page_id; |
|
| 1645 | + |
|
| 1646 | + public $cancel_page_id; |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1650 | + * |
|
| 1651 | + * @var int |
|
| 1652 | + */ |
|
| 1653 | + public $reg_page_url; |
|
| 1654 | + |
|
| 1655 | + public $txn_page_url; |
|
| 1656 | + |
|
| 1657 | + public $thank_you_page_url; |
|
| 1658 | + |
|
| 1659 | + public $cancel_page_url; |
|
| 1660 | + |
|
| 1661 | + /** |
|
| 1662 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1663 | + */ |
|
| 1664 | + public $event_cpt_slug; |
|
| 1665 | + |
|
| 1666 | + /** |
|
| 1667 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1668 | + * request across blog switches in a multisite context. |
|
| 1669 | + * Avoids extra queries to the db for this option. |
|
| 1670 | + * |
|
| 1671 | + * @var bool |
|
| 1672 | + */ |
|
| 1673 | + public static $ee_ueip_option; |
|
| 1674 | + |
|
| 1675 | + |
|
| 1676 | + /** |
|
| 1677 | + * class constructor |
|
| 1678 | + * |
|
| 1679 | + * @access public |
|
| 1680 | + */ |
|
| 1681 | + public function __construct() |
|
| 1682 | + { |
|
| 1683 | + // set default organization settings |
|
| 1684 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1685 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1686 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1687 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1688 | + $this->post_shortcodes = array(); |
|
| 1689 | + $this->module_route_map = array(); |
|
| 1690 | + $this->module_forward_map = array(); |
|
| 1691 | + $this->module_view_map = array(); |
|
| 1692 | + // critical EE page IDs |
|
| 1693 | + $this->reg_page_id = 0; |
|
| 1694 | + $this->txn_page_id = 0; |
|
| 1695 | + $this->thank_you_page_id = 0; |
|
| 1696 | + $this->cancel_page_id = 0; |
|
| 1697 | + // critical EE page URLs |
|
| 1698 | + $this->reg_page_url = ''; |
|
| 1699 | + $this->txn_page_url = ''; |
|
| 1700 | + $this->thank_you_page_url = ''; |
|
| 1701 | + $this->cancel_page_url = ''; |
|
| 1702 | + // cpt slugs |
|
| 1703 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1704 | + // ueip constant check |
|
| 1705 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1706 | + $this->ee_ueip_optin = false; |
|
| 1707 | + $this->ee_ueip_has_notified = true; |
|
| 1708 | + } |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * @return array |
|
| 1714 | + */ |
|
| 1715 | + public function get_critical_pages_array() |
|
| 1716 | + { |
|
| 1717 | + return array( |
|
| 1718 | + $this->reg_page_id, |
|
| 1719 | + $this->txn_page_id, |
|
| 1720 | + $this->thank_you_page_id, |
|
| 1721 | + $this->cancel_page_id, |
|
| 1722 | + ); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * @return array |
|
| 1728 | + */ |
|
| 1729 | + public function get_critical_pages_shortcodes_array() |
|
| 1730 | + { |
|
| 1731 | + return array( |
|
| 1732 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1733 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1734 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1735 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1736 | + ); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * gets/returns URL for EE reg_page |
|
| 1742 | + * |
|
| 1743 | + * @access public |
|
| 1744 | + * @return string |
|
| 1745 | + */ |
|
| 1746 | + public function reg_page_url() |
|
| 1747 | + { |
|
| 1748 | + if (! $this->reg_page_url) { |
|
| 1749 | + $this->reg_page_url = add_query_arg( |
|
| 1750 | + array('uts' => time()), |
|
| 1751 | + get_permalink($this->reg_page_id) |
|
| 1752 | + ) . '#checkout'; |
|
| 1753 | + } |
|
| 1754 | + return $this->reg_page_url; |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + |
|
| 1758 | + /** |
|
| 1759 | + * gets/returns URL for EE txn_page |
|
| 1760 | + * |
|
| 1761 | + * @param array $query_args like what gets passed to |
|
| 1762 | + * add_query_arg() as the first argument |
|
| 1763 | + * @access public |
|
| 1764 | + * @return string |
|
| 1765 | + */ |
|
| 1766 | + public function txn_page_url($query_args = array()) |
|
| 1767 | + { |
|
| 1768 | + if (! $this->txn_page_url) { |
|
| 1769 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1770 | + } |
|
| 1771 | + if ($query_args) { |
|
| 1772 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1773 | + } else { |
|
| 1774 | + return $this->txn_page_url; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * gets/returns URL for EE thank_you_page |
|
| 1781 | + * |
|
| 1782 | + * @param array $query_args like what gets passed to |
|
| 1783 | + * add_query_arg() as the first argument |
|
| 1784 | + * @access public |
|
| 1785 | + * @return string |
|
| 1786 | + */ |
|
| 1787 | + public function thank_you_page_url($query_args = array()) |
|
| 1788 | + { |
|
| 1789 | + if (! $this->thank_you_page_url) { |
|
| 1790 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1791 | + } |
|
| 1792 | + if ($query_args) { |
|
| 1793 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1794 | + } else { |
|
| 1795 | + return $this->thank_you_page_url; |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * gets/returns URL for EE cancel_page |
|
| 1802 | + * |
|
| 1803 | + * @access public |
|
| 1804 | + * @return string |
|
| 1805 | + */ |
|
| 1806 | + public function cancel_page_url() |
|
| 1807 | + { |
|
| 1808 | + if (! $this->cancel_page_url) { |
|
| 1809 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1810 | + } |
|
| 1811 | + return $this->cancel_page_url; |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + /** |
|
| 1816 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1817 | + * |
|
| 1818 | + * @since 4.7.5 |
|
| 1819 | + */ |
|
| 1820 | + protected function _reset_urls() |
|
| 1821 | + { |
|
| 1822 | + $this->reg_page_url = ''; |
|
| 1823 | + $this->txn_page_url = ''; |
|
| 1824 | + $this->cancel_page_url = ''; |
|
| 1825 | + $this->thank_you_page_url = ''; |
|
| 1826 | + } |
|
| 1827 | + |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1831 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1832 | + * on the main site only. |
|
| 1833 | + * |
|
| 1834 | + * @return bool |
|
| 1835 | + */ |
|
| 1836 | + protected function _get_main_ee_ueip_optin() |
|
| 1837 | + { |
|
| 1838 | + // if this is the main site then we can just bypass our direct query. |
|
| 1839 | + if (is_main_site()) { |
|
| 1840 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1841 | + } |
|
| 1842 | + // is this already cached for this request? If so use it. |
|
| 1843 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1844 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1845 | + } |
|
| 1846 | + global $wpdb; |
|
| 1847 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1848 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1849 | + $option = self::OPTION_NAME_UXIP; |
|
| 1850 | + // set correct table for query |
|
| 1851 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1852 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1853 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1854 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1855 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1856 | + // for the purpose of caching. |
|
| 1857 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1858 | + if (false !== $pre) { |
|
| 1859 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1860 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1861 | + } |
|
| 1862 | + $row = $wpdb->get_row( |
|
| 1863 | + $wpdb->prepare( |
|
| 1864 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1865 | + $option |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + if (is_object($row)) { |
|
| 1869 | + $value = $row->option_value; |
|
| 1870 | + } else { // option does not exist so use default. |
|
| 1871 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1872 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1873 | + } |
|
| 1874 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1875 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * Utility function for escaping the value of a property and returning. |
|
| 1881 | + * |
|
| 1882 | + * @param string $property property name (checks to see if exists). |
|
| 1883 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1884 | + * @throws \EE_Error |
|
| 1885 | + */ |
|
| 1886 | + public function get_pretty($property) |
|
| 1887 | + { |
|
| 1888 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1889 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1890 | + } |
|
| 1891 | + return parent::get_pretty($property); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1897 | + * on the object. |
|
| 1898 | + * |
|
| 1899 | + * @return array |
|
| 1900 | + */ |
|
| 1901 | + public function __sleep() |
|
| 1902 | + { |
|
| 1903 | + // reset all url properties |
|
| 1904 | + $this->_reset_urls(); |
|
| 1905 | + // return what to save to db |
|
| 1906 | + return array_keys(get_object_vars($this)); |
|
| 1907 | + } |
|
| 1908 | +} |
|
| 2292 | 1909 | |
| 2293 | - /** |
|
| 2294 | - * array of form names protected by ReCaptcha |
|
| 2295 | - * |
|
| 2296 | - * @var array $recaptcha_protected_forms |
|
| 2297 | - */ |
|
| 2298 | - public $recaptcha_protected_forms; |
|
| 1910 | +/** |
|
| 1911 | + * Config class for storing info on the Organization |
|
| 1912 | + */ |
|
| 1913 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1914 | +{ |
|
| 2299 | 1915 | |
| 2300 | - /** |
|
| 2301 | - * ReCaptcha width |
|
| 2302 | - * |
|
| 2303 | - * @var int $recaptcha_width |
|
| 2304 | - * @deprecated |
|
| 2305 | - */ |
|
| 2306 | - public $recaptcha_width; |
|
| 1916 | + /** |
|
| 1917 | + * @var string $name |
|
| 1918 | + * eg EE4.1 |
|
| 1919 | + */ |
|
| 1920 | + public $name; |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * @var string $address_1 |
|
| 1924 | + * eg 123 Onna Road |
|
| 1925 | + */ |
|
| 1926 | + public $address_1 = ''; |
|
| 1927 | + |
|
| 1928 | + /** |
|
| 1929 | + * @var string $address_2 |
|
| 1930 | + * eg PO Box 123 |
|
| 1931 | + */ |
|
| 1932 | + public $address_2 = ''; |
|
| 1933 | + |
|
| 1934 | + /** |
|
| 1935 | + * @var string $city |
|
| 1936 | + * eg Inna City |
|
| 1937 | + */ |
|
| 1938 | + public $city = ''; |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * @var int $STA_ID |
|
| 1942 | + * eg 4 |
|
| 1943 | + */ |
|
| 1944 | + public $STA_ID = 0; |
|
| 1945 | + |
|
| 1946 | + /** |
|
| 1947 | + * @var string $CNT_ISO |
|
| 1948 | + * eg US |
|
| 1949 | + */ |
|
| 1950 | + public $CNT_ISO = ''; |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @var string $zip |
|
| 1954 | + * eg 12345 or V1A 2B3 |
|
| 1955 | + */ |
|
| 1956 | + public $zip = ''; |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * @var string $email |
|
| 1960 | + * eg [email protected] |
|
| 1961 | + */ |
|
| 1962 | + public $email; |
|
| 1963 | + |
|
| 1964 | + /** |
|
| 1965 | + * @var string $phone |
|
| 1966 | + * eg. 111-111-1111 |
|
| 1967 | + */ |
|
| 1968 | + public $phone = ''; |
|
| 1969 | + |
|
| 1970 | + /** |
|
| 1971 | + * @var string $vat |
|
| 1972 | + * VAT/Tax Number |
|
| 1973 | + */ |
|
| 1974 | + public $vat = ''; |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @var string $logo_url |
|
| 1978 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1979 | + */ |
|
| 1980 | + public $logo_url = ''; |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1984 | + * |
|
| 1985 | + * @var string |
|
| 1986 | + */ |
|
| 1987 | + /** |
|
| 1988 | + * facebook (facebook.com/profile.name) |
|
| 1989 | + * |
|
| 1990 | + * @var string |
|
| 1991 | + */ |
|
| 1992 | + public $facebook = ''; |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * twitter (twitter.com/twitter_handle) |
|
| 1996 | + * |
|
| 1997 | + * @var string |
|
| 1998 | + */ |
|
| 1999 | + public $twitter = ''; |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2003 | + * |
|
| 2004 | + * @var string |
|
| 2005 | + */ |
|
| 2006 | + public $linkedin = ''; |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2010 | + * |
|
| 2011 | + * @var string |
|
| 2012 | + */ |
|
| 2013 | + public $pinterest = ''; |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * google+ (google.com/+profileName) |
|
| 2017 | + * |
|
| 2018 | + * @var string |
|
| 2019 | + */ |
|
| 2020 | + public $google = ''; |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * instagram (instagram.com/handle) |
|
| 2024 | + * |
|
| 2025 | + * @var string |
|
| 2026 | + */ |
|
| 2027 | + public $instagram = ''; |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * class constructor |
|
| 2032 | + * |
|
| 2033 | + * @access public |
|
| 2034 | + */ |
|
| 2035 | + public function __construct() |
|
| 2036 | + { |
|
| 2037 | + // set default organization settings |
|
| 2038 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2039 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2040 | + $this->email = get_bloginfo('admin_email'); |
|
| 2041 | + } |
|
| 2042 | +} |
|
| 2307 | 2043 | |
| 2308 | - /** |
|
| 2309 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | - * |
|
| 2311 | - * @var boolean $track_invalid_checkout_access |
|
| 2312 | - */ |
|
| 2313 | - protected $track_invalid_checkout_access = true; |
|
| 2044 | +/** |
|
| 2045 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2046 | + */ |
|
| 2047 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2048 | +{ |
|
| 2314 | 2049 | |
| 2315 | - /** |
|
| 2316 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | - * |
|
| 2318 | - * @var bool |
|
| 2319 | - */ |
|
| 2320 | - public $consent_checkbox_enabled; |
|
| 2050 | + /** |
|
| 2051 | + * @var string $code |
|
| 2052 | + * eg 'US' |
|
| 2053 | + */ |
|
| 2054 | + public $code; |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * @var string $name |
|
| 2058 | + * eg 'Dollar' |
|
| 2059 | + */ |
|
| 2060 | + public $name; |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * plural name |
|
| 2064 | + * |
|
| 2065 | + * @var string $plural |
|
| 2066 | + * eg 'Dollars' |
|
| 2067 | + */ |
|
| 2068 | + public $plural; |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * currency sign |
|
| 2072 | + * |
|
| 2073 | + * @var string $sign |
|
| 2074 | + * eg '$' |
|
| 2075 | + */ |
|
| 2076 | + public $sign; |
|
| 2077 | + |
|
| 2078 | + /** |
|
| 2079 | + * Whether the currency sign should come before the number or not |
|
| 2080 | + * |
|
| 2081 | + * @var boolean $sign_b4 |
|
| 2082 | + */ |
|
| 2083 | + public $sign_b4; |
|
| 2084 | + |
|
| 2085 | + /** |
|
| 2086 | + * How many digits should come after the decimal place |
|
| 2087 | + * |
|
| 2088 | + * @var int $dec_plc |
|
| 2089 | + */ |
|
| 2090 | + public $dec_plc; |
|
| 2091 | + |
|
| 2092 | + /** |
|
| 2093 | + * Symbol to use for decimal mark |
|
| 2094 | + * |
|
| 2095 | + * @var string $dec_mrk |
|
| 2096 | + * eg '.' |
|
| 2097 | + */ |
|
| 2098 | + public $dec_mrk; |
|
| 2099 | + |
|
| 2100 | + /** |
|
| 2101 | + * Symbol to use for thousands |
|
| 2102 | + * |
|
| 2103 | + * @var string $thsnds |
|
| 2104 | + * eg ',' |
|
| 2105 | + */ |
|
| 2106 | + public $thsnds; |
|
| 2107 | + |
|
| 2108 | + |
|
| 2109 | + /** |
|
| 2110 | + * class constructor |
|
| 2111 | + * |
|
| 2112 | + * @access public |
|
| 2113 | + * @param string $CNT_ISO |
|
| 2114 | + * @throws \EE_Error |
|
| 2115 | + */ |
|
| 2116 | + public function __construct($CNT_ISO = '') |
|
| 2117 | + { |
|
| 2118 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2119 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2120 | + // get country code from organization settings or use default |
|
| 2121 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2122 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2123 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2124 | + : ''; |
|
| 2125 | + // but override if requested |
|
| 2126 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2127 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2128 | + if (! empty($CNT_ISO) |
|
| 2129 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2130 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2131 | + ) { |
|
| 2132 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2133 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2134 | + if ($country instanceof EE_Country) { |
|
| 2135 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2136 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2137 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2138 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2139 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2140 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2141 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2142 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2143 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2144 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2145 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2149 | + if (empty($this->code)) { |
|
| 2150 | + // set default currency settings |
|
| 2151 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2152 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2153 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2154 | + $this->sign = '$'; // currency sign: $ |
|
| 2155 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2156 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2157 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2158 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | +} |
|
| 2321 | 2162 | |
| 2322 | - /** |
|
| 2323 | - * Label text to show on the checkbox |
|
| 2324 | - * |
|
| 2325 | - * @var string |
|
| 2326 | - */ |
|
| 2327 | - public $consent_checkbox_label_text; |
|
| 2163 | +/** |
|
| 2164 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2165 | + */ |
|
| 2166 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2167 | +{ |
|
| 2328 | 2168 | |
| 2329 | - /* |
|
| 2169 | + /** |
|
| 2170 | + * Default registration status |
|
| 2171 | + * |
|
| 2172 | + * @var string $default_STS_ID |
|
| 2173 | + * eg 'RPP' |
|
| 2174 | + */ |
|
| 2175 | + public $default_STS_ID; |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2179 | + * registrations) |
|
| 2180 | + * |
|
| 2181 | + * @var int |
|
| 2182 | + */ |
|
| 2183 | + public $default_maximum_number_of_tickets; |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * level of validation to apply to email addresses |
|
| 2187 | + * |
|
| 2188 | + * @var string $email_validation_level |
|
| 2189 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2190 | + */ |
|
| 2191 | + public $email_validation_level; |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2195 | + * |
|
| 2196 | + * @var boolean $show_pending_payment_options |
|
| 2197 | + */ |
|
| 2198 | + public $show_pending_payment_options; |
|
| 2199 | + |
|
| 2200 | + /** |
|
| 2201 | + * Whether to skip the registration confirmation page |
|
| 2202 | + * |
|
| 2203 | + * @var boolean $skip_reg_confirmation |
|
| 2204 | + */ |
|
| 2205 | + public $skip_reg_confirmation; |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * an array of SPCO reg steps where: |
|
| 2209 | + * the keys denotes the reg step order |
|
| 2210 | + * each element consists of an array with the following elements: |
|
| 2211 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2212 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2213 | + * "slug" => the URL param used to trigger the reg step |
|
| 2214 | + * |
|
| 2215 | + * @var array $reg_steps |
|
| 2216 | + */ |
|
| 2217 | + public $reg_steps; |
|
| 2218 | + |
|
| 2219 | + /** |
|
| 2220 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2221 | + * |
|
| 2222 | + * @var boolean $reg_confirmation_last |
|
| 2223 | + */ |
|
| 2224 | + public $reg_confirmation_last; |
|
| 2225 | + |
|
| 2226 | + /** |
|
| 2227 | + * Whether or not to enable the EE Bot Trap |
|
| 2228 | + * |
|
| 2229 | + * @var boolean $use_bot_trap |
|
| 2230 | + */ |
|
| 2231 | + public $use_bot_trap; |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2235 | + * |
|
| 2236 | + * @var boolean $use_encryption |
|
| 2237 | + */ |
|
| 2238 | + public $use_encryption; |
|
| 2239 | + |
|
| 2240 | + /** |
|
| 2241 | + * Whether or not to use ReCaptcha |
|
| 2242 | + * |
|
| 2243 | + * @var boolean $use_captcha |
|
| 2244 | + */ |
|
| 2245 | + public $use_captcha; |
|
| 2246 | + |
|
| 2247 | + /** |
|
| 2248 | + * ReCaptcha Theme |
|
| 2249 | + * |
|
| 2250 | + * @var string $recaptcha_theme |
|
| 2251 | + * options: 'dark', 'light', 'invisible' |
|
| 2252 | + */ |
|
| 2253 | + public $recaptcha_theme; |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2257 | + * |
|
| 2258 | + * @var string $recaptcha_badge |
|
| 2259 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2260 | + */ |
|
| 2261 | + public $recaptcha_badge; |
|
| 2262 | + |
|
| 2263 | + /** |
|
| 2264 | + * ReCaptcha Type |
|
| 2265 | + * |
|
| 2266 | + * @var string $recaptcha_type |
|
| 2267 | + * options: 'audio', 'image' |
|
| 2268 | + */ |
|
| 2269 | + public $recaptcha_type; |
|
| 2270 | + |
|
| 2271 | + /** |
|
| 2272 | + * ReCaptcha language |
|
| 2273 | + * |
|
| 2274 | + * @var string $recaptcha_language |
|
| 2275 | + * eg 'en' |
|
| 2276 | + */ |
|
| 2277 | + public $recaptcha_language; |
|
| 2278 | + |
|
| 2279 | + /** |
|
| 2280 | + * ReCaptcha public key |
|
| 2281 | + * |
|
| 2282 | + * @var string $recaptcha_publickey |
|
| 2283 | + */ |
|
| 2284 | + public $recaptcha_publickey; |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * ReCaptcha private key |
|
| 2288 | + * |
|
| 2289 | + * @var string $recaptcha_privatekey |
|
| 2290 | + */ |
|
| 2291 | + public $recaptcha_privatekey; |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * array of form names protected by ReCaptcha |
|
| 2295 | + * |
|
| 2296 | + * @var array $recaptcha_protected_forms |
|
| 2297 | + */ |
|
| 2298 | + public $recaptcha_protected_forms; |
|
| 2299 | + |
|
| 2300 | + /** |
|
| 2301 | + * ReCaptcha width |
|
| 2302 | + * |
|
| 2303 | + * @var int $recaptcha_width |
|
| 2304 | + * @deprecated |
|
| 2305 | + */ |
|
| 2306 | + public $recaptcha_width; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2310 | + * |
|
| 2311 | + * @var boolean $track_invalid_checkout_access |
|
| 2312 | + */ |
|
| 2313 | + protected $track_invalid_checkout_access = true; |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2317 | + * |
|
| 2318 | + * @var bool |
|
| 2319 | + */ |
|
| 2320 | + public $consent_checkbox_enabled; |
|
| 2321 | + |
|
| 2322 | + /** |
|
| 2323 | + * Label text to show on the checkbox |
|
| 2324 | + * |
|
| 2325 | + * @var string |
|
| 2326 | + */ |
|
| 2327 | + public $consent_checkbox_label_text; |
|
| 2328 | + |
|
| 2329 | + /* |
|
| 2330 | 2330 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2331 | 2331 | * @var string |
| 2332 | 2332 | */ |
| 2333 | - public $gateway_log_lifespan = '1 week'; |
|
| 2334 | - |
|
| 2335 | - |
|
| 2336 | - /** |
|
| 2337 | - * class constructor |
|
| 2338 | - * |
|
| 2339 | - * @access public |
|
| 2340 | - */ |
|
| 2341 | - public function __construct() |
|
| 2342 | - { |
|
| 2343 | - // set default registration settings |
|
| 2344 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2345 | - $this->email_validation_level = 'wp_default'; |
|
| 2346 | - $this->show_pending_payment_options = true; |
|
| 2347 | - $this->skip_reg_confirmation = true; |
|
| 2348 | - $this->reg_steps = array(); |
|
| 2349 | - $this->reg_confirmation_last = false; |
|
| 2350 | - $this->use_bot_trap = true; |
|
| 2351 | - $this->use_encryption = true; |
|
| 2352 | - $this->use_captcha = false; |
|
| 2353 | - $this->recaptcha_theme = 'light'; |
|
| 2354 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2355 | - $this->recaptcha_type = 'image'; |
|
| 2356 | - $this->recaptcha_language = 'en'; |
|
| 2357 | - $this->recaptcha_publickey = null; |
|
| 2358 | - $this->recaptcha_privatekey = null; |
|
| 2359 | - $this->recaptcha_protected_forms = array(); |
|
| 2360 | - $this->recaptcha_width = 500; |
|
| 2361 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2362 | - $this->consent_checkbox_enabled = false; |
|
| 2363 | - $this->consent_checkbox_label_text = ''; |
|
| 2364 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2365 | - } |
|
| 2366 | - |
|
| 2367 | - |
|
| 2368 | - /** |
|
| 2369 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2370 | - * |
|
| 2371 | - * @since 4.8.8.rc.019 |
|
| 2372 | - */ |
|
| 2373 | - public function do_hooks() |
|
| 2374 | - { |
|
| 2375 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2376 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2377 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2378 | - } |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2383 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2384 | - */ |
|
| 2385 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2386 | - { |
|
| 2387 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2388 | - } |
|
| 2389 | - |
|
| 2390 | - |
|
| 2391 | - /** |
|
| 2392 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2393 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2394 | - */ |
|
| 2395 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2396 | - { |
|
| 2397 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2398 | - } |
|
| 2399 | - |
|
| 2400 | - |
|
| 2401 | - /** |
|
| 2402 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2403 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2404 | - * |
|
| 2405 | - * @throws InvalidArgumentException |
|
| 2406 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2407 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2408 | - */ |
|
| 2409 | - public function setDefaultCheckboxLabelText() |
|
| 2410 | - { |
|
| 2411 | - if ($this->getConsentCheckboxLabelText() === null |
|
| 2412 | - || $this->getConsentCheckboxLabelText() === '') { |
|
| 2413 | - $opening_a_tag = ''; |
|
| 2414 | - $closing_a_tag = ''; |
|
| 2415 | - if (function_exists('get_privacy_policy_url')) { |
|
| 2416 | - $privacy_page_url = get_privacy_policy_url(); |
|
| 2417 | - if (! empty($privacy_page_url)) { |
|
| 2418 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2419 | - $closing_a_tag = '</a>'; |
|
| 2420 | - } |
|
| 2421 | - } |
|
| 2422 | - $loader = LoaderFactory::getLoader(); |
|
| 2423 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2424 | - /** |
|
| 2425 | - * @var $org_config EE_Organization_Config |
|
| 2426 | - */ |
|
| 2427 | - |
|
| 2428 | - $this->setConsentCheckboxLabelText( |
|
| 2429 | - sprintf( |
|
| 2430 | - esc_html__( |
|
| 2431 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2432 | - 'event_espresso' |
|
| 2433 | - ), |
|
| 2434 | - $org_config->name, |
|
| 2435 | - $opening_a_tag, |
|
| 2436 | - $closing_a_tag |
|
| 2437 | - ) |
|
| 2438 | - ); |
|
| 2439 | - } |
|
| 2440 | - } |
|
| 2441 | - |
|
| 2442 | - |
|
| 2443 | - /** |
|
| 2444 | - * @return boolean |
|
| 2445 | - */ |
|
| 2446 | - public function track_invalid_checkout_access() |
|
| 2447 | - { |
|
| 2448 | - return $this->track_invalid_checkout_access; |
|
| 2449 | - } |
|
| 2450 | - |
|
| 2451 | - |
|
| 2452 | - /** |
|
| 2453 | - * @param boolean $track_invalid_checkout_access |
|
| 2454 | - */ |
|
| 2455 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2456 | - { |
|
| 2457 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2458 | - $track_invalid_checkout_access, |
|
| 2459 | - FILTER_VALIDATE_BOOLEAN |
|
| 2460 | - ); |
|
| 2461 | - } |
|
| 2462 | - |
|
| 2463 | - |
|
| 2464 | - /** |
|
| 2465 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2466 | - * @return array |
|
| 2467 | - */ |
|
| 2468 | - public function gatewayLogLifespanOptions() |
|
| 2469 | - { |
|
| 2470 | - return (array) apply_filters( |
|
| 2471 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2472 | - array( |
|
| 2473 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2474 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2475 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2476 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2477 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2478 | - ) |
|
| 2479 | - ); |
|
| 2480 | - } |
|
| 2481 | - |
|
| 2482 | - |
|
| 2483 | - /** |
|
| 2484 | - * @return bool |
|
| 2485 | - */ |
|
| 2486 | - public function isConsentCheckboxEnabled() |
|
| 2487 | - { |
|
| 2488 | - return $this->consent_checkbox_enabled; |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * @param bool $consent_checkbox_enabled |
|
| 2494 | - */ |
|
| 2495 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2496 | - { |
|
| 2497 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2498 | - $consent_checkbox_enabled, |
|
| 2499 | - FILTER_VALIDATE_BOOLEAN |
|
| 2500 | - ); |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - |
|
| 2504 | - /** |
|
| 2505 | - * @return string |
|
| 2506 | - */ |
|
| 2507 | - public function getConsentCheckboxLabelText() |
|
| 2508 | - { |
|
| 2509 | - return $this->consent_checkbox_label_text; |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - |
|
| 2513 | - /** |
|
| 2514 | - * @param string $consent_checkbox_label_text |
|
| 2515 | - */ |
|
| 2516 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2517 | - { |
|
| 2518 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2519 | - } |
|
| 2333 | + public $gateway_log_lifespan = '1 week'; |
|
| 2334 | + |
|
| 2335 | + |
|
| 2336 | + /** |
|
| 2337 | + * class constructor |
|
| 2338 | + * |
|
| 2339 | + * @access public |
|
| 2340 | + */ |
|
| 2341 | + public function __construct() |
|
| 2342 | + { |
|
| 2343 | + // set default registration settings |
|
| 2344 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2345 | + $this->email_validation_level = 'wp_default'; |
|
| 2346 | + $this->show_pending_payment_options = true; |
|
| 2347 | + $this->skip_reg_confirmation = true; |
|
| 2348 | + $this->reg_steps = array(); |
|
| 2349 | + $this->reg_confirmation_last = false; |
|
| 2350 | + $this->use_bot_trap = true; |
|
| 2351 | + $this->use_encryption = true; |
|
| 2352 | + $this->use_captcha = false; |
|
| 2353 | + $this->recaptcha_theme = 'light'; |
|
| 2354 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2355 | + $this->recaptcha_type = 'image'; |
|
| 2356 | + $this->recaptcha_language = 'en'; |
|
| 2357 | + $this->recaptcha_publickey = null; |
|
| 2358 | + $this->recaptcha_privatekey = null; |
|
| 2359 | + $this->recaptcha_protected_forms = array(); |
|
| 2360 | + $this->recaptcha_width = 500; |
|
| 2361 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2362 | + $this->consent_checkbox_enabled = false; |
|
| 2363 | + $this->consent_checkbox_label_text = ''; |
|
| 2364 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + |
|
| 2368 | + /** |
|
| 2369 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2370 | + * |
|
| 2371 | + * @since 4.8.8.rc.019 |
|
| 2372 | + */ |
|
| 2373 | + public function do_hooks() |
|
| 2374 | + { |
|
| 2375 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2376 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2377 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2378 | + } |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2383 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2384 | + */ |
|
| 2385 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2386 | + { |
|
| 2387 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2388 | + } |
|
| 2389 | + |
|
| 2390 | + |
|
| 2391 | + /** |
|
| 2392 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2393 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2394 | + */ |
|
| 2395 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2396 | + { |
|
| 2397 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2398 | + } |
|
| 2399 | + |
|
| 2400 | + |
|
| 2401 | + /** |
|
| 2402 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2403 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2404 | + * |
|
| 2405 | + * @throws InvalidArgumentException |
|
| 2406 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2407 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2408 | + */ |
|
| 2409 | + public function setDefaultCheckboxLabelText() |
|
| 2410 | + { |
|
| 2411 | + if ($this->getConsentCheckboxLabelText() === null |
|
| 2412 | + || $this->getConsentCheckboxLabelText() === '') { |
|
| 2413 | + $opening_a_tag = ''; |
|
| 2414 | + $closing_a_tag = ''; |
|
| 2415 | + if (function_exists('get_privacy_policy_url')) { |
|
| 2416 | + $privacy_page_url = get_privacy_policy_url(); |
|
| 2417 | + if (! empty($privacy_page_url)) { |
|
| 2418 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
| 2419 | + $closing_a_tag = '</a>'; |
|
| 2420 | + } |
|
| 2421 | + } |
|
| 2422 | + $loader = LoaderFactory::getLoader(); |
|
| 2423 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2424 | + /** |
|
| 2425 | + * @var $org_config EE_Organization_Config |
|
| 2426 | + */ |
|
| 2427 | + |
|
| 2428 | + $this->setConsentCheckboxLabelText( |
|
| 2429 | + sprintf( |
|
| 2430 | + esc_html__( |
|
| 2431 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2432 | + 'event_espresso' |
|
| 2433 | + ), |
|
| 2434 | + $org_config->name, |
|
| 2435 | + $opening_a_tag, |
|
| 2436 | + $closing_a_tag |
|
| 2437 | + ) |
|
| 2438 | + ); |
|
| 2439 | + } |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + /** |
|
| 2444 | + * @return boolean |
|
| 2445 | + */ |
|
| 2446 | + public function track_invalid_checkout_access() |
|
| 2447 | + { |
|
| 2448 | + return $this->track_invalid_checkout_access; |
|
| 2449 | + } |
|
| 2450 | + |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * @param boolean $track_invalid_checkout_access |
|
| 2454 | + */ |
|
| 2455 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2456 | + { |
|
| 2457 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2458 | + $track_invalid_checkout_access, |
|
| 2459 | + FILTER_VALIDATE_BOOLEAN |
|
| 2460 | + ); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + |
|
| 2464 | + /** |
|
| 2465 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2466 | + * @return array |
|
| 2467 | + */ |
|
| 2468 | + public function gatewayLogLifespanOptions() |
|
| 2469 | + { |
|
| 2470 | + return (array) apply_filters( |
|
| 2471 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2472 | + array( |
|
| 2473 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2474 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2475 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2476 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2477 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2478 | + ) |
|
| 2479 | + ); |
|
| 2480 | + } |
|
| 2481 | + |
|
| 2482 | + |
|
| 2483 | + /** |
|
| 2484 | + * @return bool |
|
| 2485 | + */ |
|
| 2486 | + public function isConsentCheckboxEnabled() |
|
| 2487 | + { |
|
| 2488 | + return $this->consent_checkbox_enabled; |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * @param bool $consent_checkbox_enabled |
|
| 2494 | + */ |
|
| 2495 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2496 | + { |
|
| 2497 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2498 | + $consent_checkbox_enabled, |
|
| 2499 | + FILTER_VALIDATE_BOOLEAN |
|
| 2500 | + ); |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + |
|
| 2504 | + /** |
|
| 2505 | + * @return string |
|
| 2506 | + */ |
|
| 2507 | + public function getConsentCheckboxLabelText() |
|
| 2508 | + { |
|
| 2509 | + return $this->consent_checkbox_label_text; |
|
| 2510 | + } |
|
| 2511 | + |
|
| 2512 | + |
|
| 2513 | + /** |
|
| 2514 | + * @param string $consent_checkbox_label_text |
|
| 2515 | + */ |
|
| 2516 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2517 | + { |
|
| 2518 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2519 | + } |
|
| 2520 | 2520 | } |
| 2521 | 2521 | |
| 2522 | 2522 | /** |
@@ -2525,154 +2525,154 @@ discard block |
||
| 2525 | 2525 | class EE_Admin_Config extends EE_Config_Base |
| 2526 | 2526 | { |
| 2527 | 2527 | |
| 2528 | - /** |
|
| 2529 | - * @var boolean $use_personnel_manager |
|
| 2530 | - */ |
|
| 2531 | - public $use_personnel_manager; |
|
| 2532 | - |
|
| 2533 | - /** |
|
| 2534 | - * @var boolean $use_dashboard_widget |
|
| 2535 | - */ |
|
| 2536 | - public $use_dashboard_widget; |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * @var int $events_in_dashboard |
|
| 2540 | - */ |
|
| 2541 | - public $events_in_dashboard; |
|
| 2542 | - |
|
| 2543 | - /** |
|
| 2544 | - * @var boolean $use_event_timezones |
|
| 2545 | - */ |
|
| 2546 | - public $use_event_timezones; |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @var boolean $use_full_logging |
|
| 2550 | - */ |
|
| 2551 | - public $use_full_logging; |
|
| 2552 | - |
|
| 2553 | - /** |
|
| 2554 | - * @var string $log_file_name |
|
| 2555 | - */ |
|
| 2556 | - public $log_file_name; |
|
| 2557 | - |
|
| 2558 | - /** |
|
| 2559 | - * @var string $debug_file_name |
|
| 2560 | - */ |
|
| 2561 | - public $debug_file_name; |
|
| 2562 | - |
|
| 2563 | - /** |
|
| 2564 | - * @var boolean $use_remote_logging |
|
| 2565 | - */ |
|
| 2566 | - public $use_remote_logging; |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * @var string $remote_logging_url |
|
| 2570 | - */ |
|
| 2571 | - public $remote_logging_url; |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @var boolean $show_reg_footer |
|
| 2575 | - */ |
|
| 2576 | - public $show_reg_footer; |
|
| 2577 | - |
|
| 2578 | - /** |
|
| 2579 | - * @var string $affiliate_id |
|
| 2580 | - */ |
|
| 2581 | - public $affiliate_id; |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * help tours on or off (global setting) |
|
| 2585 | - * |
|
| 2586 | - * @var boolean |
|
| 2587 | - */ |
|
| 2588 | - public $help_tour_activation; |
|
| 2589 | - |
|
| 2590 | - /** |
|
| 2591 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2592 | - * but is incompatible with some server configuration errors |
|
| 2593 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2594 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2595 | - * |
|
| 2596 | - * @var boolean $encode_session_data |
|
| 2597 | - */ |
|
| 2598 | - private $encode_session_data = false; |
|
| 2599 | - |
|
| 2600 | - |
|
| 2601 | - /** |
|
| 2602 | - * class constructor |
|
| 2603 | - * |
|
| 2604 | - * @access public |
|
| 2605 | - */ |
|
| 2606 | - public function __construct() |
|
| 2607 | - { |
|
| 2608 | - // set default general admin settings |
|
| 2609 | - $this->use_personnel_manager = true; |
|
| 2610 | - $this->use_dashboard_widget = true; |
|
| 2611 | - $this->events_in_dashboard = 30; |
|
| 2612 | - $this->use_event_timezones = false; |
|
| 2613 | - $this->use_full_logging = false; |
|
| 2614 | - $this->use_remote_logging = false; |
|
| 2615 | - $this->remote_logging_url = null; |
|
| 2616 | - $this->show_reg_footer = true; |
|
| 2617 | - $this->affiliate_id = 'default'; |
|
| 2618 | - $this->help_tour_activation = true; |
|
| 2619 | - $this->encode_session_data = false; |
|
| 2620 | - } |
|
| 2621 | - |
|
| 2622 | - |
|
| 2623 | - /** |
|
| 2624 | - * @param bool $reset |
|
| 2625 | - * @return string |
|
| 2626 | - */ |
|
| 2627 | - public function log_file_name($reset = false) |
|
| 2628 | - { |
|
| 2629 | - if (empty($this->log_file_name) || $reset) { |
|
| 2630 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2631 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2632 | - } |
|
| 2633 | - return $this->log_file_name; |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - |
|
| 2637 | - /** |
|
| 2638 | - * @param bool $reset |
|
| 2639 | - * @return string |
|
| 2640 | - */ |
|
| 2641 | - public function debug_file_name($reset = false) |
|
| 2642 | - { |
|
| 2643 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2644 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2645 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2646 | - } |
|
| 2647 | - return $this->debug_file_name; |
|
| 2648 | - } |
|
| 2649 | - |
|
| 2650 | - |
|
| 2651 | - /** |
|
| 2652 | - * @return string |
|
| 2653 | - */ |
|
| 2654 | - public function affiliate_id() |
|
| 2655 | - { |
|
| 2656 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - |
|
| 2660 | - /** |
|
| 2661 | - * @return boolean |
|
| 2662 | - */ |
|
| 2663 | - public function encode_session_data() |
|
| 2664 | - { |
|
| 2665 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - |
|
| 2669 | - /** |
|
| 2670 | - * @param boolean $encode_session_data |
|
| 2671 | - */ |
|
| 2672 | - public function set_encode_session_data($encode_session_data) |
|
| 2673 | - { |
|
| 2674 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2675 | - } |
|
| 2528 | + /** |
|
| 2529 | + * @var boolean $use_personnel_manager |
|
| 2530 | + */ |
|
| 2531 | + public $use_personnel_manager; |
|
| 2532 | + |
|
| 2533 | + /** |
|
| 2534 | + * @var boolean $use_dashboard_widget |
|
| 2535 | + */ |
|
| 2536 | + public $use_dashboard_widget; |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * @var int $events_in_dashboard |
|
| 2540 | + */ |
|
| 2541 | + public $events_in_dashboard; |
|
| 2542 | + |
|
| 2543 | + /** |
|
| 2544 | + * @var boolean $use_event_timezones |
|
| 2545 | + */ |
|
| 2546 | + public $use_event_timezones; |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @var boolean $use_full_logging |
|
| 2550 | + */ |
|
| 2551 | + public $use_full_logging; |
|
| 2552 | + |
|
| 2553 | + /** |
|
| 2554 | + * @var string $log_file_name |
|
| 2555 | + */ |
|
| 2556 | + public $log_file_name; |
|
| 2557 | + |
|
| 2558 | + /** |
|
| 2559 | + * @var string $debug_file_name |
|
| 2560 | + */ |
|
| 2561 | + public $debug_file_name; |
|
| 2562 | + |
|
| 2563 | + /** |
|
| 2564 | + * @var boolean $use_remote_logging |
|
| 2565 | + */ |
|
| 2566 | + public $use_remote_logging; |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * @var string $remote_logging_url |
|
| 2570 | + */ |
|
| 2571 | + public $remote_logging_url; |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @var boolean $show_reg_footer |
|
| 2575 | + */ |
|
| 2576 | + public $show_reg_footer; |
|
| 2577 | + |
|
| 2578 | + /** |
|
| 2579 | + * @var string $affiliate_id |
|
| 2580 | + */ |
|
| 2581 | + public $affiliate_id; |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * help tours on or off (global setting) |
|
| 2585 | + * |
|
| 2586 | + * @var boolean |
|
| 2587 | + */ |
|
| 2588 | + public $help_tour_activation; |
|
| 2589 | + |
|
| 2590 | + /** |
|
| 2591 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2592 | + * but is incompatible with some server configuration errors |
|
| 2593 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2594 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2595 | + * |
|
| 2596 | + * @var boolean $encode_session_data |
|
| 2597 | + */ |
|
| 2598 | + private $encode_session_data = false; |
|
| 2599 | + |
|
| 2600 | + |
|
| 2601 | + /** |
|
| 2602 | + * class constructor |
|
| 2603 | + * |
|
| 2604 | + * @access public |
|
| 2605 | + */ |
|
| 2606 | + public function __construct() |
|
| 2607 | + { |
|
| 2608 | + // set default general admin settings |
|
| 2609 | + $this->use_personnel_manager = true; |
|
| 2610 | + $this->use_dashboard_widget = true; |
|
| 2611 | + $this->events_in_dashboard = 30; |
|
| 2612 | + $this->use_event_timezones = false; |
|
| 2613 | + $this->use_full_logging = false; |
|
| 2614 | + $this->use_remote_logging = false; |
|
| 2615 | + $this->remote_logging_url = null; |
|
| 2616 | + $this->show_reg_footer = true; |
|
| 2617 | + $this->affiliate_id = 'default'; |
|
| 2618 | + $this->help_tour_activation = true; |
|
| 2619 | + $this->encode_session_data = false; |
|
| 2620 | + } |
|
| 2621 | + |
|
| 2622 | + |
|
| 2623 | + /** |
|
| 2624 | + * @param bool $reset |
|
| 2625 | + * @return string |
|
| 2626 | + */ |
|
| 2627 | + public function log_file_name($reset = false) |
|
| 2628 | + { |
|
| 2629 | + if (empty($this->log_file_name) || $reset) { |
|
| 2630 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2631 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2632 | + } |
|
| 2633 | + return $this->log_file_name; |
|
| 2634 | + } |
|
| 2635 | + |
|
| 2636 | + |
|
| 2637 | + /** |
|
| 2638 | + * @param bool $reset |
|
| 2639 | + * @return string |
|
| 2640 | + */ |
|
| 2641 | + public function debug_file_name($reset = false) |
|
| 2642 | + { |
|
| 2643 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2644 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2645 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2646 | + } |
|
| 2647 | + return $this->debug_file_name; |
|
| 2648 | + } |
|
| 2649 | + |
|
| 2650 | + |
|
| 2651 | + /** |
|
| 2652 | + * @return string |
|
| 2653 | + */ |
|
| 2654 | + public function affiliate_id() |
|
| 2655 | + { |
|
| 2656 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + |
|
| 2660 | + /** |
|
| 2661 | + * @return boolean |
|
| 2662 | + */ |
|
| 2663 | + public function encode_session_data() |
|
| 2664 | + { |
|
| 2665 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + |
|
| 2669 | + /** |
|
| 2670 | + * @param boolean $encode_session_data |
|
| 2671 | + */ |
|
| 2672 | + public function set_encode_session_data($encode_session_data) |
|
| 2673 | + { |
|
| 2674 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2675 | + } |
|
| 2676 | 2676 | } |
| 2677 | 2677 | |
| 2678 | 2678 | /** |
@@ -2681,70 +2681,70 @@ discard block |
||
| 2681 | 2681 | class EE_Template_Config extends EE_Config_Base |
| 2682 | 2682 | { |
| 2683 | 2683 | |
| 2684 | - /** |
|
| 2685 | - * @var boolean $enable_default_style |
|
| 2686 | - */ |
|
| 2687 | - public $enable_default_style; |
|
| 2688 | - |
|
| 2689 | - /** |
|
| 2690 | - * @var string $custom_style_sheet |
|
| 2691 | - */ |
|
| 2692 | - public $custom_style_sheet; |
|
| 2693 | - |
|
| 2694 | - /** |
|
| 2695 | - * @var boolean $display_address_in_regform |
|
| 2696 | - */ |
|
| 2697 | - public $display_address_in_regform; |
|
| 2698 | - |
|
| 2699 | - /** |
|
| 2700 | - * @var int $display_description_on_multi_reg_page |
|
| 2701 | - */ |
|
| 2702 | - public $display_description_on_multi_reg_page; |
|
| 2703 | - |
|
| 2704 | - /** |
|
| 2705 | - * @var boolean $use_custom_templates |
|
| 2706 | - */ |
|
| 2707 | - public $use_custom_templates; |
|
| 2708 | - |
|
| 2709 | - /** |
|
| 2710 | - * @var string $current_espresso_theme |
|
| 2711 | - */ |
|
| 2712 | - public $current_espresso_theme; |
|
| 2713 | - |
|
| 2714 | - /** |
|
| 2715 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2716 | - */ |
|
| 2717 | - public $EED_Ticket_Selector; |
|
| 2718 | - |
|
| 2719 | - /** |
|
| 2720 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2721 | - */ |
|
| 2722 | - public $EED_Event_Single; |
|
| 2723 | - |
|
| 2724 | - /** |
|
| 2725 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2726 | - */ |
|
| 2727 | - public $EED_Events_Archive; |
|
| 2728 | - |
|
| 2729 | - |
|
| 2730 | - /** |
|
| 2731 | - * class constructor |
|
| 2732 | - * |
|
| 2733 | - * @access public |
|
| 2734 | - */ |
|
| 2735 | - public function __construct() |
|
| 2736 | - { |
|
| 2737 | - // set default template settings |
|
| 2738 | - $this->enable_default_style = true; |
|
| 2739 | - $this->custom_style_sheet = null; |
|
| 2740 | - $this->display_address_in_regform = true; |
|
| 2741 | - $this->display_description_on_multi_reg_page = false; |
|
| 2742 | - $this->use_custom_templates = false; |
|
| 2743 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2744 | - $this->EED_Event_Single = null; |
|
| 2745 | - $this->EED_Events_Archive = null; |
|
| 2746 | - $this->EED_Ticket_Selector = null; |
|
| 2747 | - } |
|
| 2684 | + /** |
|
| 2685 | + * @var boolean $enable_default_style |
|
| 2686 | + */ |
|
| 2687 | + public $enable_default_style; |
|
| 2688 | + |
|
| 2689 | + /** |
|
| 2690 | + * @var string $custom_style_sheet |
|
| 2691 | + */ |
|
| 2692 | + public $custom_style_sheet; |
|
| 2693 | + |
|
| 2694 | + /** |
|
| 2695 | + * @var boolean $display_address_in_regform |
|
| 2696 | + */ |
|
| 2697 | + public $display_address_in_regform; |
|
| 2698 | + |
|
| 2699 | + /** |
|
| 2700 | + * @var int $display_description_on_multi_reg_page |
|
| 2701 | + */ |
|
| 2702 | + public $display_description_on_multi_reg_page; |
|
| 2703 | + |
|
| 2704 | + /** |
|
| 2705 | + * @var boolean $use_custom_templates |
|
| 2706 | + */ |
|
| 2707 | + public $use_custom_templates; |
|
| 2708 | + |
|
| 2709 | + /** |
|
| 2710 | + * @var string $current_espresso_theme |
|
| 2711 | + */ |
|
| 2712 | + public $current_espresso_theme; |
|
| 2713 | + |
|
| 2714 | + /** |
|
| 2715 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2716 | + */ |
|
| 2717 | + public $EED_Ticket_Selector; |
|
| 2718 | + |
|
| 2719 | + /** |
|
| 2720 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2721 | + */ |
|
| 2722 | + public $EED_Event_Single; |
|
| 2723 | + |
|
| 2724 | + /** |
|
| 2725 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2726 | + */ |
|
| 2727 | + public $EED_Events_Archive; |
|
| 2728 | + |
|
| 2729 | + |
|
| 2730 | + /** |
|
| 2731 | + * class constructor |
|
| 2732 | + * |
|
| 2733 | + * @access public |
|
| 2734 | + */ |
|
| 2735 | + public function __construct() |
|
| 2736 | + { |
|
| 2737 | + // set default template settings |
|
| 2738 | + $this->enable_default_style = true; |
|
| 2739 | + $this->custom_style_sheet = null; |
|
| 2740 | + $this->display_address_in_regform = true; |
|
| 2741 | + $this->display_description_on_multi_reg_page = false; |
|
| 2742 | + $this->use_custom_templates = false; |
|
| 2743 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2744 | + $this->EED_Event_Single = null; |
|
| 2745 | + $this->EED_Events_Archive = null; |
|
| 2746 | + $this->EED_Ticket_Selector = null; |
|
| 2747 | + } |
|
| 2748 | 2748 | } |
| 2749 | 2749 | |
| 2750 | 2750 | /** |
@@ -2753,114 +2753,114 @@ discard block |
||
| 2753 | 2753 | class EE_Map_Config extends EE_Config_Base |
| 2754 | 2754 | { |
| 2755 | 2755 | |
| 2756 | - /** |
|
| 2757 | - * @var boolean $use_google_maps |
|
| 2758 | - */ |
|
| 2759 | - public $use_google_maps; |
|
| 2760 | - |
|
| 2761 | - /** |
|
| 2762 | - * @var string $api_key |
|
| 2763 | - */ |
|
| 2764 | - public $google_map_api_key; |
|
| 2765 | - |
|
| 2766 | - /** |
|
| 2767 | - * @var int $event_details_map_width |
|
| 2768 | - */ |
|
| 2769 | - public $event_details_map_width; |
|
| 2770 | - |
|
| 2771 | - /** |
|
| 2772 | - * @var int $event_details_map_height |
|
| 2773 | - */ |
|
| 2774 | - public $event_details_map_height; |
|
| 2775 | - |
|
| 2776 | - /** |
|
| 2777 | - * @var int $event_details_map_zoom |
|
| 2778 | - */ |
|
| 2779 | - public $event_details_map_zoom; |
|
| 2780 | - |
|
| 2781 | - /** |
|
| 2782 | - * @var boolean $event_details_display_nav |
|
| 2783 | - */ |
|
| 2784 | - public $event_details_display_nav; |
|
| 2785 | - |
|
| 2786 | - /** |
|
| 2787 | - * @var boolean $event_details_nav_size |
|
| 2788 | - */ |
|
| 2789 | - public $event_details_nav_size; |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * @var string $event_details_control_type |
|
| 2793 | - */ |
|
| 2794 | - public $event_details_control_type; |
|
| 2795 | - |
|
| 2796 | - /** |
|
| 2797 | - * @var string $event_details_map_align |
|
| 2798 | - */ |
|
| 2799 | - public $event_details_map_align; |
|
| 2800 | - |
|
| 2801 | - /** |
|
| 2802 | - * @var int $event_list_map_width |
|
| 2803 | - */ |
|
| 2804 | - public $event_list_map_width; |
|
| 2805 | - |
|
| 2806 | - /** |
|
| 2807 | - * @var int $event_list_map_height |
|
| 2808 | - */ |
|
| 2809 | - public $event_list_map_height; |
|
| 2810 | - |
|
| 2811 | - /** |
|
| 2812 | - * @var int $event_list_map_zoom |
|
| 2813 | - */ |
|
| 2814 | - public $event_list_map_zoom; |
|
| 2815 | - |
|
| 2816 | - /** |
|
| 2817 | - * @var boolean $event_list_display_nav |
|
| 2818 | - */ |
|
| 2819 | - public $event_list_display_nav; |
|
| 2820 | - |
|
| 2821 | - /** |
|
| 2822 | - * @var boolean $event_list_nav_size |
|
| 2823 | - */ |
|
| 2824 | - public $event_list_nav_size; |
|
| 2825 | - |
|
| 2826 | - /** |
|
| 2827 | - * @var string $event_list_control_type |
|
| 2828 | - */ |
|
| 2829 | - public $event_list_control_type; |
|
| 2830 | - |
|
| 2831 | - /** |
|
| 2832 | - * @var string $event_list_map_align |
|
| 2833 | - */ |
|
| 2834 | - public $event_list_map_align; |
|
| 2835 | - |
|
| 2836 | - |
|
| 2837 | - /** |
|
| 2838 | - * class constructor |
|
| 2839 | - * |
|
| 2840 | - * @access public |
|
| 2841 | - */ |
|
| 2842 | - public function __construct() |
|
| 2843 | - { |
|
| 2844 | - // set default map settings |
|
| 2845 | - $this->use_google_maps = true; |
|
| 2846 | - $this->google_map_api_key = ''; |
|
| 2847 | - // for event details pages (reg page) |
|
| 2848 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2849 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2850 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2851 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2852 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2853 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2854 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2855 | - // for event list pages |
|
| 2856 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2857 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2858 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2859 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2860 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2861 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2862 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2863 | - } |
|
| 2756 | + /** |
|
| 2757 | + * @var boolean $use_google_maps |
|
| 2758 | + */ |
|
| 2759 | + public $use_google_maps; |
|
| 2760 | + |
|
| 2761 | + /** |
|
| 2762 | + * @var string $api_key |
|
| 2763 | + */ |
|
| 2764 | + public $google_map_api_key; |
|
| 2765 | + |
|
| 2766 | + /** |
|
| 2767 | + * @var int $event_details_map_width |
|
| 2768 | + */ |
|
| 2769 | + public $event_details_map_width; |
|
| 2770 | + |
|
| 2771 | + /** |
|
| 2772 | + * @var int $event_details_map_height |
|
| 2773 | + */ |
|
| 2774 | + public $event_details_map_height; |
|
| 2775 | + |
|
| 2776 | + /** |
|
| 2777 | + * @var int $event_details_map_zoom |
|
| 2778 | + */ |
|
| 2779 | + public $event_details_map_zoom; |
|
| 2780 | + |
|
| 2781 | + /** |
|
| 2782 | + * @var boolean $event_details_display_nav |
|
| 2783 | + */ |
|
| 2784 | + public $event_details_display_nav; |
|
| 2785 | + |
|
| 2786 | + /** |
|
| 2787 | + * @var boolean $event_details_nav_size |
|
| 2788 | + */ |
|
| 2789 | + public $event_details_nav_size; |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * @var string $event_details_control_type |
|
| 2793 | + */ |
|
| 2794 | + public $event_details_control_type; |
|
| 2795 | + |
|
| 2796 | + /** |
|
| 2797 | + * @var string $event_details_map_align |
|
| 2798 | + */ |
|
| 2799 | + public $event_details_map_align; |
|
| 2800 | + |
|
| 2801 | + /** |
|
| 2802 | + * @var int $event_list_map_width |
|
| 2803 | + */ |
|
| 2804 | + public $event_list_map_width; |
|
| 2805 | + |
|
| 2806 | + /** |
|
| 2807 | + * @var int $event_list_map_height |
|
| 2808 | + */ |
|
| 2809 | + public $event_list_map_height; |
|
| 2810 | + |
|
| 2811 | + /** |
|
| 2812 | + * @var int $event_list_map_zoom |
|
| 2813 | + */ |
|
| 2814 | + public $event_list_map_zoom; |
|
| 2815 | + |
|
| 2816 | + /** |
|
| 2817 | + * @var boolean $event_list_display_nav |
|
| 2818 | + */ |
|
| 2819 | + public $event_list_display_nav; |
|
| 2820 | + |
|
| 2821 | + /** |
|
| 2822 | + * @var boolean $event_list_nav_size |
|
| 2823 | + */ |
|
| 2824 | + public $event_list_nav_size; |
|
| 2825 | + |
|
| 2826 | + /** |
|
| 2827 | + * @var string $event_list_control_type |
|
| 2828 | + */ |
|
| 2829 | + public $event_list_control_type; |
|
| 2830 | + |
|
| 2831 | + /** |
|
| 2832 | + * @var string $event_list_map_align |
|
| 2833 | + */ |
|
| 2834 | + public $event_list_map_align; |
|
| 2835 | + |
|
| 2836 | + |
|
| 2837 | + /** |
|
| 2838 | + * class constructor |
|
| 2839 | + * |
|
| 2840 | + * @access public |
|
| 2841 | + */ |
|
| 2842 | + public function __construct() |
|
| 2843 | + { |
|
| 2844 | + // set default map settings |
|
| 2845 | + $this->use_google_maps = true; |
|
| 2846 | + $this->google_map_api_key = ''; |
|
| 2847 | + // for event details pages (reg page) |
|
| 2848 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2849 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2850 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2851 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2852 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2853 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2854 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2855 | + // for event list pages |
|
| 2856 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2857 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2858 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2859 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2860 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2861 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2862 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2863 | + } |
|
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | /** |
@@ -2869,46 +2869,46 @@ discard block |
||
| 2869 | 2869 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2870 | 2870 | { |
| 2871 | 2871 | |
| 2872 | - public $display_status_banner; |
|
| 2872 | + public $display_status_banner; |
|
| 2873 | 2873 | |
| 2874 | - public $display_description; |
|
| 2874 | + public $display_description; |
|
| 2875 | 2875 | |
| 2876 | - public $display_ticket_selector; |
|
| 2876 | + public $display_ticket_selector; |
|
| 2877 | 2877 | |
| 2878 | - public $display_datetimes; |
|
| 2878 | + public $display_datetimes; |
|
| 2879 | 2879 | |
| 2880 | - public $display_venue; |
|
| 2880 | + public $display_venue; |
|
| 2881 | 2881 | |
| 2882 | - public $display_expired_events; |
|
| 2882 | + public $display_expired_events; |
|
| 2883 | 2883 | |
| 2884 | - public $use_sortable_display_order; |
|
| 2884 | + public $use_sortable_display_order; |
|
| 2885 | 2885 | |
| 2886 | - public $display_order_tickets; |
|
| 2886 | + public $display_order_tickets; |
|
| 2887 | 2887 | |
| 2888 | - public $display_order_datetimes; |
|
| 2888 | + public $display_order_datetimes; |
|
| 2889 | 2889 | |
| 2890 | - public $display_order_event; |
|
| 2890 | + public $display_order_event; |
|
| 2891 | 2891 | |
| 2892 | - public $display_order_venue; |
|
| 2892 | + public $display_order_venue; |
|
| 2893 | 2893 | |
| 2894 | 2894 | |
| 2895 | - /** |
|
| 2896 | - * class constructor |
|
| 2897 | - */ |
|
| 2898 | - public function __construct() |
|
| 2899 | - { |
|
| 2900 | - $this->display_status_banner = 0; |
|
| 2901 | - $this->display_description = 1; |
|
| 2902 | - $this->display_ticket_selector = 0; |
|
| 2903 | - $this->display_datetimes = 1; |
|
| 2904 | - $this->display_venue = 0; |
|
| 2905 | - $this->display_expired_events = 0; |
|
| 2906 | - $this->use_sortable_display_order = false; |
|
| 2907 | - $this->display_order_tickets = 100; |
|
| 2908 | - $this->display_order_datetimes = 110; |
|
| 2909 | - $this->display_order_event = 120; |
|
| 2910 | - $this->display_order_venue = 130; |
|
| 2911 | - } |
|
| 2895 | + /** |
|
| 2896 | + * class constructor |
|
| 2897 | + */ |
|
| 2898 | + public function __construct() |
|
| 2899 | + { |
|
| 2900 | + $this->display_status_banner = 0; |
|
| 2901 | + $this->display_description = 1; |
|
| 2902 | + $this->display_ticket_selector = 0; |
|
| 2903 | + $this->display_datetimes = 1; |
|
| 2904 | + $this->display_venue = 0; |
|
| 2905 | + $this->display_expired_events = 0; |
|
| 2906 | + $this->use_sortable_display_order = false; |
|
| 2907 | + $this->display_order_tickets = 100; |
|
| 2908 | + $this->display_order_datetimes = 110; |
|
| 2909 | + $this->display_order_event = 120; |
|
| 2910 | + $this->display_order_venue = 130; |
|
| 2911 | + } |
|
| 2912 | 2912 | } |
| 2913 | 2913 | |
| 2914 | 2914 | /** |
@@ -2917,34 +2917,34 @@ discard block |
||
| 2917 | 2917 | class EE_Event_Single_Config extends EE_Config_Base |
| 2918 | 2918 | { |
| 2919 | 2919 | |
| 2920 | - public $display_status_banner_single; |
|
| 2920 | + public $display_status_banner_single; |
|
| 2921 | 2921 | |
| 2922 | - public $display_venue; |
|
| 2922 | + public $display_venue; |
|
| 2923 | 2923 | |
| 2924 | - public $use_sortable_display_order; |
|
| 2924 | + public $use_sortable_display_order; |
|
| 2925 | 2925 | |
| 2926 | - public $display_order_tickets; |
|
| 2926 | + public $display_order_tickets; |
|
| 2927 | 2927 | |
| 2928 | - public $display_order_datetimes; |
|
| 2928 | + public $display_order_datetimes; |
|
| 2929 | 2929 | |
| 2930 | - public $display_order_event; |
|
| 2930 | + public $display_order_event; |
|
| 2931 | 2931 | |
| 2932 | - public $display_order_venue; |
|
| 2932 | + public $display_order_venue; |
|
| 2933 | 2933 | |
| 2934 | 2934 | |
| 2935 | - /** |
|
| 2936 | - * class constructor |
|
| 2937 | - */ |
|
| 2938 | - public function __construct() |
|
| 2939 | - { |
|
| 2940 | - $this->display_status_banner_single = 0; |
|
| 2941 | - $this->display_venue = 1; |
|
| 2942 | - $this->use_sortable_display_order = false; |
|
| 2943 | - $this->display_order_tickets = 100; |
|
| 2944 | - $this->display_order_datetimes = 110; |
|
| 2945 | - $this->display_order_event = 120; |
|
| 2946 | - $this->display_order_venue = 130; |
|
| 2947 | - } |
|
| 2935 | + /** |
|
| 2936 | + * class constructor |
|
| 2937 | + */ |
|
| 2938 | + public function __construct() |
|
| 2939 | + { |
|
| 2940 | + $this->display_status_banner_single = 0; |
|
| 2941 | + $this->display_venue = 1; |
|
| 2942 | + $this->use_sortable_display_order = false; |
|
| 2943 | + $this->display_order_tickets = 100; |
|
| 2944 | + $this->display_order_datetimes = 110; |
|
| 2945 | + $this->display_order_event = 120; |
|
| 2946 | + $this->display_order_venue = 130; |
|
| 2947 | + } |
|
| 2948 | 2948 | } |
| 2949 | 2949 | |
| 2950 | 2950 | /** |
@@ -2953,172 +2953,172 @@ discard block |
||
| 2953 | 2953 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2954 | 2954 | { |
| 2955 | 2955 | |
| 2956 | - /** |
|
| 2957 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2958 | - */ |
|
| 2959 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2960 | - |
|
| 2961 | - /** |
|
| 2962 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2963 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2964 | - */ |
|
| 2965 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2966 | - |
|
| 2967 | - /** |
|
| 2968 | - * @var boolean $show_ticket_sale_columns |
|
| 2969 | - */ |
|
| 2970 | - public $show_ticket_sale_columns; |
|
| 2971 | - |
|
| 2972 | - /** |
|
| 2973 | - * @var boolean $show_ticket_details |
|
| 2974 | - */ |
|
| 2975 | - public $show_ticket_details; |
|
| 2976 | - |
|
| 2977 | - /** |
|
| 2978 | - * @var boolean $show_expired_tickets |
|
| 2979 | - */ |
|
| 2980 | - public $show_expired_tickets; |
|
| 2981 | - |
|
| 2982 | - /** |
|
| 2983 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2984 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2985 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2986 | - * |
|
| 2987 | - * @var string $show_datetime_selector |
|
| 2988 | - */ |
|
| 2989 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2990 | - |
|
| 2991 | - /** |
|
| 2992 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2993 | - * |
|
| 2994 | - * @var int $datetime_selector_threshold |
|
| 2995 | - */ |
|
| 2996 | - private $datetime_selector_threshold = 3; |
|
| 2997 | - |
|
| 2998 | - /** |
|
| 2999 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3000 | - * |
|
| 3001 | - * @var int $datetime_selector_checked |
|
| 3002 | - */ |
|
| 3003 | - private $datetime_selector_max_checked = 10; |
|
| 3004 | - |
|
| 3005 | - |
|
| 3006 | - /** |
|
| 3007 | - * class constructor |
|
| 3008 | - */ |
|
| 3009 | - public function __construct() |
|
| 3010 | - { |
|
| 3011 | - $this->show_ticket_sale_columns = true; |
|
| 3012 | - $this->show_ticket_details = true; |
|
| 3013 | - $this->show_expired_tickets = true; |
|
| 3014 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3015 | - $this->datetime_selector_threshold = 3; |
|
| 3016 | - $this->datetime_selector_max_checked = 10; |
|
| 3017 | - } |
|
| 3018 | - |
|
| 3019 | - |
|
| 3020 | - /** |
|
| 3021 | - * returns true if a datetime selector should be displayed |
|
| 3022 | - * |
|
| 3023 | - * @param array $datetimes |
|
| 3024 | - * @return bool |
|
| 3025 | - */ |
|
| 3026 | - public function showDatetimeSelector(array $datetimes) |
|
| 3027 | - { |
|
| 3028 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3029 | - return ! ( |
|
| 3030 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3031 | - || ( |
|
| 3032 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3033 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3034 | - ) |
|
| 3035 | - ); |
|
| 3036 | - } |
|
| 3037 | - |
|
| 3038 | - |
|
| 3039 | - /** |
|
| 3040 | - * @return string |
|
| 3041 | - */ |
|
| 3042 | - public function getShowDatetimeSelector() |
|
| 3043 | - { |
|
| 3044 | - return $this->show_datetime_selector; |
|
| 3045 | - } |
|
| 3046 | - |
|
| 3047 | - |
|
| 3048 | - /** |
|
| 3049 | - * @param bool $keys_only |
|
| 3050 | - * @return array |
|
| 3051 | - */ |
|
| 3052 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3053 | - { |
|
| 3054 | - return $keys_only |
|
| 3055 | - ? array( |
|
| 3056 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3057 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3058 | - ) |
|
| 3059 | - : array( |
|
| 3060 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3061 | - 'Do not show date & time filter', |
|
| 3062 | - 'event_espresso' |
|
| 3063 | - ), |
|
| 3064 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3065 | - 'Maybe show date & time filter', |
|
| 3066 | - 'event_espresso' |
|
| 3067 | - ), |
|
| 3068 | - ); |
|
| 3069 | - } |
|
| 3070 | - |
|
| 3071 | - |
|
| 3072 | - /** |
|
| 3073 | - * @param string $show_datetime_selector |
|
| 3074 | - */ |
|
| 3075 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3076 | - { |
|
| 3077 | - $this->show_datetime_selector = in_array( |
|
| 3078 | - $show_datetime_selector, |
|
| 3079 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3080 | - true |
|
| 3081 | - ) |
|
| 3082 | - ? $show_datetime_selector |
|
| 3083 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3084 | - } |
|
| 3085 | - |
|
| 3086 | - |
|
| 3087 | - /** |
|
| 3088 | - * @return int |
|
| 3089 | - */ |
|
| 3090 | - public function getDatetimeSelectorThreshold() |
|
| 3091 | - { |
|
| 3092 | - return $this->datetime_selector_threshold; |
|
| 3093 | - } |
|
| 3094 | - |
|
| 3095 | - |
|
| 3096 | - /** |
|
| 3097 | - * @param int $datetime_selector_threshold |
|
| 3098 | - */ |
|
| 3099 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3100 | - { |
|
| 3101 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3102 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3103 | - } |
|
| 3104 | - |
|
| 3105 | - |
|
| 3106 | - /** |
|
| 3107 | - * @return int |
|
| 3108 | - */ |
|
| 3109 | - public function getDatetimeSelectorMaxChecked() |
|
| 3110 | - { |
|
| 3111 | - return $this->datetime_selector_max_checked; |
|
| 3112 | - } |
|
| 3113 | - |
|
| 3114 | - |
|
| 3115 | - /** |
|
| 3116 | - * @param int $datetime_selector_max_checked |
|
| 3117 | - */ |
|
| 3118 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3119 | - { |
|
| 3120 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3121 | - } |
|
| 2956 | + /** |
|
| 2957 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2958 | + */ |
|
| 2959 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2960 | + |
|
| 2961 | + /** |
|
| 2962 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2963 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2964 | + */ |
|
| 2965 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2966 | + |
|
| 2967 | + /** |
|
| 2968 | + * @var boolean $show_ticket_sale_columns |
|
| 2969 | + */ |
|
| 2970 | + public $show_ticket_sale_columns; |
|
| 2971 | + |
|
| 2972 | + /** |
|
| 2973 | + * @var boolean $show_ticket_details |
|
| 2974 | + */ |
|
| 2975 | + public $show_ticket_details; |
|
| 2976 | + |
|
| 2977 | + /** |
|
| 2978 | + * @var boolean $show_expired_tickets |
|
| 2979 | + */ |
|
| 2980 | + public $show_expired_tickets; |
|
| 2981 | + |
|
| 2982 | + /** |
|
| 2983 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2984 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2985 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2986 | + * |
|
| 2987 | + * @var string $show_datetime_selector |
|
| 2988 | + */ |
|
| 2989 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2990 | + |
|
| 2991 | + /** |
|
| 2992 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2993 | + * |
|
| 2994 | + * @var int $datetime_selector_threshold |
|
| 2995 | + */ |
|
| 2996 | + private $datetime_selector_threshold = 3; |
|
| 2997 | + |
|
| 2998 | + /** |
|
| 2999 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3000 | + * |
|
| 3001 | + * @var int $datetime_selector_checked |
|
| 3002 | + */ |
|
| 3003 | + private $datetime_selector_max_checked = 10; |
|
| 3004 | + |
|
| 3005 | + |
|
| 3006 | + /** |
|
| 3007 | + * class constructor |
|
| 3008 | + */ |
|
| 3009 | + public function __construct() |
|
| 3010 | + { |
|
| 3011 | + $this->show_ticket_sale_columns = true; |
|
| 3012 | + $this->show_ticket_details = true; |
|
| 3013 | + $this->show_expired_tickets = true; |
|
| 3014 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3015 | + $this->datetime_selector_threshold = 3; |
|
| 3016 | + $this->datetime_selector_max_checked = 10; |
|
| 3017 | + } |
|
| 3018 | + |
|
| 3019 | + |
|
| 3020 | + /** |
|
| 3021 | + * returns true if a datetime selector should be displayed |
|
| 3022 | + * |
|
| 3023 | + * @param array $datetimes |
|
| 3024 | + * @return bool |
|
| 3025 | + */ |
|
| 3026 | + public function showDatetimeSelector(array $datetimes) |
|
| 3027 | + { |
|
| 3028 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3029 | + return ! ( |
|
| 3030 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3031 | + || ( |
|
| 3032 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3033 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3034 | + ) |
|
| 3035 | + ); |
|
| 3036 | + } |
|
| 3037 | + |
|
| 3038 | + |
|
| 3039 | + /** |
|
| 3040 | + * @return string |
|
| 3041 | + */ |
|
| 3042 | + public function getShowDatetimeSelector() |
|
| 3043 | + { |
|
| 3044 | + return $this->show_datetime_selector; |
|
| 3045 | + } |
|
| 3046 | + |
|
| 3047 | + |
|
| 3048 | + /** |
|
| 3049 | + * @param bool $keys_only |
|
| 3050 | + * @return array |
|
| 3051 | + */ |
|
| 3052 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3053 | + { |
|
| 3054 | + return $keys_only |
|
| 3055 | + ? array( |
|
| 3056 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3057 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3058 | + ) |
|
| 3059 | + : array( |
|
| 3060 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3061 | + 'Do not show date & time filter', |
|
| 3062 | + 'event_espresso' |
|
| 3063 | + ), |
|
| 3064 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3065 | + 'Maybe show date & time filter', |
|
| 3066 | + 'event_espresso' |
|
| 3067 | + ), |
|
| 3068 | + ); |
|
| 3069 | + } |
|
| 3070 | + |
|
| 3071 | + |
|
| 3072 | + /** |
|
| 3073 | + * @param string $show_datetime_selector |
|
| 3074 | + */ |
|
| 3075 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3076 | + { |
|
| 3077 | + $this->show_datetime_selector = in_array( |
|
| 3078 | + $show_datetime_selector, |
|
| 3079 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3080 | + true |
|
| 3081 | + ) |
|
| 3082 | + ? $show_datetime_selector |
|
| 3083 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3084 | + } |
|
| 3085 | + |
|
| 3086 | + |
|
| 3087 | + /** |
|
| 3088 | + * @return int |
|
| 3089 | + */ |
|
| 3090 | + public function getDatetimeSelectorThreshold() |
|
| 3091 | + { |
|
| 3092 | + return $this->datetime_selector_threshold; |
|
| 3093 | + } |
|
| 3094 | + |
|
| 3095 | + |
|
| 3096 | + /** |
|
| 3097 | + * @param int $datetime_selector_threshold |
|
| 3098 | + */ |
|
| 3099 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3100 | + { |
|
| 3101 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3102 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3103 | + } |
|
| 3104 | + |
|
| 3105 | + |
|
| 3106 | + /** |
|
| 3107 | + * @return int |
|
| 3108 | + */ |
|
| 3109 | + public function getDatetimeSelectorMaxChecked() |
|
| 3110 | + { |
|
| 3111 | + return $this->datetime_selector_max_checked; |
|
| 3112 | + } |
|
| 3113 | + |
|
| 3114 | + |
|
| 3115 | + /** |
|
| 3116 | + * @param int $datetime_selector_max_checked |
|
| 3117 | + */ |
|
| 3118 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3119 | + { |
|
| 3120 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3121 | + } |
|
| 3122 | 3122 | } |
| 3123 | 3123 | |
| 3124 | 3124 | /** |
@@ -3131,81 +3131,81 @@ discard block |
||
| 3131 | 3131 | class EE_Environment_Config extends EE_Config_Base |
| 3132 | 3132 | { |
| 3133 | 3133 | |
| 3134 | - /** |
|
| 3135 | - * Hold any php environment variables that we want to track. |
|
| 3136 | - * |
|
| 3137 | - * @var stdClass; |
|
| 3138 | - */ |
|
| 3139 | - public $php; |
|
| 3140 | - |
|
| 3141 | - |
|
| 3142 | - /** |
|
| 3143 | - * constructor |
|
| 3144 | - */ |
|
| 3145 | - public function __construct() |
|
| 3146 | - { |
|
| 3147 | - $this->php = new stdClass(); |
|
| 3148 | - $this->_set_php_values(); |
|
| 3149 | - } |
|
| 3150 | - |
|
| 3151 | - |
|
| 3152 | - /** |
|
| 3153 | - * This sets the php environment variables. |
|
| 3154 | - * |
|
| 3155 | - * @since 4.4.0 |
|
| 3156 | - * @return void |
|
| 3157 | - */ |
|
| 3158 | - protected function _set_php_values() |
|
| 3159 | - { |
|
| 3160 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3161 | - $this->php->version = phpversion(); |
|
| 3162 | - } |
|
| 3163 | - |
|
| 3164 | - |
|
| 3165 | - /** |
|
| 3166 | - * helper method for determining whether input_count is |
|
| 3167 | - * reaching the potential maximum the server can handle |
|
| 3168 | - * according to max_input_vars |
|
| 3169 | - * |
|
| 3170 | - * @param int $input_count the count of input vars. |
|
| 3171 | - * @return array { |
|
| 3172 | - * An array that represents whether available space and if no available space the error |
|
| 3173 | - * message. |
|
| 3174 | - * @type bool $has_space whether more inputs can be added. |
|
| 3175 | - * @type string $msg Any message to be displayed. |
|
| 3176 | - * } |
|
| 3177 | - */ |
|
| 3178 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3179 | - { |
|
| 3180 | - if (! empty($this->php->max_input_vars) |
|
| 3181 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3182 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3183 | - ) { |
|
| 3184 | - return sprintf( |
|
| 3185 | - __( |
|
| 3186 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3187 | - 'event_espresso' |
|
| 3188 | - ), |
|
| 3189 | - '<br>', |
|
| 3190 | - $input_count, |
|
| 3191 | - $this->php->max_input_vars |
|
| 3192 | - ); |
|
| 3193 | - } else { |
|
| 3194 | - return ''; |
|
| 3195 | - } |
|
| 3196 | - } |
|
| 3197 | - |
|
| 3198 | - |
|
| 3199 | - /** |
|
| 3200 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3201 | - * |
|
| 3202 | - * @since 4.4.1 |
|
| 3203 | - * @return void |
|
| 3204 | - */ |
|
| 3205 | - public function recheck_values() |
|
| 3206 | - { |
|
| 3207 | - $this->_set_php_values(); |
|
| 3208 | - } |
|
| 3134 | + /** |
|
| 3135 | + * Hold any php environment variables that we want to track. |
|
| 3136 | + * |
|
| 3137 | + * @var stdClass; |
|
| 3138 | + */ |
|
| 3139 | + public $php; |
|
| 3140 | + |
|
| 3141 | + |
|
| 3142 | + /** |
|
| 3143 | + * constructor |
|
| 3144 | + */ |
|
| 3145 | + public function __construct() |
|
| 3146 | + { |
|
| 3147 | + $this->php = new stdClass(); |
|
| 3148 | + $this->_set_php_values(); |
|
| 3149 | + } |
|
| 3150 | + |
|
| 3151 | + |
|
| 3152 | + /** |
|
| 3153 | + * This sets the php environment variables. |
|
| 3154 | + * |
|
| 3155 | + * @since 4.4.0 |
|
| 3156 | + * @return void |
|
| 3157 | + */ |
|
| 3158 | + protected function _set_php_values() |
|
| 3159 | + { |
|
| 3160 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3161 | + $this->php->version = phpversion(); |
|
| 3162 | + } |
|
| 3163 | + |
|
| 3164 | + |
|
| 3165 | + /** |
|
| 3166 | + * helper method for determining whether input_count is |
|
| 3167 | + * reaching the potential maximum the server can handle |
|
| 3168 | + * according to max_input_vars |
|
| 3169 | + * |
|
| 3170 | + * @param int $input_count the count of input vars. |
|
| 3171 | + * @return array { |
|
| 3172 | + * An array that represents whether available space and if no available space the error |
|
| 3173 | + * message. |
|
| 3174 | + * @type bool $has_space whether more inputs can be added. |
|
| 3175 | + * @type string $msg Any message to be displayed. |
|
| 3176 | + * } |
|
| 3177 | + */ |
|
| 3178 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3179 | + { |
|
| 3180 | + if (! empty($this->php->max_input_vars) |
|
| 3181 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3182 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3183 | + ) { |
|
| 3184 | + return sprintf( |
|
| 3185 | + __( |
|
| 3186 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3187 | + 'event_espresso' |
|
| 3188 | + ), |
|
| 3189 | + '<br>', |
|
| 3190 | + $input_count, |
|
| 3191 | + $this->php->max_input_vars |
|
| 3192 | + ); |
|
| 3193 | + } else { |
|
| 3194 | + return ''; |
|
| 3195 | + } |
|
| 3196 | + } |
|
| 3197 | + |
|
| 3198 | + |
|
| 3199 | + /** |
|
| 3200 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3201 | + * |
|
| 3202 | + * @since 4.4.1 |
|
| 3203 | + * @return void |
|
| 3204 | + */ |
|
| 3205 | + public function recheck_values() |
|
| 3206 | + { |
|
| 3207 | + $this->_set_php_values(); |
|
| 3208 | + } |
|
| 3209 | 3209 | } |
| 3210 | 3210 | |
| 3211 | 3211 | /** |
@@ -3218,21 +3218,21 @@ discard block |
||
| 3218 | 3218 | class EE_Tax_Config extends EE_Config_Base |
| 3219 | 3219 | { |
| 3220 | 3220 | |
| 3221 | - /* |
|
| 3221 | + /* |
|
| 3222 | 3222 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3223 | 3223 | * |
| 3224 | 3224 | * @var boolean $prices_displayed_including_taxes |
| 3225 | 3225 | */ |
| 3226 | - public $prices_displayed_including_taxes; |
|
| 3226 | + public $prices_displayed_including_taxes; |
|
| 3227 | 3227 | |
| 3228 | 3228 | |
| 3229 | - /** |
|
| 3230 | - * class constructor |
|
| 3231 | - */ |
|
| 3232 | - public function __construct() |
|
| 3233 | - { |
|
| 3234 | - $this->prices_displayed_including_taxes = true; |
|
| 3235 | - } |
|
| 3229 | + /** |
|
| 3230 | + * class constructor |
|
| 3231 | + */ |
|
| 3232 | + public function __construct() |
|
| 3233 | + { |
|
| 3234 | + $this->prices_displayed_including_taxes = true; |
|
| 3235 | + } |
|
| 3236 | 3236 | } |
| 3237 | 3237 | |
| 3238 | 3238 | /** |
@@ -3246,19 +3246,19 @@ discard block |
||
| 3246 | 3246 | class EE_Messages_Config extends EE_Config_Base |
| 3247 | 3247 | { |
| 3248 | 3248 | |
| 3249 | - /** |
|
| 3250 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3251 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3252 | - * |
|
| 3253 | - * @var integer |
|
| 3254 | - */ |
|
| 3255 | - public $delete_threshold; |
|
| 3249 | + /** |
|
| 3250 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3251 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3252 | + * |
|
| 3253 | + * @var integer |
|
| 3254 | + */ |
|
| 3255 | + public $delete_threshold; |
|
| 3256 | 3256 | |
| 3257 | 3257 | |
| 3258 | - public function __construct() |
|
| 3259 | - { |
|
| 3260 | - $this->delete_threshold = 0; |
|
| 3261 | - } |
|
| 3258 | + public function __construct() |
|
| 3259 | + { |
|
| 3260 | + $this->delete_threshold = 0; |
|
| 3261 | + } |
|
| 3262 | 3262 | } |
| 3263 | 3263 | |
| 3264 | 3264 | /** |
@@ -3269,31 +3269,31 @@ discard block |
||
| 3269 | 3269 | class EE_Gateway_Config extends EE_Config_Base |
| 3270 | 3270 | { |
| 3271 | 3271 | |
| 3272 | - /** |
|
| 3273 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3274 | - * with any config info the gateway wants to store |
|
| 3275 | - * |
|
| 3276 | - * @var array |
|
| 3277 | - */ |
|
| 3278 | - public $payment_settings; |
|
| 3279 | - |
|
| 3280 | - /** |
|
| 3281 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3282 | - * the gateway is stored in the uploads directory |
|
| 3283 | - * |
|
| 3284 | - * @var array |
|
| 3285 | - */ |
|
| 3286 | - public $active_gateways; |
|
| 3287 | - |
|
| 3288 | - |
|
| 3289 | - /** |
|
| 3290 | - * class constructor |
|
| 3291 | - * |
|
| 3292 | - * @deprecated |
|
| 3293 | - */ |
|
| 3294 | - public function __construct() |
|
| 3295 | - { |
|
| 3296 | - $this->payment_settings = array(); |
|
| 3297 | - $this->active_gateways = array('Invoice' => false); |
|
| 3298 | - } |
|
| 3272 | + /** |
|
| 3273 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3274 | + * with any config info the gateway wants to store |
|
| 3275 | + * |
|
| 3276 | + * @var array |
|
| 3277 | + */ |
|
| 3278 | + public $payment_settings; |
|
| 3279 | + |
|
| 3280 | + /** |
|
| 3281 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3282 | + * the gateway is stored in the uploads directory |
|
| 3283 | + * |
|
| 3284 | + * @var array |
|
| 3285 | + */ |
|
| 3286 | + public $active_gateways; |
|
| 3287 | + |
|
| 3288 | + |
|
| 3289 | + /** |
|
| 3290 | + * class constructor |
|
| 3291 | + * |
|
| 3292 | + * @deprecated |
|
| 3293 | + */ |
|
| 3294 | + public function __construct() |
|
| 3295 | + { |
|
| 3296 | + $this->payment_settings = array(); |
|
| 3297 | + $this->active_gateways = array('Invoice' => false); |
|
| 3298 | + } |
|
| 3299 | 3299 | } |
@@ -18,842 +18,842 @@ |
||
| 18 | 18 | class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var EE_Payment_Processor $_instance |
|
| 23 | - * @access private |
|
| 24 | - */ |
|
| 25 | - private static $_instance; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @singleton method used to instantiate class object |
|
| 30 | - * @access public |
|
| 31 | - * @return EE_Payment_Processor instance |
|
| 32 | - */ |
|
| 33 | - public static function instance() |
|
| 34 | - { |
|
| 35 | - // check if class object is instantiated |
|
| 36 | - if (! self::$_instance instanceof EE_Payment_Processor) { |
|
| 37 | - self::$_instance = new self(); |
|
| 38 | - } |
|
| 39 | - return self::$_instance; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return EE_Payment_Processor |
|
| 45 | - */ |
|
| 46 | - public static function reset() |
|
| 47 | - { |
|
| 48 | - self::$_instance = null; |
|
| 49 | - return self::instance(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - *private constructor to prevent direct creation |
|
| 55 | - * |
|
| 56 | - * @Constructor |
|
| 57 | - * @access private |
|
| 58 | - */ |
|
| 59 | - private function __construct() |
|
| 60 | - { |
|
| 61 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
| 62 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
| 68 | - * appropriately. Saves the payment that is generated |
|
| 69 | - * |
|
| 70 | - * @param EE_Payment_Method $payment_method |
|
| 71 | - * @param EE_Transaction $transaction |
|
| 72 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
| 73 | - * Leave null if payment is for the full amount owing |
|
| 74 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
| 75 | - * Receive_form_submission() should have |
|
| 76 | - * already been called on the billing form |
|
| 77 | - * (ie, its inputs should have their normalized values set). |
|
| 78 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
| 79 | - * where to go AFTER the offsite gateway |
|
| 80 | - * @param string $method like 'CART', indicates who the client who called this was |
|
| 81 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
| 82 | - * @param boolean $update_txn whether or not to call |
|
| 83 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
| 84 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
| 85 | - * @return EE_Payment |
|
| 86 | - * @throws EE_Error |
|
| 87 | - * @throws InvalidArgumentException |
|
| 88 | - * @throws ReflectionException |
|
| 89 | - * @throws RuntimeException |
|
| 90 | - * @throws InvalidDataTypeException |
|
| 91 | - * @throws InvalidInterfaceException |
|
| 92 | - */ |
|
| 93 | - public function process_payment( |
|
| 94 | - EE_Payment_Method $payment_method, |
|
| 95 | - EE_Transaction $transaction, |
|
| 96 | - $amount = null, |
|
| 97 | - $billing_form = null, |
|
| 98 | - $return_url = null, |
|
| 99 | - $method = 'CART', |
|
| 100 | - $by_admin = false, |
|
| 101 | - $update_txn = true, |
|
| 102 | - $cancel_url = '' |
|
| 103 | - ) { |
|
| 104 | - if ((float) $amount < 0) { |
|
| 105 | - throw new EE_Error( |
|
| 106 | - sprintf( |
|
| 107 | - __( |
|
| 108 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
| 109 | - 'event_espresso' |
|
| 110 | - ), |
|
| 111 | - $amount, |
|
| 112 | - $transaction->ID() |
|
| 113 | - ) |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - // verify payment method |
|
| 117 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
| 118 | - $payment_method, |
|
| 119 | - true |
|
| 120 | - ); |
|
| 121 | - // verify transaction |
|
| 122 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 123 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
| 124 | - // verify payment method type |
|
| 125 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 126 | - $payment = $payment_method->type_obj()->process_payment( |
|
| 127 | - $transaction, |
|
| 128 | - min($amount, $transaction->remaining()), // make sure we don't overcharge |
|
| 129 | - $billing_form, |
|
| 130 | - $return_url, |
|
| 131 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
| 132 | - $method, |
|
| 133 | - $by_admin |
|
| 134 | - ); |
|
| 135 | - // check if payment method uses an off-site gateway |
|
| 136 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
| 137 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
| 138 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
| 139 | - } |
|
| 140 | - return $payment; |
|
| 141 | - } |
|
| 142 | - EE_Error::add_error( |
|
| 143 | - sprintf( |
|
| 144 | - __( |
|
| 145 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 146 | - 'event_espresso' |
|
| 147 | - ), |
|
| 148 | - '<br/>', |
|
| 149 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 150 | - ), |
|
| 151 | - __FILE__, |
|
| 152 | - __FUNCTION__, |
|
| 153 | - __LINE__ |
|
| 154 | - ); |
|
| 155 | - return null; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param EE_Transaction|int $transaction |
|
| 161 | - * @param EE_Payment_Method $payment_method |
|
| 162 | - * @return string |
|
| 163 | - * @throws EE_Error |
|
| 164 | - * @throws InvalidArgumentException |
|
| 165 | - * @throws InvalidDataTypeException |
|
| 166 | - * @throws InvalidInterfaceException |
|
| 167 | - */ |
|
| 168 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
| 169 | - { |
|
| 170 | - /** @type \EE_Transaction $transaction */ |
|
| 171 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 172 | - $primary_reg = $transaction->primary_registration(); |
|
| 173 | - if (! $primary_reg instanceof EE_Registration) { |
|
| 174 | - throw new EE_Error( |
|
| 175 | - sprintf( |
|
| 176 | - __( |
|
| 177 | - 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
| 178 | - 'event_espresso' |
|
| 179 | - ), |
|
| 180 | - $transaction->ID() |
|
| 181 | - ) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
| 185 | - $payment_method, |
|
| 186 | - true |
|
| 187 | - ); |
|
| 188 | - $url = add_query_arg( |
|
| 189 | - array( |
|
| 190 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
| 191 | - 'ee_payment_method' => $payment_method->slug(), |
|
| 192 | - ), |
|
| 193 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
| 194 | - ); |
|
| 195 | - return $url; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
| 201 | - * we can easily find what registration the IPN is for and what payment method. |
|
| 202 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
| 203 | - * If a payment is found for the IPN info, it is saved. |
|
| 204 | - * |
|
| 205 | - * @param array $_req_data eg $_REQUEST |
|
| 206 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
| 207 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
| 208 | - * @param boolean $update_txn whether or not to call |
|
| 209 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
| 210 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
| 211 | - * or is processed manually ( false like Mijireh ) |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws Exception |
|
| 214 | - * @return EE_Payment |
|
| 215 | - * @throws \RuntimeException |
|
| 216 | - * @throws \ReflectionException |
|
| 217 | - * @throws \InvalidArgumentException |
|
| 218 | - * @throws InvalidInterfaceException |
|
| 219 | - * @throws InvalidDataTypeException |
|
| 220 | - */ |
|
| 221 | - public function process_ipn( |
|
| 222 | - $_req_data, |
|
| 223 | - $transaction = null, |
|
| 224 | - $payment_method = null, |
|
| 225 | - $update_txn = true, |
|
| 226 | - $separate_IPN_request = true |
|
| 227 | - ) { |
|
| 228 | - EE_Registry::instance()->load_model('Change_Log'); |
|
| 229 | - $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
| 230 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
| 231 | - $obj_for_log = null; |
|
| 232 | - if ($transaction instanceof EE_Transaction) { |
|
| 233 | - $obj_for_log = $transaction; |
|
| 234 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 235 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
| 236 | - array( |
|
| 237 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
| 238 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - } elseif ($payment_method instanceof EE_Payment) { |
|
| 243 | - $obj_for_log = $payment_method; |
|
| 244 | - } |
|
| 245 | - $log = EEM_Change_Log::instance()->log( |
|
| 246 | - EEM_Change_Log::type_gateway, |
|
| 247 | - array('IPN data received' => $_req_data), |
|
| 248 | - $obj_for_log |
|
| 249 | - ); |
|
| 250 | - try { |
|
| 251 | - /** |
|
| 252 | - * @var EE_Payment $payment |
|
| 253 | - */ |
|
| 254 | - $payment = null; |
|
| 255 | - if ($transaction && $payment_method) { |
|
| 256 | - /** @type EE_Transaction $transaction */ |
|
| 257 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 258 | - /** @type EE_Payment_Method $payment_method */ |
|
| 259 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
| 260 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 261 | - try { |
|
| 262 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
| 263 | - $log->set_object($payment); |
|
| 264 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
| 265 | - EEM_Change_Log::instance()->log( |
|
| 266 | - EEM_Change_Log::type_gateway, |
|
| 267 | - array( |
|
| 268 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
| 269 | - 'current_url' => EEH_URL::current_url(), |
|
| 270 | - 'payment' => $e->getPaymentProperties(), |
|
| 271 | - 'IPN_data' => $e->getIpnData(), |
|
| 272 | - ), |
|
| 273 | - $obj_for_log |
|
| 274 | - ); |
|
| 275 | - return $e->getPayment(); |
|
| 276 | - } |
|
| 277 | - } else { |
|
| 278 | - // not a payment |
|
| 279 | - EE_Error::add_error( |
|
| 280 | - sprintf( |
|
| 281 | - __( |
|
| 282 | - 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', |
|
| 283 | - 'event_espresso' |
|
| 284 | - ), |
|
| 285 | - '<br/>', |
|
| 286 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 287 | - ), |
|
| 288 | - __FILE__, |
|
| 289 | - __FUNCTION__, |
|
| 290 | - __LINE__ |
|
| 291 | - ); |
|
| 292 | - } |
|
| 293 | - } else { |
|
| 294 | - // that's actually pretty ok. The IPN just wasn't able |
|
| 295 | - // to identify which transaction or payment method this was for |
|
| 296 | - // give all active payment methods a chance to claim it |
|
| 297 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
| 298 | - foreach ($active_payment_methods as $active_payment_method) { |
|
| 299 | - try { |
|
| 300 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
| 301 | - $payment_method = $active_payment_method; |
|
| 302 | - EEM_Change_Log::instance()->log( |
|
| 303 | - EEM_Change_Log::type_gateway, |
|
| 304 | - array('IPN data' => $_req_data), |
|
| 305 | - $payment |
|
| 306 | - ); |
|
| 307 | - break; |
|
| 308 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
| 309 | - EEM_Change_Log::instance()->log( |
|
| 310 | - EEM_Change_Log::type_gateway, |
|
| 311 | - array( |
|
| 312 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
| 313 | - 'current_url' => EEH_URL::current_url(), |
|
| 314 | - 'payment' => $e->getPaymentProperties(), |
|
| 315 | - 'IPN_data' => $e->getIpnData(), |
|
| 316 | - ), |
|
| 317 | - $obj_for_log |
|
| 318 | - ); |
|
| 319 | - return $e->getPayment(); |
|
| 320 | - } catch (EE_Error $e) { |
|
| 321 | - // that's fine- it apparently couldn't handle the IPN |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
| 326 | - if ($payment instanceof EE_Payment) { |
|
| 327 | - $payment->save(); |
|
| 328 | - // update the TXN |
|
| 329 | - $this->update_txn_based_on_payment( |
|
| 330 | - $transaction, |
|
| 331 | - $payment, |
|
| 332 | - $update_txn, |
|
| 333 | - $separate_IPN_request |
|
| 334 | - ); |
|
| 335 | - } else { |
|
| 336 | - // we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
| 337 | - if ($payment_method) { |
|
| 338 | - EEM_Change_Log::instance()->log( |
|
| 339 | - EEM_Change_Log::type_gateway, |
|
| 340 | - array('IPN data' => $_req_data), |
|
| 341 | - $payment_method |
|
| 342 | - ); |
|
| 343 | - } elseif ($transaction) { |
|
| 344 | - EEM_Change_Log::instance()->log( |
|
| 345 | - EEM_Change_Log::type_gateway, |
|
| 346 | - array('IPN data' => $_req_data), |
|
| 347 | - $transaction |
|
| 348 | - ); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - return $payment; |
|
| 352 | - } catch (EE_Error $e) { |
|
| 353 | - do_action( |
|
| 354 | - 'AHEE__log', |
|
| 355 | - __FILE__, |
|
| 356 | - __FUNCTION__, |
|
| 357 | - sprintf( |
|
| 358 | - __( |
|
| 359 | - 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
| 360 | - 'event_espresso' |
|
| 361 | - ), |
|
| 362 | - print_r($transaction, true), |
|
| 363 | - print_r($_req_data, true), |
|
| 364 | - $e->getMessage() |
|
| 365 | - ) |
|
| 366 | - ); |
|
| 367 | - throw $e; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Removes any non-printable illegal characters from the input, |
|
| 374 | - * which might cause a raucous when trying to insert into the database |
|
| 375 | - * |
|
| 376 | - * @param array $request_data |
|
| 377 | - * @return array |
|
| 378 | - */ |
|
| 379 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
| 380 | - { |
|
| 381 | - $return_data = array(); |
|
| 382 | - foreach ($request_data as $key => $value) { |
|
| 383 | - $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
| 384 | - $value |
|
| 385 | - ); |
|
| 386 | - } |
|
| 387 | - return $return_data; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Removes any non-printable illegal characters from the input, |
|
| 393 | - * which might cause a raucous when trying to insert into the database |
|
| 394 | - * |
|
| 395 | - * @param string $request_data |
|
| 396 | - * @return string |
|
| 397 | - */ |
|
| 398 | - protected function _remove_unusable_characters($request_data) |
|
| 399 | - { |
|
| 400 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Should be called just before displaying the payment attempt results to the user, |
|
| 406 | - * when the payment attempt has finished. Some payment methods may have special |
|
| 407 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
| 408 | - * and then the user is redirected to a page that displays the payment's status, this |
|
| 409 | - * should be called while loading the page that displays the payment's status. If the user is |
|
| 410 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
| 411 | - * provider. |
|
| 412 | - * |
|
| 413 | - * @param EE_Transaction|int $transaction |
|
| 414 | - * @param bool $update_txn whether or not to call |
|
| 415 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
| 416 | - * @return EE_Payment |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws InvalidArgumentException |
|
| 419 | - * @throws ReflectionException |
|
| 420 | - * @throws RuntimeException |
|
| 421 | - * @throws InvalidDataTypeException |
|
| 422 | - * @throws InvalidInterfaceException |
|
| 423 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
| 424 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
| 425 | - */ |
|
| 426 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
| 427 | - { |
|
| 428 | - /** @var $transaction EE_Transaction */ |
|
| 429 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 430 | - $last_payment_method = $transaction->payment_method(); |
|
| 431 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
| 432 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
| 433 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
| 434 | - return $payment; |
|
| 435 | - } |
|
| 436 | - return null; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
| 442 | - * |
|
| 443 | - * @param EE_Payment_Method $payment_method |
|
| 444 | - * @param EE_Payment $payment_to_refund |
|
| 445 | - * @param array $refund_info |
|
| 446 | - * @return EE_Payment |
|
| 447 | - * @throws EE_Error |
|
| 448 | - * @throws InvalidArgumentException |
|
| 449 | - * @throws ReflectionException |
|
| 450 | - * @throws RuntimeException |
|
| 451 | - * @throws InvalidDataTypeException |
|
| 452 | - * @throws InvalidInterfaceException |
|
| 453 | - */ |
|
| 454 | - public function process_refund( |
|
| 455 | - EE_Payment_Method $payment_method, |
|
| 456 | - EE_Payment $payment_to_refund, |
|
| 457 | - array $refund_info = array() |
|
| 458 | - ) { |
|
| 459 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
| 460 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
| 461 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
| 462 | - } |
|
| 463 | - return $payment_to_refund; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * This should be called each time there may have been an update to a |
|
| 469 | - * payment on a transaction (ie, we asked for a payment to process a |
|
| 470 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
| 471 | - * we told a payment method to |
|
| 472 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
| 473 | - * process a refund. This should handle firing the correct hooks to |
|
| 474 | - * indicate |
|
| 475 | - * what exactly happened and updating the transaction appropriately). This |
|
| 476 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
| 477 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
| 478 | - * of transactions and payments, and to be tied to payment processing. |
|
| 479 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
| 480 | - * of previous code to decide whether or not to save (because the payment passed into |
|
| 481 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
| 482 | - * in which case we only want that payment object for some temporary usage during this request, |
|
| 483 | - * but we don't want it to be saved). |
|
| 484 | - * |
|
| 485 | - * @param EE_Transaction|int $transaction |
|
| 486 | - * @param EE_Payment $payment |
|
| 487 | - * @param boolean $update_txn |
|
| 488 | - * whether or not to call |
|
| 489 | - * EE_Transaction_Processor:: |
|
| 490 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
| 491 | - * (you can save 1 DB query if you know you're going |
|
| 492 | - * to save it later instead) |
|
| 493 | - * @param bool $IPN |
|
| 494 | - * if processing IPNs or other similar payment |
|
| 495 | - * related activities that occur in alternate |
|
| 496 | - * requests than the main one that is processing the |
|
| 497 | - * TXN, then set this to true to check whether the |
|
| 498 | - * TXN is locked before updating |
|
| 499 | - * @throws EE_Error |
|
| 500 | - * @throws InvalidArgumentException |
|
| 501 | - * @throws ReflectionException |
|
| 502 | - * @throws RuntimeException |
|
| 503 | - * @throws InvalidDataTypeException |
|
| 504 | - * @throws InvalidInterfaceException |
|
| 505 | - */ |
|
| 506 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
| 507 | - { |
|
| 508 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
| 509 | - /** @type EE_Transaction $transaction */ |
|
| 510 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 511 | - // can we freely update the TXN at this moment? |
|
| 512 | - if ($IPN && $transaction->is_locked()) { |
|
| 513 | - // don't update the transaction at this exact moment |
|
| 514 | - // because the TXN is active in another request |
|
| 515 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 516 | - time(), |
|
| 517 | - $transaction->ID(), |
|
| 518 | - $payment->ID() |
|
| 519 | - ); |
|
| 520 | - } else { |
|
| 521 | - // verify payment and that it has been saved |
|
| 522 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
| 523 | - if ($payment->payment_method() instanceof EE_Payment_Method |
|
| 524 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
| 525 | - ) { |
|
| 526 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
| 527 | - // update TXN registrations with payment info |
|
| 528 | - $this->process_registration_payments($transaction, $payment); |
|
| 529 | - } |
|
| 530 | - $do_action = $payment->just_approved() |
|
| 531 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
| 532 | - : $do_action; |
|
| 533 | - } else { |
|
| 534 | - // send out notifications |
|
| 535 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 536 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
| 537 | - } |
|
| 538 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
| 539 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 540 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 541 | - // set new value for total paid |
|
| 542 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
| 543 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
| 544 | - if ($update_txn) { |
|
| 545 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - // granular hook for others to use. |
|
| 549 | - do_action($do_action, $transaction, $payment); |
|
| 550 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
| 551 | - // global hook for others to use. |
|
| 552 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
| 559 | - * |
|
| 560 | - * @param EE_Transaction $transaction |
|
| 561 | - * @param EE_Payment $payment |
|
| 562 | - * @param EE_Registration[] $registrations |
|
| 563 | - * @throws EE_Error |
|
| 564 | - * @throws InvalidArgumentException |
|
| 565 | - * @throws RuntimeException |
|
| 566 | - * @throws InvalidDataTypeException |
|
| 567 | - * @throws InvalidInterfaceException |
|
| 568 | - */ |
|
| 569 | - public function process_registration_payments( |
|
| 570 | - EE_Transaction $transaction, |
|
| 571 | - EE_Payment $payment, |
|
| 572 | - array $registrations = array() |
|
| 573 | - ) { |
|
| 574 | - // only process if payment was successful |
|
| 575 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
| 576 | - return; |
|
| 577 | - } |
|
| 578 | - // EEM_Registration::instance()->show_next_x_db_queries(); |
|
| 579 | - if (empty($registrations)) { |
|
| 580 | - // find registrations with monies owing that can receive a payment |
|
| 581 | - $registrations = $transaction->registrations( |
|
| 582 | - array( |
|
| 583 | - array( |
|
| 584 | - // only these reg statuses can receive payments |
|
| 585 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
| 586 | - 'REG_final_price' => array('!=', 0), |
|
| 587 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
| 588 | - ), |
|
| 589 | - ) |
|
| 590 | - ); |
|
| 591 | - } |
|
| 592 | - // still nothing ??!?? |
|
| 593 | - if (empty($registrations)) { |
|
| 594 | - return; |
|
| 595 | - } |
|
| 596 | - // todo: break out the following logic into a separate strategy class |
|
| 597 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
| 598 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
| 599 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
| 600 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
| 601 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
| 602 | - $refund = $payment->is_a_refund(); |
|
| 603 | - // how much is available to apply to registrations? |
|
| 604 | - $available_payment_amount = abs($payment->amount()); |
|
| 605 | - foreach ($registrations as $registration) { |
|
| 606 | - if ($registration instanceof EE_Registration) { |
|
| 607 | - // nothing left? |
|
| 608 | - if ($available_payment_amount <= 0) { |
|
| 609 | - break; |
|
| 610 | - } |
|
| 611 | - if ($refund) { |
|
| 612 | - $available_payment_amount = $this->process_registration_refund( |
|
| 613 | - $registration, |
|
| 614 | - $payment, |
|
| 615 | - $available_payment_amount |
|
| 616 | - ); |
|
| 617 | - } else { |
|
| 618 | - $available_payment_amount = $this->process_registration_payment( |
|
| 619 | - $registration, |
|
| 620 | - $payment, |
|
| 621 | - $available_payment_amount |
|
| 622 | - ); |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - if ($available_payment_amount > 0 |
|
| 627 | - && apply_filters( |
|
| 628 | - 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
| 629 | - false |
|
| 630 | - )) { |
|
| 631 | - EE_Error::add_attention( |
|
| 632 | - sprintf( |
|
| 633 | - __( |
|
| 634 | - 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - EEH_Template::format_currency($available_payment_amount), |
|
| 638 | - implode(', ', array_keys($registrations)), |
|
| 639 | - '<br/>', |
|
| 640 | - EEH_Template::format_currency($payment->amount()) |
|
| 641 | - ), |
|
| 642 | - __FILE__, |
|
| 643 | - __FUNCTION__, |
|
| 644 | - __LINE__ |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * update registration REG_paid field after successful payment and link registration with payment |
|
| 652 | - * |
|
| 653 | - * @param EE_Registration $registration |
|
| 654 | - * @param EE_Payment $payment |
|
| 655 | - * @param float $available_payment_amount |
|
| 656 | - * @return float |
|
| 657 | - * @throws EE_Error |
|
| 658 | - * @throws InvalidArgumentException |
|
| 659 | - * @throws RuntimeException |
|
| 660 | - * @throws InvalidDataTypeException |
|
| 661 | - * @throws InvalidInterfaceException |
|
| 662 | - */ |
|
| 663 | - public function process_registration_payment( |
|
| 664 | - EE_Registration $registration, |
|
| 665 | - EE_Payment $payment, |
|
| 666 | - $available_payment_amount = 0.00 |
|
| 667 | - ) { |
|
| 668 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 669 | - if ($owing > 0) { |
|
| 670 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
| 671 | - $payment_amount = min($available_payment_amount, $owing); |
|
| 672 | - // update $available_payment_amount |
|
| 673 | - $available_payment_amount -= $payment_amount; |
|
| 674 | - // calculate and set new REG_paid |
|
| 675 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
| 676 | - // now save it |
|
| 677 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
| 678 | - } |
|
| 679 | - return $available_payment_amount; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * update registration REG_paid field after successful payment and link registration with payment |
|
| 685 | - * |
|
| 686 | - * @param EE_Registration $registration |
|
| 687 | - * @param EE_Payment $payment |
|
| 688 | - * @param float $payment_amount |
|
| 689 | - * @return void |
|
| 690 | - * @throws EE_Error |
|
| 691 | - * @throws InvalidArgumentException |
|
| 692 | - * @throws InvalidDataTypeException |
|
| 693 | - * @throws InvalidInterfaceException |
|
| 694 | - */ |
|
| 695 | - protected function _apply_registration_payment( |
|
| 696 | - EE_Registration $registration, |
|
| 697 | - EE_Payment $payment, |
|
| 698 | - $payment_amount = 0.00 |
|
| 699 | - ) { |
|
| 700 | - // find any existing reg payment records for this registration and payment |
|
| 701 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
| 702 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
| 703 | - ); |
|
| 704 | - // if existing registration payment exists |
|
| 705 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
| 706 | - // then update that record |
|
| 707 | - $existing_reg_payment->set_amount($payment_amount); |
|
| 708 | - $existing_reg_payment->save(); |
|
| 709 | - } else { |
|
| 710 | - // or add new relation between registration and payment and set amount |
|
| 711 | - $registration->_add_relation_to( |
|
| 712 | - $payment, |
|
| 713 | - 'Payment', |
|
| 714 | - array('RPY_amount' => $payment_amount) |
|
| 715 | - ); |
|
| 716 | - // make it stick |
|
| 717 | - $registration->save(); |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * update registration REG_paid field after refund and link registration with payment |
|
| 724 | - * |
|
| 725 | - * @param EE_Registration $registration |
|
| 726 | - * @param EE_Payment $payment |
|
| 727 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
| 728 | - * @return float |
|
| 729 | - * @throws EE_Error |
|
| 730 | - * @throws InvalidArgumentException |
|
| 731 | - * @throws RuntimeException |
|
| 732 | - * @throws InvalidDataTypeException |
|
| 733 | - * @throws InvalidInterfaceException |
|
| 734 | - */ |
|
| 735 | - public function process_registration_refund( |
|
| 736 | - EE_Registration $registration, |
|
| 737 | - EE_Payment $payment, |
|
| 738 | - $available_refund_amount = 0.00 |
|
| 739 | - ) { |
|
| 740 | - // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
| 741 | - if ($registration->paid() > 0) { |
|
| 742 | - // ensure $available_refund_amount is NOT negative |
|
| 743 | - $available_refund_amount = (float) abs($available_refund_amount); |
|
| 744 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
| 745 | - $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
| 746 | - // update $available_payment_amount |
|
| 747 | - $available_refund_amount -= $refund_amount; |
|
| 748 | - // calculate and set new REG_paid |
|
| 749 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
| 750 | - // convert payment amount back to a negative value for storage in the db |
|
| 751 | - $refund_amount = (float) abs($refund_amount) * -1; |
|
| 752 | - // now save it |
|
| 753 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
| 754 | - } |
|
| 755 | - return $available_refund_amount; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * Process payments and transaction after payment process completed. |
|
| 761 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
| 762 | - * if this request happens to be processing an IPN, |
|
| 763 | - * then we will also set the Payment Options Reg Step to completed, |
|
| 764 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
| 765 | - * |
|
| 766 | - * @param EE_Transaction $transaction |
|
| 767 | - * @param EE_Payment $payment |
|
| 768 | - * @param bool $IPN |
|
| 769 | - * @throws EE_Error |
|
| 770 | - * @throws InvalidArgumentException |
|
| 771 | - * @throws ReflectionException |
|
| 772 | - * @throws RuntimeException |
|
| 773 | - * @throws InvalidDataTypeException |
|
| 774 | - * @throws InvalidInterfaceException |
|
| 775 | - */ |
|
| 776 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
| 777 | - { |
|
| 778 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 779 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 780 | - // is the Payment Options Reg Step completed ? |
|
| 781 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
| 782 | - // if the Payment Options Reg Step is completed... |
|
| 783 | - $revisit = $payment_options_step_completed === true; |
|
| 784 | - // then this is kinda sorta a revisit with regards to payments at least |
|
| 785 | - $transaction_processor->set_revisit($revisit); |
|
| 786 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
| 787 | - if ($IPN |
|
| 788 | - && $payment_options_step_completed !== true |
|
| 789 | - && ($payment->is_approved() || $payment->is_pending()) |
|
| 790 | - ) { |
|
| 791 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
| 792 | - 'payment_options' |
|
| 793 | - ); |
|
| 794 | - } |
|
| 795 | - // maybe update status, but don't save transaction just yet |
|
| 796 | - $transaction->update_status_based_on_total_paid(false); |
|
| 797 | - // check if 'finalize_registration' step has been completed... |
|
| 798 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 799 | - // if this is an IPN and the final step has not been initiated |
|
| 800 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
| 801 | - // and if it hasn't already been set as being started... |
|
| 802 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
| 803 | - } |
|
| 804 | - $transaction->save(); |
|
| 805 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
| 806 | - if ($IPN && $finalized !== false) { |
|
| 807 | - // and if we are all good to go, then send out notifications |
|
| 808 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 809 | - // ok, now process the transaction according to the payment |
|
| 810 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 811 | - $transaction, |
|
| 812 | - $payment |
|
| 813 | - ); |
|
| 814 | - } |
|
| 815 | - // DEBUG LOG |
|
| 816 | - $payment_method = $payment->payment_method(); |
|
| 817 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 818 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
| 819 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
| 820 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
| 821 | - if ($gateway instanceof EE_Gateway) { |
|
| 822 | - $gateway->log( |
|
| 823 | - array( |
|
| 824 | - 'message' => (string) __('Post Payment Transaction Details', 'event_espresso'), |
|
| 825 | - 'transaction' => $transaction->model_field_array(), |
|
| 826 | - 'finalized' => $finalized, |
|
| 827 | - 'IPN' => $IPN, |
|
| 828 | - 'deliver_notifications' => has_filter( |
|
| 829 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 830 | - ), |
|
| 831 | - ), |
|
| 832 | - $payment |
|
| 833 | - ); |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Force posts to PayPal to use TLS v1.2. See: |
|
| 842 | - * https://core.trac.wordpress.org/ticket/36320 |
|
| 843 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
| 844 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
| 845 | - * This will affect PayPal standard, pro, express, and Payflow. |
|
| 846 | - * |
|
| 847 | - * @param $handle |
|
| 848 | - * @param $r |
|
| 849 | - * @param $url |
|
| 850 | - */ |
|
| 851 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
| 852 | - { |
|
| 853 | - if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
| 854 | - // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
| 855 | - // instead of the constant because it might not be defined |
|
| 856 | - curl_setopt($handle, CURLOPT_SSLVERSION, 6); |
|
| 857 | - } |
|
| 858 | - } |
|
| 21 | + /** |
|
| 22 | + * @var EE_Payment_Processor $_instance |
|
| 23 | + * @access private |
|
| 24 | + */ |
|
| 25 | + private static $_instance; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @singleton method used to instantiate class object |
|
| 30 | + * @access public |
|
| 31 | + * @return EE_Payment_Processor instance |
|
| 32 | + */ |
|
| 33 | + public static function instance() |
|
| 34 | + { |
|
| 35 | + // check if class object is instantiated |
|
| 36 | + if (! self::$_instance instanceof EE_Payment_Processor) { |
|
| 37 | + self::$_instance = new self(); |
|
| 38 | + } |
|
| 39 | + return self::$_instance; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return EE_Payment_Processor |
|
| 45 | + */ |
|
| 46 | + public static function reset() |
|
| 47 | + { |
|
| 48 | + self::$_instance = null; |
|
| 49 | + return self::instance(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + *private constructor to prevent direct creation |
|
| 55 | + * |
|
| 56 | + * @Constructor |
|
| 57 | + * @access private |
|
| 58 | + */ |
|
| 59 | + private function __construct() |
|
| 60 | + { |
|
| 61 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
| 62 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
| 68 | + * appropriately. Saves the payment that is generated |
|
| 69 | + * |
|
| 70 | + * @param EE_Payment_Method $payment_method |
|
| 71 | + * @param EE_Transaction $transaction |
|
| 72 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
| 73 | + * Leave null if payment is for the full amount owing |
|
| 74 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
| 75 | + * Receive_form_submission() should have |
|
| 76 | + * already been called on the billing form |
|
| 77 | + * (ie, its inputs should have their normalized values set). |
|
| 78 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
| 79 | + * where to go AFTER the offsite gateway |
|
| 80 | + * @param string $method like 'CART', indicates who the client who called this was |
|
| 81 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
| 82 | + * @param boolean $update_txn whether or not to call |
|
| 83 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
| 84 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
| 85 | + * @return EE_Payment |
|
| 86 | + * @throws EE_Error |
|
| 87 | + * @throws InvalidArgumentException |
|
| 88 | + * @throws ReflectionException |
|
| 89 | + * @throws RuntimeException |
|
| 90 | + * @throws InvalidDataTypeException |
|
| 91 | + * @throws InvalidInterfaceException |
|
| 92 | + */ |
|
| 93 | + public function process_payment( |
|
| 94 | + EE_Payment_Method $payment_method, |
|
| 95 | + EE_Transaction $transaction, |
|
| 96 | + $amount = null, |
|
| 97 | + $billing_form = null, |
|
| 98 | + $return_url = null, |
|
| 99 | + $method = 'CART', |
|
| 100 | + $by_admin = false, |
|
| 101 | + $update_txn = true, |
|
| 102 | + $cancel_url = '' |
|
| 103 | + ) { |
|
| 104 | + if ((float) $amount < 0) { |
|
| 105 | + throw new EE_Error( |
|
| 106 | + sprintf( |
|
| 107 | + __( |
|
| 108 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
| 109 | + 'event_espresso' |
|
| 110 | + ), |
|
| 111 | + $amount, |
|
| 112 | + $transaction->ID() |
|
| 113 | + ) |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + // verify payment method |
|
| 117 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
| 118 | + $payment_method, |
|
| 119 | + true |
|
| 120 | + ); |
|
| 121 | + // verify transaction |
|
| 122 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 123 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
| 124 | + // verify payment method type |
|
| 125 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 126 | + $payment = $payment_method->type_obj()->process_payment( |
|
| 127 | + $transaction, |
|
| 128 | + min($amount, $transaction->remaining()), // make sure we don't overcharge |
|
| 129 | + $billing_form, |
|
| 130 | + $return_url, |
|
| 131 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
| 132 | + $method, |
|
| 133 | + $by_admin |
|
| 134 | + ); |
|
| 135 | + // check if payment method uses an off-site gateway |
|
| 136 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
| 137 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
| 138 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
| 139 | + } |
|
| 140 | + return $payment; |
|
| 141 | + } |
|
| 142 | + EE_Error::add_error( |
|
| 143 | + sprintf( |
|
| 144 | + __( |
|
| 145 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 146 | + 'event_espresso' |
|
| 147 | + ), |
|
| 148 | + '<br/>', |
|
| 149 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 150 | + ), |
|
| 151 | + __FILE__, |
|
| 152 | + __FUNCTION__, |
|
| 153 | + __LINE__ |
|
| 154 | + ); |
|
| 155 | + return null; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param EE_Transaction|int $transaction |
|
| 161 | + * @param EE_Payment_Method $payment_method |
|
| 162 | + * @return string |
|
| 163 | + * @throws EE_Error |
|
| 164 | + * @throws InvalidArgumentException |
|
| 165 | + * @throws InvalidDataTypeException |
|
| 166 | + * @throws InvalidInterfaceException |
|
| 167 | + */ |
|
| 168 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
| 169 | + { |
|
| 170 | + /** @type \EE_Transaction $transaction */ |
|
| 171 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 172 | + $primary_reg = $transaction->primary_registration(); |
|
| 173 | + if (! $primary_reg instanceof EE_Registration) { |
|
| 174 | + throw new EE_Error( |
|
| 175 | + sprintf( |
|
| 176 | + __( |
|
| 177 | + 'Cannot get IPN URL for transaction with ID %d because it has no primary registration', |
|
| 178 | + 'event_espresso' |
|
| 179 | + ), |
|
| 180 | + $transaction->ID() |
|
| 181 | + ) |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( |
|
| 185 | + $payment_method, |
|
| 186 | + true |
|
| 187 | + ); |
|
| 188 | + $url = add_query_arg( |
|
| 189 | + array( |
|
| 190 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
| 191 | + 'ee_payment_method' => $payment_method->slug(), |
|
| 192 | + ), |
|
| 193 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
| 194 | + ); |
|
| 195 | + return $url; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
| 201 | + * we can easily find what registration the IPN is for and what payment method. |
|
| 202 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
| 203 | + * If a payment is found for the IPN info, it is saved. |
|
| 204 | + * |
|
| 205 | + * @param array $_req_data eg $_REQUEST |
|
| 206 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
| 207 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
| 208 | + * @param boolean $update_txn whether or not to call |
|
| 209 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
| 210 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
| 211 | + * or is processed manually ( false like Mijireh ) |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws Exception |
|
| 214 | + * @return EE_Payment |
|
| 215 | + * @throws \RuntimeException |
|
| 216 | + * @throws \ReflectionException |
|
| 217 | + * @throws \InvalidArgumentException |
|
| 218 | + * @throws InvalidInterfaceException |
|
| 219 | + * @throws InvalidDataTypeException |
|
| 220 | + */ |
|
| 221 | + public function process_ipn( |
|
| 222 | + $_req_data, |
|
| 223 | + $transaction = null, |
|
| 224 | + $payment_method = null, |
|
| 225 | + $update_txn = true, |
|
| 226 | + $separate_IPN_request = true |
|
| 227 | + ) { |
|
| 228 | + EE_Registry::instance()->load_model('Change_Log'); |
|
| 229 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
| 230 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
| 231 | + $obj_for_log = null; |
|
| 232 | + if ($transaction instanceof EE_Transaction) { |
|
| 233 | + $obj_for_log = $transaction; |
|
| 234 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 235 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
| 236 | + array( |
|
| 237 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
| 238 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + } elseif ($payment_method instanceof EE_Payment) { |
|
| 243 | + $obj_for_log = $payment_method; |
|
| 244 | + } |
|
| 245 | + $log = EEM_Change_Log::instance()->log( |
|
| 246 | + EEM_Change_Log::type_gateway, |
|
| 247 | + array('IPN data received' => $_req_data), |
|
| 248 | + $obj_for_log |
|
| 249 | + ); |
|
| 250 | + try { |
|
| 251 | + /** |
|
| 252 | + * @var EE_Payment $payment |
|
| 253 | + */ |
|
| 254 | + $payment = null; |
|
| 255 | + if ($transaction && $payment_method) { |
|
| 256 | + /** @type EE_Transaction $transaction */ |
|
| 257 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 258 | + /** @type EE_Payment_Method $payment_method */ |
|
| 259 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
| 260 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 261 | + try { |
|
| 262 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
| 263 | + $log->set_object($payment); |
|
| 264 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
| 265 | + EEM_Change_Log::instance()->log( |
|
| 266 | + EEM_Change_Log::type_gateway, |
|
| 267 | + array( |
|
| 268 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
| 269 | + 'current_url' => EEH_URL::current_url(), |
|
| 270 | + 'payment' => $e->getPaymentProperties(), |
|
| 271 | + 'IPN_data' => $e->getIpnData(), |
|
| 272 | + ), |
|
| 273 | + $obj_for_log |
|
| 274 | + ); |
|
| 275 | + return $e->getPayment(); |
|
| 276 | + } |
|
| 277 | + } else { |
|
| 278 | + // not a payment |
|
| 279 | + EE_Error::add_error( |
|
| 280 | + sprintf( |
|
| 281 | + __( |
|
| 282 | + 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', |
|
| 283 | + 'event_espresso' |
|
| 284 | + ), |
|
| 285 | + '<br/>', |
|
| 286 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 287 | + ), |
|
| 288 | + __FILE__, |
|
| 289 | + __FUNCTION__, |
|
| 290 | + __LINE__ |
|
| 291 | + ); |
|
| 292 | + } |
|
| 293 | + } else { |
|
| 294 | + // that's actually pretty ok. The IPN just wasn't able |
|
| 295 | + // to identify which transaction or payment method this was for |
|
| 296 | + // give all active payment methods a chance to claim it |
|
| 297 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
| 298 | + foreach ($active_payment_methods as $active_payment_method) { |
|
| 299 | + try { |
|
| 300 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
| 301 | + $payment_method = $active_payment_method; |
|
| 302 | + EEM_Change_Log::instance()->log( |
|
| 303 | + EEM_Change_Log::type_gateway, |
|
| 304 | + array('IPN data' => $_req_data), |
|
| 305 | + $payment |
|
| 306 | + ); |
|
| 307 | + break; |
|
| 308 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
| 309 | + EEM_Change_Log::instance()->log( |
|
| 310 | + EEM_Change_Log::type_gateway, |
|
| 311 | + array( |
|
| 312 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
| 313 | + 'current_url' => EEH_URL::current_url(), |
|
| 314 | + 'payment' => $e->getPaymentProperties(), |
|
| 315 | + 'IPN_data' => $e->getIpnData(), |
|
| 316 | + ), |
|
| 317 | + $obj_for_log |
|
| 318 | + ); |
|
| 319 | + return $e->getPayment(); |
|
| 320 | + } catch (EE_Error $e) { |
|
| 321 | + // that's fine- it apparently couldn't handle the IPN |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
| 326 | + if ($payment instanceof EE_Payment) { |
|
| 327 | + $payment->save(); |
|
| 328 | + // update the TXN |
|
| 329 | + $this->update_txn_based_on_payment( |
|
| 330 | + $transaction, |
|
| 331 | + $payment, |
|
| 332 | + $update_txn, |
|
| 333 | + $separate_IPN_request |
|
| 334 | + ); |
|
| 335 | + } else { |
|
| 336 | + // we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
| 337 | + if ($payment_method) { |
|
| 338 | + EEM_Change_Log::instance()->log( |
|
| 339 | + EEM_Change_Log::type_gateway, |
|
| 340 | + array('IPN data' => $_req_data), |
|
| 341 | + $payment_method |
|
| 342 | + ); |
|
| 343 | + } elseif ($transaction) { |
|
| 344 | + EEM_Change_Log::instance()->log( |
|
| 345 | + EEM_Change_Log::type_gateway, |
|
| 346 | + array('IPN data' => $_req_data), |
|
| 347 | + $transaction |
|
| 348 | + ); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + return $payment; |
|
| 352 | + } catch (EE_Error $e) { |
|
| 353 | + do_action( |
|
| 354 | + 'AHEE__log', |
|
| 355 | + __FILE__, |
|
| 356 | + __FUNCTION__, |
|
| 357 | + sprintf( |
|
| 358 | + __( |
|
| 359 | + 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', |
|
| 360 | + 'event_espresso' |
|
| 361 | + ), |
|
| 362 | + print_r($transaction, true), |
|
| 363 | + print_r($_req_data, true), |
|
| 364 | + $e->getMessage() |
|
| 365 | + ) |
|
| 366 | + ); |
|
| 367 | + throw $e; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Removes any non-printable illegal characters from the input, |
|
| 374 | + * which might cause a raucous when trying to insert into the database |
|
| 375 | + * |
|
| 376 | + * @param array $request_data |
|
| 377 | + * @return array |
|
| 378 | + */ |
|
| 379 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
| 380 | + { |
|
| 381 | + $return_data = array(); |
|
| 382 | + foreach ($request_data as $key => $value) { |
|
| 383 | + $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters( |
|
| 384 | + $value |
|
| 385 | + ); |
|
| 386 | + } |
|
| 387 | + return $return_data; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Removes any non-printable illegal characters from the input, |
|
| 393 | + * which might cause a raucous when trying to insert into the database |
|
| 394 | + * |
|
| 395 | + * @param string $request_data |
|
| 396 | + * @return string |
|
| 397 | + */ |
|
| 398 | + protected function _remove_unusable_characters($request_data) |
|
| 399 | + { |
|
| 400 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Should be called just before displaying the payment attempt results to the user, |
|
| 406 | + * when the payment attempt has finished. Some payment methods may have special |
|
| 407 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
| 408 | + * and then the user is redirected to a page that displays the payment's status, this |
|
| 409 | + * should be called while loading the page that displays the payment's status. If the user is |
|
| 410 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
| 411 | + * provider. |
|
| 412 | + * |
|
| 413 | + * @param EE_Transaction|int $transaction |
|
| 414 | + * @param bool $update_txn whether or not to call |
|
| 415 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
| 416 | + * @return EE_Payment |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws InvalidArgumentException |
|
| 419 | + * @throws ReflectionException |
|
| 420 | + * @throws RuntimeException |
|
| 421 | + * @throws InvalidDataTypeException |
|
| 422 | + * @throws InvalidInterfaceException |
|
| 423 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
| 424 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
| 425 | + */ |
|
| 426 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
| 427 | + { |
|
| 428 | + /** @var $transaction EE_Transaction */ |
|
| 429 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 430 | + $last_payment_method = $transaction->payment_method(); |
|
| 431 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
| 432 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
| 433 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
| 434 | + return $payment; |
|
| 435 | + } |
|
| 436 | + return null; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
| 442 | + * |
|
| 443 | + * @param EE_Payment_Method $payment_method |
|
| 444 | + * @param EE_Payment $payment_to_refund |
|
| 445 | + * @param array $refund_info |
|
| 446 | + * @return EE_Payment |
|
| 447 | + * @throws EE_Error |
|
| 448 | + * @throws InvalidArgumentException |
|
| 449 | + * @throws ReflectionException |
|
| 450 | + * @throws RuntimeException |
|
| 451 | + * @throws InvalidDataTypeException |
|
| 452 | + * @throws InvalidInterfaceException |
|
| 453 | + */ |
|
| 454 | + public function process_refund( |
|
| 455 | + EE_Payment_Method $payment_method, |
|
| 456 | + EE_Payment $payment_to_refund, |
|
| 457 | + array $refund_info = array() |
|
| 458 | + ) { |
|
| 459 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
| 460 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
| 461 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
| 462 | + } |
|
| 463 | + return $payment_to_refund; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * This should be called each time there may have been an update to a |
|
| 469 | + * payment on a transaction (ie, we asked for a payment to process a |
|
| 470 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
| 471 | + * we told a payment method to |
|
| 472 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
| 473 | + * process a refund. This should handle firing the correct hooks to |
|
| 474 | + * indicate |
|
| 475 | + * what exactly happened and updating the transaction appropriately). This |
|
| 476 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
| 477 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
| 478 | + * of transactions and payments, and to be tied to payment processing. |
|
| 479 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
| 480 | + * of previous code to decide whether or not to save (because the payment passed into |
|
| 481 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
| 482 | + * in which case we only want that payment object for some temporary usage during this request, |
|
| 483 | + * but we don't want it to be saved). |
|
| 484 | + * |
|
| 485 | + * @param EE_Transaction|int $transaction |
|
| 486 | + * @param EE_Payment $payment |
|
| 487 | + * @param boolean $update_txn |
|
| 488 | + * whether or not to call |
|
| 489 | + * EE_Transaction_Processor:: |
|
| 490 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
| 491 | + * (you can save 1 DB query if you know you're going |
|
| 492 | + * to save it later instead) |
|
| 493 | + * @param bool $IPN |
|
| 494 | + * if processing IPNs or other similar payment |
|
| 495 | + * related activities that occur in alternate |
|
| 496 | + * requests than the main one that is processing the |
|
| 497 | + * TXN, then set this to true to check whether the |
|
| 498 | + * TXN is locked before updating |
|
| 499 | + * @throws EE_Error |
|
| 500 | + * @throws InvalidArgumentException |
|
| 501 | + * @throws ReflectionException |
|
| 502 | + * @throws RuntimeException |
|
| 503 | + * @throws InvalidDataTypeException |
|
| 504 | + * @throws InvalidInterfaceException |
|
| 505 | + */ |
|
| 506 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
| 507 | + { |
|
| 508 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
| 509 | + /** @type EE_Transaction $transaction */ |
|
| 510 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
| 511 | + // can we freely update the TXN at this moment? |
|
| 512 | + if ($IPN && $transaction->is_locked()) { |
|
| 513 | + // don't update the transaction at this exact moment |
|
| 514 | + // because the TXN is active in another request |
|
| 515 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 516 | + time(), |
|
| 517 | + $transaction->ID(), |
|
| 518 | + $payment->ID() |
|
| 519 | + ); |
|
| 520 | + } else { |
|
| 521 | + // verify payment and that it has been saved |
|
| 522 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
| 523 | + if ($payment->payment_method() instanceof EE_Payment_Method |
|
| 524 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
| 525 | + ) { |
|
| 526 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
| 527 | + // update TXN registrations with payment info |
|
| 528 | + $this->process_registration_payments($transaction, $payment); |
|
| 529 | + } |
|
| 530 | + $do_action = $payment->just_approved() |
|
| 531 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
| 532 | + : $do_action; |
|
| 533 | + } else { |
|
| 534 | + // send out notifications |
|
| 535 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 536 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
| 537 | + } |
|
| 538 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
| 539 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 540 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 541 | + // set new value for total paid |
|
| 542 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
| 543 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
| 544 | + if ($update_txn) { |
|
| 545 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + // granular hook for others to use. |
|
| 549 | + do_action($do_action, $transaction, $payment); |
|
| 550 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
| 551 | + // global hook for others to use. |
|
| 552 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
| 559 | + * |
|
| 560 | + * @param EE_Transaction $transaction |
|
| 561 | + * @param EE_Payment $payment |
|
| 562 | + * @param EE_Registration[] $registrations |
|
| 563 | + * @throws EE_Error |
|
| 564 | + * @throws InvalidArgumentException |
|
| 565 | + * @throws RuntimeException |
|
| 566 | + * @throws InvalidDataTypeException |
|
| 567 | + * @throws InvalidInterfaceException |
|
| 568 | + */ |
|
| 569 | + public function process_registration_payments( |
|
| 570 | + EE_Transaction $transaction, |
|
| 571 | + EE_Payment $payment, |
|
| 572 | + array $registrations = array() |
|
| 573 | + ) { |
|
| 574 | + // only process if payment was successful |
|
| 575 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
| 576 | + return; |
|
| 577 | + } |
|
| 578 | + // EEM_Registration::instance()->show_next_x_db_queries(); |
|
| 579 | + if (empty($registrations)) { |
|
| 580 | + // find registrations with monies owing that can receive a payment |
|
| 581 | + $registrations = $transaction->registrations( |
|
| 582 | + array( |
|
| 583 | + array( |
|
| 584 | + // only these reg statuses can receive payments |
|
| 585 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
| 586 | + 'REG_final_price' => array('!=', 0), |
|
| 587 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
| 588 | + ), |
|
| 589 | + ) |
|
| 590 | + ); |
|
| 591 | + } |
|
| 592 | + // still nothing ??!?? |
|
| 593 | + if (empty($registrations)) { |
|
| 594 | + return; |
|
| 595 | + } |
|
| 596 | + // todo: break out the following logic into a separate strategy class |
|
| 597 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
| 598 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
| 599 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
| 600 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
| 601 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
| 602 | + $refund = $payment->is_a_refund(); |
|
| 603 | + // how much is available to apply to registrations? |
|
| 604 | + $available_payment_amount = abs($payment->amount()); |
|
| 605 | + foreach ($registrations as $registration) { |
|
| 606 | + if ($registration instanceof EE_Registration) { |
|
| 607 | + // nothing left? |
|
| 608 | + if ($available_payment_amount <= 0) { |
|
| 609 | + break; |
|
| 610 | + } |
|
| 611 | + if ($refund) { |
|
| 612 | + $available_payment_amount = $this->process_registration_refund( |
|
| 613 | + $registration, |
|
| 614 | + $payment, |
|
| 615 | + $available_payment_amount |
|
| 616 | + ); |
|
| 617 | + } else { |
|
| 618 | + $available_payment_amount = $this->process_registration_payment( |
|
| 619 | + $registration, |
|
| 620 | + $payment, |
|
| 621 | + $available_payment_amount |
|
| 622 | + ); |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + if ($available_payment_amount > 0 |
|
| 627 | + && apply_filters( |
|
| 628 | + 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', |
|
| 629 | + false |
|
| 630 | + )) { |
|
| 631 | + EE_Error::add_attention( |
|
| 632 | + sprintf( |
|
| 633 | + __( |
|
| 634 | + 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + EEH_Template::format_currency($available_payment_amount), |
|
| 638 | + implode(', ', array_keys($registrations)), |
|
| 639 | + '<br/>', |
|
| 640 | + EEH_Template::format_currency($payment->amount()) |
|
| 641 | + ), |
|
| 642 | + __FILE__, |
|
| 643 | + __FUNCTION__, |
|
| 644 | + __LINE__ |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * update registration REG_paid field after successful payment and link registration with payment |
|
| 652 | + * |
|
| 653 | + * @param EE_Registration $registration |
|
| 654 | + * @param EE_Payment $payment |
|
| 655 | + * @param float $available_payment_amount |
|
| 656 | + * @return float |
|
| 657 | + * @throws EE_Error |
|
| 658 | + * @throws InvalidArgumentException |
|
| 659 | + * @throws RuntimeException |
|
| 660 | + * @throws InvalidDataTypeException |
|
| 661 | + * @throws InvalidInterfaceException |
|
| 662 | + */ |
|
| 663 | + public function process_registration_payment( |
|
| 664 | + EE_Registration $registration, |
|
| 665 | + EE_Payment $payment, |
|
| 666 | + $available_payment_amount = 0.00 |
|
| 667 | + ) { |
|
| 668 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 669 | + if ($owing > 0) { |
|
| 670 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
| 671 | + $payment_amount = min($available_payment_amount, $owing); |
|
| 672 | + // update $available_payment_amount |
|
| 673 | + $available_payment_amount -= $payment_amount; |
|
| 674 | + // calculate and set new REG_paid |
|
| 675 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
| 676 | + // now save it |
|
| 677 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
| 678 | + } |
|
| 679 | + return $available_payment_amount; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * update registration REG_paid field after successful payment and link registration with payment |
|
| 685 | + * |
|
| 686 | + * @param EE_Registration $registration |
|
| 687 | + * @param EE_Payment $payment |
|
| 688 | + * @param float $payment_amount |
|
| 689 | + * @return void |
|
| 690 | + * @throws EE_Error |
|
| 691 | + * @throws InvalidArgumentException |
|
| 692 | + * @throws InvalidDataTypeException |
|
| 693 | + * @throws InvalidInterfaceException |
|
| 694 | + */ |
|
| 695 | + protected function _apply_registration_payment( |
|
| 696 | + EE_Registration $registration, |
|
| 697 | + EE_Payment $payment, |
|
| 698 | + $payment_amount = 0.00 |
|
| 699 | + ) { |
|
| 700 | + // find any existing reg payment records for this registration and payment |
|
| 701 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
| 702 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
| 703 | + ); |
|
| 704 | + // if existing registration payment exists |
|
| 705 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
| 706 | + // then update that record |
|
| 707 | + $existing_reg_payment->set_amount($payment_amount); |
|
| 708 | + $existing_reg_payment->save(); |
|
| 709 | + } else { |
|
| 710 | + // or add new relation between registration and payment and set amount |
|
| 711 | + $registration->_add_relation_to( |
|
| 712 | + $payment, |
|
| 713 | + 'Payment', |
|
| 714 | + array('RPY_amount' => $payment_amount) |
|
| 715 | + ); |
|
| 716 | + // make it stick |
|
| 717 | + $registration->save(); |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * update registration REG_paid field after refund and link registration with payment |
|
| 724 | + * |
|
| 725 | + * @param EE_Registration $registration |
|
| 726 | + * @param EE_Payment $payment |
|
| 727 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
| 728 | + * @return float |
|
| 729 | + * @throws EE_Error |
|
| 730 | + * @throws InvalidArgumentException |
|
| 731 | + * @throws RuntimeException |
|
| 732 | + * @throws InvalidDataTypeException |
|
| 733 | + * @throws InvalidInterfaceException |
|
| 734 | + */ |
|
| 735 | + public function process_registration_refund( |
|
| 736 | + EE_Registration $registration, |
|
| 737 | + EE_Payment $payment, |
|
| 738 | + $available_refund_amount = 0.00 |
|
| 739 | + ) { |
|
| 740 | + // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
| 741 | + if ($registration->paid() > 0) { |
|
| 742 | + // ensure $available_refund_amount is NOT negative |
|
| 743 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
| 744 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
| 745 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
| 746 | + // update $available_payment_amount |
|
| 747 | + $available_refund_amount -= $refund_amount; |
|
| 748 | + // calculate and set new REG_paid |
|
| 749 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
| 750 | + // convert payment amount back to a negative value for storage in the db |
|
| 751 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
| 752 | + // now save it |
|
| 753 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
| 754 | + } |
|
| 755 | + return $available_refund_amount; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * Process payments and transaction after payment process completed. |
|
| 761 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
| 762 | + * if this request happens to be processing an IPN, |
|
| 763 | + * then we will also set the Payment Options Reg Step to completed, |
|
| 764 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
| 765 | + * |
|
| 766 | + * @param EE_Transaction $transaction |
|
| 767 | + * @param EE_Payment $payment |
|
| 768 | + * @param bool $IPN |
|
| 769 | + * @throws EE_Error |
|
| 770 | + * @throws InvalidArgumentException |
|
| 771 | + * @throws ReflectionException |
|
| 772 | + * @throws RuntimeException |
|
| 773 | + * @throws InvalidDataTypeException |
|
| 774 | + * @throws InvalidInterfaceException |
|
| 775 | + */ |
|
| 776 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
| 777 | + { |
|
| 778 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 779 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 780 | + // is the Payment Options Reg Step completed ? |
|
| 781 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
| 782 | + // if the Payment Options Reg Step is completed... |
|
| 783 | + $revisit = $payment_options_step_completed === true; |
|
| 784 | + // then this is kinda sorta a revisit with regards to payments at least |
|
| 785 | + $transaction_processor->set_revisit($revisit); |
|
| 786 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
| 787 | + if ($IPN |
|
| 788 | + && $payment_options_step_completed !== true |
|
| 789 | + && ($payment->is_approved() || $payment->is_pending()) |
|
| 790 | + ) { |
|
| 791 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
| 792 | + 'payment_options' |
|
| 793 | + ); |
|
| 794 | + } |
|
| 795 | + // maybe update status, but don't save transaction just yet |
|
| 796 | + $transaction->update_status_based_on_total_paid(false); |
|
| 797 | + // check if 'finalize_registration' step has been completed... |
|
| 798 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 799 | + // if this is an IPN and the final step has not been initiated |
|
| 800 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
| 801 | + // and if it hasn't already been set as being started... |
|
| 802 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
| 803 | + } |
|
| 804 | + $transaction->save(); |
|
| 805 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
| 806 | + if ($IPN && $finalized !== false) { |
|
| 807 | + // and if we are all good to go, then send out notifications |
|
| 808 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 809 | + // ok, now process the transaction according to the payment |
|
| 810 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
| 811 | + $transaction, |
|
| 812 | + $payment |
|
| 813 | + ); |
|
| 814 | + } |
|
| 815 | + // DEBUG LOG |
|
| 816 | + $payment_method = $payment->payment_method(); |
|
| 817 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 818 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
| 819 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
| 820 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
| 821 | + if ($gateway instanceof EE_Gateway) { |
|
| 822 | + $gateway->log( |
|
| 823 | + array( |
|
| 824 | + 'message' => (string) __('Post Payment Transaction Details', 'event_espresso'), |
|
| 825 | + 'transaction' => $transaction->model_field_array(), |
|
| 826 | + 'finalized' => $finalized, |
|
| 827 | + 'IPN' => $IPN, |
|
| 828 | + 'deliver_notifications' => has_filter( |
|
| 829 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 830 | + ), |
|
| 831 | + ), |
|
| 832 | + $payment |
|
| 833 | + ); |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Force posts to PayPal to use TLS v1.2. See: |
|
| 842 | + * https://core.trac.wordpress.org/ticket/36320 |
|
| 843 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
| 844 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
| 845 | + * This will affect PayPal standard, pro, express, and Payflow. |
|
| 846 | + * |
|
| 847 | + * @param $handle |
|
| 848 | + * @param $r |
|
| 849 | + * @param $url |
|
| 850 | + */ |
|
| 851 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
| 852 | + { |
|
| 853 | + if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) { |
|
| 854 | + // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
| 855 | + // instead of the constant because it might not be defined |
|
| 856 | + curl_setopt($handle, CURLOPT_SSLVERSION, 6); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | 859 | } |
@@ -11,674 +11,674 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 13 | 13 | if (! function_exists('mb_strcut')) { |
| 14 | - /** |
|
| 15 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 16 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 17 | - * @param $string |
|
| 18 | - * @param $start |
|
| 19 | - * @param $length |
|
| 20 | - * @return bool|string |
|
| 21 | - */ |
|
| 22 | - function mb_strcut($string, $start, $length = null) |
|
| 23 | - { |
|
| 24 | - return mb_substr($string, $start, $length); |
|
| 25 | - } |
|
| 14 | + /** |
|
| 15 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 16 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 17 | + * @param $string |
|
| 18 | + * @param $start |
|
| 19 | + * @param $length |
|
| 20 | + * @return bool|string |
|
| 21 | + */ |
|
| 22 | + function mb_strcut($string, $start, $length = null) |
|
| 23 | + { |
|
| 24 | + return mb_substr($string, $start, $length); |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Merchant API Username. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $_api_username; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Merchant API Password. |
|
| 39 | - * |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected $_api_password; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * API Signature. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $_api_signature; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Request Shipping address on PP checkout page. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $_request_shipping_addr; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Business/personal logo. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - protected $_image_url; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * gateway URL variable |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - protected $_base_gateway_url = ''; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * EEG_Paypal_Express constructor. |
|
| 76 | - */ |
|
| 77 | - public function __construct() |
|
| 78 | - { |
|
| 79 | - $this->_currencies_supported = array( |
|
| 80 | - 'USD', |
|
| 81 | - 'AUD', |
|
| 82 | - 'BRL', |
|
| 83 | - 'CAD', |
|
| 84 | - 'CZK', |
|
| 85 | - 'DKK', |
|
| 86 | - 'EUR', |
|
| 87 | - 'HKD', |
|
| 88 | - 'HUF', |
|
| 89 | - 'ILS', |
|
| 90 | - 'JPY', |
|
| 91 | - 'MYR', |
|
| 92 | - 'MXN', |
|
| 93 | - 'NOK', |
|
| 94 | - 'NZD', |
|
| 95 | - 'PHP', |
|
| 96 | - 'PLN', |
|
| 97 | - 'GBP', |
|
| 98 | - 'RUB', |
|
| 99 | - 'SGD', |
|
| 100 | - 'SEK', |
|
| 101 | - 'CHF', |
|
| 102 | - 'TWD', |
|
| 103 | - 'THB', |
|
| 104 | - 'TRY', |
|
| 105 | - 'INR', |
|
| 106 | - ); |
|
| 107 | - parent::__construct(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 114 | - * |
|
| 115 | - * @param array $settings_array |
|
| 116 | - */ |
|
| 117 | - public function set_settings($settings_array) |
|
| 118 | - { |
|
| 119 | - parent::set_settings($settings_array); |
|
| 120 | - // Redirect URL. |
|
| 121 | - $this->_base_gateway_url = $this->_debug_mode |
|
| 122 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 123 | - : 'https://api-3t.paypal.com/nvp'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param EEI_Payment $payment |
|
| 130 | - * @param array $billing_info |
|
| 131 | - * @param string $return_url |
|
| 132 | - * @param string $notify_url |
|
| 133 | - * @param string $cancel_url |
|
| 134 | - * @return \EE_Payment|\EEI_Payment |
|
| 135 | - * @throws \EE_Error |
|
| 136 | - */ |
|
| 137 | - public function set_redirection_info( |
|
| 138 | - $payment, |
|
| 139 | - $billing_info = array(), |
|
| 140 | - $return_url = null, |
|
| 141 | - $notify_url = null, |
|
| 142 | - $cancel_url = null |
|
| 143 | - ) { |
|
| 144 | - if (! $payment instanceof EEI_Payment) { |
|
| 145 | - $payment->set_gateway_response( |
|
| 146 | - esc_html__( |
|
| 147 | - 'Error. No associated payment was found.', |
|
| 148 | - 'event_espresso' |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 152 | - return $payment; |
|
| 153 | - } |
|
| 154 | - $transaction = $payment->transaction(); |
|
| 155 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 156 | - $payment->set_gateway_response( |
|
| 157 | - esc_html__( |
|
| 158 | - 'Could not process this payment because it has no associated transaction.', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ) |
|
| 161 | - ); |
|
| 162 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 163 | - return $payment; |
|
| 164 | - } |
|
| 165 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 166 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 167 | - $primary_registration = $transaction->primary_registration(); |
|
| 168 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 169 | - ? $primary_registration->attendee() |
|
| 170 | - : false; |
|
| 171 | - $locale = explode('-', get_bloginfo('language')); |
|
| 172 | - // Gather request parameters. |
|
| 173 | - $token_request_dtls = array( |
|
| 174 | - 'METHOD' => 'SetExpressCheckout', |
|
| 175 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 176 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 177 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 178 | - 'RETURNURL' => $return_url, |
|
| 179 | - 'CANCELURL' => $cancel_url, |
|
| 180 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 181 | - // Buyer does not need to create a PayPal account to check out. |
|
| 182 | - // This is referred to as PayPal Account Optional. |
|
| 183 | - 'SOLUTIONTYPE' => 'Sole', |
|
| 184 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 185 | - 'LOCALECODE' => $locale[1] |
|
| 186 | - ); |
|
| 187 | - // Show itemized list. |
|
| 188 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 189 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 190 | - // Automatically filling out shipping and contact information. |
|
| 191 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 192 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 193 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 194 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 195 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 200 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 202 | - } elseif (! $this->_request_shipping_addr) { |
|
| 203 | - // Do not request shipping details on the PP Checkout page. |
|
| 204 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 205 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 206 | - } |
|
| 207 | - // Used a business/personal logo on the PayPal page. |
|
| 208 | - if (! empty($this->_image_url)) { |
|
| 209 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 210 | - } |
|
| 211 | - $token_request_dtls = apply_filters( |
|
| 212 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 213 | - $token_request_dtls, |
|
| 214 | - $this |
|
| 215 | - ); |
|
| 216 | - // Request PayPal token. |
|
| 217 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 218 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 219 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 220 | - ? $token_rstatus['args'] |
|
| 221 | - : array(); |
|
| 222 | - if ($token_rstatus['status']) { |
|
| 223 | - // We got the Token so we may continue with the payment and redirect the client. |
|
| 224 | - $payment->set_details($response_args); |
|
| 225 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 226 | - $payment->set_redirect_url( |
|
| 227 | - $gateway_url |
|
| 228 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 229 | - . $response_args['TOKEN'] |
|
| 230 | - ); |
|
| 231 | - } else { |
|
| 232 | - if (isset($response_args['L_ERRORCODE'])) { |
|
| 233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | - } else { |
|
| 235 | - $payment->set_gateway_response( |
|
| 236 | - esc_html__( |
|
| 237 | - 'Error occurred while trying to setup the Express Checkout.', |
|
| 238 | - 'event_espresso' |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - $payment->set_details($response_args); |
|
| 243 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 244 | - } |
|
| 245 | - return $payment; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param array $update_info { |
|
| 252 | - * @type string $gateway_txn_id |
|
| 253 | - * @type string status an EEMI_Payment status |
|
| 254 | - * } |
|
| 255 | - * @param EEI_Transaction $transaction |
|
| 256 | - * @return EEI_Payment |
|
| 257 | - */ |
|
| 258 | - public function handle_payment_update($update_info, $transaction) |
|
| 259 | - { |
|
| 260 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 261 | - if ($payment instanceof EEI_Payment) { |
|
| 262 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 263 | - $transaction = $payment->transaction(); |
|
| 264 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | - $payment->set_gateway_response( |
|
| 266 | - esc_html__( |
|
| 267 | - 'Could not process this payment because it has no associated transaction.', |
|
| 268 | - 'event_espresso' |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 272 | - return $payment; |
|
| 273 | - } |
|
| 274 | - $primary_registrant = $transaction->primary_registration(); |
|
| 275 | - $payment_details = $payment->details(); |
|
| 276 | - // Check if we still have the token. |
|
| 277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 279 | - return $payment; |
|
| 280 | - } |
|
| 281 | - $cdetails_request_dtls = array( |
|
| 282 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 283 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 284 | - ); |
|
| 285 | - // Request Customer Details. |
|
| 286 | - $cdetails_request_response = $this->_ppExpress_request( |
|
| 287 | - $cdetails_request_dtls, |
|
| 288 | - 'Customer Details', |
|
| 289 | - $payment |
|
| 290 | - ); |
|
| 291 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 292 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 293 | - ? $cdetails_rstatus['args'] |
|
| 294 | - : array(); |
|
| 295 | - if ($cdetails_rstatus['status']) { |
|
| 296 | - // We got the PayerID so now we can Complete the transaction. |
|
| 297 | - $docheckout_request_dtls = array( |
|
| 298 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 299 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 300 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 301 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 302 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 303 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 304 | - ); |
|
| 305 | - // Include itemized list. |
|
| 306 | - $itemized_list = $this->itemize_list( |
|
| 307 | - $payment, |
|
| 308 | - $transaction, |
|
| 309 | - $cdata_response_args |
|
| 310 | - ); |
|
| 311 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 312 | - // Payment Checkout/Capture. |
|
| 313 | - $docheckout_request_response = $this->_ppExpress_request( |
|
| 314 | - $docheckout_request_dtls, |
|
| 315 | - 'Do Payment', |
|
| 316 | - $payment |
|
| 317 | - ); |
|
| 318 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 319 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 320 | - ? $docheckout_rstatus['args'] |
|
| 321 | - : array(); |
|
| 322 | - if ($docheckout_rstatus['status']) { |
|
| 323 | - // All is well, payment approved. |
|
| 324 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 325 | - $primary_registrant->reg_code() |
|
| 326 | - : ''; |
|
| 327 | - $payment->set_extra_accntng($primary_registration_code); |
|
| 328 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 329 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 330 | - : 0); |
|
| 331 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 332 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 333 | - : null); |
|
| 334 | - $payment->set_details($cdata_response_args); |
|
| 335 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 336 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 337 | - : ''); |
|
| 338 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 339 | - } else { |
|
| 340 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 341 | - $payment->set_gateway_response( |
|
| 342 | - $docheckout_response_args['L_ERRORCODE'] |
|
| 343 | - . '; ' |
|
| 344 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 345 | - ); |
|
| 346 | - } else { |
|
| 347 | - $payment->set_gateway_response( |
|
| 348 | - esc_html__( |
|
| 349 | - 'Error occurred while trying to Capture the funds.', |
|
| 350 | - 'event_espresso' |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - $payment->set_details($docheckout_response_args); |
|
| 355 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 356 | - } |
|
| 357 | - } else { |
|
| 358 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 359 | - $payment->set_gateway_response( |
|
| 360 | - $cdata_response_args['L_ERRORCODE'] |
|
| 361 | - . '; ' |
|
| 362 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 363 | - ); |
|
| 364 | - } else { |
|
| 365 | - $payment->set_gateway_response( |
|
| 366 | - esc_html__( |
|
| 367 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
| 368 | - 'event_espresso' |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - $payment->set_details($cdata_response_args); |
|
| 373 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 374 | - } |
|
| 375 | - } else { |
|
| 376 | - $payment->set_gateway_response( |
|
| 377 | - esc_html__( |
|
| 378 | - 'Error occurred while trying to process the payment.', |
|
| 379 | - 'event_espresso' |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 383 | - } |
|
| 384 | - return $payment; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Make a list of items that are in the giver transaction. |
|
| 391 | - * |
|
| 392 | - * @param EEI_Payment $payment |
|
| 393 | - * @param EEI_Transaction $transaction |
|
| 394 | - * @param array $request_response_args Data from a previous communication with PP. |
|
| 395 | - * @return array |
|
| 396 | - */ |
|
| 397 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 398 | - { |
|
| 399 | - $itemized_list = array(); |
|
| 400 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 401 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 402 | - if (! empty($request_response_args) |
|
| 403 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 404 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 405 | - ) { |
|
| 406 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 407 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 408 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
| 409 | - ) { |
|
| 410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - // If we got only a few Items then something is not right. |
|
| 414 | - if (count($itemized_list) > 2) { |
|
| 415 | - return $itemized_list; |
|
| 416 | - } else { |
|
| 417 | - if (WP_DEBUG) { |
|
| 418 | - throw new EE_Error( |
|
| 419 | - sprintf( |
|
| 420 | - esc_html__( |
|
| 421 | - // @codingStandardsIgnoreStart |
|
| 422 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 423 | - // @codingStandardsIgnoreEnd |
|
| 424 | - 'event_espresso' |
|
| 425 | - ), |
|
| 426 | - wp_json_encode($itemized_list) |
|
| 427 | - ) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 431 | - $itemized_list = array(); |
|
| 432 | - $this->log( |
|
| 433 | - array( |
|
| 434 | - (string) esc_html__( |
|
| 435 | - 'Could not generate a proper item list with:', |
|
| 436 | - 'event_espresso' |
|
| 437 | - ) => $request_response_args |
|
| 438 | - ), |
|
| 439 | - $payment |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - // ...otherwise we generate a new list for this transaction. |
|
| 444 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 445 | - $item_num = 0; |
|
| 446 | - $itemized_sum = 0; |
|
| 447 | - $total_line_items = $transaction->total_line_item(); |
|
| 448 | - // Go through each item in the list. |
|
| 449 | - foreach ($total_line_items->get_items() as $line_item) { |
|
| 450 | - if ($line_item instanceof EE_Line_Item) { |
|
| 451 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 452 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 453 | - continue; |
|
| 454 | - } |
|
| 455 | - $unit_price = $line_item->unit_price(); |
|
| 456 | - $line_item_quantity = $line_item->quantity(); |
|
| 457 | - // This is a discount. |
|
| 458 | - if ($line_item->is_percent()) { |
|
| 459 | - $unit_price = $line_item->total(); |
|
| 460 | - $line_item_quantity = 1; |
|
| 461 | - } |
|
| 462 | - // Item Name. |
|
| 463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 464 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 465 | - 0, |
|
| 466 | - 127 |
|
| 467 | - ); |
|
| 468 | - // Item description. |
|
| 469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 470 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 471 | - 0, |
|
| 472 | - 127 |
|
| 473 | - ); |
|
| 474 | - // Cost of individual item. |
|
| 475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | - // Item Number. |
|
| 477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 478 | - // Item quantity. |
|
| 479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 480 | - // Digital item is sold. |
|
| 481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 482 | - $itemized_sum += $line_item->total(); |
|
| 483 | - ++$item_num; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - // Item's sales S/H and tax amount. |
|
| 487 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 488 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 489 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 490 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 491 | - $itemized_sum_diff_from_txn_total = round( |
|
| 492 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 493 | - 2 |
|
| 494 | - ); |
|
| 495 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 496 | - // add the difference as an extra line item. |
|
| 497 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 498 | - // Item Name. |
|
| 499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 500 | - esc_html__( |
|
| 501 | - 'Other (promotion/surcharge/cancellation)', |
|
| 502 | - 'event_espresso' |
|
| 503 | - ), |
|
| 504 | - 0, |
|
| 505 | - 127 |
|
| 506 | - ); |
|
| 507 | - // Item description. |
|
| 508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 509 | - // Cost of individual item. |
|
| 510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 511 | - $itemized_sum_diff_from_txn_total |
|
| 512 | - ); |
|
| 513 | - // Item Number. |
|
| 514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 515 | - // Item quantity. |
|
| 516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 517 | - // Digital item is sold. |
|
| 518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 519 | - $item_num++; |
|
| 520 | - } |
|
| 521 | - } else { |
|
| 522 | - // Just one Item. |
|
| 523 | - // Item Name. |
|
| 524 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 525 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 526 | - 0, |
|
| 527 | - 127 |
|
| 528 | - ); |
|
| 529 | - // Item description. |
|
| 530 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 531 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 532 | - 0, |
|
| 533 | - 127 |
|
| 534 | - ); |
|
| 535 | - // Cost of individual item. |
|
| 536 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 537 | - // Item Number. |
|
| 538 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 539 | - // Item quantity. |
|
| 540 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 541 | - // Digital item is sold. |
|
| 542 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 543 | - // Item's sales S/H and tax amount. |
|
| 544 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 545 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 546 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 547 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 548 | - } |
|
| 549 | - return $itemized_list; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Make the Express checkout request. |
|
| 556 | - * |
|
| 557 | - * @param array $request_params |
|
| 558 | - * @param string $request_text |
|
| 559 | - * @param EEI_Payment $payment |
|
| 560 | - * @return mixed |
|
| 561 | - */ |
|
| 562 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 563 | - { |
|
| 564 | - $request_dtls = array( |
|
| 565 | - 'VERSION' => '204.0', |
|
| 566 | - 'USER' => urlencode($this->_api_username), |
|
| 567 | - 'PWD' => urlencode($this->_api_password), |
|
| 568 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 569 | - // EE will blow up if you change this |
|
| 570 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 571 | - ); |
|
| 572 | - $dtls = array_merge($request_dtls, $request_params); |
|
| 573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | - // Request Customer Details. |
|
| 575 | - $request_response = wp_remote_post( |
|
| 576 | - $this->_base_gateway_url, |
|
| 577 | - array( |
|
| 578 | - 'method' => 'POST', |
|
| 579 | - 'timeout' => 45, |
|
| 580 | - 'httpversion' => '1.1', |
|
| 581 | - 'cookies' => array(), |
|
| 582 | - 'headers' => array(), |
|
| 583 | - 'body' => http_build_query($dtls, '', '&'), |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - // Log the response. |
|
| 587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | - return $request_response; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Check the response status. |
|
| 595 | - * |
|
| 596 | - * @param mixed $request_response |
|
| 597 | - * @return array |
|
| 598 | - */ |
|
| 599 | - public function _ppExpress_check_response($request_response) |
|
| 600 | - { |
|
| 601 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 602 | - // If we got here then there was an error in this request. |
|
| 603 | - return array('status' => false, 'args' => $request_response); |
|
| 604 | - } |
|
| 605 | - $response_args = array(); |
|
| 606 | - parse_str(urldecode($request_response['body']), $response_args); |
|
| 607 | - if (! isset($response_args['ACK'])) { |
|
| 608 | - return array('status' => false, 'args' => $request_response); |
|
| 609 | - } |
|
| 610 | - if (( |
|
| 611 | - isset($response_args['PAYERID']) |
|
| 612 | - || isset($response_args['TOKEN']) |
|
| 613 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 614 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 615 | - ) |
|
| 616 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 617 | - ) { |
|
| 618 | - // Response status OK, return response parameters for further processing. |
|
| 619 | - return array('status' => true, 'args' => $response_args); |
|
| 620 | - } |
|
| 621 | - $errors = $this->_get_errors($response_args); |
|
| 622 | - return array('status' => false, 'args' => $errors); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Log a "Cleared" request. |
|
| 629 | - * |
|
| 630 | - * @param array $request |
|
| 631 | - * @param EEI_Payment $payment |
|
| 632 | - * @param string $info |
|
| 633 | - * @return void |
|
| 634 | - */ |
|
| 635 | - private function _log_clean_request($request, $payment, $info) |
|
| 636 | - { |
|
| 637 | - $cleaned_request_data = $request; |
|
| 638 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 639 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Get error from the response data. |
|
| 646 | - * |
|
| 647 | - * @param array $data_array |
|
| 648 | - * @return array |
|
| 649 | - */ |
|
| 650 | - private function _get_errors($data_array) |
|
| 651 | - { |
|
| 652 | - $errors = array(); |
|
| 653 | - $n = 0; |
|
| 654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 657 | - : ''; |
|
| 658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 660 | - : ''; |
|
| 661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 663 | - : ''; |
|
| 664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 666 | - : ''; |
|
| 667 | - if ($n === 0) { |
|
| 668 | - $errors = array( |
|
| 669 | - 'L_ERRORCODE' => $l_error_code, |
|
| 670 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
| 671 | - 'L_LONGMESSAGE' => $l_long_message, |
|
| 672 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
| 673 | - ); |
|
| 674 | - } else { |
|
| 675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 679 | - } |
|
| 680 | - $n++; |
|
| 681 | - } |
|
| 682 | - return $errors; |
|
| 683 | - } |
|
| 30 | + /** |
|
| 31 | + * Merchant API Username. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $_api_username; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Merchant API Password. |
|
| 39 | + * |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected $_api_password; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * API Signature. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $_api_signature; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Request Shipping address on PP checkout page. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $_request_shipping_addr; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Business/personal logo. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + protected $_image_url; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * gateway URL variable |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + protected $_base_gateway_url = ''; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * EEG_Paypal_Express constructor. |
|
| 76 | + */ |
|
| 77 | + public function __construct() |
|
| 78 | + { |
|
| 79 | + $this->_currencies_supported = array( |
|
| 80 | + 'USD', |
|
| 81 | + 'AUD', |
|
| 82 | + 'BRL', |
|
| 83 | + 'CAD', |
|
| 84 | + 'CZK', |
|
| 85 | + 'DKK', |
|
| 86 | + 'EUR', |
|
| 87 | + 'HKD', |
|
| 88 | + 'HUF', |
|
| 89 | + 'ILS', |
|
| 90 | + 'JPY', |
|
| 91 | + 'MYR', |
|
| 92 | + 'MXN', |
|
| 93 | + 'NOK', |
|
| 94 | + 'NZD', |
|
| 95 | + 'PHP', |
|
| 96 | + 'PLN', |
|
| 97 | + 'GBP', |
|
| 98 | + 'RUB', |
|
| 99 | + 'SGD', |
|
| 100 | + 'SEK', |
|
| 101 | + 'CHF', |
|
| 102 | + 'TWD', |
|
| 103 | + 'THB', |
|
| 104 | + 'TRY', |
|
| 105 | + 'INR', |
|
| 106 | + ); |
|
| 107 | + parent::__construct(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
| 114 | + * |
|
| 115 | + * @param array $settings_array |
|
| 116 | + */ |
|
| 117 | + public function set_settings($settings_array) |
|
| 118 | + { |
|
| 119 | + parent::set_settings($settings_array); |
|
| 120 | + // Redirect URL. |
|
| 121 | + $this->_base_gateway_url = $this->_debug_mode |
|
| 122 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 123 | + : 'https://api-3t.paypal.com/nvp'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param EEI_Payment $payment |
|
| 130 | + * @param array $billing_info |
|
| 131 | + * @param string $return_url |
|
| 132 | + * @param string $notify_url |
|
| 133 | + * @param string $cancel_url |
|
| 134 | + * @return \EE_Payment|\EEI_Payment |
|
| 135 | + * @throws \EE_Error |
|
| 136 | + */ |
|
| 137 | + public function set_redirection_info( |
|
| 138 | + $payment, |
|
| 139 | + $billing_info = array(), |
|
| 140 | + $return_url = null, |
|
| 141 | + $notify_url = null, |
|
| 142 | + $cancel_url = null |
|
| 143 | + ) { |
|
| 144 | + if (! $payment instanceof EEI_Payment) { |
|
| 145 | + $payment->set_gateway_response( |
|
| 146 | + esc_html__( |
|
| 147 | + 'Error. No associated payment was found.', |
|
| 148 | + 'event_espresso' |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 152 | + return $payment; |
|
| 153 | + } |
|
| 154 | + $transaction = $payment->transaction(); |
|
| 155 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 156 | + $payment->set_gateway_response( |
|
| 157 | + esc_html__( |
|
| 158 | + 'Could not process this payment because it has no associated transaction.', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ) |
|
| 161 | + ); |
|
| 162 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 163 | + return $payment; |
|
| 164 | + } |
|
| 165 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 166 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
| 167 | + $primary_registration = $transaction->primary_registration(); |
|
| 168 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 169 | + ? $primary_registration->attendee() |
|
| 170 | + : false; |
|
| 171 | + $locale = explode('-', get_bloginfo('language')); |
|
| 172 | + // Gather request parameters. |
|
| 173 | + $token_request_dtls = array( |
|
| 174 | + 'METHOD' => 'SetExpressCheckout', |
|
| 175 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 176 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 177 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
| 178 | + 'RETURNURL' => $return_url, |
|
| 179 | + 'CANCELURL' => $cancel_url, |
|
| 180 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 181 | + // Buyer does not need to create a PayPal account to check out. |
|
| 182 | + // This is referred to as PayPal Account Optional. |
|
| 183 | + 'SOLUTIONTYPE' => 'Sole', |
|
| 184 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 185 | + 'LOCALECODE' => $locale[1] |
|
| 186 | + ); |
|
| 187 | + // Show itemized list. |
|
| 188 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 189 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 190 | + // Automatically filling out shipping and contact information. |
|
| 191 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 192 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 193 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 194 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 195 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 200 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 202 | + } elseif (! $this->_request_shipping_addr) { |
|
| 203 | + // Do not request shipping details on the PP Checkout page. |
|
| 204 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 205 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 206 | + } |
|
| 207 | + // Used a business/personal logo on the PayPal page. |
|
| 208 | + if (! empty($this->_image_url)) { |
|
| 209 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 210 | + } |
|
| 211 | + $token_request_dtls = apply_filters( |
|
| 212 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 213 | + $token_request_dtls, |
|
| 214 | + $this |
|
| 215 | + ); |
|
| 216 | + // Request PayPal token. |
|
| 217 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 218 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 219 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 220 | + ? $token_rstatus['args'] |
|
| 221 | + : array(); |
|
| 222 | + if ($token_rstatus['status']) { |
|
| 223 | + // We got the Token so we may continue with the payment and redirect the client. |
|
| 224 | + $payment->set_details($response_args); |
|
| 225 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 226 | + $payment->set_redirect_url( |
|
| 227 | + $gateway_url |
|
| 228 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 229 | + . $response_args['TOKEN'] |
|
| 230 | + ); |
|
| 231 | + } else { |
|
| 232 | + if (isset($response_args['L_ERRORCODE'])) { |
|
| 233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | + } else { |
|
| 235 | + $payment->set_gateway_response( |
|
| 236 | + esc_html__( |
|
| 237 | + 'Error occurred while trying to setup the Express Checkout.', |
|
| 238 | + 'event_espresso' |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + $payment->set_details($response_args); |
|
| 243 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 244 | + } |
|
| 245 | + return $payment; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param array $update_info { |
|
| 252 | + * @type string $gateway_txn_id |
|
| 253 | + * @type string status an EEMI_Payment status |
|
| 254 | + * } |
|
| 255 | + * @param EEI_Transaction $transaction |
|
| 256 | + * @return EEI_Payment |
|
| 257 | + */ |
|
| 258 | + public function handle_payment_update($update_info, $transaction) |
|
| 259 | + { |
|
| 260 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 261 | + if ($payment instanceof EEI_Payment) { |
|
| 262 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 263 | + $transaction = $payment->transaction(); |
|
| 264 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | + $payment->set_gateway_response( |
|
| 266 | + esc_html__( |
|
| 267 | + 'Could not process this payment because it has no associated transaction.', |
|
| 268 | + 'event_espresso' |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 272 | + return $payment; |
|
| 273 | + } |
|
| 274 | + $primary_registrant = $transaction->primary_registration(); |
|
| 275 | + $payment_details = $payment->details(); |
|
| 276 | + // Check if we still have the token. |
|
| 277 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 279 | + return $payment; |
|
| 280 | + } |
|
| 281 | + $cdetails_request_dtls = array( |
|
| 282 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 283 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 284 | + ); |
|
| 285 | + // Request Customer Details. |
|
| 286 | + $cdetails_request_response = $this->_ppExpress_request( |
|
| 287 | + $cdetails_request_dtls, |
|
| 288 | + 'Customer Details', |
|
| 289 | + $payment |
|
| 290 | + ); |
|
| 291 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 292 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 293 | + ? $cdetails_rstatus['args'] |
|
| 294 | + : array(); |
|
| 295 | + if ($cdetails_rstatus['status']) { |
|
| 296 | + // We got the PayerID so now we can Complete the transaction. |
|
| 297 | + $docheckout_request_dtls = array( |
|
| 298 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 299 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 300 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 301 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 302 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 303 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 304 | + ); |
|
| 305 | + // Include itemized list. |
|
| 306 | + $itemized_list = $this->itemize_list( |
|
| 307 | + $payment, |
|
| 308 | + $transaction, |
|
| 309 | + $cdata_response_args |
|
| 310 | + ); |
|
| 311 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 312 | + // Payment Checkout/Capture. |
|
| 313 | + $docheckout_request_response = $this->_ppExpress_request( |
|
| 314 | + $docheckout_request_dtls, |
|
| 315 | + 'Do Payment', |
|
| 316 | + $payment |
|
| 317 | + ); |
|
| 318 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 319 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 320 | + ? $docheckout_rstatus['args'] |
|
| 321 | + : array(); |
|
| 322 | + if ($docheckout_rstatus['status']) { |
|
| 323 | + // All is well, payment approved. |
|
| 324 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 325 | + $primary_registrant->reg_code() |
|
| 326 | + : ''; |
|
| 327 | + $payment->set_extra_accntng($primary_registration_code); |
|
| 328 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 329 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 330 | + : 0); |
|
| 331 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 332 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 333 | + : null); |
|
| 334 | + $payment->set_details($cdata_response_args); |
|
| 335 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 336 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 337 | + : ''); |
|
| 338 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 339 | + } else { |
|
| 340 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 341 | + $payment->set_gateway_response( |
|
| 342 | + $docheckout_response_args['L_ERRORCODE'] |
|
| 343 | + . '; ' |
|
| 344 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 345 | + ); |
|
| 346 | + } else { |
|
| 347 | + $payment->set_gateway_response( |
|
| 348 | + esc_html__( |
|
| 349 | + 'Error occurred while trying to Capture the funds.', |
|
| 350 | + 'event_espresso' |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + $payment->set_details($docheckout_response_args); |
|
| 355 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 356 | + } |
|
| 357 | + } else { |
|
| 358 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 359 | + $payment->set_gateway_response( |
|
| 360 | + $cdata_response_args['L_ERRORCODE'] |
|
| 361 | + . '; ' |
|
| 362 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 363 | + ); |
|
| 364 | + } else { |
|
| 365 | + $payment->set_gateway_response( |
|
| 366 | + esc_html__( |
|
| 367 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
| 368 | + 'event_espresso' |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + $payment->set_details($cdata_response_args); |
|
| 373 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 374 | + } |
|
| 375 | + } else { |
|
| 376 | + $payment->set_gateway_response( |
|
| 377 | + esc_html__( |
|
| 378 | + 'Error occurred while trying to process the payment.', |
|
| 379 | + 'event_espresso' |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 383 | + } |
|
| 384 | + return $payment; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Make a list of items that are in the giver transaction. |
|
| 391 | + * |
|
| 392 | + * @param EEI_Payment $payment |
|
| 393 | + * @param EEI_Transaction $transaction |
|
| 394 | + * @param array $request_response_args Data from a previous communication with PP. |
|
| 395 | + * @return array |
|
| 396 | + */ |
|
| 397 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 398 | + { |
|
| 399 | + $itemized_list = array(); |
|
| 400 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 401 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 402 | + if (! empty($request_response_args) |
|
| 403 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 404 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 405 | + ) { |
|
| 406 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 407 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 408 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
| 409 | + ) { |
|
| 410 | + $itemized_list[ $arg_key ] = $arg_val; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + // If we got only a few Items then something is not right. |
|
| 414 | + if (count($itemized_list) > 2) { |
|
| 415 | + return $itemized_list; |
|
| 416 | + } else { |
|
| 417 | + if (WP_DEBUG) { |
|
| 418 | + throw new EE_Error( |
|
| 419 | + sprintf( |
|
| 420 | + esc_html__( |
|
| 421 | + // @codingStandardsIgnoreStart |
|
| 422 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 423 | + // @codingStandardsIgnoreEnd |
|
| 424 | + 'event_espresso' |
|
| 425 | + ), |
|
| 426 | + wp_json_encode($itemized_list) |
|
| 427 | + ) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 431 | + $itemized_list = array(); |
|
| 432 | + $this->log( |
|
| 433 | + array( |
|
| 434 | + (string) esc_html__( |
|
| 435 | + 'Could not generate a proper item list with:', |
|
| 436 | + 'event_espresso' |
|
| 437 | + ) => $request_response_args |
|
| 438 | + ), |
|
| 439 | + $payment |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + // ...otherwise we generate a new list for this transaction. |
|
| 444 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 445 | + $item_num = 0; |
|
| 446 | + $itemized_sum = 0; |
|
| 447 | + $total_line_items = $transaction->total_line_item(); |
|
| 448 | + // Go through each item in the list. |
|
| 449 | + foreach ($total_line_items->get_items() as $line_item) { |
|
| 450 | + if ($line_item instanceof EE_Line_Item) { |
|
| 451 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 452 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 453 | + continue; |
|
| 454 | + } |
|
| 455 | + $unit_price = $line_item->unit_price(); |
|
| 456 | + $line_item_quantity = $line_item->quantity(); |
|
| 457 | + // This is a discount. |
|
| 458 | + if ($line_item->is_percent()) { |
|
| 459 | + $unit_price = $line_item->total(); |
|
| 460 | + $line_item_quantity = 1; |
|
| 461 | + } |
|
| 462 | + // Item Name. |
|
| 463 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 464 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 465 | + 0, |
|
| 466 | + 127 |
|
| 467 | + ); |
|
| 468 | + // Item description. |
|
| 469 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 470 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 471 | + 0, |
|
| 472 | + 127 |
|
| 473 | + ); |
|
| 474 | + // Cost of individual item. |
|
| 475 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | + // Item Number. |
|
| 477 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 478 | + // Item quantity. |
|
| 479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 480 | + // Digital item is sold. |
|
| 481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 482 | + $itemized_sum += $line_item->total(); |
|
| 483 | + ++$item_num; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + // Item's sales S/H and tax amount. |
|
| 487 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 488 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 489 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 490 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 491 | + $itemized_sum_diff_from_txn_total = round( |
|
| 492 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 493 | + 2 |
|
| 494 | + ); |
|
| 495 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 496 | + // add the difference as an extra line item. |
|
| 497 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 498 | + // Item Name. |
|
| 499 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 500 | + esc_html__( |
|
| 501 | + 'Other (promotion/surcharge/cancellation)', |
|
| 502 | + 'event_espresso' |
|
| 503 | + ), |
|
| 504 | + 0, |
|
| 505 | + 127 |
|
| 506 | + ); |
|
| 507 | + // Item description. |
|
| 508 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 509 | + // Cost of individual item. |
|
| 510 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 511 | + $itemized_sum_diff_from_txn_total |
|
| 512 | + ); |
|
| 513 | + // Item Number. |
|
| 514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 515 | + // Item quantity. |
|
| 516 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 517 | + // Digital item is sold. |
|
| 518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 519 | + $item_num++; |
|
| 520 | + } |
|
| 521 | + } else { |
|
| 522 | + // Just one Item. |
|
| 523 | + // Item Name. |
|
| 524 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 525 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 526 | + 0, |
|
| 527 | + 127 |
|
| 528 | + ); |
|
| 529 | + // Item description. |
|
| 530 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 531 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 532 | + 0, |
|
| 533 | + 127 |
|
| 534 | + ); |
|
| 535 | + // Cost of individual item. |
|
| 536 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 537 | + // Item Number. |
|
| 538 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 539 | + // Item quantity. |
|
| 540 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 541 | + // Digital item is sold. |
|
| 542 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 543 | + // Item's sales S/H and tax amount. |
|
| 544 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 545 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 546 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 547 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 548 | + } |
|
| 549 | + return $itemized_list; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Make the Express checkout request. |
|
| 556 | + * |
|
| 557 | + * @param array $request_params |
|
| 558 | + * @param string $request_text |
|
| 559 | + * @param EEI_Payment $payment |
|
| 560 | + * @return mixed |
|
| 561 | + */ |
|
| 562 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 563 | + { |
|
| 564 | + $request_dtls = array( |
|
| 565 | + 'VERSION' => '204.0', |
|
| 566 | + 'USER' => urlencode($this->_api_username), |
|
| 567 | + 'PWD' => urlencode($this->_api_password), |
|
| 568 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
| 569 | + // EE will blow up if you change this |
|
| 570 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 571 | + ); |
|
| 572 | + $dtls = array_merge($request_dtls, $request_params); |
|
| 573 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | + // Request Customer Details. |
|
| 575 | + $request_response = wp_remote_post( |
|
| 576 | + $this->_base_gateway_url, |
|
| 577 | + array( |
|
| 578 | + 'method' => 'POST', |
|
| 579 | + 'timeout' => 45, |
|
| 580 | + 'httpversion' => '1.1', |
|
| 581 | + 'cookies' => array(), |
|
| 582 | + 'headers' => array(), |
|
| 583 | + 'body' => http_build_query($dtls, '', '&'), |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + // Log the response. |
|
| 587 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | + return $request_response; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Check the response status. |
|
| 595 | + * |
|
| 596 | + * @param mixed $request_response |
|
| 597 | + * @return array |
|
| 598 | + */ |
|
| 599 | + public function _ppExpress_check_response($request_response) |
|
| 600 | + { |
|
| 601 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 602 | + // If we got here then there was an error in this request. |
|
| 603 | + return array('status' => false, 'args' => $request_response); |
|
| 604 | + } |
|
| 605 | + $response_args = array(); |
|
| 606 | + parse_str(urldecode($request_response['body']), $response_args); |
|
| 607 | + if (! isset($response_args['ACK'])) { |
|
| 608 | + return array('status' => false, 'args' => $request_response); |
|
| 609 | + } |
|
| 610 | + if (( |
|
| 611 | + isset($response_args['PAYERID']) |
|
| 612 | + || isset($response_args['TOKEN']) |
|
| 613 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 614 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 615 | + ) |
|
| 616 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 617 | + ) { |
|
| 618 | + // Response status OK, return response parameters for further processing. |
|
| 619 | + return array('status' => true, 'args' => $response_args); |
|
| 620 | + } |
|
| 621 | + $errors = $this->_get_errors($response_args); |
|
| 622 | + return array('status' => false, 'args' => $errors); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Log a "Cleared" request. |
|
| 629 | + * |
|
| 630 | + * @param array $request |
|
| 631 | + * @param EEI_Payment $payment |
|
| 632 | + * @param string $info |
|
| 633 | + * @return void |
|
| 634 | + */ |
|
| 635 | + private function _log_clean_request($request, $payment, $info) |
|
| 636 | + { |
|
| 637 | + $cleaned_request_data = $request; |
|
| 638 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 639 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Get error from the response data. |
|
| 646 | + * |
|
| 647 | + * @param array $data_array |
|
| 648 | + * @return array |
|
| 649 | + */ |
|
| 650 | + private function _get_errors($data_array) |
|
| 651 | + { |
|
| 652 | + $errors = array(); |
|
| 653 | + $n = 0; |
|
| 654 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 657 | + : ''; |
|
| 658 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 660 | + : ''; |
|
| 661 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 663 | + : ''; |
|
| 664 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 666 | + : ''; |
|
| 667 | + if ($n === 0) { |
|
| 668 | + $errors = array( |
|
| 669 | + 'L_ERRORCODE' => $l_error_code, |
|
| 670 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
| 671 | + 'L_LONGMESSAGE' => $l_long_message, |
|
| 672 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
| 673 | + ); |
|
| 674 | + } else { |
|
| 675 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 679 | + } |
|
| 680 | + $n++; |
|
| 681 | + } |
|
| 682 | + return $errors; |
|
| 683 | + } |
|
| 684 | 684 | } |
@@ -16,447 +16,447 @@ |
||
| 16 | 16 | class EE_CPT_Strategy extends EE_Base |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var EE_CPT_Strategy $_instance |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * the current page, if it utilizes CPTs |
|
| 26 | - * |
|
| 27 | - * @var array $CPT |
|
| 28 | - */ |
|
| 29 | - protected $CPT; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
| 33 | - * |
|
| 34 | - * @var array $_CPTs |
|
| 35 | - */ |
|
| 36 | - protected $_CPTs = array(); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array $_CPT_taxonomies |
|
| 40 | - */ |
|
| 41 | - protected $_CPT_taxonomies = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var array $_CPT_terms |
|
| 45 | - */ |
|
| 46 | - protected $_CPT_terms = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var array $_CPT_endpoints |
|
| 50 | - */ |
|
| 51 | - protected $_CPT_endpoints = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var EEM_Base $CPT_model |
|
| 55 | - */ |
|
| 56 | - protected $CPT_model; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
| 60 | - */ |
|
| 61 | - protected $query_modifier; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @singleton method used to instantiate class object |
|
| 66 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
| 67 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
| 68 | - * @return EE_CPT_Strategy |
|
| 69 | - */ |
|
| 70 | - public static function instance( |
|
| 71 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
| 72 | - CustomTaxonomyDefinitions $taxonomies = null |
|
| 73 | - ) { |
|
| 74 | - // check if class object is instantiated |
|
| 75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
| 76 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
| 77 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
| 78 | - ) { |
|
| 79 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
| 80 | - } |
|
| 81 | - return self::$_instance; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
| 87 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
| 88 | - */ |
|
| 89 | - protected function __construct( |
|
| 90 | - CustomPostTypeDefinitions $custom_post_types, |
|
| 91 | - CustomTaxonomyDefinitions $taxonomies |
|
| 92 | - ) { |
|
| 93 | - // get CPT data |
|
| 94 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
| 95 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
| 96 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
| 97 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - public function get_CPT_endpoints() |
|
| 105 | - { |
|
| 106 | - return $this->_CPT_endpoints; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function get_CPT_taxonomies() |
|
| 114 | - { |
|
| 115 | - return $this->_CPT_taxonomies; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * add CPT "slugs" to array of default espresso "pages" |
|
| 121 | - * |
|
| 122 | - * @return array |
|
| 123 | - */ |
|
| 124 | - private function _set_CPT_endpoints() |
|
| 125 | - { |
|
| 126 | - $_CPT_endpoints = array(); |
|
| 127 | - if (is_array($this->_CPTs)) { |
|
| 128 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
| 129 | - if (isset($CPT['plural_slug'])) { |
|
| 130 | - $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $_CPT_endpoints; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
| 140 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
| 141 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
| 142 | - * |
|
| 143 | - * @param WP_Query $WP_Query |
|
| 144 | - * @return void |
|
| 145 | - * @throws \EE_Error |
|
| 146 | - * @throws \InvalidArgumentException |
|
| 147 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 148 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 149 | - */ |
|
| 150 | - public function pre_get_posts($WP_Query) |
|
| 151 | - { |
|
| 152 | - // check that post-type is set |
|
| 153 | - if (! $WP_Query instanceof WP_Query) { |
|
| 154 | - return; |
|
| 155 | - } |
|
| 156 | - // add our conditionals |
|
| 157 | - $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
| 158 | - // check for terms |
|
| 159 | - $this->_set_post_type_for_terms($WP_Query); |
|
| 160 | - // make sure paging is always set |
|
| 161 | - $this->_set_paging($WP_Query); |
|
| 162 | - // is a taxonomy set ? |
|
| 163 | - $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
| 164 | - // loop thru post_types if set |
|
| 165 | - $this->_process_WP_Query_post_types($WP_Query); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param WP_Query $WP_Query |
|
| 171 | - * @return void |
|
| 172 | - */ |
|
| 173 | - private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
| 174 | - { |
|
| 175 | - $WP_Query->is_espresso_event_single = false; |
|
| 176 | - $WP_Query->is_espresso_event_archive = false; |
|
| 177 | - $WP_Query->is_espresso_event_taxonomy = false; |
|
| 178 | - $WP_Query->is_espresso_venue_single = false; |
|
| 179 | - $WP_Query->is_espresso_venue_archive = false; |
|
| 180 | - $WP_Query->is_espresso_venue_taxonomy = false; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return void |
|
| 186 | - * @throws EE_Error |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - */ |
|
| 191 | - private function _set_CPT_terms() |
|
| 192 | - { |
|
| 193 | - if (empty($this->_CPT_terms)) { |
|
| 194 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
| 195 | - foreach ($terms as $term) { |
|
| 196 | - if ($term instanceof EE_Term) { |
|
| 197 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @param WP_Query $WP_Query |
|
| 206 | - * @return void |
|
| 207 | - * @throws EE_Error |
|
| 208 | - * @throws InvalidArgumentException |
|
| 209 | - * @throws InvalidDataTypeException |
|
| 210 | - * @throws InvalidInterfaceException |
|
| 211 | - */ |
|
| 212 | - private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
| 213 | - { |
|
| 214 | - // is a tag set ? |
|
| 215 | - if (isset($WP_Query->query['tag'])) { |
|
| 216 | - // get term for tag |
|
| 217 | - $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
| 218 | - // verify the term |
|
| 219 | - if ($term instanceof EE_Term) { |
|
| 220 | - $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
| 221 | - $term->post_type = apply_filters( |
|
| 222 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
| 223 | - $term->post_type, |
|
| 224 | - $term |
|
| 225 | - ); |
|
| 226 | - // if a post type is already set |
|
| 227 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
| 228 | - // add to existing array |
|
| 229 | - $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
| 230 | - } |
|
| 231 | - // just set post_type to our CPT |
|
| 232 | - $WP_Query->set('post_type', array_unique($term->post_type)); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param WP_Query $WP_Query |
|
| 240 | - * @return void |
|
| 241 | - */ |
|
| 242 | - public function _set_paging($WP_Query) |
|
| 243 | - { |
|
| 244 | - if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
| 245 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
| 246 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
| 247 | - $WP_Query->set('paged', $paged); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @param \WP_Query $WP_Query |
|
| 254 | - */ |
|
| 255 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
| 256 | - { |
|
| 257 | - // is a taxonomy set ? |
|
| 258 | - if ($WP_Query->is_tax) { |
|
| 259 | - // loop thru our taxonomies |
|
| 260 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
| 261 | - // check if one of our taxonomies is set as a query var |
|
| 262 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
| 263 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
| 264 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
| 265 | - // verify our CPT has args, is public and has taxonomies set |
|
| 266 | - if (isset($CPT['args']['public']) |
|
| 267 | - && $CPT['args']['public'] |
|
| 268 | - && ! empty($CPT['args']['taxonomies']) |
|
| 269 | - && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
| 270 | - ) { |
|
| 271 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
| 272 | - $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
| 273 | - ? (array) $WP_Query->query_vars['post_type'] |
|
| 274 | - : array(); |
|
| 275 | - $WP_Query->query_vars['post_type'][] = $post_type; |
|
| 276 | - switch ($post_type) { |
|
| 277 | - case 'espresso_events': |
|
| 278 | - $WP_Query->is_espresso_event_taxonomy = true; |
|
| 279 | - break; |
|
| 280 | - case 'espresso_venues': |
|
| 281 | - $WP_Query->is_espresso_venue_taxonomy = true; |
|
| 282 | - break; |
|
| 283 | - default: |
|
| 284 | - do_action( |
|
| 285 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
| 286 | - $WP_Query, |
|
| 287 | - $this |
|
| 288 | - ); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @param \WP_Query $WP_Query |
|
| 300 | - * @throws InvalidArgumentException |
|
| 301 | - * @throws InvalidDataTypeException |
|
| 302 | - * @throws InvalidInterfaceException |
|
| 303 | - */ |
|
| 304 | - protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
| 305 | - { |
|
| 306 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
| 307 | - // loop thru post_types as array |
|
| 308 | - foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
| 309 | - // is current query for an EE CPT ? |
|
| 310 | - if (isset($this->_CPTs[ $post_type ])) { |
|
| 311 | - // is EE on or off ? |
|
| 312 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
| 313 | - // reroute CPT template view to maintenance_mode.template.php |
|
| 314 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 315 | - add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
| 316 | - } |
|
| 317 | - if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
| 318 | - add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
| 319 | - } |
|
| 320 | - return; |
|
| 321 | - } |
|
| 322 | - $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @param \WP_Query $WP_Query |
|
| 331 | - * @param string $post_type |
|
| 332 | - * @throws InvalidArgumentException |
|
| 333 | - * @throws InvalidDataTypeException |
|
| 334 | - * @throws InvalidInterfaceException |
|
| 335 | - */ |
|
| 336 | - protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
| 337 | - { |
|
| 338 | - $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
| 339 | - 'EventEspresso\core\CPTs\CptQueryModifier', |
|
| 340 | - array( |
|
| 341 | - $post_type, |
|
| 342 | - $this->_CPTs[ $post_type ], |
|
| 343 | - $WP_Query, |
|
| 344 | - ) |
|
| 345 | - ); |
|
| 346 | - $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * inject_EE_shortcode_placeholder |
|
| 352 | - * in order to display the M-Mode notice on our CPT routes, |
|
| 353 | - * we need to first inject what looks like one of our shortcodes, |
|
| 354 | - * so that it can be replaced with the actual M-Mode notice |
|
| 355 | - * |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function inject_EE_shortcode_placeholder() |
|
| 359 | - { |
|
| 360 | - return '[ESPRESSO_'; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * @deprecated |
|
| 366 | - * @since 4.8.41 |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function _possibly_set_ee_request_var() |
|
| 370 | - { |
|
| 371 | - $this->query_modifier->setRequestVarsIfCpt(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @deprecated |
|
| 377 | - * @since 4.8.41 |
|
| 378 | - * @param $SQL |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function posts_fields($SQL) |
|
| 382 | - { |
|
| 383 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 384 | - return $this->query_modifier->postsFields($SQL); |
|
| 385 | - } |
|
| 386 | - return $SQL; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @deprecated |
|
| 392 | - * @since 4.8.41 |
|
| 393 | - * @param $SQL |
|
| 394 | - * @return string |
|
| 395 | - */ |
|
| 396 | - public function posts_join($SQL) |
|
| 397 | - { |
|
| 398 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 399 | - return $this->query_modifier->postsJoin($SQL); |
|
| 400 | - } |
|
| 401 | - return $SQL; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @deprecated |
|
| 407 | - * @since 4.8.41 |
|
| 408 | - * @param \WP_Post[] $posts |
|
| 409 | - * @return \WP_Post[] |
|
| 410 | - */ |
|
| 411 | - public function the_posts($posts) |
|
| 412 | - { |
|
| 413 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 414 | - $this->query_modifier->thePosts($posts); |
|
| 415 | - } |
|
| 416 | - return $posts; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @deprecated |
|
| 422 | - * @since 4.8.41 |
|
| 423 | - * @param $url |
|
| 424 | - * @param $ID |
|
| 425 | - * @return string |
|
| 426 | - */ |
|
| 427 | - public function get_edit_post_link($url, $ID) |
|
| 428 | - { |
|
| 429 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 430 | - return $this->query_modifier->getEditPostLink($url, $ID); |
|
| 431 | - } |
|
| 432 | - return ''; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * @deprecated |
|
| 438 | - * @since 4.8.41 |
|
| 439 | - * @param null $WP_Query |
|
| 440 | - */ |
|
| 441 | - protected function _do_template_filters($WP_Query = null) |
|
| 442 | - { |
|
| 443 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 444 | - $this->query_modifier->addTemplateFilters(); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @deprecated |
|
| 451 | - * @since 4.8.41 |
|
| 452 | - * @param string $current_template Existing default template path derived for this page call. |
|
| 453 | - * @return string the path to the full template file. |
|
| 454 | - */ |
|
| 455 | - public function single_cpt_template($current_template) |
|
| 456 | - { |
|
| 457 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 458 | - return $this->query_modifier->singleCptTemplate($current_template); |
|
| 459 | - } |
|
| 460 | - return $current_template; |
|
| 461 | - } |
|
| 19 | + /** |
|
| 20 | + * @var EE_CPT_Strategy $_instance |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * the current page, if it utilizes CPTs |
|
| 26 | + * |
|
| 27 | + * @var array $CPT |
|
| 28 | + */ |
|
| 29 | + protected $CPT; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
| 33 | + * |
|
| 34 | + * @var array $_CPTs |
|
| 35 | + */ |
|
| 36 | + protected $_CPTs = array(); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array $_CPT_taxonomies |
|
| 40 | + */ |
|
| 41 | + protected $_CPT_taxonomies = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var array $_CPT_terms |
|
| 45 | + */ |
|
| 46 | + protected $_CPT_terms = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var array $_CPT_endpoints |
|
| 50 | + */ |
|
| 51 | + protected $_CPT_endpoints = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var EEM_Base $CPT_model |
|
| 55 | + */ |
|
| 56 | + protected $CPT_model; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
| 60 | + */ |
|
| 61 | + protected $query_modifier; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @singleton method used to instantiate class object |
|
| 66 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
| 67 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
| 68 | + * @return EE_CPT_Strategy |
|
| 69 | + */ |
|
| 70 | + public static function instance( |
|
| 71 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
| 72 | + CustomTaxonomyDefinitions $taxonomies = null |
|
| 73 | + ) { |
|
| 74 | + // check if class object is instantiated |
|
| 75 | + if (! self::$_instance instanceof EE_CPT_Strategy |
|
| 76 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
| 77 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
| 78 | + ) { |
|
| 79 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
| 80 | + } |
|
| 81 | + return self::$_instance; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
| 87 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
| 88 | + */ |
|
| 89 | + protected function __construct( |
|
| 90 | + CustomPostTypeDefinitions $custom_post_types, |
|
| 91 | + CustomTaxonomyDefinitions $taxonomies |
|
| 92 | + ) { |
|
| 93 | + // get CPT data |
|
| 94 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
| 95 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
| 96 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
| 97 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + public function get_CPT_endpoints() |
|
| 105 | + { |
|
| 106 | + return $this->_CPT_endpoints; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function get_CPT_taxonomies() |
|
| 114 | + { |
|
| 115 | + return $this->_CPT_taxonomies; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * add CPT "slugs" to array of default espresso "pages" |
|
| 121 | + * |
|
| 122 | + * @return array |
|
| 123 | + */ |
|
| 124 | + private function _set_CPT_endpoints() |
|
| 125 | + { |
|
| 126 | + $_CPT_endpoints = array(); |
|
| 127 | + if (is_array($this->_CPTs)) { |
|
| 128 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
| 129 | + if (isset($CPT['plural_slug'])) { |
|
| 130 | + $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $_CPT_endpoints; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
| 140 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
| 141 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
| 142 | + * |
|
| 143 | + * @param WP_Query $WP_Query |
|
| 144 | + * @return void |
|
| 145 | + * @throws \EE_Error |
|
| 146 | + * @throws \InvalidArgumentException |
|
| 147 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 148 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 149 | + */ |
|
| 150 | + public function pre_get_posts($WP_Query) |
|
| 151 | + { |
|
| 152 | + // check that post-type is set |
|
| 153 | + if (! $WP_Query instanceof WP_Query) { |
|
| 154 | + return; |
|
| 155 | + } |
|
| 156 | + // add our conditionals |
|
| 157 | + $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
| 158 | + // check for terms |
|
| 159 | + $this->_set_post_type_for_terms($WP_Query); |
|
| 160 | + // make sure paging is always set |
|
| 161 | + $this->_set_paging($WP_Query); |
|
| 162 | + // is a taxonomy set ? |
|
| 163 | + $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
| 164 | + // loop thru post_types if set |
|
| 165 | + $this->_process_WP_Query_post_types($WP_Query); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param WP_Query $WP_Query |
|
| 171 | + * @return void |
|
| 172 | + */ |
|
| 173 | + private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
| 174 | + { |
|
| 175 | + $WP_Query->is_espresso_event_single = false; |
|
| 176 | + $WP_Query->is_espresso_event_archive = false; |
|
| 177 | + $WP_Query->is_espresso_event_taxonomy = false; |
|
| 178 | + $WP_Query->is_espresso_venue_single = false; |
|
| 179 | + $WP_Query->is_espresso_venue_archive = false; |
|
| 180 | + $WP_Query->is_espresso_venue_taxonomy = false; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return void |
|
| 186 | + * @throws EE_Error |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + */ |
|
| 191 | + private function _set_CPT_terms() |
|
| 192 | + { |
|
| 193 | + if (empty($this->_CPT_terms)) { |
|
| 194 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
| 195 | + foreach ($terms as $term) { |
|
| 196 | + if ($term instanceof EE_Term) { |
|
| 197 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @param WP_Query $WP_Query |
|
| 206 | + * @return void |
|
| 207 | + * @throws EE_Error |
|
| 208 | + * @throws InvalidArgumentException |
|
| 209 | + * @throws InvalidDataTypeException |
|
| 210 | + * @throws InvalidInterfaceException |
|
| 211 | + */ |
|
| 212 | + private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
| 213 | + { |
|
| 214 | + // is a tag set ? |
|
| 215 | + if (isset($WP_Query->query['tag'])) { |
|
| 216 | + // get term for tag |
|
| 217 | + $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
| 218 | + // verify the term |
|
| 219 | + if ($term instanceof EE_Term) { |
|
| 220 | + $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
| 221 | + $term->post_type = apply_filters( |
|
| 222 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
| 223 | + $term->post_type, |
|
| 224 | + $term |
|
| 225 | + ); |
|
| 226 | + // if a post type is already set |
|
| 227 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
| 228 | + // add to existing array |
|
| 229 | + $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
| 230 | + } |
|
| 231 | + // just set post_type to our CPT |
|
| 232 | + $WP_Query->set('post_type', array_unique($term->post_type)); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param WP_Query $WP_Query |
|
| 240 | + * @return void |
|
| 241 | + */ |
|
| 242 | + public function _set_paging($WP_Query) |
|
| 243 | + { |
|
| 244 | + if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
| 245 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
| 246 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
| 247 | + $WP_Query->set('paged', $paged); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @param \WP_Query $WP_Query |
|
| 254 | + */ |
|
| 255 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
| 256 | + { |
|
| 257 | + // is a taxonomy set ? |
|
| 258 | + if ($WP_Query->is_tax) { |
|
| 259 | + // loop thru our taxonomies |
|
| 260 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
| 261 | + // check if one of our taxonomies is set as a query var |
|
| 262 | + if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
| 263 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
| 264 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
| 265 | + // verify our CPT has args, is public and has taxonomies set |
|
| 266 | + if (isset($CPT['args']['public']) |
|
| 267 | + && $CPT['args']['public'] |
|
| 268 | + && ! empty($CPT['args']['taxonomies']) |
|
| 269 | + && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
| 270 | + ) { |
|
| 271 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
| 272 | + $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
| 273 | + ? (array) $WP_Query->query_vars['post_type'] |
|
| 274 | + : array(); |
|
| 275 | + $WP_Query->query_vars['post_type'][] = $post_type; |
|
| 276 | + switch ($post_type) { |
|
| 277 | + case 'espresso_events': |
|
| 278 | + $WP_Query->is_espresso_event_taxonomy = true; |
|
| 279 | + break; |
|
| 280 | + case 'espresso_venues': |
|
| 281 | + $WP_Query->is_espresso_venue_taxonomy = true; |
|
| 282 | + break; |
|
| 283 | + default: |
|
| 284 | + do_action( |
|
| 285 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
| 286 | + $WP_Query, |
|
| 287 | + $this |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @param \WP_Query $WP_Query |
|
| 300 | + * @throws InvalidArgumentException |
|
| 301 | + * @throws InvalidDataTypeException |
|
| 302 | + * @throws InvalidInterfaceException |
|
| 303 | + */ |
|
| 304 | + protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
| 305 | + { |
|
| 306 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
| 307 | + // loop thru post_types as array |
|
| 308 | + foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
| 309 | + // is current query for an EE CPT ? |
|
| 310 | + if (isset($this->_CPTs[ $post_type ])) { |
|
| 311 | + // is EE on or off ? |
|
| 312 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
| 313 | + // reroute CPT template view to maintenance_mode.template.php |
|
| 314 | + if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 315 | + add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
| 316 | + } |
|
| 317 | + if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
| 318 | + add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
| 319 | + } |
|
| 320 | + return; |
|
| 321 | + } |
|
| 322 | + $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @param \WP_Query $WP_Query |
|
| 331 | + * @param string $post_type |
|
| 332 | + * @throws InvalidArgumentException |
|
| 333 | + * @throws InvalidDataTypeException |
|
| 334 | + * @throws InvalidInterfaceException |
|
| 335 | + */ |
|
| 336 | + protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
| 337 | + { |
|
| 338 | + $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
| 339 | + 'EventEspresso\core\CPTs\CptQueryModifier', |
|
| 340 | + array( |
|
| 341 | + $post_type, |
|
| 342 | + $this->_CPTs[ $post_type ], |
|
| 343 | + $WP_Query, |
|
| 344 | + ) |
|
| 345 | + ); |
|
| 346 | + $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * inject_EE_shortcode_placeholder |
|
| 352 | + * in order to display the M-Mode notice on our CPT routes, |
|
| 353 | + * we need to first inject what looks like one of our shortcodes, |
|
| 354 | + * so that it can be replaced with the actual M-Mode notice |
|
| 355 | + * |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function inject_EE_shortcode_placeholder() |
|
| 359 | + { |
|
| 360 | + return '[ESPRESSO_'; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * @deprecated |
|
| 366 | + * @since 4.8.41 |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function _possibly_set_ee_request_var() |
|
| 370 | + { |
|
| 371 | + $this->query_modifier->setRequestVarsIfCpt(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @deprecated |
|
| 377 | + * @since 4.8.41 |
|
| 378 | + * @param $SQL |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function posts_fields($SQL) |
|
| 382 | + { |
|
| 383 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 384 | + return $this->query_modifier->postsFields($SQL); |
|
| 385 | + } |
|
| 386 | + return $SQL; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @deprecated |
|
| 392 | + * @since 4.8.41 |
|
| 393 | + * @param $SQL |
|
| 394 | + * @return string |
|
| 395 | + */ |
|
| 396 | + public function posts_join($SQL) |
|
| 397 | + { |
|
| 398 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 399 | + return $this->query_modifier->postsJoin($SQL); |
|
| 400 | + } |
|
| 401 | + return $SQL; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @deprecated |
|
| 407 | + * @since 4.8.41 |
|
| 408 | + * @param \WP_Post[] $posts |
|
| 409 | + * @return \WP_Post[] |
|
| 410 | + */ |
|
| 411 | + public function the_posts($posts) |
|
| 412 | + { |
|
| 413 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 414 | + $this->query_modifier->thePosts($posts); |
|
| 415 | + } |
|
| 416 | + return $posts; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @deprecated |
|
| 422 | + * @since 4.8.41 |
|
| 423 | + * @param $url |
|
| 424 | + * @param $ID |
|
| 425 | + * @return string |
|
| 426 | + */ |
|
| 427 | + public function get_edit_post_link($url, $ID) |
|
| 428 | + { |
|
| 429 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 430 | + return $this->query_modifier->getEditPostLink($url, $ID); |
|
| 431 | + } |
|
| 432 | + return ''; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * @deprecated |
|
| 438 | + * @since 4.8.41 |
|
| 439 | + * @param null $WP_Query |
|
| 440 | + */ |
|
| 441 | + protected function _do_template_filters($WP_Query = null) |
|
| 442 | + { |
|
| 443 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 444 | + $this->query_modifier->addTemplateFilters(); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @deprecated |
|
| 451 | + * @since 4.8.41 |
|
| 452 | + * @param string $current_template Existing default template path derived for this page call. |
|
| 453 | + * @return string the path to the full template file. |
|
| 454 | + */ |
|
| 455 | + public function single_cpt_template($current_template) |
|
| 456 | + { |
|
| 457 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
| 458 | + return $this->query_modifier->singleCptTemplate($current_template); |
|
| 459 | + } |
|
| 460 | + return $current_template; |
|
| 461 | + } |
|
| 462 | 462 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | CustomTaxonomyDefinitions $taxonomies = null |
| 73 | 73 | ) { |
| 74 | 74 | // check if class object is instantiated |
| 75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
| 75 | + if ( ! self::$_instance instanceof EE_CPT_Strategy |
|
| 76 | 76 | && $custom_post_types instanceof CustomPostTypeDefinitions |
| 77 | 77 | && $taxonomies instanceof CustomTaxonomyDefinitions |
| 78 | 78 | ) { |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | if (is_array($this->_CPTs)) { |
| 128 | 128 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
| 129 | 129 | if (isset($CPT['plural_slug'])) { |
| 130 | - $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type; |
|
| 130 | + $_CPT_endpoints [(string) $CPT['plural_slug']] = $CPT_type; |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | public function pre_get_posts($WP_Query) |
| 151 | 151 | { |
| 152 | 152 | // check that post-type is set |
| 153 | - if (! $WP_Query instanceof WP_Query) { |
|
| 153 | + if ( ! $WP_Query instanceof WP_Query) { |
|
| 154 | 154 | return; |
| 155 | 155 | } |
| 156 | 156 | // add our conditionals |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
| 195 | 195 | foreach ($terms as $term) { |
| 196 | 196 | if ($term instanceof EE_Term) { |
| 197 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
| 197 | + $this->_CPT_terms[$term->slug()] = $term; |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | // loop thru our taxonomies |
| 260 | 260 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
| 261 | 261 | // check if one of our taxonomies is set as a query var |
| 262 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
| 262 | + if (isset($WP_Query->query[$CPT_taxonomy])) { |
|
| 263 | 263 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
| 264 | 264 | foreach ($this->_CPTs as $post_type => $CPT) { |
| 265 | 265 | // verify our CPT has args, is public and has taxonomies set |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | break; |
| 283 | 283 | default: |
| 284 | 284 | do_action( |
| 285 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
| 285 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
| 286 | 286 | $WP_Query, |
| 287 | 287 | $this |
| 288 | 288 | ); |
@@ -307,11 +307,11 @@ discard block |
||
| 307 | 307 | // loop thru post_types as array |
| 308 | 308 | foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
| 309 | 309 | // is current query for an EE CPT ? |
| 310 | - if (isset($this->_CPTs[ $post_type ])) { |
|
| 310 | + if (isset($this->_CPTs[$post_type])) { |
|
| 311 | 311 | // is EE on or off ? |
| 312 | 312 | if (EE_Maintenance_Mode::instance()->level()) { |
| 313 | 313 | // reroute CPT template view to maintenance_mode.template.php |
| 314 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 314 | + if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
| 315 | 315 | add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
| 316 | 316 | } |
| 317 | 317 | if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | 'EventEspresso\core\CPTs\CptQueryModifier', |
| 340 | 340 | array( |
| 341 | 341 | $post_type, |
| 342 | - $this->_CPTs[ $post_type ], |
|
| 342 | + $this->_CPTs[$post_type], |
|
| 343 | 343 | $WP_Query, |
| 344 | 344 | ) |
| 345 | 345 | ); |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | $stages = glob(EE_CORE . 'data_migration_scripts/4_6_0_stages/*'); |
| 15 | 15 | $class_to_filepath = array(); |
| 16 | 16 | foreach ($stages as $filepath) { |
| 17 | - $matches = array(); |
|
| 18 | - preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 19 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 17 | + $matches = array(); |
|
| 18 | + preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
| 19 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
| 20 | 20 | } |
| 21 | 21 | // give addons a chance to autoload their stages too |
| 22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_6_0__autoloaded_stages', $class_to_filepath); |
@@ -35,69 +35,69 @@ discard block |
||
| 35 | 35 | class EE_DMS_Core_4_6_0 extends EE_Data_Migration_Script_Base |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * return EE_DMS_Core_4_6_0 |
|
| 40 | - * |
|
| 41 | - * @param TableManager $table_manager |
|
| 42 | - * @param TableAnalysis $table_analysis |
|
| 43 | - */ |
|
| 44 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 45 | - { |
|
| 46 | - $this->_pretty_name = __("Data Update to Event Espresso 4.6.0", "event_espresso"); |
|
| 47 | - $this->_priority = 10; |
|
| 48 | - $this->_migration_stages = array( |
|
| 49 | - new EE_DMS_4_6_0_gateways(), |
|
| 50 | - new EE_DMS_4_6_0_question_types(), |
|
| 51 | - new EE_DMS_4_6_0_country_system_question(), |
|
| 52 | - new EE_DMS_4_6_0_state_system_question(), |
|
| 53 | - new EE_DMS_4_6_0_billing_info(), |
|
| 54 | - new EE_DMS_4_6_0_transactions(), |
|
| 55 | - new EE_DMS_4_6_0_payments(), |
|
| 56 | - new EE_DMS_4_6_0_invoice_settings(), |
|
| 57 | - ); |
|
| 58 | - parent::__construct($table_manager, $table_analysis); |
|
| 59 | - } |
|
| 38 | + /** |
|
| 39 | + * return EE_DMS_Core_4_6_0 |
|
| 40 | + * |
|
| 41 | + * @param TableManager $table_manager |
|
| 42 | + * @param TableAnalysis $table_analysis |
|
| 43 | + */ |
|
| 44 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 45 | + { |
|
| 46 | + $this->_pretty_name = __("Data Update to Event Espresso 4.6.0", "event_espresso"); |
|
| 47 | + $this->_priority = 10; |
|
| 48 | + $this->_migration_stages = array( |
|
| 49 | + new EE_DMS_4_6_0_gateways(), |
|
| 50 | + new EE_DMS_4_6_0_question_types(), |
|
| 51 | + new EE_DMS_4_6_0_country_system_question(), |
|
| 52 | + new EE_DMS_4_6_0_state_system_question(), |
|
| 53 | + new EE_DMS_4_6_0_billing_info(), |
|
| 54 | + new EE_DMS_4_6_0_transactions(), |
|
| 55 | + new EE_DMS_4_6_0_payments(), |
|
| 56 | + new EE_DMS_4_6_0_invoice_settings(), |
|
| 57 | + ); |
|
| 58 | + parent::__construct($table_manager, $table_analysis); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param array $version_array |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - public function can_migrate_from_version($version_array) |
|
| 68 | - { |
|
| 69 | - $version_string = $version_array['Core']; |
|
| 70 | - if (version_compare($version_string, '4.6.0', '<=') && version_compare($version_string, '4.5.0', '>=')) { |
|
| 63 | + /** |
|
| 64 | + * @param array $version_array |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + public function can_migrate_from_version($version_array) |
|
| 68 | + { |
|
| 69 | + $version_string = $version_array['Core']; |
|
| 70 | + if (version_compare($version_string, '4.6.0', '<=') && version_compare($version_string, '4.5.0', '>=')) { |
|
| 71 | 71 | // echo "$version_string can be migrated from"; |
| 72 | - return true; |
|
| 73 | - } elseif (! $version_string) { |
|
| 72 | + return true; |
|
| 73 | + } elseif (! $version_string) { |
|
| 74 | 74 | // echo "no version string provided: $version_string"; |
| 75 | - // no version string provided... this must be pre 4.3 |
|
| 76 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 77 | - } else { |
|
| 75 | + // no version string provided... this must be pre 4.3 |
|
| 76 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
| 77 | + } else { |
|
| 78 | 78 | // echo "$version_string doesnt apply"; |
| 79 | - return false; |
|
| 80 | - } |
|
| 81 | - } |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - public function schema_changes_before_migration() |
|
| 89 | - { |
|
| 90 | - // relies on 4.1's EEH_Activation::create_table |
|
| 91 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 92 | - $table_name = 'esp_answer'; |
|
| 93 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 85 | + /** |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + public function schema_changes_before_migration() |
|
| 89 | + { |
|
| 90 | + // relies on 4.1's EEH_Activation::create_table |
|
| 91 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
| 92 | + $table_name = 'esp_answer'; |
|
| 93 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 94 | 94 | REG_ID INT UNSIGNED NOT NULL, |
| 95 | 95 | QST_ID INT UNSIGNED NOT NULL, |
| 96 | 96 | ANS_value TEXT NOT NULL, |
| 97 | 97 | PRIMARY KEY (ANS_ID)"; |
| 98 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 99 | - $table_name = 'esp_attendee_meta'; |
|
| 100 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 98 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 99 | + $table_name = 'esp_attendee_meta'; |
|
| 100 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 101 | 101 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 102 | 102 | ATT_fname VARCHAR(45) NOT NULL, |
| 103 | 103 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | KEY ATT_fname (ATT_fname), |
| 114 | 114 | KEY ATT_lname (ATT_lname), |
| 115 | 115 | KEY ATT_email (ATT_email(191))"; |
| 116 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 117 | - $table_name = 'esp_country'; |
|
| 118 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
| 116 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 117 | + $table_name = 'esp_country'; |
|
| 118 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
| 119 | 119 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
| 120 | 120 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
| 121 | 121 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -131,24 +131,24 @@ discard block |
||
| 131 | 131 | CNT_is_EU TINYINT(1) DEFAULT '0', |
| 132 | 132 | CNT_active TINYINT(1) DEFAULT '0', |
| 133 | 133 | PRIMARY KEY (CNT_ISO)"; |
| 134 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 135 | - $table_name = 'esp_currency'; |
|
| 136 | - $sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL, |
|
| 134 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 135 | + $table_name = 'esp_currency'; |
|
| 136 | + $sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL, |
|
| 137 | 137 | CUR_single VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollar', |
| 138 | 138 | CUR_plural VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollars', |
| 139 | 139 | CUR_sign VARCHAR(45) COLLATE utf8_bin DEFAULT '$', |
| 140 | 140 | CUR_dec_plc VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT '2', |
| 141 | 141 | CUR_active TINYINT(1) DEFAULT '0', |
| 142 | 142 | PRIMARY KEY (CUR_code)"; |
| 143 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 144 | - $table_name = 'esp_currency_payment_method'; |
|
| 145 | - $sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 143 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 144 | + $table_name = 'esp_currency_payment_method'; |
|
| 145 | + $sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 146 | 146 | CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL, |
| 147 | 147 | PMD_ID INT(11) NOT NULL, |
| 148 | 148 | PRIMARY KEY (CPM_ID)"; |
| 149 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 150 | - $table_name = 'esp_datetime'; |
|
| 151 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 149 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 150 | + $table_name = 'esp_datetime'; |
|
| 151 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 152 | 152 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 153 | 153 | DTT_name VARCHAR(255) NOT NULL DEFAULT '', |
| 154 | 154 | DTT_description TEXT NOT NULL, |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | PRIMARY KEY (DTT_ID), |
| 164 | 164 | KEY EVT_ID (EVT_ID), |
| 165 | 165 | KEY DTT_is_primary (DTT_is_primary)"; |
| 166 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 167 | - $table_name = 'esp_event_meta'; |
|
| 168 | - $sql = " |
|
| 166 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 167 | + $table_name = 'esp_event_meta'; |
|
| 168 | + $sql = " |
|
| 169 | 169 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
| 170 | 170 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 171 | 171 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -180,31 +180,31 @@ discard block |
||
| 180 | 180 | EVT_external_URL VARCHAR(200) NULL, |
| 181 | 181 | EVT_donations TINYINT(1) NULL, |
| 182 | 182 | PRIMARY KEY (EVTM_ID)"; |
| 183 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 184 | - $table_name = 'esp_event_question_group'; |
|
| 185 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 183 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 184 | + $table_name = 'esp_event_question_group'; |
|
| 185 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 186 | 186 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 187 | 187 | QSG_ID INT UNSIGNED NOT NULL, |
| 188 | 188 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 189 | 189 | PRIMARY KEY (EQG_ID)"; |
| 190 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 191 | - $table_name = 'esp_event_venue'; |
|
| 192 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 190 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 191 | + $table_name = 'esp_event_venue'; |
|
| 192 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 193 | 193 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 194 | 194 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
| 195 | 195 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 196 | 196 | PRIMARY KEY (EVV_ID)"; |
| 197 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | - $table_name = 'esp_extra_meta'; |
|
| 199 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 197 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 198 | + $table_name = 'esp_extra_meta'; |
|
| 199 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 200 | 200 | OBJ_ID INT(11) DEFAULT NULL, |
| 201 | 201 | EXM_type VARCHAR(45) DEFAULT NULL, |
| 202 | 202 | EXM_key VARCHAR(45) DEFAULT NULL, |
| 203 | 203 | EXM_value TEXT, |
| 204 | 204 | PRIMARY KEY (EXM_ID)"; |
| 205 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 206 | - $table_name = 'esp_line_item'; |
|
| 207 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 205 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 206 | + $table_name = 'esp_line_item'; |
|
| 207 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 208 | 208 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
| 209 | 209 | TXN_ID INT(11) DEFAULT NULL, |
| 210 | 210 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | OBJ_ID INT(11) DEFAULT NULL, |
| 221 | 221 | OBJ_type VARCHAR(45)DEFAULT NULL, |
| 222 | 222 | PRIMARY KEY (LIN_ID)"; |
| 223 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 224 | - $table_name = 'esp_log'; |
|
| 225 | - $sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 223 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 224 | + $table_name = 'esp_log'; |
|
| 225 | + $sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 226 | 226 | LOG_time DATETIME DEFAULT NULL, |
| 227 | 227 | OBJ_ID VARCHAR(45) DEFAULT NULL, |
| 228 | 228 | OBJ_type VARCHAR(45) DEFAULT NULL, |
@@ -230,19 +230,19 @@ discard block |
||
| 230 | 230 | LOG_message TEXT, |
| 231 | 231 | LOG_wp_user INT(11) DEFAULT NULL, |
| 232 | 232 | PRIMARY KEY (LOG_ID)"; |
| 233 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 234 | - $table_name = 'esp_message_template'; |
|
| 235 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 233 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 234 | + $table_name = 'esp_message_template'; |
|
| 235 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 236 | 236 | GRP_ID INT(10) UNSIGNED NOT NULL, |
| 237 | 237 | MTP_context VARCHAR(50) NOT NULL, |
| 238 | 238 | MTP_template_field VARCHAR(30) NOT NULL, |
| 239 | 239 | MTP_content TEXT NOT NULL, |
| 240 | 240 | PRIMARY KEY (MTP_ID), |
| 241 | 241 | KEY GRP_ID (GRP_ID)"; |
| 242 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 243 | - $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
| 244 | - $table_name = 'esp_message_template_group'; |
|
| 245 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 242 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 243 | + $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
| 244 | + $table_name = 'esp_message_template_group'; |
|
| 245 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 246 | 246 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
| 247 | 247 | MTP_name VARCHAR(245) NOT NULL DEFAULT '', |
| 248 | 248 | MTP_description VARCHAR(245) NOT NULL DEFAULT '', |
@@ -254,17 +254,17 @@ discard block |
||
| 254 | 254 | MTP_is_active TINYINT(1) NOT NULL DEFAULT '1', |
| 255 | 255 | PRIMARY KEY (GRP_ID), |
| 256 | 256 | KEY MTP_user_id (MTP_user_id)"; |
| 257 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 258 | - $table_name = 'esp_event_message_template'; |
|
| 259 | - $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 257 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 258 | + $table_name = 'esp_event_message_template'; |
|
| 259 | + $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 260 | 260 | EVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
| 261 | 261 | GRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0, |
| 262 | 262 | PRIMARY KEY (EMT_ID), |
| 263 | 263 | KEY EVT_ID (EVT_ID), |
| 264 | 264 | KEY GRP_ID (GRP_ID)"; |
| 265 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 266 | - $table_name = 'esp_payment'; |
|
| 267 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 265 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 266 | + $table_name = 'esp_payment'; |
|
| 267 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 268 | 268 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
| 269 | 269 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
| 270 | 270 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -281,9 +281,9 @@ discard block |
||
| 281 | 281 | PRIMARY KEY (PAY_ID), |
| 282 | 282 | KEY TXN_ID (TXN_ID), |
| 283 | 283 | KEY PAY_timestamp (PAY_timestamp)"; |
| 284 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 285 | - $table_name = 'esp_payment_method'; |
|
| 286 | - $sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 284 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 285 | + $table_name = 'esp_payment_method'; |
|
| 286 | + $sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 287 | 287 | PMD_type VARCHAR(124) DEFAULT NULL, |
| 288 | 288 | PMD_name VARCHAR(255) DEFAULT NULL, |
| 289 | 289 | PMD_desc TEXT, |
@@ -298,28 +298,28 @@ discard block |
||
| 298 | 298 | PMD_scope VARCHAR(255) NULL DEFAULT 'frontend', |
| 299 | 299 | PRIMARY KEY (PMD_ID), |
| 300 | 300 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug)"; |
| 301 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 302 | - $table_name = "esp_ticket_price"; |
|
| 303 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 301 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 302 | + $table_name = "esp_ticket_price"; |
|
| 303 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 304 | 304 | TKT_ID INT(10) UNSIGNED NOT NULL, |
| 305 | 305 | PRC_ID INT(10) UNSIGNED NOT NULL, |
| 306 | 306 | PRIMARY KEY (TKP_ID)"; |
| 307 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 308 | - $table_name = "esp_datetime_ticket"; |
|
| 309 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 307 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 308 | + $table_name = "esp_datetime_ticket"; |
|
| 309 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 310 | 310 | DTT_ID INT(10) UNSIGNED NOT NULL, |
| 311 | 311 | TKT_ID INT(10) UNSIGNED NOT NULL, |
| 312 | 312 | PRIMARY KEY (DTK_ID)"; |
| 313 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 314 | - $table_name = "esp_ticket_template"; |
|
| 315 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 313 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 314 | + $table_name = "esp_ticket_template"; |
|
| 315 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 316 | 316 | TTM_name VARCHAR(45) NOT NULL, |
| 317 | 317 | TTM_description TEXT, |
| 318 | 318 | TTM_file VARCHAR(45), |
| 319 | 319 | PRIMARY KEY (TTM_ID)"; |
| 320 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 321 | - $table_name = 'esp_question'; |
|
| 322 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 320 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 321 | + $table_name = 'esp_question'; |
|
| 322 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 323 | 323 | QST_display_text TEXT NOT NULL, |
| 324 | 324 | QST_admin_label VARCHAR(255) NOT NULL, |
| 325 | 325 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -331,25 +331,25 @@ discard block |
||
| 331 | 331 | QST_wp_user BIGINT UNSIGNED NULL, |
| 332 | 332 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
| 333 | 333 | PRIMARY KEY (QST_ID)'; |
| 334 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 335 | - $table_name = 'esp_question_group_question'; |
|
| 336 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 334 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 335 | + $table_name = 'esp_question_group_question'; |
|
| 336 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 337 | 337 | QSG_ID INT UNSIGNED NOT NULL, |
| 338 | 338 | QST_ID INT UNSIGNED NOT NULL, |
| 339 | 339 | QGQ_order INT UNSIGNED NOT NULL DEFAULT 0, |
| 340 | 340 | PRIMARY KEY (QGQ_ID) "; |
| 341 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | - $table_name = 'esp_question_option'; |
|
| 343 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 341 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 342 | + $table_name = 'esp_question_option'; |
|
| 343 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 344 | 344 | QSO_value VARCHAR(255) NOT NULL, |
| 345 | 345 | QSO_desc TEXT NOT NULL, |
| 346 | 346 | QST_ID INT UNSIGNED NOT NULL, |
| 347 | 347 | QSO_order INT UNSIGNED NOT NULL DEFAULT 0, |
| 348 | 348 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
| 349 | 349 | PRIMARY KEY (QSO_ID)"; |
| 350 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 351 | - $table_name = 'esp_registration'; |
|
| 352 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 350 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 351 | + $table_name = 'esp_registration'; |
|
| 352 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 353 | 353 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 354 | 354 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
| 355 | 355 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -372,25 +372,25 @@ discard block |
||
| 372 | 372 | KEY STS_ID (STS_ID), |
| 373 | 373 | KEY REG_url_link (REG_url_link), |
| 374 | 374 | KEY REG_code (REG_code)"; |
| 375 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 376 | - $table_name = 'esp_checkin'; |
|
| 377 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 375 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 376 | + $table_name = 'esp_checkin'; |
|
| 377 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 378 | 378 | REG_ID INT(10) UNSIGNED NOT NULL, |
| 379 | 379 | DTT_ID INT(10) UNSIGNED NOT NULL, |
| 380 | 380 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
| 381 | 381 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 382 | 382 | PRIMARY KEY (CHK_ID)"; |
| 383 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | - $table_name = 'esp_state'; |
|
| 385 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 383 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 384 | + $table_name = 'esp_state'; |
|
| 385 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 386 | 386 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
| 387 | 387 | STA_abbrev VARCHAR(24) COLLATE utf8_bin NOT NULL, |
| 388 | 388 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
| 389 | 389 | STA_active TINYINT(1) DEFAULT '1', |
| 390 | 390 | PRIMARY KEY (STA_ID)"; |
| 391 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 392 | - $table_name = 'esp_status'; |
|
| 393 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
| 391 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 392 | + $table_name = 'esp_status'; |
|
| 393 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
| 394 | 394 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
| 395 | 395 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
| 396 | 396 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -398,9 +398,9 @@ discard block |
||
| 398 | 398 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
| 399 | 399 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
| 400 | 400 | KEY STS_type (STS_type)"; |
| 401 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 402 | - $table_name = 'esp_transaction'; |
|
| 403 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 401 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 402 | + $table_name = 'esp_transaction'; |
|
| 403 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 404 | 404 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
| 405 | 405 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
| 406 | 406 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -412,9 +412,9 @@ discard block |
||
| 412 | 412 | PRIMARY KEY (TXN_ID), |
| 413 | 413 | KEY TXN_timestamp (TXN_timestamp), |
| 414 | 414 | KEY STS_ID (STS_ID)"; |
| 415 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 416 | - $table_name = 'esp_venue_meta'; |
|
| 417 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 415 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 416 | + $table_name = 'esp_venue_meta'; |
|
| 417 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
| 418 | 418 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
| 419 | 419 | VNU_address VARCHAR(255) DEFAULT NULL, |
| 420 | 420 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -432,10 +432,10 @@ discard block |
||
| 432 | 432 | PRIMARY KEY (VNUM_ID), |
| 433 | 433 | KEY STA_ID (STA_ID), |
| 434 | 434 | KEY CNT_ISO (CNT_ISO)"; |
| 435 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 436 | - // modified tables |
|
| 437 | - $table_name = "esp_price"; |
|
| 438 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 435 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 436 | + // modified tables |
|
| 437 | + $table_name = "esp_price"; |
|
| 438 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 439 | 439 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
| 440 | 440 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
| 441 | 441 | PRC_name VARCHAR(245) NOT NULL, |
@@ -447,9 +447,9 @@ discard block |
||
| 447 | 447 | PRC_wp_user BIGINT UNSIGNED NULL, |
| 448 | 448 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
| 449 | 449 | PRIMARY KEY (PRC_ID)"; |
| 450 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 451 | - $table_name = "esp_price_type"; |
|
| 452 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 450 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 451 | + $table_name = "esp_price_type"; |
|
| 452 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 453 | 453 | PRT_name VARCHAR(45) NOT NULL, |
| 454 | 454 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
| 455 | 455 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -458,9 +458,9 @@ discard block |
||
| 458 | 458 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
| 459 | 459 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
| 460 | 460 | PRIMARY KEY (PRT_ID)"; |
| 461 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 462 | - $table_name = "esp_ticket"; |
|
| 463 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 461 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
| 462 | + $table_name = "esp_ticket"; |
|
| 463 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 464 | 464 | TTM_ID INT(10) UNSIGNED NOT NULL, |
| 465 | 465 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
| 466 | 466 | TKT_description TEXT NOT NULL, |
@@ -481,10 +481,10 @@ discard block |
||
| 481 | 481 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
| 482 | 482 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
| 483 | 483 | PRIMARY KEY (TKT_ID)"; |
| 484 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 485 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 486 | - $table_name = 'esp_question_group'; |
|
| 487 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 484 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 485 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
| 486 | + $table_name = 'esp_question_group'; |
|
| 487 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
| 488 | 488 | QSG_name VARCHAR(255) NOT NULL, |
| 489 | 489 | QSG_identifier VARCHAR(100) NOT NULL, |
| 490 | 490 | QSG_desc TEXT NULL, |
@@ -496,124 +496,124 @@ discard block |
||
| 496 | 496 | QSG_wp_user BIGINT UNSIGNED NULL, |
| 497 | 497 | PRIMARY KEY (QSG_ID), |
| 498 | 498 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
| 499 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 500 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
| 501 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
| 502 | - // (because many need to convert old string states to foreign keys into the states table) |
|
| 503 | - $script_4_1_defaults->insert_default_states(); |
|
| 504 | - $script_4_1_defaults->insert_default_countries(); |
|
| 505 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
| 506 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
| 507 | - $script_4_5_defaults->insert_default_price_types(); |
|
| 508 | - $script_4_5_defaults->insert_default_prices(); |
|
| 509 | - $script_4_5_defaults->insert_default_tickets(); |
|
| 510 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen here |
|
| 511 | - EE_Config::instance()->update_espresso_config(false, true); |
|
| 512 | - $this->add_default_admin_only_payments(); |
|
| 513 | - $this->insert_default_currencies(); |
|
| 514 | - return true; |
|
| 515 | - } |
|
| 499 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
| 500 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
| 501 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
| 502 | + // (because many need to convert old string states to foreign keys into the states table) |
|
| 503 | + $script_4_1_defaults->insert_default_states(); |
|
| 504 | + $script_4_1_defaults->insert_default_countries(); |
|
| 505 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
| 506 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
| 507 | + $script_4_5_defaults->insert_default_price_types(); |
|
| 508 | + $script_4_5_defaults->insert_default_prices(); |
|
| 509 | + $script_4_5_defaults->insert_default_tickets(); |
|
| 510 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen here |
|
| 511 | + EE_Config::instance()->update_espresso_config(false, true); |
|
| 512 | + $this->add_default_admin_only_payments(); |
|
| 513 | + $this->insert_default_currencies(); |
|
| 514 | + return true; |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | 517 | |
| 518 | 518 | |
| 519 | - /** |
|
| 520 | - * @return boolean |
|
| 521 | - */ |
|
| 522 | - public function schema_changes_after_migration() |
|
| 523 | - { |
|
| 524 | - return true; |
|
| 525 | - } |
|
| 519 | + /** |
|
| 520 | + * @return boolean |
|
| 521 | + */ |
|
| 522 | + public function schema_changes_after_migration() |
|
| 523 | + { |
|
| 524 | + return true; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | 527 | |
| 528 | 528 | |
| 529 | - public function migration_page_hooks() |
|
| 530 | - { |
|
| 531 | - } |
|
| 529 | + public function migration_page_hooks() |
|
| 530 | + { |
|
| 531 | + } |
|
| 532 | 532 | |
| 533 | 533 | |
| 534 | 534 | |
| 535 | - public function add_default_admin_only_payments() |
|
| 536 | - { |
|
| 537 | - global $wpdb; |
|
| 538 | - $table_name = $wpdb->prefix . "esp_payment_method"; |
|
| 539 | - $user_id = EEH_Activation::get_default_creator_id(); |
|
| 540 | - if ($this->_get_table_analysis()->tableExists($table_name)) { |
|
| 541 | - $SQL = "SELECT COUNT( * ) FROM $table_name"; |
|
| 542 | - $existing_payment_methods = $wpdb->get_var($SQL); |
|
| 543 | - $default_admin_only_payment_methods = apply_filters( |
|
| 544 | - 'FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods', |
|
| 545 | - array( |
|
| 546 | - (string) __("Bank", 'event_espresso') => __("Bank Draft", 'event_espresso'), |
|
| 547 | - (string) __("Cash", 'event_espresso') => __("Cash Delivered Physically", 'event_espresso'), |
|
| 548 | - (string) __("Check", 'event_espresso') => __("Paper Check", 'event_espresso'), |
|
| 549 | - (string) __("Credit Card", 'event_espresso') => __("Offline Credit Card Payment", 'event_espresso'), |
|
| 550 | - (string) __("Debit Card", 'event_espresso') => __("Offline Debit Payment", 'event_espresso'), |
|
| 551 | - (string) __("Invoice", 'event_espresso') => __( |
|
| 552 | - "Invoice received with monies included", |
|
| 553 | - 'event_espresso' |
|
| 554 | - ), |
|
| 555 | - (string) __("Money Order", 'event_espresso') => '', |
|
| 556 | - (string) __("Paypal", 'event_espresso') => __("Paypal eCheck, Invoice, etc", 'event_espresso'), |
|
| 557 | - (string) __('Other', 'event_espresso') => __('Other method of payment', 'event_espresso'), |
|
| 558 | - ) |
|
| 559 | - ); |
|
| 560 | - // make sure we hae payment method records for the following |
|
| 561 | - // so admins can record payments for them from the admin page |
|
| 562 | - foreach ($default_admin_only_payment_methods as $nicename => $description) { |
|
| 563 | - $slug = sanitize_key($nicename); |
|
| 564 | - // check that such a payment method exists |
|
| 565 | - $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug)); |
|
| 566 | - if (! $exists) { |
|
| 567 | - $values = array( |
|
| 568 | - 'PMD_type' => 'Admin_Only', |
|
| 569 | - 'PMD_name' => $nicename, |
|
| 570 | - 'PMD_admin_name' => $nicename, |
|
| 571 | - 'PMD_admin_desc' => $description, |
|
| 572 | - 'PMD_slug' => $slug, |
|
| 573 | - 'PMD_wp_user' => $user_id, |
|
| 574 | - 'PMD_scope' => serialize(array('ADMIN')), |
|
| 575 | - ); |
|
| 576 | - $success = $wpdb->insert( |
|
| 577 | - $table_name, |
|
| 578 | - $values, |
|
| 579 | - array( |
|
| 580 | - '%s',// PMD_type |
|
| 581 | - '%s',// PMD_name |
|
| 582 | - '%s',// PMD_admin_name |
|
| 583 | - '%s',// PMD_admin_desc |
|
| 584 | - '%s',// PMD_slug |
|
| 585 | - '%d',// PMD_wp_user |
|
| 586 | - '%s',// PMD_scope |
|
| 587 | - ) |
|
| 588 | - ); |
|
| 589 | - if (! $success) { |
|
| 590 | - $this->add_error(sprintf(__( |
|
| 591 | - "Could not insert new admin-only payment method with values %s during migration", |
|
| 592 | - "event_espresso" |
|
| 593 | - ), $this->_json_encode($values))); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - } |
|
| 535 | + public function add_default_admin_only_payments() |
|
| 536 | + { |
|
| 537 | + global $wpdb; |
|
| 538 | + $table_name = $wpdb->prefix . "esp_payment_method"; |
|
| 539 | + $user_id = EEH_Activation::get_default_creator_id(); |
|
| 540 | + if ($this->_get_table_analysis()->tableExists($table_name)) { |
|
| 541 | + $SQL = "SELECT COUNT( * ) FROM $table_name"; |
|
| 542 | + $existing_payment_methods = $wpdb->get_var($SQL); |
|
| 543 | + $default_admin_only_payment_methods = apply_filters( |
|
| 544 | + 'FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods', |
|
| 545 | + array( |
|
| 546 | + (string) __("Bank", 'event_espresso') => __("Bank Draft", 'event_espresso'), |
|
| 547 | + (string) __("Cash", 'event_espresso') => __("Cash Delivered Physically", 'event_espresso'), |
|
| 548 | + (string) __("Check", 'event_espresso') => __("Paper Check", 'event_espresso'), |
|
| 549 | + (string) __("Credit Card", 'event_espresso') => __("Offline Credit Card Payment", 'event_espresso'), |
|
| 550 | + (string) __("Debit Card", 'event_espresso') => __("Offline Debit Payment", 'event_espresso'), |
|
| 551 | + (string) __("Invoice", 'event_espresso') => __( |
|
| 552 | + "Invoice received with monies included", |
|
| 553 | + 'event_espresso' |
|
| 554 | + ), |
|
| 555 | + (string) __("Money Order", 'event_espresso') => '', |
|
| 556 | + (string) __("Paypal", 'event_espresso') => __("Paypal eCheck, Invoice, etc", 'event_espresso'), |
|
| 557 | + (string) __('Other', 'event_espresso') => __('Other method of payment', 'event_espresso'), |
|
| 558 | + ) |
|
| 559 | + ); |
|
| 560 | + // make sure we hae payment method records for the following |
|
| 561 | + // so admins can record payments for them from the admin page |
|
| 562 | + foreach ($default_admin_only_payment_methods as $nicename => $description) { |
|
| 563 | + $slug = sanitize_key($nicename); |
|
| 564 | + // check that such a payment method exists |
|
| 565 | + $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug)); |
|
| 566 | + if (! $exists) { |
|
| 567 | + $values = array( |
|
| 568 | + 'PMD_type' => 'Admin_Only', |
|
| 569 | + 'PMD_name' => $nicename, |
|
| 570 | + 'PMD_admin_name' => $nicename, |
|
| 571 | + 'PMD_admin_desc' => $description, |
|
| 572 | + 'PMD_slug' => $slug, |
|
| 573 | + 'PMD_wp_user' => $user_id, |
|
| 574 | + 'PMD_scope' => serialize(array('ADMIN')), |
|
| 575 | + ); |
|
| 576 | + $success = $wpdb->insert( |
|
| 577 | + $table_name, |
|
| 578 | + $values, |
|
| 579 | + array( |
|
| 580 | + '%s',// PMD_type |
|
| 581 | + '%s',// PMD_name |
|
| 582 | + '%s',// PMD_admin_name |
|
| 583 | + '%s',// PMD_admin_desc |
|
| 584 | + '%s',// PMD_slug |
|
| 585 | + '%d',// PMD_wp_user |
|
| 586 | + '%s',// PMD_scope |
|
| 587 | + ) |
|
| 588 | + ); |
|
| 589 | + if (! $success) { |
|
| 590 | + $this->add_error(sprintf(__( |
|
| 591 | + "Could not insert new admin-only payment method with values %s during migration", |
|
| 592 | + "event_espresso" |
|
| 593 | + ), $this->_json_encode($values))); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | 600 | |
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * insert_default_countries |
|
| 604 | - * |
|
| 605 | - * @static |
|
| 606 | - * @return void |
|
| 607 | - */ |
|
| 608 | - public function insert_default_currencies() |
|
| 609 | - { |
|
| 610 | - global $wpdb; |
|
| 611 | - $currency_table = $wpdb->prefix . "esp_currency"; |
|
| 612 | - if ($this->_get_table_analysis()->tableExists($currency_table)) { |
|
| 613 | - $SQL = "SELECT COUNT('CUR_code') FROM $currency_table"; |
|
| 614 | - $countries = $wpdb->get_var($SQL); |
|
| 615 | - if (! $countries) { |
|
| 616 | - $SQL = "INSERT INTO $currency_table |
|
| 602 | + /** |
|
| 603 | + * insert_default_countries |
|
| 604 | + * |
|
| 605 | + * @static |
|
| 606 | + * @return void |
|
| 607 | + */ |
|
| 608 | + public function insert_default_currencies() |
|
| 609 | + { |
|
| 610 | + global $wpdb; |
|
| 611 | + $currency_table = $wpdb->prefix . "esp_currency"; |
|
| 612 | + if ($this->_get_table_analysis()->tableExists($currency_table)) { |
|
| 613 | + $SQL = "SELECT COUNT('CUR_code') FROM $currency_table"; |
|
| 614 | + $countries = $wpdb->get_var($SQL); |
|
| 615 | + if (! $countries) { |
|
| 616 | + $SQL = "INSERT INTO $currency_table |
|
| 617 | 617 | ( CUR_code, CUR_single, CUR_plural, CUR_sign, CUR_dec_plc, CUR_active) VALUES |
| 618 | 618 | ( 'EUR', 'Euro', 'Euros', '€', 2,1), |
| 619 | 619 | ( 'AED', 'Dirham', 'Dirhams', 'د.إ',2,1), |
@@ -767,8 +767,8 @@ discard block |
||
| 767 | 767 | ( 'ZAR', 'Rand', 'Rands', 'R', 2,1), |
| 768 | 768 | ( 'ZMK', 'Kwacha', 'Kwachas', '', 2,1), |
| 769 | 769 | ( 'ZWD', 'Dollar', 'Dollars', 'Z$', 2,1);"; |
| 770 | - $wpdb->query($SQL); |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - } |
|
| 770 | + $wpdb->query($SQL); |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | 774 | } |
@@ -14,1227 +14,1227 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Holds a collection of EE_Message_Template_Pack objects. |
|
| 19 | - * @type EE_Messages_Template_Pack_Collection |
|
| 20 | - */ |
|
| 21 | - protected static $_template_pack_collection; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - private static function _set_autoloader() |
|
| 27 | - { |
|
| 28 | - EED_Messages::set_autoloaders(); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * generate_new_templates |
|
| 34 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. |
|
| 35 | - * |
|
| 36 | - * @access protected |
|
| 37 | - * @param string $messenger the messenger we are generating templates for |
|
| 38 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 39 | - * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template. |
|
| 40 | - * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation. |
|
| 41 | - * @throws \EE_Error |
|
| 42 | - * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates |
|
| 43 | - * that are generated. If this is an empty array then it means no templates were generated which usually |
|
| 44 | - * means there was an error. Anything in the array with an empty value for `MTP_context` means that it |
|
| 45 | - * was not a new generated template but just reactivated (which only happens for global templates that |
|
| 46 | - * already exist in the database. |
|
| 47 | - */ |
|
| 48 | - public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 49 | - { |
|
| 50 | - // make sure message_type is an array. |
|
| 51 | - $message_types = (array) $message_types; |
|
| 52 | - $templates = array(); |
|
| 53 | - |
|
| 54 | - if (empty($messenger)) { |
|
| 55 | - throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
| 59 | - if (empty($message_types)) { |
|
| 60 | - throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - EEH_MSG_Template::_set_autoloader(); |
|
| 64 | - foreach ($message_types as $message_type) { |
|
| 65 | - // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
| 66 | - if ($global && empty($GRP_ID)) { |
|
| 67 | - $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
| 68 | - array( |
|
| 69 | - array( |
|
| 70 | - 'MTP_messenger' => $messenger, |
|
| 71 | - 'MTP_message_type' => $message_type, |
|
| 72 | - 'MTP_is_global' => true, |
|
| 73 | - ), |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
| 77 | - } |
|
| 78 | - // if this is global template generation. |
|
| 79 | - // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
| 80 | - // If we do then NO generation!! |
|
| 81 | - if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 82 | - $templates[] = array( |
|
| 83 | - 'GRP_ID' => $GRP_ID, |
|
| 84 | - 'MTP_context' => '', |
|
| 85 | - ); |
|
| 86 | - // we already have generated templates for this so let's go to the next message type. |
|
| 87 | - continue; |
|
| 88 | - } |
|
| 89 | - $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 90 | - |
|
| 91 | - if (! $new_message_template_group) { |
|
| 92 | - continue; |
|
| 93 | - } |
|
| 94 | - $templates[] = $new_message_template_group; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $templates; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * The purpose of this method is to determine if there are already generated templates in the database for the given variables. |
|
| 103 | - * @param string $messenger messenger |
|
| 104 | - * @param string $message_type message type |
|
| 105 | - * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global template check) |
|
| 106 | - * @return bool true = generated, false = hasn't been generated. |
|
| 107 | - */ |
|
| 108 | - public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
| 109 | - { |
|
| 110 | - EEH_MSG_Template::_set_autoloader(); |
|
| 111 | - // what method we use depends on whether we have an GRP_ID or not |
|
| 112 | - $count = empty($GRP_ID) |
|
| 113 | - ? EEM_Message_Template::instance()->count( |
|
| 114 | - array( |
|
| 115 | - array( |
|
| 116 | - 'Message_Template_Group.MTP_messenger' => $messenger, |
|
| 117 | - 'Message_Template_Group.MTP_message_type' => $message_type, |
|
| 118 | - 'Message_Template_Group.MTP_is_global' => true |
|
| 119 | - ) |
|
| 120 | - ) |
|
| 121 | - ) |
|
| 122 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 123 | - |
|
| 124 | - return $count > 0; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Updates all message templates matching the incoming messengers and message types to active status. |
|
| 132 | - * |
|
| 133 | - * @static |
|
| 134 | - * @param array $messenger_names Messenger slug |
|
| 135 | - * @param array $message_type_names Message type slug |
|
| 136 | - * @return int count of updated records. |
|
| 137 | - */ |
|
| 138 | - public static function update_to_active($messenger_names, $message_type_names) |
|
| 139 | - { |
|
| 140 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 141 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 142 | - return EEM_Message_Template_Group::instance()->update( |
|
| 143 | - array( 'MTP_is_active' => 1 ), |
|
| 144 | - array( |
|
| 145 | - array( |
|
| 146 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 147 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 148 | - ) |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
| 157 | - * |
|
| 158 | - * @static |
|
| 159 | - * @param array $messenger_names The messenger slugs. |
|
| 160 | - * If empty then all templates matching the message types are marked inactive. |
|
| 161 | - * Otherwise only templates matching the messengers and message types. |
|
| 162 | - * @param array $message_type_names The message type slugs. |
|
| 163 | - * If empty then all templates matching the messengers are marked inactive. |
|
| 164 | - * Otherwise only templates matching the messengers and message types. |
|
| 165 | - * |
|
| 166 | - * @return int count of updated records. |
|
| 167 | - */ |
|
| 168 | - public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
| 169 | - { |
|
| 170 | - return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
| 171 | - $messenger_names, |
|
| 172 | - $message_type_names |
|
| 173 | - ); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * The purpose of this function is to return all installed message objects |
|
| 179 | - * (messengers and message type regardless of whether they are ACTIVE or not) |
|
| 180 | - * |
|
| 181 | - * @deprecated 4.9.0 |
|
| 182 | - * @static |
|
| 183 | - * @param string $type |
|
| 184 | - * @return array array consisting of installed messenger objects and installed message type objects. |
|
| 185 | - */ |
|
| 186 | - public static function get_installed_message_objects($type = 'all') |
|
| 187 | - { |
|
| 188 | - self::_set_autoloader(); |
|
| 189 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 190 | - return array( |
|
| 191 | - 'messenger' => $message_resource_manager->installed_messengers(), |
|
| 192 | - 'message_type' => $message_resource_manager->installed_message_types() |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * This will return an array of shortcodes => labels from the |
|
| 199 | - * messenger and message_type objects associated with this |
|
| 200 | - * template. |
|
| 201 | - * |
|
| 202 | - * @since 4.3.0 |
|
| 203 | - * |
|
| 204 | - * @param string $message_type |
|
| 205 | - * @param string $messenger |
|
| 206 | - * @param array $fields What fields we're returning valid shortcodes for. |
|
| 207 | - * If empty then we assume all fields are to be returned. Optional. |
|
| 208 | - * @param string $context What context we're going to return shortcodes for. Optional. |
|
| 209 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
| 210 | - * but instead an array of the unique shortcodes for all the given ( or all) fields. |
|
| 211 | - * Optional. |
|
| 212 | - * @throws \EE_Error |
|
| 213 | - * @return mixed (array|bool) an array of shortcodes in the format |
|
| 214 | - * array( '[shortcode] => 'label') |
|
| 215 | - * OR |
|
| 216 | - * FALSE if no shortcodes found. |
|
| 217 | - */ |
|
| 218 | - public static function get_shortcodes( |
|
| 219 | - $message_type, |
|
| 220 | - $messenger, |
|
| 221 | - $fields = array(), |
|
| 222 | - $context = 'admin', |
|
| 223 | - $merged = false |
|
| 224 | - ) { |
|
| 225 | - $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 226 | - $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 227 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 228 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 229 | - // convert slug to object |
|
| 230 | - $messenger = $message_resource_manager->get_messenger($messenger); |
|
| 231 | - |
|
| 232 | - // if messenger isn't a EE_messenger resource then bail. |
|
| 233 | - if (! $messenger instanceof EE_messenger) { |
|
| 234 | - return array(); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // validate class for getting our list of shortcodes |
|
| 238 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 239 | - if (! class_exists($classname)) { |
|
| 240 | - $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
| 241 | - $msg[] = sprintf( |
|
| 242 | - __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
| 243 | - $classname |
|
| 244 | - ); |
|
| 245 | - throw new EE_Error(implode('||', $msg)); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** @type EE_Messages_Validator $_VLD */ |
|
| 249 | - $_VLD = new $classname(array(), $context); |
|
| 250 | - $valid_shortcodes = $_VLD->get_validators(); |
|
| 251 | - |
|
| 252 | - // let's make sure we're only getting the shortcode part of the validators |
|
| 253 | - $shortcodes = array(); |
|
| 254 | - foreach ($valid_shortcodes as $field => $validators) { |
|
| 255 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 256 | - } |
|
| 257 | - $valid_shortcodes = $shortcodes; |
|
| 258 | - |
|
| 259 | - // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
| 260 | - if (! empty($fields)) { |
|
| 261 | - $specified_shortcodes = array(); |
|
| 262 | - foreach ($fields as $field) { |
|
| 263 | - if (isset($valid_shortcodes[ $field ])) { |
|
| 264 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - $valid_shortcodes = $specified_shortcodes; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // if not merged then let's replace the fields with the localized fields |
|
| 271 | - if (! $merged) { |
|
| 272 | - // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
| 273 | - $field_settings = $messenger->get_template_fields(); |
|
| 274 | - $localized = array(); |
|
| 275 | - foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 276 | - // get localized field label |
|
| 277 | - if (isset($field_settings[ $field ])) { |
|
| 278 | - // possible that this is used as a main field. |
|
| 279 | - if (empty($field_settings[ $field ])) { |
|
| 280 | - if (isset($field_settings['extra'][ $field ])) { |
|
| 281 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 282 | - } else { |
|
| 283 | - $_field = $field; |
|
| 284 | - } |
|
| 285 | - } else { |
|
| 286 | - $_field = $field_settings[ $field ]['label']; |
|
| 287 | - } |
|
| 288 | - } elseif (isset($field_settings['extra'])) { |
|
| 289 | - // loop through extra "main fields" and see if any of their children have our field |
|
| 290 | - foreach ($field_settings['extra'] as $main_field => $fields) { |
|
| 291 | - if (isset($fields[ $field ])) { |
|
| 292 | - $_field = $fields[ $field ]['label']; |
|
| 293 | - } else { |
|
| 294 | - $_field = $field; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } else { |
|
| 298 | - $_field = $field; |
|
| 299 | - } |
|
| 300 | - if (isset($_field)) { |
|
| 301 | - $localized[ (string) $_field ] = $shortcodes; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - $valid_shortcodes = $localized; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
| 308 | - if ($merged) { |
|
| 309 | - $merged_codes = array(); |
|
| 310 | - foreach ($valid_shortcodes as $field => $shortcode) { |
|
| 311 | - foreach ($shortcode as $code => $label) { |
|
| 312 | - if (isset($merged_codes[ $code ])) { |
|
| 313 | - continue; |
|
| 314 | - } else { |
|
| 315 | - $merged_codes[ $code ] = $label; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - $valid_shortcodes = $merged_codes; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return $valid_shortcodes; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Get Messenger object. |
|
| 328 | - * |
|
| 329 | - * @since 4.3.0 |
|
| 330 | - * @deprecated 4.9.0 |
|
| 331 | - * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
| 332 | - * @throws \EE_Error |
|
| 333 | - * @return EE_messenger |
|
| 334 | - */ |
|
| 335 | - public static function messenger_obj($messenger) |
|
| 336 | - { |
|
| 337 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 338 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 339 | - return $Message_Resource_Manager->get_messenger($messenger); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * get Message type object |
|
| 345 | - * |
|
| 346 | - * @since 4.3.0 |
|
| 347 | - * @deprecated 4.9.0 |
|
| 348 | - * @param string $message_type the slug for the message type object to retrieve |
|
| 349 | - * @throws \EE_Error |
|
| 350 | - * @return EE_message_type |
|
| 351 | - */ |
|
| 352 | - public static function message_type_obj($message_type) |
|
| 353 | - { |
|
| 354 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 355 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 356 | - return $Message_Resource_Manager->get_message_type($message_type); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Given a message_type slug, will return whether that message type is active in the system or not. |
|
| 365 | - * |
|
| 366 | - * @since 4.3.0 |
|
| 367 | - * @param string $message_type message type to check for. |
|
| 368 | - * @return boolean |
|
| 369 | - */ |
|
| 370 | - public static function is_mt_active($message_type) |
|
| 371 | - { |
|
| 372 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 373 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 374 | - $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
| 375 | - return in_array($message_type, $active_mts); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
| 382 | - * |
|
| 383 | - * @since 4.3.0 |
|
| 384 | - * |
|
| 385 | - * @param string $messenger slug for messenger to check. |
|
| 386 | - * @return boolean |
|
| 387 | - */ |
|
| 388 | - public static function is_messenger_active($messenger) |
|
| 389 | - { |
|
| 390 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 391 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 392 | - $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
| 393 | - return $active_messenger instanceof EE_messenger ? true : false; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Used to return active messengers array stored in the wp options table. |
|
| 400 | - * If no value is present in the option then an empty array is returned. |
|
| 401 | - * |
|
| 402 | - * @deprecated 4.9 |
|
| 403 | - * @since 4.3.1 |
|
| 404 | - * |
|
| 405 | - * @return array |
|
| 406 | - */ |
|
| 407 | - public static function get_active_messengers_in_db() |
|
| 408 | - { |
|
| 409 | - EE_Error::doing_it_wrong( |
|
| 410 | - __METHOD__, |
|
| 411 | - __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
| 412 | - '4.9.0' |
|
| 413 | - ); |
|
| 414 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 415 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 416 | - return $Message_Resource_Manager->get_active_messengers_option(); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Used to update the active messengers array stored in the wp options table. |
|
| 424 | - * |
|
| 425 | - * @since 4.3.1 |
|
| 426 | - * @deprecated 4.9.0 |
|
| 427 | - * |
|
| 428 | - * @param array $data_to_save Incoming data to save. |
|
| 429 | - * |
|
| 430 | - * @return bool FALSE if not updated, TRUE if updated. |
|
| 431 | - */ |
|
| 432 | - public static function update_active_messengers_in_db($data_to_save) |
|
| 433 | - { |
|
| 434 | - EE_Error::doing_it_wrong( |
|
| 435 | - __METHOD__, |
|
| 436 | - __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
| 437 | - '4.9.0' |
|
| 438 | - ); |
|
| 439 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 440 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 441 | - return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
| 447 | - * appropriate url trigger |
|
| 448 | - * |
|
| 449 | - * @param EE_message_type $message_type |
|
| 450 | - * @param EE_Message $message |
|
| 451 | - * @param EE_Registration | null $registration The registration object must be included if this |
|
| 452 | - * is going to be a registration trigger url. |
|
| 453 | - * @param string $sending_messenger The (optional) sending messenger for the url. |
|
| 454 | - * |
|
| 455 | - * @return string |
|
| 456 | - * @throws EE_Error |
|
| 457 | - */ |
|
| 458 | - public static function get_url_trigger( |
|
| 459 | - EE_message_type $message_type, |
|
| 460 | - EE_Message $message, |
|
| 461 | - $registration = null, |
|
| 462 | - $sending_messenger = '' |
|
| 463 | - ) { |
|
| 464 | - // first determine if the url can be to the EE_Message object. |
|
| 465 | - if (! $message_type->always_generate()) { |
|
| 466 | - return EEH_MSG_Template::generate_browser_trigger($message); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
| 470 | - if (! $registration instanceof EE_Registration) { |
|
| 471 | - throw new EE_Error( |
|
| 472 | - __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // validate given context |
|
| 477 | - $contexts = $message_type->get_contexts(); |
|
| 478 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 479 | - throw new EE_Error( |
|
| 480 | - sprintf( |
|
| 481 | - __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 482 | - $message->context(), |
|
| 483 | - get_class($message_type) |
|
| 484 | - ) |
|
| 485 | - ); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
| 489 | - if (! empty($sending_messenger)) { |
|
| 490 | - $with_messengers = $message_type->with_messengers(); |
|
| 491 | - if (! isset($with_messengers[ $message->messenger() ]) |
|
| 492 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) ) { |
|
| 493 | - throw new EE_Error( |
|
| 494 | - sprintf( |
|
| 495 | - __( |
|
| 496 | - 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 497 | - 'event_espresso' |
|
| 498 | - ), |
|
| 499 | - $sending_messenger, |
|
| 500 | - get_class($message_type) |
|
| 501 | - ) |
|
| 502 | - ); |
|
| 503 | - } |
|
| 504 | - } else { |
|
| 505 | - $sending_messenger = $message->messenger(); |
|
| 506 | - } |
|
| 507 | - return EEH_MSG_Template::generate_url_trigger( |
|
| 508 | - $sending_messenger, |
|
| 509 | - $message->messenger(), |
|
| 510 | - $message->context(), |
|
| 511 | - $message->message_type(), |
|
| 512 | - $registration, |
|
| 513 | - $message->GRP_ID() |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
| 520 | - * @param EE_Message $message |
|
| 521 | - * @return string. |
|
| 522 | - */ |
|
| 523 | - public static function generate_browser_trigger(EE_Message $message) |
|
| 524 | - { |
|
| 525 | - $query_args = array( |
|
| 526 | - 'ee' => 'msg_browser_trigger', |
|
| 527 | - 'token' => $message->MSG_token() |
|
| 528 | - ); |
|
| 529 | - return apply_filters( |
|
| 530 | - 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
| 531 | - add_query_arg($query_args, site_url()), |
|
| 532 | - $message |
|
| 533 | - ); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
| 543 | - * @param EE_Message $message |
|
| 544 | - * @return string |
|
| 545 | - */ |
|
| 546 | - public static function generate_error_display_trigger(EE_Message $message) |
|
| 547 | - { |
|
| 548 | - return apply_filters( |
|
| 549 | - 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
| 550 | - add_query_arg( |
|
| 551 | - array( |
|
| 552 | - 'ee' => 'msg_browser_error_trigger', |
|
| 553 | - 'token' => $message->MSG_token() |
|
| 554 | - ), |
|
| 555 | - site_url() |
|
| 556 | - ), |
|
| 557 | - $message |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
| 568 | - * |
|
| 569 | - * @param string $sending_messenger The sending messenger slug. |
|
| 570 | - * @param string $generating_messenger The generating messenger slug. |
|
| 571 | - * @param string $context The context for the template. |
|
| 572 | - * @param string $message_type The message type slug |
|
| 573 | - * @param EE_Registration $registration |
|
| 574 | - * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
| 575 | - * @param integer $data_id The id to the EE_Base_Class for getting the data used by the trigger. |
|
| 576 | - * @return string The generated url. |
|
| 577 | - */ |
|
| 578 | - public static function generate_url_trigger( |
|
| 579 | - $sending_messenger, |
|
| 580 | - $generating_messenger, |
|
| 581 | - $context, |
|
| 582 | - $message_type, |
|
| 583 | - EE_Registration $registration, |
|
| 584 | - $message_template_group, |
|
| 585 | - $data_id = 0 |
|
| 586 | - ) { |
|
| 587 | - $query_args = array( |
|
| 588 | - 'ee' => 'msg_url_trigger', |
|
| 589 | - 'snd_msgr' => $sending_messenger, |
|
| 590 | - 'gen_msgr' => $generating_messenger, |
|
| 591 | - 'message_type' => $message_type, |
|
| 592 | - 'context' => $context, |
|
| 593 | - 'token' => $registration->reg_url_link(), |
|
| 594 | - 'GRP_ID' => $message_template_group, |
|
| 595 | - 'id' => $data_id |
|
| 596 | - ); |
|
| 597 | - $url = add_query_arg($query_args, get_home_url()); |
|
| 598 | - |
|
| 599 | - // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
| 600 | - $url = apply_filters( |
|
| 601 | - 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
| 602 | - $url, |
|
| 603 | - $sending_messenger, |
|
| 604 | - $generating_messenger, |
|
| 605 | - $context, |
|
| 606 | - $message_type, |
|
| 607 | - $registration, |
|
| 608 | - $message_template_group, |
|
| 609 | - $data_id |
|
| 610 | - ); |
|
| 611 | - return $url; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Return the specific css for the action icon given. |
|
| 619 | - * |
|
| 620 | - * @since 4.9.0 |
|
| 621 | - * |
|
| 622 | - * @param string $type What action to return. |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public static function get_message_action_icon($type) |
|
| 626 | - { |
|
| 627 | - $action_icons = self::get_message_action_icons(); |
|
| 628 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : ''; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * This is used for retrieving the css classes used for the icons representing message actions. |
|
| 634 | - * |
|
| 635 | - * @since 4.9.0 |
|
| 636 | - * |
|
| 637 | - * @return array |
|
| 638 | - */ |
|
| 639 | - public static function get_message_action_icons() |
|
| 640 | - { |
|
| 641 | - return apply_filters( |
|
| 642 | - 'FHEE__EEH_MSG_Template__message_action_icons', |
|
| 643 | - array( |
|
| 644 | - 'view' => array( |
|
| 645 | - 'label' => __('View Message', 'event_espresso'), |
|
| 646 | - 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
| 647 | - ), |
|
| 648 | - 'error' => array( |
|
| 649 | - 'label' => __('View Error Message', 'event_espresso'), |
|
| 650 | - 'css_class' => 'dashicons dashicons-info', |
|
| 651 | - ), |
|
| 652 | - 'see_notifications_for' => array( |
|
| 653 | - 'label' => __('View Related Messages', 'event_espresso'), |
|
| 654 | - 'css_class' => 'dashicons dashicons-megaphone', |
|
| 655 | - ), |
|
| 656 | - 'generate_now' => array( |
|
| 657 | - 'label' => __('Generate the message now.', 'event_espresso'), |
|
| 658 | - 'css_class' => 'dashicons dashicons-admin-tools', |
|
| 659 | - ), |
|
| 660 | - 'send_now' => array( |
|
| 661 | - 'label' => __('Send Immediately', 'event_espresso'), |
|
| 662 | - 'css_class' => 'dashicons dashicons-controls-forward', |
|
| 663 | - ), |
|
| 664 | - 'queue_for_resending' => array( |
|
| 665 | - 'label' => __('Queue for Resending', 'event_espresso'), |
|
| 666 | - 'css_class' => 'dashicons dashicons-controls-repeat', |
|
| 667 | - ), |
|
| 668 | - 'view_transaction' => array( |
|
| 669 | - 'label' => __('View related Transaction', 'event_espresso'), |
|
| 670 | - 'css_class' => 'dashicons dashicons-cart', |
|
| 671 | - ) |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - /** |
|
| 678 | - * This returns the url for a given action related to EE_Message. |
|
| 679 | - * |
|
| 680 | - * @since 4.9.0 |
|
| 681 | - * |
|
| 682 | - * @param string $type What type of action to return the url for. |
|
| 683 | - * @param EE_Message $message Required for generating the correct url for some types. |
|
| 684 | - * @param array $query_params Any additional query params to be included with the generated url. |
|
| 685 | - * |
|
| 686 | - * @return string |
|
| 687 | - */ |
|
| 688 | - public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
| 689 | - { |
|
| 690 | - $action_urls = self::get_message_action_urls($message, $query_params); |
|
| 691 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * This returns all the current urls for EE_Message actions. |
|
| 698 | - * |
|
| 699 | - * @since 4.9.0 |
|
| 700 | - * |
|
| 701 | - * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
| 702 | - * @param array $query_params Any additional query_params to be included with the generated url. |
|
| 703 | - * |
|
| 704 | - * @return array |
|
| 705 | - */ |
|
| 706 | - public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
| 707 | - { |
|
| 708 | - EE_Registry::instance()->load_helper('URL'); |
|
| 709 | - // if $message is not an instance of EE_Message then let's just do a dummy. |
|
| 710 | - $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
| 711 | - $action_urls = apply_filters( |
|
| 712 | - 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
| 713 | - array( |
|
| 714 | - 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
| 715 | - 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
| 716 | - 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
| 717 | - array_merge( |
|
| 718 | - array( |
|
| 719 | - 'page' => 'espresso_messages', |
|
| 720 | - 'action' => 'default', |
|
| 721 | - 'filterby' => 1, |
|
| 722 | - ), |
|
| 723 | - $query_params |
|
| 724 | - ), |
|
| 725 | - admin_url('admin.php') |
|
| 726 | - ), |
|
| 727 | - 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
| 728 | - array( |
|
| 729 | - 'page' => 'espresso_messages', |
|
| 730 | - 'action' => 'generate_now', |
|
| 731 | - 'MSG_ID' => $message->ID() |
|
| 732 | - ), |
|
| 733 | - admin_url('admin.php') |
|
| 734 | - ), |
|
| 735 | - 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
| 736 | - array( |
|
| 737 | - 'page' => 'espresso_messages', |
|
| 738 | - 'action' => 'send_now', |
|
| 739 | - 'MSG_ID' => $message->ID() |
|
| 740 | - ), |
|
| 741 | - admin_url('admin.php') |
|
| 742 | - ), |
|
| 743 | - 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
| 744 | - array( |
|
| 745 | - 'page' => 'espresso_messages', |
|
| 746 | - 'action' => 'queue_for_resending', |
|
| 747 | - 'MSG_ID' => $message->ID() |
|
| 748 | - ), |
|
| 749 | - admin_url('admin.php') |
|
| 750 | - ), |
|
| 751 | - ) |
|
| 752 | - ); |
|
| 753 | - if ($message->TXN_ID() > 0 |
|
| 754 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 755 | - 'ee_read_transaction', |
|
| 756 | - 'espresso_transactions_default', |
|
| 757 | - $message->TXN_ID() |
|
| 758 | - ) |
|
| 759 | - ) { |
|
| 760 | - $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
| 761 | - array( |
|
| 762 | - 'page' => 'espresso_transactions', |
|
| 763 | - 'action' => 'view_transaction', |
|
| 764 | - 'TXN_ID' => $message->TXN_ID() |
|
| 765 | - ), |
|
| 766 | - admin_url('admin.php') |
|
| 767 | - ); |
|
| 768 | - } else { |
|
| 769 | - $action_urls['view_transaction'] = ''; |
|
| 770 | - } |
|
| 771 | - return $action_urls; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
| 777 | - * |
|
| 778 | - * @since 4.9.0 |
|
| 779 | - * |
|
| 780 | - * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
| 781 | - * empty string is returned) |
|
| 782 | - * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
| 783 | - * @param array $query_params Any extra query params to include in the generated link. |
|
| 784 | - * |
|
| 785 | - * @return string |
|
| 786 | - */ |
|
| 787 | - public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
| 788 | - { |
|
| 789 | - $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
| 790 | - $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
| 791 | - $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
| 792 | - |
|
| 793 | - if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
| 794 | - return ''; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - $icon_css['css_class'] .= esc_attr( |
|
| 798 | - apply_filters( |
|
| 799 | - 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
| 800 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 801 | - $type, |
|
| 802 | - $message, |
|
| 803 | - $query_params |
|
| 804 | - ) |
|
| 805 | - ); |
|
| 806 | - |
|
| 807 | - return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>'; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
| 816 | - * |
|
| 817 | - * @since 4.9.0 |
|
| 818 | - * @return array |
|
| 819 | - */ |
|
| 820 | - public static function reg_status_to_message_type_array() |
|
| 821 | - { |
|
| 822 | - return (array) apply_filters( |
|
| 823 | - 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
| 824 | - array( |
|
| 825 | - EEM_Registration::status_id_approved => 'registration', |
|
| 826 | - EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
| 827 | - EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
| 828 | - EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
| 829 | - EEM_Registration::status_id_declined => 'declined_registration' |
|
| 830 | - ) |
|
| 831 | - ); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
| 839 | - * match, then returns an empty string. |
|
| 840 | - * |
|
| 841 | - * @since 4.9.0 |
|
| 842 | - * @param $reg_status |
|
| 843 | - * @return string |
|
| 844 | - */ |
|
| 845 | - public static function convert_reg_status_to_message_type($reg_status) |
|
| 846 | - { |
|
| 847 | - $reg_status_array = self::reg_status_to_message_type_array(); |
|
| 848 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
| 854 | - * |
|
| 855 | - * @since 4.9.0 |
|
| 856 | - * @return array |
|
| 857 | - */ |
|
| 858 | - public static function payment_status_to_message_type_array() |
|
| 859 | - { |
|
| 860 | - return (array) apply_filters( |
|
| 861 | - 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
| 862 | - array( |
|
| 863 | - EEM_Payment::status_id_approved => 'payment', |
|
| 864 | - EEM_Payment::status_id_pending => 'payment_pending', |
|
| 865 | - EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
| 866 | - EEM_Payment::status_id_declined => 'payment_declined', |
|
| 867 | - EEM_Payment::status_id_failed => 'payment_failed' |
|
| 868 | - ) |
|
| 869 | - ); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
| 877 | - * an empty string is returned |
|
| 878 | - * |
|
| 879 | - * @since 4.9.0 |
|
| 880 | - * @param $payment_status |
|
| 881 | - * @return string |
|
| 882 | - */ |
|
| 883 | - public static function convert_payment_status_to_message_type($payment_status) |
|
| 884 | - { |
|
| 885 | - $payment_status_array = self::payment_status_to_message_type_array(); |
|
| 886 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * This is used to retrieve the template pack for the given name. |
|
| 892 | - * |
|
| 893 | - * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
| 894 | - * |
|
| 895 | - * @return EE_Messages_Template_Pack |
|
| 896 | - */ |
|
| 897 | - public static function get_template_pack($template_pack_name) |
|
| 898 | - { |
|
| 899 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 900 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - // first see if in collection already |
|
| 904 | - $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
| 905 | - |
|
| 906 | - if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
| 907 | - return $template_pack; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - // nope...let's get it. |
|
| 911 | - // not set yet so let's attempt to get it. |
|
| 912 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 913 | - ' ', |
|
| 914 | - '_', |
|
| 915 | - ucwords( |
|
| 916 | - str_replace('_', ' ', $template_pack_name) |
|
| 917 | - ) |
|
| 918 | - ); |
|
| 919 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 920 | - return self::get_template_pack('default'); |
|
| 921 | - } else { |
|
| 922 | - $template_pack = new $pack_class_name; |
|
| 923 | - self::$_template_pack_collection->add($template_pack); |
|
| 924 | - return $template_pack; |
|
| 925 | - } |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
| 933 | - * in it. |
|
| 934 | - * |
|
| 935 | - * @since 4.9.0 |
|
| 936 | - * |
|
| 937 | - * @return EE_Messages_Template_Pack_Collection |
|
| 938 | - */ |
|
| 939 | - public static function get_template_pack_collection() |
|
| 940 | - { |
|
| 941 | - $new_collection = false; |
|
| 942 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 943 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 944 | - $new_collection = true; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - // glob the defaults directory for messages |
|
| 948 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 949 | - foreach ($templates as $template_path) { |
|
| 950 | - // grab folder name |
|
| 951 | - $template = basename($template_path); |
|
| 952 | - |
|
| 953 | - if (! $new_collection) { |
|
| 954 | - // already have it? |
|
| 955 | - if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
| 956 | - continue; |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - // setup classname. |
|
| 961 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 962 | - ' ', |
|
| 963 | - '_', |
|
| 964 | - ucwords( |
|
| 965 | - str_replace( |
|
| 966 | - '_', |
|
| 967 | - ' ', |
|
| 968 | - $template |
|
| 969 | - ) |
|
| 970 | - ) |
|
| 971 | - ); |
|
| 972 | - if (! class_exists($template_pack_class_name)) { |
|
| 973 | - continue; |
|
| 974 | - } |
|
| 975 | - self::$_template_pack_collection->add(new $template_pack_class_name); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * Filter for plugins to add in any additional template packs |
|
| 980 | - * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
| 981 | - */ |
|
| 982 | - $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
| 983 | - foreach ((array) $additional_template_packs as $template_pack) { |
|
| 984 | - if (! self::$_template_pack_collection->contains($template_pack)) { |
|
| 985 | - self::$_template_pack_collection->add($template_pack); |
|
| 986 | - } |
|
| 987 | - } |
|
| 988 | - return self::$_template_pack_collection; |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * This is a wrapper for the protected _create_new_templates function |
|
| 995 | - * |
|
| 996 | - * @param string $messenger_name |
|
| 997 | - * @param string $message_type_name message type that the templates are being created for |
|
| 998 | - * @param int $GRP_ID |
|
| 999 | - * @param bool $global |
|
| 1000 | - * @return array |
|
| 1001 | - * @throws \EE_Error |
|
| 1002 | - */ |
|
| 1003 | - public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
| 1004 | - { |
|
| 1005 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1006 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1007 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1008 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1009 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1010 | - return array(); |
|
| 1011 | - } |
|
| 1012 | - // whew made it this far! Okay, let's go ahead and create the templates then |
|
| 1013 | - return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * @param \EE_messenger $messenger |
|
| 1020 | - * @param \EE_message_type $message_type |
|
| 1021 | - * @param $GRP_ID |
|
| 1022 | - * @param $global |
|
| 1023 | - * @return array|mixed |
|
| 1024 | - */ |
|
| 1025 | - protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
| 1026 | - { |
|
| 1027 | - // if we're creating a custom template then we don't need to use the defaults class |
|
| 1028 | - if (! $global) { |
|
| 1029 | - return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
| 1030 | - } |
|
| 1031 | - /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
| 1032 | - $Message_Template_Defaults = EE_Registry::factory( |
|
| 1033 | - 'EE_Messages_Template_Defaults', |
|
| 1034 | - array( $messenger, $message_type, $GRP_ID ) |
|
| 1035 | - ); |
|
| 1036 | - // generate templates |
|
| 1037 | - $success = $Message_Template_Defaults->create_new_templates(); |
|
| 1038 | - |
|
| 1039 | - // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
| 1040 | - // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
| 1041 | - // attempts. |
|
| 1042 | - if (! $success) { |
|
| 1043 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1044 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1045 | - $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - /** |
|
| 1049 | - * $success is in an array in the following format |
|
| 1050 | - * array( |
|
| 1051 | - * 'GRP_ID' => $new_grp_id, |
|
| 1052 | - * 'MTP_context' => $first_context_in_new_templates, |
|
| 1053 | - * ) |
|
| 1054 | - */ |
|
| 1055 | - return $success; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * This creates a custom template using the incoming GRP_ID |
|
| 1062 | - * |
|
| 1063 | - * @param \EE_messenger $messenger |
|
| 1064 | - * @param \EE_message_type $message_type |
|
| 1065 | - * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
| 1066 | - * @return array $success This will be an array in the format: |
|
| 1067 | - * array( |
|
| 1068 | - * 'GRP_ID' => $new_grp_id, |
|
| 1069 | - * 'MTP_context' => $first_context_in_created_template |
|
| 1070 | - * ) |
|
| 1071 | - * @access private |
|
| 1072 | - */ |
|
| 1073 | - private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
| 1074 | - { |
|
| 1075 | - // defaults |
|
| 1076 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1077 | - // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
| 1078 | - $Message_Template_Group = empty($GRP_ID) |
|
| 1079 | - ? EEM_Message_Template_Group::instance()->get_one( |
|
| 1080 | - array( |
|
| 1081 | - array( |
|
| 1082 | - 'MTP_messenger' => $messenger->name, |
|
| 1083 | - 'MTP_message_type' => $message_type->name, |
|
| 1084 | - 'MTP_is_global' => true |
|
| 1085 | - ) |
|
| 1086 | - ) |
|
| 1087 | - ) |
|
| 1088 | - : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1089 | - // if we don't have a mtg at this point then we need to bail. |
|
| 1090 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1091 | - EE_Error::add_error( |
|
| 1092 | - sprintf( |
|
| 1093 | - __( |
|
| 1094 | - 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
| 1095 | - 'event_espresso' |
|
| 1096 | - ), |
|
| 1097 | - $GRP_ID |
|
| 1098 | - ), |
|
| 1099 | - __FILE__, |
|
| 1100 | - __FUNCTION__, |
|
| 1101 | - __LINE__ |
|
| 1102 | - ); |
|
| 1103 | - return $success; |
|
| 1104 | - } |
|
| 1105 | - // let's get all the related message_template objects for this group. |
|
| 1106 | - $message_templates = $Message_Template_Group->message_templates(); |
|
| 1107 | - // now we have what we need to setup the new template |
|
| 1108 | - $new_mtg = clone $Message_Template_Group; |
|
| 1109 | - $new_mtg->set('GRP_ID', 0); |
|
| 1110 | - $new_mtg->set('MTP_is_global', false); |
|
| 1111 | - $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName']) |
|
| 1112 | - ? $_POST['templateName'] |
|
| 1113 | - : __( |
|
| 1114 | - 'New Custom Template', |
|
| 1115 | - 'event_espresso' |
|
| 1116 | - ); |
|
| 1117 | - $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription']) |
|
| 1118 | - ? $_POST['templateDescription'] |
|
| 1119 | - : sprintf( |
|
| 1120 | - __( |
|
| 1121 | - 'This is a custom template that was created for the %s messenger and %s message type.', |
|
| 1122 | - 'event_espresso' |
|
| 1123 | - ), |
|
| 1124 | - $new_mtg->messenger_obj()->label['singular'], |
|
| 1125 | - $new_mtg->message_type_obj()->label['singular'] |
|
| 1126 | - ); |
|
| 1127 | - $new_mtg->set('MTP_name', $template_name); |
|
| 1128 | - $new_mtg->set('MTP_description', $template_description); |
|
| 1129 | - // remove ALL relations on this template group so they don't get saved! |
|
| 1130 | - $new_mtg->_remove_relations('Message_Template'); |
|
| 1131 | - $new_mtg->save(); |
|
| 1132 | - $success['GRP_ID'] = $new_mtg->ID(); |
|
| 1133 | - $success['template_name'] = $template_name; |
|
| 1134 | - // add new message templates and add relation to. |
|
| 1135 | - foreach ($message_templates as $message_template) { |
|
| 1136 | - if (! $message_template instanceof EE_Message_Template) { |
|
| 1137 | - continue; |
|
| 1138 | - } |
|
| 1139 | - $new_message_template = clone $message_template; |
|
| 1140 | - $new_message_template->set('MTP_ID', 0); |
|
| 1141 | - $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
| 1142 | - $new_message_template->save(); |
|
| 1143 | - if (empty($success['MTP_context'])) { |
|
| 1144 | - $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - return $success; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * message_type_has_active_templates_for_messenger |
|
| 1154 | - * |
|
| 1155 | - * @param \EE_messenger $messenger |
|
| 1156 | - * @param \EE_message_type $message_type |
|
| 1157 | - * @param bool $global |
|
| 1158 | - * @return bool |
|
| 1159 | - */ |
|
| 1160 | - public static function message_type_has_active_templates_for_messenger( |
|
| 1161 | - EE_messenger $messenger, |
|
| 1162 | - EE_message_type $message_type, |
|
| 1163 | - $global = false |
|
| 1164 | - ) { |
|
| 1165 | - // is given message_type valid for given messenger (if this is not a global save) |
|
| 1166 | - if ($global) { |
|
| 1167 | - return true; |
|
| 1168 | - } |
|
| 1169 | - $active_templates = EEM_Message_Template_Group::instance()->count( |
|
| 1170 | - array( |
|
| 1171 | - array( |
|
| 1172 | - 'MTP_is_active' => true, |
|
| 1173 | - 'MTP_messenger' => $messenger->name, |
|
| 1174 | - 'MTP_message_type' => $message_type->name |
|
| 1175 | - ) |
|
| 1176 | - ) |
|
| 1177 | - ); |
|
| 1178 | - if ($active_templates > 0) { |
|
| 1179 | - return true; |
|
| 1180 | - } |
|
| 1181 | - EE_Error::add_error( |
|
| 1182 | - sprintf( |
|
| 1183 | - __( |
|
| 1184 | - 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
| 1185 | - 'event_espresso' |
|
| 1186 | - ), |
|
| 1187 | - $message_type->name, |
|
| 1188 | - $messenger->name |
|
| 1189 | - ), |
|
| 1190 | - __FILE__, |
|
| 1191 | - __FUNCTION__, |
|
| 1192 | - __LINE__ |
|
| 1193 | - ); |
|
| 1194 | - return false; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - |
|
| 1198 | - |
|
| 1199 | - /** |
|
| 1200 | - * get_fields |
|
| 1201 | - * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
| 1202 | - * |
|
| 1203 | - * @param string $messenger_name name of EE_messenger |
|
| 1204 | - * @param string $message_type_name name of EE_message_type |
|
| 1205 | - * @return array |
|
| 1206 | - */ |
|
| 1207 | - public static function get_fields($messenger_name, $message_type_name) |
|
| 1208 | - { |
|
| 1209 | - $template_fields = array(); |
|
| 1210 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1211 | - $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1212 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1213 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1214 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1215 | - return array(); |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
| 1219 | - |
|
| 1220 | - // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
| 1221 | - foreach ($message_type->get_contexts() as $context => $details) { |
|
| 1222 | - foreach ($messenger->get_template_fields() as $field => $value) { |
|
| 1223 | - if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
| 1224 | - continue; |
|
| 1225 | - } |
|
| 1226 | - $template_fields[ $context ][ $field ] = $value; |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 1229 | - if (empty($template_fields)) { |
|
| 1230 | - EE_Error::add_error( |
|
| 1231 | - __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
| 1232 | - __FILE__, |
|
| 1233 | - __FUNCTION__, |
|
| 1234 | - __LINE__ |
|
| 1235 | - ); |
|
| 1236 | - return array(); |
|
| 1237 | - } |
|
| 1238 | - return $template_fields; |
|
| 1239 | - } |
|
| 17 | + /** |
|
| 18 | + * Holds a collection of EE_Message_Template_Pack objects. |
|
| 19 | + * @type EE_Messages_Template_Pack_Collection |
|
| 20 | + */ |
|
| 21 | + protected static $_template_pack_collection; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + private static function _set_autoloader() |
|
| 27 | + { |
|
| 28 | + EED_Messages::set_autoloaders(); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * generate_new_templates |
|
| 34 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will automatically create the defaults for the event. The user would then be redirected to edit the default context for the event. |
|
| 35 | + * |
|
| 36 | + * @access protected |
|
| 37 | + * @param string $messenger the messenger we are generating templates for |
|
| 38 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 39 | + * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID to use as the base for the new generated template. |
|
| 40 | + * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID for event specific template generation. |
|
| 41 | + * @throws \EE_Error |
|
| 42 | + * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array for templates |
|
| 43 | + * that are generated. If this is an empty array then it means no templates were generated which usually |
|
| 44 | + * means there was an error. Anything in the array with an empty value for `MTP_context` means that it |
|
| 45 | + * was not a new generated template but just reactivated (which only happens for global templates that |
|
| 46 | + * already exist in the database. |
|
| 47 | + */ |
|
| 48 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 49 | + { |
|
| 50 | + // make sure message_type is an array. |
|
| 51 | + $message_types = (array) $message_types; |
|
| 52 | + $templates = array(); |
|
| 53 | + |
|
| 54 | + if (empty($messenger)) { |
|
| 55 | + throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
|
| 59 | + if (empty($message_types)) { |
|
| 60 | + throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + EEH_MSG_Template::_set_autoloader(); |
|
| 64 | + foreach ($message_types as $message_type) { |
|
| 65 | + // if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
|
| 66 | + if ($global && empty($GRP_ID)) { |
|
| 67 | + $GRP_ID = EEM_Message_Template_Group::instance()->get_one( |
|
| 68 | + array( |
|
| 69 | + array( |
|
| 70 | + 'MTP_messenger' => $messenger, |
|
| 71 | + 'MTP_message_type' => $message_type, |
|
| 72 | + 'MTP_is_global' => true, |
|
| 73 | + ), |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
|
| 77 | + } |
|
| 78 | + // if this is global template generation. |
|
| 79 | + // First let's determine if we already HAVE global templates for this messenger and message_type combination. |
|
| 80 | + // If we do then NO generation!! |
|
| 81 | + if ($global && EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 82 | + $templates[] = array( |
|
| 83 | + 'GRP_ID' => $GRP_ID, |
|
| 84 | + 'MTP_context' => '', |
|
| 85 | + ); |
|
| 86 | + // we already have generated templates for this so let's go to the next message type. |
|
| 87 | + continue; |
|
| 88 | + } |
|
| 89 | + $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 90 | + |
|
| 91 | + if (! $new_message_template_group) { |
|
| 92 | + continue; |
|
| 93 | + } |
|
| 94 | + $templates[] = $new_message_template_group; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $templates; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * The purpose of this method is to determine if there are already generated templates in the database for the given variables. |
|
| 103 | + * @param string $messenger messenger |
|
| 104 | + * @param string $message_type message type |
|
| 105 | + * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global template check) |
|
| 106 | + * @return bool true = generated, false = hasn't been generated. |
|
| 107 | + */ |
|
| 108 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0) |
|
| 109 | + { |
|
| 110 | + EEH_MSG_Template::_set_autoloader(); |
|
| 111 | + // what method we use depends on whether we have an GRP_ID or not |
|
| 112 | + $count = empty($GRP_ID) |
|
| 113 | + ? EEM_Message_Template::instance()->count( |
|
| 114 | + array( |
|
| 115 | + array( |
|
| 116 | + 'Message_Template_Group.MTP_messenger' => $messenger, |
|
| 117 | + 'Message_Template_Group.MTP_message_type' => $message_type, |
|
| 118 | + 'Message_Template_Group.MTP_is_global' => true |
|
| 119 | + ) |
|
| 120 | + ) |
|
| 121 | + ) |
|
| 122 | + : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 123 | + |
|
| 124 | + return $count > 0; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Updates all message templates matching the incoming messengers and message types to active status. |
|
| 132 | + * |
|
| 133 | + * @static |
|
| 134 | + * @param array $messenger_names Messenger slug |
|
| 135 | + * @param array $message_type_names Message type slug |
|
| 136 | + * @return int count of updated records. |
|
| 137 | + */ |
|
| 138 | + public static function update_to_active($messenger_names, $message_type_names) |
|
| 139 | + { |
|
| 140 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 141 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 142 | + return EEM_Message_Template_Group::instance()->update( |
|
| 143 | + array( 'MTP_is_active' => 1 ), |
|
| 144 | + array( |
|
| 145 | + array( |
|
| 146 | + 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 147 | + 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 148 | + ) |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
| 157 | + * |
|
| 158 | + * @static |
|
| 159 | + * @param array $messenger_names The messenger slugs. |
|
| 160 | + * If empty then all templates matching the message types are marked inactive. |
|
| 161 | + * Otherwise only templates matching the messengers and message types. |
|
| 162 | + * @param array $message_type_names The message type slugs. |
|
| 163 | + * If empty then all templates matching the messengers are marked inactive. |
|
| 164 | + * Otherwise only templates matching the messengers and message types. |
|
| 165 | + * |
|
| 166 | + * @return int count of updated records. |
|
| 167 | + */ |
|
| 168 | + public static function update_to_inactive($messenger_names = array(), $message_type_names = array()) |
|
| 169 | + { |
|
| 170 | + return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for( |
|
| 171 | + $messenger_names, |
|
| 172 | + $message_type_names |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * The purpose of this function is to return all installed message objects |
|
| 179 | + * (messengers and message type regardless of whether they are ACTIVE or not) |
|
| 180 | + * |
|
| 181 | + * @deprecated 4.9.0 |
|
| 182 | + * @static |
|
| 183 | + * @param string $type |
|
| 184 | + * @return array array consisting of installed messenger objects and installed message type objects. |
|
| 185 | + */ |
|
| 186 | + public static function get_installed_message_objects($type = 'all') |
|
| 187 | + { |
|
| 188 | + self::_set_autoloader(); |
|
| 189 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 190 | + return array( |
|
| 191 | + 'messenger' => $message_resource_manager->installed_messengers(), |
|
| 192 | + 'message_type' => $message_resource_manager->installed_message_types() |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * This will return an array of shortcodes => labels from the |
|
| 199 | + * messenger and message_type objects associated with this |
|
| 200 | + * template. |
|
| 201 | + * |
|
| 202 | + * @since 4.3.0 |
|
| 203 | + * |
|
| 204 | + * @param string $message_type |
|
| 205 | + * @param string $messenger |
|
| 206 | + * @param array $fields What fields we're returning valid shortcodes for. |
|
| 207 | + * If empty then we assume all fields are to be returned. Optional. |
|
| 208 | + * @param string $context What context we're going to return shortcodes for. Optional. |
|
| 209 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field, |
|
| 210 | + * but instead an array of the unique shortcodes for all the given ( or all) fields. |
|
| 211 | + * Optional. |
|
| 212 | + * @throws \EE_Error |
|
| 213 | + * @return mixed (array|bool) an array of shortcodes in the format |
|
| 214 | + * array( '[shortcode] => 'label') |
|
| 215 | + * OR |
|
| 216 | + * FALSE if no shortcodes found. |
|
| 217 | + */ |
|
| 218 | + public static function get_shortcodes( |
|
| 219 | + $message_type, |
|
| 220 | + $messenger, |
|
| 221 | + $fields = array(), |
|
| 222 | + $context = 'admin', |
|
| 223 | + $merged = false |
|
| 224 | + ) { |
|
| 225 | + $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 226 | + $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 227 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 228 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 229 | + // convert slug to object |
|
| 230 | + $messenger = $message_resource_manager->get_messenger($messenger); |
|
| 231 | + |
|
| 232 | + // if messenger isn't a EE_messenger resource then bail. |
|
| 233 | + if (! $messenger instanceof EE_messenger) { |
|
| 234 | + return array(); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // validate class for getting our list of shortcodes |
|
| 238 | + $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 239 | + if (! class_exists($classname)) { |
|
| 240 | + $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
| 241 | + $msg[] = sprintf( |
|
| 242 | + __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
|
| 243 | + $classname |
|
| 244 | + ); |
|
| 245 | + throw new EE_Error(implode('||', $msg)); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** @type EE_Messages_Validator $_VLD */ |
|
| 249 | + $_VLD = new $classname(array(), $context); |
|
| 250 | + $valid_shortcodes = $_VLD->get_validators(); |
|
| 251 | + |
|
| 252 | + // let's make sure we're only getting the shortcode part of the validators |
|
| 253 | + $shortcodes = array(); |
|
| 254 | + foreach ($valid_shortcodes as $field => $validators) { |
|
| 255 | + $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 256 | + } |
|
| 257 | + $valid_shortcodes = $shortcodes; |
|
| 258 | + |
|
| 259 | + // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
|
| 260 | + if (! empty($fields)) { |
|
| 261 | + $specified_shortcodes = array(); |
|
| 262 | + foreach ($fields as $field) { |
|
| 263 | + if (isset($valid_shortcodes[ $field ])) { |
|
| 264 | + $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + $valid_shortcodes = $specified_shortcodes; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // if not merged then let's replace the fields with the localized fields |
|
| 271 | + if (! $merged) { |
|
| 272 | + // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
|
| 273 | + $field_settings = $messenger->get_template_fields(); |
|
| 274 | + $localized = array(); |
|
| 275 | + foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 276 | + // get localized field label |
|
| 277 | + if (isset($field_settings[ $field ])) { |
|
| 278 | + // possible that this is used as a main field. |
|
| 279 | + if (empty($field_settings[ $field ])) { |
|
| 280 | + if (isset($field_settings['extra'][ $field ])) { |
|
| 281 | + $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 282 | + } else { |
|
| 283 | + $_field = $field; |
|
| 284 | + } |
|
| 285 | + } else { |
|
| 286 | + $_field = $field_settings[ $field ]['label']; |
|
| 287 | + } |
|
| 288 | + } elseif (isset($field_settings['extra'])) { |
|
| 289 | + // loop through extra "main fields" and see if any of their children have our field |
|
| 290 | + foreach ($field_settings['extra'] as $main_field => $fields) { |
|
| 291 | + if (isset($fields[ $field ])) { |
|
| 292 | + $_field = $fields[ $field ]['label']; |
|
| 293 | + } else { |
|
| 294 | + $_field = $field; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } else { |
|
| 298 | + $_field = $field; |
|
| 299 | + } |
|
| 300 | + if (isset($_field)) { |
|
| 301 | + $localized[ (string) $_field ] = $shortcodes; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + $valid_shortcodes = $localized; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
|
| 308 | + if ($merged) { |
|
| 309 | + $merged_codes = array(); |
|
| 310 | + foreach ($valid_shortcodes as $field => $shortcode) { |
|
| 311 | + foreach ($shortcode as $code => $label) { |
|
| 312 | + if (isset($merged_codes[ $code ])) { |
|
| 313 | + continue; |
|
| 314 | + } else { |
|
| 315 | + $merged_codes[ $code ] = $label; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + $valid_shortcodes = $merged_codes; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return $valid_shortcodes; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Get Messenger object. |
|
| 328 | + * |
|
| 329 | + * @since 4.3.0 |
|
| 330 | + * @deprecated 4.9.0 |
|
| 331 | + * @param string $messenger messenger slug for the messenger object we want to retrieve. |
|
| 332 | + * @throws \EE_Error |
|
| 333 | + * @return EE_messenger |
|
| 334 | + */ |
|
| 335 | + public static function messenger_obj($messenger) |
|
| 336 | + { |
|
| 337 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 338 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 339 | + return $Message_Resource_Manager->get_messenger($messenger); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * get Message type object |
|
| 345 | + * |
|
| 346 | + * @since 4.3.0 |
|
| 347 | + * @deprecated 4.9.0 |
|
| 348 | + * @param string $message_type the slug for the message type object to retrieve |
|
| 349 | + * @throws \EE_Error |
|
| 350 | + * @return EE_message_type |
|
| 351 | + */ |
|
| 352 | + public static function message_type_obj($message_type) |
|
| 353 | + { |
|
| 354 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 355 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 356 | + return $Message_Resource_Manager->get_message_type($message_type); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Given a message_type slug, will return whether that message type is active in the system or not. |
|
| 365 | + * |
|
| 366 | + * @since 4.3.0 |
|
| 367 | + * @param string $message_type message type to check for. |
|
| 368 | + * @return boolean |
|
| 369 | + */ |
|
| 370 | + public static function is_mt_active($message_type) |
|
| 371 | + { |
|
| 372 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 373 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 374 | + $active_mts = $Message_Resource_Manager->list_of_active_message_types(); |
|
| 375 | + return in_array($message_type, $active_mts); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Given a messenger slug, will return whether that messenger is active in the system or not. |
|
| 382 | + * |
|
| 383 | + * @since 4.3.0 |
|
| 384 | + * |
|
| 385 | + * @param string $messenger slug for messenger to check. |
|
| 386 | + * @return boolean |
|
| 387 | + */ |
|
| 388 | + public static function is_messenger_active($messenger) |
|
| 389 | + { |
|
| 390 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 391 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 392 | + $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger); |
|
| 393 | + return $active_messenger instanceof EE_messenger ? true : false; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Used to return active messengers array stored in the wp options table. |
|
| 400 | + * If no value is present in the option then an empty array is returned. |
|
| 401 | + * |
|
| 402 | + * @deprecated 4.9 |
|
| 403 | + * @since 4.3.1 |
|
| 404 | + * |
|
| 405 | + * @return array |
|
| 406 | + */ |
|
| 407 | + public static function get_active_messengers_in_db() |
|
| 408 | + { |
|
| 409 | + EE_Error::doing_it_wrong( |
|
| 410 | + __METHOD__, |
|
| 411 | + __('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), |
|
| 412 | + '4.9.0' |
|
| 413 | + ); |
|
| 414 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 415 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 416 | + return $Message_Resource_Manager->get_active_messengers_option(); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Used to update the active messengers array stored in the wp options table. |
|
| 424 | + * |
|
| 425 | + * @since 4.3.1 |
|
| 426 | + * @deprecated 4.9.0 |
|
| 427 | + * |
|
| 428 | + * @param array $data_to_save Incoming data to save. |
|
| 429 | + * |
|
| 430 | + * @return bool FALSE if not updated, TRUE if updated. |
|
| 431 | + */ |
|
| 432 | + public static function update_active_messengers_in_db($data_to_save) |
|
| 433 | + { |
|
| 434 | + EE_Error::doing_it_wrong( |
|
| 435 | + __METHOD__, |
|
| 436 | + __('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), |
|
| 437 | + '4.9.0' |
|
| 438 | + ); |
|
| 439 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 440 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 441 | + return $Message_Resource_Manager->update_active_messengers_option($data_to_save); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * This does some validation of incoming params, determines what type of url is being prepped and returns the |
|
| 447 | + * appropriate url trigger |
|
| 448 | + * |
|
| 449 | + * @param EE_message_type $message_type |
|
| 450 | + * @param EE_Message $message |
|
| 451 | + * @param EE_Registration | null $registration The registration object must be included if this |
|
| 452 | + * is going to be a registration trigger url. |
|
| 453 | + * @param string $sending_messenger The (optional) sending messenger for the url. |
|
| 454 | + * |
|
| 455 | + * @return string |
|
| 456 | + * @throws EE_Error |
|
| 457 | + */ |
|
| 458 | + public static function get_url_trigger( |
|
| 459 | + EE_message_type $message_type, |
|
| 460 | + EE_Message $message, |
|
| 461 | + $registration = null, |
|
| 462 | + $sending_messenger = '' |
|
| 463 | + ) { |
|
| 464 | + // first determine if the url can be to the EE_Message object. |
|
| 465 | + if (! $message_type->always_generate()) { |
|
| 466 | + return EEH_MSG_Template::generate_browser_trigger($message); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + // if $registration object is not valid then exit early because there's nothing that can be generated. |
|
| 470 | + if (! $registration instanceof EE_Registration) { |
|
| 471 | + throw new EE_Error( |
|
| 472 | + __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // validate given context |
|
| 477 | + $contexts = $message_type->get_contexts(); |
|
| 478 | + if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 479 | + throw new EE_Error( |
|
| 480 | + sprintf( |
|
| 481 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
| 482 | + $message->context(), |
|
| 483 | + get_class($message_type) |
|
| 484 | + ) |
|
| 485 | + ); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
|
| 489 | + if (! empty($sending_messenger)) { |
|
| 490 | + $with_messengers = $message_type->with_messengers(); |
|
| 491 | + if (! isset($with_messengers[ $message->messenger() ]) |
|
| 492 | + || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) ) { |
|
| 493 | + throw new EE_Error( |
|
| 494 | + sprintf( |
|
| 495 | + __( |
|
| 496 | + 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
| 497 | + 'event_espresso' |
|
| 498 | + ), |
|
| 499 | + $sending_messenger, |
|
| 500 | + get_class($message_type) |
|
| 501 | + ) |
|
| 502 | + ); |
|
| 503 | + } |
|
| 504 | + } else { |
|
| 505 | + $sending_messenger = $message->messenger(); |
|
| 506 | + } |
|
| 507 | + return EEH_MSG_Template::generate_url_trigger( |
|
| 508 | + $sending_messenger, |
|
| 509 | + $message->messenger(), |
|
| 510 | + $message->context(), |
|
| 511 | + $message->message_type(), |
|
| 512 | + $registration, |
|
| 513 | + $message->GRP_ID() |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * This returns the url for triggering a in browser view of a specific EE_Message object. |
|
| 520 | + * @param EE_Message $message |
|
| 521 | + * @return string. |
|
| 522 | + */ |
|
| 523 | + public static function generate_browser_trigger(EE_Message $message) |
|
| 524 | + { |
|
| 525 | + $query_args = array( |
|
| 526 | + 'ee' => 'msg_browser_trigger', |
|
| 527 | + 'token' => $message->MSG_token() |
|
| 528 | + ); |
|
| 529 | + return apply_filters( |
|
| 530 | + 'FHEE__EEH_MSG_Template__generate_browser_trigger', |
|
| 531 | + add_query_arg($query_args, site_url()), |
|
| 532 | + $message |
|
| 533 | + ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * This returns the url for triggering an in browser view of the error saved on the incoming message object. |
|
| 543 | + * @param EE_Message $message |
|
| 544 | + * @return string |
|
| 545 | + */ |
|
| 546 | + public static function generate_error_display_trigger(EE_Message $message) |
|
| 547 | + { |
|
| 548 | + return apply_filters( |
|
| 549 | + 'FHEE__EEH_MSG_Template__generate_error_display_trigger', |
|
| 550 | + add_query_arg( |
|
| 551 | + array( |
|
| 552 | + 'ee' => 'msg_browser_error_trigger', |
|
| 553 | + 'token' => $message->MSG_token() |
|
| 554 | + ), |
|
| 555 | + site_url() |
|
| 556 | + ), |
|
| 557 | + $message |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * This generates a url trigger for the msg_url_trigger route using the given arguments |
|
| 568 | + * |
|
| 569 | + * @param string $sending_messenger The sending messenger slug. |
|
| 570 | + * @param string $generating_messenger The generating messenger slug. |
|
| 571 | + * @param string $context The context for the template. |
|
| 572 | + * @param string $message_type The message type slug |
|
| 573 | + * @param EE_Registration $registration |
|
| 574 | + * @param integer $message_template_group id The EE_Message_Template_Group ID for the template. |
|
| 575 | + * @param integer $data_id The id to the EE_Base_Class for getting the data used by the trigger. |
|
| 576 | + * @return string The generated url. |
|
| 577 | + */ |
|
| 578 | + public static function generate_url_trigger( |
|
| 579 | + $sending_messenger, |
|
| 580 | + $generating_messenger, |
|
| 581 | + $context, |
|
| 582 | + $message_type, |
|
| 583 | + EE_Registration $registration, |
|
| 584 | + $message_template_group, |
|
| 585 | + $data_id = 0 |
|
| 586 | + ) { |
|
| 587 | + $query_args = array( |
|
| 588 | + 'ee' => 'msg_url_trigger', |
|
| 589 | + 'snd_msgr' => $sending_messenger, |
|
| 590 | + 'gen_msgr' => $generating_messenger, |
|
| 591 | + 'message_type' => $message_type, |
|
| 592 | + 'context' => $context, |
|
| 593 | + 'token' => $registration->reg_url_link(), |
|
| 594 | + 'GRP_ID' => $message_template_group, |
|
| 595 | + 'id' => $data_id |
|
| 596 | + ); |
|
| 597 | + $url = add_query_arg($query_args, get_home_url()); |
|
| 598 | + |
|
| 599 | + // made it here so now we can just get the url and filter it. Filtered globally and by message type. |
|
| 600 | + $url = apply_filters( |
|
| 601 | + 'FHEE__EEH_MSG_Template__generate_url_trigger', |
|
| 602 | + $url, |
|
| 603 | + $sending_messenger, |
|
| 604 | + $generating_messenger, |
|
| 605 | + $context, |
|
| 606 | + $message_type, |
|
| 607 | + $registration, |
|
| 608 | + $message_template_group, |
|
| 609 | + $data_id |
|
| 610 | + ); |
|
| 611 | + return $url; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Return the specific css for the action icon given. |
|
| 619 | + * |
|
| 620 | + * @since 4.9.0 |
|
| 621 | + * |
|
| 622 | + * @param string $type What action to return. |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public static function get_message_action_icon($type) |
|
| 626 | + { |
|
| 627 | + $action_icons = self::get_message_action_icons(); |
|
| 628 | + return isset($action_icons[ $type ]) ? $action_icons[ $type ] : ''; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * This is used for retrieving the css classes used for the icons representing message actions. |
|
| 634 | + * |
|
| 635 | + * @since 4.9.0 |
|
| 636 | + * |
|
| 637 | + * @return array |
|
| 638 | + */ |
|
| 639 | + public static function get_message_action_icons() |
|
| 640 | + { |
|
| 641 | + return apply_filters( |
|
| 642 | + 'FHEE__EEH_MSG_Template__message_action_icons', |
|
| 643 | + array( |
|
| 644 | + 'view' => array( |
|
| 645 | + 'label' => __('View Message', 'event_espresso'), |
|
| 646 | + 'css_class' => 'dashicons dashicons-welcome-view-site', |
|
| 647 | + ), |
|
| 648 | + 'error' => array( |
|
| 649 | + 'label' => __('View Error Message', 'event_espresso'), |
|
| 650 | + 'css_class' => 'dashicons dashicons-info', |
|
| 651 | + ), |
|
| 652 | + 'see_notifications_for' => array( |
|
| 653 | + 'label' => __('View Related Messages', 'event_espresso'), |
|
| 654 | + 'css_class' => 'dashicons dashicons-megaphone', |
|
| 655 | + ), |
|
| 656 | + 'generate_now' => array( |
|
| 657 | + 'label' => __('Generate the message now.', 'event_espresso'), |
|
| 658 | + 'css_class' => 'dashicons dashicons-admin-tools', |
|
| 659 | + ), |
|
| 660 | + 'send_now' => array( |
|
| 661 | + 'label' => __('Send Immediately', 'event_espresso'), |
|
| 662 | + 'css_class' => 'dashicons dashicons-controls-forward', |
|
| 663 | + ), |
|
| 664 | + 'queue_for_resending' => array( |
|
| 665 | + 'label' => __('Queue for Resending', 'event_espresso'), |
|
| 666 | + 'css_class' => 'dashicons dashicons-controls-repeat', |
|
| 667 | + ), |
|
| 668 | + 'view_transaction' => array( |
|
| 669 | + 'label' => __('View related Transaction', 'event_espresso'), |
|
| 670 | + 'css_class' => 'dashicons dashicons-cart', |
|
| 671 | + ) |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + /** |
|
| 678 | + * This returns the url for a given action related to EE_Message. |
|
| 679 | + * |
|
| 680 | + * @since 4.9.0 |
|
| 681 | + * |
|
| 682 | + * @param string $type What type of action to return the url for. |
|
| 683 | + * @param EE_Message $message Required for generating the correct url for some types. |
|
| 684 | + * @param array $query_params Any additional query params to be included with the generated url. |
|
| 685 | + * |
|
| 686 | + * @return string |
|
| 687 | + */ |
|
| 688 | + public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
|
| 689 | + { |
|
| 690 | + $action_urls = self::get_message_action_urls($message, $query_params); |
|
| 691 | + return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * This returns all the current urls for EE_Message actions. |
|
| 698 | + * |
|
| 699 | + * @since 4.9.0 |
|
| 700 | + * |
|
| 701 | + * @param EE_Message $message The EE_Message object required to generate correct urls for some types. |
|
| 702 | + * @param array $query_params Any additional query_params to be included with the generated url. |
|
| 703 | + * |
|
| 704 | + * @return array |
|
| 705 | + */ |
|
| 706 | + public static function get_message_action_urls(EE_Message $message = null, $query_params = array()) |
|
| 707 | + { |
|
| 708 | + EE_Registry::instance()->load_helper('URL'); |
|
| 709 | + // if $message is not an instance of EE_Message then let's just do a dummy. |
|
| 710 | + $message = empty($message) ? EE_Message_Factory::create() : $message; |
|
| 711 | + $action_urls = apply_filters( |
|
| 712 | + 'FHEE__EEH_MSG_Template__get_message_action_url', |
|
| 713 | + array( |
|
| 714 | + 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
|
| 715 | + 'error' => EEH_MSG_Template::generate_error_display_trigger($message), |
|
| 716 | + 'see_notifications_for' => EEH_URL::add_query_args_and_nonce( |
|
| 717 | + array_merge( |
|
| 718 | + array( |
|
| 719 | + 'page' => 'espresso_messages', |
|
| 720 | + 'action' => 'default', |
|
| 721 | + 'filterby' => 1, |
|
| 722 | + ), |
|
| 723 | + $query_params |
|
| 724 | + ), |
|
| 725 | + admin_url('admin.php') |
|
| 726 | + ), |
|
| 727 | + 'generate_now' => EEH_URL::add_query_args_and_nonce( |
|
| 728 | + array( |
|
| 729 | + 'page' => 'espresso_messages', |
|
| 730 | + 'action' => 'generate_now', |
|
| 731 | + 'MSG_ID' => $message->ID() |
|
| 732 | + ), |
|
| 733 | + admin_url('admin.php') |
|
| 734 | + ), |
|
| 735 | + 'send_now' => EEH_URL::add_query_args_and_nonce( |
|
| 736 | + array( |
|
| 737 | + 'page' => 'espresso_messages', |
|
| 738 | + 'action' => 'send_now', |
|
| 739 | + 'MSG_ID' => $message->ID() |
|
| 740 | + ), |
|
| 741 | + admin_url('admin.php') |
|
| 742 | + ), |
|
| 743 | + 'queue_for_resending' => EEH_URL::add_query_args_and_nonce( |
|
| 744 | + array( |
|
| 745 | + 'page' => 'espresso_messages', |
|
| 746 | + 'action' => 'queue_for_resending', |
|
| 747 | + 'MSG_ID' => $message->ID() |
|
| 748 | + ), |
|
| 749 | + admin_url('admin.php') |
|
| 750 | + ), |
|
| 751 | + ) |
|
| 752 | + ); |
|
| 753 | + if ($message->TXN_ID() > 0 |
|
| 754 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 755 | + 'ee_read_transaction', |
|
| 756 | + 'espresso_transactions_default', |
|
| 757 | + $message->TXN_ID() |
|
| 758 | + ) |
|
| 759 | + ) { |
|
| 760 | + $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce( |
|
| 761 | + array( |
|
| 762 | + 'page' => 'espresso_transactions', |
|
| 763 | + 'action' => 'view_transaction', |
|
| 764 | + 'TXN_ID' => $message->TXN_ID() |
|
| 765 | + ), |
|
| 766 | + admin_url('admin.php') |
|
| 767 | + ); |
|
| 768 | + } else { |
|
| 769 | + $action_urls['view_transaction'] = ''; |
|
| 770 | + } |
|
| 771 | + return $action_urls; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * This returns a generated link html including the icon used for the action link for EE_Message actions. |
|
| 777 | + * |
|
| 778 | + * @since 4.9.0 |
|
| 779 | + * |
|
| 780 | + * @param string $type What type of action the link is for (if invalid type is passed in then an |
|
| 781 | + * empty string is returned) |
|
| 782 | + * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly) |
|
| 783 | + * @param array $query_params Any extra query params to include in the generated link. |
|
| 784 | + * |
|
| 785 | + * @return string |
|
| 786 | + */ |
|
| 787 | + public static function get_message_action_link($type, EE_Message $message = null, $query_params = array()) |
|
| 788 | + { |
|
| 789 | + $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
|
| 790 | + $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
|
| 791 | + $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
| 792 | + |
|
| 793 | + if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
|
| 794 | + return ''; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + $icon_css['css_class'] .= esc_attr( |
|
| 798 | + apply_filters( |
|
| 799 | + 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
|
| 800 | + ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 801 | + $type, |
|
| 802 | + $message, |
|
| 803 | + $query_params |
|
| 804 | + ) |
|
| 805 | + ); |
|
| 806 | + |
|
| 807 | + return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>'; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered). |
|
| 816 | + * |
|
| 817 | + * @since 4.9.0 |
|
| 818 | + * @return array |
|
| 819 | + */ |
|
| 820 | + public static function reg_status_to_message_type_array() |
|
| 821 | + { |
|
| 822 | + return (array) apply_filters( |
|
| 823 | + 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array', |
|
| 824 | + array( |
|
| 825 | + EEM_Registration::status_id_approved => 'registration', |
|
| 826 | + EEM_Registration::status_id_pending_payment => 'pending_approval', |
|
| 827 | + EEM_Registration::status_id_not_approved => 'not_approved_registration', |
|
| 828 | + EEM_Registration::status_id_cancelled => 'cancelled_registration', |
|
| 829 | + EEM_Registration::status_id_declined => 'declined_registration' |
|
| 830 | + ) |
|
| 831 | + ); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * This returns the corresponding registration message type slug to the given reg status. If there isn't a |
|
| 839 | + * match, then returns an empty string. |
|
| 840 | + * |
|
| 841 | + * @since 4.9.0 |
|
| 842 | + * @param $reg_status |
|
| 843 | + * @return string |
|
| 844 | + */ |
|
| 845 | + public static function convert_reg_status_to_message_type($reg_status) |
|
| 846 | + { |
|
| 847 | + $reg_status_array = self::reg_status_to_message_type_array(); |
|
| 848 | + return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered). |
|
| 854 | + * |
|
| 855 | + * @since 4.9.0 |
|
| 856 | + * @return array |
|
| 857 | + */ |
|
| 858 | + public static function payment_status_to_message_type_array() |
|
| 859 | + { |
|
| 860 | + return (array) apply_filters( |
|
| 861 | + 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array', |
|
| 862 | + array( |
|
| 863 | + EEM_Payment::status_id_approved => 'payment', |
|
| 864 | + EEM_Payment::status_id_pending => 'payment_pending', |
|
| 865 | + EEM_Payment::status_id_cancelled => 'payment_cancelled', |
|
| 866 | + EEM_Payment::status_id_declined => 'payment_declined', |
|
| 867 | + EEM_Payment::status_id_failed => 'payment_failed' |
|
| 868 | + ) |
|
| 869 | + ); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then |
|
| 877 | + * an empty string is returned |
|
| 878 | + * |
|
| 879 | + * @since 4.9.0 |
|
| 880 | + * @param $payment_status |
|
| 881 | + * @return string |
|
| 882 | + */ |
|
| 883 | + public static function convert_payment_status_to_message_type($payment_status) |
|
| 884 | + { |
|
| 885 | + $payment_status_array = self::payment_status_to_message_type_array(); |
|
| 886 | + return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * This is used to retrieve the template pack for the given name. |
|
| 892 | + * |
|
| 893 | + * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack. |
|
| 894 | + * |
|
| 895 | + * @return EE_Messages_Template_Pack |
|
| 896 | + */ |
|
| 897 | + public static function get_template_pack($template_pack_name) |
|
| 898 | + { |
|
| 899 | + if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 900 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + // first see if in collection already |
|
| 904 | + $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name); |
|
| 905 | + |
|
| 906 | + if ($template_pack instanceof EE_Messages_Template_Pack) { |
|
| 907 | + return $template_pack; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + // nope...let's get it. |
|
| 911 | + // not set yet so let's attempt to get it. |
|
| 912 | + $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 913 | + ' ', |
|
| 914 | + '_', |
|
| 915 | + ucwords( |
|
| 916 | + str_replace('_', ' ', $template_pack_name) |
|
| 917 | + ) |
|
| 918 | + ); |
|
| 919 | + if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 920 | + return self::get_template_pack('default'); |
|
| 921 | + } else { |
|
| 922 | + $template_pack = new $pack_class_name; |
|
| 923 | + self::$_template_pack_collection->add($template_pack); |
|
| 924 | + return $template_pack; |
|
| 925 | + } |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Globs template packs installed in core and returns the template pack collection with all installed template packs |
|
| 933 | + * in it. |
|
| 934 | + * |
|
| 935 | + * @since 4.9.0 |
|
| 936 | + * |
|
| 937 | + * @return EE_Messages_Template_Pack_Collection |
|
| 938 | + */ |
|
| 939 | + public static function get_template_pack_collection() |
|
| 940 | + { |
|
| 941 | + $new_collection = false; |
|
| 942 | + if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 943 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
|
| 944 | + $new_collection = true; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + // glob the defaults directory for messages |
|
| 948 | + $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 949 | + foreach ($templates as $template_path) { |
|
| 950 | + // grab folder name |
|
| 951 | + $template = basename($template_path); |
|
| 952 | + |
|
| 953 | + if (! $new_collection) { |
|
| 954 | + // already have it? |
|
| 955 | + if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
|
| 956 | + continue; |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + // setup classname. |
|
| 961 | + $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 962 | + ' ', |
|
| 963 | + '_', |
|
| 964 | + ucwords( |
|
| 965 | + str_replace( |
|
| 966 | + '_', |
|
| 967 | + ' ', |
|
| 968 | + $template |
|
| 969 | + ) |
|
| 970 | + ) |
|
| 971 | + ); |
|
| 972 | + if (! class_exists($template_pack_class_name)) { |
|
| 973 | + continue; |
|
| 974 | + } |
|
| 975 | + self::$_template_pack_collection->add(new $template_pack_class_name); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * Filter for plugins to add in any additional template packs |
|
| 980 | + * Note the filter name here is for backward compat, this used to be found in EED_Messages. |
|
| 981 | + */ |
|
| 982 | + $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
|
| 983 | + foreach ((array) $additional_template_packs as $template_pack) { |
|
| 984 | + if (! self::$_template_pack_collection->contains($template_pack)) { |
|
| 985 | + self::$_template_pack_collection->add($template_pack); |
|
| 986 | + } |
|
| 987 | + } |
|
| 988 | + return self::$_template_pack_collection; |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * This is a wrapper for the protected _create_new_templates function |
|
| 995 | + * |
|
| 996 | + * @param string $messenger_name |
|
| 997 | + * @param string $message_type_name message type that the templates are being created for |
|
| 998 | + * @param int $GRP_ID |
|
| 999 | + * @param bool $global |
|
| 1000 | + * @return array |
|
| 1001 | + * @throws \EE_Error |
|
| 1002 | + */ |
|
| 1003 | + public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false) |
|
| 1004 | + { |
|
| 1005 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1006 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1007 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1008 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1009 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1010 | + return array(); |
|
| 1011 | + } |
|
| 1012 | + // whew made it this far! Okay, let's go ahead and create the templates then |
|
| 1013 | + return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global); |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * @param \EE_messenger $messenger |
|
| 1020 | + * @param \EE_message_type $message_type |
|
| 1021 | + * @param $GRP_ID |
|
| 1022 | + * @param $global |
|
| 1023 | + * @return array|mixed |
|
| 1024 | + */ |
|
| 1025 | + protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
|
| 1026 | + { |
|
| 1027 | + // if we're creating a custom template then we don't need to use the defaults class |
|
| 1028 | + if (! $global) { |
|
| 1029 | + return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
|
| 1030 | + } |
|
| 1031 | + /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
|
| 1032 | + $Message_Template_Defaults = EE_Registry::factory( |
|
| 1033 | + 'EE_Messages_Template_Defaults', |
|
| 1034 | + array( $messenger, $message_type, $GRP_ID ) |
|
| 1035 | + ); |
|
| 1036 | + // generate templates |
|
| 1037 | + $success = $Message_Template_Defaults->create_new_templates(); |
|
| 1038 | + |
|
| 1039 | + // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
|
| 1040 | + // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
|
| 1041 | + // attempts. |
|
| 1042 | + if (! $success) { |
|
| 1043 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1044 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1045 | + $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + /** |
|
| 1049 | + * $success is in an array in the following format |
|
| 1050 | + * array( |
|
| 1051 | + * 'GRP_ID' => $new_grp_id, |
|
| 1052 | + * 'MTP_context' => $first_context_in_new_templates, |
|
| 1053 | + * ) |
|
| 1054 | + */ |
|
| 1055 | + return $success; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * This creates a custom template using the incoming GRP_ID |
|
| 1062 | + * |
|
| 1063 | + * @param \EE_messenger $messenger |
|
| 1064 | + * @param \EE_message_type $message_type |
|
| 1065 | + * @param int $GRP_ID GRP_ID for the template_group being used as the base |
|
| 1066 | + * @return array $success This will be an array in the format: |
|
| 1067 | + * array( |
|
| 1068 | + * 'GRP_ID' => $new_grp_id, |
|
| 1069 | + * 'MTP_context' => $first_context_in_created_template |
|
| 1070 | + * ) |
|
| 1071 | + * @access private |
|
| 1072 | + */ |
|
| 1073 | + private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
|
| 1074 | + { |
|
| 1075 | + // defaults |
|
| 1076 | + $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1077 | + // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
|
| 1078 | + $Message_Template_Group = empty($GRP_ID) |
|
| 1079 | + ? EEM_Message_Template_Group::instance()->get_one( |
|
| 1080 | + array( |
|
| 1081 | + array( |
|
| 1082 | + 'MTP_messenger' => $messenger->name, |
|
| 1083 | + 'MTP_message_type' => $message_type->name, |
|
| 1084 | + 'MTP_is_global' => true |
|
| 1085 | + ) |
|
| 1086 | + ) |
|
| 1087 | + ) |
|
| 1088 | + : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1089 | + // if we don't have a mtg at this point then we need to bail. |
|
| 1090 | + if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1091 | + EE_Error::add_error( |
|
| 1092 | + sprintf( |
|
| 1093 | + __( |
|
| 1094 | + 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.', |
|
| 1095 | + 'event_espresso' |
|
| 1096 | + ), |
|
| 1097 | + $GRP_ID |
|
| 1098 | + ), |
|
| 1099 | + __FILE__, |
|
| 1100 | + __FUNCTION__, |
|
| 1101 | + __LINE__ |
|
| 1102 | + ); |
|
| 1103 | + return $success; |
|
| 1104 | + } |
|
| 1105 | + // let's get all the related message_template objects for this group. |
|
| 1106 | + $message_templates = $Message_Template_Group->message_templates(); |
|
| 1107 | + // now we have what we need to setup the new template |
|
| 1108 | + $new_mtg = clone $Message_Template_Group; |
|
| 1109 | + $new_mtg->set('GRP_ID', 0); |
|
| 1110 | + $new_mtg->set('MTP_is_global', false); |
|
| 1111 | + $template_name = defined('DOING_AJAX') && ! empty($_POST['templateName']) |
|
| 1112 | + ? $_POST['templateName'] |
|
| 1113 | + : __( |
|
| 1114 | + 'New Custom Template', |
|
| 1115 | + 'event_espresso' |
|
| 1116 | + ); |
|
| 1117 | + $template_description = defined("DOING_AJAX") && ! empty($_POST['templateDescription']) |
|
| 1118 | + ? $_POST['templateDescription'] |
|
| 1119 | + : sprintf( |
|
| 1120 | + __( |
|
| 1121 | + 'This is a custom template that was created for the %s messenger and %s message type.', |
|
| 1122 | + 'event_espresso' |
|
| 1123 | + ), |
|
| 1124 | + $new_mtg->messenger_obj()->label['singular'], |
|
| 1125 | + $new_mtg->message_type_obj()->label['singular'] |
|
| 1126 | + ); |
|
| 1127 | + $new_mtg->set('MTP_name', $template_name); |
|
| 1128 | + $new_mtg->set('MTP_description', $template_description); |
|
| 1129 | + // remove ALL relations on this template group so they don't get saved! |
|
| 1130 | + $new_mtg->_remove_relations('Message_Template'); |
|
| 1131 | + $new_mtg->save(); |
|
| 1132 | + $success['GRP_ID'] = $new_mtg->ID(); |
|
| 1133 | + $success['template_name'] = $template_name; |
|
| 1134 | + // add new message templates and add relation to. |
|
| 1135 | + foreach ($message_templates as $message_template) { |
|
| 1136 | + if (! $message_template instanceof EE_Message_Template) { |
|
| 1137 | + continue; |
|
| 1138 | + } |
|
| 1139 | + $new_message_template = clone $message_template; |
|
| 1140 | + $new_message_template->set('MTP_ID', 0); |
|
| 1141 | + $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation |
|
| 1142 | + $new_message_template->save(); |
|
| 1143 | + if (empty($success['MTP_context'])) { |
|
| 1144 | + $success['MTP_context'] = $new_message_template->get('MTP_context'); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + return $success; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * message_type_has_active_templates_for_messenger |
|
| 1154 | + * |
|
| 1155 | + * @param \EE_messenger $messenger |
|
| 1156 | + * @param \EE_message_type $message_type |
|
| 1157 | + * @param bool $global |
|
| 1158 | + * @return bool |
|
| 1159 | + */ |
|
| 1160 | + public static function message_type_has_active_templates_for_messenger( |
|
| 1161 | + EE_messenger $messenger, |
|
| 1162 | + EE_message_type $message_type, |
|
| 1163 | + $global = false |
|
| 1164 | + ) { |
|
| 1165 | + // is given message_type valid for given messenger (if this is not a global save) |
|
| 1166 | + if ($global) { |
|
| 1167 | + return true; |
|
| 1168 | + } |
|
| 1169 | + $active_templates = EEM_Message_Template_Group::instance()->count( |
|
| 1170 | + array( |
|
| 1171 | + array( |
|
| 1172 | + 'MTP_is_active' => true, |
|
| 1173 | + 'MTP_messenger' => $messenger->name, |
|
| 1174 | + 'MTP_message_type' => $message_type->name |
|
| 1175 | + ) |
|
| 1176 | + ) |
|
| 1177 | + ); |
|
| 1178 | + if ($active_templates > 0) { |
|
| 1179 | + return true; |
|
| 1180 | + } |
|
| 1181 | + EE_Error::add_error( |
|
| 1182 | + sprintf( |
|
| 1183 | + __( |
|
| 1184 | + 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.', |
|
| 1185 | + 'event_espresso' |
|
| 1186 | + ), |
|
| 1187 | + $message_type->name, |
|
| 1188 | + $messenger->name |
|
| 1189 | + ), |
|
| 1190 | + __FILE__, |
|
| 1191 | + __FUNCTION__, |
|
| 1192 | + __LINE__ |
|
| 1193 | + ); |
|
| 1194 | + return false; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + |
|
| 1198 | + |
|
| 1199 | + /** |
|
| 1200 | + * get_fields |
|
| 1201 | + * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). |
|
| 1202 | + * |
|
| 1203 | + * @param string $messenger_name name of EE_messenger |
|
| 1204 | + * @param string $message_type_name name of EE_message_type |
|
| 1205 | + * @return array |
|
| 1206 | + */ |
|
| 1207 | + public static function get_fields($messenger_name, $message_type_name) |
|
| 1208 | + { |
|
| 1209 | + $template_fields = array(); |
|
| 1210 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ |
|
| 1211 | + $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1212 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
|
| 1213 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
|
| 1214 | + if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1215 | + return array(); |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); |
|
| 1219 | + |
|
| 1220 | + // okay now let's assemble an array with the messenger template fields added to the message_type contexts. |
|
| 1221 | + foreach ($message_type->get_contexts() as $context => $details) { |
|
| 1222 | + foreach ($messenger->get_template_fields() as $field => $value) { |
|
| 1223 | + if (in_array($field, $excluded_fields_for_messenger, true)) { |
|
| 1224 | + continue; |
|
| 1225 | + } |
|
| 1226 | + $template_fields[ $context ][ $field ] = $value; |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | + if (empty($template_fields)) { |
|
| 1230 | + EE_Error::add_error( |
|
| 1231 | + __('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), |
|
| 1232 | + __FILE__, |
|
| 1233 | + __FUNCTION__, |
|
| 1234 | + __LINE__ |
|
| 1235 | + ); |
|
| 1236 | + return array(); |
|
| 1237 | + } |
|
| 1238 | + return $template_fields; |
|
| 1239 | + } |
|
| 1240 | 1240 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | } |
| 89 | 89 | $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global); |
| 90 | 90 | |
| 91 | - if (! $new_message_template_group) { |
|
| 91 | + if ( ! $new_message_template_group) { |
|
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | 94 | $templates[] = $new_message_template_group; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | ) |
| 120 | 120 | ) |
| 121 | 121 | ) |
| 122 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) )); |
|
| 122 | + : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID))); |
|
| 123 | 123 | |
| 124 | 124 | return $count > 0; |
| 125 | 125 | } |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public static function update_to_active($messenger_names, $message_type_names) |
| 139 | 139 | { |
| 140 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names ); |
|
| 141 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names ); |
|
| 140 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names); |
|
| 141 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names); |
|
| 142 | 142 | return EEM_Message_Template_Group::instance()->update( |
| 143 | - array( 'MTP_is_active' => 1 ), |
|
| 143 | + array('MTP_is_active' => 1), |
|
| 144 | 144 | array( |
| 145 | 145 | array( |
| 146 | - 'MTP_messenger' => array( 'IN', $messenger_names ), |
|
| 147 | - 'MTP_message_type' => array( 'IN', $message_type_names ) |
|
| 146 | + 'MTP_messenger' => array('IN', $messenger_names), |
|
| 147 | + 'MTP_message_type' => array('IN', $message_type_names) |
|
| 148 | 148 | ) |
| 149 | 149 | ) |
| 150 | 150 | ); |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | $messenger = $message_resource_manager->get_messenger($messenger); |
| 231 | 231 | |
| 232 | 232 | // if messenger isn't a EE_messenger resource then bail. |
| 233 | - if (! $messenger instanceof EE_messenger) { |
|
| 233 | + if ( ! $messenger instanceof EE_messenger) { |
|
| 234 | 234 | return array(); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // validate class for getting our list of shortcodes |
| 238 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 239 | - if (! class_exists($classname)) { |
|
| 238 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator'; |
|
| 239 | + if ( ! class_exists($classname)) { |
|
| 240 | 240 | $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
| 241 | 241 | $msg[] = sprintf( |
| 242 | 242 | __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), |
@@ -252,44 +252,44 @@ discard block |
||
| 252 | 252 | // let's make sure we're only getting the shortcode part of the validators |
| 253 | 253 | $shortcodes = array(); |
| 254 | 254 | foreach ($valid_shortcodes as $field => $validators) { |
| 255 | - $shortcodes[ $field ] = $validators['shortcodes']; |
|
| 255 | + $shortcodes[$field] = $validators['shortcodes']; |
|
| 256 | 256 | } |
| 257 | 257 | $valid_shortcodes = $shortcodes; |
| 258 | 258 | |
| 259 | 259 | // if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
| 260 | - if (! empty($fields)) { |
|
| 260 | + if ( ! empty($fields)) { |
|
| 261 | 261 | $specified_shortcodes = array(); |
| 262 | 262 | foreach ($fields as $field) { |
| 263 | - if (isset($valid_shortcodes[ $field ])) { |
|
| 264 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ]; |
|
| 263 | + if (isset($valid_shortcodes[$field])) { |
|
| 264 | + $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | $valid_shortcodes = $specified_shortcodes; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // if not merged then let's replace the fields with the localized fields |
| 271 | - if (! $merged) { |
|
| 271 | + if ( ! $merged) { |
|
| 272 | 272 | // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
| 273 | 273 | $field_settings = $messenger->get_template_fields(); |
| 274 | 274 | $localized = array(); |
| 275 | 275 | foreach ($valid_shortcodes as $field => $shortcodes) { |
| 276 | 276 | // get localized field label |
| 277 | - if (isset($field_settings[ $field ])) { |
|
| 277 | + if (isset($field_settings[$field])) { |
|
| 278 | 278 | // possible that this is used as a main field. |
| 279 | - if (empty($field_settings[ $field ])) { |
|
| 280 | - if (isset($field_settings['extra'][ $field ])) { |
|
| 281 | - $_field = $field_settings['extra'][ $field ]['main']['label']; |
|
| 279 | + if (empty($field_settings[$field])) { |
|
| 280 | + if (isset($field_settings['extra'][$field])) { |
|
| 281 | + $_field = $field_settings['extra'][$field]['main']['label']; |
|
| 282 | 282 | } else { |
| 283 | 283 | $_field = $field; |
| 284 | 284 | } |
| 285 | 285 | } else { |
| 286 | - $_field = $field_settings[ $field ]['label']; |
|
| 286 | + $_field = $field_settings[$field]['label']; |
|
| 287 | 287 | } |
| 288 | 288 | } elseif (isset($field_settings['extra'])) { |
| 289 | 289 | // loop through extra "main fields" and see if any of their children have our field |
| 290 | 290 | foreach ($field_settings['extra'] as $main_field => $fields) { |
| 291 | - if (isset($fields[ $field ])) { |
|
| 292 | - $_field = $fields[ $field ]['label']; |
|
| 291 | + if (isset($fields[$field])) { |
|
| 292 | + $_field = $fields[$field]['label']; |
|
| 293 | 293 | } else { |
| 294 | 294 | $_field = $field; |
| 295 | 295 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $_field = $field; |
| 299 | 299 | } |
| 300 | 300 | if (isset($_field)) { |
| 301 | - $localized[ (string) $_field ] = $shortcodes; |
|
| 301 | + $localized[(string) $_field] = $shortcodes; |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | $valid_shortcodes = $localized; |
@@ -309,10 +309,10 @@ discard block |
||
| 309 | 309 | $merged_codes = array(); |
| 310 | 310 | foreach ($valid_shortcodes as $field => $shortcode) { |
| 311 | 311 | foreach ($shortcode as $code => $label) { |
| 312 | - if (isset($merged_codes[ $code ])) { |
|
| 312 | + if (isset($merged_codes[$code])) { |
|
| 313 | 313 | continue; |
| 314 | 314 | } else { |
| 315 | - $merged_codes[ $code ] = $label; |
|
| 315 | + $merged_codes[$code] = $label; |
|
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | } |
@@ -462,12 +462,12 @@ discard block |
||
| 462 | 462 | $sending_messenger = '' |
| 463 | 463 | ) { |
| 464 | 464 | // first determine if the url can be to the EE_Message object. |
| 465 | - if (! $message_type->always_generate()) { |
|
| 465 | + if ( ! $message_type->always_generate()) { |
|
| 466 | 466 | return EEH_MSG_Template::generate_browser_trigger($message); |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | // if $registration object is not valid then exit early because there's nothing that can be generated. |
| 470 | - if (! $registration instanceof EE_Registration) { |
|
| 470 | + if ( ! $registration instanceof EE_Registration) { |
|
| 471 | 471 | throw new EE_Error( |
| 472 | 472 | __('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') |
| 473 | 473 | ); |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | // validate given context |
| 477 | 477 | $contexts = $message_type->get_contexts(); |
| 478 | - if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { |
|
| 478 | + if ($message->context() !== '' && ! isset($contexts[$message->context()])) { |
|
| 479 | 479 | throw new EE_Error( |
| 480 | 480 | sprintf( |
| 481 | 481 | __('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -486,10 +486,10 @@ discard block |
||
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. |
| 489 | - if (! empty($sending_messenger)) { |
|
| 489 | + if ( ! empty($sending_messenger)) { |
|
| 490 | 490 | $with_messengers = $message_type->with_messengers(); |
| 491 | - if (! isset($with_messengers[ $message->messenger() ]) |
|
| 492 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ]) ) { |
|
| 491 | + if ( ! isset($with_messengers[$message->messenger()]) |
|
| 492 | + || ! in_array($sending_messenger, $with_messengers[$message->messenger()])) { |
|
| 493 | 493 | throw new EE_Error( |
| 494 | 494 | sprintf( |
| 495 | 495 | __( |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | public static function get_message_action_icon($type) |
| 626 | 626 | { |
| 627 | 627 | $action_icons = self::get_message_action_icons(); |
| 628 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : ''; |
|
| 628 | + return isset($action_icons[$type]) ? $action_icons[$type] : ''; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | public static function get_message_action_url($type, EE_Message $message = null, $query_params = array()) |
| 689 | 689 | { |
| 690 | 690 | $action_urls = self::get_message_action_urls($message, $query_params); |
| 691 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : ''; |
|
| 691 | + return isset($action_urls[$type]) ? $action_urls[$type] : ''; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | EE_Registry::instance()->load_helper('URL'); |
| 709 | 709 | // if $message is not an instance of EE_Message then let's just do a dummy. |
| 710 | 710 | $message = empty($message) ? EE_Message_Factory::create() : $message; |
| 711 | - $action_urls = apply_filters( |
|
| 711 | + $action_urls = apply_filters( |
|
| 712 | 712 | 'FHEE__EEH_MSG_Template__get_message_action_url', |
| 713 | 713 | array( |
| 714 | 714 | 'view' => EEH_MSG_Template::generate_browser_trigger($message), |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | { |
| 789 | 789 | $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params); |
| 790 | 790 | $icon_css = EEH_MSG_Template::get_message_action_icon($type); |
| 791 | - $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : ''; |
|
| 791 | + $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : ''; |
|
| 792 | 792 | |
| 793 | 793 | if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { |
| 794 | 794 | return ''; |
@@ -797,14 +797,14 @@ discard block |
||
| 797 | 797 | $icon_css['css_class'] .= esc_attr( |
| 798 | 798 | apply_filters( |
| 799 | 799 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class', |
| 800 | - ' js-ee-message-action-link ee-message-action-link-' . $type, |
|
| 800 | + ' js-ee-message-action-link ee-message-action-link-'.$type, |
|
| 801 | 801 | $type, |
| 802 | 802 | $message, |
| 803 | 803 | $query_params |
| 804 | 804 | ) |
| 805 | 805 | ); |
| 806 | 806 | |
| 807 | - return '<a href="' . $url . '"' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>'; |
|
| 807 | + return '<a href="'.$url.'"'.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>'; |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | public static function convert_reg_status_to_message_type($reg_status) |
| 846 | 846 | { |
| 847 | 847 | $reg_status_array = self::reg_status_to_message_type_array(); |
| 848 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : ''; |
|
| 848 | + return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : ''; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | public static function convert_payment_status_to_message_type($payment_status) |
| 884 | 884 | { |
| 885 | 885 | $payment_status_array = self::payment_status_to_message_type_array(); |
| 886 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : ''; |
|
| 886 | + return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : ''; |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | */ |
| 897 | 897 | public static function get_template_pack($template_pack_name) |
| 898 | 898 | { |
| 899 | - if (! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 899 | + if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) { |
|
| 900 | 900 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
| 901 | 901 | } |
| 902 | 902 | |
@@ -909,14 +909,14 @@ discard block |
||
| 909 | 909 | |
| 910 | 910 | // nope...let's get it. |
| 911 | 911 | // not set yet so let's attempt to get it. |
| 912 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 912 | + $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
| 913 | 913 | ' ', |
| 914 | 914 | '_', |
| 915 | 915 | ucwords( |
| 916 | 916 | str_replace('_', ' ', $template_pack_name) |
| 917 | 917 | ) |
| 918 | 918 | ); |
| 919 | - if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 919 | + if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') { |
|
| 920 | 920 | return self::get_template_pack('default'); |
| 921 | 921 | } else { |
| 922 | 922 | $template_pack = new $pack_class_name; |
@@ -939,18 +939,18 @@ discard block |
||
| 939 | 939 | public static function get_template_pack_collection() |
| 940 | 940 | { |
| 941 | 941 | $new_collection = false; |
| 942 | - if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 942 | + if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { |
|
| 943 | 943 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection(); |
| 944 | 944 | $new_collection = true; |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | // glob the defaults directory for messages |
| 948 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR); |
|
| 948 | + $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR); |
|
| 949 | 949 | foreach ($templates as $template_path) { |
| 950 | 950 | // grab folder name |
| 951 | 951 | $template = basename($template_path); |
| 952 | 952 | |
| 953 | - if (! $new_collection) { |
|
| 953 | + if ( ! $new_collection) { |
|
| 954 | 954 | // already have it? |
| 955 | 955 | if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { |
| 956 | 956 | continue; |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | // setup classname. |
| 961 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace( |
|
| 961 | + $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace( |
|
| 962 | 962 | ' ', |
| 963 | 963 | '_', |
| 964 | 964 | ucwords( |
@@ -969,7 +969,7 @@ discard block |
||
| 969 | 969 | ) |
| 970 | 970 | ) |
| 971 | 971 | ); |
| 972 | - if (! class_exists($template_pack_class_name)) { |
|
| 972 | + if ( ! class_exists($template_pack_class_name)) { |
|
| 973 | 973 | continue; |
| 974 | 974 | } |
| 975 | 975 | self::$_template_pack_collection->add(new $template_pack_class_name); |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | */ |
| 982 | 982 | $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); |
| 983 | 983 | foreach ((array) $additional_template_packs as $template_pack) { |
| 984 | - if (! self::$_template_pack_collection->contains($template_pack)) { |
|
| 984 | + if ( ! self::$_template_pack_collection->contains($template_pack)) { |
|
| 985 | 985 | self::$_template_pack_collection->add($template_pack); |
| 986 | 986 | } |
| 987 | 987 | } |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1007 | 1007 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
| 1008 | 1008 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
| 1009 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1009 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { |
|
| 1010 | 1010 | return array(); |
| 1011 | 1011 | } |
| 1012 | 1012 | // whew made it this far! Okay, let's go ahead and create the templates then |
@@ -1025,13 +1025,13 @@ discard block |
||
| 1025 | 1025 | protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global) |
| 1026 | 1026 | { |
| 1027 | 1027 | // if we're creating a custom template then we don't need to use the defaults class |
| 1028 | - if (! $global) { |
|
| 1028 | + if ( ! $global) { |
|
| 1029 | 1029 | return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID); |
| 1030 | 1030 | } |
| 1031 | 1031 | /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */ |
| 1032 | 1032 | $Message_Template_Defaults = EE_Registry::factory( |
| 1033 | 1033 | 'EE_Messages_Template_Defaults', |
| 1034 | - array( $messenger, $message_type, $GRP_ID ) |
|
| 1034 | + array($messenger, $message_type, $GRP_ID) |
|
| 1035 | 1035 | ); |
| 1036 | 1036 | // generate templates |
| 1037 | 1037 | $success = $Message_Template_Defaults->create_new_templates(); |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | // if creating the template failed. Then we should deactivate the related message_type for the messenger because |
| 1040 | 1040 | // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation |
| 1041 | 1041 | // attempts. |
| 1042 | - if (! $success) { |
|
| 1042 | + if ( ! $success) { |
|
| 1043 | 1043 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
| 1044 | 1044 | $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1045 | 1045 | $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name); |
@@ -1073,7 +1073,7 @@ discard block |
||
| 1073 | 1073 | private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID) |
| 1074 | 1074 | { |
| 1075 | 1075 | // defaults |
| 1076 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' ); |
|
| 1076 | + $success = array('GRP_ID' => null, 'MTP_context' => ''); |
|
| 1077 | 1077 | // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type. |
| 1078 | 1078 | $Message_Template_Group = empty($GRP_ID) |
| 1079 | 1079 | ? EEM_Message_Template_Group::instance()->get_one( |
@@ -1087,7 +1087,7 @@ discard block |
||
| 1087 | 1087 | ) |
| 1088 | 1088 | : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
| 1089 | 1089 | // if we don't have a mtg at this point then we need to bail. |
| 1090 | - if (! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1090 | + if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) { |
|
| 1091 | 1091 | EE_Error::add_error( |
| 1092 | 1092 | sprintf( |
| 1093 | 1093 | __( |
@@ -1133,7 +1133,7 @@ discard block |
||
| 1133 | 1133 | $success['template_name'] = $template_name; |
| 1134 | 1134 | // add new message templates and add relation to. |
| 1135 | 1135 | foreach ($message_templates as $message_template) { |
| 1136 | - if (! $message_template instanceof EE_Message_Template) { |
|
| 1136 | + if ( ! $message_template instanceof EE_Message_Template) { |
|
| 1137 | 1137 | continue; |
| 1138 | 1138 | } |
| 1139 | 1139 | $new_message_template = clone $message_template; |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 1212 | 1212 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); |
| 1213 | 1213 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); |
| 1214 | - if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1214 | + if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { |
|
| 1215 | 1215 | return array(); |
| 1216 | 1216 | } |
| 1217 | 1217 | |
@@ -1223,7 +1223,7 @@ discard block |
||
| 1223 | 1223 | if (in_array($field, $excluded_fields_for_messenger, true)) { |
| 1224 | 1224 | continue; |
| 1225 | 1225 | } |
| 1226 | - $template_fields[ $context ][ $field ] = $value; |
|
| 1226 | + $template_fields[$context][$field] = $value; |
|
| 1227 | 1227 | } |
| 1228 | 1228 | } |
| 1229 | 1229 | if (empty($template_fields)) { |
@@ -31,524 +31,524 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class RegistrationsReport extends JobHandlerFile |
| 33 | 33 | { |
| 34 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 35 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 36 | - /** |
|
| 37 | - * Performs any necessary setup for starting the job. This is also a good |
|
| 38 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 39 | - * when continue_job will be called |
|
| 40 | - * |
|
| 41 | - * @param JobParameters $job_parameters |
|
| 42 | - * @throws BatchRequestException |
|
| 43 | - * @return JobStepResponse |
|
| 44 | - */ |
|
| 45 | - public function create_job(JobParameters $job_parameters) |
|
| 46 | - { |
|
| 47 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
| 48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 49 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
| 50 | - } |
|
| 51 | - $filepath = $this->create_file_from_job_with_name( |
|
| 52 | - $job_parameters->job_id(), |
|
| 53 | - $this->get_filename($event_id) |
|
| 54 | - ); |
|
| 55 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
| 56 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
| 57 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
| 58 | - } else { |
|
| 59 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
| 60 | - array( |
|
| 61 | - 'OR' => array( |
|
| 62 | - // don't include registrations from failed or abandoned transactions... |
|
| 63 | - 'Transaction.STS_ID' => array( |
|
| 64 | - 'NOT IN', |
|
| 65 | - array( |
|
| 66 | - EEM_Transaction::failed_status_code, |
|
| 67 | - EEM_Transaction::abandoned_status_code, |
|
| 68 | - ), |
|
| 69 | - ), |
|
| 70 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
| 71 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
| 72 | - ), |
|
| 73 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
| 74 | - ), |
|
| 75 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
| 76 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
| 77 | - 'caps' => \EEM_Base::caps_read_admin, |
|
| 78 | - ), $event_id); |
|
| 79 | - if ($event_id) { |
|
| 80 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 81 | - } else { |
|
| 82 | - $query_params['force_join'][] = 'Event'; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - if (! isset($query_params['force_join'])) { |
|
| 86 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
| 87 | - } |
|
| 88 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
| 89 | - $question_labels = $this->_get_question_labels($query_params); |
|
| 90 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
| 91 | - $job_parameters->set_job_size( |
|
| 92 | - \EEM_Registration::instance()->count( |
|
| 93 | - array_diff_key( |
|
| 94 | - $query_params, |
|
| 95 | - array_flip( |
|
| 96 | - array('limit') |
|
| 97 | - ) |
|
| 98 | - ) |
|
| 99 | - ) |
|
| 100 | - ); |
|
| 101 | - // we should also set the header columns |
|
| 102 | - $csv_data_for_row = $this->get_csv_data_for( |
|
| 103 | - $event_id, |
|
| 104 | - 0, |
|
| 105 | - 1, |
|
| 106 | - $job_parameters->extra_datum('question_labels'), |
|
| 107 | - $job_parameters->extra_datum('query_params') |
|
| 108 | - ); |
|
| 109 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
| 110 | - // if we actually processed a row there, record it |
|
| 111 | - if ($job_parameters->job_size()) { |
|
| 112 | - $job_parameters->mark_processed(1); |
|
| 113 | - } |
|
| 114 | - return new JobStepResponse( |
|
| 115 | - $job_parameters, |
|
| 116 | - __('Registrations report started successfully...', 'event_espresso') |
|
| 117 | - ); |
|
| 118 | - } |
|
| 34 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 35 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 36 | + /** |
|
| 37 | + * Performs any necessary setup for starting the job. This is also a good |
|
| 38 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
| 39 | + * when continue_job will be called |
|
| 40 | + * |
|
| 41 | + * @param JobParameters $job_parameters |
|
| 42 | + * @throws BatchRequestException |
|
| 43 | + * @return JobStepResponse |
|
| 44 | + */ |
|
| 45 | + public function create_job(JobParameters $job_parameters) |
|
| 46 | + { |
|
| 47 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
| 48 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 49 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
| 50 | + } |
|
| 51 | + $filepath = $this->create_file_from_job_with_name( |
|
| 52 | + $job_parameters->job_id(), |
|
| 53 | + $this->get_filename($event_id) |
|
| 54 | + ); |
|
| 55 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
| 56 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
| 57 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
| 58 | + } else { |
|
| 59 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
| 60 | + array( |
|
| 61 | + 'OR' => array( |
|
| 62 | + // don't include registrations from failed or abandoned transactions... |
|
| 63 | + 'Transaction.STS_ID' => array( |
|
| 64 | + 'NOT IN', |
|
| 65 | + array( |
|
| 66 | + EEM_Transaction::failed_status_code, |
|
| 67 | + EEM_Transaction::abandoned_status_code, |
|
| 68 | + ), |
|
| 69 | + ), |
|
| 70 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
| 71 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
| 72 | + ), |
|
| 73 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
| 74 | + ), |
|
| 75 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
| 76 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
| 77 | + 'caps' => \EEM_Base::caps_read_admin, |
|
| 78 | + ), $event_id); |
|
| 79 | + if ($event_id) { |
|
| 80 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 81 | + } else { |
|
| 82 | + $query_params['force_join'][] = 'Event'; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + if (! isset($query_params['force_join'])) { |
|
| 86 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
| 87 | + } |
|
| 88 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
| 89 | + $question_labels = $this->_get_question_labels($query_params); |
|
| 90 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
| 91 | + $job_parameters->set_job_size( |
|
| 92 | + \EEM_Registration::instance()->count( |
|
| 93 | + array_diff_key( |
|
| 94 | + $query_params, |
|
| 95 | + array_flip( |
|
| 96 | + array('limit') |
|
| 97 | + ) |
|
| 98 | + ) |
|
| 99 | + ) |
|
| 100 | + ); |
|
| 101 | + // we should also set the header columns |
|
| 102 | + $csv_data_for_row = $this->get_csv_data_for( |
|
| 103 | + $event_id, |
|
| 104 | + 0, |
|
| 105 | + 1, |
|
| 106 | + $job_parameters->extra_datum('question_labels'), |
|
| 107 | + $job_parameters->extra_datum('query_params') |
|
| 108 | + ); |
|
| 109 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
| 110 | + // if we actually processed a row there, record it |
|
| 111 | + if ($job_parameters->job_size()) { |
|
| 112 | + $job_parameters->mark_processed(1); |
|
| 113 | + } |
|
| 114 | + return new JobStepResponse( |
|
| 115 | + $job_parameters, |
|
| 116 | + __('Registrations report started successfully...', 'event_espresso') |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Gets the filename |
|
| 123 | - * |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - protected function get_filename() |
|
| 127 | - { |
|
| 128 | - return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
| 129 | - } |
|
| 121 | + /** |
|
| 122 | + * Gets the filename |
|
| 123 | + * |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + protected function get_filename() |
|
| 127 | + { |
|
| 128 | + return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Gets the questions which are to be used for this report, so they |
|
| 134 | - * can be remembered for later |
|
| 135 | - * |
|
| 136 | - * @param array $registration_query_params |
|
| 137 | - * @return array question admin labels to be used for this report |
|
| 138 | - */ |
|
| 139 | - protected function _get_question_labels($registration_query_params) |
|
| 140 | - { |
|
| 141 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
| 142 | - $question_query_params = array(); |
|
| 143 | - if ($where !== null) { |
|
| 144 | - $question_query_params = array( |
|
| 145 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - $question_query_params[0]['QST_system'] = array( |
|
| 149 | - 'NOT_IN', |
|
| 150 | - array_keys(EEM_Attendee::instance()->system_question_to_attendee_field_mapping()), |
|
| 151 | - ); |
|
| 152 | - if (apply_filters( |
|
| 153 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
| 154 | - false, |
|
| 155 | - $registration_query_params |
|
| 156 | - )) { |
|
| 157 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
| 158 | - } |
|
| 159 | - $question_query_params['group_by'] = array('QST_ID'); |
|
| 160 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
| 161 | - } |
|
| 132 | + /** |
|
| 133 | + * Gets the questions which are to be used for this report, so they |
|
| 134 | + * can be remembered for later |
|
| 135 | + * |
|
| 136 | + * @param array $registration_query_params |
|
| 137 | + * @return array question admin labels to be used for this report |
|
| 138 | + */ |
|
| 139 | + protected function _get_question_labels($registration_query_params) |
|
| 140 | + { |
|
| 141 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
| 142 | + $question_query_params = array(); |
|
| 143 | + if ($where !== null) { |
|
| 144 | + $question_query_params = array( |
|
| 145 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + $question_query_params[0]['QST_system'] = array( |
|
| 149 | + 'NOT_IN', |
|
| 150 | + array_keys(EEM_Attendee::instance()->system_question_to_attendee_field_mapping()), |
|
| 151 | + ); |
|
| 152 | + if (apply_filters( |
|
| 153 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
| 154 | + false, |
|
| 155 | + $registration_query_params |
|
| 156 | + )) { |
|
| 157 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
| 158 | + } |
|
| 159 | + $question_query_params['group_by'] = array('QST_ID'); |
|
| 160 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Takes where params meant for registrations and changes them to work for questions |
|
| 166 | - * |
|
| 167 | - * @param array $reg_where_params |
|
| 168 | - * @return array |
|
| 169 | - */ |
|
| 170 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
| 171 | - { |
|
| 172 | - $question_where_params = array(); |
|
| 173 | - foreach ($reg_where_params as $key => $val) { |
|
| 174 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
| 175 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
| 176 | - } else { |
|
| 177 | - // it's a normal where condition |
|
| 178 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - return $question_where_params; |
|
| 182 | - } |
|
| 164 | + /** |
|
| 165 | + * Takes where params meant for registrations and changes them to work for questions |
|
| 166 | + * |
|
| 167 | + * @param array $reg_where_params |
|
| 168 | + * @return array |
|
| 169 | + */ |
|
| 170 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
| 171 | + { |
|
| 172 | + $question_where_params = array(); |
|
| 173 | + foreach ($reg_where_params as $key => $val) { |
|
| 174 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
| 175 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
| 176 | + } else { |
|
| 177 | + // it's a normal where condition |
|
| 178 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + return $question_where_params; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * Performs another step of the job |
|
| 187 | - * |
|
| 188 | - * @param JobParameters $job_parameters |
|
| 189 | - * @param int $batch_size |
|
| 190 | - * @return JobStepResponse |
|
| 191 | - * @throws \EE_Error |
|
| 192 | - */ |
|
| 193 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 194 | - { |
|
| 195 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
| 196 | - $csv_data = $this->get_csv_data_for( |
|
| 197 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
| 198 | - $job_parameters->units_processed(), |
|
| 199 | - $batch_size, |
|
| 200 | - $job_parameters->extra_datum('question_labels'), |
|
| 201 | - $job_parameters->extra_datum('query_params') |
|
| 202 | - ); |
|
| 203 | - EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
| 204 | - $units_processed = count($csv_data); |
|
| 205 | - } else { |
|
| 206 | - $csv_data = array(); |
|
| 207 | - $units_processed = 0; |
|
| 208 | - } |
|
| 209 | - $job_parameters->mark_processed($units_processed); |
|
| 210 | - $extra_response_data = array( |
|
| 211 | - 'file_url' => '', |
|
| 212 | - ); |
|
| 213 | - if ($units_processed < $batch_size) { |
|
| 214 | - $job_parameters->set_status(JobParameters::status_complete); |
|
| 215 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
| 216 | - } |
|
| 185 | + /** |
|
| 186 | + * Performs another step of the job |
|
| 187 | + * |
|
| 188 | + * @param JobParameters $job_parameters |
|
| 189 | + * @param int $batch_size |
|
| 190 | + * @return JobStepResponse |
|
| 191 | + * @throws \EE_Error |
|
| 192 | + */ |
|
| 193 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
| 194 | + { |
|
| 195 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
| 196 | + $csv_data = $this->get_csv_data_for( |
|
| 197 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
| 198 | + $job_parameters->units_processed(), |
|
| 199 | + $batch_size, |
|
| 200 | + $job_parameters->extra_datum('question_labels'), |
|
| 201 | + $job_parameters->extra_datum('query_params') |
|
| 202 | + ); |
|
| 203 | + EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
| 204 | + $units_processed = count($csv_data); |
|
| 205 | + } else { |
|
| 206 | + $csv_data = array(); |
|
| 207 | + $units_processed = 0; |
|
| 208 | + } |
|
| 209 | + $job_parameters->mark_processed($units_processed); |
|
| 210 | + $extra_response_data = array( |
|
| 211 | + 'file_url' => '', |
|
| 212 | + ); |
|
| 213 | + if ($units_processed < $batch_size) { |
|
| 214 | + $job_parameters->set_status(JobParameters::status_complete); |
|
| 215 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return new JobStepResponse( |
|
| 219 | - $job_parameters, |
|
| 220 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
| 221 | - $extra_response_data |
|
| 222 | - ); |
|
| 223 | - } |
|
| 218 | + return new JobStepResponse( |
|
| 219 | + $job_parameters, |
|
| 220 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
| 221 | + $extra_response_data |
|
| 222 | + ); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Gets the csv data for a batch of registrations |
|
| 228 | - * |
|
| 229 | - * @param int|null $event_id |
|
| 230 | - * @param int $offset |
|
| 231 | - * @param int $limit |
|
| 232 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
| 233 | - * @param array $query_params for using where querying the model |
|
| 234 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
| 235 | - * @throws \EE_Error |
|
| 236 | - */ |
|
| 237 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
| 238 | - { |
|
| 239 | - $reg_fields_to_include = array( |
|
| 240 | - 'TXN_ID', |
|
| 241 | - 'ATT_ID', |
|
| 242 | - 'REG_ID', |
|
| 243 | - 'REG_date', |
|
| 244 | - 'REG_code', |
|
| 245 | - 'REG_count', |
|
| 246 | - 'REG_final_price', |
|
| 247 | - ); |
|
| 248 | - $att_fields_to_include = array( |
|
| 249 | - 'ATT_fname', |
|
| 250 | - 'ATT_lname', |
|
| 251 | - 'ATT_email', |
|
| 252 | - 'ATT_address', |
|
| 253 | - 'ATT_address2', |
|
| 254 | - 'ATT_city', |
|
| 255 | - 'STA_ID', |
|
| 256 | - 'CNT_ISO', |
|
| 257 | - 'ATT_zip', |
|
| 258 | - 'ATT_phone', |
|
| 259 | - ); |
|
| 260 | - $registrations_csv_ready_array = array(); |
|
| 261 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
| 262 | - $query_params['limit'] = array($offset, $limit); |
|
| 263 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 264 | - $registration_ids = array(); |
|
| 265 | - foreach ($registration_rows as $reg_row) { |
|
| 266 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 267 | - } |
|
| 268 | - foreach ($registration_rows as $reg_row) { |
|
| 269 | - if (is_array($reg_row)) { |
|
| 270 | - $reg_csv_array = array(); |
|
| 271 | - if (! $event_id) { |
|
| 272 | - // get the event's name and Id |
|
| 273 | - $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
| 274 | - /* translators: 1: event name, 2: event ID */ |
|
| 275 | - __('%1$s (%2$s)', 'event_espresso'), |
|
| 276 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 277 | - EEM_Event::instance(), |
|
| 278 | - 'EVT_name', |
|
| 279 | - $reg_row['Event_CPT.post_title'] |
|
| 280 | - ), |
|
| 281 | - $reg_row['Event_CPT.ID'] |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 285 | - /*@var $reg_row EE_Registration */ |
|
| 286 | - foreach ($reg_fields_to_include as $field_name) { |
|
| 287 | - $field = $reg_model->field_settings_for($field_name); |
|
| 288 | - if ($field_name == 'REG_final_price') { |
|
| 289 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 290 | - $reg_model, |
|
| 291 | - $field_name, |
|
| 292 | - $reg_row['Registration.REG_final_price'], |
|
| 293 | - 'localized_float' |
|
| 294 | - ); |
|
| 295 | - } elseif ($field_name == 'REG_count') { |
|
| 296 | - $value = sprintf( |
|
| 297 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
| 298 | - __('%1$s of %2$s', 'event_espresso'), |
|
| 299 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 300 | - $reg_model, |
|
| 301 | - 'REG_count', |
|
| 302 | - $reg_row['Registration.REG_count'] |
|
| 303 | - ), |
|
| 304 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 305 | - $reg_model, |
|
| 306 | - 'REG_group_size', |
|
| 307 | - $reg_row['Registration.REG_group_size'] |
|
| 308 | - ) |
|
| 309 | - ); |
|
| 310 | - } elseif ($field_name == 'REG_date') { |
|
| 311 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 312 | - $reg_model, |
|
| 313 | - $field_name, |
|
| 314 | - $reg_row['Registration.REG_date'], |
|
| 315 | - 'no_html' |
|
| 316 | - ); |
|
| 317 | - } else { |
|
| 318 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 319 | - $reg_model, |
|
| 320 | - $field_name, |
|
| 321 | - $reg_row[ $field->get_qualified_column() ] |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
| 325 | - if ($field_name == 'REG_final_price') { |
|
| 326 | - // add a column named Currency after the final price |
|
| 327 | - $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - // get pretty status |
|
| 331 | - $stati = EEM_Status::instance()->localized_status( |
|
| 332 | - array( |
|
| 333 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 334 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 335 | - ), |
|
| 336 | - false, |
|
| 337 | - 'sentence' |
|
| 338 | - ); |
|
| 339 | - $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 340 | - // get pretty transaction status |
|
| 341 | - $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 342 | - $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 343 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
| 344 | - EEM_Transaction::instance(), |
|
| 345 | - 'TXN_total', |
|
| 346 | - $reg_row['TransactionTable.TXN_total'], |
|
| 347 | - 'localized_float' |
|
| 348 | - ) : '0.00'; |
|
| 349 | - $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 350 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
| 351 | - EEM_Transaction::instance(), |
|
| 352 | - 'TXN_paid', |
|
| 353 | - $reg_row['TransactionTable.TXN_paid'], |
|
| 354 | - 'localized_float' |
|
| 355 | - ) : '0.00'; |
|
| 356 | - $payment_methods = array(); |
|
| 357 | - $gateway_txn_ids_etc = array(); |
|
| 358 | - $payment_times = array(); |
|
| 359 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 360 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
| 361 | - array( |
|
| 362 | - array( |
|
| 363 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 364 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
| 365 | - ), |
|
| 366 | - 'force_join' => array('Payment_Method'), |
|
| 367 | - ), |
|
| 368 | - ARRAY_A, |
|
| 369 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
| 370 | - ); |
|
| 371 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 372 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
| 373 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 374 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
| 375 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 376 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
| 377 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
| 381 | - $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
| 382 | - $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 383 | - ',', |
|
| 384 | - $gateway_txn_ids_etc |
|
| 385 | - ); |
|
| 386 | - // get whether or not the user has checked in |
|
| 387 | - $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
| 388 | - $reg_row['Registration.REG_ID'], |
|
| 389 | - 'Checkin' |
|
| 390 | - ); |
|
| 391 | - // get ticket of registration and its price |
|
| 392 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 393 | - if ($reg_row['Ticket.TKT_ID']) { |
|
| 394 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
| 395 | - $ticket_model, |
|
| 396 | - 'TKT_name', |
|
| 397 | - $reg_row['Ticket.TKT_name'] |
|
| 398 | - ); |
|
| 399 | - $datetimes_strings = array(); |
|
| 400 | - foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
| 401 | - array( |
|
| 402 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
| 403 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 404 | - 'default_where_conditions' => 'none', |
|
| 405 | - ) |
|
| 406 | - ) as $datetime) { |
|
| 407 | - $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
| 408 | - EEM_Datetime::instance(), |
|
| 409 | - 'DTT_EVT_start', |
|
| 410 | - $datetime['Datetime.DTT_EVT_start'] |
|
| 411 | - ); |
|
| 412 | - } |
|
| 413 | - } else { |
|
| 414 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
| 415 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 416 | - } |
|
| 417 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 418 | - $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
| 419 | - // get datetime(s) of registration |
|
| 420 | - // add attendee columns |
|
| 421 | - foreach ($att_fields_to_include as $att_field_name) { |
|
| 422 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
| 423 | - if ($reg_row['Attendee_CPT.ID']) { |
|
| 424 | - if ($att_field_name == 'STA_ID') { |
|
| 425 | - $value = EEM_State::instance()->get_var( |
|
| 426 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
| 427 | - 'STA_name' |
|
| 428 | - ); |
|
| 429 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
| 430 | - $value = EEM_Country::instance()->get_var( |
|
| 431 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
| 432 | - 'CNT_name' |
|
| 433 | - ); |
|
| 434 | - } else { |
|
| 435 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 436 | - EEM_Attendee::instance(), |
|
| 437 | - $att_field_name, |
|
| 438 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
| 439 | - ); |
|
| 440 | - } |
|
| 441 | - } else { |
|
| 442 | - $value = ''; |
|
| 443 | - } |
|
| 444 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
| 445 | - } |
|
| 446 | - // make sure each registration has the same questions in the same order |
|
| 447 | - foreach ($question_labels as $question_label) { |
|
| 448 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
| 449 | - $reg_csv_array[ $question_label ] = null; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
| 453 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
| 454 | - 'force_join' => array('Question'), |
|
| 455 | - )); |
|
| 456 | - // now fill out the questions THEY answered |
|
| 457 | - foreach ($answers as $answer_row) { |
|
| 458 | - if ($answer_row['Question.QST_ID']) { |
|
| 459 | - $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
| 460 | - EEM_Question::instance(), |
|
| 461 | - 'QST_admin_label', |
|
| 462 | - $answer_row['Question.QST_admin_label'] |
|
| 463 | - ); |
|
| 464 | - } else { |
|
| 465 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 466 | - } |
|
| 467 | - if (isset($answer_row['Question.QST_type']) |
|
| 468 | - && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
| 469 | - ) { |
|
| 470 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
| 471 | - $answer_row['Answer.ANS_value'] |
|
| 472 | - ); |
|
| 473 | - } else { |
|
| 474 | - // this isn't for html, so don't show html entities |
|
| 475 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
| 476 | - EEH_Export::prepare_value_from_db_for_display( |
|
| 477 | - EEM_Answer::instance(), |
|
| 478 | - 'ANS_value', |
|
| 479 | - $answer_row['Answer.ANS_value'] |
|
| 480 | - ) |
|
| 481 | - ); |
|
| 482 | - } |
|
| 483 | - } |
|
| 226 | + /** |
|
| 227 | + * Gets the csv data for a batch of registrations |
|
| 228 | + * |
|
| 229 | + * @param int|null $event_id |
|
| 230 | + * @param int $offset |
|
| 231 | + * @param int $limit |
|
| 232 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
| 233 | + * @param array $query_params for using where querying the model |
|
| 234 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
| 235 | + * @throws \EE_Error |
|
| 236 | + */ |
|
| 237 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
| 238 | + { |
|
| 239 | + $reg_fields_to_include = array( |
|
| 240 | + 'TXN_ID', |
|
| 241 | + 'ATT_ID', |
|
| 242 | + 'REG_ID', |
|
| 243 | + 'REG_date', |
|
| 244 | + 'REG_code', |
|
| 245 | + 'REG_count', |
|
| 246 | + 'REG_final_price', |
|
| 247 | + ); |
|
| 248 | + $att_fields_to_include = array( |
|
| 249 | + 'ATT_fname', |
|
| 250 | + 'ATT_lname', |
|
| 251 | + 'ATT_email', |
|
| 252 | + 'ATT_address', |
|
| 253 | + 'ATT_address2', |
|
| 254 | + 'ATT_city', |
|
| 255 | + 'STA_ID', |
|
| 256 | + 'CNT_ISO', |
|
| 257 | + 'ATT_zip', |
|
| 258 | + 'ATT_phone', |
|
| 259 | + ); |
|
| 260 | + $registrations_csv_ready_array = array(); |
|
| 261 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
| 262 | + $query_params['limit'] = array($offset, $limit); |
|
| 263 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
| 264 | + $registration_ids = array(); |
|
| 265 | + foreach ($registration_rows as $reg_row) { |
|
| 266 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
| 267 | + } |
|
| 268 | + foreach ($registration_rows as $reg_row) { |
|
| 269 | + if (is_array($reg_row)) { |
|
| 270 | + $reg_csv_array = array(); |
|
| 271 | + if (! $event_id) { |
|
| 272 | + // get the event's name and Id |
|
| 273 | + $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
| 274 | + /* translators: 1: event name, 2: event ID */ |
|
| 275 | + __('%1$s (%2$s)', 'event_espresso'), |
|
| 276 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 277 | + EEM_Event::instance(), |
|
| 278 | + 'EVT_name', |
|
| 279 | + $reg_row['Event_CPT.post_title'] |
|
| 280 | + ), |
|
| 281 | + $reg_row['Event_CPT.ID'] |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
| 285 | + /*@var $reg_row EE_Registration */ |
|
| 286 | + foreach ($reg_fields_to_include as $field_name) { |
|
| 287 | + $field = $reg_model->field_settings_for($field_name); |
|
| 288 | + if ($field_name == 'REG_final_price') { |
|
| 289 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 290 | + $reg_model, |
|
| 291 | + $field_name, |
|
| 292 | + $reg_row['Registration.REG_final_price'], |
|
| 293 | + 'localized_float' |
|
| 294 | + ); |
|
| 295 | + } elseif ($field_name == 'REG_count') { |
|
| 296 | + $value = sprintf( |
|
| 297 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
| 298 | + __('%1$s of %2$s', 'event_espresso'), |
|
| 299 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 300 | + $reg_model, |
|
| 301 | + 'REG_count', |
|
| 302 | + $reg_row['Registration.REG_count'] |
|
| 303 | + ), |
|
| 304 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 305 | + $reg_model, |
|
| 306 | + 'REG_group_size', |
|
| 307 | + $reg_row['Registration.REG_group_size'] |
|
| 308 | + ) |
|
| 309 | + ); |
|
| 310 | + } elseif ($field_name == 'REG_date') { |
|
| 311 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 312 | + $reg_model, |
|
| 313 | + $field_name, |
|
| 314 | + $reg_row['Registration.REG_date'], |
|
| 315 | + 'no_html' |
|
| 316 | + ); |
|
| 317 | + } else { |
|
| 318 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 319 | + $reg_model, |
|
| 320 | + $field_name, |
|
| 321 | + $reg_row[ $field->get_qualified_column() ] |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
| 325 | + if ($field_name == 'REG_final_price') { |
|
| 326 | + // add a column named Currency after the final price |
|
| 327 | + $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + // get pretty status |
|
| 331 | + $stati = EEM_Status::instance()->localized_status( |
|
| 332 | + array( |
|
| 333 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 334 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
| 335 | + ), |
|
| 336 | + false, |
|
| 337 | + 'sentence' |
|
| 338 | + ); |
|
| 339 | + $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 340 | + // get pretty transaction status |
|
| 341 | + $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 342 | + $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 343 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
| 344 | + EEM_Transaction::instance(), |
|
| 345 | + 'TXN_total', |
|
| 346 | + $reg_row['TransactionTable.TXN_total'], |
|
| 347 | + 'localized_float' |
|
| 348 | + ) : '0.00'; |
|
| 349 | + $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 350 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
| 351 | + EEM_Transaction::instance(), |
|
| 352 | + 'TXN_paid', |
|
| 353 | + $reg_row['TransactionTable.TXN_paid'], |
|
| 354 | + 'localized_float' |
|
| 355 | + ) : '0.00'; |
|
| 356 | + $payment_methods = array(); |
|
| 357 | + $gateway_txn_ids_etc = array(); |
|
| 358 | + $payment_times = array(); |
|
| 359 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
| 360 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
| 361 | + array( |
|
| 362 | + array( |
|
| 363 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
| 364 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
| 365 | + ), |
|
| 366 | + 'force_join' => array('Payment_Method'), |
|
| 367 | + ), |
|
| 368 | + ARRAY_A, |
|
| 369 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
| 370 | + ); |
|
| 371 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
| 372 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
| 373 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
| 374 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
| 375 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
| 376 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
| 377 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
| 381 | + $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
| 382 | + $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 383 | + ',', |
|
| 384 | + $gateway_txn_ids_etc |
|
| 385 | + ); |
|
| 386 | + // get whether or not the user has checked in |
|
| 387 | + $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
| 388 | + $reg_row['Registration.REG_ID'], |
|
| 389 | + 'Checkin' |
|
| 390 | + ); |
|
| 391 | + // get ticket of registration and its price |
|
| 392 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 393 | + if ($reg_row['Ticket.TKT_ID']) { |
|
| 394 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
| 395 | + $ticket_model, |
|
| 396 | + 'TKT_name', |
|
| 397 | + $reg_row['Ticket.TKT_name'] |
|
| 398 | + ); |
|
| 399 | + $datetimes_strings = array(); |
|
| 400 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
| 401 | + array( |
|
| 402 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
| 403 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 404 | + 'default_where_conditions' => 'none', |
|
| 405 | + ) |
|
| 406 | + ) as $datetime) { |
|
| 407 | + $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
| 408 | + EEM_Datetime::instance(), |
|
| 409 | + 'DTT_EVT_start', |
|
| 410 | + $datetime['Datetime.DTT_EVT_start'] |
|
| 411 | + ); |
|
| 412 | + } |
|
| 413 | + } else { |
|
| 414 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
| 415 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
| 416 | + } |
|
| 417 | + $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 418 | + $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
| 419 | + // get datetime(s) of registration |
|
| 420 | + // add attendee columns |
|
| 421 | + foreach ($att_fields_to_include as $att_field_name) { |
|
| 422 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
| 423 | + if ($reg_row['Attendee_CPT.ID']) { |
|
| 424 | + if ($att_field_name == 'STA_ID') { |
|
| 425 | + $value = EEM_State::instance()->get_var( |
|
| 426 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
| 427 | + 'STA_name' |
|
| 428 | + ); |
|
| 429 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
| 430 | + $value = EEM_Country::instance()->get_var( |
|
| 431 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
| 432 | + 'CNT_name' |
|
| 433 | + ); |
|
| 434 | + } else { |
|
| 435 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
| 436 | + EEM_Attendee::instance(), |
|
| 437 | + $att_field_name, |
|
| 438 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
| 439 | + ); |
|
| 440 | + } |
|
| 441 | + } else { |
|
| 442 | + $value = ''; |
|
| 443 | + } |
|
| 444 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
| 445 | + } |
|
| 446 | + // make sure each registration has the same questions in the same order |
|
| 447 | + foreach ($question_labels as $question_label) { |
|
| 448 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
| 449 | + $reg_csv_array[ $question_label ] = null; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
| 453 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
| 454 | + 'force_join' => array('Question'), |
|
| 455 | + )); |
|
| 456 | + // now fill out the questions THEY answered |
|
| 457 | + foreach ($answers as $answer_row) { |
|
| 458 | + if ($answer_row['Question.QST_ID']) { |
|
| 459 | + $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
| 460 | + EEM_Question::instance(), |
|
| 461 | + 'QST_admin_label', |
|
| 462 | + $answer_row['Question.QST_admin_label'] |
|
| 463 | + ); |
|
| 464 | + } else { |
|
| 465 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
| 466 | + } |
|
| 467 | + if (isset($answer_row['Question.QST_type']) |
|
| 468 | + && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
| 469 | + ) { |
|
| 470 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
| 471 | + $answer_row['Answer.ANS_value'] |
|
| 472 | + ); |
|
| 473 | + } else { |
|
| 474 | + // this isn't for html, so don't show html entities |
|
| 475 | + $reg_csv_array[ $question_label ] = html_entity_decode( |
|
| 476 | + EEH_Export::prepare_value_from_db_for_display( |
|
| 477 | + EEM_Answer::instance(), |
|
| 478 | + 'ANS_value', |
|
| 479 | + $answer_row['Answer.ANS_value'] |
|
| 480 | + ) |
|
| 481 | + ); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | - /** |
|
| 486 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
| 487 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
| 488 | - * Note when using: all rows in the CSV should have the same columns. |
|
| 489 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
| 490 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
| 491 | - */ |
|
| 492 | - $registrations_csv_ready_array[] = apply_filters( |
|
| 493 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
| 494 | - $reg_csv_array, |
|
| 495 | - $reg_row |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - // if we couldn't export anything, we want to at least show the column headers |
|
| 500 | - if (empty($registrations_csv_ready_array)) { |
|
| 501 | - $reg_csv_array = array(); |
|
| 502 | - $model_and_fields_to_include = array( |
|
| 503 | - 'Registration' => $reg_fields_to_include, |
|
| 504 | - 'Attendee' => $att_fields_to_include, |
|
| 505 | - ); |
|
| 506 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 507 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 508 | - foreach ($field_list as $field_name) { |
|
| 509 | - $field = $model->field_settings_for($field_name); |
|
| 510 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
| 514 | - } |
|
| 515 | - return $registrations_csv_ready_array; |
|
| 516 | - } |
|
| 485 | + /** |
|
| 486 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
| 487 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
| 488 | + * Note when using: all rows in the CSV should have the same columns. |
|
| 489 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
| 490 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
| 491 | + */ |
|
| 492 | + $registrations_csv_ready_array[] = apply_filters( |
|
| 493 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
| 494 | + $reg_csv_array, |
|
| 495 | + $reg_row |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + // if we couldn't export anything, we want to at least show the column headers |
|
| 500 | + if (empty($registrations_csv_ready_array)) { |
|
| 501 | + $reg_csv_array = array(); |
|
| 502 | + $model_and_fields_to_include = array( |
|
| 503 | + 'Registration' => $reg_fields_to_include, |
|
| 504 | + 'Attendee' => $att_fields_to_include, |
|
| 505 | + ); |
|
| 506 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
| 507 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 508 | + foreach ($field_list as $field_name) { |
|
| 509 | + $field = $model->field_settings_for($field_name); |
|
| 510 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
| 514 | + } |
|
| 515 | + return $registrations_csv_ready_array; |
|
| 516 | + } |
|
| 517 | 517 | |
| 518 | 518 | |
| 519 | - /** |
|
| 520 | - * Counts total unit to process |
|
| 521 | - * |
|
| 522 | - * @deprecated since 4.9.19 |
|
| 523 | - * @param int|array $event_id |
|
| 524 | - * @return int |
|
| 525 | - */ |
|
| 526 | - public function count_units_to_process($event_id) |
|
| 527 | - { |
|
| 528 | - // use the legacy filter |
|
| 529 | - if ($event_id) { |
|
| 530 | - $query_params[0]['EVT_ID'] = $event_id; |
|
| 531 | - } else { |
|
| 532 | - $query_params['force_join'][] = 'Event'; |
|
| 533 | - } |
|
| 534 | - return \EEM_Registration::instance()->count($query_params); |
|
| 535 | - } |
|
| 519 | + /** |
|
| 520 | + * Counts total unit to process |
|
| 521 | + * |
|
| 522 | + * @deprecated since 4.9.19 |
|
| 523 | + * @param int|array $event_id |
|
| 524 | + * @return int |
|
| 525 | + */ |
|
| 526 | + public function count_units_to_process($event_id) |
|
| 527 | + { |
|
| 528 | + // use the legacy filter |
|
| 529 | + if ($event_id) { |
|
| 530 | + $query_params[0]['EVT_ID'] = $event_id; |
|
| 531 | + } else { |
|
| 532 | + $query_params['force_join'][] = 'Event'; |
|
| 533 | + } |
|
| 534 | + return \EEM_Registration::instance()->count($query_params); |
|
| 535 | + } |
|
| 536 | 536 | |
| 537 | 537 | |
| 538 | - /** |
|
| 539 | - * Performs any clean-up logic when we know the job is completed. |
|
| 540 | - * In this case, we delete the temporary file |
|
| 541 | - * |
|
| 542 | - * @param JobParameters $job_parameters |
|
| 543 | - * @return boolean |
|
| 544 | - */ |
|
| 545 | - public function cleanup_job(JobParameters $job_parameters) |
|
| 546 | - { |
|
| 547 | - $this->_file_helper->delete( |
|
| 548 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
| 549 | - true, |
|
| 550 | - 'd' |
|
| 551 | - ); |
|
| 552 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
| 553 | - } |
|
| 538 | + /** |
|
| 539 | + * Performs any clean-up logic when we know the job is completed. |
|
| 540 | + * In this case, we delete the temporary file |
|
| 541 | + * |
|
| 542 | + * @param JobParameters $job_parameters |
|
| 543 | + * @return boolean |
|
| 544 | + */ |
|
| 545 | + public function cleanup_job(JobParameters $job_parameters) |
|
| 546 | + { |
|
| 547 | + $this->_file_helper->delete( |
|
| 548 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
| 549 | + true, |
|
| 550 | + 'd' |
|
| 551 | + ); |
|
| 552 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
| 553 | + } |
|
| 554 | 554 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function create_job(JobParameters $job_parameters) |
| 46 | 46 | { |
| 47 | 47 | $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
| 48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 48 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
| 49 | 49 | throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
| 50 | 50 | } |
| 51 | 51 | $filepath = $this->create_file_from_job_with_name( |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $query_params['force_join'][] = 'Event'; |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | - if (! isset($query_params['force_join'])) { |
|
| 85 | + if ( ! isset($query_params['force_join'])) { |
|
| 86 | 86 | $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
| 87 | 87 | } |
| 88 | 88 | $job_parameters->add_extra_data('query_params', $query_params); |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | $question_where_params = array(); |
| 173 | 173 | foreach ($reg_where_params as $key => $val) { |
| 174 | 174 | if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
| 175 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
| 175 | + $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
| 176 | 176 | } else { |
| 177 | 177 | // it's a normal where condition |
| 178 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
| 178 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | return $question_where_params; |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | foreach ($registration_rows as $reg_row) { |
| 269 | 269 | if (is_array($reg_row)) { |
| 270 | 270 | $reg_csv_array = array(); |
| 271 | - if (! $event_id) { |
|
| 271 | + if ( ! $event_id) { |
|
| 272 | 272 | // get the event's name and Id |
| 273 | - $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
| 273 | + $reg_csv_array[(string) __('Event', 'event_espresso')] = sprintf( |
|
| 274 | 274 | /* translators: 1: event name, 2: event ID */ |
| 275 | 275 | __('%1$s (%2$s)', 'event_espresso'), |
| 276 | 276 | EEH_Export::prepare_value_from_db_for_display( |
@@ -318,13 +318,13 @@ discard block |
||
| 318 | 318 | $value = EEH_Export::prepare_value_from_db_for_display( |
| 319 | 319 | $reg_model, |
| 320 | 320 | $field_name, |
| 321 | - $reg_row[ $field->get_qualified_column() ] |
|
| 321 | + $reg_row[$field->get_qualified_column()] |
|
| 322 | 322 | ); |
| 323 | 323 | } |
| 324 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
| 324 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value; |
|
| 325 | 325 | if ($field_name == 'REG_final_price') { |
| 326 | 326 | // add a column named Currency after the final price |
| 327 | - $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
| 327 | + $reg_csv_array[(string) __("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | // get pretty status |
@@ -336,17 +336,17 @@ discard block |
||
| 336 | 336 | false, |
| 337 | 337 | 'sentence' |
| 338 | 338 | ); |
| 339 | - $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
| 339 | + $reg_csv_array[(string) __("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
| 340 | 340 | // get pretty transaction status |
| 341 | - $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
| 342 | - $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
| 341 | + $reg_csv_array[(string) __("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
| 342 | + $reg_csv_array[(string) __('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
| 343 | 343 | ? EEH_Export::prepare_value_from_db_for_display( |
| 344 | 344 | EEM_Transaction::instance(), |
| 345 | 345 | 'TXN_total', |
| 346 | 346 | $reg_row['TransactionTable.TXN_total'], |
| 347 | 347 | 'localized_float' |
| 348 | 348 | ) : '0.00'; |
| 349 | - $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
| 349 | + $reg_csv_array[(string) __('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
| 350 | 350 | ? EEH_Export::prepare_value_from_db_for_display( |
| 351 | 351 | EEM_Transaction::instance(), |
| 352 | 352 | 'TXN_paid', |
@@ -377,14 +377,14 @@ discard block |
||
| 377 | 377 | ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | - $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
| 381 | - $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
| 382 | - $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
| 380 | + $reg_csv_array[(string) __('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
| 381 | + $reg_csv_array[(string) __('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
| 382 | + $reg_csv_array[(string) __('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
| 383 | 383 | ',', |
| 384 | 384 | $gateway_txn_ids_etc |
| 385 | 385 | ); |
| 386 | 386 | // get whether or not the user has checked in |
| 387 | - $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
| 387 | + $reg_csv_array[(string) __("Check-Ins", "event_espresso")] = $reg_model->count_related( |
|
| 388 | 388 | $reg_row['Registration.REG_ID'], |
| 389 | 389 | 'Checkin' |
| 390 | 390 | ); |
@@ -414,8 +414,8 @@ discard block |
||
| 414 | 414 | $ticket_name = __('Unknown', 'event_espresso'); |
| 415 | 415 | $datetimes_strings = array(__('Unknown', 'event_espresso')); |
| 416 | 416 | } |
| 417 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
| 418 | - $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
| 417 | + $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
| 418 | + $reg_csv_array[(string) __("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
| 419 | 419 | // get datetime(s) of registration |
| 420 | 420 | // add attendee columns |
| 421 | 421 | foreach ($att_fields_to_include as $att_field_name) { |
@@ -435,18 +435,18 @@ discard block |
||
| 435 | 435 | $value = EEH_Export::prepare_value_from_db_for_display( |
| 436 | 436 | EEM_Attendee::instance(), |
| 437 | 437 | $att_field_name, |
| 438 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
| 438 | + $reg_row[$field_obj->get_qualified_column()] |
|
| 439 | 439 | ); |
| 440 | 440 | } |
| 441 | 441 | } else { |
| 442 | 442 | $value = ''; |
| 443 | 443 | } |
| 444 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
| 444 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
| 445 | 445 | } |
| 446 | 446 | // make sure each registration has the same questions in the same order |
| 447 | 447 | foreach ($question_labels as $question_label) { |
| 448 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
| 449 | - $reg_csv_array[ $question_label ] = null; |
|
| 448 | + if ( ! isset($reg_csv_array[$question_label])) { |
|
| 449 | + $reg_csv_array[$question_label] = null; |
|
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
@@ -467,12 +467,12 @@ discard block |
||
| 467 | 467 | if (isset($answer_row['Question.QST_type']) |
| 468 | 468 | && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
| 469 | 469 | ) { |
| 470 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
| 470 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
| 471 | 471 | $answer_row['Answer.ANS_value'] |
| 472 | 472 | ); |
| 473 | 473 | } else { |
| 474 | 474 | // this isn't for html, so don't show html entities |
| 475 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
| 475 | + $reg_csv_array[$question_label] = html_entity_decode( |
|
| 476 | 476 | EEH_Export::prepare_value_from_db_for_display( |
| 477 | 477 | EEM_Answer::instance(), |
| 478 | 478 | 'ANS_value', |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | $model = EE_Registry::instance()->load_model($model_name); |
| 508 | 508 | foreach ($field_list as $field_name) { |
| 509 | 509 | $field = $model->field_settings_for($field_name); |
| 510 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
| 510 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null; |
|
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | $registrations_csv_ready_array[] = $reg_csv_array; |
@@ -22,310 +22,310 @@ |
||
| 22 | 22 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var string $editor_script_handle |
|
| 27 | - */ |
|
| 28 | - private $editor_script_handle; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string $editor_style_handle |
|
| 32 | - */ |
|
| 33 | - private $editor_style_handle; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string $script_handle |
|
| 37 | - */ |
|
| 38 | - private $script_handle; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string $style_handle |
|
| 42 | - */ |
|
| 43 | - private $style_handle; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function getEditorScriptHandle() |
|
| 50 | - { |
|
| 51 | - return $this->editor_script_handle; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $editor_script_handle |
|
| 57 | - */ |
|
| 58 | - public function setEditorScriptHandle($editor_script_handle) |
|
| 59 | - { |
|
| 60 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 61 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
| 62 | - } |
|
| 63 | - $this->editor_script_handle = $editor_script_handle; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function getEditorStyleHandle() |
|
| 71 | - { |
|
| 72 | - return $this->editor_style_handle; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $editor_style_handle |
|
| 78 | - */ |
|
| 79 | - public function setEditorStyleHandle($editor_style_handle) |
|
| 80 | - { |
|
| 81 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 82 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
| 83 | - } |
|
| 84 | - $this->editor_style_handle = $editor_style_handle; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function getScriptHandle() |
|
| 92 | - { |
|
| 93 | - return $this->script_handle; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param string $script_handle |
|
| 99 | - */ |
|
| 100 | - public function setScriptHandle($script_handle) |
|
| 101 | - { |
|
| 102 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 103 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
| 104 | - } |
|
| 105 | - $this->script_handle = $script_handle; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function getStyleHandle() |
|
| 113 | - { |
|
| 114 | - return $this->style_handle; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param string $style_handle |
|
| 120 | - */ |
|
| 121 | - public function setStyleHandle($style_handle) |
|
| 122 | - { |
|
| 123 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 124 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
| 125 | - } |
|
| 126 | - $this->style_handle = $style_handle; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @since $VID:$ |
|
| 131 | - * @throws InvalidDataTypeException |
|
| 132 | - * @throws InvalidEntityException |
|
| 133 | - * @throws DuplicateCollectionIdentifierException |
|
| 134 | - */ |
|
| 135 | - public function addAssets() |
|
| 136 | - { |
|
| 137 | - $this->addEditorScript($this->getEditorScriptHandle()); |
|
| 138 | - $this->addEditorStyle($this->getEditorStyleHandle()); |
|
| 139 | - $this->addScript($this->getScriptHandle()); |
|
| 140 | - $this->addStyle($this->getStyleHandle()); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param $handle |
|
| 146 | - * @param array $dependencies |
|
| 147 | - * @since $VID:$ |
|
| 148 | - * @return JavascriptAsset |
|
| 149 | - * @throws InvalidDataTypeException |
|
| 150 | - * @throws InvalidEntityException |
|
| 151 | - * @throws DuplicateCollectionIdentifierException |
|
| 152 | - */ |
|
| 153 | - public function addEditorScript($handle, array $dependencies = array()) |
|
| 154 | - { |
|
| 155 | - if($this->assets->hasJavascriptAsset($handle)){ |
|
| 156 | - return $this->assets->getJavascriptAsset($handle); |
|
| 157 | - } |
|
| 158 | - return parent::addJavascript( |
|
| 159 | - $handle, |
|
| 160 | - $this->registry->getJsUrl( |
|
| 161 | - $this->domain->assetNamespace(), |
|
| 162 | - $handle |
|
| 163 | - ), |
|
| 164 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
| 165 | - ) |
|
| 166 | - ->setRequiresTranslation(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param $handle |
|
| 172 | - * @param array $dependencies |
|
| 173 | - * @since $VID:$ |
|
| 174 | - * @return StylesheetAsset |
|
| 175 | - * @throws InvalidDataTypeException |
|
| 176 | - * @throws InvalidEntityException |
|
| 177 | - * @throws DuplicateCollectionIdentifierException |
|
| 178 | - */ |
|
| 179 | - public function addEditorStyle($handle, array $dependencies = array()) |
|
| 180 | - { |
|
| 181 | - if ($this->assets->hasStylesheetAsset($handle)) { |
|
| 182 | - return $this->assets->getStylesheetAsset($handle); |
|
| 183 | - } |
|
| 184 | - return parent::addStylesheet( |
|
| 185 | - $handle, |
|
| 186 | - $this->registry->getCssUrl( |
|
| 187 | - $this->domain->assetNamespace(), |
|
| 188 | - $handle |
|
| 189 | - ), |
|
| 190 | - $this->addDefaultBlockStyleDependencies($dependencies) |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param $handle |
|
| 197 | - * @param array $dependencies |
|
| 198 | - * @since $VID:$ |
|
| 199 | - * @return JavascriptAsset |
|
| 200 | - * @throws InvalidDataTypeException |
|
| 201 | - * @throws InvalidEntityException |
|
| 202 | - * @throws DuplicateCollectionIdentifierException |
|
| 203 | - */ |
|
| 204 | - public function addScript($handle, array $dependencies = array()) |
|
| 205 | - { |
|
| 206 | - if ($this->assets->hasJavascriptAsset($handle)) { |
|
| 207 | - return $this->assets->getJavascriptAsset($handle); |
|
| 208 | - } |
|
| 209 | - return parent::addJavascript( |
|
| 210 | - $handle, |
|
| 211 | - $this->registry->getJsUrl( |
|
| 212 | - $this->domain->assetNamespace(), |
|
| 213 | - $handle |
|
| 214 | - ), |
|
| 215 | - $dependencies + array( CoreAssetManager::JS_HANDLE_COMPONENTS ) |
|
| 216 | - ) |
|
| 217 | - ->setRequiresTranslation(); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * @param $handle |
|
| 223 | - * @param array $dependencies |
|
| 224 | - * @since $VID:$ |
|
| 225 | - * @return StylesheetAsset |
|
| 226 | - * @throws InvalidDataTypeException |
|
| 227 | - * @throws InvalidEntityException |
|
| 228 | - * @throws DuplicateCollectionIdentifierException |
|
| 229 | - */ |
|
| 230 | - public function addStyle($handle, array $dependencies = array()) |
|
| 231 | - { |
|
| 232 | - if ($this->assets->hasStylesheetAsset($handle)) { |
|
| 233 | - return $this->assets->getStylesheetAsset($handle); |
|
| 234 | - } |
|
| 235 | - return parent::addStylesheet( |
|
| 236 | - $handle, |
|
| 237 | - $this->registry->getCssUrl( |
|
| 238 | - $this->domain->assetNamespace(), |
|
| 239 | - $handle |
|
| 240 | - ), |
|
| 241 | - $dependencies + array( CoreAssetManager::CSS_HANDLE_COMPONENTS ) |
|
| 242 | - ); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param array $dependencies |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
| 251 | - { |
|
| 252 | - $dependencies += array( |
|
| 253 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 254 | - 'wp-i18n', // Provides localization functions |
|
| 255 | - 'wp-element', // Provides React.Component |
|
| 256 | - 'wp-components', // Provides many prebuilt components and controls |
|
| 257 | - CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
|
| 258 | - $this->getScriptHandle(), |
|
| 259 | - ); |
|
| 260 | - return $dependencies; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @param array $dependencies |
|
| 266 | - * @return array |
|
| 267 | - */ |
|
| 268 | - protected function addDefaultBlockStyleDependencies(array $dependencies) |
|
| 269 | - { |
|
| 270 | - $dependencies += array( |
|
| 271 | - $this->getStyleHandle() |
|
| 272 | - ); |
|
| 273 | - return $dependencies; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return JavascriptAsset|null |
|
| 279 | - */ |
|
| 280 | - public function getEditorScript() |
|
| 281 | - { |
|
| 282 | - return $this->assets->getJavascriptAsset($this->editor_script_handle); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @return StylesheetAsset|null |
|
| 288 | - */ |
|
| 289 | - public function getEditorStyle() |
|
| 290 | - { |
|
| 291 | - return $this->assets->getStylesheetAsset($this->editor_style_handle); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @return JavascriptAsset|null |
|
| 297 | - */ |
|
| 298 | - public function getScript() |
|
| 299 | - { |
|
| 300 | - return $this->assets->getJavascriptAsset($this->script_handle); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @return StylesheetAsset|null |
|
| 306 | - */ |
|
| 307 | - public function getStyle() |
|
| 308 | - { |
|
| 309 | - return $this->assets->getStylesheetAsset($this->style_handle); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @return void |
|
| 315 | - */ |
|
| 316 | - public function enqueueAssets() |
|
| 317 | - { |
|
| 318 | - $assets = array( |
|
| 319 | - $this->getEditorScript(), |
|
| 320 | - $this->getEditorStyle(), |
|
| 321 | - $this->getScript(), |
|
| 322 | - $this->getStyle(), |
|
| 323 | - ); |
|
| 324 | - foreach ($assets as $asset) { |
|
| 325 | - if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
| 326 | - $asset->enqueueAsset(); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - } |
|
| 25 | + /** |
|
| 26 | + * @var string $editor_script_handle |
|
| 27 | + */ |
|
| 28 | + private $editor_script_handle; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string $editor_style_handle |
|
| 32 | + */ |
|
| 33 | + private $editor_style_handle; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string $script_handle |
|
| 37 | + */ |
|
| 38 | + private $script_handle; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string $style_handle |
|
| 42 | + */ |
|
| 43 | + private $style_handle; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function getEditorScriptHandle() |
|
| 50 | + { |
|
| 51 | + return $this->editor_script_handle; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $editor_script_handle |
|
| 57 | + */ |
|
| 58 | + public function setEditorScriptHandle($editor_script_handle) |
|
| 59 | + { |
|
| 60 | + if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 61 | + $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
| 62 | + } |
|
| 63 | + $this->editor_script_handle = $editor_script_handle; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function getEditorStyleHandle() |
|
| 71 | + { |
|
| 72 | + return $this->editor_style_handle; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $editor_style_handle |
|
| 78 | + */ |
|
| 79 | + public function setEditorStyleHandle($editor_style_handle) |
|
| 80 | + { |
|
| 81 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 82 | + $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
| 83 | + } |
|
| 84 | + $this->editor_style_handle = $editor_style_handle; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function getScriptHandle() |
|
| 92 | + { |
|
| 93 | + return $this->script_handle; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param string $script_handle |
|
| 99 | + */ |
|
| 100 | + public function setScriptHandle($script_handle) |
|
| 101 | + { |
|
| 102 | + if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 103 | + $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
| 104 | + } |
|
| 105 | + $this->script_handle = $script_handle; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function getStyleHandle() |
|
| 113 | + { |
|
| 114 | + return $this->style_handle; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param string $style_handle |
|
| 120 | + */ |
|
| 121 | + public function setStyleHandle($style_handle) |
|
| 122 | + { |
|
| 123 | + if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 124 | + $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
| 125 | + } |
|
| 126 | + $this->style_handle = $style_handle; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @since $VID:$ |
|
| 131 | + * @throws InvalidDataTypeException |
|
| 132 | + * @throws InvalidEntityException |
|
| 133 | + * @throws DuplicateCollectionIdentifierException |
|
| 134 | + */ |
|
| 135 | + public function addAssets() |
|
| 136 | + { |
|
| 137 | + $this->addEditorScript($this->getEditorScriptHandle()); |
|
| 138 | + $this->addEditorStyle($this->getEditorStyleHandle()); |
|
| 139 | + $this->addScript($this->getScriptHandle()); |
|
| 140 | + $this->addStyle($this->getStyleHandle()); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param $handle |
|
| 146 | + * @param array $dependencies |
|
| 147 | + * @since $VID:$ |
|
| 148 | + * @return JavascriptAsset |
|
| 149 | + * @throws InvalidDataTypeException |
|
| 150 | + * @throws InvalidEntityException |
|
| 151 | + * @throws DuplicateCollectionIdentifierException |
|
| 152 | + */ |
|
| 153 | + public function addEditorScript($handle, array $dependencies = array()) |
|
| 154 | + { |
|
| 155 | + if($this->assets->hasJavascriptAsset($handle)){ |
|
| 156 | + return $this->assets->getJavascriptAsset($handle); |
|
| 157 | + } |
|
| 158 | + return parent::addJavascript( |
|
| 159 | + $handle, |
|
| 160 | + $this->registry->getJsUrl( |
|
| 161 | + $this->domain->assetNamespace(), |
|
| 162 | + $handle |
|
| 163 | + ), |
|
| 164 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
| 165 | + ) |
|
| 166 | + ->setRequiresTranslation(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param $handle |
|
| 172 | + * @param array $dependencies |
|
| 173 | + * @since $VID:$ |
|
| 174 | + * @return StylesheetAsset |
|
| 175 | + * @throws InvalidDataTypeException |
|
| 176 | + * @throws InvalidEntityException |
|
| 177 | + * @throws DuplicateCollectionIdentifierException |
|
| 178 | + */ |
|
| 179 | + public function addEditorStyle($handle, array $dependencies = array()) |
|
| 180 | + { |
|
| 181 | + if ($this->assets->hasStylesheetAsset($handle)) { |
|
| 182 | + return $this->assets->getStylesheetAsset($handle); |
|
| 183 | + } |
|
| 184 | + return parent::addStylesheet( |
|
| 185 | + $handle, |
|
| 186 | + $this->registry->getCssUrl( |
|
| 187 | + $this->domain->assetNamespace(), |
|
| 188 | + $handle |
|
| 189 | + ), |
|
| 190 | + $this->addDefaultBlockStyleDependencies($dependencies) |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param $handle |
|
| 197 | + * @param array $dependencies |
|
| 198 | + * @since $VID:$ |
|
| 199 | + * @return JavascriptAsset |
|
| 200 | + * @throws InvalidDataTypeException |
|
| 201 | + * @throws InvalidEntityException |
|
| 202 | + * @throws DuplicateCollectionIdentifierException |
|
| 203 | + */ |
|
| 204 | + public function addScript($handle, array $dependencies = array()) |
|
| 205 | + { |
|
| 206 | + if ($this->assets->hasJavascriptAsset($handle)) { |
|
| 207 | + return $this->assets->getJavascriptAsset($handle); |
|
| 208 | + } |
|
| 209 | + return parent::addJavascript( |
|
| 210 | + $handle, |
|
| 211 | + $this->registry->getJsUrl( |
|
| 212 | + $this->domain->assetNamespace(), |
|
| 213 | + $handle |
|
| 214 | + ), |
|
| 215 | + $dependencies + array( CoreAssetManager::JS_HANDLE_COMPONENTS ) |
|
| 216 | + ) |
|
| 217 | + ->setRequiresTranslation(); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @param $handle |
|
| 223 | + * @param array $dependencies |
|
| 224 | + * @since $VID:$ |
|
| 225 | + * @return StylesheetAsset |
|
| 226 | + * @throws InvalidDataTypeException |
|
| 227 | + * @throws InvalidEntityException |
|
| 228 | + * @throws DuplicateCollectionIdentifierException |
|
| 229 | + */ |
|
| 230 | + public function addStyle($handle, array $dependencies = array()) |
|
| 231 | + { |
|
| 232 | + if ($this->assets->hasStylesheetAsset($handle)) { |
|
| 233 | + return $this->assets->getStylesheetAsset($handle); |
|
| 234 | + } |
|
| 235 | + return parent::addStylesheet( |
|
| 236 | + $handle, |
|
| 237 | + $this->registry->getCssUrl( |
|
| 238 | + $this->domain->assetNamespace(), |
|
| 239 | + $handle |
|
| 240 | + ), |
|
| 241 | + $dependencies + array( CoreAssetManager::CSS_HANDLE_COMPONENTS ) |
|
| 242 | + ); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param array $dependencies |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
| 251 | + { |
|
| 252 | + $dependencies += array( |
|
| 253 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 254 | + 'wp-i18n', // Provides localization functions |
|
| 255 | + 'wp-element', // Provides React.Component |
|
| 256 | + 'wp-components', // Provides many prebuilt components and controls |
|
| 257 | + CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
|
| 258 | + $this->getScriptHandle(), |
|
| 259 | + ); |
|
| 260 | + return $dependencies; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @param array $dependencies |
|
| 266 | + * @return array |
|
| 267 | + */ |
|
| 268 | + protected function addDefaultBlockStyleDependencies(array $dependencies) |
|
| 269 | + { |
|
| 270 | + $dependencies += array( |
|
| 271 | + $this->getStyleHandle() |
|
| 272 | + ); |
|
| 273 | + return $dependencies; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return JavascriptAsset|null |
|
| 279 | + */ |
|
| 280 | + public function getEditorScript() |
|
| 281 | + { |
|
| 282 | + return $this->assets->getJavascriptAsset($this->editor_script_handle); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @return StylesheetAsset|null |
|
| 288 | + */ |
|
| 289 | + public function getEditorStyle() |
|
| 290 | + { |
|
| 291 | + return $this->assets->getStylesheetAsset($this->editor_style_handle); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @return JavascriptAsset|null |
|
| 297 | + */ |
|
| 298 | + public function getScript() |
|
| 299 | + { |
|
| 300 | + return $this->assets->getJavascriptAsset($this->script_handle); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @return StylesheetAsset|null |
|
| 306 | + */ |
|
| 307 | + public function getStyle() |
|
| 308 | + { |
|
| 309 | + return $this->assets->getStylesheetAsset($this->style_handle); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @return void |
|
| 315 | + */ |
|
| 316 | + public function enqueueAssets() |
|
| 317 | + { |
|
| 318 | + $assets = array( |
|
| 319 | + $this->getEditorScript(), |
|
| 320 | + $this->getEditorStyle(), |
|
| 321 | + $this->getScript(), |
|
| 322 | + $this->getStyle(), |
|
| 323 | + ); |
|
| 324 | + foreach ($assets as $asset) { |
|
| 325 | + if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
| 326 | + $asset->enqueueAsset(); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | 331 | } |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function setEditorScriptHandle($editor_script_handle) |
| 59 | 59 | { |
| 60 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 61 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
| 60 | + if (strpos($editor_script_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
| 61 | + $editor_script_handle = BlockInterface::NAME_SPACE.'-'.$editor_script_handle; |
|
| 62 | 62 | } |
| 63 | 63 | $this->editor_script_handle = $editor_script_handle; |
| 64 | 64 | } |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function setEditorStyleHandle($editor_style_handle) |
| 80 | 80 | { |
| 81 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 82 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
| 81 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
| 82 | + $editor_style_handle = BlockInterface::NAME_SPACE.'-'.$editor_style_handle; |
|
| 83 | 83 | } |
| 84 | 84 | $this->editor_style_handle = $editor_style_handle; |
| 85 | 85 | } |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function setScriptHandle($script_handle) |
| 101 | 101 | { |
| 102 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 103 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
| 102 | + if (strpos($script_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
| 103 | + $script_handle = BlockInterface::NAME_SPACE.'-'.$script_handle; |
|
| 104 | 104 | } |
| 105 | 105 | $this->script_handle = $script_handle; |
| 106 | 106 | } |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function setStyleHandle($style_handle) |
| 122 | 122 | { |
| 123 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
| 124 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
| 123 | + if (strpos($style_handle, BlockInterface::NAME_SPACE.'-') !== 0) { |
|
| 124 | + $style_handle = BlockInterface::NAME_SPACE.'-'.$style_handle; |
|
| 125 | 125 | } |
| 126 | 126 | $this->style_handle = $style_handle; |
| 127 | 127 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function addEditorScript($handle, array $dependencies = array()) |
| 154 | 154 | { |
| 155 | - if($this->assets->hasJavascriptAsset($handle)){ |
|
| 155 | + if ($this->assets->hasJavascriptAsset($handle)) { |
|
| 156 | 156 | return $this->assets->getJavascriptAsset($handle); |
| 157 | 157 | } |
| 158 | 158 | return parent::addJavascript( |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $this->domain->assetNamespace(), |
| 213 | 213 | $handle |
| 214 | 214 | ), |
| 215 | - $dependencies + array( CoreAssetManager::JS_HANDLE_COMPONENTS ) |
|
| 215 | + $dependencies + array(CoreAssetManager::JS_HANDLE_COMPONENTS) |
|
| 216 | 216 | ) |
| 217 | 217 | ->setRequiresTranslation(); |
| 218 | 218 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $this->domain->assetNamespace(), |
| 239 | 239 | $handle |
| 240 | 240 | ), |
| 241 | - $dependencies + array( CoreAssetManager::CSS_HANDLE_COMPONENTS ) |
|
| 241 | + $dependencies + array(CoreAssetManager::CSS_HANDLE_COMPONENTS) |
|
| 242 | 242 | ); |
| 243 | 243 | } |
| 244 | 244 | |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | protected function addDefaultBlockScriptDependencies(array $dependencies) |
| 251 | 251 | { |
| 252 | 252 | $dependencies += array( |
| 253 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 254 | - 'wp-i18n', // Provides localization functions |
|
| 255 | - 'wp-element', // Provides React.Component |
|
| 253 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
| 254 | + 'wp-i18n', // Provides localization functions |
|
| 255 | + 'wp-element', // Provides React.Component |
|
| 256 | 256 | 'wp-components', // Provides many prebuilt components and controls |
| 257 | 257 | CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
| 258 | 258 | $this->getScriptHandle(), |
@@ -330,11 +330,11 @@ discard block |
||
| 330 | 330 | |
| 331 | 331 | $this->addJavascript( |
| 332 | 332 | CoreAssetManager::JS_HANDLE_CORE, |
| 333 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 333 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
| 334 | 334 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
| 335 | 335 | ) |
| 336 | 336 | ->setInlineDataCallback( |
| 337 | - function () { |
|
| 337 | + function() { |
|
| 338 | 338 | wp_localize_script( |
| 339 | 339 | CoreAssetManager::JS_HANDLE_CORE, |
| 340 | 340 | CoreAssetManager::JS_HANDLE_I18N, |
@@ -438,16 +438,16 @@ discard block |
||
| 438 | 438 | if ($this->template_config->enable_default_style && ! is_admin()) { |
| 439 | 439 | $this->addStylesheet( |
| 440 | 440 | CoreAssetManager::CSS_HANDLE_DEFAULT, |
| 441 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 441 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
| 442 | 442 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
| 443 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 443 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
| 444 | 444 | array('dashicons') |
| 445 | 445 | ); |
| 446 | 446 | //Load custom style sheet if available |
| 447 | 447 | if ($this->template_config->custom_style_sheet !== null) { |
| 448 | 448 | $this->addStylesheet( |
| 449 | 449 | CoreAssetManager::CSS_HANDLE_CUSTOM, |
| 450 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 450 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
| 451 | 451 | array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
| 452 | 452 | ); |
| 453 | 453 | } |
@@ -475,14 +475,14 @@ discard block |
||
| 475 | 475 | { |
| 476 | 476 | $this->addJavascript( |
| 477 | 477 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
| 478 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 478 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
| 479 | 479 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
| 480 | 480 | ) |
| 481 | 481 | ->setVersion('1.15.0'); |
| 482 | 482 | |
| 483 | 483 | $this->addJavascript( |
| 484 | 484 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
| 485 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 485 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
| 486 | 486 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
| 487 | 487 | ) |
| 488 | 488 | ->setVersion('1.15.0'); |
@@ -504,18 +504,18 @@ discard block |
||
| 504 | 504 | // @link http://josscrowcroft.github.io/accounting.js/ |
| 505 | 505 | $this->addJavascript( |
| 506 | 506 | CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
| 507 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 507 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
| 508 | 508 | array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
| 509 | 509 | ) |
| 510 | 510 | ->setVersion('0.3.2'); |
| 511 | 511 | |
| 512 | 512 | $this->addJavascript( |
| 513 | 513 | CoreAssetManager::JS_HANDLE_ACCOUNTING, |
| 514 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 514 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
| 515 | 515 | array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
| 516 | 516 | ) |
| 517 | 517 | ->setInlineDataCallback( |
| 518 | - function () { |
|
| 518 | + function() { |
|
| 519 | 519 | wp_localize_script( |
| 520 | 520 | CoreAssetManager::JS_HANDLE_ACCOUNTING, |
| 521 | 521 | 'EE_ACCOUNTING_CFG', |
@@ -31,543 +31,543 @@ |
||
| 31 | 31 | class CoreAssetManager extends AssetManager |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - // WordPress core / Third party JS asset handles |
|
| 35 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
| 34 | + // WordPress core / Third party JS asset handles |
|
| 35 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
| 36 | 36 | |
| 37 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 37 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
| 38 | 38 | |
| 39 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 39 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
| 40 | 40 | |
| 41 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 41 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
| 42 | 42 | |
| 43 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 43 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @since $VID:$ |
|
| 47 | - */ |
|
| 48 | - const JS_HANDLE_REACT = 'react'; |
|
| 45 | + /** |
|
| 46 | + * @since $VID:$ |
|
| 47 | + */ |
|
| 48 | + const JS_HANDLE_REACT = 'react'; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @since $VID:$ |
|
| 52 | - */ |
|
| 53 | - const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
| 50 | + /** |
|
| 51 | + * @since $VID:$ |
|
| 52 | + */ |
|
| 53 | + const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @since $VID:$ |
|
| 57 | - */ |
|
| 58 | - const JS_HANDLE_LODASH = 'lodash'; |
|
| 55 | + /** |
|
| 56 | + * @since $VID:$ |
|
| 57 | + */ |
|
| 58 | + const JS_HANDLE_LODASH = 'lodash'; |
|
| 59 | 59 | |
| 60 | - // EE JS assets handles |
|
| 61 | - const JS_HANDLE_MANIFEST = 'ee-manifest'; |
|
| 60 | + // EE JS assets handles |
|
| 61 | + const JS_HANDLE_MANIFEST = 'ee-manifest'; |
|
| 62 | 62 | |
| 63 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
| 63 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
| 64 | 64 | |
| 65 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 65 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
| 66 | 66 | |
| 67 | - const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
| 67 | + const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
| 68 | 68 | |
| 69 | - const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
| 69 | + const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
| 70 | 70 | |
| 71 | - const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
| 71 | + const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
| 72 | 72 | |
| 73 | - const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
| 73 | + const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
| 74 | 74 | |
| 75 | - const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
| 75 | + const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
| 76 | 76 | |
| 77 | - const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 78 | - |
|
| 79 | - const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
| 77 | + const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 78 | + |
|
| 79 | + const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
| 80 | 80 | |
| 81 | - const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
| 81 | + const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
| 82 | 82 | |
| 83 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
| 83 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
| 84 | 84 | |
| 85 | - const JS_HANDLE_I18N = 'eei18n'; |
|
| 86 | - |
|
| 87 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
| 88 | - |
|
| 89 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 90 | - |
|
| 91 | - // EE CSS assets handles |
|
| 92 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
| 93 | - |
|
| 94 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
| 95 | - |
|
| 96 | - const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var EE_Currency_Config $currency_config |
|
| 100 | - */ |
|
| 101 | - protected $currency_config; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var EE_Template_Config $template_config |
|
| 105 | - */ |
|
| 106 | - protected $template_config; |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * CoreAssetRegister constructor. |
|
| 111 | - * |
|
| 112 | - * @param AssetCollection $assets |
|
| 113 | - * @param EE_Currency_Config $currency_config |
|
| 114 | - * @param EE_Template_Config $template_config |
|
| 115 | - * @param DomainInterface $domain |
|
| 116 | - * @param Registry $registry |
|
| 117 | - */ |
|
| 118 | - public function __construct( |
|
| 119 | - AssetCollection $assets, |
|
| 120 | - EE_Currency_Config $currency_config, |
|
| 121 | - EE_Template_Config $template_config, |
|
| 122 | - DomainInterface $domain, |
|
| 123 | - Registry $registry |
|
| 124 | - ) { |
|
| 125 | - $this->currency_config = $currency_config; |
|
| 126 | - $this->template_config = $template_config; |
|
| 127 | - parent::__construct($domain, $assets, $registry); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @since 4.9.62.p |
|
| 133 | - * @throws DomainException |
|
| 134 | - * @throws DuplicateCollectionIdentifierException |
|
| 135 | - * @throws InvalidArgumentException |
|
| 136 | - * @throws InvalidDataTypeException |
|
| 137 | - * @throws InvalidEntityException |
|
| 138 | - * @throws InvalidInterfaceException |
|
| 139 | - */ |
|
| 140 | - public function addAssets() |
|
| 141 | - { |
|
| 142 | - $this->addJavascriptFiles(); |
|
| 143 | - $this->addStylesheetFiles(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @since 4.9.62.p |
|
| 149 | - * @throws DomainException |
|
| 150 | - * @throws DuplicateCollectionIdentifierException |
|
| 151 | - * @throws InvalidArgumentException |
|
| 152 | - * @throws InvalidDataTypeException |
|
| 153 | - * @throws InvalidEntityException |
|
| 154 | - * @throws InvalidInterfaceException |
|
| 155 | - */ |
|
| 156 | - public function addJavascriptFiles() |
|
| 157 | - { |
|
| 158 | - $this->loadCoreJs(); |
|
| 159 | - $this->loadJqueryValidate(); |
|
| 160 | - $this->loadAccountingJs(); |
|
| 161 | - add_action( |
|
| 162 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 163 | - array($this, 'loadQtipJs') |
|
| 164 | - ); |
|
| 165 | - $this->registerAdminAssets(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @since 4.9.62.p |
|
| 171 | - * @throws DuplicateCollectionIdentifierException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidEntityException |
|
| 174 | - */ |
|
| 175 | - public function addStylesheetFiles() |
|
| 176 | - { |
|
| 177 | - $this->loadCoreCss(); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * core default javascript |
|
| 183 | - * |
|
| 184 | - * @since 4.9.62.p |
|
| 185 | - * @throws DomainException |
|
| 186 | - * @throws DuplicateCollectionIdentifierException |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidEntityException |
|
| 190 | - * @throws InvalidInterfaceException |
|
| 191 | - */ |
|
| 192 | - private function loadCoreJs() |
|
| 193 | - { |
|
| 194 | - // conditionally load third-party libraries that WP core MIGHT have. |
|
| 195 | - $this->registerWpAssets(); |
|
| 196 | - |
|
| 197 | - $this->addJavascript( |
|
| 198 | - CoreAssetManager::JS_HANDLE_MANIFEST, |
|
| 199 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 200 | - ); |
|
| 201 | - |
|
| 202 | - $this->addJavascript( |
|
| 203 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 204 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 205 | - array(CoreAssetManager::JS_HANDLE_MANIFEST) |
|
| 206 | - ) |
|
| 207 | - ->setHasInlineData(); |
|
| 208 | - |
|
| 209 | - $this->addJavascript( |
|
| 210 | - CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 211 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'), |
|
| 212 | - array( |
|
| 213 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 214 | - CoreAssetManager::JS_HANDLE_REACT, |
|
| 215 | - CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 216 | - CoreAssetManager::JS_HANDLE_LODASH, |
|
| 217 | - ) |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - $this->addJavascript( |
|
| 221 | - CoreAssetManager::JS_HANDLE_VALIDATORS, |
|
| 222 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'validators') |
|
| 223 | - )->setRequiresTranslation(); |
|
| 224 | - |
|
| 225 | - $this->addJavascript( |
|
| 226 | - CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 227 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'), |
|
| 228 | - array( |
|
| 229 | - CoreAssetManager::JS_HANDLE_VALIDATORS |
|
| 230 | - ) |
|
| 231 | - )->setRequiresTranslation(); |
|
| 232 | - |
|
| 233 | - $this->addJavascript( |
|
| 234 | - CoreAssetManager::JS_HANDLE_MODEL, |
|
| 235 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'), |
|
| 236 | - array( |
|
| 237 | - CoreAssetManager::JS_HANDLE_HELPERS |
|
| 238 | - ) |
|
| 239 | - )->setRequiresTranslation(); |
|
| 240 | - |
|
| 241 | - $this->addJavascript( |
|
| 242 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 243 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'), |
|
| 244 | - array( |
|
| 245 | - CoreAssetManager::JS_HANDLE_MODEL |
|
| 246 | - ) |
|
| 247 | - )->setRequiresTranslation(); |
|
| 248 | - |
|
| 249 | - $this->addJavascript( |
|
| 250 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 251 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'), |
|
| 252 | - array( |
|
| 253 | - CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 254 | - 'wp-data', |
|
| 255 | - 'wp-api-request', |
|
| 256 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS |
|
| 257 | - ) |
|
| 258 | - ) |
|
| 259 | - ->setRequiresTranslation(); |
|
| 260 | - |
|
| 261 | - $this->addJavascript( |
|
| 262 | - CoreAssetManager::JS_HANDLE_HOCS, |
|
| 263 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'), |
|
| 264 | - array( |
|
| 265 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 266 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 267 | - 'wp-components', |
|
| 268 | - ) |
|
| 269 | - )->setRequiresTranslation(); |
|
| 270 | - |
|
| 271 | - $this->addJavascript( |
|
| 272 | - CoreAssetManager::JS_HANDLE_COMPONENTS, |
|
| 273 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'), |
|
| 274 | - array( |
|
| 275 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 276 | - CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 277 | - 'wp-components', |
|
| 278 | - ) |
|
| 279 | - ) |
|
| 280 | - ->setRequiresTranslation(); |
|
| 281 | - |
|
| 282 | - $this->addJavascript( |
|
| 283 | - CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
|
| 284 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'), |
|
| 285 | - array( |
|
| 286 | - CoreAssetManager::JS_HANDLE_COMPONENTS |
|
| 287 | - ) |
|
| 288 | - )->setRequiresTranslation(); |
|
| 289 | - |
|
| 290 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 291 | - $this->registry->addData( |
|
| 292 | - 'paths', |
|
| 293 | - array( |
|
| 294 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
| 295 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
| 296 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
| 297 | - 'site_url' => site_url('/'), |
|
| 298 | - 'admin_url' => admin_url('/'), |
|
| 299 | - ) |
|
| 300 | - ); |
|
| 301 | - /** site formatting values **/ |
|
| 302 | - $this->registry->addData( |
|
| 303 | - 'site_formats', |
|
| 304 | - array( |
|
| 305 | - 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
| 306 | - ) |
|
| 307 | - ); |
|
| 308 | - /** currency data **/ |
|
| 309 | - $this->registry->addData( |
|
| 310 | - 'currency_config', |
|
| 311 | - $this->getCurrencySettings() |
|
| 312 | - ); |
|
| 313 | - /** site timezone */ |
|
| 314 | - $this->registry->addData( |
|
| 315 | - 'default_timezone', |
|
| 316 | - array( |
|
| 317 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
| 318 | - 'string' => get_option('timezone_string'), |
|
| 319 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
| 320 | - ) |
|
| 321 | - ); |
|
| 322 | - /** site locale (user locale if user logged in) */ |
|
| 323 | - $this->registry->addData( |
|
| 324 | - 'locale', |
|
| 325 | - array( |
|
| 326 | - 'user' => get_user_locale(), |
|
| 327 | - 'site' => get_locale() |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - $this->addJavascript( |
|
| 332 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 333 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 334 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 335 | - ) |
|
| 336 | - ->setInlineDataCallback( |
|
| 337 | - function () { |
|
| 338 | - wp_localize_script( |
|
| 339 | - CoreAssetManager::JS_HANDLE_CORE, |
|
| 340 | - CoreAssetManager::JS_HANDLE_I18N, |
|
| 341 | - EE_Registry::$i18n_js_strings |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
| 350 | - * WordPress in the running environment. |
|
| 351 | - * |
|
| 352 | - * @throws DuplicateCollectionIdentifierException |
|
| 353 | - * @throws InvalidDataTypeException |
|
| 354 | - * @throws InvalidEntityException |
|
| 355 | - * @throws DomainException |
|
| 356 | - * @since $VID:$ |
|
| 357 | - */ |
|
| 358 | - private function registerWpAssets() |
|
| 359 | - { |
|
| 360 | - global $wp_version; |
|
| 361 | - if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
| 362 | - return; |
|
| 363 | - } |
|
| 364 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT) |
|
| 365 | - ->setVersion('16.6.0'); |
|
| 366 | - $this->addVendorJavascript( |
|
| 367 | - CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 368 | - array(CoreAssetManager::JS_HANDLE_REACT) |
|
| 369 | - )->setVersion('16.6.0'); |
|
| 370 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH) |
|
| 371 | - ->setInlineDataCallback( |
|
| 372 | - function() { |
|
| 373 | - wp_add_inline_script( |
|
| 374 | - CoreAssetManager::JS_HANDLE_LODASH, |
|
| 375 | - 'window.lodash = _.noConflict();' |
|
| 376 | - ); |
|
| 377 | - } |
|
| 378 | - ) |
|
| 379 | - ->setVersion('4.17.11'); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Returns configuration data for the accounting-js library. |
|
| 385 | - * @since $VID:$ |
|
| 386 | - * @return array |
|
| 387 | - */ |
|
| 388 | - private function getAccountingSettings() { |
|
| 389 | - return array( |
|
| 390 | - 'currency' => array( |
|
| 391 | - 'symbol' => $this->currency_config->sign, |
|
| 392 | - 'format' => array( |
|
| 393 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 394 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 395 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 396 | - ), |
|
| 397 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 398 | - 'thousand' => $this->currency_config->thsnds, |
|
| 399 | - 'precision' => $this->currency_config->dec_plc, |
|
| 400 | - ), |
|
| 401 | - 'number' => array( |
|
| 402 | - 'precision' => $this->currency_config->dec_plc, |
|
| 403 | - 'thousand' => $this->currency_config->thsnds, |
|
| 404 | - 'decimal' => $this->currency_config->dec_mrk, |
|
| 405 | - ), |
|
| 406 | - ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Returns configuration data for the js Currency VO. |
|
| 412 | - * @since $VID:$ |
|
| 413 | - * @return array |
|
| 414 | - */ |
|
| 415 | - private function getCurrencySettings() |
|
| 416 | - { |
|
| 417 | - return array( |
|
| 418 | - 'code' => $this->currency_config->code, |
|
| 419 | - 'singularLabel' => $this->currency_config->name, |
|
| 420 | - 'pluralLabel' => $this->currency_config->plural, |
|
| 421 | - 'sign' => $this->currency_config->sign, |
|
| 422 | - 'signB4' => $this->currency_config->sign_b4, |
|
| 423 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
| 424 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
| 425 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @since 4.9.62.p |
|
| 432 | - * @throws DuplicateCollectionIdentifierException |
|
| 433 | - * @throws InvalidDataTypeException |
|
| 434 | - * @throws InvalidEntityException |
|
| 435 | - */ |
|
| 436 | - private function loadCoreCss() |
|
| 437 | - { |
|
| 438 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 439 | - $this->addStylesheet( |
|
| 440 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
| 441 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 442 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 443 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 444 | - array('dashicons') |
|
| 445 | - ); |
|
| 446 | - //Load custom style sheet if available |
|
| 447 | - if ($this->template_config->custom_style_sheet !== null) { |
|
| 448 | - $this->addStylesheet( |
|
| 449 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
| 450 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 451 | - array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
| 452 | - ); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - $this->addStylesheet( |
|
| 456 | - CoreAssetManager::CSS_HANDLE_COMPONENTS, |
|
| 457 | - $this->registry->getCssUrl( |
|
| 458 | - $this->domain->assetNamespace(), |
|
| 459 | - 'components' |
|
| 460 | - ) |
|
| 461 | - ); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * jQuery Validate for form validation |
|
| 467 | - * |
|
| 468 | - * @since 4.9.62.p |
|
| 469 | - * @throws DomainException |
|
| 470 | - * @throws DuplicateCollectionIdentifierException |
|
| 471 | - * @throws InvalidDataTypeException |
|
| 472 | - * @throws InvalidEntityException |
|
| 473 | - */ |
|
| 474 | - private function loadJqueryValidate() |
|
| 475 | - { |
|
| 476 | - $this->addJavascript( |
|
| 477 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 478 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 479 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 480 | - ) |
|
| 481 | - ->setVersion('1.15.0'); |
|
| 482 | - |
|
| 483 | - $this->addJavascript( |
|
| 484 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 485 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 486 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 487 | - ) |
|
| 488 | - ->setVersion('1.15.0'); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * accounting.js for performing client-side calculations |
|
| 494 | - * |
|
| 495 | - * @since 4.9.62.p |
|
| 496 | - * @throws DomainException |
|
| 497 | - * @throws DuplicateCollectionIdentifierException |
|
| 498 | - * @throws InvalidDataTypeException |
|
| 499 | - * @throws InvalidEntityException |
|
| 500 | - */ |
|
| 501 | - private function loadAccountingJs() |
|
| 502 | - { |
|
| 503 | - //accounting.js library |
|
| 504 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 505 | - $this->addJavascript( |
|
| 506 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 507 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 508 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 509 | - ) |
|
| 510 | - ->setVersion('0.3.2'); |
|
| 511 | - |
|
| 512 | - $this->addJavascript( |
|
| 513 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 514 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 515 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 516 | - ) |
|
| 517 | - ->setInlineDataCallback( |
|
| 518 | - function () { |
|
| 519 | - wp_localize_script( |
|
| 520 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 521 | - 'EE_ACCOUNTING_CFG', |
|
| 522 | - $this->getAccountingSettings() |
|
| 523 | - ); |
|
| 524 | - } |
|
| 525 | - ) |
|
| 526 | - ->setVersion(); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * registers assets for cleaning your ears |
|
| 532 | - * |
|
| 533 | - * @param JavascriptAsset $script |
|
| 534 | - */ |
|
| 535 | - public function loadQtipJs(JavascriptAsset $script) |
|
| 536 | - { |
|
| 537 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 538 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 539 | - if ( |
|
| 540 | - $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
| 541 | - && apply_filters('FHEE_load_qtip', false) |
|
| 542 | - ) { |
|
| 543 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * assets that are used in the WordPress admin |
|
| 550 | - * |
|
| 551 | - * @since 4.9.62.p |
|
| 552 | - * @throws DuplicateCollectionIdentifierException |
|
| 553 | - * @throws InvalidDataTypeException |
|
| 554 | - * @throws InvalidEntityException |
|
| 555 | - */ |
|
| 556 | - private function registerAdminAssets() |
|
| 557 | - { |
|
| 558 | - $this->addJavascript( |
|
| 559 | - CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 560 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 561 | - array( |
|
| 562 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 563 | - CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 564 | - ) |
|
| 565 | - ) |
|
| 566 | - ->setRequiresTranslation(); |
|
| 567 | - |
|
| 568 | - $this->addStylesheet( |
|
| 569 | - CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 570 | - $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 571 | - ); |
|
| 572 | - } |
|
| 85 | + const JS_HANDLE_I18N = 'eei18n'; |
|
| 86 | + |
|
| 87 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
| 88 | + |
|
| 89 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
| 90 | + |
|
| 91 | + // EE CSS assets handles |
|
| 92 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
| 93 | + |
|
| 94 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
| 95 | + |
|
| 96 | + const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var EE_Currency_Config $currency_config |
|
| 100 | + */ |
|
| 101 | + protected $currency_config; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var EE_Template_Config $template_config |
|
| 105 | + */ |
|
| 106 | + protected $template_config; |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * CoreAssetRegister constructor. |
|
| 111 | + * |
|
| 112 | + * @param AssetCollection $assets |
|
| 113 | + * @param EE_Currency_Config $currency_config |
|
| 114 | + * @param EE_Template_Config $template_config |
|
| 115 | + * @param DomainInterface $domain |
|
| 116 | + * @param Registry $registry |
|
| 117 | + */ |
|
| 118 | + public function __construct( |
|
| 119 | + AssetCollection $assets, |
|
| 120 | + EE_Currency_Config $currency_config, |
|
| 121 | + EE_Template_Config $template_config, |
|
| 122 | + DomainInterface $domain, |
|
| 123 | + Registry $registry |
|
| 124 | + ) { |
|
| 125 | + $this->currency_config = $currency_config; |
|
| 126 | + $this->template_config = $template_config; |
|
| 127 | + parent::__construct($domain, $assets, $registry); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @since 4.9.62.p |
|
| 133 | + * @throws DomainException |
|
| 134 | + * @throws DuplicateCollectionIdentifierException |
|
| 135 | + * @throws InvalidArgumentException |
|
| 136 | + * @throws InvalidDataTypeException |
|
| 137 | + * @throws InvalidEntityException |
|
| 138 | + * @throws InvalidInterfaceException |
|
| 139 | + */ |
|
| 140 | + public function addAssets() |
|
| 141 | + { |
|
| 142 | + $this->addJavascriptFiles(); |
|
| 143 | + $this->addStylesheetFiles(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @since 4.9.62.p |
|
| 149 | + * @throws DomainException |
|
| 150 | + * @throws DuplicateCollectionIdentifierException |
|
| 151 | + * @throws InvalidArgumentException |
|
| 152 | + * @throws InvalidDataTypeException |
|
| 153 | + * @throws InvalidEntityException |
|
| 154 | + * @throws InvalidInterfaceException |
|
| 155 | + */ |
|
| 156 | + public function addJavascriptFiles() |
|
| 157 | + { |
|
| 158 | + $this->loadCoreJs(); |
|
| 159 | + $this->loadJqueryValidate(); |
|
| 160 | + $this->loadAccountingJs(); |
|
| 161 | + add_action( |
|
| 162 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
| 163 | + array($this, 'loadQtipJs') |
|
| 164 | + ); |
|
| 165 | + $this->registerAdminAssets(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @since 4.9.62.p |
|
| 171 | + * @throws DuplicateCollectionIdentifierException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidEntityException |
|
| 174 | + */ |
|
| 175 | + public function addStylesheetFiles() |
|
| 176 | + { |
|
| 177 | + $this->loadCoreCss(); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * core default javascript |
|
| 183 | + * |
|
| 184 | + * @since 4.9.62.p |
|
| 185 | + * @throws DomainException |
|
| 186 | + * @throws DuplicateCollectionIdentifierException |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidEntityException |
|
| 190 | + * @throws InvalidInterfaceException |
|
| 191 | + */ |
|
| 192 | + private function loadCoreJs() |
|
| 193 | + { |
|
| 194 | + // conditionally load third-party libraries that WP core MIGHT have. |
|
| 195 | + $this->registerWpAssets(); |
|
| 196 | + |
|
| 197 | + $this->addJavascript( |
|
| 198 | + CoreAssetManager::JS_HANDLE_MANIFEST, |
|
| 199 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
| 200 | + ); |
|
| 201 | + |
|
| 202 | + $this->addJavascript( |
|
| 203 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 204 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
| 205 | + array(CoreAssetManager::JS_HANDLE_MANIFEST) |
|
| 206 | + ) |
|
| 207 | + ->setHasInlineData(); |
|
| 208 | + |
|
| 209 | + $this->addJavascript( |
|
| 210 | + CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 211 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'), |
|
| 212 | + array( |
|
| 213 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
| 214 | + CoreAssetManager::JS_HANDLE_REACT, |
|
| 215 | + CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 216 | + CoreAssetManager::JS_HANDLE_LODASH, |
|
| 217 | + ) |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + $this->addJavascript( |
|
| 221 | + CoreAssetManager::JS_HANDLE_VALIDATORS, |
|
| 222 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'validators') |
|
| 223 | + )->setRequiresTranslation(); |
|
| 224 | + |
|
| 225 | + $this->addJavascript( |
|
| 226 | + CoreAssetManager::JS_HANDLE_HELPERS, |
|
| 227 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'), |
|
| 228 | + array( |
|
| 229 | + CoreAssetManager::JS_HANDLE_VALIDATORS |
|
| 230 | + ) |
|
| 231 | + )->setRequiresTranslation(); |
|
| 232 | + |
|
| 233 | + $this->addJavascript( |
|
| 234 | + CoreAssetManager::JS_HANDLE_MODEL, |
|
| 235 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'), |
|
| 236 | + array( |
|
| 237 | + CoreAssetManager::JS_HANDLE_HELPERS |
|
| 238 | + ) |
|
| 239 | + )->setRequiresTranslation(); |
|
| 240 | + |
|
| 241 | + $this->addJavascript( |
|
| 242 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 243 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'), |
|
| 244 | + array( |
|
| 245 | + CoreAssetManager::JS_HANDLE_MODEL |
|
| 246 | + ) |
|
| 247 | + )->setRequiresTranslation(); |
|
| 248 | + |
|
| 249 | + $this->addJavascript( |
|
| 250 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 251 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'), |
|
| 252 | + array( |
|
| 253 | + CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 254 | + 'wp-data', |
|
| 255 | + 'wp-api-request', |
|
| 256 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS |
|
| 257 | + ) |
|
| 258 | + ) |
|
| 259 | + ->setRequiresTranslation(); |
|
| 260 | + |
|
| 261 | + $this->addJavascript( |
|
| 262 | + CoreAssetManager::JS_HANDLE_HOCS, |
|
| 263 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'), |
|
| 264 | + array( |
|
| 265 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 266 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 267 | + 'wp-components', |
|
| 268 | + ) |
|
| 269 | + )->setRequiresTranslation(); |
|
| 270 | + |
|
| 271 | + $this->addJavascript( |
|
| 272 | + CoreAssetManager::JS_HANDLE_COMPONENTS, |
|
| 273 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'), |
|
| 274 | + array( |
|
| 275 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
| 276 | + CoreAssetManager::JS_HANDLE_VALUE_OBJECTS, |
|
| 277 | + 'wp-components', |
|
| 278 | + ) |
|
| 279 | + ) |
|
| 280 | + ->setRequiresTranslation(); |
|
| 281 | + |
|
| 282 | + $this->addJavascript( |
|
| 283 | + CoreAssetManager::JS_HANDLE_EDITOR_HOCS, |
|
| 284 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'), |
|
| 285 | + array( |
|
| 286 | + CoreAssetManager::JS_HANDLE_COMPONENTS |
|
| 287 | + ) |
|
| 288 | + )->setRequiresTranslation(); |
|
| 289 | + |
|
| 290 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
| 291 | + $this->registry->addData( |
|
| 292 | + 'paths', |
|
| 293 | + array( |
|
| 294 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
| 295 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
| 296 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
| 297 | + 'site_url' => site_url('/'), |
|
| 298 | + 'admin_url' => admin_url('/'), |
|
| 299 | + ) |
|
| 300 | + ); |
|
| 301 | + /** site formatting values **/ |
|
| 302 | + $this->registry->addData( |
|
| 303 | + 'site_formats', |
|
| 304 | + array( |
|
| 305 | + 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
| 306 | + ) |
|
| 307 | + ); |
|
| 308 | + /** currency data **/ |
|
| 309 | + $this->registry->addData( |
|
| 310 | + 'currency_config', |
|
| 311 | + $this->getCurrencySettings() |
|
| 312 | + ); |
|
| 313 | + /** site timezone */ |
|
| 314 | + $this->registry->addData( |
|
| 315 | + 'default_timezone', |
|
| 316 | + array( |
|
| 317 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
| 318 | + 'string' => get_option('timezone_string'), |
|
| 319 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
| 320 | + ) |
|
| 321 | + ); |
|
| 322 | + /** site locale (user locale if user logged in) */ |
|
| 323 | + $this->registry->addData( |
|
| 324 | + 'locale', |
|
| 325 | + array( |
|
| 326 | + 'user' => get_user_locale(), |
|
| 327 | + 'site' => get_locale() |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + $this->addJavascript( |
|
| 332 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 333 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
| 334 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 335 | + ) |
|
| 336 | + ->setInlineDataCallback( |
|
| 337 | + function () { |
|
| 338 | + wp_localize_script( |
|
| 339 | + CoreAssetManager::JS_HANDLE_CORE, |
|
| 340 | + CoreAssetManager::JS_HANDLE_I18N, |
|
| 341 | + EE_Registry::$i18n_js_strings |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
| 350 | + * WordPress in the running environment. |
|
| 351 | + * |
|
| 352 | + * @throws DuplicateCollectionIdentifierException |
|
| 353 | + * @throws InvalidDataTypeException |
|
| 354 | + * @throws InvalidEntityException |
|
| 355 | + * @throws DomainException |
|
| 356 | + * @since $VID:$ |
|
| 357 | + */ |
|
| 358 | + private function registerWpAssets() |
|
| 359 | + { |
|
| 360 | + global $wp_version; |
|
| 361 | + if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
| 362 | + return; |
|
| 363 | + } |
|
| 364 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT) |
|
| 365 | + ->setVersion('16.6.0'); |
|
| 366 | + $this->addVendorJavascript( |
|
| 367 | + CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
| 368 | + array(CoreAssetManager::JS_HANDLE_REACT) |
|
| 369 | + )->setVersion('16.6.0'); |
|
| 370 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH) |
|
| 371 | + ->setInlineDataCallback( |
|
| 372 | + function() { |
|
| 373 | + wp_add_inline_script( |
|
| 374 | + CoreAssetManager::JS_HANDLE_LODASH, |
|
| 375 | + 'window.lodash = _.noConflict();' |
|
| 376 | + ); |
|
| 377 | + } |
|
| 378 | + ) |
|
| 379 | + ->setVersion('4.17.11'); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Returns configuration data for the accounting-js library. |
|
| 385 | + * @since $VID:$ |
|
| 386 | + * @return array |
|
| 387 | + */ |
|
| 388 | + private function getAccountingSettings() { |
|
| 389 | + return array( |
|
| 390 | + 'currency' => array( |
|
| 391 | + 'symbol' => $this->currency_config->sign, |
|
| 392 | + 'format' => array( |
|
| 393 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
| 394 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 395 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
| 396 | + ), |
|
| 397 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 398 | + 'thousand' => $this->currency_config->thsnds, |
|
| 399 | + 'precision' => $this->currency_config->dec_plc, |
|
| 400 | + ), |
|
| 401 | + 'number' => array( |
|
| 402 | + 'precision' => $this->currency_config->dec_plc, |
|
| 403 | + 'thousand' => $this->currency_config->thsnds, |
|
| 404 | + 'decimal' => $this->currency_config->dec_mrk, |
|
| 405 | + ), |
|
| 406 | + ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Returns configuration data for the js Currency VO. |
|
| 412 | + * @since $VID:$ |
|
| 413 | + * @return array |
|
| 414 | + */ |
|
| 415 | + private function getCurrencySettings() |
|
| 416 | + { |
|
| 417 | + return array( |
|
| 418 | + 'code' => $this->currency_config->code, |
|
| 419 | + 'singularLabel' => $this->currency_config->name, |
|
| 420 | + 'pluralLabel' => $this->currency_config->plural, |
|
| 421 | + 'sign' => $this->currency_config->sign, |
|
| 422 | + 'signB4' => $this->currency_config->sign_b4, |
|
| 423 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
| 424 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
| 425 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @since 4.9.62.p |
|
| 432 | + * @throws DuplicateCollectionIdentifierException |
|
| 433 | + * @throws InvalidDataTypeException |
|
| 434 | + * @throws InvalidEntityException |
|
| 435 | + */ |
|
| 436 | + private function loadCoreCss() |
|
| 437 | + { |
|
| 438 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
| 439 | + $this->addStylesheet( |
|
| 440 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
| 441 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
| 442 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
| 443 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 444 | + array('dashicons') |
|
| 445 | + ); |
|
| 446 | + //Load custom style sheet if available |
|
| 447 | + if ($this->template_config->custom_style_sheet !== null) { |
|
| 448 | + $this->addStylesheet( |
|
| 449 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
| 450 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
| 451 | + array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
| 452 | + ); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + $this->addStylesheet( |
|
| 456 | + CoreAssetManager::CSS_HANDLE_COMPONENTS, |
|
| 457 | + $this->registry->getCssUrl( |
|
| 458 | + $this->domain->assetNamespace(), |
|
| 459 | + 'components' |
|
| 460 | + ) |
|
| 461 | + ); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * jQuery Validate for form validation |
|
| 467 | + * |
|
| 468 | + * @since 4.9.62.p |
|
| 469 | + * @throws DomainException |
|
| 470 | + * @throws DuplicateCollectionIdentifierException |
|
| 471 | + * @throws InvalidDataTypeException |
|
| 472 | + * @throws InvalidEntityException |
|
| 473 | + */ |
|
| 474 | + private function loadJqueryValidate() |
|
| 475 | + { |
|
| 476 | + $this->addJavascript( |
|
| 477 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
| 478 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
| 479 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
| 480 | + ) |
|
| 481 | + ->setVersion('1.15.0'); |
|
| 482 | + |
|
| 483 | + $this->addJavascript( |
|
| 484 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
| 485 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
| 486 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
| 487 | + ) |
|
| 488 | + ->setVersion('1.15.0'); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * accounting.js for performing client-side calculations |
|
| 494 | + * |
|
| 495 | + * @since 4.9.62.p |
|
| 496 | + * @throws DomainException |
|
| 497 | + * @throws DuplicateCollectionIdentifierException |
|
| 498 | + * @throws InvalidDataTypeException |
|
| 499 | + * @throws InvalidEntityException |
|
| 500 | + */ |
|
| 501 | + private function loadAccountingJs() |
|
| 502 | + { |
|
| 503 | + //accounting.js library |
|
| 504 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 505 | + $this->addJavascript( |
|
| 506 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
| 507 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
| 508 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
| 509 | + ) |
|
| 510 | + ->setVersion('0.3.2'); |
|
| 511 | + |
|
| 512 | + $this->addJavascript( |
|
| 513 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 514 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 515 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
| 516 | + ) |
|
| 517 | + ->setInlineDataCallback( |
|
| 518 | + function () { |
|
| 519 | + wp_localize_script( |
|
| 520 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
| 521 | + 'EE_ACCOUNTING_CFG', |
|
| 522 | + $this->getAccountingSettings() |
|
| 523 | + ); |
|
| 524 | + } |
|
| 525 | + ) |
|
| 526 | + ->setVersion(); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * registers assets for cleaning your ears |
|
| 532 | + * |
|
| 533 | + * @param JavascriptAsset $script |
|
| 534 | + */ |
|
| 535 | + public function loadQtipJs(JavascriptAsset $script) |
|
| 536 | + { |
|
| 537 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
| 538 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 539 | + if ( |
|
| 540 | + $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
| 541 | + && apply_filters('FHEE_load_qtip', false) |
|
| 542 | + ) { |
|
| 543 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * assets that are used in the WordPress admin |
|
| 550 | + * |
|
| 551 | + * @since 4.9.62.p |
|
| 552 | + * @throws DuplicateCollectionIdentifierException |
|
| 553 | + * @throws InvalidDataTypeException |
|
| 554 | + * @throws InvalidEntityException |
|
| 555 | + */ |
|
| 556 | + private function registerAdminAssets() |
|
| 557 | + { |
|
| 558 | + $this->addJavascript( |
|
| 559 | + CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 560 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
| 561 | + array( |
|
| 562 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
| 563 | + CoreAssetManager::JS_HANDLE_VENDOR, |
|
| 564 | + ) |
|
| 565 | + ) |
|
| 566 | + ->setRequiresTranslation(); |
|
| 567 | + |
|
| 568 | + $this->addStylesheet( |
|
| 569 | + CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
| 570 | + $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
| 571 | + ); |
|
| 572 | + } |
|
| 573 | 573 | } |