@@ -18,27 +18,27 @@ |
||
| 18 | 18 | * @author Darren Ethier |
| 19 | 19 | */ |
| 20 | 20 | class EE_Messages_Email_Newsletter_Validator extends EE_Messages_Validator { |
| 21 | - public function __construct( $fields, $context ) { |
|
| 22 | - $this->_m_name = 'email'; |
|
| 23 | - $this->_mt_name = 'newsletter'; |
|
| 21 | + public function __construct( $fields, $context ) { |
|
| 22 | + $this->_m_name = 'email'; |
|
| 23 | + $this->_mt_name = 'newsletter'; |
|
| 24 | 24 | |
| 25 | - parent::__construct( $fields, $context ); |
|
| 26 | - } |
|
| 25 | + parent::__construct( $fields, $context ); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * custom validator (restricting what was originally set by the messenger) |
|
| 30 | - */ |
|
| 31 | - protected function _modify_validator() { |
|
| 32 | - if ( $this->_context == 'attendee' ) |
|
| 33 | - $this->_valid_shortcodes_modifier[$this->_context]['from'] = array('recipient_details', 'email', 'organization'); |
|
| 28 | + /** |
|
| 29 | + * custom validator (restricting what was originally set by the messenger) |
|
| 30 | + */ |
|
| 31 | + protected function _modify_validator() { |
|
| 32 | + if ( $this->_context == 'attendee' ) |
|
| 33 | + $this->_valid_shortcodes_modifier[$this->_context]['from'] = array('recipient_details', 'email', 'organization'); |
|
| 34 | 34 | |
| 35 | - //excluded shortcodes |
|
| 36 | - $fields = array('to','from','subject','content','newsletter_content'); |
|
| 37 | - foreach ( $fields as $field ) { |
|
| 38 | - $this->_specific_shortcode_excludes[$field] = array('[RECIPIENT_REGISTRATION_CODE]', '[EVENT_AUTHOR_FORMATTED_EMAIL]', '[EVENT_AUTHOR_EMAIL]'); |
|
| 39 | - } |
|
| 40 | - $add_excludes = array( '[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]','[CO_ADD2]', '[CO_CITY]', '[CO_STATE]','[CO_ZIP]','[CO_LOGO]','[CO_PHONE]','[CO_LOGO_URL]','[CO_FACEBOOK_URL]','[CO_TWITTER_URL]','[CO_PINTEREST_URL]','[CO_GOOGLE_URL]','[CO_LINKEDIN_URL]','[CO_INSTAGRAM_URL]'); |
|
| 41 | - $this->_specific_shortcode_excludes['from'] = array_merge($this->_specific_shortcode_excludes['from'], $add_excludes); |
|
| 42 | - $this->_specific_shortcode_excludes['content'] = array_merge( $this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') ); |
|
| 43 | - } |
|
| 35 | + //excluded shortcodes |
|
| 36 | + $fields = array('to','from','subject','content','newsletter_content'); |
|
| 37 | + foreach ( $fields as $field ) { |
|
| 38 | + $this->_specific_shortcode_excludes[$field] = array('[RECIPIENT_REGISTRATION_CODE]', '[EVENT_AUTHOR_FORMATTED_EMAIL]', '[EVENT_AUTHOR_EMAIL]'); |
|
| 39 | + } |
|
| 40 | + $add_excludes = array( '[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]','[CO_ADD2]', '[CO_CITY]', '[CO_STATE]','[CO_ZIP]','[CO_LOGO]','[CO_PHONE]','[CO_LOGO_URL]','[CO_FACEBOOK_URL]','[CO_TWITTER_URL]','[CO_PINTEREST_URL]','[CO_GOOGLE_URL]','[CO_LINKEDIN_URL]','[CO_INSTAGRAM_URL]'); |
|
| 41 | + $this->_specific_shortcode_excludes['from'] = array_merge($this->_specific_shortcode_excludes['from'], $add_excludes); |
|
| 42 | + $this->_specific_shortcode_excludes['content'] = array_merge( $this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') ); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -18,27 +18,27 @@ |
||
| 18 | 18 | * @author Darren Ethier |
| 19 | 19 | */ |
| 20 | 20 | class EE_Messages_Email_Newsletter_Validator extends EE_Messages_Validator { |
| 21 | - public function __construct( $fields, $context ) { |
|
| 21 | + public function __construct($fields, $context) { |
|
| 22 | 22 | $this->_m_name = 'email'; |
| 23 | 23 | $this->_mt_name = 'newsletter'; |
| 24 | 24 | |
| 25 | - parent::__construct( $fields, $context ); |
|
| 25 | + parent::__construct($fields, $context); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * custom validator (restricting what was originally set by the messenger) |
| 30 | 30 | */ |
| 31 | 31 | protected function _modify_validator() { |
| 32 | - if ( $this->_context == 'attendee' ) |
|
| 32 | + if ($this->_context == 'attendee') |
|
| 33 | 33 | $this->_valid_shortcodes_modifier[$this->_context]['from'] = array('recipient_details', 'email', 'organization'); |
| 34 | 34 | |
| 35 | 35 | //excluded shortcodes |
| 36 | - $fields = array('to','from','subject','content','newsletter_content'); |
|
| 37 | - foreach ( $fields as $field ) { |
|
| 36 | + $fields = array('to', 'from', 'subject', 'content', 'newsletter_content'); |
|
| 37 | + foreach ($fields as $field) { |
|
| 38 | 38 | $this->_specific_shortcode_excludes[$field] = array('[RECIPIENT_REGISTRATION_CODE]', '[EVENT_AUTHOR_FORMATTED_EMAIL]', '[EVENT_AUTHOR_EMAIL]'); |
| 39 | 39 | } |
| 40 | - $add_excludes = array( '[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]','[CO_ADD2]', '[CO_CITY]', '[CO_STATE]','[CO_ZIP]','[CO_LOGO]','[CO_PHONE]','[CO_LOGO_URL]','[CO_FACEBOOK_URL]','[CO_TWITTER_URL]','[CO_PINTEREST_URL]','[CO_GOOGLE_URL]','[CO_LINKEDIN_URL]','[CO_INSTAGRAM_URL]'); |
|
| 40 | + $add_excludes = array('[RECIPIENT_FNAME]', '[RECIPIENT_LNAME]', '[RECIPIENT_EMAIL]', '[COMPANY]', '[CO_ADD1]', '[CO_ADD2]', '[CO_CITY]', '[CO_STATE]', '[CO_ZIP]', '[CO_LOGO]', '[CO_PHONE]', '[CO_LOGO_URL]', '[CO_FACEBOOK_URL]', '[CO_TWITTER_URL]', '[CO_PINTEREST_URL]', '[CO_GOOGLE_URL]', '[CO_LINKEDIN_URL]', '[CO_INSTAGRAM_URL]'); |
|
| 41 | 41 | $this->_specific_shortcode_excludes['from'] = array_merge($this->_specific_shortcode_excludes['from'], $add_excludes); |
| 42 | - $this->_specific_shortcode_excludes['content'] = array_merge( $this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]') ); |
|
| 42 | + $this->_specific_shortcode_excludes['content'] = array_merge($this->_specific_shortcode_excludes['content'], array('[DISPLAY_PDF_URL]', '[DISPLAY_PDF_BUTTON]')); |
|
| 43 | 43 | } |
| 44 | 44 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * Get Timezone Offset for given timezone object. |
| 338 | 338 | * |
| 339 | 339 | * @param DateTimeZone $date_time_zone |
| 340 | - * @param null $time |
|
| 340 | + * @param integer|null $time |
|
| 341 | 341 | * @return mixed |
| 342 | 342 | * @throws DomainException |
| 343 | 343 | */ |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | * @param DateTime $DateTime DateTime object |
| 562 | 562 | * @param string $period a value to indicate what interval is being used in the calculation. The options are |
| 563 | 563 | * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
| 564 | - * @param int|string $value What you want to increment the date by |
|
| 564 | + * @param integer $value What you want to increment the date by |
|
| 565 | 565 | * @param string $operand What operand you wish to use for the calculation |
| 566 | 566 | * @return DateTime return whatever type came in. |
| 567 | 567 | * @throws Exception |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | * this method will add that "1" into your date regardless of the format. |
| 1098 | 1098 | * |
| 1099 | 1099 | * @param string $month |
| 1100 | - * @return string |
|
| 1100 | + * @return integer |
|
| 1101 | 1101 | */ |
| 1102 | 1102 | public static function first_of_month_timestamp($month = '') |
| 1103 | 1103 | { |
@@ -1245,7 +1245,7 @@ discard block |
||
| 1245 | 1245 | /** |
| 1246 | 1246 | * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
| 1247 | 1247 | * |
| 1248 | - * @param int|WP_User $user_id |
|
| 1248 | + * @param integer $user_id |
|
| 1249 | 1249 | * @return string |
| 1250 | 1250 | */ |
| 1251 | 1251 | public static function get_user_locale($user_id = 0) |
@@ -15,377 +15,377 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * return the timezone set for the WP install |
|
| 20 | - * |
|
| 21 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
| 22 | - * @throws EE_Error |
|
| 23 | - */ |
|
| 24 | - public static function get_timezone() |
|
| 25 | - { |
|
| 26 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * get_valid_timezone_string |
|
| 32 | - * ensures that a valid timezone string is returned |
|
| 33 | - * |
|
| 34 | - * @param string $timezone_string |
|
| 35 | - * @return string |
|
| 36 | - * @throws EE_Error |
|
| 37 | - */ |
|
| 38 | - public static function get_valid_timezone_string($timezone_string = '') |
|
| 39 | - { |
|
| 40 | - // if passed a value, then use that, else get WP option |
|
| 41 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
| 42 | - // value from above exists, use that, else get timezone string from gmt_offset |
|
| 43 | - $timezone_string = ! empty($timezone_string) |
|
| 44 | - ? $timezone_string |
|
| 45 | - : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 46 | - EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 47 | - return $timezone_string; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 53 | - * |
|
| 54 | - * @static |
|
| 55 | - * @param string $timezone_string Timezone string to check |
|
| 56 | - * @param bool $throw_error |
|
| 57 | - * @return bool |
|
| 58 | - * @throws EE_Error |
|
| 59 | - */ |
|
| 60 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 61 | - { |
|
| 62 | - // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
|
| 63 | - try { |
|
| 64 | - new DateTimeZone($timezone_string); |
|
| 65 | - } catch (Exception $e) { |
|
| 66 | - // sometimes we take exception to exceptions |
|
| 67 | - if (! $throw_error) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - throw new EE_Error( |
|
| 71 | - sprintf( |
|
| 72 | - esc_html__( |
|
| 73 | - 'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 74 | - 'event_espresso' |
|
| 75 | - ), |
|
| 76 | - $timezone_string, |
|
| 77 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 78 | - '</a>' |
|
| 79 | - ) |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - return true; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * _create_timezone_object_from_timezone_name |
|
| 88 | - * |
|
| 89 | - * @param float|string $gmt_offset |
|
| 90 | - * @return string |
|
| 91 | - * @throws EE_Error |
|
| 92 | - */ |
|
| 93 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 94 | - { |
|
| 95 | - $timezone_string = 'UTC'; |
|
| 96 | - //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 97 | - //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 98 | - //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 99 | - if ($gmt_offset === '') { |
|
| 100 | - //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 101 | - if (get_option('timezone_string')) { |
|
| 102 | - return (string) get_option('timezone_string'); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset'); |
|
| 106 | - $gmt_offset = (float) $gmt_offset; |
|
| 107 | - //if $gmt_offset is 0, then just return UTC |
|
| 108 | - if ($gmt_offset === (float) 0) { |
|
| 109 | - return $timezone_string; |
|
| 110 | - } |
|
| 111 | - if ($gmt_offset !== '') { |
|
| 112 | - // convert GMT offset to seconds |
|
| 113 | - $gmt_offset *= HOUR_IN_SECONDS; |
|
| 114 | - // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 115 | - $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 116 | - //only use this timezone_string IF it's current offset matches the given offset |
|
| 117 | - if(! empty($timezone_string)) { |
|
| 118 | - $offset = null; |
|
| 119 | - try { |
|
| 120 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 121 | - if ($offset !== $gmt_offset) { |
|
| 122 | - $timezone_string = false; |
|
| 123 | - } |
|
| 124 | - } catch (Exception $e) { |
|
| 125 | - $timezone_string = false; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 130 | - $timezone_string = $timezone_string !== false |
|
| 131 | - ? $timezone_string |
|
| 132 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 133 | - return $timezone_string; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Gets the site's GMT offset based on either the timezone string |
|
| 139 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 140 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 141 | - * |
|
| 142 | - * @return int seconds offset |
|
| 143 | - */ |
|
| 144 | - public static function get_site_timezone_gmt_offset() |
|
| 145 | - { |
|
| 146 | - $timezone_string = (string) get_option('timezone_string'); |
|
| 147 | - if ($timezone_string) { |
|
| 148 | - try { |
|
| 149 | - $timezone = new DateTimeZone($timezone_string); |
|
| 150 | - return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 151 | - } catch (Exception $e) { |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - $offset = get_option('gmt_offset'); |
|
| 155 | - return (int) ($offset * HOUR_IN_SECONDS); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Depending on PHP version, |
|
| 161 | - * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
| 162 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 163 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 164 | - * |
|
| 165 | - * @param int $gmt_offset |
|
| 166 | - * @return int |
|
| 167 | - */ |
|
| 168 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 169 | - { |
|
| 170 | - //make sure $gmt_offset is int |
|
| 171 | - $gmt_offset = (int) $gmt_offset; |
|
| 172 | - switch ($gmt_offset) { |
|
| 173 | - //-12 |
|
| 174 | - case -43200: |
|
| 175 | - $gmt_offset = -39600; |
|
| 176 | - break; |
|
| 177 | - //-11.5 |
|
| 178 | - case -41400: |
|
| 179 | - $gmt_offset = -39600; |
|
| 180 | - break; |
|
| 181 | - //-10.5 |
|
| 182 | - case -37800: |
|
| 183 | - $gmt_offset = -39600; |
|
| 184 | - break; |
|
| 185 | - //-8.5 |
|
| 186 | - case -30600: |
|
| 187 | - $gmt_offset = -28800; |
|
| 188 | - break; |
|
| 189 | - //-7.5 |
|
| 190 | - case -27000: |
|
| 191 | - $gmt_offset = -25200; |
|
| 192 | - break; |
|
| 193 | - //-6.5 |
|
| 194 | - case -23400: |
|
| 195 | - $gmt_offset = -21600; |
|
| 196 | - break; |
|
| 197 | - //-5.5 |
|
| 198 | - case -19800: |
|
| 199 | - $gmt_offset = -18000; |
|
| 200 | - break; |
|
| 201 | - //-4.5 |
|
| 202 | - case -16200: |
|
| 203 | - $gmt_offset = -14400; |
|
| 204 | - break; |
|
| 205 | - //-3.5 |
|
| 206 | - case -12600: |
|
| 207 | - $gmt_offset = -10800; |
|
| 208 | - break; |
|
| 209 | - //-2.5 |
|
| 210 | - case -9000: |
|
| 211 | - $gmt_offset = -7200; |
|
| 212 | - break; |
|
| 213 | - //-1.5 |
|
| 214 | - case -5400: |
|
| 215 | - $gmt_offset = -3600; |
|
| 216 | - break; |
|
| 217 | - //-0.5 |
|
| 218 | - case -1800: |
|
| 219 | - $gmt_offset = 0; |
|
| 220 | - break; |
|
| 221 | - //.5 |
|
| 222 | - case 1800: |
|
| 223 | - $gmt_offset = 3600; |
|
| 224 | - break; |
|
| 225 | - //1.5 |
|
| 226 | - case 5400: |
|
| 227 | - $gmt_offset = 7200; |
|
| 228 | - break; |
|
| 229 | - //2.5 |
|
| 230 | - case 9000: |
|
| 231 | - $gmt_offset = 10800; |
|
| 232 | - break; |
|
| 233 | - //3.5 |
|
| 234 | - case 12600: |
|
| 235 | - $gmt_offset = 14400; |
|
| 236 | - break; |
|
| 237 | - //7.5 |
|
| 238 | - case 27000: |
|
| 239 | - $gmt_offset = 28800; |
|
| 240 | - break; |
|
| 241 | - //8.5 |
|
| 242 | - case 30600: |
|
| 243 | - $gmt_offset = 31500; |
|
| 244 | - break; |
|
| 245 | - //10.5 |
|
| 246 | - case 37800: |
|
| 247 | - $gmt_offset = 39600; |
|
| 248 | - break; |
|
| 249 | - //11.5 |
|
| 250 | - case 41400: |
|
| 251 | - $gmt_offset = 43200; |
|
| 252 | - break; |
|
| 253 | - //12.75 |
|
| 254 | - case 45900: |
|
| 255 | - $gmt_offset = 46800; |
|
| 256 | - break; |
|
| 257 | - //13.75 |
|
| 258 | - case 49500: |
|
| 259 | - $gmt_offset = 50400; |
|
| 260 | - break; |
|
| 261 | - } |
|
| 262 | - return $gmt_offset; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * get_timezone_string_from_abbreviations_list |
|
| 268 | - * |
|
| 269 | - * @param int $gmt_offset |
|
| 270 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 271 | - * @return string |
|
| 272 | - * @throws EE_Error |
|
| 273 | - */ |
|
| 274 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 275 | - { |
|
| 276 | - $gmt_offset = (int) $gmt_offset; |
|
| 277 | - /** @var array[] $abbreviations */ |
|
| 278 | - $abbreviations = DateTimeZone::listAbbreviations(); |
|
| 279 | - foreach ($abbreviations as $abbreviation) { |
|
| 280 | - foreach ($abbreviation as $timezone) { |
|
| 281 | - if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
| 282 | - try { |
|
| 283 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
| 284 | - if ($offset !== $gmt_offset) { |
|
| 285 | - continue; |
|
| 286 | - } |
|
| 287 | - return $timezone['timezone_id']; |
|
| 288 | - } catch (Exception $e) { |
|
| 289 | - continue; |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 295 | - if ($coerce === true) { |
|
| 296 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 297 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 298 | - false |
|
| 299 | - ); |
|
| 300 | - if ($timezone_string) { |
|
| 301 | - return $timezone_string; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - throw new EE_Error( |
|
| 305 | - sprintf( |
|
| 306 | - esc_html__( |
|
| 307 | - 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 308 | - 'event_espresso' |
|
| 309 | - ), |
|
| 310 | - $gmt_offset / HOUR_IN_SECONDS, |
|
| 311 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 312 | - '</a>' |
|
| 313 | - ) |
|
| 314 | - ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get Timezone Transitions |
|
| 321 | - * |
|
| 322 | - * @param DateTimeZone $date_time_zone |
|
| 323 | - * @param int|null $time |
|
| 324 | - * @param bool $first_only |
|
| 325 | - * @return array|mixed |
|
| 326 | - */ |
|
| 327 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 328 | - { |
|
| 329 | - $time = is_int($time) || $time === null ? $time : (int) strtotime($time); |
|
| 330 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 331 | - $transitions = $date_time_zone->getTransitions($time); |
|
| 332 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Get Timezone Offset for given timezone object. |
|
| 338 | - * |
|
| 339 | - * @param DateTimeZone $date_time_zone |
|
| 340 | - * @param null $time |
|
| 341 | - * @return mixed |
|
| 342 | - * @throws DomainException |
|
| 343 | - */ |
|
| 344 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 345 | - { |
|
| 346 | - $transition = self::get_timezone_transitions($date_time_zone, $time); |
|
| 347 | - if (! isset($transition['offset'])) { |
|
| 348 | - $transition['offset'] = 0; |
|
| 349 | - if (! isset($transition['ts'])) { |
|
| 350 | - throw new DomainException( |
|
| 351 | - sprintf( |
|
| 352 | - esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'), |
|
| 353 | - print_r($transition, true) |
|
| 354 | - ) |
|
| 355 | - ); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - return $transition['offset']; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * @param string $timezone_string |
|
| 364 | - * @throws EE_Error |
|
| 365 | - */ |
|
| 366 | - public static function timezone_select_input($timezone_string = '') |
|
| 367 | - { |
|
| 368 | - // get WP date time format |
|
| 369 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 370 | - // if passed a value, then use that, else get WP option |
|
| 371 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
| 372 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 373 | - $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false) |
|
| 374 | - ? $timezone_string |
|
| 375 | - : ''; |
|
| 376 | - $gmt_offset = get_option('gmt_offset'); |
|
| 377 | - $check_zone_info = true; |
|
| 378 | - if (empty($timezone_string)) { |
|
| 379 | - // Create a UTC+- zone if no timezone string exists |
|
| 380 | - $timezone_string = 'UTC'; |
|
| 381 | - $check_zone_info = false; |
|
| 382 | - if ($gmt_offset > 0) { |
|
| 383 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 384 | - } elseif ($gmt_offset < 0) { |
|
| 385 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - ?> |
|
| 18 | + /** |
|
| 19 | + * return the timezone set for the WP install |
|
| 20 | + * |
|
| 21 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
| 22 | + * @throws EE_Error |
|
| 23 | + */ |
|
| 24 | + public static function get_timezone() |
|
| 25 | + { |
|
| 26 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * get_valid_timezone_string |
|
| 32 | + * ensures that a valid timezone string is returned |
|
| 33 | + * |
|
| 34 | + * @param string $timezone_string |
|
| 35 | + * @return string |
|
| 36 | + * @throws EE_Error |
|
| 37 | + */ |
|
| 38 | + public static function get_valid_timezone_string($timezone_string = '') |
|
| 39 | + { |
|
| 40 | + // if passed a value, then use that, else get WP option |
|
| 41 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
| 42 | + // value from above exists, use that, else get timezone string from gmt_offset |
|
| 43 | + $timezone_string = ! empty($timezone_string) |
|
| 44 | + ? $timezone_string |
|
| 45 | + : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 46 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 47 | + return $timezone_string; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 53 | + * |
|
| 54 | + * @static |
|
| 55 | + * @param string $timezone_string Timezone string to check |
|
| 56 | + * @param bool $throw_error |
|
| 57 | + * @return bool |
|
| 58 | + * @throws EE_Error |
|
| 59 | + */ |
|
| 60 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 61 | + { |
|
| 62 | + // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
|
| 63 | + try { |
|
| 64 | + new DateTimeZone($timezone_string); |
|
| 65 | + } catch (Exception $e) { |
|
| 66 | + // sometimes we take exception to exceptions |
|
| 67 | + if (! $throw_error) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + throw new EE_Error( |
|
| 71 | + sprintf( |
|
| 72 | + esc_html__( |
|
| 73 | + 'The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 74 | + 'event_espresso' |
|
| 75 | + ), |
|
| 76 | + $timezone_string, |
|
| 77 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 78 | + '</a>' |
|
| 79 | + ) |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + return true; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * _create_timezone_object_from_timezone_name |
|
| 88 | + * |
|
| 89 | + * @param float|string $gmt_offset |
|
| 90 | + * @return string |
|
| 91 | + * @throws EE_Error |
|
| 92 | + */ |
|
| 93 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 94 | + { |
|
| 95 | + $timezone_string = 'UTC'; |
|
| 96 | + //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 97 | + //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 98 | + //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 99 | + if ($gmt_offset === '') { |
|
| 100 | + //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 101 | + if (get_option('timezone_string')) { |
|
| 102 | + return (string) get_option('timezone_string'); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + $gmt_offset = $gmt_offset !== '' ? $gmt_offset : (string) get_option('gmt_offset'); |
|
| 106 | + $gmt_offset = (float) $gmt_offset; |
|
| 107 | + //if $gmt_offset is 0, then just return UTC |
|
| 108 | + if ($gmt_offset === (float) 0) { |
|
| 109 | + return $timezone_string; |
|
| 110 | + } |
|
| 111 | + if ($gmt_offset !== '') { |
|
| 112 | + // convert GMT offset to seconds |
|
| 113 | + $gmt_offset *= HOUR_IN_SECONDS; |
|
| 114 | + // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 115 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 116 | + //only use this timezone_string IF it's current offset matches the given offset |
|
| 117 | + if(! empty($timezone_string)) { |
|
| 118 | + $offset = null; |
|
| 119 | + try { |
|
| 120 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 121 | + if ($offset !== $gmt_offset) { |
|
| 122 | + $timezone_string = false; |
|
| 123 | + } |
|
| 124 | + } catch (Exception $e) { |
|
| 125 | + $timezone_string = false; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 130 | + $timezone_string = $timezone_string !== false |
|
| 131 | + ? $timezone_string |
|
| 132 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 133 | + return $timezone_string; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Gets the site's GMT offset based on either the timezone string |
|
| 139 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 140 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 141 | + * |
|
| 142 | + * @return int seconds offset |
|
| 143 | + */ |
|
| 144 | + public static function get_site_timezone_gmt_offset() |
|
| 145 | + { |
|
| 146 | + $timezone_string = (string) get_option('timezone_string'); |
|
| 147 | + if ($timezone_string) { |
|
| 148 | + try { |
|
| 149 | + $timezone = new DateTimeZone($timezone_string); |
|
| 150 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 151 | + } catch (Exception $e) { |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + $offset = get_option('gmt_offset'); |
|
| 155 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Depending on PHP version, |
|
| 161 | + * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
| 162 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 163 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 164 | + * |
|
| 165 | + * @param int $gmt_offset |
|
| 166 | + * @return int |
|
| 167 | + */ |
|
| 168 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 169 | + { |
|
| 170 | + //make sure $gmt_offset is int |
|
| 171 | + $gmt_offset = (int) $gmt_offset; |
|
| 172 | + switch ($gmt_offset) { |
|
| 173 | + //-12 |
|
| 174 | + case -43200: |
|
| 175 | + $gmt_offset = -39600; |
|
| 176 | + break; |
|
| 177 | + //-11.5 |
|
| 178 | + case -41400: |
|
| 179 | + $gmt_offset = -39600; |
|
| 180 | + break; |
|
| 181 | + //-10.5 |
|
| 182 | + case -37800: |
|
| 183 | + $gmt_offset = -39600; |
|
| 184 | + break; |
|
| 185 | + //-8.5 |
|
| 186 | + case -30600: |
|
| 187 | + $gmt_offset = -28800; |
|
| 188 | + break; |
|
| 189 | + //-7.5 |
|
| 190 | + case -27000: |
|
| 191 | + $gmt_offset = -25200; |
|
| 192 | + break; |
|
| 193 | + //-6.5 |
|
| 194 | + case -23400: |
|
| 195 | + $gmt_offset = -21600; |
|
| 196 | + break; |
|
| 197 | + //-5.5 |
|
| 198 | + case -19800: |
|
| 199 | + $gmt_offset = -18000; |
|
| 200 | + break; |
|
| 201 | + //-4.5 |
|
| 202 | + case -16200: |
|
| 203 | + $gmt_offset = -14400; |
|
| 204 | + break; |
|
| 205 | + //-3.5 |
|
| 206 | + case -12600: |
|
| 207 | + $gmt_offset = -10800; |
|
| 208 | + break; |
|
| 209 | + //-2.5 |
|
| 210 | + case -9000: |
|
| 211 | + $gmt_offset = -7200; |
|
| 212 | + break; |
|
| 213 | + //-1.5 |
|
| 214 | + case -5400: |
|
| 215 | + $gmt_offset = -3600; |
|
| 216 | + break; |
|
| 217 | + //-0.5 |
|
| 218 | + case -1800: |
|
| 219 | + $gmt_offset = 0; |
|
| 220 | + break; |
|
| 221 | + //.5 |
|
| 222 | + case 1800: |
|
| 223 | + $gmt_offset = 3600; |
|
| 224 | + break; |
|
| 225 | + //1.5 |
|
| 226 | + case 5400: |
|
| 227 | + $gmt_offset = 7200; |
|
| 228 | + break; |
|
| 229 | + //2.5 |
|
| 230 | + case 9000: |
|
| 231 | + $gmt_offset = 10800; |
|
| 232 | + break; |
|
| 233 | + //3.5 |
|
| 234 | + case 12600: |
|
| 235 | + $gmt_offset = 14400; |
|
| 236 | + break; |
|
| 237 | + //7.5 |
|
| 238 | + case 27000: |
|
| 239 | + $gmt_offset = 28800; |
|
| 240 | + break; |
|
| 241 | + //8.5 |
|
| 242 | + case 30600: |
|
| 243 | + $gmt_offset = 31500; |
|
| 244 | + break; |
|
| 245 | + //10.5 |
|
| 246 | + case 37800: |
|
| 247 | + $gmt_offset = 39600; |
|
| 248 | + break; |
|
| 249 | + //11.5 |
|
| 250 | + case 41400: |
|
| 251 | + $gmt_offset = 43200; |
|
| 252 | + break; |
|
| 253 | + //12.75 |
|
| 254 | + case 45900: |
|
| 255 | + $gmt_offset = 46800; |
|
| 256 | + break; |
|
| 257 | + //13.75 |
|
| 258 | + case 49500: |
|
| 259 | + $gmt_offset = 50400; |
|
| 260 | + break; |
|
| 261 | + } |
|
| 262 | + return $gmt_offset; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * get_timezone_string_from_abbreviations_list |
|
| 268 | + * |
|
| 269 | + * @param int $gmt_offset |
|
| 270 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 271 | + * @return string |
|
| 272 | + * @throws EE_Error |
|
| 273 | + */ |
|
| 274 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 275 | + { |
|
| 276 | + $gmt_offset = (int) $gmt_offset; |
|
| 277 | + /** @var array[] $abbreviations */ |
|
| 278 | + $abbreviations = DateTimeZone::listAbbreviations(); |
|
| 279 | + foreach ($abbreviations as $abbreviation) { |
|
| 280 | + foreach ($abbreviation as $timezone) { |
|
| 281 | + if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
| 282 | + try { |
|
| 283 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
| 284 | + if ($offset !== $gmt_offset) { |
|
| 285 | + continue; |
|
| 286 | + } |
|
| 287 | + return $timezone['timezone_id']; |
|
| 288 | + } catch (Exception $e) { |
|
| 289 | + continue; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 295 | + if ($coerce === true) { |
|
| 296 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 297 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 298 | + false |
|
| 299 | + ); |
|
| 300 | + if ($timezone_string) { |
|
| 301 | + return $timezone_string; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + throw new EE_Error( |
|
| 305 | + sprintf( |
|
| 306 | + esc_html__( |
|
| 307 | + 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 308 | + 'event_espresso' |
|
| 309 | + ), |
|
| 310 | + $gmt_offset / HOUR_IN_SECONDS, |
|
| 311 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 312 | + '</a>' |
|
| 313 | + ) |
|
| 314 | + ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get Timezone Transitions |
|
| 321 | + * |
|
| 322 | + * @param DateTimeZone $date_time_zone |
|
| 323 | + * @param int|null $time |
|
| 324 | + * @param bool $first_only |
|
| 325 | + * @return array|mixed |
|
| 326 | + */ |
|
| 327 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 328 | + { |
|
| 329 | + $time = is_int($time) || $time === null ? $time : (int) strtotime($time); |
|
| 330 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 331 | + $transitions = $date_time_zone->getTransitions($time); |
|
| 332 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Get Timezone Offset for given timezone object. |
|
| 338 | + * |
|
| 339 | + * @param DateTimeZone $date_time_zone |
|
| 340 | + * @param null $time |
|
| 341 | + * @return mixed |
|
| 342 | + * @throws DomainException |
|
| 343 | + */ |
|
| 344 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 345 | + { |
|
| 346 | + $transition = self::get_timezone_transitions($date_time_zone, $time); |
|
| 347 | + if (! isset($transition['offset'])) { |
|
| 348 | + $transition['offset'] = 0; |
|
| 349 | + if (! isset($transition['ts'])) { |
|
| 350 | + throw new DomainException( |
|
| 351 | + sprintf( |
|
| 352 | + esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'), |
|
| 353 | + print_r($transition, true) |
|
| 354 | + ) |
|
| 355 | + ); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + return $transition['offset']; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * @param string $timezone_string |
|
| 364 | + * @throws EE_Error |
|
| 365 | + */ |
|
| 366 | + public static function timezone_select_input($timezone_string = '') |
|
| 367 | + { |
|
| 368 | + // get WP date time format |
|
| 369 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 370 | + // if passed a value, then use that, else get WP option |
|
| 371 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
|
| 372 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 373 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false) |
|
| 374 | + ? $timezone_string |
|
| 375 | + : ''; |
|
| 376 | + $gmt_offset = get_option('gmt_offset'); |
|
| 377 | + $check_zone_info = true; |
|
| 378 | + if (empty($timezone_string)) { |
|
| 379 | + // Create a UTC+- zone if no timezone string exists |
|
| 380 | + $timezone_string = 'UTC'; |
|
| 381 | + $check_zone_info = false; |
|
| 382 | + if ($gmt_offset > 0) { |
|
| 383 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
| 384 | + } elseif ($gmt_offset < 0) { |
|
| 385 | + $timezone_string = 'UTC' . $gmt_offset; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + ?> |
|
| 389 | 389 | |
| 390 | 390 | <p> |
| 391 | 391 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
@@ -398,13 +398,13 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | <p> |
| 400 | 400 | <span><?php |
| 401 | - printf( |
|
| 402 | - __('%1$sUTC%2$s time is %3$s'), |
|
| 403 | - '<abbr title="Coordinated Universal Time">', |
|
| 404 | - '</abbr>', |
|
| 405 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 406 | - ); |
|
| 407 | - ?></span> |
|
| 401 | + printf( |
|
| 402 | + __('%1$sUTC%2$s time is %3$s'), |
|
| 403 | + '<abbr title="Coordinated Universal Time">', |
|
| 404 | + '</abbr>', |
|
| 405 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 406 | + ); |
|
| 407 | + ?></span> |
|
| 408 | 408 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
| 409 | 409 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
| 410 | 410 | <?php endif; ?> |
@@ -413,847 +413,847 @@ discard block |
||
| 413 | 413 | <br/> |
| 414 | 414 | <span> |
| 415 | 415 | <?php |
| 416 | - // Set TZ so localtime works. |
|
| 417 | - date_default_timezone_set($timezone_string); |
|
| 418 | - $now = localtime(time(), true); |
|
| 419 | - if ($now['tm_isdst']) { |
|
| 420 | - _e('This timezone is currently in daylight saving time.'); |
|
| 421 | - } else { |
|
| 422 | - _e('This timezone is currently in standard time.'); |
|
| 423 | - } |
|
| 424 | - ?> |
|
| 416 | + // Set TZ so localtime works. |
|
| 417 | + date_default_timezone_set($timezone_string); |
|
| 418 | + $now = localtime(time(), true); |
|
| 419 | + if ($now['tm_isdst']) { |
|
| 420 | + _e('This timezone is currently in daylight saving time.'); |
|
| 421 | + } else { |
|
| 422 | + _e('This timezone is currently in standard time.'); |
|
| 423 | + } |
|
| 424 | + ?> |
|
| 425 | 425 | <br/> |
| 426 | 426 | <?php |
| 427 | - if (function_exists('timezone_transitions_get')) { |
|
| 428 | - $found = false; |
|
| 429 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 430 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 431 | - $right_now = time(); |
|
| 432 | - $tr['isdst'] = false; |
|
| 433 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 434 | - if ($tr['ts'] > $right_now) { |
|
| 435 | - $found = true; |
|
| 436 | - break; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - if ($found) { |
|
| 440 | - $message = $tr['isdst'] |
|
| 441 | - ? |
|
| 442 | - __(' Daylight saving time begins on: %s.') |
|
| 443 | - : |
|
| 444 | - __(' Standard time begins on: %s.'); |
|
| 445 | - // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 446 | - printf( |
|
| 447 | - $message, |
|
| 448 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
|
| 449 | - ); |
|
| 450 | - } else { |
|
| 451 | - _e('This timezone does not observe daylight saving time.'); |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - // Set back to UTC. |
|
| 455 | - date_default_timezone_set('UTC'); |
|
| 456 | - ?> |
|
| 427 | + if (function_exists('timezone_transitions_get')) { |
|
| 428 | + $found = false; |
|
| 429 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 430 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 431 | + $right_now = time(); |
|
| 432 | + $tr['isdst'] = false; |
|
| 433 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 434 | + if ($tr['ts'] > $right_now) { |
|
| 435 | + $found = true; |
|
| 436 | + break; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + if ($found) { |
|
| 440 | + $message = $tr['isdst'] |
|
| 441 | + ? |
|
| 442 | + __(' Daylight saving time begins on: %s.') |
|
| 443 | + : |
|
| 444 | + __(' Standard time begins on: %s.'); |
|
| 445 | + // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 446 | + printf( |
|
| 447 | + $message, |
|
| 448 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
|
| 449 | + ); |
|
| 450 | + } else { |
|
| 451 | + _e('This timezone does not observe daylight saving time.'); |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + // Set back to UTC. |
|
| 455 | + date_default_timezone_set('UTC'); |
|
| 456 | + ?> |
|
| 457 | 457 | </span></p> |
| 458 | 458 | <?php |
| 459 | - endif; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 465 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 466 | - * the site is used. |
|
| 467 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 468 | - * computed timestamp (i.e. date_i18n() ) |
|
| 469 | - * |
|
| 470 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 471 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 472 | - * site will be used. |
|
| 473 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 474 | - * @throws EE_Error |
|
| 475 | - */ |
|
| 476 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 477 | - { |
|
| 478 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 479 | - $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 480 | - $TimeZone = new DateTimeZone($timezone_string); |
|
| 481 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 482 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 483 | - return (int) $DateTime->format('U') + (int) $offset; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * _set_date_time_field |
|
| 489 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 490 | - * |
|
| 491 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 492 | - * @param DateTime $DateTime PHP DateTime object |
|
| 493 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 494 | - * @return EE_Base_Class |
|
| 495 | - * @throws EE_Error |
|
| 496 | - */ |
|
| 497 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 498 | - { |
|
| 499 | - // grab current datetime format |
|
| 500 | - $current_format = $obj->get_format(); |
|
| 501 | - // set new full timestamp format |
|
| 502 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 503 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 504 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 505 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 506 | - // reset datetime formats |
|
| 507 | - $obj->set_date_format($current_format[0]); |
|
| 508 | - $obj->set_time_format($current_format[1]); |
|
| 509 | - return $obj; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * date_time_add |
|
| 515 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 516 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 517 | - * |
|
| 518 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 519 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 520 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 521 | - * minutes, seconds) defaults to years |
|
| 522 | - * @param integer $value what you want to increment the time by |
|
| 523 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 524 | - * (chaining) |
|
| 525 | - * @throws EE_Error |
|
| 526 | - * @throws Exception |
|
| 527 | - */ |
|
| 528 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 529 | - { |
|
| 530 | - //get the raw UTC date. |
|
| 531 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 532 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 533 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * date_time_subtract |
|
| 539 | - * same as date_time_add except subtracting value instead of adding. |
|
| 540 | - * |
|
| 541 | - * @param EE_Base_Class $obj |
|
| 542 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 543 | - * @param string $period |
|
| 544 | - * @param int $value |
|
| 545 | - * @return EE_Base_Class |
|
| 546 | - * @throws EE_Error |
|
| 547 | - * @throws Exception |
|
| 548 | - */ |
|
| 549 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 550 | - { |
|
| 551 | - //get the raw UTC date |
|
| 552 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 553 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 554 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 560 | - * |
|
| 561 | - * @param DateTime $DateTime DateTime object |
|
| 562 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 563 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 564 | - * @param int|string $value What you want to increment the date by |
|
| 565 | - * @param string $operand What operand you wish to use for the calculation |
|
| 566 | - * @return DateTime return whatever type came in. |
|
| 567 | - * @throws Exception |
|
| 568 | - * @throws EE_Error |
|
| 569 | - */ |
|
| 570 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 571 | - { |
|
| 572 | - if (! $DateTime instanceof DateTime) { |
|
| 573 | - throw new EE_Error( |
|
| 574 | - sprintf( |
|
| 575 | - esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 576 | - print_r($DateTime, true) |
|
| 577 | - ) |
|
| 578 | - ); |
|
| 579 | - } |
|
| 580 | - switch ($period) { |
|
| 581 | - case 'years' : |
|
| 582 | - $value = 'P' . $value . 'Y'; |
|
| 583 | - break; |
|
| 584 | - case 'months' : |
|
| 585 | - $value = 'P' . $value . 'M'; |
|
| 586 | - break; |
|
| 587 | - case 'weeks' : |
|
| 588 | - $value = 'P' . $value . 'W'; |
|
| 589 | - break; |
|
| 590 | - case 'days' : |
|
| 591 | - $value = 'P' . $value . 'D'; |
|
| 592 | - break; |
|
| 593 | - case 'hours' : |
|
| 594 | - $value = 'PT' . $value . 'H'; |
|
| 595 | - break; |
|
| 596 | - case 'minutes' : |
|
| 597 | - $value = 'PT' . $value . 'M'; |
|
| 598 | - break; |
|
| 599 | - case 'seconds' : |
|
| 600 | - $value = 'PT' . $value . 'S'; |
|
| 601 | - break; |
|
| 602 | - } |
|
| 603 | - switch ($operand) { |
|
| 604 | - case '+': |
|
| 605 | - $DateTime->add(new DateInterval($value)); |
|
| 606 | - break; |
|
| 607 | - case '-': |
|
| 608 | - $DateTime->sub(new DateInterval($value)); |
|
| 609 | - break; |
|
| 610 | - } |
|
| 611 | - return $DateTime; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 617 | - * |
|
| 618 | - * @param int $timestamp Unix timestamp |
|
| 619 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 620 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 621 | - * @param integer $value What you want to increment the date by |
|
| 622 | - * @param string $operand What operand you wish to use for the calculation |
|
| 623 | - * @return int |
|
| 624 | - * @throws EE_Error |
|
| 625 | - */ |
|
| 626 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 627 | - { |
|
| 628 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 629 | - throw new EE_Error( |
|
| 630 | - sprintf( |
|
| 631 | - esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 632 | - print_r($timestamp, true) |
|
| 633 | - ) |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - switch ($period) { |
|
| 637 | - case 'years' : |
|
| 638 | - $value = YEAR_IN_SECONDS * $value; |
|
| 639 | - break; |
|
| 640 | - case 'months' : |
|
| 641 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 642 | - break; |
|
| 643 | - case 'weeks' : |
|
| 644 | - $value = WEEK_IN_SECONDS * $value; |
|
| 645 | - break; |
|
| 646 | - case 'days' : |
|
| 647 | - $value = DAY_IN_SECONDS * $value; |
|
| 648 | - break; |
|
| 649 | - case 'hours' : |
|
| 650 | - $value = HOUR_IN_SECONDS * $value; |
|
| 651 | - break; |
|
| 652 | - case 'minutes' : |
|
| 653 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 654 | - break; |
|
| 655 | - } |
|
| 656 | - switch ($operand) { |
|
| 657 | - case '+': |
|
| 658 | - $timestamp += $value; |
|
| 659 | - break; |
|
| 660 | - case '-': |
|
| 661 | - $timestamp -= $value; |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - return $timestamp; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 670 | - * parameters and returns the new timestamp or DateTime. |
|
| 671 | - * |
|
| 672 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 673 | - * @param string $period a value to indicate what interval is being used in the |
|
| 674 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 675 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 676 | - * @param integer $value What you want to increment the date by |
|
| 677 | - * @param string $operand What operand you wish to use for the calculation |
|
| 678 | - * @return mixed string|DateTime return whatever type came in. |
|
| 679 | - * @throws Exception |
|
| 680 | - * @throws EE_Error |
|
| 681 | - */ |
|
| 682 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 683 | - { |
|
| 684 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 685 | - return EEH_DTT_Helper::_modify_datetime_object( |
|
| 686 | - $DateTime_or_timestamp, |
|
| 687 | - $period, |
|
| 688 | - $value, |
|
| 689 | - $operand |
|
| 690 | - ); |
|
| 691 | - } |
|
| 692 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 693 | - return EEH_DTT_Helper::_modify_timestamp( |
|
| 694 | - $DateTime_or_timestamp, |
|
| 695 | - $period, |
|
| 696 | - $value, |
|
| 697 | - $operand |
|
| 698 | - ); |
|
| 699 | - } |
|
| 700 | - //error |
|
| 701 | - return $DateTime_or_timestamp; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 707 | - * and spit out the js and moment.js equivalent formats. |
|
| 708 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 709 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 710 | - * time picker. |
|
| 711 | - * |
|
| 712 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 713 | - * @param string $date_format_string |
|
| 714 | - * @param string $time_format_string |
|
| 715 | - * @return array |
|
| 716 | - * array( |
|
| 717 | - * 'js' => array ( |
|
| 718 | - * 'date' => //date format |
|
| 719 | - * 'time' => //time format |
|
| 720 | - * ), |
|
| 721 | - * 'moment' => //date and time format. |
|
| 722 | - * ) |
|
| 723 | - */ |
|
| 724 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 725 | - $date_format_string = null, |
|
| 726 | - $time_format_string = null |
|
| 727 | - ) { |
|
| 728 | - if ($date_format_string === null) { |
|
| 729 | - $date_format_string = (string) get_option('date_format'); |
|
| 730 | - } |
|
| 731 | - if ($time_format_string === null) { |
|
| 732 | - $time_format_string = (string) get_option('time_format'); |
|
| 733 | - } |
|
| 734 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 735 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 736 | - return array( |
|
| 737 | - 'js' => array( |
|
| 738 | - 'date' => $date_format['js'], |
|
| 739 | - 'time' => $time_format['js'], |
|
| 740 | - ), |
|
| 741 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 742 | - ); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * This converts incoming format string into js and moment variations. |
|
| 748 | - * |
|
| 749 | - * @param string $format_string incoming php format string |
|
| 750 | - * @return array js and moment formats. |
|
| 751 | - */ |
|
| 752 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 753 | - { |
|
| 754 | - /** |
|
| 755 | - * This is a map of symbols for formats. |
|
| 756 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 757 | - * |
|
| 758 | - * @var array |
|
| 759 | - */ |
|
| 760 | - $symbols_map = array( |
|
| 761 | - // Day |
|
| 762 | - //01 |
|
| 763 | - 'd' => array( |
|
| 764 | - 'js' => 'dd', |
|
| 765 | - 'moment' => 'DD', |
|
| 766 | - ), |
|
| 767 | - //Mon |
|
| 768 | - 'D' => array( |
|
| 769 | - 'js' => 'D', |
|
| 770 | - 'moment' => 'ddd', |
|
| 771 | - ), |
|
| 772 | - //1,2,...31 |
|
| 773 | - 'j' => array( |
|
| 774 | - 'js' => 'd', |
|
| 775 | - 'moment' => 'D', |
|
| 776 | - ), |
|
| 777 | - //Monday |
|
| 778 | - 'l' => array( |
|
| 779 | - 'js' => 'DD', |
|
| 780 | - 'moment' => 'dddd', |
|
| 781 | - ), |
|
| 782 | - //ISO numeric representation of the day of the week (1-6) |
|
| 783 | - 'N' => array( |
|
| 784 | - 'js' => '', |
|
| 785 | - 'moment' => 'E', |
|
| 786 | - ), |
|
| 787 | - //st,nd.rd |
|
| 788 | - 'S' => array( |
|
| 789 | - 'js' => '', |
|
| 790 | - 'moment' => 'o', |
|
| 791 | - ), |
|
| 792 | - //numeric representation of day of week (0-6) |
|
| 793 | - 'w' => array( |
|
| 794 | - 'js' => '', |
|
| 795 | - 'moment' => 'd', |
|
| 796 | - ), |
|
| 797 | - //day of year starting from 0 (0-365) |
|
| 798 | - 'z' => array( |
|
| 799 | - 'js' => 'o', |
|
| 800 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 801 | - ), |
|
| 802 | - // Week |
|
| 803 | - //ISO-8601 week number of year (weeks starting on monday) |
|
| 804 | - 'W' => array( |
|
| 805 | - 'js' => '', |
|
| 806 | - 'moment' => 'w', |
|
| 807 | - ), |
|
| 808 | - // Month |
|
| 809 | - // January...December |
|
| 810 | - 'F' => array( |
|
| 811 | - 'js' => 'MM', |
|
| 812 | - 'moment' => 'MMMM', |
|
| 813 | - ), |
|
| 814 | - //01...12 |
|
| 815 | - 'm' => array( |
|
| 816 | - 'js' => 'mm', |
|
| 817 | - 'moment' => 'MM', |
|
| 818 | - ), |
|
| 819 | - //Jan...Dec |
|
| 820 | - 'M' => array( |
|
| 821 | - 'js' => 'M', |
|
| 822 | - 'moment' => 'MMM', |
|
| 823 | - ), |
|
| 824 | - //1-12 |
|
| 825 | - 'n' => array( |
|
| 826 | - 'js' => 'm', |
|
| 827 | - 'moment' => 'M', |
|
| 828 | - ), |
|
| 829 | - //number of days in given month |
|
| 830 | - 't' => array( |
|
| 831 | - 'js' => '', |
|
| 832 | - 'moment' => '', |
|
| 833 | - ), |
|
| 834 | - // Year |
|
| 835 | - //whether leap year or not 1/0 |
|
| 836 | - 'L' => array( |
|
| 837 | - 'js' => '', |
|
| 838 | - 'moment' => '', |
|
| 839 | - ), |
|
| 840 | - //ISO-8601 year number |
|
| 841 | - 'o' => array( |
|
| 842 | - 'js' => '', |
|
| 843 | - 'moment' => 'GGGG', |
|
| 844 | - ), |
|
| 845 | - //1999...2003 |
|
| 846 | - 'Y' => array( |
|
| 847 | - 'js' => 'yy', |
|
| 848 | - 'moment' => 'YYYY', |
|
| 849 | - ), |
|
| 850 | - //99...03 |
|
| 851 | - 'y' => array( |
|
| 852 | - 'js' => 'y', |
|
| 853 | - 'moment' => 'YY', |
|
| 854 | - ), |
|
| 855 | - // Time |
|
| 856 | - // am/pm |
|
| 857 | - 'a' => array( |
|
| 858 | - 'js' => 'tt', |
|
| 859 | - 'moment' => 'a', |
|
| 860 | - ), |
|
| 861 | - // AM/PM |
|
| 862 | - 'A' => array( |
|
| 863 | - 'js' => 'TT', |
|
| 864 | - 'moment' => 'A', |
|
| 865 | - ), |
|
| 866 | - // Swatch Internet Time?!? |
|
| 867 | - 'B' => array( |
|
| 868 | - 'js' => '', |
|
| 869 | - 'moment' => '', |
|
| 870 | - ), |
|
| 871 | - //1...12 |
|
| 872 | - 'g' => array( |
|
| 873 | - 'js' => 'h', |
|
| 874 | - 'moment' => 'h', |
|
| 875 | - ), |
|
| 876 | - //0...23 |
|
| 877 | - 'G' => array( |
|
| 878 | - 'js' => 'H', |
|
| 879 | - 'moment' => 'H', |
|
| 880 | - ), |
|
| 881 | - //01...12 |
|
| 882 | - 'h' => array( |
|
| 883 | - 'js' => 'hh', |
|
| 884 | - 'moment' => 'hh', |
|
| 885 | - ), |
|
| 886 | - //00...23 |
|
| 887 | - 'H' => array( |
|
| 888 | - 'js' => 'HH', |
|
| 889 | - 'moment' => 'HH', |
|
| 890 | - ), |
|
| 891 | - //00..59 |
|
| 892 | - 'i' => array( |
|
| 893 | - 'js' => 'mm', |
|
| 894 | - 'moment' => 'mm', |
|
| 895 | - ), |
|
| 896 | - //seconds... 00...59 |
|
| 897 | - 's' => array( |
|
| 898 | - 'js' => 'ss', |
|
| 899 | - 'moment' => 'ss', |
|
| 900 | - ), |
|
| 901 | - //microseconds |
|
| 902 | - 'u' => array( |
|
| 903 | - 'js' => '', |
|
| 904 | - 'moment' => '', |
|
| 905 | - ), |
|
| 906 | - ); |
|
| 907 | - $jquery_ui_format = ''; |
|
| 908 | - $moment_format = ''; |
|
| 909 | - $escaping = false; |
|
| 910 | - $format_string_length = strlen($format_string); |
|
| 911 | - for ($i = 0; $i < $format_string_length; $i++) { |
|
| 912 | - $char = $format_string[ $i ]; |
|
| 913 | - if ($char === '\\') { // PHP date format escaping character |
|
| 914 | - $i++; |
|
| 915 | - if ($escaping) { |
|
| 916 | - $jquery_ui_format .= $format_string[ $i ]; |
|
| 917 | - $moment_format .= $format_string[ $i ]; |
|
| 918 | - } else { |
|
| 919 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
| 920 | - $moment_format .= $format_string[ $i ]; |
|
| 921 | - } |
|
| 922 | - $escaping = true; |
|
| 923 | - } else { |
|
| 924 | - if ($escaping) { |
|
| 925 | - $jquery_ui_format .= "'"; |
|
| 926 | - $moment_format .= "'"; |
|
| 927 | - $escaping = false; |
|
| 928 | - } |
|
| 929 | - if (isset($symbols_map[ $char ])) { |
|
| 930 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
| 931 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
| 932 | - } else { |
|
| 933 | - $jquery_ui_format .= $char; |
|
| 934 | - $moment_format .= $char; |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - } |
|
| 938 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 944 | - * |
|
| 945 | - * @param string $format_string Incoming format string for php date(). |
|
| 946 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 947 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 948 | - * indicate failed validations. |
|
| 949 | - */ |
|
| 950 | - public static function validate_format_string($format_string) |
|
| 951 | - { |
|
| 952 | - $error_msg = array(); |
|
| 953 | - //time format checks |
|
| 954 | - switch (true) { |
|
| 955 | - case strpos($format_string, 'h') !== false : |
|
| 956 | - case strpos($format_string, 'g') !== false : |
|
| 957 | - /** |
|
| 958 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 959 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 960 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 961 | - */ |
|
| 962 | - if (stripos($format_string, 'A') === false) { |
|
| 963 | - $error_msg[] = esc_html__( |
|
| 964 | - '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".', |
|
| 965 | - 'event_espresso' |
|
| 966 | - ); |
|
| 967 | - } |
|
| 968 | - break; |
|
| 969 | - } |
|
| 970 | - return empty($error_msg) ? true : $error_msg; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 976 | - * very next day then this method will return true. |
|
| 977 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 978 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 979 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 980 | - * |
|
| 981 | - * @param mixed $date_1 |
|
| 982 | - * @param mixed $date_2 |
|
| 983 | - * @return bool |
|
| 984 | - */ |
|
| 985 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 986 | - { |
|
| 987 | - |
|
| 988 | - if ( |
|
| 989 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 990 | - || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
| 991 | - || $date_2->format( |
|
| 992 | - EE_Datetime_Field::mysql_time_format |
|
| 993 | - ) !== '00:00:00') |
|
| 994 | - ) { |
|
| 995 | - return false; |
|
| 996 | - } |
|
| 997 | - return $date_2->format('U') - $date_1->format('U') === 86400; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 1003 | - * Functions. |
|
| 1004 | - * |
|
| 1005 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 1006 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 1007 | - * @return string |
|
| 1008 | - */ |
|
| 1009 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 1010 | - { |
|
| 1011 | - try { |
|
| 1012 | - /** need to account for timezone offset on the selects */ |
|
| 1013 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 1014 | - } catch (Exception $e) { |
|
| 1015 | - $DateTimeZone = null; |
|
| 1016 | - } |
|
| 1017 | - /** |
|
| 1018 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 1019 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 1020 | - */ |
|
| 1021 | - $offset = $DateTimeZone instanceof DateTimeZone |
|
| 1022 | - ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
| 1023 | - : (float) get_option('gmt_offset'); |
|
| 1024 | - $query_interval = $offset < 0 |
|
| 1025 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1026 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1027 | - return $query_interval; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1033 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1034 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1035 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1036 | - * (although note that we remove any HTML that may be added) |
|
| 1037 | - * |
|
| 1038 | - * @return string |
|
| 1039 | - */ |
|
| 1040 | - public static function get_timezone_string_for_display() |
|
| 1041 | - { |
|
| 1042 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1043 | - if (! empty($pretty_timezone)) { |
|
| 1044 | - return esc_html($pretty_timezone); |
|
| 1045 | - } |
|
| 1046 | - $timezone_string = get_option('timezone_string'); |
|
| 1047 | - if ($timezone_string) { |
|
| 1048 | - static $mo_loaded = false; |
|
| 1049 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1050 | - if (! $mo_loaded) { |
|
| 1051 | - $locale = get_locale(); |
|
| 1052 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1053 | - load_textdomain('continents-cities', $mofile); |
|
| 1054 | - $mo_loaded = true; |
|
| 1055 | - } |
|
| 1056 | - //well that was easy. |
|
| 1057 | - $parts = explode('/', $timezone_string); |
|
| 1058 | - //remove the continent |
|
| 1059 | - unset($parts[0]); |
|
| 1060 | - $t_parts = array(); |
|
| 1061 | - foreach ($parts as $part) { |
|
| 1062 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1063 | - } |
|
| 1064 | - return implode(' - ', $t_parts); |
|
| 1065 | - } |
|
| 1066 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1067 | - $gmt_offset = get_option('gmt_offset'); |
|
| 1068 | - $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
| 1069 | - $parts = explode('.', (string) $gmt_offset); |
|
| 1070 | - if (count($parts) === 1) { |
|
| 1071 | - $parts[1] = '00'; |
|
| 1072 | - } else { |
|
| 1073 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1074 | - //to minutes, eg 30 or 15, respectively |
|
| 1075 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
| 1076 | - $parts[1] = (string) $hour_fraction * 60; |
|
| 1077 | - } |
|
| 1078 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1085 | - * for a month using a string like "February" or "February 2017", |
|
| 1086 | - * and you don't specify a day as part of your string, |
|
| 1087 | - * then PHP will use whatever the current day of the month is. |
|
| 1088 | - * IF the current day of the month happens to be the 30th or 31st, |
|
| 1089 | - * then PHP gets really confused by a date like February 30, |
|
| 1090 | - * so instead of saying |
|
| 1091 | - * "Hey February only has 28 days (this year)... |
|
| 1092 | - * ...you must have meant the last day of the month!" |
|
| 1093 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1094 | - * because someone requesting February 30th obviously meant March 1st! |
|
| 1095 | - * The way around this is to always set the day to the first, |
|
| 1096 | - * so that the month will stay on the month you wanted. |
|
| 1097 | - * this method will add that "1" into your date regardless of the format. |
|
| 1098 | - * |
|
| 1099 | - * @param string $month |
|
| 1100 | - * @return string |
|
| 1101 | - */ |
|
| 1102 | - public static function first_of_month_timestamp($month = '') |
|
| 1103 | - { |
|
| 1104 | - $month = (string) $month; |
|
| 1105 | - $year = ''; |
|
| 1106 | - // check if the incoming string has a year in it or not |
|
| 1107 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1108 | - $year = $matches[0]; |
|
| 1109 | - // ten remove that from the month string as well as any spaces |
|
| 1110 | - $month = trim(str_replace($year, '', $month)); |
|
| 1111 | - // add a space before the year |
|
| 1112 | - $year = " {$year}"; |
|
| 1113 | - } |
|
| 1114 | - // return timestamp for something like "February 1 2017" |
|
| 1115 | - return strtotime("{$month} 1{$year}"); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1121 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1122 | - */ |
|
| 1123 | - public static function tomorrow() |
|
| 1124 | - { |
|
| 1125 | - //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
| 1126 | - //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
| 1127 | - //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
| 1128 | - //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
| 1129 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * ** |
|
| 1135 | - * Gives a nicely-formatted list of timezone strings. |
|
| 1136 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1137 | - * |
|
| 1138 | - * @since 4.9.40.rc.008 |
|
| 1139 | - * @staticvar bool $mo_loaded |
|
| 1140 | - * @staticvar string $locale_loaded |
|
| 1141 | - * @param string $selected_zone Selected timezone. |
|
| 1142 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1143 | - * @return string |
|
| 1144 | - */ |
|
| 1145 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1146 | - { |
|
| 1147 | - static $mo_loaded = false, $locale_loaded = null; |
|
| 1148 | - $continents = array( |
|
| 1149 | - 'Africa', |
|
| 1150 | - 'America', |
|
| 1151 | - 'Antarctica', |
|
| 1152 | - 'Arctic', |
|
| 1153 | - 'Asia', |
|
| 1154 | - 'Atlantic', |
|
| 1155 | - 'Australia', |
|
| 1156 | - 'Europe', |
|
| 1157 | - 'Indian', |
|
| 1158 | - 'Pacific', |
|
| 1159 | - ); |
|
| 1160 | - // Load translations for continents and cities. |
|
| 1161 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1162 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1163 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1164 | - unload_textdomain('continents-cities'); |
|
| 1165 | - load_textdomain('continents-cities', $mofile); |
|
| 1166 | - $mo_loaded = true; |
|
| 1167 | - } |
|
| 1168 | - $zone_data = array(); |
|
| 1169 | - foreach (timezone_identifiers_list() as $zone) { |
|
| 1170 | - $zone = explode('/', $zone); |
|
| 1171 | - if (! in_array($zone[0], $continents, true)) { |
|
| 1172 | - continue; |
|
| 1173 | - } |
|
| 1174 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1175 | - $exists = array( |
|
| 1176 | - 0 => isset($zone[0]) && $zone[0], |
|
| 1177 | - 1 => isset($zone[1]) && $zone[1], |
|
| 1178 | - 2 => isset($zone[2]) && $zone[2], |
|
| 1179 | - ); |
|
| 1180 | - $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
| 1181 | - $exists[4] = $exists[1] && $exists[3]; |
|
| 1182 | - $exists[5] = $exists[2] && $exists[3]; |
|
| 1183 | - $zone_data[] = array( |
|
| 1184 | - 'continent' => $exists[0] ? $zone[0] : '', |
|
| 1185 | - 'city' => $exists[1] ? $zone[1] : '', |
|
| 1186 | - 'subcity' => $exists[2] ? $zone[2] : '', |
|
| 1187 | - 't_continent' => $exists[3] |
|
| 1188 | - ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
| 1189 | - : '', |
|
| 1190 | - 't_city' => $exists[4] |
|
| 1191 | - ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
| 1192 | - : '', |
|
| 1193 | - 't_subcity' => $exists[5] |
|
| 1194 | - ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
| 1195 | - : '', |
|
| 1196 | - ); |
|
| 1197 | - } |
|
| 1198 | - usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
| 1199 | - $structure = array(); |
|
| 1200 | - if (empty($selected_zone)) { |
|
| 1201 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1202 | - } |
|
| 1203 | - foreach ($zone_data as $key => $zone) { |
|
| 1204 | - // Build value in an array to join later |
|
| 1205 | - $value = array($zone['continent']); |
|
| 1206 | - if (empty($zone['city'])) { |
|
| 1207 | - // It's at the continent level (generally won't happen) |
|
| 1208 | - $display = $zone['t_continent']; |
|
| 1209 | - } else { |
|
| 1210 | - // It's inside a continent group |
|
| 1211 | - // Continent optgroup |
|
| 1212 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
| 1213 | - $label = $zone['t_continent']; |
|
| 1214 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1215 | - } |
|
| 1216 | - // Add the city to the value |
|
| 1217 | - $value[] = $zone['city']; |
|
| 1218 | - $display = $zone['t_city']; |
|
| 1219 | - if (! empty($zone['subcity'])) { |
|
| 1220 | - // Add the subcity to the value |
|
| 1221 | - $value[] = $zone['subcity']; |
|
| 1222 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - // Build the value |
|
| 1226 | - $value = implode('/', $value); |
|
| 1227 | - $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
|
| 1228 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
| 1229 | - . esc_html($display) |
|
| 1230 | - . '</option>'; |
|
| 1231 | - // Close continent optgroup |
|
| 1232 | - if (! empty($zone['city']) |
|
| 1233 | - && ( |
|
| 1234 | - ! isset($zone_data[ $key + 1 ]) |
|
| 1235 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
| 1236 | - ) |
|
| 1237 | - ) { |
|
| 1238 | - $structure[] = '</optgroup>'; |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - return implode("\n", $structure); |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1247 | - * |
|
| 1248 | - * @param int|WP_User $user_id |
|
| 1249 | - * @return string |
|
| 1250 | - */ |
|
| 1251 | - public static function get_user_locale($user_id = 0) |
|
| 1252 | - { |
|
| 1253 | - if (function_exists('get_user_locale')) { |
|
| 1254 | - return get_user_locale($user_id); |
|
| 1255 | - } |
|
| 1256 | - return get_locale(); |
|
| 1257 | - } |
|
| 459 | + endif; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 465 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 466 | + * the site is used. |
|
| 467 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 468 | + * computed timestamp (i.e. date_i18n() ) |
|
| 469 | + * |
|
| 470 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 471 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 472 | + * site will be used. |
|
| 473 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 474 | + * @throws EE_Error |
|
| 475 | + */ |
|
| 476 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 477 | + { |
|
| 478 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 479 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 480 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 481 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 482 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 483 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * _set_date_time_field |
|
| 489 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 490 | + * |
|
| 491 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 492 | + * @param DateTime $DateTime PHP DateTime object |
|
| 493 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 494 | + * @return EE_Base_Class |
|
| 495 | + * @throws EE_Error |
|
| 496 | + */ |
|
| 497 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 498 | + { |
|
| 499 | + // grab current datetime format |
|
| 500 | + $current_format = $obj->get_format(); |
|
| 501 | + // set new full timestamp format |
|
| 502 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 503 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 504 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 505 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 506 | + // reset datetime formats |
|
| 507 | + $obj->set_date_format($current_format[0]); |
|
| 508 | + $obj->set_time_format($current_format[1]); |
|
| 509 | + return $obj; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * date_time_add |
|
| 515 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 516 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 517 | + * |
|
| 518 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 519 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 520 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 521 | + * minutes, seconds) defaults to years |
|
| 522 | + * @param integer $value what you want to increment the time by |
|
| 523 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 524 | + * (chaining) |
|
| 525 | + * @throws EE_Error |
|
| 526 | + * @throws Exception |
|
| 527 | + */ |
|
| 528 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 529 | + { |
|
| 530 | + //get the raw UTC date. |
|
| 531 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 532 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 533 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * date_time_subtract |
|
| 539 | + * same as date_time_add except subtracting value instead of adding. |
|
| 540 | + * |
|
| 541 | + * @param EE_Base_Class $obj |
|
| 542 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 543 | + * @param string $period |
|
| 544 | + * @param int $value |
|
| 545 | + * @return EE_Base_Class |
|
| 546 | + * @throws EE_Error |
|
| 547 | + * @throws Exception |
|
| 548 | + */ |
|
| 549 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 550 | + { |
|
| 551 | + //get the raw UTC date |
|
| 552 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 553 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 554 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 560 | + * |
|
| 561 | + * @param DateTime $DateTime DateTime object |
|
| 562 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 563 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 564 | + * @param int|string $value What you want to increment the date by |
|
| 565 | + * @param string $operand What operand you wish to use for the calculation |
|
| 566 | + * @return DateTime return whatever type came in. |
|
| 567 | + * @throws Exception |
|
| 568 | + * @throws EE_Error |
|
| 569 | + */ |
|
| 570 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 571 | + { |
|
| 572 | + if (! $DateTime instanceof DateTime) { |
|
| 573 | + throw new EE_Error( |
|
| 574 | + sprintf( |
|
| 575 | + esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 576 | + print_r($DateTime, true) |
|
| 577 | + ) |
|
| 578 | + ); |
|
| 579 | + } |
|
| 580 | + switch ($period) { |
|
| 581 | + case 'years' : |
|
| 582 | + $value = 'P' . $value . 'Y'; |
|
| 583 | + break; |
|
| 584 | + case 'months' : |
|
| 585 | + $value = 'P' . $value . 'M'; |
|
| 586 | + break; |
|
| 587 | + case 'weeks' : |
|
| 588 | + $value = 'P' . $value . 'W'; |
|
| 589 | + break; |
|
| 590 | + case 'days' : |
|
| 591 | + $value = 'P' . $value . 'D'; |
|
| 592 | + break; |
|
| 593 | + case 'hours' : |
|
| 594 | + $value = 'PT' . $value . 'H'; |
|
| 595 | + break; |
|
| 596 | + case 'minutes' : |
|
| 597 | + $value = 'PT' . $value . 'M'; |
|
| 598 | + break; |
|
| 599 | + case 'seconds' : |
|
| 600 | + $value = 'PT' . $value . 'S'; |
|
| 601 | + break; |
|
| 602 | + } |
|
| 603 | + switch ($operand) { |
|
| 604 | + case '+': |
|
| 605 | + $DateTime->add(new DateInterval($value)); |
|
| 606 | + break; |
|
| 607 | + case '-': |
|
| 608 | + $DateTime->sub(new DateInterval($value)); |
|
| 609 | + break; |
|
| 610 | + } |
|
| 611 | + return $DateTime; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 617 | + * |
|
| 618 | + * @param int $timestamp Unix timestamp |
|
| 619 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 620 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 621 | + * @param integer $value What you want to increment the date by |
|
| 622 | + * @param string $operand What operand you wish to use for the calculation |
|
| 623 | + * @return int |
|
| 624 | + * @throws EE_Error |
|
| 625 | + */ |
|
| 626 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 627 | + { |
|
| 628 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 629 | + throw new EE_Error( |
|
| 630 | + sprintf( |
|
| 631 | + esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 632 | + print_r($timestamp, true) |
|
| 633 | + ) |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + switch ($period) { |
|
| 637 | + case 'years' : |
|
| 638 | + $value = YEAR_IN_SECONDS * $value; |
|
| 639 | + break; |
|
| 640 | + case 'months' : |
|
| 641 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 642 | + break; |
|
| 643 | + case 'weeks' : |
|
| 644 | + $value = WEEK_IN_SECONDS * $value; |
|
| 645 | + break; |
|
| 646 | + case 'days' : |
|
| 647 | + $value = DAY_IN_SECONDS * $value; |
|
| 648 | + break; |
|
| 649 | + case 'hours' : |
|
| 650 | + $value = HOUR_IN_SECONDS * $value; |
|
| 651 | + break; |
|
| 652 | + case 'minutes' : |
|
| 653 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 654 | + break; |
|
| 655 | + } |
|
| 656 | + switch ($operand) { |
|
| 657 | + case '+': |
|
| 658 | + $timestamp += $value; |
|
| 659 | + break; |
|
| 660 | + case '-': |
|
| 661 | + $timestamp -= $value; |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + return $timestamp; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 670 | + * parameters and returns the new timestamp or DateTime. |
|
| 671 | + * |
|
| 672 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 673 | + * @param string $period a value to indicate what interval is being used in the |
|
| 674 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 675 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 676 | + * @param integer $value What you want to increment the date by |
|
| 677 | + * @param string $operand What operand you wish to use for the calculation |
|
| 678 | + * @return mixed string|DateTime return whatever type came in. |
|
| 679 | + * @throws Exception |
|
| 680 | + * @throws EE_Error |
|
| 681 | + */ |
|
| 682 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 683 | + { |
|
| 684 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 685 | + return EEH_DTT_Helper::_modify_datetime_object( |
|
| 686 | + $DateTime_or_timestamp, |
|
| 687 | + $period, |
|
| 688 | + $value, |
|
| 689 | + $operand |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 693 | + return EEH_DTT_Helper::_modify_timestamp( |
|
| 694 | + $DateTime_or_timestamp, |
|
| 695 | + $period, |
|
| 696 | + $value, |
|
| 697 | + $operand |
|
| 698 | + ); |
|
| 699 | + } |
|
| 700 | + //error |
|
| 701 | + return $DateTime_or_timestamp; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 707 | + * and spit out the js and moment.js equivalent formats. |
|
| 708 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 709 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 710 | + * time picker. |
|
| 711 | + * |
|
| 712 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 713 | + * @param string $date_format_string |
|
| 714 | + * @param string $time_format_string |
|
| 715 | + * @return array |
|
| 716 | + * array( |
|
| 717 | + * 'js' => array ( |
|
| 718 | + * 'date' => //date format |
|
| 719 | + * 'time' => //time format |
|
| 720 | + * ), |
|
| 721 | + * 'moment' => //date and time format. |
|
| 722 | + * ) |
|
| 723 | + */ |
|
| 724 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 725 | + $date_format_string = null, |
|
| 726 | + $time_format_string = null |
|
| 727 | + ) { |
|
| 728 | + if ($date_format_string === null) { |
|
| 729 | + $date_format_string = (string) get_option('date_format'); |
|
| 730 | + } |
|
| 731 | + if ($time_format_string === null) { |
|
| 732 | + $time_format_string = (string) get_option('time_format'); |
|
| 733 | + } |
|
| 734 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 735 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 736 | + return array( |
|
| 737 | + 'js' => array( |
|
| 738 | + 'date' => $date_format['js'], |
|
| 739 | + 'time' => $time_format['js'], |
|
| 740 | + ), |
|
| 741 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 742 | + ); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * This converts incoming format string into js and moment variations. |
|
| 748 | + * |
|
| 749 | + * @param string $format_string incoming php format string |
|
| 750 | + * @return array js and moment formats. |
|
| 751 | + */ |
|
| 752 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 753 | + { |
|
| 754 | + /** |
|
| 755 | + * This is a map of symbols for formats. |
|
| 756 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 757 | + * |
|
| 758 | + * @var array |
|
| 759 | + */ |
|
| 760 | + $symbols_map = array( |
|
| 761 | + // Day |
|
| 762 | + //01 |
|
| 763 | + 'd' => array( |
|
| 764 | + 'js' => 'dd', |
|
| 765 | + 'moment' => 'DD', |
|
| 766 | + ), |
|
| 767 | + //Mon |
|
| 768 | + 'D' => array( |
|
| 769 | + 'js' => 'D', |
|
| 770 | + 'moment' => 'ddd', |
|
| 771 | + ), |
|
| 772 | + //1,2,...31 |
|
| 773 | + 'j' => array( |
|
| 774 | + 'js' => 'd', |
|
| 775 | + 'moment' => 'D', |
|
| 776 | + ), |
|
| 777 | + //Monday |
|
| 778 | + 'l' => array( |
|
| 779 | + 'js' => 'DD', |
|
| 780 | + 'moment' => 'dddd', |
|
| 781 | + ), |
|
| 782 | + //ISO numeric representation of the day of the week (1-6) |
|
| 783 | + 'N' => array( |
|
| 784 | + 'js' => '', |
|
| 785 | + 'moment' => 'E', |
|
| 786 | + ), |
|
| 787 | + //st,nd.rd |
|
| 788 | + 'S' => array( |
|
| 789 | + 'js' => '', |
|
| 790 | + 'moment' => 'o', |
|
| 791 | + ), |
|
| 792 | + //numeric representation of day of week (0-6) |
|
| 793 | + 'w' => array( |
|
| 794 | + 'js' => '', |
|
| 795 | + 'moment' => 'd', |
|
| 796 | + ), |
|
| 797 | + //day of year starting from 0 (0-365) |
|
| 798 | + 'z' => array( |
|
| 799 | + 'js' => 'o', |
|
| 800 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 801 | + ), |
|
| 802 | + // Week |
|
| 803 | + //ISO-8601 week number of year (weeks starting on monday) |
|
| 804 | + 'W' => array( |
|
| 805 | + 'js' => '', |
|
| 806 | + 'moment' => 'w', |
|
| 807 | + ), |
|
| 808 | + // Month |
|
| 809 | + // January...December |
|
| 810 | + 'F' => array( |
|
| 811 | + 'js' => 'MM', |
|
| 812 | + 'moment' => 'MMMM', |
|
| 813 | + ), |
|
| 814 | + //01...12 |
|
| 815 | + 'm' => array( |
|
| 816 | + 'js' => 'mm', |
|
| 817 | + 'moment' => 'MM', |
|
| 818 | + ), |
|
| 819 | + //Jan...Dec |
|
| 820 | + 'M' => array( |
|
| 821 | + 'js' => 'M', |
|
| 822 | + 'moment' => 'MMM', |
|
| 823 | + ), |
|
| 824 | + //1-12 |
|
| 825 | + 'n' => array( |
|
| 826 | + 'js' => 'm', |
|
| 827 | + 'moment' => 'M', |
|
| 828 | + ), |
|
| 829 | + //number of days in given month |
|
| 830 | + 't' => array( |
|
| 831 | + 'js' => '', |
|
| 832 | + 'moment' => '', |
|
| 833 | + ), |
|
| 834 | + // Year |
|
| 835 | + //whether leap year or not 1/0 |
|
| 836 | + 'L' => array( |
|
| 837 | + 'js' => '', |
|
| 838 | + 'moment' => '', |
|
| 839 | + ), |
|
| 840 | + //ISO-8601 year number |
|
| 841 | + 'o' => array( |
|
| 842 | + 'js' => '', |
|
| 843 | + 'moment' => 'GGGG', |
|
| 844 | + ), |
|
| 845 | + //1999...2003 |
|
| 846 | + 'Y' => array( |
|
| 847 | + 'js' => 'yy', |
|
| 848 | + 'moment' => 'YYYY', |
|
| 849 | + ), |
|
| 850 | + //99...03 |
|
| 851 | + 'y' => array( |
|
| 852 | + 'js' => 'y', |
|
| 853 | + 'moment' => 'YY', |
|
| 854 | + ), |
|
| 855 | + // Time |
|
| 856 | + // am/pm |
|
| 857 | + 'a' => array( |
|
| 858 | + 'js' => 'tt', |
|
| 859 | + 'moment' => 'a', |
|
| 860 | + ), |
|
| 861 | + // AM/PM |
|
| 862 | + 'A' => array( |
|
| 863 | + 'js' => 'TT', |
|
| 864 | + 'moment' => 'A', |
|
| 865 | + ), |
|
| 866 | + // Swatch Internet Time?!? |
|
| 867 | + 'B' => array( |
|
| 868 | + 'js' => '', |
|
| 869 | + 'moment' => '', |
|
| 870 | + ), |
|
| 871 | + //1...12 |
|
| 872 | + 'g' => array( |
|
| 873 | + 'js' => 'h', |
|
| 874 | + 'moment' => 'h', |
|
| 875 | + ), |
|
| 876 | + //0...23 |
|
| 877 | + 'G' => array( |
|
| 878 | + 'js' => 'H', |
|
| 879 | + 'moment' => 'H', |
|
| 880 | + ), |
|
| 881 | + //01...12 |
|
| 882 | + 'h' => array( |
|
| 883 | + 'js' => 'hh', |
|
| 884 | + 'moment' => 'hh', |
|
| 885 | + ), |
|
| 886 | + //00...23 |
|
| 887 | + 'H' => array( |
|
| 888 | + 'js' => 'HH', |
|
| 889 | + 'moment' => 'HH', |
|
| 890 | + ), |
|
| 891 | + //00..59 |
|
| 892 | + 'i' => array( |
|
| 893 | + 'js' => 'mm', |
|
| 894 | + 'moment' => 'mm', |
|
| 895 | + ), |
|
| 896 | + //seconds... 00...59 |
|
| 897 | + 's' => array( |
|
| 898 | + 'js' => 'ss', |
|
| 899 | + 'moment' => 'ss', |
|
| 900 | + ), |
|
| 901 | + //microseconds |
|
| 902 | + 'u' => array( |
|
| 903 | + 'js' => '', |
|
| 904 | + 'moment' => '', |
|
| 905 | + ), |
|
| 906 | + ); |
|
| 907 | + $jquery_ui_format = ''; |
|
| 908 | + $moment_format = ''; |
|
| 909 | + $escaping = false; |
|
| 910 | + $format_string_length = strlen($format_string); |
|
| 911 | + for ($i = 0; $i < $format_string_length; $i++) { |
|
| 912 | + $char = $format_string[ $i ]; |
|
| 913 | + if ($char === '\\') { // PHP date format escaping character |
|
| 914 | + $i++; |
|
| 915 | + if ($escaping) { |
|
| 916 | + $jquery_ui_format .= $format_string[ $i ]; |
|
| 917 | + $moment_format .= $format_string[ $i ]; |
|
| 918 | + } else { |
|
| 919 | + $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
| 920 | + $moment_format .= $format_string[ $i ]; |
|
| 921 | + } |
|
| 922 | + $escaping = true; |
|
| 923 | + } else { |
|
| 924 | + if ($escaping) { |
|
| 925 | + $jquery_ui_format .= "'"; |
|
| 926 | + $moment_format .= "'"; |
|
| 927 | + $escaping = false; |
|
| 928 | + } |
|
| 929 | + if (isset($symbols_map[ $char ])) { |
|
| 930 | + $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
| 931 | + $moment_format .= $symbols_map[ $char ]['moment']; |
|
| 932 | + } else { |
|
| 933 | + $jquery_ui_format .= $char; |
|
| 934 | + $moment_format .= $char; |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + } |
|
| 938 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 944 | + * |
|
| 945 | + * @param string $format_string Incoming format string for php date(). |
|
| 946 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 947 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 948 | + * indicate failed validations. |
|
| 949 | + */ |
|
| 950 | + public static function validate_format_string($format_string) |
|
| 951 | + { |
|
| 952 | + $error_msg = array(); |
|
| 953 | + //time format checks |
|
| 954 | + switch (true) { |
|
| 955 | + case strpos($format_string, 'h') !== false : |
|
| 956 | + case strpos($format_string, 'g') !== false : |
|
| 957 | + /** |
|
| 958 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 959 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 960 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 961 | + */ |
|
| 962 | + if (stripos($format_string, 'A') === false) { |
|
| 963 | + $error_msg[] = esc_html__( |
|
| 964 | + '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".', |
|
| 965 | + 'event_espresso' |
|
| 966 | + ); |
|
| 967 | + } |
|
| 968 | + break; |
|
| 969 | + } |
|
| 970 | + return empty($error_msg) ? true : $error_msg; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 976 | + * very next day then this method will return true. |
|
| 977 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 978 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 979 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 980 | + * |
|
| 981 | + * @param mixed $date_1 |
|
| 982 | + * @param mixed $date_2 |
|
| 983 | + * @return bool |
|
| 984 | + */ |
|
| 985 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 986 | + { |
|
| 987 | + |
|
| 988 | + if ( |
|
| 989 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 990 | + || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
| 991 | + || $date_2->format( |
|
| 992 | + EE_Datetime_Field::mysql_time_format |
|
| 993 | + ) !== '00:00:00') |
|
| 994 | + ) { |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | + return $date_2->format('U') - $date_1->format('U') === 86400; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 1003 | + * Functions. |
|
| 1004 | + * |
|
| 1005 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 1006 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 1007 | + * @return string |
|
| 1008 | + */ |
|
| 1009 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 1010 | + { |
|
| 1011 | + try { |
|
| 1012 | + /** need to account for timezone offset on the selects */ |
|
| 1013 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 1014 | + } catch (Exception $e) { |
|
| 1015 | + $DateTimeZone = null; |
|
| 1016 | + } |
|
| 1017 | + /** |
|
| 1018 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 1019 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 1020 | + */ |
|
| 1021 | + $offset = $DateTimeZone instanceof DateTimeZone |
|
| 1022 | + ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
| 1023 | + : (float) get_option('gmt_offset'); |
|
| 1024 | + $query_interval = $offset < 0 |
|
| 1025 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1026 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1027 | + return $query_interval; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1033 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1034 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1035 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1036 | + * (although note that we remove any HTML that may be added) |
|
| 1037 | + * |
|
| 1038 | + * @return string |
|
| 1039 | + */ |
|
| 1040 | + public static function get_timezone_string_for_display() |
|
| 1041 | + { |
|
| 1042 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1043 | + if (! empty($pretty_timezone)) { |
|
| 1044 | + return esc_html($pretty_timezone); |
|
| 1045 | + } |
|
| 1046 | + $timezone_string = get_option('timezone_string'); |
|
| 1047 | + if ($timezone_string) { |
|
| 1048 | + static $mo_loaded = false; |
|
| 1049 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1050 | + if (! $mo_loaded) { |
|
| 1051 | + $locale = get_locale(); |
|
| 1052 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1053 | + load_textdomain('continents-cities', $mofile); |
|
| 1054 | + $mo_loaded = true; |
|
| 1055 | + } |
|
| 1056 | + //well that was easy. |
|
| 1057 | + $parts = explode('/', $timezone_string); |
|
| 1058 | + //remove the continent |
|
| 1059 | + unset($parts[0]); |
|
| 1060 | + $t_parts = array(); |
|
| 1061 | + foreach ($parts as $part) { |
|
| 1062 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1063 | + } |
|
| 1064 | + return implode(' - ', $t_parts); |
|
| 1065 | + } |
|
| 1066 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1067 | + $gmt_offset = get_option('gmt_offset'); |
|
| 1068 | + $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
| 1069 | + $parts = explode('.', (string) $gmt_offset); |
|
| 1070 | + if (count($parts) === 1) { |
|
| 1071 | + $parts[1] = '00'; |
|
| 1072 | + } else { |
|
| 1073 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1074 | + //to minutes, eg 30 or 15, respectively |
|
| 1075 | + $hour_fraction = (float) ('0.' . $parts[1]); |
|
| 1076 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 1077 | + } |
|
| 1078 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1085 | + * for a month using a string like "February" or "February 2017", |
|
| 1086 | + * and you don't specify a day as part of your string, |
|
| 1087 | + * then PHP will use whatever the current day of the month is. |
|
| 1088 | + * IF the current day of the month happens to be the 30th or 31st, |
|
| 1089 | + * then PHP gets really confused by a date like February 30, |
|
| 1090 | + * so instead of saying |
|
| 1091 | + * "Hey February only has 28 days (this year)... |
|
| 1092 | + * ...you must have meant the last day of the month!" |
|
| 1093 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1094 | + * because someone requesting February 30th obviously meant March 1st! |
|
| 1095 | + * The way around this is to always set the day to the first, |
|
| 1096 | + * so that the month will stay on the month you wanted. |
|
| 1097 | + * this method will add that "1" into your date regardless of the format. |
|
| 1098 | + * |
|
| 1099 | + * @param string $month |
|
| 1100 | + * @return string |
|
| 1101 | + */ |
|
| 1102 | + public static function first_of_month_timestamp($month = '') |
|
| 1103 | + { |
|
| 1104 | + $month = (string) $month; |
|
| 1105 | + $year = ''; |
|
| 1106 | + // check if the incoming string has a year in it or not |
|
| 1107 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1108 | + $year = $matches[0]; |
|
| 1109 | + // ten remove that from the month string as well as any spaces |
|
| 1110 | + $month = trim(str_replace($year, '', $month)); |
|
| 1111 | + // add a space before the year |
|
| 1112 | + $year = " {$year}"; |
|
| 1113 | + } |
|
| 1114 | + // return timestamp for something like "February 1 2017" |
|
| 1115 | + return strtotime("{$month} 1{$year}"); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1121 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1122 | + */ |
|
| 1123 | + public static function tomorrow() |
|
| 1124 | + { |
|
| 1125 | + //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
| 1126 | + //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
| 1127 | + //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
| 1128 | + //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
| 1129 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * ** |
|
| 1135 | + * Gives a nicely-formatted list of timezone strings. |
|
| 1136 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1137 | + * |
|
| 1138 | + * @since 4.9.40.rc.008 |
|
| 1139 | + * @staticvar bool $mo_loaded |
|
| 1140 | + * @staticvar string $locale_loaded |
|
| 1141 | + * @param string $selected_zone Selected timezone. |
|
| 1142 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1143 | + * @return string |
|
| 1144 | + */ |
|
| 1145 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1146 | + { |
|
| 1147 | + static $mo_loaded = false, $locale_loaded = null; |
|
| 1148 | + $continents = array( |
|
| 1149 | + 'Africa', |
|
| 1150 | + 'America', |
|
| 1151 | + 'Antarctica', |
|
| 1152 | + 'Arctic', |
|
| 1153 | + 'Asia', |
|
| 1154 | + 'Atlantic', |
|
| 1155 | + 'Australia', |
|
| 1156 | + 'Europe', |
|
| 1157 | + 'Indian', |
|
| 1158 | + 'Pacific', |
|
| 1159 | + ); |
|
| 1160 | + // Load translations for continents and cities. |
|
| 1161 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1162 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1163 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1164 | + unload_textdomain('continents-cities'); |
|
| 1165 | + load_textdomain('continents-cities', $mofile); |
|
| 1166 | + $mo_loaded = true; |
|
| 1167 | + } |
|
| 1168 | + $zone_data = array(); |
|
| 1169 | + foreach (timezone_identifiers_list() as $zone) { |
|
| 1170 | + $zone = explode('/', $zone); |
|
| 1171 | + if (! in_array($zone[0], $continents, true)) { |
|
| 1172 | + continue; |
|
| 1173 | + } |
|
| 1174 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1175 | + $exists = array( |
|
| 1176 | + 0 => isset($zone[0]) && $zone[0], |
|
| 1177 | + 1 => isset($zone[1]) && $zone[1], |
|
| 1178 | + 2 => isset($zone[2]) && $zone[2], |
|
| 1179 | + ); |
|
| 1180 | + $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
| 1181 | + $exists[4] = $exists[1] && $exists[3]; |
|
| 1182 | + $exists[5] = $exists[2] && $exists[3]; |
|
| 1183 | + $zone_data[] = array( |
|
| 1184 | + 'continent' => $exists[0] ? $zone[0] : '', |
|
| 1185 | + 'city' => $exists[1] ? $zone[1] : '', |
|
| 1186 | + 'subcity' => $exists[2] ? $zone[2] : '', |
|
| 1187 | + 't_continent' => $exists[3] |
|
| 1188 | + ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
| 1189 | + : '', |
|
| 1190 | + 't_city' => $exists[4] |
|
| 1191 | + ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
| 1192 | + : '', |
|
| 1193 | + 't_subcity' => $exists[5] |
|
| 1194 | + ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
| 1195 | + : '', |
|
| 1196 | + ); |
|
| 1197 | + } |
|
| 1198 | + usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
| 1199 | + $structure = array(); |
|
| 1200 | + if (empty($selected_zone)) { |
|
| 1201 | + $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1202 | + } |
|
| 1203 | + foreach ($zone_data as $key => $zone) { |
|
| 1204 | + // Build value in an array to join later |
|
| 1205 | + $value = array($zone['continent']); |
|
| 1206 | + if (empty($zone['city'])) { |
|
| 1207 | + // It's at the continent level (generally won't happen) |
|
| 1208 | + $display = $zone['t_continent']; |
|
| 1209 | + } else { |
|
| 1210 | + // It's inside a continent group |
|
| 1211 | + // Continent optgroup |
|
| 1212 | + if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
| 1213 | + $label = $zone['t_continent']; |
|
| 1214 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1215 | + } |
|
| 1216 | + // Add the city to the value |
|
| 1217 | + $value[] = $zone['city']; |
|
| 1218 | + $display = $zone['t_city']; |
|
| 1219 | + if (! empty($zone['subcity'])) { |
|
| 1220 | + // Add the subcity to the value |
|
| 1221 | + $value[] = $zone['subcity']; |
|
| 1222 | + $display .= ' - ' . $zone['t_subcity']; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + // Build the value |
|
| 1226 | + $value = implode('/', $value); |
|
| 1227 | + $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
|
| 1228 | + $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
| 1229 | + . esc_html($display) |
|
| 1230 | + . '</option>'; |
|
| 1231 | + // Close continent optgroup |
|
| 1232 | + if (! empty($zone['city']) |
|
| 1233 | + && ( |
|
| 1234 | + ! isset($zone_data[ $key + 1 ]) |
|
| 1235 | + || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
| 1236 | + ) |
|
| 1237 | + ) { |
|
| 1238 | + $structure[] = '</optgroup>'; |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + return implode("\n", $structure); |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1247 | + * |
|
| 1248 | + * @param int|WP_User $user_id |
|
| 1249 | + * @return string |
|
| 1250 | + */ |
|
| 1251 | + public static function get_user_locale($user_id = 0) |
|
| 1252 | + { |
|
| 1253 | + if (function_exists('get_user_locale')) { |
|
| 1254 | + return get_user_locale($user_id); |
|
| 1255 | + } |
|
| 1256 | + return get_locale(); |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | 1259 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | new DateTimeZone($timezone_string); |
| 65 | 65 | } catch (Exception $e) { |
| 66 | 66 | // sometimes we take exception to exceptions |
| 67 | - if (! $throw_error) { |
|
| 67 | + if ( ! $throw_error) { |
|
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | throw new EE_Error( |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | // although we don't know the TZ abbreviation, we know the UTC offset |
| 115 | 115 | $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
| 116 | 116 | //only use this timezone_string IF it's current offset matches the given offset |
| 117 | - if(! empty($timezone_string)) { |
|
| 118 | - $offset = null; |
|
| 117 | + if ( ! empty($timezone_string)) { |
|
| 118 | + $offset = null; |
|
| 119 | 119 | try { |
| 120 | 120 | $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
| 121 | 121 | if ($offset !== $gmt_offset) { |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
| 275 | 275 | { |
| 276 | - $gmt_offset = (int) $gmt_offset; |
|
| 276 | + $gmt_offset = (int) $gmt_offset; |
|
| 277 | 277 | /** @var array[] $abbreviations */ |
| 278 | 278 | $abbreviations = DateTimeZone::listAbbreviations(); |
| 279 | 279 | foreach ($abbreviations as $abbreviation) { |
@@ -344,9 +344,9 @@ discard block |
||
| 344 | 344 | public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
| 345 | 345 | { |
| 346 | 346 | $transition = self::get_timezone_transitions($date_time_zone, $time); |
| 347 | - if (! isset($transition['offset'])) { |
|
| 347 | + if ( ! isset($transition['offset'])) { |
|
| 348 | 348 | $transition['offset'] = 0; |
| 349 | - if (! isset($transition['ts'])) { |
|
| 349 | + if ( ! isset($transition['ts'])) { |
|
| 350 | 350 | throw new DomainException( |
| 351 | 351 | sprintf( |
| 352 | 352 | esc_html__('An invalid timezone transition was received %1$s', 'event_espresso'), |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | public static function timezone_select_input($timezone_string = '') |
| 367 | 367 | { |
| 368 | 368 | // get WP date time format |
| 369 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 369 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 370 | 370 | // if passed a value, then use that, else get WP option |
| 371 | 371 | $timezone_string = ! empty($timezone_string) ? $timezone_string : (string) get_option('timezone_string'); |
| 372 | 372 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -380,9 +380,9 @@ discard block |
||
| 380 | 380 | $timezone_string = 'UTC'; |
| 381 | 381 | $check_zone_info = false; |
| 382 | 382 | if ($gmt_offset > 0) { |
| 383 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 383 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 384 | 384 | } elseif ($gmt_offset < 0) { |
| 385 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 385 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | 388 | ?> |
@@ -402,11 +402,11 @@ discard block |
||
| 402 | 402 | __('%1$sUTC%2$s time is %3$s'), |
| 403 | 403 | '<abbr title="Coordinated Universal Time">', |
| 404 | 404 | '</abbr>', |
| 405 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 405 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 406 | 406 | ); |
| 407 | 407 | ?></span> |
| 408 | - <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 409 | - <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
| 408 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 409 | + <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 410 | 410 | <?php endif; ?> |
| 411 | 411 | |
| 412 | 412 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
| 446 | 446 | printf( |
| 447 | 447 | $message, |
| 448 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >' |
|
| 448 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >' |
|
| 449 | 449 | ); |
| 450 | 450 | } else { |
| 451 | 451 | _e('This timezone does not observe daylight saving time.'); |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
| 479 | 479 | $timezone_string = self::get_valid_timezone_string($timezone_string); |
| 480 | 480 | $TimeZone = new DateTimeZone($timezone_string); |
| 481 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 481 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 482 | 482 | $offset = timezone_offset_get($TimeZone, $DateTime); |
| 483 | 483 | return (int) $DateTime->format('U') + (int) $offset; |
| 484 | 484 | } |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | */ |
| 570 | 570 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 571 | 571 | { |
| 572 | - if (! $DateTime instanceof DateTime) { |
|
| 572 | + if ( ! $DateTime instanceof DateTime) { |
|
| 573 | 573 | throw new EE_Error( |
| 574 | 574 | sprintf( |
| 575 | 575 | esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -579,25 +579,25 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | switch ($period) { |
| 581 | 581 | case 'years' : |
| 582 | - $value = 'P' . $value . 'Y'; |
|
| 582 | + $value = 'P'.$value.'Y'; |
|
| 583 | 583 | break; |
| 584 | 584 | case 'months' : |
| 585 | - $value = 'P' . $value . 'M'; |
|
| 585 | + $value = 'P'.$value.'M'; |
|
| 586 | 586 | break; |
| 587 | 587 | case 'weeks' : |
| 588 | - $value = 'P' . $value . 'W'; |
|
| 588 | + $value = 'P'.$value.'W'; |
|
| 589 | 589 | break; |
| 590 | 590 | case 'days' : |
| 591 | - $value = 'P' . $value . 'D'; |
|
| 591 | + $value = 'P'.$value.'D'; |
|
| 592 | 592 | break; |
| 593 | 593 | case 'hours' : |
| 594 | - $value = 'PT' . $value . 'H'; |
|
| 594 | + $value = 'PT'.$value.'H'; |
|
| 595 | 595 | break; |
| 596 | 596 | case 'minutes' : |
| 597 | - $value = 'PT' . $value . 'M'; |
|
| 597 | + $value = 'PT'.$value.'M'; |
|
| 598 | 598 | break; |
| 599 | 599 | case 'seconds' : |
| 600 | - $value = 'PT' . $value . 'S'; |
|
| 600 | + $value = 'PT'.$value.'S'; |
|
| 601 | 601 | break; |
| 602 | 602 | } |
| 603 | 603 | switch ($operand) { |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | */ |
| 626 | 626 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 627 | 627 | { |
| 628 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 628 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 629 | 629 | throw new EE_Error( |
| 630 | 630 | sprintf( |
| 631 | 631 | esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | 'date' => $date_format['js'], |
| 739 | 739 | 'time' => $time_format['js'], |
| 740 | 740 | ), |
| 741 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 741 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 742 | 742 | ); |
| 743 | 743 | } |
| 744 | 744 | |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * |
| 758 | 758 | * @var array |
| 759 | 759 | */ |
| 760 | - $symbols_map = array( |
|
| 760 | + $symbols_map = array( |
|
| 761 | 761 | // Day |
| 762 | 762 | //01 |
| 763 | 763 | 'd' => array( |
@@ -909,26 +909,26 @@ discard block |
||
| 909 | 909 | $escaping = false; |
| 910 | 910 | $format_string_length = strlen($format_string); |
| 911 | 911 | for ($i = 0; $i < $format_string_length; $i++) { |
| 912 | - $char = $format_string[ $i ]; |
|
| 912 | + $char = $format_string[$i]; |
|
| 913 | 913 | if ($char === '\\') { // PHP date format escaping character |
| 914 | 914 | $i++; |
| 915 | 915 | if ($escaping) { |
| 916 | - $jquery_ui_format .= $format_string[ $i ]; |
|
| 917 | - $moment_format .= $format_string[ $i ]; |
|
| 916 | + $jquery_ui_format .= $format_string[$i]; |
|
| 917 | + $moment_format .= $format_string[$i]; |
|
| 918 | 918 | } else { |
| 919 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
| 920 | - $moment_format .= $format_string[ $i ]; |
|
| 919 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 920 | + $moment_format .= $format_string[$i]; |
|
| 921 | 921 | } |
| 922 | 922 | $escaping = true; |
| 923 | 923 | } else { |
| 924 | 924 | if ($escaping) { |
| 925 | 925 | $jquery_ui_format .= "'"; |
| 926 | 926 | $moment_format .= "'"; |
| 927 | - $escaping = false; |
|
| 927 | + $escaping = false; |
|
| 928 | 928 | } |
| 929 | - if (isset($symbols_map[ $char ])) { |
|
| 930 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
| 931 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
| 929 | + if (isset($symbols_map[$char])) { |
|
| 930 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 931 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 932 | 932 | } else { |
| 933 | 933 | $jquery_ui_format .= $char; |
| 934 | 934 | $moment_format .= $char; |
@@ -986,7 +986,7 @@ discard block |
||
| 986 | 986 | { |
| 987 | 987 | |
| 988 | 988 | if ( |
| 989 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 989 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
| 990 | 990 | || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
| 991 | 991 | || $date_2->format( |
| 992 | 992 | EE_Datetime_Field::mysql_time_format |
@@ -1022,8 +1022,8 @@ discard block |
||
| 1022 | 1022 | ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
| 1023 | 1023 | : (float) get_option('gmt_offset'); |
| 1024 | 1024 | $query_interval = $offset < 0 |
| 1025 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1026 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1025 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 1026 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 1027 | 1027 | return $query_interval; |
| 1028 | 1028 | } |
| 1029 | 1029 | |
@@ -1040,16 +1040,16 @@ discard block |
||
| 1040 | 1040 | public static function get_timezone_string_for_display() |
| 1041 | 1041 | { |
| 1042 | 1042 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 1043 | - if (! empty($pretty_timezone)) { |
|
| 1043 | + if ( ! empty($pretty_timezone)) { |
|
| 1044 | 1044 | return esc_html($pretty_timezone); |
| 1045 | 1045 | } |
| 1046 | 1046 | $timezone_string = get_option('timezone_string'); |
| 1047 | 1047 | if ($timezone_string) { |
| 1048 | 1048 | static $mo_loaded = false; |
| 1049 | 1049 | // Load translations for continents and cities just like wp_timezone_choice does |
| 1050 | - if (! $mo_loaded) { |
|
| 1050 | + if ( ! $mo_loaded) { |
|
| 1051 | 1051 | $locale = get_locale(); |
| 1052 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1052 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 1053 | 1053 | load_textdomain('continents-cities', $mofile); |
| 1054 | 1054 | $mo_loaded = true; |
| 1055 | 1055 | } |
@@ -1072,10 +1072,10 @@ discard block |
||
| 1072 | 1072 | } else { |
| 1073 | 1073 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 1074 | 1074 | //to minutes, eg 30 or 15, respectively |
| 1075 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
| 1075 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 1076 | 1076 | $parts[1] = (string) $hour_fraction * 60; |
| 1077 | 1077 | } |
| 1078 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1078 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | |
@@ -1158,9 +1158,9 @@ discard block |
||
| 1158 | 1158 | 'Pacific', |
| 1159 | 1159 | ); |
| 1160 | 1160 | // Load translations for continents and cities. |
| 1161 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1161 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1162 | 1162 | $locale_loaded = $locale ? $locale : get_locale(); |
| 1163 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1163 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
| 1164 | 1164 | unload_textdomain('continents-cities'); |
| 1165 | 1165 | load_textdomain('continents-cities', $mofile); |
| 1166 | 1166 | $mo_loaded = true; |
@@ -1168,11 +1168,11 @@ discard block |
||
| 1168 | 1168 | $zone_data = array(); |
| 1169 | 1169 | foreach (timezone_identifiers_list() as $zone) { |
| 1170 | 1170 | $zone = explode('/', $zone); |
| 1171 | - if (! in_array($zone[0], $continents, true)) { |
|
| 1171 | + if ( ! in_array($zone[0], $continents, true)) { |
|
| 1172 | 1172 | continue; |
| 1173 | 1173 | } |
| 1174 | 1174 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
| 1175 | - $exists = array( |
|
| 1175 | + $exists = array( |
|
| 1176 | 1176 | 0 => isset($zone[0]) && $zone[0], |
| 1177 | 1177 | 1 => isset($zone[1]) && $zone[1], |
| 1178 | 1178 | 2 => isset($zone[2]) && $zone[2], |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | usort($zone_data, '_wp_timezone_choice_usort_callback'); |
| 1199 | 1199 | $structure = array(); |
| 1200 | 1200 | if (empty($selected_zone)) { |
| 1201 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1201 | + $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>'; |
|
| 1202 | 1202 | } |
| 1203 | 1203 | foreach ($zone_data as $key => $zone) { |
| 1204 | 1204 | // Build value in an array to join later |
@@ -1209,30 +1209,30 @@ discard block |
||
| 1209 | 1209 | } else { |
| 1210 | 1210 | // It's inside a continent group |
| 1211 | 1211 | // Continent optgroup |
| 1212 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
| 1212 | + if ( ! isset($zone_data[$key - 1]) || $zone_data[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1213 | 1213 | $label = $zone['t_continent']; |
| 1214 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1214 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
| 1215 | 1215 | } |
| 1216 | 1216 | // Add the city to the value |
| 1217 | 1217 | $value[] = $zone['city']; |
| 1218 | 1218 | $display = $zone['t_city']; |
| 1219 | - if (! empty($zone['subcity'])) { |
|
| 1219 | + if ( ! empty($zone['subcity'])) { |
|
| 1220 | 1220 | // Add the subcity to the value |
| 1221 | 1221 | $value[] = $zone['subcity']; |
| 1222 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1222 | + $display .= ' - '.$zone['t_subcity']; |
|
| 1223 | 1223 | } |
| 1224 | 1224 | } |
| 1225 | 1225 | // Build the value |
| 1226 | 1226 | $value = implode('/', $value); |
| 1227 | 1227 | $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
| 1228 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
| 1228 | + $structure[] = '<option value="'.esc_attr($value).'"'.$selected.'>' |
|
| 1229 | 1229 | . esc_html($display) |
| 1230 | 1230 | . '</option>'; |
| 1231 | 1231 | // Close continent optgroup |
| 1232 | - if (! empty($zone['city']) |
|
| 1232 | + if ( ! empty($zone['city']) |
|
| 1233 | 1233 | && ( |
| 1234 | - ! isset($zone_data[ $key + 1 ]) |
|
| 1235 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
| 1234 | + ! isset($zone_data[$key + 1]) |
|
| 1235 | + || (isset($zone_data[$key + 1]) && $zone_data[$key + 1]['continent'] !== $zone['continent']) |
|
| 1236 | 1236 | ) |
| 1237 | 1237 | ) { |
| 1238 | 1238 | $structure[] = '</optgroup>'; |
@@ -38,217 +38,217 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | |
| 64 | 64 | } else { |
| 65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | - /** |
|
| 68 | - * espresso_minimum_php_version_error |
|
| 69 | - * |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - function espresso_minimum_php_version_error() |
|
| 73 | - { |
|
| 74 | - ?> |
|
| 65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | + /** |
|
| 68 | + * espresso_minimum_php_version_error |
|
| 69 | + * |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + function espresso_minimum_php_version_error() |
|
| 73 | + { |
|
| 74 | + ?> |
|
| 75 | 75 | <div class="error"> |
| 76 | 76 | <p> |
| 77 | 77 | <?php |
| 78 | - printf( |
|
| 79 | - esc_html__( |
|
| 80 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 81 | - 'event_espresso' |
|
| 82 | - ), |
|
| 83 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 84 | - PHP_VERSION, |
|
| 85 | - '<br/>', |
|
| 86 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 87 | - ); |
|
| 88 | - ?> |
|
| 78 | + printf( |
|
| 79 | + esc_html__( |
|
| 80 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 81 | + 'event_espresso' |
|
| 82 | + ), |
|
| 83 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 84 | + PHP_VERSION, |
|
| 85 | + '<br/>', |
|
| 86 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 87 | + ); |
|
| 88 | + ?> |
|
| 89 | 89 | </p> |
| 90 | 90 | </div> |
| 91 | 91 | <?php |
| 92 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 93 | - } |
|
| 92 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 96 | - } else { |
|
| 97 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 98 | - /** |
|
| 99 | - * espresso_version |
|
| 100 | - * Returns the plugin version |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - function espresso_version() |
|
| 105 | - { |
|
| 106 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.002'); |
|
| 107 | - } |
|
| 95 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 96 | + } else { |
|
| 97 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 98 | + /** |
|
| 99 | + * espresso_version |
|
| 100 | + * Returns the plugin version |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + function espresso_version() |
|
| 105 | + { |
|
| 106 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.002'); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * espresso_plugin_activation |
|
| 111 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 112 | - */ |
|
| 113 | - function espresso_plugin_activation() |
|
| 114 | - { |
|
| 115 | - update_option('ee_espresso_activation', true); |
|
| 116 | - } |
|
| 109 | + /** |
|
| 110 | + * espresso_plugin_activation |
|
| 111 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 112 | + */ |
|
| 113 | + function espresso_plugin_activation() |
|
| 114 | + { |
|
| 115 | + update_option('ee_espresso_activation', true); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 119 | - /** |
|
| 120 | - * espresso_load_error_handling |
|
| 121 | - * this function loads EE's class for handling exceptions and errors |
|
| 122 | - */ |
|
| 123 | - function espresso_load_error_handling() |
|
| 124 | - { |
|
| 125 | - static $error_handling_loaded = false; |
|
| 126 | - if ($error_handling_loaded) { |
|
| 127 | - return; |
|
| 128 | - } |
|
| 129 | - // load debugging tools |
|
| 130 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 131 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
| 132 | - \EEH_Debug_Tools::instance(); |
|
| 133 | - } |
|
| 134 | - // load error handling |
|
| 135 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 136 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
| 137 | - } else { |
|
| 138 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 139 | - } |
|
| 140 | - $error_handling_loaded = true; |
|
| 141 | - } |
|
| 118 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 119 | + /** |
|
| 120 | + * espresso_load_error_handling |
|
| 121 | + * this function loads EE's class for handling exceptions and errors |
|
| 122 | + */ |
|
| 123 | + function espresso_load_error_handling() |
|
| 124 | + { |
|
| 125 | + static $error_handling_loaded = false; |
|
| 126 | + if ($error_handling_loaded) { |
|
| 127 | + return; |
|
| 128 | + } |
|
| 129 | + // load debugging tools |
|
| 130 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 131 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
| 132 | + \EEH_Debug_Tools::instance(); |
|
| 133 | + } |
|
| 134 | + // load error handling |
|
| 135 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 136 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
| 137 | + } else { |
|
| 138 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 139 | + } |
|
| 140 | + $error_handling_loaded = true; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * espresso_load_required |
|
| 145 | - * given a class name and path, this function will load that file or throw an exception |
|
| 146 | - * |
|
| 147 | - * @param string $classname |
|
| 148 | - * @param string $full_path_to_file |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 152 | - { |
|
| 153 | - if (is_readable($full_path_to_file)) { |
|
| 154 | - require_once $full_path_to_file; |
|
| 155 | - } else { |
|
| 156 | - throw new \EE_Error ( |
|
| 157 | - sprintf( |
|
| 158 | - esc_html__( |
|
| 159 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 160 | - 'event_espresso' |
|
| 161 | - ), |
|
| 162 | - $classname |
|
| 163 | - ) |
|
| 164 | - ); |
|
| 165 | - } |
|
| 166 | - } |
|
| 143 | + /** |
|
| 144 | + * espresso_load_required |
|
| 145 | + * given a class name and path, this function will load that file or throw an exception |
|
| 146 | + * |
|
| 147 | + * @param string $classname |
|
| 148 | + * @param string $full_path_to_file |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 152 | + { |
|
| 153 | + if (is_readable($full_path_to_file)) { |
|
| 154 | + require_once $full_path_to_file; |
|
| 155 | + } else { |
|
| 156 | + throw new \EE_Error ( |
|
| 157 | + sprintf( |
|
| 158 | + esc_html__( |
|
| 159 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 160 | + 'event_espresso' |
|
| 161 | + ), |
|
| 162 | + $classname |
|
| 163 | + ) |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * @since 4.9.27 |
|
| 170 | - * @throws \EE_Error |
|
| 171 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 172 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 173 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
| 174 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
| 177 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
| 178 | - * @throws \OutOfBoundsException |
|
| 179 | - */ |
|
| 180 | - function bootstrap_espresso() |
|
| 181 | - { |
|
| 182 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
| 183 | - try { |
|
| 184 | - espresso_load_error_handling(); |
|
| 185 | - espresso_load_required( |
|
| 186 | - 'EEH_Base', |
|
| 187 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
| 188 | - ); |
|
| 189 | - espresso_load_required( |
|
| 190 | - 'EEH_File', |
|
| 191 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
| 192 | - ); |
|
| 193 | - espresso_load_required( |
|
| 194 | - 'EEH_File', |
|
| 195 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
| 196 | - ); |
|
| 197 | - espresso_load_required( |
|
| 198 | - 'EEH_Array', |
|
| 199 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
| 200 | - ); |
|
| 201 | - // instantiate and configure PSR4 autoloader |
|
| 202 | - espresso_load_required( |
|
| 203 | - 'Psr4Autoloader', |
|
| 204 | - EE_CORE . 'Psr4Autoloader.php' |
|
| 205 | - ); |
|
| 206 | - espresso_load_required( |
|
| 207 | - 'EE_Psr4AutoloaderInit', |
|
| 208 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
| 209 | - ); |
|
| 210 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
| 211 | - $AutoloaderInit->initializeAutoloader(); |
|
| 212 | - espresso_load_required( |
|
| 213 | - 'EE_Request', |
|
| 214 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
| 215 | - ); |
|
| 216 | - espresso_load_required( |
|
| 217 | - 'EE_Response', |
|
| 218 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
| 219 | - ); |
|
| 220 | - espresso_load_required( |
|
| 221 | - 'EE_Bootstrap', |
|
| 222 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
| 223 | - ); |
|
| 224 | - // bootstrap EE and the request stack |
|
| 225 | - new EE_Bootstrap( |
|
| 226 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
| 227 | - new EE_Response() |
|
| 228 | - ); |
|
| 229 | - } catch (Exception $e) { |
|
| 230 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
| 231 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - bootstrap_espresso(); |
|
| 235 | - } |
|
| 168 | + /** |
|
| 169 | + * @since 4.9.27 |
|
| 170 | + * @throws \EE_Error |
|
| 171 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 172 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 173 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
| 174 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
| 177 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
| 178 | + * @throws \OutOfBoundsException |
|
| 179 | + */ |
|
| 180 | + function bootstrap_espresso() |
|
| 181 | + { |
|
| 182 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
| 183 | + try { |
|
| 184 | + espresso_load_error_handling(); |
|
| 185 | + espresso_load_required( |
|
| 186 | + 'EEH_Base', |
|
| 187 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
| 188 | + ); |
|
| 189 | + espresso_load_required( |
|
| 190 | + 'EEH_File', |
|
| 191 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
| 192 | + ); |
|
| 193 | + espresso_load_required( |
|
| 194 | + 'EEH_File', |
|
| 195 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
| 196 | + ); |
|
| 197 | + espresso_load_required( |
|
| 198 | + 'EEH_Array', |
|
| 199 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
| 200 | + ); |
|
| 201 | + // instantiate and configure PSR4 autoloader |
|
| 202 | + espresso_load_required( |
|
| 203 | + 'Psr4Autoloader', |
|
| 204 | + EE_CORE . 'Psr4Autoloader.php' |
|
| 205 | + ); |
|
| 206 | + espresso_load_required( |
|
| 207 | + 'EE_Psr4AutoloaderInit', |
|
| 208 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
| 209 | + ); |
|
| 210 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
| 211 | + $AutoloaderInit->initializeAutoloader(); |
|
| 212 | + espresso_load_required( |
|
| 213 | + 'EE_Request', |
|
| 214 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
| 215 | + ); |
|
| 216 | + espresso_load_required( |
|
| 217 | + 'EE_Response', |
|
| 218 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
| 219 | + ); |
|
| 220 | + espresso_load_required( |
|
| 221 | + 'EE_Bootstrap', |
|
| 222 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
| 223 | + ); |
|
| 224 | + // bootstrap EE and the request stack |
|
| 225 | + new EE_Bootstrap( |
|
| 226 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
| 227 | + new EE_Response() |
|
| 228 | + ); |
|
| 229 | + } catch (Exception $e) { |
|
| 230 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
| 231 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + bootstrap_espresso(); |
|
| 235 | + } |
|
| 236 | 236 | } |
| 237 | 237 | if (! function_exists('espresso_deactivate_plugin')) { |
| 238 | - /** |
|
| 239 | - * deactivate_plugin |
|
| 240 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 241 | - * |
|
| 242 | - * @access public |
|
| 243 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 247 | - { |
|
| 248 | - if (! function_exists('deactivate_plugins')) { |
|
| 249 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 250 | - } |
|
| 251 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 252 | - deactivate_plugins($plugin_basename); |
|
| 253 | - } |
|
| 238 | + /** |
|
| 239 | + * deactivate_plugin |
|
| 240 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 241 | + * |
|
| 242 | + * @access public |
|
| 243 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 247 | + { |
|
| 248 | + if (! function_exists('deactivate_plugins')) { |
|
| 249 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 250 | + } |
|
| 251 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 252 | + deactivate_plugins($plugin_basename); |
|
| 253 | + } |
|
| 254 | 254 | } |
@@ -18,1250 +18,1250 @@ |
||
| 18 | 18 | class EED_Messages extends EED_Module |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * This holds the EE_messages controller |
|
| 23 | - * |
|
| 24 | - * @deprecated 4.9.0 |
|
| 25 | - * @var EE_messages $_EEMSG |
|
| 26 | - */ |
|
| 27 | - protected static $_EEMSG; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 31 | - */ |
|
| 32 | - protected static $_message_resource_manager; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This holds the EE_Messages_Processor business class. |
|
| 36 | - * |
|
| 37 | - * @type EE_Messages_Processor |
|
| 38 | - */ |
|
| 39 | - protected static $_MSG_PROCESSOR; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * holds all the paths for various messages components. |
|
| 43 | - * Utilized by autoloader registry |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected static $_MSG_PATHS; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 52 | - * Format is: |
|
| 53 | - * array( |
|
| 54 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 55 | - * ) |
|
| 56 | - * |
|
| 57 | - * @var EE_Messages_Template_Pack[] |
|
| 58 | - */ |
|
| 59 | - protected static $_TMP_PACKS = array(); |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return EED_Messages |
|
| 64 | - */ |
|
| 65 | - public static function instance() |
|
| 66 | - { |
|
| 67 | - return parent::get_instance(__CLASS__); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 73 | - * |
|
| 74 | - * @since 4.5.0 |
|
| 75 | - * @return void |
|
| 76 | - */ |
|
| 77 | - public static function set_hooks() |
|
| 78 | - { |
|
| 79 | - //actions |
|
| 80 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 81 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 82 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 83 | - //filters |
|
| 84 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 85 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 86 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 87 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 88 | - //register routes |
|
| 89 | - self::_register_routes(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 94 | - * |
|
| 95 | - * @access public |
|
| 96 | - * @return void |
|
| 97 | - */ |
|
| 98 | - public static function set_hooks_admin() |
|
| 99 | - { |
|
| 100 | - //actions |
|
| 101 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 102 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 103 | - array('EED_Messages', 'payment_reminder'), 10); |
|
| 104 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 105 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 106 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 107 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 108 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 109 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
| 110 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 111 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 112 | - //filters |
|
| 113 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 114 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
| 115 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 116 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 117 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 118 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * All the message triggers done by route go in here. |
|
| 124 | - * |
|
| 125 | - * @since 4.5.0 |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - protected static function _register_routes() |
|
| 129 | - { |
|
| 130 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 131 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 132 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 133 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 134 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * This is called when a browser display trigger is executed. |
|
| 140 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 141 | - * browser. |
|
| 142 | - * |
|
| 143 | - * @since 4.9.0 |
|
| 144 | - * @param WP $WP |
|
| 145 | - * @throws EE_Error |
|
| 146 | - * @throws InvalidArgumentException |
|
| 147 | - * @throws ReflectionException |
|
| 148 | - * @throws InvalidDataTypeException |
|
| 149 | - * @throws InvalidInterfaceException |
|
| 150 | - */ |
|
| 151 | - public function browser_trigger($WP) |
|
| 152 | - { |
|
| 153 | - //ensure controller is loaded |
|
| 154 | - self::_load_controller(); |
|
| 155 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 156 | - try { |
|
| 157 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 158 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 159 | - } catch (EE_Error $e) { |
|
| 160 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 161 | - 'event_espresso'); |
|
| 162 | - // add specific message for developers if WP_DEBUG in on |
|
| 163 | - $error_msg .= '||' . $e->getMessage(); |
|
| 164 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * This is called when a browser error trigger is executed. |
|
| 171 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 172 | - * message and display it. |
|
| 173 | - * |
|
| 174 | - * @since 4.9.0 |
|
| 175 | - * @param $WP |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws InvalidArgumentException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - */ |
|
| 181 | - public function browser_error_trigger($WP) |
|
| 182 | - { |
|
| 183 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 184 | - if ($token) { |
|
| 185 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 186 | - if ($message instanceof EE_Message) { |
|
| 187 | - header('HTTP/1.1 200 OK'); |
|
| 188 | - $error_msg = nl2br($message->error_message()); |
|
| 189 | - ?> |
|
| 21 | + /** |
|
| 22 | + * This holds the EE_messages controller |
|
| 23 | + * |
|
| 24 | + * @deprecated 4.9.0 |
|
| 25 | + * @var EE_messages $_EEMSG |
|
| 26 | + */ |
|
| 27 | + protected static $_EEMSG; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 31 | + */ |
|
| 32 | + protected static $_message_resource_manager; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This holds the EE_Messages_Processor business class. |
|
| 36 | + * |
|
| 37 | + * @type EE_Messages_Processor |
|
| 38 | + */ |
|
| 39 | + protected static $_MSG_PROCESSOR; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * holds all the paths for various messages components. |
|
| 43 | + * Utilized by autoloader registry |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected static $_MSG_PATHS; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 52 | + * Format is: |
|
| 53 | + * array( |
|
| 54 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 55 | + * ) |
|
| 56 | + * |
|
| 57 | + * @var EE_Messages_Template_Pack[] |
|
| 58 | + */ |
|
| 59 | + protected static $_TMP_PACKS = array(); |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return EED_Messages |
|
| 64 | + */ |
|
| 65 | + public static function instance() |
|
| 66 | + { |
|
| 67 | + return parent::get_instance(__CLASS__); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 73 | + * |
|
| 74 | + * @since 4.5.0 |
|
| 75 | + * @return void |
|
| 76 | + */ |
|
| 77 | + public static function set_hooks() |
|
| 78 | + { |
|
| 79 | + //actions |
|
| 80 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 81 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 82 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 83 | + //filters |
|
| 84 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 85 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 86 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 87 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 88 | + //register routes |
|
| 89 | + self::_register_routes(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 94 | + * |
|
| 95 | + * @access public |
|
| 96 | + * @return void |
|
| 97 | + */ |
|
| 98 | + public static function set_hooks_admin() |
|
| 99 | + { |
|
| 100 | + //actions |
|
| 101 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 102 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 103 | + array('EED_Messages', 'payment_reminder'), 10); |
|
| 104 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 105 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 106 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 107 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 108 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 109 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
| 110 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 111 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 112 | + //filters |
|
| 113 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 114 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
| 115 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 116 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 117 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 118 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * All the message triggers done by route go in here. |
|
| 124 | + * |
|
| 125 | + * @since 4.5.0 |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + protected static function _register_routes() |
|
| 129 | + { |
|
| 130 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 131 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 132 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 133 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 134 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * This is called when a browser display trigger is executed. |
|
| 140 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 141 | + * browser. |
|
| 142 | + * |
|
| 143 | + * @since 4.9.0 |
|
| 144 | + * @param WP $WP |
|
| 145 | + * @throws EE_Error |
|
| 146 | + * @throws InvalidArgumentException |
|
| 147 | + * @throws ReflectionException |
|
| 148 | + * @throws InvalidDataTypeException |
|
| 149 | + * @throws InvalidInterfaceException |
|
| 150 | + */ |
|
| 151 | + public function browser_trigger($WP) |
|
| 152 | + { |
|
| 153 | + //ensure controller is loaded |
|
| 154 | + self::_load_controller(); |
|
| 155 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 156 | + try { |
|
| 157 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 158 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 159 | + } catch (EE_Error $e) { |
|
| 160 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 161 | + 'event_espresso'); |
|
| 162 | + // add specific message for developers if WP_DEBUG in on |
|
| 163 | + $error_msg .= '||' . $e->getMessage(); |
|
| 164 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * This is called when a browser error trigger is executed. |
|
| 171 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 172 | + * message and display it. |
|
| 173 | + * |
|
| 174 | + * @since 4.9.0 |
|
| 175 | + * @param $WP |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws InvalidArgumentException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + */ |
|
| 181 | + public function browser_error_trigger($WP) |
|
| 182 | + { |
|
| 183 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 184 | + if ($token) { |
|
| 185 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 186 | + if ($message instanceof EE_Message) { |
|
| 187 | + header('HTTP/1.1 200 OK'); |
|
| 188 | + $error_msg = nl2br($message->error_message()); |
|
| 189 | + ?> |
|
| 190 | 190 | <!DOCTYPE html> |
| 191 | 191 | <html> |
| 192 | 192 | <head></head> |
| 193 | 193 | <body> |
| 194 | 194 | <?php echo empty($error_msg) |
| 195 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 196 | - 'event_espresso') |
|
| 197 | - : wp_kses( |
|
| 198 | - $error_msg, |
|
| 199 | - array( |
|
| 200 | - 'a' => array( |
|
| 201 | - 'href' => array(), |
|
| 202 | - 'title' => array(), |
|
| 203 | - ), |
|
| 204 | - 'span' => array(), |
|
| 205 | - 'div' => array(), |
|
| 206 | - 'p' => array(), |
|
| 207 | - 'strong' => array(), |
|
| 208 | - 'em' => array(), |
|
| 209 | - 'br' => array(), |
|
| 210 | - ) |
|
| 211 | - ); ?> |
|
| 195 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 196 | + 'event_espresso') |
|
| 197 | + : wp_kses( |
|
| 198 | + $error_msg, |
|
| 199 | + array( |
|
| 200 | + 'a' => array( |
|
| 201 | + 'href' => array(), |
|
| 202 | + 'title' => array(), |
|
| 203 | + ), |
|
| 204 | + 'span' => array(), |
|
| 205 | + 'div' => array(), |
|
| 206 | + 'p' => array(), |
|
| 207 | + 'strong' => array(), |
|
| 208 | + 'em' => array(), |
|
| 209 | + 'br' => array(), |
|
| 210 | + ) |
|
| 211 | + ); ?> |
|
| 212 | 212 | </body> |
| 213 | 213 | </html> |
| 214 | 214 | <?php |
| 215 | - exit; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - return; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * This runs when the msg_url_trigger route has initiated. |
|
| 224 | - * |
|
| 225 | - * @since 4.5.0 |
|
| 226 | - * @param WP $WP |
|
| 227 | - * @throws EE_Error |
|
| 228 | - * @throws InvalidArgumentException |
|
| 229 | - * @throws ReflectionException |
|
| 230 | - * @throws InvalidDataTypeException |
|
| 231 | - * @throws InvalidInterfaceException |
|
| 232 | - */ |
|
| 233 | - public function run($WP) |
|
| 234 | - { |
|
| 235 | - //ensure controller is loaded |
|
| 236 | - self::_load_controller(); |
|
| 237 | - // attempt to process message |
|
| 238 | - try { |
|
| 239 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 240 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 241 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 242 | - } catch (EE_Error $e) { |
|
| 243 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 244 | - 'event_espresso'); |
|
| 245 | - // add specific message for developers if WP_DEBUG in on |
|
| 246 | - $error_msg .= '||' . $e->getMessage(); |
|
| 247 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 254 | - * |
|
| 255 | - * @param WP $WP |
|
| 256 | - */ |
|
| 257 | - public function execute_batch_request($WP) |
|
| 258 | - { |
|
| 259 | - $this->run_cron(); |
|
| 260 | - header('HTTP/1.1 200 OK'); |
|
| 261 | - exit(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 267 | - * request. |
|
| 268 | - */ |
|
| 269 | - public function run_cron() |
|
| 270 | - { |
|
| 271 | - self::_load_controller(); |
|
| 272 | - //get required vars |
|
| 273 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 274 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 275 | - |
|
| 276 | - //now let's verify transient, if not valid exit immediately |
|
| 277 | - if (! get_transient($transient_key)) { |
|
| 278 | - /** |
|
| 279 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 280 | - * request. |
|
| 281 | - */ |
|
| 282 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - //if made it here, lets' delete the transient to keep the db clean |
|
| 286 | - delete_transient($transient_key); |
|
| 287 | - |
|
| 288 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 289 | - |
|
| 290 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 291 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 292 | - self::$_MSG_PROCESSOR->$method(); |
|
| 293 | - } else { |
|
| 294 | - //no matching task |
|
| 295 | - /** |
|
| 296 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 297 | - * request. |
|
| 298 | - */ |
|
| 299 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 300 | - $cron_type))); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * This is used to retrieve the template pack for the given name. |
|
| 310 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 311 | - * the default template pack is returned. |
|
| 312 | - * |
|
| 313 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 314 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 315 | - * in generating the Pack class name). |
|
| 316 | - * @return EE_Messages_Template_Pack |
|
| 317 | - * @throws EE_Error |
|
| 318 | - * @throws InvalidArgumentException |
|
| 319 | - * @throws ReflectionException |
|
| 320 | - * @throws InvalidDataTypeException |
|
| 321 | - * @throws InvalidInterfaceException |
|
| 322 | - */ |
|
| 323 | - public static function get_template_pack($template_pack_name) |
|
| 324 | - { |
|
| 325 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 326 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Retrieves an array of all template packs. |
|
| 332 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 333 | - * |
|
| 334 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 335 | - * @return EE_Messages_Template_Pack[] |
|
| 336 | - * @throws EE_Error |
|
| 337 | - * @throws InvalidArgumentException |
|
| 338 | - * @throws ReflectionException |
|
| 339 | - * @throws InvalidDataTypeException |
|
| 340 | - * @throws InvalidInterfaceException |
|
| 341 | - */ |
|
| 342 | - public static function get_template_packs() |
|
| 343 | - { |
|
| 344 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 345 | - |
|
| 346 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
| 347 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 348 | - $template_pack_collection->rewind(); |
|
| 349 | - $template_packs = array(); |
|
| 350 | - while ($template_pack_collection->valid()) { |
|
| 351 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 352 | - $template_pack_collection->next(); |
|
| 353 | - } |
|
| 354 | - return $template_packs; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 360 | - * |
|
| 361 | - * @since 4.5.0 |
|
| 362 | - * @return void |
|
| 363 | - * @throws EE_Error |
|
| 364 | - */ |
|
| 365 | - public static function set_autoloaders() |
|
| 366 | - { |
|
| 367 | - if (empty(self::$_MSG_PATHS)) { |
|
| 368 | - self::_set_messages_paths(); |
|
| 369 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 370 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 371 | - } |
|
| 372 | - // add aliases |
|
| 373 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 374 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 381 | - * for use by the Messages Autoloaders |
|
| 382 | - * |
|
| 383 | - * @since 4.5.0 |
|
| 384 | - * @return void. |
|
| 385 | - */ |
|
| 386 | - protected static function _set_messages_paths() |
|
| 387 | - { |
|
| 388 | - $dir_ref = array( |
|
| 389 | - 'messages/message_type', |
|
| 390 | - 'messages/messenger', |
|
| 391 | - 'messages/defaults', |
|
| 392 | - 'messages/defaults/email', |
|
| 393 | - 'messages/data_class', |
|
| 394 | - 'messages/validators', |
|
| 395 | - 'messages/validators/email', |
|
| 396 | - 'messages/validators/html', |
|
| 397 | - 'shortcodes', |
|
| 398 | - ); |
|
| 399 | - $paths = array(); |
|
| 400 | - foreach ($dir_ref as $index => $dir) { |
|
| 401 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
| 402 | - } |
|
| 403 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Takes care of loading dependencies |
|
| 409 | - * |
|
| 410 | - * @since 4.5.0 |
|
| 411 | - * @return void |
|
| 412 | - * @throws EE_Error |
|
| 413 | - * @throws InvalidArgumentException |
|
| 414 | - * @throws ReflectionException |
|
| 415 | - * @throws InvalidDataTypeException |
|
| 416 | - * @throws InvalidInterfaceException |
|
| 417 | - */ |
|
| 418 | - protected static function _load_controller() |
|
| 419 | - { |
|
| 420 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 421 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 422 | - self::set_autoloaders(); |
|
| 423 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 424 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 425 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @param EE_Transaction $transaction |
|
| 432 | - * @throws EE_Error |
|
| 433 | - * @throws InvalidArgumentException |
|
| 434 | - * @throws InvalidDataTypeException |
|
| 435 | - * @throws InvalidInterfaceException |
|
| 436 | - * @throws ReflectionException |
|
| 437 | - */ |
|
| 438 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 439 | - { |
|
| 440 | - self::_load_controller(); |
|
| 441 | - $data = array($transaction, null); |
|
| 442 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 448 | - * |
|
| 449 | - * @param EE_Transaction $transaction object |
|
| 450 | - * @param EE_Payment $payment object |
|
| 451 | - * @return void |
|
| 452 | - * @throws EE_Error |
|
| 453 | - * @throws InvalidArgumentException |
|
| 454 | - * @throws ReflectionException |
|
| 455 | - * @throws InvalidDataTypeException |
|
| 456 | - * @throws InvalidInterfaceException |
|
| 457 | - */ |
|
| 458 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 459 | - { |
|
| 460 | - self::_load_controller(); |
|
| 461 | - $data = array($transaction, $payment); |
|
| 462 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 463 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 464 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 465 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 466 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * @param EE_Transaction $transaction |
|
| 472 | - * @throws EE_Error |
|
| 473 | - * @throws InvalidArgumentException |
|
| 474 | - * @throws InvalidDataTypeException |
|
| 475 | - * @throws InvalidInterfaceException |
|
| 476 | - * @throws ReflectionException |
|
| 477 | - */ |
|
| 478 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 479 | - { |
|
| 480 | - self::_load_controller(); |
|
| 481 | - $data = array($transaction, null); |
|
| 482 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Trigger for Registration messages |
|
| 489 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 490 | - * incoming transaction. |
|
| 491 | - * |
|
| 492 | - * @param EE_Registration $registration |
|
| 493 | - * @param array $extra_details |
|
| 494 | - * @return void |
|
| 495 | - * @throws EE_Error |
|
| 496 | - * @throws InvalidArgumentException |
|
| 497 | - * @throws InvalidDataTypeException |
|
| 498 | - * @throws InvalidInterfaceException |
|
| 499 | - * @throws ReflectionException |
|
| 500 | - * @throws EntityNotFoundException |
|
| 501 | - */ |
|
| 502 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 503 | - { |
|
| 504 | - |
|
| 505 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 506 | - //no messages please |
|
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 511 | - $all_registrations = $registration->transaction()->registrations( |
|
| 512 | - array( |
|
| 513 | - array('REG_deleted' => false), |
|
| 514 | - 'order_by' => array( |
|
| 515 | - 'Event.EVT_name' => 'ASC', |
|
| 516 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 517 | - 'Attendee.ATT_fname' => 'ASC' |
|
| 518 | - ) |
|
| 519 | - ) |
|
| 520 | - ); |
|
| 521 | - //cached array of statuses so we only trigger messages once per status. |
|
| 522 | - $statuses_sent = array(); |
|
| 523 | - self::_load_controller(); |
|
| 524 | - $mtgs = array(); |
|
| 525 | - |
|
| 526 | - //loop through registrations and trigger messages once per status. |
|
| 527 | - foreach ($all_registrations as $reg) { |
|
| 528 | - |
|
| 529 | - //already triggered? |
|
| 530 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 531 | - continue; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 535 | - $mtgs = array_merge( |
|
| 536 | - $mtgs, |
|
| 537 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 538 | - $message_type, |
|
| 539 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 540 | - ) |
|
| 541 | - ); |
|
| 542 | - $statuses_sent[] = $reg->status_ID(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if (count($statuses_sent) > 1) { |
|
| 546 | - $mtgs = array_merge( |
|
| 547 | - $mtgs, |
|
| 548 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 549 | - 'registration_summary', |
|
| 550 | - array($registration->transaction(), null) |
|
| 551 | - ) |
|
| 552 | - ); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - //batch queue and initiate request |
|
| 556 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 557 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 563 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 564 | - * |
|
| 565 | - * @param EE_Registration $registration [description] |
|
| 566 | - * @param array $extra_details [description] |
|
| 567 | - * @return bool true = send away, false = nope halt the presses. |
|
| 568 | - */ |
|
| 569 | - protected static function _verify_registration_notification_send( |
|
| 570 | - EE_Registration $registration, |
|
| 571 | - $extra_details = array() |
|
| 572 | - ) { |
|
| 573 | - //self::log( |
|
| 574 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 575 | - // $registration->transaction(), |
|
| 576 | - // array( '$extra_details' => $extra_details ) |
|
| 577 | - //); |
|
| 578 | - // currently only using this to send messages for the primary registrant |
|
| 579 | - if (! $registration->is_primary_registrant()) { |
|
| 580 | - return false; |
|
| 581 | - } |
|
| 582 | - // first we check if we're in admin and not doing front ajax |
|
| 583 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 584 | - //make sure appropriate admin params are set for sending messages |
|
| 585 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 586 | - //no messages sent please. |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - } else { |
|
| 590 | - // frontend request (either regular or via AJAX) |
|
| 591 | - // TXN is NOT finalized ? |
|
| 592 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 593 | - return false; |
|
| 594 | - } |
|
| 595 | - // return visit but nothing changed ??? |
|
| 596 | - if ( |
|
| 597 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 598 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 599 | - ) { |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 603 | - if ( |
|
| 604 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 605 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 606 | - ) { |
|
| 607 | - return false; |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - // release the kraken |
|
| 611 | - return true; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 617 | - * status id. |
|
| 618 | - * |
|
| 619 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 620 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 621 | - * @param string $reg_status |
|
| 622 | - * @return array |
|
| 623 | - * @throws EE_Error |
|
| 624 | - * @throws InvalidArgumentException |
|
| 625 | - * @throws ReflectionException |
|
| 626 | - * @throws InvalidDataTypeException |
|
| 627 | - * @throws InvalidInterfaceException |
|
| 628 | - */ |
|
| 629 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 630 | - { |
|
| 631 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 632 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 633 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 634 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Simply returns the payment message type for the given payment status. |
|
| 640 | - * |
|
| 641 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 642 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 643 | - * @param string $payment_status The payment status being matched. |
|
| 644 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 645 | - * @throws EE_Error |
|
| 646 | - * @throws InvalidArgumentException |
|
| 647 | - * @throws ReflectionException |
|
| 648 | - * @throws InvalidDataTypeException |
|
| 649 | - * @throws InvalidInterfaceException |
|
| 650 | - */ |
|
| 651 | - protected static function _get_payment_message_type($payment_status) |
|
| 652 | - { |
|
| 653 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 654 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 655 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 656 | - : false; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 662 | - * |
|
| 663 | - * @access public |
|
| 664 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 665 | - * @return bool success/fail |
|
| 666 | - * @throws EE_Error |
|
| 667 | - * @throws InvalidArgumentException |
|
| 668 | - * @throws InvalidDataTypeException |
|
| 669 | - * @throws InvalidInterfaceException |
|
| 670 | - * @throws ReflectionException |
|
| 671 | - */ |
|
| 672 | - public static function process_resend($req_data) |
|
| 673 | - { |
|
| 674 | - self::_load_controller(); |
|
| 675 | - |
|
| 676 | - //if $msgID in this request then skip to the new resend_message |
|
| 677 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 678 | - return self::resend_message(); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 682 | - $req_data = (array)$req_data; |
|
| 683 | - foreach ($req_data as $request_key => $request_value) { |
|
| 684 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 688 | - return false; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - try { |
|
| 692 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 693 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 694 | - } catch (EE_Error $e) { |
|
| 695 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 696 | - return false; |
|
| 697 | - } |
|
| 698 | - EE_Error::add_success( |
|
| 699 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 700 | - ); |
|
| 701 | - return true; //everything got queued. |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 707 | - * |
|
| 708 | - * @return bool |
|
| 709 | - * @throws EE_Error |
|
| 710 | - * @throws InvalidArgumentException |
|
| 711 | - * @throws InvalidDataTypeException |
|
| 712 | - * @throws InvalidInterfaceException |
|
| 713 | - * @throws ReflectionException |
|
| 714 | - */ |
|
| 715 | - public static function resend_message() |
|
| 716 | - { |
|
| 717 | - self::_load_controller(); |
|
| 718 | - |
|
| 719 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 720 | - if (! $msgID) { |
|
| 721 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 722 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 723 | - return false; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 727 | - |
|
| 728 | - //setup success message. |
|
| 729 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 730 | - EE_Error::add_success(sprintf( |
|
| 731 | - _n( |
|
| 732 | - 'There was %d message queued for resending.', |
|
| 733 | - 'There were %d messages queued for resending.', |
|
| 734 | - $count_ready_for_resend, |
|
| 735 | - 'event_espresso' |
|
| 736 | - ), |
|
| 737 | - $count_ready_for_resend |
|
| 738 | - )); |
|
| 739 | - return true; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * Message triggers for manual payment applied by admin |
|
| 745 | - * |
|
| 746 | - * @param EE_Payment $payment EE_payment object |
|
| 747 | - * @return bool success/fail |
|
| 748 | - * @throws EE_Error |
|
| 749 | - * @throws InvalidArgumentException |
|
| 750 | - * @throws ReflectionException |
|
| 751 | - * @throws InvalidDataTypeException |
|
| 752 | - * @throws InvalidInterfaceException |
|
| 753 | - */ |
|
| 754 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 755 | - { |
|
| 756 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 757 | - //we need to get the transaction object |
|
| 758 | - $transaction = $payment->transaction(); |
|
| 759 | - if ($transaction instanceof EE_Transaction) { |
|
| 760 | - $data = array($transaction, $payment); |
|
| 761 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 762 | - |
|
| 763 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 764 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 765 | - |
|
| 766 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 767 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 768 | - |
|
| 769 | - self::_load_controller(); |
|
| 770 | - |
|
| 771 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 772 | - |
|
| 773 | - //get count of queued for generation |
|
| 774 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 775 | - EEM_Message::status_incomplete, |
|
| 776 | - EEM_Message::status_idle, |
|
| 777 | - )); |
|
| 778 | - |
|
| 779 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 780 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 781 | - return true; |
|
| 782 | - } else { |
|
| 783 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 784 | - /** |
|
| 785 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 786 | - * IMMEDIATE generation. |
|
| 787 | - */ |
|
| 788 | - if ($count_failed > 0) { |
|
| 789 | - EE_Error::add_error(sprintf( |
|
| 790 | - _n( |
|
| 791 | - 'The payment notification generation failed.', |
|
| 792 | - '%d payment notifications failed being sent.', |
|
| 793 | - $count_failed, |
|
| 794 | - 'event_espresso' |
|
| 795 | - ), |
|
| 796 | - $count_failed |
|
| 797 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
| 798 | - |
|
| 799 | - return false; |
|
| 800 | - } else { |
|
| 801 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 802 | - return true; |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - } else { |
|
| 806 | - EE_Error::add_error( |
|
| 807 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 808 | - 'event_espresso' |
|
| 809 | - ); |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 817 | - * |
|
| 818 | - * @since 4.3.0 |
|
| 819 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 820 | - * @param int $grp_id a specific message template group id. |
|
| 821 | - * @return void |
|
| 822 | - * @throws EE_Error |
|
| 823 | - * @throws InvalidArgumentException |
|
| 824 | - * @throws InvalidDataTypeException |
|
| 825 | - * @throws InvalidInterfaceException |
|
| 826 | - * @throws ReflectionException |
|
| 827 | - */ |
|
| 828 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 829 | - { |
|
| 830 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 831 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 832 | - self::_load_controller(); |
|
| 833 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 839 | - * |
|
| 840 | - * @since 4.3.0 |
|
| 841 | - * @param string $registration_message_trigger_url |
|
| 842 | - * @param EE_Registration $registration |
|
| 843 | - * @param string $messenger |
|
| 844 | - * @param string $message_type |
|
| 845 | - * @return string |
|
| 846 | - * @throws EE_Error |
|
| 847 | - * @throws InvalidArgumentException |
|
| 848 | - * @throws InvalidDataTypeException |
|
| 849 | - * @throws InvalidInterfaceException |
|
| 850 | - */ |
|
| 851 | - public static function registration_message_trigger_url( |
|
| 852 | - $registration_message_trigger_url, |
|
| 853 | - EE_Registration $registration, |
|
| 854 | - $messenger = 'html', |
|
| 855 | - $message_type = 'invoice' |
|
| 856 | - ) { |
|
| 857 | - // whitelist $messenger |
|
| 858 | - switch ($messenger) { |
|
| 859 | - case 'pdf' : |
|
| 860 | - $sending_messenger = 'pdf'; |
|
| 861 | - $generating_messenger = 'html'; |
|
| 862 | - break; |
|
| 863 | - case 'html' : |
|
| 864 | - default : |
|
| 865 | - $sending_messenger = 'html'; |
|
| 866 | - $generating_messenger = 'html'; |
|
| 867 | - break; |
|
| 868 | - } |
|
| 869 | - // whitelist $message_type |
|
| 870 | - switch ($message_type) { |
|
| 871 | - case 'receipt' : |
|
| 872 | - $message_type = 'receipt'; |
|
| 873 | - break; |
|
| 874 | - case 'invoice' : |
|
| 875 | - default : |
|
| 876 | - $message_type = 'invoice'; |
|
| 877 | - break; |
|
| 878 | - } |
|
| 879 | - // verify that both the messenger AND the message type are active |
|
| 880 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 881 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 882 | - $template_query_params = array( |
|
| 883 | - 'MTP_is_active' => true, |
|
| 884 | - 'MTP_messenger' => $generating_messenger, |
|
| 885 | - 'MTP_message_type' => $message_type, |
|
| 886 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 887 | - ); |
|
| 888 | - //get the message template group. |
|
| 889 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 890 | - //if we don't have an EE_Message_Template_Group then return |
|
| 891 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 892 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 893 | - unset($template_query_params['Event.EVT_ID']); |
|
| 894 | - //get global template as the fallback |
|
| 895 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 896 | - } |
|
| 897 | - //if we don't have an EE_Message_Template_Group then return |
|
| 898 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 899 | - return ''; |
|
| 900 | - } |
|
| 901 | - // generate the URL |
|
| 902 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 903 | - $sending_messenger, |
|
| 904 | - $generating_messenger, |
|
| 905 | - 'purchaser', |
|
| 906 | - $message_type, |
|
| 907 | - $registration, |
|
| 908 | - $msg_template_group->ID(), |
|
| 909 | - $registration->transaction_ID() |
|
| 910 | - ); |
|
| 911 | - |
|
| 912 | - } |
|
| 913 | - return $registration_message_trigger_url; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Use to generate and return a message preview! |
|
| 919 | - * |
|
| 920 | - * @param string $type This should correspond with a valid message type |
|
| 921 | - * @param string $context This should correspond with a valid context for the message type |
|
| 922 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 923 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 924 | - * preview |
|
| 925 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 926 | - * @throws EE_Error |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - * @throws InvalidDataTypeException |
|
| 929 | - * @throws InvalidInterfaceException |
|
| 930 | - * @throws ReflectionException |
|
| 931 | - */ |
|
| 932 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 933 | - { |
|
| 934 | - self::_load_controller(); |
|
| 935 | - $mtg = new EE_Message_To_Generate( |
|
| 936 | - $messenger, |
|
| 937 | - $type, |
|
| 938 | - array(), |
|
| 939 | - $context, |
|
| 940 | - true |
|
| 941 | - ); |
|
| 942 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 943 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 944 | - //loop through all content for the preview and remove any persisted records. |
|
| 945 | - $content = ''; |
|
| 946 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 947 | - $content = $message->content(); |
|
| 948 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 949 | - $message->delete(); |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - return $content; |
|
| 953 | - } else { |
|
| 954 | - return $generated_preview_queue; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 961 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 962 | - * content found in the EE_Message objects in the queue. |
|
| 963 | - * |
|
| 964 | - * @since 4.9.0 |
|
| 965 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 966 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 967 | - * type name is still required to send along the message type to the |
|
| 968 | - * messenger because this is used for determining what specific |
|
| 969 | - * variations might be loaded for the generated message. |
|
| 970 | - * @param EE_Messages_Queue $queue |
|
| 971 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 972 | - * aggregate EE_Message object. |
|
| 973 | - * @return bool success or fail. |
|
| 974 | - * @throws EE_Error |
|
| 975 | - * @throws InvalidArgumentException |
|
| 976 | - * @throws ReflectionException |
|
| 977 | - * @throws InvalidDataTypeException |
|
| 978 | - * @throws InvalidInterfaceException |
|
| 979 | - */ |
|
| 980 | - public static function send_message_with_messenger_only( |
|
| 981 | - $messenger, |
|
| 982 | - $message_type, |
|
| 983 | - EE_Messages_Queue $queue, |
|
| 984 | - $custom_subject = '' |
|
| 985 | - ) { |
|
| 986 | - self::_load_controller(); |
|
| 987 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 988 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 989 | - 'Message_To_Generate_From_Queue', |
|
| 990 | - array( |
|
| 991 | - $messenger, |
|
| 992 | - $message_type, |
|
| 993 | - $queue, |
|
| 994 | - $custom_subject, |
|
| 995 | - ) |
|
| 996 | - ); |
|
| 997 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1003 | - * |
|
| 1004 | - * @since 4.9.0 |
|
| 1005 | - * @param array $message_ids An array of message ids |
|
| 1006 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1007 | - * messages. |
|
| 1008 | - * @throws EE_Error |
|
| 1009 | - * @throws InvalidArgumentException |
|
| 1010 | - * @throws InvalidDataTypeException |
|
| 1011 | - * @throws InvalidInterfaceException |
|
| 1012 | - * @throws ReflectionException |
|
| 1013 | - */ |
|
| 1014 | - public static function generate_now($message_ids) |
|
| 1015 | - { |
|
| 1016 | - self::_load_controller(); |
|
| 1017 | - $messages = EEM_Message::instance()->get_all( |
|
| 1018 | - array( |
|
| 1019 | - 0 => array( |
|
| 1020 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1021 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1022 | - ), |
|
| 1023 | - ) |
|
| 1024 | - ); |
|
| 1025 | - $generated_queue = false; |
|
| 1026 | - if ($messages) { |
|
| 1027 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1031 | - EE_Error::add_error( |
|
| 1032 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1033 | - 'event_espresso'), |
|
| 1034 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1035 | - ); |
|
| 1036 | - } |
|
| 1037 | - return $generated_queue; |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1043 | - * EEM_Message::status_idle |
|
| 1044 | - * |
|
| 1045 | - * @since 4.9.0 |
|
| 1046 | - * @param $message_ids |
|
| 1047 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1048 | - * @throws EE_Error |
|
| 1049 | - * @throws InvalidArgumentException |
|
| 1050 | - * @throws InvalidDataTypeException |
|
| 1051 | - * @throws InvalidInterfaceException |
|
| 1052 | - * @throws ReflectionException |
|
| 1053 | - */ |
|
| 1054 | - public static function send_now($message_ids) |
|
| 1055 | - { |
|
| 1056 | - self::_load_controller(); |
|
| 1057 | - $messages = EEM_Message::instance()->get_all( |
|
| 1058 | - array( |
|
| 1059 | - 0 => array( |
|
| 1060 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1061 | - 'STS_ID' => array( |
|
| 1062 | - 'IN', |
|
| 1063 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1064 | - ), |
|
| 1065 | - ), |
|
| 1066 | - ) |
|
| 1067 | - ); |
|
| 1068 | - $sent_queue = false; |
|
| 1069 | - if ($messages) { |
|
| 1070 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1074 | - EE_Error::add_error( |
|
| 1075 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1076 | - 'event_espresso'), |
|
| 1077 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1078 | - ); |
|
| 1079 | - } else { |
|
| 1080 | - //can count how many sent by using the messages in the queue |
|
| 1081 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1082 | - if ($sent_count > 0) { |
|
| 1083 | - EE_Error::add_success( |
|
| 1084 | - sprintf( |
|
| 1085 | - _n( |
|
| 1086 | - 'There was %d message successfully sent.', |
|
| 1087 | - 'There were %d messages successfully sent.', |
|
| 1088 | - $sent_count, |
|
| 1089 | - 'event_espresso' |
|
| 1090 | - ), |
|
| 1091 | - $sent_count |
|
| 1092 | - ) |
|
| 1093 | - ); |
|
| 1094 | - } else { |
|
| 1095 | - EE_Error::overwrite_errors(); |
|
| 1096 | - EE_Error::add_error( |
|
| 1097 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 215 | + exit; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + return; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * This runs when the msg_url_trigger route has initiated. |
|
| 224 | + * |
|
| 225 | + * @since 4.5.0 |
|
| 226 | + * @param WP $WP |
|
| 227 | + * @throws EE_Error |
|
| 228 | + * @throws InvalidArgumentException |
|
| 229 | + * @throws ReflectionException |
|
| 230 | + * @throws InvalidDataTypeException |
|
| 231 | + * @throws InvalidInterfaceException |
|
| 232 | + */ |
|
| 233 | + public function run($WP) |
|
| 234 | + { |
|
| 235 | + //ensure controller is loaded |
|
| 236 | + self::_load_controller(); |
|
| 237 | + // attempt to process message |
|
| 238 | + try { |
|
| 239 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 240 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 241 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 242 | + } catch (EE_Error $e) { |
|
| 243 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 244 | + 'event_espresso'); |
|
| 245 | + // add specific message for developers if WP_DEBUG in on |
|
| 246 | + $error_msg .= '||' . $e->getMessage(); |
|
| 247 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 254 | + * |
|
| 255 | + * @param WP $WP |
|
| 256 | + */ |
|
| 257 | + public function execute_batch_request($WP) |
|
| 258 | + { |
|
| 259 | + $this->run_cron(); |
|
| 260 | + header('HTTP/1.1 200 OK'); |
|
| 261 | + exit(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 267 | + * request. |
|
| 268 | + */ |
|
| 269 | + public function run_cron() |
|
| 270 | + { |
|
| 271 | + self::_load_controller(); |
|
| 272 | + //get required vars |
|
| 273 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 274 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 275 | + |
|
| 276 | + //now let's verify transient, if not valid exit immediately |
|
| 277 | + if (! get_transient($transient_key)) { |
|
| 278 | + /** |
|
| 279 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 280 | + * request. |
|
| 281 | + */ |
|
| 282 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + //if made it here, lets' delete the transient to keep the db clean |
|
| 286 | + delete_transient($transient_key); |
|
| 287 | + |
|
| 288 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 289 | + |
|
| 290 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 291 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 292 | + self::$_MSG_PROCESSOR->$method(); |
|
| 293 | + } else { |
|
| 294 | + //no matching task |
|
| 295 | + /** |
|
| 296 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 297 | + * request. |
|
| 298 | + */ |
|
| 299 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 300 | + $cron_type))); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * This is used to retrieve the template pack for the given name. |
|
| 310 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 311 | + * the default template pack is returned. |
|
| 312 | + * |
|
| 313 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 314 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 315 | + * in generating the Pack class name). |
|
| 316 | + * @return EE_Messages_Template_Pack |
|
| 317 | + * @throws EE_Error |
|
| 318 | + * @throws InvalidArgumentException |
|
| 319 | + * @throws ReflectionException |
|
| 320 | + * @throws InvalidDataTypeException |
|
| 321 | + * @throws InvalidInterfaceException |
|
| 322 | + */ |
|
| 323 | + public static function get_template_pack($template_pack_name) |
|
| 324 | + { |
|
| 325 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 326 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Retrieves an array of all template packs. |
|
| 332 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 333 | + * |
|
| 334 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 335 | + * @return EE_Messages_Template_Pack[] |
|
| 336 | + * @throws EE_Error |
|
| 337 | + * @throws InvalidArgumentException |
|
| 338 | + * @throws ReflectionException |
|
| 339 | + * @throws InvalidDataTypeException |
|
| 340 | + * @throws InvalidInterfaceException |
|
| 341 | + */ |
|
| 342 | + public static function get_template_packs() |
|
| 343 | + { |
|
| 344 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 345 | + |
|
| 346 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
| 347 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 348 | + $template_pack_collection->rewind(); |
|
| 349 | + $template_packs = array(); |
|
| 350 | + while ($template_pack_collection->valid()) { |
|
| 351 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 352 | + $template_pack_collection->next(); |
|
| 353 | + } |
|
| 354 | + return $template_packs; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 360 | + * |
|
| 361 | + * @since 4.5.0 |
|
| 362 | + * @return void |
|
| 363 | + * @throws EE_Error |
|
| 364 | + */ |
|
| 365 | + public static function set_autoloaders() |
|
| 366 | + { |
|
| 367 | + if (empty(self::$_MSG_PATHS)) { |
|
| 368 | + self::_set_messages_paths(); |
|
| 369 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 370 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 371 | + } |
|
| 372 | + // add aliases |
|
| 373 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 374 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 381 | + * for use by the Messages Autoloaders |
|
| 382 | + * |
|
| 383 | + * @since 4.5.0 |
|
| 384 | + * @return void. |
|
| 385 | + */ |
|
| 386 | + protected static function _set_messages_paths() |
|
| 387 | + { |
|
| 388 | + $dir_ref = array( |
|
| 389 | + 'messages/message_type', |
|
| 390 | + 'messages/messenger', |
|
| 391 | + 'messages/defaults', |
|
| 392 | + 'messages/defaults/email', |
|
| 393 | + 'messages/data_class', |
|
| 394 | + 'messages/validators', |
|
| 395 | + 'messages/validators/email', |
|
| 396 | + 'messages/validators/html', |
|
| 397 | + 'shortcodes', |
|
| 398 | + ); |
|
| 399 | + $paths = array(); |
|
| 400 | + foreach ($dir_ref as $index => $dir) { |
|
| 401 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
| 402 | + } |
|
| 403 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Takes care of loading dependencies |
|
| 409 | + * |
|
| 410 | + * @since 4.5.0 |
|
| 411 | + * @return void |
|
| 412 | + * @throws EE_Error |
|
| 413 | + * @throws InvalidArgumentException |
|
| 414 | + * @throws ReflectionException |
|
| 415 | + * @throws InvalidDataTypeException |
|
| 416 | + * @throws InvalidInterfaceException |
|
| 417 | + */ |
|
| 418 | + protected static function _load_controller() |
|
| 419 | + { |
|
| 420 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 421 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 422 | + self::set_autoloaders(); |
|
| 423 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 424 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 425 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @param EE_Transaction $transaction |
|
| 432 | + * @throws EE_Error |
|
| 433 | + * @throws InvalidArgumentException |
|
| 434 | + * @throws InvalidDataTypeException |
|
| 435 | + * @throws InvalidInterfaceException |
|
| 436 | + * @throws ReflectionException |
|
| 437 | + */ |
|
| 438 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 439 | + { |
|
| 440 | + self::_load_controller(); |
|
| 441 | + $data = array($transaction, null); |
|
| 442 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 448 | + * |
|
| 449 | + * @param EE_Transaction $transaction object |
|
| 450 | + * @param EE_Payment $payment object |
|
| 451 | + * @return void |
|
| 452 | + * @throws EE_Error |
|
| 453 | + * @throws InvalidArgumentException |
|
| 454 | + * @throws ReflectionException |
|
| 455 | + * @throws InvalidDataTypeException |
|
| 456 | + * @throws InvalidInterfaceException |
|
| 457 | + */ |
|
| 458 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 459 | + { |
|
| 460 | + self::_load_controller(); |
|
| 461 | + $data = array($transaction, $payment); |
|
| 462 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 463 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 464 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 465 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 466 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * @param EE_Transaction $transaction |
|
| 472 | + * @throws EE_Error |
|
| 473 | + * @throws InvalidArgumentException |
|
| 474 | + * @throws InvalidDataTypeException |
|
| 475 | + * @throws InvalidInterfaceException |
|
| 476 | + * @throws ReflectionException |
|
| 477 | + */ |
|
| 478 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 479 | + { |
|
| 480 | + self::_load_controller(); |
|
| 481 | + $data = array($transaction, null); |
|
| 482 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Trigger for Registration messages |
|
| 489 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 490 | + * incoming transaction. |
|
| 491 | + * |
|
| 492 | + * @param EE_Registration $registration |
|
| 493 | + * @param array $extra_details |
|
| 494 | + * @return void |
|
| 495 | + * @throws EE_Error |
|
| 496 | + * @throws InvalidArgumentException |
|
| 497 | + * @throws InvalidDataTypeException |
|
| 498 | + * @throws InvalidInterfaceException |
|
| 499 | + * @throws ReflectionException |
|
| 500 | + * @throws EntityNotFoundException |
|
| 501 | + */ |
|
| 502 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 503 | + { |
|
| 504 | + |
|
| 505 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 506 | + //no messages please |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 511 | + $all_registrations = $registration->transaction()->registrations( |
|
| 512 | + array( |
|
| 513 | + array('REG_deleted' => false), |
|
| 514 | + 'order_by' => array( |
|
| 515 | + 'Event.EVT_name' => 'ASC', |
|
| 516 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 517 | + 'Attendee.ATT_fname' => 'ASC' |
|
| 518 | + ) |
|
| 519 | + ) |
|
| 520 | + ); |
|
| 521 | + //cached array of statuses so we only trigger messages once per status. |
|
| 522 | + $statuses_sent = array(); |
|
| 523 | + self::_load_controller(); |
|
| 524 | + $mtgs = array(); |
|
| 525 | + |
|
| 526 | + //loop through registrations and trigger messages once per status. |
|
| 527 | + foreach ($all_registrations as $reg) { |
|
| 528 | + |
|
| 529 | + //already triggered? |
|
| 530 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 531 | + continue; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 535 | + $mtgs = array_merge( |
|
| 536 | + $mtgs, |
|
| 537 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 538 | + $message_type, |
|
| 539 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 540 | + ) |
|
| 541 | + ); |
|
| 542 | + $statuses_sent[] = $reg->status_ID(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if (count($statuses_sent) > 1) { |
|
| 546 | + $mtgs = array_merge( |
|
| 547 | + $mtgs, |
|
| 548 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 549 | + 'registration_summary', |
|
| 550 | + array($registration->transaction(), null) |
|
| 551 | + ) |
|
| 552 | + ); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + //batch queue and initiate request |
|
| 556 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 557 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 563 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 564 | + * |
|
| 565 | + * @param EE_Registration $registration [description] |
|
| 566 | + * @param array $extra_details [description] |
|
| 567 | + * @return bool true = send away, false = nope halt the presses. |
|
| 568 | + */ |
|
| 569 | + protected static function _verify_registration_notification_send( |
|
| 570 | + EE_Registration $registration, |
|
| 571 | + $extra_details = array() |
|
| 572 | + ) { |
|
| 573 | + //self::log( |
|
| 574 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 575 | + // $registration->transaction(), |
|
| 576 | + // array( '$extra_details' => $extra_details ) |
|
| 577 | + //); |
|
| 578 | + // currently only using this to send messages for the primary registrant |
|
| 579 | + if (! $registration->is_primary_registrant()) { |
|
| 580 | + return false; |
|
| 581 | + } |
|
| 582 | + // first we check if we're in admin and not doing front ajax |
|
| 583 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 584 | + //make sure appropriate admin params are set for sending messages |
|
| 585 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 586 | + //no messages sent please. |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + } else { |
|
| 590 | + // frontend request (either regular or via AJAX) |
|
| 591 | + // TXN is NOT finalized ? |
|
| 592 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 593 | + return false; |
|
| 594 | + } |
|
| 595 | + // return visit but nothing changed ??? |
|
| 596 | + if ( |
|
| 597 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 598 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 599 | + ) { |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 603 | + if ( |
|
| 604 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 605 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 606 | + ) { |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + // release the kraken |
|
| 611 | + return true; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 617 | + * status id. |
|
| 618 | + * |
|
| 619 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 620 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 621 | + * @param string $reg_status |
|
| 622 | + * @return array |
|
| 623 | + * @throws EE_Error |
|
| 624 | + * @throws InvalidArgumentException |
|
| 625 | + * @throws ReflectionException |
|
| 626 | + * @throws InvalidDataTypeException |
|
| 627 | + * @throws InvalidInterfaceException |
|
| 628 | + */ |
|
| 629 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 630 | + { |
|
| 631 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 632 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 633 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 634 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Simply returns the payment message type for the given payment status. |
|
| 640 | + * |
|
| 641 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 642 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 643 | + * @param string $payment_status The payment status being matched. |
|
| 644 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 645 | + * @throws EE_Error |
|
| 646 | + * @throws InvalidArgumentException |
|
| 647 | + * @throws ReflectionException |
|
| 648 | + * @throws InvalidDataTypeException |
|
| 649 | + * @throws InvalidInterfaceException |
|
| 650 | + */ |
|
| 651 | + protected static function _get_payment_message_type($payment_status) |
|
| 652 | + { |
|
| 653 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 654 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 655 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 656 | + : false; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 662 | + * |
|
| 663 | + * @access public |
|
| 664 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 665 | + * @return bool success/fail |
|
| 666 | + * @throws EE_Error |
|
| 667 | + * @throws InvalidArgumentException |
|
| 668 | + * @throws InvalidDataTypeException |
|
| 669 | + * @throws InvalidInterfaceException |
|
| 670 | + * @throws ReflectionException |
|
| 671 | + */ |
|
| 672 | + public static function process_resend($req_data) |
|
| 673 | + { |
|
| 674 | + self::_load_controller(); |
|
| 675 | + |
|
| 676 | + //if $msgID in this request then skip to the new resend_message |
|
| 677 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 678 | + return self::resend_message(); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 682 | + $req_data = (array)$req_data; |
|
| 683 | + foreach ($req_data as $request_key => $request_value) { |
|
| 684 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 688 | + return false; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + try { |
|
| 692 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 693 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 694 | + } catch (EE_Error $e) { |
|
| 695 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 696 | + return false; |
|
| 697 | + } |
|
| 698 | + EE_Error::add_success( |
|
| 699 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 700 | + ); |
|
| 701 | + return true; //everything got queued. |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 707 | + * |
|
| 708 | + * @return bool |
|
| 709 | + * @throws EE_Error |
|
| 710 | + * @throws InvalidArgumentException |
|
| 711 | + * @throws InvalidDataTypeException |
|
| 712 | + * @throws InvalidInterfaceException |
|
| 713 | + * @throws ReflectionException |
|
| 714 | + */ |
|
| 715 | + public static function resend_message() |
|
| 716 | + { |
|
| 717 | + self::_load_controller(); |
|
| 718 | + |
|
| 719 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 720 | + if (! $msgID) { |
|
| 721 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 722 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 723 | + return false; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 727 | + |
|
| 728 | + //setup success message. |
|
| 729 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 730 | + EE_Error::add_success(sprintf( |
|
| 731 | + _n( |
|
| 732 | + 'There was %d message queued for resending.', |
|
| 733 | + 'There were %d messages queued for resending.', |
|
| 734 | + $count_ready_for_resend, |
|
| 735 | + 'event_espresso' |
|
| 736 | + ), |
|
| 737 | + $count_ready_for_resend |
|
| 738 | + )); |
|
| 739 | + return true; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * Message triggers for manual payment applied by admin |
|
| 745 | + * |
|
| 746 | + * @param EE_Payment $payment EE_payment object |
|
| 747 | + * @return bool success/fail |
|
| 748 | + * @throws EE_Error |
|
| 749 | + * @throws InvalidArgumentException |
|
| 750 | + * @throws ReflectionException |
|
| 751 | + * @throws InvalidDataTypeException |
|
| 752 | + * @throws InvalidInterfaceException |
|
| 753 | + */ |
|
| 754 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 755 | + { |
|
| 756 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 757 | + //we need to get the transaction object |
|
| 758 | + $transaction = $payment->transaction(); |
|
| 759 | + if ($transaction instanceof EE_Transaction) { |
|
| 760 | + $data = array($transaction, $payment); |
|
| 761 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 762 | + |
|
| 763 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 764 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 765 | + |
|
| 766 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 767 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 768 | + |
|
| 769 | + self::_load_controller(); |
|
| 770 | + |
|
| 771 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 772 | + |
|
| 773 | + //get count of queued for generation |
|
| 774 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 775 | + EEM_Message::status_incomplete, |
|
| 776 | + EEM_Message::status_idle, |
|
| 777 | + )); |
|
| 778 | + |
|
| 779 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 780 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 781 | + return true; |
|
| 782 | + } else { |
|
| 783 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 784 | + /** |
|
| 785 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 786 | + * IMMEDIATE generation. |
|
| 787 | + */ |
|
| 788 | + if ($count_failed > 0) { |
|
| 789 | + EE_Error::add_error(sprintf( |
|
| 790 | + _n( |
|
| 791 | + 'The payment notification generation failed.', |
|
| 792 | + '%d payment notifications failed being sent.', |
|
| 793 | + $count_failed, |
|
| 794 | + 'event_espresso' |
|
| 795 | + ), |
|
| 796 | + $count_failed |
|
| 797 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
| 798 | + |
|
| 799 | + return false; |
|
| 800 | + } else { |
|
| 801 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 802 | + return true; |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + } else { |
|
| 806 | + EE_Error::add_error( |
|
| 807 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 808 | + 'event_espresso' |
|
| 809 | + ); |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 817 | + * |
|
| 818 | + * @since 4.3.0 |
|
| 819 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 820 | + * @param int $grp_id a specific message template group id. |
|
| 821 | + * @return void |
|
| 822 | + * @throws EE_Error |
|
| 823 | + * @throws InvalidArgumentException |
|
| 824 | + * @throws InvalidDataTypeException |
|
| 825 | + * @throws InvalidInterfaceException |
|
| 826 | + * @throws ReflectionException |
|
| 827 | + */ |
|
| 828 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 829 | + { |
|
| 830 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 831 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 832 | + self::_load_controller(); |
|
| 833 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 839 | + * |
|
| 840 | + * @since 4.3.0 |
|
| 841 | + * @param string $registration_message_trigger_url |
|
| 842 | + * @param EE_Registration $registration |
|
| 843 | + * @param string $messenger |
|
| 844 | + * @param string $message_type |
|
| 845 | + * @return string |
|
| 846 | + * @throws EE_Error |
|
| 847 | + * @throws InvalidArgumentException |
|
| 848 | + * @throws InvalidDataTypeException |
|
| 849 | + * @throws InvalidInterfaceException |
|
| 850 | + */ |
|
| 851 | + public static function registration_message_trigger_url( |
|
| 852 | + $registration_message_trigger_url, |
|
| 853 | + EE_Registration $registration, |
|
| 854 | + $messenger = 'html', |
|
| 855 | + $message_type = 'invoice' |
|
| 856 | + ) { |
|
| 857 | + // whitelist $messenger |
|
| 858 | + switch ($messenger) { |
|
| 859 | + case 'pdf' : |
|
| 860 | + $sending_messenger = 'pdf'; |
|
| 861 | + $generating_messenger = 'html'; |
|
| 862 | + break; |
|
| 863 | + case 'html' : |
|
| 864 | + default : |
|
| 865 | + $sending_messenger = 'html'; |
|
| 866 | + $generating_messenger = 'html'; |
|
| 867 | + break; |
|
| 868 | + } |
|
| 869 | + // whitelist $message_type |
|
| 870 | + switch ($message_type) { |
|
| 871 | + case 'receipt' : |
|
| 872 | + $message_type = 'receipt'; |
|
| 873 | + break; |
|
| 874 | + case 'invoice' : |
|
| 875 | + default : |
|
| 876 | + $message_type = 'invoice'; |
|
| 877 | + break; |
|
| 878 | + } |
|
| 879 | + // verify that both the messenger AND the message type are active |
|
| 880 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 881 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 882 | + $template_query_params = array( |
|
| 883 | + 'MTP_is_active' => true, |
|
| 884 | + 'MTP_messenger' => $generating_messenger, |
|
| 885 | + 'MTP_message_type' => $message_type, |
|
| 886 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 887 | + ); |
|
| 888 | + //get the message template group. |
|
| 889 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 890 | + //if we don't have an EE_Message_Template_Group then return |
|
| 891 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 892 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 893 | + unset($template_query_params['Event.EVT_ID']); |
|
| 894 | + //get global template as the fallback |
|
| 895 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 896 | + } |
|
| 897 | + //if we don't have an EE_Message_Template_Group then return |
|
| 898 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 899 | + return ''; |
|
| 900 | + } |
|
| 901 | + // generate the URL |
|
| 902 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 903 | + $sending_messenger, |
|
| 904 | + $generating_messenger, |
|
| 905 | + 'purchaser', |
|
| 906 | + $message_type, |
|
| 907 | + $registration, |
|
| 908 | + $msg_template_group->ID(), |
|
| 909 | + $registration->transaction_ID() |
|
| 910 | + ); |
|
| 911 | + |
|
| 912 | + } |
|
| 913 | + return $registration_message_trigger_url; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Use to generate and return a message preview! |
|
| 919 | + * |
|
| 920 | + * @param string $type This should correspond with a valid message type |
|
| 921 | + * @param string $context This should correspond with a valid context for the message type |
|
| 922 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 923 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 924 | + * preview |
|
| 925 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 926 | + * @throws EE_Error |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + * @throws InvalidDataTypeException |
|
| 929 | + * @throws InvalidInterfaceException |
|
| 930 | + * @throws ReflectionException |
|
| 931 | + */ |
|
| 932 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 933 | + { |
|
| 934 | + self::_load_controller(); |
|
| 935 | + $mtg = new EE_Message_To_Generate( |
|
| 936 | + $messenger, |
|
| 937 | + $type, |
|
| 938 | + array(), |
|
| 939 | + $context, |
|
| 940 | + true |
|
| 941 | + ); |
|
| 942 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 943 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 944 | + //loop through all content for the preview and remove any persisted records. |
|
| 945 | + $content = ''; |
|
| 946 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 947 | + $content = $message->content(); |
|
| 948 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 949 | + $message->delete(); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + return $content; |
|
| 953 | + } else { |
|
| 954 | + return $generated_preview_queue; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 961 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 962 | + * content found in the EE_Message objects in the queue. |
|
| 963 | + * |
|
| 964 | + * @since 4.9.0 |
|
| 965 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 966 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 967 | + * type name is still required to send along the message type to the |
|
| 968 | + * messenger because this is used for determining what specific |
|
| 969 | + * variations might be loaded for the generated message. |
|
| 970 | + * @param EE_Messages_Queue $queue |
|
| 971 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 972 | + * aggregate EE_Message object. |
|
| 973 | + * @return bool success or fail. |
|
| 974 | + * @throws EE_Error |
|
| 975 | + * @throws InvalidArgumentException |
|
| 976 | + * @throws ReflectionException |
|
| 977 | + * @throws InvalidDataTypeException |
|
| 978 | + * @throws InvalidInterfaceException |
|
| 979 | + */ |
|
| 980 | + public static function send_message_with_messenger_only( |
|
| 981 | + $messenger, |
|
| 982 | + $message_type, |
|
| 983 | + EE_Messages_Queue $queue, |
|
| 984 | + $custom_subject = '' |
|
| 985 | + ) { |
|
| 986 | + self::_load_controller(); |
|
| 987 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 988 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 989 | + 'Message_To_Generate_From_Queue', |
|
| 990 | + array( |
|
| 991 | + $messenger, |
|
| 992 | + $message_type, |
|
| 993 | + $queue, |
|
| 994 | + $custom_subject, |
|
| 995 | + ) |
|
| 996 | + ); |
|
| 997 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1003 | + * |
|
| 1004 | + * @since 4.9.0 |
|
| 1005 | + * @param array $message_ids An array of message ids |
|
| 1006 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1007 | + * messages. |
|
| 1008 | + * @throws EE_Error |
|
| 1009 | + * @throws InvalidArgumentException |
|
| 1010 | + * @throws InvalidDataTypeException |
|
| 1011 | + * @throws InvalidInterfaceException |
|
| 1012 | + * @throws ReflectionException |
|
| 1013 | + */ |
|
| 1014 | + public static function generate_now($message_ids) |
|
| 1015 | + { |
|
| 1016 | + self::_load_controller(); |
|
| 1017 | + $messages = EEM_Message::instance()->get_all( |
|
| 1018 | + array( |
|
| 1019 | + 0 => array( |
|
| 1020 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1021 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1022 | + ), |
|
| 1023 | + ) |
|
| 1024 | + ); |
|
| 1025 | + $generated_queue = false; |
|
| 1026 | + if ($messages) { |
|
| 1027 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1031 | + EE_Error::add_error( |
|
| 1032 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1033 | + 'event_espresso'), |
|
| 1034 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1035 | + ); |
|
| 1036 | + } |
|
| 1037 | + return $generated_queue; |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1043 | + * EEM_Message::status_idle |
|
| 1044 | + * |
|
| 1045 | + * @since 4.9.0 |
|
| 1046 | + * @param $message_ids |
|
| 1047 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1048 | + * @throws EE_Error |
|
| 1049 | + * @throws InvalidArgumentException |
|
| 1050 | + * @throws InvalidDataTypeException |
|
| 1051 | + * @throws InvalidInterfaceException |
|
| 1052 | + * @throws ReflectionException |
|
| 1053 | + */ |
|
| 1054 | + public static function send_now($message_ids) |
|
| 1055 | + { |
|
| 1056 | + self::_load_controller(); |
|
| 1057 | + $messages = EEM_Message::instance()->get_all( |
|
| 1058 | + array( |
|
| 1059 | + 0 => array( |
|
| 1060 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1061 | + 'STS_ID' => array( |
|
| 1062 | + 'IN', |
|
| 1063 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1064 | + ), |
|
| 1065 | + ), |
|
| 1066 | + ) |
|
| 1067 | + ); |
|
| 1068 | + $sent_queue = false; |
|
| 1069 | + if ($messages) { |
|
| 1070 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1074 | + EE_Error::add_error( |
|
| 1075 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1076 | + 'event_espresso'), |
|
| 1077 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1078 | + ); |
|
| 1079 | + } else { |
|
| 1080 | + //can count how many sent by using the messages in the queue |
|
| 1081 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1082 | + if ($sent_count > 0) { |
|
| 1083 | + EE_Error::add_success( |
|
| 1084 | + sprintf( |
|
| 1085 | + _n( |
|
| 1086 | + 'There was %d message successfully sent.', |
|
| 1087 | + 'There were %d messages successfully sent.', |
|
| 1088 | + $sent_count, |
|
| 1089 | + 'event_espresso' |
|
| 1090 | + ), |
|
| 1091 | + $sent_count |
|
| 1092 | + ) |
|
| 1093 | + ); |
|
| 1094 | + } else { |
|
| 1095 | + EE_Error::overwrite_errors(); |
|
| 1096 | + EE_Error::add_error( |
|
| 1097 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 1098 | 1098 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 1099 | - 'event_espresso'), |
|
| 1100 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1101 | - ); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - return $sent_queue; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Generate and send immediately from the given $message_ids |
|
| 1110 | - * |
|
| 1111 | - * @param array $message_ids EE_Message entity ids. |
|
| 1112 | - * @throws EE_Error |
|
| 1113 | - * @throws InvalidArgumentException |
|
| 1114 | - * @throws InvalidDataTypeException |
|
| 1115 | - * @throws InvalidInterfaceException |
|
| 1116 | - * @throws ReflectionException |
|
| 1117 | - */ |
|
| 1118 | - public static function generate_and_send_now(array $message_ids) |
|
| 1119 | - { |
|
| 1120 | - $generated_queue = self::generate_now($message_ids); |
|
| 1121 | - //now let's just trigger sending immediately from this queue. |
|
| 1122 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1123 | - ? $generated_queue->execute() |
|
| 1124 | - : 0; |
|
| 1125 | - if ($messages_sent) { |
|
| 1126 | - EE_Error::add_success( |
|
| 1127 | - esc_html( |
|
| 1128 | - sprintf( |
|
| 1129 | - _n( |
|
| 1130 | - 'There was %d message successfully generated and sent.', |
|
| 1131 | - 'There were %d messages successfully generated and sent.', |
|
| 1132 | - $messages_sent, |
|
| 1133 | - 'event_espresso' |
|
| 1134 | - ), |
|
| 1135 | - $messages_sent |
|
| 1136 | - ) |
|
| 1137 | - ) |
|
| 1138 | - ); |
|
| 1139 | - //errors would be added via the generate_now method. |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - |
|
| 1144 | - /** |
|
| 1145 | - * This will queue the incoming message ids for resending. |
|
| 1146 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1147 | - * |
|
| 1148 | - * @since 4.9.0 |
|
| 1149 | - * @param array $message_ids An array of EE_Message IDs |
|
| 1150 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1151 | - * resending. |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - * @throws InvalidArgumentException |
|
| 1154 | - * @throws InvalidDataTypeException |
|
| 1155 | - * @throws InvalidInterfaceException |
|
| 1156 | - * @throws ReflectionException |
|
| 1157 | - */ |
|
| 1158 | - public static function queue_for_resending($message_ids) |
|
| 1159 | - { |
|
| 1160 | - self::_load_controller(); |
|
| 1161 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1162 | - |
|
| 1163 | - //get queue and count |
|
| 1164 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1165 | - |
|
| 1166 | - if ( |
|
| 1167 | - $queue_count > 0 |
|
| 1168 | - ) { |
|
| 1169 | - EE_Error::add_success( |
|
| 1170 | - sprintf( |
|
| 1171 | - _n( |
|
| 1172 | - '%d message successfully queued for resending.', |
|
| 1173 | - '%d messages successfully queued for resending.', |
|
| 1174 | - $queue_count, |
|
| 1175 | - 'event_espresso' |
|
| 1176 | - ), |
|
| 1177 | - $queue_count |
|
| 1178 | - ) |
|
| 1179 | - ); |
|
| 1180 | - /** |
|
| 1181 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1182 | - */ |
|
| 1183 | - } elseif ( |
|
| 1184 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1185 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1186 | - ) { |
|
| 1187 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1188 | - if ($queue_count > 0) { |
|
| 1189 | - EE_Error::add_success( |
|
| 1190 | - sprintf( |
|
| 1191 | - _n( |
|
| 1192 | - '%d message successfully sent.', |
|
| 1193 | - '%d messages successfully sent.', |
|
| 1194 | - $queue_count, |
|
| 1195 | - 'event_espresso' |
|
| 1196 | - ), |
|
| 1197 | - $queue_count |
|
| 1198 | - ) |
|
| 1199 | - ); |
|
| 1200 | - } else { |
|
| 1201 | - EE_Error::add_error( |
|
| 1202 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1203 | - 'event_espresso'), |
|
| 1204 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1205 | - ); |
|
| 1206 | - } |
|
| 1207 | - } else { |
|
| 1208 | - EE_Error::add_error( |
|
| 1209 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1210 | - 'event_espresso'), |
|
| 1211 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1212 | - ); |
|
| 1213 | - } |
|
| 1214 | - return (bool)$queue_count; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * debug |
|
| 1220 | - * |
|
| 1221 | - * @param string $class |
|
| 1222 | - * @param string $func |
|
| 1223 | - * @param string $line |
|
| 1224 | - * @param \EE_Transaction $transaction |
|
| 1225 | - * @param array $info |
|
| 1226 | - * @param bool $display_request |
|
| 1227 | - * @throws EE_Error |
|
| 1228 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1229 | - */ |
|
| 1230 | - protected static function log( |
|
| 1231 | - $class = '', |
|
| 1232 | - $func = '', |
|
| 1233 | - $line = '', |
|
| 1234 | - EE_Transaction $transaction, |
|
| 1235 | - $info = array(), |
|
| 1236 | - $display_request = false |
|
| 1237 | - ) { |
|
| 1238 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1239 | - if ($transaction instanceof EE_Transaction) { |
|
| 1240 | - // don't serialize objects |
|
| 1241 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1242 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1243 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1244 | - if ($transaction->ID()) { |
|
| 1245 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1246 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Resets all the static properties in this class when called. |
|
| 1256 | - */ |
|
| 1257 | - public static function reset() |
|
| 1258 | - { |
|
| 1259 | - self::$_EEMSG = null; |
|
| 1260 | - self::$_message_resource_manager = null; |
|
| 1261 | - self::$_MSG_PROCESSOR = null; |
|
| 1262 | - self::$_MSG_PATHS = null; |
|
| 1263 | - self::$_TMP_PACKS = array(); |
|
| 1264 | - } |
|
| 1099 | + 'event_espresso'), |
|
| 1100 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1101 | + ); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + return $sent_queue; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Generate and send immediately from the given $message_ids |
|
| 1110 | + * |
|
| 1111 | + * @param array $message_ids EE_Message entity ids. |
|
| 1112 | + * @throws EE_Error |
|
| 1113 | + * @throws InvalidArgumentException |
|
| 1114 | + * @throws InvalidDataTypeException |
|
| 1115 | + * @throws InvalidInterfaceException |
|
| 1116 | + * @throws ReflectionException |
|
| 1117 | + */ |
|
| 1118 | + public static function generate_and_send_now(array $message_ids) |
|
| 1119 | + { |
|
| 1120 | + $generated_queue = self::generate_now($message_ids); |
|
| 1121 | + //now let's just trigger sending immediately from this queue. |
|
| 1122 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1123 | + ? $generated_queue->execute() |
|
| 1124 | + : 0; |
|
| 1125 | + if ($messages_sent) { |
|
| 1126 | + EE_Error::add_success( |
|
| 1127 | + esc_html( |
|
| 1128 | + sprintf( |
|
| 1129 | + _n( |
|
| 1130 | + 'There was %d message successfully generated and sent.', |
|
| 1131 | + 'There were %d messages successfully generated and sent.', |
|
| 1132 | + $messages_sent, |
|
| 1133 | + 'event_espresso' |
|
| 1134 | + ), |
|
| 1135 | + $messages_sent |
|
| 1136 | + ) |
|
| 1137 | + ) |
|
| 1138 | + ); |
|
| 1139 | + //errors would be added via the generate_now method. |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + |
|
| 1144 | + /** |
|
| 1145 | + * This will queue the incoming message ids for resending. |
|
| 1146 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1147 | + * |
|
| 1148 | + * @since 4.9.0 |
|
| 1149 | + * @param array $message_ids An array of EE_Message IDs |
|
| 1150 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1151 | + * resending. |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + * @throws InvalidArgumentException |
|
| 1154 | + * @throws InvalidDataTypeException |
|
| 1155 | + * @throws InvalidInterfaceException |
|
| 1156 | + * @throws ReflectionException |
|
| 1157 | + */ |
|
| 1158 | + public static function queue_for_resending($message_ids) |
|
| 1159 | + { |
|
| 1160 | + self::_load_controller(); |
|
| 1161 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1162 | + |
|
| 1163 | + //get queue and count |
|
| 1164 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1165 | + |
|
| 1166 | + if ( |
|
| 1167 | + $queue_count > 0 |
|
| 1168 | + ) { |
|
| 1169 | + EE_Error::add_success( |
|
| 1170 | + sprintf( |
|
| 1171 | + _n( |
|
| 1172 | + '%d message successfully queued for resending.', |
|
| 1173 | + '%d messages successfully queued for resending.', |
|
| 1174 | + $queue_count, |
|
| 1175 | + 'event_espresso' |
|
| 1176 | + ), |
|
| 1177 | + $queue_count |
|
| 1178 | + ) |
|
| 1179 | + ); |
|
| 1180 | + /** |
|
| 1181 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1182 | + */ |
|
| 1183 | + } elseif ( |
|
| 1184 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1185 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1186 | + ) { |
|
| 1187 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1188 | + if ($queue_count > 0) { |
|
| 1189 | + EE_Error::add_success( |
|
| 1190 | + sprintf( |
|
| 1191 | + _n( |
|
| 1192 | + '%d message successfully sent.', |
|
| 1193 | + '%d messages successfully sent.', |
|
| 1194 | + $queue_count, |
|
| 1195 | + 'event_espresso' |
|
| 1196 | + ), |
|
| 1197 | + $queue_count |
|
| 1198 | + ) |
|
| 1199 | + ); |
|
| 1200 | + } else { |
|
| 1201 | + EE_Error::add_error( |
|
| 1202 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1203 | + 'event_espresso'), |
|
| 1204 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1205 | + ); |
|
| 1206 | + } |
|
| 1207 | + } else { |
|
| 1208 | + EE_Error::add_error( |
|
| 1209 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1210 | + 'event_espresso'), |
|
| 1211 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1212 | + ); |
|
| 1213 | + } |
|
| 1214 | + return (bool)$queue_count; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * debug |
|
| 1220 | + * |
|
| 1221 | + * @param string $class |
|
| 1222 | + * @param string $func |
|
| 1223 | + * @param string $line |
|
| 1224 | + * @param \EE_Transaction $transaction |
|
| 1225 | + * @param array $info |
|
| 1226 | + * @param bool $display_request |
|
| 1227 | + * @throws EE_Error |
|
| 1228 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1229 | + */ |
|
| 1230 | + protected static function log( |
|
| 1231 | + $class = '', |
|
| 1232 | + $func = '', |
|
| 1233 | + $line = '', |
|
| 1234 | + EE_Transaction $transaction, |
|
| 1235 | + $info = array(), |
|
| 1236 | + $display_request = false |
|
| 1237 | + ) { |
|
| 1238 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1239 | + if ($transaction instanceof EE_Transaction) { |
|
| 1240 | + // don't serialize objects |
|
| 1241 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1242 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1243 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1244 | + if ($transaction->ID()) { |
|
| 1245 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1246 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Resets all the static properties in this class when called. |
|
| 1256 | + */ |
|
| 1257 | + public static function reset() |
|
| 1258 | + { |
|
| 1259 | + self::$_EEMSG = null; |
|
| 1260 | + self::$_message_resource_manager = null; |
|
| 1261 | + self::$_MSG_PROCESSOR = null; |
|
| 1262 | + self::$_MSG_PATHS = null; |
|
| 1263 | + self::$_TMP_PACKS = array(); |
|
| 1264 | + } |
|
| 1265 | 1265 | |
| 1266 | 1266 | } |
| 1267 | 1267 | // End of file EED_Messages.module.php |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -17,629 +17,629 @@ discard block |
||
| 17 | 17 | class EEH_Debug_Tools |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * instance of the EEH_Autoloader object |
|
| 22 | - * |
|
| 23 | - * @var $_instance |
|
| 24 | - * @access private |
|
| 25 | - */ |
|
| 26 | - private static $_instance; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $_memory_usage_points = array(); |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @singleton method used to instantiate class object |
|
| 37 | - * @access public |
|
| 38 | - * @return EEH_Debug_Tools |
|
| 39 | - */ |
|
| 40 | - public static function instance() |
|
| 41 | - { |
|
| 42 | - // check if class object is instantiated, and instantiated properly |
|
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | - self::$_instance = new self(); |
|
| 45 | - } |
|
| 46 | - return self::$_instance; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * private class constructor |
|
| 53 | - */ |
|
| 54 | - private function __construct() |
|
| 55 | - { |
|
| 56 | - // load Kint PHP debugging library |
|
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | - } |
|
| 65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | - // } |
|
| 68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * show_db_name |
|
| 78 | - * |
|
| 79 | - * @return void |
|
| 80 | - */ |
|
| 81 | - public static function show_db_name() |
|
| 82 | - { |
|
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | - . DB_NAME |
|
| 86 | - . '</p>'; |
|
| 87 | - } |
|
| 88 | - if (EE_DEBUG) { |
|
| 89 | - Benchmark::displayResults(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function espresso_session_footer_dump() |
|
| 101 | - { |
|
| 102 | - if ( |
|
| 103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | - && ! defined('DOING_AJAX') |
|
| 105 | - && class_exists('Kint') |
|
| 106 | - && function_exists('wp_get_current_user') |
|
| 107 | - && current_user_can('update_core') |
|
| 108 | - && class_exists('EE_Registry') |
|
| 109 | - ) { |
|
| 110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | - $this->espresso_list_hooked_functions(); |
|
| 114 | - Benchmark::displayResults(); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * List All Hooked Functions |
|
| 122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | - * |
|
| 125 | - * @param string $tag |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function espresso_list_hooked_functions($tag = '') |
|
| 129 | - { |
|
| 130 | - global $wp_filter; |
|
| 131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | - if ($tag) { |
|
| 133 | - $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | - if (! is_array($hook[$tag])) { |
|
| 135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | - } else { |
|
| 140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | - ksort($hook); |
|
| 142 | - } |
|
| 143 | - foreach ($hook as $tag_name => $priorities) { |
|
| 144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | - ksort($priorities); |
|
| 146 | - foreach ($priorities as $priority => $function) { |
|
| 147 | - echo $priority; |
|
| 148 | - foreach ($function as $name => $properties) { |
|
| 149 | - echo "\t$name<br />"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * registered_filter_callbacks |
|
| 159 | - * |
|
| 160 | - * @param string $hook_name |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | - { |
|
| 165 | - $filters = array(); |
|
| 166 | - global $wp_filter; |
|
| 167 | - if (isset($wp_filter[$hook_name])) { |
|
| 168 | - $filters[$hook_name] = array(); |
|
| 169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | - $filters[$hook_name][$priority] = array(); |
|
| 171 | - foreach ($callbacks as $callback) { |
|
| 172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - return $filters; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * captures plugin activation errors for debugging |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - * @throws EE_Error |
|
| 186 | - */ |
|
| 187 | - public static function ee_plugin_activation_errors() |
|
| 188 | - { |
|
| 189 | - if (WP_DEBUG) { |
|
| 190 | - $activation_errors = ob_get_contents(); |
|
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | - } |
|
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | - if (class_exists('EEH_File')) { |
|
| 196 | - try { |
|
| 197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | - ); |
|
| 200 | - EEH_File::write_to_file( |
|
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | - $activation_errors |
|
| 203 | - ); |
|
| 204 | - } catch (EE_Error $e) { |
|
| 205 | - EE_Error::add_error( |
|
| 206 | - sprintf( |
|
| 207 | - __( |
|
| 208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | - 'event_espresso' |
|
| 210 | - ), |
|
| 211 | - $e->getMessage() |
|
| 212 | - ), |
|
| 213 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - } else { |
|
| 217 | - // old school attempt |
|
| 218 | - file_put_contents( |
|
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | - $activation_errors |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | - * or we want to make sure they use something the right way. |
|
| 234 | - * |
|
| 235 | - * @access public |
|
| 236 | - * @param string $function The function that was called |
|
| 237 | - * @param string $message A message explaining what has been done incorrectly |
|
| 238 | - * @param string $version The version of Event Espresso where the error was added |
|
| 239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | - * but not have any notices appear until a later version. This allows developers |
|
| 242 | - * extra time to update their code before notices appear. |
|
| 243 | - * @param int $error_type |
|
| 244 | - * @uses trigger_error() |
|
| 245 | - */ |
|
| 246 | - public function doing_it_wrong( |
|
| 247 | - $function, |
|
| 248 | - $message, |
|
| 249 | - $version, |
|
| 250 | - $applies_when = '', |
|
| 251 | - $error_type = null |
|
| 252 | - ) { |
|
| 253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | - // because we swapped the parameter order around for the last two params, |
|
| 256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | - if (is_int($applies_when)) { |
|
| 258 | - $error_type = $applies_when; |
|
| 259 | - $applies_when = espresso_version(); |
|
| 260 | - } |
|
| 261 | - // if not displaying notices yet, then just leave |
|
| 262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | - $version = $version === null |
|
| 267 | - ? '' |
|
| 268 | - : sprintf( |
|
| 269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | - $version |
|
| 271 | - ); |
|
| 272 | - $error_message = sprintf( |
|
| 273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | - $function, |
|
| 275 | - '<strong>', |
|
| 276 | - '</strong>', |
|
| 277 | - $message, |
|
| 278 | - $version |
|
| 279 | - ); |
|
| 280 | - // don't trigger error if doing ajax, |
|
| 281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | - 'event_espresso' |
|
| 286 | - ); |
|
| 287 | - $error_message .= '<ul><li>'; |
|
| 288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | - $error_message .= '</ul>'; |
|
| 290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | - //now we set this on the transient so it shows up on the next request. |
|
| 292 | - EE_Error::get_notices(false, true); |
|
| 293 | - } else { |
|
| 294 | - trigger_error($error_message, $error_type); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Logger helpers |
|
| 303 | - */ |
|
| 304 | - /** |
|
| 305 | - * debug |
|
| 306 | - * |
|
| 307 | - * @param string $class |
|
| 308 | - * @param string $func |
|
| 309 | - * @param string $line |
|
| 310 | - * @param array $info |
|
| 311 | - * @param bool $display_request |
|
| 312 | - * @param string $debug_index |
|
| 313 | - * @param string $debug_key |
|
| 314 | - * @throws EE_Error |
|
| 315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | - */ |
|
| 317 | - public static function log( |
|
| 318 | - $class = '', |
|
| 319 | - $func = '', |
|
| 320 | - $line = '', |
|
| 321 | - $info = array(), |
|
| 322 | - $display_request = false, |
|
| 323 | - $debug_index = '', |
|
| 324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | - ) { |
|
| 326 | - if (WP_DEBUG) { |
|
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | - $debug_data = get_option($debug_key, array()); |
|
| 329 | - $default_data = array( |
|
| 330 | - $class => $func . '() : ' . $line, |
|
| 331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | - ); |
|
| 333 | - // don't serialize objects |
|
| 334 | - $info = self::strip_objects($info); |
|
| 335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | - if (! isset($debug_data[$index])) { |
|
| 337 | - $debug_data[$index] = array(); |
|
| 338 | - } |
|
| 339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | - update_option($debug_key, $debug_data); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * strip_objects |
|
| 348 | - * |
|
| 349 | - * @param array $info |
|
| 350 | - * @return array |
|
| 351 | - */ |
|
| 352 | - public static function strip_objects($info = array()) |
|
| 353 | - { |
|
| 354 | - foreach ($info as $key => $value) { |
|
| 355 | - if (is_array($value)) { |
|
| 356 | - $info[$key] = self::strip_objects($value); |
|
| 357 | - } else if (is_object($value)) { |
|
| 358 | - $object_class = get_class($value); |
|
| 359 | - $info[$object_class] = array(); |
|
| 360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | - if (method_exists($value, 'ID')) { |
|
| 362 | - $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | - } |
|
| 364 | - if (method_exists($value, 'status')) { |
|
| 365 | - $info[$object_class]['status'] = $value->status(); |
|
| 366 | - } else if (method_exists($value, 'status_ID')) { |
|
| 367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | - } |
|
| 369 | - unset($info[$key]); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - return (array)$info; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param mixed $var |
|
| 379 | - * @param string $var_name |
|
| 380 | - * @param string $file |
|
| 381 | - * @param int|string $line |
|
| 382 | - * @param int $heading_tag |
|
| 383 | - * @param bool $die |
|
| 384 | - * @param string $margin |
|
| 385 | - */ |
|
| 386 | - public static function printv( |
|
| 387 | - $var, |
|
| 388 | - $var_name = '', |
|
| 389 | - $file = '', |
|
| 390 | - $line = '', |
|
| 391 | - $heading_tag = 5, |
|
| 392 | - $die = false, |
|
| 393 | - $margin = '' |
|
| 394 | - ) { |
|
| 395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | - $is_method = method_exists($var_name, $var); |
|
| 398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 401 | - $result .= $is_method |
|
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | - if ($die) { |
|
| 407 | - die($result); |
|
| 408 | - } |
|
| 409 | - echo $result; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $var_name |
|
| 416 | - * @param string $heading_tag |
|
| 417 | - * @param string $margin |
|
| 418 | - * @return string |
|
| 419 | - */ |
|
| 420 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
| 421 | - { |
|
| 422 | - if (defined('EE_TESTS_DIR')) { |
|
| 423 | - return "\n{$var_name}"; |
|
| 424 | - } |
|
| 425 | - $margin = "25px 0 0 {$margin}"; |
|
| 426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * @param string $heading_tag |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - protected static function headingX($heading_tag = 'h5') |
|
| 436 | - { |
|
| 437 | - if (defined('EE_TESTS_DIR')) { |
|
| 438 | - return ''; |
|
| 439 | - } |
|
| 440 | - return '</' . $heading_tag . '>'; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param string $content |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - protected static function grey_span($content = '') |
|
| 450 | - { |
|
| 451 | - if (defined('EE_TESTS_DIR')) { |
|
| 452 | - return $content; |
|
| 453 | - } |
|
| 454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @param string $file |
|
| 461 | - * @param int $line |
|
| 462 | - * @return string |
|
| 463 | - */ |
|
| 464 | - protected static function file_and_line($file, $line) |
|
| 465 | - { |
|
| 466 | - if ($file === '' || $line === '' || defined('EE_TESTS_DIR')) { |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 470 | - . $file |
|
| 471 | - . '<br />line no: ' |
|
| 472 | - . $line |
|
| 473 | - . '</span>'; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * @param string $content |
|
| 480 | - * @return string |
|
| 481 | - */ |
|
| 482 | - protected static function orange_span($content = '') |
|
| 483 | - { |
|
| 484 | - if (defined('EE_TESTS_DIR')) { |
|
| 485 | - return $content; |
|
| 486 | - } |
|
| 487 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @param mixed $var |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - protected static function pre_span($var) |
|
| 497 | - { |
|
| 498 | - ob_start(); |
|
| 499 | - var_dump($var); |
|
| 500 | - $var = ob_get_clean(); |
|
| 501 | - if (defined('EE_TESTS_DIR')) { |
|
| 502 | - return "\n" . $var; |
|
| 503 | - } |
|
| 504 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * @param mixed $var |
|
| 511 | - * @param string $var_name |
|
| 512 | - * @param string $file |
|
| 513 | - * @param int|string $line |
|
| 514 | - * @param int $heading_tag |
|
| 515 | - * @param bool $die |
|
| 516 | - */ |
|
| 517 | - public static function printr( |
|
| 518 | - $var, |
|
| 519 | - $var_name = '', |
|
| 520 | - $file = '', |
|
| 521 | - $line = '', |
|
| 522 | - $heading_tag = 5, |
|
| 523 | - $die = false |
|
| 524 | - ) { |
|
| 525 | - // return; |
|
| 526 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 527 | - $margin = is_admin() ? ' 180px' : '0'; |
|
| 528 | - //$print_r = false; |
|
| 529 | - if (is_string($var)) { |
|
| 530 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 531 | - return; |
|
| 532 | - } |
|
| 533 | - if (is_object($var)) { |
|
| 534 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
| 535 | - //$print_r = true; |
|
| 536 | - } else if (is_array($var)) { |
|
| 537 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
| 538 | - //$print_r = true; |
|
| 539 | - } else if (is_numeric($var)) { |
|
| 540 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 541 | - } else if ($var === null) { |
|
| 542 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
| 543 | - } |
|
| 544 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 545 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 546 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 547 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 548 | - EEH_Debug_Tools::pre_span($var) |
|
| 549 | - ); |
|
| 550 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 551 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 552 | - if ($die) { |
|
| 553 | - die($result); |
|
| 554 | - } |
|
| 555 | - echo $result; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /******************** deprecated ********************/ |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * @deprecated 4.9.39.rc.034 |
|
| 566 | - */ |
|
| 567 | - public function reset_times() |
|
| 568 | - { |
|
| 569 | - Benchmark::resetTimes(); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * @deprecated 4.9.39.rc.034 |
|
| 576 | - * @param null $timer_name |
|
| 577 | - */ |
|
| 578 | - public function start_timer($timer_name = null) |
|
| 579 | - { |
|
| 580 | - Benchmark::startTimer($timer_name); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * @deprecated 4.9.39.rc.034 |
|
| 587 | - * @param string $timer_name |
|
| 588 | - */ |
|
| 589 | - public function stop_timer($timer_name = '') |
|
| 590 | - { |
|
| 591 | - Benchmark::stopTimer($timer_name); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @deprecated 4.9.39.rc.034 |
|
| 598 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 599 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - public function measure_memory($label, $output_now = false) |
|
| 603 | - { |
|
| 604 | - Benchmark::measureMemory($label, $output_now); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * @deprecated 4.9.39.rc.034 |
|
| 611 | - * @param int $size |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function convert($size) |
|
| 615 | - { |
|
| 616 | - return Benchmark::convert($size); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @deprecated 4.9.39.rc.034 |
|
| 623 | - * @param bool $output_now |
|
| 624 | - * @return string |
|
| 625 | - */ |
|
| 626 | - public function show_times($output_now = true) |
|
| 627 | - { |
|
| 628 | - return Benchmark::displayResults($output_now); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * @deprecated 4.9.39.rc.034 |
|
| 635 | - * @param string $timer_name |
|
| 636 | - * @param float $total_time |
|
| 637 | - * @return string |
|
| 638 | - */ |
|
| 639 | - public function format_time($timer_name, $total_time) |
|
| 640 | - { |
|
| 641 | - return Benchmark::formatTime($timer_name, $total_time); |
|
| 642 | - } |
|
| 20 | + /** |
|
| 21 | + * instance of the EEH_Autoloader object |
|
| 22 | + * |
|
| 23 | + * @var $_instance |
|
| 24 | + * @access private |
|
| 25 | + */ |
|
| 26 | + private static $_instance; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $_memory_usage_points = array(); |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @singleton method used to instantiate class object |
|
| 37 | + * @access public |
|
| 38 | + * @return EEH_Debug_Tools |
|
| 39 | + */ |
|
| 40 | + public static function instance() |
|
| 41 | + { |
|
| 42 | + // check if class object is instantiated, and instantiated properly |
|
| 43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | + self::$_instance = new self(); |
|
| 45 | + } |
|
| 46 | + return self::$_instance; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * private class constructor |
|
| 53 | + */ |
|
| 54 | + private function __construct() |
|
| 55 | + { |
|
| 56 | + // load Kint PHP debugging library |
|
| 57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
| 59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
| 60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
| 61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
| 62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 64 | + } |
|
| 65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
| 66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
| 67 | + // } |
|
| 68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
| 69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
| 71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * show_db_name |
|
| 78 | + * |
|
| 79 | + * @return void |
|
| 80 | + */ |
|
| 81 | + public static function show_db_name() |
|
| 82 | + { |
|
| 83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
| 85 | + . DB_NAME |
|
| 86 | + . '</p>'; |
|
| 87 | + } |
|
| 88 | + if (EE_DEBUG) { |
|
| 89 | + Benchmark::displayResults(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function espresso_session_footer_dump() |
|
| 101 | + { |
|
| 102 | + if ( |
|
| 103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
| 104 | + && ! defined('DOING_AJAX') |
|
| 105 | + && class_exists('Kint') |
|
| 106 | + && function_exists('wp_get_current_user') |
|
| 107 | + && current_user_can('update_core') |
|
| 108 | + && class_exists('EE_Registry') |
|
| 109 | + ) { |
|
| 110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
| 111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
| 112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
| 113 | + $this->espresso_list_hooked_functions(); |
|
| 114 | + Benchmark::displayResults(); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * List All Hooked Functions |
|
| 122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
| 123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
| 124 | + * |
|
| 125 | + * @param string $tag |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function espresso_list_hooked_functions($tag = '') |
|
| 129 | + { |
|
| 130 | + global $wp_filter; |
|
| 131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
| 132 | + if ($tag) { |
|
| 133 | + $hook[$tag] = $wp_filter[$tag]; |
|
| 134 | + if (! is_array($hook[$tag])) { |
|
| 135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 139 | + } else { |
|
| 140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
| 141 | + ksort($hook); |
|
| 142 | + } |
|
| 143 | + foreach ($hook as $tag_name => $priorities) { |
|
| 144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
| 145 | + ksort($priorities); |
|
| 146 | + foreach ($priorities as $priority => $function) { |
|
| 147 | + echo $priority; |
|
| 148 | + foreach ($function as $name => $properties) { |
|
| 149 | + echo "\t$name<br />"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * registered_filter_callbacks |
|
| 159 | + * |
|
| 160 | + * @param string $hook_name |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public static function registered_filter_callbacks($hook_name = '') |
|
| 164 | + { |
|
| 165 | + $filters = array(); |
|
| 166 | + global $wp_filter; |
|
| 167 | + if (isset($wp_filter[$hook_name])) { |
|
| 168 | + $filters[$hook_name] = array(); |
|
| 169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
| 170 | + $filters[$hook_name][$priority] = array(); |
|
| 171 | + foreach ($callbacks as $callback) { |
|
| 172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + return $filters; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * captures plugin activation errors for debugging |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + * @throws EE_Error |
|
| 186 | + */ |
|
| 187 | + public static function ee_plugin_activation_errors() |
|
| 188 | + { |
|
| 189 | + if (WP_DEBUG) { |
|
| 190 | + $activation_errors = ob_get_contents(); |
|
| 191 | + if (! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 193 | + } |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 195 | + if (class_exists('EEH_File')) { |
|
| 196 | + try { |
|
| 197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 199 | + ); |
|
| 200 | + EEH_File::write_to_file( |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 202 | + $activation_errors |
|
| 203 | + ); |
|
| 204 | + } catch (EE_Error $e) { |
|
| 205 | + EE_Error::add_error( |
|
| 206 | + sprintf( |
|
| 207 | + __( |
|
| 208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
| 209 | + 'event_espresso' |
|
| 210 | + ), |
|
| 211 | + $e->getMessage() |
|
| 212 | + ), |
|
| 213 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + } else { |
|
| 217 | + // old school attempt |
|
| 218 | + file_put_contents( |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 220 | + $activation_errors |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
| 232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
| 233 | + * or we want to make sure they use something the right way. |
|
| 234 | + * |
|
| 235 | + * @access public |
|
| 236 | + * @param string $function The function that was called |
|
| 237 | + * @param string $message A message explaining what has been done incorrectly |
|
| 238 | + * @param string $version The version of Event Espresso where the error was added |
|
| 239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
| 240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
| 241 | + * but not have any notices appear until a later version. This allows developers |
|
| 242 | + * extra time to update their code before notices appear. |
|
| 243 | + * @param int $error_type |
|
| 244 | + * @uses trigger_error() |
|
| 245 | + */ |
|
| 246 | + public function doing_it_wrong( |
|
| 247 | + $function, |
|
| 248 | + $message, |
|
| 249 | + $version, |
|
| 250 | + $applies_when = '', |
|
| 251 | + $error_type = null |
|
| 252 | + ) { |
|
| 253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
| 254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
| 255 | + // because we swapped the parameter order around for the last two params, |
|
| 256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
| 257 | + if (is_int($applies_when)) { |
|
| 258 | + $error_type = $applies_when; |
|
| 259 | + $applies_when = espresso_version(); |
|
| 260 | + } |
|
| 261 | + // if not displaying notices yet, then just leave |
|
| 262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
| 266 | + $version = $version === null |
|
| 267 | + ? '' |
|
| 268 | + : sprintf( |
|
| 269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
| 270 | + $version |
|
| 271 | + ); |
|
| 272 | + $error_message = sprintf( |
|
| 273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
| 274 | + $function, |
|
| 275 | + '<strong>', |
|
| 276 | + '</strong>', |
|
| 277 | + $message, |
|
| 278 | + $version |
|
| 279 | + ); |
|
| 280 | + // don't trigger error if doing ajax, |
|
| 281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
| 282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 283 | + $error_message .= ' ' . esc_html__( |
|
| 284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
| 285 | + 'event_espresso' |
|
| 286 | + ); |
|
| 287 | + $error_message .= '<ul><li>'; |
|
| 288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
| 289 | + $error_message .= '</ul>'; |
|
| 290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
| 291 | + //now we set this on the transient so it shows up on the next request. |
|
| 292 | + EE_Error::get_notices(false, true); |
|
| 293 | + } else { |
|
| 294 | + trigger_error($error_message, $error_type); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Logger helpers |
|
| 303 | + */ |
|
| 304 | + /** |
|
| 305 | + * debug |
|
| 306 | + * |
|
| 307 | + * @param string $class |
|
| 308 | + * @param string $func |
|
| 309 | + * @param string $line |
|
| 310 | + * @param array $info |
|
| 311 | + * @param bool $display_request |
|
| 312 | + * @param string $debug_index |
|
| 313 | + * @param string $debug_key |
|
| 314 | + * @throws EE_Error |
|
| 315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 316 | + */ |
|
| 317 | + public static function log( |
|
| 318 | + $class = '', |
|
| 319 | + $func = '', |
|
| 320 | + $line = '', |
|
| 321 | + $info = array(), |
|
| 322 | + $display_request = false, |
|
| 323 | + $debug_index = '', |
|
| 324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
| 325 | + ) { |
|
| 326 | + if (WP_DEBUG) { |
|
| 327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 328 | + $debug_data = get_option($debug_key, array()); |
|
| 329 | + $default_data = array( |
|
| 330 | + $class => $func . '() : ' . $line, |
|
| 331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
| 332 | + ); |
|
| 333 | + // don't serialize objects |
|
| 334 | + $info = self::strip_objects($info); |
|
| 335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
| 336 | + if (! isset($debug_data[$index])) { |
|
| 337 | + $debug_data[$index] = array(); |
|
| 338 | + } |
|
| 339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
| 340 | + update_option($debug_key, $debug_data); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * strip_objects |
|
| 348 | + * |
|
| 349 | + * @param array $info |
|
| 350 | + * @return array |
|
| 351 | + */ |
|
| 352 | + public static function strip_objects($info = array()) |
|
| 353 | + { |
|
| 354 | + foreach ($info as $key => $value) { |
|
| 355 | + if (is_array($value)) { |
|
| 356 | + $info[$key] = self::strip_objects($value); |
|
| 357 | + } else if (is_object($value)) { |
|
| 358 | + $object_class = get_class($value); |
|
| 359 | + $info[$object_class] = array(); |
|
| 360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
| 361 | + if (method_exists($value, 'ID')) { |
|
| 362 | + $info[$object_class]['ID'] = $value->ID(); |
|
| 363 | + } |
|
| 364 | + if (method_exists($value, 'status')) { |
|
| 365 | + $info[$object_class]['status'] = $value->status(); |
|
| 366 | + } else if (method_exists($value, 'status_ID')) { |
|
| 367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
| 368 | + } |
|
| 369 | + unset($info[$key]); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + return (array)$info; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param mixed $var |
|
| 379 | + * @param string $var_name |
|
| 380 | + * @param string $file |
|
| 381 | + * @param int|string $line |
|
| 382 | + * @param int $heading_tag |
|
| 383 | + * @param bool $die |
|
| 384 | + * @param string $margin |
|
| 385 | + */ |
|
| 386 | + public static function printv( |
|
| 387 | + $var, |
|
| 388 | + $var_name = '', |
|
| 389 | + $file = '', |
|
| 390 | + $line = '', |
|
| 391 | + $heading_tag = 5, |
|
| 392 | + $die = false, |
|
| 393 | + $margin = '' |
|
| 394 | + ) { |
|
| 395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
| 396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
| 397 | + $is_method = method_exists($var_name, $var); |
|
| 398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
| 399 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 401 | + $result .= $is_method |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 406 | + if ($die) { |
|
| 407 | + die($result); |
|
| 408 | + } |
|
| 409 | + echo $result; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $var_name |
|
| 416 | + * @param string $heading_tag |
|
| 417 | + * @param string $margin |
|
| 418 | + * @return string |
|
| 419 | + */ |
|
| 420 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
| 421 | + { |
|
| 422 | + if (defined('EE_TESTS_DIR')) { |
|
| 423 | + return "\n{$var_name}"; |
|
| 424 | + } |
|
| 425 | + $margin = "25px 0 0 {$margin}"; |
|
| 426 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * @param string $heading_tag |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + protected static function headingX($heading_tag = 'h5') |
|
| 436 | + { |
|
| 437 | + if (defined('EE_TESTS_DIR')) { |
|
| 438 | + return ''; |
|
| 439 | + } |
|
| 440 | + return '</' . $heading_tag . '>'; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param string $content |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + protected static function grey_span($content = '') |
|
| 450 | + { |
|
| 451 | + if (defined('EE_TESTS_DIR')) { |
|
| 452 | + return $content; |
|
| 453 | + } |
|
| 454 | + return '<span style="color:#999">' . $content . '</span>'; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @param string $file |
|
| 461 | + * @param int $line |
|
| 462 | + * @return string |
|
| 463 | + */ |
|
| 464 | + protected static function file_and_line($file, $line) |
|
| 465 | + { |
|
| 466 | + if ($file === '' || $line === '' || defined('EE_TESTS_DIR')) { |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
| 470 | + . $file |
|
| 471 | + . '<br />line no: ' |
|
| 472 | + . $line |
|
| 473 | + . '</span>'; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * @param string $content |
|
| 480 | + * @return string |
|
| 481 | + */ |
|
| 482 | + protected static function orange_span($content = '') |
|
| 483 | + { |
|
| 484 | + if (defined('EE_TESTS_DIR')) { |
|
| 485 | + return $content; |
|
| 486 | + } |
|
| 487 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @param mixed $var |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + protected static function pre_span($var) |
|
| 497 | + { |
|
| 498 | + ob_start(); |
|
| 499 | + var_dump($var); |
|
| 500 | + $var = ob_get_clean(); |
|
| 501 | + if (defined('EE_TESTS_DIR')) { |
|
| 502 | + return "\n" . $var; |
|
| 503 | + } |
|
| 504 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * @param mixed $var |
|
| 511 | + * @param string $var_name |
|
| 512 | + * @param string $file |
|
| 513 | + * @param int|string $line |
|
| 514 | + * @param int $heading_tag |
|
| 515 | + * @param bool $die |
|
| 516 | + */ |
|
| 517 | + public static function printr( |
|
| 518 | + $var, |
|
| 519 | + $var_name = '', |
|
| 520 | + $file = '', |
|
| 521 | + $line = '', |
|
| 522 | + $heading_tag = 5, |
|
| 523 | + $die = false |
|
| 524 | + ) { |
|
| 525 | + // return; |
|
| 526 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
| 527 | + $margin = is_admin() ? ' 180px' : '0'; |
|
| 528 | + //$print_r = false; |
|
| 529 | + if (is_string($var)) { |
|
| 530 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
| 531 | + return; |
|
| 532 | + } |
|
| 533 | + if (is_object($var)) { |
|
| 534 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
| 535 | + //$print_r = true; |
|
| 536 | + } else if (is_array($var)) { |
|
| 537 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
| 538 | + //$print_r = true; |
|
| 539 | + } else if (is_numeric($var)) { |
|
| 540 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
| 541 | + } else if ($var === null) { |
|
| 542 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
| 543 | + } |
|
| 544 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
| 545 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
| 546 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
| 547 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 548 | + EEH_Debug_Tools::pre_span($var) |
|
| 549 | + ); |
|
| 550 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
| 551 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
| 552 | + if ($die) { |
|
| 553 | + die($result); |
|
| 554 | + } |
|
| 555 | + echo $result; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /******************** deprecated ********************/ |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * @deprecated 4.9.39.rc.034 |
|
| 566 | + */ |
|
| 567 | + public function reset_times() |
|
| 568 | + { |
|
| 569 | + Benchmark::resetTimes(); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * @deprecated 4.9.39.rc.034 |
|
| 576 | + * @param null $timer_name |
|
| 577 | + */ |
|
| 578 | + public function start_timer($timer_name = null) |
|
| 579 | + { |
|
| 580 | + Benchmark::startTimer($timer_name); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * @deprecated 4.9.39.rc.034 |
|
| 587 | + * @param string $timer_name |
|
| 588 | + */ |
|
| 589 | + public function stop_timer($timer_name = '') |
|
| 590 | + { |
|
| 591 | + Benchmark::stopTimer($timer_name); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @deprecated 4.9.39.rc.034 |
|
| 598 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 599 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + public function measure_memory($label, $output_now = false) |
|
| 603 | + { |
|
| 604 | + Benchmark::measureMemory($label, $output_now); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * @deprecated 4.9.39.rc.034 |
|
| 611 | + * @param int $size |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function convert($size) |
|
| 615 | + { |
|
| 616 | + return Benchmark::convert($size); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @deprecated 4.9.39.rc.034 |
|
| 623 | + * @param bool $output_now |
|
| 624 | + * @return string |
|
| 625 | + */ |
|
| 626 | + public function show_times($output_now = true) |
|
| 627 | + { |
|
| 628 | + return Benchmark::displayResults($output_now); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * @deprecated 4.9.39.rc.034 |
|
| 635 | + * @param string $timer_name |
|
| 636 | + * @param float $total_time |
|
| 637 | + * @return string |
|
| 638 | + */ |
|
| 639 | + public function format_time($timer_name, $total_time) |
|
| 640 | + { |
|
| 641 | + return Benchmark::formatTime($timer_name, $total_time); |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | 644 | |
| 645 | 645 | |
@@ -652,31 +652,31 @@ discard block |
||
| 652 | 652 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 653 | 653 | */ |
| 654 | 654 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
| 655 | - function dump_wp_query() |
|
| 656 | - { |
|
| 657 | - global $wp_query; |
|
| 658 | - d($wp_query); |
|
| 659 | - } |
|
| 655 | + function dump_wp_query() |
|
| 656 | + { |
|
| 657 | + global $wp_query; |
|
| 658 | + d($wp_query); |
|
| 659 | + } |
|
| 660 | 660 | } |
| 661 | 661 | /** |
| 662 | 662 | * borrowed from Kint Debugger |
| 663 | 663 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 664 | 664 | */ |
| 665 | 665 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
| 666 | - function dump_wp() |
|
| 667 | - { |
|
| 668 | - global $wp; |
|
| 669 | - d($wp); |
|
| 670 | - } |
|
| 666 | + function dump_wp() |
|
| 667 | + { |
|
| 668 | + global $wp; |
|
| 669 | + d($wp); |
|
| 670 | + } |
|
| 671 | 671 | } |
| 672 | 672 | /** |
| 673 | 673 | * borrowed from Kint Debugger |
| 674 | 674 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
| 675 | 675 | */ |
| 676 | 676 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
| 677 | - function dump_post() |
|
| 678 | - { |
|
| 679 | - global $post; |
|
| 680 | - d($post); |
|
| 681 | - } |
|
| 677 | + function dump_post() |
|
| 678 | + { |
|
| 679 | + global $post; |
|
| 680 | + d($post); |
|
| 681 | + } |
|
| 682 | 682 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
| 2 | 2 | |
| 3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | } |
| 6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public static function instance() |
| 41 | 41 | { |
| 42 | 42 | // check if class object is instantiated, and instantiated properly |
| 43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
| 44 | 44 | self::$_instance = new self(); |
| 45 | 45 | } |
| 46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | private function __construct() |
| 55 | 55 | { |
| 56 | 56 | // load Kint PHP debugging library |
| 57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
| 57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
| 58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
| 59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
| 60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
| 61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
| 62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
| 63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
| 63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
| 64 | 64 | } |
| 65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
| 66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public static function show_db_name() |
| 82 | 82 | { |
| 83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
| 84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
| 85 | 85 | . DB_NAME |
| 86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
| 132 | 132 | if ($tag) { |
| 133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
| 134 | - if (! is_array($hook[$tag])) { |
|
| 134 | + if ( ! is_array($hook[$tag])) { |
|
| 135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
| 138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
| 139 | 139 | } else { |
| 140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
| 141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | if (WP_DEBUG) { |
| 190 | 190 | $activation_errors = ob_get_contents(); |
| 191 | - if (! empty($activation_errors)) { |
|
| 192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
| 191 | + if ( ! empty($activation_errors)) { |
|
| 192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
| 193 | 193 | } |
| 194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
| 194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
| 195 | 195 | if (class_exists('EEH_File')) { |
| 196 | 196 | try { |
| 197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
| 198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
| 198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
| 199 | 199 | ); |
| 200 | 200 | EEH_File::write_to_file( |
| 201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 202 | 202 | $activation_errors |
| 203 | 203 | ); |
| 204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | } else { |
| 217 | 217 | // old school attempt |
| 218 | 218 | file_put_contents( |
| 219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
| 219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
| 220 | 220 | $activation_errors |
| 221 | 221 | ); |
| 222 | 222 | } |
| 223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
| 223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
| 224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | // don't trigger error if doing ajax, |
| 281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
| 282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 283 | - $error_message .= ' ' . esc_html__( |
|
| 283 | + $error_message .= ' '.esc_html__( |
|
| 284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
| 285 | 285 | 'event_espresso' |
| 286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
| 324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
| 325 | 325 | ) { |
| 326 | 326 | if (WP_DEBUG) { |
| 327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
| 327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
| 328 | 328 | $debug_data = get_option($debug_key, array()); |
| 329 | 329 | $default_data = array( |
| 330 | - $class => $func . '() : ' . $line, |
|
| 330 | + $class => $func.'() : '.$line, |
|
| 331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
| 332 | 332 | ); |
| 333 | 333 | // don't serialize objects |
| 334 | 334 | $info = self::strip_objects($info); |
| 335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
| 336 | - if (! isset($debug_data[$index])) { |
|
| 336 | + if ( ! isset($debug_data[$index])) { |
|
| 337 | 337 | $debug_data[$index] = array(); |
| 338 | 338 | } |
| 339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | unset($info[$key]); |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | - return (array)$info; |
|
| 372 | + return (array) $info; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
| 401 | 401 | $result .= $is_method |
| 402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
| 403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
| 402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
| 403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
| 404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
| 405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
| 406 | 406 | if ($die) { |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | return "\n{$var_name}"; |
| 424 | 424 | } |
| 425 | 425 | $margin = "25px 0 0 {$margin}"; |
| 426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
| 426 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | if (defined('EE_TESTS_DIR')) { |
| 438 | 438 | return ''; |
| 439 | 439 | } |
| 440 | - return '</' . $heading_tag . '>'; |
|
| 440 | + return '</'.$heading_tag.'>'; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | if (defined('EE_TESTS_DIR')) { |
| 452 | 452 | return $content; |
| 453 | 453 | } |
| 454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
| 454 | + return '<span style="color:#999">'.$content.'</span>'; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | if (defined('EE_TESTS_DIR')) { |
| 485 | 485 | return $content; |
| 486 | 486 | } |
| 487 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
| 487 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -499,9 +499,9 @@ discard block |
||
| 499 | 499 | var_dump($var); |
| 500 | 500 | $var = ob_get_clean(); |
| 501 | 501 | if (defined('EE_TESTS_DIR')) { |
| 502 | - return "\n" . $var; |
|
| 502 | + return "\n".$var; |
|
| 503 | 503 | } |
| 504 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
| 504 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
| 545 | 545 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
| 546 | 546 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
| 547 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
| 547 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
| 548 | 548 | EEH_Debug_Tools::pre_span($var) |
| 549 | 549 | ); |
| 550 | 550 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |