@@ -1,12 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -use EventEspresso\core\domain\DomainFactory; |
|
| 4 | -use EventEspresso\core\domain\values\FilePath; |
|
| 5 | -use EventEspresso\core\domain\values\FullyQualifiedName; |
|
| 6 | -use EventEspresso\core\domain\values\Version; |
|
| 7 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 8 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 9 | -use EventEspresso\core\services\loaders\LoaderFactory; |
|
| 10 | 5 | use EventEspresso\core\services\request\RequestDecoratorInterface; |
| 11 | 6 | use EventEspresso\core\services\request\RequestInterface; |
| 12 | 7 | use EventEspresso\core\services\request\RequestStackCoreAppInterface; |
@@ -27,114 +27,114 @@ |
||
| 27 | 27 | class EE_Load_Espresso_Core implements RequestDecoratorInterface, RequestStackCoreAppInterface |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var RequestInterface $request |
|
| 32 | - */ |
|
| 33 | - protected $request; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var ResponseInterface $response |
|
| 37 | - */ |
|
| 38 | - protected $response; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var EE_Dependency_Map $dependency_map |
|
| 42 | - */ |
|
| 43 | - protected $dependency_map; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Registry $registry |
|
| 47 | - */ |
|
| 48 | - protected $registry; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * EE_Load_Espresso_Core constructor |
|
| 53 | - * |
|
| 54 | - * @param EE_Registry $registry |
|
| 55 | - * @param EE_Dependency_Map $dependency_map |
|
| 56 | - * @throws EE_Error |
|
| 57 | - */ |
|
| 58 | - public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map) |
|
| 59 | - { |
|
| 60 | - EE_Error::doing_it_wrong( |
|
| 61 | - __METHOD__, |
|
| 62 | - sprintf( |
|
| 63 | - esc_html__( |
|
| 64 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 65 | - 'event_espresso' |
|
| 66 | - ), |
|
| 67 | - 'EventEspresso\core\services\request\RequestStackCoreApp', |
|
| 68 | - '\core\services\request', |
|
| 69 | - 'EventEspresso\core\services\request' |
|
| 70 | - ), |
|
| 71 | - '4.9.53' |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * handle |
|
| 78 | - * sets hooks for running rest of system |
|
| 79 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 80 | - * starting EE Addons from any other point may lead to problems |
|
| 81 | - * |
|
| 82 | - * @param RequestInterface $request |
|
| 83 | - * @param ResponseInterface $response |
|
| 84 | - * @return ResponseInterface |
|
| 85 | - * @throws EE_Error |
|
| 86 | - * @throws InvalidDataTypeException |
|
| 87 | - * @throws InvalidInterfaceException |
|
| 88 | - * @throws InvalidArgumentException |
|
| 89 | - * @throws DomainException |
|
| 90 | - */ |
|
| 91 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 92 | - { |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return RequestInterface |
|
| 98 | - */ |
|
| 99 | - public function request() |
|
| 100 | - { |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return ResponseInterface |
|
| 106 | - */ |
|
| 107 | - public function response() |
|
| 108 | - { |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return EE_Dependency_Map |
|
| 114 | - * @throws EE_Error |
|
| 115 | - */ |
|
| 116 | - public function dependency_map() |
|
| 117 | - { |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return EE_Registry |
|
| 123 | - * @throws EE_Error |
|
| 124 | - */ |
|
| 125 | - public function registry() |
|
| 126 | - { |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * called after the request stack has been fully processed |
|
| 132 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 133 | - * |
|
| 134 | - * @param RequestInterface $request |
|
| 135 | - * @param ResponseInterface $response |
|
| 136 | - */ |
|
| 137 | - public function handleResponse(RequestInterface $request, ResponseInterface $response) |
|
| 138 | - { |
|
| 139 | - } |
|
| 30 | + /** |
|
| 31 | + * @var RequestInterface $request |
|
| 32 | + */ |
|
| 33 | + protected $request; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var ResponseInterface $response |
|
| 37 | + */ |
|
| 38 | + protected $response; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var EE_Dependency_Map $dependency_map |
|
| 42 | + */ |
|
| 43 | + protected $dependency_map; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Registry $registry |
|
| 47 | + */ |
|
| 48 | + protected $registry; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * EE_Load_Espresso_Core constructor |
|
| 53 | + * |
|
| 54 | + * @param EE_Registry $registry |
|
| 55 | + * @param EE_Dependency_Map $dependency_map |
|
| 56 | + * @throws EE_Error |
|
| 57 | + */ |
|
| 58 | + public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map) |
|
| 59 | + { |
|
| 60 | + EE_Error::doing_it_wrong( |
|
| 61 | + __METHOD__, |
|
| 62 | + sprintf( |
|
| 63 | + esc_html__( |
|
| 64 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
| 65 | + 'event_espresso' |
|
| 66 | + ), |
|
| 67 | + 'EventEspresso\core\services\request\RequestStackCoreApp', |
|
| 68 | + '\core\services\request', |
|
| 69 | + 'EventEspresso\core\services\request' |
|
| 70 | + ), |
|
| 71 | + '4.9.53' |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * handle |
|
| 78 | + * sets hooks for running rest of system |
|
| 79 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 80 | + * starting EE Addons from any other point may lead to problems |
|
| 81 | + * |
|
| 82 | + * @param RequestInterface $request |
|
| 83 | + * @param ResponseInterface $response |
|
| 84 | + * @return ResponseInterface |
|
| 85 | + * @throws EE_Error |
|
| 86 | + * @throws InvalidDataTypeException |
|
| 87 | + * @throws InvalidInterfaceException |
|
| 88 | + * @throws InvalidArgumentException |
|
| 89 | + * @throws DomainException |
|
| 90 | + */ |
|
| 91 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 92 | + { |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return RequestInterface |
|
| 98 | + */ |
|
| 99 | + public function request() |
|
| 100 | + { |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return ResponseInterface |
|
| 106 | + */ |
|
| 107 | + public function response() |
|
| 108 | + { |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return EE_Dependency_Map |
|
| 114 | + * @throws EE_Error |
|
| 115 | + */ |
|
| 116 | + public function dependency_map() |
|
| 117 | + { |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return EE_Registry |
|
| 123 | + * @throws EE_Error |
|
| 124 | + */ |
|
| 125 | + public function registry() |
|
| 126 | + { |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * called after the request stack has been fully processed |
|
| 132 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 133 | + * |
|
| 134 | + * @param RequestInterface $request |
|
| 135 | + * @param ResponseInterface $response |
|
| 136 | + */ |
|
| 137 | + public function handleResponse(RequestInterface $request, ResponseInterface $response) |
|
| 138 | + { |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -2597,7 +2597,7 @@ discard block |
||
| 2597 | 2597 | * |
| 2598 | 2598 | * @param int $index This helps us know which template field to select from the request array. |
| 2599 | 2599 | * |
| 2600 | - * @return array |
|
| 2600 | + * @return string |
|
| 2601 | 2601 | */ |
| 2602 | 2602 | protected function _set_message_template_column_values($index) |
| 2603 | 2603 | { |
@@ -3088,7 +3088,7 @@ discard block |
||
| 3088 | 3088 | * |
| 3089 | 3089 | * @param int $GRP_ID The group being deleted |
| 3090 | 3090 | * @param bool $include_group whether to delete the Message Template Group as well. |
| 3091 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3091 | + * @return integer boolean to indicate the success of the deletes or not. |
|
| 3092 | 3092 | * @throws EE_Error |
| 3093 | 3093 | * @throws InvalidArgumentException |
| 3094 | 3094 | * @throws InvalidDataTypeException |
@@ -19,2646 +19,2646 @@ discard block |
||
| 19 | 19 | class Messages_Admin_Page extends EE_Admin_Page |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 24 | - */ |
|
| 25 | - protected $_message_resource_manager; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type string $_active_message_type_name |
|
| 29 | - */ |
|
| 30 | - protected $_active_message_type_name = ''; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type EE_messenger $_active_messenger |
|
| 34 | - */ |
|
| 35 | - protected $_active_messenger; |
|
| 36 | - protected $_activate_state; |
|
| 37 | - protected $_activate_meta_box_type; |
|
| 38 | - protected $_current_message_meta_box; |
|
| 39 | - protected $_current_message_meta_box_object; |
|
| 40 | - protected $_context_switcher; |
|
| 41 | - protected $_shortcodes = array(); |
|
| 42 | - protected $_active_messengers = array(); |
|
| 43 | - protected $_active_message_types = array(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 47 | - */ |
|
| 48 | - protected $_message_template_group; |
|
| 49 | - protected $_m_mt_settings = array(); |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 54 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 55 | - * |
|
| 56 | - * @since 4.5.0 |
|
| 57 | - * |
|
| 58 | - * @var EE_Messages_Template_Pack |
|
| 59 | - */ |
|
| 60 | - protected $_template_pack; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 65 | - * group is. If there is no group then it automatically gets set to default. |
|
| 66 | - * |
|
| 67 | - * @since 4.5.0 |
|
| 68 | - * |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 71 | - protected $_variation; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param bool $routing |
|
| 76 | - * @throws EE_Error |
|
| 77 | - */ |
|
| 78 | - public function __construct($routing = true) |
|
| 79 | - { |
|
| 80 | - // make sure messages autoloader is running |
|
| 81 | - EED_Messages::set_autoloaders(); |
|
| 82 | - parent::__construct($routing); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - protected function _init_page_props() |
|
| 87 | - { |
|
| 88 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 89 | - $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 90 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 91 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 92 | - |
|
| 93 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] |
|
| 94 | - : array(); |
|
| 95 | - |
|
| 96 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 97 | - $this->_load_message_resource_manager(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 103 | - * |
|
| 104 | - * @throws EE_Error |
|
| 105 | - * @throws InvalidDataTypeException |
|
| 106 | - * @throws InvalidInterfaceException |
|
| 107 | - * @throws InvalidArgumentException |
|
| 108 | - * @throws ReflectionException |
|
| 109 | - */ |
|
| 110 | - protected function _load_message_resource_manager() |
|
| 111 | - { |
|
| 112 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @deprecated 4.9.9.rc.014 |
|
| 118 | - * @return array |
|
| 119 | - * @throws EE_Error |
|
| 120 | - * @throws InvalidArgumentException |
|
| 121 | - * @throws InvalidDataTypeException |
|
| 122 | - * @throws InvalidInterfaceException |
|
| 123 | - */ |
|
| 124 | - public function get_messengers_for_list_table() |
|
| 125 | - { |
|
| 126 | - EE_Error::doing_it_wrong( |
|
| 127 | - __METHOD__, |
|
| 128 | - sprintf( |
|
| 129 | - esc_html__( |
|
| 130 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 131 | - 'event_espresso' |
|
| 132 | - ), |
|
| 133 | - 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 134 | - ), |
|
| 135 | - '4.9.9.rc.014' |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - $m_values = array(); |
|
| 139 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 140 | - // setup messengers for selects |
|
| 141 | - $i = 1; |
|
| 142 | - foreach ($active_messengers as $active_messenger) { |
|
| 143 | - if ($active_messenger instanceof EE_Message) { |
|
| 144 | - $m_values[ $i ]['id'] = $active_messenger->messenger(); |
|
| 145 | - $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 146 | - $i++; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $m_values; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @deprecated 4.9.9.rc.014 |
|
| 156 | - * @return array |
|
| 157 | - * @throws EE_Error |
|
| 158 | - * @throws InvalidArgumentException |
|
| 159 | - * @throws InvalidDataTypeException |
|
| 160 | - * @throws InvalidInterfaceException |
|
| 161 | - */ |
|
| 162 | - public function get_message_types_for_list_table() |
|
| 163 | - { |
|
| 164 | - EE_Error::doing_it_wrong( |
|
| 165 | - __METHOD__, |
|
| 166 | - sprintf( |
|
| 167 | - esc_html__( |
|
| 168 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 169 | - 'event_espresso' |
|
| 170 | - ), |
|
| 171 | - 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 172 | - ), |
|
| 173 | - '4.9.9.rc.014' |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - $mt_values = array(); |
|
| 177 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 178 | - $i = 1; |
|
| 179 | - foreach ($active_messages as $active_message) { |
|
| 180 | - if ($active_message instanceof EE_Message) { |
|
| 181 | - $mt_values[ $i ]['id'] = $active_message->message_type(); |
|
| 182 | - $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label()); |
|
| 183 | - $i++; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $mt_values; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @deprecated 4.9.9.rc.014 |
|
| 193 | - * @return array |
|
| 194 | - * @throws EE_Error |
|
| 195 | - * @throws InvalidArgumentException |
|
| 196 | - * @throws InvalidDataTypeException |
|
| 197 | - * @throws InvalidInterfaceException |
|
| 198 | - */ |
|
| 199 | - public function get_contexts_for_message_types_for_list_table() |
|
| 200 | - { |
|
| 201 | - EE_Error::doing_it_wrong( |
|
| 202 | - __METHOD__, |
|
| 203 | - sprintf( |
|
| 204 | - esc_html__( |
|
| 205 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ), |
|
| 208 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 209 | - ), |
|
| 210 | - '4.9.9.rc.014' |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - $contexts = array(); |
|
| 214 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 215 | - foreach ($active_message_contexts as $active_message) { |
|
| 216 | - if ($active_message instanceof EE_Message) { |
|
| 217 | - $message_type = $active_message->message_type_object(); |
|
| 218 | - if ($message_type instanceof EE_message_type) { |
|
| 219 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 220 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 221 | - $contexts[ $context ] = $context_details['label']; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $contexts; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Generate select input with provided messenger options array. |
|
| 233 | - * |
|
| 234 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 235 | - * labels. |
|
| 236 | - * @return string |
|
| 237 | - * @throws EE_Error |
|
| 238 | - */ |
|
| 239 | - public function get_messengers_select_input($messenger_options) |
|
| 240 | - { |
|
| 241 | - // if empty or just one value then just return an empty string |
|
| 242 | - if ( |
|
| 243 | - empty($messenger_options) |
|
| 244 | - || ! is_array($messenger_options) |
|
| 245 | - || count($messenger_options) === 1 |
|
| 246 | - ) { |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - // merge in default |
|
| 250 | - $messenger_options = array_merge( |
|
| 251 | - array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 252 | - $messenger_options |
|
| 253 | - ); |
|
| 254 | - $input = new EE_Select_Input( |
|
| 255 | - $messenger_options, |
|
| 256 | - array( |
|
| 257 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 258 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 259 | - 'html_class' => 'wide', |
|
| 260 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 261 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 262 | - : 'none_selected', |
|
| 263 | - ) |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - return $input->get_html_for_input(); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Generate select input with provided message type options array. |
|
| 272 | - * |
|
| 273 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 274 | - * message type labels |
|
| 275 | - * @return string |
|
| 276 | - * @throws EE_Error |
|
| 277 | - */ |
|
| 278 | - public function get_message_types_select_input($message_type_options) |
|
| 279 | - { |
|
| 280 | - // if empty or count of options is 1 then just return an empty string |
|
| 281 | - if ( |
|
| 282 | - empty($message_type_options) |
|
| 283 | - || ! is_array($message_type_options) |
|
| 284 | - || count($message_type_options) === 1 |
|
| 285 | - ) { |
|
| 286 | - return ''; |
|
| 287 | - } |
|
| 288 | - // merge in default |
|
| 289 | - $message_type_options = array_merge( |
|
| 290 | - array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 291 | - $message_type_options |
|
| 292 | - ); |
|
| 293 | - $input = new EE_Select_Input( |
|
| 294 | - $message_type_options, |
|
| 295 | - array( |
|
| 296 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 297 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 298 | - 'html_class' => 'wide', |
|
| 299 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 300 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | - : 'none_selected', |
|
| 302 | - ) |
|
| 303 | - ); |
|
| 304 | - |
|
| 305 | - return $input->get_html_for_input(); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Generate select input with provide message type contexts array. |
|
| 311 | - * |
|
| 312 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 313 | - * context label. |
|
| 314 | - * @return string |
|
| 315 | - * @throws EE_Error |
|
| 316 | - */ |
|
| 317 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 318 | - { |
|
| 319 | - // if empty or count of options is one then just return empty string |
|
| 320 | - if ( |
|
| 321 | - empty($context_options) |
|
| 322 | - || ! is_array($context_options) |
|
| 323 | - || count($context_options) === 1 |
|
| 324 | - ) { |
|
| 325 | - return ''; |
|
| 326 | - } |
|
| 327 | - // merge in default |
|
| 328 | - $context_options = array_merge( |
|
| 329 | - array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | - $context_options |
|
| 331 | - ); |
|
| 332 | - $input = new EE_Select_Input( |
|
| 333 | - $context_options, |
|
| 334 | - array( |
|
| 335 | - 'html_name' => 'ee_context_filter_by', |
|
| 336 | - 'html_id' => 'ee_context_filter_by', |
|
| 337 | - 'html_class' => 'wide', |
|
| 338 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | - : 'none_selected', |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - |
|
| 344 | - return $input->get_html_for_input(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - protected function _ajax_hooks() |
|
| 349 | - { |
|
| 350 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | - add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - protected function _define_page_props() |
|
| 360 | - { |
|
| 361 | - $this->_admin_page_title = $this->page_label; |
|
| 362 | - $this->_labels = array( |
|
| 363 | - 'buttons' => array( |
|
| 364 | - 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | - 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | - 'delete' => esc_html__('Delete Message Template', 'event_espresso'), |
|
| 367 | - ), |
|
| 368 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso'), |
|
| 369 | - ); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | - * |
|
| 376 | - * @access protected |
|
| 377 | - * @return void |
|
| 378 | - */ |
|
| 379 | - protected function _set_page_routes() |
|
| 380 | - { |
|
| 381 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 382 | - ? $this->_req_data['GRP_ID'] |
|
| 383 | - : 0; |
|
| 384 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 385 | - ? $this->_req_data['id'] |
|
| 386 | - : $grp_id; |
|
| 387 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 388 | - ? $this->_req_data['MSG_ID'] |
|
| 389 | - : 0; |
|
| 390 | - |
|
| 391 | - $this->_page_routes = array( |
|
| 392 | - 'default' => array( |
|
| 393 | - 'func' => '_message_queue_list_table', |
|
| 394 | - 'capability' => 'ee_read_global_messages', |
|
| 395 | - ), |
|
| 396 | - 'global_mtps' => array( |
|
| 397 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 398 | - 'capability' => 'ee_read_global_messages', |
|
| 399 | - ), |
|
| 400 | - 'custom_mtps' => array( |
|
| 401 | - 'func' => '_custom_mtps_preview', |
|
| 402 | - 'capability' => 'ee_read_messages', |
|
| 403 | - ), |
|
| 404 | - 'add_new_message_template' => array( |
|
| 405 | - 'func' => '_add_message_template', |
|
| 406 | - 'capability' => 'ee_edit_messages', |
|
| 407 | - 'noheader' => true, |
|
| 408 | - ), |
|
| 409 | - 'edit_message_template' => array( |
|
| 410 | - 'func' => '_edit_message_template', |
|
| 411 | - 'capability' => 'ee_edit_message', |
|
| 412 | - 'obj_id' => $grp_id, |
|
| 413 | - ), |
|
| 414 | - 'preview_message' => array( |
|
| 415 | - 'func' => '_preview_message', |
|
| 416 | - 'capability' => 'ee_read_message', |
|
| 417 | - 'obj_id' => $grp_id, |
|
| 418 | - 'noheader' => true, |
|
| 419 | - 'headers_sent_route' => 'display_preview_message', |
|
| 420 | - ), |
|
| 421 | - 'display_preview_message' => array( |
|
| 422 | - 'func' => '_display_preview_message', |
|
| 423 | - 'capability' => 'ee_read_message', |
|
| 424 | - 'obj_id' => $grp_id, |
|
| 425 | - ), |
|
| 426 | - 'insert_message_template' => array( |
|
| 427 | - 'func' => '_insert_or_update_message_template', |
|
| 428 | - 'capability' => 'ee_edit_messages', |
|
| 429 | - 'args' => array('new_template' => true), |
|
| 430 | - 'noheader' => true, |
|
| 431 | - ), |
|
| 432 | - 'update_message_template' => array( |
|
| 433 | - 'func' => '_insert_or_update_message_template', |
|
| 434 | - 'capability' => 'ee_edit_message', |
|
| 435 | - 'obj_id' => $grp_id, |
|
| 436 | - 'args' => array('new_template' => false), |
|
| 437 | - 'noheader' => true, |
|
| 438 | - ), |
|
| 439 | - 'trash_message_template' => array( |
|
| 440 | - 'func' => '_trash_or_restore_message_template', |
|
| 441 | - 'capability' => 'ee_delete_message', |
|
| 442 | - 'obj_id' => $grp_id, |
|
| 443 | - 'args' => array('trash' => true, 'all' => true), |
|
| 444 | - 'noheader' => true, |
|
| 445 | - ), |
|
| 446 | - 'trash_message_template_context' => array( |
|
| 447 | - 'func' => '_trash_or_restore_message_template', |
|
| 448 | - 'capability' => 'ee_delete_message', |
|
| 449 | - 'obj_id' => $grp_id, |
|
| 450 | - 'args' => array('trash' => true), |
|
| 451 | - 'noheader' => true, |
|
| 452 | - ), |
|
| 453 | - 'restore_message_template' => array( |
|
| 454 | - 'func' => '_trash_or_restore_message_template', |
|
| 455 | - 'capability' => 'ee_delete_message', |
|
| 456 | - 'obj_id' => $grp_id, |
|
| 457 | - 'args' => array('trash' => false, 'all' => true), |
|
| 458 | - 'noheader' => true, |
|
| 459 | - ), |
|
| 460 | - 'restore_message_template_context' => array( |
|
| 461 | - 'func' => '_trash_or_restore_message_template', |
|
| 462 | - 'capability' => 'ee_delete_message', |
|
| 463 | - 'obj_id' => $grp_id, |
|
| 464 | - 'args' => array('trash' => false), |
|
| 465 | - 'noheader' => true, |
|
| 466 | - ), |
|
| 467 | - 'delete_message_template' => array( |
|
| 468 | - 'func' => '_delete_message_template', |
|
| 469 | - 'capability' => 'ee_delete_message', |
|
| 470 | - 'obj_id' => $grp_id, |
|
| 471 | - 'noheader' => true, |
|
| 472 | - ), |
|
| 473 | - 'reset_to_default' => array( |
|
| 474 | - 'func' => '_reset_to_default_template', |
|
| 475 | - 'capability' => 'ee_edit_message', |
|
| 476 | - 'obj_id' => $grp_id, |
|
| 477 | - 'noheader' => true, |
|
| 478 | - ), |
|
| 479 | - 'settings' => array( |
|
| 480 | - 'func' => '_settings', |
|
| 481 | - 'capability' => 'manage_options', |
|
| 482 | - ), |
|
| 483 | - 'update_global_settings' => array( |
|
| 484 | - 'func' => '_update_global_settings', |
|
| 485 | - 'capability' => 'manage_options', |
|
| 486 | - 'noheader' => true, |
|
| 487 | - ), |
|
| 488 | - 'generate_now' => array( |
|
| 489 | - 'func' => '_generate_now', |
|
| 490 | - 'capability' => 'ee_send_message', |
|
| 491 | - 'noheader' => true, |
|
| 492 | - ), |
|
| 493 | - 'generate_and_send_now' => array( |
|
| 494 | - 'func' => '_generate_and_send_now', |
|
| 495 | - 'capability' => 'ee_send_message', |
|
| 496 | - 'noheader' => true, |
|
| 497 | - ), |
|
| 498 | - 'queue_for_resending' => array( |
|
| 499 | - 'func' => '_queue_for_resending', |
|
| 500 | - 'capability' => 'ee_send_message', |
|
| 501 | - 'noheader' => true, |
|
| 502 | - ), |
|
| 503 | - 'send_now' => array( |
|
| 504 | - 'func' => '_send_now', |
|
| 505 | - 'capability' => 'ee_send_message', |
|
| 506 | - 'noheader' => true, |
|
| 507 | - ), |
|
| 508 | - 'delete_ee_message' => array( |
|
| 509 | - 'func' => '_delete_ee_messages', |
|
| 510 | - 'capability' => 'ee_delete_messages', |
|
| 511 | - 'noheader' => true, |
|
| 512 | - ), |
|
| 513 | - 'delete_ee_messages' => array( |
|
| 514 | - 'func' => '_delete_ee_messages', |
|
| 515 | - 'capability' => 'ee_delete_messages', |
|
| 516 | - 'noheader' => true, |
|
| 517 | - 'obj_id' => $msg_id, |
|
| 518 | - ), |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - protected function _set_page_config() |
|
| 524 | - { |
|
| 525 | - $this->_page_config = array( |
|
| 526 | - 'default' => array( |
|
| 527 | - 'nav' => array( |
|
| 528 | - 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 529 | - 'order' => 10, |
|
| 530 | - ), |
|
| 531 | - 'list_table' => 'EE_Message_List_Table', |
|
| 532 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 533 | - 'require_nonce' => false, |
|
| 534 | - ), |
|
| 535 | - 'global_mtps' => array( |
|
| 536 | - 'nav' => array( |
|
| 537 | - 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 538 | - 'order' => 20, |
|
| 539 | - ), |
|
| 540 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 541 | - 'help_tabs' => array( |
|
| 542 | - 'messages_overview_help_tab' => array( |
|
| 543 | - 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 544 | - 'filename' => 'messages_overview', |
|
| 545 | - ), |
|
| 546 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 547 | - 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 548 | - 'filename' => 'messages_overview_table_column_headings', |
|
| 549 | - ), |
|
| 550 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 551 | - 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 552 | - 'filename' => 'messages_overview_filters', |
|
| 553 | - ), |
|
| 554 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 555 | - 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 556 | - 'filename' => 'messages_overview_views', |
|
| 557 | - ), |
|
| 558 | - 'message_overview_message_types_help_tab' => array( |
|
| 559 | - 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 560 | - 'filename' => 'messages_overview_types', |
|
| 561 | - ), |
|
| 562 | - 'messages_overview_messengers_help_tab' => array( |
|
| 563 | - 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 564 | - 'filename' => 'messages_overview_messengers', |
|
| 565 | - ), |
|
| 566 | - ), |
|
| 567 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 568 | - 'require_nonce' => false, |
|
| 569 | - ), |
|
| 570 | - 'custom_mtps' => array( |
|
| 571 | - 'nav' => array( |
|
| 572 | - 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 573 | - 'order' => 30, |
|
| 574 | - ), |
|
| 575 | - 'help_tabs' => array(), |
|
| 576 | - 'help_tour' => array(), |
|
| 577 | - 'require_nonce' => false, |
|
| 578 | - ), |
|
| 579 | - 'add_new_message_template' => array( |
|
| 580 | - 'nav' => array( |
|
| 581 | - 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 582 | - 'order' => 5, |
|
| 583 | - 'persistent' => false, |
|
| 584 | - ), |
|
| 585 | - 'require_nonce' => false, |
|
| 586 | - ), |
|
| 587 | - 'edit_message_template' => array( |
|
| 588 | - 'labels' => array( |
|
| 589 | - 'buttons' => array( |
|
| 590 | - 'reset' => esc_html__('Reset Templates', 'event_espresso'), |
|
| 591 | - ), |
|
| 592 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso'), |
|
| 593 | - ), |
|
| 594 | - 'nav' => array( |
|
| 595 | - 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 596 | - 'order' => 5, |
|
| 597 | - 'persistent' => false, |
|
| 598 | - 'url' => '', |
|
| 599 | - ), |
|
| 600 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 601 | - 'has_metaboxes' => true, |
|
| 602 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 603 | - 'help_tabs' => array( |
|
| 604 | - 'edit_message_template' => array( |
|
| 605 | - 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 606 | - 'callback' => 'edit_message_template_help_tab', |
|
| 607 | - ), |
|
| 608 | - 'message_templates_help_tab' => array( |
|
| 609 | - 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 610 | - 'filename' => 'messages_templates', |
|
| 611 | - ), |
|
| 612 | - 'message_template_shortcodes' => array( |
|
| 613 | - 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 614 | - 'callback' => 'message_template_shortcodes_help_tab', |
|
| 615 | - ), |
|
| 616 | - 'message_preview_help_tab' => array( |
|
| 617 | - 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 618 | - 'filename' => 'messages_preview', |
|
| 619 | - ), |
|
| 620 | - 'messages_overview_other_help_tab' => array( |
|
| 621 | - 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 622 | - 'filename' => 'messages_overview_other', |
|
| 623 | - ), |
|
| 624 | - ), |
|
| 625 | - 'require_nonce' => false, |
|
| 626 | - ), |
|
| 627 | - 'display_preview_message' => array( |
|
| 628 | - 'nav' => array( |
|
| 629 | - 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 630 | - 'order' => 5, |
|
| 631 | - 'url' => '', |
|
| 632 | - 'persistent' => false, |
|
| 633 | - ), |
|
| 634 | - 'help_tabs' => array( |
|
| 635 | - 'preview_message' => array( |
|
| 636 | - 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 637 | - 'callback' => 'preview_message_help_tab', |
|
| 638 | - ), |
|
| 639 | - ), |
|
| 640 | - 'require_nonce' => false, |
|
| 641 | - ), |
|
| 642 | - 'settings' => array( |
|
| 643 | - 'nav' => array( |
|
| 644 | - 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 645 | - 'order' => 40, |
|
| 646 | - ), |
|
| 647 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 648 | - 'help_tabs' => array( |
|
| 649 | - 'messages_settings_help_tab' => array( |
|
| 650 | - 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 651 | - 'filename' => 'messages_settings', |
|
| 652 | - ), |
|
| 653 | - 'messages_settings_message_types_help_tab' => array( |
|
| 654 | - 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 655 | - 'filename' => 'messages_settings_message_types', |
|
| 656 | - ), |
|
| 657 | - 'messages_settings_messengers_help_tab' => array( |
|
| 658 | - 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 659 | - 'filename' => 'messages_settings_messengers', |
|
| 660 | - ), |
|
| 661 | - ), |
|
| 662 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 663 | - 'require_nonce' => false, |
|
| 664 | - ), |
|
| 665 | - ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - protected function _add_screen_options() |
|
| 670 | - { |
|
| 671 | - // todo |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - protected function _add_screen_options_global_mtps() |
|
| 676 | - { |
|
| 677 | - /** |
|
| 678 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 679 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 680 | - */ |
|
| 681 | - $page_title = $this->_admin_page_title; |
|
| 682 | - $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 683 | - $this->_per_page_screen_option(); |
|
| 684 | - $this->_admin_page_title = $page_title; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - protected function _add_screen_options_default() |
|
| 689 | - { |
|
| 690 | - $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 691 | - $this->_per_page_screen_option(); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - // none of the below group are currently used for Messages |
|
| 696 | - protected function _add_feature_pointers() |
|
| 697 | - { |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - public function admin_init() |
|
| 701 | - { |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - public function admin_notices() |
|
| 705 | - { |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - public function admin_footer_scripts() |
|
| 709 | - { |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - public function messages_help_tab() |
|
| 714 | - { |
|
| 715 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - public function messengers_help_tab() |
|
| 720 | - { |
|
| 721 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - public function message_types_help_tab() |
|
| 726 | - { |
|
| 727 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - public function messages_overview_help_tab() |
|
| 732 | - { |
|
| 733 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - public function message_templates_help_tab() |
|
| 738 | - { |
|
| 739 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - public function edit_message_template_help_tab() |
|
| 744 | - { |
|
| 745 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 746 | - . esc_attr__('Editor Title', 'event_espresso') |
|
| 747 | - . '" />'; |
|
| 748 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 749 | - . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 750 | - . '" />'; |
|
| 751 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 752 | - . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 753 | - . '" />'; |
|
| 754 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 755 | - . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 756 | - . '" />'; |
|
| 757 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 758 | - . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 759 | - . '" />'; |
|
| 760 | - EEH_Template::display_template( |
|
| 761 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 762 | - $args |
|
| 763 | - ); |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - public function message_template_shortcodes_help_tab() |
|
| 768 | - { |
|
| 769 | - $this->_set_shortcodes(); |
|
| 770 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 771 | - EEH_Template::display_template( |
|
| 772 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 773 | - $args |
|
| 774 | - ); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - public function preview_message_help_tab() |
|
| 779 | - { |
|
| 780 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - |
|
| 784 | - public function settings_help_tab() |
|
| 785 | - { |
|
| 786 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 787 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 788 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 789 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 790 | - $args['img3'] = '<div class="switch">' |
|
| 791 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 792 | - . ' type="checkbox" checked="checked">' |
|
| 793 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 794 | - . '</div>'; |
|
| 795 | - $args['img4'] = '<div class="switch">' |
|
| 796 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 797 | - . ' type="checkbox">' |
|
| 798 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 799 | - . '</div>'; |
|
| 800 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - public function load_scripts_styles() |
|
| 805 | - { |
|
| 806 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 807 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 808 | - |
|
| 809 | - wp_register_script( |
|
| 810 | - 'ee-messages-settings', |
|
| 811 | - EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 812 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), |
|
| 813 | - EVENT_ESPRESSO_VERSION, |
|
| 814 | - true |
|
| 815 | - ); |
|
| 816 | - wp_register_script( |
|
| 817 | - 'ee-msg-list-table-js', |
|
| 818 | - EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 819 | - array('ee-dialog'), |
|
| 820 | - EVENT_ESPRESSO_VERSION |
|
| 821 | - ); |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - public function load_scripts_styles_default() |
|
| 826 | - { |
|
| 827 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - public function wp_editor_css($mce_css) |
|
| 832 | - { |
|
| 833 | - // if we're on the edit_message_template route |
|
| 834 | - if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 835 | - $message_type_name = $this->_active_message_type_name; |
|
| 836 | - |
|
| 837 | - // we're going to REPLACE the existing mce css |
|
| 838 | - // we need to get the css file location from the active messenger |
|
| 839 | - $mce_css = $this->_active_messenger->get_variation( |
|
| 840 | - $this->_template_pack, |
|
| 841 | - $message_type_name, |
|
| 842 | - true, |
|
| 843 | - 'wpeditor', |
|
| 844 | - $this->_variation |
|
| 845 | - ); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - return $mce_css; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - public function load_scripts_styles_edit_message_template() |
|
| 853 | - { |
|
| 854 | - |
|
| 855 | - $this->_set_shortcodes(); |
|
| 856 | - |
|
| 857 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 858 | - esc_html__( |
|
| 859 | - 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 860 | - 'event_espresso' |
|
| 861 | - ), |
|
| 862 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 863 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 864 | - ); |
|
| 865 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 866 | - 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 867 | - 'event_espresso' |
|
| 868 | - ); |
|
| 869 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 870 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 871 | - 'event_espresso' |
|
| 872 | - ); |
|
| 873 | - |
|
| 874 | - wp_register_script( |
|
| 875 | - 'ee_msgs_edit_js', |
|
| 876 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 877 | - array('jquery'), |
|
| 878 | - EVENT_ESPRESSO_VERSION |
|
| 879 | - ); |
|
| 880 | - |
|
| 881 | - wp_enqueue_script('ee_admin_js'); |
|
| 882 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 883 | - |
|
| 884 | - // add in special css for tiny_mce |
|
| 885 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - |
|
| 889 | - public function load_scripts_styles_display_preview_message() |
|
| 890 | - { |
|
| 891 | - |
|
| 892 | - $this->_set_message_template_group(); |
|
| 893 | - |
|
| 894 | - if (isset($this->_req_data['messenger'])) { |
|
| 895 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 896 | - $this->_req_data['messenger'] |
|
| 897 | - ); |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - wp_enqueue_style( |
|
| 904 | - 'espresso_preview_css', |
|
| 905 | - $this->_active_messenger->get_variation( |
|
| 906 | - $this->_template_pack, |
|
| 907 | - $message_type_name, |
|
| 908 | - true, |
|
| 909 | - 'preview', |
|
| 910 | - $this->_variation |
|
| 911 | - ) |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - public function load_scripts_styles_settings() |
|
| 917 | - { |
|
| 918 | - wp_register_style( |
|
| 919 | - 'ee-message-settings', |
|
| 920 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 921 | - array(), |
|
| 922 | - EVENT_ESPRESSO_VERSION |
|
| 923 | - ); |
|
| 924 | - wp_enqueue_style('ee-text-links'); |
|
| 925 | - wp_enqueue_style('ee-message-settings'); |
|
| 926 | - wp_enqueue_script('ee-messages-settings'); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * set views array for List Table |
|
| 932 | - */ |
|
| 933 | - public function _set_list_table_views_global_mtps() |
|
| 934 | - { |
|
| 935 | - $this->_views = array( |
|
| 936 | - 'in_use' => array( |
|
| 937 | - 'slug' => 'in_use', |
|
| 938 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 939 | - 'count' => 0, |
|
| 940 | - ), |
|
| 941 | - ); |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * Set views array for the Custom Template List Table |
|
| 947 | - */ |
|
| 948 | - public function _set_list_table_views_custom_mtps() |
|
| 949 | - { |
|
| 950 | - $this->_set_list_table_views_global_mtps(); |
|
| 951 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 952 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * set views array for message queue list table |
|
| 959 | - * |
|
| 960 | - * @throws InvalidDataTypeException |
|
| 961 | - * @throws InvalidInterfaceException |
|
| 962 | - * @throws InvalidArgumentException |
|
| 963 | - * @throws EE_Error |
|
| 964 | - * @throws ReflectionException |
|
| 965 | - */ |
|
| 966 | - public function _set_list_table_views_default() |
|
| 967 | - { |
|
| 968 | - EE_Registry::instance()->load_helper('Template'); |
|
| 969 | - |
|
| 970 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 971 | - 'ee_send_message', |
|
| 972 | - 'message_list_table_bulk_actions' |
|
| 973 | - ) |
|
| 974 | - ? array( |
|
| 975 | - 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 976 | - 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 977 | - 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 978 | - 'send_now' => esc_html__('Send Now', 'event_espresso'), |
|
| 979 | - ) |
|
| 980 | - : array(); |
|
| 981 | - |
|
| 982 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 983 | - 'ee_delete_messages', |
|
| 984 | - 'message_list_table_bulk_actions' |
|
| 985 | - ) |
|
| 986 | - ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 987 | - : array(); |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - $this->_views = array( |
|
| 991 | - 'all' => array( |
|
| 992 | - 'slug' => 'all', |
|
| 993 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 994 | - 'count' => 0, |
|
| 995 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action), |
|
| 996 | - ), |
|
| 997 | - ); |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 1001 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 1002 | - continue; |
|
| 1003 | - } |
|
| 1004 | - $status_bulk_actions = $common_bulk_actions; |
|
| 1005 | - // unset bulk actions not applying to status |
|
| 1006 | - if (! empty($status_bulk_actions)) { |
|
| 1007 | - switch ($status) { |
|
| 1008 | - case EEM_Message::status_idle: |
|
| 1009 | - case EEM_Message::status_resend: |
|
| 1010 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 1011 | - break; |
|
| 1012 | - |
|
| 1013 | - case EEM_Message::status_failed: |
|
| 1014 | - case EEM_Message::status_debug_only: |
|
| 1015 | - case EEM_Message::status_messenger_executing: |
|
| 1016 | - $status_bulk_actions = array(); |
|
| 1017 | - break; |
|
| 1018 | - |
|
| 1019 | - case EEM_Message::status_incomplete: |
|
| 1020 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1021 | - break; |
|
| 1022 | - |
|
| 1023 | - case EEM_Message::status_retry: |
|
| 1024 | - case EEM_Message::status_sent: |
|
| 1025 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1026 | - break; |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - // skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1031 | - if ($status === EEM_Message::status_messenger_executing) { |
|
| 1032 | - continue; |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - $this->_views[ strtolower($status) ] = array( |
|
| 1036 | - 'slug' => strtolower($status), |
|
| 1037 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1038 | - 'count' => 0, |
|
| 1039 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action), |
|
| 1040 | - ); |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - |
|
| 1045 | - protected function _ee_default_messages_overview_list_table() |
|
| 1046 | - { |
|
| 1047 | - $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1048 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - protected function _message_queue_list_table() |
|
| 1053 | - { |
|
| 1054 | - $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1055 | - $this->_template_args['per_column'] = 6; |
|
| 1056 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1057 | - $this->_template_args['before_list_table'] = '<h3>' |
|
| 1058 | - . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1059 | - . '</h3>'; |
|
| 1060 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - |
|
| 1064 | - protected function _message_legend_items() |
|
| 1065 | - { |
|
| 1066 | - |
|
| 1067 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1068 | - $action_items = array(); |
|
| 1069 | - |
|
| 1070 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1071 | - if ($action_item === 'see_notifications_for') { |
|
| 1072 | - continue; |
|
| 1073 | - } |
|
| 1074 | - $action_items[ $action_item ] = array( |
|
| 1075 | - 'class' => $action_details['css_class'], |
|
| 1076 | - 'desc' => $action_details['label'], |
|
| 1077 | - ); |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - /** @type array $status_items status legend setup */ |
|
| 1081 | - $status_items = array( |
|
| 1082 | - 'incomplete_status' => array( |
|
| 1083 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1084 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'), |
|
| 1085 | - ), |
|
| 1086 | - 'idle_status' => array( |
|
| 1087 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1088 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'), |
|
| 1089 | - ), |
|
| 1090 | - 'resend_status' => array( |
|
| 1091 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1092 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'), |
|
| 1093 | - ), |
|
| 1094 | - 'messenger_executing_status' => array( |
|
| 1095 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1096 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'), |
|
| 1097 | - ), |
|
| 1098 | - 'sent_status' => array( |
|
| 1099 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1100 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'), |
|
| 1101 | - ), |
|
| 1102 | - 'retry_status' => array( |
|
| 1103 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1104 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'), |
|
| 1105 | - ), |
|
| 1106 | - 'failed_status' => array( |
|
| 1107 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1108 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'), |
|
| 1109 | - ), |
|
| 1110 | - ); |
|
| 1111 | - if (EEM_Message::debug()) { |
|
| 1112 | - $status_items['debug_only_status'] = array( |
|
| 1113 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1114 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'), |
|
| 1115 | - ); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - return array_merge($action_items, $status_items); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - |
|
| 1122 | - protected function _custom_mtps_preview() |
|
| 1123 | - { |
|
| 1124 | - $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1125 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1126 | - . ' alt="' . esc_attr__( |
|
| 1127 | - 'Preview Custom Message Templates screenshot', |
|
| 1128 | - 'event_espresso' |
|
| 1129 | - ) . '" />'; |
|
| 1130 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 1131 | - . esc_html__( |
|
| 1132 | - 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1133 | - 'event_espresso' |
|
| 1134 | - ) |
|
| 1135 | - . '</strong>'; |
|
| 1136 | - |
|
| 1137 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - |
|
| 1141 | - /** |
|
| 1142 | - * get_message_templates |
|
| 1143 | - * This gets all the message templates for listing on the overview list. |
|
| 1144 | - * |
|
| 1145 | - * @access public |
|
| 1146 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1147 | - * @param string $type the current _view we're getting templates for |
|
| 1148 | - * @param bool $count return count? |
|
| 1149 | - * @param bool $all disregard any paging info (get all data); |
|
| 1150 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1151 | - * @return array |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - * @throws InvalidArgumentException |
|
| 1154 | - * @throws InvalidDataTypeException |
|
| 1155 | - * @throws InvalidInterfaceException |
|
| 1156 | - */ |
|
| 1157 | - public function get_message_templates( |
|
| 1158 | - $perpage = 10, |
|
| 1159 | - $type = 'in_use', |
|
| 1160 | - $count = false, |
|
| 1161 | - $all = false, |
|
| 1162 | - $global = true |
|
| 1163 | - ) { |
|
| 1164 | - |
|
| 1165 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1166 | - |
|
| 1167 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1168 | - $orderby = $this->_req_data['orderby']; |
|
| 1169 | - |
|
| 1170 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1171 | - ? $this->_req_data['order'] |
|
| 1172 | - : 'ASC'; |
|
| 1173 | - |
|
| 1174 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1175 | - ? $this->_req_data['paged'] |
|
| 1176 | - : 1; |
|
| 1177 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1178 | - ? $this->_req_data['perpage'] |
|
| 1179 | - : $perpage; |
|
| 1180 | - |
|
| 1181 | - $offset = ($current_page - 1) * $per_page; |
|
| 1182 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - // options will match what is in the _views array property |
|
| 1186 | - switch ($type) { |
|
| 1187 | - case 'in_use': |
|
| 1188 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1189 | - break; |
|
| 1190 | - default: |
|
| 1191 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - return $templates; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * filters etc might need a list of installed message_types |
|
| 1200 | - * |
|
| 1201 | - * @return array an array of message type objects |
|
| 1202 | - */ |
|
| 1203 | - public function get_installed_message_types() |
|
| 1204 | - { |
|
| 1205 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1206 | - $installed = array(); |
|
| 1207 | - |
|
| 1208 | - foreach ($installed_message_types as $message_type) { |
|
| 1209 | - $installed[ $message_type->name ] = $message_type; |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - return $installed; |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * _add_message_template |
|
| 1218 | - * |
|
| 1219 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1220 | - * |
|
| 1221 | - * @param string $message_type |
|
| 1222 | - * @param string $messenger |
|
| 1223 | - * @param string $GRP_ID |
|
| 1224 | - * |
|
| 1225 | - * @throws EE_error |
|
| 1226 | - */ |
|
| 1227 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1228 | - { |
|
| 1229 | - // set values override any request data |
|
| 1230 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1231 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1232 | - ? $this->_req_data['message_type'] |
|
| 1233 | - : $message_type; |
|
| 1234 | - |
|
| 1235 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1236 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1237 | - ? $this->_req_data['messenger'] |
|
| 1238 | - : $messenger; |
|
| 1239 | - |
|
| 1240 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1241 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1242 | - |
|
| 1243 | - // we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1244 | - if (empty($message_type) || empty($messenger)) { |
|
| 1245 | - throw new EE_Error( |
|
| 1246 | - esc_html__( |
|
| 1247 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1248 | - 'event_espresso' |
|
| 1249 | - ) |
|
| 1250 | - ); |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - // we need the GRP_ID for the template being used as the base for the new template |
|
| 1254 | - if (empty($GRP_ID)) { |
|
| 1255 | - throw new EE_Error( |
|
| 1256 | - esc_html__( |
|
| 1257 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1258 | - 'event_espresso' |
|
| 1259 | - ) |
|
| 1260 | - ); |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - // let's just make sure the template gets generated! |
|
| 1264 | - |
|
| 1265 | - // we need to reassign some variables for what the insert is expecting |
|
| 1266 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1267 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1268 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1269 | - $this->_insert_or_update_message_template(true); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * public wrapper for the _add_message_template method |
|
| 1275 | - * |
|
| 1276 | - * @param string $message_type message type slug |
|
| 1277 | - * @param string $messenger messenger slug |
|
| 1278 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1279 | - * off of. |
|
| 1280 | - * @throws EE_error |
|
| 1281 | - */ |
|
| 1282 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1283 | - { |
|
| 1284 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * _edit_message_template |
|
| 1290 | - * |
|
| 1291 | - * @access protected |
|
| 1292 | - * @return void |
|
| 1293 | - * @throws InvalidIdentifierException |
|
| 1294 | - * @throws DomainException |
|
| 1295 | - * @throws EE_Error |
|
| 1296 | - * @throws InvalidArgumentException |
|
| 1297 | - * @throws ReflectionException |
|
| 1298 | - * @throws InvalidDataTypeException |
|
| 1299 | - * @throws InvalidInterfaceException |
|
| 1300 | - */ |
|
| 1301 | - protected function _edit_message_template() |
|
| 1302 | - { |
|
| 1303 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1304 | - $template_fields = ''; |
|
| 1305 | - $sidebar_fields = ''; |
|
| 1306 | - // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1307 | - // valid html in the templates. |
|
| 1308 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1309 | - |
|
| 1310 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1311 | - ? absint($this->_req_data['id']) |
|
| 1312 | - : false; |
|
| 1313 | - |
|
| 1314 | - $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) |
|
| 1315 | - ? absint($this->_req_data['evt_id']) |
|
| 1316 | - : false; |
|
| 1317 | - |
|
| 1318 | - $this->_set_shortcodes(); // this also sets the _message_template property. |
|
| 1319 | - $message_template_group = $this->_message_template_group; |
|
| 1320 | - $c_label = $message_template_group->context_label(); |
|
| 1321 | - $c_config = $message_template_group->contexts_config(); |
|
| 1322 | - |
|
| 1323 | - reset($c_config); |
|
| 1324 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1325 | - ? strtolower($this->_req_data['context']) |
|
| 1326 | - : key($c_config); |
|
| 1327 | - |
|
| 1328 | - |
|
| 1329 | - if (empty($GRP_ID)) { |
|
| 1330 | - $action = 'insert_message_template'; |
|
| 1331 | - $edit_message_template_form_url = add_query_arg( |
|
| 1332 | - array('action' => $action, 'noheader' => true), |
|
| 1333 | - EE_MSG_ADMIN_URL |
|
| 1334 | - ); |
|
| 1335 | - } else { |
|
| 1336 | - $action = 'update_message_template'; |
|
| 1337 | - $edit_message_template_form_url = add_query_arg( |
|
| 1338 | - array('action' => $action, 'noheader' => true), |
|
| 1339 | - EE_MSG_ADMIN_URL |
|
| 1340 | - ); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - // set active messenger for this view |
|
| 1344 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1345 | - $message_template_group->messenger() |
|
| 1346 | - ); |
|
| 1347 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - // Do we have any validation errors? |
|
| 1351 | - $validators = $this->_get_transient(); |
|
| 1352 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1353 | - |
|
| 1354 | - |
|
| 1355 | - // we need to assemble the title from Various details |
|
| 1356 | - $context_label = sprintf( |
|
| 1357 | - esc_html__('(%s %s)', 'event_espresso'), |
|
| 1358 | - $c_config[ $context ]['label'], |
|
| 1359 | - ucwords($c_label['label']) |
|
| 1360 | - ); |
|
| 1361 | - |
|
| 1362 | - $title = sprintf( |
|
| 1363 | - esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1364 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1365 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1366 | - $context_label |
|
| 1367 | - ); |
|
| 1368 | - |
|
| 1369 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1370 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1371 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - // let's get EEH_MSG_Template so we can get template form fields |
|
| 1375 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1376 | - $message_template_group->messenger(), |
|
| 1377 | - $message_template_group->message_type() |
|
| 1378 | - ); |
|
| 1379 | - |
|
| 1380 | - if (! $template_field_structure) { |
|
| 1381 | - $template_field_structure = false; |
|
| 1382 | - $template_fields = esc_html__( |
|
| 1383 | - 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1384 | - 'event_espresso' |
|
| 1385 | - ); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - |
|
| 1389 | - $message_templates = $message_template_group->context_templates(); |
|
| 1390 | - |
|
| 1391 | - |
|
| 1392 | - // if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1393 | - // will get handled in the "extra" array. |
|
| 1394 | - if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { |
|
| 1395 | - foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { |
|
| 1396 | - unset($template_field_structure[ $context ][ $reference_field ]); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - // let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1401 | - if (! empty($template_field_structure)) { |
|
| 1402 | - foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { |
|
| 1403 | - // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1404 | - // the extra array and reset them. |
|
| 1405 | - if ($template_field === 'extra') { |
|
| 1406 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1407 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1408 | - $message_template = $message_templates[ $context ][ $reference_field ]; |
|
| 1409 | - $content = $message_template instanceof EE_Message_Template |
|
| 1410 | - ? $message_template->get('MTP_content') |
|
| 1411 | - : ''; |
|
| 1412 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1413 | - // let's verify if we need this extra field via the shortcodes parameter. |
|
| 1414 | - $continue = false; |
|
| 1415 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1416 | - foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1417 | - if (! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1418 | - $continue = true; |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - if ($continue) { |
|
| 1422 | - continue; |
|
| 1423 | - } |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - $field_id = $reference_field |
|
| 1427 | - . '-' |
|
| 1428 | - . $extra_field |
|
| 1429 | - . '-content'; |
|
| 1430 | - $template_form_fields[ $field_id ] = $extra_array; |
|
| 1431 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' |
|
| 1432 | - . $reference_field |
|
| 1433 | - . '][content][' |
|
| 1434 | - . $extra_field . ']'; |
|
| 1435 | - $css_class = isset($extra_array['css_class']) |
|
| 1436 | - ? $extra_array['css_class'] |
|
| 1437 | - : ''; |
|
| 1438 | - |
|
| 1439 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) |
|
| 1440 | - && in_array($extra_field, $v_fields, true) |
|
| 1441 | - && |
|
| 1442 | - ( |
|
| 1443 | - is_array($validators[ $extra_field ]) |
|
| 1444 | - && isset($validators[ $extra_field ]['msg']) |
|
| 1445 | - ) |
|
| 1446 | - ? 'validate-error ' . $css_class |
|
| 1447 | - : $css_class; |
|
| 1448 | - |
|
| 1449 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) |
|
| 1450 | - && isset($content[ $extra_field ]) |
|
| 1451 | - ? $content[ $extra_field ] |
|
| 1452 | - : ''; |
|
| 1453 | - |
|
| 1454 | - // do we have a validation error? if we do then let's use that value instead |
|
| 1455 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ]) |
|
| 1456 | - ? $validators[ $extra_field ]['value'] |
|
| 1457 | - : $template_form_fields[ $field_id ]['value']; |
|
| 1458 | - |
|
| 1459 | - |
|
| 1460 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; |
|
| 1461 | - |
|
| 1462 | - // shortcode selector |
|
| 1463 | - $field_name_to_use = $extra_field === 'main' |
|
| 1464 | - ? 'content' |
|
| 1465 | - : $extra_field; |
|
| 1466 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( |
|
| 1467 | - $field_name_to_use, |
|
| 1468 | - $field_id |
|
| 1469 | - ); |
|
| 1470 | - |
|
| 1471 | - if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1472 | - // we want to decode the entities |
|
| 1473 | - $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value']; |
|
| 1474 | - }/**/ |
|
| 1475 | - } |
|
| 1476 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1477 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1478 | - |
|
| 1479 | - $template_form_fields[ $templatefield_MTP_id ] = array( |
|
| 1480 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1481 | - 'label' => null, |
|
| 1482 | - 'input' => 'hidden', |
|
| 1483 | - 'type' => 'int', |
|
| 1484 | - 'required' => false, |
|
| 1485 | - 'validation' => false, |
|
| 1486 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1487 | - 'css_class' => '', |
|
| 1488 | - 'format' => '%d', |
|
| 1489 | - 'db-col' => 'MTP_ID', |
|
| 1490 | - ); |
|
| 1491 | - |
|
| 1492 | - $template_form_fields[ $templatefield_templatename_id ] = array( |
|
| 1493 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1494 | - 'label' => null, |
|
| 1495 | - 'input' => 'hidden', |
|
| 1496 | - 'type' => 'string', |
|
| 1497 | - 'required' => false, |
|
| 1498 | - 'validation' => true, |
|
| 1499 | - 'value' => $reference_field, |
|
| 1500 | - 'css_class' => '', |
|
| 1501 | - 'format' => '%s', |
|
| 1502 | - 'db-col' => 'MTP_template_field', |
|
| 1503 | - ); |
|
| 1504 | - } |
|
| 1505 | - continue; // skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1506 | - } else { |
|
| 1507 | - $field_id = $template_field . '-content'; |
|
| 1508 | - $template_form_fields[ $field_id ] = $field_setup_array; |
|
| 1509 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1510 | - $message_template = isset($message_templates[ $context ][ $template_field ]) |
|
| 1511 | - ? $message_templates[ $context ][ $template_field ] |
|
| 1512 | - : null; |
|
| 1513 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) |
|
| 1514 | - && is_array($message_templates[ $context ]) |
|
| 1515 | - && $message_template instanceof EE_Message_Template |
|
| 1516 | - ? $message_template->get('MTP_content') |
|
| 1517 | - : ''; |
|
| 1518 | - |
|
| 1519 | - // do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1520 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ]) |
|
| 1521 | - ? $validators[ $template_field ]['value'] |
|
| 1522 | - : $template_form_fields[ $field_id ]['value']; |
|
| 1523 | - |
|
| 1524 | - |
|
| 1525 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; |
|
| 1526 | - $css_class = isset($field_setup_array['css_class']) |
|
| 1527 | - ? $field_setup_array['css_class'] |
|
| 1528 | - : ''; |
|
| 1529 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) |
|
| 1530 | - && in_array($template_field, $v_fields, true) |
|
| 1531 | - && isset($validators[ $template_field ]['msg']) |
|
| 1532 | - ? 'validate-error ' . $css_class |
|
| 1533 | - : $css_class; |
|
| 1534 | - |
|
| 1535 | - // shortcode selector |
|
| 1536 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( |
|
| 1537 | - $template_field, |
|
| 1538 | - $field_id |
|
| 1539 | - ); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - // k took care of content field(s) now let's take care of others. |
|
| 1543 | - |
|
| 1544 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1545 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1546 | - |
|
| 1547 | - // foreach template field there are actually two form fields created |
|
| 1548 | - $template_form_fields[ $templatefield_MTP_id ] = array( |
|
| 1549 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1550 | - 'label' => null, |
|
| 1551 | - 'input' => 'hidden', |
|
| 1552 | - 'type' => 'int', |
|
| 1553 | - 'required' => false, |
|
| 1554 | - 'validation' => true, |
|
| 1555 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1556 | - 'css_class' => '', |
|
| 1557 | - 'format' => '%d', |
|
| 1558 | - 'db-col' => 'MTP_ID', |
|
| 1559 | - ); |
|
| 1560 | - |
|
| 1561 | - $template_form_fields[ $templatefield_field_templatename_id ] = array( |
|
| 1562 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1563 | - 'label' => null, |
|
| 1564 | - 'input' => 'hidden', |
|
| 1565 | - 'type' => 'string', |
|
| 1566 | - 'required' => false, |
|
| 1567 | - 'validation' => true, |
|
| 1568 | - 'value' => $template_field, |
|
| 1569 | - 'css_class' => '', |
|
| 1570 | - 'format' => '%s', |
|
| 1571 | - 'db-col' => 'MTP_template_field', |
|
| 1572 | - ); |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - // add other fields |
|
| 1576 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1577 | - 'name' => 'MTP_context', |
|
| 1578 | - 'label' => null, |
|
| 1579 | - 'input' => 'hidden', |
|
| 1580 | - 'type' => 'string', |
|
| 1581 | - 'required' => false, |
|
| 1582 | - 'validation' => true, |
|
| 1583 | - 'value' => $context, |
|
| 1584 | - 'css_class' => '', |
|
| 1585 | - 'format' => '%s', |
|
| 1586 | - 'db-col' => 'MTP_context', |
|
| 1587 | - ); |
|
| 1588 | - |
|
| 1589 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1590 | - 'name' => 'GRP_ID', |
|
| 1591 | - 'label' => null, |
|
| 1592 | - 'input' => 'hidden', |
|
| 1593 | - 'type' => 'int', |
|
| 1594 | - 'required' => false, |
|
| 1595 | - 'validation' => true, |
|
| 1596 | - 'value' => $GRP_ID, |
|
| 1597 | - 'css_class' => '', |
|
| 1598 | - 'format' => '%d', |
|
| 1599 | - 'db-col' => 'GRP_ID', |
|
| 1600 | - ); |
|
| 1601 | - |
|
| 1602 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1603 | - 'name' => 'MTP_messenger', |
|
| 1604 | - 'label' => null, |
|
| 1605 | - 'input' => 'hidden', |
|
| 1606 | - 'type' => 'string', |
|
| 1607 | - 'required' => false, |
|
| 1608 | - 'validation' => true, |
|
| 1609 | - 'value' => $message_template_group->messenger(), |
|
| 1610 | - 'css_class' => '', |
|
| 1611 | - 'format' => '%s', |
|
| 1612 | - 'db-col' => 'MTP_messenger', |
|
| 1613 | - ); |
|
| 1614 | - |
|
| 1615 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1616 | - 'name' => 'MTP_message_type', |
|
| 1617 | - 'label' => null, |
|
| 1618 | - 'input' => 'hidden', |
|
| 1619 | - 'type' => 'string', |
|
| 1620 | - 'required' => false, |
|
| 1621 | - 'validation' => true, |
|
| 1622 | - 'value' => $message_template_group->message_type(), |
|
| 1623 | - 'css_class' => '', |
|
| 1624 | - 'format' => '%s', |
|
| 1625 | - 'db-col' => 'MTP_message_type', |
|
| 1626 | - ); |
|
| 1627 | - |
|
| 1628 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1629 | - 'name' => 'MTP_is_global', |
|
| 1630 | - 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1631 | - 'input' => 'hidden', |
|
| 1632 | - 'type' => 'int', |
|
| 1633 | - 'required' => false, |
|
| 1634 | - 'validation' => true, |
|
| 1635 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1636 | - 'css_class' => '', |
|
| 1637 | - 'format' => '%d', |
|
| 1638 | - 'db-col' => 'MTP_is_global', |
|
| 1639 | - ); |
|
| 1640 | - |
|
| 1641 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1642 | - 'name' => 'MTP_is_override', |
|
| 1643 | - 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1644 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1645 | - 'type' => 'int', |
|
| 1646 | - 'required' => false, |
|
| 1647 | - 'validation' => true, |
|
| 1648 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1649 | - 'css_class' => '', |
|
| 1650 | - 'format' => '%d', |
|
| 1651 | - 'db-col' => 'MTP_is_override', |
|
| 1652 | - ); |
|
| 1653 | - |
|
| 1654 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1655 | - 'name' => 'MTP_is_active', |
|
| 1656 | - 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1657 | - 'input' => 'hidden', |
|
| 1658 | - 'type' => 'int', |
|
| 1659 | - 'required' => false, |
|
| 1660 | - 'validation' => true, |
|
| 1661 | - 'value' => $message_template_group->is_active(), |
|
| 1662 | - 'css_class' => '', |
|
| 1663 | - 'format' => '%d', |
|
| 1664 | - 'db-col' => 'MTP_is_active', |
|
| 1665 | - ); |
|
| 1666 | - |
|
| 1667 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1668 | - 'name' => 'MTP_deleted', |
|
| 1669 | - 'label' => null, |
|
| 1670 | - 'input' => 'hidden', |
|
| 1671 | - 'type' => 'int', |
|
| 1672 | - 'required' => false, |
|
| 1673 | - 'validation' => true, |
|
| 1674 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1675 | - 'css_class' => '', |
|
| 1676 | - 'format' => '%d', |
|
| 1677 | - 'db-col' => 'MTP_deleted', |
|
| 1678 | - ); |
|
| 1679 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1680 | - 'name' => 'MTP_user_id', |
|
| 1681 | - 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1682 | - 'input' => 'hidden', |
|
| 1683 | - 'type' => 'int', |
|
| 1684 | - 'required' => false, |
|
| 1685 | - 'validation' => false, |
|
| 1686 | - 'value' => $message_template_group->user(), |
|
| 1687 | - 'format' => '%d', |
|
| 1688 | - 'db-col' => 'MTP_user_id', |
|
| 1689 | - ); |
|
| 1690 | - |
|
| 1691 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1692 | - 'name' => 'action', |
|
| 1693 | - 'input' => 'hidden', |
|
| 1694 | - 'type' => 'string', |
|
| 1695 | - 'value' => $action, |
|
| 1696 | - ); |
|
| 1697 | - |
|
| 1698 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1699 | - 'name' => 'id', |
|
| 1700 | - 'input' => 'hidden', |
|
| 1701 | - 'type' => 'int', |
|
| 1702 | - 'value' => $GRP_ID, |
|
| 1703 | - ); |
|
| 1704 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1705 | - 'name' => $action . '_nonce', |
|
| 1706 | - 'input' => 'hidden', |
|
| 1707 | - 'type' => 'string', |
|
| 1708 | - 'value' => wp_create_nonce($action . '_nonce'), |
|
| 1709 | - ); |
|
| 1710 | - |
|
| 1711 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1712 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1713 | - 'name' => 'template_switch', |
|
| 1714 | - 'input' => 'hidden', |
|
| 1715 | - 'type' => 'int', |
|
| 1716 | - 'value' => 1, |
|
| 1717 | - ); |
|
| 1718 | - } |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1722 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1723 | - } //end if ( !empty($template_field_structure) ) |
|
| 1724 | - |
|
| 1725 | - // set extra content for publish box |
|
| 1726 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1727 | - $this->_set_publish_post_box_vars( |
|
| 1728 | - 'id', |
|
| 1729 | - $GRP_ID, |
|
| 1730 | - false, |
|
| 1731 | - add_query_arg( |
|
| 1732 | - array('action' => 'global_mtps'), |
|
| 1733 | - $this->_admin_base_url |
|
| 1734 | - ) |
|
| 1735 | - ); |
|
| 1736 | - |
|
| 1737 | - // add preview button |
|
| 1738 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1739 | - array( |
|
| 1740 | - 'message_type' => $message_template_group->message_type(), |
|
| 1741 | - 'messenger' => $message_template_group->messenger(), |
|
| 1742 | - 'context' => $context, |
|
| 1743 | - 'GRP_ID' => $GRP_ID, |
|
| 1744 | - 'evt_id' => $EVT_ID, |
|
| 1745 | - 'action' => 'preview_message', |
|
| 1746 | - ), |
|
| 1747 | - $this->_admin_base_url |
|
| 1748 | - ); |
|
| 1749 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1750 | - . esc_html__('Preview', 'event_espresso') |
|
| 1751 | - . '</a>'; |
|
| 1752 | - |
|
| 1753 | - |
|
| 1754 | - // setup context switcher |
|
| 1755 | - $context_switcher_args = array( |
|
| 1756 | - 'page' => 'espresso_messages', |
|
| 1757 | - 'action' => 'edit_message_template', |
|
| 1758 | - 'id' => $GRP_ID, |
|
| 1759 | - 'evt_id' => $EVT_ID, |
|
| 1760 | - 'context' => $context, |
|
| 1761 | - 'extra' => $preview_button, |
|
| 1762 | - ); |
|
| 1763 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1764 | - |
|
| 1765 | - |
|
| 1766 | - // main box |
|
| 1767 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1768 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1769 | - $this->_template_args['action'] = $action; |
|
| 1770 | - $this->_template_args['context'] = $context; |
|
| 1771 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1772 | - $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1773 | - $this->_learn_more_about_message_templates_link(); |
|
| 1774 | - |
|
| 1775 | - |
|
| 1776 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1777 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1778 | - $message_template_group, |
|
| 1779 | - $context, |
|
| 1780 | - $context_label |
|
| 1781 | - ); |
|
| 1782 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1783 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1784 | - |
|
| 1785 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1786 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1787 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1788 | - |
|
| 1789 | - // send along EE_Message_Template_Group object for further template use. |
|
| 1790 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1791 | - |
|
| 1792 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1793 | - $this->_template_path, |
|
| 1794 | - $this->_template_args, |
|
| 1795 | - true |
|
| 1796 | - ); |
|
| 1797 | - |
|
| 1798 | - |
|
| 1799 | - // finally, let's set the admin_page title |
|
| 1800 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1801 | - |
|
| 1802 | - |
|
| 1803 | - // we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1804 | - $this->_set_shortcodes(); |
|
| 1805 | - |
|
| 1806 | - |
|
| 1807 | - // final template wrapper |
|
| 1808 | - $this->display_admin_page_with_sidebar(); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - |
|
| 1812 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1813 | - { |
|
| 1814 | - return $mceInit; |
|
| 1815 | - } |
|
| 1816 | - |
|
| 1817 | - |
|
| 1818 | - public function add_context_switcher() |
|
| 1819 | - { |
|
| 1820 | - return $this->_context_switcher; |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - |
|
| 1824 | - /** |
|
| 1825 | - * Adds the activation/deactivation toggle for the message template context. |
|
| 1826 | - * |
|
| 1827 | - * @param EE_Message_Template_Group $message_template_group |
|
| 1828 | - * @param string $context |
|
| 1829 | - * @param string $context_label |
|
| 1830 | - * @return string |
|
| 1831 | - * @throws DomainException |
|
| 1832 | - * @throws EE_Error |
|
| 1833 | - * @throws InvalidIdentifierException |
|
| 1834 | - */ |
|
| 1835 | - protected function add_active_context_element( |
|
| 1836 | - EE_Message_Template_Group $message_template_group, |
|
| 1837 | - $context, |
|
| 1838 | - $context_label |
|
| 1839 | - ) { |
|
| 1840 | - $template_args = array( |
|
| 1841 | - 'context' => $context, |
|
| 1842 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1843 | - 'is_active' => $message_template_group->is_context_active($context), |
|
| 1844 | - 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1845 | - ? 'context-off' |
|
| 1846 | - : 'context-on', |
|
| 1847 | - 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1848 | - 'message_template_group_id' => $message_template_group->ID(), |
|
| 1849 | - ); |
|
| 1850 | - return EEH_Template::display_template( |
|
| 1851 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1852 | - $template_args, |
|
| 1853 | - true |
|
| 1854 | - ); |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * Ajax callback for `toggle_context_template` ajax action. |
|
| 1860 | - * Handles toggling the message context on or off. |
|
| 1861 | - * |
|
| 1862 | - * @throws EE_Error |
|
| 1863 | - * @throws InvalidArgumentException |
|
| 1864 | - * @throws InvalidDataTypeException |
|
| 1865 | - * @throws InvalidIdentifierException |
|
| 1866 | - * @throws InvalidInterfaceException |
|
| 1867 | - */ |
|
| 1868 | - public function toggle_context_template() |
|
| 1869 | - { |
|
| 1870 | - $success = true; |
|
| 1871 | - // check for required data |
|
| 1872 | - if ( |
|
| 1873 | - ! isset( |
|
| 1874 | - $this->_req_data['message_template_group_id'], |
|
| 1875 | - $this->_req_data['context'], |
|
| 1876 | - $this->_req_data['status'] |
|
| 1877 | - ) |
|
| 1878 | - ) { |
|
| 1879 | - EE_Error::add_error( |
|
| 1880 | - esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1881 | - __FILE__, |
|
| 1882 | - __FUNCTION__, |
|
| 1883 | - __LINE__ |
|
| 1884 | - ); |
|
| 1885 | - $success = false; |
|
| 1886 | - } |
|
| 1887 | - |
|
| 1888 | - $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1889 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1890 | - : ''; |
|
| 1891 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1892 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1893 | - $status = $this->_req_data['status']; |
|
| 1894 | - if ($status !== 'off' && $status !== 'on') { |
|
| 1895 | - EE_Error::add_error( |
|
| 1896 | - sprintf( |
|
| 1897 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1898 | - $this->_req_data['status'] |
|
| 1899 | - ), |
|
| 1900 | - __FILE__, |
|
| 1901 | - __FUNCTION__, |
|
| 1902 | - __LINE__ |
|
| 1903 | - ); |
|
| 1904 | - $success = false; |
|
| 1905 | - } |
|
| 1906 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1907 | - $this->_req_data['message_template_group_id'] |
|
| 1908 | - ); |
|
| 1909 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1910 | - EE_Error::add_error( |
|
| 1911 | - sprintf( |
|
| 1912 | - esc_html__( |
|
| 1913 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1914 | - 'event_espresso' |
|
| 1915 | - ), |
|
| 1916 | - $this->_req_data['message_template_group_id'], |
|
| 1917 | - 'EE_Message_Template_Group' |
|
| 1918 | - ), |
|
| 1919 | - __FILE__, |
|
| 1920 | - __FUNCTION__, |
|
| 1921 | - __LINE__ |
|
| 1922 | - ); |
|
| 1923 | - $success = false; |
|
| 1924 | - } |
|
| 1925 | - if ($success) { |
|
| 1926 | - $success = $status === 'off' |
|
| 1927 | - ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1928 | - : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1929 | - } |
|
| 1930 | - $this->_template_args['success'] = $success; |
|
| 1931 | - $this->_return_json(); |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - |
|
| 1935 | - public function _add_form_element_before() |
|
| 1936 | - { |
|
| 1937 | - return '<form method="post" action="' |
|
| 1938 | - . $this->_template_args["edit_message_template_form_url"] |
|
| 1939 | - . '" id="ee-msg-edit-frm">'; |
|
| 1940 | - } |
|
| 1941 | - |
|
| 1942 | - public function _add_form_element_after() |
|
| 1943 | - { |
|
| 1944 | - return '</form>'; |
|
| 1945 | - } |
|
| 1946 | - |
|
| 1947 | - |
|
| 1948 | - /** |
|
| 1949 | - * This executes switching the template pack for a message template. |
|
| 1950 | - * |
|
| 1951 | - * @since 4.5.0 |
|
| 1952 | - * @throws EE_Error |
|
| 1953 | - * @throws InvalidDataTypeException |
|
| 1954 | - * @throws InvalidInterfaceException |
|
| 1955 | - * @throws InvalidArgumentException |
|
| 1956 | - * @throws ReflectionException |
|
| 1957 | - */ |
|
| 1958 | - public function switch_template_pack() |
|
| 1959 | - { |
|
| 1960 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1961 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1962 | - |
|
| 1963 | - // verify we have needed values. |
|
| 1964 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1965 | - $this->_template_args['error'] = true; |
|
| 1966 | - EE_Error::add_error( |
|
| 1967 | - esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1968 | - __FILE__, |
|
| 1969 | - __FUNCTION__, |
|
| 1970 | - __LINE__ |
|
| 1971 | - ); |
|
| 1972 | - } else { |
|
| 1973 | - // get template, set the new template_pack and then reset to default |
|
| 1974 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1975 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1976 | - |
|
| 1977 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1978 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1979 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1980 | - |
|
| 1981 | - $query_args = $this->_reset_to_default_template(); |
|
| 1982 | - |
|
| 1983 | - if (empty($query_args['id'])) { |
|
| 1984 | - EE_Error::add_error( |
|
| 1985 | - esc_html__( |
|
| 1986 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1987 | - 'event_espresso' |
|
| 1988 | - ), |
|
| 1989 | - __FILE__, |
|
| 1990 | - __FUNCTION__, |
|
| 1991 | - __LINE__ |
|
| 1992 | - ); |
|
| 1993 | - $this->_template_args['error'] = true; |
|
| 1994 | - } else { |
|
| 1995 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1996 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1997 | - EE_Error::add_success( |
|
| 1998 | - sprintf( |
|
| 1999 | - esc_html__( |
|
| 2000 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 2001 | - 'event_espresso' |
|
| 2002 | - ), |
|
| 2003 | - $template_label, |
|
| 2004 | - $template_pack_labels->template_pack |
|
| 2005 | - ) |
|
| 2006 | - ); |
|
| 2007 | - // generate the redirect url for js. |
|
| 2008 | - $url = self::add_query_args_and_nonce( |
|
| 2009 | - $query_args, |
|
| 2010 | - $this->_admin_base_url |
|
| 2011 | - ); |
|
| 2012 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 2013 | - $this->_template_args['success'] = true; |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - $this->_return_json(); |
|
| 2017 | - } |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - |
|
| 2021 | - /** |
|
| 2022 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2023 | - * they want. |
|
| 2024 | - * |
|
| 2025 | - * @access protected |
|
| 2026 | - * @return array|null |
|
| 2027 | - * @throws EE_Error |
|
| 2028 | - * @throws InvalidArgumentException |
|
| 2029 | - * @throws InvalidDataTypeException |
|
| 2030 | - * @throws InvalidInterfaceException |
|
| 2031 | - */ |
|
| 2032 | - protected function _reset_to_default_template() |
|
| 2033 | - { |
|
| 2034 | - |
|
| 2035 | - $templates = array(); |
|
| 2036 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2037 | - // we need to make sure we've got the info we need. |
|
| 2038 | - if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2039 | - EE_Error::add_error( |
|
| 2040 | - esc_html__( |
|
| 2041 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2042 | - 'event_espresso' |
|
| 2043 | - ), |
|
| 2044 | - __FILE__, |
|
| 2045 | - __FUNCTION__, |
|
| 2046 | - __LINE__ |
|
| 2047 | - ); |
|
| 2048 | - } |
|
| 2049 | - |
|
| 2050 | - // all templates will be reset to whatever the defaults are |
|
| 2051 | - // for the global template matching the messenger and message type. |
|
| 2052 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 2053 | - |
|
| 2054 | - if ($success) { |
|
| 2055 | - // let's first determine if the incoming template is a global template, |
|
| 2056 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2057 | - // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2058 | - |
|
| 2059 | - |
|
| 2060 | - // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2061 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2062 | - |
|
| 2063 | - if ($success) { |
|
| 2064 | - // if successfully deleted, lets generate the new ones. |
|
| 2065 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2066 | - // will use the related global template defaults for regeneration. |
|
| 2067 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2068 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 2069 | - // for the current custom template when resetting. |
|
| 2070 | - $templates = $this->_generate_new_templates( |
|
| 2071 | - $this->_req_data['msgr'], |
|
| 2072 | - $this->_req_data['mt'], |
|
| 2073 | - $GRP_ID, |
|
| 2074 | - true |
|
| 2075 | - ); |
|
| 2076 | - } |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - // any error messages? |
|
| 2080 | - if (! $success) { |
|
| 2081 | - EE_Error::add_error( |
|
| 2082 | - esc_html__( |
|
| 2083 | - 'Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2084 | - 'event_espresso' |
|
| 2085 | - ), |
|
| 2086 | - __FILE__, |
|
| 2087 | - __FUNCTION__, |
|
| 2088 | - __LINE__ |
|
| 2089 | - ); |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - // all good, let's add a success message! |
|
| 2093 | - if ($success && ! empty($templates)) { |
|
| 2094 | - // the info for the template we generated is the first element in the returned array |
|
| 2095 | - // $templates = $templates[0]; |
|
| 2096 | - EE_Error::overwrite_success(); |
|
| 2097 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2098 | - } |
|
| 2099 | - |
|
| 2100 | - |
|
| 2101 | - $query_args = array( |
|
| 2102 | - 'id' => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null, |
|
| 2103 | - 'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null, |
|
| 2104 | - 'action' => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps', |
|
| 2105 | - ); |
|
| 2106 | - |
|
| 2107 | - // if called via ajax then we return query args otherwise redirect |
|
| 2108 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2109 | - return $query_args; |
|
| 2110 | - } else { |
|
| 2111 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2112 | - |
|
| 2113 | - return null; |
|
| 2114 | - } |
|
| 2115 | - } |
|
| 2116 | - |
|
| 2117 | - |
|
| 2118 | - /** |
|
| 2119 | - * Retrieve and set the message preview for display. |
|
| 2120 | - * |
|
| 2121 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2122 | - * @return string |
|
| 2123 | - * @throws ReflectionException |
|
| 2124 | - * @throws EE_Error |
|
| 2125 | - * @throws InvalidArgumentException |
|
| 2126 | - * @throws InvalidDataTypeException |
|
| 2127 | - * @throws InvalidInterfaceException |
|
| 2128 | - */ |
|
| 2129 | - public function _preview_message($send = false) |
|
| 2130 | - { |
|
| 2131 | - // first make sure we've got the necessary parameters |
|
| 2132 | - if ( |
|
| 2133 | - ! isset( |
|
| 2134 | - $this->_req_data['message_type'], |
|
| 2135 | - $this->_req_data['messenger'], |
|
| 2136 | - $this->_req_data['messenger'], |
|
| 2137 | - $this->_req_data['GRP_ID'] |
|
| 2138 | - ) |
|
| 2139 | - ) { |
|
| 2140 | - EE_Error::add_error( |
|
| 2141 | - esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2142 | - __FILE__, |
|
| 2143 | - __FUNCTION__, |
|
| 2144 | - __LINE__ |
|
| 2145 | - ); |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2149 | - |
|
| 2150 | - // if we have an evt_id set on the request, use it. |
|
| 2151 | - $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) |
|
| 2152 | - ? absint($this->_req_data['evt_id']) |
|
| 2153 | - : false; |
|
| 2154 | - |
|
| 2155 | - |
|
| 2156 | - // get the preview! |
|
| 2157 | - $preview = EED_Messages::preview_message( |
|
| 2158 | - $this->_req_data['message_type'], |
|
| 2159 | - $this->_req_data['context'], |
|
| 2160 | - $this->_req_data['messenger'], |
|
| 2161 | - $send |
|
| 2162 | - ); |
|
| 2163 | - |
|
| 2164 | - if ($send) { |
|
| 2165 | - return $preview; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - // let's add a button to go back to the edit view |
|
| 2169 | - $query_args = array( |
|
| 2170 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2171 | - 'evt_id' => $EVT_ID, |
|
| 2172 | - 'context' => $this->_req_data['context'], |
|
| 2173 | - 'action' => 'edit_message_template', |
|
| 2174 | - ); |
|
| 2175 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2176 | - $preview_button = '<a href="' |
|
| 2177 | - . $go_back_url |
|
| 2178 | - . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2179 | - . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2180 | - . '</a>'; |
|
| 2181 | - $message_types = $this->get_installed_message_types(); |
|
| 2182 | - $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2183 | - $this->_req_data['messenger'] |
|
| 2184 | - ); |
|
| 2185 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2186 | - ? ucwords($active_messenger->label['singular']) |
|
| 2187 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2188 | - // let's provide a helpful title for context |
|
| 2189 | - $preview_title = sprintf( |
|
| 2190 | - esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2191 | - $active_messenger_label, |
|
| 2192 | - ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular']) |
|
| 2193 | - ); |
|
| 2194 | - if (empty($preview)) { |
|
| 2195 | - $this->noEventsErrorMessage(); |
|
| 2196 | - } |
|
| 2197 | - // setup display of preview. |
|
| 2198 | - $this->_admin_page_title = $preview_title; |
|
| 2199 | - $this->_template_args['admin_page_title'] = $preview_title; |
|
| 2200 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2201 | - $this->_template_args['data']['force_json'] = true; |
|
| 2202 | - |
|
| 2203 | - return ''; |
|
| 2204 | - } |
|
| 2205 | - |
|
| 2206 | - |
|
| 2207 | - /** |
|
| 2208 | - * Used to set an error if there are no events available for generating a preview/test send. |
|
| 2209 | - * |
|
| 2210 | - * @param bool $test_send Whether the error should be generated for the context of a test send. |
|
| 2211 | - */ |
|
| 2212 | - protected function noEventsErrorMessage($test_send = false) |
|
| 2213 | - { |
|
| 2214 | - $events_url = parent::add_query_args_and_nonce( |
|
| 2215 | - array( |
|
| 2216 | - 'action' => 'default', |
|
| 2217 | - 'page' => 'espresso_events', |
|
| 2218 | - ), |
|
| 2219 | - admin_url('admin.php') |
|
| 2220 | - ); |
|
| 2221 | - $message = $test_send |
|
| 2222 | - ? __( |
|
| 2223 | - 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!', |
|
| 2224 | - 'event_espresso' |
|
| 2225 | - ) |
|
| 2226 | - : __( |
|
| 2227 | - 'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!', |
|
| 2228 | - 'event_espresso' |
|
| 2229 | - ); |
|
| 2230 | - |
|
| 2231 | - EE_Error::add_attention( |
|
| 2232 | - sprintf( |
|
| 2233 | - $message, |
|
| 2234 | - "<a href='{$events_url}'>", |
|
| 2235 | - '</a>' |
|
| 2236 | - ) |
|
| 2237 | - ); |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - |
|
| 2241 | - /** |
|
| 2242 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2243 | - * gets called automatically. |
|
| 2244 | - * |
|
| 2245 | - * @since 4.5.0 |
|
| 2246 | - * |
|
| 2247 | - * @return string |
|
| 2248 | - */ |
|
| 2249 | - protected function _display_preview_message() |
|
| 2250 | - { |
|
| 2251 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - |
|
| 2255 | - /** |
|
| 2256 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2257 | - * |
|
| 2258 | - * @access protected |
|
| 2259 | - * @return void |
|
| 2260 | - */ |
|
| 2261 | - protected function _register_edit_meta_boxes() |
|
| 2262 | - { |
|
| 2263 | - add_meta_box( |
|
| 2264 | - 'mtp_valid_shortcodes', |
|
| 2265 | - esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2266 | - array($this, 'shortcode_meta_box'), |
|
| 2267 | - $this->_current_screen->id, |
|
| 2268 | - 'side', |
|
| 2269 | - 'default' |
|
| 2270 | - ); |
|
| 2271 | - add_meta_box( |
|
| 2272 | - 'mtp_extra_actions', |
|
| 2273 | - esc_html__('Extra Actions', 'event_espresso'), |
|
| 2274 | - array($this, 'extra_actions_meta_box'), |
|
| 2275 | - $this->_current_screen->id, |
|
| 2276 | - 'side', |
|
| 2277 | - 'high' |
|
| 2278 | - ); |
|
| 2279 | - add_meta_box( |
|
| 2280 | - 'mtp_templates', |
|
| 2281 | - esc_html__('Template Styles', 'event_espresso'), |
|
| 2282 | - array($this, 'template_pack_meta_box'), |
|
| 2283 | - $this->_current_screen->id, |
|
| 2284 | - 'side', |
|
| 2285 | - 'high' |
|
| 2286 | - ); |
|
| 2287 | - } |
|
| 2288 | - |
|
| 2289 | - |
|
| 2290 | - /** |
|
| 2291 | - * metabox content for all template pack and variation selection. |
|
| 2292 | - * |
|
| 2293 | - * @since 4.5.0 |
|
| 2294 | - * @return string |
|
| 2295 | - * @throws DomainException |
|
| 2296 | - * @throws EE_Error |
|
| 2297 | - * @throws InvalidArgumentException |
|
| 2298 | - * @throws ReflectionException |
|
| 2299 | - * @throws InvalidDataTypeException |
|
| 2300 | - * @throws InvalidInterfaceException |
|
| 2301 | - */ |
|
| 2302 | - public function template_pack_meta_box() |
|
| 2303 | - { |
|
| 2304 | - $this->_set_message_template_group(); |
|
| 2305 | - |
|
| 2306 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2307 | - |
|
| 2308 | - $tp_select_values = array(); |
|
| 2309 | - |
|
| 2310 | - foreach ($tp_collection as $tp) { |
|
| 2311 | - // only include template packs that support this messenger and message type! |
|
| 2312 | - $supports = $tp->get_supports(); |
|
| 2313 | - if ( |
|
| 2314 | - ! isset($supports[ $this->_message_template_group->messenger() ]) |
|
| 2315 | - || ! in_array( |
|
| 2316 | - $this->_message_template_group->message_type(), |
|
| 2317 | - $supports[ $this->_message_template_group->messenger() ], |
|
| 2318 | - true |
|
| 2319 | - ) |
|
| 2320 | - ) { |
|
| 2321 | - // not supported |
|
| 2322 | - continue; |
|
| 2323 | - } |
|
| 2324 | - |
|
| 2325 | - $tp_select_values[] = array( |
|
| 2326 | - 'text' => $tp->label, |
|
| 2327 | - 'id' => $tp->dbref, |
|
| 2328 | - ); |
|
| 2329 | - } |
|
| 2330 | - |
|
| 2331 | - // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2332 | - // the default template pack. This still allows for the odd template pack to override. |
|
| 2333 | - if (empty($tp_select_values)) { |
|
| 2334 | - $tp_select_values[] = array( |
|
| 2335 | - 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2336 | - 'id' => 'default', |
|
| 2337 | - ); |
|
| 2338 | - } |
|
| 2339 | - |
|
| 2340 | - // setup variation select values for the currently selected template. |
|
| 2341 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2342 | - $this->_message_template_group->messenger(), |
|
| 2343 | - $this->_message_template_group->message_type() |
|
| 2344 | - ); |
|
| 2345 | - $variations_select_values = array(); |
|
| 2346 | - foreach ($variations as $variation => $label) { |
|
| 2347 | - $variations_select_values[] = array( |
|
| 2348 | - 'text' => $label, |
|
| 2349 | - 'id' => $variation, |
|
| 2350 | - ); |
|
| 2351 | - } |
|
| 2352 | - |
|
| 2353 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2354 | - |
|
| 2355 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2356 | - 'MTP_template_pack', |
|
| 2357 | - $tp_select_values, |
|
| 2358 | - $this->_message_template_group->get_template_pack_name() |
|
| 2359 | - ); |
|
| 2360 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2361 | - 'MTP_template_variation', |
|
| 2362 | - $variations_select_values, |
|
| 2363 | - $this->_message_template_group->get_template_pack_variation() |
|
| 2364 | - ); |
|
| 2365 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2366 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2367 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2368 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2369 | - |
|
| 2370 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2371 | - |
|
| 2372 | - EEH_Template::display_template($template, $template_args); |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * This meta box holds any extra actions related to Message Templates |
|
| 2378 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2379 | - * |
|
| 2380 | - * @access public |
|
| 2381 | - * @return void |
|
| 2382 | - * @throws EE_Error |
|
| 2383 | - */ |
|
| 2384 | - public function extra_actions_meta_box() |
|
| 2385 | - { |
|
| 2386 | - $template_form_fields = array(); |
|
| 2387 | - |
|
| 2388 | - $extra_args = array( |
|
| 2389 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2390 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2391 | - 'GRP_ID' => $this->_message_template_group->GRP_ID(), |
|
| 2392 | - ); |
|
| 2393 | - // first we need to see if there are any fields |
|
| 2394 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2395 | - |
|
| 2396 | - if (! empty($fields)) { |
|
| 2397 | - // yup there be fields |
|
| 2398 | - foreach ($fields as $field => $config) { |
|
| 2399 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2400 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2401 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2402 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2403 | - |
|
| 2404 | - // if type is hidden and the value is empty |
|
| 2405 | - // something may have gone wrong so let's correct with the defaults |
|
| 2406 | - $fix = $config['input'] === 'hidden' |
|
| 2407 | - && isset($existing[ $field ]) |
|
| 2408 | - && empty($existing[ $field ]) |
|
| 2409 | - ? $default |
|
| 2410 | - : ''; |
|
| 2411 | - $existing[ $field ] = isset($existing[ $field ]) && empty($fix) |
|
| 2412 | - ? $existing[ $field ] |
|
| 2413 | - : $fix; |
|
| 2414 | - |
|
| 2415 | - $template_form_fields[ $field_id ] = array( |
|
| 2416 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2417 | - 'label' => $config['label'], |
|
| 2418 | - 'input' => $config['input'], |
|
| 2419 | - 'type' => $config['type'], |
|
| 2420 | - 'required' => $config['required'], |
|
| 2421 | - 'validation' => $config['validation'], |
|
| 2422 | - 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default, |
|
| 2423 | - 'css_class' => $config['css_class'], |
|
| 2424 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2425 | - 'default' => $default, |
|
| 2426 | - 'format' => $config['format'], |
|
| 2427 | - ); |
|
| 2428 | - } |
|
| 2429 | - } |
|
| 2430 | - |
|
| 2431 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2432 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2433 | - : ''; |
|
| 2434 | - |
|
| 2435 | - $test_settings_html = ''; |
|
| 2436 | - // print out $test_settings_fields |
|
| 2437 | - if (! empty($test_settings_fields)) { |
|
| 2438 | - echo $test_settings_fields; |
|
| 2439 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2440 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2441 | - $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2442 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2443 | - } |
|
| 2444 | - |
|
| 2445 | - // and button |
|
| 2446 | - $test_settings_html .= '<p>' |
|
| 2447 | - . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2448 | - . '</p>'; |
|
| 2449 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2450 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2451 | - 'reset_to_default', |
|
| 2452 | - 'reset', |
|
| 2453 | - $extra_args, |
|
| 2454 | - 'button-primary reset-default-button' |
|
| 2455 | - ); |
|
| 2456 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2457 | - echo $test_settings_html; |
|
| 2458 | - } |
|
| 2459 | - |
|
| 2460 | - |
|
| 2461 | - /** |
|
| 2462 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2463 | - * |
|
| 2464 | - * @since 4.9.rc.000 |
|
| 2465 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2466 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2467 | - * @return string |
|
| 2468 | - * @throws DomainException |
|
| 2469 | - * @throws EE_Error |
|
| 2470 | - * @throws InvalidArgumentException |
|
| 2471 | - * @throws ReflectionException |
|
| 2472 | - * @throws InvalidDataTypeException |
|
| 2473 | - * @throws InvalidInterfaceException |
|
| 2474 | - */ |
|
| 2475 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2476 | - { |
|
| 2477 | - $template_args = array( |
|
| 2478 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2479 | - 'fieldname' => $field, |
|
| 2480 | - 'linked_input_id' => $linked_input_id, |
|
| 2481 | - ); |
|
| 2482 | - |
|
| 2483 | - return EEH_Template::display_template( |
|
| 2484 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2485 | - $template_args, |
|
| 2486 | - true |
|
| 2487 | - ); |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - |
|
| 2491 | - /** |
|
| 2492 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2493 | - * page) |
|
| 2494 | - * |
|
| 2495 | - * @access public |
|
| 2496 | - * @return void |
|
| 2497 | - * @throws EE_Error |
|
| 2498 | - * @throws InvalidArgumentException |
|
| 2499 | - * @throws ReflectionException |
|
| 2500 | - * @throws InvalidDataTypeException |
|
| 2501 | - * @throws InvalidInterfaceException |
|
| 2502 | - */ |
|
| 2503 | - public function shortcode_meta_box() |
|
| 2504 | - { |
|
| 2505 | - $shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set |
|
| 2506 | - // $messenger = $this->_message_template_group->messenger_obj(); |
|
| 2507 | - // now let's set the content depending on the status of the shortcodes array |
|
| 2508 | - if (empty($shortcodes)) { |
|
| 2509 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2510 | - echo $content; |
|
| 2511 | - } else { |
|
| 2512 | - // $alt = 0; |
|
| 2513 | - ?> |
|
| 22 | + /** |
|
| 23 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 24 | + */ |
|
| 25 | + protected $_message_resource_manager; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type string $_active_message_type_name |
|
| 29 | + */ |
|
| 30 | + protected $_active_message_type_name = ''; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type EE_messenger $_active_messenger |
|
| 34 | + */ |
|
| 35 | + protected $_active_messenger; |
|
| 36 | + protected $_activate_state; |
|
| 37 | + protected $_activate_meta_box_type; |
|
| 38 | + protected $_current_message_meta_box; |
|
| 39 | + protected $_current_message_meta_box_object; |
|
| 40 | + protected $_context_switcher; |
|
| 41 | + protected $_shortcodes = array(); |
|
| 42 | + protected $_active_messengers = array(); |
|
| 43 | + protected $_active_message_types = array(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 47 | + */ |
|
| 48 | + protected $_message_template_group; |
|
| 49 | + protected $_m_mt_settings = array(); |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 54 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 55 | + * |
|
| 56 | + * @since 4.5.0 |
|
| 57 | + * |
|
| 58 | + * @var EE_Messages_Template_Pack |
|
| 59 | + */ |
|
| 60 | + protected $_template_pack; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 65 | + * group is. If there is no group then it automatically gets set to default. |
|
| 66 | + * |
|
| 67 | + * @since 4.5.0 |
|
| 68 | + * |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | + protected $_variation; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param bool $routing |
|
| 76 | + * @throws EE_Error |
|
| 77 | + */ |
|
| 78 | + public function __construct($routing = true) |
|
| 79 | + { |
|
| 80 | + // make sure messages autoloader is running |
|
| 81 | + EED_Messages::set_autoloaders(); |
|
| 82 | + parent::__construct($routing); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + protected function _init_page_props() |
|
| 87 | + { |
|
| 88 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 89 | + $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 90 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 91 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 92 | + |
|
| 93 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] |
|
| 94 | + : array(); |
|
| 95 | + |
|
| 96 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 97 | + $this->_load_message_resource_manager(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 103 | + * |
|
| 104 | + * @throws EE_Error |
|
| 105 | + * @throws InvalidDataTypeException |
|
| 106 | + * @throws InvalidInterfaceException |
|
| 107 | + * @throws InvalidArgumentException |
|
| 108 | + * @throws ReflectionException |
|
| 109 | + */ |
|
| 110 | + protected function _load_message_resource_manager() |
|
| 111 | + { |
|
| 112 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @deprecated 4.9.9.rc.014 |
|
| 118 | + * @return array |
|
| 119 | + * @throws EE_Error |
|
| 120 | + * @throws InvalidArgumentException |
|
| 121 | + * @throws InvalidDataTypeException |
|
| 122 | + * @throws InvalidInterfaceException |
|
| 123 | + */ |
|
| 124 | + public function get_messengers_for_list_table() |
|
| 125 | + { |
|
| 126 | + EE_Error::doing_it_wrong( |
|
| 127 | + __METHOD__, |
|
| 128 | + sprintf( |
|
| 129 | + esc_html__( |
|
| 130 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 131 | + 'event_espresso' |
|
| 132 | + ), |
|
| 133 | + 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 134 | + ), |
|
| 135 | + '4.9.9.rc.014' |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + $m_values = array(); |
|
| 139 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 140 | + // setup messengers for selects |
|
| 141 | + $i = 1; |
|
| 142 | + foreach ($active_messengers as $active_messenger) { |
|
| 143 | + if ($active_messenger instanceof EE_Message) { |
|
| 144 | + $m_values[ $i ]['id'] = $active_messenger->messenger(); |
|
| 145 | + $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 146 | + $i++; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $m_values; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @deprecated 4.9.9.rc.014 |
|
| 156 | + * @return array |
|
| 157 | + * @throws EE_Error |
|
| 158 | + * @throws InvalidArgumentException |
|
| 159 | + * @throws InvalidDataTypeException |
|
| 160 | + * @throws InvalidInterfaceException |
|
| 161 | + */ |
|
| 162 | + public function get_message_types_for_list_table() |
|
| 163 | + { |
|
| 164 | + EE_Error::doing_it_wrong( |
|
| 165 | + __METHOD__, |
|
| 166 | + sprintf( |
|
| 167 | + esc_html__( |
|
| 168 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 169 | + 'event_espresso' |
|
| 170 | + ), |
|
| 171 | + 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 172 | + ), |
|
| 173 | + '4.9.9.rc.014' |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + $mt_values = array(); |
|
| 177 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 178 | + $i = 1; |
|
| 179 | + foreach ($active_messages as $active_message) { |
|
| 180 | + if ($active_message instanceof EE_Message) { |
|
| 181 | + $mt_values[ $i ]['id'] = $active_message->message_type(); |
|
| 182 | + $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label()); |
|
| 183 | + $i++; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $mt_values; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @deprecated 4.9.9.rc.014 |
|
| 193 | + * @return array |
|
| 194 | + * @throws EE_Error |
|
| 195 | + * @throws InvalidArgumentException |
|
| 196 | + * @throws InvalidDataTypeException |
|
| 197 | + * @throws InvalidInterfaceException |
|
| 198 | + */ |
|
| 199 | + public function get_contexts_for_message_types_for_list_table() |
|
| 200 | + { |
|
| 201 | + EE_Error::doing_it_wrong( |
|
| 202 | + __METHOD__, |
|
| 203 | + sprintf( |
|
| 204 | + esc_html__( |
|
| 205 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ), |
|
| 208 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 209 | + ), |
|
| 210 | + '4.9.9.rc.014' |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + $contexts = array(); |
|
| 214 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 215 | + foreach ($active_message_contexts as $active_message) { |
|
| 216 | + if ($active_message instanceof EE_Message) { |
|
| 217 | + $message_type = $active_message->message_type_object(); |
|
| 218 | + if ($message_type instanceof EE_message_type) { |
|
| 219 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 220 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 221 | + $contexts[ $context ] = $context_details['label']; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $contexts; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Generate select input with provided messenger options array. |
|
| 233 | + * |
|
| 234 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 235 | + * labels. |
|
| 236 | + * @return string |
|
| 237 | + * @throws EE_Error |
|
| 238 | + */ |
|
| 239 | + public function get_messengers_select_input($messenger_options) |
|
| 240 | + { |
|
| 241 | + // if empty or just one value then just return an empty string |
|
| 242 | + if ( |
|
| 243 | + empty($messenger_options) |
|
| 244 | + || ! is_array($messenger_options) |
|
| 245 | + || count($messenger_options) === 1 |
|
| 246 | + ) { |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + // merge in default |
|
| 250 | + $messenger_options = array_merge( |
|
| 251 | + array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 252 | + $messenger_options |
|
| 253 | + ); |
|
| 254 | + $input = new EE_Select_Input( |
|
| 255 | + $messenger_options, |
|
| 256 | + array( |
|
| 257 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 258 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 259 | + 'html_class' => 'wide', |
|
| 260 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 261 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 262 | + : 'none_selected', |
|
| 263 | + ) |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + return $input->get_html_for_input(); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Generate select input with provided message type options array. |
|
| 272 | + * |
|
| 273 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 274 | + * message type labels |
|
| 275 | + * @return string |
|
| 276 | + * @throws EE_Error |
|
| 277 | + */ |
|
| 278 | + public function get_message_types_select_input($message_type_options) |
|
| 279 | + { |
|
| 280 | + // if empty or count of options is 1 then just return an empty string |
|
| 281 | + if ( |
|
| 282 | + empty($message_type_options) |
|
| 283 | + || ! is_array($message_type_options) |
|
| 284 | + || count($message_type_options) === 1 |
|
| 285 | + ) { |
|
| 286 | + return ''; |
|
| 287 | + } |
|
| 288 | + // merge in default |
|
| 289 | + $message_type_options = array_merge( |
|
| 290 | + array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 291 | + $message_type_options |
|
| 292 | + ); |
|
| 293 | + $input = new EE_Select_Input( |
|
| 294 | + $message_type_options, |
|
| 295 | + array( |
|
| 296 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 297 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 298 | + 'html_class' => 'wide', |
|
| 299 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 300 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | + : 'none_selected', |
|
| 302 | + ) |
|
| 303 | + ); |
|
| 304 | + |
|
| 305 | + return $input->get_html_for_input(); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Generate select input with provide message type contexts array. |
|
| 311 | + * |
|
| 312 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 313 | + * context label. |
|
| 314 | + * @return string |
|
| 315 | + * @throws EE_Error |
|
| 316 | + */ |
|
| 317 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 318 | + { |
|
| 319 | + // if empty or count of options is one then just return empty string |
|
| 320 | + if ( |
|
| 321 | + empty($context_options) |
|
| 322 | + || ! is_array($context_options) |
|
| 323 | + || count($context_options) === 1 |
|
| 324 | + ) { |
|
| 325 | + return ''; |
|
| 326 | + } |
|
| 327 | + // merge in default |
|
| 328 | + $context_options = array_merge( |
|
| 329 | + array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 330 | + $context_options |
|
| 331 | + ); |
|
| 332 | + $input = new EE_Select_Input( |
|
| 333 | + $context_options, |
|
| 334 | + array( |
|
| 335 | + 'html_name' => 'ee_context_filter_by', |
|
| 336 | + 'html_id' => 'ee_context_filter_by', |
|
| 337 | + 'html_class' => 'wide', |
|
| 338 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 339 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 340 | + : 'none_selected', |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + |
|
| 344 | + return $input->get_html_for_input(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + protected function _ajax_hooks() |
|
| 349 | + { |
|
| 350 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 351 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 352 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 353 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 354 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 355 | + add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + protected function _define_page_props() |
|
| 360 | + { |
|
| 361 | + $this->_admin_page_title = $this->page_label; |
|
| 362 | + $this->_labels = array( |
|
| 363 | + 'buttons' => array( |
|
| 364 | + 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 365 | + 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 366 | + 'delete' => esc_html__('Delete Message Template', 'event_espresso'), |
|
| 367 | + ), |
|
| 368 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso'), |
|
| 369 | + ); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 375 | + * |
|
| 376 | + * @access protected |
|
| 377 | + * @return void |
|
| 378 | + */ |
|
| 379 | + protected function _set_page_routes() |
|
| 380 | + { |
|
| 381 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 382 | + ? $this->_req_data['GRP_ID'] |
|
| 383 | + : 0; |
|
| 384 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 385 | + ? $this->_req_data['id'] |
|
| 386 | + : $grp_id; |
|
| 387 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 388 | + ? $this->_req_data['MSG_ID'] |
|
| 389 | + : 0; |
|
| 390 | + |
|
| 391 | + $this->_page_routes = array( |
|
| 392 | + 'default' => array( |
|
| 393 | + 'func' => '_message_queue_list_table', |
|
| 394 | + 'capability' => 'ee_read_global_messages', |
|
| 395 | + ), |
|
| 396 | + 'global_mtps' => array( |
|
| 397 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 398 | + 'capability' => 'ee_read_global_messages', |
|
| 399 | + ), |
|
| 400 | + 'custom_mtps' => array( |
|
| 401 | + 'func' => '_custom_mtps_preview', |
|
| 402 | + 'capability' => 'ee_read_messages', |
|
| 403 | + ), |
|
| 404 | + 'add_new_message_template' => array( |
|
| 405 | + 'func' => '_add_message_template', |
|
| 406 | + 'capability' => 'ee_edit_messages', |
|
| 407 | + 'noheader' => true, |
|
| 408 | + ), |
|
| 409 | + 'edit_message_template' => array( |
|
| 410 | + 'func' => '_edit_message_template', |
|
| 411 | + 'capability' => 'ee_edit_message', |
|
| 412 | + 'obj_id' => $grp_id, |
|
| 413 | + ), |
|
| 414 | + 'preview_message' => array( |
|
| 415 | + 'func' => '_preview_message', |
|
| 416 | + 'capability' => 'ee_read_message', |
|
| 417 | + 'obj_id' => $grp_id, |
|
| 418 | + 'noheader' => true, |
|
| 419 | + 'headers_sent_route' => 'display_preview_message', |
|
| 420 | + ), |
|
| 421 | + 'display_preview_message' => array( |
|
| 422 | + 'func' => '_display_preview_message', |
|
| 423 | + 'capability' => 'ee_read_message', |
|
| 424 | + 'obj_id' => $grp_id, |
|
| 425 | + ), |
|
| 426 | + 'insert_message_template' => array( |
|
| 427 | + 'func' => '_insert_or_update_message_template', |
|
| 428 | + 'capability' => 'ee_edit_messages', |
|
| 429 | + 'args' => array('new_template' => true), |
|
| 430 | + 'noheader' => true, |
|
| 431 | + ), |
|
| 432 | + 'update_message_template' => array( |
|
| 433 | + 'func' => '_insert_or_update_message_template', |
|
| 434 | + 'capability' => 'ee_edit_message', |
|
| 435 | + 'obj_id' => $grp_id, |
|
| 436 | + 'args' => array('new_template' => false), |
|
| 437 | + 'noheader' => true, |
|
| 438 | + ), |
|
| 439 | + 'trash_message_template' => array( |
|
| 440 | + 'func' => '_trash_or_restore_message_template', |
|
| 441 | + 'capability' => 'ee_delete_message', |
|
| 442 | + 'obj_id' => $grp_id, |
|
| 443 | + 'args' => array('trash' => true, 'all' => true), |
|
| 444 | + 'noheader' => true, |
|
| 445 | + ), |
|
| 446 | + 'trash_message_template_context' => array( |
|
| 447 | + 'func' => '_trash_or_restore_message_template', |
|
| 448 | + 'capability' => 'ee_delete_message', |
|
| 449 | + 'obj_id' => $grp_id, |
|
| 450 | + 'args' => array('trash' => true), |
|
| 451 | + 'noheader' => true, |
|
| 452 | + ), |
|
| 453 | + 'restore_message_template' => array( |
|
| 454 | + 'func' => '_trash_or_restore_message_template', |
|
| 455 | + 'capability' => 'ee_delete_message', |
|
| 456 | + 'obj_id' => $grp_id, |
|
| 457 | + 'args' => array('trash' => false, 'all' => true), |
|
| 458 | + 'noheader' => true, |
|
| 459 | + ), |
|
| 460 | + 'restore_message_template_context' => array( |
|
| 461 | + 'func' => '_trash_or_restore_message_template', |
|
| 462 | + 'capability' => 'ee_delete_message', |
|
| 463 | + 'obj_id' => $grp_id, |
|
| 464 | + 'args' => array('trash' => false), |
|
| 465 | + 'noheader' => true, |
|
| 466 | + ), |
|
| 467 | + 'delete_message_template' => array( |
|
| 468 | + 'func' => '_delete_message_template', |
|
| 469 | + 'capability' => 'ee_delete_message', |
|
| 470 | + 'obj_id' => $grp_id, |
|
| 471 | + 'noheader' => true, |
|
| 472 | + ), |
|
| 473 | + 'reset_to_default' => array( |
|
| 474 | + 'func' => '_reset_to_default_template', |
|
| 475 | + 'capability' => 'ee_edit_message', |
|
| 476 | + 'obj_id' => $grp_id, |
|
| 477 | + 'noheader' => true, |
|
| 478 | + ), |
|
| 479 | + 'settings' => array( |
|
| 480 | + 'func' => '_settings', |
|
| 481 | + 'capability' => 'manage_options', |
|
| 482 | + ), |
|
| 483 | + 'update_global_settings' => array( |
|
| 484 | + 'func' => '_update_global_settings', |
|
| 485 | + 'capability' => 'manage_options', |
|
| 486 | + 'noheader' => true, |
|
| 487 | + ), |
|
| 488 | + 'generate_now' => array( |
|
| 489 | + 'func' => '_generate_now', |
|
| 490 | + 'capability' => 'ee_send_message', |
|
| 491 | + 'noheader' => true, |
|
| 492 | + ), |
|
| 493 | + 'generate_and_send_now' => array( |
|
| 494 | + 'func' => '_generate_and_send_now', |
|
| 495 | + 'capability' => 'ee_send_message', |
|
| 496 | + 'noheader' => true, |
|
| 497 | + ), |
|
| 498 | + 'queue_for_resending' => array( |
|
| 499 | + 'func' => '_queue_for_resending', |
|
| 500 | + 'capability' => 'ee_send_message', |
|
| 501 | + 'noheader' => true, |
|
| 502 | + ), |
|
| 503 | + 'send_now' => array( |
|
| 504 | + 'func' => '_send_now', |
|
| 505 | + 'capability' => 'ee_send_message', |
|
| 506 | + 'noheader' => true, |
|
| 507 | + ), |
|
| 508 | + 'delete_ee_message' => array( |
|
| 509 | + 'func' => '_delete_ee_messages', |
|
| 510 | + 'capability' => 'ee_delete_messages', |
|
| 511 | + 'noheader' => true, |
|
| 512 | + ), |
|
| 513 | + 'delete_ee_messages' => array( |
|
| 514 | + 'func' => '_delete_ee_messages', |
|
| 515 | + 'capability' => 'ee_delete_messages', |
|
| 516 | + 'noheader' => true, |
|
| 517 | + 'obj_id' => $msg_id, |
|
| 518 | + ), |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + protected function _set_page_config() |
|
| 524 | + { |
|
| 525 | + $this->_page_config = array( |
|
| 526 | + 'default' => array( |
|
| 527 | + 'nav' => array( |
|
| 528 | + 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 529 | + 'order' => 10, |
|
| 530 | + ), |
|
| 531 | + 'list_table' => 'EE_Message_List_Table', |
|
| 532 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 533 | + 'require_nonce' => false, |
|
| 534 | + ), |
|
| 535 | + 'global_mtps' => array( |
|
| 536 | + 'nav' => array( |
|
| 537 | + 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 538 | + 'order' => 20, |
|
| 539 | + ), |
|
| 540 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 541 | + 'help_tabs' => array( |
|
| 542 | + 'messages_overview_help_tab' => array( |
|
| 543 | + 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 544 | + 'filename' => 'messages_overview', |
|
| 545 | + ), |
|
| 546 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 547 | + 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 548 | + 'filename' => 'messages_overview_table_column_headings', |
|
| 549 | + ), |
|
| 550 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 551 | + 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 552 | + 'filename' => 'messages_overview_filters', |
|
| 553 | + ), |
|
| 554 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 555 | + 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 556 | + 'filename' => 'messages_overview_views', |
|
| 557 | + ), |
|
| 558 | + 'message_overview_message_types_help_tab' => array( |
|
| 559 | + 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 560 | + 'filename' => 'messages_overview_types', |
|
| 561 | + ), |
|
| 562 | + 'messages_overview_messengers_help_tab' => array( |
|
| 563 | + 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 564 | + 'filename' => 'messages_overview_messengers', |
|
| 565 | + ), |
|
| 566 | + ), |
|
| 567 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 568 | + 'require_nonce' => false, |
|
| 569 | + ), |
|
| 570 | + 'custom_mtps' => array( |
|
| 571 | + 'nav' => array( |
|
| 572 | + 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 573 | + 'order' => 30, |
|
| 574 | + ), |
|
| 575 | + 'help_tabs' => array(), |
|
| 576 | + 'help_tour' => array(), |
|
| 577 | + 'require_nonce' => false, |
|
| 578 | + ), |
|
| 579 | + 'add_new_message_template' => array( |
|
| 580 | + 'nav' => array( |
|
| 581 | + 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 582 | + 'order' => 5, |
|
| 583 | + 'persistent' => false, |
|
| 584 | + ), |
|
| 585 | + 'require_nonce' => false, |
|
| 586 | + ), |
|
| 587 | + 'edit_message_template' => array( |
|
| 588 | + 'labels' => array( |
|
| 589 | + 'buttons' => array( |
|
| 590 | + 'reset' => esc_html__('Reset Templates', 'event_espresso'), |
|
| 591 | + ), |
|
| 592 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso'), |
|
| 593 | + ), |
|
| 594 | + 'nav' => array( |
|
| 595 | + 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 596 | + 'order' => 5, |
|
| 597 | + 'persistent' => false, |
|
| 598 | + 'url' => '', |
|
| 599 | + ), |
|
| 600 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 601 | + 'has_metaboxes' => true, |
|
| 602 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 603 | + 'help_tabs' => array( |
|
| 604 | + 'edit_message_template' => array( |
|
| 605 | + 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 606 | + 'callback' => 'edit_message_template_help_tab', |
|
| 607 | + ), |
|
| 608 | + 'message_templates_help_tab' => array( |
|
| 609 | + 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 610 | + 'filename' => 'messages_templates', |
|
| 611 | + ), |
|
| 612 | + 'message_template_shortcodes' => array( |
|
| 613 | + 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 614 | + 'callback' => 'message_template_shortcodes_help_tab', |
|
| 615 | + ), |
|
| 616 | + 'message_preview_help_tab' => array( |
|
| 617 | + 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 618 | + 'filename' => 'messages_preview', |
|
| 619 | + ), |
|
| 620 | + 'messages_overview_other_help_tab' => array( |
|
| 621 | + 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 622 | + 'filename' => 'messages_overview_other', |
|
| 623 | + ), |
|
| 624 | + ), |
|
| 625 | + 'require_nonce' => false, |
|
| 626 | + ), |
|
| 627 | + 'display_preview_message' => array( |
|
| 628 | + 'nav' => array( |
|
| 629 | + 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 630 | + 'order' => 5, |
|
| 631 | + 'url' => '', |
|
| 632 | + 'persistent' => false, |
|
| 633 | + ), |
|
| 634 | + 'help_tabs' => array( |
|
| 635 | + 'preview_message' => array( |
|
| 636 | + 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 637 | + 'callback' => 'preview_message_help_tab', |
|
| 638 | + ), |
|
| 639 | + ), |
|
| 640 | + 'require_nonce' => false, |
|
| 641 | + ), |
|
| 642 | + 'settings' => array( |
|
| 643 | + 'nav' => array( |
|
| 644 | + 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 645 | + 'order' => 40, |
|
| 646 | + ), |
|
| 647 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 648 | + 'help_tabs' => array( |
|
| 649 | + 'messages_settings_help_tab' => array( |
|
| 650 | + 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 651 | + 'filename' => 'messages_settings', |
|
| 652 | + ), |
|
| 653 | + 'messages_settings_message_types_help_tab' => array( |
|
| 654 | + 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 655 | + 'filename' => 'messages_settings_message_types', |
|
| 656 | + ), |
|
| 657 | + 'messages_settings_messengers_help_tab' => array( |
|
| 658 | + 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 659 | + 'filename' => 'messages_settings_messengers', |
|
| 660 | + ), |
|
| 661 | + ), |
|
| 662 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 663 | + 'require_nonce' => false, |
|
| 664 | + ), |
|
| 665 | + ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + protected function _add_screen_options() |
|
| 670 | + { |
|
| 671 | + // todo |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + protected function _add_screen_options_global_mtps() |
|
| 676 | + { |
|
| 677 | + /** |
|
| 678 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 679 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 680 | + */ |
|
| 681 | + $page_title = $this->_admin_page_title; |
|
| 682 | + $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 683 | + $this->_per_page_screen_option(); |
|
| 684 | + $this->_admin_page_title = $page_title; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + protected function _add_screen_options_default() |
|
| 689 | + { |
|
| 690 | + $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 691 | + $this->_per_page_screen_option(); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + // none of the below group are currently used for Messages |
|
| 696 | + protected function _add_feature_pointers() |
|
| 697 | + { |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + public function admin_init() |
|
| 701 | + { |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + public function admin_notices() |
|
| 705 | + { |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + public function admin_footer_scripts() |
|
| 709 | + { |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + public function messages_help_tab() |
|
| 714 | + { |
|
| 715 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + public function messengers_help_tab() |
|
| 720 | + { |
|
| 721 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + public function message_types_help_tab() |
|
| 726 | + { |
|
| 727 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + public function messages_overview_help_tab() |
|
| 732 | + { |
|
| 733 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + public function message_templates_help_tab() |
|
| 738 | + { |
|
| 739 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + public function edit_message_template_help_tab() |
|
| 744 | + { |
|
| 745 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 746 | + . esc_attr__('Editor Title', 'event_espresso') |
|
| 747 | + . '" />'; |
|
| 748 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 749 | + . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 750 | + . '" />'; |
|
| 751 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 752 | + . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 753 | + . '" />'; |
|
| 754 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 755 | + . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 756 | + . '" />'; |
|
| 757 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 758 | + . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 759 | + . '" />'; |
|
| 760 | + EEH_Template::display_template( |
|
| 761 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 762 | + $args |
|
| 763 | + ); |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + public function message_template_shortcodes_help_tab() |
|
| 768 | + { |
|
| 769 | + $this->_set_shortcodes(); |
|
| 770 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 771 | + EEH_Template::display_template( |
|
| 772 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 773 | + $args |
|
| 774 | + ); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + public function preview_message_help_tab() |
|
| 779 | + { |
|
| 780 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + |
|
| 784 | + public function settings_help_tab() |
|
| 785 | + { |
|
| 786 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 787 | + . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 788 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 789 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 790 | + $args['img3'] = '<div class="switch">' |
|
| 791 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 792 | + . ' type="checkbox" checked="checked">' |
|
| 793 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 794 | + . '</div>'; |
|
| 795 | + $args['img4'] = '<div class="switch">' |
|
| 796 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 797 | + . ' type="checkbox">' |
|
| 798 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 799 | + . '</div>'; |
|
| 800 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + public function load_scripts_styles() |
|
| 805 | + { |
|
| 806 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 807 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 808 | + |
|
| 809 | + wp_register_script( |
|
| 810 | + 'ee-messages-settings', |
|
| 811 | + EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 812 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), |
|
| 813 | + EVENT_ESPRESSO_VERSION, |
|
| 814 | + true |
|
| 815 | + ); |
|
| 816 | + wp_register_script( |
|
| 817 | + 'ee-msg-list-table-js', |
|
| 818 | + EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 819 | + array('ee-dialog'), |
|
| 820 | + EVENT_ESPRESSO_VERSION |
|
| 821 | + ); |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + public function load_scripts_styles_default() |
|
| 826 | + { |
|
| 827 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + public function wp_editor_css($mce_css) |
|
| 832 | + { |
|
| 833 | + // if we're on the edit_message_template route |
|
| 834 | + if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 835 | + $message_type_name = $this->_active_message_type_name; |
|
| 836 | + |
|
| 837 | + // we're going to REPLACE the existing mce css |
|
| 838 | + // we need to get the css file location from the active messenger |
|
| 839 | + $mce_css = $this->_active_messenger->get_variation( |
|
| 840 | + $this->_template_pack, |
|
| 841 | + $message_type_name, |
|
| 842 | + true, |
|
| 843 | + 'wpeditor', |
|
| 844 | + $this->_variation |
|
| 845 | + ); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + return $mce_css; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + public function load_scripts_styles_edit_message_template() |
|
| 853 | + { |
|
| 854 | + |
|
| 855 | + $this->_set_shortcodes(); |
|
| 856 | + |
|
| 857 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 858 | + esc_html__( |
|
| 859 | + 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 860 | + 'event_espresso' |
|
| 861 | + ), |
|
| 862 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 863 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 864 | + ); |
|
| 865 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 866 | + 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 867 | + 'event_espresso' |
|
| 868 | + ); |
|
| 869 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 870 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 871 | + 'event_espresso' |
|
| 872 | + ); |
|
| 873 | + |
|
| 874 | + wp_register_script( |
|
| 875 | + 'ee_msgs_edit_js', |
|
| 876 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 877 | + array('jquery'), |
|
| 878 | + EVENT_ESPRESSO_VERSION |
|
| 879 | + ); |
|
| 880 | + |
|
| 881 | + wp_enqueue_script('ee_admin_js'); |
|
| 882 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 883 | + |
|
| 884 | + // add in special css for tiny_mce |
|
| 885 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + |
|
| 889 | + public function load_scripts_styles_display_preview_message() |
|
| 890 | + { |
|
| 891 | + |
|
| 892 | + $this->_set_message_template_group(); |
|
| 893 | + |
|
| 894 | + if (isset($this->_req_data['messenger'])) { |
|
| 895 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 896 | + $this->_req_data['messenger'] |
|
| 897 | + ); |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + wp_enqueue_style( |
|
| 904 | + 'espresso_preview_css', |
|
| 905 | + $this->_active_messenger->get_variation( |
|
| 906 | + $this->_template_pack, |
|
| 907 | + $message_type_name, |
|
| 908 | + true, |
|
| 909 | + 'preview', |
|
| 910 | + $this->_variation |
|
| 911 | + ) |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + public function load_scripts_styles_settings() |
|
| 917 | + { |
|
| 918 | + wp_register_style( |
|
| 919 | + 'ee-message-settings', |
|
| 920 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 921 | + array(), |
|
| 922 | + EVENT_ESPRESSO_VERSION |
|
| 923 | + ); |
|
| 924 | + wp_enqueue_style('ee-text-links'); |
|
| 925 | + wp_enqueue_style('ee-message-settings'); |
|
| 926 | + wp_enqueue_script('ee-messages-settings'); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * set views array for List Table |
|
| 932 | + */ |
|
| 933 | + public function _set_list_table_views_global_mtps() |
|
| 934 | + { |
|
| 935 | + $this->_views = array( |
|
| 936 | + 'in_use' => array( |
|
| 937 | + 'slug' => 'in_use', |
|
| 938 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 939 | + 'count' => 0, |
|
| 940 | + ), |
|
| 941 | + ); |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * Set views array for the Custom Template List Table |
|
| 947 | + */ |
|
| 948 | + public function _set_list_table_views_custom_mtps() |
|
| 949 | + { |
|
| 950 | + $this->_set_list_table_views_global_mtps(); |
|
| 951 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 952 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * set views array for message queue list table |
|
| 959 | + * |
|
| 960 | + * @throws InvalidDataTypeException |
|
| 961 | + * @throws InvalidInterfaceException |
|
| 962 | + * @throws InvalidArgumentException |
|
| 963 | + * @throws EE_Error |
|
| 964 | + * @throws ReflectionException |
|
| 965 | + */ |
|
| 966 | + public function _set_list_table_views_default() |
|
| 967 | + { |
|
| 968 | + EE_Registry::instance()->load_helper('Template'); |
|
| 969 | + |
|
| 970 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 971 | + 'ee_send_message', |
|
| 972 | + 'message_list_table_bulk_actions' |
|
| 973 | + ) |
|
| 974 | + ? array( |
|
| 975 | + 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 976 | + 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 977 | + 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 978 | + 'send_now' => esc_html__('Send Now', 'event_espresso'), |
|
| 979 | + ) |
|
| 980 | + : array(); |
|
| 981 | + |
|
| 982 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 983 | + 'ee_delete_messages', |
|
| 984 | + 'message_list_table_bulk_actions' |
|
| 985 | + ) |
|
| 986 | + ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 987 | + : array(); |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + $this->_views = array( |
|
| 991 | + 'all' => array( |
|
| 992 | + 'slug' => 'all', |
|
| 993 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 994 | + 'count' => 0, |
|
| 995 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action), |
|
| 996 | + ), |
|
| 997 | + ); |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 1001 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 1002 | + continue; |
|
| 1003 | + } |
|
| 1004 | + $status_bulk_actions = $common_bulk_actions; |
|
| 1005 | + // unset bulk actions not applying to status |
|
| 1006 | + if (! empty($status_bulk_actions)) { |
|
| 1007 | + switch ($status) { |
|
| 1008 | + case EEM_Message::status_idle: |
|
| 1009 | + case EEM_Message::status_resend: |
|
| 1010 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 1011 | + break; |
|
| 1012 | + |
|
| 1013 | + case EEM_Message::status_failed: |
|
| 1014 | + case EEM_Message::status_debug_only: |
|
| 1015 | + case EEM_Message::status_messenger_executing: |
|
| 1016 | + $status_bulk_actions = array(); |
|
| 1017 | + break; |
|
| 1018 | + |
|
| 1019 | + case EEM_Message::status_incomplete: |
|
| 1020 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1021 | + break; |
|
| 1022 | + |
|
| 1023 | + case EEM_Message::status_retry: |
|
| 1024 | + case EEM_Message::status_sent: |
|
| 1025 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1026 | + break; |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + // skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1031 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 1032 | + continue; |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + $this->_views[ strtolower($status) ] = array( |
|
| 1036 | + 'slug' => strtolower($status), |
|
| 1037 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1038 | + 'count' => 0, |
|
| 1039 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action), |
|
| 1040 | + ); |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + |
|
| 1045 | + protected function _ee_default_messages_overview_list_table() |
|
| 1046 | + { |
|
| 1047 | + $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1048 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + protected function _message_queue_list_table() |
|
| 1053 | + { |
|
| 1054 | + $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1055 | + $this->_template_args['per_column'] = 6; |
|
| 1056 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1057 | + $this->_template_args['before_list_table'] = '<h3>' |
|
| 1058 | + . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1059 | + . '</h3>'; |
|
| 1060 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + |
|
| 1064 | + protected function _message_legend_items() |
|
| 1065 | + { |
|
| 1066 | + |
|
| 1067 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1068 | + $action_items = array(); |
|
| 1069 | + |
|
| 1070 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1071 | + if ($action_item === 'see_notifications_for') { |
|
| 1072 | + continue; |
|
| 1073 | + } |
|
| 1074 | + $action_items[ $action_item ] = array( |
|
| 1075 | + 'class' => $action_details['css_class'], |
|
| 1076 | + 'desc' => $action_details['label'], |
|
| 1077 | + ); |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + /** @type array $status_items status legend setup */ |
|
| 1081 | + $status_items = array( |
|
| 1082 | + 'incomplete_status' => array( |
|
| 1083 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1084 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'), |
|
| 1085 | + ), |
|
| 1086 | + 'idle_status' => array( |
|
| 1087 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1088 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'), |
|
| 1089 | + ), |
|
| 1090 | + 'resend_status' => array( |
|
| 1091 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1092 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'), |
|
| 1093 | + ), |
|
| 1094 | + 'messenger_executing_status' => array( |
|
| 1095 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1096 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'), |
|
| 1097 | + ), |
|
| 1098 | + 'sent_status' => array( |
|
| 1099 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1100 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'), |
|
| 1101 | + ), |
|
| 1102 | + 'retry_status' => array( |
|
| 1103 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1104 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'), |
|
| 1105 | + ), |
|
| 1106 | + 'failed_status' => array( |
|
| 1107 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1108 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'), |
|
| 1109 | + ), |
|
| 1110 | + ); |
|
| 1111 | + if (EEM_Message::debug()) { |
|
| 1112 | + $status_items['debug_only_status'] = array( |
|
| 1113 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1114 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'), |
|
| 1115 | + ); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + return array_merge($action_items, $status_items); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + |
|
| 1122 | + protected function _custom_mtps_preview() |
|
| 1123 | + { |
|
| 1124 | + $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1125 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1126 | + . ' alt="' . esc_attr__( |
|
| 1127 | + 'Preview Custom Message Templates screenshot', |
|
| 1128 | + 'event_espresso' |
|
| 1129 | + ) . '" />'; |
|
| 1130 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 1131 | + . esc_html__( |
|
| 1132 | + 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1133 | + 'event_espresso' |
|
| 1134 | + ) |
|
| 1135 | + . '</strong>'; |
|
| 1136 | + |
|
| 1137 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + |
|
| 1141 | + /** |
|
| 1142 | + * get_message_templates |
|
| 1143 | + * This gets all the message templates for listing on the overview list. |
|
| 1144 | + * |
|
| 1145 | + * @access public |
|
| 1146 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1147 | + * @param string $type the current _view we're getting templates for |
|
| 1148 | + * @param bool $count return count? |
|
| 1149 | + * @param bool $all disregard any paging info (get all data); |
|
| 1150 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1151 | + * @return array |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + * @throws InvalidArgumentException |
|
| 1154 | + * @throws InvalidDataTypeException |
|
| 1155 | + * @throws InvalidInterfaceException |
|
| 1156 | + */ |
|
| 1157 | + public function get_message_templates( |
|
| 1158 | + $perpage = 10, |
|
| 1159 | + $type = 'in_use', |
|
| 1160 | + $count = false, |
|
| 1161 | + $all = false, |
|
| 1162 | + $global = true |
|
| 1163 | + ) { |
|
| 1164 | + |
|
| 1165 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1166 | + |
|
| 1167 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1168 | + $orderby = $this->_req_data['orderby']; |
|
| 1169 | + |
|
| 1170 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1171 | + ? $this->_req_data['order'] |
|
| 1172 | + : 'ASC'; |
|
| 1173 | + |
|
| 1174 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1175 | + ? $this->_req_data['paged'] |
|
| 1176 | + : 1; |
|
| 1177 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1178 | + ? $this->_req_data['perpage'] |
|
| 1179 | + : $perpage; |
|
| 1180 | + |
|
| 1181 | + $offset = ($current_page - 1) * $per_page; |
|
| 1182 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + // options will match what is in the _views array property |
|
| 1186 | + switch ($type) { |
|
| 1187 | + case 'in_use': |
|
| 1188 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1189 | + break; |
|
| 1190 | + default: |
|
| 1191 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + return $templates; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * filters etc might need a list of installed message_types |
|
| 1200 | + * |
|
| 1201 | + * @return array an array of message type objects |
|
| 1202 | + */ |
|
| 1203 | + public function get_installed_message_types() |
|
| 1204 | + { |
|
| 1205 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1206 | + $installed = array(); |
|
| 1207 | + |
|
| 1208 | + foreach ($installed_message_types as $message_type) { |
|
| 1209 | + $installed[ $message_type->name ] = $message_type; |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + return $installed; |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * _add_message_template |
|
| 1218 | + * |
|
| 1219 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1220 | + * |
|
| 1221 | + * @param string $message_type |
|
| 1222 | + * @param string $messenger |
|
| 1223 | + * @param string $GRP_ID |
|
| 1224 | + * |
|
| 1225 | + * @throws EE_error |
|
| 1226 | + */ |
|
| 1227 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1228 | + { |
|
| 1229 | + // set values override any request data |
|
| 1230 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1231 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1232 | + ? $this->_req_data['message_type'] |
|
| 1233 | + : $message_type; |
|
| 1234 | + |
|
| 1235 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1236 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1237 | + ? $this->_req_data['messenger'] |
|
| 1238 | + : $messenger; |
|
| 1239 | + |
|
| 1240 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1241 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1242 | + |
|
| 1243 | + // we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1244 | + if (empty($message_type) || empty($messenger)) { |
|
| 1245 | + throw new EE_Error( |
|
| 1246 | + esc_html__( |
|
| 1247 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1248 | + 'event_espresso' |
|
| 1249 | + ) |
|
| 1250 | + ); |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + // we need the GRP_ID for the template being used as the base for the new template |
|
| 1254 | + if (empty($GRP_ID)) { |
|
| 1255 | + throw new EE_Error( |
|
| 1256 | + esc_html__( |
|
| 1257 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1258 | + 'event_espresso' |
|
| 1259 | + ) |
|
| 1260 | + ); |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + // let's just make sure the template gets generated! |
|
| 1264 | + |
|
| 1265 | + // we need to reassign some variables for what the insert is expecting |
|
| 1266 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1267 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1268 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1269 | + $this->_insert_or_update_message_template(true); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * public wrapper for the _add_message_template method |
|
| 1275 | + * |
|
| 1276 | + * @param string $message_type message type slug |
|
| 1277 | + * @param string $messenger messenger slug |
|
| 1278 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1279 | + * off of. |
|
| 1280 | + * @throws EE_error |
|
| 1281 | + */ |
|
| 1282 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1283 | + { |
|
| 1284 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * _edit_message_template |
|
| 1290 | + * |
|
| 1291 | + * @access protected |
|
| 1292 | + * @return void |
|
| 1293 | + * @throws InvalidIdentifierException |
|
| 1294 | + * @throws DomainException |
|
| 1295 | + * @throws EE_Error |
|
| 1296 | + * @throws InvalidArgumentException |
|
| 1297 | + * @throws ReflectionException |
|
| 1298 | + * @throws InvalidDataTypeException |
|
| 1299 | + * @throws InvalidInterfaceException |
|
| 1300 | + */ |
|
| 1301 | + protected function _edit_message_template() |
|
| 1302 | + { |
|
| 1303 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1304 | + $template_fields = ''; |
|
| 1305 | + $sidebar_fields = ''; |
|
| 1306 | + // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1307 | + // valid html in the templates. |
|
| 1308 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1309 | + |
|
| 1310 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1311 | + ? absint($this->_req_data['id']) |
|
| 1312 | + : false; |
|
| 1313 | + |
|
| 1314 | + $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) |
|
| 1315 | + ? absint($this->_req_data['evt_id']) |
|
| 1316 | + : false; |
|
| 1317 | + |
|
| 1318 | + $this->_set_shortcodes(); // this also sets the _message_template property. |
|
| 1319 | + $message_template_group = $this->_message_template_group; |
|
| 1320 | + $c_label = $message_template_group->context_label(); |
|
| 1321 | + $c_config = $message_template_group->contexts_config(); |
|
| 1322 | + |
|
| 1323 | + reset($c_config); |
|
| 1324 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1325 | + ? strtolower($this->_req_data['context']) |
|
| 1326 | + : key($c_config); |
|
| 1327 | + |
|
| 1328 | + |
|
| 1329 | + if (empty($GRP_ID)) { |
|
| 1330 | + $action = 'insert_message_template'; |
|
| 1331 | + $edit_message_template_form_url = add_query_arg( |
|
| 1332 | + array('action' => $action, 'noheader' => true), |
|
| 1333 | + EE_MSG_ADMIN_URL |
|
| 1334 | + ); |
|
| 1335 | + } else { |
|
| 1336 | + $action = 'update_message_template'; |
|
| 1337 | + $edit_message_template_form_url = add_query_arg( |
|
| 1338 | + array('action' => $action, 'noheader' => true), |
|
| 1339 | + EE_MSG_ADMIN_URL |
|
| 1340 | + ); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + // set active messenger for this view |
|
| 1344 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1345 | + $message_template_group->messenger() |
|
| 1346 | + ); |
|
| 1347 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + // Do we have any validation errors? |
|
| 1351 | + $validators = $this->_get_transient(); |
|
| 1352 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1353 | + |
|
| 1354 | + |
|
| 1355 | + // we need to assemble the title from Various details |
|
| 1356 | + $context_label = sprintf( |
|
| 1357 | + esc_html__('(%s %s)', 'event_espresso'), |
|
| 1358 | + $c_config[ $context ]['label'], |
|
| 1359 | + ucwords($c_label['label']) |
|
| 1360 | + ); |
|
| 1361 | + |
|
| 1362 | + $title = sprintf( |
|
| 1363 | + esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1364 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1365 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1366 | + $context_label |
|
| 1367 | + ); |
|
| 1368 | + |
|
| 1369 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1370 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1371 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + // let's get EEH_MSG_Template so we can get template form fields |
|
| 1375 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1376 | + $message_template_group->messenger(), |
|
| 1377 | + $message_template_group->message_type() |
|
| 1378 | + ); |
|
| 1379 | + |
|
| 1380 | + if (! $template_field_structure) { |
|
| 1381 | + $template_field_structure = false; |
|
| 1382 | + $template_fields = esc_html__( |
|
| 1383 | + 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1384 | + 'event_espresso' |
|
| 1385 | + ); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + |
|
| 1389 | + $message_templates = $message_template_group->context_templates(); |
|
| 1390 | + |
|
| 1391 | + |
|
| 1392 | + // if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1393 | + // will get handled in the "extra" array. |
|
| 1394 | + if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { |
|
| 1395 | + foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { |
|
| 1396 | + unset($template_field_structure[ $context ][ $reference_field ]); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + // let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1401 | + if (! empty($template_field_structure)) { |
|
| 1402 | + foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { |
|
| 1403 | + // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1404 | + // the extra array and reset them. |
|
| 1405 | + if ($template_field === 'extra') { |
|
| 1406 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1407 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1408 | + $message_template = $message_templates[ $context ][ $reference_field ]; |
|
| 1409 | + $content = $message_template instanceof EE_Message_Template |
|
| 1410 | + ? $message_template->get('MTP_content') |
|
| 1411 | + : ''; |
|
| 1412 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1413 | + // let's verify if we need this extra field via the shortcodes parameter. |
|
| 1414 | + $continue = false; |
|
| 1415 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1416 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1417 | + if (! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1418 | + $continue = true; |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + if ($continue) { |
|
| 1422 | + continue; |
|
| 1423 | + } |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + $field_id = $reference_field |
|
| 1427 | + . '-' |
|
| 1428 | + . $extra_field |
|
| 1429 | + . '-content'; |
|
| 1430 | + $template_form_fields[ $field_id ] = $extra_array; |
|
| 1431 | + $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' |
|
| 1432 | + . $reference_field |
|
| 1433 | + . '][content][' |
|
| 1434 | + . $extra_field . ']'; |
|
| 1435 | + $css_class = isset($extra_array['css_class']) |
|
| 1436 | + ? $extra_array['css_class'] |
|
| 1437 | + : ''; |
|
| 1438 | + |
|
| 1439 | + $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) |
|
| 1440 | + && in_array($extra_field, $v_fields, true) |
|
| 1441 | + && |
|
| 1442 | + ( |
|
| 1443 | + is_array($validators[ $extra_field ]) |
|
| 1444 | + && isset($validators[ $extra_field ]['msg']) |
|
| 1445 | + ) |
|
| 1446 | + ? 'validate-error ' . $css_class |
|
| 1447 | + : $css_class; |
|
| 1448 | + |
|
| 1449 | + $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) |
|
| 1450 | + && isset($content[ $extra_field ]) |
|
| 1451 | + ? $content[ $extra_field ] |
|
| 1452 | + : ''; |
|
| 1453 | + |
|
| 1454 | + // do we have a validation error? if we do then let's use that value instead |
|
| 1455 | + $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ]) |
|
| 1456 | + ? $validators[ $extra_field ]['value'] |
|
| 1457 | + : $template_form_fields[ $field_id ]['value']; |
|
| 1458 | + |
|
| 1459 | + |
|
| 1460 | + $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; |
|
| 1461 | + |
|
| 1462 | + // shortcode selector |
|
| 1463 | + $field_name_to_use = $extra_field === 'main' |
|
| 1464 | + ? 'content' |
|
| 1465 | + : $extra_field; |
|
| 1466 | + $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( |
|
| 1467 | + $field_name_to_use, |
|
| 1468 | + $field_id |
|
| 1469 | + ); |
|
| 1470 | + |
|
| 1471 | + if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1472 | + // we want to decode the entities |
|
| 1473 | + $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value']; |
|
| 1474 | + }/**/ |
|
| 1475 | + } |
|
| 1476 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1477 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1478 | + |
|
| 1479 | + $template_form_fields[ $templatefield_MTP_id ] = array( |
|
| 1480 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1481 | + 'label' => null, |
|
| 1482 | + 'input' => 'hidden', |
|
| 1483 | + 'type' => 'int', |
|
| 1484 | + 'required' => false, |
|
| 1485 | + 'validation' => false, |
|
| 1486 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1487 | + 'css_class' => '', |
|
| 1488 | + 'format' => '%d', |
|
| 1489 | + 'db-col' => 'MTP_ID', |
|
| 1490 | + ); |
|
| 1491 | + |
|
| 1492 | + $template_form_fields[ $templatefield_templatename_id ] = array( |
|
| 1493 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1494 | + 'label' => null, |
|
| 1495 | + 'input' => 'hidden', |
|
| 1496 | + 'type' => 'string', |
|
| 1497 | + 'required' => false, |
|
| 1498 | + 'validation' => true, |
|
| 1499 | + 'value' => $reference_field, |
|
| 1500 | + 'css_class' => '', |
|
| 1501 | + 'format' => '%s', |
|
| 1502 | + 'db-col' => 'MTP_template_field', |
|
| 1503 | + ); |
|
| 1504 | + } |
|
| 1505 | + continue; // skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1506 | + } else { |
|
| 1507 | + $field_id = $template_field . '-content'; |
|
| 1508 | + $template_form_fields[ $field_id ] = $field_setup_array; |
|
| 1509 | + $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1510 | + $message_template = isset($message_templates[ $context ][ $template_field ]) |
|
| 1511 | + ? $message_templates[ $context ][ $template_field ] |
|
| 1512 | + : null; |
|
| 1513 | + $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) |
|
| 1514 | + && is_array($message_templates[ $context ]) |
|
| 1515 | + && $message_template instanceof EE_Message_Template |
|
| 1516 | + ? $message_template->get('MTP_content') |
|
| 1517 | + : ''; |
|
| 1518 | + |
|
| 1519 | + // do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1520 | + $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ]) |
|
| 1521 | + ? $validators[ $template_field ]['value'] |
|
| 1522 | + : $template_form_fields[ $field_id ]['value']; |
|
| 1523 | + |
|
| 1524 | + |
|
| 1525 | + $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; |
|
| 1526 | + $css_class = isset($field_setup_array['css_class']) |
|
| 1527 | + ? $field_setup_array['css_class'] |
|
| 1528 | + : ''; |
|
| 1529 | + $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) |
|
| 1530 | + && in_array($template_field, $v_fields, true) |
|
| 1531 | + && isset($validators[ $template_field ]['msg']) |
|
| 1532 | + ? 'validate-error ' . $css_class |
|
| 1533 | + : $css_class; |
|
| 1534 | + |
|
| 1535 | + // shortcode selector |
|
| 1536 | + $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( |
|
| 1537 | + $template_field, |
|
| 1538 | + $field_id |
|
| 1539 | + ); |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + // k took care of content field(s) now let's take care of others. |
|
| 1543 | + |
|
| 1544 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1545 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1546 | + |
|
| 1547 | + // foreach template field there are actually two form fields created |
|
| 1548 | + $template_form_fields[ $templatefield_MTP_id ] = array( |
|
| 1549 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1550 | + 'label' => null, |
|
| 1551 | + 'input' => 'hidden', |
|
| 1552 | + 'type' => 'int', |
|
| 1553 | + 'required' => false, |
|
| 1554 | + 'validation' => true, |
|
| 1555 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1556 | + 'css_class' => '', |
|
| 1557 | + 'format' => '%d', |
|
| 1558 | + 'db-col' => 'MTP_ID', |
|
| 1559 | + ); |
|
| 1560 | + |
|
| 1561 | + $template_form_fields[ $templatefield_field_templatename_id ] = array( |
|
| 1562 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1563 | + 'label' => null, |
|
| 1564 | + 'input' => 'hidden', |
|
| 1565 | + 'type' => 'string', |
|
| 1566 | + 'required' => false, |
|
| 1567 | + 'validation' => true, |
|
| 1568 | + 'value' => $template_field, |
|
| 1569 | + 'css_class' => '', |
|
| 1570 | + 'format' => '%s', |
|
| 1571 | + 'db-col' => 'MTP_template_field', |
|
| 1572 | + ); |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + // add other fields |
|
| 1576 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1577 | + 'name' => 'MTP_context', |
|
| 1578 | + 'label' => null, |
|
| 1579 | + 'input' => 'hidden', |
|
| 1580 | + 'type' => 'string', |
|
| 1581 | + 'required' => false, |
|
| 1582 | + 'validation' => true, |
|
| 1583 | + 'value' => $context, |
|
| 1584 | + 'css_class' => '', |
|
| 1585 | + 'format' => '%s', |
|
| 1586 | + 'db-col' => 'MTP_context', |
|
| 1587 | + ); |
|
| 1588 | + |
|
| 1589 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1590 | + 'name' => 'GRP_ID', |
|
| 1591 | + 'label' => null, |
|
| 1592 | + 'input' => 'hidden', |
|
| 1593 | + 'type' => 'int', |
|
| 1594 | + 'required' => false, |
|
| 1595 | + 'validation' => true, |
|
| 1596 | + 'value' => $GRP_ID, |
|
| 1597 | + 'css_class' => '', |
|
| 1598 | + 'format' => '%d', |
|
| 1599 | + 'db-col' => 'GRP_ID', |
|
| 1600 | + ); |
|
| 1601 | + |
|
| 1602 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1603 | + 'name' => 'MTP_messenger', |
|
| 1604 | + 'label' => null, |
|
| 1605 | + 'input' => 'hidden', |
|
| 1606 | + 'type' => 'string', |
|
| 1607 | + 'required' => false, |
|
| 1608 | + 'validation' => true, |
|
| 1609 | + 'value' => $message_template_group->messenger(), |
|
| 1610 | + 'css_class' => '', |
|
| 1611 | + 'format' => '%s', |
|
| 1612 | + 'db-col' => 'MTP_messenger', |
|
| 1613 | + ); |
|
| 1614 | + |
|
| 1615 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1616 | + 'name' => 'MTP_message_type', |
|
| 1617 | + 'label' => null, |
|
| 1618 | + 'input' => 'hidden', |
|
| 1619 | + 'type' => 'string', |
|
| 1620 | + 'required' => false, |
|
| 1621 | + 'validation' => true, |
|
| 1622 | + 'value' => $message_template_group->message_type(), |
|
| 1623 | + 'css_class' => '', |
|
| 1624 | + 'format' => '%s', |
|
| 1625 | + 'db-col' => 'MTP_message_type', |
|
| 1626 | + ); |
|
| 1627 | + |
|
| 1628 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1629 | + 'name' => 'MTP_is_global', |
|
| 1630 | + 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1631 | + 'input' => 'hidden', |
|
| 1632 | + 'type' => 'int', |
|
| 1633 | + 'required' => false, |
|
| 1634 | + 'validation' => true, |
|
| 1635 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1636 | + 'css_class' => '', |
|
| 1637 | + 'format' => '%d', |
|
| 1638 | + 'db-col' => 'MTP_is_global', |
|
| 1639 | + ); |
|
| 1640 | + |
|
| 1641 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1642 | + 'name' => 'MTP_is_override', |
|
| 1643 | + 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1644 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1645 | + 'type' => 'int', |
|
| 1646 | + 'required' => false, |
|
| 1647 | + 'validation' => true, |
|
| 1648 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1649 | + 'css_class' => '', |
|
| 1650 | + 'format' => '%d', |
|
| 1651 | + 'db-col' => 'MTP_is_override', |
|
| 1652 | + ); |
|
| 1653 | + |
|
| 1654 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1655 | + 'name' => 'MTP_is_active', |
|
| 1656 | + 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1657 | + 'input' => 'hidden', |
|
| 1658 | + 'type' => 'int', |
|
| 1659 | + 'required' => false, |
|
| 1660 | + 'validation' => true, |
|
| 1661 | + 'value' => $message_template_group->is_active(), |
|
| 1662 | + 'css_class' => '', |
|
| 1663 | + 'format' => '%d', |
|
| 1664 | + 'db-col' => 'MTP_is_active', |
|
| 1665 | + ); |
|
| 1666 | + |
|
| 1667 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1668 | + 'name' => 'MTP_deleted', |
|
| 1669 | + 'label' => null, |
|
| 1670 | + 'input' => 'hidden', |
|
| 1671 | + 'type' => 'int', |
|
| 1672 | + 'required' => false, |
|
| 1673 | + 'validation' => true, |
|
| 1674 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1675 | + 'css_class' => '', |
|
| 1676 | + 'format' => '%d', |
|
| 1677 | + 'db-col' => 'MTP_deleted', |
|
| 1678 | + ); |
|
| 1679 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1680 | + 'name' => 'MTP_user_id', |
|
| 1681 | + 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1682 | + 'input' => 'hidden', |
|
| 1683 | + 'type' => 'int', |
|
| 1684 | + 'required' => false, |
|
| 1685 | + 'validation' => false, |
|
| 1686 | + 'value' => $message_template_group->user(), |
|
| 1687 | + 'format' => '%d', |
|
| 1688 | + 'db-col' => 'MTP_user_id', |
|
| 1689 | + ); |
|
| 1690 | + |
|
| 1691 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1692 | + 'name' => 'action', |
|
| 1693 | + 'input' => 'hidden', |
|
| 1694 | + 'type' => 'string', |
|
| 1695 | + 'value' => $action, |
|
| 1696 | + ); |
|
| 1697 | + |
|
| 1698 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1699 | + 'name' => 'id', |
|
| 1700 | + 'input' => 'hidden', |
|
| 1701 | + 'type' => 'int', |
|
| 1702 | + 'value' => $GRP_ID, |
|
| 1703 | + ); |
|
| 1704 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1705 | + 'name' => $action . '_nonce', |
|
| 1706 | + 'input' => 'hidden', |
|
| 1707 | + 'type' => 'string', |
|
| 1708 | + 'value' => wp_create_nonce($action . '_nonce'), |
|
| 1709 | + ); |
|
| 1710 | + |
|
| 1711 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1712 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1713 | + 'name' => 'template_switch', |
|
| 1714 | + 'input' => 'hidden', |
|
| 1715 | + 'type' => 'int', |
|
| 1716 | + 'value' => 1, |
|
| 1717 | + ); |
|
| 1718 | + } |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1722 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1723 | + } //end if ( !empty($template_field_structure) ) |
|
| 1724 | + |
|
| 1725 | + // set extra content for publish box |
|
| 1726 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1727 | + $this->_set_publish_post_box_vars( |
|
| 1728 | + 'id', |
|
| 1729 | + $GRP_ID, |
|
| 1730 | + false, |
|
| 1731 | + add_query_arg( |
|
| 1732 | + array('action' => 'global_mtps'), |
|
| 1733 | + $this->_admin_base_url |
|
| 1734 | + ) |
|
| 1735 | + ); |
|
| 1736 | + |
|
| 1737 | + // add preview button |
|
| 1738 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1739 | + array( |
|
| 1740 | + 'message_type' => $message_template_group->message_type(), |
|
| 1741 | + 'messenger' => $message_template_group->messenger(), |
|
| 1742 | + 'context' => $context, |
|
| 1743 | + 'GRP_ID' => $GRP_ID, |
|
| 1744 | + 'evt_id' => $EVT_ID, |
|
| 1745 | + 'action' => 'preview_message', |
|
| 1746 | + ), |
|
| 1747 | + $this->_admin_base_url |
|
| 1748 | + ); |
|
| 1749 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1750 | + . esc_html__('Preview', 'event_espresso') |
|
| 1751 | + . '</a>'; |
|
| 1752 | + |
|
| 1753 | + |
|
| 1754 | + // setup context switcher |
|
| 1755 | + $context_switcher_args = array( |
|
| 1756 | + 'page' => 'espresso_messages', |
|
| 1757 | + 'action' => 'edit_message_template', |
|
| 1758 | + 'id' => $GRP_ID, |
|
| 1759 | + 'evt_id' => $EVT_ID, |
|
| 1760 | + 'context' => $context, |
|
| 1761 | + 'extra' => $preview_button, |
|
| 1762 | + ); |
|
| 1763 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1764 | + |
|
| 1765 | + |
|
| 1766 | + // main box |
|
| 1767 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1768 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1769 | + $this->_template_args['action'] = $action; |
|
| 1770 | + $this->_template_args['context'] = $context; |
|
| 1771 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1772 | + $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1773 | + $this->_learn_more_about_message_templates_link(); |
|
| 1774 | + |
|
| 1775 | + |
|
| 1776 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1777 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1778 | + $message_template_group, |
|
| 1779 | + $context, |
|
| 1780 | + $context_label |
|
| 1781 | + ); |
|
| 1782 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1783 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1784 | + |
|
| 1785 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1786 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1787 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1788 | + |
|
| 1789 | + // send along EE_Message_Template_Group object for further template use. |
|
| 1790 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1791 | + |
|
| 1792 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1793 | + $this->_template_path, |
|
| 1794 | + $this->_template_args, |
|
| 1795 | + true |
|
| 1796 | + ); |
|
| 1797 | + |
|
| 1798 | + |
|
| 1799 | + // finally, let's set the admin_page title |
|
| 1800 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1801 | + |
|
| 1802 | + |
|
| 1803 | + // we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1804 | + $this->_set_shortcodes(); |
|
| 1805 | + |
|
| 1806 | + |
|
| 1807 | + // final template wrapper |
|
| 1808 | + $this->display_admin_page_with_sidebar(); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + |
|
| 1812 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1813 | + { |
|
| 1814 | + return $mceInit; |
|
| 1815 | + } |
|
| 1816 | + |
|
| 1817 | + |
|
| 1818 | + public function add_context_switcher() |
|
| 1819 | + { |
|
| 1820 | + return $this->_context_switcher; |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + |
|
| 1824 | + /** |
|
| 1825 | + * Adds the activation/deactivation toggle for the message template context. |
|
| 1826 | + * |
|
| 1827 | + * @param EE_Message_Template_Group $message_template_group |
|
| 1828 | + * @param string $context |
|
| 1829 | + * @param string $context_label |
|
| 1830 | + * @return string |
|
| 1831 | + * @throws DomainException |
|
| 1832 | + * @throws EE_Error |
|
| 1833 | + * @throws InvalidIdentifierException |
|
| 1834 | + */ |
|
| 1835 | + protected function add_active_context_element( |
|
| 1836 | + EE_Message_Template_Group $message_template_group, |
|
| 1837 | + $context, |
|
| 1838 | + $context_label |
|
| 1839 | + ) { |
|
| 1840 | + $template_args = array( |
|
| 1841 | + 'context' => $context, |
|
| 1842 | + 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1843 | + 'is_active' => $message_template_group->is_context_active($context), |
|
| 1844 | + 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1845 | + ? 'context-off' |
|
| 1846 | + : 'context-on', |
|
| 1847 | + 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1848 | + 'message_template_group_id' => $message_template_group->ID(), |
|
| 1849 | + ); |
|
| 1850 | + return EEH_Template::display_template( |
|
| 1851 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1852 | + $template_args, |
|
| 1853 | + true |
|
| 1854 | + ); |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * Ajax callback for `toggle_context_template` ajax action. |
|
| 1860 | + * Handles toggling the message context on or off. |
|
| 1861 | + * |
|
| 1862 | + * @throws EE_Error |
|
| 1863 | + * @throws InvalidArgumentException |
|
| 1864 | + * @throws InvalidDataTypeException |
|
| 1865 | + * @throws InvalidIdentifierException |
|
| 1866 | + * @throws InvalidInterfaceException |
|
| 1867 | + */ |
|
| 1868 | + public function toggle_context_template() |
|
| 1869 | + { |
|
| 1870 | + $success = true; |
|
| 1871 | + // check for required data |
|
| 1872 | + if ( |
|
| 1873 | + ! isset( |
|
| 1874 | + $this->_req_data['message_template_group_id'], |
|
| 1875 | + $this->_req_data['context'], |
|
| 1876 | + $this->_req_data['status'] |
|
| 1877 | + ) |
|
| 1878 | + ) { |
|
| 1879 | + EE_Error::add_error( |
|
| 1880 | + esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1881 | + __FILE__, |
|
| 1882 | + __FUNCTION__, |
|
| 1883 | + __LINE__ |
|
| 1884 | + ); |
|
| 1885 | + $success = false; |
|
| 1886 | + } |
|
| 1887 | + |
|
| 1888 | + $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1889 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1890 | + : ''; |
|
| 1891 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1892 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1893 | + $status = $this->_req_data['status']; |
|
| 1894 | + if ($status !== 'off' && $status !== 'on') { |
|
| 1895 | + EE_Error::add_error( |
|
| 1896 | + sprintf( |
|
| 1897 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1898 | + $this->_req_data['status'] |
|
| 1899 | + ), |
|
| 1900 | + __FILE__, |
|
| 1901 | + __FUNCTION__, |
|
| 1902 | + __LINE__ |
|
| 1903 | + ); |
|
| 1904 | + $success = false; |
|
| 1905 | + } |
|
| 1906 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1907 | + $this->_req_data['message_template_group_id'] |
|
| 1908 | + ); |
|
| 1909 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1910 | + EE_Error::add_error( |
|
| 1911 | + sprintf( |
|
| 1912 | + esc_html__( |
|
| 1913 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1914 | + 'event_espresso' |
|
| 1915 | + ), |
|
| 1916 | + $this->_req_data['message_template_group_id'], |
|
| 1917 | + 'EE_Message_Template_Group' |
|
| 1918 | + ), |
|
| 1919 | + __FILE__, |
|
| 1920 | + __FUNCTION__, |
|
| 1921 | + __LINE__ |
|
| 1922 | + ); |
|
| 1923 | + $success = false; |
|
| 1924 | + } |
|
| 1925 | + if ($success) { |
|
| 1926 | + $success = $status === 'off' |
|
| 1927 | + ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1928 | + : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1929 | + } |
|
| 1930 | + $this->_template_args['success'] = $success; |
|
| 1931 | + $this->_return_json(); |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + |
|
| 1935 | + public function _add_form_element_before() |
|
| 1936 | + { |
|
| 1937 | + return '<form method="post" action="' |
|
| 1938 | + . $this->_template_args["edit_message_template_form_url"] |
|
| 1939 | + . '" id="ee-msg-edit-frm">'; |
|
| 1940 | + } |
|
| 1941 | + |
|
| 1942 | + public function _add_form_element_after() |
|
| 1943 | + { |
|
| 1944 | + return '</form>'; |
|
| 1945 | + } |
|
| 1946 | + |
|
| 1947 | + |
|
| 1948 | + /** |
|
| 1949 | + * This executes switching the template pack for a message template. |
|
| 1950 | + * |
|
| 1951 | + * @since 4.5.0 |
|
| 1952 | + * @throws EE_Error |
|
| 1953 | + * @throws InvalidDataTypeException |
|
| 1954 | + * @throws InvalidInterfaceException |
|
| 1955 | + * @throws InvalidArgumentException |
|
| 1956 | + * @throws ReflectionException |
|
| 1957 | + */ |
|
| 1958 | + public function switch_template_pack() |
|
| 1959 | + { |
|
| 1960 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1961 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1962 | + |
|
| 1963 | + // verify we have needed values. |
|
| 1964 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1965 | + $this->_template_args['error'] = true; |
|
| 1966 | + EE_Error::add_error( |
|
| 1967 | + esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1968 | + __FILE__, |
|
| 1969 | + __FUNCTION__, |
|
| 1970 | + __LINE__ |
|
| 1971 | + ); |
|
| 1972 | + } else { |
|
| 1973 | + // get template, set the new template_pack and then reset to default |
|
| 1974 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1975 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1976 | + |
|
| 1977 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1978 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1979 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1980 | + |
|
| 1981 | + $query_args = $this->_reset_to_default_template(); |
|
| 1982 | + |
|
| 1983 | + if (empty($query_args['id'])) { |
|
| 1984 | + EE_Error::add_error( |
|
| 1985 | + esc_html__( |
|
| 1986 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1987 | + 'event_espresso' |
|
| 1988 | + ), |
|
| 1989 | + __FILE__, |
|
| 1990 | + __FUNCTION__, |
|
| 1991 | + __LINE__ |
|
| 1992 | + ); |
|
| 1993 | + $this->_template_args['error'] = true; |
|
| 1994 | + } else { |
|
| 1995 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1996 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1997 | + EE_Error::add_success( |
|
| 1998 | + sprintf( |
|
| 1999 | + esc_html__( |
|
| 2000 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 2001 | + 'event_espresso' |
|
| 2002 | + ), |
|
| 2003 | + $template_label, |
|
| 2004 | + $template_pack_labels->template_pack |
|
| 2005 | + ) |
|
| 2006 | + ); |
|
| 2007 | + // generate the redirect url for js. |
|
| 2008 | + $url = self::add_query_args_and_nonce( |
|
| 2009 | + $query_args, |
|
| 2010 | + $this->_admin_base_url |
|
| 2011 | + ); |
|
| 2012 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 2013 | + $this->_template_args['success'] = true; |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + $this->_return_json(); |
|
| 2017 | + } |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + |
|
| 2021 | + /** |
|
| 2022 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2023 | + * they want. |
|
| 2024 | + * |
|
| 2025 | + * @access protected |
|
| 2026 | + * @return array|null |
|
| 2027 | + * @throws EE_Error |
|
| 2028 | + * @throws InvalidArgumentException |
|
| 2029 | + * @throws InvalidDataTypeException |
|
| 2030 | + * @throws InvalidInterfaceException |
|
| 2031 | + */ |
|
| 2032 | + protected function _reset_to_default_template() |
|
| 2033 | + { |
|
| 2034 | + |
|
| 2035 | + $templates = array(); |
|
| 2036 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2037 | + // we need to make sure we've got the info we need. |
|
| 2038 | + if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2039 | + EE_Error::add_error( |
|
| 2040 | + esc_html__( |
|
| 2041 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2042 | + 'event_espresso' |
|
| 2043 | + ), |
|
| 2044 | + __FILE__, |
|
| 2045 | + __FUNCTION__, |
|
| 2046 | + __LINE__ |
|
| 2047 | + ); |
|
| 2048 | + } |
|
| 2049 | + |
|
| 2050 | + // all templates will be reset to whatever the defaults are |
|
| 2051 | + // for the global template matching the messenger and message type. |
|
| 2052 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 2053 | + |
|
| 2054 | + if ($success) { |
|
| 2055 | + // let's first determine if the incoming template is a global template, |
|
| 2056 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2057 | + // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2058 | + |
|
| 2059 | + |
|
| 2060 | + // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2061 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2062 | + |
|
| 2063 | + if ($success) { |
|
| 2064 | + // if successfully deleted, lets generate the new ones. |
|
| 2065 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2066 | + // will use the related global template defaults for regeneration. |
|
| 2067 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2068 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 2069 | + // for the current custom template when resetting. |
|
| 2070 | + $templates = $this->_generate_new_templates( |
|
| 2071 | + $this->_req_data['msgr'], |
|
| 2072 | + $this->_req_data['mt'], |
|
| 2073 | + $GRP_ID, |
|
| 2074 | + true |
|
| 2075 | + ); |
|
| 2076 | + } |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + // any error messages? |
|
| 2080 | + if (! $success) { |
|
| 2081 | + EE_Error::add_error( |
|
| 2082 | + esc_html__( |
|
| 2083 | + 'Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2084 | + 'event_espresso' |
|
| 2085 | + ), |
|
| 2086 | + __FILE__, |
|
| 2087 | + __FUNCTION__, |
|
| 2088 | + __LINE__ |
|
| 2089 | + ); |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + // all good, let's add a success message! |
|
| 2093 | + if ($success && ! empty($templates)) { |
|
| 2094 | + // the info for the template we generated is the first element in the returned array |
|
| 2095 | + // $templates = $templates[0]; |
|
| 2096 | + EE_Error::overwrite_success(); |
|
| 2097 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2098 | + } |
|
| 2099 | + |
|
| 2100 | + |
|
| 2101 | + $query_args = array( |
|
| 2102 | + 'id' => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null, |
|
| 2103 | + 'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null, |
|
| 2104 | + 'action' => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps', |
|
| 2105 | + ); |
|
| 2106 | + |
|
| 2107 | + // if called via ajax then we return query args otherwise redirect |
|
| 2108 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2109 | + return $query_args; |
|
| 2110 | + } else { |
|
| 2111 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2112 | + |
|
| 2113 | + return null; |
|
| 2114 | + } |
|
| 2115 | + } |
|
| 2116 | + |
|
| 2117 | + |
|
| 2118 | + /** |
|
| 2119 | + * Retrieve and set the message preview for display. |
|
| 2120 | + * |
|
| 2121 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2122 | + * @return string |
|
| 2123 | + * @throws ReflectionException |
|
| 2124 | + * @throws EE_Error |
|
| 2125 | + * @throws InvalidArgumentException |
|
| 2126 | + * @throws InvalidDataTypeException |
|
| 2127 | + * @throws InvalidInterfaceException |
|
| 2128 | + */ |
|
| 2129 | + public function _preview_message($send = false) |
|
| 2130 | + { |
|
| 2131 | + // first make sure we've got the necessary parameters |
|
| 2132 | + if ( |
|
| 2133 | + ! isset( |
|
| 2134 | + $this->_req_data['message_type'], |
|
| 2135 | + $this->_req_data['messenger'], |
|
| 2136 | + $this->_req_data['messenger'], |
|
| 2137 | + $this->_req_data['GRP_ID'] |
|
| 2138 | + ) |
|
| 2139 | + ) { |
|
| 2140 | + EE_Error::add_error( |
|
| 2141 | + esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2142 | + __FILE__, |
|
| 2143 | + __FUNCTION__, |
|
| 2144 | + __LINE__ |
|
| 2145 | + ); |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2149 | + |
|
| 2150 | + // if we have an evt_id set on the request, use it. |
|
| 2151 | + $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id']) |
|
| 2152 | + ? absint($this->_req_data['evt_id']) |
|
| 2153 | + : false; |
|
| 2154 | + |
|
| 2155 | + |
|
| 2156 | + // get the preview! |
|
| 2157 | + $preview = EED_Messages::preview_message( |
|
| 2158 | + $this->_req_data['message_type'], |
|
| 2159 | + $this->_req_data['context'], |
|
| 2160 | + $this->_req_data['messenger'], |
|
| 2161 | + $send |
|
| 2162 | + ); |
|
| 2163 | + |
|
| 2164 | + if ($send) { |
|
| 2165 | + return $preview; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + // let's add a button to go back to the edit view |
|
| 2169 | + $query_args = array( |
|
| 2170 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2171 | + 'evt_id' => $EVT_ID, |
|
| 2172 | + 'context' => $this->_req_data['context'], |
|
| 2173 | + 'action' => 'edit_message_template', |
|
| 2174 | + ); |
|
| 2175 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2176 | + $preview_button = '<a href="' |
|
| 2177 | + . $go_back_url |
|
| 2178 | + . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2179 | + . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2180 | + . '</a>'; |
|
| 2181 | + $message_types = $this->get_installed_message_types(); |
|
| 2182 | + $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2183 | + $this->_req_data['messenger'] |
|
| 2184 | + ); |
|
| 2185 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2186 | + ? ucwords($active_messenger->label['singular']) |
|
| 2187 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2188 | + // let's provide a helpful title for context |
|
| 2189 | + $preview_title = sprintf( |
|
| 2190 | + esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2191 | + $active_messenger_label, |
|
| 2192 | + ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular']) |
|
| 2193 | + ); |
|
| 2194 | + if (empty($preview)) { |
|
| 2195 | + $this->noEventsErrorMessage(); |
|
| 2196 | + } |
|
| 2197 | + // setup display of preview. |
|
| 2198 | + $this->_admin_page_title = $preview_title; |
|
| 2199 | + $this->_template_args['admin_page_title'] = $preview_title; |
|
| 2200 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2201 | + $this->_template_args['data']['force_json'] = true; |
|
| 2202 | + |
|
| 2203 | + return ''; |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + |
|
| 2207 | + /** |
|
| 2208 | + * Used to set an error if there are no events available for generating a preview/test send. |
|
| 2209 | + * |
|
| 2210 | + * @param bool $test_send Whether the error should be generated for the context of a test send. |
|
| 2211 | + */ |
|
| 2212 | + protected function noEventsErrorMessage($test_send = false) |
|
| 2213 | + { |
|
| 2214 | + $events_url = parent::add_query_args_and_nonce( |
|
| 2215 | + array( |
|
| 2216 | + 'action' => 'default', |
|
| 2217 | + 'page' => 'espresso_events', |
|
| 2218 | + ), |
|
| 2219 | + admin_url('admin.php') |
|
| 2220 | + ); |
|
| 2221 | + $message = $test_send |
|
| 2222 | + ? __( |
|
| 2223 | + 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!', |
|
| 2224 | + 'event_espresso' |
|
| 2225 | + ) |
|
| 2226 | + : __( |
|
| 2227 | + 'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!', |
|
| 2228 | + 'event_espresso' |
|
| 2229 | + ); |
|
| 2230 | + |
|
| 2231 | + EE_Error::add_attention( |
|
| 2232 | + sprintf( |
|
| 2233 | + $message, |
|
| 2234 | + "<a href='{$events_url}'>", |
|
| 2235 | + '</a>' |
|
| 2236 | + ) |
|
| 2237 | + ); |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + |
|
| 2241 | + /** |
|
| 2242 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2243 | + * gets called automatically. |
|
| 2244 | + * |
|
| 2245 | + * @since 4.5.0 |
|
| 2246 | + * |
|
| 2247 | + * @return string |
|
| 2248 | + */ |
|
| 2249 | + protected function _display_preview_message() |
|
| 2250 | + { |
|
| 2251 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2257 | + * |
|
| 2258 | + * @access protected |
|
| 2259 | + * @return void |
|
| 2260 | + */ |
|
| 2261 | + protected function _register_edit_meta_boxes() |
|
| 2262 | + { |
|
| 2263 | + add_meta_box( |
|
| 2264 | + 'mtp_valid_shortcodes', |
|
| 2265 | + esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2266 | + array($this, 'shortcode_meta_box'), |
|
| 2267 | + $this->_current_screen->id, |
|
| 2268 | + 'side', |
|
| 2269 | + 'default' |
|
| 2270 | + ); |
|
| 2271 | + add_meta_box( |
|
| 2272 | + 'mtp_extra_actions', |
|
| 2273 | + esc_html__('Extra Actions', 'event_espresso'), |
|
| 2274 | + array($this, 'extra_actions_meta_box'), |
|
| 2275 | + $this->_current_screen->id, |
|
| 2276 | + 'side', |
|
| 2277 | + 'high' |
|
| 2278 | + ); |
|
| 2279 | + add_meta_box( |
|
| 2280 | + 'mtp_templates', |
|
| 2281 | + esc_html__('Template Styles', 'event_espresso'), |
|
| 2282 | + array($this, 'template_pack_meta_box'), |
|
| 2283 | + $this->_current_screen->id, |
|
| 2284 | + 'side', |
|
| 2285 | + 'high' |
|
| 2286 | + ); |
|
| 2287 | + } |
|
| 2288 | + |
|
| 2289 | + |
|
| 2290 | + /** |
|
| 2291 | + * metabox content for all template pack and variation selection. |
|
| 2292 | + * |
|
| 2293 | + * @since 4.5.0 |
|
| 2294 | + * @return string |
|
| 2295 | + * @throws DomainException |
|
| 2296 | + * @throws EE_Error |
|
| 2297 | + * @throws InvalidArgumentException |
|
| 2298 | + * @throws ReflectionException |
|
| 2299 | + * @throws InvalidDataTypeException |
|
| 2300 | + * @throws InvalidInterfaceException |
|
| 2301 | + */ |
|
| 2302 | + public function template_pack_meta_box() |
|
| 2303 | + { |
|
| 2304 | + $this->_set_message_template_group(); |
|
| 2305 | + |
|
| 2306 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2307 | + |
|
| 2308 | + $tp_select_values = array(); |
|
| 2309 | + |
|
| 2310 | + foreach ($tp_collection as $tp) { |
|
| 2311 | + // only include template packs that support this messenger and message type! |
|
| 2312 | + $supports = $tp->get_supports(); |
|
| 2313 | + if ( |
|
| 2314 | + ! isset($supports[ $this->_message_template_group->messenger() ]) |
|
| 2315 | + || ! in_array( |
|
| 2316 | + $this->_message_template_group->message_type(), |
|
| 2317 | + $supports[ $this->_message_template_group->messenger() ], |
|
| 2318 | + true |
|
| 2319 | + ) |
|
| 2320 | + ) { |
|
| 2321 | + // not supported |
|
| 2322 | + continue; |
|
| 2323 | + } |
|
| 2324 | + |
|
| 2325 | + $tp_select_values[] = array( |
|
| 2326 | + 'text' => $tp->label, |
|
| 2327 | + 'id' => $tp->dbref, |
|
| 2328 | + ); |
|
| 2329 | + } |
|
| 2330 | + |
|
| 2331 | + // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2332 | + // the default template pack. This still allows for the odd template pack to override. |
|
| 2333 | + if (empty($tp_select_values)) { |
|
| 2334 | + $tp_select_values[] = array( |
|
| 2335 | + 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2336 | + 'id' => 'default', |
|
| 2337 | + ); |
|
| 2338 | + } |
|
| 2339 | + |
|
| 2340 | + // setup variation select values for the currently selected template. |
|
| 2341 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2342 | + $this->_message_template_group->messenger(), |
|
| 2343 | + $this->_message_template_group->message_type() |
|
| 2344 | + ); |
|
| 2345 | + $variations_select_values = array(); |
|
| 2346 | + foreach ($variations as $variation => $label) { |
|
| 2347 | + $variations_select_values[] = array( |
|
| 2348 | + 'text' => $label, |
|
| 2349 | + 'id' => $variation, |
|
| 2350 | + ); |
|
| 2351 | + } |
|
| 2352 | + |
|
| 2353 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2354 | + |
|
| 2355 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2356 | + 'MTP_template_pack', |
|
| 2357 | + $tp_select_values, |
|
| 2358 | + $this->_message_template_group->get_template_pack_name() |
|
| 2359 | + ); |
|
| 2360 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2361 | + 'MTP_template_variation', |
|
| 2362 | + $variations_select_values, |
|
| 2363 | + $this->_message_template_group->get_template_pack_variation() |
|
| 2364 | + ); |
|
| 2365 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2366 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2367 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2368 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2369 | + |
|
| 2370 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2371 | + |
|
| 2372 | + EEH_Template::display_template($template, $template_args); |
|
| 2373 | + } |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * This meta box holds any extra actions related to Message Templates |
|
| 2378 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2379 | + * |
|
| 2380 | + * @access public |
|
| 2381 | + * @return void |
|
| 2382 | + * @throws EE_Error |
|
| 2383 | + */ |
|
| 2384 | + public function extra_actions_meta_box() |
|
| 2385 | + { |
|
| 2386 | + $template_form_fields = array(); |
|
| 2387 | + |
|
| 2388 | + $extra_args = array( |
|
| 2389 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2390 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2391 | + 'GRP_ID' => $this->_message_template_group->GRP_ID(), |
|
| 2392 | + ); |
|
| 2393 | + // first we need to see if there are any fields |
|
| 2394 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2395 | + |
|
| 2396 | + if (! empty($fields)) { |
|
| 2397 | + // yup there be fields |
|
| 2398 | + foreach ($fields as $field => $config) { |
|
| 2399 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2400 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2401 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2402 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2403 | + |
|
| 2404 | + // if type is hidden and the value is empty |
|
| 2405 | + // something may have gone wrong so let's correct with the defaults |
|
| 2406 | + $fix = $config['input'] === 'hidden' |
|
| 2407 | + && isset($existing[ $field ]) |
|
| 2408 | + && empty($existing[ $field ]) |
|
| 2409 | + ? $default |
|
| 2410 | + : ''; |
|
| 2411 | + $existing[ $field ] = isset($existing[ $field ]) && empty($fix) |
|
| 2412 | + ? $existing[ $field ] |
|
| 2413 | + : $fix; |
|
| 2414 | + |
|
| 2415 | + $template_form_fields[ $field_id ] = array( |
|
| 2416 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2417 | + 'label' => $config['label'], |
|
| 2418 | + 'input' => $config['input'], |
|
| 2419 | + 'type' => $config['type'], |
|
| 2420 | + 'required' => $config['required'], |
|
| 2421 | + 'validation' => $config['validation'], |
|
| 2422 | + 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default, |
|
| 2423 | + 'css_class' => $config['css_class'], |
|
| 2424 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2425 | + 'default' => $default, |
|
| 2426 | + 'format' => $config['format'], |
|
| 2427 | + ); |
|
| 2428 | + } |
|
| 2429 | + } |
|
| 2430 | + |
|
| 2431 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2432 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2433 | + : ''; |
|
| 2434 | + |
|
| 2435 | + $test_settings_html = ''; |
|
| 2436 | + // print out $test_settings_fields |
|
| 2437 | + if (! empty($test_settings_fields)) { |
|
| 2438 | + echo $test_settings_fields; |
|
| 2439 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2440 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2441 | + $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2442 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2443 | + } |
|
| 2444 | + |
|
| 2445 | + // and button |
|
| 2446 | + $test_settings_html .= '<p>' |
|
| 2447 | + . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2448 | + . '</p>'; |
|
| 2449 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2450 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2451 | + 'reset_to_default', |
|
| 2452 | + 'reset', |
|
| 2453 | + $extra_args, |
|
| 2454 | + 'button-primary reset-default-button' |
|
| 2455 | + ); |
|
| 2456 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2457 | + echo $test_settings_html; |
|
| 2458 | + } |
|
| 2459 | + |
|
| 2460 | + |
|
| 2461 | + /** |
|
| 2462 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2463 | + * |
|
| 2464 | + * @since 4.9.rc.000 |
|
| 2465 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2466 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2467 | + * @return string |
|
| 2468 | + * @throws DomainException |
|
| 2469 | + * @throws EE_Error |
|
| 2470 | + * @throws InvalidArgumentException |
|
| 2471 | + * @throws ReflectionException |
|
| 2472 | + * @throws InvalidDataTypeException |
|
| 2473 | + * @throws InvalidInterfaceException |
|
| 2474 | + */ |
|
| 2475 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2476 | + { |
|
| 2477 | + $template_args = array( |
|
| 2478 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2479 | + 'fieldname' => $field, |
|
| 2480 | + 'linked_input_id' => $linked_input_id, |
|
| 2481 | + ); |
|
| 2482 | + |
|
| 2483 | + return EEH_Template::display_template( |
|
| 2484 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2485 | + $template_args, |
|
| 2486 | + true |
|
| 2487 | + ); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + |
|
| 2491 | + /** |
|
| 2492 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2493 | + * page) |
|
| 2494 | + * |
|
| 2495 | + * @access public |
|
| 2496 | + * @return void |
|
| 2497 | + * @throws EE_Error |
|
| 2498 | + * @throws InvalidArgumentException |
|
| 2499 | + * @throws ReflectionException |
|
| 2500 | + * @throws InvalidDataTypeException |
|
| 2501 | + * @throws InvalidInterfaceException |
|
| 2502 | + */ |
|
| 2503 | + public function shortcode_meta_box() |
|
| 2504 | + { |
|
| 2505 | + $shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set |
|
| 2506 | + // $messenger = $this->_message_template_group->messenger_obj(); |
|
| 2507 | + // now let's set the content depending on the status of the shortcodes array |
|
| 2508 | + if (empty($shortcodes)) { |
|
| 2509 | + $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2510 | + echo $content; |
|
| 2511 | + } else { |
|
| 2512 | + // $alt = 0; |
|
| 2513 | + ?> |
|
| 2514 | 2514 | <div style="float:right; margin-top:10px"><?php |
| 2515 | - echo $this->_get_help_tab_link('message_template_shortcodes'); |
|
| 2516 | - ?></div> |
|
| 2515 | + echo $this->_get_help_tab_link('message_template_shortcodes'); |
|
| 2516 | + ?></div> |
|
| 2517 | 2517 | <p class="small-text"><?php |
| 2518 | - printf( |
|
| 2519 | - esc_html__( |
|
| 2520 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2521 | - 'event_espresso' |
|
| 2522 | - ), |
|
| 2523 | - '<span class="dashicons dashicons-menu"></span>' |
|
| 2524 | - ); |
|
| 2525 | - ?> |
|
| 2518 | + printf( |
|
| 2519 | + esc_html__( |
|
| 2520 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2521 | + 'event_espresso' |
|
| 2522 | + ), |
|
| 2523 | + '<span class="dashicons dashicons-menu"></span>' |
|
| 2524 | + ); |
|
| 2525 | + ?> |
|
| 2526 | 2526 | </p> |
| 2527 | 2527 | <?php |
| 2528 | - } |
|
| 2529 | - } |
|
| 2530 | - |
|
| 2531 | - |
|
| 2532 | - /** |
|
| 2533 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2534 | - * |
|
| 2535 | - * @access protected |
|
| 2536 | - * @return void |
|
| 2537 | - * @throws EE_Error |
|
| 2538 | - * @throws InvalidArgumentException |
|
| 2539 | - * @throws ReflectionException |
|
| 2540 | - * @throws InvalidDataTypeException |
|
| 2541 | - * @throws InvalidInterfaceException |
|
| 2542 | - */ |
|
| 2543 | - protected function _set_shortcodes() |
|
| 2544 | - { |
|
| 2545 | - |
|
| 2546 | - // no need to run this if the property is already set |
|
| 2547 | - if (! empty($this->_shortcodes)) { |
|
| 2548 | - return; |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - |
|
| 2555 | - /** |
|
| 2556 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2557 | - * property) |
|
| 2558 | - * |
|
| 2559 | - * @access protected |
|
| 2560 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2561 | - * for. Defaults to all (for the given context) |
|
| 2562 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2563 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2564 | - * true just an array of shortcode/label pairs. |
|
| 2565 | - * @throws EE_Error |
|
| 2566 | - * @throws InvalidArgumentException |
|
| 2567 | - * @throws ReflectionException |
|
| 2568 | - * @throws InvalidDataTypeException |
|
| 2569 | - * @throws InvalidInterfaceException |
|
| 2570 | - */ |
|
| 2571 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2572 | - { |
|
| 2573 | - $this->_set_message_template_group(); |
|
| 2574 | - |
|
| 2575 | - // we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2576 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2577 | - ? absint($this->_req_data['id']) |
|
| 2578 | - : false; |
|
| 2579 | - $context = isset($this->_req_data['context']) |
|
| 2580 | - ? $this->_req_data['context'] |
|
| 2581 | - : key($this->_message_template_group->contexts_config()); |
|
| 2582 | - |
|
| 2583 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2584 | - } |
|
| 2585 | - |
|
| 2586 | - |
|
| 2587 | - /** |
|
| 2588 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2589 | - * |
|
| 2590 | - * @access protected |
|
| 2591 | - * @return void |
|
| 2592 | - * @throws EE_Error |
|
| 2593 | - * @throws InvalidArgumentException |
|
| 2594 | - * @throws ReflectionException |
|
| 2595 | - * @throws InvalidDataTypeException |
|
| 2596 | - * @throws InvalidInterfaceException |
|
| 2597 | - */ |
|
| 2598 | - protected function _set_message_template_group() |
|
| 2599 | - { |
|
| 2600 | - |
|
| 2601 | - if (! empty($this->_message_template_group)) { |
|
| 2602 | - return; |
|
| 2603 | - } //get out if this is already set. |
|
| 2604 | - |
|
| 2605 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2606 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2607 | - |
|
| 2608 | - // let's get the message templates |
|
| 2609 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2610 | - |
|
| 2611 | - if (empty($GRP_ID)) { |
|
| 2612 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2613 | - } else { |
|
| 2614 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2615 | - } |
|
| 2616 | - |
|
| 2617 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2618 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2619 | - } |
|
| 2620 | - |
|
| 2621 | - |
|
| 2622 | - /** |
|
| 2623 | - * sets up a context switcher for edit forms |
|
| 2624 | - * |
|
| 2625 | - * @access protected |
|
| 2626 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2627 | - * @param array $args various things the context switcher needs. |
|
| 2628 | - * @throws EE_Error |
|
| 2629 | - */ |
|
| 2630 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2631 | - { |
|
| 2632 | - $context_details = $template_group_object->contexts_config(); |
|
| 2633 | - $context_label = $template_group_object->context_label(); |
|
| 2634 | - ob_start(); |
|
| 2635 | - ?> |
|
| 2528 | + } |
|
| 2529 | + } |
|
| 2530 | + |
|
| 2531 | + |
|
| 2532 | + /** |
|
| 2533 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2534 | + * |
|
| 2535 | + * @access protected |
|
| 2536 | + * @return void |
|
| 2537 | + * @throws EE_Error |
|
| 2538 | + * @throws InvalidArgumentException |
|
| 2539 | + * @throws ReflectionException |
|
| 2540 | + * @throws InvalidDataTypeException |
|
| 2541 | + * @throws InvalidInterfaceException |
|
| 2542 | + */ |
|
| 2543 | + protected function _set_shortcodes() |
|
| 2544 | + { |
|
| 2545 | + |
|
| 2546 | + // no need to run this if the property is already set |
|
| 2547 | + if (! empty($this->_shortcodes)) { |
|
| 2548 | + return; |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2552 | + } |
|
| 2553 | + |
|
| 2554 | + |
|
| 2555 | + /** |
|
| 2556 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2557 | + * property) |
|
| 2558 | + * |
|
| 2559 | + * @access protected |
|
| 2560 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2561 | + * for. Defaults to all (for the given context) |
|
| 2562 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2563 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2564 | + * true just an array of shortcode/label pairs. |
|
| 2565 | + * @throws EE_Error |
|
| 2566 | + * @throws InvalidArgumentException |
|
| 2567 | + * @throws ReflectionException |
|
| 2568 | + * @throws InvalidDataTypeException |
|
| 2569 | + * @throws InvalidInterfaceException |
|
| 2570 | + */ |
|
| 2571 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2572 | + { |
|
| 2573 | + $this->_set_message_template_group(); |
|
| 2574 | + |
|
| 2575 | + // we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2576 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2577 | + ? absint($this->_req_data['id']) |
|
| 2578 | + : false; |
|
| 2579 | + $context = isset($this->_req_data['context']) |
|
| 2580 | + ? $this->_req_data['context'] |
|
| 2581 | + : key($this->_message_template_group->contexts_config()); |
|
| 2582 | + |
|
| 2583 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2584 | + } |
|
| 2585 | + |
|
| 2586 | + |
|
| 2587 | + /** |
|
| 2588 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2589 | + * |
|
| 2590 | + * @access protected |
|
| 2591 | + * @return void |
|
| 2592 | + * @throws EE_Error |
|
| 2593 | + * @throws InvalidArgumentException |
|
| 2594 | + * @throws ReflectionException |
|
| 2595 | + * @throws InvalidDataTypeException |
|
| 2596 | + * @throws InvalidInterfaceException |
|
| 2597 | + */ |
|
| 2598 | + protected function _set_message_template_group() |
|
| 2599 | + { |
|
| 2600 | + |
|
| 2601 | + if (! empty($this->_message_template_group)) { |
|
| 2602 | + return; |
|
| 2603 | + } //get out if this is already set. |
|
| 2604 | + |
|
| 2605 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2606 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2607 | + |
|
| 2608 | + // let's get the message templates |
|
| 2609 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2610 | + |
|
| 2611 | + if (empty($GRP_ID)) { |
|
| 2612 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2613 | + } else { |
|
| 2614 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2615 | + } |
|
| 2616 | + |
|
| 2617 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2618 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2619 | + } |
|
| 2620 | + |
|
| 2621 | + |
|
| 2622 | + /** |
|
| 2623 | + * sets up a context switcher for edit forms |
|
| 2624 | + * |
|
| 2625 | + * @access protected |
|
| 2626 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2627 | + * @param array $args various things the context switcher needs. |
|
| 2628 | + * @throws EE_Error |
|
| 2629 | + */ |
|
| 2630 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2631 | + { |
|
| 2632 | + $context_details = $template_group_object->contexts_config(); |
|
| 2633 | + $context_label = $template_group_object->context_label(); |
|
| 2634 | + ob_start(); |
|
| 2635 | + ?> |
|
| 2636 | 2636 | <div class="ee-msg-switcher-container"> |
| 2637 | 2637 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2638 | 2638 | <?php |
| 2639 | - foreach ($args as $name => $value) { |
|
| 2640 | - if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2641 | - continue; |
|
| 2642 | - } |
|
| 2643 | - ?> |
|
| 2639 | + foreach ($args as $name => $value) { |
|
| 2640 | + if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2641 | + continue; |
|
| 2642 | + } |
|
| 2643 | + ?> |
|
| 2644 | 2644 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2645 | 2645 | <?php |
| 2646 | - } |
|
| 2647 | - // setup nonce_url |
|
| 2648 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2649 | - ?> |
|
| 2646 | + } |
|
| 2647 | + // setup nonce_url |
|
| 2648 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2649 | + ?> |
|
| 2650 | 2650 | <select name="context"> |
| 2651 | 2651 | <?php |
| 2652 | - $context_templates = $template_group_object->context_templates(); |
|
| 2653 | - if (is_array($context_templates)) : |
|
| 2654 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2655 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2656 | - ?> |
|
| 2652 | + $context_templates = $template_group_object->context_templates(); |
|
| 2653 | + if (is_array($context_templates)) : |
|
| 2654 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2655 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2656 | + ?> |
|
| 2657 | 2657 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2658 | 2658 | <?php echo $context_details[ $context ]['label']; ?> |
| 2659 | 2659 | </option> |
| 2660 | 2660 | <?php endforeach; |
| 2661 | - endif; ?> |
|
| 2661 | + endif; ?> |
|
| 2662 | 2662 | </select> |
| 2663 | 2663 | <?php $button_text = sprintf(__('Switch %s', 'event_espresso'), ucwords($context_label['label'])); ?> |
| 2664 | 2664 | <input id="submit-msg-context-switcher-sbmt" class="button-secondary" type="submit" |
@@ -2667,1932 +2667,1932 @@ discard block |
||
| 2667 | 2667 | <?php echo $args['extra']; ?> |
| 2668 | 2668 | </div> <!-- end .ee-msg-switcher-container --> |
| 2669 | 2669 | <?php |
| 2670 | - $output = ob_get_contents(); |
|
| 2671 | - ob_clean(); |
|
| 2672 | - $this->_context_switcher = $output; |
|
| 2673 | - } |
|
| 2674 | - |
|
| 2675 | - |
|
| 2676 | - /** |
|
| 2677 | - * utility for sanitizing new values coming in. |
|
| 2678 | - * Note: this is only used when updating a context. |
|
| 2679 | - * |
|
| 2680 | - * @access protected |
|
| 2681 | - * |
|
| 2682 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2683 | - * |
|
| 2684 | - * @return array |
|
| 2685 | - */ |
|
| 2686 | - protected function _set_message_template_column_values($index) |
|
| 2687 | - { |
|
| 2688 | - if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) { |
|
| 2689 | - foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) { |
|
| 2690 | - $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value; |
|
| 2691 | - } |
|
| 2692 | - } |
|
| 2693 | - |
|
| 2694 | - |
|
| 2695 | - $set_column_values = array( |
|
| 2696 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']), |
|
| 2697 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2698 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2699 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2700 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2701 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']), |
|
| 2702 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2703 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][ $index ]['content'], |
|
| 2704 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2705 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2706 | - : 0, |
|
| 2707 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2708 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2709 | - : 0, |
|
| 2710 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2711 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']), |
|
| 2712 | - ); |
|
| 2713 | - |
|
| 2714 | - |
|
| 2715 | - return $set_column_values; |
|
| 2716 | - } |
|
| 2717 | - |
|
| 2718 | - |
|
| 2719 | - protected function _insert_or_update_message_template($new = false) |
|
| 2720 | - { |
|
| 2721 | - |
|
| 2722 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2723 | - $success = 0; |
|
| 2724 | - $override = false; |
|
| 2725 | - |
|
| 2726 | - // setup notices description |
|
| 2727 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2728 | - |
|
| 2729 | - // need the message type and messenger objects to be able to use the labels for the notices |
|
| 2730 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2731 | - $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2732 | - ? ucwords($messenger_object->label['singular']) |
|
| 2733 | - : ''; |
|
| 2734 | - |
|
| 2735 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2736 | - ? $this->_req_data['MTP_message_type'] |
|
| 2737 | - : ''; |
|
| 2738 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2739 | - |
|
| 2740 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2741 | - ? ucwords($message_type_object->label['singular']) |
|
| 2742 | - : ''; |
|
| 2743 | - |
|
| 2744 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2745 | - ? $this->_req_data['MTP_context'] |
|
| 2746 | - : ''; |
|
| 2747 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2748 | - |
|
| 2749 | - $item_desc = $messenger_label && $message_type_label |
|
| 2750 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2751 | - : ''; |
|
| 2752 | - $item_desc .= 'Message Template'; |
|
| 2753 | - $query_args = array(); |
|
| 2754 | - $edit_array = array(); |
|
| 2755 | - $action_desc = ''; |
|
| 2756 | - |
|
| 2757 | - // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2758 | - // user to edit. |
|
| 2759 | - if ($new) { |
|
| 2760 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2761 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2762 | - if (empty($edit_array)) { |
|
| 2763 | - $success = 0; |
|
| 2764 | - } else { |
|
| 2765 | - $success = 1; |
|
| 2766 | - $edit_array = $edit_array[0]; |
|
| 2767 | - $query_args = array( |
|
| 2768 | - 'id' => $edit_array['GRP_ID'], |
|
| 2769 | - 'context' => $edit_array['MTP_context'], |
|
| 2770 | - 'action' => 'edit_message_template', |
|
| 2771 | - ); |
|
| 2772 | - } |
|
| 2773 | - } |
|
| 2774 | - $action_desc = 'created'; |
|
| 2775 | - } else { |
|
| 2776 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2777 | - $MTP = EEM_Message_Template::instance(); |
|
| 2778 | - |
|
| 2779 | - |
|
| 2780 | - // run update for each template field in displayed context |
|
| 2781 | - if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2782 | - EE_Error::add_error( |
|
| 2783 | - esc_html__( |
|
| 2784 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2785 | - 'event_espresso' |
|
| 2786 | - ), |
|
| 2787 | - __FILE__, |
|
| 2788 | - __FUNCTION__, |
|
| 2789 | - __LINE__ |
|
| 2790 | - ); |
|
| 2791 | - $success = 0; |
|
| 2792 | - } else { |
|
| 2793 | - // first validate all fields! |
|
| 2794 | - // this filter allows client code to add its own validation to the template fields as well. |
|
| 2795 | - // returning an empty array means everything passed validation. |
|
| 2796 | - // errors in validation should be represented in an array with the following shape: |
|
| 2797 | - // array( |
|
| 2798 | - // 'fieldname' => array( |
|
| 2799 | - // 'msg' => 'error message' |
|
| 2800 | - // 'value' => 'value for field producing error' |
|
| 2801 | - // ) |
|
| 2802 | - $custom_validation = (array) apply_filters( |
|
| 2803 | - 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', |
|
| 2804 | - array(), |
|
| 2805 | - $this->_req_data['MTP_template_fields'], |
|
| 2806 | - $context_slug, |
|
| 2807 | - $messenger_slug, |
|
| 2808 | - $message_type_slug |
|
| 2809 | - ); |
|
| 2810 | - |
|
| 2811 | - $system_validation = $MTPG->validate( |
|
| 2812 | - $this->_req_data['MTP_template_fields'], |
|
| 2813 | - $context_slug, |
|
| 2814 | - $messenger_slug, |
|
| 2815 | - $message_type_slug |
|
| 2816 | - ); |
|
| 2817 | - |
|
| 2818 | - $system_validation = ! is_array($system_validation) && $system_validation ? array() |
|
| 2819 | - : $system_validation; |
|
| 2820 | - $validates = array_merge($custom_validation, $system_validation); |
|
| 2821 | - |
|
| 2822 | - // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2823 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2824 | - // WE need to make sure there is no actual error messages in validates. |
|
| 2825 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2826 | - // add the transient so when the form loads we know which fields to highlight |
|
| 2827 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2828 | - |
|
| 2829 | - $success = 0; |
|
| 2830 | - |
|
| 2831 | - // setup notices |
|
| 2832 | - foreach ($validates as $field => $error) { |
|
| 2833 | - if (isset($error['msg'])) { |
|
| 2834 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2835 | - } |
|
| 2836 | - } |
|
| 2837 | - } else { |
|
| 2838 | - $set_column_values = array(); |
|
| 2839 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2840 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2841 | - |
|
| 2842 | - $where_cols_n_values = array( |
|
| 2843 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'], |
|
| 2844 | - ); |
|
| 2845 | - // if they aren't allowed to use all JS, restrict them to just posty-y tags |
|
| 2846 | - if (! current_user_can('unfiltered_html')) { |
|
| 2847 | - if (is_array($set_column_values['MTP_content'])) { |
|
| 2848 | - foreach ($set_column_values['MTP_content'] as $key => $value) { |
|
| 2849 | - // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
|
| 2850 | - // only removes slashes from double-quotes, so attributes using single quotes always |
|
| 2851 | - // appear invalid.) But currently the models expect slashed data, so after wp_kses |
|
| 2852 | - // runs we need to re-slash the data. Sheesh. See |
|
| 2853 | - // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
| 2854 | - $set_column_values['MTP_content'][ $key ] = addslashes( |
|
| 2855 | - wp_kses( |
|
| 2856 | - stripslashes($value), |
|
| 2857 | - wp_kses_allowed_html('post') |
|
| 2858 | - ) |
|
| 2859 | - ); |
|
| 2860 | - } |
|
| 2861 | - } else { |
|
| 2862 | - $set_column_values['MTP_content'] = wp_kses( |
|
| 2863 | - $set_column_values['MTP_content'], |
|
| 2864 | - wp_kses_allowed_html('post') |
|
| 2865 | - ); |
|
| 2866 | - } |
|
| 2867 | - } |
|
| 2868 | - $message_template_fields = array( |
|
| 2869 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2870 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2871 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2872 | - 'MTP_content' => $set_column_values['MTP_content'], |
|
| 2873 | - ); |
|
| 2874 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2875 | - if ($updated === false) { |
|
| 2876 | - EE_Error::add_error( |
|
| 2877 | - sprintf( |
|
| 2878 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2879 | - $template_field |
|
| 2880 | - ), |
|
| 2881 | - __FILE__, |
|
| 2882 | - __FUNCTION__, |
|
| 2883 | - __LINE__ |
|
| 2884 | - ); |
|
| 2885 | - } else { |
|
| 2886 | - $success = 1; |
|
| 2887 | - } |
|
| 2888 | - } else { |
|
| 2889 | - // only do this logic if we don't have a MTP_ID for this field |
|
| 2890 | - if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) { |
|
| 2891 | - // this has already been through the template field validator and sanitized, so it will be |
|
| 2892 | - // safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2893 | - // message template field in a messenger/message type and existing users don't have the |
|
| 2894 | - // default setup for it. |
|
| 2895 | - // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2896 | - $updated = $MTP->insert($message_template_fields); |
|
| 2897 | - if (! $updated || is_wp_error($updated)) { |
|
| 2898 | - EE_Error::add_error( |
|
| 2899 | - sprintf( |
|
| 2900 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2901 | - $template_field |
|
| 2902 | - ), |
|
| 2903 | - __FILE__, |
|
| 2904 | - __FUNCTION__, |
|
| 2905 | - __LINE__ |
|
| 2906 | - ); |
|
| 2907 | - $success = 0; |
|
| 2908 | - } else { |
|
| 2909 | - $success = 1; |
|
| 2910 | - } |
|
| 2911 | - } |
|
| 2912 | - } |
|
| 2913 | - $action_desc = 'updated'; |
|
| 2914 | - } |
|
| 2915 | - |
|
| 2916 | - // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2917 | - $mtpg_fields = array( |
|
| 2918 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2919 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2920 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2921 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2922 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2923 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2924 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2925 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2926 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2927 | - : '', |
|
| 2928 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2929 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2930 | - : '', |
|
| 2931 | - ); |
|
| 2932 | - |
|
| 2933 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2934 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2935 | - |
|
| 2936 | - if ($updated === false) { |
|
| 2937 | - EE_Error::add_error( |
|
| 2938 | - sprintf( |
|
| 2939 | - esc_html__( |
|
| 2940 | - 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2941 | - 'event_espresso' |
|
| 2942 | - ), |
|
| 2943 | - $set_column_values['GRP_ID'] |
|
| 2944 | - ), |
|
| 2945 | - __FILE__, |
|
| 2946 | - __FUNCTION__, |
|
| 2947 | - __LINE__ |
|
| 2948 | - ); |
|
| 2949 | - } else { |
|
| 2950 | - // k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2951 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2952 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2953 | - : 'default'; |
|
| 2954 | - |
|
| 2955 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2956 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2957 | - : 'default'; |
|
| 2958 | - |
|
| 2959 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2960 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2961 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2962 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2963 | - } |
|
| 2964 | - $success = 1; |
|
| 2965 | - } |
|
| 2966 | - } |
|
| 2967 | - } |
|
| 2968 | - } |
|
| 2969 | - |
|
| 2970 | - // we return things differently if doing ajax |
|
| 2971 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2972 | - $this->_template_args['success'] = $success; |
|
| 2973 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2974 | - $this->_template_args['content'] = ''; |
|
| 2975 | - $this->_template_args['data'] = array( |
|
| 2976 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2977 | - 'templateName' => $edit_array['template_name'], |
|
| 2978 | - ); |
|
| 2979 | - if ($success) { |
|
| 2980 | - EE_Error::overwrite_success(); |
|
| 2981 | - EE_Error::add_success( |
|
| 2982 | - esc_html__( |
|
| 2983 | - 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2984 | - 'event_espresso' |
|
| 2985 | - ) |
|
| 2986 | - ); |
|
| 2987 | - } |
|
| 2988 | - |
|
| 2989 | - $this->_return_json(); |
|
| 2990 | - } |
|
| 2991 | - |
|
| 2992 | - |
|
| 2993 | - // was a test send triggered? |
|
| 2994 | - if (isset($this->_req_data['test_button'])) { |
|
| 2995 | - EE_Error::overwrite_success(); |
|
| 2996 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2997 | - $override = true; |
|
| 2998 | - } |
|
| 2999 | - |
|
| 3000 | - if (empty($query_args)) { |
|
| 3001 | - $query_args = array( |
|
| 3002 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 3003 | - 'context' => $context_slug, |
|
| 3004 | - 'action' => 'edit_message_template', |
|
| 3005 | - ); |
|
| 3006 | - } |
|
| 3007 | - |
|
| 3008 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 3009 | - } |
|
| 3010 | - |
|
| 3011 | - |
|
| 3012 | - /** |
|
| 3013 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 3014 | - * |
|
| 3015 | - * @param string $context what context being tested |
|
| 3016 | - * @param string $messenger messenger being tested |
|
| 3017 | - * @param string $message_type message type being tested |
|
| 3018 | - * @throws EE_Error |
|
| 3019 | - * @throws InvalidArgumentException |
|
| 3020 | - * @throws InvalidDataTypeException |
|
| 3021 | - * @throws InvalidInterfaceException |
|
| 3022 | - */ |
|
| 3023 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 3024 | - { |
|
| 3025 | - // set things up for preview |
|
| 3026 | - $this->_req_data['messenger'] = $messenger; |
|
| 3027 | - $this->_req_data['message_type'] = $message_type; |
|
| 3028 | - $this->_req_data['context'] = $context; |
|
| 3029 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 3030 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 3031 | - |
|
| 3032 | - // let's save any existing fields that might be required by the messenger |
|
| 3033 | - if ( |
|
| 3034 | - isset($this->_req_data['test_settings_fld']) |
|
| 3035 | - && $active_messenger instanceof EE_messenger |
|
| 3036 | - && apply_filters( |
|
| 3037 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 3038 | - true, |
|
| 3039 | - $this->_req_data['test_settings_fld'], |
|
| 3040 | - $active_messenger |
|
| 3041 | - ) |
|
| 3042 | - ) { |
|
| 3043 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 3044 | - } |
|
| 3045 | - |
|
| 3046 | - /** |
|
| 3047 | - * Use filter to add additional controls on whether message can send or not |
|
| 3048 | - */ |
|
| 3049 | - if ( |
|
| 3050 | - apply_filters( |
|
| 3051 | - 'FHEE__Messages_Admin_Page__do_test_send__can_send', |
|
| 3052 | - true, |
|
| 3053 | - $context, |
|
| 3054 | - $this->_req_data, |
|
| 3055 | - $messenger, |
|
| 3056 | - $message_type |
|
| 3057 | - ) |
|
| 3058 | - ) { |
|
| 3059 | - if (EEM_Event::instance()->count() > 0) { |
|
| 3060 | - $success = $this->_preview_message(true); |
|
| 3061 | - if ($success) { |
|
| 3062 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 3063 | - } else { |
|
| 3064 | - EE_Error::add_error( |
|
| 3065 | - esc_html__('The test message was not sent', 'event_espresso'), |
|
| 3066 | - __FILE__, |
|
| 3067 | - __FUNCTION__, |
|
| 3068 | - __LINE__ |
|
| 3069 | - ); |
|
| 3070 | - } |
|
| 3071 | - } else { |
|
| 3072 | - $this->noEventsErrorMessage(true); |
|
| 3073 | - } |
|
| 3074 | - } |
|
| 3075 | - } |
|
| 3076 | - |
|
| 3077 | - |
|
| 3078 | - /** |
|
| 3079 | - * _generate_new_templates |
|
| 3080 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 3081 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 3082 | - * for the event. |
|
| 3083 | - * |
|
| 3084 | - * |
|
| 3085 | - * @param string $messenger the messenger we are generating templates for |
|
| 3086 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 3087 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 3088 | - * indicate the message_template_group being used as the base. |
|
| 3089 | - * |
|
| 3090 | - * @param bool $global |
|
| 3091 | - * |
|
| 3092 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 3093 | - * encountering problems. |
|
| 3094 | - * @throws EE_Error |
|
| 3095 | - */ |
|
| 3096 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 3097 | - { |
|
| 3098 | - |
|
| 3099 | - // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 3100 | - // just don't generate any templates. |
|
| 3101 | - if (empty($message_types)) { |
|
| 3102 | - return true; |
|
| 3103 | - } |
|
| 3104 | - |
|
| 3105 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 3106 | - } |
|
| 3107 | - |
|
| 3108 | - |
|
| 3109 | - /** |
|
| 3110 | - * [_trash_or_restore_message_template] |
|
| 3111 | - * |
|
| 3112 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 3113 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 3114 | - * an individual context (FALSE). |
|
| 3115 | - * @return void |
|
| 3116 | - * @throws EE_Error |
|
| 3117 | - * @throws InvalidArgumentException |
|
| 3118 | - * @throws InvalidDataTypeException |
|
| 3119 | - * @throws InvalidInterfaceException |
|
| 3120 | - */ |
|
| 3121 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 3122 | - { |
|
| 3123 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3124 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 3125 | - |
|
| 3126 | - $success = 1; |
|
| 3127 | - |
|
| 3128 | - // incoming GRP_IDs |
|
| 3129 | - if ($all) { |
|
| 3130 | - // Checkboxes |
|
| 3131 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3132 | - // if array has more than one element then success message should be plural. |
|
| 3133 | - // todo: what about nonce? |
|
| 3134 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3135 | - |
|
| 3136 | - // cycle through checkboxes |
|
| 3137 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3138 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3139 | - if (! $trashed_or_restored) { |
|
| 3140 | - $success = 0; |
|
| 3141 | - } |
|
| 3142 | - } |
|
| 3143 | - } else { |
|
| 3144 | - // grab single GRP_ID and handle |
|
| 3145 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3146 | - if (! empty($GRP_ID)) { |
|
| 3147 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3148 | - if (! $trashed_or_restored) { |
|
| 3149 | - $success = 0; |
|
| 3150 | - } |
|
| 3151 | - } else { |
|
| 3152 | - $success = 0; |
|
| 3153 | - } |
|
| 3154 | - } |
|
| 3155 | - } |
|
| 3156 | - |
|
| 3157 | - $action_desc = $trash |
|
| 3158 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3159 | - : esc_html__('restored', 'event_espresso'); |
|
| 3160 | - |
|
| 3161 | - $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc; |
|
| 3162 | - |
|
| 3163 | - $item_desc = $all ? _n( |
|
| 3164 | - 'Message Template Group', |
|
| 3165 | - 'Message Template Groups', |
|
| 3166 | - $success, |
|
| 3167 | - 'event_espresso' |
|
| 3168 | - ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3169 | - |
|
| 3170 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n( |
|
| 3171 | - 'template', |
|
| 3172 | - 'templates', |
|
| 3173 | - $success, |
|
| 3174 | - 'event_espresso' |
|
| 3175 | - ) : $item_desc; |
|
| 3176 | - |
|
| 3177 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3178 | - } |
|
| 3179 | - |
|
| 3180 | - |
|
| 3181 | - /** |
|
| 3182 | - * [_delete_message_template] |
|
| 3183 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3184 | - * |
|
| 3185 | - * @return void |
|
| 3186 | - * @throws EE_Error |
|
| 3187 | - * @throws InvalidArgumentException |
|
| 3188 | - * @throws InvalidDataTypeException |
|
| 3189 | - * @throws InvalidInterfaceException |
|
| 3190 | - */ |
|
| 3191 | - protected function _delete_message_template() |
|
| 3192 | - { |
|
| 3193 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3194 | - |
|
| 3195 | - // checkboxes |
|
| 3196 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3197 | - // if array has more than one element then success message should be plural |
|
| 3198 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3199 | - |
|
| 3200 | - // cycle through bulk action checkboxes |
|
| 3201 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3202 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3203 | - } |
|
| 3204 | - } else { |
|
| 3205 | - // grab single grp_id and delete |
|
| 3206 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 3207 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3208 | - } |
|
| 3209 | - |
|
| 3210 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3211 | - } |
|
| 3212 | - |
|
| 3213 | - |
|
| 3214 | - /** |
|
| 3215 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 3216 | - * |
|
| 3217 | - * @param int $GRP_ID The group being deleted |
|
| 3218 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3219 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3220 | - * @throws EE_Error |
|
| 3221 | - * @throws InvalidArgumentException |
|
| 3222 | - * @throws InvalidDataTypeException |
|
| 3223 | - * @throws InvalidInterfaceException |
|
| 3224 | - */ |
|
| 3225 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3226 | - { |
|
| 3227 | - $success = 1; |
|
| 3228 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3229 | - // first let's GET this group |
|
| 3230 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3231 | - // then delete permanently all the related Message Templates |
|
| 3232 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3233 | - |
|
| 3234 | - if ($deleted === 0) { |
|
| 3235 | - $success = 0; |
|
| 3236 | - } |
|
| 3237 | - |
|
| 3238 | - // now delete permanently this particular group |
|
| 3239 | - |
|
| 3240 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3241 | - $success = 0; |
|
| 3242 | - } |
|
| 3243 | - |
|
| 3244 | - return $success; |
|
| 3245 | - } |
|
| 3246 | - |
|
| 3247 | - |
|
| 3248 | - /** |
|
| 3249 | - * _learn_more_about_message_templates_link |
|
| 3250 | - * |
|
| 3251 | - * @access protected |
|
| 3252 | - * @return string |
|
| 3253 | - */ |
|
| 3254 | - protected function _learn_more_about_message_templates_link() |
|
| 3255 | - { |
|
| 3256 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3257 | - . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3258 | - . '</a>'; |
|
| 3259 | - } |
|
| 3260 | - |
|
| 3261 | - |
|
| 3262 | - /** |
|
| 3263 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3264 | - * ajax and other routes. |
|
| 3265 | - * |
|
| 3266 | - * @return void |
|
| 3267 | - * @throws DomainException |
|
| 3268 | - */ |
|
| 3269 | - protected function _settings() |
|
| 3270 | - { |
|
| 3271 | - |
|
| 3272 | - |
|
| 3273 | - $this->_set_m_mt_settings(); |
|
| 3274 | - |
|
| 3275 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3276 | - ? $this->_req_data['selected_messenger'] |
|
| 3277 | - : 'email'; |
|
| 3278 | - |
|
| 3279 | - // let's setup the messenger tabs |
|
| 3280 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3281 | - $this->_m_mt_settings['messenger_tabs'], |
|
| 3282 | - 'messenger_links', |
|
| 3283 | - '|', |
|
| 3284 | - $selected_messenger |
|
| 3285 | - ); |
|
| 3286 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3287 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3288 | - |
|
| 3289 | - $this->display_admin_page_with_sidebar(); |
|
| 3290 | - } |
|
| 3291 | - |
|
| 3292 | - |
|
| 3293 | - /** |
|
| 3294 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3295 | - * |
|
| 3296 | - * @access protected |
|
| 3297 | - * @return void |
|
| 3298 | - * @throws DomainException |
|
| 3299 | - */ |
|
| 3300 | - protected function _set_m_mt_settings() |
|
| 3301 | - { |
|
| 3302 | - // first if this is already set then lets get out no need to regenerate data. |
|
| 3303 | - if (! empty($this->_m_mt_settings)) { |
|
| 3304 | - return; |
|
| 3305 | - } |
|
| 3306 | - |
|
| 3307 | - // get all installed messengers and message_types |
|
| 3308 | - /** @type EE_messenger[] $messengers */ |
|
| 3309 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3310 | - /** @type EE_message_type[] $message_types */ |
|
| 3311 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3312 | - |
|
| 3313 | - |
|
| 3314 | - // assemble the array for the _tab_text_links helper |
|
| 3315 | - |
|
| 3316 | - foreach ($messengers as $messenger) { |
|
| 3317 | - $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array( |
|
| 3318 | - 'label' => ucwords($messenger->label['singular']), |
|
| 3319 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3320 | - ? 'messenger-active' |
|
| 3321 | - : '', |
|
| 3322 | - 'href' => $messenger->name, |
|
| 3323 | - 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3324 | - 'slug' => $messenger->name, |
|
| 3325 | - 'obj' => $messenger, |
|
| 3326 | - ); |
|
| 3327 | - |
|
| 3328 | - |
|
| 3329 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3330 | - |
|
| 3331 | - foreach ($message_types as $message_type) { |
|
| 3332 | - // first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3333 | - // it shouldn't show in either the inactive OR active metabox. |
|
| 3334 | - if (! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3335 | - continue; |
|
| 3336 | - } |
|
| 3337 | - |
|
| 3338 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3339 | - $messenger->name, |
|
| 3340 | - $message_type->name |
|
| 3341 | - ) |
|
| 3342 | - ? 'active' |
|
| 3343 | - : 'inactive'; |
|
| 3344 | - |
|
| 3345 | - $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array( |
|
| 3346 | - 'label' => ucwords($message_type->label['singular']), |
|
| 3347 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3348 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3349 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3350 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3351 | - 'title' => $a_or_i === 'active' |
|
| 3352 | - ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3353 | - : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3354 | - 'content' => $a_or_i === 'active' |
|
| 3355 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3356 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3357 | - 'slug' => $message_type->name, |
|
| 3358 | - 'active' => $a_or_i === 'active', |
|
| 3359 | - 'obj' => $message_type, |
|
| 3360 | - ); |
|
| 3361 | - } |
|
| 3362 | - } |
|
| 3363 | - } |
|
| 3364 | - |
|
| 3365 | - |
|
| 3366 | - /** |
|
| 3367 | - * This just prepares the content for the message type settings |
|
| 3368 | - * |
|
| 3369 | - * @param EE_message_type $message_type The message type object |
|
| 3370 | - * @param EE_messenger $messenger The messenger object |
|
| 3371 | - * @param boolean $active Whether the message type is active or not |
|
| 3372 | - * @return string html output for the content |
|
| 3373 | - * @throws DomainException |
|
| 3374 | - */ |
|
| 3375 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3376 | - { |
|
| 3377 | - // get message type fields |
|
| 3378 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 3379 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3380 | - |
|
| 3381 | - if (! empty($fields) && $active) { |
|
| 3382 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3383 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3384 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3385 | - $template_form_field[ $field_id ] = array( |
|
| 3386 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3387 | - 'label' => $fldprops['label'], |
|
| 3388 | - 'input' => $fldprops['field_type'], |
|
| 3389 | - 'type' => $fldprops['value_type'], |
|
| 3390 | - 'required' => $fldprops['required'], |
|
| 3391 | - 'validation' => $fldprops['validation'], |
|
| 3392 | - 'value' => isset($existing_settings[ $fldname ]) |
|
| 3393 | - ? $existing_settings[ $fldname ] |
|
| 3394 | - : $fldprops['default'], |
|
| 3395 | - 'options' => isset($fldprops['options']) |
|
| 3396 | - ? $fldprops['options'] |
|
| 3397 | - : array(), |
|
| 3398 | - 'default' => isset($existing_settings[ $fldname ]) |
|
| 3399 | - ? $existing_settings[ $fldname ] |
|
| 3400 | - : $fldprops['default'], |
|
| 3401 | - 'css_class' => 'no-drag', |
|
| 3402 | - 'format' => $fldprops['format'], |
|
| 3403 | - ); |
|
| 3404 | - } |
|
| 3405 | - |
|
| 3406 | - |
|
| 3407 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3408 | - ? $this->_generate_admin_form_fields( |
|
| 3409 | - $template_form_field, |
|
| 3410 | - 'string', |
|
| 3411 | - 'ee_mt_activate_form' |
|
| 3412 | - ) |
|
| 3413 | - : ''; |
|
| 3414 | - } |
|
| 3415 | - |
|
| 3416 | - $settings_template_args['description'] = $message_type->description; |
|
| 3417 | - // we also need some hidden fields |
|
| 3418 | - $settings_template_args['hidden_fields'] = array( |
|
| 3419 | - 'message_type_settings[messenger]' => array( |
|
| 3420 | - 'type' => 'hidden', |
|
| 3421 | - 'value' => $messenger->name, |
|
| 3422 | - ), |
|
| 3423 | - 'message_type_settings[message_type]' => array( |
|
| 3424 | - 'type' => 'hidden', |
|
| 3425 | - 'value' => $message_type->name, |
|
| 3426 | - ), |
|
| 3427 | - 'type' => array( |
|
| 3428 | - 'type' => 'hidden', |
|
| 3429 | - 'value' => 'message_type', |
|
| 3430 | - ), |
|
| 3431 | - ); |
|
| 3432 | - |
|
| 3433 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3434 | - $settings_template_args['hidden_fields'], |
|
| 3435 | - 'array' |
|
| 3436 | - ); |
|
| 3437 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3438 | - ? ' hidden' |
|
| 3439 | - : ''; |
|
| 3440 | - |
|
| 3441 | - |
|
| 3442 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3443 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3444 | - |
|
| 3445 | - return $content; |
|
| 3446 | - } |
|
| 3447 | - |
|
| 3448 | - |
|
| 3449 | - /** |
|
| 3450 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3451 | - * |
|
| 3452 | - * @access protected |
|
| 3453 | - * @return void |
|
| 3454 | - * @throws DomainException |
|
| 3455 | - */ |
|
| 3456 | - protected function _messages_settings_metaboxes() |
|
| 3457 | - { |
|
| 3458 | - $this->_set_m_mt_settings(); |
|
| 3459 | - $m_boxes = $mt_boxes = array(); |
|
| 3460 | - $m_template_args = $mt_template_args = array(); |
|
| 3461 | - |
|
| 3462 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3463 | - ? $this->_req_data['selected_messenger'] |
|
| 3464 | - : 'email'; |
|
| 3465 | - |
|
| 3466 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3467 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3468 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3469 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3470 | - // messenger meta boxes |
|
| 3471 | - $active = $selected_messenger === $messenger; |
|
| 3472 | - $active_mt_tabs = isset( |
|
| 3473 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] |
|
| 3474 | - ) |
|
| 3475 | - ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] |
|
| 3476 | - : ''; |
|
| 3477 | - $m_boxes[ $messenger . '_a_box' ] = sprintf( |
|
| 3478 | - esc_html__('%s Settings', 'event_espresso'), |
|
| 3479 | - $tab_array['label'] |
|
| 3480 | - ); |
|
| 3481 | - $m_template_args[ $messenger . '_a_box' ] = array( |
|
| 3482 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3483 | - 'inactive_message_types' => isset( |
|
| 3484 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] |
|
| 3485 | - ) |
|
| 3486 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) |
|
| 3487 | - : '', |
|
| 3488 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3489 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3490 | - 'hide_on_message' => $hide_on_message, |
|
| 3491 | - 'messenger' => $messenger, |
|
| 3492 | - 'active' => $active, |
|
| 3493 | - ); |
|
| 3494 | - // message type meta boxes |
|
| 3495 | - // (which is really just the inactive container for each messenger |
|
| 3496 | - // showing inactive message types for that messenger) |
|
| 3497 | - $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3498 | - $mt_template_args[ $messenger . '_i_box' ] = array( |
|
| 3499 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3500 | - 'inactive_message_types' => isset( |
|
| 3501 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] |
|
| 3502 | - ) |
|
| 3503 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) |
|
| 3504 | - : '', |
|
| 3505 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3506 | - 'hide_on_message' => $hide_on_message, |
|
| 3507 | - 'hide_off_message' => $hide_off_message, |
|
| 3508 | - 'messenger' => $messenger, |
|
| 3509 | - 'active' => $active, |
|
| 3510 | - ); |
|
| 3511 | - } |
|
| 3512 | - } |
|
| 3513 | - |
|
| 3514 | - |
|
| 3515 | - // register messenger metaboxes |
|
| 3516 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3517 | - foreach ($m_boxes as $box => $label) { |
|
| 3518 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]); |
|
| 3519 | - $msgr = str_replace('_a_box', '', $box); |
|
| 3520 | - add_meta_box( |
|
| 3521 | - 'espresso_' . $msgr . '_settings', |
|
| 3522 | - $label, |
|
| 3523 | - function ($post, $metabox) { |
|
| 3524 | - echo EEH_Template::display_template( |
|
| 3525 | - $metabox["args"]["template_path"], |
|
| 3526 | - $metabox["args"]["template_args"], |
|
| 3527 | - true |
|
| 3528 | - ); |
|
| 3529 | - }, |
|
| 3530 | - $this->_current_screen->id, |
|
| 3531 | - 'normal', |
|
| 3532 | - 'high', |
|
| 3533 | - $callback_args |
|
| 3534 | - ); |
|
| 3535 | - } |
|
| 3536 | - |
|
| 3537 | - // register message type metaboxes |
|
| 3538 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3539 | - foreach ($mt_boxes as $box => $label) { |
|
| 3540 | - $callback_args = array( |
|
| 3541 | - 'template_path' => $mt_template_path, |
|
| 3542 | - 'template_args' => $mt_template_args[ $box ], |
|
| 3543 | - ); |
|
| 3544 | - $mt = str_replace('_i_box', '', $box); |
|
| 3545 | - add_meta_box( |
|
| 3546 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3547 | - $label, |
|
| 3548 | - function ($post, $metabox) { |
|
| 3549 | - echo EEH_Template::display_template( |
|
| 3550 | - $metabox["args"]["template_path"], |
|
| 3551 | - $metabox["args"]["template_args"], |
|
| 3552 | - true |
|
| 3553 | - ); |
|
| 3554 | - }, |
|
| 3555 | - $this->_current_screen->id, |
|
| 3556 | - 'side', |
|
| 3557 | - 'high', |
|
| 3558 | - $callback_args |
|
| 3559 | - ); |
|
| 3560 | - } |
|
| 3561 | - |
|
| 3562 | - // register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3563 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3564 | - if (is_main_site()) { |
|
| 3565 | - add_meta_box( |
|
| 3566 | - 'espresso_global_message_settings', |
|
| 3567 | - esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3568 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 3569 | - $this->_current_screen->id, |
|
| 3570 | - 'normal', |
|
| 3571 | - 'low', |
|
| 3572 | - array() |
|
| 3573 | - ); |
|
| 3574 | - } |
|
| 3575 | - } |
|
| 3576 | - |
|
| 3577 | - |
|
| 3578 | - /** |
|
| 3579 | - * This generates the content for the global messages settings metabox. |
|
| 3580 | - * |
|
| 3581 | - * @return string |
|
| 3582 | - * @throws EE_Error |
|
| 3583 | - * @throws InvalidArgumentException |
|
| 3584 | - * @throws ReflectionException |
|
| 3585 | - * @throws InvalidDataTypeException |
|
| 3586 | - * @throws InvalidInterfaceException |
|
| 3587 | - */ |
|
| 3588 | - public function global_messages_settings_metabox_content() |
|
| 3589 | - { |
|
| 3590 | - $form = $this->_generate_global_settings_form(); |
|
| 3591 | - echo $form->form_open( |
|
| 3592 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3593 | - 'POST' |
|
| 3594 | - ) |
|
| 3595 | - . $form->get_html() |
|
| 3596 | - . $form->form_close(); |
|
| 3597 | - } |
|
| 3598 | - |
|
| 3599 | - |
|
| 3600 | - /** |
|
| 3601 | - * This generates and returns the form object for the global messages settings. |
|
| 3602 | - * |
|
| 3603 | - * @return EE_Form_Section_Proper |
|
| 3604 | - * @throws EE_Error |
|
| 3605 | - * @throws InvalidArgumentException |
|
| 3606 | - * @throws ReflectionException |
|
| 3607 | - * @throws InvalidDataTypeException |
|
| 3608 | - * @throws InvalidInterfaceException |
|
| 3609 | - */ |
|
| 3610 | - protected function _generate_global_settings_form() |
|
| 3611 | - { |
|
| 3612 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3613 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3614 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3615 | - |
|
| 3616 | - return new EE_Form_Section_Proper( |
|
| 3617 | - array( |
|
| 3618 | - 'name' => 'global_messages_settings', |
|
| 3619 | - 'html_id' => 'global_messages_settings', |
|
| 3620 | - 'html_class' => 'form-table', |
|
| 3621 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3622 | - 'subsections' => apply_filters( |
|
| 3623 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3624 | - array( |
|
| 3625 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3626 | - array( |
|
| 3627 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3628 | - false => esc_html__("On a separate request", "event_espresso"), |
|
| 3629 | - ), |
|
| 3630 | - array( |
|
| 3631 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3632 | - 'html_label_text' => esc_html__( |
|
| 3633 | - 'Generate and send all messages:', |
|
| 3634 | - 'event_espresso' |
|
| 3635 | - ), |
|
| 3636 | - 'html_help_text' => esc_html__( |
|
| 3637 | - 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3638 | - 'event_espresso' |
|
| 3639 | - ), |
|
| 3640 | - ) |
|
| 3641 | - ), |
|
| 3642 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3643 | - array( |
|
| 3644 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3645 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3646 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3647 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3648 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3649 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3650 | - 36 => esc_html__('36 Months', 'event_espresso'), |
|
| 3651 | - ), |
|
| 3652 | - array( |
|
| 3653 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3654 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3655 | - 'html_help_text' => esc_html__( |
|
| 3656 | - 'You can control how long a record of processed messages is kept via this option.', |
|
| 3657 | - 'event_espresso' |
|
| 3658 | - ), |
|
| 3659 | - ) |
|
| 3660 | - ), |
|
| 3661 | - 'update_settings' => new EE_Submit_Input( |
|
| 3662 | - array( |
|
| 3663 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3664 | - 'html_label_text' => ' ', |
|
| 3665 | - ) |
|
| 3666 | - ), |
|
| 3667 | - ) |
|
| 3668 | - ), |
|
| 3669 | - ) |
|
| 3670 | - ); |
|
| 3671 | - } |
|
| 3672 | - |
|
| 3673 | - |
|
| 3674 | - /** |
|
| 3675 | - * This handles updating the global settings set on the admin page. |
|
| 3676 | - * |
|
| 3677 | - * @throws EE_Error |
|
| 3678 | - * @throws InvalidDataTypeException |
|
| 3679 | - * @throws InvalidInterfaceException |
|
| 3680 | - * @throws InvalidArgumentException |
|
| 3681 | - * @throws ReflectionException |
|
| 3682 | - */ |
|
| 3683 | - protected function _update_global_settings() |
|
| 3684 | - { |
|
| 3685 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3686 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3687 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3688 | - $form = $this->_generate_global_settings_form(); |
|
| 3689 | - if ($form->was_submitted()) { |
|
| 3690 | - $form->receive_form_submission(); |
|
| 3691 | - if ($form->is_valid()) { |
|
| 3692 | - $valid_data = $form->valid_data(); |
|
| 3693 | - foreach ($valid_data as $property => $value) { |
|
| 3694 | - $setter = 'set_' . $property; |
|
| 3695 | - if (method_exists($network_config, $setter)) { |
|
| 3696 | - $network_config->{$setter}($value); |
|
| 3697 | - } elseif ( |
|
| 3698 | - property_exists($network_config, $property) |
|
| 3699 | - && $network_config->{$property} !== $value |
|
| 3700 | - ) { |
|
| 3701 | - $network_config->{$property} = $value; |
|
| 3702 | - } elseif ( |
|
| 3703 | - property_exists($messages_config, $property) |
|
| 3704 | - && $messages_config->{$property} !== $value |
|
| 3705 | - ) { |
|
| 3706 | - $messages_config->{$property} = $value; |
|
| 3707 | - } |
|
| 3708 | - } |
|
| 3709 | - // only update if the form submission was valid! |
|
| 3710 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3711 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3712 | - EE_Error::overwrite_success(); |
|
| 3713 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3714 | - } |
|
| 3715 | - } |
|
| 3716 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3717 | - } |
|
| 3718 | - |
|
| 3719 | - |
|
| 3720 | - /** |
|
| 3721 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3722 | - * |
|
| 3723 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3724 | - * @return string html formatted tabs |
|
| 3725 | - * @throws DomainException |
|
| 3726 | - */ |
|
| 3727 | - protected function _get_mt_tabs($tab_array) |
|
| 3728 | - { |
|
| 3729 | - $tab_array = (array) $tab_array; |
|
| 3730 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3731 | - $tabs = ''; |
|
| 3732 | - |
|
| 3733 | - foreach ($tab_array as $tab) { |
|
| 3734 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3735 | - } |
|
| 3736 | - |
|
| 3737 | - return $tabs; |
|
| 3738 | - } |
|
| 3739 | - |
|
| 3740 | - |
|
| 3741 | - /** |
|
| 3742 | - * This prepares the content of the messenger meta box admin settings |
|
| 3743 | - * |
|
| 3744 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3745 | - * @return string html formatted content |
|
| 3746 | - * @throws DomainException |
|
| 3747 | - */ |
|
| 3748 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3749 | - { |
|
| 3750 | - |
|
| 3751 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3752 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3753 | - |
|
| 3754 | - // is $messenger active? |
|
| 3755 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3756 | - |
|
| 3757 | - |
|
| 3758 | - if (! empty($fields)) { |
|
| 3759 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3760 | - |
|
| 3761 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3762 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3763 | - $template_form_field[ $field_id ] = array( |
|
| 3764 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3765 | - 'label' => $fldprops['label'], |
|
| 3766 | - 'input' => $fldprops['field_type'], |
|
| 3767 | - 'type' => $fldprops['value_type'], |
|
| 3768 | - 'required' => $fldprops['required'], |
|
| 3769 | - 'validation' => $fldprops['validation'], |
|
| 3770 | - 'value' => isset($existing_settings[ $field_id ]) |
|
| 3771 | - ? $existing_settings[ $field_id ] |
|
| 3772 | - : $fldprops['default'], |
|
| 3773 | - 'css_class' => '', |
|
| 3774 | - 'format' => $fldprops['format'], |
|
| 3775 | - ); |
|
| 3776 | - } |
|
| 3777 | - |
|
| 3778 | - |
|
| 3779 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3780 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3781 | - : ''; |
|
| 3782 | - } |
|
| 3783 | - |
|
| 3784 | - // we also need some hidden fields |
|
| 3785 | - $settings_template_args['hidden_fields'] = array( |
|
| 3786 | - 'messenger_settings[messenger]' => array( |
|
| 3787 | - 'type' => 'hidden', |
|
| 3788 | - 'value' => $messenger->name, |
|
| 3789 | - ), |
|
| 3790 | - 'type' => array( |
|
| 3791 | - 'type' => 'hidden', |
|
| 3792 | - 'value' => 'messenger', |
|
| 3793 | - ), |
|
| 3794 | - ); |
|
| 3795 | - |
|
| 3796 | - // make sure any active message types that are existing are included in the hidden fields |
|
| 3797 | - if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { |
|
| 3798 | - foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { |
|
| 3799 | - $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array( |
|
| 3800 | - 'type' => 'hidden', |
|
| 3801 | - 'value' => $mt, |
|
| 3802 | - ); |
|
| 3803 | - } |
|
| 3804 | - } |
|
| 3805 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3806 | - $settings_template_args['hidden_fields'], |
|
| 3807 | - 'array' |
|
| 3808 | - ); |
|
| 3809 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3810 | - |
|
| 3811 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3812 | - $settings_template_args['description'] = $messenger->description; |
|
| 3813 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3814 | - |
|
| 3815 | - |
|
| 3816 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3817 | - $messenger->name |
|
| 3818 | - ) |
|
| 3819 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3820 | - : ' hidden'; |
|
| 3821 | - |
|
| 3822 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3823 | - ? ' hidden' |
|
| 3824 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3825 | - |
|
| 3826 | - |
|
| 3827 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3828 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3829 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3830 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3831 | - $content = EEH_Template::display_template( |
|
| 3832 | - $template, |
|
| 3833 | - $settings_template_args, |
|
| 3834 | - true |
|
| 3835 | - ); |
|
| 3836 | - |
|
| 3837 | - return $content; |
|
| 3838 | - } |
|
| 3839 | - |
|
| 3840 | - |
|
| 3841 | - /** |
|
| 3842 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3843 | - * |
|
| 3844 | - * @throws DomainException |
|
| 3845 | - * @throws EE_Error |
|
| 3846 | - * @throws InvalidDataTypeException |
|
| 3847 | - * @throws InvalidInterfaceException |
|
| 3848 | - * @throws InvalidArgumentException |
|
| 3849 | - * @throws ReflectionException |
|
| 3850 | - */ |
|
| 3851 | - public function activate_messenger_toggle() |
|
| 3852 | - { |
|
| 3853 | - $success = true; |
|
| 3854 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3855 | - // let's check that we have required data |
|
| 3856 | - if (! isset($this->_req_data['messenger'])) { |
|
| 3857 | - EE_Error::add_error( |
|
| 3858 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3859 | - __FILE__, |
|
| 3860 | - __FUNCTION__, |
|
| 3861 | - __LINE__ |
|
| 3862 | - ); |
|
| 3863 | - $success = false; |
|
| 3864 | - } |
|
| 3865 | - |
|
| 3866 | - // do a nonce check here since we're not arriving via a normal route |
|
| 3867 | - $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3868 | - ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3869 | - : ''; |
|
| 3870 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3871 | - |
|
| 3872 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3873 | - |
|
| 3874 | - |
|
| 3875 | - if (! isset($this->_req_data['status'])) { |
|
| 3876 | - EE_Error::add_error( |
|
| 3877 | - esc_html__( |
|
| 3878 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3879 | - 'event_espresso' |
|
| 3880 | - ), |
|
| 3881 | - __FILE__, |
|
| 3882 | - __FUNCTION__, |
|
| 3883 | - __LINE__ |
|
| 3884 | - ); |
|
| 3885 | - $success = false; |
|
| 3886 | - } |
|
| 3887 | - |
|
| 3888 | - // do check to verify we have a valid status. |
|
| 3889 | - $status = $this->_req_data['status']; |
|
| 3890 | - |
|
| 3891 | - if ($status !== 'off' && $status !== 'on') { |
|
| 3892 | - EE_Error::add_error( |
|
| 3893 | - sprintf( |
|
| 3894 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3895 | - $this->_req_data['status'] |
|
| 3896 | - ), |
|
| 3897 | - __FILE__, |
|
| 3898 | - __FUNCTION__, |
|
| 3899 | - __LINE__ |
|
| 3900 | - ); |
|
| 3901 | - $success = false; |
|
| 3902 | - } |
|
| 3903 | - |
|
| 3904 | - if ($success) { |
|
| 3905 | - // made it here? Stop dawdling then!! |
|
| 3906 | - $success = $status === 'off' |
|
| 3907 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3908 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3909 | - } |
|
| 3910 | - |
|
| 3911 | - $this->_template_args['success'] = $success; |
|
| 3912 | - |
|
| 3913 | - // no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3914 | - $this->_return_json(); |
|
| 3915 | - } |
|
| 3916 | - |
|
| 3917 | - |
|
| 3918 | - /** |
|
| 3919 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3920 | - * |
|
| 3921 | - * @throws DomainException |
|
| 3922 | - * @throws EE_Error |
|
| 3923 | - * @throws ReflectionException |
|
| 3924 | - * @throws InvalidDataTypeException |
|
| 3925 | - * @throws InvalidInterfaceException |
|
| 3926 | - * @throws InvalidArgumentException |
|
| 3927 | - */ |
|
| 3928 | - public function activate_mt_toggle() |
|
| 3929 | - { |
|
| 3930 | - $success = true; |
|
| 3931 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3932 | - |
|
| 3933 | - // let's make sure we have the necessary data |
|
| 3934 | - if (! isset($this->_req_data['message_type'])) { |
|
| 3935 | - EE_Error::add_error( |
|
| 3936 | - esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3937 | - __FILE__, |
|
| 3938 | - __FUNCTION__, |
|
| 3939 | - __LINE__ |
|
| 3940 | - ); |
|
| 3941 | - $success = false; |
|
| 3942 | - } |
|
| 3943 | - |
|
| 3944 | - if (! isset($this->_req_data['messenger'])) { |
|
| 3945 | - EE_Error::add_error( |
|
| 3946 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3947 | - __FILE__, |
|
| 3948 | - __FUNCTION__, |
|
| 3949 | - __LINE__ |
|
| 3950 | - ); |
|
| 3951 | - $success = false; |
|
| 3952 | - } |
|
| 3953 | - |
|
| 3954 | - if (! isset($this->_req_data['status'])) { |
|
| 3955 | - EE_Error::add_error( |
|
| 3956 | - esc_html__( |
|
| 3957 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3958 | - 'event_espresso' |
|
| 3959 | - ), |
|
| 3960 | - __FILE__, |
|
| 3961 | - __FUNCTION__, |
|
| 3962 | - __LINE__ |
|
| 3963 | - ); |
|
| 3964 | - $success = false; |
|
| 3965 | - } |
|
| 3966 | - |
|
| 3967 | - |
|
| 3968 | - // do check to verify we have a valid status. |
|
| 3969 | - $status = $this->_req_data['status']; |
|
| 3970 | - |
|
| 3971 | - if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3972 | - EE_Error::add_error( |
|
| 3973 | - sprintf( |
|
| 3974 | - esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3975 | - $this->_req_data['status'] |
|
| 3976 | - ), |
|
| 3977 | - __FILE__, |
|
| 3978 | - __FUNCTION__, |
|
| 3979 | - __LINE__ |
|
| 3980 | - ); |
|
| 3981 | - $success = false; |
|
| 3982 | - } |
|
| 3983 | - |
|
| 3984 | - |
|
| 3985 | - // do a nonce check here since we're not arriving via a normal route |
|
| 3986 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3987 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3988 | - |
|
| 3989 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3990 | - |
|
| 3991 | - if ($success) { |
|
| 3992 | - // made it here? um, what are you waiting for then? |
|
| 3993 | - $success = $status === 'deactivate' |
|
| 3994 | - ? $this->_deactivate_message_type_for_messenger( |
|
| 3995 | - $this->_req_data['messenger'], |
|
| 3996 | - $this->_req_data['message_type'] |
|
| 3997 | - ) |
|
| 3998 | - : $this->_activate_message_type_for_messenger( |
|
| 3999 | - $this->_req_data['messenger'], |
|
| 4000 | - $this->_req_data['message_type'] |
|
| 4001 | - ); |
|
| 4002 | - } |
|
| 4003 | - |
|
| 4004 | - $this->_template_args['success'] = $success; |
|
| 4005 | - $this->_return_json(); |
|
| 4006 | - } |
|
| 4007 | - |
|
| 4008 | - |
|
| 4009 | - /** |
|
| 4010 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 4011 | - * |
|
| 4012 | - * @param string $messenger_name The name of the messenger being activated |
|
| 4013 | - * @return bool |
|
| 4014 | - * @throws DomainException |
|
| 4015 | - * @throws EE_Error |
|
| 4016 | - * @throws InvalidArgumentException |
|
| 4017 | - * @throws ReflectionException |
|
| 4018 | - * @throws InvalidDataTypeException |
|
| 4019 | - * @throws InvalidInterfaceException |
|
| 4020 | - */ |
|
| 4021 | - protected function _activate_messenger($messenger_name) |
|
| 4022 | - { |
|
| 4023 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4024 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4025 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 4026 | - ? $active_messenger->get_default_message_types() |
|
| 4027 | - : array(); |
|
| 4028 | - |
|
| 4029 | - // ensure is active |
|
| 4030 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 4031 | - |
|
| 4032 | - // set response_data for reload |
|
| 4033 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 4034 | - /** @var EE_message_type $message_type */ |
|
| 4035 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4036 | - if ( |
|
| 4037 | - $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 4038 | - $messenger_name, |
|
| 4039 | - $message_type_name |
|
| 4040 | - ) |
|
| 4041 | - && $message_type instanceof EE_message_type |
|
| 4042 | - ) { |
|
| 4043 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 4044 | - if ($message_type->get_admin_settings_fields()) { |
|
| 4045 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 4046 | - } |
|
| 4047 | - } |
|
| 4048 | - } |
|
| 4049 | - |
|
| 4050 | - // add success message for activating messenger |
|
| 4051 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 4052 | - } |
|
| 4053 | - |
|
| 4054 | - |
|
| 4055 | - /** |
|
| 4056 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 4057 | - * |
|
| 4058 | - * @param string $messenger_name The name of the messenger being activated |
|
| 4059 | - * @return bool |
|
| 4060 | - * @throws DomainException |
|
| 4061 | - * @throws EE_Error |
|
| 4062 | - * @throws InvalidArgumentException |
|
| 4063 | - * @throws ReflectionException |
|
| 4064 | - * @throws InvalidDataTypeException |
|
| 4065 | - * @throws InvalidInterfaceException |
|
| 4066 | - */ |
|
| 4067 | - protected function _deactivate_messenger($messenger_name) |
|
| 4068 | - { |
|
| 4069 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4070 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4071 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 4072 | - |
|
| 4073 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 4074 | - } |
|
| 4075 | - |
|
| 4076 | - |
|
| 4077 | - /** |
|
| 4078 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 4079 | - * |
|
| 4080 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 4081 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 4082 | - * @return bool |
|
| 4083 | - * @throws DomainException |
|
| 4084 | - * @throws EE_Error |
|
| 4085 | - * @throws InvalidArgumentException |
|
| 4086 | - * @throws ReflectionException |
|
| 4087 | - * @throws InvalidDataTypeException |
|
| 4088 | - * @throws InvalidInterfaceException |
|
| 4089 | - */ |
|
| 4090 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4091 | - { |
|
| 4092 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4093 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4094 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4095 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4096 | - |
|
| 4097 | - // ensure is active |
|
| 4098 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 4099 | - |
|
| 4100 | - // set response for load |
|
| 4101 | - if ( |
|
| 4102 | - $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 4103 | - $messenger_name, |
|
| 4104 | - $message_type_name |
|
| 4105 | - ) |
|
| 4106 | - ) { |
|
| 4107 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 4108 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 4109 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 4110 | - } |
|
| 4111 | - } |
|
| 4112 | - |
|
| 4113 | - return $this->_setup_response_message_for_activating_messenger_with_message_types( |
|
| 4114 | - $active_messenger, |
|
| 4115 | - $message_type_to_activate |
|
| 4116 | - ); |
|
| 4117 | - } |
|
| 4118 | - |
|
| 4119 | - |
|
| 4120 | - /** |
|
| 4121 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 4122 | - * |
|
| 4123 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 4124 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 4125 | - * @return bool |
|
| 4126 | - * @throws DomainException |
|
| 4127 | - * @throws EE_Error |
|
| 4128 | - * @throws InvalidArgumentException |
|
| 4129 | - * @throws ReflectionException |
|
| 4130 | - * @throws InvalidDataTypeException |
|
| 4131 | - * @throws InvalidInterfaceException |
|
| 4132 | - */ |
|
| 4133 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4134 | - { |
|
| 4135 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4136 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4137 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4138 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4139 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 4140 | - |
|
| 4141 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4142 | - $active_messenger, |
|
| 4143 | - $message_type_to_deactivate |
|
| 4144 | - ); |
|
| 4145 | - } |
|
| 4146 | - |
|
| 4147 | - |
|
| 4148 | - /** |
|
| 4149 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 4150 | - */ |
|
| 4151 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4152 | - { |
|
| 4153 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 4154 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 4155 | - } |
|
| 4156 | - |
|
| 4157 | - |
|
| 4158 | - /** |
|
| 4159 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 4160 | - * |
|
| 4161 | - * @param EE_messenger $messenger |
|
| 4162 | - * @param EE_message_type|null $message_type |
|
| 4163 | - * @return bool |
|
| 4164 | - * @throws DomainException |
|
| 4165 | - * @throws EE_Error |
|
| 4166 | - * @throws InvalidArgumentException |
|
| 4167 | - * @throws ReflectionException |
|
| 4168 | - * @throws InvalidDataTypeException |
|
| 4169 | - * @throws InvalidInterfaceException |
|
| 4170 | - */ |
|
| 4171 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4172 | - $messenger, |
|
| 4173 | - EE_Message_Type $message_type = null |
|
| 4174 | - ) { |
|
| 4175 | - // if $messenger isn't a valid messenger object then get out. |
|
| 4176 | - if (! $messenger instanceof EE_Messenger) { |
|
| 4177 | - EE_Error::add_error( |
|
| 4178 | - esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4179 | - __FILE__, |
|
| 4180 | - __FUNCTION__, |
|
| 4181 | - __LINE__ |
|
| 4182 | - ); |
|
| 4183 | - |
|
| 4184 | - return false; |
|
| 4185 | - } |
|
| 4186 | - // activated |
|
| 4187 | - if ($this->_template_args['data']['active_mts']) { |
|
| 4188 | - EE_Error::overwrite_success(); |
|
| 4189 | - // activated a message type with the messenger |
|
| 4190 | - if ($message_type instanceof EE_message_type) { |
|
| 4191 | - EE_Error::add_success( |
|
| 4192 | - sprintf( |
|
| 4193 | - esc_html__( |
|
| 4194 | - '%s message type has been successfully activated with the %s messenger', |
|
| 4195 | - 'event_espresso' |
|
| 4196 | - ), |
|
| 4197 | - ucwords($message_type->label['singular']), |
|
| 4198 | - ucwords($messenger->label['singular']) |
|
| 4199 | - ) |
|
| 4200 | - ); |
|
| 4201 | - |
|
| 4202 | - // if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4203 | - if ($message_type->name === 'invoice') { |
|
| 4204 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4205 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4206 | - if ($pm instanceof EE_Payment_Method) { |
|
| 4207 | - EE_Error::add_attention( |
|
| 4208 | - esc_html__( |
|
| 4209 | - 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4210 | - 'event_espresso' |
|
| 4211 | - ) |
|
| 4212 | - ); |
|
| 4213 | - } |
|
| 4214 | - } |
|
| 4215 | - // just toggles the entire messenger |
|
| 4216 | - } else { |
|
| 4217 | - EE_Error::add_success( |
|
| 4218 | - sprintf( |
|
| 4219 | - esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4220 | - ucwords($messenger->label['singular']) |
|
| 4221 | - ) |
|
| 4222 | - ); |
|
| 4223 | - } |
|
| 4224 | - |
|
| 4225 | - return true; |
|
| 4226 | - |
|
| 4227 | - // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4228 | - // message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4229 | - // in which case we just give a success message for the messenger being successfully activated. |
|
| 4230 | - } else { |
|
| 4231 | - if (! $messenger->get_default_message_types()) { |
|
| 4232 | - // messenger doesn't have any default message types so still a success. |
|
| 4233 | - EE_Error::add_success( |
|
| 4234 | - sprintf( |
|
| 4235 | - esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4236 | - ucwords($messenger->label['singular']) |
|
| 4237 | - ) |
|
| 4238 | - ); |
|
| 4239 | - |
|
| 4240 | - return true; |
|
| 4241 | - } else { |
|
| 4242 | - EE_Error::add_error( |
|
| 4243 | - $message_type instanceof EE_message_type |
|
| 4244 | - ? sprintf( |
|
| 4245 | - esc_html__( |
|
| 4246 | - '%s message type was not successfully activated with the %s messenger', |
|
| 4247 | - 'event_espresso' |
|
| 4248 | - ), |
|
| 4249 | - ucwords($message_type->label['singular']), |
|
| 4250 | - ucwords($messenger->label['singular']) |
|
| 4251 | - ) |
|
| 4252 | - : sprintf( |
|
| 4253 | - esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4254 | - ucwords($messenger->label['singular']) |
|
| 4255 | - ), |
|
| 4256 | - __FILE__, |
|
| 4257 | - __FUNCTION__, |
|
| 4258 | - __LINE__ |
|
| 4259 | - ); |
|
| 4260 | - |
|
| 4261 | - return false; |
|
| 4262 | - } |
|
| 4263 | - } |
|
| 4264 | - } |
|
| 4265 | - |
|
| 4266 | - |
|
| 4267 | - /** |
|
| 4268 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4269 | - * |
|
| 4270 | - * @param EE_messenger $messenger |
|
| 4271 | - * @param EE_message_type|null $message_type |
|
| 4272 | - * @return bool |
|
| 4273 | - * @throws DomainException |
|
| 4274 | - * @throws EE_Error |
|
| 4275 | - * @throws InvalidArgumentException |
|
| 4276 | - * @throws ReflectionException |
|
| 4277 | - * @throws InvalidDataTypeException |
|
| 4278 | - * @throws InvalidInterfaceException |
|
| 4279 | - */ |
|
| 4280 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4281 | - $messenger, |
|
| 4282 | - EE_message_type $message_type = null |
|
| 4283 | - ) { |
|
| 4284 | - EE_Error::overwrite_success(); |
|
| 4285 | - |
|
| 4286 | - // if $messenger isn't a valid messenger object then get out. |
|
| 4287 | - if (! $messenger instanceof EE_Messenger) { |
|
| 4288 | - EE_Error::add_error( |
|
| 4289 | - esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4290 | - __FILE__, |
|
| 4291 | - __FUNCTION__, |
|
| 4292 | - __LINE__ |
|
| 4293 | - ); |
|
| 4294 | - |
|
| 4295 | - return false; |
|
| 4296 | - } |
|
| 4297 | - |
|
| 4298 | - if ($message_type instanceof EE_message_type) { |
|
| 4299 | - $message_type_name = $message_type->name; |
|
| 4300 | - EE_Error::add_success( |
|
| 4301 | - sprintf( |
|
| 4302 | - esc_html__( |
|
| 4303 | - '%s message type has been successfully deactivated for the %s messenger.', |
|
| 4304 | - 'event_espresso' |
|
| 4305 | - ), |
|
| 4306 | - ucwords($message_type->label['singular']), |
|
| 4307 | - ucwords($messenger->label['singular']) |
|
| 4308 | - ) |
|
| 4309 | - ); |
|
| 4310 | - } else { |
|
| 4311 | - $message_type_name = ''; |
|
| 4312 | - EE_Error::add_success( |
|
| 4313 | - sprintf( |
|
| 4314 | - esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4315 | - ucwords($messenger->label['singular']) |
|
| 4316 | - ) |
|
| 4317 | - ); |
|
| 4318 | - } |
|
| 4319 | - |
|
| 4320 | - // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4321 | - if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4322 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4323 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4324 | - if ($count_updated > 0) { |
|
| 4325 | - $msg = $message_type_name === 'invoice' |
|
| 4326 | - ? esc_html__( |
|
| 4327 | - 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4328 | - 'event_espresso' |
|
| 4329 | - ) |
|
| 4330 | - : esc_html__( |
|
| 4331 | - 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4332 | - 'event_espresso' |
|
| 4333 | - ); |
|
| 4334 | - EE_Error::add_attention($msg); |
|
| 4335 | - } |
|
| 4336 | - } |
|
| 4337 | - |
|
| 4338 | - return true; |
|
| 4339 | - } |
|
| 4340 | - |
|
| 4341 | - |
|
| 4342 | - /** |
|
| 4343 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4344 | - * |
|
| 4345 | - * @throws DomainException |
|
| 4346 | - */ |
|
| 4347 | - public function update_mt_form() |
|
| 4348 | - { |
|
| 4349 | - if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4350 | - EE_Error::add_error( |
|
| 4351 | - esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4352 | - __FILE__, |
|
| 4353 | - __FUNCTION__, |
|
| 4354 | - __LINE__ |
|
| 4355 | - ); |
|
| 4356 | - $this->_return_json(); |
|
| 4357 | - } |
|
| 4358 | - |
|
| 4359 | - $message_types = $this->get_installed_message_types(); |
|
| 4360 | - |
|
| 4361 | - $message_type = $message_types[ $this->_req_data['message_type'] ]; |
|
| 4362 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4363 | - |
|
| 4364 | - $content = $this->_message_type_settings_content( |
|
| 4365 | - $message_type, |
|
| 4366 | - $messenger, |
|
| 4367 | - true |
|
| 4368 | - ); |
|
| 4369 | - $this->_template_args['success'] = true; |
|
| 4370 | - $this->_template_args['content'] = $content; |
|
| 4371 | - $this->_return_json(); |
|
| 4372 | - } |
|
| 4373 | - |
|
| 4374 | - |
|
| 4375 | - /** |
|
| 4376 | - * this handles saving the settings for a messenger or message type |
|
| 4377 | - * |
|
| 4378 | - */ |
|
| 4379 | - public function save_settings() |
|
| 4380 | - { |
|
| 4381 | - if (! isset($this->_req_data['type'])) { |
|
| 4382 | - EE_Error::add_error( |
|
| 4383 | - esc_html__( |
|
| 4384 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4385 | - 'event_espresso' |
|
| 4386 | - ), |
|
| 4387 | - __FILE__, |
|
| 4388 | - __FUNCTION__, |
|
| 4389 | - __LINE__ |
|
| 4390 | - ); |
|
| 4391 | - $this->_template_args['error'] = true; |
|
| 4392 | - $this->_return_json(); |
|
| 4393 | - } |
|
| 4394 | - |
|
| 4395 | - |
|
| 4396 | - if ($this->_req_data['type'] === 'messenger') { |
|
| 4397 | - // this should be an array. |
|
| 4398 | - $settings = $this->_req_data['messenger_settings']; |
|
| 4399 | - $messenger = $settings['messenger']; |
|
| 4400 | - // let's setup the settings data |
|
| 4401 | - foreach ($settings as $key => $value) { |
|
| 4402 | - switch ($key) { |
|
| 4403 | - case 'messenger': |
|
| 4404 | - unset($settings['messenger']); |
|
| 4405 | - break; |
|
| 4406 | - case 'message_types': |
|
| 4407 | - unset($settings['message_types']); |
|
| 4408 | - break; |
|
| 4409 | - default: |
|
| 4410 | - $settings[ $key ] = $value; |
|
| 4411 | - break; |
|
| 4412 | - } |
|
| 4413 | - } |
|
| 4414 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4415 | - } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4416 | - $settings = $this->_req_data['message_type_settings']; |
|
| 4417 | - $messenger = $settings['messenger']; |
|
| 4418 | - $message_type = $settings['message_type']; |
|
| 4419 | - |
|
| 4420 | - foreach ($settings as $key => $value) { |
|
| 4421 | - switch ($key) { |
|
| 4422 | - case 'messenger': |
|
| 4423 | - unset($settings['messenger']); |
|
| 4424 | - break; |
|
| 4425 | - case 'message_type': |
|
| 4426 | - unset($settings['message_type']); |
|
| 4427 | - break; |
|
| 4428 | - default: |
|
| 4429 | - $settings[ $key ] = $value; |
|
| 4430 | - break; |
|
| 4431 | - } |
|
| 4432 | - } |
|
| 4433 | - |
|
| 4434 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4435 | - } |
|
| 4436 | - |
|
| 4437 | - // okay we should have the data all setup. Now we just update! |
|
| 4438 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4439 | - |
|
| 4440 | - if ($success) { |
|
| 4441 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4442 | - } else { |
|
| 4443 | - EE_Error::add_error( |
|
| 4444 | - esc_html__( |
|
| 4445 | - 'Settings did not get updated', |
|
| 4446 | - 'event_espresso' |
|
| 4447 | - ), |
|
| 4448 | - __FILE__, |
|
| 4449 | - __FUNCTION__, |
|
| 4450 | - __LINE__ |
|
| 4451 | - ); |
|
| 4452 | - } |
|
| 4453 | - |
|
| 4454 | - $this->_template_args['success'] = $success; |
|
| 4455 | - $this->_return_json(); |
|
| 4456 | - } |
|
| 4457 | - |
|
| 4458 | - |
|
| 4459 | - |
|
| 4460 | - |
|
| 4461 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4462 | - |
|
| 4463 | - |
|
| 4464 | - /** |
|
| 4465 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4466 | - * However, this does not send immediately, it just queues for sending. |
|
| 4467 | - * |
|
| 4468 | - * @since 4.9.0 |
|
| 4469 | - * @throws EE_Error |
|
| 4470 | - * @throws InvalidDataTypeException |
|
| 4471 | - * @throws InvalidInterfaceException |
|
| 4472 | - * @throws InvalidArgumentException |
|
| 4473 | - * @throws ReflectionException |
|
| 4474 | - */ |
|
| 4475 | - protected function _generate_now() |
|
| 4476 | - { |
|
| 4477 | - EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4478 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4479 | - } |
|
| 4480 | - |
|
| 4481 | - |
|
| 4482 | - /** |
|
| 4483 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4484 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4485 | - * |
|
| 4486 | - * @since 4.9.0 |
|
| 4487 | - * @throws EE_Error |
|
| 4488 | - * @throws InvalidDataTypeException |
|
| 4489 | - * @throws InvalidInterfaceException |
|
| 4490 | - * @throws InvalidArgumentException |
|
| 4491 | - * @throws ReflectionException |
|
| 4492 | - */ |
|
| 4493 | - protected function _generate_and_send_now() |
|
| 4494 | - { |
|
| 4495 | - EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4496 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4497 | - } |
|
| 4498 | - |
|
| 4499 | - |
|
| 4500 | - /** |
|
| 4501 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4502 | - * |
|
| 4503 | - * @since 4.9.0 |
|
| 4504 | - * @throws EE_Error |
|
| 4505 | - * @throws InvalidDataTypeException |
|
| 4506 | - * @throws InvalidInterfaceException |
|
| 4507 | - * @throws InvalidArgumentException |
|
| 4508 | - * @throws ReflectionException |
|
| 4509 | - */ |
|
| 4510 | - protected function _queue_for_resending() |
|
| 4511 | - { |
|
| 4512 | - EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4513 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4514 | - } |
|
| 4515 | - |
|
| 4516 | - |
|
| 4517 | - /** |
|
| 4518 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4519 | - * |
|
| 4520 | - * @since 4.9.0 |
|
| 4521 | - * @throws EE_Error |
|
| 4522 | - * @throws InvalidDataTypeException |
|
| 4523 | - * @throws InvalidInterfaceException |
|
| 4524 | - * @throws InvalidArgumentException |
|
| 4525 | - * @throws ReflectionException |
|
| 4526 | - */ |
|
| 4527 | - protected function _send_now() |
|
| 4528 | - { |
|
| 4529 | - EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4530 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4531 | - } |
|
| 4532 | - |
|
| 4533 | - |
|
| 4534 | - /** |
|
| 4535 | - * Deletes EE_messages for IDs in the request. |
|
| 4536 | - * |
|
| 4537 | - * @since 4.9.0 |
|
| 4538 | - * @throws EE_Error |
|
| 4539 | - * @throws InvalidDataTypeException |
|
| 4540 | - * @throws InvalidInterfaceException |
|
| 4541 | - * @throws InvalidArgumentException |
|
| 4542 | - */ |
|
| 4543 | - protected function _delete_ee_messages() |
|
| 4544 | - { |
|
| 4545 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4546 | - $deleted_count = 0; |
|
| 4547 | - foreach ($msg_ids as $msg_id) { |
|
| 4548 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4549 | - $deleted_count++; |
|
| 4550 | - } |
|
| 4551 | - } |
|
| 4552 | - if ($deleted_count) { |
|
| 4553 | - EE_Error::add_success( |
|
| 4554 | - esc_html( |
|
| 4555 | - _n( |
|
| 4556 | - 'Message successfully deleted', |
|
| 4557 | - 'Messages successfully deleted', |
|
| 4558 | - $deleted_count, |
|
| 4559 | - 'event_espresso' |
|
| 4560 | - ) |
|
| 4561 | - ) |
|
| 4562 | - ); |
|
| 4563 | - $this->_redirect_after_action( |
|
| 4564 | - false, |
|
| 4565 | - '', |
|
| 4566 | - '', |
|
| 4567 | - array(), |
|
| 4568 | - true |
|
| 4569 | - ); |
|
| 4570 | - } else { |
|
| 4571 | - EE_Error::add_error( |
|
| 4572 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4573 | - __FILE__, |
|
| 4574 | - __FUNCTION__, |
|
| 4575 | - __LINE__ |
|
| 4576 | - ); |
|
| 4577 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4578 | - } |
|
| 4579 | - } |
|
| 4580 | - |
|
| 4581 | - |
|
| 4582 | - /** |
|
| 4583 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4584 | - * |
|
| 4585 | - * @since 4.9.0 |
|
| 4586 | - * @return array |
|
| 4587 | - */ |
|
| 4588 | - protected function _get_msg_ids_from_request() |
|
| 4589 | - { |
|
| 4590 | - if (! isset($this->_req_data['MSG_ID'])) { |
|
| 4591 | - return array(); |
|
| 4592 | - } |
|
| 4593 | - |
|
| 4594 | - return is_array($this->_req_data['MSG_ID']) |
|
| 4595 | - ? array_keys($this->_req_data['MSG_ID']) |
|
| 4596 | - : array($this->_req_data['MSG_ID']); |
|
| 4597 | - } |
|
| 2670 | + $output = ob_get_contents(); |
|
| 2671 | + ob_clean(); |
|
| 2672 | + $this->_context_switcher = $output; |
|
| 2673 | + } |
|
| 2674 | + |
|
| 2675 | + |
|
| 2676 | + /** |
|
| 2677 | + * utility for sanitizing new values coming in. |
|
| 2678 | + * Note: this is only used when updating a context. |
|
| 2679 | + * |
|
| 2680 | + * @access protected |
|
| 2681 | + * |
|
| 2682 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2683 | + * |
|
| 2684 | + * @return array |
|
| 2685 | + */ |
|
| 2686 | + protected function _set_message_template_column_values($index) |
|
| 2687 | + { |
|
| 2688 | + if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) { |
|
| 2689 | + foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) { |
|
| 2690 | + $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value; |
|
| 2691 | + } |
|
| 2692 | + } |
|
| 2693 | + |
|
| 2694 | + |
|
| 2695 | + $set_column_values = array( |
|
| 2696 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']), |
|
| 2697 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2698 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2699 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2700 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2701 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']), |
|
| 2702 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2703 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][ $index ]['content'], |
|
| 2704 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2705 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2706 | + : 0, |
|
| 2707 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2708 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2709 | + : 0, |
|
| 2710 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2711 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']), |
|
| 2712 | + ); |
|
| 2713 | + |
|
| 2714 | + |
|
| 2715 | + return $set_column_values; |
|
| 2716 | + } |
|
| 2717 | + |
|
| 2718 | + |
|
| 2719 | + protected function _insert_or_update_message_template($new = false) |
|
| 2720 | + { |
|
| 2721 | + |
|
| 2722 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2723 | + $success = 0; |
|
| 2724 | + $override = false; |
|
| 2725 | + |
|
| 2726 | + // setup notices description |
|
| 2727 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2728 | + |
|
| 2729 | + // need the message type and messenger objects to be able to use the labels for the notices |
|
| 2730 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2731 | + $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2732 | + ? ucwords($messenger_object->label['singular']) |
|
| 2733 | + : ''; |
|
| 2734 | + |
|
| 2735 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2736 | + ? $this->_req_data['MTP_message_type'] |
|
| 2737 | + : ''; |
|
| 2738 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2739 | + |
|
| 2740 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2741 | + ? ucwords($message_type_object->label['singular']) |
|
| 2742 | + : ''; |
|
| 2743 | + |
|
| 2744 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2745 | + ? $this->_req_data['MTP_context'] |
|
| 2746 | + : ''; |
|
| 2747 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2748 | + |
|
| 2749 | + $item_desc = $messenger_label && $message_type_label |
|
| 2750 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2751 | + : ''; |
|
| 2752 | + $item_desc .= 'Message Template'; |
|
| 2753 | + $query_args = array(); |
|
| 2754 | + $edit_array = array(); |
|
| 2755 | + $action_desc = ''; |
|
| 2756 | + |
|
| 2757 | + // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2758 | + // user to edit. |
|
| 2759 | + if ($new) { |
|
| 2760 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2761 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2762 | + if (empty($edit_array)) { |
|
| 2763 | + $success = 0; |
|
| 2764 | + } else { |
|
| 2765 | + $success = 1; |
|
| 2766 | + $edit_array = $edit_array[0]; |
|
| 2767 | + $query_args = array( |
|
| 2768 | + 'id' => $edit_array['GRP_ID'], |
|
| 2769 | + 'context' => $edit_array['MTP_context'], |
|
| 2770 | + 'action' => 'edit_message_template', |
|
| 2771 | + ); |
|
| 2772 | + } |
|
| 2773 | + } |
|
| 2774 | + $action_desc = 'created'; |
|
| 2775 | + } else { |
|
| 2776 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2777 | + $MTP = EEM_Message_Template::instance(); |
|
| 2778 | + |
|
| 2779 | + |
|
| 2780 | + // run update for each template field in displayed context |
|
| 2781 | + if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2782 | + EE_Error::add_error( |
|
| 2783 | + esc_html__( |
|
| 2784 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2785 | + 'event_espresso' |
|
| 2786 | + ), |
|
| 2787 | + __FILE__, |
|
| 2788 | + __FUNCTION__, |
|
| 2789 | + __LINE__ |
|
| 2790 | + ); |
|
| 2791 | + $success = 0; |
|
| 2792 | + } else { |
|
| 2793 | + // first validate all fields! |
|
| 2794 | + // this filter allows client code to add its own validation to the template fields as well. |
|
| 2795 | + // returning an empty array means everything passed validation. |
|
| 2796 | + // errors in validation should be represented in an array with the following shape: |
|
| 2797 | + // array( |
|
| 2798 | + // 'fieldname' => array( |
|
| 2799 | + // 'msg' => 'error message' |
|
| 2800 | + // 'value' => 'value for field producing error' |
|
| 2801 | + // ) |
|
| 2802 | + $custom_validation = (array) apply_filters( |
|
| 2803 | + 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates', |
|
| 2804 | + array(), |
|
| 2805 | + $this->_req_data['MTP_template_fields'], |
|
| 2806 | + $context_slug, |
|
| 2807 | + $messenger_slug, |
|
| 2808 | + $message_type_slug |
|
| 2809 | + ); |
|
| 2810 | + |
|
| 2811 | + $system_validation = $MTPG->validate( |
|
| 2812 | + $this->_req_data['MTP_template_fields'], |
|
| 2813 | + $context_slug, |
|
| 2814 | + $messenger_slug, |
|
| 2815 | + $message_type_slug |
|
| 2816 | + ); |
|
| 2817 | + |
|
| 2818 | + $system_validation = ! is_array($system_validation) && $system_validation ? array() |
|
| 2819 | + : $system_validation; |
|
| 2820 | + $validates = array_merge($custom_validation, $system_validation); |
|
| 2821 | + |
|
| 2822 | + // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2823 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2824 | + // WE need to make sure there is no actual error messages in validates. |
|
| 2825 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2826 | + // add the transient so when the form loads we know which fields to highlight |
|
| 2827 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2828 | + |
|
| 2829 | + $success = 0; |
|
| 2830 | + |
|
| 2831 | + // setup notices |
|
| 2832 | + foreach ($validates as $field => $error) { |
|
| 2833 | + if (isset($error['msg'])) { |
|
| 2834 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2835 | + } |
|
| 2836 | + } |
|
| 2837 | + } else { |
|
| 2838 | + $set_column_values = array(); |
|
| 2839 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2840 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2841 | + |
|
| 2842 | + $where_cols_n_values = array( |
|
| 2843 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'], |
|
| 2844 | + ); |
|
| 2845 | + // if they aren't allowed to use all JS, restrict them to just posty-y tags |
|
| 2846 | + if (! current_user_can('unfiltered_html')) { |
|
| 2847 | + if (is_array($set_column_values['MTP_content'])) { |
|
| 2848 | + foreach ($set_column_values['MTP_content'] as $key => $value) { |
|
| 2849 | + // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
|
| 2850 | + // only removes slashes from double-quotes, so attributes using single quotes always |
|
| 2851 | + // appear invalid.) But currently the models expect slashed data, so after wp_kses |
|
| 2852 | + // runs we need to re-slash the data. Sheesh. See |
|
| 2853 | + // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
|
| 2854 | + $set_column_values['MTP_content'][ $key ] = addslashes( |
|
| 2855 | + wp_kses( |
|
| 2856 | + stripslashes($value), |
|
| 2857 | + wp_kses_allowed_html('post') |
|
| 2858 | + ) |
|
| 2859 | + ); |
|
| 2860 | + } |
|
| 2861 | + } else { |
|
| 2862 | + $set_column_values['MTP_content'] = wp_kses( |
|
| 2863 | + $set_column_values['MTP_content'], |
|
| 2864 | + wp_kses_allowed_html('post') |
|
| 2865 | + ); |
|
| 2866 | + } |
|
| 2867 | + } |
|
| 2868 | + $message_template_fields = array( |
|
| 2869 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2870 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2871 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2872 | + 'MTP_content' => $set_column_values['MTP_content'], |
|
| 2873 | + ); |
|
| 2874 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2875 | + if ($updated === false) { |
|
| 2876 | + EE_Error::add_error( |
|
| 2877 | + sprintf( |
|
| 2878 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2879 | + $template_field |
|
| 2880 | + ), |
|
| 2881 | + __FILE__, |
|
| 2882 | + __FUNCTION__, |
|
| 2883 | + __LINE__ |
|
| 2884 | + ); |
|
| 2885 | + } else { |
|
| 2886 | + $success = 1; |
|
| 2887 | + } |
|
| 2888 | + } else { |
|
| 2889 | + // only do this logic if we don't have a MTP_ID for this field |
|
| 2890 | + if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) { |
|
| 2891 | + // this has already been through the template field validator and sanitized, so it will be |
|
| 2892 | + // safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2893 | + // message template field in a messenger/message type and existing users don't have the |
|
| 2894 | + // default setup for it. |
|
| 2895 | + // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2896 | + $updated = $MTP->insert($message_template_fields); |
|
| 2897 | + if (! $updated || is_wp_error($updated)) { |
|
| 2898 | + EE_Error::add_error( |
|
| 2899 | + sprintf( |
|
| 2900 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2901 | + $template_field |
|
| 2902 | + ), |
|
| 2903 | + __FILE__, |
|
| 2904 | + __FUNCTION__, |
|
| 2905 | + __LINE__ |
|
| 2906 | + ); |
|
| 2907 | + $success = 0; |
|
| 2908 | + } else { |
|
| 2909 | + $success = 1; |
|
| 2910 | + } |
|
| 2911 | + } |
|
| 2912 | + } |
|
| 2913 | + $action_desc = 'updated'; |
|
| 2914 | + } |
|
| 2915 | + |
|
| 2916 | + // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2917 | + $mtpg_fields = array( |
|
| 2918 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2919 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2920 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2921 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2922 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2923 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2924 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2925 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2926 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2927 | + : '', |
|
| 2928 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2929 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2930 | + : '', |
|
| 2931 | + ); |
|
| 2932 | + |
|
| 2933 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2934 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2935 | + |
|
| 2936 | + if ($updated === false) { |
|
| 2937 | + EE_Error::add_error( |
|
| 2938 | + sprintf( |
|
| 2939 | + esc_html__( |
|
| 2940 | + 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2941 | + 'event_espresso' |
|
| 2942 | + ), |
|
| 2943 | + $set_column_values['GRP_ID'] |
|
| 2944 | + ), |
|
| 2945 | + __FILE__, |
|
| 2946 | + __FUNCTION__, |
|
| 2947 | + __LINE__ |
|
| 2948 | + ); |
|
| 2949 | + } else { |
|
| 2950 | + // k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2951 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2952 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2953 | + : 'default'; |
|
| 2954 | + |
|
| 2955 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2956 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2957 | + : 'default'; |
|
| 2958 | + |
|
| 2959 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2960 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2961 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2962 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2963 | + } |
|
| 2964 | + $success = 1; |
|
| 2965 | + } |
|
| 2966 | + } |
|
| 2967 | + } |
|
| 2968 | + } |
|
| 2969 | + |
|
| 2970 | + // we return things differently if doing ajax |
|
| 2971 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2972 | + $this->_template_args['success'] = $success; |
|
| 2973 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2974 | + $this->_template_args['content'] = ''; |
|
| 2975 | + $this->_template_args['data'] = array( |
|
| 2976 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2977 | + 'templateName' => $edit_array['template_name'], |
|
| 2978 | + ); |
|
| 2979 | + if ($success) { |
|
| 2980 | + EE_Error::overwrite_success(); |
|
| 2981 | + EE_Error::add_success( |
|
| 2982 | + esc_html__( |
|
| 2983 | + 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2984 | + 'event_espresso' |
|
| 2985 | + ) |
|
| 2986 | + ); |
|
| 2987 | + } |
|
| 2988 | + |
|
| 2989 | + $this->_return_json(); |
|
| 2990 | + } |
|
| 2991 | + |
|
| 2992 | + |
|
| 2993 | + // was a test send triggered? |
|
| 2994 | + if (isset($this->_req_data['test_button'])) { |
|
| 2995 | + EE_Error::overwrite_success(); |
|
| 2996 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2997 | + $override = true; |
|
| 2998 | + } |
|
| 2999 | + |
|
| 3000 | + if (empty($query_args)) { |
|
| 3001 | + $query_args = array( |
|
| 3002 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 3003 | + 'context' => $context_slug, |
|
| 3004 | + 'action' => 'edit_message_template', |
|
| 3005 | + ); |
|
| 3006 | + } |
|
| 3007 | + |
|
| 3008 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 3009 | + } |
|
| 3010 | + |
|
| 3011 | + |
|
| 3012 | + /** |
|
| 3013 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 3014 | + * |
|
| 3015 | + * @param string $context what context being tested |
|
| 3016 | + * @param string $messenger messenger being tested |
|
| 3017 | + * @param string $message_type message type being tested |
|
| 3018 | + * @throws EE_Error |
|
| 3019 | + * @throws InvalidArgumentException |
|
| 3020 | + * @throws InvalidDataTypeException |
|
| 3021 | + * @throws InvalidInterfaceException |
|
| 3022 | + */ |
|
| 3023 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 3024 | + { |
|
| 3025 | + // set things up for preview |
|
| 3026 | + $this->_req_data['messenger'] = $messenger; |
|
| 3027 | + $this->_req_data['message_type'] = $message_type; |
|
| 3028 | + $this->_req_data['context'] = $context; |
|
| 3029 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 3030 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 3031 | + |
|
| 3032 | + // let's save any existing fields that might be required by the messenger |
|
| 3033 | + if ( |
|
| 3034 | + isset($this->_req_data['test_settings_fld']) |
|
| 3035 | + && $active_messenger instanceof EE_messenger |
|
| 3036 | + && apply_filters( |
|
| 3037 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 3038 | + true, |
|
| 3039 | + $this->_req_data['test_settings_fld'], |
|
| 3040 | + $active_messenger |
|
| 3041 | + ) |
|
| 3042 | + ) { |
|
| 3043 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 3044 | + } |
|
| 3045 | + |
|
| 3046 | + /** |
|
| 3047 | + * Use filter to add additional controls on whether message can send or not |
|
| 3048 | + */ |
|
| 3049 | + if ( |
|
| 3050 | + apply_filters( |
|
| 3051 | + 'FHEE__Messages_Admin_Page__do_test_send__can_send', |
|
| 3052 | + true, |
|
| 3053 | + $context, |
|
| 3054 | + $this->_req_data, |
|
| 3055 | + $messenger, |
|
| 3056 | + $message_type |
|
| 3057 | + ) |
|
| 3058 | + ) { |
|
| 3059 | + if (EEM_Event::instance()->count() > 0) { |
|
| 3060 | + $success = $this->_preview_message(true); |
|
| 3061 | + if ($success) { |
|
| 3062 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 3063 | + } else { |
|
| 3064 | + EE_Error::add_error( |
|
| 3065 | + esc_html__('The test message was not sent', 'event_espresso'), |
|
| 3066 | + __FILE__, |
|
| 3067 | + __FUNCTION__, |
|
| 3068 | + __LINE__ |
|
| 3069 | + ); |
|
| 3070 | + } |
|
| 3071 | + } else { |
|
| 3072 | + $this->noEventsErrorMessage(true); |
|
| 3073 | + } |
|
| 3074 | + } |
|
| 3075 | + } |
|
| 3076 | + |
|
| 3077 | + |
|
| 3078 | + /** |
|
| 3079 | + * _generate_new_templates |
|
| 3080 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 3081 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 3082 | + * for the event. |
|
| 3083 | + * |
|
| 3084 | + * |
|
| 3085 | + * @param string $messenger the messenger we are generating templates for |
|
| 3086 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 3087 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 3088 | + * indicate the message_template_group being used as the base. |
|
| 3089 | + * |
|
| 3090 | + * @param bool $global |
|
| 3091 | + * |
|
| 3092 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 3093 | + * encountering problems. |
|
| 3094 | + * @throws EE_Error |
|
| 3095 | + */ |
|
| 3096 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 3097 | + { |
|
| 3098 | + |
|
| 3099 | + // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 3100 | + // just don't generate any templates. |
|
| 3101 | + if (empty($message_types)) { |
|
| 3102 | + return true; |
|
| 3103 | + } |
|
| 3104 | + |
|
| 3105 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 3106 | + } |
|
| 3107 | + |
|
| 3108 | + |
|
| 3109 | + /** |
|
| 3110 | + * [_trash_or_restore_message_template] |
|
| 3111 | + * |
|
| 3112 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 3113 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 3114 | + * an individual context (FALSE). |
|
| 3115 | + * @return void |
|
| 3116 | + * @throws EE_Error |
|
| 3117 | + * @throws InvalidArgumentException |
|
| 3118 | + * @throws InvalidDataTypeException |
|
| 3119 | + * @throws InvalidInterfaceException |
|
| 3120 | + */ |
|
| 3121 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 3122 | + { |
|
| 3123 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3124 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 3125 | + |
|
| 3126 | + $success = 1; |
|
| 3127 | + |
|
| 3128 | + // incoming GRP_IDs |
|
| 3129 | + if ($all) { |
|
| 3130 | + // Checkboxes |
|
| 3131 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3132 | + // if array has more than one element then success message should be plural. |
|
| 3133 | + // todo: what about nonce? |
|
| 3134 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3135 | + |
|
| 3136 | + // cycle through checkboxes |
|
| 3137 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3138 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3139 | + if (! $trashed_or_restored) { |
|
| 3140 | + $success = 0; |
|
| 3141 | + } |
|
| 3142 | + } |
|
| 3143 | + } else { |
|
| 3144 | + // grab single GRP_ID and handle |
|
| 3145 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3146 | + if (! empty($GRP_ID)) { |
|
| 3147 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3148 | + if (! $trashed_or_restored) { |
|
| 3149 | + $success = 0; |
|
| 3150 | + } |
|
| 3151 | + } else { |
|
| 3152 | + $success = 0; |
|
| 3153 | + } |
|
| 3154 | + } |
|
| 3155 | + } |
|
| 3156 | + |
|
| 3157 | + $action_desc = $trash |
|
| 3158 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3159 | + : esc_html__('restored', 'event_espresso'); |
|
| 3160 | + |
|
| 3161 | + $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc; |
|
| 3162 | + |
|
| 3163 | + $item_desc = $all ? _n( |
|
| 3164 | + 'Message Template Group', |
|
| 3165 | + 'Message Template Groups', |
|
| 3166 | + $success, |
|
| 3167 | + 'event_espresso' |
|
| 3168 | + ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3169 | + |
|
| 3170 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n( |
|
| 3171 | + 'template', |
|
| 3172 | + 'templates', |
|
| 3173 | + $success, |
|
| 3174 | + 'event_espresso' |
|
| 3175 | + ) : $item_desc; |
|
| 3176 | + |
|
| 3177 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3178 | + } |
|
| 3179 | + |
|
| 3180 | + |
|
| 3181 | + /** |
|
| 3182 | + * [_delete_message_template] |
|
| 3183 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3184 | + * |
|
| 3185 | + * @return void |
|
| 3186 | + * @throws EE_Error |
|
| 3187 | + * @throws InvalidArgumentException |
|
| 3188 | + * @throws InvalidDataTypeException |
|
| 3189 | + * @throws InvalidInterfaceException |
|
| 3190 | + */ |
|
| 3191 | + protected function _delete_message_template() |
|
| 3192 | + { |
|
| 3193 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3194 | + |
|
| 3195 | + // checkboxes |
|
| 3196 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3197 | + // if array has more than one element then success message should be plural |
|
| 3198 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3199 | + |
|
| 3200 | + // cycle through bulk action checkboxes |
|
| 3201 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3202 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3203 | + } |
|
| 3204 | + } else { |
|
| 3205 | + // grab single grp_id and delete |
|
| 3206 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 3207 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3208 | + } |
|
| 3209 | + |
|
| 3210 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3211 | + } |
|
| 3212 | + |
|
| 3213 | + |
|
| 3214 | + /** |
|
| 3215 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 3216 | + * |
|
| 3217 | + * @param int $GRP_ID The group being deleted |
|
| 3218 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3219 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 3220 | + * @throws EE_Error |
|
| 3221 | + * @throws InvalidArgumentException |
|
| 3222 | + * @throws InvalidDataTypeException |
|
| 3223 | + * @throws InvalidInterfaceException |
|
| 3224 | + */ |
|
| 3225 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3226 | + { |
|
| 3227 | + $success = 1; |
|
| 3228 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3229 | + // first let's GET this group |
|
| 3230 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3231 | + // then delete permanently all the related Message Templates |
|
| 3232 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3233 | + |
|
| 3234 | + if ($deleted === 0) { |
|
| 3235 | + $success = 0; |
|
| 3236 | + } |
|
| 3237 | + |
|
| 3238 | + // now delete permanently this particular group |
|
| 3239 | + |
|
| 3240 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3241 | + $success = 0; |
|
| 3242 | + } |
|
| 3243 | + |
|
| 3244 | + return $success; |
|
| 3245 | + } |
|
| 3246 | + |
|
| 3247 | + |
|
| 3248 | + /** |
|
| 3249 | + * _learn_more_about_message_templates_link |
|
| 3250 | + * |
|
| 3251 | + * @access protected |
|
| 3252 | + * @return string |
|
| 3253 | + */ |
|
| 3254 | + protected function _learn_more_about_message_templates_link() |
|
| 3255 | + { |
|
| 3256 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3257 | + . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3258 | + . '</a>'; |
|
| 3259 | + } |
|
| 3260 | + |
|
| 3261 | + |
|
| 3262 | + /** |
|
| 3263 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3264 | + * ajax and other routes. |
|
| 3265 | + * |
|
| 3266 | + * @return void |
|
| 3267 | + * @throws DomainException |
|
| 3268 | + */ |
|
| 3269 | + protected function _settings() |
|
| 3270 | + { |
|
| 3271 | + |
|
| 3272 | + |
|
| 3273 | + $this->_set_m_mt_settings(); |
|
| 3274 | + |
|
| 3275 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3276 | + ? $this->_req_data['selected_messenger'] |
|
| 3277 | + : 'email'; |
|
| 3278 | + |
|
| 3279 | + // let's setup the messenger tabs |
|
| 3280 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3281 | + $this->_m_mt_settings['messenger_tabs'], |
|
| 3282 | + 'messenger_links', |
|
| 3283 | + '|', |
|
| 3284 | + $selected_messenger |
|
| 3285 | + ); |
|
| 3286 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3287 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3288 | + |
|
| 3289 | + $this->display_admin_page_with_sidebar(); |
|
| 3290 | + } |
|
| 3291 | + |
|
| 3292 | + |
|
| 3293 | + /** |
|
| 3294 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3295 | + * |
|
| 3296 | + * @access protected |
|
| 3297 | + * @return void |
|
| 3298 | + * @throws DomainException |
|
| 3299 | + */ |
|
| 3300 | + protected function _set_m_mt_settings() |
|
| 3301 | + { |
|
| 3302 | + // first if this is already set then lets get out no need to regenerate data. |
|
| 3303 | + if (! empty($this->_m_mt_settings)) { |
|
| 3304 | + return; |
|
| 3305 | + } |
|
| 3306 | + |
|
| 3307 | + // get all installed messengers and message_types |
|
| 3308 | + /** @type EE_messenger[] $messengers */ |
|
| 3309 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3310 | + /** @type EE_message_type[] $message_types */ |
|
| 3311 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3312 | + |
|
| 3313 | + |
|
| 3314 | + // assemble the array for the _tab_text_links helper |
|
| 3315 | + |
|
| 3316 | + foreach ($messengers as $messenger) { |
|
| 3317 | + $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array( |
|
| 3318 | + 'label' => ucwords($messenger->label['singular']), |
|
| 3319 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3320 | + ? 'messenger-active' |
|
| 3321 | + : '', |
|
| 3322 | + 'href' => $messenger->name, |
|
| 3323 | + 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3324 | + 'slug' => $messenger->name, |
|
| 3325 | + 'obj' => $messenger, |
|
| 3326 | + ); |
|
| 3327 | + |
|
| 3328 | + |
|
| 3329 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3330 | + |
|
| 3331 | + foreach ($message_types as $message_type) { |
|
| 3332 | + // first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3333 | + // it shouldn't show in either the inactive OR active metabox. |
|
| 3334 | + if (! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3335 | + continue; |
|
| 3336 | + } |
|
| 3337 | + |
|
| 3338 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3339 | + $messenger->name, |
|
| 3340 | + $message_type->name |
|
| 3341 | + ) |
|
| 3342 | + ? 'active' |
|
| 3343 | + : 'inactive'; |
|
| 3344 | + |
|
| 3345 | + $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array( |
|
| 3346 | + 'label' => ucwords($message_type->label['singular']), |
|
| 3347 | + 'class' => 'message-type-' . $a_or_i, |
|
| 3348 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3349 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3350 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3351 | + 'title' => $a_or_i === 'active' |
|
| 3352 | + ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3353 | + : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3354 | + 'content' => $a_or_i === 'active' |
|
| 3355 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3356 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3357 | + 'slug' => $message_type->name, |
|
| 3358 | + 'active' => $a_or_i === 'active', |
|
| 3359 | + 'obj' => $message_type, |
|
| 3360 | + ); |
|
| 3361 | + } |
|
| 3362 | + } |
|
| 3363 | + } |
|
| 3364 | + |
|
| 3365 | + |
|
| 3366 | + /** |
|
| 3367 | + * This just prepares the content for the message type settings |
|
| 3368 | + * |
|
| 3369 | + * @param EE_message_type $message_type The message type object |
|
| 3370 | + * @param EE_messenger $messenger The messenger object |
|
| 3371 | + * @param boolean $active Whether the message type is active or not |
|
| 3372 | + * @return string html output for the content |
|
| 3373 | + * @throws DomainException |
|
| 3374 | + */ |
|
| 3375 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3376 | + { |
|
| 3377 | + // get message type fields |
|
| 3378 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 3379 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3380 | + |
|
| 3381 | + if (! empty($fields) && $active) { |
|
| 3382 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3383 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3384 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3385 | + $template_form_field[ $field_id ] = array( |
|
| 3386 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3387 | + 'label' => $fldprops['label'], |
|
| 3388 | + 'input' => $fldprops['field_type'], |
|
| 3389 | + 'type' => $fldprops['value_type'], |
|
| 3390 | + 'required' => $fldprops['required'], |
|
| 3391 | + 'validation' => $fldprops['validation'], |
|
| 3392 | + 'value' => isset($existing_settings[ $fldname ]) |
|
| 3393 | + ? $existing_settings[ $fldname ] |
|
| 3394 | + : $fldprops['default'], |
|
| 3395 | + 'options' => isset($fldprops['options']) |
|
| 3396 | + ? $fldprops['options'] |
|
| 3397 | + : array(), |
|
| 3398 | + 'default' => isset($existing_settings[ $fldname ]) |
|
| 3399 | + ? $existing_settings[ $fldname ] |
|
| 3400 | + : $fldprops['default'], |
|
| 3401 | + 'css_class' => 'no-drag', |
|
| 3402 | + 'format' => $fldprops['format'], |
|
| 3403 | + ); |
|
| 3404 | + } |
|
| 3405 | + |
|
| 3406 | + |
|
| 3407 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3408 | + ? $this->_generate_admin_form_fields( |
|
| 3409 | + $template_form_field, |
|
| 3410 | + 'string', |
|
| 3411 | + 'ee_mt_activate_form' |
|
| 3412 | + ) |
|
| 3413 | + : ''; |
|
| 3414 | + } |
|
| 3415 | + |
|
| 3416 | + $settings_template_args['description'] = $message_type->description; |
|
| 3417 | + // we also need some hidden fields |
|
| 3418 | + $settings_template_args['hidden_fields'] = array( |
|
| 3419 | + 'message_type_settings[messenger]' => array( |
|
| 3420 | + 'type' => 'hidden', |
|
| 3421 | + 'value' => $messenger->name, |
|
| 3422 | + ), |
|
| 3423 | + 'message_type_settings[message_type]' => array( |
|
| 3424 | + 'type' => 'hidden', |
|
| 3425 | + 'value' => $message_type->name, |
|
| 3426 | + ), |
|
| 3427 | + 'type' => array( |
|
| 3428 | + 'type' => 'hidden', |
|
| 3429 | + 'value' => 'message_type', |
|
| 3430 | + ), |
|
| 3431 | + ); |
|
| 3432 | + |
|
| 3433 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3434 | + $settings_template_args['hidden_fields'], |
|
| 3435 | + 'array' |
|
| 3436 | + ); |
|
| 3437 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3438 | + ? ' hidden' |
|
| 3439 | + : ''; |
|
| 3440 | + |
|
| 3441 | + |
|
| 3442 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3443 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3444 | + |
|
| 3445 | + return $content; |
|
| 3446 | + } |
|
| 3447 | + |
|
| 3448 | + |
|
| 3449 | + /** |
|
| 3450 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3451 | + * |
|
| 3452 | + * @access protected |
|
| 3453 | + * @return void |
|
| 3454 | + * @throws DomainException |
|
| 3455 | + */ |
|
| 3456 | + protected function _messages_settings_metaboxes() |
|
| 3457 | + { |
|
| 3458 | + $this->_set_m_mt_settings(); |
|
| 3459 | + $m_boxes = $mt_boxes = array(); |
|
| 3460 | + $m_template_args = $mt_template_args = array(); |
|
| 3461 | + |
|
| 3462 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3463 | + ? $this->_req_data['selected_messenger'] |
|
| 3464 | + : 'email'; |
|
| 3465 | + |
|
| 3466 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3467 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3468 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3469 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3470 | + // messenger meta boxes |
|
| 3471 | + $active = $selected_messenger === $messenger; |
|
| 3472 | + $active_mt_tabs = isset( |
|
| 3473 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] |
|
| 3474 | + ) |
|
| 3475 | + ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] |
|
| 3476 | + : ''; |
|
| 3477 | + $m_boxes[ $messenger . '_a_box' ] = sprintf( |
|
| 3478 | + esc_html__('%s Settings', 'event_espresso'), |
|
| 3479 | + $tab_array['label'] |
|
| 3480 | + ); |
|
| 3481 | + $m_template_args[ $messenger . '_a_box' ] = array( |
|
| 3482 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3483 | + 'inactive_message_types' => isset( |
|
| 3484 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] |
|
| 3485 | + ) |
|
| 3486 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) |
|
| 3487 | + : '', |
|
| 3488 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3489 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3490 | + 'hide_on_message' => $hide_on_message, |
|
| 3491 | + 'messenger' => $messenger, |
|
| 3492 | + 'active' => $active, |
|
| 3493 | + ); |
|
| 3494 | + // message type meta boxes |
|
| 3495 | + // (which is really just the inactive container for each messenger |
|
| 3496 | + // showing inactive message types for that messenger) |
|
| 3497 | + $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3498 | + $mt_template_args[ $messenger . '_i_box' ] = array( |
|
| 3499 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3500 | + 'inactive_message_types' => isset( |
|
| 3501 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] |
|
| 3502 | + ) |
|
| 3503 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) |
|
| 3504 | + : '', |
|
| 3505 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3506 | + 'hide_on_message' => $hide_on_message, |
|
| 3507 | + 'hide_off_message' => $hide_off_message, |
|
| 3508 | + 'messenger' => $messenger, |
|
| 3509 | + 'active' => $active, |
|
| 3510 | + ); |
|
| 3511 | + } |
|
| 3512 | + } |
|
| 3513 | + |
|
| 3514 | + |
|
| 3515 | + // register messenger metaboxes |
|
| 3516 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3517 | + foreach ($m_boxes as $box => $label) { |
|
| 3518 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]); |
|
| 3519 | + $msgr = str_replace('_a_box', '', $box); |
|
| 3520 | + add_meta_box( |
|
| 3521 | + 'espresso_' . $msgr . '_settings', |
|
| 3522 | + $label, |
|
| 3523 | + function ($post, $metabox) { |
|
| 3524 | + echo EEH_Template::display_template( |
|
| 3525 | + $metabox["args"]["template_path"], |
|
| 3526 | + $metabox["args"]["template_args"], |
|
| 3527 | + true |
|
| 3528 | + ); |
|
| 3529 | + }, |
|
| 3530 | + $this->_current_screen->id, |
|
| 3531 | + 'normal', |
|
| 3532 | + 'high', |
|
| 3533 | + $callback_args |
|
| 3534 | + ); |
|
| 3535 | + } |
|
| 3536 | + |
|
| 3537 | + // register message type metaboxes |
|
| 3538 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3539 | + foreach ($mt_boxes as $box => $label) { |
|
| 3540 | + $callback_args = array( |
|
| 3541 | + 'template_path' => $mt_template_path, |
|
| 3542 | + 'template_args' => $mt_template_args[ $box ], |
|
| 3543 | + ); |
|
| 3544 | + $mt = str_replace('_i_box', '', $box); |
|
| 3545 | + add_meta_box( |
|
| 3546 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 3547 | + $label, |
|
| 3548 | + function ($post, $metabox) { |
|
| 3549 | + echo EEH_Template::display_template( |
|
| 3550 | + $metabox["args"]["template_path"], |
|
| 3551 | + $metabox["args"]["template_args"], |
|
| 3552 | + true |
|
| 3553 | + ); |
|
| 3554 | + }, |
|
| 3555 | + $this->_current_screen->id, |
|
| 3556 | + 'side', |
|
| 3557 | + 'high', |
|
| 3558 | + $callback_args |
|
| 3559 | + ); |
|
| 3560 | + } |
|
| 3561 | + |
|
| 3562 | + // register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3563 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3564 | + if (is_main_site()) { |
|
| 3565 | + add_meta_box( |
|
| 3566 | + 'espresso_global_message_settings', |
|
| 3567 | + esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3568 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 3569 | + $this->_current_screen->id, |
|
| 3570 | + 'normal', |
|
| 3571 | + 'low', |
|
| 3572 | + array() |
|
| 3573 | + ); |
|
| 3574 | + } |
|
| 3575 | + } |
|
| 3576 | + |
|
| 3577 | + |
|
| 3578 | + /** |
|
| 3579 | + * This generates the content for the global messages settings metabox. |
|
| 3580 | + * |
|
| 3581 | + * @return string |
|
| 3582 | + * @throws EE_Error |
|
| 3583 | + * @throws InvalidArgumentException |
|
| 3584 | + * @throws ReflectionException |
|
| 3585 | + * @throws InvalidDataTypeException |
|
| 3586 | + * @throws InvalidInterfaceException |
|
| 3587 | + */ |
|
| 3588 | + public function global_messages_settings_metabox_content() |
|
| 3589 | + { |
|
| 3590 | + $form = $this->_generate_global_settings_form(); |
|
| 3591 | + echo $form->form_open( |
|
| 3592 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3593 | + 'POST' |
|
| 3594 | + ) |
|
| 3595 | + . $form->get_html() |
|
| 3596 | + . $form->form_close(); |
|
| 3597 | + } |
|
| 3598 | + |
|
| 3599 | + |
|
| 3600 | + /** |
|
| 3601 | + * This generates and returns the form object for the global messages settings. |
|
| 3602 | + * |
|
| 3603 | + * @return EE_Form_Section_Proper |
|
| 3604 | + * @throws EE_Error |
|
| 3605 | + * @throws InvalidArgumentException |
|
| 3606 | + * @throws ReflectionException |
|
| 3607 | + * @throws InvalidDataTypeException |
|
| 3608 | + * @throws InvalidInterfaceException |
|
| 3609 | + */ |
|
| 3610 | + protected function _generate_global_settings_form() |
|
| 3611 | + { |
|
| 3612 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3613 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3614 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3615 | + |
|
| 3616 | + return new EE_Form_Section_Proper( |
|
| 3617 | + array( |
|
| 3618 | + 'name' => 'global_messages_settings', |
|
| 3619 | + 'html_id' => 'global_messages_settings', |
|
| 3620 | + 'html_class' => 'form-table', |
|
| 3621 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3622 | + 'subsections' => apply_filters( |
|
| 3623 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3624 | + array( |
|
| 3625 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3626 | + array( |
|
| 3627 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3628 | + false => esc_html__("On a separate request", "event_espresso"), |
|
| 3629 | + ), |
|
| 3630 | + array( |
|
| 3631 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3632 | + 'html_label_text' => esc_html__( |
|
| 3633 | + 'Generate and send all messages:', |
|
| 3634 | + 'event_espresso' |
|
| 3635 | + ), |
|
| 3636 | + 'html_help_text' => esc_html__( |
|
| 3637 | + 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3638 | + 'event_espresso' |
|
| 3639 | + ), |
|
| 3640 | + ) |
|
| 3641 | + ), |
|
| 3642 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3643 | + array( |
|
| 3644 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3645 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3646 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3647 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3648 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3649 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3650 | + 36 => esc_html__('36 Months', 'event_espresso'), |
|
| 3651 | + ), |
|
| 3652 | + array( |
|
| 3653 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3654 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3655 | + 'html_help_text' => esc_html__( |
|
| 3656 | + 'You can control how long a record of processed messages is kept via this option.', |
|
| 3657 | + 'event_espresso' |
|
| 3658 | + ), |
|
| 3659 | + ) |
|
| 3660 | + ), |
|
| 3661 | + 'update_settings' => new EE_Submit_Input( |
|
| 3662 | + array( |
|
| 3663 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3664 | + 'html_label_text' => ' ', |
|
| 3665 | + ) |
|
| 3666 | + ), |
|
| 3667 | + ) |
|
| 3668 | + ), |
|
| 3669 | + ) |
|
| 3670 | + ); |
|
| 3671 | + } |
|
| 3672 | + |
|
| 3673 | + |
|
| 3674 | + /** |
|
| 3675 | + * This handles updating the global settings set on the admin page. |
|
| 3676 | + * |
|
| 3677 | + * @throws EE_Error |
|
| 3678 | + * @throws InvalidDataTypeException |
|
| 3679 | + * @throws InvalidInterfaceException |
|
| 3680 | + * @throws InvalidArgumentException |
|
| 3681 | + * @throws ReflectionException |
|
| 3682 | + */ |
|
| 3683 | + protected function _update_global_settings() |
|
| 3684 | + { |
|
| 3685 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3686 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3687 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3688 | + $form = $this->_generate_global_settings_form(); |
|
| 3689 | + if ($form->was_submitted()) { |
|
| 3690 | + $form->receive_form_submission(); |
|
| 3691 | + if ($form->is_valid()) { |
|
| 3692 | + $valid_data = $form->valid_data(); |
|
| 3693 | + foreach ($valid_data as $property => $value) { |
|
| 3694 | + $setter = 'set_' . $property; |
|
| 3695 | + if (method_exists($network_config, $setter)) { |
|
| 3696 | + $network_config->{$setter}($value); |
|
| 3697 | + } elseif ( |
|
| 3698 | + property_exists($network_config, $property) |
|
| 3699 | + && $network_config->{$property} !== $value |
|
| 3700 | + ) { |
|
| 3701 | + $network_config->{$property} = $value; |
|
| 3702 | + } elseif ( |
|
| 3703 | + property_exists($messages_config, $property) |
|
| 3704 | + && $messages_config->{$property} !== $value |
|
| 3705 | + ) { |
|
| 3706 | + $messages_config->{$property} = $value; |
|
| 3707 | + } |
|
| 3708 | + } |
|
| 3709 | + // only update if the form submission was valid! |
|
| 3710 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3711 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3712 | + EE_Error::overwrite_success(); |
|
| 3713 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3714 | + } |
|
| 3715 | + } |
|
| 3716 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3717 | + } |
|
| 3718 | + |
|
| 3719 | + |
|
| 3720 | + /** |
|
| 3721 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3722 | + * |
|
| 3723 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3724 | + * @return string html formatted tabs |
|
| 3725 | + * @throws DomainException |
|
| 3726 | + */ |
|
| 3727 | + protected function _get_mt_tabs($tab_array) |
|
| 3728 | + { |
|
| 3729 | + $tab_array = (array) $tab_array; |
|
| 3730 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3731 | + $tabs = ''; |
|
| 3732 | + |
|
| 3733 | + foreach ($tab_array as $tab) { |
|
| 3734 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3735 | + } |
|
| 3736 | + |
|
| 3737 | + return $tabs; |
|
| 3738 | + } |
|
| 3739 | + |
|
| 3740 | + |
|
| 3741 | + /** |
|
| 3742 | + * This prepares the content of the messenger meta box admin settings |
|
| 3743 | + * |
|
| 3744 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3745 | + * @return string html formatted content |
|
| 3746 | + * @throws DomainException |
|
| 3747 | + */ |
|
| 3748 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3749 | + { |
|
| 3750 | + |
|
| 3751 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3752 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3753 | + |
|
| 3754 | + // is $messenger active? |
|
| 3755 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3756 | + |
|
| 3757 | + |
|
| 3758 | + if (! empty($fields)) { |
|
| 3759 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3760 | + |
|
| 3761 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3762 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3763 | + $template_form_field[ $field_id ] = array( |
|
| 3764 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3765 | + 'label' => $fldprops['label'], |
|
| 3766 | + 'input' => $fldprops['field_type'], |
|
| 3767 | + 'type' => $fldprops['value_type'], |
|
| 3768 | + 'required' => $fldprops['required'], |
|
| 3769 | + 'validation' => $fldprops['validation'], |
|
| 3770 | + 'value' => isset($existing_settings[ $field_id ]) |
|
| 3771 | + ? $existing_settings[ $field_id ] |
|
| 3772 | + : $fldprops['default'], |
|
| 3773 | + 'css_class' => '', |
|
| 3774 | + 'format' => $fldprops['format'], |
|
| 3775 | + ); |
|
| 3776 | + } |
|
| 3777 | + |
|
| 3778 | + |
|
| 3779 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3780 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3781 | + : ''; |
|
| 3782 | + } |
|
| 3783 | + |
|
| 3784 | + // we also need some hidden fields |
|
| 3785 | + $settings_template_args['hidden_fields'] = array( |
|
| 3786 | + 'messenger_settings[messenger]' => array( |
|
| 3787 | + 'type' => 'hidden', |
|
| 3788 | + 'value' => $messenger->name, |
|
| 3789 | + ), |
|
| 3790 | + 'type' => array( |
|
| 3791 | + 'type' => 'hidden', |
|
| 3792 | + 'value' => 'messenger', |
|
| 3793 | + ), |
|
| 3794 | + ); |
|
| 3795 | + |
|
| 3796 | + // make sure any active message types that are existing are included in the hidden fields |
|
| 3797 | + if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { |
|
| 3798 | + foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { |
|
| 3799 | + $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array( |
|
| 3800 | + 'type' => 'hidden', |
|
| 3801 | + 'value' => $mt, |
|
| 3802 | + ); |
|
| 3803 | + } |
|
| 3804 | + } |
|
| 3805 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3806 | + $settings_template_args['hidden_fields'], |
|
| 3807 | + 'array' |
|
| 3808 | + ); |
|
| 3809 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3810 | + |
|
| 3811 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3812 | + $settings_template_args['description'] = $messenger->description; |
|
| 3813 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3814 | + |
|
| 3815 | + |
|
| 3816 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3817 | + $messenger->name |
|
| 3818 | + ) |
|
| 3819 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3820 | + : ' hidden'; |
|
| 3821 | + |
|
| 3822 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3823 | + ? ' hidden' |
|
| 3824 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3825 | + |
|
| 3826 | + |
|
| 3827 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3828 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3829 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3830 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3831 | + $content = EEH_Template::display_template( |
|
| 3832 | + $template, |
|
| 3833 | + $settings_template_args, |
|
| 3834 | + true |
|
| 3835 | + ); |
|
| 3836 | + |
|
| 3837 | + return $content; |
|
| 3838 | + } |
|
| 3839 | + |
|
| 3840 | + |
|
| 3841 | + /** |
|
| 3842 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3843 | + * |
|
| 3844 | + * @throws DomainException |
|
| 3845 | + * @throws EE_Error |
|
| 3846 | + * @throws InvalidDataTypeException |
|
| 3847 | + * @throws InvalidInterfaceException |
|
| 3848 | + * @throws InvalidArgumentException |
|
| 3849 | + * @throws ReflectionException |
|
| 3850 | + */ |
|
| 3851 | + public function activate_messenger_toggle() |
|
| 3852 | + { |
|
| 3853 | + $success = true; |
|
| 3854 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3855 | + // let's check that we have required data |
|
| 3856 | + if (! isset($this->_req_data['messenger'])) { |
|
| 3857 | + EE_Error::add_error( |
|
| 3858 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3859 | + __FILE__, |
|
| 3860 | + __FUNCTION__, |
|
| 3861 | + __LINE__ |
|
| 3862 | + ); |
|
| 3863 | + $success = false; |
|
| 3864 | + } |
|
| 3865 | + |
|
| 3866 | + // do a nonce check here since we're not arriving via a normal route |
|
| 3867 | + $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3868 | + ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3869 | + : ''; |
|
| 3870 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3871 | + |
|
| 3872 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3873 | + |
|
| 3874 | + |
|
| 3875 | + if (! isset($this->_req_data['status'])) { |
|
| 3876 | + EE_Error::add_error( |
|
| 3877 | + esc_html__( |
|
| 3878 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3879 | + 'event_espresso' |
|
| 3880 | + ), |
|
| 3881 | + __FILE__, |
|
| 3882 | + __FUNCTION__, |
|
| 3883 | + __LINE__ |
|
| 3884 | + ); |
|
| 3885 | + $success = false; |
|
| 3886 | + } |
|
| 3887 | + |
|
| 3888 | + // do check to verify we have a valid status. |
|
| 3889 | + $status = $this->_req_data['status']; |
|
| 3890 | + |
|
| 3891 | + if ($status !== 'off' && $status !== 'on') { |
|
| 3892 | + EE_Error::add_error( |
|
| 3893 | + sprintf( |
|
| 3894 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3895 | + $this->_req_data['status'] |
|
| 3896 | + ), |
|
| 3897 | + __FILE__, |
|
| 3898 | + __FUNCTION__, |
|
| 3899 | + __LINE__ |
|
| 3900 | + ); |
|
| 3901 | + $success = false; |
|
| 3902 | + } |
|
| 3903 | + |
|
| 3904 | + if ($success) { |
|
| 3905 | + // made it here? Stop dawdling then!! |
|
| 3906 | + $success = $status === 'off' |
|
| 3907 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3908 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3909 | + } |
|
| 3910 | + |
|
| 3911 | + $this->_template_args['success'] = $success; |
|
| 3912 | + |
|
| 3913 | + // no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3914 | + $this->_return_json(); |
|
| 3915 | + } |
|
| 3916 | + |
|
| 3917 | + |
|
| 3918 | + /** |
|
| 3919 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3920 | + * |
|
| 3921 | + * @throws DomainException |
|
| 3922 | + * @throws EE_Error |
|
| 3923 | + * @throws ReflectionException |
|
| 3924 | + * @throws InvalidDataTypeException |
|
| 3925 | + * @throws InvalidInterfaceException |
|
| 3926 | + * @throws InvalidArgumentException |
|
| 3927 | + */ |
|
| 3928 | + public function activate_mt_toggle() |
|
| 3929 | + { |
|
| 3930 | + $success = true; |
|
| 3931 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3932 | + |
|
| 3933 | + // let's make sure we have the necessary data |
|
| 3934 | + if (! isset($this->_req_data['message_type'])) { |
|
| 3935 | + EE_Error::add_error( |
|
| 3936 | + esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3937 | + __FILE__, |
|
| 3938 | + __FUNCTION__, |
|
| 3939 | + __LINE__ |
|
| 3940 | + ); |
|
| 3941 | + $success = false; |
|
| 3942 | + } |
|
| 3943 | + |
|
| 3944 | + if (! isset($this->_req_data['messenger'])) { |
|
| 3945 | + EE_Error::add_error( |
|
| 3946 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3947 | + __FILE__, |
|
| 3948 | + __FUNCTION__, |
|
| 3949 | + __LINE__ |
|
| 3950 | + ); |
|
| 3951 | + $success = false; |
|
| 3952 | + } |
|
| 3953 | + |
|
| 3954 | + if (! isset($this->_req_data['status'])) { |
|
| 3955 | + EE_Error::add_error( |
|
| 3956 | + esc_html__( |
|
| 3957 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3958 | + 'event_espresso' |
|
| 3959 | + ), |
|
| 3960 | + __FILE__, |
|
| 3961 | + __FUNCTION__, |
|
| 3962 | + __LINE__ |
|
| 3963 | + ); |
|
| 3964 | + $success = false; |
|
| 3965 | + } |
|
| 3966 | + |
|
| 3967 | + |
|
| 3968 | + // do check to verify we have a valid status. |
|
| 3969 | + $status = $this->_req_data['status']; |
|
| 3970 | + |
|
| 3971 | + if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3972 | + EE_Error::add_error( |
|
| 3973 | + sprintf( |
|
| 3974 | + esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3975 | + $this->_req_data['status'] |
|
| 3976 | + ), |
|
| 3977 | + __FILE__, |
|
| 3978 | + __FUNCTION__, |
|
| 3979 | + __LINE__ |
|
| 3980 | + ); |
|
| 3981 | + $success = false; |
|
| 3982 | + } |
|
| 3983 | + |
|
| 3984 | + |
|
| 3985 | + // do a nonce check here since we're not arriving via a normal route |
|
| 3986 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3987 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3988 | + |
|
| 3989 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3990 | + |
|
| 3991 | + if ($success) { |
|
| 3992 | + // made it here? um, what are you waiting for then? |
|
| 3993 | + $success = $status === 'deactivate' |
|
| 3994 | + ? $this->_deactivate_message_type_for_messenger( |
|
| 3995 | + $this->_req_data['messenger'], |
|
| 3996 | + $this->_req_data['message_type'] |
|
| 3997 | + ) |
|
| 3998 | + : $this->_activate_message_type_for_messenger( |
|
| 3999 | + $this->_req_data['messenger'], |
|
| 4000 | + $this->_req_data['message_type'] |
|
| 4001 | + ); |
|
| 4002 | + } |
|
| 4003 | + |
|
| 4004 | + $this->_template_args['success'] = $success; |
|
| 4005 | + $this->_return_json(); |
|
| 4006 | + } |
|
| 4007 | + |
|
| 4008 | + |
|
| 4009 | + /** |
|
| 4010 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 4011 | + * |
|
| 4012 | + * @param string $messenger_name The name of the messenger being activated |
|
| 4013 | + * @return bool |
|
| 4014 | + * @throws DomainException |
|
| 4015 | + * @throws EE_Error |
|
| 4016 | + * @throws InvalidArgumentException |
|
| 4017 | + * @throws ReflectionException |
|
| 4018 | + * @throws InvalidDataTypeException |
|
| 4019 | + * @throws InvalidInterfaceException |
|
| 4020 | + */ |
|
| 4021 | + protected function _activate_messenger($messenger_name) |
|
| 4022 | + { |
|
| 4023 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4024 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4025 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 4026 | + ? $active_messenger->get_default_message_types() |
|
| 4027 | + : array(); |
|
| 4028 | + |
|
| 4029 | + // ensure is active |
|
| 4030 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 4031 | + |
|
| 4032 | + // set response_data for reload |
|
| 4033 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 4034 | + /** @var EE_message_type $message_type */ |
|
| 4035 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4036 | + if ( |
|
| 4037 | + $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 4038 | + $messenger_name, |
|
| 4039 | + $message_type_name |
|
| 4040 | + ) |
|
| 4041 | + && $message_type instanceof EE_message_type |
|
| 4042 | + ) { |
|
| 4043 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 4044 | + if ($message_type->get_admin_settings_fields()) { |
|
| 4045 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 4046 | + } |
|
| 4047 | + } |
|
| 4048 | + } |
|
| 4049 | + |
|
| 4050 | + // add success message for activating messenger |
|
| 4051 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 4052 | + } |
|
| 4053 | + |
|
| 4054 | + |
|
| 4055 | + /** |
|
| 4056 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 4057 | + * |
|
| 4058 | + * @param string $messenger_name The name of the messenger being activated |
|
| 4059 | + * @return bool |
|
| 4060 | + * @throws DomainException |
|
| 4061 | + * @throws EE_Error |
|
| 4062 | + * @throws InvalidArgumentException |
|
| 4063 | + * @throws ReflectionException |
|
| 4064 | + * @throws InvalidDataTypeException |
|
| 4065 | + * @throws InvalidInterfaceException |
|
| 4066 | + */ |
|
| 4067 | + protected function _deactivate_messenger($messenger_name) |
|
| 4068 | + { |
|
| 4069 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4070 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4071 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 4072 | + |
|
| 4073 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 4074 | + } |
|
| 4075 | + |
|
| 4076 | + |
|
| 4077 | + /** |
|
| 4078 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 4079 | + * |
|
| 4080 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 4081 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 4082 | + * @return bool |
|
| 4083 | + * @throws DomainException |
|
| 4084 | + * @throws EE_Error |
|
| 4085 | + * @throws InvalidArgumentException |
|
| 4086 | + * @throws ReflectionException |
|
| 4087 | + * @throws InvalidDataTypeException |
|
| 4088 | + * @throws InvalidInterfaceException |
|
| 4089 | + */ |
|
| 4090 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4091 | + { |
|
| 4092 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4093 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4094 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4095 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4096 | + |
|
| 4097 | + // ensure is active |
|
| 4098 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 4099 | + |
|
| 4100 | + // set response for load |
|
| 4101 | + if ( |
|
| 4102 | + $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 4103 | + $messenger_name, |
|
| 4104 | + $message_type_name |
|
| 4105 | + ) |
|
| 4106 | + ) { |
|
| 4107 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 4108 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 4109 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 4110 | + } |
|
| 4111 | + } |
|
| 4112 | + |
|
| 4113 | + return $this->_setup_response_message_for_activating_messenger_with_message_types( |
|
| 4114 | + $active_messenger, |
|
| 4115 | + $message_type_to_activate |
|
| 4116 | + ); |
|
| 4117 | + } |
|
| 4118 | + |
|
| 4119 | + |
|
| 4120 | + /** |
|
| 4121 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 4122 | + * |
|
| 4123 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 4124 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 4125 | + * @return bool |
|
| 4126 | + * @throws DomainException |
|
| 4127 | + * @throws EE_Error |
|
| 4128 | + * @throws InvalidArgumentException |
|
| 4129 | + * @throws ReflectionException |
|
| 4130 | + * @throws InvalidDataTypeException |
|
| 4131 | + * @throws InvalidInterfaceException |
|
| 4132 | + */ |
|
| 4133 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 4134 | + { |
|
| 4135 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 4136 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 4137 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 4138 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 4139 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 4140 | + |
|
| 4141 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4142 | + $active_messenger, |
|
| 4143 | + $message_type_to_deactivate |
|
| 4144 | + ); |
|
| 4145 | + } |
|
| 4146 | + |
|
| 4147 | + |
|
| 4148 | + /** |
|
| 4149 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 4150 | + */ |
|
| 4151 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4152 | + { |
|
| 4153 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 4154 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 4155 | + } |
|
| 4156 | + |
|
| 4157 | + |
|
| 4158 | + /** |
|
| 4159 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 4160 | + * |
|
| 4161 | + * @param EE_messenger $messenger |
|
| 4162 | + * @param EE_message_type|null $message_type |
|
| 4163 | + * @return bool |
|
| 4164 | + * @throws DomainException |
|
| 4165 | + * @throws EE_Error |
|
| 4166 | + * @throws InvalidArgumentException |
|
| 4167 | + * @throws ReflectionException |
|
| 4168 | + * @throws InvalidDataTypeException |
|
| 4169 | + * @throws InvalidInterfaceException |
|
| 4170 | + */ |
|
| 4171 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4172 | + $messenger, |
|
| 4173 | + EE_Message_Type $message_type = null |
|
| 4174 | + ) { |
|
| 4175 | + // if $messenger isn't a valid messenger object then get out. |
|
| 4176 | + if (! $messenger instanceof EE_Messenger) { |
|
| 4177 | + EE_Error::add_error( |
|
| 4178 | + esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4179 | + __FILE__, |
|
| 4180 | + __FUNCTION__, |
|
| 4181 | + __LINE__ |
|
| 4182 | + ); |
|
| 4183 | + |
|
| 4184 | + return false; |
|
| 4185 | + } |
|
| 4186 | + // activated |
|
| 4187 | + if ($this->_template_args['data']['active_mts']) { |
|
| 4188 | + EE_Error::overwrite_success(); |
|
| 4189 | + // activated a message type with the messenger |
|
| 4190 | + if ($message_type instanceof EE_message_type) { |
|
| 4191 | + EE_Error::add_success( |
|
| 4192 | + sprintf( |
|
| 4193 | + esc_html__( |
|
| 4194 | + '%s message type has been successfully activated with the %s messenger', |
|
| 4195 | + 'event_espresso' |
|
| 4196 | + ), |
|
| 4197 | + ucwords($message_type->label['singular']), |
|
| 4198 | + ucwords($messenger->label['singular']) |
|
| 4199 | + ) |
|
| 4200 | + ); |
|
| 4201 | + |
|
| 4202 | + // if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4203 | + if ($message_type->name === 'invoice') { |
|
| 4204 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4205 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4206 | + if ($pm instanceof EE_Payment_Method) { |
|
| 4207 | + EE_Error::add_attention( |
|
| 4208 | + esc_html__( |
|
| 4209 | + 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4210 | + 'event_espresso' |
|
| 4211 | + ) |
|
| 4212 | + ); |
|
| 4213 | + } |
|
| 4214 | + } |
|
| 4215 | + // just toggles the entire messenger |
|
| 4216 | + } else { |
|
| 4217 | + EE_Error::add_success( |
|
| 4218 | + sprintf( |
|
| 4219 | + esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4220 | + ucwords($messenger->label['singular']) |
|
| 4221 | + ) |
|
| 4222 | + ); |
|
| 4223 | + } |
|
| 4224 | + |
|
| 4225 | + return true; |
|
| 4226 | + |
|
| 4227 | + // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4228 | + // message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4229 | + // in which case we just give a success message for the messenger being successfully activated. |
|
| 4230 | + } else { |
|
| 4231 | + if (! $messenger->get_default_message_types()) { |
|
| 4232 | + // messenger doesn't have any default message types so still a success. |
|
| 4233 | + EE_Error::add_success( |
|
| 4234 | + sprintf( |
|
| 4235 | + esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4236 | + ucwords($messenger->label['singular']) |
|
| 4237 | + ) |
|
| 4238 | + ); |
|
| 4239 | + |
|
| 4240 | + return true; |
|
| 4241 | + } else { |
|
| 4242 | + EE_Error::add_error( |
|
| 4243 | + $message_type instanceof EE_message_type |
|
| 4244 | + ? sprintf( |
|
| 4245 | + esc_html__( |
|
| 4246 | + '%s message type was not successfully activated with the %s messenger', |
|
| 4247 | + 'event_espresso' |
|
| 4248 | + ), |
|
| 4249 | + ucwords($message_type->label['singular']), |
|
| 4250 | + ucwords($messenger->label['singular']) |
|
| 4251 | + ) |
|
| 4252 | + : sprintf( |
|
| 4253 | + esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4254 | + ucwords($messenger->label['singular']) |
|
| 4255 | + ), |
|
| 4256 | + __FILE__, |
|
| 4257 | + __FUNCTION__, |
|
| 4258 | + __LINE__ |
|
| 4259 | + ); |
|
| 4260 | + |
|
| 4261 | + return false; |
|
| 4262 | + } |
|
| 4263 | + } |
|
| 4264 | + } |
|
| 4265 | + |
|
| 4266 | + |
|
| 4267 | + /** |
|
| 4268 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4269 | + * |
|
| 4270 | + * @param EE_messenger $messenger |
|
| 4271 | + * @param EE_message_type|null $message_type |
|
| 4272 | + * @return bool |
|
| 4273 | + * @throws DomainException |
|
| 4274 | + * @throws EE_Error |
|
| 4275 | + * @throws InvalidArgumentException |
|
| 4276 | + * @throws ReflectionException |
|
| 4277 | + * @throws InvalidDataTypeException |
|
| 4278 | + * @throws InvalidInterfaceException |
|
| 4279 | + */ |
|
| 4280 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4281 | + $messenger, |
|
| 4282 | + EE_message_type $message_type = null |
|
| 4283 | + ) { |
|
| 4284 | + EE_Error::overwrite_success(); |
|
| 4285 | + |
|
| 4286 | + // if $messenger isn't a valid messenger object then get out. |
|
| 4287 | + if (! $messenger instanceof EE_Messenger) { |
|
| 4288 | + EE_Error::add_error( |
|
| 4289 | + esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4290 | + __FILE__, |
|
| 4291 | + __FUNCTION__, |
|
| 4292 | + __LINE__ |
|
| 4293 | + ); |
|
| 4294 | + |
|
| 4295 | + return false; |
|
| 4296 | + } |
|
| 4297 | + |
|
| 4298 | + if ($message_type instanceof EE_message_type) { |
|
| 4299 | + $message_type_name = $message_type->name; |
|
| 4300 | + EE_Error::add_success( |
|
| 4301 | + sprintf( |
|
| 4302 | + esc_html__( |
|
| 4303 | + '%s message type has been successfully deactivated for the %s messenger.', |
|
| 4304 | + 'event_espresso' |
|
| 4305 | + ), |
|
| 4306 | + ucwords($message_type->label['singular']), |
|
| 4307 | + ucwords($messenger->label['singular']) |
|
| 4308 | + ) |
|
| 4309 | + ); |
|
| 4310 | + } else { |
|
| 4311 | + $message_type_name = ''; |
|
| 4312 | + EE_Error::add_success( |
|
| 4313 | + sprintf( |
|
| 4314 | + esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4315 | + ucwords($messenger->label['singular']) |
|
| 4316 | + ) |
|
| 4317 | + ); |
|
| 4318 | + } |
|
| 4319 | + |
|
| 4320 | + // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4321 | + if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4322 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4323 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4324 | + if ($count_updated > 0) { |
|
| 4325 | + $msg = $message_type_name === 'invoice' |
|
| 4326 | + ? esc_html__( |
|
| 4327 | + 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4328 | + 'event_espresso' |
|
| 4329 | + ) |
|
| 4330 | + : esc_html__( |
|
| 4331 | + 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4332 | + 'event_espresso' |
|
| 4333 | + ); |
|
| 4334 | + EE_Error::add_attention($msg); |
|
| 4335 | + } |
|
| 4336 | + } |
|
| 4337 | + |
|
| 4338 | + return true; |
|
| 4339 | + } |
|
| 4340 | + |
|
| 4341 | + |
|
| 4342 | + /** |
|
| 4343 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4344 | + * |
|
| 4345 | + * @throws DomainException |
|
| 4346 | + */ |
|
| 4347 | + public function update_mt_form() |
|
| 4348 | + { |
|
| 4349 | + if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4350 | + EE_Error::add_error( |
|
| 4351 | + esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4352 | + __FILE__, |
|
| 4353 | + __FUNCTION__, |
|
| 4354 | + __LINE__ |
|
| 4355 | + ); |
|
| 4356 | + $this->_return_json(); |
|
| 4357 | + } |
|
| 4358 | + |
|
| 4359 | + $message_types = $this->get_installed_message_types(); |
|
| 4360 | + |
|
| 4361 | + $message_type = $message_types[ $this->_req_data['message_type'] ]; |
|
| 4362 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4363 | + |
|
| 4364 | + $content = $this->_message_type_settings_content( |
|
| 4365 | + $message_type, |
|
| 4366 | + $messenger, |
|
| 4367 | + true |
|
| 4368 | + ); |
|
| 4369 | + $this->_template_args['success'] = true; |
|
| 4370 | + $this->_template_args['content'] = $content; |
|
| 4371 | + $this->_return_json(); |
|
| 4372 | + } |
|
| 4373 | + |
|
| 4374 | + |
|
| 4375 | + /** |
|
| 4376 | + * this handles saving the settings for a messenger or message type |
|
| 4377 | + * |
|
| 4378 | + */ |
|
| 4379 | + public function save_settings() |
|
| 4380 | + { |
|
| 4381 | + if (! isset($this->_req_data['type'])) { |
|
| 4382 | + EE_Error::add_error( |
|
| 4383 | + esc_html__( |
|
| 4384 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4385 | + 'event_espresso' |
|
| 4386 | + ), |
|
| 4387 | + __FILE__, |
|
| 4388 | + __FUNCTION__, |
|
| 4389 | + __LINE__ |
|
| 4390 | + ); |
|
| 4391 | + $this->_template_args['error'] = true; |
|
| 4392 | + $this->_return_json(); |
|
| 4393 | + } |
|
| 4394 | + |
|
| 4395 | + |
|
| 4396 | + if ($this->_req_data['type'] === 'messenger') { |
|
| 4397 | + // this should be an array. |
|
| 4398 | + $settings = $this->_req_data['messenger_settings']; |
|
| 4399 | + $messenger = $settings['messenger']; |
|
| 4400 | + // let's setup the settings data |
|
| 4401 | + foreach ($settings as $key => $value) { |
|
| 4402 | + switch ($key) { |
|
| 4403 | + case 'messenger': |
|
| 4404 | + unset($settings['messenger']); |
|
| 4405 | + break; |
|
| 4406 | + case 'message_types': |
|
| 4407 | + unset($settings['message_types']); |
|
| 4408 | + break; |
|
| 4409 | + default: |
|
| 4410 | + $settings[ $key ] = $value; |
|
| 4411 | + break; |
|
| 4412 | + } |
|
| 4413 | + } |
|
| 4414 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4415 | + } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4416 | + $settings = $this->_req_data['message_type_settings']; |
|
| 4417 | + $messenger = $settings['messenger']; |
|
| 4418 | + $message_type = $settings['message_type']; |
|
| 4419 | + |
|
| 4420 | + foreach ($settings as $key => $value) { |
|
| 4421 | + switch ($key) { |
|
| 4422 | + case 'messenger': |
|
| 4423 | + unset($settings['messenger']); |
|
| 4424 | + break; |
|
| 4425 | + case 'message_type': |
|
| 4426 | + unset($settings['message_type']); |
|
| 4427 | + break; |
|
| 4428 | + default: |
|
| 4429 | + $settings[ $key ] = $value; |
|
| 4430 | + break; |
|
| 4431 | + } |
|
| 4432 | + } |
|
| 4433 | + |
|
| 4434 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4435 | + } |
|
| 4436 | + |
|
| 4437 | + // okay we should have the data all setup. Now we just update! |
|
| 4438 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4439 | + |
|
| 4440 | + if ($success) { |
|
| 4441 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4442 | + } else { |
|
| 4443 | + EE_Error::add_error( |
|
| 4444 | + esc_html__( |
|
| 4445 | + 'Settings did not get updated', |
|
| 4446 | + 'event_espresso' |
|
| 4447 | + ), |
|
| 4448 | + __FILE__, |
|
| 4449 | + __FUNCTION__, |
|
| 4450 | + __LINE__ |
|
| 4451 | + ); |
|
| 4452 | + } |
|
| 4453 | + |
|
| 4454 | + $this->_template_args['success'] = $success; |
|
| 4455 | + $this->_return_json(); |
|
| 4456 | + } |
|
| 4457 | + |
|
| 4458 | + |
|
| 4459 | + |
|
| 4460 | + |
|
| 4461 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4462 | + |
|
| 4463 | + |
|
| 4464 | + /** |
|
| 4465 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4466 | + * However, this does not send immediately, it just queues for sending. |
|
| 4467 | + * |
|
| 4468 | + * @since 4.9.0 |
|
| 4469 | + * @throws EE_Error |
|
| 4470 | + * @throws InvalidDataTypeException |
|
| 4471 | + * @throws InvalidInterfaceException |
|
| 4472 | + * @throws InvalidArgumentException |
|
| 4473 | + * @throws ReflectionException |
|
| 4474 | + */ |
|
| 4475 | + protected function _generate_now() |
|
| 4476 | + { |
|
| 4477 | + EED_Messages::generate_now($this->_get_msg_ids_from_request()); |
|
| 4478 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4479 | + } |
|
| 4480 | + |
|
| 4481 | + |
|
| 4482 | + /** |
|
| 4483 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4484 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4485 | + * |
|
| 4486 | + * @since 4.9.0 |
|
| 4487 | + * @throws EE_Error |
|
| 4488 | + * @throws InvalidDataTypeException |
|
| 4489 | + * @throws InvalidInterfaceException |
|
| 4490 | + * @throws InvalidArgumentException |
|
| 4491 | + * @throws ReflectionException |
|
| 4492 | + */ |
|
| 4493 | + protected function _generate_and_send_now() |
|
| 4494 | + { |
|
| 4495 | + EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request()); |
|
| 4496 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4497 | + } |
|
| 4498 | + |
|
| 4499 | + |
|
| 4500 | + /** |
|
| 4501 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4502 | + * |
|
| 4503 | + * @since 4.9.0 |
|
| 4504 | + * @throws EE_Error |
|
| 4505 | + * @throws InvalidDataTypeException |
|
| 4506 | + * @throws InvalidInterfaceException |
|
| 4507 | + * @throws InvalidArgumentException |
|
| 4508 | + * @throws ReflectionException |
|
| 4509 | + */ |
|
| 4510 | + protected function _queue_for_resending() |
|
| 4511 | + { |
|
| 4512 | + EED_Messages::queue_for_resending($this->_get_msg_ids_from_request()); |
|
| 4513 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4514 | + } |
|
| 4515 | + |
|
| 4516 | + |
|
| 4517 | + /** |
|
| 4518 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4519 | + * |
|
| 4520 | + * @since 4.9.0 |
|
| 4521 | + * @throws EE_Error |
|
| 4522 | + * @throws InvalidDataTypeException |
|
| 4523 | + * @throws InvalidInterfaceException |
|
| 4524 | + * @throws InvalidArgumentException |
|
| 4525 | + * @throws ReflectionException |
|
| 4526 | + */ |
|
| 4527 | + protected function _send_now() |
|
| 4528 | + { |
|
| 4529 | + EED_Messages::send_now($this->_get_msg_ids_from_request()); |
|
| 4530 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4531 | + } |
|
| 4532 | + |
|
| 4533 | + |
|
| 4534 | + /** |
|
| 4535 | + * Deletes EE_messages for IDs in the request. |
|
| 4536 | + * |
|
| 4537 | + * @since 4.9.0 |
|
| 4538 | + * @throws EE_Error |
|
| 4539 | + * @throws InvalidDataTypeException |
|
| 4540 | + * @throws InvalidInterfaceException |
|
| 4541 | + * @throws InvalidArgumentException |
|
| 4542 | + */ |
|
| 4543 | + protected function _delete_ee_messages() |
|
| 4544 | + { |
|
| 4545 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4546 | + $deleted_count = 0; |
|
| 4547 | + foreach ($msg_ids as $msg_id) { |
|
| 4548 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4549 | + $deleted_count++; |
|
| 4550 | + } |
|
| 4551 | + } |
|
| 4552 | + if ($deleted_count) { |
|
| 4553 | + EE_Error::add_success( |
|
| 4554 | + esc_html( |
|
| 4555 | + _n( |
|
| 4556 | + 'Message successfully deleted', |
|
| 4557 | + 'Messages successfully deleted', |
|
| 4558 | + $deleted_count, |
|
| 4559 | + 'event_espresso' |
|
| 4560 | + ) |
|
| 4561 | + ) |
|
| 4562 | + ); |
|
| 4563 | + $this->_redirect_after_action( |
|
| 4564 | + false, |
|
| 4565 | + '', |
|
| 4566 | + '', |
|
| 4567 | + array(), |
|
| 4568 | + true |
|
| 4569 | + ); |
|
| 4570 | + } else { |
|
| 4571 | + EE_Error::add_error( |
|
| 4572 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4573 | + __FILE__, |
|
| 4574 | + __FUNCTION__, |
|
| 4575 | + __LINE__ |
|
| 4576 | + ); |
|
| 4577 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4578 | + } |
|
| 4579 | + } |
|
| 4580 | + |
|
| 4581 | + |
|
| 4582 | + /** |
|
| 4583 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4584 | + * |
|
| 4585 | + * @since 4.9.0 |
|
| 4586 | + * @return array |
|
| 4587 | + */ |
|
| 4588 | + protected function _get_msg_ids_from_request() |
|
| 4589 | + { |
|
| 4590 | + if (! isset($this->_req_data['MSG_ID'])) { |
|
| 4591 | + return array(); |
|
| 4592 | + } |
|
| 4593 | + |
|
| 4594 | + return is_array($this->_req_data['MSG_ID']) |
|
| 4595 | + ? array_keys($this->_req_data['MSG_ID']) |
|
| 4596 | + : array($this->_req_data['MSG_ID']); |
|
| 4597 | + } |
|
| 4598 | 4598 | } |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | $i = 1; |
| 142 | 142 | foreach ($active_messengers as $active_messenger) { |
| 143 | 143 | if ($active_messenger instanceof EE_Message) { |
| 144 | - $m_values[ $i ]['id'] = $active_messenger->messenger(); |
|
| 145 | - $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 144 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 145 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 146 | 146 | $i++; |
| 147 | 147 | } |
| 148 | 148 | } |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | $i = 1; |
| 179 | 179 | foreach ($active_messages as $active_message) { |
| 180 | 180 | if ($active_message instanceof EE_Message) { |
| 181 | - $mt_values[ $i ]['id'] = $active_message->message_type(); |
|
| 182 | - $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label()); |
|
| 181 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 182 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 183 | 183 | $i++; |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | if ($message_type instanceof EE_message_type) { |
| 219 | 219 | $message_type_contexts = $message_type->get_contexts(); |
| 220 | 220 | foreach ($message_type_contexts as $context => $context_details) { |
| 221 | - $contexts[ $context ] = $context_details['label']; |
|
| 221 | + $contexts[$context] = $context_details['label']; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
@@ -712,53 +712,53 @@ discard block |
||
| 712 | 712 | |
| 713 | 713 | public function messages_help_tab() |
| 714 | 714 | { |
| 715 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 715 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | |
| 719 | 719 | public function messengers_help_tab() |
| 720 | 720 | { |
| 721 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 721 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | |
| 725 | 725 | public function message_types_help_tab() |
| 726 | 726 | { |
| 727 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 727 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | |
| 731 | 731 | public function messages_overview_help_tab() |
| 732 | 732 | { |
| 733 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 733 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | |
| 737 | 737 | public function message_templates_help_tab() |
| 738 | 738 | { |
| 739 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 739 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | |
| 743 | 743 | public function edit_message_template_help_tab() |
| 744 | 744 | { |
| 745 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 745 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="' |
|
| 746 | 746 | . esc_attr__('Editor Title', 'event_espresso') |
| 747 | 747 | . '" />'; |
| 748 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 748 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="' |
|
| 749 | 749 | . esc_attr__('Context Switcher and Preview', 'event_espresso') |
| 750 | 750 | . '" />'; |
| 751 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 751 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="' |
|
| 752 | 752 | . esc_attr__('Message Template Form Fields', 'event_espresso') |
| 753 | 753 | . '" />'; |
| 754 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 754 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="' |
|
| 755 | 755 | . esc_attr__('Shortcodes Metabox', 'event_espresso') |
| 756 | 756 | . '" />'; |
| 757 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 757 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="' |
|
| 758 | 758 | . esc_attr__('Publish Metabox', 'event_espresso') |
| 759 | 759 | . '" />'; |
| 760 | 760 | EEH_Template::display_template( |
| 761 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 761 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 762 | 762 | $args |
| 763 | 763 | ); |
| 764 | 764 | } |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | $this->_set_shortcodes(); |
| 770 | 770 | $args['shortcodes'] = $this->_shortcodes; |
| 771 | 771 | EEH_Template::display_template( |
| 772 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 772 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 773 | 773 | $args |
| 774 | 774 | ); |
| 775 | 775 | } |
@@ -777,16 +777,16 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | public function preview_message_help_tab() |
| 779 | 779 | { |
| 780 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 780 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | |
| 784 | 784 | public function settings_help_tab() |
| 785 | 785 | { |
| 786 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 787 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 788 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 789 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 786 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png' |
|
| 787 | + . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'; |
|
| 788 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
| 789 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'; |
|
| 790 | 790 | $args['img3'] = '<div class="switch">' |
| 791 | 791 | . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
| 792 | 792 | . ' type="checkbox" checked="checked">' |
@@ -797,25 +797,25 @@ discard block |
||
| 797 | 797 | . ' type="checkbox">' |
| 798 | 798 | . '<label for="ee-on-off-toggle-on"></label>' |
| 799 | 799 | . '</div>'; |
| 800 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 800 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | |
| 804 | 804 | public function load_scripts_styles() |
| 805 | 805 | { |
| 806 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 806 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 807 | 807 | wp_enqueue_style('espresso_ee_msg'); |
| 808 | 808 | |
| 809 | 809 | wp_register_script( |
| 810 | 810 | 'ee-messages-settings', |
| 811 | - EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 811 | + EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 812 | 812 | array('jquery-ui-droppable', 'ee-serialize-full-array'), |
| 813 | 813 | EVENT_ESPRESSO_VERSION, |
| 814 | 814 | true |
| 815 | 815 | ); |
| 816 | 816 | wp_register_script( |
| 817 | 817 | 'ee-msg-list-table-js', |
| 818 | - EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 818 | + EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 819 | 819 | array('ee-dialog'), |
| 820 | 820 | EVENT_ESPRESSO_VERSION |
| 821 | 821 | ); |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | |
| 874 | 874 | wp_register_script( |
| 875 | 875 | 'ee_msgs_edit_js', |
| 876 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 876 | + EE_MSG_ASSETS_URL.'ee_message_editor.js', |
|
| 877 | 877 | array('jquery'), |
| 878 | 878 | EVENT_ESPRESSO_VERSION |
| 879 | 879 | ); |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | { |
| 918 | 918 | wp_register_style( |
| 919 | 919 | 'ee-message-settings', |
| 920 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 920 | + EE_MSG_ASSETS_URL.'ee_message_settings.css', |
|
| 921 | 921 | array(), |
| 922 | 922 | EVENT_ESPRESSO_VERSION |
| 923 | 923 | ); |
@@ -1003,7 +1003,7 @@ discard block |
||
| 1003 | 1003 | } |
| 1004 | 1004 | $status_bulk_actions = $common_bulk_actions; |
| 1005 | 1005 | // unset bulk actions not applying to status |
| 1006 | - if (! empty($status_bulk_actions)) { |
|
| 1006 | + if ( ! empty($status_bulk_actions)) { |
|
| 1007 | 1007 | switch ($status) { |
| 1008 | 1008 | case EEM_Message::status_idle: |
| 1009 | 1009 | case EEM_Message::status_resend: |
@@ -1032,7 +1032,7 @@ discard block |
||
| 1032 | 1032 | continue; |
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | - $this->_views[ strtolower($status) ] = array( |
|
| 1035 | + $this->_views[strtolower($status)] = array( |
|
| 1036 | 1036 | 'slug' => strtolower($status), |
| 1037 | 1037 | 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
| 1038 | 1038 | 'count' => 0, |
@@ -1071,7 +1071,7 @@ discard block |
||
| 1071 | 1071 | if ($action_item === 'see_notifications_for') { |
| 1072 | 1072 | continue; |
| 1073 | 1073 | } |
| 1074 | - $action_items[ $action_item ] = array( |
|
| 1074 | + $action_items[$action_item] = array( |
|
| 1075 | 1075 | 'class' => $action_details['css_class'], |
| 1076 | 1076 | 'desc' => $action_details['label'], |
| 1077 | 1077 | ); |
@@ -1080,37 +1080,37 @@ discard block |
||
| 1080 | 1080 | /** @type array $status_items status legend setup */ |
| 1081 | 1081 | $status_items = array( |
| 1082 | 1082 | 'incomplete_status' => array( |
| 1083 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1083 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 1084 | 1084 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'), |
| 1085 | 1085 | ), |
| 1086 | 1086 | 'idle_status' => array( |
| 1087 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1087 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 1088 | 1088 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'), |
| 1089 | 1089 | ), |
| 1090 | 1090 | 'resend_status' => array( |
| 1091 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1091 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 1092 | 1092 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'), |
| 1093 | 1093 | ), |
| 1094 | 1094 | 'messenger_executing_status' => array( |
| 1095 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1095 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 1096 | 1096 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'), |
| 1097 | 1097 | ), |
| 1098 | 1098 | 'sent_status' => array( |
| 1099 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1099 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 1100 | 1100 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'), |
| 1101 | 1101 | ), |
| 1102 | 1102 | 'retry_status' => array( |
| 1103 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1103 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 1104 | 1104 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'), |
| 1105 | 1105 | ), |
| 1106 | 1106 | 'failed_status' => array( |
| 1107 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1107 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 1108 | 1108 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'), |
| 1109 | 1109 | ), |
| 1110 | 1110 | ); |
| 1111 | 1111 | if (EEM_Message::debug()) { |
| 1112 | 1112 | $status_items['debug_only_status'] = array( |
| 1113 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1113 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1114 | 1114 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'), |
| 1115 | 1115 | ); |
| 1116 | 1116 | } |
@@ -1122,11 +1122,11 @@ discard block |
||
| 1122 | 1122 | protected function _custom_mtps_preview() |
| 1123 | 1123 | { |
| 1124 | 1124 | $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
| 1125 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1126 | - . ' alt="' . esc_attr__( |
|
| 1125 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"' |
|
| 1126 | + . ' alt="'.esc_attr__( |
|
| 1127 | 1127 | 'Preview Custom Message Templates screenshot', |
| 1128 | 1128 | 'event_espresso' |
| 1129 | - ) . '" />'; |
|
| 1129 | + ).'" />'; |
|
| 1130 | 1130 | $this->_template_args['preview_text'] = '<strong>' |
| 1131 | 1131 | . esc_html__( |
| 1132 | 1132 | 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | $installed = array(); |
| 1207 | 1207 | |
| 1208 | 1208 | foreach ($installed_message_types as $message_type) { |
| 1209 | - $installed[ $message_type->name ] = $message_type; |
|
| 1209 | + $installed[$message_type->name] = $message_type; |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | return $installed; |
@@ -1355,7 +1355,7 @@ discard block |
||
| 1355 | 1355 | // we need to assemble the title from Various details |
| 1356 | 1356 | $context_label = sprintf( |
| 1357 | 1357 | esc_html__('(%s %s)', 'event_espresso'), |
| 1358 | - $c_config[ $context ]['label'], |
|
| 1358 | + $c_config[$context]['label'], |
|
| 1359 | 1359 | ucwords($c_label['label']) |
| 1360 | 1360 | ); |
| 1361 | 1361 | |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | $message_template_group->message_type() |
| 1378 | 1378 | ); |
| 1379 | 1379 | |
| 1380 | - if (! $template_field_structure) { |
|
| 1380 | + if ( ! $template_field_structure) { |
|
| 1381 | 1381 | $template_field_structure = false; |
| 1382 | 1382 | $template_fields = esc_html__( |
| 1383 | 1383 | 'There was an error in assembling the fields for this display (you should see an error message)', |
@@ -1391,21 +1391,21 @@ discard block |
||
| 1391 | 1391 | |
| 1392 | 1392 | // if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
| 1393 | 1393 | // will get handled in the "extra" array. |
| 1394 | - if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { |
|
| 1395 | - foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { |
|
| 1396 | - unset($template_field_structure[ $context ][ $reference_field ]); |
|
| 1394 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1395 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1396 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1397 | 1397 | } |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | 1400 | // let's loop through the template_field_structure and actually assemble the input fields! |
| 1401 | - if (! empty($template_field_structure)) { |
|
| 1402 | - foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { |
|
| 1401 | + if ( ! empty($template_field_structure)) { |
|
| 1402 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1403 | 1403 | // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
| 1404 | 1404 | // the extra array and reset them. |
| 1405 | 1405 | if ($template_field === 'extra') { |
| 1406 | 1406 | $this->_template_args['is_extra_fields'] = true; |
| 1407 | 1407 | foreach ($field_setup_array as $reference_field => $new_fields_array) { |
| 1408 | - $message_template = $message_templates[ $context ][ $reference_field ]; |
|
| 1408 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1409 | 1409 | $content = $message_template instanceof EE_Message_Template |
| 1410 | 1410 | ? $message_template->get('MTP_content') |
| 1411 | 1411 | : ''; |
@@ -1414,7 +1414,7 @@ discard block |
||
| 1414 | 1414 | $continue = false; |
| 1415 | 1415 | if (isset($extra_array['shortcodes_required'])) { |
| 1416 | 1416 | foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
| 1417 | - if (! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1417 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1418 | 1418 | $continue = true; |
| 1419 | 1419 | } |
| 1420 | 1420 | } |
@@ -1427,57 +1427,57 @@ discard block |
||
| 1427 | 1427 | . '-' |
| 1428 | 1428 | . $extra_field |
| 1429 | 1429 | . '-content'; |
| 1430 | - $template_form_fields[ $field_id ] = $extra_array; |
|
| 1431 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' |
|
| 1430 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1431 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1432 | 1432 | . $reference_field |
| 1433 | 1433 | . '][content][' |
| 1434 | - . $extra_field . ']'; |
|
| 1434 | + . $extra_field.']'; |
|
| 1435 | 1435 | $css_class = isset($extra_array['css_class']) |
| 1436 | 1436 | ? $extra_array['css_class'] |
| 1437 | 1437 | : ''; |
| 1438 | 1438 | |
| 1439 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) |
|
| 1439 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1440 | 1440 | && in_array($extra_field, $v_fields, true) |
| 1441 | 1441 | && |
| 1442 | 1442 | ( |
| 1443 | - is_array($validators[ $extra_field ]) |
|
| 1444 | - && isset($validators[ $extra_field ]['msg']) |
|
| 1443 | + is_array($validators[$extra_field]) |
|
| 1444 | + && isset($validators[$extra_field]['msg']) |
|
| 1445 | 1445 | ) |
| 1446 | - ? 'validate-error ' . $css_class |
|
| 1446 | + ? 'validate-error '.$css_class |
|
| 1447 | 1447 | : $css_class; |
| 1448 | 1448 | |
| 1449 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) |
|
| 1450 | - && isset($content[ $extra_field ]) |
|
| 1451 | - ? $content[ $extra_field ] |
|
| 1449 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1450 | + && isset($content[$extra_field]) |
|
| 1451 | + ? $content[$extra_field] |
|
| 1452 | 1452 | : ''; |
| 1453 | 1453 | |
| 1454 | 1454 | // do we have a validation error? if we do then let's use that value instead |
| 1455 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ]) |
|
| 1456 | - ? $validators[ $extra_field ]['value'] |
|
| 1457 | - : $template_form_fields[ $field_id ]['value']; |
|
| 1455 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1456 | + ? $validators[$extra_field]['value'] |
|
| 1457 | + : $template_form_fields[$field_id]['value']; |
|
| 1458 | 1458 | |
| 1459 | 1459 | |
| 1460 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; |
|
| 1460 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1461 | 1461 | |
| 1462 | 1462 | // shortcode selector |
| 1463 | 1463 | $field_name_to_use = $extra_field === 'main' |
| 1464 | 1464 | ? 'content' |
| 1465 | 1465 | : $extra_field; |
| 1466 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( |
|
| 1466 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1467 | 1467 | $field_name_to_use, |
| 1468 | 1468 | $field_id |
| 1469 | 1469 | ); |
| 1470 | 1470 | |
| 1471 | 1471 | if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
| 1472 | 1472 | // we want to decode the entities |
| 1473 | - $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value']; |
|
| 1473 | + $template_form_fields[$field_id]['value'] = $template_form_fields[$field_id]['value']; |
|
| 1474 | 1474 | }/**/ |
| 1475 | 1475 | } |
| 1476 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1477 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1476 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1477 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1478 | 1478 | |
| 1479 | - $template_form_fields[ $templatefield_MTP_id ] = array( |
|
| 1480 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1479 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1480 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1481 | 1481 | 'label' => null, |
| 1482 | 1482 | 'input' => 'hidden', |
| 1483 | 1483 | 'type' => 'int', |
@@ -1489,8 +1489,8 @@ discard block |
||
| 1489 | 1489 | 'db-col' => 'MTP_ID', |
| 1490 | 1490 | ); |
| 1491 | 1491 | |
| 1492 | - $template_form_fields[ $templatefield_templatename_id ] = array( |
|
| 1493 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1492 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1493 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1494 | 1494 | 'label' => null, |
| 1495 | 1495 | 'input' => 'hidden', |
| 1496 | 1496 | 'type' => 'string', |
@@ -1504,36 +1504,36 @@ discard block |
||
| 1504 | 1504 | } |
| 1505 | 1505 | continue; // skip the next stuff, we got the necessary fields here for this dataset. |
| 1506 | 1506 | } else { |
| 1507 | - $field_id = $template_field . '-content'; |
|
| 1508 | - $template_form_fields[ $field_id ] = $field_setup_array; |
|
| 1509 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1510 | - $message_template = isset($message_templates[ $context ][ $template_field ]) |
|
| 1511 | - ? $message_templates[ $context ][ $template_field ] |
|
| 1507 | + $field_id = $template_field.'-content'; |
|
| 1508 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1509 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1510 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1511 | + ? $message_templates[$context][$template_field] |
|
| 1512 | 1512 | : null; |
| 1513 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) |
|
| 1514 | - && is_array($message_templates[ $context ]) |
|
| 1513 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1514 | + && is_array($message_templates[$context]) |
|
| 1515 | 1515 | && $message_template instanceof EE_Message_Template |
| 1516 | 1516 | ? $message_template->get('MTP_content') |
| 1517 | 1517 | : ''; |
| 1518 | 1518 | |
| 1519 | 1519 | // do we have a validator error for this field? if we do then we'll use that value instead |
| 1520 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ]) |
|
| 1521 | - ? $validators[ $template_field ]['value'] |
|
| 1522 | - : $template_form_fields[ $field_id ]['value']; |
|
| 1520 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1521 | + ? $validators[$template_field]['value'] |
|
| 1522 | + : $template_form_fields[$field_id]['value']; |
|
| 1523 | 1523 | |
| 1524 | 1524 | |
| 1525 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; |
|
| 1525 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1526 | 1526 | $css_class = isset($field_setup_array['css_class']) |
| 1527 | 1527 | ? $field_setup_array['css_class'] |
| 1528 | 1528 | : ''; |
| 1529 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) |
|
| 1529 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1530 | 1530 | && in_array($template_field, $v_fields, true) |
| 1531 | - && isset($validators[ $template_field ]['msg']) |
|
| 1532 | - ? 'validate-error ' . $css_class |
|
| 1531 | + && isset($validators[$template_field]['msg']) |
|
| 1532 | + ? 'validate-error '.$css_class |
|
| 1533 | 1533 | : $css_class; |
| 1534 | 1534 | |
| 1535 | 1535 | // shortcode selector |
| 1536 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector( |
|
| 1536 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1537 | 1537 | $template_field, |
| 1538 | 1538 | $field_id |
| 1539 | 1539 | ); |
@@ -1541,12 +1541,12 @@ discard block |
||
| 1541 | 1541 | |
| 1542 | 1542 | // k took care of content field(s) now let's take care of others. |
| 1543 | 1543 | |
| 1544 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1545 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1544 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1545 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1546 | 1546 | |
| 1547 | 1547 | // foreach template field there are actually two form fields created |
| 1548 | - $template_form_fields[ $templatefield_MTP_id ] = array( |
|
| 1549 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1548 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1549 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1550 | 1550 | 'label' => null, |
| 1551 | 1551 | 'input' => 'hidden', |
| 1552 | 1552 | 'type' => 'int', |
@@ -1558,8 +1558,8 @@ discard block |
||
| 1558 | 1558 | 'db-col' => 'MTP_ID', |
| 1559 | 1559 | ); |
| 1560 | 1560 | |
| 1561 | - $template_form_fields[ $templatefield_field_templatename_id ] = array( |
|
| 1562 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1561 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1562 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1563 | 1563 | 'label' => null, |
| 1564 | 1564 | 'input' => 'hidden', |
| 1565 | 1565 | 'type' => 'string', |
@@ -1702,10 +1702,10 @@ discard block |
||
| 1702 | 1702 | 'value' => $GRP_ID, |
| 1703 | 1703 | ); |
| 1704 | 1704 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1705 | - 'name' => $action . '_nonce', |
|
| 1705 | + 'name' => $action.'_nonce', |
|
| 1706 | 1706 | 'input' => 'hidden', |
| 1707 | 1707 | 'type' => 'string', |
| 1708 | - 'value' => wp_create_nonce($action . '_nonce'), |
|
| 1708 | + 'value' => wp_create_nonce($action.'_nonce'), |
|
| 1709 | 1709 | ); |
| 1710 | 1710 | |
| 1711 | 1711 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1746,7 +1746,7 @@ discard block |
||
| 1746 | 1746 | ), |
| 1747 | 1747 | $this->_admin_base_url |
| 1748 | 1748 | ); |
| 1749 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1749 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">' |
|
| 1750 | 1750 | . esc_html__('Preview', 'event_espresso') |
| 1751 | 1751 | . '</a>'; |
| 1752 | 1752 | |
@@ -1784,7 +1784,7 @@ discard block |
||
| 1784 | 1784 | |
| 1785 | 1785 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1786 | 1786 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
| 1787 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1787 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1788 | 1788 | |
| 1789 | 1789 | // send along EE_Message_Template_Group object for further template use. |
| 1790 | 1790 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1839,7 +1839,7 @@ discard block |
||
| 1839 | 1839 | ) { |
| 1840 | 1840 | $template_args = array( |
| 1841 | 1841 | 'context' => $context, |
| 1842 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1842 | + 'nonce' => wp_create_nonce('activate_'.$context.'_toggle_nonce'), |
|
| 1843 | 1843 | 'is_active' => $message_template_group->is_context_active($context), |
| 1844 | 1844 | 'on_off_action' => $message_template_group->is_context_active($context) |
| 1845 | 1845 | ? 'context-off' |
@@ -1848,7 +1848,7 @@ discard block |
||
| 1848 | 1848 | 'message_template_group_id' => $message_template_group->ID(), |
| 1849 | 1849 | ); |
| 1850 | 1850 | return EEH_Template::display_template( |
| 1851 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1851 | + EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php', |
|
| 1852 | 1852 | $template_args, |
| 1853 | 1853 | true |
| 1854 | 1854 | ); |
@@ -1888,7 +1888,7 @@ discard block |
||
| 1888 | 1888 | $nonce = isset($this->_req_data['toggle_context_nonce']) |
| 1889 | 1889 | ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
| 1890 | 1890 | : ''; |
| 1891 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1891 | + $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce'; |
|
| 1892 | 1892 | $this->_verify_nonce($nonce, $nonce_ref); |
| 1893 | 1893 | $status = $this->_req_data['status']; |
| 1894 | 1894 | if ($status !== 'off' && $status !== 'on') { |
@@ -1906,7 +1906,7 @@ discard block |
||
| 1906 | 1906 | $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
| 1907 | 1907 | $this->_req_data['message_template_group_id'] |
| 1908 | 1908 | ); |
| 1909 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1909 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1910 | 1910 | EE_Error::add_error( |
| 1911 | 1911 | sprintf( |
| 1912 | 1912 | esc_html__( |
@@ -2035,7 +2035,7 @@ discard block |
||
| 2035 | 2035 | $templates = array(); |
| 2036 | 2036 | $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
| 2037 | 2037 | // we need to make sure we've got the info we need. |
| 2038 | - if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2038 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2039 | 2039 | EE_Error::add_error( |
| 2040 | 2040 | esc_html__( |
| 2041 | 2041 | 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
@@ -2077,7 +2077,7 @@ discard block |
||
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | 2079 | // any error messages? |
| 2080 | - if (! $success) { |
|
| 2080 | + if ( ! $success) { |
|
| 2081 | 2081 | EE_Error::add_error( |
| 2082 | 2082 | esc_html__( |
| 2083 | 2083 | 'Something went wrong with deleting existing templates. Unable to reset to default', |
@@ -2189,7 +2189,7 @@ discard block |
||
| 2189 | 2189 | $preview_title = sprintf( |
| 2190 | 2190 | esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
| 2191 | 2191 | $active_messenger_label, |
| 2192 | - ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular']) |
|
| 2192 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2193 | 2193 | ); |
| 2194 | 2194 | if (empty($preview)) { |
| 2195 | 2195 | $this->noEventsErrorMessage(); |
@@ -2197,7 +2197,7 @@ discard block |
||
| 2197 | 2197 | // setup display of preview. |
| 2198 | 2198 | $this->_admin_page_title = $preview_title; |
| 2199 | 2199 | $this->_template_args['admin_page_title'] = $preview_title; |
| 2200 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview; |
|
| 2200 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview; |
|
| 2201 | 2201 | $this->_template_args['data']['force_json'] = true; |
| 2202 | 2202 | |
| 2203 | 2203 | return ''; |
@@ -2311,10 +2311,10 @@ discard block |
||
| 2311 | 2311 | // only include template packs that support this messenger and message type! |
| 2312 | 2312 | $supports = $tp->get_supports(); |
| 2313 | 2313 | if ( |
| 2314 | - ! isset($supports[ $this->_message_template_group->messenger() ]) |
|
| 2314 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2315 | 2315 | || ! in_array( |
| 2316 | 2316 | $this->_message_template_group->message_type(), |
| 2317 | - $supports[ $this->_message_template_group->messenger() ], |
|
| 2317 | + $supports[$this->_message_template_group->messenger()], |
|
| 2318 | 2318 | true |
| 2319 | 2319 | ) |
| 2320 | 2320 | ) { |
@@ -2367,7 +2367,7 @@ discard block |
||
| 2367 | 2367 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 2368 | 2368 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 2369 | 2369 | |
| 2370 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2370 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 2371 | 2371 | |
| 2372 | 2372 | EEH_Template::display_template($template, $template_args); |
| 2373 | 2373 | } |
@@ -2393,10 +2393,10 @@ discard block |
||
| 2393 | 2393 | // first we need to see if there are any fields |
| 2394 | 2394 | $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
| 2395 | 2395 | |
| 2396 | - if (! empty($fields)) { |
|
| 2396 | + if ( ! empty($fields)) { |
|
| 2397 | 2397 | // yup there be fields |
| 2398 | 2398 | foreach ($fields as $field => $config) { |
| 2399 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2399 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2400 | 2400 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2401 | 2401 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2402 | 2402 | $default = isset($config['value']) ? $config['value'] : $default; |
@@ -2404,22 +2404,22 @@ discard block |
||
| 2404 | 2404 | // if type is hidden and the value is empty |
| 2405 | 2405 | // something may have gone wrong so let's correct with the defaults |
| 2406 | 2406 | $fix = $config['input'] === 'hidden' |
| 2407 | - && isset($existing[ $field ]) |
|
| 2408 | - && empty($existing[ $field ]) |
|
| 2407 | + && isset($existing[$field]) |
|
| 2408 | + && empty($existing[$field]) |
|
| 2409 | 2409 | ? $default |
| 2410 | 2410 | : ''; |
| 2411 | - $existing[ $field ] = isset($existing[ $field ]) && empty($fix) |
|
| 2412 | - ? $existing[ $field ] |
|
| 2411 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2412 | + ? $existing[$field] |
|
| 2413 | 2413 | : $fix; |
| 2414 | 2414 | |
| 2415 | - $template_form_fields[ $field_id ] = array( |
|
| 2416 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2415 | + $template_form_fields[$field_id] = array( |
|
| 2416 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2417 | 2417 | 'label' => $config['label'], |
| 2418 | 2418 | 'input' => $config['input'], |
| 2419 | 2419 | 'type' => $config['type'], |
| 2420 | 2420 | 'required' => $config['required'], |
| 2421 | 2421 | 'validation' => $config['validation'], |
| 2422 | - 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default, |
|
| 2422 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2423 | 2423 | 'css_class' => $config['css_class'], |
| 2424 | 2424 | 'options' => isset($config['options']) ? $config['options'] : array(), |
| 2425 | 2425 | 'default' => $default, |
@@ -2434,7 +2434,7 @@ discard block |
||
| 2434 | 2434 | |
| 2435 | 2435 | $test_settings_html = ''; |
| 2436 | 2436 | // print out $test_settings_fields |
| 2437 | - if (! empty($test_settings_fields)) { |
|
| 2437 | + if ( ! empty($test_settings_fields)) { |
|
| 2438 | 2438 | echo $test_settings_fields; |
| 2439 | 2439 | $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
| 2440 | 2440 | $test_settings_html .= 'name="test_button" value="'; |
@@ -2481,7 +2481,7 @@ discard block |
||
| 2481 | 2481 | ); |
| 2482 | 2482 | |
| 2483 | 2483 | return EEH_Template::display_template( |
| 2484 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2484 | + EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2485 | 2485 | $template_args, |
| 2486 | 2486 | true |
| 2487 | 2487 | ); |
@@ -2506,7 +2506,7 @@ discard block |
||
| 2506 | 2506 | // $messenger = $this->_message_template_group->messenger_obj(); |
| 2507 | 2507 | // now let's set the content depending on the status of the shortcodes array |
| 2508 | 2508 | if (empty($shortcodes)) { |
| 2509 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2509 | + $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2510 | 2510 | echo $content; |
| 2511 | 2511 | } else { |
| 2512 | 2512 | // $alt = 0; |
@@ -2544,7 +2544,7 @@ discard block |
||
| 2544 | 2544 | { |
| 2545 | 2545 | |
| 2546 | 2546 | // no need to run this if the property is already set |
| 2547 | - if (! empty($this->_shortcodes)) { |
|
| 2547 | + if ( ! empty($this->_shortcodes)) { |
|
| 2548 | 2548 | return; |
| 2549 | 2549 | } |
| 2550 | 2550 | |
@@ -2598,7 +2598,7 @@ discard block |
||
| 2598 | 2598 | protected function _set_message_template_group() |
| 2599 | 2599 | { |
| 2600 | 2600 | |
| 2601 | - if (! empty($this->_message_template_group)) { |
|
| 2601 | + if ( ! empty($this->_message_template_group)) { |
|
| 2602 | 2602 | return; |
| 2603 | 2603 | } //get out if this is already set. |
| 2604 | 2604 | |
@@ -2645,7 +2645,7 @@ discard block |
||
| 2645 | 2645 | <?php |
| 2646 | 2646 | } |
| 2647 | 2647 | // setup nonce_url |
| 2648 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2648 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2649 | 2649 | ?> |
| 2650 | 2650 | <select name="context"> |
| 2651 | 2651 | <?php |
@@ -2655,7 +2655,7 @@ discard block |
||
| 2655 | 2655 | $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
| 2656 | 2656 | ?> |
| 2657 | 2657 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2658 | - <?php echo $context_details[ $context ]['label']; ?> |
|
| 2658 | + <?php echo $context_details[$context]['label']; ?> |
|
| 2659 | 2659 | </option> |
| 2660 | 2660 | <?php endforeach; |
| 2661 | 2661 | endif; ?> |
@@ -2685,22 +2685,22 @@ discard block |
||
| 2685 | 2685 | */ |
| 2686 | 2686 | protected function _set_message_template_column_values($index) |
| 2687 | 2687 | { |
| 2688 | - if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) { |
|
| 2689 | - foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) { |
|
| 2690 | - $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value; |
|
| 2688 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2689 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2690 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2691 | 2691 | } |
| 2692 | 2692 | } |
| 2693 | 2693 | |
| 2694 | 2694 | |
| 2695 | 2695 | $set_column_values = array( |
| 2696 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']), |
|
| 2696 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2697 | 2697 | 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
| 2698 | 2698 | 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
| 2699 | 2699 | 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
| 2700 | 2700 | 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
| 2701 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']), |
|
| 2701 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2702 | 2702 | 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
| 2703 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][ $index ]['content'], |
|
| 2703 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2704 | 2704 | 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
| 2705 | 2705 | ? absint($this->_req_data['MTP_is_global']) |
| 2706 | 2706 | : 0, |
@@ -2747,7 +2747,7 @@ discard block |
||
| 2747 | 2747 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2748 | 2748 | |
| 2749 | 2749 | $item_desc = $messenger_label && $message_type_label |
| 2750 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2750 | + ? $messenger_label.' '.$message_type_label.' '.$context.' ' |
|
| 2751 | 2751 | : ''; |
| 2752 | 2752 | $item_desc .= 'Message Template'; |
| 2753 | 2753 | $query_args = array(); |
@@ -2778,7 +2778,7 @@ discard block |
||
| 2778 | 2778 | |
| 2779 | 2779 | |
| 2780 | 2780 | // run update for each template field in displayed context |
| 2781 | - if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2781 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2782 | 2782 | EE_Error::add_error( |
| 2783 | 2783 | esc_html__( |
| 2784 | 2784 | 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
@@ -2840,10 +2840,10 @@ discard block |
||
| 2840 | 2840 | $set_column_values = $this->_set_message_template_column_values($template_field); |
| 2841 | 2841 | |
| 2842 | 2842 | $where_cols_n_values = array( |
| 2843 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'], |
|
| 2843 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'], |
|
| 2844 | 2844 | ); |
| 2845 | 2845 | // if they aren't allowed to use all JS, restrict them to just posty-y tags |
| 2846 | - if (! current_user_can('unfiltered_html')) { |
|
| 2846 | + if ( ! current_user_can('unfiltered_html')) { |
|
| 2847 | 2847 | if (is_array($set_column_values['MTP_content'])) { |
| 2848 | 2848 | foreach ($set_column_values['MTP_content'] as $key => $value) { |
| 2849 | 2849 | // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function |
@@ -2851,7 +2851,7 @@ discard block |
||
| 2851 | 2851 | // appear invalid.) But currently the models expect slashed data, so after wp_kses |
| 2852 | 2852 | // runs we need to re-slash the data. Sheesh. See |
| 2853 | 2853 | // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587 |
| 2854 | - $set_column_values['MTP_content'][ $key ] = addslashes( |
|
| 2854 | + $set_column_values['MTP_content'][$key] = addslashes( |
|
| 2855 | 2855 | wp_kses( |
| 2856 | 2856 | stripslashes($value), |
| 2857 | 2857 | wp_kses_allowed_html('post') |
@@ -2887,14 +2887,14 @@ discard block |
||
| 2887 | 2887 | } |
| 2888 | 2888 | } else { |
| 2889 | 2889 | // only do this logic if we don't have a MTP_ID for this field |
| 2890 | - if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) { |
|
| 2890 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2891 | 2891 | // this has already been through the template field validator and sanitized, so it will be |
| 2892 | 2892 | // safe to insert this field. Why insert? This typically happens when we introduce a new |
| 2893 | 2893 | // message template field in a messenger/message type and existing users don't have the |
| 2894 | 2894 | // default setup for it. |
| 2895 | 2895 | // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
| 2896 | 2896 | $updated = $MTP->insert($message_template_fields); |
| 2897 | - if (! $updated || is_wp_error($updated)) { |
|
| 2897 | + if ( ! $updated || is_wp_error($updated)) { |
|
| 2898 | 2898 | EE_Error::add_error( |
| 2899 | 2899 | sprintf( |
| 2900 | 2900 | esc_html__('%s field could not be updated.', 'event_espresso'), |
@@ -3128,7 +3128,7 @@ discard block |
||
| 3128 | 3128 | // incoming GRP_IDs |
| 3129 | 3129 | if ($all) { |
| 3130 | 3130 | // Checkboxes |
| 3131 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3131 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3132 | 3132 | // if array has more than one element then success message should be plural. |
| 3133 | 3133 | // todo: what about nonce? |
| 3134 | 3134 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
@@ -3136,16 +3136,16 @@ discard block |
||
| 3136 | 3136 | // cycle through checkboxes |
| 3137 | 3137 | while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
| 3138 | 3138 | $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
| 3139 | - if (! $trashed_or_restored) { |
|
| 3139 | + if ( ! $trashed_or_restored) { |
|
| 3140 | 3140 | $success = 0; |
| 3141 | 3141 | } |
| 3142 | 3142 | } |
| 3143 | 3143 | } else { |
| 3144 | 3144 | // grab single GRP_ID and handle |
| 3145 | 3145 | $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
| 3146 | - if (! empty($GRP_ID)) { |
|
| 3146 | + if ( ! empty($GRP_ID)) { |
|
| 3147 | 3147 | $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
| 3148 | - if (! $trashed_or_restored) { |
|
| 3148 | + if ( ! $trashed_or_restored) { |
|
| 3149 | 3149 | $success = 0; |
| 3150 | 3150 | } |
| 3151 | 3151 | } else { |
@@ -3193,7 +3193,7 @@ discard block |
||
| 3193 | 3193 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 3194 | 3194 | |
| 3195 | 3195 | // checkboxes |
| 3196 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3196 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3197 | 3197 | // if array has more than one element then success message should be plural |
| 3198 | 3198 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
| 3199 | 3199 | |
@@ -3300,7 +3300,7 @@ discard block |
||
| 3300 | 3300 | protected function _set_m_mt_settings() |
| 3301 | 3301 | { |
| 3302 | 3302 | // first if this is already set then lets get out no need to regenerate data. |
| 3303 | - if (! empty($this->_m_mt_settings)) { |
|
| 3303 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 3304 | 3304 | return; |
| 3305 | 3305 | } |
| 3306 | 3306 | |
@@ -3314,7 +3314,7 @@ discard block |
||
| 3314 | 3314 | // assemble the array for the _tab_text_links helper |
| 3315 | 3315 | |
| 3316 | 3316 | foreach ($messengers as $messenger) { |
| 3317 | - $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array( |
|
| 3317 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3318 | 3318 | 'label' => ucwords($messenger->label['singular']), |
| 3319 | 3319 | 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
| 3320 | 3320 | ? 'messenger-active' |
@@ -3331,7 +3331,7 @@ discard block |
||
| 3331 | 3331 | foreach ($message_types as $message_type) { |
| 3332 | 3332 | // first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
| 3333 | 3333 | // it shouldn't show in either the inactive OR active metabox. |
| 3334 | - if (! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3334 | + if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3335 | 3335 | continue; |
| 3336 | 3336 | } |
| 3337 | 3337 | |
@@ -3342,12 +3342,12 @@ discard block |
||
| 3342 | 3342 | ? 'active' |
| 3343 | 3343 | : 'inactive'; |
| 3344 | 3344 | |
| 3345 | - $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array( |
|
| 3345 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3346 | 3346 | 'label' => ucwords($message_type->label['singular']), |
| 3347 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3348 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3349 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3350 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3347 | + 'class' => 'message-type-'.$a_or_i, |
|
| 3348 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 3349 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 3350 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 3351 | 3351 | 'title' => $a_or_i === 'active' |
| 3352 | 3352 | ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 3353 | 3353 | : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -3378,25 +3378,25 @@ discard block |
||
| 3378 | 3378 | $fields = $message_type->get_admin_settings_fields(); |
| 3379 | 3379 | $settings_template_args['template_form_fields'] = ''; |
| 3380 | 3380 | |
| 3381 | - if (! empty($fields) && $active) { |
|
| 3381 | + if ( ! empty($fields) && $active) { |
|
| 3382 | 3382 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 3383 | 3383 | foreach ($fields as $fldname => $fldprops) { |
| 3384 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3385 | - $template_form_field[ $field_id ] = array( |
|
| 3386 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3384 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 3385 | + $template_form_field[$field_id] = array( |
|
| 3386 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 3387 | 3387 | 'label' => $fldprops['label'], |
| 3388 | 3388 | 'input' => $fldprops['field_type'], |
| 3389 | 3389 | 'type' => $fldprops['value_type'], |
| 3390 | 3390 | 'required' => $fldprops['required'], |
| 3391 | 3391 | 'validation' => $fldprops['validation'], |
| 3392 | - 'value' => isset($existing_settings[ $fldname ]) |
|
| 3393 | - ? $existing_settings[ $fldname ] |
|
| 3392 | + 'value' => isset($existing_settings[$fldname]) |
|
| 3393 | + ? $existing_settings[$fldname] |
|
| 3394 | 3394 | : $fldprops['default'], |
| 3395 | 3395 | 'options' => isset($fldprops['options']) |
| 3396 | 3396 | ? $fldprops['options'] |
| 3397 | 3397 | : array(), |
| 3398 | - 'default' => isset($existing_settings[ $fldname ]) |
|
| 3399 | - ? $existing_settings[ $fldname ] |
|
| 3398 | + 'default' => isset($existing_settings[$fldname]) |
|
| 3399 | + ? $existing_settings[$fldname] |
|
| 3400 | 3400 | : $fldprops['default'], |
| 3401 | 3401 | 'css_class' => 'no-drag', |
| 3402 | 3402 | 'format' => $fldprops['format'], |
@@ -3439,7 +3439,7 @@ discard block |
||
| 3439 | 3439 | : ''; |
| 3440 | 3440 | |
| 3441 | 3441 | |
| 3442 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3442 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 3443 | 3443 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 3444 | 3444 | |
| 3445 | 3445 | return $content; |
@@ -3470,20 +3470,20 @@ discard block |
||
| 3470 | 3470 | // messenger meta boxes |
| 3471 | 3471 | $active = $selected_messenger === $messenger; |
| 3472 | 3472 | $active_mt_tabs = isset( |
| 3473 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] |
|
| 3473 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3474 | 3474 | ) |
| 3475 | - ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'] |
|
| 3475 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3476 | 3476 | : ''; |
| 3477 | - $m_boxes[ $messenger . '_a_box' ] = sprintf( |
|
| 3477 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 3478 | 3478 | esc_html__('%s Settings', 'event_espresso'), |
| 3479 | 3479 | $tab_array['label'] |
| 3480 | 3480 | ); |
| 3481 | - $m_template_args[ $messenger . '_a_box' ] = array( |
|
| 3481 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 3482 | 3482 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 3483 | 3483 | 'inactive_message_types' => isset( |
| 3484 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] |
|
| 3484 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3485 | 3485 | ) |
| 3486 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) |
|
| 3486 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3487 | 3487 | : '', |
| 3488 | 3488 | 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
| 3489 | 3489 | 'hidden' => $active ? '' : ' hidden', |
@@ -3494,13 +3494,13 @@ discard block |
||
| 3494 | 3494 | // message type meta boxes |
| 3495 | 3495 | // (which is really just the inactive container for each messenger |
| 3496 | 3496 | // showing inactive message types for that messenger) |
| 3497 | - $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3498 | - $mt_template_args[ $messenger . '_i_box' ] = array( |
|
| 3497 | + $mt_boxes[$messenger.'_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3498 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 3499 | 3499 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 3500 | 3500 | 'inactive_message_types' => isset( |
| 3501 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'] |
|
| 3501 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3502 | 3502 | ) |
| 3503 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']) |
|
| 3503 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3504 | 3504 | : '', |
| 3505 | 3505 | 'hidden' => $active ? '' : ' hidden', |
| 3506 | 3506 | 'hide_on_message' => $hide_on_message, |
@@ -3513,14 +3513,14 @@ discard block |
||
| 3513 | 3513 | |
| 3514 | 3514 | |
| 3515 | 3515 | // register messenger metaboxes |
| 3516 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3516 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3517 | 3517 | foreach ($m_boxes as $box => $label) { |
| 3518 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]); |
|
| 3518 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3519 | 3519 | $msgr = str_replace('_a_box', '', $box); |
| 3520 | 3520 | add_meta_box( |
| 3521 | - 'espresso_' . $msgr . '_settings', |
|
| 3521 | + 'espresso_'.$msgr.'_settings', |
|
| 3522 | 3522 | $label, |
| 3523 | - function ($post, $metabox) { |
|
| 3523 | + function($post, $metabox) { |
|
| 3524 | 3524 | echo EEH_Template::display_template( |
| 3525 | 3525 | $metabox["args"]["template_path"], |
| 3526 | 3526 | $metabox["args"]["template_args"], |
@@ -3535,17 +3535,17 @@ discard block |
||
| 3535 | 3535 | } |
| 3536 | 3536 | |
| 3537 | 3537 | // register message type metaboxes |
| 3538 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3538 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3539 | 3539 | foreach ($mt_boxes as $box => $label) { |
| 3540 | 3540 | $callback_args = array( |
| 3541 | 3541 | 'template_path' => $mt_template_path, |
| 3542 | - 'template_args' => $mt_template_args[ $box ], |
|
| 3542 | + 'template_args' => $mt_template_args[$box], |
|
| 3543 | 3543 | ); |
| 3544 | 3544 | $mt = str_replace('_i_box', '', $box); |
| 3545 | 3545 | add_meta_box( |
| 3546 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3546 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 3547 | 3547 | $label, |
| 3548 | - function ($post, $metabox) { |
|
| 3548 | + function($post, $metabox) { |
|
| 3549 | 3549 | echo EEH_Template::display_template( |
| 3550 | 3550 | $metabox["args"]["template_path"], |
| 3551 | 3551 | $metabox["args"]["template_args"], |
@@ -3691,7 +3691,7 @@ discard block |
||
| 3691 | 3691 | if ($form->is_valid()) { |
| 3692 | 3692 | $valid_data = $form->valid_data(); |
| 3693 | 3693 | foreach ($valid_data as $property => $value) { |
| 3694 | - $setter = 'set_' . $property; |
|
| 3694 | + $setter = 'set_'.$property; |
|
| 3695 | 3695 | if (method_exists($network_config, $setter)) { |
| 3696 | 3696 | $network_config->{$setter}($value); |
| 3697 | 3697 | } elseif ( |
@@ -3727,7 +3727,7 @@ discard block |
||
| 3727 | 3727 | protected function _get_mt_tabs($tab_array) |
| 3728 | 3728 | { |
| 3729 | 3729 | $tab_array = (array) $tab_array; |
| 3730 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3730 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3731 | 3731 | $tabs = ''; |
| 3732 | 3732 | |
| 3733 | 3733 | foreach ($tab_array as $tab) { |
@@ -3755,20 +3755,20 @@ discard block |
||
| 3755 | 3755 | $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
| 3756 | 3756 | |
| 3757 | 3757 | |
| 3758 | - if (! empty($fields)) { |
|
| 3758 | + if ( ! empty($fields)) { |
|
| 3759 | 3759 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3760 | 3760 | |
| 3761 | 3761 | foreach ($fields as $fldname => $fldprops) { |
| 3762 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3763 | - $template_form_field[ $field_id ] = array( |
|
| 3764 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3762 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3763 | + $template_form_field[$field_id] = array( |
|
| 3764 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3765 | 3765 | 'label' => $fldprops['label'], |
| 3766 | 3766 | 'input' => $fldprops['field_type'], |
| 3767 | 3767 | 'type' => $fldprops['value_type'], |
| 3768 | 3768 | 'required' => $fldprops['required'], |
| 3769 | 3769 | 'validation' => $fldprops['validation'], |
| 3770 | - 'value' => isset($existing_settings[ $field_id ]) |
|
| 3771 | - ? $existing_settings[ $field_id ] |
|
| 3770 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3771 | + ? $existing_settings[$field_id] |
|
| 3772 | 3772 | : $fldprops['default'], |
| 3773 | 3773 | 'css_class' => '', |
| 3774 | 3774 | 'format' => $fldprops['format'], |
@@ -3794,9 +3794,9 @@ discard block |
||
| 3794 | 3794 | ); |
| 3795 | 3795 | |
| 3796 | 3796 | // make sure any active message types that are existing are included in the hidden fields |
| 3797 | - if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { |
|
| 3798 | - foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { |
|
| 3799 | - $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array( |
|
| 3797 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3798 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3799 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3800 | 3800 | 'type' => 'hidden', |
| 3801 | 3801 | 'value' => $mt, |
| 3802 | 3802 | ); |
@@ -3825,9 +3825,9 @@ discard block |
||
| 3825 | 3825 | |
| 3826 | 3826 | |
| 3827 | 3827 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3828 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3828 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3829 | 3829 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3830 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3830 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3831 | 3831 | $content = EEH_Template::display_template( |
| 3832 | 3832 | $template, |
| 3833 | 3833 | $settings_template_args, |
@@ -3853,7 +3853,7 @@ discard block |
||
| 3853 | 3853 | $success = true; |
| 3854 | 3854 | $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
| 3855 | 3855 | // let's check that we have required data |
| 3856 | - if (! isset($this->_req_data['messenger'])) { |
|
| 3856 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3857 | 3857 | EE_Error::add_error( |
| 3858 | 3858 | esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
| 3859 | 3859 | __FILE__, |
@@ -3867,12 +3867,12 @@ discard block |
||
| 3867 | 3867 | $nonce = isset($this->_req_data['activate_nonce']) |
| 3868 | 3868 | ? sanitize_text_field($this->_req_data['activate_nonce']) |
| 3869 | 3869 | : ''; |
| 3870 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3870 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3871 | 3871 | |
| 3872 | 3872 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3873 | 3873 | |
| 3874 | 3874 | |
| 3875 | - if (! isset($this->_req_data['status'])) { |
|
| 3875 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3876 | 3876 | EE_Error::add_error( |
| 3877 | 3877 | esc_html__( |
| 3878 | 3878 | 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
@@ -3931,7 +3931,7 @@ discard block |
||
| 3931 | 3931 | $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
| 3932 | 3932 | |
| 3933 | 3933 | // let's make sure we have the necessary data |
| 3934 | - if (! isset($this->_req_data['message_type'])) { |
|
| 3934 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3935 | 3935 | EE_Error::add_error( |
| 3936 | 3936 | esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
| 3937 | 3937 | __FILE__, |
@@ -3941,7 +3941,7 @@ discard block |
||
| 3941 | 3941 | $success = false; |
| 3942 | 3942 | } |
| 3943 | 3943 | |
| 3944 | - if (! isset($this->_req_data['messenger'])) { |
|
| 3944 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3945 | 3945 | EE_Error::add_error( |
| 3946 | 3946 | esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
| 3947 | 3947 | __FILE__, |
@@ -3951,7 +3951,7 @@ discard block |
||
| 3951 | 3951 | $success = false; |
| 3952 | 3952 | } |
| 3953 | 3953 | |
| 3954 | - if (! isset($this->_req_data['status'])) { |
|
| 3954 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3955 | 3955 | EE_Error::add_error( |
| 3956 | 3956 | esc_html__( |
| 3957 | 3957 | 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
@@ -3984,7 +3984,7 @@ discard block |
||
| 3984 | 3984 | |
| 3985 | 3985 | // do a nonce check here since we're not arriving via a normal route |
| 3986 | 3986 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3987 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3987 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3988 | 3988 | |
| 3989 | 3989 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3990 | 3990 | |
@@ -4173,7 +4173,7 @@ discard block |
||
| 4173 | 4173 | EE_Message_Type $message_type = null |
| 4174 | 4174 | ) { |
| 4175 | 4175 | // if $messenger isn't a valid messenger object then get out. |
| 4176 | - if (! $messenger instanceof EE_Messenger) { |
|
| 4176 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4177 | 4177 | EE_Error::add_error( |
| 4178 | 4178 | esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
| 4179 | 4179 | __FILE__, |
@@ -4228,7 +4228,7 @@ discard block |
||
| 4228 | 4228 | // message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
| 4229 | 4229 | // in which case we just give a success message for the messenger being successfully activated. |
| 4230 | 4230 | } else { |
| 4231 | - if (! $messenger->get_default_message_types()) { |
|
| 4231 | + if ( ! $messenger->get_default_message_types()) { |
|
| 4232 | 4232 | // messenger doesn't have any default message types so still a success. |
| 4233 | 4233 | EE_Error::add_success( |
| 4234 | 4234 | sprintf( |
@@ -4284,7 +4284,7 @@ discard block |
||
| 4284 | 4284 | EE_Error::overwrite_success(); |
| 4285 | 4285 | |
| 4286 | 4286 | // if $messenger isn't a valid messenger object then get out. |
| 4287 | - if (! $messenger instanceof EE_Messenger) { |
|
| 4287 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4288 | 4288 | EE_Error::add_error( |
| 4289 | 4289 | esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
| 4290 | 4290 | __FILE__, |
@@ -4346,7 +4346,7 @@ discard block |
||
| 4346 | 4346 | */ |
| 4347 | 4347 | public function update_mt_form() |
| 4348 | 4348 | { |
| 4349 | - if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4349 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4350 | 4350 | EE_Error::add_error( |
| 4351 | 4351 | esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
| 4352 | 4352 | __FILE__, |
@@ -4358,7 +4358,7 @@ discard block |
||
| 4358 | 4358 | |
| 4359 | 4359 | $message_types = $this->get_installed_message_types(); |
| 4360 | 4360 | |
| 4361 | - $message_type = $message_types[ $this->_req_data['message_type'] ]; |
|
| 4361 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4362 | 4362 | $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 4363 | 4363 | |
| 4364 | 4364 | $content = $this->_message_type_settings_content( |
@@ -4378,7 +4378,7 @@ discard block |
||
| 4378 | 4378 | */ |
| 4379 | 4379 | public function save_settings() |
| 4380 | 4380 | { |
| 4381 | - if (! isset($this->_req_data['type'])) { |
|
| 4381 | + if ( ! isset($this->_req_data['type'])) { |
|
| 4382 | 4382 | EE_Error::add_error( |
| 4383 | 4383 | esc_html__( |
| 4384 | 4384 | 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
@@ -4407,7 +4407,7 @@ discard block |
||
| 4407 | 4407 | unset($settings['message_types']); |
| 4408 | 4408 | break; |
| 4409 | 4409 | default: |
| 4410 | - $settings[ $key ] = $value; |
|
| 4410 | + $settings[$key] = $value; |
|
| 4411 | 4411 | break; |
| 4412 | 4412 | } |
| 4413 | 4413 | } |
@@ -4426,7 +4426,7 @@ discard block |
||
| 4426 | 4426 | unset($settings['message_type']); |
| 4427 | 4427 | break; |
| 4428 | 4428 | default: |
| 4429 | - $settings[ $key ] = $value; |
|
| 4429 | + $settings[$key] = $value; |
|
| 4430 | 4430 | break; |
| 4431 | 4431 | } |
| 4432 | 4432 | } |
@@ -4587,7 +4587,7 @@ discard block |
||
| 4587 | 4587 | */ |
| 4588 | 4588 | protected function _get_msg_ids_from_request() |
| 4589 | 4589 | { |
| 4590 | - if (! isset($this->_req_data['MSG_ID'])) { |
|
| 4590 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4591 | 4591 | return array(); |
| 4592 | 4592 | } |
| 4593 | 4593 | |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | * Get Timezone Offset for given timezone object. |
| 198 | 198 | * |
| 199 | 199 | * @param DateTimeZone $date_time_zone |
| 200 | - * @param null $time |
|
| 201 | - * @return mixed |
|
| 200 | + * @param integer|null $time |
|
| 201 | + * @return integer |
|
| 202 | 202 | * @throws InvalidArgumentException |
| 203 | 203 | * @throws InvalidDataTypeException |
| 204 | 204 | * @throws InvalidInterfaceException |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @param DateTime $DateTime DateTime object |
| 321 | 321 | * @param string $period a value to indicate what interval is being used in the calculation. The options are |
| 322 | 322 | * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
| 323 | - * @param int|string $value What you want to increment the date by |
|
| 323 | + * @param integer $value What you want to increment the date by |
|
| 324 | 324 | * @param string $operand What operand you wish to use for the calculation |
| 325 | 325 | * @return DateTime return whatever type came in. |
| 326 | 326 | * @throws Exception |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | * this method will add that "1" into your date regardless of the format. |
| 857 | 857 | * |
| 858 | 858 | * @param string $month |
| 859 | - * @return string |
|
| 859 | + * @return integer |
|
| 860 | 860 | */ |
| 861 | 861 | public static function first_of_month_timestamp($month = '') |
| 862 | 862 | { |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | /** |
| 1005 | 1005 | * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
| 1006 | 1006 | * |
| 1007 | - * @param int|WP_User $user_id |
|
| 1007 | + * @param integer $user_id |
|
| 1008 | 1008 | * @return string |
| 1009 | 1009 | */ |
| 1010 | 1010 | public static function get_user_locale($user_id = 0) |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
| 133 | 133 | { |
| 134 | - $gmt_offset = (int) $gmt_offset; |
|
| 134 | + $gmt_offset = (int) $gmt_offset; |
|
| 135 | 135 | /** @var array[] $abbreviations */ |
| 136 | 136 | $abbreviations = DateTimeZone::listAbbreviations(); |
| 137 | 137 | foreach ($abbreviations as $abbreviation) { |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 328 | 328 | { |
| 329 | - if (! $DateTime instanceof DateTime) { |
|
| 329 | + if ( ! $DateTime instanceof DateTime) { |
|
| 330 | 330 | throw new EE_Error( |
| 331 | 331 | sprintf( |
| 332 | 332 | esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -336,25 +336,25 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | switch ($period) { |
| 338 | 338 | case 'years': |
| 339 | - $value = 'P' . $value . 'Y'; |
|
| 339 | + $value = 'P'.$value.'Y'; |
|
| 340 | 340 | break; |
| 341 | 341 | case 'months': |
| 342 | - $value = 'P' . $value . 'M'; |
|
| 342 | + $value = 'P'.$value.'M'; |
|
| 343 | 343 | break; |
| 344 | 344 | case 'weeks': |
| 345 | - $value = 'P' . $value . 'W'; |
|
| 345 | + $value = 'P'.$value.'W'; |
|
| 346 | 346 | break; |
| 347 | 347 | case 'days': |
| 348 | - $value = 'P' . $value . 'D'; |
|
| 348 | + $value = 'P'.$value.'D'; |
|
| 349 | 349 | break; |
| 350 | 350 | case 'hours': |
| 351 | - $value = 'PT' . $value . 'H'; |
|
| 351 | + $value = 'PT'.$value.'H'; |
|
| 352 | 352 | break; |
| 353 | 353 | case 'minutes': |
| 354 | - $value = 'PT' . $value . 'M'; |
|
| 354 | + $value = 'PT'.$value.'M'; |
|
| 355 | 355 | break; |
| 356 | 356 | case 'seconds': |
| 357 | - $value = 'PT' . $value . 'S'; |
|
| 357 | + $value = 'PT'.$value.'S'; |
|
| 358 | 358 | break; |
| 359 | 359 | } |
| 360 | 360 | switch ($operand) { |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 384 | 384 | { |
| 385 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 385 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 386 | 386 | throw new EE_Error( |
| 387 | 387 | sprintf( |
| 388 | 388 | esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | 'date' => $date_format['js'], |
| 496 | 496 | 'time' => $time_format['js'], |
| 497 | 497 | ), |
| 498 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 498 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 499 | 499 | 'moment_split' => array( |
| 500 | 500 | 'date' => $date_format['moment'], |
| 501 | 501 | 'time' => $time_format['moment'] |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * |
| 519 | 519 | * @var array |
| 520 | 520 | */ |
| 521 | - $symbols_map = array( |
|
| 521 | + $symbols_map = array( |
|
| 522 | 522 | // Day |
| 523 | 523 | // 01 |
| 524 | 524 | 'd' => array( |
@@ -670,26 +670,26 @@ discard block |
||
| 670 | 670 | $escaping = false; |
| 671 | 671 | $format_string_length = strlen($format_string); |
| 672 | 672 | for ($i = 0; $i < $format_string_length; $i++) { |
| 673 | - $char = $format_string[ $i ]; |
|
| 673 | + $char = $format_string[$i]; |
|
| 674 | 674 | if ($char === '\\') { // PHP date format escaping character |
| 675 | 675 | $i++; |
| 676 | 676 | if ($escaping) { |
| 677 | - $jquery_ui_format .= $format_string[ $i ]; |
|
| 678 | - $moment_format .= $format_string[ $i ]; |
|
| 677 | + $jquery_ui_format .= $format_string[$i]; |
|
| 678 | + $moment_format .= $format_string[$i]; |
|
| 679 | 679 | } else { |
| 680 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
| 681 | - $moment_format .= $format_string[ $i ]; |
|
| 680 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 681 | + $moment_format .= $format_string[$i]; |
|
| 682 | 682 | } |
| 683 | 683 | $escaping = true; |
| 684 | 684 | } else { |
| 685 | 685 | if ($escaping) { |
| 686 | 686 | $jquery_ui_format .= "'"; |
| 687 | 687 | $moment_format .= "'"; |
| 688 | - $escaping = false; |
|
| 688 | + $escaping = false; |
|
| 689 | 689 | } |
| 690 | - if (isset($symbols_map[ $char ])) { |
|
| 691 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
| 692 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
| 690 | + if (isset($symbols_map[$char])) { |
|
| 691 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 692 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 693 | 693 | } else { |
| 694 | 694 | $jquery_ui_format .= $char; |
| 695 | 695 | $moment_format .= $char; |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | { |
| 748 | 748 | |
| 749 | 749 | if ( |
| 750 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 750 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 751 | 751 | || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
| 752 | 752 | || $date_2->format( |
| 753 | 753 | EE_Datetime_Field::mysql_time_format |
@@ -783,8 +783,8 @@ discard block |
||
| 783 | 783 | ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
| 784 | 784 | : (float) get_option('gmt_offset'); |
| 785 | 785 | $query_interval = $offset < 0 |
| 786 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 787 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 786 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 787 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 788 | 788 | return $query_interval; |
| 789 | 789 | } |
| 790 | 790 | |
@@ -801,16 +801,16 @@ discard block |
||
| 801 | 801 | public static function get_timezone_string_for_display() |
| 802 | 802 | { |
| 803 | 803 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 804 | - if (! empty($pretty_timezone)) { |
|
| 804 | + if ( ! empty($pretty_timezone)) { |
|
| 805 | 805 | return esc_html($pretty_timezone); |
| 806 | 806 | } |
| 807 | 807 | $timezone_string = get_option('timezone_string'); |
| 808 | 808 | if ($timezone_string) { |
| 809 | 809 | static $mo_loaded = false; |
| 810 | 810 | // Load translations for continents and cities just like wp_timezone_choice does |
| 811 | - if (! $mo_loaded) { |
|
| 811 | + if ( ! $mo_loaded) { |
|
| 812 | 812 | $locale = get_locale(); |
| 813 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 813 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 814 | 814 | load_textdomain('continents-cities', $mofile); |
| 815 | 815 | $mo_loaded = true; |
| 816 | 816 | } |
@@ -837,10 +837,10 @@ discard block |
||
| 837 | 837 | } else { |
| 838 | 838 | // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 839 | 839 | // to minutes, eg 30 or 15, respectively |
| 840 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
| 840 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 841 | 841 | $parts[1] = (string) $hour_fraction * 60; |
| 842 | 842 | } |
| 843 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 843 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | |
@@ -923,9 +923,9 @@ discard block |
||
| 923 | 923 | 'Pacific', |
| 924 | 924 | ); |
| 925 | 925 | // Load translations for continents and cities. |
| 926 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 926 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
| 927 | 927 | $locale_loaded = $locale ? $locale : get_locale(); |
| 928 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 928 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
| 929 | 929 | unload_textdomain('continents-cities'); |
| 930 | 930 | load_textdomain('continents-cities', $mofile); |
| 931 | 931 | $mo_loaded = true; |
@@ -933,11 +933,11 @@ discard block |
||
| 933 | 933 | $zone_data = array(); |
| 934 | 934 | foreach (timezone_identifiers_list() as $zone) { |
| 935 | 935 | $zone = explode('/', $zone); |
| 936 | - if (! in_array($zone[0], $continents, true)) { |
|
| 936 | + if ( ! in_array($zone[0], $continents, true)) { |
|
| 937 | 937 | continue; |
| 938 | 938 | } |
| 939 | 939 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
| 940 | - $exists = array( |
|
| 940 | + $exists = array( |
|
| 941 | 941 | 0 => isset($zone[0]) && $zone[0], |
| 942 | 942 | 1 => isset($zone[1]) && $zone[1], |
| 943 | 943 | 2 => isset($zone[2]) && $zone[2], |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | usort($zone_data, '_wp_timezone_choice_usort_callback'); |
| 968 | 968 | $structure = array(); |
| 969 | 969 | if (empty($selected_zone)) { |
| 970 | - $structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>'; |
|
| 970 | + $structure[] = '<option selected="selected" value="">'.__('Select a city', 'event_espresso').'</option>'; |
|
| 971 | 971 | } |
| 972 | 972 | foreach ($zone_data as $key => $zone) { |
| 973 | 973 | // Build value in an array to join later |
@@ -978,31 +978,31 @@ discard block |
||
| 978 | 978 | } else { |
| 979 | 979 | // It's inside a continent group |
| 980 | 980 | // Continent optgroup |
| 981 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
| 981 | + if ( ! isset($zone_data[$key - 1]) || $zone_data[$key - 1]['continent'] !== $zone['continent']) { |
|
| 982 | 982 | $label = $zone['t_continent']; |
| 983 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 983 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
| 984 | 984 | } |
| 985 | 985 | // Add the city to the value |
| 986 | 986 | $value[] = $zone['city']; |
| 987 | 987 | $display = $zone['t_city']; |
| 988 | - if (! empty($zone['subcity'])) { |
|
| 988 | + if ( ! empty($zone['subcity'])) { |
|
| 989 | 989 | // Add the subcity to the value |
| 990 | 990 | $value[] = $zone['subcity']; |
| 991 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 991 | + $display .= ' - '.$zone['t_subcity']; |
|
| 992 | 992 | } |
| 993 | 993 | } |
| 994 | 994 | // Build the value |
| 995 | 995 | $value = implode('/', $value); |
| 996 | 996 | $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
| 997 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
| 997 | + $structure[] = '<option value="'.esc_attr($value).'"'.$selected.'>' |
|
| 998 | 998 | . esc_html($display) |
| 999 | 999 | . '</option>'; |
| 1000 | 1000 | // Close continent optgroup |
| 1001 | 1001 | if ( |
| 1002 | 1002 | ! empty($zone['city']) |
| 1003 | 1003 | && ( |
| 1004 | - ! isset($zone_data[ $key + 1 ]) |
|
| 1005 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
| 1004 | + ! isset($zone_data[$key + 1]) |
|
| 1005 | + || (isset($zone_data[$key + 1]) && $zone_data[$key + 1]['continent'] !== $zone['continent']) |
|
| 1006 | 1006 | ) |
| 1007 | 1007 | ) { |
| 1008 | 1008 | $structure[] = '</optgroup>'; |
@@ -16,1052 +16,1052 @@ |
||
| 16 | 16 | class EEH_DTT_Helper |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * return the timezone set for the WP install |
|
| 21 | - * |
|
| 22 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
| 23 | - * @throws InvalidArgumentException |
|
| 24 | - * @throws InvalidDataTypeException |
|
| 25 | - * @throws InvalidInterfaceException |
|
| 26 | - */ |
|
| 27 | - public static function get_timezone() |
|
| 28 | - { |
|
| 29 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 30 | - } |
|
| 19 | + /** |
|
| 20 | + * return the timezone set for the WP install |
|
| 21 | + * |
|
| 22 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
| 23 | + * @throws InvalidArgumentException |
|
| 24 | + * @throws InvalidDataTypeException |
|
| 25 | + * @throws InvalidInterfaceException |
|
| 26 | + */ |
|
| 27 | + public static function get_timezone() |
|
| 28 | + { |
|
| 29 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * get_valid_timezone_string |
|
| 35 | - * ensures that a valid timezone string is returned |
|
| 36 | - * |
|
| 37 | - * @param string $timezone_string |
|
| 38 | - * @param bool $throw_error |
|
| 39 | - * @return string |
|
| 40 | - * @throws InvalidArgumentException |
|
| 41 | - * @throws InvalidDataTypeException |
|
| 42 | - * @throws InvalidInterfaceException |
|
| 43 | - */ |
|
| 44 | - public static function get_valid_timezone_string($timezone_string = '', $throw_error = false) |
|
| 45 | - { |
|
| 46 | - return self::getHelperAdapter()->getValidTimezoneString($timezone_string, $throw_error); |
|
| 47 | - } |
|
| 33 | + /** |
|
| 34 | + * get_valid_timezone_string |
|
| 35 | + * ensures that a valid timezone string is returned |
|
| 36 | + * |
|
| 37 | + * @param string $timezone_string |
|
| 38 | + * @param bool $throw_error |
|
| 39 | + * @return string |
|
| 40 | + * @throws InvalidArgumentException |
|
| 41 | + * @throws InvalidDataTypeException |
|
| 42 | + * @throws InvalidInterfaceException |
|
| 43 | + */ |
|
| 44 | + public static function get_valid_timezone_string($timezone_string = '', $throw_error = false) |
|
| 45 | + { |
|
| 46 | + return self::getHelperAdapter()->getValidTimezoneString($timezone_string, $throw_error); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public static function resetDefaultTimezoneString() |
|
| 51 | - { |
|
| 52 | - self::getHelperAdapter()->resetDefaultTimezoneString(); |
|
| 53 | - } |
|
| 50 | + public static function resetDefaultTimezoneString() |
|
| 51 | + { |
|
| 52 | + self::getHelperAdapter()->resetDefaultTimezoneString(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 58 | - * |
|
| 59 | - * @static |
|
| 60 | - * @param string $timezone_string Timezone string to check |
|
| 61 | - * @param bool $throw_error |
|
| 62 | - * @return bool |
|
| 63 | - * @throws InvalidArgumentException |
|
| 64 | - * @throws InvalidDataTypeException |
|
| 65 | - * @throws InvalidInterfaceException |
|
| 66 | - */ |
|
| 67 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 68 | - { |
|
| 69 | - return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error); |
|
| 70 | - } |
|
| 56 | + /** |
|
| 57 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 58 | + * |
|
| 59 | + * @static |
|
| 60 | + * @param string $timezone_string Timezone string to check |
|
| 61 | + * @param bool $throw_error |
|
| 62 | + * @return bool |
|
| 63 | + * @throws InvalidArgumentException |
|
| 64 | + * @throws InvalidDataTypeException |
|
| 65 | + * @throws InvalidInterfaceException |
|
| 66 | + */ |
|
| 67 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 68 | + { |
|
| 69 | + return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * This returns a string that can represent the provided gmt offset in format that can be passed into |
|
| 75 | - * DateTimeZone. This is NOT a string that can be passed as a value on the WordPress timezone_string option. |
|
| 76 | - * |
|
| 77 | - * @param float|string $gmt_offset |
|
| 78 | - * @return string |
|
| 79 | - * @throws InvalidArgumentException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 84 | - { |
|
| 85 | - return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset); |
|
| 86 | - } |
|
| 73 | + /** |
|
| 74 | + * This returns a string that can represent the provided gmt offset in format that can be passed into |
|
| 75 | + * DateTimeZone. This is NOT a string that can be passed as a value on the WordPress timezone_string option. |
|
| 76 | + * |
|
| 77 | + * @param float|string $gmt_offset |
|
| 78 | + * @return string |
|
| 79 | + * @throws InvalidArgumentException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 84 | + { |
|
| 85 | + return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Gets the site's GMT offset based on either the timezone string |
|
| 91 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 92 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 93 | - * |
|
| 94 | - * @return int seconds offset |
|
| 95 | - * @throws InvalidArgumentException |
|
| 96 | - * @throws InvalidDataTypeException |
|
| 97 | - * @throws InvalidInterfaceException |
|
| 98 | - */ |
|
| 99 | - public static function get_site_timezone_gmt_offset() |
|
| 100 | - { |
|
| 101 | - return self::getHelperAdapter()->getSiteTimezoneGmtOffset(); |
|
| 102 | - } |
|
| 89 | + /** |
|
| 90 | + * Gets the site's GMT offset based on either the timezone string |
|
| 91 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 92 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 93 | + * |
|
| 94 | + * @return int seconds offset |
|
| 95 | + * @throws InvalidArgumentException |
|
| 96 | + * @throws InvalidDataTypeException |
|
| 97 | + * @throws InvalidInterfaceException |
|
| 98 | + */ |
|
| 99 | + public static function get_site_timezone_gmt_offset() |
|
| 100 | + { |
|
| 101 | + return self::getHelperAdapter()->getSiteTimezoneGmtOffset(); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Depending on PHP version, |
|
| 107 | - * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
| 108 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 109 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 110 | - * |
|
| 111 | - * @deprecated 4.9.54.rc Developers this was always meant to only be an internally used method. This will be |
|
| 112 | - * removed in a future version of EE. |
|
| 113 | - * @param int $gmt_offset |
|
| 114 | - * @return int |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - * @throws InvalidDataTypeException |
|
| 117 | - * @throws InvalidInterfaceException |
|
| 118 | - */ |
|
| 119 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 120 | - { |
|
| 121 | - return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset); |
|
| 122 | - } |
|
| 105 | + /** |
|
| 106 | + * Depending on PHP version, |
|
| 107 | + * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
| 108 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 109 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 110 | + * |
|
| 111 | + * @deprecated 4.9.54.rc Developers this was always meant to only be an internally used method. This will be |
|
| 112 | + * removed in a future version of EE. |
|
| 113 | + * @param int $gmt_offset |
|
| 114 | + * @return int |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + * @throws InvalidDataTypeException |
|
| 117 | + * @throws InvalidInterfaceException |
|
| 118 | + */ |
|
| 119 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 120 | + { |
|
| 121 | + return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * get_timezone_string_from_abbreviations_list |
|
| 127 | - * |
|
| 128 | - * @deprecated 4.9.54.rc Developers, this was never intended to be public. This is a soft deprecation for now. |
|
| 129 | - * If you are using this, you'll want to work out an alternate way of getting the value. |
|
| 130 | - * @param int $gmt_offset |
|
| 131 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 132 | - * @return string |
|
| 133 | - * @throws EE_Error |
|
| 134 | - * @throws InvalidArgumentException |
|
| 135 | - * @throws InvalidDataTypeException |
|
| 136 | - * @throws InvalidInterfaceException |
|
| 137 | - */ |
|
| 138 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 139 | - { |
|
| 140 | - $gmt_offset = (int) $gmt_offset; |
|
| 141 | - /** @var array[] $abbreviations */ |
|
| 142 | - $abbreviations = DateTimeZone::listAbbreviations(); |
|
| 143 | - foreach ($abbreviations as $abbreviation) { |
|
| 144 | - foreach ($abbreviation as $timezone) { |
|
| 145 | - if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
| 146 | - try { |
|
| 147 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
| 148 | - if ($offset !== $gmt_offset) { |
|
| 149 | - continue; |
|
| 150 | - } |
|
| 151 | - return $timezone['timezone_id']; |
|
| 152 | - } catch (Exception $e) { |
|
| 153 | - continue; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 159 | - if ($coerce === true) { |
|
| 160 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 161 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 162 | - false |
|
| 163 | - ); |
|
| 164 | - if ($timezone_string) { |
|
| 165 | - return $timezone_string; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - throw new EE_Error( |
|
| 169 | - sprintf( |
|
| 170 | - esc_html__( |
|
| 171 | - 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 172 | - 'event_espresso' |
|
| 173 | - ), |
|
| 174 | - $gmt_offset / HOUR_IN_SECONDS, |
|
| 175 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 176 | - '</a>' |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - } |
|
| 125 | + /** |
|
| 126 | + * get_timezone_string_from_abbreviations_list |
|
| 127 | + * |
|
| 128 | + * @deprecated 4.9.54.rc Developers, this was never intended to be public. This is a soft deprecation for now. |
|
| 129 | + * If you are using this, you'll want to work out an alternate way of getting the value. |
|
| 130 | + * @param int $gmt_offset |
|
| 131 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 132 | + * @return string |
|
| 133 | + * @throws EE_Error |
|
| 134 | + * @throws InvalidArgumentException |
|
| 135 | + * @throws InvalidDataTypeException |
|
| 136 | + * @throws InvalidInterfaceException |
|
| 137 | + */ |
|
| 138 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 139 | + { |
|
| 140 | + $gmt_offset = (int) $gmt_offset; |
|
| 141 | + /** @var array[] $abbreviations */ |
|
| 142 | + $abbreviations = DateTimeZone::listAbbreviations(); |
|
| 143 | + foreach ($abbreviations as $abbreviation) { |
|
| 144 | + foreach ($abbreviation as $timezone) { |
|
| 145 | + if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
| 146 | + try { |
|
| 147 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
| 148 | + if ($offset !== $gmt_offset) { |
|
| 149 | + continue; |
|
| 150 | + } |
|
| 151 | + return $timezone['timezone_id']; |
|
| 152 | + } catch (Exception $e) { |
|
| 153 | + continue; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 159 | + if ($coerce === true) { |
|
| 160 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 161 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 162 | + false |
|
| 163 | + ); |
|
| 164 | + if ($timezone_string) { |
|
| 165 | + return $timezone_string; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + throw new EE_Error( |
|
| 169 | + sprintf( |
|
| 170 | + esc_html__( |
|
| 171 | + 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 172 | + 'event_espresso' |
|
| 173 | + ), |
|
| 174 | + $gmt_offset / HOUR_IN_SECONDS, |
|
| 175 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 176 | + '</a>' |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Get Timezone Transitions |
|
| 184 | - * |
|
| 185 | - * @param DateTimeZone $date_time_zone |
|
| 186 | - * @param int|null $time |
|
| 187 | - * @param bool $first_only |
|
| 188 | - * @return array |
|
| 189 | - * @throws InvalidArgumentException |
|
| 190 | - * @throws InvalidDataTypeException |
|
| 191 | - * @throws InvalidInterfaceException |
|
| 192 | - */ |
|
| 193 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 194 | - { |
|
| 195 | - return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only); |
|
| 196 | - } |
|
| 182 | + /** |
|
| 183 | + * Get Timezone Transitions |
|
| 184 | + * |
|
| 185 | + * @param DateTimeZone $date_time_zone |
|
| 186 | + * @param int|null $time |
|
| 187 | + * @param bool $first_only |
|
| 188 | + * @return array |
|
| 189 | + * @throws InvalidArgumentException |
|
| 190 | + * @throws InvalidDataTypeException |
|
| 191 | + * @throws InvalidInterfaceException |
|
| 192 | + */ |
|
| 193 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 194 | + { |
|
| 195 | + return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * Get Timezone Offset for given timezone object. |
|
| 201 | - * |
|
| 202 | - * @param DateTimeZone $date_time_zone |
|
| 203 | - * @param null $time |
|
| 204 | - * @return mixed |
|
| 205 | - * @throws InvalidArgumentException |
|
| 206 | - * @throws InvalidDataTypeException |
|
| 207 | - * @throws InvalidInterfaceException |
|
| 208 | - */ |
|
| 209 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 210 | - { |
|
| 211 | - return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time); |
|
| 212 | - } |
|
| 199 | + /** |
|
| 200 | + * Get Timezone Offset for given timezone object. |
|
| 201 | + * |
|
| 202 | + * @param DateTimeZone $date_time_zone |
|
| 203 | + * @param null $time |
|
| 204 | + * @return mixed |
|
| 205 | + * @throws InvalidArgumentException |
|
| 206 | + * @throws InvalidDataTypeException |
|
| 207 | + * @throws InvalidInterfaceException |
|
| 208 | + */ |
|
| 209 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 210 | + { |
|
| 211 | + return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Prints a select input for the given timezone string. |
|
| 217 | - * @param string $timezone_string |
|
| 218 | - * @deprecatd 4.9.54.rc Soft deprecation. Consider using \EEH_DTT_Helper::wp_timezone_choice instead. |
|
| 219 | - * @throws InvalidArgumentException |
|
| 220 | - * @throws InvalidDataTypeException |
|
| 221 | - * @throws InvalidInterfaceException |
|
| 222 | - */ |
|
| 223 | - public static function timezone_select_input($timezone_string = '') |
|
| 224 | - { |
|
| 225 | - self::getHelperAdapter()->timezoneSelectInput($timezone_string); |
|
| 226 | - } |
|
| 215 | + /** |
|
| 216 | + * Prints a select input for the given timezone string. |
|
| 217 | + * @param string $timezone_string |
|
| 218 | + * @deprecatd 4.9.54.rc Soft deprecation. Consider using \EEH_DTT_Helper::wp_timezone_choice instead. |
|
| 219 | + * @throws InvalidArgumentException |
|
| 220 | + * @throws InvalidDataTypeException |
|
| 221 | + * @throws InvalidInterfaceException |
|
| 222 | + */ |
|
| 223 | + public static function timezone_select_input($timezone_string = '') |
|
| 224 | + { |
|
| 225 | + self::getHelperAdapter()->timezoneSelectInput($timezone_string); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 231 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 232 | - * the site is used. |
|
| 233 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 234 | - * computed timestamp (i.e. date_i18n() ) |
|
| 235 | - * |
|
| 236 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 237 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 238 | - * site will be used. |
|
| 239 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 240 | - * @throws InvalidArgumentException |
|
| 241 | - * @throws InvalidDataTypeException |
|
| 242 | - * @throws InvalidInterfaceException |
|
| 243 | - */ |
|
| 244 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 245 | - { |
|
| 246 | - return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string); |
|
| 247 | - } |
|
| 229 | + /** |
|
| 230 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 231 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 232 | + * the site is used. |
|
| 233 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 234 | + * computed timestamp (i.e. date_i18n() ) |
|
| 235 | + * |
|
| 236 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 237 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 238 | + * site will be used. |
|
| 239 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 240 | + * @throws InvalidArgumentException |
|
| 241 | + * @throws InvalidDataTypeException |
|
| 242 | + * @throws InvalidInterfaceException |
|
| 243 | + */ |
|
| 244 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 245 | + { |
|
| 246 | + return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * _set_date_time_field |
|
| 252 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 253 | - * |
|
| 254 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 255 | - * @param DateTime $DateTime PHP DateTime object |
|
| 256 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 257 | - * @return EE_Base_Class |
|
| 258 | - * @throws EE_Error |
|
| 259 | - */ |
|
| 260 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 261 | - { |
|
| 262 | - // grab current datetime format |
|
| 263 | - $current_format = $obj->get_format(); |
|
| 264 | - // set new full timestamp format |
|
| 265 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 266 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 267 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 268 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 269 | - // reset datetime formats |
|
| 270 | - $obj->set_date_format($current_format[0]); |
|
| 271 | - $obj->set_time_format($current_format[1]); |
|
| 272 | - return $obj; |
|
| 273 | - } |
|
| 250 | + /** |
|
| 251 | + * _set_date_time_field |
|
| 252 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 253 | + * |
|
| 254 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 255 | + * @param DateTime $DateTime PHP DateTime object |
|
| 256 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 257 | + * @return EE_Base_Class |
|
| 258 | + * @throws EE_Error |
|
| 259 | + */ |
|
| 260 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 261 | + { |
|
| 262 | + // grab current datetime format |
|
| 263 | + $current_format = $obj->get_format(); |
|
| 264 | + // set new full timestamp format |
|
| 265 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 266 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 267 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 268 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 269 | + // reset datetime formats |
|
| 270 | + $obj->set_date_format($current_format[0]); |
|
| 271 | + $obj->set_time_format($current_format[1]); |
|
| 272 | + return $obj; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * date_time_add |
|
| 278 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 279 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 280 | - * |
|
| 281 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 282 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 283 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 284 | - * minutes, seconds) defaults to years |
|
| 285 | - * @param integer $value what you want to increment the time by |
|
| 286 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 287 | - * (chaining) |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws Exception |
|
| 290 | - */ |
|
| 291 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 292 | - { |
|
| 293 | - // get the raw UTC date. |
|
| 294 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 295 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 296 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 297 | - } |
|
| 276 | + /** |
|
| 277 | + * date_time_add |
|
| 278 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 279 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 280 | + * |
|
| 281 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 282 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 283 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 284 | + * minutes, seconds) defaults to years |
|
| 285 | + * @param integer $value what you want to increment the time by |
|
| 286 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 287 | + * (chaining) |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws Exception |
|
| 290 | + */ |
|
| 291 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 292 | + { |
|
| 293 | + // get the raw UTC date. |
|
| 294 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 295 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 296 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * date_time_subtract |
|
| 302 | - * same as date_time_add except subtracting value instead of adding. |
|
| 303 | - * |
|
| 304 | - * @param EE_Base_Class $obj |
|
| 305 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 306 | - * @param string $period |
|
| 307 | - * @param int $value |
|
| 308 | - * @return EE_Base_Class |
|
| 309 | - * @throws EE_Error |
|
| 310 | - * @throws Exception |
|
| 311 | - */ |
|
| 312 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 313 | - { |
|
| 314 | - // get the raw UTC date |
|
| 315 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 316 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 317 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 318 | - } |
|
| 300 | + /** |
|
| 301 | + * date_time_subtract |
|
| 302 | + * same as date_time_add except subtracting value instead of adding. |
|
| 303 | + * |
|
| 304 | + * @param EE_Base_Class $obj |
|
| 305 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 306 | + * @param string $period |
|
| 307 | + * @param int $value |
|
| 308 | + * @return EE_Base_Class |
|
| 309 | + * @throws EE_Error |
|
| 310 | + * @throws Exception |
|
| 311 | + */ |
|
| 312 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 313 | + { |
|
| 314 | + // get the raw UTC date |
|
| 315 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 316 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 317 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | 320 | |
| 321 | - /** |
|
| 322 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 323 | - * |
|
| 324 | - * @param DateTime $DateTime DateTime object |
|
| 325 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 326 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 327 | - * @param int|string $value What you want to increment the date by |
|
| 328 | - * @param string $operand What operand you wish to use for the calculation |
|
| 329 | - * @return DateTime return whatever type came in. |
|
| 330 | - * @throws Exception |
|
| 331 | - * @throws EE_Error |
|
| 332 | - */ |
|
| 333 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 334 | - { |
|
| 335 | - if (! $DateTime instanceof DateTime) { |
|
| 336 | - throw new EE_Error( |
|
| 337 | - sprintf( |
|
| 338 | - esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 339 | - print_r($DateTime, true) |
|
| 340 | - ) |
|
| 341 | - ); |
|
| 342 | - } |
|
| 343 | - switch ($period) { |
|
| 344 | - case 'years': |
|
| 345 | - $value = 'P' . $value . 'Y'; |
|
| 346 | - break; |
|
| 347 | - case 'months': |
|
| 348 | - $value = 'P' . $value . 'M'; |
|
| 349 | - break; |
|
| 350 | - case 'weeks': |
|
| 351 | - $value = 'P' . $value . 'W'; |
|
| 352 | - break; |
|
| 353 | - case 'days': |
|
| 354 | - $value = 'P' . $value . 'D'; |
|
| 355 | - break; |
|
| 356 | - case 'hours': |
|
| 357 | - $value = 'PT' . $value . 'H'; |
|
| 358 | - break; |
|
| 359 | - case 'minutes': |
|
| 360 | - $value = 'PT' . $value . 'M'; |
|
| 361 | - break; |
|
| 362 | - case 'seconds': |
|
| 363 | - $value = 'PT' . $value . 'S'; |
|
| 364 | - break; |
|
| 365 | - } |
|
| 366 | - switch ($operand) { |
|
| 367 | - case '+': |
|
| 368 | - $DateTime->add(new DateInterval($value)); |
|
| 369 | - break; |
|
| 370 | - case '-': |
|
| 371 | - $DateTime->sub(new DateInterval($value)); |
|
| 372 | - break; |
|
| 373 | - } |
|
| 374 | - return $DateTime; |
|
| 375 | - } |
|
| 321 | + /** |
|
| 322 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 323 | + * |
|
| 324 | + * @param DateTime $DateTime DateTime object |
|
| 325 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 326 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 327 | + * @param int|string $value What you want to increment the date by |
|
| 328 | + * @param string $operand What operand you wish to use for the calculation |
|
| 329 | + * @return DateTime return whatever type came in. |
|
| 330 | + * @throws Exception |
|
| 331 | + * @throws EE_Error |
|
| 332 | + */ |
|
| 333 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 334 | + { |
|
| 335 | + if (! $DateTime instanceof DateTime) { |
|
| 336 | + throw new EE_Error( |
|
| 337 | + sprintf( |
|
| 338 | + esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 339 | + print_r($DateTime, true) |
|
| 340 | + ) |
|
| 341 | + ); |
|
| 342 | + } |
|
| 343 | + switch ($period) { |
|
| 344 | + case 'years': |
|
| 345 | + $value = 'P' . $value . 'Y'; |
|
| 346 | + break; |
|
| 347 | + case 'months': |
|
| 348 | + $value = 'P' . $value . 'M'; |
|
| 349 | + break; |
|
| 350 | + case 'weeks': |
|
| 351 | + $value = 'P' . $value . 'W'; |
|
| 352 | + break; |
|
| 353 | + case 'days': |
|
| 354 | + $value = 'P' . $value . 'D'; |
|
| 355 | + break; |
|
| 356 | + case 'hours': |
|
| 357 | + $value = 'PT' . $value . 'H'; |
|
| 358 | + break; |
|
| 359 | + case 'minutes': |
|
| 360 | + $value = 'PT' . $value . 'M'; |
|
| 361 | + break; |
|
| 362 | + case 'seconds': |
|
| 363 | + $value = 'PT' . $value . 'S'; |
|
| 364 | + break; |
|
| 365 | + } |
|
| 366 | + switch ($operand) { |
|
| 367 | + case '+': |
|
| 368 | + $DateTime->add(new DateInterval($value)); |
|
| 369 | + break; |
|
| 370 | + case '-': |
|
| 371 | + $DateTime->sub(new DateInterval($value)); |
|
| 372 | + break; |
|
| 373 | + } |
|
| 374 | + return $DateTime; |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 380 | - * |
|
| 381 | - * @param int $timestamp Unix timestamp |
|
| 382 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 383 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 384 | - * @param integer $value What you want to increment the date by |
|
| 385 | - * @param string $operand What operand you wish to use for the calculation |
|
| 386 | - * @return int |
|
| 387 | - * @throws EE_Error |
|
| 388 | - */ |
|
| 389 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 390 | - { |
|
| 391 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 392 | - throw new EE_Error( |
|
| 393 | - sprintf( |
|
| 394 | - esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 395 | - print_r($timestamp, true) |
|
| 396 | - ) |
|
| 397 | - ); |
|
| 398 | - } |
|
| 399 | - switch ($period) { |
|
| 400 | - case 'years': |
|
| 401 | - $value = YEAR_IN_SECONDS * $value; |
|
| 402 | - break; |
|
| 403 | - case 'months': |
|
| 404 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 405 | - break; |
|
| 406 | - case 'weeks': |
|
| 407 | - $value = WEEK_IN_SECONDS * $value; |
|
| 408 | - break; |
|
| 409 | - case 'days': |
|
| 410 | - $value = DAY_IN_SECONDS * $value; |
|
| 411 | - break; |
|
| 412 | - case 'hours': |
|
| 413 | - $value = HOUR_IN_SECONDS * $value; |
|
| 414 | - break; |
|
| 415 | - case 'minutes': |
|
| 416 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 417 | - break; |
|
| 418 | - } |
|
| 419 | - switch ($operand) { |
|
| 420 | - case '+': |
|
| 421 | - $timestamp += $value; |
|
| 422 | - break; |
|
| 423 | - case '-': |
|
| 424 | - $timestamp -= $value; |
|
| 425 | - break; |
|
| 426 | - } |
|
| 427 | - return $timestamp; |
|
| 428 | - } |
|
| 378 | + /** |
|
| 379 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 380 | + * |
|
| 381 | + * @param int $timestamp Unix timestamp |
|
| 382 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 383 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 384 | + * @param integer $value What you want to increment the date by |
|
| 385 | + * @param string $operand What operand you wish to use for the calculation |
|
| 386 | + * @return int |
|
| 387 | + * @throws EE_Error |
|
| 388 | + */ |
|
| 389 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 390 | + { |
|
| 391 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 392 | + throw new EE_Error( |
|
| 393 | + sprintf( |
|
| 394 | + esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 395 | + print_r($timestamp, true) |
|
| 396 | + ) |
|
| 397 | + ); |
|
| 398 | + } |
|
| 399 | + switch ($period) { |
|
| 400 | + case 'years': |
|
| 401 | + $value = YEAR_IN_SECONDS * $value; |
|
| 402 | + break; |
|
| 403 | + case 'months': |
|
| 404 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 405 | + break; |
|
| 406 | + case 'weeks': |
|
| 407 | + $value = WEEK_IN_SECONDS * $value; |
|
| 408 | + break; |
|
| 409 | + case 'days': |
|
| 410 | + $value = DAY_IN_SECONDS * $value; |
|
| 411 | + break; |
|
| 412 | + case 'hours': |
|
| 413 | + $value = HOUR_IN_SECONDS * $value; |
|
| 414 | + break; |
|
| 415 | + case 'minutes': |
|
| 416 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 417 | + break; |
|
| 418 | + } |
|
| 419 | + switch ($operand) { |
|
| 420 | + case '+': |
|
| 421 | + $timestamp += $value; |
|
| 422 | + break; |
|
| 423 | + case '-': |
|
| 424 | + $timestamp -= $value; |
|
| 425 | + break; |
|
| 426 | + } |
|
| 427 | + return $timestamp; |
|
| 428 | + } |
|
| 429 | 429 | |
| 430 | 430 | |
| 431 | - /** |
|
| 432 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 433 | - * parameters and returns the new timestamp or DateTime. |
|
| 434 | - * |
|
| 435 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 436 | - * @param string $period a value to indicate what interval is being used in the |
|
| 437 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 438 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 439 | - * @param integer $value What you want to increment the date by |
|
| 440 | - * @param string $operand What operand you wish to use for the calculation |
|
| 441 | - * @return mixed string|DateTime return whatever type came in. |
|
| 442 | - * @throws Exception |
|
| 443 | - * @throws EE_Error |
|
| 444 | - */ |
|
| 445 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 446 | - { |
|
| 447 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 448 | - return EEH_DTT_Helper::_modify_datetime_object( |
|
| 449 | - $DateTime_or_timestamp, |
|
| 450 | - $period, |
|
| 451 | - $value, |
|
| 452 | - $operand |
|
| 453 | - ); |
|
| 454 | - } |
|
| 455 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 456 | - return EEH_DTT_Helper::_modify_timestamp( |
|
| 457 | - $DateTime_or_timestamp, |
|
| 458 | - $period, |
|
| 459 | - $value, |
|
| 460 | - $operand |
|
| 461 | - ); |
|
| 462 | - } |
|
| 463 | - // error |
|
| 464 | - return $DateTime_or_timestamp; |
|
| 465 | - } |
|
| 431 | + /** |
|
| 432 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 433 | + * parameters and returns the new timestamp or DateTime. |
|
| 434 | + * |
|
| 435 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 436 | + * @param string $period a value to indicate what interval is being used in the |
|
| 437 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 438 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 439 | + * @param integer $value What you want to increment the date by |
|
| 440 | + * @param string $operand What operand you wish to use for the calculation |
|
| 441 | + * @return mixed string|DateTime return whatever type came in. |
|
| 442 | + * @throws Exception |
|
| 443 | + * @throws EE_Error |
|
| 444 | + */ |
|
| 445 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 446 | + { |
|
| 447 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 448 | + return EEH_DTT_Helper::_modify_datetime_object( |
|
| 449 | + $DateTime_or_timestamp, |
|
| 450 | + $period, |
|
| 451 | + $value, |
|
| 452 | + $operand |
|
| 453 | + ); |
|
| 454 | + } |
|
| 455 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 456 | + return EEH_DTT_Helper::_modify_timestamp( |
|
| 457 | + $DateTime_or_timestamp, |
|
| 458 | + $period, |
|
| 459 | + $value, |
|
| 460 | + $operand |
|
| 461 | + ); |
|
| 462 | + } |
|
| 463 | + // error |
|
| 464 | + return $DateTime_or_timestamp; |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | 467 | |
| 468 | - /** |
|
| 469 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 470 | - * and spit out the js and moment.js equivalent formats. |
|
| 471 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 472 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 473 | - * time picker. |
|
| 474 | - * |
|
| 475 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 476 | - * @param string $date_format_string |
|
| 477 | - * @param string $time_format_string |
|
| 478 | - * @return array |
|
| 479 | - * array( |
|
| 480 | - * 'js' => array ( |
|
| 481 | - * 'date' => //date format |
|
| 482 | - * 'time' => //time format |
|
| 483 | - * ), |
|
| 484 | - * 'moment' => //date and time format. |
|
| 485 | - * ) |
|
| 486 | - */ |
|
| 487 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 488 | - $date_format_string = null, |
|
| 489 | - $time_format_string = null |
|
| 490 | - ) { |
|
| 491 | - if ($date_format_string === null) { |
|
| 492 | - $date_format_string = (string) get_option('date_format'); |
|
| 493 | - } |
|
| 494 | - if ($time_format_string === null) { |
|
| 495 | - $time_format_string = (string) get_option('time_format'); |
|
| 496 | - } |
|
| 497 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 498 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 499 | - return array( |
|
| 500 | - 'js' => array( |
|
| 501 | - 'date' => $date_format['js'], |
|
| 502 | - 'time' => $time_format['js'], |
|
| 503 | - ), |
|
| 504 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 505 | - 'moment_split' => array( |
|
| 506 | - 'date' => $date_format['moment'], |
|
| 507 | - 'time' => $time_format['moment'] |
|
| 508 | - ) |
|
| 509 | - ); |
|
| 510 | - } |
|
| 468 | + /** |
|
| 469 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 470 | + * and spit out the js and moment.js equivalent formats. |
|
| 471 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 472 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 473 | + * time picker. |
|
| 474 | + * |
|
| 475 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 476 | + * @param string $date_format_string |
|
| 477 | + * @param string $time_format_string |
|
| 478 | + * @return array |
|
| 479 | + * array( |
|
| 480 | + * 'js' => array ( |
|
| 481 | + * 'date' => //date format |
|
| 482 | + * 'time' => //time format |
|
| 483 | + * ), |
|
| 484 | + * 'moment' => //date and time format. |
|
| 485 | + * ) |
|
| 486 | + */ |
|
| 487 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 488 | + $date_format_string = null, |
|
| 489 | + $time_format_string = null |
|
| 490 | + ) { |
|
| 491 | + if ($date_format_string === null) { |
|
| 492 | + $date_format_string = (string) get_option('date_format'); |
|
| 493 | + } |
|
| 494 | + if ($time_format_string === null) { |
|
| 495 | + $time_format_string = (string) get_option('time_format'); |
|
| 496 | + } |
|
| 497 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 498 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 499 | + return array( |
|
| 500 | + 'js' => array( |
|
| 501 | + 'date' => $date_format['js'], |
|
| 502 | + 'time' => $time_format['js'], |
|
| 503 | + ), |
|
| 504 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 505 | + 'moment_split' => array( |
|
| 506 | + 'date' => $date_format['moment'], |
|
| 507 | + 'time' => $time_format['moment'] |
|
| 508 | + ) |
|
| 509 | + ); |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | 512 | |
| 513 | - /** |
|
| 514 | - * This converts incoming format string into js and moment variations. |
|
| 515 | - * |
|
| 516 | - * @param string $format_string incoming php format string |
|
| 517 | - * @return array js and moment formats. |
|
| 518 | - */ |
|
| 519 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 520 | - { |
|
| 521 | - /** |
|
| 522 | - * This is a map of symbols for formats. |
|
| 523 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 524 | - * |
|
| 525 | - * @var array |
|
| 526 | - */ |
|
| 527 | - $symbols_map = array( |
|
| 528 | - // Day |
|
| 529 | - // 01 |
|
| 530 | - 'd' => array( |
|
| 531 | - 'js' => 'dd', |
|
| 532 | - 'moment' => 'DD', |
|
| 533 | - ), |
|
| 534 | - // Mon |
|
| 535 | - 'D' => array( |
|
| 536 | - 'js' => 'D', |
|
| 537 | - 'moment' => 'ddd', |
|
| 538 | - ), |
|
| 539 | - // 1,2,...31 |
|
| 540 | - 'j' => array( |
|
| 541 | - 'js' => 'd', |
|
| 542 | - 'moment' => 'D', |
|
| 543 | - ), |
|
| 544 | - // Monday |
|
| 545 | - 'l' => array( |
|
| 546 | - 'js' => 'DD', |
|
| 547 | - 'moment' => 'dddd', |
|
| 548 | - ), |
|
| 549 | - // ISO numeric representation of the day of the week (1-6) |
|
| 550 | - 'N' => array( |
|
| 551 | - 'js' => '', |
|
| 552 | - 'moment' => 'E', |
|
| 553 | - ), |
|
| 554 | - // st,nd.rd |
|
| 555 | - 'S' => array( |
|
| 556 | - 'js' => '', |
|
| 557 | - 'moment' => 'o', |
|
| 558 | - ), |
|
| 559 | - // numeric representation of day of week (0-6) |
|
| 560 | - 'w' => array( |
|
| 561 | - 'js' => '', |
|
| 562 | - 'moment' => 'd', |
|
| 563 | - ), |
|
| 564 | - // day of year starting from 0 (0-365) |
|
| 565 | - 'z' => array( |
|
| 566 | - 'js' => 'o', |
|
| 567 | - 'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 568 | - ), |
|
| 569 | - // Week |
|
| 570 | - // ISO-8601 week number of year (weeks starting on monday) |
|
| 571 | - 'W' => array( |
|
| 572 | - 'js' => '', |
|
| 573 | - 'moment' => 'w', |
|
| 574 | - ), |
|
| 575 | - // Month |
|
| 576 | - // January...December |
|
| 577 | - 'F' => array( |
|
| 578 | - 'js' => 'MM', |
|
| 579 | - 'moment' => 'MMMM', |
|
| 580 | - ), |
|
| 581 | - // 01...12 |
|
| 582 | - 'm' => array( |
|
| 583 | - 'js' => 'mm', |
|
| 584 | - 'moment' => 'MM', |
|
| 585 | - ), |
|
| 586 | - // Jan...Dec |
|
| 587 | - 'M' => array( |
|
| 588 | - 'js' => 'M', |
|
| 589 | - 'moment' => 'MMM', |
|
| 590 | - ), |
|
| 591 | - // 1-12 |
|
| 592 | - 'n' => array( |
|
| 593 | - 'js' => 'm', |
|
| 594 | - 'moment' => 'M', |
|
| 595 | - ), |
|
| 596 | - // number of days in given month |
|
| 597 | - 't' => array( |
|
| 598 | - 'js' => '', |
|
| 599 | - 'moment' => '', |
|
| 600 | - ), |
|
| 601 | - // Year |
|
| 602 | - // whether leap year or not 1/0 |
|
| 603 | - 'L' => array( |
|
| 604 | - 'js' => '', |
|
| 605 | - 'moment' => '', |
|
| 606 | - ), |
|
| 607 | - // ISO-8601 year number |
|
| 608 | - 'o' => array( |
|
| 609 | - 'js' => '', |
|
| 610 | - 'moment' => 'GGGG', |
|
| 611 | - ), |
|
| 612 | - // 1999...2003 |
|
| 613 | - 'Y' => array( |
|
| 614 | - 'js' => 'yy', |
|
| 615 | - 'moment' => 'YYYY', |
|
| 616 | - ), |
|
| 617 | - // 99...03 |
|
| 618 | - 'y' => array( |
|
| 619 | - 'js' => 'y', |
|
| 620 | - 'moment' => 'YY', |
|
| 621 | - ), |
|
| 622 | - // Time |
|
| 623 | - // am/pm |
|
| 624 | - 'a' => array( |
|
| 625 | - 'js' => 'tt', |
|
| 626 | - 'moment' => 'a', |
|
| 627 | - ), |
|
| 628 | - // AM/PM |
|
| 629 | - 'A' => array( |
|
| 630 | - 'js' => 'TT', |
|
| 631 | - 'moment' => 'A', |
|
| 632 | - ), |
|
| 633 | - // Swatch Internet Time?!? |
|
| 634 | - 'B' => array( |
|
| 635 | - 'js' => '', |
|
| 636 | - 'moment' => '', |
|
| 637 | - ), |
|
| 638 | - // 1...12 |
|
| 639 | - 'g' => array( |
|
| 640 | - 'js' => 'h', |
|
| 641 | - 'moment' => 'h', |
|
| 642 | - ), |
|
| 643 | - // 0...23 |
|
| 644 | - 'G' => array( |
|
| 645 | - 'js' => 'H', |
|
| 646 | - 'moment' => 'H', |
|
| 647 | - ), |
|
| 648 | - // 01...12 |
|
| 649 | - 'h' => array( |
|
| 650 | - 'js' => 'hh', |
|
| 651 | - 'moment' => 'hh', |
|
| 652 | - ), |
|
| 653 | - // 00...23 |
|
| 654 | - 'H' => array( |
|
| 655 | - 'js' => 'HH', |
|
| 656 | - 'moment' => 'HH', |
|
| 657 | - ), |
|
| 658 | - // 00..59 |
|
| 659 | - 'i' => array( |
|
| 660 | - 'js' => 'mm', |
|
| 661 | - 'moment' => 'mm', |
|
| 662 | - ), |
|
| 663 | - // seconds... 00...59 |
|
| 664 | - 's' => array( |
|
| 665 | - 'js' => 'ss', |
|
| 666 | - 'moment' => 'ss', |
|
| 667 | - ), |
|
| 668 | - // microseconds |
|
| 669 | - 'u' => array( |
|
| 670 | - 'js' => '', |
|
| 671 | - 'moment' => '', |
|
| 672 | - ), |
|
| 673 | - ); |
|
| 674 | - $jquery_ui_format = ''; |
|
| 675 | - $moment_format = ''; |
|
| 676 | - $escaping = false; |
|
| 677 | - $format_string_length = strlen($format_string); |
|
| 678 | - for ($i = 0; $i < $format_string_length; $i++) { |
|
| 679 | - $char = $format_string[ $i ]; |
|
| 680 | - if ($char === '\\') { // PHP date format escaping character |
|
| 681 | - $i++; |
|
| 682 | - if ($escaping) { |
|
| 683 | - $jquery_ui_format .= $format_string[ $i ]; |
|
| 684 | - $moment_format .= $format_string[ $i ]; |
|
| 685 | - } else { |
|
| 686 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
| 687 | - $moment_format .= $format_string[ $i ]; |
|
| 688 | - } |
|
| 689 | - $escaping = true; |
|
| 690 | - } else { |
|
| 691 | - if ($escaping) { |
|
| 692 | - $jquery_ui_format .= "'"; |
|
| 693 | - $moment_format .= "'"; |
|
| 694 | - $escaping = false; |
|
| 695 | - } |
|
| 696 | - if (isset($symbols_map[ $char ])) { |
|
| 697 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
| 698 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
| 699 | - } else { |
|
| 700 | - $jquery_ui_format .= $char; |
|
| 701 | - $moment_format .= $char; |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 706 | - } |
|
| 513 | + /** |
|
| 514 | + * This converts incoming format string into js and moment variations. |
|
| 515 | + * |
|
| 516 | + * @param string $format_string incoming php format string |
|
| 517 | + * @return array js and moment formats. |
|
| 518 | + */ |
|
| 519 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 520 | + { |
|
| 521 | + /** |
|
| 522 | + * This is a map of symbols for formats. |
|
| 523 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 524 | + * |
|
| 525 | + * @var array |
|
| 526 | + */ |
|
| 527 | + $symbols_map = array( |
|
| 528 | + // Day |
|
| 529 | + // 01 |
|
| 530 | + 'd' => array( |
|
| 531 | + 'js' => 'dd', |
|
| 532 | + 'moment' => 'DD', |
|
| 533 | + ), |
|
| 534 | + // Mon |
|
| 535 | + 'D' => array( |
|
| 536 | + 'js' => 'D', |
|
| 537 | + 'moment' => 'ddd', |
|
| 538 | + ), |
|
| 539 | + // 1,2,...31 |
|
| 540 | + 'j' => array( |
|
| 541 | + 'js' => 'd', |
|
| 542 | + 'moment' => 'D', |
|
| 543 | + ), |
|
| 544 | + // Monday |
|
| 545 | + 'l' => array( |
|
| 546 | + 'js' => 'DD', |
|
| 547 | + 'moment' => 'dddd', |
|
| 548 | + ), |
|
| 549 | + // ISO numeric representation of the day of the week (1-6) |
|
| 550 | + 'N' => array( |
|
| 551 | + 'js' => '', |
|
| 552 | + 'moment' => 'E', |
|
| 553 | + ), |
|
| 554 | + // st,nd.rd |
|
| 555 | + 'S' => array( |
|
| 556 | + 'js' => '', |
|
| 557 | + 'moment' => 'o', |
|
| 558 | + ), |
|
| 559 | + // numeric representation of day of week (0-6) |
|
| 560 | + 'w' => array( |
|
| 561 | + 'js' => '', |
|
| 562 | + 'moment' => 'd', |
|
| 563 | + ), |
|
| 564 | + // day of year starting from 0 (0-365) |
|
| 565 | + 'z' => array( |
|
| 566 | + 'js' => 'o', |
|
| 567 | + 'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 568 | + ), |
|
| 569 | + // Week |
|
| 570 | + // ISO-8601 week number of year (weeks starting on monday) |
|
| 571 | + 'W' => array( |
|
| 572 | + 'js' => '', |
|
| 573 | + 'moment' => 'w', |
|
| 574 | + ), |
|
| 575 | + // Month |
|
| 576 | + // January...December |
|
| 577 | + 'F' => array( |
|
| 578 | + 'js' => 'MM', |
|
| 579 | + 'moment' => 'MMMM', |
|
| 580 | + ), |
|
| 581 | + // 01...12 |
|
| 582 | + 'm' => array( |
|
| 583 | + 'js' => 'mm', |
|
| 584 | + 'moment' => 'MM', |
|
| 585 | + ), |
|
| 586 | + // Jan...Dec |
|
| 587 | + 'M' => array( |
|
| 588 | + 'js' => 'M', |
|
| 589 | + 'moment' => 'MMM', |
|
| 590 | + ), |
|
| 591 | + // 1-12 |
|
| 592 | + 'n' => array( |
|
| 593 | + 'js' => 'm', |
|
| 594 | + 'moment' => 'M', |
|
| 595 | + ), |
|
| 596 | + // number of days in given month |
|
| 597 | + 't' => array( |
|
| 598 | + 'js' => '', |
|
| 599 | + 'moment' => '', |
|
| 600 | + ), |
|
| 601 | + // Year |
|
| 602 | + // whether leap year or not 1/0 |
|
| 603 | + 'L' => array( |
|
| 604 | + 'js' => '', |
|
| 605 | + 'moment' => '', |
|
| 606 | + ), |
|
| 607 | + // ISO-8601 year number |
|
| 608 | + 'o' => array( |
|
| 609 | + 'js' => '', |
|
| 610 | + 'moment' => 'GGGG', |
|
| 611 | + ), |
|
| 612 | + // 1999...2003 |
|
| 613 | + 'Y' => array( |
|
| 614 | + 'js' => 'yy', |
|
| 615 | + 'moment' => 'YYYY', |
|
| 616 | + ), |
|
| 617 | + // 99...03 |
|
| 618 | + 'y' => array( |
|
| 619 | + 'js' => 'y', |
|
| 620 | + 'moment' => 'YY', |
|
| 621 | + ), |
|
| 622 | + // Time |
|
| 623 | + // am/pm |
|
| 624 | + 'a' => array( |
|
| 625 | + 'js' => 'tt', |
|
| 626 | + 'moment' => 'a', |
|
| 627 | + ), |
|
| 628 | + // AM/PM |
|
| 629 | + 'A' => array( |
|
| 630 | + 'js' => 'TT', |
|
| 631 | + 'moment' => 'A', |
|
| 632 | + ), |
|
| 633 | + // Swatch Internet Time?!? |
|
| 634 | + 'B' => array( |
|
| 635 | + 'js' => '', |
|
| 636 | + 'moment' => '', |
|
| 637 | + ), |
|
| 638 | + // 1...12 |
|
| 639 | + 'g' => array( |
|
| 640 | + 'js' => 'h', |
|
| 641 | + 'moment' => 'h', |
|
| 642 | + ), |
|
| 643 | + // 0...23 |
|
| 644 | + 'G' => array( |
|
| 645 | + 'js' => 'H', |
|
| 646 | + 'moment' => 'H', |
|
| 647 | + ), |
|
| 648 | + // 01...12 |
|
| 649 | + 'h' => array( |
|
| 650 | + 'js' => 'hh', |
|
| 651 | + 'moment' => 'hh', |
|
| 652 | + ), |
|
| 653 | + // 00...23 |
|
| 654 | + 'H' => array( |
|
| 655 | + 'js' => 'HH', |
|
| 656 | + 'moment' => 'HH', |
|
| 657 | + ), |
|
| 658 | + // 00..59 |
|
| 659 | + 'i' => array( |
|
| 660 | + 'js' => 'mm', |
|
| 661 | + 'moment' => 'mm', |
|
| 662 | + ), |
|
| 663 | + // seconds... 00...59 |
|
| 664 | + 's' => array( |
|
| 665 | + 'js' => 'ss', |
|
| 666 | + 'moment' => 'ss', |
|
| 667 | + ), |
|
| 668 | + // microseconds |
|
| 669 | + 'u' => array( |
|
| 670 | + 'js' => '', |
|
| 671 | + 'moment' => '', |
|
| 672 | + ), |
|
| 673 | + ); |
|
| 674 | + $jquery_ui_format = ''; |
|
| 675 | + $moment_format = ''; |
|
| 676 | + $escaping = false; |
|
| 677 | + $format_string_length = strlen($format_string); |
|
| 678 | + for ($i = 0; $i < $format_string_length; $i++) { |
|
| 679 | + $char = $format_string[ $i ]; |
|
| 680 | + if ($char === '\\') { // PHP date format escaping character |
|
| 681 | + $i++; |
|
| 682 | + if ($escaping) { |
|
| 683 | + $jquery_ui_format .= $format_string[ $i ]; |
|
| 684 | + $moment_format .= $format_string[ $i ]; |
|
| 685 | + } else { |
|
| 686 | + $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
| 687 | + $moment_format .= $format_string[ $i ]; |
|
| 688 | + } |
|
| 689 | + $escaping = true; |
|
| 690 | + } else { |
|
| 691 | + if ($escaping) { |
|
| 692 | + $jquery_ui_format .= "'"; |
|
| 693 | + $moment_format .= "'"; |
|
| 694 | + $escaping = false; |
|
| 695 | + } |
|
| 696 | + if (isset($symbols_map[ $char ])) { |
|
| 697 | + $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
| 698 | + $moment_format .= $symbols_map[ $char ]['moment']; |
|
| 699 | + } else { |
|
| 700 | + $jquery_ui_format .= $char; |
|
| 701 | + $moment_format .= $char; |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | |
| 709 | - /** |
|
| 710 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 711 | - * |
|
| 712 | - * @param string $format_string Incoming format string for php date(). |
|
| 713 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 714 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 715 | - * indicate failed validations. |
|
| 716 | - */ |
|
| 717 | - public static function validate_format_string($format_string) |
|
| 718 | - { |
|
| 719 | - $error_msg = array(); |
|
| 720 | - // time format checks |
|
| 721 | - switch (true) { |
|
| 722 | - case strpos($format_string, 'h') !== false: |
|
| 723 | - case strpos($format_string, 'g') !== false: |
|
| 724 | - /** |
|
| 725 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 726 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 727 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 728 | - */ |
|
| 729 | - if (stripos($format_string, 'A') === false) { |
|
| 730 | - $error_msg[] = esc_html__( |
|
| 731 | - 'There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
| 732 | - 'event_espresso' |
|
| 733 | - ); |
|
| 734 | - } |
|
| 735 | - break; |
|
| 736 | - } |
|
| 737 | - return empty($error_msg) ? true : $error_msg; |
|
| 738 | - } |
|
| 709 | + /** |
|
| 710 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 711 | + * |
|
| 712 | + * @param string $format_string Incoming format string for php date(). |
|
| 713 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 714 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 715 | + * indicate failed validations. |
|
| 716 | + */ |
|
| 717 | + public static function validate_format_string($format_string) |
|
| 718 | + { |
|
| 719 | + $error_msg = array(); |
|
| 720 | + // time format checks |
|
| 721 | + switch (true) { |
|
| 722 | + case strpos($format_string, 'h') !== false: |
|
| 723 | + case strpos($format_string, 'g') !== false: |
|
| 724 | + /** |
|
| 725 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 726 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 727 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 728 | + */ |
|
| 729 | + if (stripos($format_string, 'A') === false) { |
|
| 730 | + $error_msg[] = esc_html__( |
|
| 731 | + 'There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
| 732 | + 'event_espresso' |
|
| 733 | + ); |
|
| 734 | + } |
|
| 735 | + break; |
|
| 736 | + } |
|
| 737 | + return empty($error_msg) ? true : $error_msg; |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | |
| 741 | - /** |
|
| 742 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 743 | - * very next day then this method will return true. |
|
| 744 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 745 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 746 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 747 | - * |
|
| 748 | - * @param mixed $date_1 |
|
| 749 | - * @param mixed $date_2 |
|
| 750 | - * @return bool |
|
| 751 | - */ |
|
| 752 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 753 | - { |
|
| 741 | + /** |
|
| 742 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 743 | + * very next day then this method will return true. |
|
| 744 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 745 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 746 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 747 | + * |
|
| 748 | + * @param mixed $date_1 |
|
| 749 | + * @param mixed $date_2 |
|
| 750 | + * @return bool |
|
| 751 | + */ |
|
| 752 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 753 | + { |
|
| 754 | 754 | |
| 755 | - if ( |
|
| 756 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 757 | - || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
| 758 | - || $date_2->format( |
|
| 759 | - EE_Datetime_Field::mysql_time_format |
|
| 760 | - ) !== '00:00:00') |
|
| 761 | - ) { |
|
| 762 | - return false; |
|
| 763 | - } |
|
| 764 | - return $date_2->format('U') - $date_1->format('U') === 86400; |
|
| 765 | - } |
|
| 755 | + if ( |
|
| 756 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 757 | + || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
| 758 | + || $date_2->format( |
|
| 759 | + EE_Datetime_Field::mysql_time_format |
|
| 760 | + ) !== '00:00:00') |
|
| 761 | + ) { |
|
| 762 | + return false; |
|
| 763 | + } |
|
| 764 | + return $date_2->format('U') - $date_1->format('U') === 86400; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | 767 | |
| 768 | - /** |
|
| 769 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 770 | - * Functions. |
|
| 771 | - * |
|
| 772 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 773 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 774 | - * @return string |
|
| 775 | - */ |
|
| 776 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 777 | - { |
|
| 778 | - try { |
|
| 779 | - /** need to account for timezone offset on the selects */ |
|
| 780 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 781 | - } catch (Exception $e) { |
|
| 782 | - $DateTimeZone = null; |
|
| 783 | - } |
|
| 784 | - /** |
|
| 785 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 786 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 787 | - */ |
|
| 788 | - $offset = $DateTimeZone instanceof DateTimeZone |
|
| 789 | - ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
| 790 | - : (float) get_option('gmt_offset'); |
|
| 791 | - $query_interval = $offset < 0 |
|
| 792 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 793 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 794 | - return $query_interval; |
|
| 795 | - } |
|
| 768 | + /** |
|
| 769 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 770 | + * Functions. |
|
| 771 | + * |
|
| 772 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 773 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 774 | + * @return string |
|
| 775 | + */ |
|
| 776 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 777 | + { |
|
| 778 | + try { |
|
| 779 | + /** need to account for timezone offset on the selects */ |
|
| 780 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 781 | + } catch (Exception $e) { |
|
| 782 | + $DateTimeZone = null; |
|
| 783 | + } |
|
| 784 | + /** |
|
| 785 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 786 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 787 | + */ |
|
| 788 | + $offset = $DateTimeZone instanceof DateTimeZone |
|
| 789 | + ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
| 790 | + : (float) get_option('gmt_offset'); |
|
| 791 | + $query_interval = $offset < 0 |
|
| 792 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 793 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 794 | + return $query_interval; |
|
| 795 | + } |
|
| 796 | 796 | |
| 797 | 797 | |
| 798 | - /** |
|
| 799 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 800 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 801 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 802 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 803 | - * (although note that we remove any HTML that may be added) |
|
| 804 | - * |
|
| 805 | - * @return string |
|
| 806 | - */ |
|
| 807 | - public static function get_timezone_string_for_display() |
|
| 808 | - { |
|
| 809 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 810 | - if (! empty($pretty_timezone)) { |
|
| 811 | - return esc_html($pretty_timezone); |
|
| 812 | - } |
|
| 813 | - $timezone_string = get_option('timezone_string'); |
|
| 814 | - if ($timezone_string) { |
|
| 815 | - static $mo_loaded = false; |
|
| 816 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 817 | - if (! $mo_loaded) { |
|
| 818 | - $locale = get_locale(); |
|
| 819 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 820 | - load_textdomain('continents-cities', $mofile); |
|
| 821 | - $mo_loaded = true; |
|
| 822 | - } |
|
| 823 | - // well that was easy. |
|
| 824 | - $parts = explode('/', $timezone_string); |
|
| 825 | - // remove the continent |
|
| 826 | - unset($parts[0]); |
|
| 827 | - $t_parts = array(); |
|
| 828 | - // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
| 829 | - // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
| 830 | - // disabled because this code is copied from WordPress and is a WordPress domain |
|
| 831 | - foreach ($parts as $part) { |
|
| 832 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 833 | - } |
|
| 834 | - return implode(' - ', $t_parts); |
|
| 835 | - // phpcs:enable |
|
| 836 | - } |
|
| 837 | - // they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 838 | - $gmt_offset = get_option('gmt_offset'); |
|
| 839 | - $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
| 840 | - $parts = explode('.', (string) $gmt_offset); |
|
| 841 | - if (count($parts) === 1) { |
|
| 842 | - $parts[1] = '00'; |
|
| 843 | - } else { |
|
| 844 | - // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 845 | - // to minutes, eg 30 or 15, respectively |
|
| 846 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
| 847 | - $parts[1] = (string) $hour_fraction * 60; |
|
| 848 | - } |
|
| 849 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 850 | - } |
|
| 798 | + /** |
|
| 799 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 800 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 801 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 802 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 803 | + * (although note that we remove any HTML that may be added) |
|
| 804 | + * |
|
| 805 | + * @return string |
|
| 806 | + */ |
|
| 807 | + public static function get_timezone_string_for_display() |
|
| 808 | + { |
|
| 809 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 810 | + if (! empty($pretty_timezone)) { |
|
| 811 | + return esc_html($pretty_timezone); |
|
| 812 | + } |
|
| 813 | + $timezone_string = get_option('timezone_string'); |
|
| 814 | + if ($timezone_string) { |
|
| 815 | + static $mo_loaded = false; |
|
| 816 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 817 | + if (! $mo_loaded) { |
|
| 818 | + $locale = get_locale(); |
|
| 819 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 820 | + load_textdomain('continents-cities', $mofile); |
|
| 821 | + $mo_loaded = true; |
|
| 822 | + } |
|
| 823 | + // well that was easy. |
|
| 824 | + $parts = explode('/', $timezone_string); |
|
| 825 | + // remove the continent |
|
| 826 | + unset($parts[0]); |
|
| 827 | + $t_parts = array(); |
|
| 828 | + // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
| 829 | + // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
| 830 | + // disabled because this code is copied from WordPress and is a WordPress domain |
|
| 831 | + foreach ($parts as $part) { |
|
| 832 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 833 | + } |
|
| 834 | + return implode(' - ', $t_parts); |
|
| 835 | + // phpcs:enable |
|
| 836 | + } |
|
| 837 | + // they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 838 | + $gmt_offset = get_option('gmt_offset'); |
|
| 839 | + $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
| 840 | + $parts = explode('.', (string) $gmt_offset); |
|
| 841 | + if (count($parts) === 1) { |
|
| 842 | + $parts[1] = '00'; |
|
| 843 | + } else { |
|
| 844 | + // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 845 | + // to minutes, eg 30 or 15, respectively |
|
| 846 | + $hour_fraction = (float) ('0.' . $parts[1]); |
|
| 847 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 848 | + } |
|
| 849 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | 852 | |
| 853 | 853 | |
| 854 | - /** |
|
| 855 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 856 | - * for a month using a string like "February" or "February 2017", |
|
| 857 | - * and you don't specify a day as part of your string, |
|
| 858 | - * then PHP will use whatever the current day of the month is. |
|
| 859 | - * IF the current day of the month happens to be the 30th or 31st, |
|
| 860 | - * then PHP gets really confused by a date like February 30, |
|
| 861 | - * so instead of saying |
|
| 862 | - * "Hey February only has 28 days (this year)... |
|
| 863 | - * ...you must have meant the last day of the month!" |
|
| 864 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 865 | - * because someone requesting February 30th obviously meant March 1st! |
|
| 866 | - * The way around this is to always set the day to the first, |
|
| 867 | - * so that the month will stay on the month you wanted. |
|
| 868 | - * this method will add that "1" into your date regardless of the format. |
|
| 869 | - * |
|
| 870 | - * @param string $month |
|
| 871 | - * @return string |
|
| 872 | - */ |
|
| 873 | - public static function first_of_month_timestamp($month = '') |
|
| 874 | - { |
|
| 875 | - $month = (string) $month; |
|
| 876 | - $year = ''; |
|
| 877 | - // check if the incoming string has a year in it or not |
|
| 878 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 879 | - $year = $matches[0]; |
|
| 880 | - // ten remove that from the month string as well as any spaces |
|
| 881 | - $month = trim(str_replace($year, '', $month)); |
|
| 882 | - // add a space before the year |
|
| 883 | - $year = " {$year}"; |
|
| 884 | - } |
|
| 885 | - // return timestamp for something like "February 1 2017" |
|
| 886 | - return strtotime("{$month} 1{$year}"); |
|
| 887 | - } |
|
| 854 | + /** |
|
| 855 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 856 | + * for a month using a string like "February" or "February 2017", |
|
| 857 | + * and you don't specify a day as part of your string, |
|
| 858 | + * then PHP will use whatever the current day of the month is. |
|
| 859 | + * IF the current day of the month happens to be the 30th or 31st, |
|
| 860 | + * then PHP gets really confused by a date like February 30, |
|
| 861 | + * so instead of saying |
|
| 862 | + * "Hey February only has 28 days (this year)... |
|
| 863 | + * ...you must have meant the last day of the month!" |
|
| 864 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 865 | + * because someone requesting February 30th obviously meant March 1st! |
|
| 866 | + * The way around this is to always set the day to the first, |
|
| 867 | + * so that the month will stay on the month you wanted. |
|
| 868 | + * this method will add that "1" into your date regardless of the format. |
|
| 869 | + * |
|
| 870 | + * @param string $month |
|
| 871 | + * @return string |
|
| 872 | + */ |
|
| 873 | + public static function first_of_month_timestamp($month = '') |
|
| 874 | + { |
|
| 875 | + $month = (string) $month; |
|
| 876 | + $year = ''; |
|
| 877 | + // check if the incoming string has a year in it or not |
|
| 878 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 879 | + $year = $matches[0]; |
|
| 880 | + // ten remove that from the month string as well as any spaces |
|
| 881 | + $month = trim(str_replace($year, '', $month)); |
|
| 882 | + // add a space before the year |
|
| 883 | + $year = " {$year}"; |
|
| 884 | + } |
|
| 885 | + // return timestamp for something like "February 1 2017" |
|
| 886 | + return strtotime("{$month} 1{$year}"); |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | 889 | |
| 890 | - /** |
|
| 891 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 892 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 893 | - */ |
|
| 894 | - public static function tomorrow() |
|
| 895 | - { |
|
| 896 | - // The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
| 897 | - // before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
| 898 | - // not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
| 899 | - // final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
| 900 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 901 | - } |
|
| 890 | + /** |
|
| 891 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 892 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 893 | + */ |
|
| 894 | + public static function tomorrow() |
|
| 895 | + { |
|
| 896 | + // The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
| 897 | + // before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
| 898 | + // not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
| 899 | + // final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
| 900 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | 903 | |
| 904 | - /** |
|
| 905 | - * ** |
|
| 906 | - * Gives a nicely-formatted list of timezone strings. |
|
| 907 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 908 | - * |
|
| 909 | - * @since 4.9.40.rc.008 |
|
| 910 | - * @staticvar bool $mo_loaded |
|
| 911 | - * @staticvar string $locale_loaded |
|
| 912 | - * @param string $selected_zone Selected timezone. |
|
| 913 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 914 | - * @return string |
|
| 915 | - */ |
|
| 916 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 917 | - { |
|
| 918 | - static $mo_loaded = false, $locale_loaded = null; |
|
| 919 | - $continents = array( |
|
| 920 | - 'Africa', |
|
| 921 | - 'America', |
|
| 922 | - 'Antarctica', |
|
| 923 | - 'Arctic', |
|
| 924 | - 'Asia', |
|
| 925 | - 'Atlantic', |
|
| 926 | - 'Australia', |
|
| 927 | - 'Europe', |
|
| 928 | - 'Indian', |
|
| 929 | - 'Pacific', |
|
| 930 | - ); |
|
| 931 | - // Load translations for continents and cities. |
|
| 932 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 933 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
| 934 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 935 | - unload_textdomain('continents-cities'); |
|
| 936 | - load_textdomain('continents-cities', $mofile); |
|
| 937 | - $mo_loaded = true; |
|
| 938 | - } |
|
| 939 | - $zone_data = array(); |
|
| 940 | - foreach (timezone_identifiers_list() as $zone) { |
|
| 941 | - $zone = explode('/', $zone); |
|
| 942 | - if (! in_array($zone[0], $continents, true)) { |
|
| 943 | - continue; |
|
| 944 | - } |
|
| 945 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 946 | - $exists = array( |
|
| 947 | - 0 => isset($zone[0]) && $zone[0], |
|
| 948 | - 1 => isset($zone[1]) && $zone[1], |
|
| 949 | - 2 => isset($zone[2]) && $zone[2], |
|
| 950 | - ); |
|
| 951 | - $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
| 952 | - $exists[4] = $exists[1] && $exists[3]; |
|
| 953 | - $exists[5] = $exists[2] && $exists[3]; |
|
| 954 | - // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
| 955 | - // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
| 956 | - // disabled because this code is copied from WordPress and is a WordPress domain |
|
| 957 | - $zone_data[] = array( |
|
| 958 | - 'continent' => $exists[0] ? $zone[0] : '', |
|
| 959 | - 'city' => $exists[1] ? $zone[1] : '', |
|
| 960 | - 'subcity' => $exists[2] ? $zone[2] : '', |
|
| 961 | - 't_continent' => $exists[3] |
|
| 962 | - ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
| 963 | - : '', |
|
| 964 | - 't_city' => $exists[4] |
|
| 965 | - ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
| 966 | - : '', |
|
| 967 | - 't_subcity' => $exists[5] |
|
| 968 | - ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
| 969 | - : '', |
|
| 970 | - ); |
|
| 971 | - // phpcs:enable |
|
| 972 | - } |
|
| 973 | - usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
| 974 | - $structure = array(); |
|
| 975 | - if (empty($selected_zone)) { |
|
| 976 | - $structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>'; |
|
| 977 | - } |
|
| 978 | - foreach ($zone_data as $key => $zone) { |
|
| 979 | - // Build value in an array to join later |
|
| 980 | - $value = array($zone['continent']); |
|
| 981 | - if (empty($zone['city'])) { |
|
| 982 | - // It's at the continent level (generally won't happen) |
|
| 983 | - $display = $zone['t_continent']; |
|
| 984 | - } else { |
|
| 985 | - // It's inside a continent group |
|
| 986 | - // Continent optgroup |
|
| 987 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
| 988 | - $label = $zone['t_continent']; |
|
| 989 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 990 | - } |
|
| 991 | - // Add the city to the value |
|
| 992 | - $value[] = $zone['city']; |
|
| 993 | - $display = $zone['t_city']; |
|
| 994 | - if (! empty($zone['subcity'])) { |
|
| 995 | - // Add the subcity to the value |
|
| 996 | - $value[] = $zone['subcity']; |
|
| 997 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 998 | - } |
|
| 999 | - } |
|
| 1000 | - // Build the value |
|
| 1001 | - $value = implode('/', $value); |
|
| 1002 | - $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
|
| 1003 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
| 1004 | - . esc_html($display) |
|
| 1005 | - . '</option>'; |
|
| 1006 | - // Close continent optgroup |
|
| 1007 | - if ( |
|
| 1008 | - ! empty($zone['city']) |
|
| 1009 | - && ( |
|
| 1010 | - ! isset($zone_data[ $key + 1 ]) |
|
| 1011 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
| 1012 | - ) |
|
| 1013 | - ) { |
|
| 1014 | - $structure[] = '</optgroup>'; |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - return implode("\n", $structure); |
|
| 1018 | - } |
|
| 904 | + /** |
|
| 905 | + * ** |
|
| 906 | + * Gives a nicely-formatted list of timezone strings. |
|
| 907 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 908 | + * |
|
| 909 | + * @since 4.9.40.rc.008 |
|
| 910 | + * @staticvar bool $mo_loaded |
|
| 911 | + * @staticvar string $locale_loaded |
|
| 912 | + * @param string $selected_zone Selected timezone. |
|
| 913 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 914 | + * @return string |
|
| 915 | + */ |
|
| 916 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 917 | + { |
|
| 918 | + static $mo_loaded = false, $locale_loaded = null; |
|
| 919 | + $continents = array( |
|
| 920 | + 'Africa', |
|
| 921 | + 'America', |
|
| 922 | + 'Antarctica', |
|
| 923 | + 'Arctic', |
|
| 924 | + 'Asia', |
|
| 925 | + 'Atlantic', |
|
| 926 | + 'Australia', |
|
| 927 | + 'Europe', |
|
| 928 | + 'Indian', |
|
| 929 | + 'Pacific', |
|
| 930 | + ); |
|
| 931 | + // Load translations for continents and cities. |
|
| 932 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 933 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
| 934 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 935 | + unload_textdomain('continents-cities'); |
|
| 936 | + load_textdomain('continents-cities', $mofile); |
|
| 937 | + $mo_loaded = true; |
|
| 938 | + } |
|
| 939 | + $zone_data = array(); |
|
| 940 | + foreach (timezone_identifiers_list() as $zone) { |
|
| 941 | + $zone = explode('/', $zone); |
|
| 942 | + if (! in_array($zone[0], $continents, true)) { |
|
| 943 | + continue; |
|
| 944 | + } |
|
| 945 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 946 | + $exists = array( |
|
| 947 | + 0 => isset($zone[0]) && $zone[0], |
|
| 948 | + 1 => isset($zone[1]) && $zone[1], |
|
| 949 | + 2 => isset($zone[2]) && $zone[2], |
|
| 950 | + ); |
|
| 951 | + $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
| 952 | + $exists[4] = $exists[1] && $exists[3]; |
|
| 953 | + $exists[5] = $exists[2] && $exists[3]; |
|
| 954 | + // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
| 955 | + // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
| 956 | + // disabled because this code is copied from WordPress and is a WordPress domain |
|
| 957 | + $zone_data[] = array( |
|
| 958 | + 'continent' => $exists[0] ? $zone[0] : '', |
|
| 959 | + 'city' => $exists[1] ? $zone[1] : '', |
|
| 960 | + 'subcity' => $exists[2] ? $zone[2] : '', |
|
| 961 | + 't_continent' => $exists[3] |
|
| 962 | + ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
| 963 | + : '', |
|
| 964 | + 't_city' => $exists[4] |
|
| 965 | + ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
| 966 | + : '', |
|
| 967 | + 't_subcity' => $exists[5] |
|
| 968 | + ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
| 969 | + : '', |
|
| 970 | + ); |
|
| 971 | + // phpcs:enable |
|
| 972 | + } |
|
| 973 | + usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
| 974 | + $structure = array(); |
|
| 975 | + if (empty($selected_zone)) { |
|
| 976 | + $structure[] = '<option selected="selected" value="">' . __('Select a city', 'event_espresso') . '</option>'; |
|
| 977 | + } |
|
| 978 | + foreach ($zone_data as $key => $zone) { |
|
| 979 | + // Build value in an array to join later |
|
| 980 | + $value = array($zone['continent']); |
|
| 981 | + if (empty($zone['city'])) { |
|
| 982 | + // It's at the continent level (generally won't happen) |
|
| 983 | + $display = $zone['t_continent']; |
|
| 984 | + } else { |
|
| 985 | + // It's inside a continent group |
|
| 986 | + // Continent optgroup |
|
| 987 | + if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
| 988 | + $label = $zone['t_continent']; |
|
| 989 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 990 | + } |
|
| 991 | + // Add the city to the value |
|
| 992 | + $value[] = $zone['city']; |
|
| 993 | + $display = $zone['t_city']; |
|
| 994 | + if (! empty($zone['subcity'])) { |
|
| 995 | + // Add the subcity to the value |
|
| 996 | + $value[] = $zone['subcity']; |
|
| 997 | + $display .= ' - ' . $zone['t_subcity']; |
|
| 998 | + } |
|
| 999 | + } |
|
| 1000 | + // Build the value |
|
| 1001 | + $value = implode('/', $value); |
|
| 1002 | + $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
|
| 1003 | + $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
| 1004 | + . esc_html($display) |
|
| 1005 | + . '</option>'; |
|
| 1006 | + // Close continent optgroup |
|
| 1007 | + if ( |
|
| 1008 | + ! empty($zone['city']) |
|
| 1009 | + && ( |
|
| 1010 | + ! isset($zone_data[ $key + 1 ]) |
|
| 1011 | + || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
| 1012 | + ) |
|
| 1013 | + ) { |
|
| 1014 | + $structure[] = '</optgroup>'; |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + return implode("\n", $structure); |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | 1020 | |
| 1021 | - /** |
|
| 1022 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1023 | - * |
|
| 1024 | - * @param int|WP_User $user_id |
|
| 1025 | - * @return string |
|
| 1026 | - */ |
|
| 1027 | - public static function get_user_locale($user_id = 0) |
|
| 1028 | - { |
|
| 1029 | - if (function_exists('get_user_locale')) { |
|
| 1030 | - return get_user_locale($user_id); |
|
| 1031 | - } |
|
| 1032 | - return get_locale(); |
|
| 1033 | - } |
|
| 1021 | + /** |
|
| 1022 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1023 | + * |
|
| 1024 | + * @param int|WP_User $user_id |
|
| 1025 | + * @return string |
|
| 1026 | + */ |
|
| 1027 | + public static function get_user_locale($user_id = 0) |
|
| 1028 | + { |
|
| 1029 | + if (function_exists('get_user_locale')) { |
|
| 1030 | + return get_user_locale($user_id); |
|
| 1031 | + } |
|
| 1032 | + return get_locale(); |
|
| 1033 | + } |
|
| 1034 | 1034 | |
| 1035 | 1035 | |
| 1036 | - /** |
|
| 1037 | - * Return the appropriate helper adapter for DTT related things. |
|
| 1038 | - * |
|
| 1039 | - * @return HelperInterface |
|
| 1040 | - * @throws InvalidArgumentException |
|
| 1041 | - * @throws InvalidDataTypeException |
|
| 1042 | - * @throws InvalidInterfaceException |
|
| 1043 | - */ |
|
| 1044 | - private static function getHelperAdapter() |
|
| 1045 | - { |
|
| 1046 | - $dtt_helper_fqcn = PHP_VERSION_ID < 50600 |
|
| 1047 | - ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper' |
|
| 1048 | - : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'; |
|
| 1049 | - return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn); |
|
| 1050 | - } |
|
| 1036 | + /** |
|
| 1037 | + * Return the appropriate helper adapter for DTT related things. |
|
| 1038 | + * |
|
| 1039 | + * @return HelperInterface |
|
| 1040 | + * @throws InvalidArgumentException |
|
| 1041 | + * @throws InvalidDataTypeException |
|
| 1042 | + * @throws InvalidInterfaceException |
|
| 1043 | + */ |
|
| 1044 | + private static function getHelperAdapter() |
|
| 1045 | + { |
|
| 1046 | + $dtt_helper_fqcn = PHP_VERSION_ID < 50600 |
|
| 1047 | + ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper' |
|
| 1048 | + : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'; |
|
| 1049 | + return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn); |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | 1052 | |
| 1053 | - /** |
|
| 1054 | - * Helper function for setting the timezone on a DateTime object. |
|
| 1055 | - * This is implemented to standardize a workaround for a PHP bug outlined in |
|
| 1056 | - * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and |
|
| 1057 | - * https://events.codebasehq.com/projects/event-espresso/tickets/11233 |
|
| 1058 | - * |
|
| 1059 | - * @param DateTime $datetime |
|
| 1060 | - * @param DateTimeZone $timezone |
|
| 1061 | - */ |
|
| 1062 | - public static function setTimezone(DateTime $datetime, DateTimeZone $timezone) |
|
| 1063 | - { |
|
| 1064 | - $datetime->setTimezone($timezone); |
|
| 1065 | - $datetime->getTimestamp(); |
|
| 1066 | - } |
|
| 1053 | + /** |
|
| 1054 | + * Helper function for setting the timezone on a DateTime object. |
|
| 1055 | + * This is implemented to standardize a workaround for a PHP bug outlined in |
|
| 1056 | + * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and |
|
| 1057 | + * https://events.codebasehq.com/projects/event-espresso/tickets/11233 |
|
| 1058 | + * |
|
| 1059 | + * @param DateTime $datetime |
|
| 1060 | + * @param DateTimeZone $timezone |
|
| 1061 | + */ |
|
| 1062 | + public static function setTimezone(DateTime $datetime, DateTimeZone $timezone) |
|
| 1063 | + { |
|
| 1064 | + $datetime->setTimezone($timezone); |
|
| 1065 | + $datetime->getTimestamp(); |
|
| 1066 | + } |
|
| 1067 | 1067 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | private function setScheme($url) |
| 93 | 93 | { |
| 94 | - $this->scheme = $url['scheme'] . '://'; |
|
| 94 | + $this->scheme = $url['scheme'].'://'; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function queryString() |
| 147 | 147 | { |
| 148 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
| 148 | + return $this->query !== '' ? '?'.$this->query : ''; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function fragment() |
| 180 | 180 | { |
| 181 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
| 181 | + return $this->fragment !== '' ? '#'.$this->fragment : ''; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function getFullUrl() |
| 201 | 201 | { |
| 202 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
| 202 | + return $this->scheme().$this->host().$this->path().$this->queryString().$this->fragment(); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -17,200 +17,200 @@ |
||
| 17 | 17 | class Url |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string $scheme |
|
| 22 | - */ |
|
| 23 | - private $scheme; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string $host |
|
| 27 | - */ |
|
| 28 | - private $host; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string $path |
|
| 32 | - */ |
|
| 33 | - private $path; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string $query |
|
| 37 | - */ |
|
| 38 | - private $query; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string $fragment |
|
| 42 | - */ |
|
| 43 | - private $fragment; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Url constructor. |
|
| 48 | - * |
|
| 49 | - * @param $url |
|
| 50 | - * @throws InvalidArgumentException |
|
| 51 | - */ |
|
| 52 | - public function __construct($url) |
|
| 53 | - { |
|
| 54 | - if ( |
|
| 55 | - ! filter_var( |
|
| 56 | - $url, |
|
| 57 | - FILTER_VALIDATE_URL, |
|
| 58 | - array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED) |
|
| 59 | - ) |
|
| 60 | - ) { |
|
| 61 | - throw new InvalidArgumentException( |
|
| 62 | - esc_html__( |
|
| 63 | - 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ) |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - $url = parse_url($url); |
|
| 69 | - $this->setScheme($url); |
|
| 70 | - $this->setHost($url); |
|
| 71 | - $this->setPath($url); |
|
| 72 | - $this->setQuery($url); |
|
| 73 | - $this->setFragment($url); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 79 | - * will return a string like: 'abc://' |
|
| 80 | - * |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function scheme() |
|
| 84 | - { |
|
| 85 | - return $this->scheme; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param array $url |
|
| 91 | - */ |
|
| 92 | - private function setScheme($url) |
|
| 93 | - { |
|
| 94 | - $this->scheme = $url['scheme'] . '://'; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 100 | - * will return a string like: 'example.com' |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - public function host() |
|
| 105 | - { |
|
| 106 | - return $this->host; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param array $url |
|
| 112 | - */ |
|
| 113 | - private function setHost($url) |
|
| 114 | - { |
|
| 115 | - $this->host = $url['host']; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 121 | - * will return a string like: '/path/data' |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public function path() |
|
| 126 | - { |
|
| 127 | - return $this->path; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @param array $url |
|
| 133 | - */ |
|
| 134 | - private function setPath($url) |
|
| 135 | - { |
|
| 136 | - $this->path = isset($url['path']) ? $url['path'] : ''; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 142 | - * will return a string like: '?key=value' |
|
| 143 | - * |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function queryString() |
|
| 147 | - { |
|
| 148 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 154 | - * will return an array like: array('key' => 'value') |
|
| 155 | - * |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - public function queryParams() |
|
| 159 | - { |
|
| 160 | - return wp_parse_args($this->query); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param array $url |
|
| 166 | - */ |
|
| 167 | - private function setQuery($url) |
|
| 168 | - { |
|
| 169 | - $this->query = isset($url['query']) ? $url['query'] : ''; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 175 | - * will return a string like: '#id' |
|
| 176 | - * |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - public function fragment() |
|
| 180 | - { |
|
| 181 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @param array $url |
|
| 187 | - */ |
|
| 188 | - private function setFragment($url) |
|
| 189 | - { |
|
| 190 | - $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 196 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
| 197 | - * |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public function getFullUrl() |
|
| 201 | - { |
|
| 202 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 208 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
| 209 | - * |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public function __toString() |
|
| 213 | - { |
|
| 214 | - return $this->getFullUrl(); |
|
| 215 | - } |
|
| 20 | + /** |
|
| 21 | + * @var string $scheme |
|
| 22 | + */ |
|
| 23 | + private $scheme; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string $host |
|
| 27 | + */ |
|
| 28 | + private $host; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string $path |
|
| 32 | + */ |
|
| 33 | + private $path; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string $query |
|
| 37 | + */ |
|
| 38 | + private $query; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string $fragment |
|
| 42 | + */ |
|
| 43 | + private $fragment; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Url constructor. |
|
| 48 | + * |
|
| 49 | + * @param $url |
|
| 50 | + * @throws InvalidArgumentException |
|
| 51 | + */ |
|
| 52 | + public function __construct($url) |
|
| 53 | + { |
|
| 54 | + if ( |
|
| 55 | + ! filter_var( |
|
| 56 | + $url, |
|
| 57 | + FILTER_VALIDATE_URL, |
|
| 58 | + array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED) |
|
| 59 | + ) |
|
| 60 | + ) { |
|
| 61 | + throw new InvalidArgumentException( |
|
| 62 | + esc_html__( |
|
| 63 | + 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ) |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + $url = parse_url($url); |
|
| 69 | + $this->setScheme($url); |
|
| 70 | + $this->setHost($url); |
|
| 71 | + $this->setPath($url); |
|
| 72 | + $this->setQuery($url); |
|
| 73 | + $this->setFragment($url); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 79 | + * will return a string like: 'abc://' |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function scheme() |
|
| 84 | + { |
|
| 85 | + return $this->scheme; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param array $url |
|
| 91 | + */ |
|
| 92 | + private function setScheme($url) |
|
| 93 | + { |
|
| 94 | + $this->scheme = $url['scheme'] . '://'; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 100 | + * will return a string like: 'example.com' |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + public function host() |
|
| 105 | + { |
|
| 106 | + return $this->host; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param array $url |
|
| 112 | + */ |
|
| 113 | + private function setHost($url) |
|
| 114 | + { |
|
| 115 | + $this->host = $url['host']; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 121 | + * will return a string like: '/path/data' |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public function path() |
|
| 126 | + { |
|
| 127 | + return $this->path; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @param array $url |
|
| 133 | + */ |
|
| 134 | + private function setPath($url) |
|
| 135 | + { |
|
| 136 | + $this->path = isset($url['path']) ? $url['path'] : ''; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 142 | + * will return a string like: '?key=value' |
|
| 143 | + * |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function queryString() |
|
| 147 | + { |
|
| 148 | + return $this->query !== '' ? '?' . $this->query : ''; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 154 | + * will return an array like: array('key' => 'value') |
|
| 155 | + * |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + public function queryParams() |
|
| 159 | + { |
|
| 160 | + return wp_parse_args($this->query); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param array $url |
|
| 166 | + */ |
|
| 167 | + private function setQuery($url) |
|
| 168 | + { |
|
| 169 | + $this->query = isset($url['query']) ? $url['query'] : ''; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 175 | + * will return a string like: '#id' |
|
| 176 | + * |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + public function fragment() |
|
| 180 | + { |
|
| 181 | + return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @param array $url |
|
| 187 | + */ |
|
| 188 | + private function setFragment($url) |
|
| 189 | + { |
|
| 190 | + $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 196 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
| 197 | + * |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public function getFullUrl() |
|
| 201 | + { |
|
| 202 | + return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
| 208 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
| 209 | + * |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + public function __toString() |
|
| 213 | + { |
|
| 214 | + return $this->getFullUrl(); |
|
| 215 | + } |
|
| 216 | 216 | } |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | { |
| 88 | 88 | $this->evaluation_callback = $evaluation_callback instanceof Closure |
| 89 | 89 | ? $evaluation_callback |
| 90 | - : function (ContextInterface $context, $acceptable_values) { |
|
| 90 | + : function(ContextInterface $context, $acceptable_values) { |
|
| 91 | 91 | return in_array($context->slug(), $acceptable_values, true); |
| 92 | 92 | }; |
| 93 | 93 | } |
@@ -17,145 +17,145 @@ |
||
| 17 | 17 | class ContextChecker |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * A unique string used to identify where this ContextChecker is being employed |
|
| 22 | - * Is currently only used within the hook name for the filterable return value of isAllowed(). |
|
| 23 | - * |
|
| 24 | - * @var string $identifier |
|
| 25 | - */ |
|
| 26 | - private $identifier; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * A list of values to be compared against the slug of the Context class passed to isAllowed() |
|
| 30 | - * |
|
| 31 | - * @var array $acceptable_values |
|
| 32 | - */ |
|
| 33 | - private $acceptable_values; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Closure that will be called to perform the evaluation within isAllowed(). |
|
| 37 | - * If none is provided, then a simple type sensitive in_array() check will be used |
|
| 38 | - * and return true if the incoming Context::slug() is found within the array of $acceptable_values. |
|
| 39 | - * |
|
| 40 | - * @var Closure $evaluation_callback |
|
| 41 | - */ |
|
| 42 | - private $evaluation_callback; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * ContextChecker constructor. |
|
| 47 | - * |
|
| 48 | - * @param string $identifier |
|
| 49 | - * @param array $acceptable_values |
|
| 50 | - * @param Closure|null $evaluation_callback [optional] |
|
| 51 | - */ |
|
| 52 | - public function __construct($identifier, array $acceptable_values, Closure $evaluation_callback = null) |
|
| 53 | - { |
|
| 54 | - $this->setIdentifier($identifier); |
|
| 55 | - $this->setAcceptableValues($acceptable_values); |
|
| 56 | - $this->setEvaluationCallback($evaluation_callback); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param string $identifier |
|
| 62 | - */ |
|
| 63 | - private function setIdentifier($identifier) |
|
| 64 | - { |
|
| 65 | - $this->identifier = sanitize_key($identifier); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param array $acceptable_values |
|
| 71 | - */ |
|
| 72 | - private function setAcceptableValues(array $acceptable_values) |
|
| 73 | - { |
|
| 74 | - $this->acceptable_values = $acceptable_values; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param Closure $evaluation_callback |
|
| 80 | - */ |
|
| 81 | - private function setEvaluationCallback(Closure $evaluation_callback = null) |
|
| 82 | - { |
|
| 83 | - $this->evaluation_callback = $evaluation_callback instanceof Closure |
|
| 84 | - ? $evaluation_callback |
|
| 85 | - : function (ContextInterface $context, $acceptable_values) { |
|
| 86 | - return in_array($context->slug(), $acceptable_values, true); |
|
| 87 | - }; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - protected function identifier() |
|
| 95 | - { |
|
| 96 | - return $this->identifier; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - protected function acceptableValues() |
|
| 104 | - { |
|
| 105 | - return apply_filters( |
|
| 106 | - "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__acceptableValues", |
|
| 107 | - $this->acceptable_values |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return Closure |
|
| 114 | - */ |
|
| 115 | - protected function evaluationCallback() |
|
| 116 | - { |
|
| 117 | - return $this->evaluation_callback; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Returns true if the incoming Context class slug matches one of the preset acceptable values. |
|
| 123 | - * The result is filterable using the identifier for this ContextChecker. |
|
| 124 | - * example: |
|
| 125 | - * If this ContextChecker's $identifier was set to "registration-checkout-type", |
|
| 126 | - * then the filter here would be named: |
|
| 127 | - * "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed". |
|
| 128 | - * Other code could hook into the filter in isAllowed() using the above name |
|
| 129 | - * and test for additional acceptable values. |
|
| 130 | - * So if the set of $acceptable_values was: [ "initial-visit", "revisit" ] |
|
| 131 | - * then adding a filter to |
|
| 132 | - * "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed", |
|
| 133 | - * would allow you to perform your own conditional and allow "wait-list-checkout" as an acceptable value. |
|
| 134 | - * example: |
|
| 135 | - * add_filter( |
|
| 136 | - * 'FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed', |
|
| 137 | - * function ($is_allowed, ContextInterface $context) { return $context->slug() === 'wait-list-checkout' |
|
| 138 | - * ? true |
|
| 139 | - * : $is_allowed; |
|
| 140 | - * }, |
|
| 141 | - * 10, |
|
| 142 | - * 2 |
|
| 143 | - * ); |
|
| 144 | - * |
|
| 145 | - * @param ContextInterface $context |
|
| 146 | - * @return boolean |
|
| 147 | - */ |
|
| 148 | - public function isAllowed(ContextInterface $context) |
|
| 149 | - { |
|
| 150 | - $evaluation_callback = $this->evaluationCallback(); |
|
| 151 | - return filter_var( |
|
| 152 | - apply_filters( |
|
| 153 | - "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__isAllowed", |
|
| 154 | - $evaluation_callback($context, $this->acceptableValues()), |
|
| 155 | - $context, |
|
| 156 | - $this |
|
| 157 | - ), |
|
| 158 | - FILTER_VALIDATE_BOOLEAN |
|
| 159 | - ); |
|
| 160 | - } |
|
| 20 | + /** |
|
| 21 | + * A unique string used to identify where this ContextChecker is being employed |
|
| 22 | + * Is currently only used within the hook name for the filterable return value of isAllowed(). |
|
| 23 | + * |
|
| 24 | + * @var string $identifier |
|
| 25 | + */ |
|
| 26 | + private $identifier; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * A list of values to be compared against the slug of the Context class passed to isAllowed() |
|
| 30 | + * |
|
| 31 | + * @var array $acceptable_values |
|
| 32 | + */ |
|
| 33 | + private $acceptable_values; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Closure that will be called to perform the evaluation within isAllowed(). |
|
| 37 | + * If none is provided, then a simple type sensitive in_array() check will be used |
|
| 38 | + * and return true if the incoming Context::slug() is found within the array of $acceptable_values. |
|
| 39 | + * |
|
| 40 | + * @var Closure $evaluation_callback |
|
| 41 | + */ |
|
| 42 | + private $evaluation_callback; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * ContextChecker constructor. |
|
| 47 | + * |
|
| 48 | + * @param string $identifier |
|
| 49 | + * @param array $acceptable_values |
|
| 50 | + * @param Closure|null $evaluation_callback [optional] |
|
| 51 | + */ |
|
| 52 | + public function __construct($identifier, array $acceptable_values, Closure $evaluation_callback = null) |
|
| 53 | + { |
|
| 54 | + $this->setIdentifier($identifier); |
|
| 55 | + $this->setAcceptableValues($acceptable_values); |
|
| 56 | + $this->setEvaluationCallback($evaluation_callback); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param string $identifier |
|
| 62 | + */ |
|
| 63 | + private function setIdentifier($identifier) |
|
| 64 | + { |
|
| 65 | + $this->identifier = sanitize_key($identifier); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param array $acceptable_values |
|
| 71 | + */ |
|
| 72 | + private function setAcceptableValues(array $acceptable_values) |
|
| 73 | + { |
|
| 74 | + $this->acceptable_values = $acceptable_values; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param Closure $evaluation_callback |
|
| 80 | + */ |
|
| 81 | + private function setEvaluationCallback(Closure $evaluation_callback = null) |
|
| 82 | + { |
|
| 83 | + $this->evaluation_callback = $evaluation_callback instanceof Closure |
|
| 84 | + ? $evaluation_callback |
|
| 85 | + : function (ContextInterface $context, $acceptable_values) { |
|
| 86 | + return in_array($context->slug(), $acceptable_values, true); |
|
| 87 | + }; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + protected function identifier() |
|
| 95 | + { |
|
| 96 | + return $this->identifier; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + protected function acceptableValues() |
|
| 104 | + { |
|
| 105 | + return apply_filters( |
|
| 106 | + "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__acceptableValues", |
|
| 107 | + $this->acceptable_values |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return Closure |
|
| 114 | + */ |
|
| 115 | + protected function evaluationCallback() |
|
| 116 | + { |
|
| 117 | + return $this->evaluation_callback; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Returns true if the incoming Context class slug matches one of the preset acceptable values. |
|
| 123 | + * The result is filterable using the identifier for this ContextChecker. |
|
| 124 | + * example: |
|
| 125 | + * If this ContextChecker's $identifier was set to "registration-checkout-type", |
|
| 126 | + * then the filter here would be named: |
|
| 127 | + * "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed". |
|
| 128 | + * Other code could hook into the filter in isAllowed() using the above name |
|
| 129 | + * and test for additional acceptable values. |
|
| 130 | + * So if the set of $acceptable_values was: [ "initial-visit", "revisit" ] |
|
| 131 | + * then adding a filter to |
|
| 132 | + * "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed", |
|
| 133 | + * would allow you to perform your own conditional and allow "wait-list-checkout" as an acceptable value. |
|
| 134 | + * example: |
|
| 135 | + * add_filter( |
|
| 136 | + * 'FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed', |
|
| 137 | + * function ($is_allowed, ContextInterface $context) { return $context->slug() === 'wait-list-checkout' |
|
| 138 | + * ? true |
|
| 139 | + * : $is_allowed; |
|
| 140 | + * }, |
|
| 141 | + * 10, |
|
| 142 | + * 2 |
|
| 143 | + * ); |
|
| 144 | + * |
|
| 145 | + * @param ContextInterface $context |
|
| 146 | + * @return boolean |
|
| 147 | + */ |
|
| 148 | + public function isAllowed(ContextInterface $context) |
|
| 149 | + { |
|
| 150 | + $evaluation_callback = $this->evaluationCallback(); |
|
| 151 | + return filter_var( |
|
| 152 | + apply_filters( |
|
| 153 | + "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__isAllowed", |
|
| 154 | + $evaluation_callback($context, $this->acceptableValues()), |
|
| 155 | + $context, |
|
| 156 | + $this |
|
| 157 | + ), |
|
| 158 | + FILTER_VALIDATE_BOOLEAN |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -18,14 +18,14 @@ |
||
| 18 | 18 | interface ContextInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - public function slug(); |
|
| 21 | + /** |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + public function slug(); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function description(); |
|
| 27 | + /** |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function description(); |
|
| 31 | 31 | } |
@@ -2166,6 +2166,7 @@ |
||
| 2166 | 2166 | * |
| 2167 | 2167 | * @access protected |
| 2168 | 2168 | * @param \EE_Payment | null $payment |
| 2169 | + * @param EE_Payment $payment |
|
| 2169 | 2170 | */ |
| 2170 | 2171 | protected function _maybe_send_notifications($payment = null) |
| 2171 | 2172 | { |
@@ -13,2572 +13,2572 @@ |
||
| 13 | 13 | class Transactions_Admin_Page extends EE_Admin_Page |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EE_Transaction |
|
| 18 | - */ |
|
| 19 | - private $_transaction; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var EE_Session |
|
| 23 | - */ |
|
| 24 | - private $_session; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array $_txn_status |
|
| 28 | - */ |
|
| 29 | - private static $_txn_status; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array $_pay_status |
|
| 33 | - */ |
|
| 34 | - private static $_pay_status; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | - */ |
|
| 39 | - protected $_existing_reg_payment_REG_IDs; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * _init_page_props |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - protected function _init_page_props() |
|
| 48 | - { |
|
| 49 | - $this->page_slug = TXN_PG_SLUG; |
|
| 50 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * _ajax_hooks |
|
| 58 | - * |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - protected function _ajax_hooks() |
|
| 62 | - { |
|
| 63 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * _define_page_props |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _define_page_props() |
|
| 75 | - { |
|
| 76 | - $this->_admin_page_title = $this->page_label; |
|
| 77 | - $this->_labels = array( |
|
| 78 | - 'buttons' => array( |
|
| 79 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | - ), |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * grab url requests and route them |
|
| 89 | - * |
|
| 90 | - * @access private |
|
| 91 | - * @return void |
|
| 92 | - * @throws EE_Error |
|
| 93 | - * @throws InvalidArgumentException |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidInterfaceException |
|
| 96 | - */ |
|
| 97 | - public function _set_page_routes() |
|
| 98 | - { |
|
| 99 | - |
|
| 100 | - $this->_set_transaction_status_array(); |
|
| 101 | - |
|
| 102 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | - && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | - ? $this->_req_data['TXN_ID'] |
|
| 105 | - : 0; |
|
| 106 | - |
|
| 107 | - $this->_page_routes = array( |
|
| 108 | - |
|
| 109 | - 'default' => array( |
|
| 110 | - 'func' => '_transactions_overview_list_table', |
|
| 111 | - 'capability' => 'ee_read_transactions', |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'view_transaction' => array( |
|
| 115 | - 'func' => '_transaction_details', |
|
| 116 | - 'capability' => 'ee_read_transaction', |
|
| 117 | - 'obj_id' => $txn_id, |
|
| 118 | - ), |
|
| 119 | - |
|
| 120 | - 'send_payment_reminder' => array( |
|
| 121 | - 'func' => '_send_payment_reminder', |
|
| 122 | - 'noheader' => true, |
|
| 123 | - 'capability' => 'ee_send_message', |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'espresso_apply_payment' => array( |
|
| 127 | - 'func' => 'apply_payments_or_refunds', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - 'capability' => 'ee_edit_payments', |
|
| 130 | - ), |
|
| 131 | - |
|
| 132 | - 'espresso_apply_refund' => array( |
|
| 133 | - 'func' => 'apply_payments_or_refunds', |
|
| 134 | - 'noheader' => true, |
|
| 135 | - 'capability' => 'ee_edit_payments', |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'espresso_delete_payment' => array( |
|
| 139 | - 'func' => 'delete_payment', |
|
| 140 | - 'noheader' => true, |
|
| 141 | - 'capability' => 'ee_delete_payments', |
|
| 142 | - ), |
|
| 143 | - |
|
| 144 | - 'espresso_recalculate_line_items' => array( |
|
| 145 | - 'func' => 'recalculateLineItems', |
|
| 146 | - 'noheader' => true, |
|
| 147 | - 'capability' => 'ee_edit_payments', |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - protected function _set_page_config() |
|
| 155 | - { |
|
| 156 | - $this->_page_config = array( |
|
| 157 | - 'default' => array( |
|
| 158 | - 'nav' => array( |
|
| 159 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | - 'order' => 10, |
|
| 161 | - ), |
|
| 162 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | - 'help_tabs' => array( |
|
| 164 | - 'transactions_overview_help_tab' => array( |
|
| 165 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | - 'filename' => 'transactions_overview', |
|
| 167 | - ), |
|
| 168 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | - 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | - ), |
|
| 172 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | - 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | - ), |
|
| 176 | - ), |
|
| 177 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | - /** |
|
| 179 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | - * may change in a later iteration so want to keep the code for then. |
|
| 181 | - */ |
|
| 182 | - // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | - 'require_nonce' => false, |
|
| 184 | - ), |
|
| 185 | - 'view_transaction' => array( |
|
| 186 | - 'nav' => array( |
|
| 187 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | - 'order' => 5, |
|
| 189 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | - : $this->_admin_base_url, |
|
| 192 | - 'persistent' => false, |
|
| 193 | - ), |
|
| 194 | - 'help_tabs' => array( |
|
| 195 | - 'transactions_view_transaction_help_tab' => array( |
|
| 196 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | - 'filename' => 'transactions_view_transaction', |
|
| 198 | - ), |
|
| 199 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | - ), |
|
| 203 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | - ), |
|
| 207 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | - ), |
|
| 211 | - ), |
|
| 212 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | - |
|
| 216 | - 'require_nonce' => false, |
|
| 217 | - ), |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * The below methods aren't used by this class currently |
|
| 224 | - */ |
|
| 225 | - protected function _add_screen_options() |
|
| 226 | - { |
|
| 227 | - // noop |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - protected function _add_feature_pointers() |
|
| 232 | - { |
|
| 233 | - // noop |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - public function admin_init() |
|
| 238 | - { |
|
| 239 | - // IF a registration was JUST added via the admin... |
|
| 240 | - if ( |
|
| 241 | - isset( |
|
| 242 | - $this->_req_data['redirect_from'], |
|
| 243 | - $this->_req_data['EVT_ID'], |
|
| 244 | - $this->_req_data['event_name'] |
|
| 245 | - ) |
|
| 246 | - ) { |
|
| 247 | - // then set a cookie so that we can block any attempts to use |
|
| 248 | - // the back button as a way to enter another registration. |
|
| 249 | - setcookie( |
|
| 250 | - 'ee_registration_added', |
|
| 251 | - $this->_req_data['EVT_ID'], |
|
| 252 | - time() + WEEK_IN_SECONDS, |
|
| 253 | - '/' |
|
| 254 | - ); |
|
| 255 | - // and update the global |
|
| 256 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 257 | - } |
|
| 258 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 259 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 260 | - 'event_espresso' |
|
| 261 | - ); |
|
| 262 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 263 | - 'An error occurred! Please refresh the page and try again.', |
|
| 264 | - 'event_espresso' |
|
| 265 | - ); |
|
| 266 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 267 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 268 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 269 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 270 | - 'This transaction has been overpaid ! Payments Total', |
|
| 271 | - 'event_espresso' |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - public function admin_notices() |
|
| 277 | - { |
|
| 278 | - // noop |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - public function admin_footer_scripts() |
|
| 283 | - { |
|
| 284 | - // noop |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * _set_transaction_status_array |
|
| 290 | - * sets list of transaction statuses |
|
| 291 | - * |
|
| 292 | - * @access private |
|
| 293 | - * @return void |
|
| 294 | - * @throws EE_Error |
|
| 295 | - * @throws InvalidArgumentException |
|
| 296 | - * @throws InvalidDataTypeException |
|
| 297 | - * @throws InvalidInterfaceException |
|
| 298 | - */ |
|
| 299 | - private function _set_transaction_status_array() |
|
| 300 | - { |
|
| 301 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * get_transaction_status_array |
|
| 307 | - * return the transaction status array for wp_list_table |
|
| 308 | - * |
|
| 309 | - * @access public |
|
| 310 | - * @return array |
|
| 311 | - */ |
|
| 312 | - public function get_transaction_status_array() |
|
| 313 | - { |
|
| 314 | - return self::$_txn_status; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * get list of payment statuses |
|
| 320 | - * |
|
| 321 | - * @access private |
|
| 322 | - * @return void |
|
| 323 | - * @throws EE_Error |
|
| 324 | - * @throws InvalidArgumentException |
|
| 325 | - * @throws InvalidDataTypeException |
|
| 326 | - * @throws InvalidInterfaceException |
|
| 327 | - */ |
|
| 328 | - private function _get_payment_status_array() |
|
| 329 | - { |
|
| 330 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 331 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * _add_screen_options_default |
|
| 337 | - * |
|
| 338 | - * @access protected |
|
| 339 | - * @return void |
|
| 340 | - * @throws InvalidArgumentException |
|
| 341 | - * @throws InvalidDataTypeException |
|
| 342 | - * @throws InvalidInterfaceException |
|
| 343 | - */ |
|
| 344 | - protected function _add_screen_options_default() |
|
| 345 | - { |
|
| 346 | - $this->_per_page_screen_option(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * load_scripts_styles |
|
| 352 | - * |
|
| 353 | - * @access public |
|
| 354 | - * @return void |
|
| 355 | - */ |
|
| 356 | - public function load_scripts_styles() |
|
| 357 | - { |
|
| 358 | - // enqueue style |
|
| 359 | - wp_register_style( |
|
| 360 | - 'espresso_txn', |
|
| 361 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 362 | - array(), |
|
| 363 | - EVENT_ESPRESSO_VERSION |
|
| 364 | - ); |
|
| 365 | - wp_enqueue_style('espresso_txn'); |
|
| 366 | - // scripts |
|
| 367 | - wp_register_script( |
|
| 368 | - 'espresso_txn', |
|
| 369 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 370 | - array( |
|
| 371 | - 'ee_admin_js', |
|
| 372 | - 'ee-datepicker', |
|
| 373 | - 'jquery-ui-datepicker', |
|
| 374 | - 'jquery-ui-draggable', |
|
| 375 | - 'ee-dialog', |
|
| 376 | - 'ee-accounting', |
|
| 377 | - 'ee-serialize-full-array', |
|
| 378 | - ), |
|
| 379 | - EVENT_ESPRESSO_VERSION, |
|
| 380 | - true |
|
| 381 | - ); |
|
| 382 | - wp_enqueue_script('espresso_txn'); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * load_scripts_styles_view_transaction |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - * @return void |
|
| 391 | - */ |
|
| 392 | - public function load_scripts_styles_view_transaction() |
|
| 393 | - { |
|
| 394 | - // styles |
|
| 395 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * load_scripts_styles_default |
|
| 401 | - * |
|
| 402 | - * @access public |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - public function load_scripts_styles_default() |
|
| 406 | - { |
|
| 407 | - // styles |
|
| 408 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * _set_list_table_views_default |
|
| 414 | - * |
|
| 415 | - * @access protected |
|
| 416 | - * @return void |
|
| 417 | - */ |
|
| 418 | - protected function _set_list_table_views_default() |
|
| 419 | - { |
|
| 420 | - $this->_views = array( |
|
| 421 | - 'all' => array( |
|
| 422 | - 'slug' => 'all', |
|
| 423 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 424 | - 'count' => 0, |
|
| 425 | - ), |
|
| 426 | - 'abandoned' => array( |
|
| 427 | - 'slug' => 'abandoned', |
|
| 428 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 429 | - 'count' => 0, |
|
| 430 | - ), |
|
| 431 | - 'incomplete' => array( |
|
| 432 | - 'slug' => 'incomplete', |
|
| 433 | - 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 434 | - 'count' => 0, |
|
| 435 | - ), |
|
| 436 | - ); |
|
| 437 | - if ( |
|
| 16 | + /** |
|
| 17 | + * @var EE_Transaction |
|
| 18 | + */ |
|
| 19 | + private $_transaction; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var EE_Session |
|
| 23 | + */ |
|
| 24 | + private $_session; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array $_txn_status |
|
| 28 | + */ |
|
| 29 | + private static $_txn_status; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array $_pay_status |
|
| 33 | + */ |
|
| 34 | + private static $_pay_status; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | + */ |
|
| 39 | + protected $_existing_reg_payment_REG_IDs; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * _init_page_props |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + protected function _init_page_props() |
|
| 48 | + { |
|
| 49 | + $this->page_slug = TXN_PG_SLUG; |
|
| 50 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * _ajax_hooks |
|
| 58 | + * |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + protected function _ajax_hooks() |
|
| 62 | + { |
|
| 63 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * _define_page_props |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _define_page_props() |
|
| 75 | + { |
|
| 76 | + $this->_admin_page_title = $this->page_label; |
|
| 77 | + $this->_labels = array( |
|
| 78 | + 'buttons' => array( |
|
| 79 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | + ), |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * grab url requests and route them |
|
| 89 | + * |
|
| 90 | + * @access private |
|
| 91 | + * @return void |
|
| 92 | + * @throws EE_Error |
|
| 93 | + * @throws InvalidArgumentException |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidInterfaceException |
|
| 96 | + */ |
|
| 97 | + public function _set_page_routes() |
|
| 98 | + { |
|
| 99 | + |
|
| 100 | + $this->_set_transaction_status_array(); |
|
| 101 | + |
|
| 102 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | + && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | + ? $this->_req_data['TXN_ID'] |
|
| 105 | + : 0; |
|
| 106 | + |
|
| 107 | + $this->_page_routes = array( |
|
| 108 | + |
|
| 109 | + 'default' => array( |
|
| 110 | + 'func' => '_transactions_overview_list_table', |
|
| 111 | + 'capability' => 'ee_read_transactions', |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'view_transaction' => array( |
|
| 115 | + 'func' => '_transaction_details', |
|
| 116 | + 'capability' => 'ee_read_transaction', |
|
| 117 | + 'obj_id' => $txn_id, |
|
| 118 | + ), |
|
| 119 | + |
|
| 120 | + 'send_payment_reminder' => array( |
|
| 121 | + 'func' => '_send_payment_reminder', |
|
| 122 | + 'noheader' => true, |
|
| 123 | + 'capability' => 'ee_send_message', |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'espresso_apply_payment' => array( |
|
| 127 | + 'func' => 'apply_payments_or_refunds', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + 'capability' => 'ee_edit_payments', |
|
| 130 | + ), |
|
| 131 | + |
|
| 132 | + 'espresso_apply_refund' => array( |
|
| 133 | + 'func' => 'apply_payments_or_refunds', |
|
| 134 | + 'noheader' => true, |
|
| 135 | + 'capability' => 'ee_edit_payments', |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'espresso_delete_payment' => array( |
|
| 139 | + 'func' => 'delete_payment', |
|
| 140 | + 'noheader' => true, |
|
| 141 | + 'capability' => 'ee_delete_payments', |
|
| 142 | + ), |
|
| 143 | + |
|
| 144 | + 'espresso_recalculate_line_items' => array( |
|
| 145 | + 'func' => 'recalculateLineItems', |
|
| 146 | + 'noheader' => true, |
|
| 147 | + 'capability' => 'ee_edit_payments', |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + protected function _set_page_config() |
|
| 155 | + { |
|
| 156 | + $this->_page_config = array( |
|
| 157 | + 'default' => array( |
|
| 158 | + 'nav' => array( |
|
| 159 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | + 'order' => 10, |
|
| 161 | + ), |
|
| 162 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | + 'help_tabs' => array( |
|
| 164 | + 'transactions_overview_help_tab' => array( |
|
| 165 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | + 'filename' => 'transactions_overview', |
|
| 167 | + ), |
|
| 168 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | + 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | + ), |
|
| 172 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | + 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | + ), |
|
| 176 | + ), |
|
| 177 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | + /** |
|
| 179 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | + * may change in a later iteration so want to keep the code for then. |
|
| 181 | + */ |
|
| 182 | + // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | + 'require_nonce' => false, |
|
| 184 | + ), |
|
| 185 | + 'view_transaction' => array( |
|
| 186 | + 'nav' => array( |
|
| 187 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | + 'order' => 5, |
|
| 189 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | + : $this->_admin_base_url, |
|
| 192 | + 'persistent' => false, |
|
| 193 | + ), |
|
| 194 | + 'help_tabs' => array( |
|
| 195 | + 'transactions_view_transaction_help_tab' => array( |
|
| 196 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | + 'filename' => 'transactions_view_transaction', |
|
| 198 | + ), |
|
| 199 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | + ), |
|
| 203 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | + ), |
|
| 207 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | + ), |
|
| 211 | + ), |
|
| 212 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | + |
|
| 216 | + 'require_nonce' => false, |
|
| 217 | + ), |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * The below methods aren't used by this class currently |
|
| 224 | + */ |
|
| 225 | + protected function _add_screen_options() |
|
| 226 | + { |
|
| 227 | + // noop |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + protected function _add_feature_pointers() |
|
| 232 | + { |
|
| 233 | + // noop |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + public function admin_init() |
|
| 238 | + { |
|
| 239 | + // IF a registration was JUST added via the admin... |
|
| 240 | + if ( |
|
| 241 | + isset( |
|
| 242 | + $this->_req_data['redirect_from'], |
|
| 243 | + $this->_req_data['EVT_ID'], |
|
| 244 | + $this->_req_data['event_name'] |
|
| 245 | + ) |
|
| 246 | + ) { |
|
| 247 | + // then set a cookie so that we can block any attempts to use |
|
| 248 | + // the back button as a way to enter another registration. |
|
| 249 | + setcookie( |
|
| 250 | + 'ee_registration_added', |
|
| 251 | + $this->_req_data['EVT_ID'], |
|
| 252 | + time() + WEEK_IN_SECONDS, |
|
| 253 | + '/' |
|
| 254 | + ); |
|
| 255 | + // and update the global |
|
| 256 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 257 | + } |
|
| 258 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 259 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
| 260 | + 'event_espresso' |
|
| 261 | + ); |
|
| 262 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 263 | + 'An error occurred! Please refresh the page and try again.', |
|
| 264 | + 'event_espresso' |
|
| 265 | + ); |
|
| 266 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 267 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 268 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 269 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 270 | + 'This transaction has been overpaid ! Payments Total', |
|
| 271 | + 'event_espresso' |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + public function admin_notices() |
|
| 277 | + { |
|
| 278 | + // noop |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + public function admin_footer_scripts() |
|
| 283 | + { |
|
| 284 | + // noop |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * _set_transaction_status_array |
|
| 290 | + * sets list of transaction statuses |
|
| 291 | + * |
|
| 292 | + * @access private |
|
| 293 | + * @return void |
|
| 294 | + * @throws EE_Error |
|
| 295 | + * @throws InvalidArgumentException |
|
| 296 | + * @throws InvalidDataTypeException |
|
| 297 | + * @throws InvalidInterfaceException |
|
| 298 | + */ |
|
| 299 | + private function _set_transaction_status_array() |
|
| 300 | + { |
|
| 301 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * get_transaction_status_array |
|
| 307 | + * return the transaction status array for wp_list_table |
|
| 308 | + * |
|
| 309 | + * @access public |
|
| 310 | + * @return array |
|
| 311 | + */ |
|
| 312 | + public function get_transaction_status_array() |
|
| 313 | + { |
|
| 314 | + return self::$_txn_status; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * get list of payment statuses |
|
| 320 | + * |
|
| 321 | + * @access private |
|
| 322 | + * @return void |
|
| 323 | + * @throws EE_Error |
|
| 324 | + * @throws InvalidArgumentException |
|
| 325 | + * @throws InvalidDataTypeException |
|
| 326 | + * @throws InvalidInterfaceException |
|
| 327 | + */ |
|
| 328 | + private function _get_payment_status_array() |
|
| 329 | + { |
|
| 330 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 331 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * _add_screen_options_default |
|
| 337 | + * |
|
| 338 | + * @access protected |
|
| 339 | + * @return void |
|
| 340 | + * @throws InvalidArgumentException |
|
| 341 | + * @throws InvalidDataTypeException |
|
| 342 | + * @throws InvalidInterfaceException |
|
| 343 | + */ |
|
| 344 | + protected function _add_screen_options_default() |
|
| 345 | + { |
|
| 346 | + $this->_per_page_screen_option(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * load_scripts_styles |
|
| 352 | + * |
|
| 353 | + * @access public |
|
| 354 | + * @return void |
|
| 355 | + */ |
|
| 356 | + public function load_scripts_styles() |
|
| 357 | + { |
|
| 358 | + // enqueue style |
|
| 359 | + wp_register_style( |
|
| 360 | + 'espresso_txn', |
|
| 361 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 362 | + array(), |
|
| 363 | + EVENT_ESPRESSO_VERSION |
|
| 364 | + ); |
|
| 365 | + wp_enqueue_style('espresso_txn'); |
|
| 366 | + // scripts |
|
| 367 | + wp_register_script( |
|
| 368 | + 'espresso_txn', |
|
| 369 | + TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 370 | + array( |
|
| 371 | + 'ee_admin_js', |
|
| 372 | + 'ee-datepicker', |
|
| 373 | + 'jquery-ui-datepicker', |
|
| 374 | + 'jquery-ui-draggable', |
|
| 375 | + 'ee-dialog', |
|
| 376 | + 'ee-accounting', |
|
| 377 | + 'ee-serialize-full-array', |
|
| 378 | + ), |
|
| 379 | + EVENT_ESPRESSO_VERSION, |
|
| 380 | + true |
|
| 381 | + ); |
|
| 382 | + wp_enqueue_script('espresso_txn'); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * load_scripts_styles_view_transaction |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + * @return void |
|
| 391 | + */ |
|
| 392 | + public function load_scripts_styles_view_transaction() |
|
| 393 | + { |
|
| 394 | + // styles |
|
| 395 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * load_scripts_styles_default |
|
| 401 | + * |
|
| 402 | + * @access public |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + public function load_scripts_styles_default() |
|
| 406 | + { |
|
| 407 | + // styles |
|
| 408 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * _set_list_table_views_default |
|
| 414 | + * |
|
| 415 | + * @access protected |
|
| 416 | + * @return void |
|
| 417 | + */ |
|
| 418 | + protected function _set_list_table_views_default() |
|
| 419 | + { |
|
| 420 | + $this->_views = array( |
|
| 421 | + 'all' => array( |
|
| 422 | + 'slug' => 'all', |
|
| 423 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 424 | + 'count' => 0, |
|
| 425 | + ), |
|
| 426 | + 'abandoned' => array( |
|
| 427 | + 'slug' => 'abandoned', |
|
| 428 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 429 | + 'count' => 0, |
|
| 430 | + ), |
|
| 431 | + 'incomplete' => array( |
|
| 432 | + 'slug' => 'incomplete', |
|
| 433 | + 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 434 | + 'count' => 0, |
|
| 435 | + ), |
|
| 436 | + ); |
|
| 437 | + if ( |
|
| 438 | 438 | /** |
| 439 | - * Filters whether a link to the "Failed Transactions" list table |
|
| 440 | - * appears on the Transactions Admin Page list table. |
|
| 441 | - * List display can be turned back on via the following: |
|
| 442 | - * add_filter( |
|
| 443 | - * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 444 | - * '__return_true' |
|
| 445 | - * ); |
|
| 446 | - * |
|
| 447 | - * @since 4.9.70.p |
|
| 448 | - * @param boolean $display_failed_txns_list |
|
| 449 | - * @param Transactions_Admin_Page $this |
|
| 450 | - */ |
|
| 451 | - apply_filters( |
|
| 452 | - 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 453 | - false, |
|
| 454 | - $this |
|
| 455 | - ) |
|
| 456 | - ) { |
|
| 457 | - $this->_views['failed'] = array( |
|
| 458 | - 'slug' => 'failed', |
|
| 459 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 460 | - 'count' => 0, |
|
| 461 | - ); |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * _set_transaction_object |
|
| 468 | - * This sets the _transaction property for the transaction details screen |
|
| 469 | - * |
|
| 470 | - * @access private |
|
| 471 | - * @return void |
|
| 472 | - * @throws EE_Error |
|
| 473 | - * @throws InvalidArgumentException |
|
| 474 | - * @throws RuntimeException |
|
| 475 | - * @throws InvalidDataTypeException |
|
| 476 | - * @throws InvalidInterfaceException |
|
| 477 | - * @throws ReflectionException |
|
| 478 | - */ |
|
| 479 | - private function _set_transaction_object() |
|
| 480 | - { |
|
| 481 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 482 | - return; |
|
| 483 | - } //get out we've already set the object |
|
| 484 | - |
|
| 485 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 486 | - ? absint($this->_req_data['TXN_ID']) |
|
| 487 | - : false; |
|
| 488 | - |
|
| 489 | - // get transaction object |
|
| 490 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 491 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 492 | - ? $this->_transaction->session_data() |
|
| 493 | - : null; |
|
| 494 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 495 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 499 | - $error_msg = sprintf( |
|
| 500 | - esc_html__( |
|
| 501 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 502 | - 'event_espresso' |
|
| 503 | - ), |
|
| 504 | - $TXN_ID |
|
| 505 | - ); |
|
| 506 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * _transaction_legend_items |
|
| 513 | - * |
|
| 514 | - * @access protected |
|
| 515 | - * @return array |
|
| 516 | - * @throws EE_Error |
|
| 517 | - * @throws InvalidArgumentException |
|
| 518 | - * @throws ReflectionException |
|
| 519 | - * @throws InvalidDataTypeException |
|
| 520 | - * @throws InvalidInterfaceException |
|
| 521 | - */ |
|
| 522 | - protected function _transaction_legend_items() |
|
| 523 | - { |
|
| 524 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 525 | - $items = array(); |
|
| 526 | - |
|
| 527 | - if ( |
|
| 528 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 529 | - 'ee_read_global_messages', |
|
| 530 | - 'view_filtered_messages' |
|
| 531 | - ) |
|
| 532 | - ) { |
|
| 533 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 534 | - if ( |
|
| 535 | - is_array($related_for_icon) |
|
| 536 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 537 | - ) { |
|
| 538 | - $items['view_related_messages'] = array( |
|
| 539 | - 'class' => $related_for_icon['css_class'], |
|
| 540 | - 'desc' => $related_for_icon['label'], |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - $items = apply_filters( |
|
| 546 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 547 | - array_merge( |
|
| 548 | - $items, |
|
| 549 | - array( |
|
| 550 | - 'view_details' => array( |
|
| 551 | - 'class' => 'dashicons dashicons-cart', |
|
| 552 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 553 | - ), |
|
| 554 | - 'view_invoice' => array( |
|
| 555 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 556 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 557 | - ), |
|
| 558 | - 'view_receipt' => array( |
|
| 559 | - 'class' => 'dashicons dashicons-media-default', |
|
| 560 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 561 | - ), |
|
| 562 | - 'view_registration' => array( |
|
| 563 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 564 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 565 | - ), |
|
| 566 | - 'payment_overview_link' => array( |
|
| 567 | - 'class' => 'dashicons dashicons-money', |
|
| 568 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 569 | - ), |
|
| 570 | - ) |
|
| 571 | - ) |
|
| 572 | - ); |
|
| 573 | - |
|
| 574 | - if ( |
|
| 575 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 576 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 577 | - 'ee_send_message', |
|
| 578 | - 'espresso_transactions_send_payment_reminder' |
|
| 579 | - ) |
|
| 580 | - ) { |
|
| 581 | - $items['send_payment_reminder'] = array( |
|
| 582 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 583 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - $more_items = apply_filters( |
|
| 587 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 588 | - array( |
|
| 589 | - 'overpaid' => array( |
|
| 590 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 591 | - 'desc' => EEH_Template::pretty_status( |
|
| 592 | - EEM_Transaction::overpaid_status_code, |
|
| 593 | - false, |
|
| 594 | - 'sentence' |
|
| 595 | - ), |
|
| 596 | - ), |
|
| 597 | - 'complete' => array( |
|
| 598 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 599 | - 'desc' => EEH_Template::pretty_status( |
|
| 600 | - EEM_Transaction::complete_status_code, |
|
| 601 | - false, |
|
| 602 | - 'sentence' |
|
| 603 | - ), |
|
| 604 | - ), |
|
| 605 | - 'incomplete' => array( |
|
| 606 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 607 | - 'desc' => EEH_Template::pretty_status( |
|
| 608 | - EEM_Transaction::incomplete_status_code, |
|
| 609 | - false, |
|
| 610 | - 'sentence' |
|
| 611 | - ), |
|
| 612 | - ), |
|
| 613 | - 'abandoned' => array( |
|
| 614 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 615 | - 'desc' => EEH_Template::pretty_status( |
|
| 616 | - EEM_Transaction::abandoned_status_code, |
|
| 617 | - false, |
|
| 618 | - 'sentence' |
|
| 619 | - ), |
|
| 620 | - ), |
|
| 621 | - 'failed' => array( |
|
| 622 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 623 | - 'desc' => EEH_Template::pretty_status( |
|
| 624 | - EEM_Transaction::failed_status_code, |
|
| 625 | - false, |
|
| 626 | - 'sentence' |
|
| 627 | - ), |
|
| 628 | - ), |
|
| 629 | - ) |
|
| 630 | - ); |
|
| 631 | - |
|
| 632 | - return array_merge($items, $more_items); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * _transactions_overview_list_table |
|
| 638 | - * |
|
| 639 | - * @access protected |
|
| 640 | - * @return void |
|
| 641 | - * @throws DomainException |
|
| 642 | - * @throws EE_Error |
|
| 643 | - * @throws InvalidArgumentException |
|
| 644 | - * @throws InvalidDataTypeException |
|
| 645 | - * @throws InvalidInterfaceException |
|
| 646 | - * @throws ReflectionException |
|
| 647 | - */ |
|
| 648 | - protected function _transactions_overview_list_table() |
|
| 649 | - { |
|
| 650 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 651 | - $event = isset($this->_req_data['EVT_ID']) |
|
| 652 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 653 | - : null; |
|
| 654 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 655 | - ? sprintf( |
|
| 656 | - esc_html__( |
|
| 657 | - '%sViewing Transactions for the Event: %s%s', |
|
| 658 | - 'event_espresso' |
|
| 659 | - ), |
|
| 660 | - '<h3>', |
|
| 661 | - '<a href="' |
|
| 662 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 663 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 664 | - EVENTS_ADMIN_URL |
|
| 665 | - ) |
|
| 666 | - . '" title="' |
|
| 667 | - . esc_attr__( |
|
| 668 | - 'Click to Edit event', |
|
| 669 | - 'event_espresso' |
|
| 670 | - ) |
|
| 671 | - . '">' . $event->name() . '</a>', |
|
| 672 | - '</h3>' |
|
| 673 | - ) |
|
| 674 | - : ''; |
|
| 675 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 676 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * _transaction_details |
|
| 682 | - * generates HTML for the View Transaction Details Admin page |
|
| 683 | - * |
|
| 684 | - * @access protected |
|
| 685 | - * @return void |
|
| 686 | - * @throws DomainException |
|
| 687 | - * @throws EE_Error |
|
| 688 | - * @throws InvalidArgumentException |
|
| 689 | - * @throws InvalidDataTypeException |
|
| 690 | - * @throws InvalidInterfaceException |
|
| 691 | - * @throws RuntimeException |
|
| 692 | - * @throws ReflectionException |
|
| 693 | - */ |
|
| 694 | - protected function _transaction_details() |
|
| 695 | - { |
|
| 696 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 697 | - |
|
| 698 | - $this->_set_transaction_status_array(); |
|
| 699 | - |
|
| 700 | - $this->_template_args = array(); |
|
| 701 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 702 | - |
|
| 703 | - $this->_set_transaction_object(); |
|
| 704 | - |
|
| 705 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 706 | - return; |
|
| 707 | - } |
|
| 708 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 709 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 710 | - ? $primary_registration->attendee() |
|
| 711 | - : null; |
|
| 712 | - |
|
| 713 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 714 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 715 | - |
|
| 716 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 717 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 718 | - |
|
| 719 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 720 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 721 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 722 | - |
|
| 723 | - $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 724 | - $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 725 | - |
|
| 726 | - $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 727 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 728 | - $amount_due, |
|
| 729 | - true |
|
| 730 | - ); |
|
| 731 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 732 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 733 | - . $this->_template_args['amount_due']; |
|
| 734 | - } else { |
|
| 735 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 736 | - } |
|
| 737 | - $this->_template_args['amount_due_class'] = ''; |
|
| 738 | - |
|
| 739 | - if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 740 | - // paid in full |
|
| 741 | - $this->_template_args['amount_due'] = false; |
|
| 742 | - } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 743 | - // overpaid |
|
| 744 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 745 | - } elseif ($this->_transaction->total() > (float) 0) { |
|
| 746 | - if ($this->_transaction->paid() > (float) 0) { |
|
| 747 | - // monies owing |
|
| 748 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 749 | - } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 750 | - // no payments made yet |
|
| 751 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 752 | - } |
|
| 753 | - } elseif ($this->_transaction->total() === (float) 0) { |
|
| 754 | - // free event |
|
| 755 | - $this->_template_args['amount_due'] = false; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - $payment_method = $this->_transaction->payment_method(); |
|
| 759 | - |
|
| 760 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 761 | - ? $payment_method->admin_name() |
|
| 762 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 763 | - |
|
| 764 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 765 | - // link back to overview |
|
| 766 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 767 | - ? $_SERVER['HTTP_REFERER'] |
|
| 768 | - : TXN_ADMIN_URL; |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - // next link |
|
| 772 | - $next_txn = $this->_transaction->next( |
|
| 773 | - null, |
|
| 774 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 775 | - 'TXN_ID' |
|
| 776 | - ); |
|
| 777 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 778 | - ? $this->_next_link( |
|
| 779 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 780 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 781 | - TXN_ADMIN_URL |
|
| 782 | - ), |
|
| 783 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 784 | - ) |
|
| 785 | - : ''; |
|
| 786 | - // previous link |
|
| 787 | - $previous_txn = $this->_transaction->previous( |
|
| 788 | - null, |
|
| 789 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 790 | - 'TXN_ID' |
|
| 791 | - ); |
|
| 792 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 793 | - ? $this->_previous_link( |
|
| 794 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 795 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 796 | - TXN_ADMIN_URL |
|
| 797 | - ), |
|
| 798 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 799 | - ) |
|
| 800 | - : ''; |
|
| 801 | - |
|
| 802 | - // were we just redirected here after adding a new registration ??? |
|
| 803 | - if ( |
|
| 804 | - isset( |
|
| 805 | - $this->_req_data['redirect_from'], |
|
| 806 | - $this->_req_data['EVT_ID'], |
|
| 807 | - $this->_req_data['event_name'] |
|
| 808 | - ) |
|
| 809 | - ) { |
|
| 810 | - if ( |
|
| 811 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 812 | - 'ee_edit_registrations', |
|
| 813 | - 'espresso_registrations_new_registration', |
|
| 814 | - $this->_req_data['EVT_ID'] |
|
| 815 | - ) |
|
| 816 | - ) { |
|
| 817 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 818 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 819 | - array( |
|
| 820 | - 'page' => 'espresso_registrations', |
|
| 821 | - 'action' => 'new_registration', |
|
| 822 | - 'return' => 'default', |
|
| 823 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 824 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 825 | - ), |
|
| 826 | - REG_ADMIN_URL |
|
| 827 | - ); |
|
| 828 | - $this->_admin_page_title .= '">'; |
|
| 829 | - |
|
| 830 | - $this->_admin_page_title .= sprintf( |
|
| 831 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 832 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 833 | - ); |
|
| 834 | - $this->_admin_page_title .= '</a>'; |
|
| 835 | - } |
|
| 836 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 837 | - } |
|
| 838 | - // grab messages at the last second |
|
| 839 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 840 | - // path to template |
|
| 841 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 842 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 843 | - $template_path, |
|
| 844 | - $this->_template_args, |
|
| 845 | - true |
|
| 846 | - ); |
|
| 847 | - |
|
| 848 | - // the details template wrapper |
|
| 849 | - $this->display_admin_page_with_sidebar(); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * _transaction_details_metaboxes |
|
| 855 | - * |
|
| 856 | - * @access protected |
|
| 857 | - * @return void |
|
| 858 | - * @throws EE_Error |
|
| 859 | - * @throws InvalidArgumentException |
|
| 860 | - * @throws InvalidDataTypeException |
|
| 861 | - * @throws InvalidInterfaceException |
|
| 862 | - * @throws RuntimeException |
|
| 863 | - * @throws ReflectionException |
|
| 864 | - */ |
|
| 865 | - protected function _transaction_details_metaboxes() |
|
| 866 | - { |
|
| 867 | - |
|
| 868 | - $this->_set_transaction_object(); |
|
| 869 | - |
|
| 870 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 871 | - return; |
|
| 872 | - } |
|
| 873 | - add_meta_box( |
|
| 874 | - 'edit-txn-details-mbox', |
|
| 875 | - esc_html__('Transaction Details', 'event_espresso'), |
|
| 876 | - array($this, 'txn_details_meta_box'), |
|
| 877 | - $this->_wp_page_slug, |
|
| 878 | - 'normal', |
|
| 879 | - 'high' |
|
| 880 | - ); |
|
| 881 | - add_meta_box( |
|
| 882 | - 'edit-txn-attendees-mbox', |
|
| 883 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 884 | - array($this, 'txn_attendees_meta_box'), |
|
| 885 | - $this->_wp_page_slug, |
|
| 886 | - 'normal', |
|
| 887 | - 'high', |
|
| 888 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 889 | - ); |
|
| 890 | - add_meta_box( |
|
| 891 | - 'edit-txn-registrant-mbox', |
|
| 892 | - esc_html__('Primary Contact', 'event_espresso'), |
|
| 893 | - array($this, 'txn_registrant_side_meta_box'), |
|
| 894 | - $this->_wp_page_slug, |
|
| 895 | - 'side', |
|
| 896 | - 'high' |
|
| 897 | - ); |
|
| 898 | - add_meta_box( |
|
| 899 | - 'edit-txn-billing-info-mbox', |
|
| 900 | - esc_html__('Billing Information', 'event_espresso'), |
|
| 901 | - array($this, 'txn_billing_info_side_meta_box'), |
|
| 902 | - $this->_wp_page_slug, |
|
| 903 | - 'side', |
|
| 904 | - 'high' |
|
| 905 | - ); |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Callback for transaction actions metabox. |
|
| 911 | - * |
|
| 912 | - * @param EE_Transaction|null $transaction |
|
| 913 | - * @return string |
|
| 914 | - * @throws DomainException |
|
| 915 | - * @throws EE_Error |
|
| 916 | - * @throws InvalidArgumentException |
|
| 917 | - * @throws InvalidDataTypeException |
|
| 918 | - * @throws InvalidInterfaceException |
|
| 919 | - * @throws ReflectionException |
|
| 920 | - * @throws RuntimeException |
|
| 921 | - */ |
|
| 922 | - public function getActionButtons(EE_Transaction $transaction = null) |
|
| 923 | - { |
|
| 924 | - $content = ''; |
|
| 925 | - $actions = array(); |
|
| 926 | - if (! $transaction instanceof EE_Transaction) { |
|
| 927 | - return $content; |
|
| 928 | - } |
|
| 929 | - /** @var EE_Registration $primary_registration */ |
|
| 930 | - $primary_registration = $transaction->primary_registration(); |
|
| 931 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 932 | - ? $primary_registration->attendee() |
|
| 933 | - : null; |
|
| 934 | - |
|
| 935 | - if ( |
|
| 936 | - $attendee instanceof EE_Attendee |
|
| 937 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 938 | - 'ee_send_message', |
|
| 939 | - 'espresso_transactions_send_payment_reminder' |
|
| 940 | - ) |
|
| 941 | - ) { |
|
| 942 | - $actions['payment_reminder'] = |
|
| 943 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 944 | - && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 945 | - && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 946 | - ? EEH_Template::get_button_or_link( |
|
| 947 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 948 | - array( |
|
| 949 | - 'action' => 'send_payment_reminder', |
|
| 950 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 951 | - 'redirect_to' => 'view_transaction', |
|
| 952 | - ), |
|
| 953 | - TXN_ADMIN_URL |
|
| 954 | - ), |
|
| 955 | - esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 956 | - 'button secondary-button', |
|
| 957 | - 'dashicons dashicons-email-alt' |
|
| 958 | - ) |
|
| 959 | - : ''; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - if ( |
|
| 963 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 964 | - 'ee_edit_payments', |
|
| 965 | - 'espresso_transactions_recalculate_line_items' |
|
| 966 | - ) |
|
| 967 | - ) { |
|
| 968 | - $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 969 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 970 | - array( |
|
| 971 | - 'action' => 'espresso_recalculate_line_items', |
|
| 972 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 973 | - 'redirect_to' => 'view_transaction', |
|
| 974 | - ), |
|
| 975 | - TXN_ADMIN_URL |
|
| 976 | - ), |
|
| 977 | - esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 978 | - 'button secondary-button', |
|
| 979 | - 'dashicons dashicons-update' |
|
| 980 | - ); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - if ( |
|
| 984 | - $primary_registration instanceof EE_Registration |
|
| 985 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
| 986 | - ) { |
|
| 987 | - $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 988 | - $primary_registration->receipt_url(), |
|
| 989 | - esc_html__('View Receipt', 'event_espresso'), |
|
| 990 | - 'button secondary-button', |
|
| 991 | - 'dashicons dashicons-media-default' |
|
| 992 | - ); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - if ( |
|
| 996 | - $primary_registration instanceof EE_Registration |
|
| 997 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 998 | - ) { |
|
| 999 | - $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 1000 | - $primary_registration->invoice_url(), |
|
| 1001 | - esc_html__('View Invoice', 'event_espresso'), |
|
| 1002 | - 'button secondary-button', |
|
| 1003 | - 'dashicons dashicons-media-spreadsheet' |
|
| 1004 | - ); |
|
| 1005 | - } |
|
| 1006 | - $actions = array_filter( |
|
| 1007 | - apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 1008 | - ); |
|
| 1009 | - if ($actions) { |
|
| 1010 | - $content = '<ul>'; |
|
| 1011 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1012 | - $content .= '</uL>'; |
|
| 1013 | - } |
|
| 1014 | - return $content; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * txn_details_meta_box |
|
| 1020 | - * generates HTML for the Transaction main meta box |
|
| 1021 | - * |
|
| 1022 | - * @return void |
|
| 1023 | - * @throws DomainException |
|
| 1024 | - * @throws EE_Error |
|
| 1025 | - * @throws InvalidArgumentException |
|
| 1026 | - * @throws InvalidDataTypeException |
|
| 1027 | - * @throws InvalidInterfaceException |
|
| 1028 | - * @throws RuntimeException |
|
| 1029 | - * @throws ReflectionException |
|
| 1030 | - */ |
|
| 1031 | - public function txn_details_meta_box() |
|
| 1032 | - { |
|
| 1033 | - $this->_set_transaction_object(); |
|
| 1034 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1035 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1036 | - ? $this->_transaction->primary_registration()->attendee() |
|
| 1037 | - : null; |
|
| 1038 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1039 | - 'ee_edit_payments', |
|
| 1040 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1041 | - ); |
|
| 1042 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1043 | - 'ee_delete_payments', |
|
| 1044 | - 'delete_payment_from_registration_details' |
|
| 1045 | - ); |
|
| 1046 | - |
|
| 1047 | - // get line table |
|
| 1048 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1049 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1050 | - 'admin_table', |
|
| 1051 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1052 | - ); |
|
| 1053 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1054 | - $this->_transaction->total_line_item() |
|
| 1055 | - ); |
|
| 1056 | - $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1057 | - |
|
| 1058 | - // process taxes |
|
| 1059 | - $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1060 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1061 | - |
|
| 1062 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1063 | - $this->_transaction->total(), |
|
| 1064 | - false, |
|
| 1065 | - false |
|
| 1066 | - ); |
|
| 1067 | - $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1068 | - $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1069 | - |
|
| 1070 | - // process payment details |
|
| 1071 | - $payments = $this->_transaction->payments(); |
|
| 1072 | - if (! empty($payments)) { |
|
| 1073 | - $this->_template_args['payments'] = $payments; |
|
| 1074 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1075 | - } else { |
|
| 1076 | - $this->_template_args['payments'] = false; |
|
| 1077 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1081 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1082 | - array('action' => 'espresso_delete_payment'), |
|
| 1083 | - TXN_ADMIN_URL |
|
| 1084 | - ); |
|
| 1085 | - |
|
| 1086 | - if (isset($txn_details['invoice_number'])) { |
|
| 1087 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1088 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1089 | - 'Invoice Number', |
|
| 1090 | - 'event_espresso' |
|
| 1091 | - ); |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1095 | - ->primary_registration() |
|
| 1096 | - ->session_ID(); |
|
| 1097 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1098 | - 'Registration Session', |
|
| 1099 | - 'event_espresso' |
|
| 1100 | - ); |
|
| 1101 | - |
|
| 1102 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1103 | - ? $this->_session['ip_address'] |
|
| 1104 | - : ''; |
|
| 1105 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1106 | - 'Transaction placed from IP', |
|
| 1107 | - 'event_espresso' |
|
| 1108 | - ); |
|
| 1109 | - |
|
| 1110 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1111 | - ? $this->_session['user_agent'] |
|
| 1112 | - : ''; |
|
| 1113 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1114 | - 'Registrant User Agent', |
|
| 1115 | - 'event_espresso' |
|
| 1116 | - ); |
|
| 1117 | - |
|
| 1118 | - $reg_steps = '<ul>'; |
|
| 1119 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1120 | - if ($reg_step_status === true) { |
|
| 1121 | - $reg_steps .= '<li style="color:#70cc50">' |
|
| 1122 | - . sprintf( |
|
| 1123 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1124 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1125 | - ) |
|
| 1126 | - . '</li>'; |
|
| 1127 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1128 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1129 | - . sprintf( |
|
| 1130 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1131 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1132 | - date( |
|
| 1133 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1134 | - $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1135 | - ) |
|
| 1136 | - ) |
|
| 1137 | - . '</li>'; |
|
| 1138 | - } else { |
|
| 1139 | - $reg_steps .= '<li style="color:#E76700">' |
|
| 1140 | - . sprintf( |
|
| 1141 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1142 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1143 | - ) |
|
| 1144 | - . '</li>'; |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - $reg_steps .= '</ul>'; |
|
| 1148 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1149 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1150 | - 'Registration Step Progress', |
|
| 1151 | - 'event_espresso' |
|
| 1152 | - ); |
|
| 1153 | - |
|
| 1154 | - |
|
| 1155 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 1156 | - $this->_get_payment_methods($payments); |
|
| 1157 | - $this->_get_payment_status_array(); |
|
| 1158 | - $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1159 | - |
|
| 1160 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1161 | - array( |
|
| 1162 | - 'action' => 'edit_transaction', |
|
| 1163 | - 'process' => 'transaction', |
|
| 1164 | - ), |
|
| 1165 | - TXN_ADMIN_URL |
|
| 1166 | - ); |
|
| 1167 | - $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1168 | - array( |
|
| 1169 | - 'page' => 'espresso_transactions', |
|
| 1170 | - 'action' => 'espresso_apply_payment', |
|
| 1171 | - ), |
|
| 1172 | - WP_AJAX_URL |
|
| 1173 | - ); |
|
| 1174 | - $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1175 | - array( |
|
| 1176 | - 'page' => 'espresso_transactions', |
|
| 1177 | - 'action' => 'espresso_delete_payment', |
|
| 1178 | - ), |
|
| 1179 | - WP_AJAX_URL |
|
| 1180 | - ); |
|
| 1181 | - |
|
| 1182 | - $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1183 | - |
|
| 1184 | - // 'espresso_delete_payment_nonce' |
|
| 1185 | - |
|
| 1186 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1187 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - |
|
| 1191 | - /** |
|
| 1192 | - * _get_registration_payment_IDs |
|
| 1193 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1194 | - * |
|
| 1195 | - * @access protected |
|
| 1196 | - * @param EE_Payment[] $payments |
|
| 1197 | - * @return array |
|
| 1198 | - * @throws EE_Error |
|
| 1199 | - * @throws InvalidArgumentException |
|
| 1200 | - * @throws InvalidDataTypeException |
|
| 1201 | - * @throws InvalidInterfaceException |
|
| 1202 | - * @throws ReflectionException |
|
| 1203 | - */ |
|
| 1204 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 1205 | - { |
|
| 1206 | - $existing_reg_payments = array(); |
|
| 1207 | - // get all reg payments for these payments |
|
| 1208 | - $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1209 | - array( |
|
| 1210 | - array( |
|
| 1211 | - 'PAY_ID' => array( |
|
| 1212 | - 'IN', |
|
| 1213 | - array_keys($payments), |
|
| 1214 | - ), |
|
| 1215 | - ), |
|
| 1216 | - ) |
|
| 1217 | - ); |
|
| 1218 | - if (! empty($reg_payments)) { |
|
| 1219 | - foreach ($payments as $payment) { |
|
| 1220 | - if (! $payment instanceof EE_Payment) { |
|
| 1221 | - continue; |
|
| 1222 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1223 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1224 | - } |
|
| 1225 | - foreach ($reg_payments as $reg_payment) { |
|
| 1226 | - if ( |
|
| 1227 | - $reg_payment instanceof EE_Registration_Payment |
|
| 1228 | - && $reg_payment->payment_ID() === $payment->ID() |
|
| 1229 | - ) { |
|
| 1230 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - return $existing_reg_payments; |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * _get_registrations_to_apply_payment_to |
|
| 1242 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1243 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 1244 | - * |
|
| 1245 | - * @access protected |
|
| 1246 | - * @return void |
|
| 1247 | - * @throws EE_Error |
|
| 1248 | - * @throws InvalidArgumentException |
|
| 1249 | - * @throws InvalidDataTypeException |
|
| 1250 | - * @throws InvalidInterfaceException |
|
| 1251 | - * @throws ReflectionException |
|
| 1252 | - */ |
|
| 1253 | - protected function _get_registrations_to_apply_payment_to() |
|
| 1254 | - { |
|
| 1255 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1256 | - $query_params = array( |
|
| 1257 | - array( |
|
| 1258 | - 'STS_ID' => array( |
|
| 1259 | - 'IN', |
|
| 1260 | - array( |
|
| 1261 | - EEM_Registration::status_id_approved, |
|
| 1262 | - EEM_Registration::status_id_pending_payment, |
|
| 1263 | - EEM_Registration::status_id_not_approved, |
|
| 1264 | - ), |
|
| 1265 | - ), |
|
| 1266 | - ), |
|
| 1267 | - ); |
|
| 1268 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1269 | - '', |
|
| 1270 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1271 | - '', |
|
| 1272 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1273 | - ); |
|
| 1274 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1275 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1276 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1277 | - EEH_HTML::tr( |
|
| 1278 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1279 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1280 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1281 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1282 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1283 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1284 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1285 | - ) |
|
| 1286 | - ); |
|
| 1287 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1288 | - // get registrations for TXN |
|
| 1289 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 1290 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1291 | - foreach ($registrations as $registration) { |
|
| 1292 | - if ($registration instanceof EE_Registration) { |
|
| 1293 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1294 | - ? $registration->attendee()->full_name() |
|
| 1295 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1296 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 1297 | - $taxable = $registration->ticket()->taxable() |
|
| 1298 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1299 | - : ''; |
|
| 1300 | - $checked = empty($existing_reg_payments) |
|
| 1301 | - || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1302 | - ? ' checked="checked"' |
|
| 1303 | - : ''; |
|
| 1304 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1305 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1306 | - EEH_HTML::td($registration->ID()) . |
|
| 1307 | - EEH_HTML::td($attendee_name) . |
|
| 1308 | - EEH_HTML::td( |
|
| 1309 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1310 | - ) . |
|
| 1311 | - EEH_HTML::td($registration->event_name()) . |
|
| 1312 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1313 | - EEH_HTML::td( |
|
| 1314 | - EEH_Template::format_currency($owing), |
|
| 1315 | - '', |
|
| 1316 | - 'txn-admin-payment-owing-td jst-cntr' |
|
| 1317 | - ) . |
|
| 1318 | - EEH_HTML::td( |
|
| 1319 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1320 | - . '" name="txn_admin_payment[registrations]"' |
|
| 1321 | - . $checked . $disabled . '>', |
|
| 1322 | - '', |
|
| 1323 | - 'jst-cntr' |
|
| 1324 | - ), |
|
| 1325 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1326 | - ); |
|
| 1327 | - } |
|
| 1328 | - } |
|
| 1329 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1330 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1331 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1332 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1333 | - esc_html__( |
|
| 1334 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1335 | - 'event_espresso' |
|
| 1336 | - ), |
|
| 1337 | - '', |
|
| 1338 | - 'clear description' |
|
| 1339 | - ); |
|
| 1340 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1341 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1342 | - } |
|
| 1343 | - |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * _get_reg_status_selection |
|
| 1347 | - * |
|
| 1348 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1349 | - * instead of events. |
|
| 1350 | - * @access protected |
|
| 1351 | - * @return void |
|
| 1352 | - * @throws EE_Error |
|
| 1353 | - */ |
|
| 1354 | - protected function _get_reg_status_selection() |
|
| 1355 | - { |
|
| 1356 | - // first get all possible statuses |
|
| 1357 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1358 | - // let's add a "don't change" option. |
|
| 1359 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1360 | - $status_array = array_merge($status_array, $statuses); |
|
| 1361 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1362 | - 'txn_reg_status_change[reg_status]', |
|
| 1363 | - $status_array, |
|
| 1364 | - 'NAN', |
|
| 1365 | - 'id="txn-admin-payment-reg-status-inp"', |
|
| 1366 | - 'txn-reg-status-change-reg-status' |
|
| 1367 | - ); |
|
| 1368 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1369 | - 'delete_txn_reg_status_change[reg_status]', |
|
| 1370 | - $status_array, |
|
| 1371 | - 'NAN', |
|
| 1372 | - 'delete-txn-admin-payment-reg-status-inp', |
|
| 1373 | - 'delete-txn-reg-status-change-reg-status' |
|
| 1374 | - ); |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * _get_payment_methods |
|
| 1380 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1381 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1382 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1383 | - * |
|
| 1384 | - * @access private |
|
| 1385 | - * @param EE_Payment[] to show on this page |
|
| 1386 | - * @return void |
|
| 1387 | - * @throws EE_Error |
|
| 1388 | - * @throws InvalidArgumentException |
|
| 1389 | - * @throws InvalidDataTypeException |
|
| 1390 | - * @throws InvalidInterfaceException |
|
| 1391 | - * @throws ReflectionException |
|
| 1392 | - */ |
|
| 1393 | - private function _get_payment_methods($payments = array()) |
|
| 1394 | - { |
|
| 1395 | - $payment_methods_of_payments = array(); |
|
| 1396 | - foreach ($payments as $payment) { |
|
| 1397 | - if ($payment instanceof EE_Payment) { |
|
| 1398 | - $payment_methods_of_payments[] = $payment->ID(); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - if ($payment_methods_of_payments) { |
|
| 1402 | - $query_args = array( |
|
| 1403 | - array( |
|
| 1404 | - 'OR*payment_method_for_payment' => array( |
|
| 1405 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1406 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1407 | - ), |
|
| 1408 | - ), |
|
| 1409 | - ); |
|
| 1410 | - } else { |
|
| 1411 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1412 | - } |
|
| 1413 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * txn_attendees_meta_box |
|
| 1419 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1420 | - * |
|
| 1421 | - * @access public |
|
| 1422 | - * @param WP_Post $post |
|
| 1423 | - * @param array $metabox |
|
| 1424 | - * @return void |
|
| 1425 | - * @throws DomainException |
|
| 1426 | - * @throws EE_Error |
|
| 1427 | - * @throws InvalidArgumentException |
|
| 1428 | - * @throws InvalidDataTypeException |
|
| 1429 | - * @throws InvalidInterfaceException |
|
| 1430 | - * @throws ReflectionException |
|
| 1431 | - */ |
|
| 1432 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1433 | - { |
|
| 1434 | - |
|
| 1435 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1436 | - extract($metabox['args']); |
|
| 1437 | - $this->_template_args['post'] = $post; |
|
| 1438 | - $this->_template_args['event_attendees'] = array(); |
|
| 1439 | - // process items in cart |
|
| 1440 | - $line_items = $this->_transaction->get_many_related( |
|
| 1441 | - 'Line_Item', |
|
| 1442 | - array(array('LIN_type' => 'line-item')) |
|
| 1443 | - ); |
|
| 1444 | - if (! empty($line_items)) { |
|
| 1445 | - foreach ($line_items as $item) { |
|
| 1446 | - if ($item instanceof EE_Line_Item) { |
|
| 1447 | - switch ($item->OBJ_type()) { |
|
| 1448 | - case 'Event': |
|
| 1449 | - break; |
|
| 1450 | - case 'Ticket': |
|
| 1451 | - $ticket = $item->ticket(); |
|
| 1452 | - // right now we're only handling tickets here. |
|
| 1453 | - // Cause its expected that only tickets will have attendees right? |
|
| 1454 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1455 | - break; |
|
| 1456 | - } |
|
| 1457 | - try { |
|
| 1458 | - $event_name = $ticket->get_event_name(); |
|
| 1459 | - } catch (Exception $e) { |
|
| 1460 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1461 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1462 | - } |
|
| 1463 | - $event_name .= ' - ' . $item->name(); |
|
| 1464 | - $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1465 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1466 | - $registrations = $ticket->registrations( |
|
| 1467 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1468 | - ); |
|
| 1469 | - foreach ($registrations as $registration) { |
|
| 1470 | - if (! $registration instanceof EE_Registration) { |
|
| 1471 | - break; |
|
| 1472 | - } |
|
| 1473 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1474 | - = $registration->status_ID(); |
|
| 1475 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1476 | - = $registration->count(); |
|
| 1477 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1478 | - = $event_name; |
|
| 1479 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1480 | - = $ticket_price; |
|
| 1481 | - // attendee info |
|
| 1482 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1483 | - if ($attendee instanceof EE_Attendee) { |
|
| 1484 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1485 | - = $attendee->ID(); |
|
| 1486 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1487 | - = $attendee->full_name(); |
|
| 1488 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1489 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1490 | - . esc_html__( |
|
| 1491 | - ' Event', |
|
| 1492 | - 'event_espresso' |
|
| 1493 | - ) |
|
| 1494 | - . '">' . $attendee->email() . '</a>'; |
|
| 1495 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1496 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1497 | - } else { |
|
| 1498 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1499 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1500 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1501 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1502 | - } |
|
| 1503 | - } |
|
| 1504 | - break; |
|
| 1505 | - } |
|
| 1506 | - } |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1510 | - array( |
|
| 1511 | - 'action' => 'edit_transaction', |
|
| 1512 | - 'process' => 'attendees', |
|
| 1513 | - ), |
|
| 1514 | - TXN_ADMIN_URL |
|
| 1515 | - ); |
|
| 1516 | - echo EEH_Template::display_template( |
|
| 1517 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1518 | - $this->_template_args, |
|
| 1519 | - true |
|
| 1520 | - ); |
|
| 1521 | - } else { |
|
| 1522 | - echo sprintf( |
|
| 1523 | - esc_html__( |
|
| 1524 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1525 | - 'event_espresso' |
|
| 1526 | - ), |
|
| 1527 | - '<p class="important-notice">', |
|
| 1528 | - '</p>' |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - } |
|
| 1532 | - |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * txn_registrant_side_meta_box |
|
| 1536 | - * generates HTML for the Edit Transaction side meta box |
|
| 1537 | - * |
|
| 1538 | - * @access public |
|
| 1539 | - * @return void |
|
| 1540 | - * @throws DomainException |
|
| 1541 | - * @throws EE_Error |
|
| 1542 | - * @throws InvalidArgumentException |
|
| 1543 | - * @throws InvalidDataTypeException |
|
| 1544 | - * @throws InvalidInterfaceException |
|
| 1545 | - * @throws ReflectionException |
|
| 1546 | - */ |
|
| 1547 | - public function txn_registrant_side_meta_box() |
|
| 1548 | - { |
|
| 1549 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1550 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1551 | - : null; |
|
| 1552 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1553 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1554 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1555 | - 'event_espresso' |
|
| 1556 | - ); |
|
| 1557 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1558 | - } |
|
| 1559 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1560 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1561 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1562 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1563 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1564 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1565 | - array( |
|
| 1566 | - 'action' => 'edit_attendee', |
|
| 1567 | - 'post' => $primary_att->ID(), |
|
| 1568 | - ), |
|
| 1569 | - REG_ADMIN_URL |
|
| 1570 | - ); |
|
| 1571 | - // get formatted address for registrant |
|
| 1572 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1573 | - echo EEH_Template::display_template( |
|
| 1574 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1575 | - $this->_template_args, |
|
| 1576 | - true |
|
| 1577 | - ); |
|
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - |
|
| 1581 | - /** |
|
| 1582 | - * txn_billing_info_side_meta_box |
|
| 1583 | - * generates HTML for the Edit Transaction side meta box |
|
| 1584 | - * |
|
| 1585 | - * @access public |
|
| 1586 | - * @return void |
|
| 1587 | - * @throws DomainException |
|
| 1588 | - * @throws EE_Error |
|
| 1589 | - */ |
|
| 1590 | - public function txn_billing_info_side_meta_box() |
|
| 1591 | - { |
|
| 1592 | - |
|
| 1593 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1594 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1595 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1596 | - TXN_ADMIN_URL |
|
| 1597 | - ); |
|
| 1598 | - |
|
| 1599 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1600 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * apply_payments_or_refunds |
|
| 1606 | - * registers a payment or refund made towards a transaction |
|
| 1607 | - * |
|
| 1608 | - * @access public |
|
| 1609 | - * @return void |
|
| 1610 | - * @throws EE_Error |
|
| 1611 | - * @throws InvalidArgumentException |
|
| 1612 | - * @throws ReflectionException |
|
| 1613 | - * @throws RuntimeException |
|
| 1614 | - * @throws InvalidDataTypeException |
|
| 1615 | - * @throws InvalidInterfaceException |
|
| 1616 | - */ |
|
| 1617 | - public function apply_payments_or_refunds() |
|
| 1618 | - { |
|
| 1619 | - $json_response_data = array('return_data' => false); |
|
| 1620 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1621 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1622 | - 'ee_edit_payments', |
|
| 1623 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1624 | - ); |
|
| 1625 | - if (! empty($valid_data) && $has_access) { |
|
| 1626 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1627 | - // save the new payment |
|
| 1628 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1629 | - // get the TXN for this payment |
|
| 1630 | - $transaction = $payment->transaction(); |
|
| 1631 | - // verify transaction |
|
| 1632 | - if ($transaction instanceof EE_Transaction) { |
|
| 1633 | - // calculate_total_payments_and_update_status |
|
| 1634 | - $this->_process_transaction_payments($transaction); |
|
| 1635 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1636 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1637 | - // apply payment to registrations (if applicable) |
|
| 1638 | - if (! empty($REG_IDs)) { |
|
| 1639 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1640 | - $this->_maybe_send_notifications(); |
|
| 1641 | - // now process status changes for the same registrations |
|
| 1642 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1643 | - } |
|
| 1644 | - $this->_maybe_send_notifications($payment); |
|
| 1645 | - // prepare to render page |
|
| 1646 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1647 | - do_action( |
|
| 1648 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1649 | - $transaction, |
|
| 1650 | - $payment |
|
| 1651 | - ); |
|
| 1652 | - } else { |
|
| 1653 | - EE_Error::add_error( |
|
| 1654 | - esc_html__( |
|
| 1655 | - 'A valid Transaction for this payment could not be retrieved.', |
|
| 1656 | - 'event_espresso' |
|
| 1657 | - ), |
|
| 1658 | - __FILE__, |
|
| 1659 | - __FUNCTION__, |
|
| 1660 | - __LINE__ |
|
| 1661 | - ); |
|
| 1662 | - } |
|
| 1663 | - } elseif ($has_access) { |
|
| 1664 | - EE_Error::add_error( |
|
| 1665 | - esc_html__( |
|
| 1666 | - 'The payment form data could not be processed. Please try again.', |
|
| 1667 | - 'event_espresso' |
|
| 1668 | - ), |
|
| 1669 | - __FILE__, |
|
| 1670 | - __FUNCTION__, |
|
| 1671 | - __LINE__ |
|
| 1672 | - ); |
|
| 1673 | - } else { |
|
| 1674 | - EE_Error::add_error( |
|
| 1675 | - esc_html__( |
|
| 1676 | - 'You do not have access to apply payments or refunds to a registration.', |
|
| 1677 | - 'event_espresso' |
|
| 1678 | - ), |
|
| 1679 | - __FILE__, |
|
| 1680 | - __FUNCTION__, |
|
| 1681 | - __LINE__ |
|
| 1682 | - ); |
|
| 1683 | - } |
|
| 1684 | - $notices = EE_Error::get_notices( |
|
| 1685 | - false, |
|
| 1686 | - false, |
|
| 1687 | - false |
|
| 1688 | - ); |
|
| 1689 | - $this->_template_args = array( |
|
| 1690 | - 'data' => $json_response_data, |
|
| 1691 | - 'error' => $notices['errors'], |
|
| 1692 | - 'success' => $notices['success'], |
|
| 1693 | - ); |
|
| 1694 | - $this->_return_json(); |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - |
|
| 1698 | - /** |
|
| 1699 | - * _validate_payment_request_data |
|
| 1700 | - * |
|
| 1701 | - * @return array |
|
| 1702 | - * @throws EE_Error |
|
| 1703 | - * @throws InvalidArgumentException |
|
| 1704 | - * @throws InvalidDataTypeException |
|
| 1705 | - * @throws InvalidInterfaceException |
|
| 1706 | - */ |
|
| 1707 | - protected function _validate_payment_request_data() |
|
| 1708 | - { |
|
| 1709 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1710 | - return array(); |
|
| 1711 | - } |
|
| 1712 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1713 | - try { |
|
| 1714 | - if ($payment_form->was_submitted()) { |
|
| 1715 | - $payment_form->receive_form_submission(); |
|
| 1716 | - if (! $payment_form->is_valid()) { |
|
| 1717 | - $submission_error_messages = array(); |
|
| 1718 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1719 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1720 | - $submission_error_messages[] = sprintf( |
|
| 1721 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1722 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1723 | - $validation_error->getMessage() |
|
| 1724 | - ); |
|
| 1725 | - } |
|
| 1726 | - } |
|
| 1727 | - EE_Error::add_error( |
|
| 1728 | - implode('<br />', $submission_error_messages), |
|
| 1729 | - __FILE__, |
|
| 1730 | - __FUNCTION__, |
|
| 1731 | - __LINE__ |
|
| 1732 | - ); |
|
| 1733 | - return array(); |
|
| 1734 | - } |
|
| 1735 | - } |
|
| 1736 | - } catch (EE_Error $e) { |
|
| 1737 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1738 | - return array(); |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - return $payment_form->valid_data(); |
|
| 1742 | - } |
|
| 1743 | - |
|
| 1744 | - |
|
| 1745 | - /** |
|
| 1746 | - * _generate_payment_form_section |
|
| 1747 | - * |
|
| 1748 | - * @return EE_Form_Section_Proper |
|
| 1749 | - * @throws EE_Error |
|
| 1750 | - */ |
|
| 1751 | - protected function _generate_payment_form_section() |
|
| 1752 | - { |
|
| 1753 | - return new EE_Form_Section_Proper( |
|
| 1754 | - array( |
|
| 1755 | - 'name' => 'txn_admin_payment', |
|
| 1756 | - 'subsections' => array( |
|
| 1757 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1758 | - array( |
|
| 1759 | - 'default' => 0, |
|
| 1760 | - 'required' => false, |
|
| 1761 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1762 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1763 | - ) |
|
| 1764 | - ), |
|
| 1765 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1766 | - array( |
|
| 1767 | - 'default' => 0, |
|
| 1768 | - 'required' => true, |
|
| 1769 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1770 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1771 | - ) |
|
| 1772 | - ), |
|
| 1773 | - 'type' => new EE_Text_Input( |
|
| 1774 | - array( |
|
| 1775 | - 'default' => 1, |
|
| 1776 | - 'required' => true, |
|
| 1777 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1778 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1779 | - ) |
|
| 1780 | - ), |
|
| 1781 | - 'amount' => new EE_Text_Input( |
|
| 1782 | - array( |
|
| 1783 | - 'default' => 0, |
|
| 1784 | - 'required' => true, |
|
| 1785 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1786 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1787 | - ) |
|
| 1788 | - ), |
|
| 1789 | - 'status' => new EE_Text_Input( |
|
| 1790 | - array( |
|
| 1791 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1792 | - 'required' => true, |
|
| 1793 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1794 | - ) |
|
| 1795 | - ), |
|
| 1796 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1797 | - array( |
|
| 1798 | - 'default' => 2, |
|
| 1799 | - 'required' => true, |
|
| 1800 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1801 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1802 | - ) |
|
| 1803 | - ), |
|
| 1804 | - 'date' => new EE_Text_Input( |
|
| 1805 | - array( |
|
| 1806 | - 'default' => time(), |
|
| 1807 | - 'required' => true, |
|
| 1808 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1809 | - ) |
|
| 1810 | - ), |
|
| 1811 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1812 | - array( |
|
| 1813 | - 'default' => '', |
|
| 1814 | - 'required' => false, |
|
| 1815 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1816 | - 'validation_strategies' => array( |
|
| 1817 | - new EE_Max_Length_Validation_Strategy( |
|
| 1818 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1819 | - 100 |
|
| 1820 | - ), |
|
| 1821 | - ), |
|
| 1822 | - ) |
|
| 1823 | - ), |
|
| 1824 | - 'po_number' => new EE_Text_Input( |
|
| 1825 | - array( |
|
| 1826 | - 'default' => '', |
|
| 1827 | - 'required' => false, |
|
| 1828 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1829 | - 'validation_strategies' => array( |
|
| 1830 | - new EE_Max_Length_Validation_Strategy( |
|
| 1831 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1832 | - 100 |
|
| 1833 | - ), |
|
| 1834 | - ), |
|
| 1835 | - ) |
|
| 1836 | - ), |
|
| 1837 | - 'accounting' => new EE_Text_Input( |
|
| 1838 | - array( |
|
| 1839 | - 'default' => '', |
|
| 1840 | - 'required' => false, |
|
| 1841 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1842 | - 'validation_strategies' => array( |
|
| 1843 | - new EE_Max_Length_Validation_Strategy( |
|
| 1844 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1845 | - 100 |
|
| 1846 | - ), |
|
| 1847 | - ), |
|
| 1848 | - ) |
|
| 1849 | - ), |
|
| 1850 | - ), |
|
| 1851 | - ) |
|
| 1852 | - ); |
|
| 1853 | - } |
|
| 1854 | - |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * _create_payment_from_request_data |
|
| 1858 | - * |
|
| 1859 | - * @param array $valid_data |
|
| 1860 | - * @return EE_Payment |
|
| 1861 | - * @throws EE_Error |
|
| 1862 | - * @throws InvalidArgumentException |
|
| 1863 | - * @throws InvalidDataTypeException |
|
| 1864 | - * @throws InvalidInterfaceException |
|
| 1865 | - * @throws ReflectionException |
|
| 1866 | - */ |
|
| 1867 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1868 | - { |
|
| 1869 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1870 | - // get payment amount |
|
| 1871 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1872 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1873 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1874 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1875 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1876 | - $date = $valid_data['date'] |
|
| 1877 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1878 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1879 | - $payment = EE_Payment::new_instance( |
|
| 1880 | - array( |
|
| 1881 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1882 | - 'STS_ID' => $valid_data['status'], |
|
| 1883 | - 'PAY_timestamp' => $date, |
|
| 1884 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1885 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1886 | - 'PAY_amount' => $amount, |
|
| 1887 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1888 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1889 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1890 | - 'PAY_details' => $valid_data, |
|
| 1891 | - 'PAY_ID' => $PAY_ID, |
|
| 1892 | - ), |
|
| 1893 | - '', |
|
| 1894 | - array('Y-m-d', 'g:i a') |
|
| 1895 | - ); |
|
| 1896 | - |
|
| 1897 | - if (! $payment->save()) { |
|
| 1898 | - EE_Error::add_error( |
|
| 1899 | - sprintf( |
|
| 1900 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1901 | - $payment->ID() |
|
| 1902 | - ), |
|
| 1903 | - __FILE__, |
|
| 1904 | - __FUNCTION__, |
|
| 1905 | - __LINE__ |
|
| 1906 | - ); |
|
| 1907 | - } |
|
| 1908 | - |
|
| 1909 | - return $payment; |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - |
|
| 1913 | - /** |
|
| 1914 | - * _process_transaction_payments |
|
| 1915 | - * |
|
| 1916 | - * @param \EE_Transaction $transaction |
|
| 1917 | - * @return void |
|
| 1918 | - * @throws EE_Error |
|
| 1919 | - * @throws InvalidArgumentException |
|
| 1920 | - * @throws ReflectionException |
|
| 1921 | - * @throws InvalidDataTypeException |
|
| 1922 | - * @throws InvalidInterfaceException |
|
| 1923 | - */ |
|
| 1924 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1925 | - { |
|
| 1926 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1927 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1928 | - // update the transaction with this payment |
|
| 1929 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1930 | - EE_Error::add_success( |
|
| 1931 | - esc_html__( |
|
| 1932 | - 'The payment has been processed successfully.', |
|
| 1933 | - 'event_espresso' |
|
| 1934 | - ), |
|
| 1935 | - __FILE__, |
|
| 1936 | - __FUNCTION__, |
|
| 1937 | - __LINE__ |
|
| 1938 | - ); |
|
| 1939 | - } else { |
|
| 1940 | - EE_Error::add_error( |
|
| 1941 | - esc_html__( |
|
| 1942 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1943 | - 'event_espresso' |
|
| 1944 | - ), |
|
| 1945 | - __FILE__, |
|
| 1946 | - __FUNCTION__, |
|
| 1947 | - __LINE__ |
|
| 1948 | - ); |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - |
|
| 1953 | - /** |
|
| 1954 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1955 | - * returns a list of registration IDs that the payment will apply to |
|
| 1956 | - * |
|
| 1957 | - * @param \EE_Payment $payment |
|
| 1958 | - * @return array |
|
| 1959 | - * @throws EE_Error |
|
| 1960 | - * @throws InvalidArgumentException |
|
| 1961 | - * @throws InvalidDataTypeException |
|
| 1962 | - * @throws InvalidInterfaceException |
|
| 1963 | - * @throws ReflectionException |
|
| 1964 | - */ |
|
| 1965 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1966 | - { |
|
| 1967 | - $REG_IDs = array(); |
|
| 1968 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1969 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1970 | - $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1971 | - } |
|
| 1972 | - // nothing specified ? then get all reg IDs |
|
| 1973 | - if (empty($REG_IDs)) { |
|
| 1974 | - $registrations = $payment->transaction()->registrations(); |
|
| 1975 | - $REG_IDs = ! empty($registrations) |
|
| 1976 | - ? array_keys($registrations) |
|
| 1977 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1978 | - } |
|
| 1979 | - |
|
| 1980 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1981 | - return array_map('intval', $REG_IDs); |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - |
|
| 1985 | - /** |
|
| 1986 | - * @return array |
|
| 1987 | - */ |
|
| 1988 | - public function existing_reg_payment_REG_IDs() |
|
| 1989 | - { |
|
| 1990 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1991 | - } |
|
| 1992 | - |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1996 | - */ |
|
| 1997 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1998 | - { |
|
| 1999 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 2000 | - } |
|
| 2001 | - |
|
| 2002 | - |
|
| 2003 | - /** |
|
| 2004 | - * _get_existing_reg_payment_REG_IDs |
|
| 2005 | - * returns a list of registration IDs that the payment is currently related to |
|
| 2006 | - * as recorded in the database |
|
| 2007 | - * |
|
| 2008 | - * @param \EE_Payment $payment |
|
| 2009 | - * @return array |
|
| 2010 | - * @throws EE_Error |
|
| 2011 | - * @throws InvalidArgumentException |
|
| 2012 | - * @throws InvalidDataTypeException |
|
| 2013 | - * @throws InvalidInterfaceException |
|
| 2014 | - * @throws ReflectionException |
|
| 2015 | - */ |
|
| 2016 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2017 | - { |
|
| 2018 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2019 | - // let's get any existing reg payment records for this payment |
|
| 2020 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2021 | - // but we only want the REG IDs, so grab the array keys |
|
| 2022 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2023 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2024 | - : array(); |
|
| 2025 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2026 | - } |
|
| 2027 | - |
|
| 2028 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 2029 | - } |
|
| 2030 | - |
|
| 2031 | - |
|
| 2032 | - /** |
|
| 2033 | - * _remove_existing_registration_payments |
|
| 2034 | - * this calculates the difference between existing relations |
|
| 2035 | - * to the supplied payment and the new list registration IDs, |
|
| 2036 | - * removes any related registrations that no longer apply, |
|
| 2037 | - * and then updates the registration paid fields |
|
| 2038 | - * |
|
| 2039 | - * @param \EE_Payment $payment |
|
| 2040 | - * @param int $PAY_ID |
|
| 2041 | - * @return bool; |
|
| 2042 | - * @throws EE_Error |
|
| 2043 | - * @throws InvalidArgumentException |
|
| 2044 | - * @throws ReflectionException |
|
| 2045 | - * @throws InvalidDataTypeException |
|
| 2046 | - * @throws InvalidInterfaceException |
|
| 2047 | - */ |
|
| 2048 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2049 | - { |
|
| 2050 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 2051 | - if (absint($PAY_ID) === 0) { |
|
| 2052 | - return false; |
|
| 2053 | - } |
|
| 2054 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2055 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2056 | - return false; |
|
| 2057 | - } |
|
| 2058 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2059 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2060 | - |
|
| 2061 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2062 | - $payment, |
|
| 2063 | - array( |
|
| 2064 | - array( |
|
| 2065 | - 'PAY_ID' => $payment->ID(), |
|
| 2066 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2067 | - ), |
|
| 2068 | - ) |
|
| 2069 | - ); |
|
| 2070 | - } |
|
| 2071 | - |
|
| 2072 | - |
|
| 2073 | - /** |
|
| 2074 | - * _update_registration_payments |
|
| 2075 | - * this applies the payments to the selected registrations |
|
| 2076 | - * but only if they have not already been paid for |
|
| 2077 | - * |
|
| 2078 | - * @param EE_Transaction $transaction |
|
| 2079 | - * @param \EE_Payment $payment |
|
| 2080 | - * @param array $REG_IDs |
|
| 2081 | - * @return void |
|
| 2082 | - * @throws EE_Error |
|
| 2083 | - * @throws InvalidArgumentException |
|
| 2084 | - * @throws ReflectionException |
|
| 2085 | - * @throws RuntimeException |
|
| 2086 | - * @throws InvalidDataTypeException |
|
| 2087 | - * @throws InvalidInterfaceException |
|
| 2088 | - */ |
|
| 2089 | - protected function _update_registration_payments( |
|
| 2090 | - EE_Transaction $transaction, |
|
| 2091 | - EE_Payment $payment, |
|
| 2092 | - $REG_IDs = array() |
|
| 2093 | - ) { |
|
| 2094 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2095 | - // so let's do that using our set of REG_IDs from the form |
|
| 2096 | - $registration_query_where_params = array( |
|
| 2097 | - 'REG_ID' => array('IN', $REG_IDs), |
|
| 2098 | - ); |
|
| 2099 | - // but add in some conditions regarding payment, |
|
| 2100 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2101 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2102 | - if (! $payment->is_a_refund()) { |
|
| 2103 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2104 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2105 | - } |
|
| 2106 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2107 | - if (! empty($registrations)) { |
|
| 2108 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2109 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2110 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2111 | - } |
|
| 2112 | - } |
|
| 2113 | - |
|
| 2114 | - |
|
| 2115 | - /** |
|
| 2116 | - * _process_registration_status_change |
|
| 2117 | - * This processes requested registration status changes for all the registrations |
|
| 2118 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2119 | - * |
|
| 2120 | - * @param EE_Transaction $transaction |
|
| 2121 | - * @param array $REG_IDs |
|
| 2122 | - * @return bool |
|
| 2123 | - * @throws EE_Error |
|
| 2124 | - * @throws InvalidArgumentException |
|
| 2125 | - * @throws ReflectionException |
|
| 2126 | - * @throws InvalidDataTypeException |
|
| 2127 | - * @throws InvalidInterfaceException |
|
| 2128 | - */ |
|
| 2129 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2130 | - { |
|
| 2131 | - // first if there is no change in status then we get out. |
|
| 2132 | - if ( |
|
| 2133 | - ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2134 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2135 | - ) { |
|
| 2136 | - // no error message, no change requested, just nothing to do man. |
|
| 2137 | - return false; |
|
| 2138 | - } |
|
| 2139 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2140 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2141 | - |
|
| 2142 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2143 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 2144 | - $transaction, |
|
| 2145 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2146 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2147 | - ); |
|
| 2148 | - } |
|
| 2149 | - |
|
| 2150 | - |
|
| 2151 | - /** |
|
| 2152 | - * _build_payment_json_response |
|
| 2153 | - * |
|
| 2154 | - * @access public |
|
| 2155 | - * @param \EE_Payment $payment |
|
| 2156 | - * @param array $REG_IDs |
|
| 2157 | - * @param bool | null $delete_txn_reg_status_change |
|
| 2158 | - * @return array |
|
| 2159 | - * @throws EE_Error |
|
| 2160 | - * @throws InvalidArgumentException |
|
| 2161 | - * @throws InvalidDataTypeException |
|
| 2162 | - * @throws InvalidInterfaceException |
|
| 2163 | - * @throws ReflectionException |
|
| 2164 | - */ |
|
| 2165 | - protected function _build_payment_json_response( |
|
| 2166 | - EE_Payment $payment, |
|
| 2167 | - $REG_IDs = array(), |
|
| 2168 | - $delete_txn_reg_status_change = null |
|
| 2169 | - ) { |
|
| 2170 | - // was the payment deleted ? |
|
| 2171 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 2172 | - return array( |
|
| 2173 | - 'PAY_ID' => $payment->ID(), |
|
| 2174 | - 'amount' => $payment->amount(), |
|
| 2175 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2176 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2177 | - 'pay_status' => $payment->STS_ID(), |
|
| 2178 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2179 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2180 | - ); |
|
| 2181 | - } else { |
|
| 2182 | - $this->_get_payment_status_array(); |
|
| 2183 | - |
|
| 2184 | - return array( |
|
| 2185 | - 'amount' => $payment->amount(), |
|
| 2186 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2187 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2188 | - 'pay_status' => $payment->STS_ID(), |
|
| 2189 | - 'PAY_ID' => $payment->ID(), |
|
| 2190 | - 'STS_ID' => $payment->STS_ID(), |
|
| 2191 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2192 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2193 | - 'method' => strtoupper($payment->source()), |
|
| 2194 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2195 | - 'gateway' => $payment->payment_method() |
|
| 2196 | - ? $payment->payment_method()->admin_name() |
|
| 2197 | - : esc_html__('Unknown', 'event_espresso'), |
|
| 2198 | - 'gateway_response' => $payment->gateway_response(), |
|
| 2199 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2200 | - 'po_number' => $payment->po_number(), |
|
| 2201 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 2202 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2203 | - ); |
|
| 2204 | - } |
|
| 2205 | - } |
|
| 2206 | - |
|
| 2207 | - |
|
| 2208 | - /** |
|
| 2209 | - * delete_payment |
|
| 2210 | - * delete a payment or refund made towards a transaction |
|
| 2211 | - * |
|
| 2212 | - * @access public |
|
| 2213 | - * @return void |
|
| 2214 | - * @throws EE_Error |
|
| 2215 | - * @throws InvalidArgumentException |
|
| 2216 | - * @throws ReflectionException |
|
| 2217 | - * @throws InvalidDataTypeException |
|
| 2218 | - * @throws InvalidInterfaceException |
|
| 2219 | - */ |
|
| 2220 | - public function delete_payment() |
|
| 2221 | - { |
|
| 2222 | - $json_response_data = array('return_data' => false); |
|
| 2223 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2224 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2225 | - : 0; |
|
| 2226 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2227 | - 'ee_delete_payments', |
|
| 2228 | - 'delete_payment_from_registration_details' |
|
| 2229 | - ); |
|
| 2230 | - if ($PAY_ID && $can_delete) { |
|
| 2231 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2232 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2233 | - : false; |
|
| 2234 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2235 | - if ($payment instanceof EE_Payment) { |
|
| 2236 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2237 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2238 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2239 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2240 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2241 | - $payment, |
|
| 2242 | - $REG_IDs, |
|
| 2243 | - $delete_txn_reg_status_change |
|
| 2244 | - ); |
|
| 2245 | - if ($delete_txn_reg_status_change) { |
|
| 2246 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2247 | - // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2248 | - // $_REQUEST global because that's how messages will be looking for it. |
|
| 2249 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2250 | - $this->_maybe_send_notifications(); |
|
| 2251 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2252 | - } |
|
| 2253 | - } |
|
| 2254 | - } else { |
|
| 2255 | - EE_Error::add_error( |
|
| 2256 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2257 | - __FILE__, |
|
| 2258 | - __FUNCTION__, |
|
| 2259 | - __LINE__ |
|
| 2260 | - ); |
|
| 2261 | - } |
|
| 2262 | - } elseif ($can_delete) { |
|
| 2263 | - EE_Error::add_error( |
|
| 2264 | - esc_html__( |
|
| 2265 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2266 | - 'event_espresso' |
|
| 2267 | - ), |
|
| 2268 | - __FILE__, |
|
| 2269 | - __FUNCTION__, |
|
| 2270 | - __LINE__ |
|
| 2271 | - ); |
|
| 2272 | - } else { |
|
| 2273 | - EE_Error::add_error( |
|
| 2274 | - esc_html__( |
|
| 2275 | - 'You do not have access to delete a payment.', |
|
| 2276 | - 'event_espresso' |
|
| 2277 | - ), |
|
| 2278 | - __FILE__, |
|
| 2279 | - __FUNCTION__, |
|
| 2280 | - __LINE__ |
|
| 2281 | - ); |
|
| 2282 | - } |
|
| 2283 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 2284 | - $this->_template_args = array( |
|
| 2285 | - 'data' => $json_response_data, |
|
| 2286 | - 'success' => $notices['success'], |
|
| 2287 | - 'error' => $notices['errors'], |
|
| 2288 | - 'attention' => $notices['attention'], |
|
| 2289 | - ); |
|
| 2290 | - $this->_return_json(); |
|
| 2291 | - } |
|
| 2292 | - |
|
| 2293 | - |
|
| 2294 | - /** |
|
| 2295 | - * _registration_payment_data_array |
|
| 2296 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2297 | - * |
|
| 2298 | - * @access protected |
|
| 2299 | - * @param array $REG_IDs |
|
| 2300 | - * @return array |
|
| 2301 | - * @throws EE_Error |
|
| 2302 | - * @throws InvalidArgumentException |
|
| 2303 | - * @throws InvalidDataTypeException |
|
| 2304 | - * @throws InvalidInterfaceException |
|
| 2305 | - * @throws ReflectionException |
|
| 2306 | - */ |
|
| 2307 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 2308 | - { |
|
| 2309 | - $registration_payment_data = array(); |
|
| 2310 | - // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2311 | - if (! empty($REG_IDs)) { |
|
| 2312 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2313 | - foreach ($registrations as $registration) { |
|
| 2314 | - if ($registration instanceof EE_Registration) { |
|
| 2315 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 2316 | - 'paid' => $registration->pretty_paid(), |
|
| 2317 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2318 | - ); |
|
| 2319 | - } |
|
| 2320 | - } |
|
| 2321 | - } |
|
| 2322 | - |
|
| 2323 | - return $registration_payment_data; |
|
| 2324 | - } |
|
| 2325 | - |
|
| 2326 | - |
|
| 2327 | - /** |
|
| 2328 | - * _maybe_send_notifications |
|
| 2329 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2330 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 2331 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2332 | - * |
|
| 2333 | - * @access protected |
|
| 2334 | - * @param \EE_Payment | null $payment |
|
| 2335 | - */ |
|
| 2336 | - protected function _maybe_send_notifications($payment = null) |
|
| 2337 | - { |
|
| 2338 | - switch ($payment instanceof EE_Payment) { |
|
| 2339 | - // payment notifications |
|
| 2340 | - case true: |
|
| 2341 | - if ( |
|
| 2342 | - isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2343 | - && filter_var( |
|
| 2344 | - $this->_req_data['txn_payments']['send_notifications'], |
|
| 2345 | - FILTER_VALIDATE_BOOLEAN |
|
| 2346 | - ) |
|
| 2347 | - ) { |
|
| 2348 | - $this->_process_payment_notification($payment); |
|
| 2349 | - } |
|
| 2350 | - break; |
|
| 2351 | - // registration notifications |
|
| 2352 | - case false: |
|
| 2353 | - if ( |
|
| 2354 | - isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2355 | - && filter_var( |
|
| 2356 | - $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2357 | - FILTER_VALIDATE_BOOLEAN |
|
| 2358 | - ) |
|
| 2359 | - ) { |
|
| 2360 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2361 | - } |
|
| 2362 | - break; |
|
| 2363 | - } |
|
| 2364 | - } |
|
| 2365 | - |
|
| 2366 | - |
|
| 2367 | - /** |
|
| 2368 | - * _send_payment_reminder |
|
| 2369 | - * generates HTML for the View Transaction Details Admin page |
|
| 2370 | - * |
|
| 2371 | - * @access protected |
|
| 2372 | - * @return void |
|
| 2373 | - * @throws EE_Error |
|
| 2374 | - * @throws InvalidArgumentException |
|
| 2375 | - * @throws InvalidDataTypeException |
|
| 2376 | - * @throws InvalidInterfaceException |
|
| 2377 | - */ |
|
| 2378 | - protected function _send_payment_reminder() |
|
| 2379 | - { |
|
| 2380 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2381 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2382 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2383 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2384 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2385 | - ) : array(); |
|
| 2386 | - do_action( |
|
| 2387 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2388 | - $transaction |
|
| 2389 | - ); |
|
| 2390 | - $this->_redirect_after_action( |
|
| 2391 | - false, |
|
| 2392 | - esc_html__('payment reminder', 'event_espresso'), |
|
| 2393 | - esc_html__('sent', 'event_espresso'), |
|
| 2394 | - $query_args, |
|
| 2395 | - true |
|
| 2396 | - ); |
|
| 2397 | - } |
|
| 2398 | - |
|
| 2399 | - |
|
| 2400 | - /** |
|
| 2401 | - * get_transactions |
|
| 2402 | - * get transactions for given parameters (used by list table) |
|
| 2403 | - * |
|
| 2404 | - * @param int $perpage how many transactions displayed per page |
|
| 2405 | - * @param boolean $count return the count or objects |
|
| 2406 | - * @param string $view |
|
| 2407 | - * @return mixed int = count || array of transaction objects |
|
| 2408 | - * @throws EE_Error |
|
| 2409 | - * @throws InvalidArgumentException |
|
| 2410 | - * @throws InvalidDataTypeException |
|
| 2411 | - * @throws InvalidInterfaceException |
|
| 2412 | - */ |
|
| 2413 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 2414 | - { |
|
| 2415 | - |
|
| 2416 | - $TXN = EEM_Transaction::instance(); |
|
| 2417 | - |
|
| 2418 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2419 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2420 | - : date( |
|
| 2421 | - 'm/d/Y', |
|
| 2422 | - strtotime('-10 year') |
|
| 2423 | - ); |
|
| 2424 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2425 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2426 | - : date('m/d/Y'); |
|
| 2427 | - |
|
| 2428 | - // make sure our timestamps start and end right at the boundaries for each day |
|
| 2429 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2430 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2431 | - |
|
| 2432 | - |
|
| 2433 | - // convert to timestamps |
|
| 2434 | - $start_date = strtotime($start_date); |
|
| 2435 | - $end_date = strtotime($end_date); |
|
| 2436 | - |
|
| 2437 | - // makes sure start date is the lowest value and vice versa |
|
| 2438 | - $start_date = min($start_date, $end_date); |
|
| 2439 | - $end_date = max($start_date, $end_date); |
|
| 2440 | - |
|
| 2441 | - // convert to correct format for query |
|
| 2442 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2443 | - 'TXN_timestamp', |
|
| 2444 | - date('Y-m-d H:i:s', $start_date), |
|
| 2445 | - 'Y-m-d H:i:s' |
|
| 2446 | - ); |
|
| 2447 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2448 | - 'TXN_timestamp', |
|
| 2449 | - date('Y-m-d H:i:s', $end_date), |
|
| 2450 | - 'Y-m-d H:i:s' |
|
| 2451 | - ); |
|
| 2452 | - |
|
| 2453 | - |
|
| 2454 | - // set orderby |
|
| 2455 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2456 | - |
|
| 2457 | - switch ($this->_req_data['orderby']) { |
|
| 2458 | - case 'TXN_ID': |
|
| 2459 | - $orderby = 'TXN_ID'; |
|
| 2460 | - break; |
|
| 2461 | - case 'ATT_fname': |
|
| 2462 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2463 | - break; |
|
| 2464 | - case 'event_name': |
|
| 2465 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 2466 | - break; |
|
| 2467 | - default: // 'TXN_timestamp' |
|
| 2468 | - $orderby = 'TXN_timestamp'; |
|
| 2469 | - } |
|
| 2470 | - |
|
| 2471 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2472 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2473 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2474 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2475 | - |
|
| 2476 | - $offset = ($current_page - 1) * $per_page; |
|
| 2477 | - $limit = array($offset, $per_page); |
|
| 2478 | - |
|
| 2479 | - $_where = array( |
|
| 2480 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2481 | - 'Registration.REG_count' => 1, |
|
| 2482 | - ); |
|
| 2483 | - |
|
| 2484 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 2485 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2486 | - } |
|
| 2487 | - |
|
| 2488 | - if (isset($this->_req_data['s'])) { |
|
| 2489 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2490 | - $_where['OR'] = array( |
|
| 2491 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2492 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2493 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2494 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2495 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2496 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2497 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2498 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2499 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2500 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2501 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2502 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2503 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2504 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2505 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2506 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2507 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2508 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2509 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2510 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2511 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2512 | - ); |
|
| 2513 | - } |
|
| 2514 | - |
|
| 2515 | - // failed transactions |
|
| 2516 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2517 | - || ($count && $view === 'failed'); |
|
| 2518 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2519 | - || ($count && $view === 'abandoned'); |
|
| 2520 | - $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2521 | - || ($count && $view === 'incomplete'); |
|
| 2522 | - |
|
| 2523 | - if ($failed) { |
|
| 2524 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2525 | - } elseif ($abandoned) { |
|
| 2526 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2527 | - } elseif ($incomplete) { |
|
| 2528 | - $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2529 | - } else { |
|
| 2530 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2531 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - $query_params = apply_filters( |
|
| 2535 | - 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2536 | - array( |
|
| 2537 | - $_where, |
|
| 2538 | - 'order_by' => array($orderby => $sort), |
|
| 2539 | - 'limit' => $limit, |
|
| 2540 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2541 | - ), |
|
| 2542 | - $this->_req_data, |
|
| 2543 | - $view, |
|
| 2544 | - $count |
|
| 2545 | - ); |
|
| 2546 | - |
|
| 2547 | - $transactions = $count |
|
| 2548 | - ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2549 | - : $TXN->get_all($query_params); |
|
| 2550 | - |
|
| 2551 | - return $transactions; |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - |
|
| 2555 | - /** |
|
| 2556 | - * @since 4.9.79.p |
|
| 2557 | - * @throws EE_Error |
|
| 2558 | - * @throws InvalidArgumentException |
|
| 2559 | - * @throws InvalidDataTypeException |
|
| 2560 | - * @throws InvalidInterfaceException |
|
| 2561 | - * @throws ReflectionException |
|
| 2562 | - * @throws RuntimeException |
|
| 2563 | - */ |
|
| 2564 | - public function recalculateLineItems() |
|
| 2565 | - { |
|
| 2566 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2567 | - /** @var EE_Transaction $transaction */ |
|
| 2568 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2569 | - $total_line_item = $transaction->total_line_item(false); |
|
| 2570 | - $success = $transaction->recalculateLineItems(); |
|
| 2571 | - $this->_redirect_after_action( |
|
| 2572 | - (bool) $success, |
|
| 2573 | - esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2574 | - esc_html__('recalculated', 'event_espresso'), |
|
| 2575 | - isset($this->_req_data['redirect_to']) |
|
| 2576 | - ? array( |
|
| 2577 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2578 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2579 | - ) |
|
| 2580 | - : array(), |
|
| 2581 | - true |
|
| 2582 | - ); |
|
| 2583 | - } |
|
| 439 | + * Filters whether a link to the "Failed Transactions" list table |
|
| 440 | + * appears on the Transactions Admin Page list table. |
|
| 441 | + * List display can be turned back on via the following: |
|
| 442 | + * add_filter( |
|
| 443 | + * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 444 | + * '__return_true' |
|
| 445 | + * ); |
|
| 446 | + * |
|
| 447 | + * @since 4.9.70.p |
|
| 448 | + * @param boolean $display_failed_txns_list |
|
| 449 | + * @param Transactions_Admin_Page $this |
|
| 450 | + */ |
|
| 451 | + apply_filters( |
|
| 452 | + 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 453 | + false, |
|
| 454 | + $this |
|
| 455 | + ) |
|
| 456 | + ) { |
|
| 457 | + $this->_views['failed'] = array( |
|
| 458 | + 'slug' => 'failed', |
|
| 459 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 460 | + 'count' => 0, |
|
| 461 | + ); |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * _set_transaction_object |
|
| 468 | + * This sets the _transaction property for the transaction details screen |
|
| 469 | + * |
|
| 470 | + * @access private |
|
| 471 | + * @return void |
|
| 472 | + * @throws EE_Error |
|
| 473 | + * @throws InvalidArgumentException |
|
| 474 | + * @throws RuntimeException |
|
| 475 | + * @throws InvalidDataTypeException |
|
| 476 | + * @throws InvalidInterfaceException |
|
| 477 | + * @throws ReflectionException |
|
| 478 | + */ |
|
| 479 | + private function _set_transaction_object() |
|
| 480 | + { |
|
| 481 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 482 | + return; |
|
| 483 | + } //get out we've already set the object |
|
| 484 | + |
|
| 485 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 486 | + ? absint($this->_req_data['TXN_ID']) |
|
| 487 | + : false; |
|
| 488 | + |
|
| 489 | + // get transaction object |
|
| 490 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 491 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 492 | + ? $this->_transaction->session_data() |
|
| 493 | + : null; |
|
| 494 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 495 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 499 | + $error_msg = sprintf( |
|
| 500 | + esc_html__( |
|
| 501 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 502 | + 'event_espresso' |
|
| 503 | + ), |
|
| 504 | + $TXN_ID |
|
| 505 | + ); |
|
| 506 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * _transaction_legend_items |
|
| 513 | + * |
|
| 514 | + * @access protected |
|
| 515 | + * @return array |
|
| 516 | + * @throws EE_Error |
|
| 517 | + * @throws InvalidArgumentException |
|
| 518 | + * @throws ReflectionException |
|
| 519 | + * @throws InvalidDataTypeException |
|
| 520 | + * @throws InvalidInterfaceException |
|
| 521 | + */ |
|
| 522 | + protected function _transaction_legend_items() |
|
| 523 | + { |
|
| 524 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 525 | + $items = array(); |
|
| 526 | + |
|
| 527 | + if ( |
|
| 528 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 529 | + 'ee_read_global_messages', |
|
| 530 | + 'view_filtered_messages' |
|
| 531 | + ) |
|
| 532 | + ) { |
|
| 533 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 534 | + if ( |
|
| 535 | + is_array($related_for_icon) |
|
| 536 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 537 | + ) { |
|
| 538 | + $items['view_related_messages'] = array( |
|
| 539 | + 'class' => $related_for_icon['css_class'], |
|
| 540 | + 'desc' => $related_for_icon['label'], |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + $items = apply_filters( |
|
| 546 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 547 | + array_merge( |
|
| 548 | + $items, |
|
| 549 | + array( |
|
| 550 | + 'view_details' => array( |
|
| 551 | + 'class' => 'dashicons dashicons-cart', |
|
| 552 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 553 | + ), |
|
| 554 | + 'view_invoice' => array( |
|
| 555 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 556 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 557 | + ), |
|
| 558 | + 'view_receipt' => array( |
|
| 559 | + 'class' => 'dashicons dashicons-media-default', |
|
| 560 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 561 | + ), |
|
| 562 | + 'view_registration' => array( |
|
| 563 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 564 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 565 | + ), |
|
| 566 | + 'payment_overview_link' => array( |
|
| 567 | + 'class' => 'dashicons dashicons-money', |
|
| 568 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 569 | + ), |
|
| 570 | + ) |
|
| 571 | + ) |
|
| 572 | + ); |
|
| 573 | + |
|
| 574 | + if ( |
|
| 575 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 576 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 577 | + 'ee_send_message', |
|
| 578 | + 'espresso_transactions_send_payment_reminder' |
|
| 579 | + ) |
|
| 580 | + ) { |
|
| 581 | + $items['send_payment_reminder'] = array( |
|
| 582 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 583 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + $more_items = apply_filters( |
|
| 587 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 588 | + array( |
|
| 589 | + 'overpaid' => array( |
|
| 590 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 591 | + 'desc' => EEH_Template::pretty_status( |
|
| 592 | + EEM_Transaction::overpaid_status_code, |
|
| 593 | + false, |
|
| 594 | + 'sentence' |
|
| 595 | + ), |
|
| 596 | + ), |
|
| 597 | + 'complete' => array( |
|
| 598 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 599 | + 'desc' => EEH_Template::pretty_status( |
|
| 600 | + EEM_Transaction::complete_status_code, |
|
| 601 | + false, |
|
| 602 | + 'sentence' |
|
| 603 | + ), |
|
| 604 | + ), |
|
| 605 | + 'incomplete' => array( |
|
| 606 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 607 | + 'desc' => EEH_Template::pretty_status( |
|
| 608 | + EEM_Transaction::incomplete_status_code, |
|
| 609 | + false, |
|
| 610 | + 'sentence' |
|
| 611 | + ), |
|
| 612 | + ), |
|
| 613 | + 'abandoned' => array( |
|
| 614 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 615 | + 'desc' => EEH_Template::pretty_status( |
|
| 616 | + EEM_Transaction::abandoned_status_code, |
|
| 617 | + false, |
|
| 618 | + 'sentence' |
|
| 619 | + ), |
|
| 620 | + ), |
|
| 621 | + 'failed' => array( |
|
| 622 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 623 | + 'desc' => EEH_Template::pretty_status( |
|
| 624 | + EEM_Transaction::failed_status_code, |
|
| 625 | + false, |
|
| 626 | + 'sentence' |
|
| 627 | + ), |
|
| 628 | + ), |
|
| 629 | + ) |
|
| 630 | + ); |
|
| 631 | + |
|
| 632 | + return array_merge($items, $more_items); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * _transactions_overview_list_table |
|
| 638 | + * |
|
| 639 | + * @access protected |
|
| 640 | + * @return void |
|
| 641 | + * @throws DomainException |
|
| 642 | + * @throws EE_Error |
|
| 643 | + * @throws InvalidArgumentException |
|
| 644 | + * @throws InvalidDataTypeException |
|
| 645 | + * @throws InvalidInterfaceException |
|
| 646 | + * @throws ReflectionException |
|
| 647 | + */ |
|
| 648 | + protected function _transactions_overview_list_table() |
|
| 649 | + { |
|
| 650 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 651 | + $event = isset($this->_req_data['EVT_ID']) |
|
| 652 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 653 | + : null; |
|
| 654 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 655 | + ? sprintf( |
|
| 656 | + esc_html__( |
|
| 657 | + '%sViewing Transactions for the Event: %s%s', |
|
| 658 | + 'event_espresso' |
|
| 659 | + ), |
|
| 660 | + '<h3>', |
|
| 661 | + '<a href="' |
|
| 662 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 663 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 664 | + EVENTS_ADMIN_URL |
|
| 665 | + ) |
|
| 666 | + . '" title="' |
|
| 667 | + . esc_attr__( |
|
| 668 | + 'Click to Edit event', |
|
| 669 | + 'event_espresso' |
|
| 670 | + ) |
|
| 671 | + . '">' . $event->name() . '</a>', |
|
| 672 | + '</h3>' |
|
| 673 | + ) |
|
| 674 | + : ''; |
|
| 675 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 676 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * _transaction_details |
|
| 682 | + * generates HTML for the View Transaction Details Admin page |
|
| 683 | + * |
|
| 684 | + * @access protected |
|
| 685 | + * @return void |
|
| 686 | + * @throws DomainException |
|
| 687 | + * @throws EE_Error |
|
| 688 | + * @throws InvalidArgumentException |
|
| 689 | + * @throws InvalidDataTypeException |
|
| 690 | + * @throws InvalidInterfaceException |
|
| 691 | + * @throws RuntimeException |
|
| 692 | + * @throws ReflectionException |
|
| 693 | + */ |
|
| 694 | + protected function _transaction_details() |
|
| 695 | + { |
|
| 696 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 697 | + |
|
| 698 | + $this->_set_transaction_status_array(); |
|
| 699 | + |
|
| 700 | + $this->_template_args = array(); |
|
| 701 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 702 | + |
|
| 703 | + $this->_set_transaction_object(); |
|
| 704 | + |
|
| 705 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 706 | + return; |
|
| 707 | + } |
|
| 708 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 709 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 710 | + ? $primary_registration->attendee() |
|
| 711 | + : null; |
|
| 712 | + |
|
| 713 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 714 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 715 | + |
|
| 716 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 717 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 718 | + |
|
| 719 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 720 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 721 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 722 | + |
|
| 723 | + $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 724 | + $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 725 | + |
|
| 726 | + $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 727 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 728 | + $amount_due, |
|
| 729 | + true |
|
| 730 | + ); |
|
| 731 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 732 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 733 | + . $this->_template_args['amount_due']; |
|
| 734 | + } else { |
|
| 735 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 736 | + } |
|
| 737 | + $this->_template_args['amount_due_class'] = ''; |
|
| 738 | + |
|
| 739 | + if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 740 | + // paid in full |
|
| 741 | + $this->_template_args['amount_due'] = false; |
|
| 742 | + } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 743 | + // overpaid |
|
| 744 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 745 | + } elseif ($this->_transaction->total() > (float) 0) { |
|
| 746 | + if ($this->_transaction->paid() > (float) 0) { |
|
| 747 | + // monies owing |
|
| 748 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 749 | + } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 750 | + // no payments made yet |
|
| 751 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 752 | + } |
|
| 753 | + } elseif ($this->_transaction->total() === (float) 0) { |
|
| 754 | + // free event |
|
| 755 | + $this->_template_args['amount_due'] = false; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + $payment_method = $this->_transaction->payment_method(); |
|
| 759 | + |
|
| 760 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 761 | + ? $payment_method->admin_name() |
|
| 762 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 763 | + |
|
| 764 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 765 | + // link back to overview |
|
| 766 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 767 | + ? $_SERVER['HTTP_REFERER'] |
|
| 768 | + : TXN_ADMIN_URL; |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + // next link |
|
| 772 | + $next_txn = $this->_transaction->next( |
|
| 773 | + null, |
|
| 774 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 775 | + 'TXN_ID' |
|
| 776 | + ); |
|
| 777 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 778 | + ? $this->_next_link( |
|
| 779 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 780 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 781 | + TXN_ADMIN_URL |
|
| 782 | + ), |
|
| 783 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 784 | + ) |
|
| 785 | + : ''; |
|
| 786 | + // previous link |
|
| 787 | + $previous_txn = $this->_transaction->previous( |
|
| 788 | + null, |
|
| 789 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 790 | + 'TXN_ID' |
|
| 791 | + ); |
|
| 792 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 793 | + ? $this->_previous_link( |
|
| 794 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 795 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 796 | + TXN_ADMIN_URL |
|
| 797 | + ), |
|
| 798 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 799 | + ) |
|
| 800 | + : ''; |
|
| 801 | + |
|
| 802 | + // were we just redirected here after adding a new registration ??? |
|
| 803 | + if ( |
|
| 804 | + isset( |
|
| 805 | + $this->_req_data['redirect_from'], |
|
| 806 | + $this->_req_data['EVT_ID'], |
|
| 807 | + $this->_req_data['event_name'] |
|
| 808 | + ) |
|
| 809 | + ) { |
|
| 810 | + if ( |
|
| 811 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 812 | + 'ee_edit_registrations', |
|
| 813 | + 'espresso_registrations_new_registration', |
|
| 814 | + $this->_req_data['EVT_ID'] |
|
| 815 | + ) |
|
| 816 | + ) { |
|
| 817 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 818 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 819 | + array( |
|
| 820 | + 'page' => 'espresso_registrations', |
|
| 821 | + 'action' => 'new_registration', |
|
| 822 | + 'return' => 'default', |
|
| 823 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 824 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 825 | + ), |
|
| 826 | + REG_ADMIN_URL |
|
| 827 | + ); |
|
| 828 | + $this->_admin_page_title .= '">'; |
|
| 829 | + |
|
| 830 | + $this->_admin_page_title .= sprintf( |
|
| 831 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 832 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 833 | + ); |
|
| 834 | + $this->_admin_page_title .= '</a>'; |
|
| 835 | + } |
|
| 836 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 837 | + } |
|
| 838 | + // grab messages at the last second |
|
| 839 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 840 | + // path to template |
|
| 841 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 842 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 843 | + $template_path, |
|
| 844 | + $this->_template_args, |
|
| 845 | + true |
|
| 846 | + ); |
|
| 847 | + |
|
| 848 | + // the details template wrapper |
|
| 849 | + $this->display_admin_page_with_sidebar(); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * _transaction_details_metaboxes |
|
| 855 | + * |
|
| 856 | + * @access protected |
|
| 857 | + * @return void |
|
| 858 | + * @throws EE_Error |
|
| 859 | + * @throws InvalidArgumentException |
|
| 860 | + * @throws InvalidDataTypeException |
|
| 861 | + * @throws InvalidInterfaceException |
|
| 862 | + * @throws RuntimeException |
|
| 863 | + * @throws ReflectionException |
|
| 864 | + */ |
|
| 865 | + protected function _transaction_details_metaboxes() |
|
| 866 | + { |
|
| 867 | + |
|
| 868 | + $this->_set_transaction_object(); |
|
| 869 | + |
|
| 870 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 871 | + return; |
|
| 872 | + } |
|
| 873 | + add_meta_box( |
|
| 874 | + 'edit-txn-details-mbox', |
|
| 875 | + esc_html__('Transaction Details', 'event_espresso'), |
|
| 876 | + array($this, 'txn_details_meta_box'), |
|
| 877 | + $this->_wp_page_slug, |
|
| 878 | + 'normal', |
|
| 879 | + 'high' |
|
| 880 | + ); |
|
| 881 | + add_meta_box( |
|
| 882 | + 'edit-txn-attendees-mbox', |
|
| 883 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 884 | + array($this, 'txn_attendees_meta_box'), |
|
| 885 | + $this->_wp_page_slug, |
|
| 886 | + 'normal', |
|
| 887 | + 'high', |
|
| 888 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 889 | + ); |
|
| 890 | + add_meta_box( |
|
| 891 | + 'edit-txn-registrant-mbox', |
|
| 892 | + esc_html__('Primary Contact', 'event_espresso'), |
|
| 893 | + array($this, 'txn_registrant_side_meta_box'), |
|
| 894 | + $this->_wp_page_slug, |
|
| 895 | + 'side', |
|
| 896 | + 'high' |
|
| 897 | + ); |
|
| 898 | + add_meta_box( |
|
| 899 | + 'edit-txn-billing-info-mbox', |
|
| 900 | + esc_html__('Billing Information', 'event_espresso'), |
|
| 901 | + array($this, 'txn_billing_info_side_meta_box'), |
|
| 902 | + $this->_wp_page_slug, |
|
| 903 | + 'side', |
|
| 904 | + 'high' |
|
| 905 | + ); |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Callback for transaction actions metabox. |
|
| 911 | + * |
|
| 912 | + * @param EE_Transaction|null $transaction |
|
| 913 | + * @return string |
|
| 914 | + * @throws DomainException |
|
| 915 | + * @throws EE_Error |
|
| 916 | + * @throws InvalidArgumentException |
|
| 917 | + * @throws InvalidDataTypeException |
|
| 918 | + * @throws InvalidInterfaceException |
|
| 919 | + * @throws ReflectionException |
|
| 920 | + * @throws RuntimeException |
|
| 921 | + */ |
|
| 922 | + public function getActionButtons(EE_Transaction $transaction = null) |
|
| 923 | + { |
|
| 924 | + $content = ''; |
|
| 925 | + $actions = array(); |
|
| 926 | + if (! $transaction instanceof EE_Transaction) { |
|
| 927 | + return $content; |
|
| 928 | + } |
|
| 929 | + /** @var EE_Registration $primary_registration */ |
|
| 930 | + $primary_registration = $transaction->primary_registration(); |
|
| 931 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 932 | + ? $primary_registration->attendee() |
|
| 933 | + : null; |
|
| 934 | + |
|
| 935 | + if ( |
|
| 936 | + $attendee instanceof EE_Attendee |
|
| 937 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 938 | + 'ee_send_message', |
|
| 939 | + 'espresso_transactions_send_payment_reminder' |
|
| 940 | + ) |
|
| 941 | + ) { |
|
| 942 | + $actions['payment_reminder'] = |
|
| 943 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 944 | + && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 945 | + && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 946 | + ? EEH_Template::get_button_or_link( |
|
| 947 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 948 | + array( |
|
| 949 | + 'action' => 'send_payment_reminder', |
|
| 950 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 951 | + 'redirect_to' => 'view_transaction', |
|
| 952 | + ), |
|
| 953 | + TXN_ADMIN_URL |
|
| 954 | + ), |
|
| 955 | + esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 956 | + 'button secondary-button', |
|
| 957 | + 'dashicons dashicons-email-alt' |
|
| 958 | + ) |
|
| 959 | + : ''; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + if ( |
|
| 963 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 964 | + 'ee_edit_payments', |
|
| 965 | + 'espresso_transactions_recalculate_line_items' |
|
| 966 | + ) |
|
| 967 | + ) { |
|
| 968 | + $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 969 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 970 | + array( |
|
| 971 | + 'action' => 'espresso_recalculate_line_items', |
|
| 972 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 973 | + 'redirect_to' => 'view_transaction', |
|
| 974 | + ), |
|
| 975 | + TXN_ADMIN_URL |
|
| 976 | + ), |
|
| 977 | + esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 978 | + 'button secondary-button', |
|
| 979 | + 'dashicons dashicons-update' |
|
| 980 | + ); |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + if ( |
|
| 984 | + $primary_registration instanceof EE_Registration |
|
| 985 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
| 986 | + ) { |
|
| 987 | + $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 988 | + $primary_registration->receipt_url(), |
|
| 989 | + esc_html__('View Receipt', 'event_espresso'), |
|
| 990 | + 'button secondary-button', |
|
| 991 | + 'dashicons dashicons-media-default' |
|
| 992 | + ); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + if ( |
|
| 996 | + $primary_registration instanceof EE_Registration |
|
| 997 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 998 | + ) { |
|
| 999 | + $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 1000 | + $primary_registration->invoice_url(), |
|
| 1001 | + esc_html__('View Invoice', 'event_espresso'), |
|
| 1002 | + 'button secondary-button', |
|
| 1003 | + 'dashicons dashicons-media-spreadsheet' |
|
| 1004 | + ); |
|
| 1005 | + } |
|
| 1006 | + $actions = array_filter( |
|
| 1007 | + apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 1008 | + ); |
|
| 1009 | + if ($actions) { |
|
| 1010 | + $content = '<ul>'; |
|
| 1011 | + $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1012 | + $content .= '</uL>'; |
|
| 1013 | + } |
|
| 1014 | + return $content; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * txn_details_meta_box |
|
| 1020 | + * generates HTML for the Transaction main meta box |
|
| 1021 | + * |
|
| 1022 | + * @return void |
|
| 1023 | + * @throws DomainException |
|
| 1024 | + * @throws EE_Error |
|
| 1025 | + * @throws InvalidArgumentException |
|
| 1026 | + * @throws InvalidDataTypeException |
|
| 1027 | + * @throws InvalidInterfaceException |
|
| 1028 | + * @throws RuntimeException |
|
| 1029 | + * @throws ReflectionException |
|
| 1030 | + */ |
|
| 1031 | + public function txn_details_meta_box() |
|
| 1032 | + { |
|
| 1033 | + $this->_set_transaction_object(); |
|
| 1034 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1035 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1036 | + ? $this->_transaction->primary_registration()->attendee() |
|
| 1037 | + : null; |
|
| 1038 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1039 | + 'ee_edit_payments', |
|
| 1040 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1041 | + ); |
|
| 1042 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1043 | + 'ee_delete_payments', |
|
| 1044 | + 'delete_payment_from_registration_details' |
|
| 1045 | + ); |
|
| 1046 | + |
|
| 1047 | + // get line table |
|
| 1048 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1049 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1050 | + 'admin_table', |
|
| 1051 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1052 | + ); |
|
| 1053 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1054 | + $this->_transaction->total_line_item() |
|
| 1055 | + ); |
|
| 1056 | + $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1057 | + |
|
| 1058 | + // process taxes |
|
| 1059 | + $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1060 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1061 | + |
|
| 1062 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1063 | + $this->_transaction->total(), |
|
| 1064 | + false, |
|
| 1065 | + false |
|
| 1066 | + ); |
|
| 1067 | + $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1068 | + $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1069 | + |
|
| 1070 | + // process payment details |
|
| 1071 | + $payments = $this->_transaction->payments(); |
|
| 1072 | + if (! empty($payments)) { |
|
| 1073 | + $this->_template_args['payments'] = $payments; |
|
| 1074 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1075 | + } else { |
|
| 1076 | + $this->_template_args['payments'] = false; |
|
| 1077 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1081 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1082 | + array('action' => 'espresso_delete_payment'), |
|
| 1083 | + TXN_ADMIN_URL |
|
| 1084 | + ); |
|
| 1085 | + |
|
| 1086 | + if (isset($txn_details['invoice_number'])) { |
|
| 1087 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1088 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1089 | + 'Invoice Number', |
|
| 1090 | + 'event_espresso' |
|
| 1091 | + ); |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1095 | + ->primary_registration() |
|
| 1096 | + ->session_ID(); |
|
| 1097 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1098 | + 'Registration Session', |
|
| 1099 | + 'event_espresso' |
|
| 1100 | + ); |
|
| 1101 | + |
|
| 1102 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1103 | + ? $this->_session['ip_address'] |
|
| 1104 | + : ''; |
|
| 1105 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1106 | + 'Transaction placed from IP', |
|
| 1107 | + 'event_espresso' |
|
| 1108 | + ); |
|
| 1109 | + |
|
| 1110 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1111 | + ? $this->_session['user_agent'] |
|
| 1112 | + : ''; |
|
| 1113 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1114 | + 'Registrant User Agent', |
|
| 1115 | + 'event_espresso' |
|
| 1116 | + ); |
|
| 1117 | + |
|
| 1118 | + $reg_steps = '<ul>'; |
|
| 1119 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1120 | + if ($reg_step_status === true) { |
|
| 1121 | + $reg_steps .= '<li style="color:#70cc50">' |
|
| 1122 | + . sprintf( |
|
| 1123 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1124 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1125 | + ) |
|
| 1126 | + . '</li>'; |
|
| 1127 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1128 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1129 | + . sprintf( |
|
| 1130 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1131 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1132 | + date( |
|
| 1133 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1134 | + $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1135 | + ) |
|
| 1136 | + ) |
|
| 1137 | + . '</li>'; |
|
| 1138 | + } else { |
|
| 1139 | + $reg_steps .= '<li style="color:#E76700">' |
|
| 1140 | + . sprintf( |
|
| 1141 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1142 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1143 | + ) |
|
| 1144 | + . '</li>'; |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + $reg_steps .= '</ul>'; |
|
| 1148 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1149 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1150 | + 'Registration Step Progress', |
|
| 1151 | + 'event_espresso' |
|
| 1152 | + ); |
|
| 1153 | + |
|
| 1154 | + |
|
| 1155 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 1156 | + $this->_get_payment_methods($payments); |
|
| 1157 | + $this->_get_payment_status_array(); |
|
| 1158 | + $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1159 | + |
|
| 1160 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1161 | + array( |
|
| 1162 | + 'action' => 'edit_transaction', |
|
| 1163 | + 'process' => 'transaction', |
|
| 1164 | + ), |
|
| 1165 | + TXN_ADMIN_URL |
|
| 1166 | + ); |
|
| 1167 | + $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1168 | + array( |
|
| 1169 | + 'page' => 'espresso_transactions', |
|
| 1170 | + 'action' => 'espresso_apply_payment', |
|
| 1171 | + ), |
|
| 1172 | + WP_AJAX_URL |
|
| 1173 | + ); |
|
| 1174 | + $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1175 | + array( |
|
| 1176 | + 'page' => 'espresso_transactions', |
|
| 1177 | + 'action' => 'espresso_delete_payment', |
|
| 1178 | + ), |
|
| 1179 | + WP_AJAX_URL |
|
| 1180 | + ); |
|
| 1181 | + |
|
| 1182 | + $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1183 | + |
|
| 1184 | + // 'espresso_delete_payment_nonce' |
|
| 1185 | + |
|
| 1186 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1187 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + |
|
| 1191 | + /** |
|
| 1192 | + * _get_registration_payment_IDs |
|
| 1193 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1194 | + * |
|
| 1195 | + * @access protected |
|
| 1196 | + * @param EE_Payment[] $payments |
|
| 1197 | + * @return array |
|
| 1198 | + * @throws EE_Error |
|
| 1199 | + * @throws InvalidArgumentException |
|
| 1200 | + * @throws InvalidDataTypeException |
|
| 1201 | + * @throws InvalidInterfaceException |
|
| 1202 | + * @throws ReflectionException |
|
| 1203 | + */ |
|
| 1204 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 1205 | + { |
|
| 1206 | + $existing_reg_payments = array(); |
|
| 1207 | + // get all reg payments for these payments |
|
| 1208 | + $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1209 | + array( |
|
| 1210 | + array( |
|
| 1211 | + 'PAY_ID' => array( |
|
| 1212 | + 'IN', |
|
| 1213 | + array_keys($payments), |
|
| 1214 | + ), |
|
| 1215 | + ), |
|
| 1216 | + ) |
|
| 1217 | + ); |
|
| 1218 | + if (! empty($reg_payments)) { |
|
| 1219 | + foreach ($payments as $payment) { |
|
| 1220 | + if (! $payment instanceof EE_Payment) { |
|
| 1221 | + continue; |
|
| 1222 | + } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1223 | + $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1224 | + } |
|
| 1225 | + foreach ($reg_payments as $reg_payment) { |
|
| 1226 | + if ( |
|
| 1227 | + $reg_payment instanceof EE_Registration_Payment |
|
| 1228 | + && $reg_payment->payment_ID() === $payment->ID() |
|
| 1229 | + ) { |
|
| 1230 | + $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + return $existing_reg_payments; |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * _get_registrations_to_apply_payment_to |
|
| 1242 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1243 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 1244 | + * |
|
| 1245 | + * @access protected |
|
| 1246 | + * @return void |
|
| 1247 | + * @throws EE_Error |
|
| 1248 | + * @throws InvalidArgumentException |
|
| 1249 | + * @throws InvalidDataTypeException |
|
| 1250 | + * @throws InvalidInterfaceException |
|
| 1251 | + * @throws ReflectionException |
|
| 1252 | + */ |
|
| 1253 | + protected function _get_registrations_to_apply_payment_to() |
|
| 1254 | + { |
|
| 1255 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1256 | + $query_params = array( |
|
| 1257 | + array( |
|
| 1258 | + 'STS_ID' => array( |
|
| 1259 | + 'IN', |
|
| 1260 | + array( |
|
| 1261 | + EEM_Registration::status_id_approved, |
|
| 1262 | + EEM_Registration::status_id_pending_payment, |
|
| 1263 | + EEM_Registration::status_id_not_approved, |
|
| 1264 | + ), |
|
| 1265 | + ), |
|
| 1266 | + ), |
|
| 1267 | + ); |
|
| 1268 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1269 | + '', |
|
| 1270 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1271 | + '', |
|
| 1272 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1273 | + ); |
|
| 1274 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1275 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1276 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1277 | + EEH_HTML::tr( |
|
| 1278 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1279 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1280 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1281 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1282 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1283 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1284 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1285 | + ) |
|
| 1286 | + ); |
|
| 1287 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1288 | + // get registrations for TXN |
|
| 1289 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 1290 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1291 | + foreach ($registrations as $registration) { |
|
| 1292 | + if ($registration instanceof EE_Registration) { |
|
| 1293 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1294 | + ? $registration->attendee()->full_name() |
|
| 1295 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1296 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 1297 | + $taxable = $registration->ticket()->taxable() |
|
| 1298 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1299 | + : ''; |
|
| 1300 | + $checked = empty($existing_reg_payments) |
|
| 1301 | + || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1302 | + ? ' checked="checked"' |
|
| 1303 | + : ''; |
|
| 1304 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1305 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1306 | + EEH_HTML::td($registration->ID()) . |
|
| 1307 | + EEH_HTML::td($attendee_name) . |
|
| 1308 | + EEH_HTML::td( |
|
| 1309 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1310 | + ) . |
|
| 1311 | + EEH_HTML::td($registration->event_name()) . |
|
| 1312 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1313 | + EEH_HTML::td( |
|
| 1314 | + EEH_Template::format_currency($owing), |
|
| 1315 | + '', |
|
| 1316 | + 'txn-admin-payment-owing-td jst-cntr' |
|
| 1317 | + ) . |
|
| 1318 | + EEH_HTML::td( |
|
| 1319 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 1320 | + . '" name="txn_admin_payment[registrations]"' |
|
| 1321 | + . $checked . $disabled . '>', |
|
| 1322 | + '', |
|
| 1323 | + 'jst-cntr' |
|
| 1324 | + ), |
|
| 1325 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1326 | + ); |
|
| 1327 | + } |
|
| 1328 | + } |
|
| 1329 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1330 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1331 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1332 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1333 | + esc_html__( |
|
| 1334 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
| 1335 | + 'event_espresso' |
|
| 1336 | + ), |
|
| 1337 | + '', |
|
| 1338 | + 'clear description' |
|
| 1339 | + ); |
|
| 1340 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1341 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1342 | + } |
|
| 1343 | + |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * _get_reg_status_selection |
|
| 1347 | + * |
|
| 1348 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1349 | + * instead of events. |
|
| 1350 | + * @access protected |
|
| 1351 | + * @return void |
|
| 1352 | + * @throws EE_Error |
|
| 1353 | + */ |
|
| 1354 | + protected function _get_reg_status_selection() |
|
| 1355 | + { |
|
| 1356 | + // first get all possible statuses |
|
| 1357 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1358 | + // let's add a "don't change" option. |
|
| 1359 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1360 | + $status_array = array_merge($status_array, $statuses); |
|
| 1361 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1362 | + 'txn_reg_status_change[reg_status]', |
|
| 1363 | + $status_array, |
|
| 1364 | + 'NAN', |
|
| 1365 | + 'id="txn-admin-payment-reg-status-inp"', |
|
| 1366 | + 'txn-reg-status-change-reg-status' |
|
| 1367 | + ); |
|
| 1368 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1369 | + 'delete_txn_reg_status_change[reg_status]', |
|
| 1370 | + $status_array, |
|
| 1371 | + 'NAN', |
|
| 1372 | + 'delete-txn-admin-payment-reg-status-inp', |
|
| 1373 | + 'delete-txn-reg-status-change-reg-status' |
|
| 1374 | + ); |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * _get_payment_methods |
|
| 1380 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1381 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1382 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1383 | + * |
|
| 1384 | + * @access private |
|
| 1385 | + * @param EE_Payment[] to show on this page |
|
| 1386 | + * @return void |
|
| 1387 | + * @throws EE_Error |
|
| 1388 | + * @throws InvalidArgumentException |
|
| 1389 | + * @throws InvalidDataTypeException |
|
| 1390 | + * @throws InvalidInterfaceException |
|
| 1391 | + * @throws ReflectionException |
|
| 1392 | + */ |
|
| 1393 | + private function _get_payment_methods($payments = array()) |
|
| 1394 | + { |
|
| 1395 | + $payment_methods_of_payments = array(); |
|
| 1396 | + foreach ($payments as $payment) { |
|
| 1397 | + if ($payment instanceof EE_Payment) { |
|
| 1398 | + $payment_methods_of_payments[] = $payment->ID(); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + if ($payment_methods_of_payments) { |
|
| 1402 | + $query_args = array( |
|
| 1403 | + array( |
|
| 1404 | + 'OR*payment_method_for_payment' => array( |
|
| 1405 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1406 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1407 | + ), |
|
| 1408 | + ), |
|
| 1409 | + ); |
|
| 1410 | + } else { |
|
| 1411 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1412 | + } |
|
| 1413 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * txn_attendees_meta_box |
|
| 1419 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1420 | + * |
|
| 1421 | + * @access public |
|
| 1422 | + * @param WP_Post $post |
|
| 1423 | + * @param array $metabox |
|
| 1424 | + * @return void |
|
| 1425 | + * @throws DomainException |
|
| 1426 | + * @throws EE_Error |
|
| 1427 | + * @throws InvalidArgumentException |
|
| 1428 | + * @throws InvalidDataTypeException |
|
| 1429 | + * @throws InvalidInterfaceException |
|
| 1430 | + * @throws ReflectionException |
|
| 1431 | + */ |
|
| 1432 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1433 | + { |
|
| 1434 | + |
|
| 1435 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1436 | + extract($metabox['args']); |
|
| 1437 | + $this->_template_args['post'] = $post; |
|
| 1438 | + $this->_template_args['event_attendees'] = array(); |
|
| 1439 | + // process items in cart |
|
| 1440 | + $line_items = $this->_transaction->get_many_related( |
|
| 1441 | + 'Line_Item', |
|
| 1442 | + array(array('LIN_type' => 'line-item')) |
|
| 1443 | + ); |
|
| 1444 | + if (! empty($line_items)) { |
|
| 1445 | + foreach ($line_items as $item) { |
|
| 1446 | + if ($item instanceof EE_Line_Item) { |
|
| 1447 | + switch ($item->OBJ_type()) { |
|
| 1448 | + case 'Event': |
|
| 1449 | + break; |
|
| 1450 | + case 'Ticket': |
|
| 1451 | + $ticket = $item->ticket(); |
|
| 1452 | + // right now we're only handling tickets here. |
|
| 1453 | + // Cause its expected that only tickets will have attendees right? |
|
| 1454 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1455 | + break; |
|
| 1456 | + } |
|
| 1457 | + try { |
|
| 1458 | + $event_name = $ticket->get_event_name(); |
|
| 1459 | + } catch (Exception $e) { |
|
| 1460 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1461 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1462 | + } |
|
| 1463 | + $event_name .= ' - ' . $item->name(); |
|
| 1464 | + $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1465 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1466 | + $registrations = $ticket->registrations( |
|
| 1467 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1468 | + ); |
|
| 1469 | + foreach ($registrations as $registration) { |
|
| 1470 | + if (! $registration instanceof EE_Registration) { |
|
| 1471 | + break; |
|
| 1472 | + } |
|
| 1473 | + $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1474 | + = $registration->status_ID(); |
|
| 1475 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1476 | + = $registration->count(); |
|
| 1477 | + $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1478 | + = $event_name; |
|
| 1479 | + $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1480 | + = $ticket_price; |
|
| 1481 | + // attendee info |
|
| 1482 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1483 | + if ($attendee instanceof EE_Attendee) { |
|
| 1484 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1485 | + = $attendee->ID(); |
|
| 1486 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1487 | + = $attendee->full_name(); |
|
| 1488 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1489 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1490 | + . esc_html__( |
|
| 1491 | + ' Event', |
|
| 1492 | + 'event_espresso' |
|
| 1493 | + ) |
|
| 1494 | + . '">' . $attendee->email() . '</a>'; |
|
| 1495 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1496 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1497 | + } else { |
|
| 1498 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1499 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1500 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1501 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1502 | + } |
|
| 1503 | + } |
|
| 1504 | + break; |
|
| 1505 | + } |
|
| 1506 | + } |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1510 | + array( |
|
| 1511 | + 'action' => 'edit_transaction', |
|
| 1512 | + 'process' => 'attendees', |
|
| 1513 | + ), |
|
| 1514 | + TXN_ADMIN_URL |
|
| 1515 | + ); |
|
| 1516 | + echo EEH_Template::display_template( |
|
| 1517 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1518 | + $this->_template_args, |
|
| 1519 | + true |
|
| 1520 | + ); |
|
| 1521 | + } else { |
|
| 1522 | + echo sprintf( |
|
| 1523 | + esc_html__( |
|
| 1524 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1525 | + 'event_espresso' |
|
| 1526 | + ), |
|
| 1527 | + '<p class="important-notice">', |
|
| 1528 | + '</p>' |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + } |
|
| 1532 | + |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * txn_registrant_side_meta_box |
|
| 1536 | + * generates HTML for the Edit Transaction side meta box |
|
| 1537 | + * |
|
| 1538 | + * @access public |
|
| 1539 | + * @return void |
|
| 1540 | + * @throws DomainException |
|
| 1541 | + * @throws EE_Error |
|
| 1542 | + * @throws InvalidArgumentException |
|
| 1543 | + * @throws InvalidDataTypeException |
|
| 1544 | + * @throws InvalidInterfaceException |
|
| 1545 | + * @throws ReflectionException |
|
| 1546 | + */ |
|
| 1547 | + public function txn_registrant_side_meta_box() |
|
| 1548 | + { |
|
| 1549 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1550 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1551 | + : null; |
|
| 1552 | + if (! $primary_att instanceof EE_Attendee) { |
|
| 1553 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1554 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1555 | + 'event_espresso' |
|
| 1556 | + ); |
|
| 1557 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1558 | + } |
|
| 1559 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1560 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1561 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1562 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1563 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1564 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1565 | + array( |
|
| 1566 | + 'action' => 'edit_attendee', |
|
| 1567 | + 'post' => $primary_att->ID(), |
|
| 1568 | + ), |
|
| 1569 | + REG_ADMIN_URL |
|
| 1570 | + ); |
|
| 1571 | + // get formatted address for registrant |
|
| 1572 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1573 | + echo EEH_Template::display_template( |
|
| 1574 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1575 | + $this->_template_args, |
|
| 1576 | + true |
|
| 1577 | + ); |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + |
|
| 1581 | + /** |
|
| 1582 | + * txn_billing_info_side_meta_box |
|
| 1583 | + * generates HTML for the Edit Transaction side meta box |
|
| 1584 | + * |
|
| 1585 | + * @access public |
|
| 1586 | + * @return void |
|
| 1587 | + * @throws DomainException |
|
| 1588 | + * @throws EE_Error |
|
| 1589 | + */ |
|
| 1590 | + public function txn_billing_info_side_meta_box() |
|
| 1591 | + { |
|
| 1592 | + |
|
| 1593 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1594 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1595 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1596 | + TXN_ADMIN_URL |
|
| 1597 | + ); |
|
| 1598 | + |
|
| 1599 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1600 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * apply_payments_or_refunds |
|
| 1606 | + * registers a payment or refund made towards a transaction |
|
| 1607 | + * |
|
| 1608 | + * @access public |
|
| 1609 | + * @return void |
|
| 1610 | + * @throws EE_Error |
|
| 1611 | + * @throws InvalidArgumentException |
|
| 1612 | + * @throws ReflectionException |
|
| 1613 | + * @throws RuntimeException |
|
| 1614 | + * @throws InvalidDataTypeException |
|
| 1615 | + * @throws InvalidInterfaceException |
|
| 1616 | + */ |
|
| 1617 | + public function apply_payments_or_refunds() |
|
| 1618 | + { |
|
| 1619 | + $json_response_data = array('return_data' => false); |
|
| 1620 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1621 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1622 | + 'ee_edit_payments', |
|
| 1623 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1624 | + ); |
|
| 1625 | + if (! empty($valid_data) && $has_access) { |
|
| 1626 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1627 | + // save the new payment |
|
| 1628 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1629 | + // get the TXN for this payment |
|
| 1630 | + $transaction = $payment->transaction(); |
|
| 1631 | + // verify transaction |
|
| 1632 | + if ($transaction instanceof EE_Transaction) { |
|
| 1633 | + // calculate_total_payments_and_update_status |
|
| 1634 | + $this->_process_transaction_payments($transaction); |
|
| 1635 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1636 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1637 | + // apply payment to registrations (if applicable) |
|
| 1638 | + if (! empty($REG_IDs)) { |
|
| 1639 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1640 | + $this->_maybe_send_notifications(); |
|
| 1641 | + // now process status changes for the same registrations |
|
| 1642 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1643 | + } |
|
| 1644 | + $this->_maybe_send_notifications($payment); |
|
| 1645 | + // prepare to render page |
|
| 1646 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1647 | + do_action( |
|
| 1648 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1649 | + $transaction, |
|
| 1650 | + $payment |
|
| 1651 | + ); |
|
| 1652 | + } else { |
|
| 1653 | + EE_Error::add_error( |
|
| 1654 | + esc_html__( |
|
| 1655 | + 'A valid Transaction for this payment could not be retrieved.', |
|
| 1656 | + 'event_espresso' |
|
| 1657 | + ), |
|
| 1658 | + __FILE__, |
|
| 1659 | + __FUNCTION__, |
|
| 1660 | + __LINE__ |
|
| 1661 | + ); |
|
| 1662 | + } |
|
| 1663 | + } elseif ($has_access) { |
|
| 1664 | + EE_Error::add_error( |
|
| 1665 | + esc_html__( |
|
| 1666 | + 'The payment form data could not be processed. Please try again.', |
|
| 1667 | + 'event_espresso' |
|
| 1668 | + ), |
|
| 1669 | + __FILE__, |
|
| 1670 | + __FUNCTION__, |
|
| 1671 | + __LINE__ |
|
| 1672 | + ); |
|
| 1673 | + } else { |
|
| 1674 | + EE_Error::add_error( |
|
| 1675 | + esc_html__( |
|
| 1676 | + 'You do not have access to apply payments or refunds to a registration.', |
|
| 1677 | + 'event_espresso' |
|
| 1678 | + ), |
|
| 1679 | + __FILE__, |
|
| 1680 | + __FUNCTION__, |
|
| 1681 | + __LINE__ |
|
| 1682 | + ); |
|
| 1683 | + } |
|
| 1684 | + $notices = EE_Error::get_notices( |
|
| 1685 | + false, |
|
| 1686 | + false, |
|
| 1687 | + false |
|
| 1688 | + ); |
|
| 1689 | + $this->_template_args = array( |
|
| 1690 | + 'data' => $json_response_data, |
|
| 1691 | + 'error' => $notices['errors'], |
|
| 1692 | + 'success' => $notices['success'], |
|
| 1693 | + ); |
|
| 1694 | + $this->_return_json(); |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * _validate_payment_request_data |
|
| 1700 | + * |
|
| 1701 | + * @return array |
|
| 1702 | + * @throws EE_Error |
|
| 1703 | + * @throws InvalidArgumentException |
|
| 1704 | + * @throws InvalidDataTypeException |
|
| 1705 | + * @throws InvalidInterfaceException |
|
| 1706 | + */ |
|
| 1707 | + protected function _validate_payment_request_data() |
|
| 1708 | + { |
|
| 1709 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1710 | + return array(); |
|
| 1711 | + } |
|
| 1712 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1713 | + try { |
|
| 1714 | + if ($payment_form->was_submitted()) { |
|
| 1715 | + $payment_form->receive_form_submission(); |
|
| 1716 | + if (! $payment_form->is_valid()) { |
|
| 1717 | + $submission_error_messages = array(); |
|
| 1718 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1719 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1720 | + $submission_error_messages[] = sprintf( |
|
| 1721 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1722 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1723 | + $validation_error->getMessage() |
|
| 1724 | + ); |
|
| 1725 | + } |
|
| 1726 | + } |
|
| 1727 | + EE_Error::add_error( |
|
| 1728 | + implode('<br />', $submission_error_messages), |
|
| 1729 | + __FILE__, |
|
| 1730 | + __FUNCTION__, |
|
| 1731 | + __LINE__ |
|
| 1732 | + ); |
|
| 1733 | + return array(); |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 1736 | + } catch (EE_Error $e) { |
|
| 1737 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1738 | + return array(); |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + return $payment_form->valid_data(); |
|
| 1742 | + } |
|
| 1743 | + |
|
| 1744 | + |
|
| 1745 | + /** |
|
| 1746 | + * _generate_payment_form_section |
|
| 1747 | + * |
|
| 1748 | + * @return EE_Form_Section_Proper |
|
| 1749 | + * @throws EE_Error |
|
| 1750 | + */ |
|
| 1751 | + protected function _generate_payment_form_section() |
|
| 1752 | + { |
|
| 1753 | + return new EE_Form_Section_Proper( |
|
| 1754 | + array( |
|
| 1755 | + 'name' => 'txn_admin_payment', |
|
| 1756 | + 'subsections' => array( |
|
| 1757 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1758 | + array( |
|
| 1759 | + 'default' => 0, |
|
| 1760 | + 'required' => false, |
|
| 1761 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1762 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1763 | + ) |
|
| 1764 | + ), |
|
| 1765 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1766 | + array( |
|
| 1767 | + 'default' => 0, |
|
| 1768 | + 'required' => true, |
|
| 1769 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1770 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1771 | + ) |
|
| 1772 | + ), |
|
| 1773 | + 'type' => new EE_Text_Input( |
|
| 1774 | + array( |
|
| 1775 | + 'default' => 1, |
|
| 1776 | + 'required' => true, |
|
| 1777 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1778 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1779 | + ) |
|
| 1780 | + ), |
|
| 1781 | + 'amount' => new EE_Text_Input( |
|
| 1782 | + array( |
|
| 1783 | + 'default' => 0, |
|
| 1784 | + 'required' => true, |
|
| 1785 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1786 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1787 | + ) |
|
| 1788 | + ), |
|
| 1789 | + 'status' => new EE_Text_Input( |
|
| 1790 | + array( |
|
| 1791 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1792 | + 'required' => true, |
|
| 1793 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1794 | + ) |
|
| 1795 | + ), |
|
| 1796 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1797 | + array( |
|
| 1798 | + 'default' => 2, |
|
| 1799 | + 'required' => true, |
|
| 1800 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1801 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1802 | + ) |
|
| 1803 | + ), |
|
| 1804 | + 'date' => new EE_Text_Input( |
|
| 1805 | + array( |
|
| 1806 | + 'default' => time(), |
|
| 1807 | + 'required' => true, |
|
| 1808 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1809 | + ) |
|
| 1810 | + ), |
|
| 1811 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1812 | + array( |
|
| 1813 | + 'default' => '', |
|
| 1814 | + 'required' => false, |
|
| 1815 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1816 | + 'validation_strategies' => array( |
|
| 1817 | + new EE_Max_Length_Validation_Strategy( |
|
| 1818 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1819 | + 100 |
|
| 1820 | + ), |
|
| 1821 | + ), |
|
| 1822 | + ) |
|
| 1823 | + ), |
|
| 1824 | + 'po_number' => new EE_Text_Input( |
|
| 1825 | + array( |
|
| 1826 | + 'default' => '', |
|
| 1827 | + 'required' => false, |
|
| 1828 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1829 | + 'validation_strategies' => array( |
|
| 1830 | + new EE_Max_Length_Validation_Strategy( |
|
| 1831 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1832 | + 100 |
|
| 1833 | + ), |
|
| 1834 | + ), |
|
| 1835 | + ) |
|
| 1836 | + ), |
|
| 1837 | + 'accounting' => new EE_Text_Input( |
|
| 1838 | + array( |
|
| 1839 | + 'default' => '', |
|
| 1840 | + 'required' => false, |
|
| 1841 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1842 | + 'validation_strategies' => array( |
|
| 1843 | + new EE_Max_Length_Validation_Strategy( |
|
| 1844 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1845 | + 100 |
|
| 1846 | + ), |
|
| 1847 | + ), |
|
| 1848 | + ) |
|
| 1849 | + ), |
|
| 1850 | + ), |
|
| 1851 | + ) |
|
| 1852 | + ); |
|
| 1853 | + } |
|
| 1854 | + |
|
| 1855 | + |
|
| 1856 | + /** |
|
| 1857 | + * _create_payment_from_request_data |
|
| 1858 | + * |
|
| 1859 | + * @param array $valid_data |
|
| 1860 | + * @return EE_Payment |
|
| 1861 | + * @throws EE_Error |
|
| 1862 | + * @throws InvalidArgumentException |
|
| 1863 | + * @throws InvalidDataTypeException |
|
| 1864 | + * @throws InvalidInterfaceException |
|
| 1865 | + * @throws ReflectionException |
|
| 1866 | + */ |
|
| 1867 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1868 | + { |
|
| 1869 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1870 | + // get payment amount |
|
| 1871 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1872 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1873 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1874 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1875 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1876 | + $date = $valid_data['date'] |
|
| 1877 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1878 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1879 | + $payment = EE_Payment::new_instance( |
|
| 1880 | + array( |
|
| 1881 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1882 | + 'STS_ID' => $valid_data['status'], |
|
| 1883 | + 'PAY_timestamp' => $date, |
|
| 1884 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1885 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1886 | + 'PAY_amount' => $amount, |
|
| 1887 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1888 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1889 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1890 | + 'PAY_details' => $valid_data, |
|
| 1891 | + 'PAY_ID' => $PAY_ID, |
|
| 1892 | + ), |
|
| 1893 | + '', |
|
| 1894 | + array('Y-m-d', 'g:i a') |
|
| 1895 | + ); |
|
| 1896 | + |
|
| 1897 | + if (! $payment->save()) { |
|
| 1898 | + EE_Error::add_error( |
|
| 1899 | + sprintf( |
|
| 1900 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1901 | + $payment->ID() |
|
| 1902 | + ), |
|
| 1903 | + __FILE__, |
|
| 1904 | + __FUNCTION__, |
|
| 1905 | + __LINE__ |
|
| 1906 | + ); |
|
| 1907 | + } |
|
| 1908 | + |
|
| 1909 | + return $payment; |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + |
|
| 1913 | + /** |
|
| 1914 | + * _process_transaction_payments |
|
| 1915 | + * |
|
| 1916 | + * @param \EE_Transaction $transaction |
|
| 1917 | + * @return void |
|
| 1918 | + * @throws EE_Error |
|
| 1919 | + * @throws InvalidArgumentException |
|
| 1920 | + * @throws ReflectionException |
|
| 1921 | + * @throws InvalidDataTypeException |
|
| 1922 | + * @throws InvalidInterfaceException |
|
| 1923 | + */ |
|
| 1924 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1925 | + { |
|
| 1926 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1927 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1928 | + // update the transaction with this payment |
|
| 1929 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1930 | + EE_Error::add_success( |
|
| 1931 | + esc_html__( |
|
| 1932 | + 'The payment has been processed successfully.', |
|
| 1933 | + 'event_espresso' |
|
| 1934 | + ), |
|
| 1935 | + __FILE__, |
|
| 1936 | + __FUNCTION__, |
|
| 1937 | + __LINE__ |
|
| 1938 | + ); |
|
| 1939 | + } else { |
|
| 1940 | + EE_Error::add_error( |
|
| 1941 | + esc_html__( |
|
| 1942 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1943 | + 'event_espresso' |
|
| 1944 | + ), |
|
| 1945 | + __FILE__, |
|
| 1946 | + __FUNCTION__, |
|
| 1947 | + __LINE__ |
|
| 1948 | + ); |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + |
|
| 1953 | + /** |
|
| 1954 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1955 | + * returns a list of registration IDs that the payment will apply to |
|
| 1956 | + * |
|
| 1957 | + * @param \EE_Payment $payment |
|
| 1958 | + * @return array |
|
| 1959 | + * @throws EE_Error |
|
| 1960 | + * @throws InvalidArgumentException |
|
| 1961 | + * @throws InvalidDataTypeException |
|
| 1962 | + * @throws InvalidInterfaceException |
|
| 1963 | + * @throws ReflectionException |
|
| 1964 | + */ |
|
| 1965 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1966 | + { |
|
| 1967 | + $REG_IDs = array(); |
|
| 1968 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1969 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1970 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1971 | + } |
|
| 1972 | + // nothing specified ? then get all reg IDs |
|
| 1973 | + if (empty($REG_IDs)) { |
|
| 1974 | + $registrations = $payment->transaction()->registrations(); |
|
| 1975 | + $REG_IDs = ! empty($registrations) |
|
| 1976 | + ? array_keys($registrations) |
|
| 1977 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1978 | + } |
|
| 1979 | + |
|
| 1980 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1981 | + return array_map('intval', $REG_IDs); |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + |
|
| 1985 | + /** |
|
| 1986 | + * @return array |
|
| 1987 | + */ |
|
| 1988 | + public function existing_reg_payment_REG_IDs() |
|
| 1989 | + { |
|
| 1990 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1991 | + } |
|
| 1992 | + |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1996 | + */ |
|
| 1997 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1998 | + { |
|
| 1999 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 2000 | + } |
|
| 2001 | + |
|
| 2002 | + |
|
| 2003 | + /** |
|
| 2004 | + * _get_existing_reg_payment_REG_IDs |
|
| 2005 | + * returns a list of registration IDs that the payment is currently related to |
|
| 2006 | + * as recorded in the database |
|
| 2007 | + * |
|
| 2008 | + * @param \EE_Payment $payment |
|
| 2009 | + * @return array |
|
| 2010 | + * @throws EE_Error |
|
| 2011 | + * @throws InvalidArgumentException |
|
| 2012 | + * @throws InvalidDataTypeException |
|
| 2013 | + * @throws InvalidInterfaceException |
|
| 2014 | + * @throws ReflectionException |
|
| 2015 | + */ |
|
| 2016 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2017 | + { |
|
| 2018 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2019 | + // let's get any existing reg payment records for this payment |
|
| 2020 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2021 | + // but we only want the REG IDs, so grab the array keys |
|
| 2022 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2023 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2024 | + : array(); |
|
| 2025 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2026 | + } |
|
| 2027 | + |
|
| 2028 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 2029 | + } |
|
| 2030 | + |
|
| 2031 | + |
|
| 2032 | + /** |
|
| 2033 | + * _remove_existing_registration_payments |
|
| 2034 | + * this calculates the difference between existing relations |
|
| 2035 | + * to the supplied payment and the new list registration IDs, |
|
| 2036 | + * removes any related registrations that no longer apply, |
|
| 2037 | + * and then updates the registration paid fields |
|
| 2038 | + * |
|
| 2039 | + * @param \EE_Payment $payment |
|
| 2040 | + * @param int $PAY_ID |
|
| 2041 | + * @return bool; |
|
| 2042 | + * @throws EE_Error |
|
| 2043 | + * @throws InvalidArgumentException |
|
| 2044 | + * @throws ReflectionException |
|
| 2045 | + * @throws InvalidDataTypeException |
|
| 2046 | + * @throws InvalidInterfaceException |
|
| 2047 | + */ |
|
| 2048 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2049 | + { |
|
| 2050 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 2051 | + if (absint($PAY_ID) === 0) { |
|
| 2052 | + return false; |
|
| 2053 | + } |
|
| 2054 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2055 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2056 | + return false; |
|
| 2057 | + } |
|
| 2058 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2059 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2060 | + |
|
| 2061 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2062 | + $payment, |
|
| 2063 | + array( |
|
| 2064 | + array( |
|
| 2065 | + 'PAY_ID' => $payment->ID(), |
|
| 2066 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2067 | + ), |
|
| 2068 | + ) |
|
| 2069 | + ); |
|
| 2070 | + } |
|
| 2071 | + |
|
| 2072 | + |
|
| 2073 | + /** |
|
| 2074 | + * _update_registration_payments |
|
| 2075 | + * this applies the payments to the selected registrations |
|
| 2076 | + * but only if they have not already been paid for |
|
| 2077 | + * |
|
| 2078 | + * @param EE_Transaction $transaction |
|
| 2079 | + * @param \EE_Payment $payment |
|
| 2080 | + * @param array $REG_IDs |
|
| 2081 | + * @return void |
|
| 2082 | + * @throws EE_Error |
|
| 2083 | + * @throws InvalidArgumentException |
|
| 2084 | + * @throws ReflectionException |
|
| 2085 | + * @throws RuntimeException |
|
| 2086 | + * @throws InvalidDataTypeException |
|
| 2087 | + * @throws InvalidInterfaceException |
|
| 2088 | + */ |
|
| 2089 | + protected function _update_registration_payments( |
|
| 2090 | + EE_Transaction $transaction, |
|
| 2091 | + EE_Payment $payment, |
|
| 2092 | + $REG_IDs = array() |
|
| 2093 | + ) { |
|
| 2094 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2095 | + // so let's do that using our set of REG_IDs from the form |
|
| 2096 | + $registration_query_where_params = array( |
|
| 2097 | + 'REG_ID' => array('IN', $REG_IDs), |
|
| 2098 | + ); |
|
| 2099 | + // but add in some conditions regarding payment, |
|
| 2100 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2101 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2102 | + if (! $payment->is_a_refund()) { |
|
| 2103 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2104 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2105 | + } |
|
| 2106 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2107 | + if (! empty($registrations)) { |
|
| 2108 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2109 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2110 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2111 | + } |
|
| 2112 | + } |
|
| 2113 | + |
|
| 2114 | + |
|
| 2115 | + /** |
|
| 2116 | + * _process_registration_status_change |
|
| 2117 | + * This processes requested registration status changes for all the registrations |
|
| 2118 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2119 | + * |
|
| 2120 | + * @param EE_Transaction $transaction |
|
| 2121 | + * @param array $REG_IDs |
|
| 2122 | + * @return bool |
|
| 2123 | + * @throws EE_Error |
|
| 2124 | + * @throws InvalidArgumentException |
|
| 2125 | + * @throws ReflectionException |
|
| 2126 | + * @throws InvalidDataTypeException |
|
| 2127 | + * @throws InvalidInterfaceException |
|
| 2128 | + */ |
|
| 2129 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2130 | + { |
|
| 2131 | + // first if there is no change in status then we get out. |
|
| 2132 | + if ( |
|
| 2133 | + ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2134 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2135 | + ) { |
|
| 2136 | + // no error message, no change requested, just nothing to do man. |
|
| 2137 | + return false; |
|
| 2138 | + } |
|
| 2139 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2140 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2141 | + |
|
| 2142 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2143 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 2144 | + $transaction, |
|
| 2145 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2146 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2147 | + ); |
|
| 2148 | + } |
|
| 2149 | + |
|
| 2150 | + |
|
| 2151 | + /** |
|
| 2152 | + * _build_payment_json_response |
|
| 2153 | + * |
|
| 2154 | + * @access public |
|
| 2155 | + * @param \EE_Payment $payment |
|
| 2156 | + * @param array $REG_IDs |
|
| 2157 | + * @param bool | null $delete_txn_reg_status_change |
|
| 2158 | + * @return array |
|
| 2159 | + * @throws EE_Error |
|
| 2160 | + * @throws InvalidArgumentException |
|
| 2161 | + * @throws InvalidDataTypeException |
|
| 2162 | + * @throws InvalidInterfaceException |
|
| 2163 | + * @throws ReflectionException |
|
| 2164 | + */ |
|
| 2165 | + protected function _build_payment_json_response( |
|
| 2166 | + EE_Payment $payment, |
|
| 2167 | + $REG_IDs = array(), |
|
| 2168 | + $delete_txn_reg_status_change = null |
|
| 2169 | + ) { |
|
| 2170 | + // was the payment deleted ? |
|
| 2171 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 2172 | + return array( |
|
| 2173 | + 'PAY_ID' => $payment->ID(), |
|
| 2174 | + 'amount' => $payment->amount(), |
|
| 2175 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2176 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2177 | + 'pay_status' => $payment->STS_ID(), |
|
| 2178 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2179 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2180 | + ); |
|
| 2181 | + } else { |
|
| 2182 | + $this->_get_payment_status_array(); |
|
| 2183 | + |
|
| 2184 | + return array( |
|
| 2185 | + 'amount' => $payment->amount(), |
|
| 2186 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2187 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2188 | + 'pay_status' => $payment->STS_ID(), |
|
| 2189 | + 'PAY_ID' => $payment->ID(), |
|
| 2190 | + 'STS_ID' => $payment->STS_ID(), |
|
| 2191 | + 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2192 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2193 | + 'method' => strtoupper($payment->source()), |
|
| 2194 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2195 | + 'gateway' => $payment->payment_method() |
|
| 2196 | + ? $payment->payment_method()->admin_name() |
|
| 2197 | + : esc_html__('Unknown', 'event_espresso'), |
|
| 2198 | + 'gateway_response' => $payment->gateway_response(), |
|
| 2199 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2200 | + 'po_number' => $payment->po_number(), |
|
| 2201 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 2202 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2203 | + ); |
|
| 2204 | + } |
|
| 2205 | + } |
|
| 2206 | + |
|
| 2207 | + |
|
| 2208 | + /** |
|
| 2209 | + * delete_payment |
|
| 2210 | + * delete a payment or refund made towards a transaction |
|
| 2211 | + * |
|
| 2212 | + * @access public |
|
| 2213 | + * @return void |
|
| 2214 | + * @throws EE_Error |
|
| 2215 | + * @throws InvalidArgumentException |
|
| 2216 | + * @throws ReflectionException |
|
| 2217 | + * @throws InvalidDataTypeException |
|
| 2218 | + * @throws InvalidInterfaceException |
|
| 2219 | + */ |
|
| 2220 | + public function delete_payment() |
|
| 2221 | + { |
|
| 2222 | + $json_response_data = array('return_data' => false); |
|
| 2223 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2224 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2225 | + : 0; |
|
| 2226 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2227 | + 'ee_delete_payments', |
|
| 2228 | + 'delete_payment_from_registration_details' |
|
| 2229 | + ); |
|
| 2230 | + if ($PAY_ID && $can_delete) { |
|
| 2231 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2232 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2233 | + : false; |
|
| 2234 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2235 | + if ($payment instanceof EE_Payment) { |
|
| 2236 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2237 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2238 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2239 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2240 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2241 | + $payment, |
|
| 2242 | + $REG_IDs, |
|
| 2243 | + $delete_txn_reg_status_change |
|
| 2244 | + ); |
|
| 2245 | + if ($delete_txn_reg_status_change) { |
|
| 2246 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2247 | + // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2248 | + // $_REQUEST global because that's how messages will be looking for it. |
|
| 2249 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2250 | + $this->_maybe_send_notifications(); |
|
| 2251 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2252 | + } |
|
| 2253 | + } |
|
| 2254 | + } else { |
|
| 2255 | + EE_Error::add_error( |
|
| 2256 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2257 | + __FILE__, |
|
| 2258 | + __FUNCTION__, |
|
| 2259 | + __LINE__ |
|
| 2260 | + ); |
|
| 2261 | + } |
|
| 2262 | + } elseif ($can_delete) { |
|
| 2263 | + EE_Error::add_error( |
|
| 2264 | + esc_html__( |
|
| 2265 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2266 | + 'event_espresso' |
|
| 2267 | + ), |
|
| 2268 | + __FILE__, |
|
| 2269 | + __FUNCTION__, |
|
| 2270 | + __LINE__ |
|
| 2271 | + ); |
|
| 2272 | + } else { |
|
| 2273 | + EE_Error::add_error( |
|
| 2274 | + esc_html__( |
|
| 2275 | + 'You do not have access to delete a payment.', |
|
| 2276 | + 'event_espresso' |
|
| 2277 | + ), |
|
| 2278 | + __FILE__, |
|
| 2279 | + __FUNCTION__, |
|
| 2280 | + __LINE__ |
|
| 2281 | + ); |
|
| 2282 | + } |
|
| 2283 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 2284 | + $this->_template_args = array( |
|
| 2285 | + 'data' => $json_response_data, |
|
| 2286 | + 'success' => $notices['success'], |
|
| 2287 | + 'error' => $notices['errors'], |
|
| 2288 | + 'attention' => $notices['attention'], |
|
| 2289 | + ); |
|
| 2290 | + $this->_return_json(); |
|
| 2291 | + } |
|
| 2292 | + |
|
| 2293 | + |
|
| 2294 | + /** |
|
| 2295 | + * _registration_payment_data_array |
|
| 2296 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2297 | + * |
|
| 2298 | + * @access protected |
|
| 2299 | + * @param array $REG_IDs |
|
| 2300 | + * @return array |
|
| 2301 | + * @throws EE_Error |
|
| 2302 | + * @throws InvalidArgumentException |
|
| 2303 | + * @throws InvalidDataTypeException |
|
| 2304 | + * @throws InvalidInterfaceException |
|
| 2305 | + * @throws ReflectionException |
|
| 2306 | + */ |
|
| 2307 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 2308 | + { |
|
| 2309 | + $registration_payment_data = array(); |
|
| 2310 | + // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2311 | + if (! empty($REG_IDs)) { |
|
| 2312 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2313 | + foreach ($registrations as $registration) { |
|
| 2314 | + if ($registration instanceof EE_Registration) { |
|
| 2315 | + $registration_payment_data[ $registration->ID() ] = array( |
|
| 2316 | + 'paid' => $registration->pretty_paid(), |
|
| 2317 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2318 | + ); |
|
| 2319 | + } |
|
| 2320 | + } |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + return $registration_payment_data; |
|
| 2324 | + } |
|
| 2325 | + |
|
| 2326 | + |
|
| 2327 | + /** |
|
| 2328 | + * _maybe_send_notifications |
|
| 2329 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2330 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 2331 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2332 | + * |
|
| 2333 | + * @access protected |
|
| 2334 | + * @param \EE_Payment | null $payment |
|
| 2335 | + */ |
|
| 2336 | + protected function _maybe_send_notifications($payment = null) |
|
| 2337 | + { |
|
| 2338 | + switch ($payment instanceof EE_Payment) { |
|
| 2339 | + // payment notifications |
|
| 2340 | + case true: |
|
| 2341 | + if ( |
|
| 2342 | + isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2343 | + && filter_var( |
|
| 2344 | + $this->_req_data['txn_payments']['send_notifications'], |
|
| 2345 | + FILTER_VALIDATE_BOOLEAN |
|
| 2346 | + ) |
|
| 2347 | + ) { |
|
| 2348 | + $this->_process_payment_notification($payment); |
|
| 2349 | + } |
|
| 2350 | + break; |
|
| 2351 | + // registration notifications |
|
| 2352 | + case false: |
|
| 2353 | + if ( |
|
| 2354 | + isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2355 | + && filter_var( |
|
| 2356 | + $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2357 | + FILTER_VALIDATE_BOOLEAN |
|
| 2358 | + ) |
|
| 2359 | + ) { |
|
| 2360 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2361 | + } |
|
| 2362 | + break; |
|
| 2363 | + } |
|
| 2364 | + } |
|
| 2365 | + |
|
| 2366 | + |
|
| 2367 | + /** |
|
| 2368 | + * _send_payment_reminder |
|
| 2369 | + * generates HTML for the View Transaction Details Admin page |
|
| 2370 | + * |
|
| 2371 | + * @access protected |
|
| 2372 | + * @return void |
|
| 2373 | + * @throws EE_Error |
|
| 2374 | + * @throws InvalidArgumentException |
|
| 2375 | + * @throws InvalidDataTypeException |
|
| 2376 | + * @throws InvalidInterfaceException |
|
| 2377 | + */ |
|
| 2378 | + protected function _send_payment_reminder() |
|
| 2379 | + { |
|
| 2380 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2381 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2382 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2383 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2384 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2385 | + ) : array(); |
|
| 2386 | + do_action( |
|
| 2387 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2388 | + $transaction |
|
| 2389 | + ); |
|
| 2390 | + $this->_redirect_after_action( |
|
| 2391 | + false, |
|
| 2392 | + esc_html__('payment reminder', 'event_espresso'), |
|
| 2393 | + esc_html__('sent', 'event_espresso'), |
|
| 2394 | + $query_args, |
|
| 2395 | + true |
|
| 2396 | + ); |
|
| 2397 | + } |
|
| 2398 | + |
|
| 2399 | + |
|
| 2400 | + /** |
|
| 2401 | + * get_transactions |
|
| 2402 | + * get transactions for given parameters (used by list table) |
|
| 2403 | + * |
|
| 2404 | + * @param int $perpage how many transactions displayed per page |
|
| 2405 | + * @param boolean $count return the count or objects |
|
| 2406 | + * @param string $view |
|
| 2407 | + * @return mixed int = count || array of transaction objects |
|
| 2408 | + * @throws EE_Error |
|
| 2409 | + * @throws InvalidArgumentException |
|
| 2410 | + * @throws InvalidDataTypeException |
|
| 2411 | + * @throws InvalidInterfaceException |
|
| 2412 | + */ |
|
| 2413 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 2414 | + { |
|
| 2415 | + |
|
| 2416 | + $TXN = EEM_Transaction::instance(); |
|
| 2417 | + |
|
| 2418 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2419 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2420 | + : date( |
|
| 2421 | + 'm/d/Y', |
|
| 2422 | + strtotime('-10 year') |
|
| 2423 | + ); |
|
| 2424 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2425 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2426 | + : date('m/d/Y'); |
|
| 2427 | + |
|
| 2428 | + // make sure our timestamps start and end right at the boundaries for each day |
|
| 2429 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2430 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2431 | + |
|
| 2432 | + |
|
| 2433 | + // convert to timestamps |
|
| 2434 | + $start_date = strtotime($start_date); |
|
| 2435 | + $end_date = strtotime($end_date); |
|
| 2436 | + |
|
| 2437 | + // makes sure start date is the lowest value and vice versa |
|
| 2438 | + $start_date = min($start_date, $end_date); |
|
| 2439 | + $end_date = max($start_date, $end_date); |
|
| 2440 | + |
|
| 2441 | + // convert to correct format for query |
|
| 2442 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2443 | + 'TXN_timestamp', |
|
| 2444 | + date('Y-m-d H:i:s', $start_date), |
|
| 2445 | + 'Y-m-d H:i:s' |
|
| 2446 | + ); |
|
| 2447 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2448 | + 'TXN_timestamp', |
|
| 2449 | + date('Y-m-d H:i:s', $end_date), |
|
| 2450 | + 'Y-m-d H:i:s' |
|
| 2451 | + ); |
|
| 2452 | + |
|
| 2453 | + |
|
| 2454 | + // set orderby |
|
| 2455 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2456 | + |
|
| 2457 | + switch ($this->_req_data['orderby']) { |
|
| 2458 | + case 'TXN_ID': |
|
| 2459 | + $orderby = 'TXN_ID'; |
|
| 2460 | + break; |
|
| 2461 | + case 'ATT_fname': |
|
| 2462 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2463 | + break; |
|
| 2464 | + case 'event_name': |
|
| 2465 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 2466 | + break; |
|
| 2467 | + default: // 'TXN_timestamp' |
|
| 2468 | + $orderby = 'TXN_timestamp'; |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2472 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2473 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2474 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2475 | + |
|
| 2476 | + $offset = ($current_page - 1) * $per_page; |
|
| 2477 | + $limit = array($offset, $per_page); |
|
| 2478 | + |
|
| 2479 | + $_where = array( |
|
| 2480 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2481 | + 'Registration.REG_count' => 1, |
|
| 2482 | + ); |
|
| 2483 | + |
|
| 2484 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 2485 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2486 | + } |
|
| 2487 | + |
|
| 2488 | + if (isset($this->_req_data['s'])) { |
|
| 2489 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2490 | + $_where['OR'] = array( |
|
| 2491 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2492 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2493 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2494 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2495 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2496 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2497 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2498 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2499 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2500 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2501 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2502 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2503 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2504 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2505 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2506 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2507 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2508 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2509 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2510 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2511 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2512 | + ); |
|
| 2513 | + } |
|
| 2514 | + |
|
| 2515 | + // failed transactions |
|
| 2516 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2517 | + || ($count && $view === 'failed'); |
|
| 2518 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2519 | + || ($count && $view === 'abandoned'); |
|
| 2520 | + $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2521 | + || ($count && $view === 'incomplete'); |
|
| 2522 | + |
|
| 2523 | + if ($failed) { |
|
| 2524 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2525 | + } elseif ($abandoned) { |
|
| 2526 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2527 | + } elseif ($incomplete) { |
|
| 2528 | + $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2529 | + } else { |
|
| 2530 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2531 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + $query_params = apply_filters( |
|
| 2535 | + 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2536 | + array( |
|
| 2537 | + $_where, |
|
| 2538 | + 'order_by' => array($orderby => $sort), |
|
| 2539 | + 'limit' => $limit, |
|
| 2540 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2541 | + ), |
|
| 2542 | + $this->_req_data, |
|
| 2543 | + $view, |
|
| 2544 | + $count |
|
| 2545 | + ); |
|
| 2546 | + |
|
| 2547 | + $transactions = $count |
|
| 2548 | + ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2549 | + : $TXN->get_all($query_params); |
|
| 2550 | + |
|
| 2551 | + return $transactions; |
|
| 2552 | + } |
|
| 2553 | + |
|
| 2554 | + |
|
| 2555 | + /** |
|
| 2556 | + * @since 4.9.79.p |
|
| 2557 | + * @throws EE_Error |
|
| 2558 | + * @throws InvalidArgumentException |
|
| 2559 | + * @throws InvalidDataTypeException |
|
| 2560 | + * @throws InvalidInterfaceException |
|
| 2561 | + * @throws ReflectionException |
|
| 2562 | + * @throws RuntimeException |
|
| 2563 | + */ |
|
| 2564 | + public function recalculateLineItems() |
|
| 2565 | + { |
|
| 2566 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2567 | + /** @var EE_Transaction $transaction */ |
|
| 2568 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2569 | + $total_line_item = $transaction->total_line_item(false); |
|
| 2570 | + $success = $transaction->recalculateLineItems(); |
|
| 2571 | + $this->_redirect_after_action( |
|
| 2572 | + (bool) $success, |
|
| 2573 | + esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2574 | + esc_html__('recalculated', 'event_espresso'), |
|
| 2575 | + isset($this->_req_data['redirect_to']) |
|
| 2576 | + ? array( |
|
| 2577 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2578 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2579 | + ) |
|
| 2580 | + : array(), |
|
| 2581 | + true |
|
| 2582 | + ); |
|
| 2583 | + } |
|
| 2584 | 2584 | } |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | // enqueue style |
| 359 | 359 | wp_register_style( |
| 360 | 360 | 'espresso_txn', |
| 361 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 361 | + TXN_ASSETS_URL.'espresso_transactions_admin.css', |
|
| 362 | 362 | array(), |
| 363 | 363 | EVENT_ESPRESSO_VERSION |
| 364 | 364 | ); |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | // scripts |
| 367 | 367 | wp_register_script( |
| 368 | 368 | 'espresso_txn', |
| 369 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 369 | + TXN_ASSETS_URL.'espresso_transactions_admin.js', |
|
| 370 | 370 | array( |
| 371 | 371 | 'ee_admin_js', |
| 372 | 372 | 'ee-datepicker', |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | $this->_transaction->verify_abandoned_transaction_status(); |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 498 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 499 | 499 | $error_msg = sprintf( |
| 500 | 500 | esc_html__( |
| 501 | 501 | 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 588 | 588 | array( |
| 589 | 589 | 'overpaid' => array( |
| 590 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 590 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 591 | 591 | 'desc' => EEH_Template::pretty_status( |
| 592 | 592 | EEM_Transaction::overpaid_status_code, |
| 593 | 593 | false, |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | ), |
| 596 | 596 | ), |
| 597 | 597 | 'complete' => array( |
| 598 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 598 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 599 | 599 | 'desc' => EEH_Template::pretty_status( |
| 600 | 600 | EEM_Transaction::complete_status_code, |
| 601 | 601 | false, |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | ), |
| 604 | 604 | ), |
| 605 | 605 | 'incomplete' => array( |
| 606 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 606 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 607 | 607 | 'desc' => EEH_Template::pretty_status( |
| 608 | 608 | EEM_Transaction::incomplete_status_code, |
| 609 | 609 | false, |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | ), |
| 612 | 612 | ), |
| 613 | 613 | 'abandoned' => array( |
| 614 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 614 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 615 | 615 | 'desc' => EEH_Template::pretty_status( |
| 616 | 616 | EEM_Transaction::abandoned_status_code, |
| 617 | 617 | false, |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | ), |
| 620 | 620 | ), |
| 621 | 621 | 'failed' => array( |
| 622 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 622 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 623 | 623 | 'desc' => EEH_Template::pretty_status( |
| 624 | 624 | EEM_Transaction::failed_status_code, |
| 625 | 625 | false, |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | 'Click to Edit event', |
| 669 | 669 | 'event_espresso' |
| 670 | 670 | ) |
| 671 | - . '">' . $event->name() . '</a>', |
|
| 671 | + . '">'.$event->name().'</a>', |
|
| 672 | 672 | '</h3>' |
| 673 | 673 | ) |
| 674 | 674 | : ''; |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | $this->_set_transaction_object(); |
| 704 | 704 | |
| 705 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 705 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 706 | 706 | return; |
| 707 | 707 | } |
| 708 | 708 | $primary_registration = $this->_transaction->primary_registration(); |
@@ -716,9 +716,9 @@ discard block |
||
| 716 | 716 | $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
| 717 | 717 | $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
| 718 | 718 | |
| 719 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 719 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->status_ID()]; |
|
| 720 | 720 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
| 721 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 721 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->status_ID(); |
|
| 722 | 722 | |
| 723 | 723 | $this->_template_args['grand_total'] = $this->_transaction->total(); |
| 724 | 724 | $this->_template_args['total_paid'] = $this->_transaction->paid(); |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | // grab messages at the last second |
| 839 | 839 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 840 | 840 | // path to template |
| 841 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 841 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 842 | 842 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
| 843 | 843 | $template_path, |
| 844 | 844 | $this->_template_args, |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | |
| 868 | 868 | $this->_set_transaction_object(); |
| 869 | 869 | |
| 870 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 870 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 871 | 871 | return; |
| 872 | 872 | } |
| 873 | 873 | add_meta_box( |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | { |
| 924 | 924 | $content = ''; |
| 925 | 925 | $actions = array(); |
| 926 | - if (! $transaction instanceof EE_Transaction) { |
|
| 926 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 927 | 927 | return $content; |
| 928 | 928 | } |
| 929 | 929 | /** @var EE_Registration $primary_registration */ |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | ); |
| 1009 | 1009 | if ($actions) { |
| 1010 | 1010 | $content = '<ul>'; |
| 1011 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1011 | + $content .= '<li>'.implode('</li><li>', $actions).'</li>'; |
|
| 1012 | 1012 | $content .= '</uL>'; |
| 1013 | 1013 | } |
| 1014 | 1014 | return $content; |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | |
| 1070 | 1070 | // process payment details |
| 1071 | 1071 | $payments = $this->_transaction->payments(); |
| 1072 | - if (! empty($payments)) { |
|
| 1072 | + if ( ! empty($payments)) { |
|
| 1073 | 1073 | $this->_template_args['payments'] = $payments; |
| 1074 | 1074 | $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
| 1075 | 1075 | } else { |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
| 1131 | 1131 | ucwords(str_replace('_', ' ', $reg_step)), |
| 1132 | 1132 | date( |
| 1133 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1133 | + get_option('date_format').' '.get_option('time_format'), |
|
| 1134 | 1134 | $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
| 1135 | 1135 | ) |
| 1136 | 1136 | ) |
@@ -1183,7 +1183,7 @@ discard block |
||
| 1183 | 1183 | |
| 1184 | 1184 | // 'espresso_delete_payment_nonce' |
| 1185 | 1185 | |
| 1186 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1186 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1187 | 1187 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1188 | 1188 | } |
| 1189 | 1189 | |
@@ -1215,19 +1215,19 @@ discard block |
||
| 1215 | 1215 | ), |
| 1216 | 1216 | ) |
| 1217 | 1217 | ); |
| 1218 | - if (! empty($reg_payments)) { |
|
| 1218 | + if ( ! empty($reg_payments)) { |
|
| 1219 | 1219 | foreach ($payments as $payment) { |
| 1220 | - if (! $payment instanceof EE_Payment) { |
|
| 1220 | + if ( ! $payment instanceof EE_Payment) { |
|
| 1221 | 1221 | continue; |
| 1222 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1223 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1222 | + } elseif ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1223 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 1224 | 1224 | } |
| 1225 | 1225 | foreach ($reg_payments as $reg_payment) { |
| 1226 | 1226 | if ( |
| 1227 | 1227 | $reg_payment instanceof EE_Registration_Payment |
| 1228 | 1228 | && $reg_payment->payment_ID() === $payment->ID() |
| 1229 | 1229 | ) { |
| 1230 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1230 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | 1233 | } |
@@ -1265,22 +1265,22 @@ discard block |
||
| 1265 | 1265 | ), |
| 1266 | 1266 | ), |
| 1267 | 1267 | ); |
| 1268 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1268 | + $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div( |
|
| 1269 | 1269 | '', |
| 1270 | 1270 | 'txn-admin-apply-payment-to-registrations-dv', |
| 1271 | 1271 | '', |
| 1272 | 1272 | 'clear: both; margin: 1.5em 0 0; display: none;' |
| 1273 | 1273 | ); |
| 1274 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1274 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1275 | 1275 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
| 1276 | 1276 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
| 1277 | 1277 | EEH_HTML::tr( |
| 1278 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1279 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1280 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1281 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1282 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1283 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1278 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
| 1279 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
| 1280 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
| 1281 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
| 1282 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1283 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 1284 | 1284 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
| 1285 | 1285 | ) |
| 1286 | 1286 | ); |
@@ -1295,7 +1295,7 @@ discard block |
||
| 1295 | 1295 | : esc_html__('Unknown Attendee', 'event_espresso'); |
| 1296 | 1296 | $owing = $registration->final_price() - $registration->paid(); |
| 1297 | 1297 | $taxable = $registration->ticket()->taxable() |
| 1298 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1298 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
| 1299 | 1299 | : ''; |
| 1300 | 1300 | $checked = empty($existing_reg_payments) |
| 1301 | 1301 | || in_array($registration->ID(), $existing_reg_payments, true) |
@@ -1303,26 +1303,26 @@ discard block |
||
| 1303 | 1303 | : ''; |
| 1304 | 1304 | $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
| 1305 | 1305 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
| 1306 | - EEH_HTML::td($registration->ID()) . |
|
| 1307 | - EEH_HTML::td($attendee_name) . |
|
| 1306 | + EEH_HTML::td($registration->ID()). |
|
| 1307 | + EEH_HTML::td($attendee_name). |
|
| 1308 | 1308 | EEH_HTML::td( |
| 1309 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1310 | - ) . |
|
| 1311 | - EEH_HTML::td($registration->event_name()) . |
|
| 1312 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1309 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
| 1310 | + ). |
|
| 1311 | + EEH_HTML::td($registration->event_name()). |
|
| 1312 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1313 | 1313 | EEH_HTML::td( |
| 1314 | 1314 | EEH_Template::format_currency($owing), |
| 1315 | 1315 | '', |
| 1316 | 1316 | 'txn-admin-payment-owing-td jst-cntr' |
| 1317 | - ) . |
|
| 1317 | + ). |
|
| 1318 | 1318 | EEH_HTML::td( |
| 1319 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1319 | + '<input type="checkbox" value="'.$registration->ID() |
|
| 1320 | 1320 | . '" name="txn_admin_payment[registrations]"' |
| 1321 | - . $checked . $disabled . '>', |
|
| 1321 | + . $checked.$disabled.'>', |
|
| 1322 | 1322 | '', |
| 1323 | 1323 | 'jst-cntr' |
| 1324 | 1324 | ), |
| 1325 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1325 | + 'apply-payment-registration-row-'.$registration->ID() |
|
| 1326 | 1326 | ); |
| 1327 | 1327 | } |
| 1328 | 1328 | } |
@@ -1403,12 +1403,12 @@ discard block |
||
| 1403 | 1403 | array( |
| 1404 | 1404 | 'OR*payment_method_for_payment' => array( |
| 1405 | 1405 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
| 1406 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1406 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'), |
|
| 1407 | 1407 | ), |
| 1408 | 1408 | ), |
| 1409 | 1409 | ); |
| 1410 | 1410 | } else { |
| 1411 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1411 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 1412 | 1412 | } |
| 1413 | 1413 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
| 1414 | 1414 | } |
@@ -1441,7 +1441,7 @@ discard block |
||
| 1441 | 1441 | 'Line_Item', |
| 1442 | 1442 | array(array('LIN_type' => 'line-item')) |
| 1443 | 1443 | ); |
| 1444 | - if (! empty($line_items)) { |
|
| 1444 | + if ( ! empty($line_items)) { |
|
| 1445 | 1445 | foreach ($line_items as $item) { |
| 1446 | 1446 | if ($item instanceof EE_Line_Item) { |
| 1447 | 1447 | switch ($item->OBJ_type()) { |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | $ticket = $item->ticket(); |
| 1452 | 1452 | // right now we're only handling tickets here. |
| 1453 | 1453 | // Cause its expected that only tickets will have attendees right? |
| 1454 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1454 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1455 | 1455 | break; |
| 1456 | 1456 | } |
| 1457 | 1457 | try { |
@@ -1460,45 +1460,45 @@ discard block |
||
| 1460 | 1460 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1461 | 1461 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
| 1462 | 1462 | } |
| 1463 | - $event_name .= ' - ' . $item->name(); |
|
| 1463 | + $event_name .= ' - '.$item->name(); |
|
| 1464 | 1464 | $ticket_price = EEH_Template::format_currency($item->unit_price()); |
| 1465 | 1465 | // now get all of the registrations for this transaction that use this ticket |
| 1466 | 1466 | $registrations = $ticket->registrations( |
| 1467 | 1467 | array(array('TXN_ID' => $this->_transaction->ID())) |
| 1468 | 1468 | ); |
| 1469 | 1469 | foreach ($registrations as $registration) { |
| 1470 | - if (! $registration instanceof EE_Registration) { |
|
| 1470 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1471 | 1471 | break; |
| 1472 | 1472 | } |
| 1473 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1473 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
| 1474 | 1474 | = $registration->status_ID(); |
| 1475 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1475 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
| 1476 | 1476 | = $registration->count(); |
| 1477 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1477 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
| 1478 | 1478 | = $event_name; |
| 1479 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1479 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
| 1480 | 1480 | = $ticket_price; |
| 1481 | 1481 | // attendee info |
| 1482 | 1482 | $attendee = $registration->get_first_related('Attendee'); |
| 1483 | 1483 | if ($attendee instanceof EE_Attendee) { |
| 1484 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1484 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
| 1485 | 1485 | = $attendee->ID(); |
| 1486 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1486 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
| 1487 | 1487 | = $attendee->full_name(); |
| 1488 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1489 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1488 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
| 1489 | + = '<a href="mailto:'.$attendee->email().'?subject='.$event_name |
|
| 1490 | 1490 | . esc_html__( |
| 1491 | 1491 | ' Event', |
| 1492 | 1492 | 'event_espresso' |
| 1493 | 1493 | ) |
| 1494 | - . '">' . $attendee->email() . '</a>'; |
|
| 1495 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1494 | + . '">'.$attendee->email().'</a>'; |
|
| 1495 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
| 1496 | 1496 | = EEH_Address::format($attendee, 'inline', false, false); |
| 1497 | 1497 | } else { |
| 1498 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1499 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1500 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1501 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1498 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1499 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1500 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1501 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1502 | 1502 | } |
| 1503 | 1503 | } |
| 1504 | 1504 | break; |
@@ -1514,7 +1514,7 @@ discard block |
||
| 1514 | 1514 | TXN_ADMIN_URL |
| 1515 | 1515 | ); |
| 1516 | 1516 | echo EEH_Template::display_template( |
| 1517 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1517 | + TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1518 | 1518 | $this->_template_args, |
| 1519 | 1519 | true |
| 1520 | 1520 | ); |
@@ -1549,7 +1549,7 @@ discard block |
||
| 1549 | 1549 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
| 1550 | 1550 | ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
| 1551 | 1551 | : null; |
| 1552 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1552 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1553 | 1553 | $this->_template_args['no_attendee_message'] = esc_html__( |
| 1554 | 1554 | 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
| 1555 | 1555 | 'event_espresso' |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | // get formatted address for registrant |
| 1572 | 1572 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
| 1573 | 1573 | echo EEH_Template::display_template( |
| 1574 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1574 | + TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1575 | 1575 | $this->_template_args, |
| 1576 | 1576 | true |
| 1577 | 1577 | ); |
@@ -1596,7 +1596,7 @@ discard block |
||
| 1596 | 1596 | TXN_ADMIN_URL |
| 1597 | 1597 | ); |
| 1598 | 1598 | |
| 1599 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1599 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1600 | 1600 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1601 | 1601 | } |
| 1602 | 1602 | |
@@ -1622,7 +1622,7 @@ discard block |
||
| 1622 | 1622 | 'ee_edit_payments', |
| 1623 | 1623 | 'apply_payment_or_refund_from_registration_details' |
| 1624 | 1624 | ); |
| 1625 | - if (! empty($valid_data) && $has_access) { |
|
| 1625 | + if ( ! empty($valid_data) && $has_access) { |
|
| 1626 | 1626 | $PAY_ID = $valid_data['PAY_ID']; |
| 1627 | 1627 | // save the new payment |
| 1628 | 1628 | $payment = $this->_create_payment_from_request_data($valid_data); |
@@ -1635,7 +1635,7 @@ discard block |
||
| 1635 | 1635 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
| 1636 | 1636 | $this->_remove_existing_registration_payments($payment, $PAY_ID); |
| 1637 | 1637 | // apply payment to registrations (if applicable) |
| 1638 | - if (! empty($REG_IDs)) { |
|
| 1638 | + if ( ! empty($REG_IDs)) { |
|
| 1639 | 1639 | $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
| 1640 | 1640 | $this->_maybe_send_notifications(); |
| 1641 | 1641 | // now process status changes for the same registrations |
@@ -1706,14 +1706,14 @@ discard block |
||
| 1706 | 1706 | */ |
| 1707 | 1707 | protected function _validate_payment_request_data() |
| 1708 | 1708 | { |
| 1709 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1709 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1710 | 1710 | return array(); |
| 1711 | 1711 | } |
| 1712 | 1712 | $payment_form = $this->_generate_payment_form_section(); |
| 1713 | 1713 | try { |
| 1714 | 1714 | if ($payment_form->was_submitted()) { |
| 1715 | 1715 | $payment_form->receive_form_submission(); |
| 1716 | - if (! $payment_form->is_valid()) { |
|
| 1716 | + if ( ! $payment_form->is_valid()) { |
|
| 1717 | 1717 | $submission_error_messages = array(); |
| 1718 | 1718 | foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
| 1719 | 1719 | if ($validation_error instanceof EE_Validation_Error) { |
@@ -1894,7 +1894,7 @@ discard block |
||
| 1894 | 1894 | array('Y-m-d', 'g:i a') |
| 1895 | 1895 | ); |
| 1896 | 1896 | |
| 1897 | - if (! $payment->save()) { |
|
| 1897 | + if ( ! $payment->save()) { |
|
| 1898 | 1898 | EE_Error::add_error( |
| 1899 | 1899 | sprintf( |
| 1900 | 1900 | esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
@@ -2099,12 +2099,12 @@ discard block |
||
| 2099 | 2099 | // but add in some conditions regarding payment, |
| 2100 | 2100 | // so that we don't apply payments to registrations that are free or have already been paid for |
| 2101 | 2101 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
| 2102 | - if (! $payment->is_a_refund()) { |
|
| 2102 | + if ( ! $payment->is_a_refund()) { |
|
| 2103 | 2103 | $registration_query_where_params['REG_final_price'] = array('!=', 0); |
| 2104 | 2104 | $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
| 2105 | 2105 | } |
| 2106 | 2106 | $registrations = $transaction->registrations(array($registration_query_where_params)); |
| 2107 | - if (! empty($registrations)) { |
|
| 2107 | + if ( ! empty($registrations)) { |
|
| 2108 | 2108 | /** @type EE_Payment_Processor $payment_processor */ |
| 2109 | 2109 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
| 2110 | 2110 | $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
@@ -2188,7 +2188,7 @@ discard block |
||
| 2188 | 2188 | 'pay_status' => $payment->STS_ID(), |
| 2189 | 2189 | 'PAY_ID' => $payment->ID(), |
| 2190 | 2190 | 'STS_ID' => $payment->STS_ID(), |
| 2191 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2191 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 2192 | 2192 | 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
| 2193 | 2193 | 'method' => strtoupper($payment->source()), |
| 2194 | 2194 | 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
@@ -2308,11 +2308,11 @@ discard block |
||
| 2308 | 2308 | { |
| 2309 | 2309 | $registration_payment_data = array(); |
| 2310 | 2310 | // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
| 2311 | - if (! empty($REG_IDs)) { |
|
| 2311 | + if ( ! empty($REG_IDs)) { |
|
| 2312 | 2312 | $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
| 2313 | 2313 | foreach ($registrations as $registration) { |
| 2314 | 2314 | if ($registration instanceof EE_Registration) { |
| 2315 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 2315 | + $registration_payment_data[$registration->ID()] = array( |
|
| 2316 | 2316 | 'paid' => $registration->pretty_paid(), |
| 2317 | 2317 | 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
| 2318 | 2318 | ); |
@@ -2426,8 +2426,8 @@ discard block |
||
| 2426 | 2426 | : date('m/d/Y'); |
| 2427 | 2427 | |
| 2428 | 2428 | // make sure our timestamps start and end right at the boundaries for each day |
| 2429 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2430 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2429 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 2430 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 2431 | 2431 | |
| 2432 | 2432 | |
| 2433 | 2433 | // convert to timestamps |
@@ -2486,7 +2486,7 @@ discard block |
||
| 2486 | 2486 | } |
| 2487 | 2487 | |
| 2488 | 2488 | if (isset($this->_req_data['s'])) { |
| 2489 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2489 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 2490 | 2490 | $_where['OR'] = array( |
| 2491 | 2491 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
| 2492 | 2492 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -2513,11 +2513,11 @@ discard block |
||
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 2515 | 2515 | // failed transactions |
| 2516 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2516 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2517 | 2517 | || ($count && $view === 'failed'); |
| 2518 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2518 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2519 | 2519 | || ($count && $view === 'abandoned'); |
| 2520 | - $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2520 | + $incomplete = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2521 | 2521 | || ($count && $view === 'incomplete'); |
| 2522 | 2522 | |
| 2523 | 2523 | if ($failed) { |
@@ -23,14 +23,14 @@ |
||
| 23 | 23 | class CartFactory |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return EE_Cart |
|
| 28 | - * @throws InvalidArgumentException |
|
| 29 | - * @throws InvalidInterfaceException |
|
| 30 | - * @throws InvalidDataTypeException |
|
| 31 | - */ |
|
| 32 | - public static function getCart() |
|
| 33 | - { |
|
| 34 | - return LoaderFactory::getLoader()->getShared('EE_Cart'); |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * @return EE_Cart |
|
| 28 | + * @throws InvalidArgumentException |
|
| 29 | + * @throws InvalidInterfaceException |
|
| 30 | + * @throws InvalidDataTypeException |
|
| 31 | + */ |
|
| 32 | + public static function getCart() |
|
| 33 | + { |
|
| 34 | + return LoaderFactory::getLoader()->getShared('EE_Cart'); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | * @param string $name |
| 534 | 534 | * @param string $config_class |
| 535 | 535 | * @param EE_Config_Base $config_obj |
| 536 | - * @param array $tests_to_run |
|
| 536 | + * @param integer[] $tests_to_run |
|
| 537 | 537 | * @param bool $display_errors |
| 538 | 538 | * @return bool TRUE on success, FALSE on fail |
| 539 | 539 | */ |
@@ -797,7 +797,7 @@ discard block |
||
| 797 | 797 | * @access public |
| 798 | 798 | * @param string $section |
| 799 | 799 | * @param string $name |
| 800 | - * @param EE_Config_Base|string $config_obj |
|
| 800 | + * @param EE_Config_Base $config_obj |
|
| 801 | 801 | * @param bool $throw_errors |
| 802 | 802 | * @return bool |
| 803 | 803 | */ |
@@ -1764,7 +1764,7 @@ discard block |
||
| 1764 | 1764 | |
| 1765 | 1765 | |
| 1766 | 1766 | /** |
| 1767 | - * @return array |
|
| 1767 | + * @return integer[] |
|
| 1768 | 1768 | */ |
| 1769 | 1769 | public function get_critical_pages_array() |
| 1770 | 1770 | { |
@@ -1779,7 +1779,7 @@ discard block |
||
| 1779 | 1779 | |
| 1780 | 1780 | |
| 1781 | 1781 | /** |
| 1782 | - * @return array |
|
| 1782 | + * @return string[] |
|
| 1783 | 1783 | */ |
| 1784 | 1784 | public function get_critical_pages_shortcodes_array() |
| 1785 | 1785 | { |
@@ -3122,7 +3122,7 @@ discard block |
||
| 3122 | 3122 | * according to max_input_vars |
| 3123 | 3123 | * |
| 3124 | 3124 | * @param int $input_count the count of input vars. |
| 3125 | - * @return array { |
|
| 3125 | + * @return string { |
|
| 3126 | 3126 | * An array that represents whether available space and if no available space the error |
| 3127 | 3127 | * message. |
| 3128 | 3128 | * @type bool $has_space whether more inputs can be added. |
@@ -14,2544 +14,2544 @@ 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 ( |
|
| 574 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 575 | - ) { |
|
| 576 | - if ($display_errors) { |
|
| 577 | - throw new EE_Error( |
|
| 578 | - sprintf( |
|
| 579 | - __( |
|
| 580 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 581 | - 'event_espresso' |
|
| 582 | - ), |
|
| 583 | - $section |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - } |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - break; |
|
| 590 | - // TEST #4 : check that config section name has been set |
|
| 591 | - case 4: |
|
| 592 | - if (empty($name)) { |
|
| 593 | - if ($display_errors) { |
|
| 594 | - throw new EE_Error( |
|
| 595 | - __( |
|
| 596 | - 'No name has been provided for the specific configuration section.', |
|
| 597 | - 'event_espresso' |
|
| 598 | - ) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - return false; |
|
| 602 | - } |
|
| 603 | - break; |
|
| 604 | - // TEST #5 : check that a config class name has been set |
|
| 605 | - case 5: |
|
| 606 | - if (empty($config_class)) { |
|
| 607 | - if ($display_errors) { |
|
| 608 | - throw new EE_Error( |
|
| 609 | - __( |
|
| 610 | - 'No class name has been provided for the specific configuration section.', |
|
| 611 | - 'event_espresso' |
|
| 612 | - ) |
|
| 613 | - ); |
|
| 614 | - } |
|
| 615 | - return false; |
|
| 616 | - } |
|
| 617 | - break; |
|
| 618 | - // TEST #6 : verify config class is accessible |
|
| 619 | - case 6: |
|
| 620 | - if (! class_exists($config_class)) { |
|
| 621 | - if ($display_errors) { |
|
| 622 | - throw new EE_Error( |
|
| 623 | - sprintf( |
|
| 624 | - __( |
|
| 625 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 626 | - 'event_espresso' |
|
| 627 | - ), |
|
| 628 | - $config_class |
|
| 629 | - ) |
|
| 630 | - ); |
|
| 631 | - } |
|
| 632 | - return false; |
|
| 633 | - } |
|
| 634 | - break; |
|
| 635 | - // TEST #7 : check that config has even been set |
|
| 636 | - case 7: |
|
| 637 | - if (! isset($this->{$section}->{$name})) { |
|
| 638 | - if ($display_errors) { |
|
| 639 | - throw new EE_Error( |
|
| 640 | - sprintf( |
|
| 641 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 642 | - $section, |
|
| 643 | - $name |
|
| 644 | - ) |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - return false; |
|
| 648 | - } else { |
|
| 649 | - // and make sure it's not serialized |
|
| 650 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 651 | - } |
|
| 652 | - break; |
|
| 653 | - // TEST #8 : check that config is the requested type |
|
| 654 | - case 8: |
|
| 655 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 656 | - if ($display_errors) { |
|
| 657 | - throw new EE_Error( |
|
| 658 | - sprintf( |
|
| 659 | - __( |
|
| 660 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 661 | - 'event_espresso' |
|
| 662 | - ), |
|
| 663 | - $section, |
|
| 664 | - $name, |
|
| 665 | - $config_class |
|
| 666 | - ) |
|
| 667 | - ); |
|
| 668 | - } |
|
| 669 | - return false; |
|
| 670 | - } |
|
| 671 | - break; |
|
| 672 | - // TEST #9 : verify config object |
|
| 673 | - case 9: |
|
| 674 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 675 | - if ($display_errors) { |
|
| 676 | - throw new EE_Error( |
|
| 677 | - sprintf( |
|
| 678 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 679 | - print_r($config_obj, true) |
|
| 680 | - ) |
|
| 681 | - ); |
|
| 682 | - } |
|
| 683 | - return false; |
|
| 684 | - } |
|
| 685 | - break; |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - } catch (EE_Error $e) { |
|
| 689 | - $e->get_error(); |
|
| 690 | - } |
|
| 691 | - // you have successfully run the gauntlet |
|
| 692 | - return true; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * _generate_config_option_name |
|
| 698 | - * |
|
| 699 | - * @access protected |
|
| 700 | - * @param string $section |
|
| 701 | - * @param string $name |
|
| 702 | - * @return string |
|
| 703 | - */ |
|
| 704 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 705 | - { |
|
| 706 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * _set_config_class |
|
| 712 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 713 | - * |
|
| 714 | - * @access private |
|
| 715 | - * @param string $config_class |
|
| 716 | - * @param string $name |
|
| 717 | - * @return string |
|
| 718 | - */ |
|
| 719 | - private function _set_config_class($config_class = '', $name = '') |
|
| 720 | - { |
|
| 721 | - return ! empty($config_class) |
|
| 722 | - ? $config_class |
|
| 723 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * set_config |
|
| 729 | - * |
|
| 730 | - * @access protected |
|
| 731 | - * @param string $section |
|
| 732 | - * @param string $name |
|
| 733 | - * @param string $config_class |
|
| 734 | - * @param EE_Config_Base $config_obj |
|
| 735 | - * @return EE_Config_Base |
|
| 736 | - */ |
|
| 737 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 738 | - { |
|
| 739 | - // ensure config class is set to something |
|
| 740 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 741 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 742 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 743 | - return null; |
|
| 744 | - } |
|
| 745 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 746 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 747 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 748 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 749 | - $this->update_addon_option_names(); |
|
| 750 | - } |
|
| 751 | - // verify the incoming config object but suppress errors |
|
| 752 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 753 | - $config_obj = new $config_class(); |
|
| 754 | - } |
|
| 755 | - if (get_option($config_option_name)) { |
|
| 756 | - EE_Config::log($config_option_name); |
|
| 757 | - update_option($config_option_name, $config_obj); |
|
| 758 | - $this->{$section}->{$name} = $config_obj; |
|
| 759 | - return $this->{$section}->{$name}; |
|
| 760 | - } else { |
|
| 761 | - // create a wp-option for this config |
|
| 762 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 763 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 764 | - return $this->{$section}->{$name}; |
|
| 765 | - } else { |
|
| 766 | - EE_Error::add_error( |
|
| 767 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 768 | - __FILE__, |
|
| 769 | - __FUNCTION__, |
|
| 770 | - __LINE__ |
|
| 771 | - ); |
|
| 772 | - return null; |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * update_config |
|
| 780 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 781 | - * |
|
| 782 | - * @access public |
|
| 783 | - * @param string $section |
|
| 784 | - * @param string $name |
|
| 785 | - * @param EE_Config_Base|string $config_obj |
|
| 786 | - * @param bool $throw_errors |
|
| 787 | - * @return bool |
|
| 788 | - */ |
|
| 789 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 790 | - { |
|
| 791 | - // don't allow config updates during WP heartbeats |
|
| 792 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 793 | - return false; |
|
| 794 | - } |
|
| 795 | - $config_obj = maybe_unserialize($config_obj); |
|
| 796 | - // get class name of the incoming object |
|
| 797 | - $config_class = get_class($config_obj); |
|
| 798 | - // run tests 1-5 and 9 to verify config |
|
| 799 | - if ( |
|
| 800 | - ! $this->_verify_config_params( |
|
| 801 | - $section, |
|
| 802 | - $name, |
|
| 803 | - $config_class, |
|
| 804 | - $config_obj, |
|
| 805 | - array(1, 2, 3, 4, 7, 9) |
|
| 806 | - ) |
|
| 807 | - ) { |
|
| 808 | - return false; |
|
| 809 | - } |
|
| 810 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 811 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 812 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 813 | - // save new config to db |
|
| 814 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 815 | - return true; |
|
| 816 | - } |
|
| 817 | - } else { |
|
| 818 | - // first check if the record already exists |
|
| 819 | - $existing_config = get_option($config_option_name); |
|
| 820 | - $config_obj = serialize($config_obj); |
|
| 821 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 822 | - if ($existing_config == $config_obj) { |
|
| 823 | - $this->{$section}->{$name} = $config_obj; |
|
| 824 | - return true; |
|
| 825 | - } elseif (update_option($config_option_name, $config_obj)) { |
|
| 826 | - EE_Config::log($config_option_name); |
|
| 827 | - // update wp-option for this config class |
|
| 828 | - $this->{$section}->{$name} = $config_obj; |
|
| 829 | - return true; |
|
| 830 | - } elseif ($throw_errors) { |
|
| 831 | - EE_Error::add_error( |
|
| 832 | - sprintf( |
|
| 833 | - __( |
|
| 834 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 835 | - 'event_espresso' |
|
| 836 | - ), |
|
| 837 | - $config_class, |
|
| 838 | - 'EE_Config->' . $section . '->' . $name |
|
| 839 | - ), |
|
| 840 | - __FILE__, |
|
| 841 | - __FUNCTION__, |
|
| 842 | - __LINE__ |
|
| 843 | - ); |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - return false; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * get_config |
|
| 852 | - * |
|
| 853 | - * @access public |
|
| 854 | - * @param string $section |
|
| 855 | - * @param string $name |
|
| 856 | - * @param string $config_class |
|
| 857 | - * @return mixed EE_Config_Base | NULL |
|
| 858 | - */ |
|
| 859 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 860 | - { |
|
| 861 | - // ensure config class is set to something |
|
| 862 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 863 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 864 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 865 | - return null; |
|
| 866 | - } |
|
| 867 | - // now test if the requested config object exists, but suppress errors |
|
| 868 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 869 | - // config already exists, so pass it back |
|
| 870 | - return $this->{$section}->{$name}; |
|
| 871 | - } |
|
| 872 | - // load config option from db if it exists |
|
| 873 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 874 | - // verify the newly retrieved config object, but suppress errors |
|
| 875 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 876 | - // config is good, so set it and pass it back |
|
| 877 | - $this->{$section}->{$name} = $config_obj; |
|
| 878 | - return $this->{$section}->{$name}; |
|
| 879 | - } |
|
| 880 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 881 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 882 | - // verify the newly created config object |
|
| 883 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 884 | - return $this->{$section}->{$name}; |
|
| 885 | - } else { |
|
| 886 | - EE_Error::add_error( |
|
| 887 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 888 | - __FILE__, |
|
| 889 | - __FUNCTION__, |
|
| 890 | - __LINE__ |
|
| 891 | - ); |
|
| 892 | - } |
|
| 893 | - return null; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * get_config_option |
|
| 899 | - * |
|
| 900 | - * @access public |
|
| 901 | - * @param string $config_option_name |
|
| 902 | - * @return mixed EE_Config_Base | FALSE |
|
| 903 | - */ |
|
| 904 | - public function get_config_option($config_option_name = '') |
|
| 905 | - { |
|
| 906 | - // retrieve the wp-option for this config class. |
|
| 907 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 908 | - if (empty($config_option)) { |
|
| 909 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 910 | - } |
|
| 911 | - return $config_option; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - |
|
| 915 | - /** |
|
| 916 | - * log |
|
| 917 | - * |
|
| 918 | - * @param string $config_option_name |
|
| 919 | - */ |
|
| 920 | - public static function log($config_option_name = '') |
|
| 921 | - { |
|
| 922 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 923 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 924 | - // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 925 | - $_request = $_REQUEST; |
|
| 926 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 927 | - $config_log[ (string) microtime(true) ] = array( |
|
| 928 | - 'config_name' => $config_option_name, |
|
| 929 | - 'request' => $_request, |
|
| 930 | - ); |
|
| 931 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - /** |
|
| 937 | - * trim_log |
|
| 938 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 939 | - */ |
|
| 940 | - public static function trim_log() |
|
| 941 | - { |
|
| 942 | - if (! EE_Config::logging_enabled()) { |
|
| 943 | - return; |
|
| 944 | - } |
|
| 945 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 946 | - $log_length = count($config_log); |
|
| 947 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 948 | - ksort($config_log); |
|
| 949 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 950 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 951 | - } |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * get_page_for_posts |
|
| 957 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 958 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 959 | - * |
|
| 960 | - * @access public |
|
| 961 | - * @return string |
|
| 962 | - */ |
|
| 963 | - public static function get_page_for_posts() |
|
| 964 | - { |
|
| 965 | - $page_for_posts = get_option('page_for_posts'); |
|
| 966 | - if (! $page_for_posts) { |
|
| 967 | - return 'posts'; |
|
| 968 | - } |
|
| 969 | - /** @type WPDB $wpdb */ |
|
| 970 | - global $wpdb; |
|
| 971 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 972 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - /** |
|
| 977 | - * register_shortcodes_and_modules. |
|
| 978 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 979 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 980 | - * so they can help trigger maintenance mode if it's needed |
|
| 981 | - * |
|
| 982 | - * @access public |
|
| 983 | - * @return void |
|
| 984 | - */ |
|
| 985 | - public function register_shortcodes_and_modules() |
|
| 986 | - { |
|
| 987 | - // allow modules to set hooks for the rest of the system |
|
| 988 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - /** |
|
| 993 | - * initialize_shortcodes_and_modules |
|
| 994 | - * meaning they can start adding their hooks to get stuff done |
|
| 995 | - * |
|
| 996 | - * @access public |
|
| 997 | - * @return void |
|
| 998 | - */ |
|
| 999 | - public function initialize_shortcodes_and_modules() |
|
| 1000 | - { |
|
| 1001 | - // allow modules to set hooks for the rest of the system |
|
| 1002 | - $this->_initialize_modules(); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * widgets_init |
|
| 1008 | - * |
|
| 1009 | - * @access private |
|
| 1010 | - * @return void |
|
| 1011 | - */ |
|
| 1012 | - public function widgets_init() |
|
| 1013 | - { |
|
| 1014 | - // only init widgets on admin pages when not in complete maintenance, and |
|
| 1015 | - // on frontend when not in any maintenance mode |
|
| 1016 | - if ( |
|
| 1017 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 1018 | - || ( |
|
| 1019 | - is_admin() |
|
| 1020 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1021 | - ) |
|
| 1022 | - ) { |
|
| 1023 | - // grab list of installed widgets |
|
| 1024 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1025 | - // filter list of modules to register |
|
| 1026 | - $widgets_to_register = apply_filters( |
|
| 1027 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1028 | - $widgets_to_register |
|
| 1029 | - ); |
|
| 1030 | - if (! empty($widgets_to_register)) { |
|
| 1031 | - // cycle thru widget folders |
|
| 1032 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1033 | - // add to list of installed widget modules |
|
| 1034 | - EE_Config::register_ee_widget($widget_path); |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - // filter list of installed modules |
|
| 1038 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1039 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1040 | - EE_Registry::instance()->widgets |
|
| 1041 | - ); |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * register_ee_widget - makes core aware of this widget |
|
| 1048 | - * |
|
| 1049 | - * @access public |
|
| 1050 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1051 | - * @return void |
|
| 1052 | - */ |
|
| 1053 | - public static function register_ee_widget($widget_path = null) |
|
| 1054 | - { |
|
| 1055 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1056 | - $widget_ext = '.widget.php'; |
|
| 1057 | - // make all separators match |
|
| 1058 | - $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1059 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1060 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1061 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1062 | - $file_name = explode('.', basename($widget_path)); |
|
| 1063 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1064 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1065 | - // sanitize shortcode directory name |
|
| 1066 | - $widget = sanitize_key($widget); |
|
| 1067 | - // now we need to rebuild the shortcode path |
|
| 1068 | - $widget_path = explode('/', $widget_path); |
|
| 1069 | - // remove last segment |
|
| 1070 | - array_pop($widget_path); |
|
| 1071 | - // glue it back together |
|
| 1072 | - $widget_path = implode(DS, $widget_path); |
|
| 1073 | - } else { |
|
| 1074 | - // grab and sanitize widget directory name |
|
| 1075 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1076 | - } |
|
| 1077 | - // create classname from widget directory name |
|
| 1078 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1079 | - // add class prefix |
|
| 1080 | - $widget_class = 'EEW_' . $widget; |
|
| 1081 | - // does the widget exist ? |
|
| 1082 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1083 | - $msg = sprintf( |
|
| 1084 | - __( |
|
| 1085 | - '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', |
|
| 1086 | - 'event_espresso' |
|
| 1087 | - ), |
|
| 1088 | - $widget_class, |
|
| 1089 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1090 | - ); |
|
| 1091 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1092 | - return; |
|
| 1093 | - } |
|
| 1094 | - // load the widget class file |
|
| 1095 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1096 | - // verify that class exists |
|
| 1097 | - if (! class_exists($widget_class)) { |
|
| 1098 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1099 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1100 | - return; |
|
| 1101 | - } |
|
| 1102 | - register_widget($widget_class); |
|
| 1103 | - // add to array of registered widgets |
|
| 1104 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * _register_modules |
|
| 1110 | - * |
|
| 1111 | - * @access private |
|
| 1112 | - * @return array |
|
| 1113 | - */ |
|
| 1114 | - private function _register_modules() |
|
| 1115 | - { |
|
| 1116 | - // grab list of installed modules |
|
| 1117 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1118 | - // filter list of modules to register |
|
| 1119 | - $modules_to_register = apply_filters( |
|
| 1120 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1121 | - $modules_to_register |
|
| 1122 | - ); |
|
| 1123 | - if (! empty($modules_to_register)) { |
|
| 1124 | - // loop through folders |
|
| 1125 | - foreach ($modules_to_register as $module_path) { |
|
| 1126 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1127 | - if ( |
|
| 1128 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1129 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1130 | - ) { |
|
| 1131 | - // add to list of installed modules |
|
| 1132 | - EE_Config::register_module($module_path); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - // filter list of installed modules |
|
| 1137 | - return apply_filters( |
|
| 1138 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1139 | - EE_Registry::instance()->modules |
|
| 1140 | - ); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * register_module - makes core aware of this module |
|
| 1146 | - * |
|
| 1147 | - * @access public |
|
| 1148 | - * @param string $module_path - full path up to and including module folder |
|
| 1149 | - * @return bool |
|
| 1150 | - */ |
|
| 1151 | - public static function register_module($module_path = null) |
|
| 1152 | - { |
|
| 1153 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1154 | - $module_ext = '.module.php'; |
|
| 1155 | - // make all separators match |
|
| 1156 | - $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1157 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1158 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1159 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1160 | - $module_file = explode('.', basename($module_path)); |
|
| 1161 | - // now we need to rebuild the shortcode path |
|
| 1162 | - $module_path = explode('/', $module_path); |
|
| 1163 | - // remove last segment |
|
| 1164 | - array_pop($module_path); |
|
| 1165 | - // glue it back together |
|
| 1166 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1167 | - // take first segment from file name pieces and sanitize it |
|
| 1168 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1169 | - // ensure class prefix is added |
|
| 1170 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1171 | - } else { |
|
| 1172 | - // we need to generate the filename based off of the folder name |
|
| 1173 | - // grab and sanitize module name |
|
| 1174 | - $module = strtolower(basename($module_path)); |
|
| 1175 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1176 | - // like trailingslashit() |
|
| 1177 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1178 | - // create classname from module directory name |
|
| 1179 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1180 | - // add class prefix |
|
| 1181 | - $module_class = 'EED_' . $module; |
|
| 1182 | - } |
|
| 1183 | - // does the module exist ? |
|
| 1184 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1185 | - $msg = sprintf( |
|
| 1186 | - __( |
|
| 1187 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1188 | - 'event_espresso' |
|
| 1189 | - ), |
|
| 1190 | - $module |
|
| 1191 | - ); |
|
| 1192 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1193 | - return false; |
|
| 1194 | - } |
|
| 1195 | - // load the module class file |
|
| 1196 | - require_once($module_path . $module_class . $module_ext); |
|
| 1197 | - // verify that class exists |
|
| 1198 | - if (! class_exists($module_class)) { |
|
| 1199 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1200 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1201 | - return false; |
|
| 1202 | - } |
|
| 1203 | - // add to array of registered modules |
|
| 1204 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1205 | - do_action( |
|
| 1206 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1207 | - $module_class, |
|
| 1208 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1209 | - ); |
|
| 1210 | - return true; |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * _initialize_modules |
|
| 1216 | - * allow modules to set hooks for the rest of the system |
|
| 1217 | - * |
|
| 1218 | - * @access private |
|
| 1219 | - * @return void |
|
| 1220 | - */ |
|
| 1221 | - private function _initialize_modules() |
|
| 1222 | - { |
|
| 1223 | - // cycle thru shortcode folders |
|
| 1224 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1225 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1226 | - // which set hooks ? |
|
| 1227 | - if (is_admin()) { |
|
| 1228 | - // fire immediately |
|
| 1229 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1230 | - } else { |
|
| 1231 | - // delay until other systems are online |
|
| 1232 | - add_action( |
|
| 1233 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1234 | - array($module_class, 'set_hooks') |
|
| 1235 | - ); |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * register_route - adds module method routes to route_map |
|
| 1243 | - * |
|
| 1244 | - * @access public |
|
| 1245 | - * @param string $route - "pretty" public alias for module method |
|
| 1246 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1247 | - * @param string $method_name - the actual module method to be routed to |
|
| 1248 | - * @param string $key - url param key indicating a route is being called |
|
| 1249 | - * @return bool |
|
| 1250 | - */ |
|
| 1251 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1252 | - { |
|
| 1253 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1254 | - $module = str_replace('EED_', '', $module); |
|
| 1255 | - $module_class = 'EED_' . $module; |
|
| 1256 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1257 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1258 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | - return false; |
|
| 1260 | - } |
|
| 1261 | - if (empty($route)) { |
|
| 1262 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1263 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1264 | - return false; |
|
| 1265 | - } |
|
| 1266 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1267 | - $msg = sprintf( |
|
| 1268 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1269 | - $route |
|
| 1270 | - ); |
|
| 1271 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1272 | - return false; |
|
| 1273 | - } |
|
| 1274 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1275 | - return true; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * get_route - get module method route |
|
| 1281 | - * |
|
| 1282 | - * @access public |
|
| 1283 | - * @param string $route - "pretty" public alias for module method |
|
| 1284 | - * @param string $key - url param key indicating a route is being called |
|
| 1285 | - * @return string |
|
| 1286 | - */ |
|
| 1287 | - public static function get_route($route = null, $key = 'ee') |
|
| 1288 | - { |
|
| 1289 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1290 | - $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1291 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1292 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1293 | - } |
|
| 1294 | - return null; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * get_routes - get ALL module method routes |
|
| 1300 | - * |
|
| 1301 | - * @access public |
|
| 1302 | - * @return array |
|
| 1303 | - */ |
|
| 1304 | - public static function get_routes() |
|
| 1305 | - { |
|
| 1306 | - return EE_Config::$_module_route_map; |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1312 | - * |
|
| 1313 | - * @access public |
|
| 1314 | - * @param string $route - "pretty" public alias for module method |
|
| 1315 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1316 | - * class, allows different forwards to be served based on status |
|
| 1317 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1318 | - * @param string $key - url param key indicating a route is being called |
|
| 1319 | - * @return bool |
|
| 1320 | - */ |
|
| 1321 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1322 | - { |
|
| 1323 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1324 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1325 | - $msg = sprintf( |
|
| 1326 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1327 | - $route |
|
| 1328 | - ); |
|
| 1329 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | - return false; |
|
| 1331 | - } |
|
| 1332 | - if (empty($forward)) { |
|
| 1333 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1334 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1335 | - return false; |
|
| 1336 | - } |
|
| 1337 | - if (is_array($forward)) { |
|
| 1338 | - if (! isset($forward[1])) { |
|
| 1339 | - $msg = sprintf( |
|
| 1340 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1341 | - $route |
|
| 1342 | - ); |
|
| 1343 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1344 | - return false; |
|
| 1345 | - } |
|
| 1346 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1347 | - $msg = sprintf( |
|
| 1348 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1349 | - $forward[1], |
|
| 1350 | - $route |
|
| 1351 | - ); |
|
| 1352 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1353 | - return false; |
|
| 1354 | - } |
|
| 1355 | - } elseif (! function_exists($forward)) { |
|
| 1356 | - $msg = sprintf( |
|
| 1357 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1358 | - $forward, |
|
| 1359 | - $route |
|
| 1360 | - ); |
|
| 1361 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1362 | - return false; |
|
| 1363 | - } |
|
| 1364 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1365 | - return true; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /** |
|
| 1370 | - * get_forward - get forwarding route |
|
| 1371 | - * |
|
| 1372 | - * @access public |
|
| 1373 | - * @param string $route - "pretty" public alias for module method |
|
| 1374 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1375 | - * allows different forwards to be served based on status |
|
| 1376 | - * @param string $key - url param key indicating a route is being called |
|
| 1377 | - * @return string |
|
| 1378 | - */ |
|
| 1379 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1380 | - { |
|
| 1381 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1382 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1383 | - return apply_filters( |
|
| 1384 | - 'FHEE__EE_Config__get_forward', |
|
| 1385 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1386 | - $route, |
|
| 1387 | - $status |
|
| 1388 | - ); |
|
| 1389 | - } |
|
| 1390 | - return null; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1396 | - * results |
|
| 1397 | - * |
|
| 1398 | - * @access public |
|
| 1399 | - * @param string $route - "pretty" public alias for module method |
|
| 1400 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1401 | - * allows different views to be served based on status |
|
| 1402 | - * @param string $view |
|
| 1403 | - * @param string $key - url param key indicating a route is being called |
|
| 1404 | - * @return bool |
|
| 1405 | - */ |
|
| 1406 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1407 | - { |
|
| 1408 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1409 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1410 | - $msg = sprintf( |
|
| 1411 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1412 | - $route |
|
| 1413 | - ); |
|
| 1414 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1415 | - return false; |
|
| 1416 | - } |
|
| 1417 | - if (! is_readable($view)) { |
|
| 1418 | - $msg = sprintf( |
|
| 1419 | - __( |
|
| 1420 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1421 | - 'event_espresso' |
|
| 1422 | - ), |
|
| 1423 | - $view |
|
| 1424 | - ); |
|
| 1425 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1426 | - return false; |
|
| 1427 | - } |
|
| 1428 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1429 | - return true; |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - |
|
| 1433 | - /** |
|
| 1434 | - * get_view - get view for route and status |
|
| 1435 | - * |
|
| 1436 | - * @access public |
|
| 1437 | - * @param string $route - "pretty" public alias for module method |
|
| 1438 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1439 | - * allows different views to be served based on status |
|
| 1440 | - * @param string $key - url param key indicating a route is being called |
|
| 1441 | - * @return string |
|
| 1442 | - */ |
|
| 1443 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1444 | - { |
|
| 1445 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1446 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1447 | - return apply_filters( |
|
| 1448 | - 'FHEE__EE_Config__get_view', |
|
| 1449 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1450 | - $route, |
|
| 1451 | - $status |
|
| 1452 | - ); |
|
| 1453 | - } |
|
| 1454 | - return null; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - |
|
| 1458 | - public function update_addon_option_names() |
|
| 1459 | - { |
|
| 1460 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - |
|
| 1464 | - public function shutdown() |
|
| 1465 | - { |
|
| 1466 | - $this->update_addon_option_names(); |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * @return LegacyShortcodesManager |
|
| 1472 | - */ |
|
| 1473 | - public static function getLegacyShortcodesManager() |
|
| 1474 | - { |
|
| 1475 | - |
|
| 1476 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1477 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1478 | - EE_Registry::instance() |
|
| 1479 | - ); |
|
| 1480 | - } |
|
| 1481 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * register_shortcode - makes core aware of this shortcode |
|
| 1487 | - * |
|
| 1488 | - * @deprecated 4.9.26 |
|
| 1489 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1490 | - * @return bool |
|
| 1491 | - */ |
|
| 1492 | - public static function register_shortcode($shortcode_path = null) |
|
| 1493 | - { |
|
| 1494 | - EE_Error::doing_it_wrong( |
|
| 1495 | - __METHOD__, |
|
| 1496 | - __( |
|
| 1497 | - '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.', |
|
| 1498 | - 'event_espresso' |
|
| 1499 | - ), |
|
| 1500 | - '4.9.26' |
|
| 1501 | - ); |
|
| 1502 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1503 | - } |
|
| 1504 | -} |
|
| 1505 | - |
|
| 1506 | -/** |
|
| 1507 | - * Base class used for config classes. These classes should generally not have |
|
| 1508 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1509 | - * basically, they should just be well-defined stdClasses |
|
| 1510 | - */ |
|
| 1511 | -class EE_Config_Base |
|
| 1512 | -{ |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * Utility function for escaping the value of a property and returning. |
|
| 1516 | - * |
|
| 1517 | - * @param string $property property name (checks to see if exists). |
|
| 1518 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1519 | - * @throws \EE_Error |
|
| 1520 | - */ |
|
| 1521 | - public function get_pretty($property) |
|
| 1522 | - { |
|
| 1523 | - if (! property_exists($this, $property)) { |
|
| 1524 | - throw new EE_Error( |
|
| 1525 | - sprintf( |
|
| 1526 | - __( |
|
| 1527 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1528 | - 'event_espresso' |
|
| 1529 | - ), |
|
| 1530 | - get_class($this), |
|
| 1531 | - $property |
|
| 1532 | - ) |
|
| 1533 | - ); |
|
| 1534 | - } |
|
| 1535 | - // just handling escaping of strings for now. |
|
| 1536 | - if (is_string($this->{$property})) { |
|
| 1537 | - return stripslashes($this->{$property}); |
|
| 1538 | - } |
|
| 1539 | - return $this->{$property}; |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - public function populate() |
|
| 1544 | - { |
|
| 1545 | - // grab defaults via a new instance of this class. |
|
| 1546 | - $class_name = get_class($this); |
|
| 1547 | - $defaults = new $class_name(); |
|
| 1548 | - // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1549 | - // default from our $defaults object. |
|
| 1550 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1551 | - if ($this->{$property} === null) { |
|
| 1552 | - $this->{$property} = $value; |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - // cleanup |
|
| 1556 | - unset($defaults); |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - |
|
| 1560 | - /** |
|
| 1561 | - * __isset |
|
| 1562 | - * |
|
| 1563 | - * @param $a |
|
| 1564 | - * @return bool |
|
| 1565 | - */ |
|
| 1566 | - public function __isset($a) |
|
| 1567 | - { |
|
| 1568 | - return false; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - |
|
| 1572 | - /** |
|
| 1573 | - * __unset |
|
| 1574 | - * |
|
| 1575 | - * @param $a |
|
| 1576 | - * @return bool |
|
| 1577 | - */ |
|
| 1578 | - public function __unset($a) |
|
| 1579 | - { |
|
| 1580 | - return false; |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - |
|
| 1584 | - /** |
|
| 1585 | - * __clone |
|
| 1586 | - */ |
|
| 1587 | - public function __clone() |
|
| 1588 | - { |
|
| 1589 | - } |
|
| 1590 | - |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * __wakeup |
|
| 1594 | - */ |
|
| 1595 | - public function __wakeup() |
|
| 1596 | - { |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - /** |
|
| 1601 | - * __destruct |
|
| 1602 | - */ |
|
| 1603 | - public function __destruct() |
|
| 1604 | - { |
|
| 1605 | - } |
|
| 1606 | -} |
|
| 1607 | - |
|
| 1608 | -/** |
|
| 1609 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1610 | - */ |
|
| 1611 | -class EE_Core_Config extends EE_Config_Base |
|
| 1612 | -{ |
|
| 1613 | - |
|
| 1614 | - const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - public $current_blog_id; |
|
| 1618 | - |
|
| 1619 | - public $ee_ueip_optin; |
|
| 1620 | - |
|
| 1621 | - public $ee_ueip_has_notified; |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * Not to be confused with the 4 critical page variables (See |
|
| 1625 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1626 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1627 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1628 | - * |
|
| 1629 | - * @var array |
|
| 1630 | - */ |
|
| 1631 | - public $post_shortcodes; |
|
| 1632 | - |
|
| 1633 | - public $module_route_map; |
|
| 1634 | - |
|
| 1635 | - public $module_forward_map; |
|
| 1636 | - |
|
| 1637 | - public $module_view_map; |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1641 | - * |
|
| 1642 | - * @var int |
|
| 1643 | - */ |
|
| 1644 | - public $reg_page_id; |
|
| 1645 | - |
|
| 1646 | - public $txn_page_id; |
|
| 1647 | - |
|
| 1648 | - public $thank_you_page_id; |
|
| 1649 | - |
|
| 1650 | - public $cancel_page_id; |
|
| 1651 | - |
|
| 1652 | - /** |
|
| 1653 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1654 | - * |
|
| 1655 | - * @var int |
|
| 1656 | - */ |
|
| 1657 | - public $reg_page_url; |
|
| 1658 | - |
|
| 1659 | - public $txn_page_url; |
|
| 1660 | - |
|
| 1661 | - public $thank_you_page_url; |
|
| 1662 | - |
|
| 1663 | - public $cancel_page_url; |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1667 | - */ |
|
| 1668 | - public $event_cpt_slug; |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1672 | - * request across blog switches in a multisite context. |
|
| 1673 | - * Avoids extra queries to the db for this option. |
|
| 1674 | - * |
|
| 1675 | - * @var bool |
|
| 1676 | - */ |
|
| 1677 | - public static $ee_ueip_option; |
|
| 1678 | - |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * class constructor |
|
| 1682 | - * |
|
| 1683 | - * @access public |
|
| 1684 | - */ |
|
| 1685 | - public function __construct() |
|
| 1686 | - { |
|
| 1687 | - // set default organization settings |
|
| 1688 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1689 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1690 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1691 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1692 | - $this->post_shortcodes = array(); |
|
| 1693 | - $this->module_route_map = array(); |
|
| 1694 | - $this->module_forward_map = array(); |
|
| 1695 | - $this->module_view_map = array(); |
|
| 1696 | - // critical EE page IDs |
|
| 1697 | - $this->reg_page_id = 0; |
|
| 1698 | - $this->txn_page_id = 0; |
|
| 1699 | - $this->thank_you_page_id = 0; |
|
| 1700 | - $this->cancel_page_id = 0; |
|
| 1701 | - // critical EE page URLs |
|
| 1702 | - $this->reg_page_url = ''; |
|
| 1703 | - $this->txn_page_url = ''; |
|
| 1704 | - $this->thank_you_page_url = ''; |
|
| 1705 | - $this->cancel_page_url = ''; |
|
| 1706 | - // cpt slugs |
|
| 1707 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1708 | - // ueip constant check |
|
| 1709 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1710 | - $this->ee_ueip_optin = false; |
|
| 1711 | - $this->ee_ueip_has_notified = true; |
|
| 1712 | - } |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - |
|
| 1716 | - /** |
|
| 1717 | - * @return array |
|
| 1718 | - */ |
|
| 1719 | - public function get_critical_pages_array() |
|
| 1720 | - { |
|
| 1721 | - return array( |
|
| 1722 | - $this->reg_page_id, |
|
| 1723 | - $this->txn_page_id, |
|
| 1724 | - $this->thank_you_page_id, |
|
| 1725 | - $this->cancel_page_id, |
|
| 1726 | - ); |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * @return array |
|
| 1732 | - */ |
|
| 1733 | - public function get_critical_pages_shortcodes_array() |
|
| 1734 | - { |
|
| 1735 | - return array( |
|
| 1736 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1737 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1738 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1739 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1740 | - ); |
|
| 1741 | - } |
|
| 1742 | - |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * gets/returns URL for EE reg_page |
|
| 1746 | - * |
|
| 1747 | - * @access public |
|
| 1748 | - * @return string |
|
| 1749 | - */ |
|
| 1750 | - public function reg_page_url() |
|
| 1751 | - { |
|
| 1752 | - if (! $this->reg_page_url) { |
|
| 1753 | - $this->reg_page_url = add_query_arg( |
|
| 1754 | - array('uts' => time()), |
|
| 1755 | - get_permalink($this->reg_page_id) |
|
| 1756 | - ) . '#checkout'; |
|
| 1757 | - } |
|
| 1758 | - return $this->reg_page_url; |
|
| 1759 | - } |
|
| 1760 | - |
|
| 1761 | - |
|
| 1762 | - /** |
|
| 1763 | - * gets/returns URL for EE txn_page |
|
| 1764 | - * |
|
| 1765 | - * @param array $query_args like what gets passed to |
|
| 1766 | - * add_query_arg() as the first argument |
|
| 1767 | - * @access public |
|
| 1768 | - * @return string |
|
| 1769 | - */ |
|
| 1770 | - public function txn_page_url($query_args = array()) |
|
| 1771 | - { |
|
| 1772 | - if (! $this->txn_page_url) { |
|
| 1773 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1774 | - } |
|
| 1775 | - if ($query_args) { |
|
| 1776 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1777 | - } else { |
|
| 1778 | - return $this->txn_page_url; |
|
| 1779 | - } |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - |
|
| 1783 | - /** |
|
| 1784 | - * gets/returns URL for EE thank_you_page |
|
| 1785 | - * |
|
| 1786 | - * @param array $query_args like what gets passed to |
|
| 1787 | - * add_query_arg() as the first argument |
|
| 1788 | - * @access public |
|
| 1789 | - * @return string |
|
| 1790 | - */ |
|
| 1791 | - public function thank_you_page_url($query_args = array()) |
|
| 1792 | - { |
|
| 1793 | - if (! $this->thank_you_page_url) { |
|
| 1794 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1795 | - } |
|
| 1796 | - if ($query_args) { |
|
| 1797 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1798 | - } else { |
|
| 1799 | - return $this->thank_you_page_url; |
|
| 1800 | - } |
|
| 1801 | - } |
|
| 1802 | - |
|
| 1803 | - |
|
| 1804 | - /** |
|
| 1805 | - * gets/returns URL for EE cancel_page |
|
| 1806 | - * |
|
| 1807 | - * @access public |
|
| 1808 | - * @return string |
|
| 1809 | - */ |
|
| 1810 | - public function cancel_page_url() |
|
| 1811 | - { |
|
| 1812 | - if (! $this->cancel_page_url) { |
|
| 1813 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1814 | - } |
|
| 1815 | - return $this->cancel_page_url; |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1821 | - * |
|
| 1822 | - * @since 4.7.5 |
|
| 1823 | - */ |
|
| 1824 | - protected function _reset_urls() |
|
| 1825 | - { |
|
| 1826 | - $this->reg_page_url = ''; |
|
| 1827 | - $this->txn_page_url = ''; |
|
| 1828 | - $this->cancel_page_url = ''; |
|
| 1829 | - $this->thank_you_page_url = ''; |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - |
|
| 1833 | - /** |
|
| 1834 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1835 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1836 | - * on the main site only. |
|
| 1837 | - * |
|
| 1838 | - * @return bool |
|
| 1839 | - */ |
|
| 1840 | - protected function _get_main_ee_ueip_optin() |
|
| 1841 | - { |
|
| 1842 | - // if this is the main site then we can just bypass our direct query. |
|
| 1843 | - if (is_main_site()) { |
|
| 1844 | - return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1845 | - } |
|
| 1846 | - // is this already cached for this request? If so use it. |
|
| 1847 | - if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1848 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1849 | - } |
|
| 1850 | - global $wpdb; |
|
| 1851 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1852 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1853 | - $option = self::OPTION_NAME_UXIP; |
|
| 1854 | - // set correct table for query |
|
| 1855 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1856 | - // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1857 | - // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1858 | - // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1859 | - // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1860 | - // for the purpose of caching. |
|
| 1861 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1862 | - if (false !== $pre) { |
|
| 1863 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1864 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1865 | - } |
|
| 1866 | - $row = $wpdb->get_row( |
|
| 1867 | - $wpdb->prepare( |
|
| 1868 | - "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1869 | - $option |
|
| 1870 | - ) |
|
| 1871 | - ); |
|
| 1872 | - if (is_object($row)) { |
|
| 1873 | - $value = $row->option_value; |
|
| 1874 | - } else { // option does not exist so use default. |
|
| 1875 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1876 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1877 | - } |
|
| 1878 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1879 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * Utility function for escaping the value of a property and returning. |
|
| 1885 | - * |
|
| 1886 | - * @param string $property property name (checks to see if exists). |
|
| 1887 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1888 | - * @throws \EE_Error |
|
| 1889 | - */ |
|
| 1890 | - public function get_pretty($property) |
|
| 1891 | - { |
|
| 1892 | - if ($property === self::OPTION_NAME_UXIP) { |
|
| 1893 | - return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1894 | - } |
|
| 1895 | - return parent::get_pretty($property); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - |
|
| 1899 | - /** |
|
| 1900 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1901 | - * on the object. |
|
| 1902 | - * |
|
| 1903 | - * @return array |
|
| 1904 | - */ |
|
| 1905 | - public function __sleep() |
|
| 1906 | - { |
|
| 1907 | - // reset all url properties |
|
| 1908 | - $this->_reset_urls(); |
|
| 1909 | - // return what to save to db |
|
| 1910 | - return array_keys(get_object_vars($this)); |
|
| 1911 | - } |
|
| 1912 | -} |
|
| 1913 | - |
|
| 1914 | -/** |
|
| 1915 | - * Config class for storing info on the Organization |
|
| 1916 | - */ |
|
| 1917 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1918 | -{ |
|
| 1919 | - |
|
| 1920 | - /** |
|
| 1921 | - * @var string $name |
|
| 1922 | - * eg EE4.1 |
|
| 1923 | - */ |
|
| 1924 | - public $name; |
|
| 1925 | - |
|
| 1926 | - /** |
|
| 1927 | - * @var string $address_1 |
|
| 1928 | - * eg 123 Onna Road |
|
| 1929 | - */ |
|
| 1930 | - public $address_1 = ''; |
|
| 1931 | - |
|
| 1932 | - /** |
|
| 1933 | - * @var string $address_2 |
|
| 1934 | - * eg PO Box 123 |
|
| 1935 | - */ |
|
| 1936 | - public $address_2 = ''; |
|
| 1937 | - |
|
| 1938 | - /** |
|
| 1939 | - * @var string $city |
|
| 1940 | - * eg Inna City |
|
| 1941 | - */ |
|
| 1942 | - public $city = ''; |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * @var int $STA_ID |
|
| 1946 | - * eg 4 |
|
| 1947 | - */ |
|
| 1948 | - public $STA_ID = 0; |
|
| 1949 | - |
|
| 1950 | - /** |
|
| 1951 | - * @var string $CNT_ISO |
|
| 1952 | - * eg US |
|
| 1953 | - */ |
|
| 1954 | - public $CNT_ISO = ''; |
|
| 1955 | - |
|
| 1956 | - /** |
|
| 1957 | - * @var string $zip |
|
| 1958 | - * eg 12345 or V1A 2B3 |
|
| 1959 | - */ |
|
| 1960 | - public $zip = ''; |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * @var string $email |
|
| 1964 | - * eg [email protected] |
|
| 1965 | - */ |
|
| 1966 | - public $email; |
|
| 1967 | - |
|
| 1968 | - /** |
|
| 1969 | - * @var string $phone |
|
| 1970 | - * eg. 111-111-1111 |
|
| 1971 | - */ |
|
| 1972 | - public $phone = ''; |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * @var string $vat |
|
| 1976 | - * VAT/Tax Number |
|
| 1977 | - */ |
|
| 1978 | - public $vat = ''; |
|
| 1979 | - |
|
| 1980 | - /** |
|
| 1981 | - * @var string $logo_url |
|
| 1982 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1983 | - */ |
|
| 1984 | - public $logo_url = ''; |
|
| 1985 | - |
|
| 1986 | - /** |
|
| 1987 | - * The below are all various properties for holding links to organization social network profiles |
|
| 1988 | - * |
|
| 1989 | - * @var string |
|
| 1990 | - */ |
|
| 1991 | - /** |
|
| 1992 | - * facebook (facebook.com/profile.name) |
|
| 1993 | - * |
|
| 1994 | - * @var string |
|
| 1995 | - */ |
|
| 1996 | - public $facebook = ''; |
|
| 1997 | - |
|
| 1998 | - /** |
|
| 1999 | - * twitter (twitter.com/twitter_handle) |
|
| 2000 | - * |
|
| 2001 | - * @var string |
|
| 2002 | - */ |
|
| 2003 | - public $twitter = ''; |
|
| 2004 | - |
|
| 2005 | - /** |
|
| 2006 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2007 | - * |
|
| 2008 | - * @var string |
|
| 2009 | - */ |
|
| 2010 | - public $linkedin = ''; |
|
| 2011 | - |
|
| 2012 | - /** |
|
| 2013 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2014 | - * |
|
| 2015 | - * @var string |
|
| 2016 | - */ |
|
| 2017 | - public $pinterest = ''; |
|
| 2018 | - |
|
| 2019 | - /** |
|
| 2020 | - * google+ (google.com/+profileName) |
|
| 2021 | - * |
|
| 2022 | - * @var string |
|
| 2023 | - */ |
|
| 2024 | - public $google = ''; |
|
| 2025 | - |
|
| 2026 | - /** |
|
| 2027 | - * instagram (instagram.com/handle) |
|
| 2028 | - * |
|
| 2029 | - * @var string |
|
| 2030 | - */ |
|
| 2031 | - public $instagram = ''; |
|
| 2032 | - |
|
| 2033 | - |
|
| 2034 | - /** |
|
| 2035 | - * class constructor |
|
| 2036 | - * |
|
| 2037 | - * @access public |
|
| 2038 | - */ |
|
| 2039 | - public function __construct() |
|
| 2040 | - { |
|
| 2041 | - // set default organization settings |
|
| 2042 | - // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2043 | - $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2044 | - $this->email = get_bloginfo('admin_email'); |
|
| 2045 | - } |
|
| 2046 | -} |
|
| 2047 | - |
|
| 2048 | -/** |
|
| 2049 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2050 | - */ |
|
| 2051 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2052 | -{ |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * @var string $code |
|
| 2056 | - * eg 'US' |
|
| 2057 | - */ |
|
| 2058 | - public $code; |
|
| 2059 | - |
|
| 2060 | - /** |
|
| 2061 | - * @var string $name |
|
| 2062 | - * eg 'Dollar' |
|
| 2063 | - */ |
|
| 2064 | - public $name; |
|
| 2065 | - |
|
| 2066 | - /** |
|
| 2067 | - * plural name |
|
| 2068 | - * |
|
| 2069 | - * @var string $plural |
|
| 2070 | - * eg 'Dollars' |
|
| 2071 | - */ |
|
| 2072 | - public $plural; |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * currency sign |
|
| 2076 | - * |
|
| 2077 | - * @var string $sign |
|
| 2078 | - * eg '$' |
|
| 2079 | - */ |
|
| 2080 | - public $sign; |
|
| 2081 | - |
|
| 2082 | - /** |
|
| 2083 | - * Whether the currency sign should come before the number or not |
|
| 2084 | - * |
|
| 2085 | - * @var boolean $sign_b4 |
|
| 2086 | - */ |
|
| 2087 | - public $sign_b4; |
|
| 2088 | - |
|
| 2089 | - /** |
|
| 2090 | - * How many digits should come after the decimal place |
|
| 2091 | - * |
|
| 2092 | - * @var int $dec_plc |
|
| 2093 | - */ |
|
| 2094 | - public $dec_plc; |
|
| 2095 | - |
|
| 2096 | - /** |
|
| 2097 | - * Symbol to use for decimal mark |
|
| 2098 | - * |
|
| 2099 | - * @var string $dec_mrk |
|
| 2100 | - * eg '.' |
|
| 2101 | - */ |
|
| 2102 | - public $dec_mrk; |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * Symbol to use for thousands |
|
| 2106 | - * |
|
| 2107 | - * @var string $thsnds |
|
| 2108 | - * eg ',' |
|
| 2109 | - */ |
|
| 2110 | - public $thsnds; |
|
| 2111 | - |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * class constructor |
|
| 2115 | - * |
|
| 2116 | - * @access public |
|
| 2117 | - * @param string $CNT_ISO |
|
| 2118 | - * @throws \EE_Error |
|
| 2119 | - */ |
|
| 2120 | - public function __construct($CNT_ISO = '') |
|
| 2121 | - { |
|
| 2122 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2123 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2124 | - // get country code from organization settings or use default |
|
| 2125 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2126 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2127 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2128 | - : ''; |
|
| 2129 | - // but override if requested |
|
| 2130 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2131 | - // 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 |
|
| 2132 | - if ( |
|
| 2133 | - ! empty($CNT_ISO) |
|
| 2134 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2135 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2136 | - ) { |
|
| 2137 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2138 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2139 | - if ($country instanceof EE_Country) { |
|
| 2140 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2141 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2142 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2143 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2144 | - $this->sign_b4 = $country->currency_sign_before( |
|
| 2145 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2146 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2147 | - $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2148 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2149 | - $this->thsnds = $country->currency_thousands_separator( |
|
| 2150 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | - } |
|
| 2152 | - } |
|
| 2153 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2154 | - if (empty($this->code)) { |
|
| 2155 | - // set default currency settings |
|
| 2156 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2157 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2158 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2159 | - $this->sign = '$'; // currency sign: $ |
|
| 2160 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2161 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2162 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2163 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2164 | - } |
|
| 2165 | - } |
|
| 2166 | -} |
|
| 2167 | - |
|
| 2168 | -/** |
|
| 2169 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2170 | - */ |
|
| 2171 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2172 | -{ |
|
| 2173 | - |
|
| 2174 | - /** |
|
| 2175 | - * Default registration status |
|
| 2176 | - * |
|
| 2177 | - * @var string $default_STS_ID |
|
| 2178 | - * eg 'RPP' |
|
| 2179 | - */ |
|
| 2180 | - public $default_STS_ID; |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2184 | - * registrations) |
|
| 2185 | - * |
|
| 2186 | - * @var int |
|
| 2187 | - */ |
|
| 2188 | - public $default_maximum_number_of_tickets; |
|
| 2189 | - |
|
| 2190 | - /** |
|
| 2191 | - * level of validation to apply to email addresses |
|
| 2192 | - * |
|
| 2193 | - * @var string $email_validation_level |
|
| 2194 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2195 | - */ |
|
| 2196 | - public $email_validation_level; |
|
| 2197 | - |
|
| 2198 | - /** |
|
| 2199 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2200 | - * |
|
| 2201 | - * @var boolean $show_pending_payment_options |
|
| 2202 | - */ |
|
| 2203 | - public $show_pending_payment_options; |
|
| 2204 | - |
|
| 2205 | - /** |
|
| 2206 | - * Whether to skip the registration confirmation page |
|
| 2207 | - * |
|
| 2208 | - * @var boolean $skip_reg_confirmation |
|
| 2209 | - */ |
|
| 2210 | - public $skip_reg_confirmation; |
|
| 2211 | - |
|
| 2212 | - /** |
|
| 2213 | - * an array of SPCO reg steps where: |
|
| 2214 | - * the keys denotes the reg step order |
|
| 2215 | - * each element consists of an array with the following elements: |
|
| 2216 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2217 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2218 | - * "slug" => the URL param used to trigger the reg step |
|
| 2219 | - * |
|
| 2220 | - * @var array $reg_steps |
|
| 2221 | - */ |
|
| 2222 | - public $reg_steps; |
|
| 2223 | - |
|
| 2224 | - /** |
|
| 2225 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2226 | - * |
|
| 2227 | - * @var boolean $reg_confirmation_last |
|
| 2228 | - */ |
|
| 2229 | - public $reg_confirmation_last; |
|
| 2230 | - |
|
| 2231 | - /** |
|
| 2232 | - * Whether or not to enable the EE Bot Trap |
|
| 2233 | - * |
|
| 2234 | - * @var boolean $use_bot_trap |
|
| 2235 | - */ |
|
| 2236 | - public $use_bot_trap; |
|
| 2237 | - |
|
| 2238 | - /** |
|
| 2239 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2240 | - * |
|
| 2241 | - * @var boolean $use_encryption |
|
| 2242 | - */ |
|
| 2243 | - public $use_encryption; |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * Whether or not to use ReCaptcha |
|
| 2247 | - * |
|
| 2248 | - * @var boolean $use_captcha |
|
| 2249 | - */ |
|
| 2250 | - public $use_captcha; |
|
| 2251 | - |
|
| 2252 | - /** |
|
| 2253 | - * ReCaptcha Theme |
|
| 2254 | - * |
|
| 2255 | - * @var string $recaptcha_theme |
|
| 2256 | - * options: 'dark', 'light', 'invisible' |
|
| 2257 | - */ |
|
| 2258 | - public $recaptcha_theme; |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2262 | - * |
|
| 2263 | - * @var string $recaptcha_badge |
|
| 2264 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2265 | - */ |
|
| 2266 | - 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 ( |
|
| 574 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 575 | + ) { |
|
| 576 | + if ($display_errors) { |
|
| 577 | + throw new EE_Error( |
|
| 578 | + sprintf( |
|
| 579 | + __( |
|
| 580 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 581 | + 'event_espresso' |
|
| 582 | + ), |
|
| 583 | + $section |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + } |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + break; |
|
| 590 | + // TEST #4 : check that config section name has been set |
|
| 591 | + case 4: |
|
| 592 | + if (empty($name)) { |
|
| 593 | + if ($display_errors) { |
|
| 594 | + throw new EE_Error( |
|
| 595 | + __( |
|
| 596 | + 'No name has been provided for the specific configuration section.', |
|
| 597 | + 'event_espresso' |
|
| 598 | + ) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 603 | + break; |
|
| 604 | + // TEST #5 : check that a config class name has been set |
|
| 605 | + case 5: |
|
| 606 | + if (empty($config_class)) { |
|
| 607 | + if ($display_errors) { |
|
| 608 | + throw new EE_Error( |
|
| 609 | + __( |
|
| 610 | + 'No class name has been provided for the specific configuration section.', |
|
| 611 | + 'event_espresso' |
|
| 612 | + ) |
|
| 613 | + ); |
|
| 614 | + } |
|
| 615 | + return false; |
|
| 616 | + } |
|
| 617 | + break; |
|
| 618 | + // TEST #6 : verify config class is accessible |
|
| 619 | + case 6: |
|
| 620 | + if (! class_exists($config_class)) { |
|
| 621 | + if ($display_errors) { |
|
| 622 | + throw new EE_Error( |
|
| 623 | + sprintf( |
|
| 624 | + __( |
|
| 625 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 626 | + 'event_espresso' |
|
| 627 | + ), |
|
| 628 | + $config_class |
|
| 629 | + ) |
|
| 630 | + ); |
|
| 631 | + } |
|
| 632 | + return false; |
|
| 633 | + } |
|
| 634 | + break; |
|
| 635 | + // TEST #7 : check that config has even been set |
|
| 636 | + case 7: |
|
| 637 | + if (! isset($this->{$section}->{$name})) { |
|
| 638 | + if ($display_errors) { |
|
| 639 | + throw new EE_Error( |
|
| 640 | + sprintf( |
|
| 641 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 642 | + $section, |
|
| 643 | + $name |
|
| 644 | + ) |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + return false; |
|
| 648 | + } else { |
|
| 649 | + // and make sure it's not serialized |
|
| 650 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 651 | + } |
|
| 652 | + break; |
|
| 653 | + // TEST #8 : check that config is the requested type |
|
| 654 | + case 8: |
|
| 655 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 656 | + if ($display_errors) { |
|
| 657 | + throw new EE_Error( |
|
| 658 | + sprintf( |
|
| 659 | + __( |
|
| 660 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 661 | + 'event_espresso' |
|
| 662 | + ), |
|
| 663 | + $section, |
|
| 664 | + $name, |
|
| 665 | + $config_class |
|
| 666 | + ) |
|
| 667 | + ); |
|
| 668 | + } |
|
| 669 | + return false; |
|
| 670 | + } |
|
| 671 | + break; |
|
| 672 | + // TEST #9 : verify config object |
|
| 673 | + case 9: |
|
| 674 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 675 | + if ($display_errors) { |
|
| 676 | + throw new EE_Error( |
|
| 677 | + sprintf( |
|
| 678 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 679 | + print_r($config_obj, true) |
|
| 680 | + ) |
|
| 681 | + ); |
|
| 682 | + } |
|
| 683 | + return false; |
|
| 684 | + } |
|
| 685 | + break; |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + } catch (EE_Error $e) { |
|
| 689 | + $e->get_error(); |
|
| 690 | + } |
|
| 691 | + // you have successfully run the gauntlet |
|
| 692 | + return true; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * _generate_config_option_name |
|
| 698 | + * |
|
| 699 | + * @access protected |
|
| 700 | + * @param string $section |
|
| 701 | + * @param string $name |
|
| 702 | + * @return string |
|
| 703 | + */ |
|
| 704 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 705 | + { |
|
| 706 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * _set_config_class |
|
| 712 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 713 | + * |
|
| 714 | + * @access private |
|
| 715 | + * @param string $config_class |
|
| 716 | + * @param string $name |
|
| 717 | + * @return string |
|
| 718 | + */ |
|
| 719 | + private function _set_config_class($config_class = '', $name = '') |
|
| 720 | + { |
|
| 721 | + return ! empty($config_class) |
|
| 722 | + ? $config_class |
|
| 723 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * set_config |
|
| 729 | + * |
|
| 730 | + * @access protected |
|
| 731 | + * @param string $section |
|
| 732 | + * @param string $name |
|
| 733 | + * @param string $config_class |
|
| 734 | + * @param EE_Config_Base $config_obj |
|
| 735 | + * @return EE_Config_Base |
|
| 736 | + */ |
|
| 737 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 738 | + { |
|
| 739 | + // ensure config class is set to something |
|
| 740 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 741 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 742 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 743 | + return null; |
|
| 744 | + } |
|
| 745 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 746 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 747 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 748 | + $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 749 | + $this->update_addon_option_names(); |
|
| 750 | + } |
|
| 751 | + // verify the incoming config object but suppress errors |
|
| 752 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 753 | + $config_obj = new $config_class(); |
|
| 754 | + } |
|
| 755 | + if (get_option($config_option_name)) { |
|
| 756 | + EE_Config::log($config_option_name); |
|
| 757 | + update_option($config_option_name, $config_obj); |
|
| 758 | + $this->{$section}->{$name} = $config_obj; |
|
| 759 | + return $this->{$section}->{$name}; |
|
| 760 | + } else { |
|
| 761 | + // create a wp-option for this config |
|
| 762 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 763 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 764 | + return $this->{$section}->{$name}; |
|
| 765 | + } else { |
|
| 766 | + EE_Error::add_error( |
|
| 767 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 768 | + __FILE__, |
|
| 769 | + __FUNCTION__, |
|
| 770 | + __LINE__ |
|
| 771 | + ); |
|
| 772 | + return null; |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * update_config |
|
| 780 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 781 | + * |
|
| 782 | + * @access public |
|
| 783 | + * @param string $section |
|
| 784 | + * @param string $name |
|
| 785 | + * @param EE_Config_Base|string $config_obj |
|
| 786 | + * @param bool $throw_errors |
|
| 787 | + * @return bool |
|
| 788 | + */ |
|
| 789 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 790 | + { |
|
| 791 | + // don't allow config updates during WP heartbeats |
|
| 792 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 793 | + return false; |
|
| 794 | + } |
|
| 795 | + $config_obj = maybe_unserialize($config_obj); |
|
| 796 | + // get class name of the incoming object |
|
| 797 | + $config_class = get_class($config_obj); |
|
| 798 | + // run tests 1-5 and 9 to verify config |
|
| 799 | + if ( |
|
| 800 | + ! $this->_verify_config_params( |
|
| 801 | + $section, |
|
| 802 | + $name, |
|
| 803 | + $config_class, |
|
| 804 | + $config_obj, |
|
| 805 | + array(1, 2, 3, 4, 7, 9) |
|
| 806 | + ) |
|
| 807 | + ) { |
|
| 808 | + return false; |
|
| 809 | + } |
|
| 810 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 811 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 812 | + if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 813 | + // save new config to db |
|
| 814 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 815 | + return true; |
|
| 816 | + } |
|
| 817 | + } else { |
|
| 818 | + // first check if the record already exists |
|
| 819 | + $existing_config = get_option($config_option_name); |
|
| 820 | + $config_obj = serialize($config_obj); |
|
| 821 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 822 | + if ($existing_config == $config_obj) { |
|
| 823 | + $this->{$section}->{$name} = $config_obj; |
|
| 824 | + return true; |
|
| 825 | + } elseif (update_option($config_option_name, $config_obj)) { |
|
| 826 | + EE_Config::log($config_option_name); |
|
| 827 | + // update wp-option for this config class |
|
| 828 | + $this->{$section}->{$name} = $config_obj; |
|
| 829 | + return true; |
|
| 830 | + } elseif ($throw_errors) { |
|
| 831 | + EE_Error::add_error( |
|
| 832 | + sprintf( |
|
| 833 | + __( |
|
| 834 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 835 | + 'event_espresso' |
|
| 836 | + ), |
|
| 837 | + $config_class, |
|
| 838 | + 'EE_Config->' . $section . '->' . $name |
|
| 839 | + ), |
|
| 840 | + __FILE__, |
|
| 841 | + __FUNCTION__, |
|
| 842 | + __LINE__ |
|
| 843 | + ); |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + return false; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * get_config |
|
| 852 | + * |
|
| 853 | + * @access public |
|
| 854 | + * @param string $section |
|
| 855 | + * @param string $name |
|
| 856 | + * @param string $config_class |
|
| 857 | + * @return mixed EE_Config_Base | NULL |
|
| 858 | + */ |
|
| 859 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 860 | + { |
|
| 861 | + // ensure config class is set to something |
|
| 862 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 863 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 864 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 865 | + return null; |
|
| 866 | + } |
|
| 867 | + // now test if the requested config object exists, but suppress errors |
|
| 868 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 869 | + // config already exists, so pass it back |
|
| 870 | + return $this->{$section}->{$name}; |
|
| 871 | + } |
|
| 872 | + // load config option from db if it exists |
|
| 873 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 874 | + // verify the newly retrieved config object, but suppress errors |
|
| 875 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 876 | + // config is good, so set it and pass it back |
|
| 877 | + $this->{$section}->{$name} = $config_obj; |
|
| 878 | + return $this->{$section}->{$name}; |
|
| 879 | + } |
|
| 880 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 881 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 882 | + // verify the newly created config object |
|
| 883 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 884 | + return $this->{$section}->{$name}; |
|
| 885 | + } else { |
|
| 886 | + EE_Error::add_error( |
|
| 887 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 888 | + __FILE__, |
|
| 889 | + __FUNCTION__, |
|
| 890 | + __LINE__ |
|
| 891 | + ); |
|
| 892 | + } |
|
| 893 | + return null; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * get_config_option |
|
| 899 | + * |
|
| 900 | + * @access public |
|
| 901 | + * @param string $config_option_name |
|
| 902 | + * @return mixed EE_Config_Base | FALSE |
|
| 903 | + */ |
|
| 904 | + public function get_config_option($config_option_name = '') |
|
| 905 | + { |
|
| 906 | + // retrieve the wp-option for this config class. |
|
| 907 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 908 | + if (empty($config_option)) { |
|
| 909 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 910 | + } |
|
| 911 | + return $config_option; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + |
|
| 915 | + /** |
|
| 916 | + * log |
|
| 917 | + * |
|
| 918 | + * @param string $config_option_name |
|
| 919 | + */ |
|
| 920 | + public static function log($config_option_name = '') |
|
| 921 | + { |
|
| 922 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 923 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 924 | + // copy incoming $_REQUEST and sanitize it so we can save it |
|
| 925 | + $_request = $_REQUEST; |
|
| 926 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 927 | + $config_log[ (string) microtime(true) ] = array( |
|
| 928 | + 'config_name' => $config_option_name, |
|
| 929 | + 'request' => $_request, |
|
| 930 | + ); |
|
| 931 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + /** |
|
| 937 | + * trim_log |
|
| 938 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 939 | + */ |
|
| 940 | + public static function trim_log() |
|
| 941 | + { |
|
| 942 | + if (! EE_Config::logging_enabled()) { |
|
| 943 | + return; |
|
| 944 | + } |
|
| 945 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 946 | + $log_length = count($config_log); |
|
| 947 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 948 | + ksort($config_log); |
|
| 949 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 950 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 951 | + } |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * get_page_for_posts |
|
| 957 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 958 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 959 | + * |
|
| 960 | + * @access public |
|
| 961 | + * @return string |
|
| 962 | + */ |
|
| 963 | + public static function get_page_for_posts() |
|
| 964 | + { |
|
| 965 | + $page_for_posts = get_option('page_for_posts'); |
|
| 966 | + if (! $page_for_posts) { |
|
| 967 | + return 'posts'; |
|
| 968 | + } |
|
| 969 | + /** @type WPDB $wpdb */ |
|
| 970 | + global $wpdb; |
|
| 971 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 972 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + /** |
|
| 977 | + * register_shortcodes_and_modules. |
|
| 978 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 979 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 980 | + * so they can help trigger maintenance mode if it's needed |
|
| 981 | + * |
|
| 982 | + * @access public |
|
| 983 | + * @return void |
|
| 984 | + */ |
|
| 985 | + public function register_shortcodes_and_modules() |
|
| 986 | + { |
|
| 987 | + // allow modules to set hooks for the rest of the system |
|
| 988 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + /** |
|
| 993 | + * initialize_shortcodes_and_modules |
|
| 994 | + * meaning they can start adding their hooks to get stuff done |
|
| 995 | + * |
|
| 996 | + * @access public |
|
| 997 | + * @return void |
|
| 998 | + */ |
|
| 999 | + public function initialize_shortcodes_and_modules() |
|
| 1000 | + { |
|
| 1001 | + // allow modules to set hooks for the rest of the system |
|
| 1002 | + $this->_initialize_modules(); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * widgets_init |
|
| 1008 | + * |
|
| 1009 | + * @access private |
|
| 1010 | + * @return void |
|
| 1011 | + */ |
|
| 1012 | + public function widgets_init() |
|
| 1013 | + { |
|
| 1014 | + // only init widgets on admin pages when not in complete maintenance, and |
|
| 1015 | + // on frontend when not in any maintenance mode |
|
| 1016 | + if ( |
|
| 1017 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 1018 | + || ( |
|
| 1019 | + is_admin() |
|
| 1020 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1021 | + ) |
|
| 1022 | + ) { |
|
| 1023 | + // grab list of installed widgets |
|
| 1024 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1025 | + // filter list of modules to register |
|
| 1026 | + $widgets_to_register = apply_filters( |
|
| 1027 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1028 | + $widgets_to_register |
|
| 1029 | + ); |
|
| 1030 | + if (! empty($widgets_to_register)) { |
|
| 1031 | + // cycle thru widget folders |
|
| 1032 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1033 | + // add to list of installed widget modules |
|
| 1034 | + EE_Config::register_ee_widget($widget_path); |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + // filter list of installed modules |
|
| 1038 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1039 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1040 | + EE_Registry::instance()->widgets |
|
| 1041 | + ); |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * register_ee_widget - makes core aware of this widget |
|
| 1048 | + * |
|
| 1049 | + * @access public |
|
| 1050 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1051 | + * @return void |
|
| 1052 | + */ |
|
| 1053 | + public static function register_ee_widget($widget_path = null) |
|
| 1054 | + { |
|
| 1055 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1056 | + $widget_ext = '.widget.php'; |
|
| 1057 | + // make all separators match |
|
| 1058 | + $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS); |
|
| 1059 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1060 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1061 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1062 | + $file_name = explode('.', basename($widget_path)); |
|
| 1063 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1064 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1065 | + // sanitize shortcode directory name |
|
| 1066 | + $widget = sanitize_key($widget); |
|
| 1067 | + // now we need to rebuild the shortcode path |
|
| 1068 | + $widget_path = explode('/', $widget_path); |
|
| 1069 | + // remove last segment |
|
| 1070 | + array_pop($widget_path); |
|
| 1071 | + // glue it back together |
|
| 1072 | + $widget_path = implode(DS, $widget_path); |
|
| 1073 | + } else { |
|
| 1074 | + // grab and sanitize widget directory name |
|
| 1075 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1076 | + } |
|
| 1077 | + // create classname from widget directory name |
|
| 1078 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1079 | + // add class prefix |
|
| 1080 | + $widget_class = 'EEW_' . $widget; |
|
| 1081 | + // does the widget exist ? |
|
| 1082 | + if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1083 | + $msg = sprintf( |
|
| 1084 | + __( |
|
| 1085 | + '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', |
|
| 1086 | + 'event_espresso' |
|
| 1087 | + ), |
|
| 1088 | + $widget_class, |
|
| 1089 | + $widget_path . '/' . $widget_class . $widget_ext |
|
| 1090 | + ); |
|
| 1091 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1092 | + return; |
|
| 1093 | + } |
|
| 1094 | + // load the widget class file |
|
| 1095 | + require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1096 | + // verify that class exists |
|
| 1097 | + if (! class_exists($widget_class)) { |
|
| 1098 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1099 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1100 | + return; |
|
| 1101 | + } |
|
| 1102 | + register_widget($widget_class); |
|
| 1103 | + // add to array of registered widgets |
|
| 1104 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * _register_modules |
|
| 1110 | + * |
|
| 1111 | + * @access private |
|
| 1112 | + * @return array |
|
| 1113 | + */ |
|
| 1114 | + private function _register_modules() |
|
| 1115 | + { |
|
| 1116 | + // grab list of installed modules |
|
| 1117 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1118 | + // filter list of modules to register |
|
| 1119 | + $modules_to_register = apply_filters( |
|
| 1120 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1121 | + $modules_to_register |
|
| 1122 | + ); |
|
| 1123 | + if (! empty($modules_to_register)) { |
|
| 1124 | + // loop through folders |
|
| 1125 | + foreach ($modules_to_register as $module_path) { |
|
| 1126 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1127 | + if ( |
|
| 1128 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1129 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1130 | + ) { |
|
| 1131 | + // add to list of installed modules |
|
| 1132 | + EE_Config::register_module($module_path); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + // filter list of installed modules |
|
| 1137 | + return apply_filters( |
|
| 1138 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1139 | + EE_Registry::instance()->modules |
|
| 1140 | + ); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * register_module - makes core aware of this module |
|
| 1146 | + * |
|
| 1147 | + * @access public |
|
| 1148 | + * @param string $module_path - full path up to and including module folder |
|
| 1149 | + * @return bool |
|
| 1150 | + */ |
|
| 1151 | + public static function register_module($module_path = null) |
|
| 1152 | + { |
|
| 1153 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1154 | + $module_ext = '.module.php'; |
|
| 1155 | + // make all separators match |
|
| 1156 | + $module_path = str_replace(array('\\', '/'), '/', $module_path); |
|
| 1157 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1158 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1159 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1160 | + $module_file = explode('.', basename($module_path)); |
|
| 1161 | + // now we need to rebuild the shortcode path |
|
| 1162 | + $module_path = explode('/', $module_path); |
|
| 1163 | + // remove last segment |
|
| 1164 | + array_pop($module_path); |
|
| 1165 | + // glue it back together |
|
| 1166 | + $module_path = implode('/', $module_path) . '/'; |
|
| 1167 | + // take first segment from file name pieces and sanitize it |
|
| 1168 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1169 | + // ensure class prefix is added |
|
| 1170 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1171 | + } else { |
|
| 1172 | + // we need to generate the filename based off of the folder name |
|
| 1173 | + // grab and sanitize module name |
|
| 1174 | + $module = strtolower(basename($module_path)); |
|
| 1175 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1176 | + // like trailingslashit() |
|
| 1177 | + $module_path = rtrim($module_path, '/') . '/'; |
|
| 1178 | + // create classname from module directory name |
|
| 1179 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1180 | + // add class prefix |
|
| 1181 | + $module_class = 'EED_' . $module; |
|
| 1182 | + } |
|
| 1183 | + // does the module exist ? |
|
| 1184 | + if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1185 | + $msg = sprintf( |
|
| 1186 | + __( |
|
| 1187 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1188 | + 'event_espresso' |
|
| 1189 | + ), |
|
| 1190 | + $module |
|
| 1191 | + ); |
|
| 1192 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1193 | + return false; |
|
| 1194 | + } |
|
| 1195 | + // load the module class file |
|
| 1196 | + require_once($module_path . $module_class . $module_ext); |
|
| 1197 | + // verify that class exists |
|
| 1198 | + if (! class_exists($module_class)) { |
|
| 1199 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1200 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1201 | + return false; |
|
| 1202 | + } |
|
| 1203 | + // add to array of registered modules |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1205 | + do_action( |
|
| 1206 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1207 | + $module_class, |
|
| 1208 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1209 | + ); |
|
| 1210 | + return true; |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * _initialize_modules |
|
| 1216 | + * allow modules to set hooks for the rest of the system |
|
| 1217 | + * |
|
| 1218 | + * @access private |
|
| 1219 | + * @return void |
|
| 1220 | + */ |
|
| 1221 | + private function _initialize_modules() |
|
| 1222 | + { |
|
| 1223 | + // cycle thru shortcode folders |
|
| 1224 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1225 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1226 | + // which set hooks ? |
|
| 1227 | + if (is_admin()) { |
|
| 1228 | + // fire immediately |
|
| 1229 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1230 | + } else { |
|
| 1231 | + // delay until other systems are online |
|
| 1232 | + add_action( |
|
| 1233 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1234 | + array($module_class, 'set_hooks') |
|
| 1235 | + ); |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * register_route - adds module method routes to route_map |
|
| 1243 | + * |
|
| 1244 | + * @access public |
|
| 1245 | + * @param string $route - "pretty" public alias for module method |
|
| 1246 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1247 | + * @param string $method_name - the actual module method to be routed to |
|
| 1248 | + * @param string $key - url param key indicating a route is being called |
|
| 1249 | + * @return bool |
|
| 1250 | + */ |
|
| 1251 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1252 | + { |
|
| 1253 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1254 | + $module = str_replace('EED_', '', $module); |
|
| 1255 | + $module_class = 'EED_' . $module; |
|
| 1256 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1257 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1258 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | + return false; |
|
| 1260 | + } |
|
| 1261 | + if (empty($route)) { |
|
| 1262 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1263 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1264 | + return false; |
|
| 1265 | + } |
|
| 1266 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1267 | + $msg = sprintf( |
|
| 1268 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1269 | + $route |
|
| 1270 | + ); |
|
| 1271 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1272 | + return false; |
|
| 1273 | + } |
|
| 1274 | + EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1275 | + return true; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * get_route - get module method route |
|
| 1281 | + * |
|
| 1282 | + * @access public |
|
| 1283 | + * @param string $route - "pretty" public alias for module method |
|
| 1284 | + * @param string $key - url param key indicating a route is being called |
|
| 1285 | + * @return string |
|
| 1286 | + */ |
|
| 1287 | + public static function get_route($route = null, $key = 'ee') |
|
| 1288 | + { |
|
| 1289 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1290 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1291 | + if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1292 | + return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1293 | + } |
|
| 1294 | + return null; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * get_routes - get ALL module method routes |
|
| 1300 | + * |
|
| 1301 | + * @access public |
|
| 1302 | + * @return array |
|
| 1303 | + */ |
|
| 1304 | + public static function get_routes() |
|
| 1305 | + { |
|
| 1306 | + return EE_Config::$_module_route_map; |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1312 | + * |
|
| 1313 | + * @access public |
|
| 1314 | + * @param string $route - "pretty" public alias for module method |
|
| 1315 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1316 | + * class, allows different forwards to be served based on status |
|
| 1317 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1318 | + * @param string $key - url param key indicating a route is being called |
|
| 1319 | + * @return bool |
|
| 1320 | + */ |
|
| 1321 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1322 | + { |
|
| 1323 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1324 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1325 | + $msg = sprintf( |
|
| 1326 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1327 | + $route |
|
| 1328 | + ); |
|
| 1329 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | + return false; |
|
| 1331 | + } |
|
| 1332 | + if (empty($forward)) { |
|
| 1333 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1334 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1335 | + return false; |
|
| 1336 | + } |
|
| 1337 | + if (is_array($forward)) { |
|
| 1338 | + if (! isset($forward[1])) { |
|
| 1339 | + $msg = sprintf( |
|
| 1340 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1341 | + $route |
|
| 1342 | + ); |
|
| 1343 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1344 | + return false; |
|
| 1345 | + } |
|
| 1346 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1347 | + $msg = sprintf( |
|
| 1348 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1349 | + $forward[1], |
|
| 1350 | + $route |
|
| 1351 | + ); |
|
| 1352 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1353 | + return false; |
|
| 1354 | + } |
|
| 1355 | + } elseif (! function_exists($forward)) { |
|
| 1356 | + $msg = sprintf( |
|
| 1357 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1358 | + $forward, |
|
| 1359 | + $route |
|
| 1360 | + ); |
|
| 1361 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1362 | + return false; |
|
| 1363 | + } |
|
| 1364 | + EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1365 | + return true; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /** |
|
| 1370 | + * get_forward - get forwarding route |
|
| 1371 | + * |
|
| 1372 | + * @access public |
|
| 1373 | + * @param string $route - "pretty" public alias for module method |
|
| 1374 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1375 | + * allows different forwards to be served based on status |
|
| 1376 | + * @param string $key - url param key indicating a route is being called |
|
| 1377 | + * @return string |
|
| 1378 | + */ |
|
| 1379 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1380 | + { |
|
| 1381 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1382 | + if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1383 | + return apply_filters( |
|
| 1384 | + 'FHEE__EE_Config__get_forward', |
|
| 1385 | + EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1386 | + $route, |
|
| 1387 | + $status |
|
| 1388 | + ); |
|
| 1389 | + } |
|
| 1390 | + return null; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1396 | + * results |
|
| 1397 | + * |
|
| 1398 | + * @access public |
|
| 1399 | + * @param string $route - "pretty" public alias for module method |
|
| 1400 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1401 | + * allows different views to be served based on status |
|
| 1402 | + * @param string $view |
|
| 1403 | + * @param string $key - url param key indicating a route is being called |
|
| 1404 | + * @return bool |
|
| 1405 | + */ |
|
| 1406 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1407 | + { |
|
| 1408 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1409 | + if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1410 | + $msg = sprintf( |
|
| 1411 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1412 | + $route |
|
| 1413 | + ); |
|
| 1414 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1415 | + return false; |
|
| 1416 | + } |
|
| 1417 | + if (! is_readable($view)) { |
|
| 1418 | + $msg = sprintf( |
|
| 1419 | + __( |
|
| 1420 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1421 | + 'event_espresso' |
|
| 1422 | + ), |
|
| 1423 | + $view |
|
| 1424 | + ); |
|
| 1425 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1426 | + return false; |
|
| 1427 | + } |
|
| 1428 | + EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1429 | + return true; |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + |
|
| 1433 | + /** |
|
| 1434 | + * get_view - get view for route and status |
|
| 1435 | + * |
|
| 1436 | + * @access public |
|
| 1437 | + * @param string $route - "pretty" public alias for module method |
|
| 1438 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1439 | + * allows different views to be served based on status |
|
| 1440 | + * @param string $key - url param key indicating a route is being called |
|
| 1441 | + * @return string |
|
| 1442 | + */ |
|
| 1443 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1444 | + { |
|
| 1445 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1446 | + if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1447 | + return apply_filters( |
|
| 1448 | + 'FHEE__EE_Config__get_view', |
|
| 1449 | + EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1450 | + $route, |
|
| 1451 | + $status |
|
| 1452 | + ); |
|
| 1453 | + } |
|
| 1454 | + return null; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + |
|
| 1458 | + public function update_addon_option_names() |
|
| 1459 | + { |
|
| 1460 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + |
|
| 1464 | + public function shutdown() |
|
| 1465 | + { |
|
| 1466 | + $this->update_addon_option_names(); |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * @return LegacyShortcodesManager |
|
| 1472 | + */ |
|
| 1473 | + public static function getLegacyShortcodesManager() |
|
| 1474 | + { |
|
| 1475 | + |
|
| 1476 | + if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1477 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1478 | + EE_Registry::instance() |
|
| 1479 | + ); |
|
| 1480 | + } |
|
| 1481 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * register_shortcode - makes core aware of this shortcode |
|
| 1487 | + * |
|
| 1488 | + * @deprecated 4.9.26 |
|
| 1489 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1490 | + * @return bool |
|
| 1491 | + */ |
|
| 1492 | + public static function register_shortcode($shortcode_path = null) |
|
| 1493 | + { |
|
| 1494 | + EE_Error::doing_it_wrong( |
|
| 1495 | + __METHOD__, |
|
| 1496 | + __( |
|
| 1497 | + '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.', |
|
| 1498 | + 'event_espresso' |
|
| 1499 | + ), |
|
| 1500 | + '4.9.26' |
|
| 1501 | + ); |
|
| 1502 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1503 | + } |
|
| 1504 | +} |
|
| 2267 | 1505 | |
| 2268 | - /** |
|
| 2269 | - * ReCaptcha Type |
|
| 2270 | - * |
|
| 2271 | - * @var string $recaptcha_type |
|
| 2272 | - * options: 'audio', 'image' |
|
| 2273 | - */ |
|
| 2274 | - public $recaptcha_type; |
|
| 1506 | +/** |
|
| 1507 | + * Base class used for config classes. These classes should generally not have |
|
| 1508 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1509 | + * basically, they should just be well-defined stdClasses |
|
| 1510 | + */ |
|
| 1511 | +class EE_Config_Base |
|
| 1512 | +{ |
|
| 2275 | 1513 | |
| 2276 | - /** |
|
| 2277 | - * ReCaptcha language |
|
| 2278 | - * |
|
| 2279 | - * @var string $recaptcha_language |
|
| 2280 | - * eg 'en' |
|
| 2281 | - */ |
|
| 2282 | - public $recaptcha_language; |
|
| 1514 | + /** |
|
| 1515 | + * Utility function for escaping the value of a property and returning. |
|
| 1516 | + * |
|
| 1517 | + * @param string $property property name (checks to see if exists). |
|
| 1518 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1519 | + * @throws \EE_Error |
|
| 1520 | + */ |
|
| 1521 | + public function get_pretty($property) |
|
| 1522 | + { |
|
| 1523 | + if (! property_exists($this, $property)) { |
|
| 1524 | + throw new EE_Error( |
|
| 1525 | + sprintf( |
|
| 1526 | + __( |
|
| 1527 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1528 | + 'event_espresso' |
|
| 1529 | + ), |
|
| 1530 | + get_class($this), |
|
| 1531 | + $property |
|
| 1532 | + ) |
|
| 1533 | + ); |
|
| 1534 | + } |
|
| 1535 | + // just handling escaping of strings for now. |
|
| 1536 | + if (is_string($this->{$property})) { |
|
| 1537 | + return stripslashes($this->{$property}); |
|
| 1538 | + } |
|
| 1539 | + return $this->{$property}; |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + |
|
| 1543 | + public function populate() |
|
| 1544 | + { |
|
| 1545 | + // grab defaults via a new instance of this class. |
|
| 1546 | + $class_name = get_class($this); |
|
| 1547 | + $defaults = new $class_name(); |
|
| 1548 | + // loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1549 | + // default from our $defaults object. |
|
| 1550 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1551 | + if ($this->{$property} === null) { |
|
| 1552 | + $this->{$property} = $value; |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + // cleanup |
|
| 1556 | + unset($defaults); |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + |
|
| 1560 | + /** |
|
| 1561 | + * __isset |
|
| 1562 | + * |
|
| 1563 | + * @param $a |
|
| 1564 | + * @return bool |
|
| 1565 | + */ |
|
| 1566 | + public function __isset($a) |
|
| 1567 | + { |
|
| 1568 | + return false; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + |
|
| 1572 | + /** |
|
| 1573 | + * __unset |
|
| 1574 | + * |
|
| 1575 | + * @param $a |
|
| 1576 | + * @return bool |
|
| 1577 | + */ |
|
| 1578 | + public function __unset($a) |
|
| 1579 | + { |
|
| 1580 | + return false; |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + |
|
| 1584 | + /** |
|
| 1585 | + * __clone |
|
| 1586 | + */ |
|
| 1587 | + public function __clone() |
|
| 1588 | + { |
|
| 1589 | + } |
|
| 1590 | + |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * __wakeup |
|
| 1594 | + */ |
|
| 1595 | + public function __wakeup() |
|
| 1596 | + { |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + /** |
|
| 1601 | + * __destruct |
|
| 1602 | + */ |
|
| 1603 | + public function __destruct() |
|
| 1604 | + { |
|
| 1605 | + } |
|
| 1606 | +} |
|
| 2283 | 1607 | |
| 2284 | - /** |
|
| 2285 | - * ReCaptcha public key |
|
| 2286 | - * |
|
| 2287 | - * @var string $recaptcha_publickey |
|
| 2288 | - */ |
|
| 2289 | - public $recaptcha_publickey; |
|
| 1608 | +/** |
|
| 1609 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1610 | + */ |
|
| 1611 | +class EE_Core_Config extends EE_Config_Base |
|
| 1612 | +{ |
|
| 2290 | 1613 | |
| 2291 | - /** |
|
| 2292 | - * ReCaptcha private key |
|
| 2293 | - * |
|
| 2294 | - * @var string $recaptcha_privatekey |
|
| 2295 | - */ |
|
| 2296 | - public $recaptcha_privatekey; |
|
| 1614 | + const OPTION_NAME_UXIP = 'ee_ueip_optin'; |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + public $current_blog_id; |
|
| 1618 | + |
|
| 1619 | + public $ee_ueip_optin; |
|
| 1620 | + |
|
| 1621 | + public $ee_ueip_has_notified; |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * Not to be confused with the 4 critical page variables (See |
|
| 1625 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1626 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1627 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1628 | + * |
|
| 1629 | + * @var array |
|
| 1630 | + */ |
|
| 1631 | + public $post_shortcodes; |
|
| 1632 | + |
|
| 1633 | + public $module_route_map; |
|
| 1634 | + |
|
| 1635 | + public $module_forward_map; |
|
| 1636 | + |
|
| 1637 | + public $module_view_map; |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1641 | + * |
|
| 1642 | + * @var int |
|
| 1643 | + */ |
|
| 1644 | + public $reg_page_id; |
|
| 1645 | + |
|
| 1646 | + public $txn_page_id; |
|
| 1647 | + |
|
| 1648 | + public $thank_you_page_id; |
|
| 1649 | + |
|
| 1650 | + public $cancel_page_id; |
|
| 1651 | + |
|
| 1652 | + /** |
|
| 1653 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1654 | + * |
|
| 1655 | + * @var int |
|
| 1656 | + */ |
|
| 1657 | + public $reg_page_url; |
|
| 1658 | + |
|
| 1659 | + public $txn_page_url; |
|
| 1660 | + |
|
| 1661 | + public $thank_you_page_url; |
|
| 1662 | + |
|
| 1663 | + public $cancel_page_url; |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1667 | + */ |
|
| 1668 | + public $event_cpt_slug; |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1672 | + * request across blog switches in a multisite context. |
|
| 1673 | + * Avoids extra queries to the db for this option. |
|
| 1674 | + * |
|
| 1675 | + * @var bool |
|
| 1676 | + */ |
|
| 1677 | + public static $ee_ueip_option; |
|
| 1678 | + |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * class constructor |
|
| 1682 | + * |
|
| 1683 | + * @access public |
|
| 1684 | + */ |
|
| 1685 | + public function __construct() |
|
| 1686 | + { |
|
| 1687 | + // set default organization settings |
|
| 1688 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1689 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1690 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1691 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1692 | + $this->post_shortcodes = array(); |
|
| 1693 | + $this->module_route_map = array(); |
|
| 1694 | + $this->module_forward_map = array(); |
|
| 1695 | + $this->module_view_map = array(); |
|
| 1696 | + // critical EE page IDs |
|
| 1697 | + $this->reg_page_id = 0; |
|
| 1698 | + $this->txn_page_id = 0; |
|
| 1699 | + $this->thank_you_page_id = 0; |
|
| 1700 | + $this->cancel_page_id = 0; |
|
| 1701 | + // critical EE page URLs |
|
| 1702 | + $this->reg_page_url = ''; |
|
| 1703 | + $this->txn_page_url = ''; |
|
| 1704 | + $this->thank_you_page_url = ''; |
|
| 1705 | + $this->cancel_page_url = ''; |
|
| 1706 | + // cpt slugs |
|
| 1707 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1708 | + // ueip constant check |
|
| 1709 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1710 | + $this->ee_ueip_optin = false; |
|
| 1711 | + $this->ee_ueip_has_notified = true; |
|
| 1712 | + } |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + |
|
| 1716 | + /** |
|
| 1717 | + * @return array |
|
| 1718 | + */ |
|
| 1719 | + public function get_critical_pages_array() |
|
| 1720 | + { |
|
| 1721 | + return array( |
|
| 1722 | + $this->reg_page_id, |
|
| 1723 | + $this->txn_page_id, |
|
| 1724 | + $this->thank_you_page_id, |
|
| 1725 | + $this->cancel_page_id, |
|
| 1726 | + ); |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * @return array |
|
| 1732 | + */ |
|
| 1733 | + public function get_critical_pages_shortcodes_array() |
|
| 1734 | + { |
|
| 1735 | + return array( |
|
| 1736 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1737 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1738 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1739 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1740 | + ); |
|
| 1741 | + } |
|
| 1742 | + |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * gets/returns URL for EE reg_page |
|
| 1746 | + * |
|
| 1747 | + * @access public |
|
| 1748 | + * @return string |
|
| 1749 | + */ |
|
| 1750 | + public function reg_page_url() |
|
| 1751 | + { |
|
| 1752 | + if (! $this->reg_page_url) { |
|
| 1753 | + $this->reg_page_url = add_query_arg( |
|
| 1754 | + array('uts' => time()), |
|
| 1755 | + get_permalink($this->reg_page_id) |
|
| 1756 | + ) . '#checkout'; |
|
| 1757 | + } |
|
| 1758 | + return $this->reg_page_url; |
|
| 1759 | + } |
|
| 1760 | + |
|
| 1761 | + |
|
| 1762 | + /** |
|
| 1763 | + * gets/returns URL for EE txn_page |
|
| 1764 | + * |
|
| 1765 | + * @param array $query_args like what gets passed to |
|
| 1766 | + * add_query_arg() as the first argument |
|
| 1767 | + * @access public |
|
| 1768 | + * @return string |
|
| 1769 | + */ |
|
| 1770 | + public function txn_page_url($query_args = array()) |
|
| 1771 | + { |
|
| 1772 | + if (! $this->txn_page_url) { |
|
| 1773 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1774 | + } |
|
| 1775 | + if ($query_args) { |
|
| 1776 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1777 | + } else { |
|
| 1778 | + return $this->txn_page_url; |
|
| 1779 | + } |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + |
|
| 1783 | + /** |
|
| 1784 | + * gets/returns URL for EE thank_you_page |
|
| 1785 | + * |
|
| 1786 | + * @param array $query_args like what gets passed to |
|
| 1787 | + * add_query_arg() as the first argument |
|
| 1788 | + * @access public |
|
| 1789 | + * @return string |
|
| 1790 | + */ |
|
| 1791 | + public function thank_you_page_url($query_args = array()) |
|
| 1792 | + { |
|
| 1793 | + if (! $this->thank_you_page_url) { |
|
| 1794 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1795 | + } |
|
| 1796 | + if ($query_args) { |
|
| 1797 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1798 | + } else { |
|
| 1799 | + return $this->thank_you_page_url; |
|
| 1800 | + } |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + |
|
| 1804 | + /** |
|
| 1805 | + * gets/returns URL for EE cancel_page |
|
| 1806 | + * |
|
| 1807 | + * @access public |
|
| 1808 | + * @return string |
|
| 1809 | + */ |
|
| 1810 | + public function cancel_page_url() |
|
| 1811 | + { |
|
| 1812 | + if (! $this->cancel_page_url) { |
|
| 1813 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1814 | + } |
|
| 1815 | + return $this->cancel_page_url; |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1821 | + * |
|
| 1822 | + * @since 4.7.5 |
|
| 1823 | + */ |
|
| 1824 | + protected function _reset_urls() |
|
| 1825 | + { |
|
| 1826 | + $this->reg_page_url = ''; |
|
| 1827 | + $this->txn_page_url = ''; |
|
| 1828 | + $this->cancel_page_url = ''; |
|
| 1829 | + $this->thank_you_page_url = ''; |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + |
|
| 1833 | + /** |
|
| 1834 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
| 1835 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1836 | + * on the main site only. |
|
| 1837 | + * |
|
| 1838 | + * @return bool |
|
| 1839 | + */ |
|
| 1840 | + protected function _get_main_ee_ueip_optin() |
|
| 1841 | + { |
|
| 1842 | + // if this is the main site then we can just bypass our direct query. |
|
| 1843 | + if (is_main_site()) { |
|
| 1844 | + return get_option(self::OPTION_NAME_UXIP, false); |
|
| 1845 | + } |
|
| 1846 | + // is this already cached for this request? If so use it. |
|
| 1847 | + if (EE_Core_Config::$ee_ueip_option !== null) { |
|
| 1848 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1849 | + } |
|
| 1850 | + global $wpdb; |
|
| 1851 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1852 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1853 | + $option = self::OPTION_NAME_UXIP; |
|
| 1854 | + // set correct table for query |
|
| 1855 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1856 | + // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1857 | + // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1858 | + // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1859 | + // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1860 | + // for the purpose of caching. |
|
| 1861 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1862 | + if (false !== $pre) { |
|
| 1863 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1864 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1865 | + } |
|
| 1866 | + $row = $wpdb->get_row( |
|
| 1867 | + $wpdb->prepare( |
|
| 1868 | + "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1869 | + $option |
|
| 1870 | + ) |
|
| 1871 | + ); |
|
| 1872 | + if (is_object($row)) { |
|
| 1873 | + $value = $row->option_value; |
|
| 1874 | + } else { // option does not exist so use default. |
|
| 1875 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1876 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1877 | + } |
|
| 1878 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1879 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * Utility function for escaping the value of a property and returning. |
|
| 1885 | + * |
|
| 1886 | + * @param string $property property name (checks to see if exists). |
|
| 1887 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1888 | + * @throws \EE_Error |
|
| 1889 | + */ |
|
| 1890 | + public function get_pretty($property) |
|
| 1891 | + { |
|
| 1892 | + if ($property === self::OPTION_NAME_UXIP) { |
|
| 1893 | + return $this->ee_ueip_optin ? 'yes' : 'no'; |
|
| 1894 | + } |
|
| 1895 | + return parent::get_pretty($property); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + |
|
| 1899 | + /** |
|
| 1900 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1901 | + * on the object. |
|
| 1902 | + * |
|
| 1903 | + * @return array |
|
| 1904 | + */ |
|
| 1905 | + public function __sleep() |
|
| 1906 | + { |
|
| 1907 | + // reset all url properties |
|
| 1908 | + $this->_reset_urls(); |
|
| 1909 | + // return what to save to db |
|
| 1910 | + return array_keys(get_object_vars($this)); |
|
| 1911 | + } |
|
| 1912 | +} |
|
| 2297 | 1913 | |
| 2298 | - /** |
|
| 2299 | - * array of form names protected by ReCaptcha |
|
| 2300 | - * |
|
| 2301 | - * @var array $recaptcha_protected_forms |
|
| 2302 | - */ |
|
| 2303 | - public $recaptcha_protected_forms; |
|
| 1914 | +/** |
|
| 1915 | + * Config class for storing info on the Organization |
|
| 1916 | + */ |
|
| 1917 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1918 | +{ |
|
| 2304 | 1919 | |
| 2305 | - /** |
|
| 2306 | - * ReCaptcha width |
|
| 2307 | - * |
|
| 2308 | - * @var int $recaptcha_width |
|
| 2309 | - * @deprecated |
|
| 2310 | - */ |
|
| 2311 | - public $recaptcha_width; |
|
| 1920 | + /** |
|
| 1921 | + * @var string $name |
|
| 1922 | + * eg EE4.1 |
|
| 1923 | + */ |
|
| 1924 | + public $name; |
|
| 1925 | + |
|
| 1926 | + /** |
|
| 1927 | + * @var string $address_1 |
|
| 1928 | + * eg 123 Onna Road |
|
| 1929 | + */ |
|
| 1930 | + public $address_1 = ''; |
|
| 1931 | + |
|
| 1932 | + /** |
|
| 1933 | + * @var string $address_2 |
|
| 1934 | + * eg PO Box 123 |
|
| 1935 | + */ |
|
| 1936 | + public $address_2 = ''; |
|
| 1937 | + |
|
| 1938 | + /** |
|
| 1939 | + * @var string $city |
|
| 1940 | + * eg Inna City |
|
| 1941 | + */ |
|
| 1942 | + public $city = ''; |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * @var int $STA_ID |
|
| 1946 | + * eg 4 |
|
| 1947 | + */ |
|
| 1948 | + public $STA_ID = 0; |
|
| 1949 | + |
|
| 1950 | + /** |
|
| 1951 | + * @var string $CNT_ISO |
|
| 1952 | + * eg US |
|
| 1953 | + */ |
|
| 1954 | + public $CNT_ISO = ''; |
|
| 1955 | + |
|
| 1956 | + /** |
|
| 1957 | + * @var string $zip |
|
| 1958 | + * eg 12345 or V1A 2B3 |
|
| 1959 | + */ |
|
| 1960 | + public $zip = ''; |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * @var string $email |
|
| 1964 | + * eg [email protected] |
|
| 1965 | + */ |
|
| 1966 | + public $email; |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * @var string $phone |
|
| 1970 | + * eg. 111-111-1111 |
|
| 1971 | + */ |
|
| 1972 | + public $phone = ''; |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * @var string $vat |
|
| 1976 | + * VAT/Tax Number |
|
| 1977 | + */ |
|
| 1978 | + public $vat = ''; |
|
| 1979 | + |
|
| 1980 | + /** |
|
| 1981 | + * @var string $logo_url |
|
| 1982 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 1983 | + */ |
|
| 1984 | + public $logo_url = ''; |
|
| 1985 | + |
|
| 1986 | + /** |
|
| 1987 | + * The below are all various properties for holding links to organization social network profiles |
|
| 1988 | + * |
|
| 1989 | + * @var string |
|
| 1990 | + */ |
|
| 1991 | + /** |
|
| 1992 | + * facebook (facebook.com/profile.name) |
|
| 1993 | + * |
|
| 1994 | + * @var string |
|
| 1995 | + */ |
|
| 1996 | + public $facebook = ''; |
|
| 1997 | + |
|
| 1998 | + /** |
|
| 1999 | + * twitter (twitter.com/twitter_handle) |
|
| 2000 | + * |
|
| 2001 | + * @var string |
|
| 2002 | + */ |
|
| 2003 | + public $twitter = ''; |
|
| 2004 | + |
|
| 2005 | + /** |
|
| 2006 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2007 | + * |
|
| 2008 | + * @var string |
|
| 2009 | + */ |
|
| 2010 | + public $linkedin = ''; |
|
| 2011 | + |
|
| 2012 | + /** |
|
| 2013 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2014 | + * |
|
| 2015 | + * @var string |
|
| 2016 | + */ |
|
| 2017 | + public $pinterest = ''; |
|
| 2018 | + |
|
| 2019 | + /** |
|
| 2020 | + * google+ (google.com/+profileName) |
|
| 2021 | + * |
|
| 2022 | + * @var string |
|
| 2023 | + */ |
|
| 2024 | + public $google = ''; |
|
| 2025 | + |
|
| 2026 | + /** |
|
| 2027 | + * instagram (instagram.com/handle) |
|
| 2028 | + * |
|
| 2029 | + * @var string |
|
| 2030 | + */ |
|
| 2031 | + public $instagram = ''; |
|
| 2032 | + |
|
| 2033 | + |
|
| 2034 | + /** |
|
| 2035 | + * class constructor |
|
| 2036 | + * |
|
| 2037 | + * @access public |
|
| 2038 | + */ |
|
| 2039 | + public function __construct() |
|
| 2040 | + { |
|
| 2041 | + // set default organization settings |
|
| 2042 | + // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded |
|
| 2043 | + $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
|
| 2044 | + $this->email = get_bloginfo('admin_email'); |
|
| 2045 | + } |
|
| 2046 | +} |
|
| 2312 | 2047 | |
| 2313 | - /** |
|
| 2314 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2315 | - * |
|
| 2316 | - * @var boolean $track_invalid_checkout_access |
|
| 2317 | - */ |
|
| 2318 | - protected $track_invalid_checkout_access = true; |
|
| 2048 | +/** |
|
| 2049 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2050 | + */ |
|
| 2051 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2052 | +{ |
|
| 2319 | 2053 | |
| 2320 | - /** |
|
| 2321 | - * Whether or not to show the privacy policy consent checkbox |
|
| 2322 | - * |
|
| 2323 | - * @var bool |
|
| 2324 | - */ |
|
| 2325 | - public $consent_checkbox_enabled; |
|
| 2054 | + /** |
|
| 2055 | + * @var string $code |
|
| 2056 | + * eg 'US' |
|
| 2057 | + */ |
|
| 2058 | + public $code; |
|
| 2059 | + |
|
| 2060 | + /** |
|
| 2061 | + * @var string $name |
|
| 2062 | + * eg 'Dollar' |
|
| 2063 | + */ |
|
| 2064 | + public $name; |
|
| 2065 | + |
|
| 2066 | + /** |
|
| 2067 | + * plural name |
|
| 2068 | + * |
|
| 2069 | + * @var string $plural |
|
| 2070 | + * eg 'Dollars' |
|
| 2071 | + */ |
|
| 2072 | + public $plural; |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * currency sign |
|
| 2076 | + * |
|
| 2077 | + * @var string $sign |
|
| 2078 | + * eg '$' |
|
| 2079 | + */ |
|
| 2080 | + public $sign; |
|
| 2081 | + |
|
| 2082 | + /** |
|
| 2083 | + * Whether the currency sign should come before the number or not |
|
| 2084 | + * |
|
| 2085 | + * @var boolean $sign_b4 |
|
| 2086 | + */ |
|
| 2087 | + public $sign_b4; |
|
| 2088 | + |
|
| 2089 | + /** |
|
| 2090 | + * How many digits should come after the decimal place |
|
| 2091 | + * |
|
| 2092 | + * @var int $dec_plc |
|
| 2093 | + */ |
|
| 2094 | + public $dec_plc; |
|
| 2095 | + |
|
| 2096 | + /** |
|
| 2097 | + * Symbol to use for decimal mark |
|
| 2098 | + * |
|
| 2099 | + * @var string $dec_mrk |
|
| 2100 | + * eg '.' |
|
| 2101 | + */ |
|
| 2102 | + public $dec_mrk; |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * Symbol to use for thousands |
|
| 2106 | + * |
|
| 2107 | + * @var string $thsnds |
|
| 2108 | + * eg ',' |
|
| 2109 | + */ |
|
| 2110 | + public $thsnds; |
|
| 2111 | + |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * class constructor |
|
| 2115 | + * |
|
| 2116 | + * @access public |
|
| 2117 | + * @param string $CNT_ISO |
|
| 2118 | + * @throws \EE_Error |
|
| 2119 | + */ |
|
| 2120 | + public function __construct($CNT_ISO = '') |
|
| 2121 | + { |
|
| 2122 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2123 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2124 | + // get country code from organization settings or use default |
|
| 2125 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
| 2126 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
| 2127 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
| 2128 | + : ''; |
|
| 2129 | + // but override if requested |
|
| 2130 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
| 2131 | + // 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 |
|
| 2132 | + if ( |
|
| 2133 | + ! empty($CNT_ISO) |
|
| 2134 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2135 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2136 | + ) { |
|
| 2137 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2138 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2139 | + if ($country instanceof EE_Country) { |
|
| 2140 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2141 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2142 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2143 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2144 | + $this->sign_b4 = $country->currency_sign_before( |
|
| 2145 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2146 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2147 | + $this->dec_mrk = $country->currency_decimal_mark( |
|
| 2148 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2149 | + $this->thsnds = $country->currency_thousands_separator( |
|
| 2150 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | + } |
|
| 2152 | + } |
|
| 2153 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2154 | + if (empty($this->code)) { |
|
| 2155 | + // set default currency settings |
|
| 2156 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2157 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2158 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2159 | + $this->sign = '$'; // currency sign: $ |
|
| 2160 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2161 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2162 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2163 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2164 | + } |
|
| 2165 | + } |
|
| 2166 | +} |
|
| 2326 | 2167 | |
| 2327 | - /** |
|
| 2328 | - * Label text to show on the checkbox |
|
| 2329 | - * |
|
| 2330 | - * @var string |
|
| 2331 | - */ |
|
| 2332 | - public $consent_checkbox_label_text; |
|
| 2168 | +/** |
|
| 2169 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2170 | + */ |
|
| 2171 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2172 | +{ |
|
| 2333 | 2173 | |
| 2334 | - /* |
|
| 2174 | + /** |
|
| 2175 | + * Default registration status |
|
| 2176 | + * |
|
| 2177 | + * @var string $default_STS_ID |
|
| 2178 | + * eg 'RPP' |
|
| 2179 | + */ |
|
| 2180 | + public $default_STS_ID; |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2184 | + * registrations) |
|
| 2185 | + * |
|
| 2186 | + * @var int |
|
| 2187 | + */ |
|
| 2188 | + public $default_maximum_number_of_tickets; |
|
| 2189 | + |
|
| 2190 | + /** |
|
| 2191 | + * level of validation to apply to email addresses |
|
| 2192 | + * |
|
| 2193 | + * @var string $email_validation_level |
|
| 2194 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2195 | + */ |
|
| 2196 | + public $email_validation_level; |
|
| 2197 | + |
|
| 2198 | + /** |
|
| 2199 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2200 | + * |
|
| 2201 | + * @var boolean $show_pending_payment_options |
|
| 2202 | + */ |
|
| 2203 | + public $show_pending_payment_options; |
|
| 2204 | + |
|
| 2205 | + /** |
|
| 2206 | + * Whether to skip the registration confirmation page |
|
| 2207 | + * |
|
| 2208 | + * @var boolean $skip_reg_confirmation |
|
| 2209 | + */ |
|
| 2210 | + public $skip_reg_confirmation; |
|
| 2211 | + |
|
| 2212 | + /** |
|
| 2213 | + * an array of SPCO reg steps where: |
|
| 2214 | + * the keys denotes the reg step order |
|
| 2215 | + * each element consists of an array with the following elements: |
|
| 2216 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2217 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2218 | + * "slug" => the URL param used to trigger the reg step |
|
| 2219 | + * |
|
| 2220 | + * @var array $reg_steps |
|
| 2221 | + */ |
|
| 2222 | + public $reg_steps; |
|
| 2223 | + |
|
| 2224 | + /** |
|
| 2225 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2226 | + * |
|
| 2227 | + * @var boolean $reg_confirmation_last |
|
| 2228 | + */ |
|
| 2229 | + public $reg_confirmation_last; |
|
| 2230 | + |
|
| 2231 | + /** |
|
| 2232 | + * Whether or not to enable the EE Bot Trap |
|
| 2233 | + * |
|
| 2234 | + * @var boolean $use_bot_trap |
|
| 2235 | + */ |
|
| 2236 | + public $use_bot_trap; |
|
| 2237 | + |
|
| 2238 | + /** |
|
| 2239 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2240 | + * |
|
| 2241 | + * @var boolean $use_encryption |
|
| 2242 | + */ |
|
| 2243 | + public $use_encryption; |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * Whether or not to use ReCaptcha |
|
| 2247 | + * |
|
| 2248 | + * @var boolean $use_captcha |
|
| 2249 | + */ |
|
| 2250 | + public $use_captcha; |
|
| 2251 | + |
|
| 2252 | + /** |
|
| 2253 | + * ReCaptcha Theme |
|
| 2254 | + * |
|
| 2255 | + * @var string $recaptcha_theme |
|
| 2256 | + * options: 'dark', 'light', 'invisible' |
|
| 2257 | + */ |
|
| 2258 | + public $recaptcha_theme; |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
| 2262 | + * |
|
| 2263 | + * @var string $recaptcha_badge |
|
| 2264 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
| 2265 | + */ |
|
| 2266 | + public $recaptcha_badge; |
|
| 2267 | + |
|
| 2268 | + /** |
|
| 2269 | + * ReCaptcha Type |
|
| 2270 | + * |
|
| 2271 | + * @var string $recaptcha_type |
|
| 2272 | + * options: 'audio', 'image' |
|
| 2273 | + */ |
|
| 2274 | + public $recaptcha_type; |
|
| 2275 | + |
|
| 2276 | + /** |
|
| 2277 | + * ReCaptcha language |
|
| 2278 | + * |
|
| 2279 | + * @var string $recaptcha_language |
|
| 2280 | + * eg 'en' |
|
| 2281 | + */ |
|
| 2282 | + public $recaptcha_language; |
|
| 2283 | + |
|
| 2284 | + /** |
|
| 2285 | + * ReCaptcha public key |
|
| 2286 | + * |
|
| 2287 | + * @var string $recaptcha_publickey |
|
| 2288 | + */ |
|
| 2289 | + public $recaptcha_publickey; |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * ReCaptcha private key |
|
| 2293 | + * |
|
| 2294 | + * @var string $recaptcha_privatekey |
|
| 2295 | + */ |
|
| 2296 | + public $recaptcha_privatekey; |
|
| 2297 | + |
|
| 2298 | + /** |
|
| 2299 | + * array of form names protected by ReCaptcha |
|
| 2300 | + * |
|
| 2301 | + * @var array $recaptcha_protected_forms |
|
| 2302 | + */ |
|
| 2303 | + public $recaptcha_protected_forms; |
|
| 2304 | + |
|
| 2305 | + /** |
|
| 2306 | + * ReCaptcha width |
|
| 2307 | + * |
|
| 2308 | + * @var int $recaptcha_width |
|
| 2309 | + * @deprecated |
|
| 2310 | + */ |
|
| 2311 | + public $recaptcha_width; |
|
| 2312 | + |
|
| 2313 | + /** |
|
| 2314 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2315 | + * |
|
| 2316 | + * @var boolean $track_invalid_checkout_access |
|
| 2317 | + */ |
|
| 2318 | + protected $track_invalid_checkout_access = true; |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * Whether or not to show the privacy policy consent checkbox |
|
| 2322 | + * |
|
| 2323 | + * @var bool |
|
| 2324 | + */ |
|
| 2325 | + public $consent_checkbox_enabled; |
|
| 2326 | + |
|
| 2327 | + /** |
|
| 2328 | + * Label text to show on the checkbox |
|
| 2329 | + * |
|
| 2330 | + * @var string |
|
| 2331 | + */ |
|
| 2332 | + public $consent_checkbox_label_text; |
|
| 2333 | + |
|
| 2334 | + /* |
|
| 2335 | 2335 | * String describing how long to keep payment logs. Passed into DateTime constructor |
| 2336 | 2336 | * @var string |
| 2337 | 2337 | */ |
| 2338 | - public $gateway_log_lifespan = '1 week'; |
|
| 2339 | - |
|
| 2340 | - /** |
|
| 2341 | - * Enable copy attendee info at form |
|
| 2342 | - * |
|
| 2343 | - * @var boolean $enable_copy_attendee |
|
| 2344 | - */ |
|
| 2345 | - protected $copy_attendee_info = true; |
|
| 2346 | - |
|
| 2347 | - |
|
| 2348 | - /** |
|
| 2349 | - * class constructor |
|
| 2350 | - * |
|
| 2351 | - * @access public |
|
| 2352 | - */ |
|
| 2353 | - public function __construct() |
|
| 2354 | - { |
|
| 2355 | - // set default registration settings |
|
| 2356 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2357 | - $this->email_validation_level = 'wp_default'; |
|
| 2358 | - $this->show_pending_payment_options = true; |
|
| 2359 | - $this->skip_reg_confirmation = true; |
|
| 2360 | - $this->reg_steps = array(); |
|
| 2361 | - $this->reg_confirmation_last = false; |
|
| 2362 | - $this->use_bot_trap = true; |
|
| 2363 | - $this->use_encryption = true; |
|
| 2364 | - $this->use_captcha = false; |
|
| 2365 | - $this->recaptcha_theme = 'light'; |
|
| 2366 | - $this->recaptcha_badge = 'bottomleft'; |
|
| 2367 | - $this->recaptcha_type = 'image'; |
|
| 2368 | - $this->recaptcha_language = 'en'; |
|
| 2369 | - $this->recaptcha_publickey = null; |
|
| 2370 | - $this->recaptcha_privatekey = null; |
|
| 2371 | - $this->recaptcha_protected_forms = array(); |
|
| 2372 | - $this->recaptcha_width = 500; |
|
| 2373 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2374 | - $this->consent_checkbox_enabled = false; |
|
| 2375 | - $this->consent_checkbox_label_text = ''; |
|
| 2376 | - $this->gateway_log_lifespan = '7 days'; |
|
| 2377 | - $this->copy_attendee_info = true; |
|
| 2378 | - } |
|
| 2379 | - |
|
| 2380 | - |
|
| 2381 | - /** |
|
| 2382 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2383 | - * |
|
| 2384 | - * @since 4.8.8.rc.019 |
|
| 2385 | - */ |
|
| 2386 | - public function do_hooks() |
|
| 2387 | - { |
|
| 2388 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2389 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2390 | - add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2391 | - } |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - /** |
|
| 2395 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2396 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2397 | - */ |
|
| 2398 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2399 | - { |
|
| 2400 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2401 | - } |
|
| 2402 | - |
|
| 2403 | - |
|
| 2404 | - /** |
|
| 2405 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2406 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2407 | - */ |
|
| 2408 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2409 | - { |
|
| 2410 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2411 | - } |
|
| 2412 | - |
|
| 2413 | - |
|
| 2414 | - /** |
|
| 2415 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2416 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2417 | - * |
|
| 2418 | - * @throws InvalidArgumentException |
|
| 2419 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2420 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2421 | - */ |
|
| 2422 | - public function setDefaultCheckboxLabelText() |
|
| 2423 | - { |
|
| 2424 | - if ( |
|
| 2425 | - $this->getConsentCheckboxLabelText() === null |
|
| 2426 | - || $this->getConsentCheckboxLabelText() === '' |
|
| 2427 | - ) { |
|
| 2428 | - $opening_a_tag = ''; |
|
| 2429 | - $closing_a_tag = ''; |
|
| 2430 | - if (function_exists('get_privacy_policy_url')) { |
|
| 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">'; |
|
| 2434 | - $closing_a_tag = '</a>'; |
|
| 2435 | - } |
|
| 2436 | - } |
|
| 2437 | - $loader = LoaderFactory::getLoader(); |
|
| 2438 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2439 | - /** |
|
| 2440 | - * @var $org_config EE_Organization_Config |
|
| 2441 | - */ |
|
| 2442 | - |
|
| 2443 | - $this->setConsentCheckboxLabelText( |
|
| 2444 | - sprintf( |
|
| 2445 | - esc_html__( |
|
| 2446 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2447 | - 'event_espresso' |
|
| 2448 | - ), |
|
| 2449 | - $org_config->name, |
|
| 2450 | - $opening_a_tag, |
|
| 2451 | - $closing_a_tag |
|
| 2452 | - ) |
|
| 2453 | - ); |
|
| 2454 | - } |
|
| 2455 | - } |
|
| 2456 | - |
|
| 2457 | - |
|
| 2458 | - /** |
|
| 2459 | - * @return boolean |
|
| 2460 | - */ |
|
| 2461 | - public function track_invalid_checkout_access() |
|
| 2462 | - { |
|
| 2463 | - return $this->track_invalid_checkout_access; |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - |
|
| 2467 | - /** |
|
| 2468 | - * @param boolean $track_invalid_checkout_access |
|
| 2469 | - */ |
|
| 2470 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2471 | - { |
|
| 2472 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2473 | - $track_invalid_checkout_access, |
|
| 2474 | - FILTER_VALIDATE_BOOLEAN |
|
| 2475 | - ); |
|
| 2476 | - } |
|
| 2477 | - |
|
| 2478 | - /** |
|
| 2479 | - * @return boolean |
|
| 2480 | - */ |
|
| 2481 | - public function copyAttendeeInfo() |
|
| 2482 | - { |
|
| 2483 | - return $this->copy_attendee_info; |
|
| 2484 | - } |
|
| 2485 | - |
|
| 2486 | - |
|
| 2487 | - /** |
|
| 2488 | - * @param boolean $copy_attendee_info |
|
| 2489 | - */ |
|
| 2490 | - public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2491 | - { |
|
| 2492 | - $this->copy_attendee_info = filter_var( |
|
| 2493 | - $copy_attendee_info, |
|
| 2494 | - FILTER_VALIDATE_BOOLEAN |
|
| 2495 | - ); |
|
| 2496 | - } |
|
| 2497 | - |
|
| 2498 | - |
|
| 2499 | - /** |
|
| 2500 | - * Gets the options to make availalbe for the gateway log lifespan |
|
| 2501 | - * @return array |
|
| 2502 | - */ |
|
| 2503 | - public function gatewayLogLifespanOptions() |
|
| 2504 | - { |
|
| 2505 | - return (array) apply_filters( |
|
| 2506 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2507 | - array( |
|
| 2508 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2509 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2510 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2511 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2512 | - '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2513 | - ) |
|
| 2514 | - ); |
|
| 2515 | - } |
|
| 2516 | - |
|
| 2517 | - |
|
| 2518 | - /** |
|
| 2519 | - * @return bool |
|
| 2520 | - */ |
|
| 2521 | - public function isConsentCheckboxEnabled() |
|
| 2522 | - { |
|
| 2523 | - return $this->consent_checkbox_enabled; |
|
| 2524 | - } |
|
| 2525 | - |
|
| 2526 | - |
|
| 2527 | - /** |
|
| 2528 | - * @param bool $consent_checkbox_enabled |
|
| 2529 | - */ |
|
| 2530 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2531 | - { |
|
| 2532 | - $this->consent_checkbox_enabled = filter_var( |
|
| 2533 | - $consent_checkbox_enabled, |
|
| 2534 | - FILTER_VALIDATE_BOOLEAN |
|
| 2535 | - ); |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - |
|
| 2539 | - /** |
|
| 2540 | - * @return string |
|
| 2541 | - */ |
|
| 2542 | - public function getConsentCheckboxLabelText() |
|
| 2543 | - { |
|
| 2544 | - return $this->consent_checkbox_label_text; |
|
| 2545 | - } |
|
| 2546 | - |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @param string $consent_checkbox_label_text |
|
| 2550 | - */ |
|
| 2551 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2552 | - { |
|
| 2553 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2554 | - } |
|
| 2338 | + public $gateway_log_lifespan = '1 week'; |
|
| 2339 | + |
|
| 2340 | + /** |
|
| 2341 | + * Enable copy attendee info at form |
|
| 2342 | + * |
|
| 2343 | + * @var boolean $enable_copy_attendee |
|
| 2344 | + */ |
|
| 2345 | + protected $copy_attendee_info = true; |
|
| 2346 | + |
|
| 2347 | + |
|
| 2348 | + /** |
|
| 2349 | + * class constructor |
|
| 2350 | + * |
|
| 2351 | + * @access public |
|
| 2352 | + */ |
|
| 2353 | + public function __construct() |
|
| 2354 | + { |
|
| 2355 | + // set default registration settings |
|
| 2356 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2357 | + $this->email_validation_level = 'wp_default'; |
|
| 2358 | + $this->show_pending_payment_options = true; |
|
| 2359 | + $this->skip_reg_confirmation = true; |
|
| 2360 | + $this->reg_steps = array(); |
|
| 2361 | + $this->reg_confirmation_last = false; |
|
| 2362 | + $this->use_bot_trap = true; |
|
| 2363 | + $this->use_encryption = true; |
|
| 2364 | + $this->use_captcha = false; |
|
| 2365 | + $this->recaptcha_theme = 'light'; |
|
| 2366 | + $this->recaptcha_badge = 'bottomleft'; |
|
| 2367 | + $this->recaptcha_type = 'image'; |
|
| 2368 | + $this->recaptcha_language = 'en'; |
|
| 2369 | + $this->recaptcha_publickey = null; |
|
| 2370 | + $this->recaptcha_privatekey = null; |
|
| 2371 | + $this->recaptcha_protected_forms = array(); |
|
| 2372 | + $this->recaptcha_width = 500; |
|
| 2373 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2374 | + $this->consent_checkbox_enabled = false; |
|
| 2375 | + $this->consent_checkbox_label_text = ''; |
|
| 2376 | + $this->gateway_log_lifespan = '7 days'; |
|
| 2377 | + $this->copy_attendee_info = true; |
|
| 2378 | + } |
|
| 2379 | + |
|
| 2380 | + |
|
| 2381 | + /** |
|
| 2382 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2383 | + * |
|
| 2384 | + * @since 4.8.8.rc.019 |
|
| 2385 | + */ |
|
| 2386 | + public function do_hooks() |
|
| 2387 | + { |
|
| 2388 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2389 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2390 | + add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText')); |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
| 2396 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
| 2397 | + */ |
|
| 2398 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2399 | + { |
|
| 2400 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2401 | + } |
|
| 2402 | + |
|
| 2403 | + |
|
| 2404 | + /** |
|
| 2405 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2406 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2407 | + */ |
|
| 2408 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2409 | + { |
|
| 2410 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + |
|
| 2414 | + /** |
|
| 2415 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
| 2416 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
| 2417 | + * |
|
| 2418 | + * @throws InvalidArgumentException |
|
| 2419 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2420 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2421 | + */ |
|
| 2422 | + public function setDefaultCheckboxLabelText() |
|
| 2423 | + { |
|
| 2424 | + if ( |
|
| 2425 | + $this->getConsentCheckboxLabelText() === null |
|
| 2426 | + || $this->getConsentCheckboxLabelText() === '' |
|
| 2427 | + ) { |
|
| 2428 | + $opening_a_tag = ''; |
|
| 2429 | + $closing_a_tag = ''; |
|
| 2430 | + if (function_exists('get_privacy_policy_url')) { |
|
| 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">'; |
|
| 2434 | + $closing_a_tag = '</a>'; |
|
| 2435 | + } |
|
| 2436 | + } |
|
| 2437 | + $loader = LoaderFactory::getLoader(); |
|
| 2438 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
| 2439 | + /** |
|
| 2440 | + * @var $org_config EE_Organization_Config |
|
| 2441 | + */ |
|
| 2442 | + |
|
| 2443 | + $this->setConsentCheckboxLabelText( |
|
| 2444 | + sprintf( |
|
| 2445 | + esc_html__( |
|
| 2446 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
| 2447 | + 'event_espresso' |
|
| 2448 | + ), |
|
| 2449 | + $org_config->name, |
|
| 2450 | + $opening_a_tag, |
|
| 2451 | + $closing_a_tag |
|
| 2452 | + ) |
|
| 2453 | + ); |
|
| 2454 | + } |
|
| 2455 | + } |
|
| 2456 | + |
|
| 2457 | + |
|
| 2458 | + /** |
|
| 2459 | + * @return boolean |
|
| 2460 | + */ |
|
| 2461 | + public function track_invalid_checkout_access() |
|
| 2462 | + { |
|
| 2463 | + return $this->track_invalid_checkout_access; |
|
| 2464 | + } |
|
| 2465 | + |
|
| 2466 | + |
|
| 2467 | + /** |
|
| 2468 | + * @param boolean $track_invalid_checkout_access |
|
| 2469 | + */ |
|
| 2470 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2471 | + { |
|
| 2472 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2473 | + $track_invalid_checkout_access, |
|
| 2474 | + FILTER_VALIDATE_BOOLEAN |
|
| 2475 | + ); |
|
| 2476 | + } |
|
| 2477 | + |
|
| 2478 | + /** |
|
| 2479 | + * @return boolean |
|
| 2480 | + */ |
|
| 2481 | + public function copyAttendeeInfo() |
|
| 2482 | + { |
|
| 2483 | + return $this->copy_attendee_info; |
|
| 2484 | + } |
|
| 2485 | + |
|
| 2486 | + |
|
| 2487 | + /** |
|
| 2488 | + * @param boolean $copy_attendee_info |
|
| 2489 | + */ |
|
| 2490 | + public function setCopyAttendeeInfo($copy_attendee_info) |
|
| 2491 | + { |
|
| 2492 | + $this->copy_attendee_info = filter_var( |
|
| 2493 | + $copy_attendee_info, |
|
| 2494 | + FILTER_VALIDATE_BOOLEAN |
|
| 2495 | + ); |
|
| 2496 | + } |
|
| 2497 | + |
|
| 2498 | + |
|
| 2499 | + /** |
|
| 2500 | + * Gets the options to make availalbe for the gateway log lifespan |
|
| 2501 | + * @return array |
|
| 2502 | + */ |
|
| 2503 | + public function gatewayLogLifespanOptions() |
|
| 2504 | + { |
|
| 2505 | + return (array) apply_filters( |
|
| 2506 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
| 2507 | + array( |
|
| 2508 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
| 2509 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
| 2510 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
| 2511 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
| 2512 | + '30 days' => esc_html__('30 Days', 'event_espresso') |
|
| 2513 | + ) |
|
| 2514 | + ); |
|
| 2515 | + } |
|
| 2516 | + |
|
| 2517 | + |
|
| 2518 | + /** |
|
| 2519 | + * @return bool |
|
| 2520 | + */ |
|
| 2521 | + public function isConsentCheckboxEnabled() |
|
| 2522 | + { |
|
| 2523 | + return $this->consent_checkbox_enabled; |
|
| 2524 | + } |
|
| 2525 | + |
|
| 2526 | + |
|
| 2527 | + /** |
|
| 2528 | + * @param bool $consent_checkbox_enabled |
|
| 2529 | + */ |
|
| 2530 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
| 2531 | + { |
|
| 2532 | + $this->consent_checkbox_enabled = filter_var( |
|
| 2533 | + $consent_checkbox_enabled, |
|
| 2534 | + FILTER_VALIDATE_BOOLEAN |
|
| 2535 | + ); |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + |
|
| 2539 | + /** |
|
| 2540 | + * @return string |
|
| 2541 | + */ |
|
| 2542 | + public function getConsentCheckboxLabelText() |
|
| 2543 | + { |
|
| 2544 | + return $this->consent_checkbox_label_text; |
|
| 2545 | + } |
|
| 2546 | + |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @param string $consent_checkbox_label_text |
|
| 2550 | + */ |
|
| 2551 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
| 2552 | + { |
|
| 2553 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
| 2554 | + } |
|
| 2555 | 2555 | } |
| 2556 | 2556 | |
| 2557 | 2557 | /** |
@@ -2560,180 +2560,180 @@ discard block |
||
| 2560 | 2560 | class EE_Admin_Config extends EE_Config_Base |
| 2561 | 2561 | { |
| 2562 | 2562 | |
| 2563 | - /** |
|
| 2564 | - * @var boolean $useAdvancedEditor |
|
| 2565 | - */ |
|
| 2566 | - private $useAdvancedEditor; |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * @var boolean $use_personnel_manager |
|
| 2570 | - */ |
|
| 2571 | - public $use_personnel_manager; |
|
| 2572 | - |
|
| 2573 | - /** |
|
| 2574 | - * @var boolean $use_dashboard_widget |
|
| 2575 | - */ |
|
| 2576 | - public $use_dashboard_widget; |
|
| 2577 | - |
|
| 2578 | - /** |
|
| 2579 | - * @var int $events_in_dashboard |
|
| 2580 | - */ |
|
| 2581 | - public $events_in_dashboard; |
|
| 2582 | - |
|
| 2583 | - /** |
|
| 2584 | - * @var boolean $use_event_timezones |
|
| 2585 | - */ |
|
| 2586 | - public $use_event_timezones; |
|
| 2587 | - |
|
| 2588 | - /** |
|
| 2589 | - * @var string $log_file_name |
|
| 2590 | - */ |
|
| 2591 | - public $log_file_name; |
|
| 2592 | - |
|
| 2593 | - /** |
|
| 2594 | - * @var string $debug_file_name |
|
| 2595 | - */ |
|
| 2596 | - public $debug_file_name; |
|
| 2597 | - |
|
| 2598 | - /** |
|
| 2599 | - * @var boolean $use_remote_logging |
|
| 2600 | - */ |
|
| 2601 | - public $use_remote_logging; |
|
| 2602 | - |
|
| 2603 | - /** |
|
| 2604 | - * @var string $remote_logging_url |
|
| 2605 | - */ |
|
| 2606 | - public $remote_logging_url; |
|
| 2607 | - |
|
| 2608 | - /** |
|
| 2609 | - * @var boolean $show_reg_footer |
|
| 2610 | - */ |
|
| 2611 | - public $show_reg_footer; |
|
| 2612 | - |
|
| 2613 | - /** |
|
| 2614 | - * @var string $affiliate_id |
|
| 2615 | - */ |
|
| 2616 | - public $affiliate_id; |
|
| 2617 | - |
|
| 2618 | - /** |
|
| 2619 | - * help tours on or off (global setting) |
|
| 2620 | - * |
|
| 2621 | - * @var boolean |
|
| 2622 | - */ |
|
| 2623 | - public $help_tour_activation; |
|
| 2624 | - |
|
| 2625 | - /** |
|
| 2626 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2627 | - * but is incompatible with some server configuration errors |
|
| 2628 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2629 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2630 | - * |
|
| 2631 | - * @var boolean $encode_session_data |
|
| 2632 | - */ |
|
| 2633 | - private $encode_session_data = false; |
|
| 2634 | - |
|
| 2635 | - |
|
| 2636 | - /** |
|
| 2637 | - * class constructor |
|
| 2638 | - * |
|
| 2639 | - * @access public |
|
| 2640 | - */ |
|
| 2641 | - public function __construct() |
|
| 2642 | - { |
|
| 2643 | - // set default general admin settings |
|
| 2644 | - $this->useAdvancedEditor = true; |
|
| 2645 | - $this->use_personnel_manager = true; |
|
| 2646 | - $this->use_dashboard_widget = true; |
|
| 2647 | - $this->events_in_dashboard = 30; |
|
| 2648 | - $this->use_event_timezones = false; |
|
| 2649 | - $this->use_remote_logging = false; |
|
| 2650 | - $this->remote_logging_url = null; |
|
| 2651 | - $this->show_reg_footer = apply_filters( |
|
| 2652 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2653 | - false |
|
| 2654 | - ); |
|
| 2655 | - $this->affiliate_id = 'default'; |
|
| 2656 | - $this->help_tour_activation = true; |
|
| 2657 | - $this->encode_session_data = false; |
|
| 2658 | - } |
|
| 2659 | - |
|
| 2660 | - |
|
| 2661 | - /** |
|
| 2662 | - * @param bool $reset |
|
| 2663 | - * @return string |
|
| 2664 | - */ |
|
| 2665 | - public function log_file_name($reset = false) |
|
| 2666 | - { |
|
| 2667 | - if (empty($this->log_file_name) || $reset) { |
|
| 2668 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2669 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2670 | - } |
|
| 2671 | - return $this->log_file_name; |
|
| 2672 | - } |
|
| 2673 | - |
|
| 2674 | - |
|
| 2675 | - /** |
|
| 2676 | - * @param bool $reset |
|
| 2677 | - * @return string |
|
| 2678 | - */ |
|
| 2679 | - public function debug_file_name($reset = false) |
|
| 2680 | - { |
|
| 2681 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2682 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2683 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2684 | - } |
|
| 2685 | - return $this->debug_file_name; |
|
| 2686 | - } |
|
| 2687 | - |
|
| 2688 | - |
|
| 2689 | - /** |
|
| 2690 | - * @return string |
|
| 2691 | - */ |
|
| 2692 | - public function affiliate_id() |
|
| 2693 | - { |
|
| 2694 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2695 | - } |
|
| 2696 | - |
|
| 2697 | - |
|
| 2698 | - /** |
|
| 2699 | - * @return boolean |
|
| 2700 | - */ |
|
| 2701 | - public function encode_session_data() |
|
| 2702 | - { |
|
| 2703 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2704 | - } |
|
| 2705 | - |
|
| 2706 | - |
|
| 2707 | - /** |
|
| 2708 | - * @param boolean $encode_session_data |
|
| 2709 | - */ |
|
| 2710 | - public function set_encode_session_data($encode_session_data) |
|
| 2711 | - { |
|
| 2712 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2713 | - } |
|
| 2714 | - |
|
| 2715 | - /** |
|
| 2716 | - * @return boolean |
|
| 2717 | - */ |
|
| 2718 | - public function useAdvancedEditor() |
|
| 2719 | - { |
|
| 2720 | - $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
| 2721 | - return $this->useAdvancedEditor && $domain->isCaffeinated(); |
|
| 2722 | - } |
|
| 2723 | - |
|
| 2724 | - /** |
|
| 2725 | - * @param boolean $use_advanced_editor |
|
| 2726 | - */ |
|
| 2727 | - public function setUseAdvancedEditor($use_advanced_editor = true) |
|
| 2728 | - { |
|
| 2729 | - $this->useAdvancedEditor = filter_var( |
|
| 2730 | - apply_filters( |
|
| 2731 | - 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
| 2732 | - $use_advanced_editor |
|
| 2733 | - ), |
|
| 2734 | - FILTER_VALIDATE_BOOLEAN |
|
| 2735 | - ); |
|
| 2736 | - } |
|
| 2563 | + /** |
|
| 2564 | + * @var boolean $useAdvancedEditor |
|
| 2565 | + */ |
|
| 2566 | + private $useAdvancedEditor; |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * @var boolean $use_personnel_manager |
|
| 2570 | + */ |
|
| 2571 | + public $use_personnel_manager; |
|
| 2572 | + |
|
| 2573 | + /** |
|
| 2574 | + * @var boolean $use_dashboard_widget |
|
| 2575 | + */ |
|
| 2576 | + public $use_dashboard_widget; |
|
| 2577 | + |
|
| 2578 | + /** |
|
| 2579 | + * @var int $events_in_dashboard |
|
| 2580 | + */ |
|
| 2581 | + public $events_in_dashboard; |
|
| 2582 | + |
|
| 2583 | + /** |
|
| 2584 | + * @var boolean $use_event_timezones |
|
| 2585 | + */ |
|
| 2586 | + public $use_event_timezones; |
|
| 2587 | + |
|
| 2588 | + /** |
|
| 2589 | + * @var string $log_file_name |
|
| 2590 | + */ |
|
| 2591 | + public $log_file_name; |
|
| 2592 | + |
|
| 2593 | + /** |
|
| 2594 | + * @var string $debug_file_name |
|
| 2595 | + */ |
|
| 2596 | + public $debug_file_name; |
|
| 2597 | + |
|
| 2598 | + /** |
|
| 2599 | + * @var boolean $use_remote_logging |
|
| 2600 | + */ |
|
| 2601 | + public $use_remote_logging; |
|
| 2602 | + |
|
| 2603 | + /** |
|
| 2604 | + * @var string $remote_logging_url |
|
| 2605 | + */ |
|
| 2606 | + public $remote_logging_url; |
|
| 2607 | + |
|
| 2608 | + /** |
|
| 2609 | + * @var boolean $show_reg_footer |
|
| 2610 | + */ |
|
| 2611 | + public $show_reg_footer; |
|
| 2612 | + |
|
| 2613 | + /** |
|
| 2614 | + * @var string $affiliate_id |
|
| 2615 | + */ |
|
| 2616 | + public $affiliate_id; |
|
| 2617 | + |
|
| 2618 | + /** |
|
| 2619 | + * help tours on or off (global setting) |
|
| 2620 | + * |
|
| 2621 | + * @var boolean |
|
| 2622 | + */ |
|
| 2623 | + public $help_tour_activation; |
|
| 2624 | + |
|
| 2625 | + /** |
|
| 2626 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2627 | + * but is incompatible with some server configuration errors |
|
| 2628 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2629 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2630 | + * |
|
| 2631 | + * @var boolean $encode_session_data |
|
| 2632 | + */ |
|
| 2633 | + private $encode_session_data = false; |
|
| 2634 | + |
|
| 2635 | + |
|
| 2636 | + /** |
|
| 2637 | + * class constructor |
|
| 2638 | + * |
|
| 2639 | + * @access public |
|
| 2640 | + */ |
|
| 2641 | + public function __construct() |
|
| 2642 | + { |
|
| 2643 | + // set default general admin settings |
|
| 2644 | + $this->useAdvancedEditor = true; |
|
| 2645 | + $this->use_personnel_manager = true; |
|
| 2646 | + $this->use_dashboard_widget = true; |
|
| 2647 | + $this->events_in_dashboard = 30; |
|
| 2648 | + $this->use_event_timezones = false; |
|
| 2649 | + $this->use_remote_logging = false; |
|
| 2650 | + $this->remote_logging_url = null; |
|
| 2651 | + $this->show_reg_footer = apply_filters( |
|
| 2652 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
| 2653 | + false |
|
| 2654 | + ); |
|
| 2655 | + $this->affiliate_id = 'default'; |
|
| 2656 | + $this->help_tour_activation = true; |
|
| 2657 | + $this->encode_session_data = false; |
|
| 2658 | + } |
|
| 2659 | + |
|
| 2660 | + |
|
| 2661 | + /** |
|
| 2662 | + * @param bool $reset |
|
| 2663 | + * @return string |
|
| 2664 | + */ |
|
| 2665 | + public function log_file_name($reset = false) |
|
| 2666 | + { |
|
| 2667 | + if (empty($this->log_file_name) || $reset) { |
|
| 2668 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2669 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2670 | + } |
|
| 2671 | + return $this->log_file_name; |
|
| 2672 | + } |
|
| 2673 | + |
|
| 2674 | + |
|
| 2675 | + /** |
|
| 2676 | + * @param bool $reset |
|
| 2677 | + * @return string |
|
| 2678 | + */ |
|
| 2679 | + public function debug_file_name($reset = false) |
|
| 2680 | + { |
|
| 2681 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2682 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2683 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2684 | + } |
|
| 2685 | + return $this->debug_file_name; |
|
| 2686 | + } |
|
| 2687 | + |
|
| 2688 | + |
|
| 2689 | + /** |
|
| 2690 | + * @return string |
|
| 2691 | + */ |
|
| 2692 | + public function affiliate_id() |
|
| 2693 | + { |
|
| 2694 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2695 | + } |
|
| 2696 | + |
|
| 2697 | + |
|
| 2698 | + /** |
|
| 2699 | + * @return boolean |
|
| 2700 | + */ |
|
| 2701 | + public function encode_session_data() |
|
| 2702 | + { |
|
| 2703 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2704 | + } |
|
| 2705 | + |
|
| 2706 | + |
|
| 2707 | + /** |
|
| 2708 | + * @param boolean $encode_session_data |
|
| 2709 | + */ |
|
| 2710 | + public function set_encode_session_data($encode_session_data) |
|
| 2711 | + { |
|
| 2712 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2713 | + } |
|
| 2714 | + |
|
| 2715 | + /** |
|
| 2716 | + * @return boolean |
|
| 2717 | + */ |
|
| 2718 | + public function useAdvancedEditor() |
|
| 2719 | + { |
|
| 2720 | + $domain = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\Domain'); |
|
| 2721 | + return $this->useAdvancedEditor && $domain->isCaffeinated(); |
|
| 2722 | + } |
|
| 2723 | + |
|
| 2724 | + /** |
|
| 2725 | + * @param boolean $use_advanced_editor |
|
| 2726 | + */ |
|
| 2727 | + public function setUseAdvancedEditor($use_advanced_editor = true) |
|
| 2728 | + { |
|
| 2729 | + $this->useAdvancedEditor = filter_var( |
|
| 2730 | + apply_filters( |
|
| 2731 | + 'FHEE__EE_Admin_Config__setUseAdvancedEditor__use_advanced_editor', |
|
| 2732 | + $use_advanced_editor |
|
| 2733 | + ), |
|
| 2734 | + FILTER_VALIDATE_BOOLEAN |
|
| 2735 | + ); |
|
| 2736 | + } |
|
| 2737 | 2737 | } |
| 2738 | 2738 | |
| 2739 | 2739 | /** |
@@ -2742,70 +2742,70 @@ discard block |
||
| 2742 | 2742 | class EE_Template_Config extends EE_Config_Base |
| 2743 | 2743 | { |
| 2744 | 2744 | |
| 2745 | - /** |
|
| 2746 | - * @var boolean $enable_default_style |
|
| 2747 | - */ |
|
| 2748 | - public $enable_default_style; |
|
| 2749 | - |
|
| 2750 | - /** |
|
| 2751 | - * @var string $custom_style_sheet |
|
| 2752 | - */ |
|
| 2753 | - public $custom_style_sheet; |
|
| 2754 | - |
|
| 2755 | - /** |
|
| 2756 | - * @var boolean $display_address_in_regform |
|
| 2757 | - */ |
|
| 2758 | - public $display_address_in_regform; |
|
| 2759 | - |
|
| 2760 | - /** |
|
| 2761 | - * @var int $display_description_on_multi_reg_page |
|
| 2762 | - */ |
|
| 2763 | - public $display_description_on_multi_reg_page; |
|
| 2764 | - |
|
| 2765 | - /** |
|
| 2766 | - * @var boolean $use_custom_templates |
|
| 2767 | - */ |
|
| 2768 | - public $use_custom_templates; |
|
| 2769 | - |
|
| 2770 | - /** |
|
| 2771 | - * @var string $current_espresso_theme |
|
| 2772 | - */ |
|
| 2773 | - public $current_espresso_theme; |
|
| 2774 | - |
|
| 2775 | - /** |
|
| 2776 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2777 | - */ |
|
| 2778 | - public $EED_Ticket_Selector; |
|
| 2779 | - |
|
| 2780 | - /** |
|
| 2781 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2782 | - */ |
|
| 2783 | - public $EED_Event_Single; |
|
| 2784 | - |
|
| 2785 | - /** |
|
| 2786 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2787 | - */ |
|
| 2788 | - public $EED_Events_Archive; |
|
| 2789 | - |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * class constructor |
|
| 2793 | - * |
|
| 2794 | - * @access public |
|
| 2795 | - */ |
|
| 2796 | - public function __construct() |
|
| 2797 | - { |
|
| 2798 | - // set default template settings |
|
| 2799 | - $this->enable_default_style = true; |
|
| 2800 | - $this->custom_style_sheet = null; |
|
| 2801 | - $this->display_address_in_regform = true; |
|
| 2802 | - $this->display_description_on_multi_reg_page = false; |
|
| 2803 | - $this->use_custom_templates = false; |
|
| 2804 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2805 | - $this->EED_Event_Single = null; |
|
| 2806 | - $this->EED_Events_Archive = null; |
|
| 2807 | - $this->EED_Ticket_Selector = null; |
|
| 2808 | - } |
|
| 2745 | + /** |
|
| 2746 | + * @var boolean $enable_default_style |
|
| 2747 | + */ |
|
| 2748 | + public $enable_default_style; |
|
| 2749 | + |
|
| 2750 | + /** |
|
| 2751 | + * @var string $custom_style_sheet |
|
| 2752 | + */ |
|
| 2753 | + public $custom_style_sheet; |
|
| 2754 | + |
|
| 2755 | + /** |
|
| 2756 | + * @var boolean $display_address_in_regform |
|
| 2757 | + */ |
|
| 2758 | + public $display_address_in_regform; |
|
| 2759 | + |
|
| 2760 | + /** |
|
| 2761 | + * @var int $display_description_on_multi_reg_page |
|
| 2762 | + */ |
|
| 2763 | + public $display_description_on_multi_reg_page; |
|
| 2764 | + |
|
| 2765 | + /** |
|
| 2766 | + * @var boolean $use_custom_templates |
|
| 2767 | + */ |
|
| 2768 | + public $use_custom_templates; |
|
| 2769 | + |
|
| 2770 | + /** |
|
| 2771 | + * @var string $current_espresso_theme |
|
| 2772 | + */ |
|
| 2773 | + public $current_espresso_theme; |
|
| 2774 | + |
|
| 2775 | + /** |
|
| 2776 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2777 | + */ |
|
| 2778 | + public $EED_Ticket_Selector; |
|
| 2779 | + |
|
| 2780 | + /** |
|
| 2781 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2782 | + */ |
|
| 2783 | + public $EED_Event_Single; |
|
| 2784 | + |
|
| 2785 | + /** |
|
| 2786 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2787 | + */ |
|
| 2788 | + public $EED_Events_Archive; |
|
| 2789 | + |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * class constructor |
|
| 2793 | + * |
|
| 2794 | + * @access public |
|
| 2795 | + */ |
|
| 2796 | + public function __construct() |
|
| 2797 | + { |
|
| 2798 | + // set default template settings |
|
| 2799 | + $this->enable_default_style = true; |
|
| 2800 | + $this->custom_style_sheet = null; |
|
| 2801 | + $this->display_address_in_regform = true; |
|
| 2802 | + $this->display_description_on_multi_reg_page = false; |
|
| 2803 | + $this->use_custom_templates = false; |
|
| 2804 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2805 | + $this->EED_Event_Single = null; |
|
| 2806 | + $this->EED_Events_Archive = null; |
|
| 2807 | + $this->EED_Ticket_Selector = null; |
|
| 2808 | + } |
|
| 2809 | 2809 | } |
| 2810 | 2810 | |
| 2811 | 2811 | /** |
@@ -2814,114 +2814,114 @@ discard block |
||
| 2814 | 2814 | class EE_Map_Config extends EE_Config_Base |
| 2815 | 2815 | { |
| 2816 | 2816 | |
| 2817 | - /** |
|
| 2818 | - * @var boolean $use_google_maps |
|
| 2819 | - */ |
|
| 2820 | - public $use_google_maps; |
|
| 2821 | - |
|
| 2822 | - /** |
|
| 2823 | - * @var string $api_key |
|
| 2824 | - */ |
|
| 2825 | - public $google_map_api_key; |
|
| 2826 | - |
|
| 2827 | - /** |
|
| 2828 | - * @var int $event_details_map_width |
|
| 2829 | - */ |
|
| 2830 | - public $event_details_map_width; |
|
| 2831 | - |
|
| 2832 | - /** |
|
| 2833 | - * @var int $event_details_map_height |
|
| 2834 | - */ |
|
| 2835 | - public $event_details_map_height; |
|
| 2836 | - |
|
| 2837 | - /** |
|
| 2838 | - * @var int $event_details_map_zoom |
|
| 2839 | - */ |
|
| 2840 | - public $event_details_map_zoom; |
|
| 2841 | - |
|
| 2842 | - /** |
|
| 2843 | - * @var boolean $event_details_display_nav |
|
| 2844 | - */ |
|
| 2845 | - public $event_details_display_nav; |
|
| 2846 | - |
|
| 2847 | - /** |
|
| 2848 | - * @var boolean $event_details_nav_size |
|
| 2849 | - */ |
|
| 2850 | - public $event_details_nav_size; |
|
| 2851 | - |
|
| 2852 | - /** |
|
| 2853 | - * @var string $event_details_control_type |
|
| 2854 | - */ |
|
| 2855 | - public $event_details_control_type; |
|
| 2856 | - |
|
| 2857 | - /** |
|
| 2858 | - * @var string $event_details_map_align |
|
| 2859 | - */ |
|
| 2860 | - public $event_details_map_align; |
|
| 2861 | - |
|
| 2862 | - /** |
|
| 2863 | - * @var int $event_list_map_width |
|
| 2864 | - */ |
|
| 2865 | - public $event_list_map_width; |
|
| 2866 | - |
|
| 2867 | - /** |
|
| 2868 | - * @var int $event_list_map_height |
|
| 2869 | - */ |
|
| 2870 | - public $event_list_map_height; |
|
| 2871 | - |
|
| 2872 | - /** |
|
| 2873 | - * @var int $event_list_map_zoom |
|
| 2874 | - */ |
|
| 2875 | - public $event_list_map_zoom; |
|
| 2876 | - |
|
| 2877 | - /** |
|
| 2878 | - * @var boolean $event_list_display_nav |
|
| 2879 | - */ |
|
| 2880 | - public $event_list_display_nav; |
|
| 2881 | - |
|
| 2882 | - /** |
|
| 2883 | - * @var boolean $event_list_nav_size |
|
| 2884 | - */ |
|
| 2885 | - public $event_list_nav_size; |
|
| 2886 | - |
|
| 2887 | - /** |
|
| 2888 | - * @var string $event_list_control_type |
|
| 2889 | - */ |
|
| 2890 | - public $event_list_control_type; |
|
| 2891 | - |
|
| 2892 | - /** |
|
| 2893 | - * @var string $event_list_map_align |
|
| 2894 | - */ |
|
| 2895 | - public $event_list_map_align; |
|
| 2896 | - |
|
| 2897 | - |
|
| 2898 | - /** |
|
| 2899 | - * class constructor |
|
| 2900 | - * |
|
| 2901 | - * @access public |
|
| 2902 | - */ |
|
| 2903 | - public function __construct() |
|
| 2904 | - { |
|
| 2905 | - // set default map settings |
|
| 2906 | - $this->use_google_maps = true; |
|
| 2907 | - $this->google_map_api_key = ''; |
|
| 2908 | - // for event details pages (reg page) |
|
| 2909 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2910 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2911 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2912 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2913 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2914 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2915 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2916 | - // for event list pages |
|
| 2917 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2918 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2919 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2920 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2921 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2922 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2923 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2924 | - } |
|
| 2817 | + /** |
|
| 2818 | + * @var boolean $use_google_maps |
|
| 2819 | + */ |
|
| 2820 | + public $use_google_maps; |
|
| 2821 | + |
|
| 2822 | + /** |
|
| 2823 | + * @var string $api_key |
|
| 2824 | + */ |
|
| 2825 | + public $google_map_api_key; |
|
| 2826 | + |
|
| 2827 | + /** |
|
| 2828 | + * @var int $event_details_map_width |
|
| 2829 | + */ |
|
| 2830 | + public $event_details_map_width; |
|
| 2831 | + |
|
| 2832 | + /** |
|
| 2833 | + * @var int $event_details_map_height |
|
| 2834 | + */ |
|
| 2835 | + public $event_details_map_height; |
|
| 2836 | + |
|
| 2837 | + /** |
|
| 2838 | + * @var int $event_details_map_zoom |
|
| 2839 | + */ |
|
| 2840 | + public $event_details_map_zoom; |
|
| 2841 | + |
|
| 2842 | + /** |
|
| 2843 | + * @var boolean $event_details_display_nav |
|
| 2844 | + */ |
|
| 2845 | + public $event_details_display_nav; |
|
| 2846 | + |
|
| 2847 | + /** |
|
| 2848 | + * @var boolean $event_details_nav_size |
|
| 2849 | + */ |
|
| 2850 | + public $event_details_nav_size; |
|
| 2851 | + |
|
| 2852 | + /** |
|
| 2853 | + * @var string $event_details_control_type |
|
| 2854 | + */ |
|
| 2855 | + public $event_details_control_type; |
|
| 2856 | + |
|
| 2857 | + /** |
|
| 2858 | + * @var string $event_details_map_align |
|
| 2859 | + */ |
|
| 2860 | + public $event_details_map_align; |
|
| 2861 | + |
|
| 2862 | + /** |
|
| 2863 | + * @var int $event_list_map_width |
|
| 2864 | + */ |
|
| 2865 | + public $event_list_map_width; |
|
| 2866 | + |
|
| 2867 | + /** |
|
| 2868 | + * @var int $event_list_map_height |
|
| 2869 | + */ |
|
| 2870 | + public $event_list_map_height; |
|
| 2871 | + |
|
| 2872 | + /** |
|
| 2873 | + * @var int $event_list_map_zoom |
|
| 2874 | + */ |
|
| 2875 | + public $event_list_map_zoom; |
|
| 2876 | + |
|
| 2877 | + /** |
|
| 2878 | + * @var boolean $event_list_display_nav |
|
| 2879 | + */ |
|
| 2880 | + public $event_list_display_nav; |
|
| 2881 | + |
|
| 2882 | + /** |
|
| 2883 | + * @var boolean $event_list_nav_size |
|
| 2884 | + */ |
|
| 2885 | + public $event_list_nav_size; |
|
| 2886 | + |
|
| 2887 | + /** |
|
| 2888 | + * @var string $event_list_control_type |
|
| 2889 | + */ |
|
| 2890 | + public $event_list_control_type; |
|
| 2891 | + |
|
| 2892 | + /** |
|
| 2893 | + * @var string $event_list_map_align |
|
| 2894 | + */ |
|
| 2895 | + public $event_list_map_align; |
|
| 2896 | + |
|
| 2897 | + |
|
| 2898 | + /** |
|
| 2899 | + * class constructor |
|
| 2900 | + * |
|
| 2901 | + * @access public |
|
| 2902 | + */ |
|
| 2903 | + public function __construct() |
|
| 2904 | + { |
|
| 2905 | + // set default map settings |
|
| 2906 | + $this->use_google_maps = true; |
|
| 2907 | + $this->google_map_api_key = ''; |
|
| 2908 | + // for event details pages (reg page) |
|
| 2909 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2910 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2911 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2912 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2913 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2914 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2915 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2916 | + // for event list pages |
|
| 2917 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2918 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2919 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2920 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2921 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2922 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2923 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2924 | + } |
|
| 2925 | 2925 | } |
| 2926 | 2926 | |
| 2927 | 2927 | /** |
@@ -2930,46 +2930,46 @@ discard block |
||
| 2930 | 2930 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2931 | 2931 | { |
| 2932 | 2932 | |
| 2933 | - public $display_status_banner; |
|
| 2933 | + public $display_status_banner; |
|
| 2934 | 2934 | |
| 2935 | - public $display_description; |
|
| 2935 | + public $display_description; |
|
| 2936 | 2936 | |
| 2937 | - public $display_ticket_selector; |
|
| 2937 | + public $display_ticket_selector; |
|
| 2938 | 2938 | |
| 2939 | - public $display_datetimes; |
|
| 2939 | + public $display_datetimes; |
|
| 2940 | 2940 | |
| 2941 | - public $display_venue; |
|
| 2941 | + public $display_venue; |
|
| 2942 | 2942 | |
| 2943 | - public $display_expired_events; |
|
| 2943 | + public $display_expired_events; |
|
| 2944 | 2944 | |
| 2945 | - public $use_sortable_display_order; |
|
| 2945 | + public $use_sortable_display_order; |
|
| 2946 | 2946 | |
| 2947 | - public $display_order_tickets; |
|
| 2947 | + public $display_order_tickets; |
|
| 2948 | 2948 | |
| 2949 | - public $display_order_datetimes; |
|
| 2949 | + public $display_order_datetimes; |
|
| 2950 | 2950 | |
| 2951 | - public $display_order_event; |
|
| 2951 | + public $display_order_event; |
|
| 2952 | 2952 | |
| 2953 | - public $display_order_venue; |
|
| 2953 | + public $display_order_venue; |
|
| 2954 | 2954 | |
| 2955 | 2955 | |
| 2956 | - /** |
|
| 2957 | - * class constructor |
|
| 2958 | - */ |
|
| 2959 | - public function __construct() |
|
| 2960 | - { |
|
| 2961 | - $this->display_status_banner = 0; |
|
| 2962 | - $this->display_description = 1; |
|
| 2963 | - $this->display_ticket_selector = 0; |
|
| 2964 | - $this->display_datetimes = 1; |
|
| 2965 | - $this->display_venue = 0; |
|
| 2966 | - $this->display_expired_events = 0; |
|
| 2967 | - $this->use_sortable_display_order = false; |
|
| 2968 | - $this->display_order_tickets = 100; |
|
| 2969 | - $this->display_order_datetimes = 110; |
|
| 2970 | - $this->display_order_event = 120; |
|
| 2971 | - $this->display_order_venue = 130; |
|
| 2972 | - } |
|
| 2956 | + /** |
|
| 2957 | + * class constructor |
|
| 2958 | + */ |
|
| 2959 | + public function __construct() |
|
| 2960 | + { |
|
| 2961 | + $this->display_status_banner = 0; |
|
| 2962 | + $this->display_description = 1; |
|
| 2963 | + $this->display_ticket_selector = 0; |
|
| 2964 | + $this->display_datetimes = 1; |
|
| 2965 | + $this->display_venue = 0; |
|
| 2966 | + $this->display_expired_events = 0; |
|
| 2967 | + $this->use_sortable_display_order = false; |
|
| 2968 | + $this->display_order_tickets = 100; |
|
| 2969 | + $this->display_order_datetimes = 110; |
|
| 2970 | + $this->display_order_event = 120; |
|
| 2971 | + $this->display_order_venue = 130; |
|
| 2972 | + } |
|
| 2973 | 2973 | } |
| 2974 | 2974 | |
| 2975 | 2975 | /** |
@@ -2978,34 +2978,34 @@ discard block |
||
| 2978 | 2978 | class EE_Event_Single_Config extends EE_Config_Base |
| 2979 | 2979 | { |
| 2980 | 2980 | |
| 2981 | - public $display_status_banner_single; |
|
| 2981 | + public $display_status_banner_single; |
|
| 2982 | 2982 | |
| 2983 | - public $display_venue; |
|
| 2983 | + public $display_venue; |
|
| 2984 | 2984 | |
| 2985 | - public $use_sortable_display_order; |
|
| 2985 | + public $use_sortable_display_order; |
|
| 2986 | 2986 | |
| 2987 | - public $display_order_tickets; |
|
| 2987 | + public $display_order_tickets; |
|
| 2988 | 2988 | |
| 2989 | - public $display_order_datetimes; |
|
| 2989 | + public $display_order_datetimes; |
|
| 2990 | 2990 | |
| 2991 | - public $display_order_event; |
|
| 2991 | + public $display_order_event; |
|
| 2992 | 2992 | |
| 2993 | - public $display_order_venue; |
|
| 2993 | + public $display_order_venue; |
|
| 2994 | 2994 | |
| 2995 | 2995 | |
| 2996 | - /** |
|
| 2997 | - * class constructor |
|
| 2998 | - */ |
|
| 2999 | - public function __construct() |
|
| 3000 | - { |
|
| 3001 | - $this->display_status_banner_single = 0; |
|
| 3002 | - $this->display_venue = 1; |
|
| 3003 | - $this->use_sortable_display_order = false; |
|
| 3004 | - $this->display_order_tickets = 100; |
|
| 3005 | - $this->display_order_datetimes = 110; |
|
| 3006 | - $this->display_order_event = 120; |
|
| 3007 | - $this->display_order_venue = 130; |
|
| 3008 | - } |
|
| 2996 | + /** |
|
| 2997 | + * class constructor |
|
| 2998 | + */ |
|
| 2999 | + public function __construct() |
|
| 3000 | + { |
|
| 3001 | + $this->display_status_banner_single = 0; |
|
| 3002 | + $this->display_venue = 1; |
|
| 3003 | + $this->use_sortable_display_order = false; |
|
| 3004 | + $this->display_order_tickets = 100; |
|
| 3005 | + $this->display_order_datetimes = 110; |
|
| 3006 | + $this->display_order_event = 120; |
|
| 3007 | + $this->display_order_venue = 130; |
|
| 3008 | + } |
|
| 3009 | 3009 | } |
| 3010 | 3010 | |
| 3011 | 3011 | /** |
@@ -3014,172 +3014,172 @@ discard block |
||
| 3014 | 3014 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 3015 | 3015 | { |
| 3016 | 3016 | |
| 3017 | - /** |
|
| 3018 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3019 | - */ |
|
| 3020 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3021 | - |
|
| 3022 | - /** |
|
| 3023 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3024 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3025 | - */ |
|
| 3026 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3027 | - |
|
| 3028 | - /** |
|
| 3029 | - * @var boolean $show_ticket_sale_columns |
|
| 3030 | - */ |
|
| 3031 | - public $show_ticket_sale_columns; |
|
| 3032 | - |
|
| 3033 | - /** |
|
| 3034 | - * @var boolean $show_ticket_details |
|
| 3035 | - */ |
|
| 3036 | - public $show_ticket_details; |
|
| 3037 | - |
|
| 3038 | - /** |
|
| 3039 | - * @var boolean $show_expired_tickets |
|
| 3040 | - */ |
|
| 3041 | - public $show_expired_tickets; |
|
| 3042 | - |
|
| 3043 | - /** |
|
| 3044 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 3045 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 3046 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3047 | - * |
|
| 3048 | - * @var string $show_datetime_selector |
|
| 3049 | - */ |
|
| 3050 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3051 | - |
|
| 3052 | - /** |
|
| 3053 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3054 | - * |
|
| 3055 | - * @var int $datetime_selector_threshold |
|
| 3056 | - */ |
|
| 3057 | - private $datetime_selector_threshold = 3; |
|
| 3058 | - |
|
| 3059 | - /** |
|
| 3060 | - * determines the maximum number of "checked" dates in the date and time filter |
|
| 3061 | - * |
|
| 3062 | - * @var int $datetime_selector_checked |
|
| 3063 | - */ |
|
| 3064 | - private $datetime_selector_max_checked = 10; |
|
| 3065 | - |
|
| 3066 | - |
|
| 3067 | - /** |
|
| 3068 | - * class constructor |
|
| 3069 | - */ |
|
| 3070 | - public function __construct() |
|
| 3071 | - { |
|
| 3072 | - $this->show_ticket_sale_columns = true; |
|
| 3073 | - $this->show_ticket_details = true; |
|
| 3074 | - $this->show_expired_tickets = true; |
|
| 3075 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3076 | - $this->datetime_selector_threshold = 3; |
|
| 3077 | - $this->datetime_selector_max_checked = 10; |
|
| 3078 | - } |
|
| 3079 | - |
|
| 3080 | - |
|
| 3081 | - /** |
|
| 3082 | - * returns true if a datetime selector should be displayed |
|
| 3083 | - * |
|
| 3084 | - * @param array $datetimes |
|
| 3085 | - * @return bool |
|
| 3086 | - */ |
|
| 3087 | - public function showDatetimeSelector(array $datetimes) |
|
| 3088 | - { |
|
| 3089 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3090 | - return ! ( |
|
| 3091 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3092 | - || ( |
|
| 3093 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3094 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3095 | - ) |
|
| 3096 | - ); |
|
| 3097 | - } |
|
| 3098 | - |
|
| 3099 | - |
|
| 3100 | - /** |
|
| 3101 | - * @return string |
|
| 3102 | - */ |
|
| 3103 | - public function getShowDatetimeSelector() |
|
| 3104 | - { |
|
| 3105 | - return $this->show_datetime_selector; |
|
| 3106 | - } |
|
| 3107 | - |
|
| 3108 | - |
|
| 3109 | - /** |
|
| 3110 | - * @param bool $keys_only |
|
| 3111 | - * @return array |
|
| 3112 | - */ |
|
| 3113 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3114 | - { |
|
| 3115 | - return $keys_only |
|
| 3116 | - ? array( |
|
| 3117 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3118 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3119 | - ) |
|
| 3120 | - : array( |
|
| 3121 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3122 | - 'Do not show date & time filter', |
|
| 3123 | - 'event_espresso' |
|
| 3124 | - ), |
|
| 3125 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3126 | - 'Maybe show date & time filter', |
|
| 3127 | - 'event_espresso' |
|
| 3128 | - ), |
|
| 3129 | - ); |
|
| 3130 | - } |
|
| 3131 | - |
|
| 3132 | - |
|
| 3133 | - /** |
|
| 3134 | - * @param string $show_datetime_selector |
|
| 3135 | - */ |
|
| 3136 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3137 | - { |
|
| 3138 | - $this->show_datetime_selector = in_array( |
|
| 3139 | - $show_datetime_selector, |
|
| 3140 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3141 | - true |
|
| 3142 | - ) |
|
| 3143 | - ? $show_datetime_selector |
|
| 3144 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3145 | - } |
|
| 3146 | - |
|
| 3147 | - |
|
| 3148 | - /** |
|
| 3149 | - * @return int |
|
| 3150 | - */ |
|
| 3151 | - public function getDatetimeSelectorThreshold() |
|
| 3152 | - { |
|
| 3153 | - return $this->datetime_selector_threshold; |
|
| 3154 | - } |
|
| 3155 | - |
|
| 3156 | - |
|
| 3157 | - /** |
|
| 3158 | - * @param int $datetime_selector_threshold |
|
| 3159 | - */ |
|
| 3160 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3161 | - { |
|
| 3162 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3163 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3164 | - } |
|
| 3165 | - |
|
| 3166 | - |
|
| 3167 | - /** |
|
| 3168 | - * @return int |
|
| 3169 | - */ |
|
| 3170 | - public function getDatetimeSelectorMaxChecked() |
|
| 3171 | - { |
|
| 3172 | - return $this->datetime_selector_max_checked; |
|
| 3173 | - } |
|
| 3174 | - |
|
| 3175 | - |
|
| 3176 | - /** |
|
| 3177 | - * @param int $datetime_selector_max_checked |
|
| 3178 | - */ |
|
| 3179 | - public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3180 | - { |
|
| 3181 | - $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3182 | - } |
|
| 3017 | + /** |
|
| 3018 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 3019 | + */ |
|
| 3020 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 3021 | + |
|
| 3022 | + /** |
|
| 3023 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 3024 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 3025 | + */ |
|
| 3026 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 3027 | + |
|
| 3028 | + /** |
|
| 3029 | + * @var boolean $show_ticket_sale_columns |
|
| 3030 | + */ |
|
| 3031 | + public $show_ticket_sale_columns; |
|
| 3032 | + |
|
| 3033 | + /** |
|
| 3034 | + * @var boolean $show_ticket_details |
|
| 3035 | + */ |
|
| 3036 | + public $show_ticket_details; |
|
| 3037 | + |
|
| 3038 | + /** |
|
| 3039 | + * @var boolean $show_expired_tickets |
|
| 3040 | + */ |
|
| 3041 | + public $show_expired_tickets; |
|
| 3042 | + |
|
| 3043 | + /** |
|
| 3044 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 3045 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 3046 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 3047 | + * |
|
| 3048 | + * @var string $show_datetime_selector |
|
| 3049 | + */ |
|
| 3050 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 3051 | + |
|
| 3052 | + /** |
|
| 3053 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 3054 | + * |
|
| 3055 | + * @var int $datetime_selector_threshold |
|
| 3056 | + */ |
|
| 3057 | + private $datetime_selector_threshold = 3; |
|
| 3058 | + |
|
| 3059 | + /** |
|
| 3060 | + * determines the maximum number of "checked" dates in the date and time filter |
|
| 3061 | + * |
|
| 3062 | + * @var int $datetime_selector_checked |
|
| 3063 | + */ |
|
| 3064 | + private $datetime_selector_max_checked = 10; |
|
| 3065 | + |
|
| 3066 | + |
|
| 3067 | + /** |
|
| 3068 | + * class constructor |
|
| 3069 | + */ |
|
| 3070 | + public function __construct() |
|
| 3071 | + { |
|
| 3072 | + $this->show_ticket_sale_columns = true; |
|
| 3073 | + $this->show_ticket_details = true; |
|
| 3074 | + $this->show_expired_tickets = true; |
|
| 3075 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3076 | + $this->datetime_selector_threshold = 3; |
|
| 3077 | + $this->datetime_selector_max_checked = 10; |
|
| 3078 | + } |
|
| 3079 | + |
|
| 3080 | + |
|
| 3081 | + /** |
|
| 3082 | + * returns true if a datetime selector should be displayed |
|
| 3083 | + * |
|
| 3084 | + * @param array $datetimes |
|
| 3085 | + * @return bool |
|
| 3086 | + */ |
|
| 3087 | + public function showDatetimeSelector(array $datetimes) |
|
| 3088 | + { |
|
| 3089 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3090 | + return ! ( |
|
| 3091 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3092 | + || ( |
|
| 3093 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3094 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3095 | + ) |
|
| 3096 | + ); |
|
| 3097 | + } |
|
| 3098 | + |
|
| 3099 | + |
|
| 3100 | + /** |
|
| 3101 | + * @return string |
|
| 3102 | + */ |
|
| 3103 | + public function getShowDatetimeSelector() |
|
| 3104 | + { |
|
| 3105 | + return $this->show_datetime_selector; |
|
| 3106 | + } |
|
| 3107 | + |
|
| 3108 | + |
|
| 3109 | + /** |
|
| 3110 | + * @param bool $keys_only |
|
| 3111 | + * @return array |
|
| 3112 | + */ |
|
| 3113 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3114 | + { |
|
| 3115 | + return $keys_only |
|
| 3116 | + ? array( |
|
| 3117 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3118 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3119 | + ) |
|
| 3120 | + : array( |
|
| 3121 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3122 | + 'Do not show date & time filter', |
|
| 3123 | + 'event_espresso' |
|
| 3124 | + ), |
|
| 3125 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3126 | + 'Maybe show date & time filter', |
|
| 3127 | + 'event_espresso' |
|
| 3128 | + ), |
|
| 3129 | + ); |
|
| 3130 | + } |
|
| 3131 | + |
|
| 3132 | + |
|
| 3133 | + /** |
|
| 3134 | + * @param string $show_datetime_selector |
|
| 3135 | + */ |
|
| 3136 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3137 | + { |
|
| 3138 | + $this->show_datetime_selector = in_array( |
|
| 3139 | + $show_datetime_selector, |
|
| 3140 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3141 | + true |
|
| 3142 | + ) |
|
| 3143 | + ? $show_datetime_selector |
|
| 3144 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3145 | + } |
|
| 3146 | + |
|
| 3147 | + |
|
| 3148 | + /** |
|
| 3149 | + * @return int |
|
| 3150 | + */ |
|
| 3151 | + public function getDatetimeSelectorThreshold() |
|
| 3152 | + { |
|
| 3153 | + return $this->datetime_selector_threshold; |
|
| 3154 | + } |
|
| 3155 | + |
|
| 3156 | + |
|
| 3157 | + /** |
|
| 3158 | + * @param int $datetime_selector_threshold |
|
| 3159 | + */ |
|
| 3160 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3161 | + { |
|
| 3162 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3163 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3164 | + } |
|
| 3165 | + |
|
| 3166 | + |
|
| 3167 | + /** |
|
| 3168 | + * @return int |
|
| 3169 | + */ |
|
| 3170 | + public function getDatetimeSelectorMaxChecked() |
|
| 3171 | + { |
|
| 3172 | + return $this->datetime_selector_max_checked; |
|
| 3173 | + } |
|
| 3174 | + |
|
| 3175 | + |
|
| 3176 | + /** |
|
| 3177 | + * @param int $datetime_selector_max_checked |
|
| 3178 | + */ |
|
| 3179 | + public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked) |
|
| 3180 | + { |
|
| 3181 | + $this->datetime_selector_max_checked = absint($datetime_selector_max_checked); |
|
| 3182 | + } |
|
| 3183 | 3183 | } |
| 3184 | 3184 | |
| 3185 | 3185 | /** |
@@ -3192,87 +3192,87 @@ discard block |
||
| 3192 | 3192 | class EE_Environment_Config extends EE_Config_Base |
| 3193 | 3193 | { |
| 3194 | 3194 | |
| 3195 | - /** |
|
| 3196 | - * Hold any php environment variables that we want to track. |
|
| 3197 | - * |
|
| 3198 | - * @var stdClass; |
|
| 3199 | - */ |
|
| 3200 | - public $php; |
|
| 3201 | - |
|
| 3202 | - |
|
| 3203 | - /** |
|
| 3204 | - * constructor |
|
| 3205 | - */ |
|
| 3206 | - public function __construct() |
|
| 3207 | - { |
|
| 3208 | - $this->php = new stdClass(); |
|
| 3209 | - $this->_set_php_values(); |
|
| 3210 | - } |
|
| 3211 | - |
|
| 3212 | - |
|
| 3213 | - /** |
|
| 3214 | - * This sets the php environment variables. |
|
| 3215 | - * |
|
| 3216 | - * @since 4.4.0 |
|
| 3217 | - * @return void |
|
| 3218 | - */ |
|
| 3219 | - protected function _set_php_values() |
|
| 3220 | - { |
|
| 3221 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3222 | - $this->php->version = phpversion(); |
|
| 3223 | - } |
|
| 3224 | - |
|
| 3225 | - |
|
| 3226 | - /** |
|
| 3227 | - * helper method for determining whether input_count is |
|
| 3228 | - * reaching the potential maximum the server can handle |
|
| 3229 | - * according to max_input_vars |
|
| 3230 | - * |
|
| 3231 | - * @param int $input_count the count of input vars. |
|
| 3232 | - * @return array { |
|
| 3233 | - * An array that represents whether available space and if no available space the error |
|
| 3234 | - * message. |
|
| 3235 | - * @type bool $has_space whether more inputs can be added. |
|
| 3236 | - * @type string $msg Any message to be displayed. |
|
| 3237 | - * } |
|
| 3238 | - */ |
|
| 3239 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3240 | - { |
|
| 3241 | - if ( |
|
| 3242 | - ! empty($this->php->max_input_vars) |
|
| 3243 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3244 | - ) { |
|
| 3245 | - // check the server setting because the config value could be stale |
|
| 3246 | - $max_input_vars = ini_get('max_input_vars'); |
|
| 3247 | - if ($input_count >= $max_input_vars) { |
|
| 3248 | - return sprintf( |
|
| 3249 | - esc_html__( |
|
| 3250 | - 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3251 | - 'event_espresso' |
|
| 3252 | - ), |
|
| 3253 | - '<br>', |
|
| 3254 | - $input_count, |
|
| 3255 | - $max_input_vars |
|
| 3256 | - ); |
|
| 3257 | - } else { |
|
| 3258 | - return ''; |
|
| 3259 | - } |
|
| 3260 | - } else { |
|
| 3261 | - return ''; |
|
| 3262 | - } |
|
| 3263 | - } |
|
| 3264 | - |
|
| 3265 | - |
|
| 3266 | - /** |
|
| 3267 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3268 | - * |
|
| 3269 | - * @since 4.4.1 |
|
| 3270 | - * @return void |
|
| 3271 | - */ |
|
| 3272 | - public function recheck_values() |
|
| 3273 | - { |
|
| 3274 | - $this->_set_php_values(); |
|
| 3275 | - } |
|
| 3195 | + /** |
|
| 3196 | + * Hold any php environment variables that we want to track. |
|
| 3197 | + * |
|
| 3198 | + * @var stdClass; |
|
| 3199 | + */ |
|
| 3200 | + public $php; |
|
| 3201 | + |
|
| 3202 | + |
|
| 3203 | + /** |
|
| 3204 | + * constructor |
|
| 3205 | + */ |
|
| 3206 | + public function __construct() |
|
| 3207 | + { |
|
| 3208 | + $this->php = new stdClass(); |
|
| 3209 | + $this->_set_php_values(); |
|
| 3210 | + } |
|
| 3211 | + |
|
| 3212 | + |
|
| 3213 | + /** |
|
| 3214 | + * This sets the php environment variables. |
|
| 3215 | + * |
|
| 3216 | + * @since 4.4.0 |
|
| 3217 | + * @return void |
|
| 3218 | + */ |
|
| 3219 | + protected function _set_php_values() |
|
| 3220 | + { |
|
| 3221 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3222 | + $this->php->version = phpversion(); |
|
| 3223 | + } |
|
| 3224 | + |
|
| 3225 | + |
|
| 3226 | + /** |
|
| 3227 | + * helper method for determining whether input_count is |
|
| 3228 | + * reaching the potential maximum the server can handle |
|
| 3229 | + * according to max_input_vars |
|
| 3230 | + * |
|
| 3231 | + * @param int $input_count the count of input vars. |
|
| 3232 | + * @return array { |
|
| 3233 | + * An array that represents whether available space and if no available space the error |
|
| 3234 | + * message. |
|
| 3235 | + * @type bool $has_space whether more inputs can be added. |
|
| 3236 | + * @type string $msg Any message to be displayed. |
|
| 3237 | + * } |
|
| 3238 | + */ |
|
| 3239 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3240 | + { |
|
| 3241 | + if ( |
|
| 3242 | + ! empty($this->php->max_input_vars) |
|
| 3243 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3244 | + ) { |
|
| 3245 | + // check the server setting because the config value could be stale |
|
| 3246 | + $max_input_vars = ini_get('max_input_vars'); |
|
| 3247 | + if ($input_count >= $max_input_vars) { |
|
| 3248 | + return sprintf( |
|
| 3249 | + esc_html__( |
|
| 3250 | + 'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.', |
|
| 3251 | + 'event_espresso' |
|
| 3252 | + ), |
|
| 3253 | + '<br>', |
|
| 3254 | + $input_count, |
|
| 3255 | + $max_input_vars |
|
| 3256 | + ); |
|
| 3257 | + } else { |
|
| 3258 | + return ''; |
|
| 3259 | + } |
|
| 3260 | + } else { |
|
| 3261 | + return ''; |
|
| 3262 | + } |
|
| 3263 | + } |
|
| 3264 | + |
|
| 3265 | + |
|
| 3266 | + /** |
|
| 3267 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3268 | + * |
|
| 3269 | + * @since 4.4.1 |
|
| 3270 | + * @return void |
|
| 3271 | + */ |
|
| 3272 | + public function recheck_values() |
|
| 3273 | + { |
|
| 3274 | + $this->_set_php_values(); |
|
| 3275 | + } |
|
| 3276 | 3276 | } |
| 3277 | 3277 | |
| 3278 | 3278 | /** |
@@ -3285,21 +3285,21 @@ discard block |
||
| 3285 | 3285 | class EE_Tax_Config extends EE_Config_Base |
| 3286 | 3286 | { |
| 3287 | 3287 | |
| 3288 | - /* |
|
| 3288 | + /* |
|
| 3289 | 3289 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3290 | 3290 | * |
| 3291 | 3291 | * @var boolean $prices_displayed_including_taxes |
| 3292 | 3292 | */ |
| 3293 | - public $prices_displayed_including_taxes; |
|
| 3293 | + public $prices_displayed_including_taxes; |
|
| 3294 | 3294 | |
| 3295 | 3295 | |
| 3296 | - /** |
|
| 3297 | - * class constructor |
|
| 3298 | - */ |
|
| 3299 | - public function __construct() |
|
| 3300 | - { |
|
| 3301 | - $this->prices_displayed_including_taxes = true; |
|
| 3302 | - } |
|
| 3296 | + /** |
|
| 3297 | + * class constructor |
|
| 3298 | + */ |
|
| 3299 | + public function __construct() |
|
| 3300 | + { |
|
| 3301 | + $this->prices_displayed_including_taxes = true; |
|
| 3302 | + } |
|
| 3303 | 3303 | } |
| 3304 | 3304 | |
| 3305 | 3305 | /** |
@@ -3313,19 +3313,19 @@ discard block |
||
| 3313 | 3313 | class EE_Messages_Config extends EE_Config_Base |
| 3314 | 3314 | { |
| 3315 | 3315 | |
| 3316 | - /** |
|
| 3317 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3318 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3319 | - * |
|
| 3320 | - * @var integer |
|
| 3321 | - */ |
|
| 3322 | - public $delete_threshold; |
|
| 3316 | + /** |
|
| 3317 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3318 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3319 | + * |
|
| 3320 | + * @var integer |
|
| 3321 | + */ |
|
| 3322 | + public $delete_threshold; |
|
| 3323 | 3323 | |
| 3324 | 3324 | |
| 3325 | - public function __construct() |
|
| 3326 | - { |
|
| 3327 | - $this->delete_threshold = 0; |
|
| 3328 | - } |
|
| 3325 | + public function __construct() |
|
| 3326 | + { |
|
| 3327 | + $this->delete_threshold = 0; |
|
| 3328 | + } |
|
| 3329 | 3329 | } |
| 3330 | 3330 | |
| 3331 | 3331 | /** |
@@ -3336,31 +3336,31 @@ discard block |
||
| 3336 | 3336 | class EE_Gateway_Config extends EE_Config_Base |
| 3337 | 3337 | { |
| 3338 | 3338 | |
| 3339 | - /** |
|
| 3340 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3341 | - * with any config info the gateway wants to store |
|
| 3342 | - * |
|
| 3343 | - * @var array |
|
| 3344 | - */ |
|
| 3345 | - public $payment_settings; |
|
| 3346 | - |
|
| 3347 | - /** |
|
| 3348 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3349 | - * the gateway is stored in the uploads directory |
|
| 3350 | - * |
|
| 3351 | - * @var array |
|
| 3352 | - */ |
|
| 3353 | - public $active_gateways; |
|
| 3354 | - |
|
| 3355 | - |
|
| 3356 | - /** |
|
| 3357 | - * class constructor |
|
| 3358 | - * |
|
| 3359 | - * @deprecated |
|
| 3360 | - */ |
|
| 3361 | - public function __construct() |
|
| 3362 | - { |
|
| 3363 | - $this->payment_settings = array(); |
|
| 3364 | - $this->active_gateways = array('Invoice' => false); |
|
| 3365 | - } |
|
| 3339 | + /** |
|
| 3340 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3341 | + * with any config info the gateway wants to store |
|
| 3342 | + * |
|
| 3343 | + * @var array |
|
| 3344 | + */ |
|
| 3345 | + public $payment_settings; |
|
| 3346 | + |
|
| 3347 | + /** |
|
| 3348 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3349 | + * the gateway is stored in the uploads directory |
|
| 3350 | + * |
|
| 3351 | + * @var array |
|
| 3352 | + */ |
|
| 3353 | + public $active_gateways; |
|
| 3354 | + |
|
| 3355 | + |
|
| 3356 | + /** |
|
| 3357 | + * class constructor |
|
| 3358 | + * |
|
| 3359 | + * @deprecated |
|
| 3360 | + */ |
|
| 3361 | + public function __construct() |
|
| 3362 | + { |
|
| 3363 | + $this->payment_settings = array(); |
|
| 3364 | + $this->active_gateways = array('Invoice' => false); |
|
| 3365 | + } |
|
| 3366 | 3366 | } |
@@ -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( |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | break; |
| 618 | 618 | // TEST #6 : verify config class is accessible |
| 619 | 619 | case 6: |
| 620 | - if (! class_exists($config_class)) { |
|
| 620 | + if ( ! class_exists($config_class)) { |
|
| 621 | 621 | if ($display_errors) { |
| 622 | 622 | throw new EE_Error( |
| 623 | 623 | sprintf( |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | break; |
| 635 | 635 | // TEST #7 : check that config has even been set |
| 636 | 636 | case 7: |
| 637 | - if (! isset($this->{$section}->{$name})) { |
|
| 637 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 638 | 638 | if ($display_errors) { |
| 639 | 639 | throw new EE_Error( |
| 640 | 640 | sprintf( |
@@ -652,7 +652,7 @@ discard block |
||
| 652 | 652 | break; |
| 653 | 653 | // TEST #8 : check that config is the requested type |
| 654 | 654 | case 8: |
| 655 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 655 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 656 | 656 | if ($display_errors) { |
| 657 | 657 | throw new EE_Error( |
| 658 | 658 | sprintf( |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | break; |
| 672 | 672 | // TEST #9 : verify config object |
| 673 | 673 | case 9: |
| 674 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 674 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 675 | 675 | if ($display_errors) { |
| 676 | 676 | throw new EE_Error( |
| 677 | 677 | sprintf( |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | */ |
| 704 | 704 | private function _generate_config_option_name($section = '', $name = '') |
| 705 | 705 | { |
| 706 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 706 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | { |
| 721 | 721 | return ! empty($config_class) |
| 722 | 722 | ? $config_class |
| 723 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 723 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | |
@@ -739,17 +739,17 @@ discard block |
||
| 739 | 739 | // ensure config class is set to something |
| 740 | 740 | $config_class = $this->_set_config_class($config_class, $name); |
| 741 | 741 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 742 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 742 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 743 | 743 | return null; |
| 744 | 744 | } |
| 745 | 745 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 746 | 746 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 747 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 748 | - $this->_addon_option_names[ $config_option_name ] = $config_class; |
|
| 747 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 748 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 749 | 749 | $this->update_addon_option_names(); |
| 750 | 750 | } |
| 751 | 751 | // verify the incoming config object but suppress errors |
| 752 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 752 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 753 | 753 | $config_obj = new $config_class(); |
| 754 | 754 | } |
| 755 | 755 | if (get_option($config_option_name)) { |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | } |
| 810 | 810 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 811 | 811 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 812 | - if (! isset($this->_addon_option_names[ $config_option_name ])) { |
|
| 812 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 813 | 813 | // save new config to db |
| 814 | 814 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 815 | 815 | return true; |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | 'event_espresso' |
| 836 | 836 | ), |
| 837 | 837 | $config_class, |
| 838 | - 'EE_Config->' . $section . '->' . $name |
|
| 838 | + 'EE_Config->'.$section.'->'.$name |
|
| 839 | 839 | ), |
| 840 | 840 | __FILE__, |
| 841 | 841 | __FUNCTION__, |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | // ensure config class is set to something |
| 862 | 862 | $config_class = $this->_set_config_class($config_class, $name); |
| 863 | 863 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 864 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 864 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 865 | 865 | return null; |
| 866 | 866 | } |
| 867 | 867 | // now test if the requested config object exists, but suppress errors |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | // retrieve the wp-option for this config class. |
| 907 | 907 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 908 | 908 | if (empty($config_option)) { |
| 909 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 909 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 910 | 910 | } |
| 911 | 911 | return $config_option; |
| 912 | 912 | } |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | // copy incoming $_REQUEST and sanitize it so we can save it |
| 925 | 925 | $_request = $_REQUEST; |
| 926 | 926 | array_walk_recursive($_request, 'sanitize_text_field'); |
| 927 | - $config_log[ (string) microtime(true) ] = array( |
|
| 927 | + $config_log[(string) microtime(true)] = array( |
|
| 928 | 928 | 'config_name' => $config_option_name, |
| 929 | 929 | 'request' => $_request, |
| 930 | 930 | ); |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | */ |
| 940 | 940 | public static function trim_log() |
| 941 | 941 | { |
| 942 | - if (! EE_Config::logging_enabled()) { |
|
| 942 | + if ( ! EE_Config::logging_enabled()) { |
|
| 943 | 943 | return; |
| 944 | 944 | } |
| 945 | 945 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | public static function get_page_for_posts() |
| 964 | 964 | { |
| 965 | 965 | $page_for_posts = get_option('page_for_posts'); |
| 966 | - if (! $page_for_posts) { |
|
| 966 | + if ( ! $page_for_posts) { |
|
| 967 | 967 | return 'posts'; |
| 968 | 968 | } |
| 969 | 969 | /** @type WPDB $wpdb */ |
@@ -1021,13 +1021,13 @@ discard block |
||
| 1021 | 1021 | ) |
| 1022 | 1022 | ) { |
| 1023 | 1023 | // grab list of installed widgets |
| 1024 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1024 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 1025 | 1025 | // filter list of modules to register |
| 1026 | 1026 | $widgets_to_register = apply_filters( |
| 1027 | 1027 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1028 | 1028 | $widgets_to_register |
| 1029 | 1029 | ); |
| 1030 | - if (! empty($widgets_to_register)) { |
|
| 1030 | + if ( ! empty($widgets_to_register)) { |
|
| 1031 | 1031 | // cycle thru widget folders |
| 1032 | 1032 | foreach ($widgets_to_register as $widget_path) { |
| 1033 | 1033 | // add to list of installed widget modules |
@@ -1077,31 +1077,31 @@ discard block |
||
| 1077 | 1077 | // create classname from widget directory name |
| 1078 | 1078 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1079 | 1079 | // add class prefix |
| 1080 | - $widget_class = 'EEW_' . $widget; |
|
| 1080 | + $widget_class = 'EEW_'.$widget; |
|
| 1081 | 1081 | // does the widget exist ? |
| 1082 | - if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) { |
|
| 1082 | + if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) { |
|
| 1083 | 1083 | $msg = sprintf( |
| 1084 | 1084 | __( |
| 1085 | 1085 | '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', |
| 1086 | 1086 | 'event_espresso' |
| 1087 | 1087 | ), |
| 1088 | 1088 | $widget_class, |
| 1089 | - $widget_path . '/' . $widget_class . $widget_ext |
|
| 1089 | + $widget_path.'/'.$widget_class.$widget_ext |
|
| 1090 | 1090 | ); |
| 1091 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1091 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1092 | 1092 | return; |
| 1093 | 1093 | } |
| 1094 | 1094 | // load the widget class file |
| 1095 | - require_once($widget_path . '/' . $widget_class . $widget_ext); |
|
| 1095 | + require_once($widget_path.'/'.$widget_class.$widget_ext); |
|
| 1096 | 1096 | // verify that class exists |
| 1097 | - if (! class_exists($widget_class)) { |
|
| 1097 | + if ( ! class_exists($widget_class)) { |
|
| 1098 | 1098 | $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1099 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1099 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1100 | 1100 | return; |
| 1101 | 1101 | } |
| 1102 | 1102 | register_widget($widget_class); |
| 1103 | 1103 | // add to array of registered widgets |
| 1104 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext; |
|
| 1104 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext; |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | |
@@ -1114,19 +1114,19 @@ discard block |
||
| 1114 | 1114 | private function _register_modules() |
| 1115 | 1115 | { |
| 1116 | 1116 | // grab list of installed modules |
| 1117 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1117 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1118 | 1118 | // filter list of modules to register |
| 1119 | 1119 | $modules_to_register = apply_filters( |
| 1120 | 1120 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1121 | 1121 | $modules_to_register |
| 1122 | 1122 | ); |
| 1123 | - if (! empty($modules_to_register)) { |
|
| 1123 | + if ( ! empty($modules_to_register)) { |
|
| 1124 | 1124 | // loop through folders |
| 1125 | 1125 | foreach ($modules_to_register as $module_path) { |
| 1126 | 1126 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1127 | 1127 | if ( |
| 1128 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1129 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1128 | + $module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1129 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1130 | 1130 | ) { |
| 1131 | 1131 | // add to list of installed modules |
| 1132 | 1132 | EE_Config::register_module($module_path); |
@@ -1163,25 +1163,25 @@ discard block |
||
| 1163 | 1163 | // remove last segment |
| 1164 | 1164 | array_pop($module_path); |
| 1165 | 1165 | // glue it back together |
| 1166 | - $module_path = implode('/', $module_path) . '/'; |
|
| 1166 | + $module_path = implode('/', $module_path).'/'; |
|
| 1167 | 1167 | // take first segment from file name pieces and sanitize it |
| 1168 | 1168 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1169 | 1169 | // ensure class prefix is added |
| 1170 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1170 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1171 | 1171 | } else { |
| 1172 | 1172 | // we need to generate the filename based off of the folder name |
| 1173 | 1173 | // grab and sanitize module name |
| 1174 | 1174 | $module = strtolower(basename($module_path)); |
| 1175 | 1175 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1176 | 1176 | // like trailingslashit() |
| 1177 | - $module_path = rtrim($module_path, '/') . '/'; |
|
| 1177 | + $module_path = rtrim($module_path, '/').'/'; |
|
| 1178 | 1178 | // create classname from module directory name |
| 1179 | 1179 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1180 | 1180 | // add class prefix |
| 1181 | - $module_class = 'EED_' . $module; |
|
| 1181 | + $module_class = 'EED_'.$module; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | // does the module exist ? |
| 1184 | - if (! is_readable($module_path . '/' . $module_class . $module_ext)) { |
|
| 1184 | + if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) { |
|
| 1185 | 1185 | $msg = sprintf( |
| 1186 | 1186 | __( |
| 1187 | 1187 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1189,19 +1189,19 @@ discard block |
||
| 1189 | 1189 | ), |
| 1190 | 1190 | $module |
| 1191 | 1191 | ); |
| 1192 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1192 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1193 | 1193 | return false; |
| 1194 | 1194 | } |
| 1195 | 1195 | // load the module class file |
| 1196 | - require_once($module_path . $module_class . $module_ext); |
|
| 1196 | + require_once($module_path.$module_class.$module_ext); |
|
| 1197 | 1197 | // verify that class exists |
| 1198 | - if (! class_exists($module_class)) { |
|
| 1198 | + if ( ! class_exists($module_class)) { |
|
| 1199 | 1199 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1200 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1200 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1201 | 1201 | return false; |
| 1202 | 1202 | } |
| 1203 | 1203 | // add to array of registered modules |
| 1204 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1204 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1205 | 1205 | do_action( |
| 1206 | 1206 | 'AHEE__EE_Config__register_module__complete', |
| 1207 | 1207 | $module_class, |
@@ -1252,26 +1252,26 @@ discard block |
||
| 1252 | 1252 | { |
| 1253 | 1253 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1254 | 1254 | $module = str_replace('EED_', '', $module); |
| 1255 | - $module_class = 'EED_' . $module; |
|
| 1256 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1255 | + $module_class = 'EED_'.$module; |
|
| 1256 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1257 | 1257 | $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1258 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1258 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1259 | 1259 | return false; |
| 1260 | 1260 | } |
| 1261 | 1261 | if (empty($route)) { |
| 1262 | 1262 | $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
| 1263 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1263 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1264 | 1264 | return false; |
| 1265 | 1265 | } |
| 1266 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1266 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1267 | 1267 | $msg = sprintf( |
| 1268 | 1268 | __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1269 | 1269 | $route |
| 1270 | 1270 | ); |
| 1271 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1271 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1272 | 1272 | return false; |
| 1273 | 1273 | } |
| 1274 | - EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name); |
|
| 1274 | + EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name); |
|
| 1275 | 1275 | return true; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
@@ -1288,8 +1288,8 @@ discard block |
||
| 1288 | 1288 | { |
| 1289 | 1289 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1290 | 1290 | $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
| 1291 | - if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) { |
|
| 1292 | - return EE_Config::$_module_route_map[ $key ][ $route ]; |
|
| 1291 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1292 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1293 | 1293 | } |
| 1294 | 1294 | return null; |
| 1295 | 1295 | } |
@@ -1321,47 +1321,47 @@ discard block |
||
| 1321 | 1321 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1322 | 1322 | { |
| 1323 | 1323 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1324 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1324 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1325 | 1325 | $msg = sprintf( |
| 1326 | 1326 | __('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1327 | 1327 | $route |
| 1328 | 1328 | ); |
| 1329 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1329 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1330 | 1330 | return false; |
| 1331 | 1331 | } |
| 1332 | 1332 | if (empty($forward)) { |
| 1333 | 1333 | $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1334 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1334 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1335 | 1335 | return false; |
| 1336 | 1336 | } |
| 1337 | 1337 | if (is_array($forward)) { |
| 1338 | - if (! isset($forward[1])) { |
|
| 1338 | + if ( ! isset($forward[1])) { |
|
| 1339 | 1339 | $msg = sprintf( |
| 1340 | 1340 | __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1341 | 1341 | $route |
| 1342 | 1342 | ); |
| 1343 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1343 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1344 | 1344 | return false; |
| 1345 | 1345 | } |
| 1346 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1346 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1347 | 1347 | $msg = sprintf( |
| 1348 | 1348 | __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1349 | 1349 | $forward[1], |
| 1350 | 1350 | $route |
| 1351 | 1351 | ); |
| 1352 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1352 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1353 | 1353 | return false; |
| 1354 | 1354 | } |
| 1355 | - } elseif (! function_exists($forward)) { |
|
| 1355 | + } elseif ( ! function_exists($forward)) { |
|
| 1356 | 1356 | $msg = sprintf( |
| 1357 | 1357 | __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1358 | 1358 | $forward, |
| 1359 | 1359 | $route |
| 1360 | 1360 | ); |
| 1361 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1361 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1362 | 1362 | return false; |
| 1363 | 1363 | } |
| 1364 | - EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward; |
|
| 1364 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1365 | 1365 | return true; |
| 1366 | 1366 | } |
| 1367 | 1367 | |
@@ -1379,10 +1379,10 @@ discard block |
||
| 1379 | 1379 | public static function get_forward($route = null, $status = 0, $key = 'ee') |
| 1380 | 1380 | { |
| 1381 | 1381 | do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
| 1382 | - if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) { |
|
| 1382 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1383 | 1383 | return apply_filters( |
| 1384 | 1384 | 'FHEE__EE_Config__get_forward', |
| 1385 | - EE_Config::$_module_forward_map[ $key ][ $route ][ $status ], |
|
| 1385 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1386 | 1386 | $route, |
| 1387 | 1387 | $status |
| 1388 | 1388 | ); |
@@ -1406,15 +1406,15 @@ discard block |
||
| 1406 | 1406 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1407 | 1407 | { |
| 1408 | 1408 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1409 | - if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) { |
|
| 1409 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1410 | 1410 | $msg = sprintf( |
| 1411 | 1411 | __('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1412 | 1412 | $route |
| 1413 | 1413 | ); |
| 1414 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1414 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1415 | 1415 | return false; |
| 1416 | 1416 | } |
| 1417 | - if (! is_readable($view)) { |
|
| 1417 | + if ( ! is_readable($view)) { |
|
| 1418 | 1418 | $msg = sprintf( |
| 1419 | 1419 | __( |
| 1420 | 1420 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1422,10 +1422,10 @@ discard block |
||
| 1422 | 1422 | ), |
| 1423 | 1423 | $view |
| 1424 | 1424 | ); |
| 1425 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1425 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1426 | 1426 | return false; |
| 1427 | 1427 | } |
| 1428 | - EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view; |
|
| 1428 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1429 | 1429 | return true; |
| 1430 | 1430 | } |
| 1431 | 1431 | |
@@ -1443,10 +1443,10 @@ discard block |
||
| 1443 | 1443 | public static function get_view($route = null, $status = 0, $key = 'ee') |
| 1444 | 1444 | { |
| 1445 | 1445 | do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
| 1446 | - if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) { |
|
| 1446 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1447 | 1447 | return apply_filters( |
| 1448 | 1448 | 'FHEE__EE_Config__get_view', |
| 1449 | - EE_Config::$_module_view_map[ $key ][ $route ][ $status ], |
|
| 1449 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1450 | 1450 | $route, |
| 1451 | 1451 | $status |
| 1452 | 1452 | ); |
@@ -1473,7 +1473,7 @@ discard block |
||
| 1473 | 1473 | public static function getLegacyShortcodesManager() |
| 1474 | 1474 | { |
| 1475 | 1475 | |
| 1476 | - if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1476 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1477 | 1477 | EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
| 1478 | 1478 | EE_Registry::instance() |
| 1479 | 1479 | ); |
@@ -1520,7 +1520,7 @@ discard block |
||
| 1520 | 1520 | */ |
| 1521 | 1521 | public function get_pretty($property) |
| 1522 | 1522 | { |
| 1523 | - if (! property_exists($this, $property)) { |
|
| 1523 | + if ( ! property_exists($this, $property)) { |
|
| 1524 | 1524 | throw new EE_Error( |
| 1525 | 1525 | sprintf( |
| 1526 | 1526 | __( |
@@ -1749,11 +1749,11 @@ discard block |
||
| 1749 | 1749 | */ |
| 1750 | 1750 | public function reg_page_url() |
| 1751 | 1751 | { |
| 1752 | - if (! $this->reg_page_url) { |
|
| 1752 | + if ( ! $this->reg_page_url) { |
|
| 1753 | 1753 | $this->reg_page_url = add_query_arg( |
| 1754 | 1754 | array('uts' => time()), |
| 1755 | 1755 | get_permalink($this->reg_page_id) |
| 1756 | - ) . '#checkout'; |
|
| 1756 | + ).'#checkout'; |
|
| 1757 | 1757 | } |
| 1758 | 1758 | return $this->reg_page_url; |
| 1759 | 1759 | } |
@@ -1769,7 +1769,7 @@ discard block |
||
| 1769 | 1769 | */ |
| 1770 | 1770 | public function txn_page_url($query_args = array()) |
| 1771 | 1771 | { |
| 1772 | - if (! $this->txn_page_url) { |
|
| 1772 | + if ( ! $this->txn_page_url) { |
|
| 1773 | 1773 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1774 | 1774 | } |
| 1775 | 1775 | if ($query_args) { |
@@ -1790,7 +1790,7 @@ discard block |
||
| 1790 | 1790 | */ |
| 1791 | 1791 | public function thank_you_page_url($query_args = array()) |
| 1792 | 1792 | { |
| 1793 | - if (! $this->thank_you_page_url) { |
|
| 1793 | + if ( ! $this->thank_you_page_url) { |
|
| 1794 | 1794 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1795 | 1795 | } |
| 1796 | 1796 | if ($query_args) { |
@@ -1809,7 +1809,7 @@ discard block |
||
| 1809 | 1809 | */ |
| 1810 | 1810 | public function cancel_page_url() |
| 1811 | 1811 | { |
| 1812 | - if (! $this->cancel_page_url) { |
|
| 1812 | + if ( ! $this->cancel_page_url) { |
|
| 1813 | 1813 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1814 | 1814 | } |
| 1815 | 1815 | return $this->cancel_page_url; |
@@ -1852,13 +1852,13 @@ discard block |
||
| 1852 | 1852 | $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
| 1853 | 1853 | $option = self::OPTION_NAME_UXIP; |
| 1854 | 1854 | // set correct table for query |
| 1855 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1855 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1856 | 1856 | // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
| 1857 | 1857 | // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
| 1858 | 1858 | // re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1859 | 1859 | // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1860 | 1860 | // for the purpose of caching. |
| 1861 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1861 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1862 | 1862 | if (false !== $pre) { |
| 1863 | 1863 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1864 | 1864 | return EE_Core_Config::$ee_ueip_option; |
@@ -1872,10 +1872,10 @@ discard block |
||
| 1872 | 1872 | if (is_object($row)) { |
| 1873 | 1873 | $value = $row->option_value; |
| 1874 | 1874 | } else { // option does not exist so use default. |
| 1875 | - EE_Core_Config::$ee_ueip_option = apply_filters('default_option_' . $option, false, $option); |
|
| 1875 | + EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option); |
|
| 1876 | 1876 | return EE_Core_Config::$ee_ueip_option; |
| 1877 | 1877 | } |
| 1878 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1878 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1879 | 1879 | return EE_Core_Config::$ee_ueip_option; |
| 1880 | 1880 | } |
| 1881 | 1881 | |
@@ -2137,30 +2137,30 @@ discard block |
||
| 2137 | 2137 | // retrieve the country settings from the db, just in case they have been customized |
| 2138 | 2138 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2139 | 2139 | if ($country instanceof EE_Country) { |
| 2140 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2141 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2142 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2143 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2140 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2141 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2142 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2143 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2144 | 2144 | $this->sign_b4 = $country->currency_sign_before( |
| 2145 | - ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2146 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2145 | + ); // currency sign before or after: $TRUE or FALSE$ |
|
| 2146 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2147 | 2147 | $this->dec_mrk = $country->currency_decimal_mark( |
| 2148 | - ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2148 | + ); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2149 | 2149 | $this->thsnds = $country->currency_thousands_separator( |
| 2150 | - ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2150 | + ); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2151 | 2151 | } |
| 2152 | 2152 | } |
| 2153 | 2153 | // fallback to hardcoded defaults, in case the above failed |
| 2154 | 2154 | if (empty($this->code)) { |
| 2155 | 2155 | // set default currency settings |
| 2156 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2157 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2158 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2159 | - $this->sign = '$'; // currency sign: $ |
|
| 2160 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2161 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2162 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2163 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2156 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2157 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
| 2158 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
| 2159 | + $this->sign = '$'; // currency sign: $ |
|
| 2160 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2161 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2162 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2163 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2164 | 2164 | } |
| 2165 | 2165 | } |
| 2166 | 2166 | } |
@@ -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 | } |
@@ -2665,7 +2665,7 @@ discard block |
||
| 2665 | 2665 | public function log_file_name($reset = false) |
| 2666 | 2666 | { |
| 2667 | 2667 | if (empty($this->log_file_name) || $reset) { |
| 2668 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2668 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2669 | 2669 | EE_Config::instance()->update_espresso_config(false, false); |
| 2670 | 2670 | } |
| 2671 | 2671 | return $this->log_file_name; |
@@ -2679,7 +2679,7 @@ discard block |
||
| 2679 | 2679 | public function debug_file_name($reset = false) |
| 2680 | 2680 | { |
| 2681 | 2681 | if (empty($this->debug_file_name) || $reset) { |
| 2682 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2682 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2683 | 2683 | EE_Config::instance()->update_espresso_config(false, false); |
| 2684 | 2684 | } |
| 2685 | 2685 | return $this->debug_file_name; |
@@ -2906,21 +2906,21 @@ discard block |
||
| 2906 | 2906 | $this->use_google_maps = true; |
| 2907 | 2907 | $this->google_map_api_key = ''; |
| 2908 | 2908 | // for event details pages (reg page) |
| 2909 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2910 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2911 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2912 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2913 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2914 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2915 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2909 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2910 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2911 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2912 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2913 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2914 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2915 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2916 | 2916 | // for event list pages |
| 2917 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2918 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2919 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2920 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2921 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2922 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2923 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2917 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2918 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2919 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2920 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2921 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2922 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2923 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2924 | 2924 | } |
| 2925 | 2925 | } |
| 2926 | 2926 | |