@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | /** |
| 328 | 328 | * Get Timezone Transitions |
| 329 | 329 | * @param \DateTimeZone $date_time_zone |
| 330 | - * @param null $time |
|
| 330 | + * @param integer|null $time |
|
| 331 | 331 | * @param bool $first_only |
| 332 | 332 | * @return array|mixed |
| 333 | 333 | */ |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | /** |
| 344 | 344 | * Get Timezone Offset for given timezone object. |
| 345 | 345 | * @param \DateTimeZone $date_time_zone |
| 346 | - * @param null $time |
|
| 346 | + * @param integer|null $time |
|
| 347 | 347 | * @return mixed |
| 348 | 348 | * @throws \DomainException |
| 349 | 349 | */ |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | * this method will add that "1" into your date regardless of the format. |
| 1076 | 1076 | * |
| 1077 | 1077 | * @param string $month |
| 1078 | - * @return string |
|
| 1078 | + * @return integer |
|
| 1079 | 1079 | */ |
| 1080 | 1080 | public static function first_of_month_timestamp($month = '') |
| 1081 | 1081 | { |
@@ -1227,7 +1227,7 @@ discard block |
||
| 1227 | 1227 | /** |
| 1228 | 1228 | * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
| 1229 | 1229 | * |
| 1230 | - * @param int|WP_User $user_id |
|
| 1230 | + * @param integer $user_id |
|
| 1231 | 1231 | * @return string |
| 1232 | 1232 | */ |
| 1233 | 1233 | public static function get_user_locale($user_id = 0) |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -26,364 +26,364 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * return the timezone set for the WP install |
|
| 31 | - * |
|
| 32 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | - */ |
|
| 34 | - public static function get_timezone() |
|
| 35 | - { |
|
| 36 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * get_valid_timezone_string |
|
| 42 | - * ensures that a valid timezone string is returned |
|
| 43 | - * |
|
| 44 | - * @access protected |
|
| 45 | - * @param string $timezone_string |
|
| 46 | - * @return string |
|
| 47 | - * @throws \EE_Error |
|
| 48 | - */ |
|
| 49 | - public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | - { |
|
| 51 | - // if passed a value, then use that, else get WP option |
|
| 52 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | - // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | - EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | - return $timezone_string; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | - * |
|
| 63 | - * @static |
|
| 64 | - * @access public |
|
| 65 | - * @param string $timezone_string Timezone string to check |
|
| 66 | - * @param bool $throw_error |
|
| 67 | - * @return bool |
|
| 68 | - * @throws \EE_Error |
|
| 69 | - */ |
|
| 70 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | - { |
|
| 72 | - // 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 |
|
| 73 | - try { |
|
| 74 | - new DateTimeZone($timezone_string); |
|
| 75 | - } catch (Exception $e) { |
|
| 76 | - // sometimes we take exception to exceptions |
|
| 77 | - if (! $throw_error) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - throw new EE_Error( |
|
| 81 | - sprintf( |
|
| 82 | - __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | - 'event_espresso'), |
|
| 84 | - $timezone_string, |
|
| 85 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | - '</a>' |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * _create_timezone_object_from_timezone_name |
|
| 96 | - * |
|
| 97 | - * @access protected |
|
| 98 | - * @param string $gmt_offset |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | - { |
|
| 103 | - $timezone_string = 'UTC'; |
|
| 104 | - //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 105 | - //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 106 | - //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 107 | - if ($gmt_offset === '') { |
|
| 108 | - //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 109 | - if (get_option('timezone_string')) { |
|
| 110 | - return get_option('timezone_string'); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset'); |
|
| 114 | - $gmt_offset = (float) $gmt_offset; |
|
| 115 | - |
|
| 116 | - //if $gmt_offset is 0, then just return UTC |
|
| 117 | - if ($gmt_offset === (float) 0) { |
|
| 118 | - return $timezone_string; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - if ($gmt_offset !== '') { |
|
| 123 | - // convert GMT offset to seconds |
|
| 124 | - $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 125 | - // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 126 | - $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 127 | - //only use this timezone_string IF it's current offset matches the given offset |
|
| 128 | - try { |
|
| 129 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 130 | - if ($offset !== $gmt_offset) { |
|
| 131 | - $timezone_string = false; |
|
| 132 | - } |
|
| 133 | - } catch (Exception $e) { |
|
| 134 | - $timezone_string = false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 138 | - $timezone_string = $timezone_string !== false |
|
| 139 | - ? $timezone_string |
|
| 140 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 141 | - return $timezone_string; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Gets the site's GMT offset based on either the timezone string |
|
| 146 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 147 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 148 | - * |
|
| 149 | - * @return int seconds offset |
|
| 150 | - */ |
|
| 151 | - public static function get_site_timezone_gmt_offset() |
|
| 152 | - { |
|
| 153 | - $timezone_string = get_option('timezone_string'); |
|
| 154 | - if ($timezone_string) { |
|
| 155 | - try { |
|
| 156 | - $timezone = new DateTimeZone($timezone_string); |
|
| 157 | - return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 158 | - } catch (Exception $e) { |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - $offset = get_option('gmt_offset'); |
|
| 162 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its |
|
| 168 | - * timezone tables. |
|
| 169 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 170 | - * |
|
| 171 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @param int $gmt_offset |
|
| 175 | - * @return int |
|
| 176 | - */ |
|
| 177 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 178 | - { |
|
| 179 | - //make sure $gmt_offset is int |
|
| 180 | - $gmt_offset = (int)$gmt_offset; |
|
| 181 | - switch ($gmt_offset) { |
|
| 182 | - //-12 |
|
| 183 | - case -43200: |
|
| 184 | - $gmt_offset = -39600; |
|
| 185 | - break; |
|
| 186 | - //-11.5 |
|
| 187 | - case -41400: |
|
| 188 | - $gmt_offset = -39600; |
|
| 189 | - break; |
|
| 190 | - //-10.5 |
|
| 191 | - case -37800: |
|
| 192 | - $gmt_offset = -39600; |
|
| 193 | - break; |
|
| 194 | - //-8.5 |
|
| 195 | - case -30600: |
|
| 196 | - $gmt_offset = -28800; |
|
| 197 | - break; |
|
| 198 | - //-7.5 |
|
| 199 | - case -27000: |
|
| 200 | - $gmt_offset = -25200; |
|
| 201 | - break; |
|
| 202 | - //-6.5 |
|
| 203 | - case -23400: |
|
| 204 | - $gmt_offset = -21600; |
|
| 205 | - break; |
|
| 206 | - //-5.5 |
|
| 207 | - case -19800: |
|
| 208 | - $gmt_offset = -18000; |
|
| 209 | - break; |
|
| 210 | - //-4.5 |
|
| 211 | - case -16200: |
|
| 212 | - $gmt_offset = -14400; |
|
| 213 | - break; |
|
| 214 | - //-3.5 |
|
| 215 | - case -12600: |
|
| 216 | - $gmt_offset = -10800; |
|
| 217 | - break; |
|
| 218 | - //-2.5 |
|
| 219 | - case -9000: |
|
| 220 | - $gmt_offset = -7200; |
|
| 221 | - break; |
|
| 222 | - //-1.5 |
|
| 223 | - case -5400: |
|
| 224 | - $gmt_offset = -3600; |
|
| 225 | - break; |
|
| 226 | - //-0.5 |
|
| 227 | - case -1800: |
|
| 228 | - $gmt_offset = 0; |
|
| 229 | - break; |
|
| 230 | - //.5 |
|
| 231 | - case 1800: |
|
| 232 | - $gmt_offset = 3600; |
|
| 233 | - break; |
|
| 234 | - //1.5 |
|
| 235 | - case 5400: |
|
| 236 | - $gmt_offset = 7200; |
|
| 237 | - break; |
|
| 238 | - //2.5 |
|
| 239 | - case 9000: |
|
| 240 | - $gmt_offset = 10800; |
|
| 241 | - break; |
|
| 242 | - //3.5 |
|
| 243 | - case 12600: |
|
| 244 | - $gmt_offset = 14400; |
|
| 245 | - break; |
|
| 246 | - |
|
| 247 | - //7.5 |
|
| 248 | - case 27000: |
|
| 249 | - $gmt_offset = 28800; |
|
| 250 | - break; |
|
| 251 | - //8.5 |
|
| 252 | - case 30600: |
|
| 253 | - $gmt_offset = 31500; |
|
| 254 | - break; |
|
| 255 | - //10.5 |
|
| 256 | - case 37800: |
|
| 257 | - $gmt_offset = 39600; |
|
| 258 | - break; |
|
| 259 | - //11.5 |
|
| 260 | - case 41400: |
|
| 261 | - $gmt_offset = 43200; |
|
| 262 | - break; |
|
| 263 | - //12.75 |
|
| 264 | - case 45900: |
|
| 265 | - $gmt_offset = 46800; |
|
| 266 | - break; |
|
| 267 | - //13.75 |
|
| 268 | - case 49500: |
|
| 269 | - $gmt_offset = 50400; |
|
| 270 | - break; |
|
| 271 | - } |
|
| 272 | - return $gmt_offset; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * get_timezone_string_from_abbreviations_list |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @param int $gmt_offset |
|
| 281 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 282 | - * @return string |
|
| 283 | - * @throws \EE_Error |
|
| 284 | - */ |
|
| 285 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 286 | - { |
|
| 287 | - $abbreviations = timezone_abbreviations_list(); |
|
| 288 | - foreach ($abbreviations as $abbreviation) { |
|
| 289 | - foreach ($abbreviation as $city) { |
|
| 290 | - if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 291 | - try { |
|
| 292 | - $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id'])); |
|
| 293 | - if ($offset !== $gmt_offset) { |
|
| 294 | - continue; |
|
| 295 | - } else { |
|
| 296 | - return $city['timezone_id']; |
|
| 297 | - } |
|
| 298 | - } catch (Exception $e) { |
|
| 299 | - continue; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 305 | - if ($coerce == true) { |
|
| 306 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 307 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 308 | - false |
|
| 309 | - ); |
|
| 310 | - if ($timezone_string) { |
|
| 311 | - return $timezone_string; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - throw new EE_Error( |
|
| 315 | - sprintf( |
|
| 316 | - __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 317 | - 'event_espresso'), |
|
| 318 | - $gmt_offset, |
|
| 319 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 320 | - '</a>' |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Get Timezone Transitions |
|
| 329 | - * @param \DateTimeZone $date_time_zone |
|
| 330 | - * @param null $time |
|
| 331 | - * @param bool $first_only |
|
| 332 | - * @return array|mixed |
|
| 333 | - */ |
|
| 334 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 335 | - { |
|
| 336 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 337 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 338 | - $transitions = $date_time_zone->getTransitions($time); |
|
| 339 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get Timezone Offset for given timezone object. |
|
| 345 | - * @param \DateTimeZone $date_time_zone |
|
| 346 | - * @param null $time |
|
| 347 | - * @return mixed |
|
| 348 | - * @throws \DomainException |
|
| 349 | - */ |
|
| 350 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 351 | - { |
|
| 352 | - $transitions = self::get_timezone_transitions($date_time_zone, $time); |
|
| 353 | - if (! isset($transitions['offset'])) { |
|
| 354 | - throw new DomainException(); |
|
| 355 | - } |
|
| 356 | - return $transitions['offset']; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @access public |
|
| 362 | - * @param string $timezone_string |
|
| 363 | - */ |
|
| 364 | - public static function timezone_select_input($timezone_string = '') |
|
| 365 | - { |
|
| 366 | - // get WP date time format |
|
| 367 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 368 | - // if passed a value, then use that, else get WP option |
|
| 369 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 370 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 371 | - $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 372 | - $gmt_offset = get_option('gmt_offset'); |
|
| 373 | - |
|
| 374 | - $check_zone_info = true; |
|
| 375 | - if (empty($timezone_string)) { |
|
| 376 | - // Create a UTC+- zone if no timezone string exists |
|
| 377 | - $check_zone_info = false; |
|
| 378 | - if ($gmt_offset > 0) { |
|
| 379 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 380 | - } elseif ($gmt_offset < 0) { |
|
| 381 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 382 | - } else { |
|
| 383 | - $timezone_string = 'UTC'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - ?> |
|
| 29 | + /** |
|
| 30 | + * return the timezone set for the WP install |
|
| 31 | + * |
|
| 32 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | + */ |
|
| 34 | + public static function get_timezone() |
|
| 35 | + { |
|
| 36 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * get_valid_timezone_string |
|
| 42 | + * ensures that a valid timezone string is returned |
|
| 43 | + * |
|
| 44 | + * @access protected |
|
| 45 | + * @param string $timezone_string |
|
| 46 | + * @return string |
|
| 47 | + * @throws \EE_Error |
|
| 48 | + */ |
|
| 49 | + public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | + { |
|
| 51 | + // if passed a value, then use that, else get WP option |
|
| 52 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | + // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | + return $timezone_string; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | + * |
|
| 63 | + * @static |
|
| 64 | + * @access public |
|
| 65 | + * @param string $timezone_string Timezone string to check |
|
| 66 | + * @param bool $throw_error |
|
| 67 | + * @return bool |
|
| 68 | + * @throws \EE_Error |
|
| 69 | + */ |
|
| 70 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | + { |
|
| 72 | + // 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 |
|
| 73 | + try { |
|
| 74 | + new DateTimeZone($timezone_string); |
|
| 75 | + } catch (Exception $e) { |
|
| 76 | + // sometimes we take exception to exceptions |
|
| 77 | + if (! $throw_error) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + throw new EE_Error( |
|
| 81 | + sprintf( |
|
| 82 | + __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | + 'event_espresso'), |
|
| 84 | + $timezone_string, |
|
| 85 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | + '</a>' |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * _create_timezone_object_from_timezone_name |
|
| 96 | + * |
|
| 97 | + * @access protected |
|
| 98 | + * @param string $gmt_offset |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | + { |
|
| 103 | + $timezone_string = 'UTC'; |
|
| 104 | + //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 105 | + //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 106 | + //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 107 | + if ($gmt_offset === '') { |
|
| 108 | + //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 109 | + if (get_option('timezone_string')) { |
|
| 110 | + return get_option('timezone_string'); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset'); |
|
| 114 | + $gmt_offset = (float) $gmt_offset; |
|
| 115 | + |
|
| 116 | + //if $gmt_offset is 0, then just return UTC |
|
| 117 | + if ($gmt_offset === (float) 0) { |
|
| 118 | + return $timezone_string; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + if ($gmt_offset !== '') { |
|
| 123 | + // convert GMT offset to seconds |
|
| 124 | + $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 125 | + // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 126 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 127 | + //only use this timezone_string IF it's current offset matches the given offset |
|
| 128 | + try { |
|
| 129 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 130 | + if ($offset !== $gmt_offset) { |
|
| 131 | + $timezone_string = false; |
|
| 132 | + } |
|
| 133 | + } catch (Exception $e) { |
|
| 134 | + $timezone_string = false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 138 | + $timezone_string = $timezone_string !== false |
|
| 139 | + ? $timezone_string |
|
| 140 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 141 | + return $timezone_string; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Gets the site's GMT offset based on either the timezone string |
|
| 146 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 147 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 148 | + * |
|
| 149 | + * @return int seconds offset |
|
| 150 | + */ |
|
| 151 | + public static function get_site_timezone_gmt_offset() |
|
| 152 | + { |
|
| 153 | + $timezone_string = get_option('timezone_string'); |
|
| 154 | + if ($timezone_string) { |
|
| 155 | + try { |
|
| 156 | + $timezone = new DateTimeZone($timezone_string); |
|
| 157 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 158 | + } catch (Exception $e) { |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + $offset = get_option('gmt_offset'); |
|
| 162 | + return (int)($offset * HOUR_IN_SECONDS); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its |
|
| 168 | + * timezone tables. |
|
| 169 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 170 | + * |
|
| 171 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @param int $gmt_offset |
|
| 175 | + * @return int |
|
| 176 | + */ |
|
| 177 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 178 | + { |
|
| 179 | + //make sure $gmt_offset is int |
|
| 180 | + $gmt_offset = (int)$gmt_offset; |
|
| 181 | + switch ($gmt_offset) { |
|
| 182 | + //-12 |
|
| 183 | + case -43200: |
|
| 184 | + $gmt_offset = -39600; |
|
| 185 | + break; |
|
| 186 | + //-11.5 |
|
| 187 | + case -41400: |
|
| 188 | + $gmt_offset = -39600; |
|
| 189 | + break; |
|
| 190 | + //-10.5 |
|
| 191 | + case -37800: |
|
| 192 | + $gmt_offset = -39600; |
|
| 193 | + break; |
|
| 194 | + //-8.5 |
|
| 195 | + case -30600: |
|
| 196 | + $gmt_offset = -28800; |
|
| 197 | + break; |
|
| 198 | + //-7.5 |
|
| 199 | + case -27000: |
|
| 200 | + $gmt_offset = -25200; |
|
| 201 | + break; |
|
| 202 | + //-6.5 |
|
| 203 | + case -23400: |
|
| 204 | + $gmt_offset = -21600; |
|
| 205 | + break; |
|
| 206 | + //-5.5 |
|
| 207 | + case -19800: |
|
| 208 | + $gmt_offset = -18000; |
|
| 209 | + break; |
|
| 210 | + //-4.5 |
|
| 211 | + case -16200: |
|
| 212 | + $gmt_offset = -14400; |
|
| 213 | + break; |
|
| 214 | + //-3.5 |
|
| 215 | + case -12600: |
|
| 216 | + $gmt_offset = -10800; |
|
| 217 | + break; |
|
| 218 | + //-2.5 |
|
| 219 | + case -9000: |
|
| 220 | + $gmt_offset = -7200; |
|
| 221 | + break; |
|
| 222 | + //-1.5 |
|
| 223 | + case -5400: |
|
| 224 | + $gmt_offset = -3600; |
|
| 225 | + break; |
|
| 226 | + //-0.5 |
|
| 227 | + case -1800: |
|
| 228 | + $gmt_offset = 0; |
|
| 229 | + break; |
|
| 230 | + //.5 |
|
| 231 | + case 1800: |
|
| 232 | + $gmt_offset = 3600; |
|
| 233 | + break; |
|
| 234 | + //1.5 |
|
| 235 | + case 5400: |
|
| 236 | + $gmt_offset = 7200; |
|
| 237 | + break; |
|
| 238 | + //2.5 |
|
| 239 | + case 9000: |
|
| 240 | + $gmt_offset = 10800; |
|
| 241 | + break; |
|
| 242 | + //3.5 |
|
| 243 | + case 12600: |
|
| 244 | + $gmt_offset = 14400; |
|
| 245 | + break; |
|
| 246 | + |
|
| 247 | + //7.5 |
|
| 248 | + case 27000: |
|
| 249 | + $gmt_offset = 28800; |
|
| 250 | + break; |
|
| 251 | + //8.5 |
|
| 252 | + case 30600: |
|
| 253 | + $gmt_offset = 31500; |
|
| 254 | + break; |
|
| 255 | + //10.5 |
|
| 256 | + case 37800: |
|
| 257 | + $gmt_offset = 39600; |
|
| 258 | + break; |
|
| 259 | + //11.5 |
|
| 260 | + case 41400: |
|
| 261 | + $gmt_offset = 43200; |
|
| 262 | + break; |
|
| 263 | + //12.75 |
|
| 264 | + case 45900: |
|
| 265 | + $gmt_offset = 46800; |
|
| 266 | + break; |
|
| 267 | + //13.75 |
|
| 268 | + case 49500: |
|
| 269 | + $gmt_offset = 50400; |
|
| 270 | + break; |
|
| 271 | + } |
|
| 272 | + return $gmt_offset; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * get_timezone_string_from_abbreviations_list |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @param int $gmt_offset |
|
| 281 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 282 | + * @return string |
|
| 283 | + * @throws \EE_Error |
|
| 284 | + */ |
|
| 285 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 286 | + { |
|
| 287 | + $abbreviations = timezone_abbreviations_list(); |
|
| 288 | + foreach ($abbreviations as $abbreviation) { |
|
| 289 | + foreach ($abbreviation as $city) { |
|
| 290 | + if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 291 | + try { |
|
| 292 | + $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id'])); |
|
| 293 | + if ($offset !== $gmt_offset) { |
|
| 294 | + continue; |
|
| 295 | + } else { |
|
| 296 | + return $city['timezone_id']; |
|
| 297 | + } |
|
| 298 | + } catch (Exception $e) { |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 305 | + if ($coerce == true) { |
|
| 306 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 307 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 308 | + false |
|
| 309 | + ); |
|
| 310 | + if ($timezone_string) { |
|
| 311 | + return $timezone_string; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + throw new EE_Error( |
|
| 315 | + sprintf( |
|
| 316 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 317 | + 'event_espresso'), |
|
| 318 | + $gmt_offset, |
|
| 319 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 320 | + '</a>' |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Get Timezone Transitions |
|
| 329 | + * @param \DateTimeZone $date_time_zone |
|
| 330 | + * @param null $time |
|
| 331 | + * @param bool $first_only |
|
| 332 | + * @return array|mixed |
|
| 333 | + */ |
|
| 334 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 335 | + { |
|
| 336 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 337 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 338 | + $transitions = $date_time_zone->getTransitions($time); |
|
| 339 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get Timezone Offset for given timezone object. |
|
| 345 | + * @param \DateTimeZone $date_time_zone |
|
| 346 | + * @param null $time |
|
| 347 | + * @return mixed |
|
| 348 | + * @throws \DomainException |
|
| 349 | + */ |
|
| 350 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 351 | + { |
|
| 352 | + $transitions = self::get_timezone_transitions($date_time_zone, $time); |
|
| 353 | + if (! isset($transitions['offset'])) { |
|
| 354 | + throw new DomainException(); |
|
| 355 | + } |
|
| 356 | + return $transitions['offset']; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @access public |
|
| 362 | + * @param string $timezone_string |
|
| 363 | + */ |
|
| 364 | + public static function timezone_select_input($timezone_string = '') |
|
| 365 | + { |
|
| 366 | + // get WP date time format |
|
| 367 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 368 | + // if passed a value, then use that, else get WP option |
|
| 369 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 370 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 371 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 372 | + $gmt_offset = get_option('gmt_offset'); |
|
| 373 | + |
|
| 374 | + $check_zone_info = true; |
|
| 375 | + if (empty($timezone_string)) { |
|
| 376 | + // Create a UTC+- zone if no timezone string exists |
|
| 377 | + $check_zone_info = false; |
|
| 378 | + if ($gmt_offset > 0) { |
|
| 379 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
| 380 | + } elseif ($gmt_offset < 0) { |
|
| 381 | + $timezone_string = 'UTC' . $gmt_offset; |
|
| 382 | + } else { |
|
| 383 | + $timezone_string = 'UTC'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + ?> |
|
| 387 | 387 | |
| 388 | 388 | <p> |
| 389 | 389 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
@@ -396,13 +396,13 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | <p> |
| 398 | 398 | <span><?php |
| 399 | - printf( |
|
| 400 | - __('%1$sUTC%2$s time is %3$s'), |
|
| 401 | - '<abbr title="Coordinated Universal Time">', |
|
| 402 | - '</abbr>', |
|
| 403 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 404 | - ); |
|
| 405 | - ?></span> |
|
| 399 | + printf( |
|
| 400 | + __('%1$sUTC%2$s time is %3$s'), |
|
| 401 | + '<abbr title="Coordinated Universal Time">', |
|
| 402 | + '</abbr>', |
|
| 403 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 404 | + ); |
|
| 405 | + ?></span> |
|
| 406 | 406 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
| 407 | 407 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
| 408 | 408 | <?php endif; ?> |
@@ -411,693 +411,693 @@ discard block |
||
| 411 | 411 | <br/> |
| 412 | 412 | <span> |
| 413 | 413 | <?php |
| 414 | - // Set TZ so localtime works. |
|
| 415 | - date_default_timezone_set($timezone_string); |
|
| 416 | - $now = localtime(time(), true); |
|
| 417 | - if ($now['tm_isdst']) { |
|
| 418 | - _e('This timezone is currently in daylight saving time.'); |
|
| 419 | - } else { |
|
| 420 | - _e('This timezone is currently in standard time.'); |
|
| 421 | - } |
|
| 422 | - ?> |
|
| 414 | + // Set TZ so localtime works. |
|
| 415 | + date_default_timezone_set($timezone_string); |
|
| 416 | + $now = localtime(time(), true); |
|
| 417 | + if ($now['tm_isdst']) { |
|
| 418 | + _e('This timezone is currently in daylight saving time.'); |
|
| 419 | + } else { |
|
| 420 | + _e('This timezone is currently in standard time.'); |
|
| 421 | + } |
|
| 422 | + ?> |
|
| 423 | 423 | <br/> |
| 424 | 424 | <?php |
| 425 | - if (function_exists('timezone_transitions_get')) { |
|
| 426 | - $found = false; |
|
| 427 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 428 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 429 | - $right_now = time(); |
|
| 430 | - $tr['isdst'] = false; |
|
| 431 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 432 | - if ($tr['ts'] > $right_now) { |
|
| 433 | - $found = true; |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if ($found) { |
|
| 439 | - $message = $tr['isdst'] ? |
|
| 440 | - __(' Daylight saving time begins on: %s.') : |
|
| 441 | - __(' Standard time begins on: %s.'); |
|
| 442 | - // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 443 | - printf($message, |
|
| 444 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 445 | - } else { |
|
| 446 | - _e('This timezone does not observe daylight saving time.'); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - // Set back to UTC. |
|
| 450 | - date_default_timezone_set('UTC'); |
|
| 451 | - ?> |
|
| 425 | + if (function_exists('timezone_transitions_get')) { |
|
| 426 | + $found = false; |
|
| 427 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 428 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 429 | + $right_now = time(); |
|
| 430 | + $tr['isdst'] = false; |
|
| 431 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 432 | + if ($tr['ts'] > $right_now) { |
|
| 433 | + $found = true; |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if ($found) { |
|
| 439 | + $message = $tr['isdst'] ? |
|
| 440 | + __(' Daylight saving time begins on: %s.') : |
|
| 441 | + __(' Standard time begins on: %s.'); |
|
| 442 | + // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 443 | + printf($message, |
|
| 444 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 445 | + } else { |
|
| 446 | + _e('This timezone does not observe daylight saving time.'); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + // Set back to UTC. |
|
| 450 | + date_default_timezone_set('UTC'); |
|
| 451 | + ?> |
|
| 452 | 452 | </span></p> |
| 453 | 453 | <?php |
| 454 | - endif; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 460 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 461 | - * the site is used. |
|
| 462 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 463 | - * computed timestamp (i.e. date_i18n() ) |
|
| 464 | - * |
|
| 465 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 466 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 467 | - * site will be used. |
|
| 468 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 469 | - */ |
|
| 470 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 471 | - { |
|
| 472 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 473 | - $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 474 | - $TimeZone = new DateTimeZone($timezone_string); |
|
| 475 | - |
|
| 476 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 477 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 478 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * _set_date_time_field |
|
| 484 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 485 | - * |
|
| 486 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 487 | - * @param DateTime $DateTime PHP DateTime object |
|
| 488 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 489 | - * @return EE_Base_Class |
|
| 490 | - */ |
|
| 491 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 492 | - { |
|
| 493 | - // grab current datetime format |
|
| 494 | - $current_format = $obj->get_format(); |
|
| 495 | - // set new full timestamp format |
|
| 496 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 497 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 498 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 499 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 500 | - // reset datetime formats |
|
| 501 | - $obj->set_date_format($current_format[0]); |
|
| 502 | - $obj->set_time_format($current_format[1]); |
|
| 503 | - return $obj; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * date_time_add |
|
| 509 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 510 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 511 | - * |
|
| 512 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 513 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 514 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 515 | - * minutes, seconds) defaults to years |
|
| 516 | - * @param integer $value what you want to increment the time by |
|
| 517 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 518 | - * (chaining) |
|
| 519 | - */ |
|
| 520 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 521 | - { |
|
| 522 | - //get the raw UTC date. |
|
| 523 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 524 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 525 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * date_time_subtract |
|
| 531 | - * same as date_time_add except subtracting value instead of adding. |
|
| 532 | - * |
|
| 533 | - * @param \EE_Base_Class $obj |
|
| 534 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 535 | - * @param string $period |
|
| 536 | - * @param int $value |
|
| 537 | - * @return \EE_Base_Class |
|
| 538 | - */ |
|
| 539 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 540 | - { |
|
| 541 | - //get the raw UTC date |
|
| 542 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 543 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 544 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 550 | - * |
|
| 551 | - * @param DateTime $DateTime DateTime object |
|
| 552 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 553 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 554 | - * @param integer $value What you want to increment the date by |
|
| 555 | - * @param string $operand What operand you wish to use for the calculation |
|
| 556 | - * @return \DateTime return whatever type came in. |
|
| 557 | - * @throws \EE_Error |
|
| 558 | - */ |
|
| 559 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 560 | - { |
|
| 561 | - if (! $DateTime instanceof DateTime) { |
|
| 562 | - throw new EE_Error( |
|
| 563 | - sprintf( |
|
| 564 | - __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 565 | - print_r($DateTime, true) |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - switch ($period) { |
|
| 570 | - case 'years' : |
|
| 571 | - $value = 'P' . $value . 'Y'; |
|
| 572 | - break; |
|
| 573 | - case 'months' : |
|
| 574 | - $value = 'P' . $value . 'M'; |
|
| 575 | - break; |
|
| 576 | - case 'weeks' : |
|
| 577 | - $value = 'P' . $value . 'W'; |
|
| 578 | - break; |
|
| 579 | - case 'days' : |
|
| 580 | - $value = 'P' . $value . 'D'; |
|
| 581 | - break; |
|
| 582 | - case 'hours' : |
|
| 583 | - $value = 'PT' . $value . 'H'; |
|
| 584 | - break; |
|
| 585 | - case 'minutes' : |
|
| 586 | - $value = 'PT' . $value . 'M'; |
|
| 587 | - break; |
|
| 588 | - case 'seconds' : |
|
| 589 | - $value = 'PT' . $value . 'S'; |
|
| 590 | - break; |
|
| 591 | - } |
|
| 592 | - switch ($operand) { |
|
| 593 | - case '+': |
|
| 594 | - $DateTime->add(new DateInterval($value)); |
|
| 595 | - break; |
|
| 596 | - case '-': |
|
| 597 | - $DateTime->sub(new DateInterval($value)); |
|
| 598 | - break; |
|
| 599 | - } |
|
| 600 | - return $DateTime; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 606 | - * |
|
| 607 | - * @param int $timestamp Unix timestamp |
|
| 608 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 609 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 610 | - * @param integer $value What you want to increment the date by |
|
| 611 | - * @param string $operand What operand you wish to use for the calculation |
|
| 612 | - * @return \DateTime return whatever type came in. |
|
| 613 | - * @throws \EE_Error |
|
| 614 | - */ |
|
| 615 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 616 | - { |
|
| 617 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | - throw new EE_Error( |
|
| 619 | - sprintf( |
|
| 620 | - __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 621 | - print_r($timestamp, true) |
|
| 622 | - ) |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - switch ($period) { |
|
| 626 | - case 'years' : |
|
| 627 | - $value = YEAR_IN_SECONDS * $value; |
|
| 628 | - break; |
|
| 629 | - case 'months' : |
|
| 630 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 631 | - break; |
|
| 632 | - case 'weeks' : |
|
| 633 | - $value = WEEK_IN_SECONDS * $value; |
|
| 634 | - break; |
|
| 635 | - case 'days' : |
|
| 636 | - $value = DAY_IN_SECONDS * $value; |
|
| 637 | - break; |
|
| 638 | - case 'hours' : |
|
| 639 | - $value = HOUR_IN_SECONDS * $value; |
|
| 640 | - break; |
|
| 641 | - case 'minutes' : |
|
| 642 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 643 | - break; |
|
| 644 | - } |
|
| 645 | - switch ($operand) { |
|
| 646 | - case '+': |
|
| 647 | - $timestamp += $value; |
|
| 648 | - break; |
|
| 649 | - case '-': |
|
| 650 | - $timestamp -= $value; |
|
| 651 | - break; |
|
| 652 | - } |
|
| 653 | - return $timestamp; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 659 | - * parameters and returns the new timestamp or DateTime. |
|
| 660 | - * |
|
| 661 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 662 | - * @param string $period a value to indicate what interval is being used in the |
|
| 663 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 664 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 665 | - * @param integer $value What you want to increment the date by |
|
| 666 | - * @param string $operand What operand you wish to use for the calculation |
|
| 667 | - * @return mixed string|DateTime return whatever type came in. |
|
| 668 | - */ |
|
| 669 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 670 | - { |
|
| 671 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 672 | - return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 673 | - } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 674 | - return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 675 | - } else { |
|
| 676 | - //error |
|
| 677 | - return $DateTime_or_timestamp; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 684 | - * and spit out the js and moment.js equivalent formats. |
|
| 685 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 686 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 687 | - * time picker. |
|
| 688 | - * |
|
| 689 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 690 | - * @param null $date_format_string |
|
| 691 | - * @param null $time_format_string |
|
| 692 | - * @return array |
|
| 693 | - * array( |
|
| 694 | - * 'js' => array ( |
|
| 695 | - * 'date' => //date format |
|
| 696 | - * 'time' => //time format |
|
| 697 | - * ), |
|
| 698 | - * 'moment' => //date and time format. |
|
| 699 | - * ) |
|
| 700 | - */ |
|
| 701 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 702 | - $date_format_string = null, |
|
| 703 | - $time_format_string = null |
|
| 704 | - ) { |
|
| 705 | - if ($date_format_string === null) { |
|
| 706 | - $date_format_string = get_option('date_format'); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if ($time_format_string === null) { |
|
| 710 | - $time_format_string = get_option('time_format'); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 714 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 715 | - |
|
| 716 | - return array( |
|
| 717 | - 'js' => array( |
|
| 718 | - 'date' => $date_format['js'], |
|
| 719 | - 'time' => $time_format['js'], |
|
| 720 | - ), |
|
| 721 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 722 | - ); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * This converts incoming format string into js and moment variations. |
|
| 728 | - * |
|
| 729 | - * @param string $format_string incoming php format string |
|
| 730 | - * @return array js and moment formats. |
|
| 731 | - */ |
|
| 732 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 733 | - { |
|
| 734 | - /** |
|
| 735 | - * This is a map of symbols for formats. |
|
| 736 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 737 | - * |
|
| 738 | - * @var array |
|
| 739 | - */ |
|
| 740 | - $symbols_map = array( |
|
| 741 | - // Day |
|
| 742 | - //01 |
|
| 743 | - 'd' => array( |
|
| 744 | - 'js' => 'dd', |
|
| 745 | - 'moment' => 'DD', |
|
| 746 | - ), |
|
| 747 | - //Mon |
|
| 748 | - 'D' => array( |
|
| 749 | - 'js' => 'D', |
|
| 750 | - 'moment' => 'ddd', |
|
| 751 | - ), |
|
| 752 | - //1,2,...31 |
|
| 753 | - 'j' => array( |
|
| 754 | - 'js' => 'd', |
|
| 755 | - 'moment' => 'D', |
|
| 756 | - ), |
|
| 757 | - //Monday |
|
| 758 | - 'l' => array( |
|
| 759 | - 'js' => 'DD', |
|
| 760 | - 'moment' => 'dddd', |
|
| 761 | - ), |
|
| 762 | - //ISO numeric representation of the day of the week (1-6) |
|
| 763 | - 'N' => array( |
|
| 764 | - 'js' => '', |
|
| 765 | - 'moment' => 'E', |
|
| 766 | - ), |
|
| 767 | - //st,nd.rd |
|
| 768 | - 'S' => array( |
|
| 769 | - 'js' => '', |
|
| 770 | - 'moment' => 'o', |
|
| 771 | - ), |
|
| 772 | - //numeric representation of day of week (0-6) |
|
| 773 | - 'w' => array( |
|
| 774 | - 'js' => '', |
|
| 775 | - 'moment' => 'd', |
|
| 776 | - ), |
|
| 777 | - //day of year starting from 0 (0-365) |
|
| 778 | - 'z' => array( |
|
| 779 | - 'js' => 'o', |
|
| 780 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 781 | - ), |
|
| 782 | - // Week |
|
| 783 | - //ISO-8601 week number of year (weeks starting on monday) |
|
| 784 | - 'W' => array( |
|
| 785 | - 'js' => '', |
|
| 786 | - 'moment' => 'w', |
|
| 787 | - ), |
|
| 788 | - // Month |
|
| 789 | - // January...December |
|
| 790 | - 'F' => array( |
|
| 791 | - 'js' => 'MM', |
|
| 792 | - 'moment' => 'MMMM', |
|
| 793 | - ), |
|
| 794 | - //01...12 |
|
| 795 | - 'm' => array( |
|
| 796 | - 'js' => 'mm', |
|
| 797 | - 'moment' => 'MM', |
|
| 798 | - ), |
|
| 799 | - //Jan...Dec |
|
| 800 | - 'M' => array( |
|
| 801 | - 'js' => 'M', |
|
| 802 | - 'moment' => 'MMM', |
|
| 803 | - ), |
|
| 804 | - //1-12 |
|
| 805 | - 'n' => array( |
|
| 806 | - 'js' => 'm', |
|
| 807 | - 'moment' => 'M', |
|
| 808 | - ), |
|
| 809 | - //number of days in given month |
|
| 810 | - 't' => array( |
|
| 811 | - 'js' => '', |
|
| 812 | - 'moment' => '', |
|
| 813 | - ), |
|
| 814 | - // Year |
|
| 815 | - //whether leap year or not 1/0 |
|
| 816 | - 'L' => array( |
|
| 817 | - 'js' => '', |
|
| 818 | - 'moment' => '', |
|
| 819 | - ), |
|
| 820 | - //ISO-8601 year number |
|
| 821 | - 'o' => array( |
|
| 822 | - 'js' => '', |
|
| 823 | - 'moment' => 'GGGG', |
|
| 824 | - ), |
|
| 825 | - //1999...2003 |
|
| 826 | - 'Y' => array( |
|
| 827 | - 'js' => 'yy', |
|
| 828 | - 'moment' => 'YYYY', |
|
| 829 | - ), |
|
| 830 | - //99...03 |
|
| 831 | - 'y' => array( |
|
| 832 | - 'js' => 'y', |
|
| 833 | - 'moment' => 'YY', |
|
| 834 | - ), |
|
| 835 | - // Time |
|
| 836 | - // am/pm |
|
| 837 | - 'a' => array( |
|
| 838 | - 'js' => 'tt', |
|
| 839 | - 'moment' => 'a', |
|
| 840 | - ), |
|
| 841 | - // AM/PM |
|
| 842 | - 'A' => array( |
|
| 843 | - 'js' => 'TT', |
|
| 844 | - 'moment' => 'A', |
|
| 845 | - ), |
|
| 846 | - // Swatch Internet Time?!? |
|
| 847 | - 'B' => array( |
|
| 848 | - 'js' => '', |
|
| 849 | - 'moment' => '', |
|
| 850 | - ), |
|
| 851 | - //1...12 |
|
| 852 | - 'g' => array( |
|
| 853 | - 'js' => 'h', |
|
| 854 | - 'moment' => 'h', |
|
| 855 | - ), |
|
| 856 | - //0...23 |
|
| 857 | - 'G' => array( |
|
| 858 | - 'js' => 'H', |
|
| 859 | - 'moment' => 'H', |
|
| 860 | - ), |
|
| 861 | - //01...12 |
|
| 862 | - 'h' => array( |
|
| 863 | - 'js' => 'hh', |
|
| 864 | - 'moment' => 'hh', |
|
| 865 | - ), |
|
| 866 | - //00...23 |
|
| 867 | - 'H' => array( |
|
| 868 | - 'js' => 'HH', |
|
| 869 | - 'moment' => 'HH', |
|
| 870 | - ), |
|
| 871 | - //00..59 |
|
| 872 | - 'i' => array( |
|
| 873 | - 'js' => 'mm', |
|
| 874 | - 'moment' => 'mm', |
|
| 875 | - ), |
|
| 876 | - //seconds... 00...59 |
|
| 877 | - 's' => array( |
|
| 878 | - 'js' => 'ss', |
|
| 879 | - 'moment' => 'ss', |
|
| 880 | - ), |
|
| 881 | - //microseconds |
|
| 882 | - 'u' => array( |
|
| 883 | - 'js' => '', |
|
| 884 | - 'moment' => '', |
|
| 885 | - ), |
|
| 886 | - ); |
|
| 887 | - $jquery_ui_format = ""; |
|
| 888 | - $moment_format = ""; |
|
| 889 | - $escaping = false; |
|
| 890 | - for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 891 | - $char = $format_string[$i]; |
|
| 892 | - if ($char === '\\') { // PHP date format escaping character |
|
| 893 | - $i++; |
|
| 894 | - if ($escaping) { |
|
| 895 | - $jquery_ui_format .= $format_string[$i]; |
|
| 896 | - $moment_format .= $format_string[$i]; |
|
| 897 | - } else { |
|
| 898 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 899 | - $moment_format .= $format_string[$i]; |
|
| 900 | - } |
|
| 901 | - $escaping = true; |
|
| 902 | - } else { |
|
| 903 | - if ($escaping) { |
|
| 904 | - $jquery_ui_format .= "'"; |
|
| 905 | - $moment_format .= "'"; |
|
| 906 | - $escaping = false; |
|
| 907 | - } |
|
| 908 | - if (isset($symbols_map[$char])) { |
|
| 909 | - $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 910 | - $moment_format .= $symbols_map[$char]['moment']; |
|
| 911 | - } else { |
|
| 912 | - $jquery_ui_format .= $char; |
|
| 913 | - $moment_format .= $char; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - } |
|
| 917 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 923 | - * |
|
| 924 | - * @param string $format_string Incoming format string for php date(). |
|
| 925 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 926 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 927 | - * indicate failed validations. |
|
| 928 | - */ |
|
| 929 | - public static function validate_format_string($format_string) |
|
| 930 | - { |
|
| 931 | - $error_msg = array(); |
|
| 932 | - //time format checks |
|
| 933 | - switch (true) { |
|
| 934 | - case strpos($format_string, 'h') !== false : |
|
| 935 | - case strpos($format_string, 'g') !== false : |
|
| 936 | - /** |
|
| 937 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 938 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 939 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 940 | - */ |
|
| 941 | - if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 942 | - $error_msg[] = __('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".', |
|
| 943 | - 'event_espresso'); |
|
| 944 | - } |
|
| 945 | - break; |
|
| 946 | - |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - return empty($error_msg) ? true : $error_msg; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 955 | - * very next day then this method will return true. |
|
| 956 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 957 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 958 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 959 | - * |
|
| 960 | - * @param mixed $date_1 |
|
| 961 | - * @param mixed $date_2 |
|
| 962 | - * @return bool |
|
| 963 | - */ |
|
| 964 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 965 | - { |
|
| 966 | - |
|
| 967 | - if ( |
|
| 968 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | - ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 970 | - ) { |
|
| 971 | - return false; |
|
| 972 | - } |
|
| 973 | - return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 979 | - * Functions. |
|
| 980 | - * |
|
| 981 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 982 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 983 | - * @return string |
|
| 984 | - */ |
|
| 985 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 986 | - { |
|
| 987 | - try { |
|
| 988 | - /** need to account for timezone offset on the selects */ |
|
| 989 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 990 | - } catch (Exception $e) { |
|
| 991 | - $DateTimeZone = null; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 996 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 997 | - */ |
|
| 998 | - $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 999 | - $query_interval = $offset < 0 |
|
| 1000 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1002 | - return $query_interval; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1007 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1008 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1009 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1010 | - * (although note that we remove any HTML that may be added) |
|
| 1011 | - * |
|
| 1012 | - * @return string |
|
| 1013 | - */ |
|
| 1014 | - public static function get_timezone_string_for_display() |
|
| 1015 | - { |
|
| 1016 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1017 | - if (! empty($pretty_timezone)) { |
|
| 1018 | - return esc_html($pretty_timezone); |
|
| 1019 | - } |
|
| 1020 | - $timezone_string = get_option('timezone_string'); |
|
| 1021 | - if ($timezone_string) { |
|
| 1022 | - static $mo_loaded = false; |
|
| 1023 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1024 | - if (! $mo_loaded) { |
|
| 1025 | - $locale = get_locale(); |
|
| 1026 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1027 | - load_textdomain('continents-cities', $mofile); |
|
| 1028 | - $mo_loaded = true; |
|
| 1029 | - } |
|
| 1030 | - //well that was easy. |
|
| 1031 | - $parts = explode('/', $timezone_string); |
|
| 1032 | - //remove the continent |
|
| 1033 | - unset($parts[0]); |
|
| 1034 | - $t_parts = array(); |
|
| 1035 | - foreach ($parts as $part) { |
|
| 1036 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1037 | - } |
|
| 1038 | - return implode(' - ', $t_parts); |
|
| 1039 | - } |
|
| 1040 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1041 | - $gmt_offset = get_option('gmt_offset'); |
|
| 1042 | - if (intval($gmt_offset) >= 0) { |
|
| 1043 | - $prefix = '+'; |
|
| 1044 | - } else { |
|
| 1045 | - $prefix = ''; |
|
| 1046 | - } |
|
| 1047 | - $parts = explode('.', (string)$gmt_offset); |
|
| 1048 | - if (count($parts) === 1) { |
|
| 1049 | - $parts[1] = '00'; |
|
| 1050 | - } else { |
|
| 1051 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1052 | - //to minutes, eg 30 or 15, respectively |
|
| 1053 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 1055 | - } |
|
| 1056 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1063 | - * for a month using a string like "February" or "February 2017", |
|
| 1064 | - * and you don't specify a day as part of your string, |
|
| 1065 | - * then PHP will use whatever the current day of the month is. |
|
| 1066 | - * IF the current day of the month happens to be the 30th or 31st, |
|
| 1067 | - * then PHP gets really confused by a date like February 30, |
|
| 1068 | - * so instead of saying |
|
| 1069 | - * "Hey February only has 28 days (this year)... |
|
| 1070 | - * ...you must have meant the last day of the month!" |
|
| 1071 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1072 | - * because someone requesting February 30th obviously meant March 1st! |
|
| 1073 | - * The way around this is to always set the day to the first, |
|
| 1074 | - * so that the month will stay on the month you wanted. |
|
| 1075 | - * this method will add that "1" into your date regardless of the format. |
|
| 1076 | - * |
|
| 1077 | - * @param string $month |
|
| 1078 | - * @return string |
|
| 1079 | - */ |
|
| 1080 | - public static function first_of_month_timestamp($month = '') |
|
| 1081 | - { |
|
| 1082 | - $month = (string)$month; |
|
| 1083 | - $year = ''; |
|
| 1084 | - // check if the incoming string has a year in it or not |
|
| 1085 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1086 | - $year = $matches[0]; |
|
| 1087 | - // ten remove that from the month string as well as any spaces |
|
| 1088 | - $month = trim(str_replace($year, '', $month)); |
|
| 1089 | - // add a space before the year |
|
| 1090 | - $year = " {$year}"; |
|
| 1091 | - } |
|
| 1092 | - // return timestamp for something like "February 1 2017" |
|
| 1093 | - return strtotime("{$month} 1{$year}"); |
|
| 1094 | - } |
|
| 454 | + endif; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 460 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 461 | + * the site is used. |
|
| 462 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 463 | + * computed timestamp (i.e. date_i18n() ) |
|
| 464 | + * |
|
| 465 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 466 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 467 | + * site will be used. |
|
| 468 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 469 | + */ |
|
| 470 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 471 | + { |
|
| 472 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 473 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 474 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 475 | + |
|
| 476 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 477 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 478 | + return (int)$DateTime->format('U') + (int)$offset; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * _set_date_time_field |
|
| 484 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 485 | + * |
|
| 486 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 487 | + * @param DateTime $DateTime PHP DateTime object |
|
| 488 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 489 | + * @return EE_Base_Class |
|
| 490 | + */ |
|
| 491 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 492 | + { |
|
| 493 | + // grab current datetime format |
|
| 494 | + $current_format = $obj->get_format(); |
|
| 495 | + // set new full timestamp format |
|
| 496 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 497 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 498 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 499 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 500 | + // reset datetime formats |
|
| 501 | + $obj->set_date_format($current_format[0]); |
|
| 502 | + $obj->set_time_format($current_format[1]); |
|
| 503 | + return $obj; |
|
| 504 | + } |
|
| 505 | + |
|
| 1095 | 506 | |
| 1096 | 507 | /** |
| 1097 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1098 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1099 | - */ |
|
| 1100 | - public static function tomorrow() |
|
| 508 | + * date_time_add |
|
| 509 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 510 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 511 | + * |
|
| 512 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 513 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 514 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 515 | + * minutes, seconds) defaults to years |
|
| 516 | + * @param integer $value what you want to increment the time by |
|
| 517 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 518 | + * (chaining) |
|
| 519 | + */ |
|
| 520 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 521 | + { |
|
| 522 | + //get the raw UTC date. |
|
| 523 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 524 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 525 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * date_time_subtract |
|
| 531 | + * same as date_time_add except subtracting value instead of adding. |
|
| 532 | + * |
|
| 533 | + * @param \EE_Base_Class $obj |
|
| 534 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 535 | + * @param string $period |
|
| 536 | + * @param int $value |
|
| 537 | + * @return \EE_Base_Class |
|
| 538 | + */ |
|
| 539 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 540 | + { |
|
| 541 | + //get the raw UTC date |
|
| 542 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 543 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 544 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 550 | + * |
|
| 551 | + * @param DateTime $DateTime DateTime object |
|
| 552 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 553 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 554 | + * @param integer $value What you want to increment the date by |
|
| 555 | + * @param string $operand What operand you wish to use for the calculation |
|
| 556 | + * @return \DateTime return whatever type came in. |
|
| 557 | + * @throws \EE_Error |
|
| 558 | + */ |
|
| 559 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 560 | + { |
|
| 561 | + if (! $DateTime instanceof DateTime) { |
|
| 562 | + throw new EE_Error( |
|
| 563 | + sprintf( |
|
| 564 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 565 | + print_r($DateTime, true) |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + switch ($period) { |
|
| 570 | + case 'years' : |
|
| 571 | + $value = 'P' . $value . 'Y'; |
|
| 572 | + break; |
|
| 573 | + case 'months' : |
|
| 574 | + $value = 'P' . $value . 'M'; |
|
| 575 | + break; |
|
| 576 | + case 'weeks' : |
|
| 577 | + $value = 'P' . $value . 'W'; |
|
| 578 | + break; |
|
| 579 | + case 'days' : |
|
| 580 | + $value = 'P' . $value . 'D'; |
|
| 581 | + break; |
|
| 582 | + case 'hours' : |
|
| 583 | + $value = 'PT' . $value . 'H'; |
|
| 584 | + break; |
|
| 585 | + case 'minutes' : |
|
| 586 | + $value = 'PT' . $value . 'M'; |
|
| 587 | + break; |
|
| 588 | + case 'seconds' : |
|
| 589 | + $value = 'PT' . $value . 'S'; |
|
| 590 | + break; |
|
| 591 | + } |
|
| 592 | + switch ($operand) { |
|
| 593 | + case '+': |
|
| 594 | + $DateTime->add(new DateInterval($value)); |
|
| 595 | + break; |
|
| 596 | + case '-': |
|
| 597 | + $DateTime->sub(new DateInterval($value)); |
|
| 598 | + break; |
|
| 599 | + } |
|
| 600 | + return $DateTime; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 606 | + * |
|
| 607 | + * @param int $timestamp Unix timestamp |
|
| 608 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 609 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 610 | + * @param integer $value What you want to increment the date by |
|
| 611 | + * @param string $operand What operand you wish to use for the calculation |
|
| 612 | + * @return \DateTime return whatever type came in. |
|
| 613 | + * @throws \EE_Error |
|
| 614 | + */ |
|
| 615 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 616 | + { |
|
| 617 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | + throw new EE_Error( |
|
| 619 | + sprintf( |
|
| 620 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 621 | + print_r($timestamp, true) |
|
| 622 | + ) |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + switch ($period) { |
|
| 626 | + case 'years' : |
|
| 627 | + $value = YEAR_IN_SECONDS * $value; |
|
| 628 | + break; |
|
| 629 | + case 'months' : |
|
| 630 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 631 | + break; |
|
| 632 | + case 'weeks' : |
|
| 633 | + $value = WEEK_IN_SECONDS * $value; |
|
| 634 | + break; |
|
| 635 | + case 'days' : |
|
| 636 | + $value = DAY_IN_SECONDS * $value; |
|
| 637 | + break; |
|
| 638 | + case 'hours' : |
|
| 639 | + $value = HOUR_IN_SECONDS * $value; |
|
| 640 | + break; |
|
| 641 | + case 'minutes' : |
|
| 642 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 643 | + break; |
|
| 644 | + } |
|
| 645 | + switch ($operand) { |
|
| 646 | + case '+': |
|
| 647 | + $timestamp += $value; |
|
| 648 | + break; |
|
| 649 | + case '-': |
|
| 650 | + $timestamp -= $value; |
|
| 651 | + break; |
|
| 652 | + } |
|
| 653 | + return $timestamp; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 659 | + * parameters and returns the new timestamp or DateTime. |
|
| 660 | + * |
|
| 661 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 662 | + * @param string $period a value to indicate what interval is being used in the |
|
| 663 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 664 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 665 | + * @param integer $value What you want to increment the date by |
|
| 666 | + * @param string $operand What operand you wish to use for the calculation |
|
| 667 | + * @return mixed string|DateTime return whatever type came in. |
|
| 668 | + */ |
|
| 669 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 670 | + { |
|
| 671 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 672 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 673 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 674 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 675 | + } else { |
|
| 676 | + //error |
|
| 677 | + return $DateTime_or_timestamp; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 684 | + * and spit out the js and moment.js equivalent formats. |
|
| 685 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 686 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 687 | + * time picker. |
|
| 688 | + * |
|
| 689 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 690 | + * @param null $date_format_string |
|
| 691 | + * @param null $time_format_string |
|
| 692 | + * @return array |
|
| 693 | + * array( |
|
| 694 | + * 'js' => array ( |
|
| 695 | + * 'date' => //date format |
|
| 696 | + * 'time' => //time format |
|
| 697 | + * ), |
|
| 698 | + * 'moment' => //date and time format. |
|
| 699 | + * ) |
|
| 700 | + */ |
|
| 701 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 702 | + $date_format_string = null, |
|
| 703 | + $time_format_string = null |
|
| 704 | + ) { |
|
| 705 | + if ($date_format_string === null) { |
|
| 706 | + $date_format_string = get_option('date_format'); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if ($time_format_string === null) { |
|
| 710 | + $time_format_string = get_option('time_format'); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 714 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 715 | + |
|
| 716 | + return array( |
|
| 717 | + 'js' => array( |
|
| 718 | + 'date' => $date_format['js'], |
|
| 719 | + 'time' => $time_format['js'], |
|
| 720 | + ), |
|
| 721 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 722 | + ); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * This converts incoming format string into js and moment variations. |
|
| 728 | + * |
|
| 729 | + * @param string $format_string incoming php format string |
|
| 730 | + * @return array js and moment formats. |
|
| 731 | + */ |
|
| 732 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 733 | + { |
|
| 734 | + /** |
|
| 735 | + * This is a map of symbols for formats. |
|
| 736 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 737 | + * |
|
| 738 | + * @var array |
|
| 739 | + */ |
|
| 740 | + $symbols_map = array( |
|
| 741 | + // Day |
|
| 742 | + //01 |
|
| 743 | + 'd' => array( |
|
| 744 | + 'js' => 'dd', |
|
| 745 | + 'moment' => 'DD', |
|
| 746 | + ), |
|
| 747 | + //Mon |
|
| 748 | + 'D' => array( |
|
| 749 | + 'js' => 'D', |
|
| 750 | + 'moment' => 'ddd', |
|
| 751 | + ), |
|
| 752 | + //1,2,...31 |
|
| 753 | + 'j' => array( |
|
| 754 | + 'js' => 'd', |
|
| 755 | + 'moment' => 'D', |
|
| 756 | + ), |
|
| 757 | + //Monday |
|
| 758 | + 'l' => array( |
|
| 759 | + 'js' => 'DD', |
|
| 760 | + 'moment' => 'dddd', |
|
| 761 | + ), |
|
| 762 | + //ISO numeric representation of the day of the week (1-6) |
|
| 763 | + 'N' => array( |
|
| 764 | + 'js' => '', |
|
| 765 | + 'moment' => 'E', |
|
| 766 | + ), |
|
| 767 | + //st,nd.rd |
|
| 768 | + 'S' => array( |
|
| 769 | + 'js' => '', |
|
| 770 | + 'moment' => 'o', |
|
| 771 | + ), |
|
| 772 | + //numeric representation of day of week (0-6) |
|
| 773 | + 'w' => array( |
|
| 774 | + 'js' => '', |
|
| 775 | + 'moment' => 'd', |
|
| 776 | + ), |
|
| 777 | + //day of year starting from 0 (0-365) |
|
| 778 | + 'z' => array( |
|
| 779 | + 'js' => 'o', |
|
| 780 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 781 | + ), |
|
| 782 | + // Week |
|
| 783 | + //ISO-8601 week number of year (weeks starting on monday) |
|
| 784 | + 'W' => array( |
|
| 785 | + 'js' => '', |
|
| 786 | + 'moment' => 'w', |
|
| 787 | + ), |
|
| 788 | + // Month |
|
| 789 | + // January...December |
|
| 790 | + 'F' => array( |
|
| 791 | + 'js' => 'MM', |
|
| 792 | + 'moment' => 'MMMM', |
|
| 793 | + ), |
|
| 794 | + //01...12 |
|
| 795 | + 'm' => array( |
|
| 796 | + 'js' => 'mm', |
|
| 797 | + 'moment' => 'MM', |
|
| 798 | + ), |
|
| 799 | + //Jan...Dec |
|
| 800 | + 'M' => array( |
|
| 801 | + 'js' => 'M', |
|
| 802 | + 'moment' => 'MMM', |
|
| 803 | + ), |
|
| 804 | + //1-12 |
|
| 805 | + 'n' => array( |
|
| 806 | + 'js' => 'm', |
|
| 807 | + 'moment' => 'M', |
|
| 808 | + ), |
|
| 809 | + //number of days in given month |
|
| 810 | + 't' => array( |
|
| 811 | + 'js' => '', |
|
| 812 | + 'moment' => '', |
|
| 813 | + ), |
|
| 814 | + // Year |
|
| 815 | + //whether leap year or not 1/0 |
|
| 816 | + 'L' => array( |
|
| 817 | + 'js' => '', |
|
| 818 | + 'moment' => '', |
|
| 819 | + ), |
|
| 820 | + //ISO-8601 year number |
|
| 821 | + 'o' => array( |
|
| 822 | + 'js' => '', |
|
| 823 | + 'moment' => 'GGGG', |
|
| 824 | + ), |
|
| 825 | + //1999...2003 |
|
| 826 | + 'Y' => array( |
|
| 827 | + 'js' => 'yy', |
|
| 828 | + 'moment' => 'YYYY', |
|
| 829 | + ), |
|
| 830 | + //99...03 |
|
| 831 | + 'y' => array( |
|
| 832 | + 'js' => 'y', |
|
| 833 | + 'moment' => 'YY', |
|
| 834 | + ), |
|
| 835 | + // Time |
|
| 836 | + // am/pm |
|
| 837 | + 'a' => array( |
|
| 838 | + 'js' => 'tt', |
|
| 839 | + 'moment' => 'a', |
|
| 840 | + ), |
|
| 841 | + // AM/PM |
|
| 842 | + 'A' => array( |
|
| 843 | + 'js' => 'TT', |
|
| 844 | + 'moment' => 'A', |
|
| 845 | + ), |
|
| 846 | + // Swatch Internet Time?!? |
|
| 847 | + 'B' => array( |
|
| 848 | + 'js' => '', |
|
| 849 | + 'moment' => '', |
|
| 850 | + ), |
|
| 851 | + //1...12 |
|
| 852 | + 'g' => array( |
|
| 853 | + 'js' => 'h', |
|
| 854 | + 'moment' => 'h', |
|
| 855 | + ), |
|
| 856 | + //0...23 |
|
| 857 | + 'G' => array( |
|
| 858 | + 'js' => 'H', |
|
| 859 | + 'moment' => 'H', |
|
| 860 | + ), |
|
| 861 | + //01...12 |
|
| 862 | + 'h' => array( |
|
| 863 | + 'js' => 'hh', |
|
| 864 | + 'moment' => 'hh', |
|
| 865 | + ), |
|
| 866 | + //00...23 |
|
| 867 | + 'H' => array( |
|
| 868 | + 'js' => 'HH', |
|
| 869 | + 'moment' => 'HH', |
|
| 870 | + ), |
|
| 871 | + //00..59 |
|
| 872 | + 'i' => array( |
|
| 873 | + 'js' => 'mm', |
|
| 874 | + 'moment' => 'mm', |
|
| 875 | + ), |
|
| 876 | + //seconds... 00...59 |
|
| 877 | + 's' => array( |
|
| 878 | + 'js' => 'ss', |
|
| 879 | + 'moment' => 'ss', |
|
| 880 | + ), |
|
| 881 | + //microseconds |
|
| 882 | + 'u' => array( |
|
| 883 | + 'js' => '', |
|
| 884 | + 'moment' => '', |
|
| 885 | + ), |
|
| 886 | + ); |
|
| 887 | + $jquery_ui_format = ""; |
|
| 888 | + $moment_format = ""; |
|
| 889 | + $escaping = false; |
|
| 890 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 891 | + $char = $format_string[$i]; |
|
| 892 | + if ($char === '\\') { // PHP date format escaping character |
|
| 893 | + $i++; |
|
| 894 | + if ($escaping) { |
|
| 895 | + $jquery_ui_format .= $format_string[$i]; |
|
| 896 | + $moment_format .= $format_string[$i]; |
|
| 897 | + } else { |
|
| 898 | + $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 899 | + $moment_format .= $format_string[$i]; |
|
| 900 | + } |
|
| 901 | + $escaping = true; |
|
| 902 | + } else { |
|
| 903 | + if ($escaping) { |
|
| 904 | + $jquery_ui_format .= "'"; |
|
| 905 | + $moment_format .= "'"; |
|
| 906 | + $escaping = false; |
|
| 907 | + } |
|
| 908 | + if (isset($symbols_map[$char])) { |
|
| 909 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 910 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 911 | + } else { |
|
| 912 | + $jquery_ui_format .= $char; |
|
| 913 | + $moment_format .= $char; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + } |
|
| 917 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 923 | + * |
|
| 924 | + * @param string $format_string Incoming format string for php date(). |
|
| 925 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 926 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 927 | + * indicate failed validations. |
|
| 928 | + */ |
|
| 929 | + public static function validate_format_string($format_string) |
|
| 930 | + { |
|
| 931 | + $error_msg = array(); |
|
| 932 | + //time format checks |
|
| 933 | + switch (true) { |
|
| 934 | + case strpos($format_string, 'h') !== false : |
|
| 935 | + case strpos($format_string, 'g') !== false : |
|
| 936 | + /** |
|
| 937 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 938 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 939 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 940 | + */ |
|
| 941 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 942 | + $error_msg[] = __('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".', |
|
| 943 | + 'event_espresso'); |
|
| 944 | + } |
|
| 945 | + break; |
|
| 946 | + |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + return empty($error_msg) ? true : $error_msg; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 955 | + * very next day then this method will return true. |
|
| 956 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 957 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 958 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 959 | + * |
|
| 960 | + * @param mixed $date_1 |
|
| 961 | + * @param mixed $date_2 |
|
| 962 | + * @return bool |
|
| 963 | + */ |
|
| 964 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 965 | + { |
|
| 966 | + |
|
| 967 | + if ( |
|
| 968 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | + ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 970 | + ) { |
|
| 971 | + return false; |
|
| 972 | + } |
|
| 973 | + return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 979 | + * Functions. |
|
| 980 | + * |
|
| 981 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 982 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 983 | + * @return string |
|
| 984 | + */ |
|
| 985 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 986 | + { |
|
| 987 | + try { |
|
| 988 | + /** need to account for timezone offset on the selects */ |
|
| 989 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 990 | + } catch (Exception $e) { |
|
| 991 | + $DateTimeZone = null; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 996 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 997 | + */ |
|
| 998 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 999 | + $query_interval = $offset < 0 |
|
| 1000 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1002 | + return $query_interval; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1007 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1008 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1009 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1010 | + * (although note that we remove any HTML that may be added) |
|
| 1011 | + * |
|
| 1012 | + * @return string |
|
| 1013 | + */ |
|
| 1014 | + public static function get_timezone_string_for_display() |
|
| 1015 | + { |
|
| 1016 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1017 | + if (! empty($pretty_timezone)) { |
|
| 1018 | + return esc_html($pretty_timezone); |
|
| 1019 | + } |
|
| 1020 | + $timezone_string = get_option('timezone_string'); |
|
| 1021 | + if ($timezone_string) { |
|
| 1022 | + static $mo_loaded = false; |
|
| 1023 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1024 | + if (! $mo_loaded) { |
|
| 1025 | + $locale = get_locale(); |
|
| 1026 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1027 | + load_textdomain('continents-cities', $mofile); |
|
| 1028 | + $mo_loaded = true; |
|
| 1029 | + } |
|
| 1030 | + //well that was easy. |
|
| 1031 | + $parts = explode('/', $timezone_string); |
|
| 1032 | + //remove the continent |
|
| 1033 | + unset($parts[0]); |
|
| 1034 | + $t_parts = array(); |
|
| 1035 | + foreach ($parts as $part) { |
|
| 1036 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1037 | + } |
|
| 1038 | + return implode(' - ', $t_parts); |
|
| 1039 | + } |
|
| 1040 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1041 | + $gmt_offset = get_option('gmt_offset'); |
|
| 1042 | + if (intval($gmt_offset) >= 0) { |
|
| 1043 | + $prefix = '+'; |
|
| 1044 | + } else { |
|
| 1045 | + $prefix = ''; |
|
| 1046 | + } |
|
| 1047 | + $parts = explode('.', (string)$gmt_offset); |
|
| 1048 | + if (count($parts) === 1) { |
|
| 1049 | + $parts[1] = '00'; |
|
| 1050 | + } else { |
|
| 1051 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1052 | + //to minutes, eg 30 or 15, respectively |
|
| 1053 | + $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | + $parts[1] = (string)$hour_fraction * 60; |
|
| 1055 | + } |
|
| 1056 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1063 | + * for a month using a string like "February" or "February 2017", |
|
| 1064 | + * and you don't specify a day as part of your string, |
|
| 1065 | + * then PHP will use whatever the current day of the month is. |
|
| 1066 | + * IF the current day of the month happens to be the 30th or 31st, |
|
| 1067 | + * then PHP gets really confused by a date like February 30, |
|
| 1068 | + * so instead of saying |
|
| 1069 | + * "Hey February only has 28 days (this year)... |
|
| 1070 | + * ...you must have meant the last day of the month!" |
|
| 1071 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1072 | + * because someone requesting February 30th obviously meant March 1st! |
|
| 1073 | + * The way around this is to always set the day to the first, |
|
| 1074 | + * so that the month will stay on the month you wanted. |
|
| 1075 | + * this method will add that "1" into your date regardless of the format. |
|
| 1076 | + * |
|
| 1077 | + * @param string $month |
|
| 1078 | + * @return string |
|
| 1079 | + */ |
|
| 1080 | + public static function first_of_month_timestamp($month = '') |
|
| 1081 | + { |
|
| 1082 | + $month = (string)$month; |
|
| 1083 | + $year = ''; |
|
| 1084 | + // check if the incoming string has a year in it or not |
|
| 1085 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1086 | + $year = $matches[0]; |
|
| 1087 | + // ten remove that from the month string as well as any spaces |
|
| 1088 | + $month = trim(str_replace($year, '', $month)); |
|
| 1089 | + // add a space before the year |
|
| 1090 | + $year = " {$year}"; |
|
| 1091 | + } |
|
| 1092 | + // return timestamp for something like "February 1 2017" |
|
| 1093 | + return strtotime("{$month} 1{$year}"); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1098 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1099 | + */ |
|
| 1100 | + public static function tomorrow() |
|
| 1101 | 1101 | { |
| 1102 | 1102 | //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
| 1103 | 1103 | //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
@@ -1107,135 +1107,135 @@ discard block |
||
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | |
| 1110 | - /** |
|
| 1111 | - * ** |
|
| 1112 | - * Gives a nicely-formatted list of timezone strings. |
|
| 1113 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1114 | - * |
|
| 1115 | - * @since 4.9.40.rc.008 |
|
| 1116 | - * @staticvar bool $mo_loaded |
|
| 1117 | - * @staticvar string $locale_loaded |
|
| 1118 | - * @param string $selected_zone Selected timezone. |
|
| 1119 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1120 | - * @return string |
|
| 1121 | - */ |
|
| 1122 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1123 | - { |
|
| 1124 | - static $mo_loaded = false, $locale_loaded = null; |
|
| 1125 | - |
|
| 1126 | - $continents = array( |
|
| 1127 | - 'Africa', |
|
| 1128 | - 'America', |
|
| 1129 | - 'Antarctica', |
|
| 1130 | - 'Arctic', |
|
| 1131 | - 'Asia', |
|
| 1132 | - 'Atlantic', |
|
| 1133 | - 'Australia', |
|
| 1134 | - 'Europe', |
|
| 1135 | - 'Indian', |
|
| 1136 | - 'Pacific', |
|
| 1137 | - ); |
|
| 1138 | - |
|
| 1139 | - // Load translations for continents and cities. |
|
| 1140 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1142 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1143 | - unload_textdomain('continents-cities'); |
|
| 1144 | - load_textdomain('continents-cities', $mofile); |
|
| 1145 | - $mo_loaded = true; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - $zonen = array(); |
|
| 1149 | - foreach (timezone_identifiers_list() as $zone) { |
|
| 1150 | - $zone = explode('/', $zone); |
|
| 1151 | - if (! in_array($zone[0], $continents)) { |
|
| 1152 | - continue; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1156 | - $exists = array( |
|
| 1157 | - 0 => (isset($zone[0]) && $zone[0]), |
|
| 1158 | - 1 => (isset($zone[1]) && $zone[1]), |
|
| 1159 | - 2 => (isset($zone[2]) && $zone[2]), |
|
| 1160 | - ); |
|
| 1161 | - $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
| 1162 | - $exists[4] = ($exists[1] && $exists[3]); |
|
| 1163 | - $exists[5] = ($exists[2] && $exists[3]); |
|
| 1164 | - |
|
| 1165 | - $zonen[] = array( |
|
| 1166 | - 'continent' => ($exists[0] ? $zone[0] : ''), |
|
| 1167 | - 'city' => ($exists[1] ? $zone[1] : ''), |
|
| 1168 | - 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
| 1169 | - 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
| 1170 | - 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
| 1171 | - 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
| 1172 | - ); |
|
| 1173 | - } |
|
| 1174 | - usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
| 1175 | - |
|
| 1176 | - $structure = array(); |
|
| 1177 | - |
|
| 1178 | - if (empty($selected_zone)) { |
|
| 1179 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - foreach ($zonen as $key => $zone) { |
|
| 1183 | - // Build value in an array to join later |
|
| 1184 | - $value = array($zone['continent']); |
|
| 1185 | - |
|
| 1186 | - if (empty($zone['city'])) { |
|
| 1187 | - // It's at the continent level (generally won't happen) |
|
| 1188 | - $display = $zone['t_continent']; |
|
| 1189 | - } else { |
|
| 1190 | - // It's inside a continent group |
|
| 1191 | - |
|
| 1192 | - // Continent optgroup |
|
| 1193 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | - $label = $zone['t_continent']; |
|
| 1195 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - // Add the city to the value |
|
| 1199 | - $value[] = $zone['city']; |
|
| 1200 | - |
|
| 1201 | - $display = $zone['t_city']; |
|
| 1202 | - if (! empty($zone['subcity'])) { |
|
| 1203 | - // Add the subcity to the value |
|
| 1204 | - $value[] = $zone['subcity']; |
|
| 1205 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - // Build the value |
|
| 1210 | - $value = join('/', $value); |
|
| 1211 | - $selected = ''; |
|
| 1212 | - if ($value === $selected_zone) { |
|
| 1213 | - $selected = 'selected="selected" '; |
|
| 1214 | - } |
|
| 1215 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1216 | - |
|
| 1217 | - // Close continent optgroup |
|
| 1218 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | - $structure[] = '</optgroup>'; |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - return join("\n", $structure); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1229 | - * |
|
| 1230 | - * @param int|WP_User $user_id |
|
| 1231 | - * @return string |
|
| 1232 | - */ |
|
| 1233 | - public static function get_user_locale($user_id = 0) |
|
| 1234 | - { |
|
| 1235 | - if (function_exists('get_user_locale')) { |
|
| 1236 | - return get_user_locale($user_id); |
|
| 1237 | - } |
|
| 1238 | - return get_locale(); |
|
| 1239 | - } |
|
| 1110 | + /** |
|
| 1111 | + * ** |
|
| 1112 | + * Gives a nicely-formatted list of timezone strings. |
|
| 1113 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1114 | + * |
|
| 1115 | + * @since 4.9.40.rc.008 |
|
| 1116 | + * @staticvar bool $mo_loaded |
|
| 1117 | + * @staticvar string $locale_loaded |
|
| 1118 | + * @param string $selected_zone Selected timezone. |
|
| 1119 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1120 | + * @return string |
|
| 1121 | + */ |
|
| 1122 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1123 | + { |
|
| 1124 | + static $mo_loaded = false, $locale_loaded = null; |
|
| 1125 | + |
|
| 1126 | + $continents = array( |
|
| 1127 | + 'Africa', |
|
| 1128 | + 'America', |
|
| 1129 | + 'Antarctica', |
|
| 1130 | + 'Arctic', |
|
| 1131 | + 'Asia', |
|
| 1132 | + 'Atlantic', |
|
| 1133 | + 'Australia', |
|
| 1134 | + 'Europe', |
|
| 1135 | + 'Indian', |
|
| 1136 | + 'Pacific', |
|
| 1137 | + ); |
|
| 1138 | + |
|
| 1139 | + // Load translations for continents and cities. |
|
| 1140 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1142 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1143 | + unload_textdomain('continents-cities'); |
|
| 1144 | + load_textdomain('continents-cities', $mofile); |
|
| 1145 | + $mo_loaded = true; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + $zonen = array(); |
|
| 1149 | + foreach (timezone_identifiers_list() as $zone) { |
|
| 1150 | + $zone = explode('/', $zone); |
|
| 1151 | + if (! in_array($zone[0], $continents)) { |
|
| 1152 | + continue; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1156 | + $exists = array( |
|
| 1157 | + 0 => (isset($zone[0]) && $zone[0]), |
|
| 1158 | + 1 => (isset($zone[1]) && $zone[1]), |
|
| 1159 | + 2 => (isset($zone[2]) && $zone[2]), |
|
| 1160 | + ); |
|
| 1161 | + $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
| 1162 | + $exists[4] = ($exists[1] && $exists[3]); |
|
| 1163 | + $exists[5] = ($exists[2] && $exists[3]); |
|
| 1164 | + |
|
| 1165 | + $zonen[] = array( |
|
| 1166 | + 'continent' => ($exists[0] ? $zone[0] : ''), |
|
| 1167 | + 'city' => ($exists[1] ? $zone[1] : ''), |
|
| 1168 | + 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
| 1169 | + 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
| 1170 | + 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
| 1171 | + 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
| 1172 | + ); |
|
| 1173 | + } |
|
| 1174 | + usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
| 1175 | + |
|
| 1176 | + $structure = array(); |
|
| 1177 | + |
|
| 1178 | + if (empty($selected_zone)) { |
|
| 1179 | + $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + foreach ($zonen as $key => $zone) { |
|
| 1183 | + // Build value in an array to join later |
|
| 1184 | + $value = array($zone['continent']); |
|
| 1185 | + |
|
| 1186 | + if (empty($zone['city'])) { |
|
| 1187 | + // It's at the continent level (generally won't happen) |
|
| 1188 | + $display = $zone['t_continent']; |
|
| 1189 | + } else { |
|
| 1190 | + // It's inside a continent group |
|
| 1191 | + |
|
| 1192 | + // Continent optgroup |
|
| 1193 | + if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | + $label = $zone['t_continent']; |
|
| 1195 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + // Add the city to the value |
|
| 1199 | + $value[] = $zone['city']; |
|
| 1200 | + |
|
| 1201 | + $display = $zone['t_city']; |
|
| 1202 | + if (! empty($zone['subcity'])) { |
|
| 1203 | + // Add the subcity to the value |
|
| 1204 | + $value[] = $zone['subcity']; |
|
| 1205 | + $display .= ' - ' . $zone['t_subcity']; |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + // Build the value |
|
| 1210 | + $value = join('/', $value); |
|
| 1211 | + $selected = ''; |
|
| 1212 | + if ($value === $selected_zone) { |
|
| 1213 | + $selected = 'selected="selected" '; |
|
| 1214 | + } |
|
| 1215 | + $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1216 | + |
|
| 1217 | + // Close continent optgroup |
|
| 1218 | + if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | + $structure[] = '</optgroup>'; |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + return join("\n", $structure); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1229 | + * |
|
| 1230 | + * @param int|WP_User $user_id |
|
| 1231 | + * @return string |
|
| 1232 | + */ |
|
| 1233 | + public static function get_user_locale($user_id = 0) |
|
| 1234 | + { |
|
| 1235 | + if (function_exists('get_user_locale')) { |
|
| 1236 | + return get_user_locale($user_id); |
|
| 1237 | + } |
|
| 1238 | + return get_locale(); |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | 1241 | }// end class EEH_DTT_Helper |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | new DateTimeZone($timezone_string); |
| 75 | 75 | } catch (Exception $e) { |
| 76 | 76 | // sometimes we take exception to exceptions |
| 77 | - if (! $throw_error) { |
|
| 77 | + if ( ! $throw_error) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | throw new EE_Error( |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | $offset = get_option('gmt_offset'); |
| 162 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 162 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
| 178 | 178 | { |
| 179 | 179 | //make sure $gmt_offset is int |
| 180 | - $gmt_offset = (int)$gmt_offset; |
|
| 180 | + $gmt_offset = (int) $gmt_offset; |
|
| 181 | 181 | switch ($gmt_offset) { |
| 182 | 182 | //-12 |
| 183 | 183 | case -43200: |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
| 351 | 351 | { |
| 352 | 352 | $transitions = self::get_timezone_transitions($date_time_zone, $time); |
| 353 | - if (! isset($transitions['offset'])) { |
|
| 353 | + if ( ! isset($transitions['offset'])) { |
|
| 354 | 354 | throw new DomainException(); |
| 355 | 355 | } |
| 356 | 356 | return $transitions['offset']; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | public static function timezone_select_input($timezone_string = '') |
| 365 | 365 | { |
| 366 | 366 | // get WP date time format |
| 367 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 367 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 368 | 368 | // if passed a value, then use that, else get WP option |
| 369 | 369 | $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
| 370 | 370 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | // Create a UTC+- zone if no timezone string exists |
| 377 | 377 | $check_zone_info = false; |
| 378 | 378 | if ($gmt_offset > 0) { |
| 379 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 379 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 380 | 380 | } elseif ($gmt_offset < 0) { |
| 381 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 381 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 382 | 382 | } else { |
| 383 | 383 | $timezone_string = 'UTC'; |
| 384 | 384 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | __('%1$sUTC%2$s time is %3$s'), |
| 401 | 401 | '<abbr title="Coordinated Universal Time">', |
| 402 | 402 | '</abbr>', |
| 403 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 403 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 404 | 404 | ); |
| 405 | 405 | ?></span> |
| 406 | - <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 407 | - <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
| 406 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 407 | + <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 408 | 408 | <?php endif; ?> |
| 409 | 409 | |
| 410 | 410 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -437,11 +437,10 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | if ($found) { |
| 439 | 439 | $message = $tr['isdst'] ? |
| 440 | - __(' Daylight saving time begins on: %s.') : |
|
| 441 | - __(' Standard time begins on: %s.'); |
|
| 440 | + __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.'); |
|
| 442 | 441 | // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
| 443 | 442 | printf($message, |
| 444 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 443 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
| 445 | 444 | } else { |
| 446 | 445 | _e('This timezone does not observe daylight saving time.'); |
| 447 | 446 | } |
@@ -469,13 +468,13 @@ discard block |
||
| 469 | 468 | */ |
| 470 | 469 | public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
| 471 | 470 | { |
| 472 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 471 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 473 | 472 | $timezone_string = self::get_valid_timezone_string($timezone_string); |
| 474 | 473 | $TimeZone = new DateTimeZone($timezone_string); |
| 475 | 474 | |
| 476 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 475 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 477 | 476 | $offset = timezone_offset_get($TimeZone, $DateTime); |
| 478 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 477 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 479 | 478 | } |
| 480 | 479 | |
| 481 | 480 | |
@@ -558,7 +557,7 @@ discard block |
||
| 558 | 557 | */ |
| 559 | 558 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 560 | 559 | { |
| 561 | - if (! $DateTime instanceof DateTime) { |
|
| 560 | + if ( ! $DateTime instanceof DateTime) { |
|
| 562 | 561 | throw new EE_Error( |
| 563 | 562 | sprintf( |
| 564 | 563 | __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -568,25 +567,25 @@ discard block |
||
| 568 | 567 | } |
| 569 | 568 | switch ($period) { |
| 570 | 569 | case 'years' : |
| 571 | - $value = 'P' . $value . 'Y'; |
|
| 570 | + $value = 'P'.$value.'Y'; |
|
| 572 | 571 | break; |
| 573 | 572 | case 'months' : |
| 574 | - $value = 'P' . $value . 'M'; |
|
| 573 | + $value = 'P'.$value.'M'; |
|
| 575 | 574 | break; |
| 576 | 575 | case 'weeks' : |
| 577 | - $value = 'P' . $value . 'W'; |
|
| 576 | + $value = 'P'.$value.'W'; |
|
| 578 | 577 | break; |
| 579 | 578 | case 'days' : |
| 580 | - $value = 'P' . $value . 'D'; |
|
| 579 | + $value = 'P'.$value.'D'; |
|
| 581 | 580 | break; |
| 582 | 581 | case 'hours' : |
| 583 | - $value = 'PT' . $value . 'H'; |
|
| 582 | + $value = 'PT'.$value.'H'; |
|
| 584 | 583 | break; |
| 585 | 584 | case 'minutes' : |
| 586 | - $value = 'PT' . $value . 'M'; |
|
| 585 | + $value = 'PT'.$value.'M'; |
|
| 587 | 586 | break; |
| 588 | 587 | case 'seconds' : |
| 589 | - $value = 'PT' . $value . 'S'; |
|
| 588 | + $value = 'PT'.$value.'S'; |
|
| 590 | 589 | break; |
| 591 | 590 | } |
| 592 | 591 | switch ($operand) { |
@@ -614,7 +613,7 @@ discard block |
||
| 614 | 613 | */ |
| 615 | 614 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 616 | 615 | { |
| 617 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 616 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | 617 | throw new EE_Error( |
| 619 | 618 | sprintf( |
| 620 | 619 | __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -718,7 +717,7 @@ discard block |
||
| 718 | 717 | 'date' => $date_format['js'], |
| 719 | 718 | 'time' => $time_format['js'], |
| 720 | 719 | ), |
| 721 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 720 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 722 | 721 | ); |
| 723 | 722 | } |
| 724 | 723 | |
@@ -737,7 +736,7 @@ discard block |
||
| 737 | 736 | * |
| 738 | 737 | * @var array |
| 739 | 738 | */ |
| 740 | - $symbols_map = array( |
|
| 739 | + $symbols_map = array( |
|
| 741 | 740 | // Day |
| 742 | 741 | //01 |
| 743 | 742 | 'd' => array( |
@@ -895,7 +894,7 @@ discard block |
||
| 895 | 894 | $jquery_ui_format .= $format_string[$i]; |
| 896 | 895 | $moment_format .= $format_string[$i]; |
| 897 | 896 | } else { |
| 898 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 897 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 899 | 898 | $moment_format .= $format_string[$i]; |
| 900 | 899 | } |
| 901 | 900 | $escaping = true; |
@@ -965,7 +964,7 @@ discard block |
||
| 965 | 964 | { |
| 966 | 965 | |
| 967 | 966 | if ( |
| 968 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 967 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | 968 | ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
| 970 | 969 | ) { |
| 971 | 970 | return false; |
@@ -997,8 +996,8 @@ discard block |
||
| 997 | 996 | */ |
| 998 | 997 | $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
| 999 | 998 | $query_interval = $offset < 0 |
| 1000 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 999 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 1000 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 1002 | 1001 | return $query_interval; |
| 1003 | 1002 | } |
| 1004 | 1003 | |
@@ -1014,16 +1013,16 @@ discard block |
||
| 1014 | 1013 | public static function get_timezone_string_for_display() |
| 1015 | 1014 | { |
| 1016 | 1015 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 1017 | - if (! empty($pretty_timezone)) { |
|
| 1016 | + if ( ! empty($pretty_timezone)) { |
|
| 1018 | 1017 | return esc_html($pretty_timezone); |
| 1019 | 1018 | } |
| 1020 | 1019 | $timezone_string = get_option('timezone_string'); |
| 1021 | 1020 | if ($timezone_string) { |
| 1022 | 1021 | static $mo_loaded = false; |
| 1023 | 1022 | // Load translations for continents and cities just like wp_timezone_choice does |
| 1024 | - if (! $mo_loaded) { |
|
| 1023 | + if ( ! $mo_loaded) { |
|
| 1025 | 1024 | $locale = get_locale(); |
| 1026 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1025 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 1027 | 1026 | load_textdomain('continents-cities', $mofile); |
| 1028 | 1027 | $mo_loaded = true; |
| 1029 | 1028 | } |
@@ -1044,16 +1043,16 @@ discard block |
||
| 1044 | 1043 | } else { |
| 1045 | 1044 | $prefix = ''; |
| 1046 | 1045 | } |
| 1047 | - $parts = explode('.', (string)$gmt_offset); |
|
| 1046 | + $parts = explode('.', (string) $gmt_offset); |
|
| 1048 | 1047 | if (count($parts) === 1) { |
| 1049 | 1048 | $parts[1] = '00'; |
| 1050 | 1049 | } else { |
| 1051 | 1050 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 1052 | 1051 | //to minutes, eg 30 or 15, respectively |
| 1053 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 1052 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 1053 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 1055 | 1054 | } |
| 1056 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1055 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 1057 | 1056 | } |
| 1058 | 1057 | |
| 1059 | 1058 | |
@@ -1079,7 +1078,7 @@ discard block |
||
| 1079 | 1078 | */ |
| 1080 | 1079 | public static function first_of_month_timestamp($month = '') |
| 1081 | 1080 | { |
| 1082 | - $month = (string)$month; |
|
| 1081 | + $month = (string) $month; |
|
| 1083 | 1082 | $year = ''; |
| 1084 | 1083 | // check if the incoming string has a year in it or not |
| 1085 | 1084 | if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
@@ -1103,7 +1102,7 @@ discard block |
||
| 1103 | 1102 | //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
| 1104 | 1103 | //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
| 1105 | 1104 | //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
| 1106 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset()*-1); |
|
| 1105 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 1107 | 1106 | } |
| 1108 | 1107 | |
| 1109 | 1108 | |
@@ -1137,9 +1136,9 @@ discard block |
||
| 1137 | 1136 | ); |
| 1138 | 1137 | |
| 1139 | 1138 | // Load translations for continents and cities. |
| 1140 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1139 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | 1140 | $locale_loaded = $locale ? $locale : get_locale(); |
| 1142 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1141 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
| 1143 | 1142 | unload_textdomain('continents-cities'); |
| 1144 | 1143 | load_textdomain('continents-cities', $mofile); |
| 1145 | 1144 | $mo_loaded = true; |
@@ -1148,12 +1147,12 @@ discard block |
||
| 1148 | 1147 | $zonen = array(); |
| 1149 | 1148 | foreach (timezone_identifiers_list() as $zone) { |
| 1150 | 1149 | $zone = explode('/', $zone); |
| 1151 | - if (! in_array($zone[0], $continents)) { |
|
| 1150 | + if ( ! in_array($zone[0], $continents)) { |
|
| 1152 | 1151 | continue; |
| 1153 | 1152 | } |
| 1154 | 1153 | |
| 1155 | 1154 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
| 1156 | - $exists = array( |
|
| 1155 | + $exists = array( |
|
| 1157 | 1156 | 0 => (isset($zone[0]) && $zone[0]), |
| 1158 | 1157 | 1 => (isset($zone[1]) && $zone[1]), |
| 1159 | 1158 | 2 => (isset($zone[2]) && $zone[2]), |
@@ -1176,7 +1175,7 @@ discard block |
||
| 1176 | 1175 | $structure = array(); |
| 1177 | 1176 | |
| 1178 | 1177 | if (empty($selected_zone)) { |
| 1179 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1178 | + $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>'; |
|
| 1180 | 1179 | } |
| 1181 | 1180 | |
| 1182 | 1181 | foreach ($zonen as $key => $zone) { |
@@ -1190,19 +1189,19 @@ discard block |
||
| 1190 | 1189 | // It's inside a continent group |
| 1191 | 1190 | |
| 1192 | 1191 | // Continent optgroup |
| 1193 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1192 | + if ( ! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | 1193 | $label = $zone['t_continent']; |
| 1195 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1194 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
| 1196 | 1195 | } |
| 1197 | 1196 | |
| 1198 | 1197 | // Add the city to the value |
| 1199 | 1198 | $value[] = $zone['city']; |
| 1200 | 1199 | |
| 1201 | 1200 | $display = $zone['t_city']; |
| 1202 | - if (! empty($zone['subcity'])) { |
|
| 1201 | + if ( ! empty($zone['subcity'])) { |
|
| 1203 | 1202 | // Add the subcity to the value |
| 1204 | 1203 | $value[] = $zone['subcity']; |
| 1205 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1204 | + $display .= ' - '.$zone['t_subcity']; |
|
| 1206 | 1205 | } |
| 1207 | 1206 | } |
| 1208 | 1207 | |
@@ -1212,10 +1211,10 @@ discard block |
||
| 1212 | 1211 | if ($value === $selected_zone) { |
| 1213 | 1212 | $selected = 'selected="selected" '; |
| 1214 | 1213 | } |
| 1215 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1214 | + $structure[] = '<option '.$selected.'value="'.esc_attr($value).'">'.esc_html($display)."</option>"; |
|
| 1216 | 1215 | |
| 1217 | 1216 | // Close continent optgroup |
| 1218 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1217 | + if ( ! empty($zone['city']) && ( ! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | 1218 | $structure[] = '</optgroup>'; |
| 1220 | 1219 | } |
| 1221 | 1220 | } |
@@ -15,395 +15,395 @@ discard block |
||
| 15 | 15 | final class EE_Admin implements InterminableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @access private |
|
| 20 | - * @var EE_Admin $_instance |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - *@ singleton method used to instantiate class object |
|
| 27 | - *@ access public |
|
| 28 | - *@ return class instance |
|
| 29 | - * |
|
| 30 | - * @throws \EE_Error |
|
| 31 | - */ |
|
| 32 | - public static function instance() |
|
| 33 | - { |
|
| 34 | - // check if class object is instantiated |
|
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | - self::$_instance = new self(); |
|
| 37 | - } |
|
| 38 | - return self::$_instance; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return EE_Admin |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - public static function reset() |
|
| 47 | - { |
|
| 48 | - self::$_instance = null; |
|
| 49 | - return self::instance(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * class constructor |
|
| 55 | - * |
|
| 56 | - * @throws \EE_Error |
|
| 57 | - */ |
|
| 58 | - protected function __construct() |
|
| 59 | - { |
|
| 60 | - // define global EE_Admin constants |
|
| 61 | - $this->_define_all_constants(); |
|
| 62 | - // set autoloaders for our admin page classes based on included path information |
|
| 63 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | - // admin hooks |
|
| 65 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | - // load EE_Request_Handler early |
|
| 67 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | - |
|
| 78 | - //reset Environment config (we only do this on admin page loads); |
|
| 79 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | - |
|
| 81 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * _define_all_constants |
|
| 87 | - * define constants that are set globally for all admin pages |
|
| 88 | - * |
|
| 89 | - * @access private |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - private function _define_all_constants() |
|
| 93 | - { |
|
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | - * |
|
| 107 | - * @access public |
|
| 108 | - * @param array $links |
|
| 109 | - * @param string $plugin |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function filter_plugin_actions($links, $plugin) |
|
| 113 | - { |
|
| 114 | - // set $main_file in stone |
|
| 115 | - static $main_file; |
|
| 116 | - // if $main_file is not set yet |
|
| 117 | - if (! $main_file) { |
|
| 118 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | - } |
|
| 120 | - if ($plugin === $main_file) { |
|
| 121 | - // compare current plugin to this one |
|
| 122 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | - . '</a>'; |
|
| 127 | - array_unshift($links, $maintenance_link); |
|
| 128 | - } else { |
|
| 129 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | - . esc_html__('Settings', 'event_espresso') |
|
| 131 | - . '</a>'; |
|
| 132 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | - . esc_html__('Events', 'event_espresso') |
|
| 134 | - . '</a>'; |
|
| 135 | - // add before other links |
|
| 136 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return $links; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * _get_request |
|
| 145 | - * |
|
| 146 | - * @access public |
|
| 147 | - * @return void |
|
| 148 | - * @throws EE_Error |
|
| 149 | - * @throws ReflectionException |
|
| 150 | - */ |
|
| 151 | - public function get_request() |
|
| 152 | - { |
|
| 153 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * hide_admin_pages_except_maintenance_mode |
|
| 160 | - * |
|
| 161 | - * @access public |
|
| 162 | - * @param array $admin_page_folder_names |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | - { |
|
| 167 | - return array( |
|
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | - * EE_Front_Controller's init phases have run |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @return void |
|
| 181 | - * @throws EE_Error |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - */ |
|
| 184 | - public function init() |
|
| 185 | - { |
|
| 186 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | - //ok so we want to enable the entire admin |
|
| 189 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | - add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | - add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | - //at a glance dashboard widget |
|
| 193 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | - //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | - } |
|
| 197 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | - try { |
|
| 200 | - //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | - } catch (EE_Error $e) { |
|
| 203 | - $e->get_error(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | - * |
|
| 222 | - * @param object $post_type WP post type object |
|
| 223 | - * @return object WP post type object |
|
| 224 | - */ |
|
| 225 | - public function remove_pages_from_nav_menu($post_type) |
|
| 226 | - { |
|
| 227 | - //if this isn't the "pages" post type let's get out |
|
| 228 | - if ($post_type->name !== 'page') { |
|
| 229 | - return $post_type; |
|
| 230 | - } |
|
| 231 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | - |
|
| 233 | - $post_type->_default_query = array( |
|
| 234 | - 'post__not_in' => $critical_pages, |
|
| 235 | - ); |
|
| 236 | - return $post_type; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | - * metaboxes get shown as well |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | - { |
|
| 249 | - global $wp_meta_boxes, $pagenow; |
|
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | - return; |
|
| 252 | - } |
|
| 253 | - $user = wp_get_current_user(); |
|
| 254 | - //has this been done yet? |
|
| 255 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | - return; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | - $initial_meta_boxes = apply_filters( |
|
| 261 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | - array( |
|
| 263 | - 'nav-menu-theme-locations', |
|
| 264 | - 'add-page', |
|
| 265 | - 'add-custom-links', |
|
| 266 | - 'add-category', |
|
| 267 | - 'add-espresso_events', |
|
| 268 | - 'add-espresso_venues', |
|
| 269 | - 'add-espresso_event_categories', |
|
| 270 | - 'add-espresso_venue_categories', |
|
| 271 | - 'add-post-type-post', |
|
| 272 | - 'add-post-type-page', |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - if (is_array($hidden_meta_boxes)) { |
|
| 277 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | - if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | - unset($hidden_meta_boxes[$key]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | - * |
|
| 293 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | - * addons etc. |
|
| 295 | - * @access public |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public function register_custom_nav_menu_boxes() |
|
| 299 | - { |
|
| 300 | - add_meta_box( |
|
| 301 | - 'add-extra-nav-menu-pages', |
|
| 302 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | - array($this, 'ee_cpt_archive_pages'), |
|
| 304 | - 'nav-menus', |
|
| 305 | - 'side', |
|
| 306 | - 'core' |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | - * |
|
| 314 | - * @since 4.3.0 |
|
| 315 | - * @param string $link the original link generated by wp |
|
| 316 | - * @param int $id post id |
|
| 317 | - * @return string the (maybe) modified link |
|
| 318 | - */ |
|
| 319 | - public function modify_edit_post_link($link, $id) |
|
| 320 | - { |
|
| 321 | - if (! $post = get_post($id)) { |
|
| 322 | - return $link; |
|
| 323 | - } |
|
| 324 | - if ($post->post_type === 'espresso_attendees') { |
|
| 325 | - $query_args = array( |
|
| 326 | - 'action' => 'edit_attendee', |
|
| 327 | - 'post' => $id, |
|
| 328 | - ); |
|
| 329 | - return EEH_URL::add_query_args_and_nonce( |
|
| 330 | - $query_args, |
|
| 331 | - admin_url('admin.php?page=espresso_registrations') |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - return $link; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - public function ee_cpt_archive_pages() |
|
| 339 | - { |
|
| 340 | - global $nav_menu_selected_id; |
|
| 341 | - |
|
| 342 | - $db_fields = false; |
|
| 343 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | - $current_tab = 'event-archives'; |
|
| 345 | - |
|
| 346 | - /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 18 | + /** |
|
| 19 | + * @access private |
|
| 20 | + * @var EE_Admin $_instance |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + *@ singleton method used to instantiate class object |
|
| 27 | + *@ access public |
|
| 28 | + *@ return class instance |
|
| 29 | + * |
|
| 30 | + * @throws \EE_Error |
|
| 31 | + */ |
|
| 32 | + public static function instance() |
|
| 33 | + { |
|
| 34 | + // check if class object is instantiated |
|
| 35 | + if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | + self::$_instance = new self(); |
|
| 37 | + } |
|
| 38 | + return self::$_instance; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return EE_Admin |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + public static function reset() |
|
| 47 | + { |
|
| 48 | + self::$_instance = null; |
|
| 49 | + return self::instance(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * class constructor |
|
| 55 | + * |
|
| 56 | + * @throws \EE_Error |
|
| 57 | + */ |
|
| 58 | + protected function __construct() |
|
| 59 | + { |
|
| 60 | + // define global EE_Admin constants |
|
| 61 | + $this->_define_all_constants(); |
|
| 62 | + // set autoloaders for our admin page classes based on included path information |
|
| 63 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | + // admin hooks |
|
| 65 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | + // load EE_Request_Handler early |
|
| 67 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | + |
|
| 78 | + //reset Environment config (we only do this on admin page loads); |
|
| 79 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | + |
|
| 81 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * _define_all_constants |
|
| 87 | + * define constants that are set globally for all admin pages |
|
| 88 | + * |
|
| 89 | + * @access private |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + private function _define_all_constants() |
|
| 93 | + { |
|
| 94 | + if (! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | + * |
|
| 107 | + * @access public |
|
| 108 | + * @param array $links |
|
| 109 | + * @param string $plugin |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function filter_plugin_actions($links, $plugin) |
|
| 113 | + { |
|
| 114 | + // set $main_file in stone |
|
| 115 | + static $main_file; |
|
| 116 | + // if $main_file is not set yet |
|
| 117 | + if (! $main_file) { |
|
| 118 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | + } |
|
| 120 | + if ($plugin === $main_file) { |
|
| 121 | + // compare current plugin to this one |
|
| 122 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | + . '</a>'; |
|
| 127 | + array_unshift($links, $maintenance_link); |
|
| 128 | + } else { |
|
| 129 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | + . esc_html__('Settings', 'event_espresso') |
|
| 131 | + . '</a>'; |
|
| 132 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | + . esc_html__('Events', 'event_espresso') |
|
| 134 | + . '</a>'; |
|
| 135 | + // add before other links |
|
| 136 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return $links; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * _get_request |
|
| 145 | + * |
|
| 146 | + * @access public |
|
| 147 | + * @return void |
|
| 148 | + * @throws EE_Error |
|
| 149 | + * @throws ReflectionException |
|
| 150 | + */ |
|
| 151 | + public function get_request() |
|
| 152 | + { |
|
| 153 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * hide_admin_pages_except_maintenance_mode |
|
| 160 | + * |
|
| 161 | + * @access public |
|
| 162 | + * @param array $admin_page_folder_names |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | + { |
|
| 167 | + return array( |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | + * EE_Front_Controller's init phases have run |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @return void |
|
| 181 | + * @throws EE_Error |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + */ |
|
| 184 | + public function init() |
|
| 185 | + { |
|
| 186 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | + //ok so we want to enable the entire admin |
|
| 189 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | + //at a glance dashboard widget |
|
| 193 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | + //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | + } |
|
| 197 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | + try { |
|
| 200 | + //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | + } catch (EE_Error $e) { |
|
| 203 | + $e->get_error(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | + * |
|
| 222 | + * @param object $post_type WP post type object |
|
| 223 | + * @return object WP post type object |
|
| 224 | + */ |
|
| 225 | + public function remove_pages_from_nav_menu($post_type) |
|
| 226 | + { |
|
| 227 | + //if this isn't the "pages" post type let's get out |
|
| 228 | + if ($post_type->name !== 'page') { |
|
| 229 | + return $post_type; |
|
| 230 | + } |
|
| 231 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | + |
|
| 233 | + $post_type->_default_query = array( |
|
| 234 | + 'post__not_in' => $critical_pages, |
|
| 235 | + ); |
|
| 236 | + return $post_type; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | + * metaboxes get shown as well |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | + { |
|
| 249 | + global $wp_meta_boxes, $pagenow; |
|
| 250 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + $user = wp_get_current_user(); |
|
| 254 | + //has this been done yet? |
|
| 255 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | + return; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | + $initial_meta_boxes = apply_filters( |
|
| 261 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | + array( |
|
| 263 | + 'nav-menu-theme-locations', |
|
| 264 | + 'add-page', |
|
| 265 | + 'add-custom-links', |
|
| 266 | + 'add-category', |
|
| 267 | + 'add-espresso_events', |
|
| 268 | + 'add-espresso_venues', |
|
| 269 | + 'add-espresso_event_categories', |
|
| 270 | + 'add-espresso_venue_categories', |
|
| 271 | + 'add-post-type-post', |
|
| 272 | + 'add-post-type-page', |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + if (is_array($hidden_meta_boxes)) { |
|
| 277 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | + unset($hidden_meta_boxes[$key]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | + * |
|
| 293 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | + * addons etc. |
|
| 295 | + * @access public |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public function register_custom_nav_menu_boxes() |
|
| 299 | + { |
|
| 300 | + add_meta_box( |
|
| 301 | + 'add-extra-nav-menu-pages', |
|
| 302 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | + array($this, 'ee_cpt_archive_pages'), |
|
| 304 | + 'nav-menus', |
|
| 305 | + 'side', |
|
| 306 | + 'core' |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | + * |
|
| 314 | + * @since 4.3.0 |
|
| 315 | + * @param string $link the original link generated by wp |
|
| 316 | + * @param int $id post id |
|
| 317 | + * @return string the (maybe) modified link |
|
| 318 | + */ |
|
| 319 | + public function modify_edit_post_link($link, $id) |
|
| 320 | + { |
|
| 321 | + if (! $post = get_post($id)) { |
|
| 322 | + return $link; |
|
| 323 | + } |
|
| 324 | + if ($post->post_type === 'espresso_attendees') { |
|
| 325 | + $query_args = array( |
|
| 326 | + 'action' => 'edit_attendee', |
|
| 327 | + 'post' => $id, |
|
| 328 | + ); |
|
| 329 | + return EEH_URL::add_query_args_and_nonce( |
|
| 330 | + $query_args, |
|
| 331 | + admin_url('admin.php?page=espresso_registrations') |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + return $link; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + public function ee_cpt_archive_pages() |
|
| 339 | + { |
|
| 340 | + global $nav_menu_selected_id; |
|
| 341 | + |
|
| 342 | + $db_fields = false; |
|
| 343 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | + $current_tab = 'event-archives'; |
|
| 345 | + |
|
| 346 | + /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 347 | 347 | $current_tab = 'search'; |
| 348 | 348 | }/**/ |
| 349 | 349 | |
| 350 | - $removed_args = array( |
|
| 351 | - 'action', |
|
| 352 | - 'customlink-tab', |
|
| 353 | - 'edit-menu-item', |
|
| 354 | - 'menu-item', |
|
| 355 | - 'page-tab', |
|
| 356 | - '_wpnonce', |
|
| 357 | - ); |
|
| 350 | + $removed_args = array( |
|
| 351 | + 'action', |
|
| 352 | + 'customlink-tab', |
|
| 353 | + 'edit-menu-item', |
|
| 354 | + 'menu-item', |
|
| 355 | + 'page-tab', |
|
| 356 | + '_wpnonce', |
|
| 357 | + ); |
|
| 358 | 358 | |
| 359 | - ?> |
|
| 359 | + ?> |
|
| 360 | 360 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 361 | 361 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 362 | 362 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
| 363 | 363 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
| 364 | 364 | href="<?php if ($nav_menu_selected_id) { |
| 365 | - echo esc_url( |
|
| 366 | - add_query_arg( |
|
| 367 | - 'extra-nav-menu-pages-tab', |
|
| 368 | - 'event-archives', |
|
| 369 | - remove_query_arg($removed_args) |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 365 | + echo esc_url( |
|
| 366 | + add_query_arg( |
|
| 367 | + 'extra-nav-menu-pages-tab', |
|
| 368 | + 'event-archives', |
|
| 369 | + remove_query_arg($removed_args) |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 373 | 373 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
| 374 | 374 | </a> |
| 375 | 375 | </li> |
| 376 | 376 | |
| 377 | 377 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 378 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | - ?>"> |
|
| 378 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | + ?>"> |
|
| 380 | 380 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 381 | 381 | <?php |
| 382 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | - $args['walker'] = $walker; |
|
| 384 | - echo walk_nav_menu_tree( |
|
| 385 | - array_map( |
|
| 386 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | - $pages |
|
| 388 | - ), |
|
| 389 | - 0, |
|
| 390 | - (object) $args |
|
| 391 | - ); |
|
| 392 | - ?> |
|
| 382 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | + $args['walker'] = $walker; |
|
| 384 | + echo walk_nav_menu_tree( |
|
| 385 | + array_map( |
|
| 386 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | + $pages |
|
| 388 | + ), |
|
| 389 | + 0, |
|
| 390 | + (object) $args |
|
| 391 | + ); |
|
| 392 | + ?> |
|
| 393 | 393 | </ul> |
| 394 | 394 | </div><!-- /.tabs-panel --> |
| 395 | 395 | |
| 396 | 396 | <p class="button-controls"> |
| 397 | 397 | <span class="list-controls"> |
| 398 | 398 | <a href="<?php |
| 399 | - echo esc_url(add_query_arg( |
|
| 400 | - array( |
|
| 401 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | - 'selectall' => 1, |
|
| 403 | - ), |
|
| 404 | - remove_query_arg($removed_args) |
|
| 405 | - )); |
|
| 406 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 399 | + echo esc_url(add_query_arg( |
|
| 400 | + array( |
|
| 401 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | + 'selectall' => 1, |
|
| 403 | + ), |
|
| 404 | + remove_query_arg($removed_args) |
|
| 405 | + )); |
|
| 406 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 407 | 407 | </span> |
| 408 | 408 | <span class="add-to-menu"> |
| 409 | 409 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -416,491 +416,491 @@ discard block |
||
| 416 | 416 | |
| 417 | 417 | </div><!-- /.posttypediv --> |
| 418 | 418 | <?php |
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns an array of event archive nav items. |
|
| 424 | - * |
|
| 425 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | - * method we use for getting the extra nav menu items |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - private function _get_extra_nav_menu_pages_items() |
|
| 430 | - { |
|
| 431 | - $menuitems[] = array( |
|
| 432 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | - ); |
|
| 436 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | - * the properties and converts it to the menu item object. |
|
| 443 | - * |
|
| 444 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | - * @param $menu_item_values |
|
| 446 | - * @return stdClass |
|
| 447 | - */ |
|
| 448 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | - { |
|
| 450 | - $menu_item = new stdClass(); |
|
| 451 | - $keys = array( |
|
| 452 | - 'ID' => 0, |
|
| 453 | - 'db_id' => 0, |
|
| 454 | - 'menu_item_parent' => 0, |
|
| 455 | - 'object_id' => -1, |
|
| 456 | - 'post_parent' => 0, |
|
| 457 | - 'type' => 'custom', |
|
| 458 | - 'object' => '', |
|
| 459 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | - 'title' => '', |
|
| 461 | - 'url' => '', |
|
| 462 | - 'target' => '', |
|
| 463 | - 'attr_title' => '', |
|
| 464 | - 'description' => '', |
|
| 465 | - 'classes' => array(), |
|
| 466 | - 'xfn' => '', |
|
| 467 | - ); |
|
| 468 | - |
|
| 469 | - foreach ($keys as $key => $value) { |
|
| 470 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | - } |
|
| 472 | - return $menu_item; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | - * EE_Admin_Page route is called. |
|
| 479 | - * |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - public function route_admin_request() |
|
| 483 | - { |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | - * |
|
| 490 | - * @return void |
|
| 491 | - */ |
|
| 492 | - public function wp_loaded() |
|
| 493 | - { |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * admin_init |
|
| 499 | - * |
|
| 500 | - * @access public |
|
| 501 | - * @return void |
|
| 502 | - * @throws EE_Error |
|
| 503 | - * @throws ReflectionException |
|
| 504 | - */ |
|
| 505 | - public function admin_init() |
|
| 506 | - { |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | - * - check if doing post processing. |
|
| 512 | - * - check if doing post processing of one of EE CPTs |
|
| 513 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | - */ |
|
| 515 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | - * Pages" tab in the EE General Settings Admin page. |
|
| 525 | - * This is for user-proofing. |
|
| 526 | - */ |
|
| 527 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | - * |
|
| 534 | - * @param string $output Current output. |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function modify_dropdown_pages($output) |
|
| 538 | - { |
|
| 539 | - //get critical pages |
|
| 540 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | - |
|
| 542 | - //split current output by line break for easier parsing. |
|
| 543 | - $split_output = explode("\n", $output); |
|
| 544 | - |
|
| 545 | - //loop through to remove any critical pages from the array. |
|
| 546 | - foreach ($critical_pages as $page_id) { |
|
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 548 | - foreach ($split_output as $key => $haystack) { |
|
| 549 | - if (strpos($haystack, $needle) !== false) { |
|
| 550 | - unset($split_output[$key]); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - //replace output with the new contents |
|
| 556 | - return implode("\n", $split_output); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | - * |
|
| 563 | - * @access public |
|
| 564 | - * @return void |
|
| 565 | - */ |
|
| 566 | - public function enqueue_admin_scripts() |
|
| 567 | - { |
|
| 568 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | - // calls. |
|
| 571 | - wp_enqueue_script( |
|
| 572 | - 'ee-inject-wp', |
|
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | - array('jquery'), |
|
| 575 | - EVENT_ESPRESSO_VERSION, |
|
| 576 | - true |
|
| 577 | - ); |
|
| 578 | - // register cookie script for future dependencies |
|
| 579 | - wp_register_script( |
|
| 580 | - 'jquery-cookie', |
|
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | - array('jquery'), |
|
| 583 | - '2.1', |
|
| 584 | - true |
|
| 585 | - ); |
|
| 586 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | - //joyride style |
|
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | - wp_register_style( |
|
| 592 | - 'ee-joyride-css', |
|
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | - array('joyride-css'), |
|
| 595 | - EVENT_ESPRESSO_VERSION |
|
| 596 | - ); |
|
| 597 | - wp_register_script( |
|
| 598 | - 'joyride-modernizr', |
|
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | - array(), |
|
| 601 | - '2.1', |
|
| 602 | - true |
|
| 603 | - ); |
|
| 604 | - //joyride JS |
|
| 605 | - wp_register_script( |
|
| 606 | - 'jquery-joyride', |
|
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | - array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | - '2.1', |
|
| 610 | - true |
|
| 611 | - ); |
|
| 612 | - // wanna go for a joyride? |
|
| 613 | - wp_enqueue_style('ee-joyride-css'); |
|
| 614 | - wp_enqueue_script('jquery-joyride'); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * display_admin_notices |
|
| 621 | - * |
|
| 622 | - * @access public |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public function display_admin_notices() |
|
| 626 | - { |
|
| 627 | - echo EE_Error::get_notices(); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * get_persistent_admin_notices |
|
| 633 | - * |
|
| 634 | - * @access public |
|
| 635 | - * @return void |
|
| 636 | - */ |
|
| 637 | - public function get_persistent_admin_notices() |
|
| 638 | - { |
|
| 639 | - // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | - $args = array( |
|
| 641 | - 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | - ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | - : '', |
|
| 644 | - 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | - ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | - : '', |
|
| 647 | - ); |
|
| 648 | - $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | - if (! get_option('timezone_string')) { |
|
| 654 | - EE_Error::add_persistent_admin_notice( |
|
| 655 | - 'datetime_fix_notice', |
|
| 656 | - sprintf( |
|
| 657 | - esc_html__( |
|
| 658 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | - 'event_espresso' |
|
| 660 | - ), |
|
| 661 | - '<strong>', |
|
| 662 | - '</strong>', |
|
| 663 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | - '</a>', |
|
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | - array( |
|
| 667 | - 'page' => 'espresso_maintenance_settings', |
|
| 668 | - 'action' => 'datetime_tools' |
|
| 669 | - ), |
|
| 670 | - admin_url('admin.php') |
|
| 671 | - ) . '">' |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * dismiss_persistent_admin_notice |
|
| 681 | - * |
|
| 682 | - * @access public |
|
| 683 | - * @return void |
|
| 684 | - */ |
|
| 685 | - public function dismiss_ee_nag_notice_callback() |
|
| 686 | - { |
|
| 687 | - EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param array $elements |
|
| 693 | - * @return array |
|
| 694 | - * @throws \EE_Error |
|
| 695 | - */ |
|
| 696 | - public function dashboard_glance_items($elements) |
|
| 697 | - { |
|
| 698 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | - $events = EEM_Event::instance()->count(); |
|
| 700 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | - array('page' => 'espresso_events'), |
|
| 702 | - admin_url('admin.php') |
|
| 703 | - ); |
|
| 704 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | - $registrations = EEM_Registration::instance()->count( |
|
| 707 | - array( |
|
| 708 | - array( |
|
| 709 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | - ), |
|
| 711 | - ) |
|
| 712 | - ); |
|
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | - array('page' => 'espresso_registrations'), |
|
| 715 | - admin_url('admin.php') |
|
| 716 | - ); |
|
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 718 | - _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | - number_format_i18n($registrations) |
|
| 720 | - ); |
|
| 721 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | - |
|
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | - |
|
| 725 | - foreach ($items as $type => $item_properties) { |
|
| 726 | - $elements[] = sprintf( |
|
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | - $item_properties['url'], |
|
| 729 | - $item_properties['title'], |
|
| 730 | - $item_properties['text'] |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - return $elements; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * check_for_invalid_datetime_formats |
|
| 739 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | - * their selected format can be parsed by PHP |
|
| 741 | - * |
|
| 742 | - * @access public |
|
| 743 | - * @param $value |
|
| 744 | - * @param $option |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @return string |
|
| 747 | - */ |
|
| 748 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | - { |
|
| 750 | - // check for date_format or time_format |
|
| 751 | - switch ($option) { |
|
| 752 | - case 'date_format': |
|
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | - break; |
|
| 755 | - case 'time_format': |
|
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | - break; |
|
| 758 | - default: |
|
| 759 | - $date_time_format = false; |
|
| 760 | - } |
|
| 761 | - // do we have a date_time format to check ? |
|
| 762 | - if ($date_time_format) { |
|
| 763 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | - |
|
| 765 | - if (is_array($error_msg)) { |
|
| 766 | - $msg = '<p>' |
|
| 767 | - . sprintf( |
|
| 768 | - esc_html__( |
|
| 769 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | - 'event_espresso' |
|
| 771 | - ), |
|
| 772 | - date($date_time_format), |
|
| 773 | - $date_time_format |
|
| 774 | - ) |
|
| 775 | - . '</p><p><ul>'; |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - foreach ($error_msg as $error) { |
|
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - $msg .= '</ul></p><p>' |
|
| 783 | - . sprintf( |
|
| 784 | - esc_html__( |
|
| 785 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | - 'event_espresso' |
|
| 787 | - ), |
|
| 788 | - '<span style="color:#D54E21;">', |
|
| 789 | - '</span>' |
|
| 790 | - ) |
|
| 791 | - . '</p>'; |
|
| 792 | - |
|
| 793 | - // trigger WP settings error |
|
| 794 | - add_settings_error( |
|
| 795 | - 'date_format', |
|
| 796 | - 'date_format', |
|
| 797 | - $msg |
|
| 798 | - ); |
|
| 799 | - |
|
| 800 | - // set format to something valid |
|
| 801 | - switch ($option) { |
|
| 802 | - case 'date_format': |
|
| 803 | - $value = 'F j, Y'; |
|
| 804 | - break; |
|
| 805 | - case 'time_format': |
|
| 806 | - $value = 'g:i a'; |
|
| 807 | - break; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - return $value; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | - * |
|
| 818 | - * @access public |
|
| 819 | - * @param $content |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function its_eSpresso($content) |
|
| 823 | - { |
|
| 824 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * espresso_admin_footer |
|
| 830 | - * |
|
| 831 | - * @access public |
|
| 832 | - * @return string |
|
| 833 | - */ |
|
| 834 | - public function espresso_admin_footer() |
|
| 835 | - { |
|
| 836 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * static method for registering ee admin page. |
|
| 842 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | - * |
|
| 844 | - * @since 4.3.0 |
|
| 845 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | - * @see EE_Register_Admin_Page::register() |
|
| 847 | - * @param $page_basename |
|
| 848 | - * @param $page_path |
|
| 849 | - * @param array $config |
|
| 850 | - * @return void |
|
| 851 | - * @throws EE_Error |
|
| 852 | - */ |
|
| 853 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | - { |
|
| 855 | - EE_Error::doing_it_wrong( |
|
| 856 | - __METHOD__, |
|
| 857 | - sprintf( |
|
| 858 | - esc_html__( |
|
| 859 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | - 'event_espresso' |
|
| 861 | - ), |
|
| 862 | - $page_basename |
|
| 863 | - ), |
|
| 864 | - '4.3' |
|
| 865 | - ); |
|
| 866 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | - $config['page_path'] = $page_path; |
|
| 868 | - } |
|
| 869 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * @deprecated 4.8.41 |
|
| 875 | - * @access public |
|
| 876 | - * @param int $post_ID |
|
| 877 | - * @param \WP_Post $post |
|
| 878 | - * @return void |
|
| 879 | - */ |
|
| 880 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | - { |
|
| 882 | - EE_Error::doing_it_wrong( |
|
| 883 | - __METHOD__, |
|
| 884 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | - '4.8.41' |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * @deprecated 4.8.41 |
|
| 892 | - * @access public |
|
| 893 | - * @param $option |
|
| 894 | - * @param $old_value |
|
| 895 | - * @param $value |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | - { |
|
| 900 | - EE_Error::doing_it_wrong( |
|
| 901 | - __METHOD__, |
|
| 902 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | - '4.8.41' |
|
| 904 | - ); |
|
| 905 | - } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns an array of event archive nav items. |
|
| 424 | + * |
|
| 425 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | + * method we use for getting the extra nav menu items |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + private function _get_extra_nav_menu_pages_items() |
|
| 430 | + { |
|
| 431 | + $menuitems[] = array( |
|
| 432 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | + ); |
|
| 436 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | + * the properties and converts it to the menu item object. |
|
| 443 | + * |
|
| 444 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | + * @param $menu_item_values |
|
| 446 | + * @return stdClass |
|
| 447 | + */ |
|
| 448 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | + { |
|
| 450 | + $menu_item = new stdClass(); |
|
| 451 | + $keys = array( |
|
| 452 | + 'ID' => 0, |
|
| 453 | + 'db_id' => 0, |
|
| 454 | + 'menu_item_parent' => 0, |
|
| 455 | + 'object_id' => -1, |
|
| 456 | + 'post_parent' => 0, |
|
| 457 | + 'type' => 'custom', |
|
| 458 | + 'object' => '', |
|
| 459 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | + 'title' => '', |
|
| 461 | + 'url' => '', |
|
| 462 | + 'target' => '', |
|
| 463 | + 'attr_title' => '', |
|
| 464 | + 'description' => '', |
|
| 465 | + 'classes' => array(), |
|
| 466 | + 'xfn' => '', |
|
| 467 | + ); |
|
| 468 | + |
|
| 469 | + foreach ($keys as $key => $value) { |
|
| 470 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | + } |
|
| 472 | + return $menu_item; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | + * EE_Admin_Page route is called. |
|
| 479 | + * |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + public function route_admin_request() |
|
| 483 | + { |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | + * |
|
| 490 | + * @return void |
|
| 491 | + */ |
|
| 492 | + public function wp_loaded() |
|
| 493 | + { |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * admin_init |
|
| 499 | + * |
|
| 500 | + * @access public |
|
| 501 | + * @return void |
|
| 502 | + * @throws EE_Error |
|
| 503 | + * @throws ReflectionException |
|
| 504 | + */ |
|
| 505 | + public function admin_init() |
|
| 506 | + { |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | + * - check if doing post processing. |
|
| 512 | + * - check if doing post processing of one of EE CPTs |
|
| 513 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | + */ |
|
| 515 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | + * Pages" tab in the EE General Settings Admin page. |
|
| 525 | + * This is for user-proofing. |
|
| 526 | + */ |
|
| 527 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | + * |
|
| 534 | + * @param string $output Current output. |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function modify_dropdown_pages($output) |
|
| 538 | + { |
|
| 539 | + //get critical pages |
|
| 540 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | + |
|
| 542 | + //split current output by line break for easier parsing. |
|
| 543 | + $split_output = explode("\n", $output); |
|
| 544 | + |
|
| 545 | + //loop through to remove any critical pages from the array. |
|
| 546 | + foreach ($critical_pages as $page_id) { |
|
| 547 | + $needle = 'value="' . $page_id . '"'; |
|
| 548 | + foreach ($split_output as $key => $haystack) { |
|
| 549 | + if (strpos($haystack, $needle) !== false) { |
|
| 550 | + unset($split_output[$key]); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + //replace output with the new contents |
|
| 556 | + return implode("\n", $split_output); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | + * |
|
| 563 | + * @access public |
|
| 564 | + * @return void |
|
| 565 | + */ |
|
| 566 | + public function enqueue_admin_scripts() |
|
| 567 | + { |
|
| 568 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | + // calls. |
|
| 571 | + wp_enqueue_script( |
|
| 572 | + 'ee-inject-wp', |
|
| 573 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | + array('jquery'), |
|
| 575 | + EVENT_ESPRESSO_VERSION, |
|
| 576 | + true |
|
| 577 | + ); |
|
| 578 | + // register cookie script for future dependencies |
|
| 579 | + wp_register_script( |
|
| 580 | + 'jquery-cookie', |
|
| 581 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | + array('jquery'), |
|
| 583 | + '2.1', |
|
| 584 | + true |
|
| 585 | + ); |
|
| 586 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | + //joyride style |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | + wp_register_style( |
|
| 592 | + 'ee-joyride-css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | + array('joyride-css'), |
|
| 595 | + EVENT_ESPRESSO_VERSION |
|
| 596 | + ); |
|
| 597 | + wp_register_script( |
|
| 598 | + 'joyride-modernizr', |
|
| 599 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | + array(), |
|
| 601 | + '2.1', |
|
| 602 | + true |
|
| 603 | + ); |
|
| 604 | + //joyride JS |
|
| 605 | + wp_register_script( |
|
| 606 | + 'jquery-joyride', |
|
| 607 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | + array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | + '2.1', |
|
| 610 | + true |
|
| 611 | + ); |
|
| 612 | + // wanna go for a joyride? |
|
| 613 | + wp_enqueue_style('ee-joyride-css'); |
|
| 614 | + wp_enqueue_script('jquery-joyride'); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * display_admin_notices |
|
| 621 | + * |
|
| 622 | + * @access public |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public function display_admin_notices() |
|
| 626 | + { |
|
| 627 | + echo EE_Error::get_notices(); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * get_persistent_admin_notices |
|
| 633 | + * |
|
| 634 | + * @access public |
|
| 635 | + * @return void |
|
| 636 | + */ |
|
| 637 | + public function get_persistent_admin_notices() |
|
| 638 | + { |
|
| 639 | + // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | + $args = array( |
|
| 641 | + 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | + ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | + : '', |
|
| 644 | + 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | + ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | + : '', |
|
| 647 | + ); |
|
| 648 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | + if (! get_option('timezone_string')) { |
|
| 654 | + EE_Error::add_persistent_admin_notice( |
|
| 655 | + 'datetime_fix_notice', |
|
| 656 | + sprintf( |
|
| 657 | + esc_html__( |
|
| 658 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | + 'event_espresso' |
|
| 660 | + ), |
|
| 661 | + '<strong>', |
|
| 662 | + '</strong>', |
|
| 663 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | + '</a>', |
|
| 665 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | + array( |
|
| 667 | + 'page' => 'espresso_maintenance_settings', |
|
| 668 | + 'action' => 'datetime_tools' |
|
| 669 | + ), |
|
| 670 | + admin_url('admin.php') |
|
| 671 | + ) . '">' |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * dismiss_persistent_admin_notice |
|
| 681 | + * |
|
| 682 | + * @access public |
|
| 683 | + * @return void |
|
| 684 | + */ |
|
| 685 | + public function dismiss_ee_nag_notice_callback() |
|
| 686 | + { |
|
| 687 | + EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param array $elements |
|
| 693 | + * @return array |
|
| 694 | + * @throws \EE_Error |
|
| 695 | + */ |
|
| 696 | + public function dashboard_glance_items($elements) |
|
| 697 | + { |
|
| 698 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | + $events = EEM_Event::instance()->count(); |
|
| 700 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | + array('page' => 'espresso_events'), |
|
| 702 | + admin_url('admin.php') |
|
| 703 | + ); |
|
| 704 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | + $registrations = EEM_Registration::instance()->count( |
|
| 707 | + array( |
|
| 708 | + array( |
|
| 709 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | + ), |
|
| 711 | + ) |
|
| 712 | + ); |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | + array('page' => 'espresso_registrations'), |
|
| 715 | + admin_url('admin.php') |
|
| 716 | + ); |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | + _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | + number_format_i18n($registrations) |
|
| 720 | + ); |
|
| 721 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | + |
|
| 723 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | + |
|
| 725 | + foreach ($items as $type => $item_properties) { |
|
| 726 | + $elements[] = sprintf( |
|
| 727 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | + $item_properties['url'], |
|
| 729 | + $item_properties['title'], |
|
| 730 | + $item_properties['text'] |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + return $elements; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * check_for_invalid_datetime_formats |
|
| 739 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | + * their selected format can be parsed by PHP |
|
| 741 | + * |
|
| 742 | + * @access public |
|
| 743 | + * @param $value |
|
| 744 | + * @param $option |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @return string |
|
| 747 | + */ |
|
| 748 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | + { |
|
| 750 | + // check for date_format or time_format |
|
| 751 | + switch ($option) { |
|
| 752 | + case 'date_format': |
|
| 753 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | + break; |
|
| 755 | + case 'time_format': |
|
| 756 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | + break; |
|
| 758 | + default: |
|
| 759 | + $date_time_format = false; |
|
| 760 | + } |
|
| 761 | + // do we have a date_time format to check ? |
|
| 762 | + if ($date_time_format) { |
|
| 763 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | + |
|
| 765 | + if (is_array($error_msg)) { |
|
| 766 | + $msg = '<p>' |
|
| 767 | + . sprintf( |
|
| 768 | + esc_html__( |
|
| 769 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | + 'event_espresso' |
|
| 771 | + ), |
|
| 772 | + date($date_time_format), |
|
| 773 | + $date_time_format |
|
| 774 | + ) |
|
| 775 | + . '</p><p><ul>'; |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + foreach ($error_msg as $error) { |
|
| 779 | + $msg .= '<li>' . $error . '</li>'; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + $msg .= '</ul></p><p>' |
|
| 783 | + . sprintf( |
|
| 784 | + esc_html__( |
|
| 785 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | + 'event_espresso' |
|
| 787 | + ), |
|
| 788 | + '<span style="color:#D54E21;">', |
|
| 789 | + '</span>' |
|
| 790 | + ) |
|
| 791 | + . '</p>'; |
|
| 792 | + |
|
| 793 | + // trigger WP settings error |
|
| 794 | + add_settings_error( |
|
| 795 | + 'date_format', |
|
| 796 | + 'date_format', |
|
| 797 | + $msg |
|
| 798 | + ); |
|
| 799 | + |
|
| 800 | + // set format to something valid |
|
| 801 | + switch ($option) { |
|
| 802 | + case 'date_format': |
|
| 803 | + $value = 'F j, Y'; |
|
| 804 | + break; |
|
| 805 | + case 'time_format': |
|
| 806 | + $value = 'g:i a'; |
|
| 807 | + break; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + return $value; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | + * |
|
| 818 | + * @access public |
|
| 819 | + * @param $content |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function its_eSpresso($content) |
|
| 823 | + { |
|
| 824 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * espresso_admin_footer |
|
| 830 | + * |
|
| 831 | + * @access public |
|
| 832 | + * @return string |
|
| 833 | + */ |
|
| 834 | + public function espresso_admin_footer() |
|
| 835 | + { |
|
| 836 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * static method for registering ee admin page. |
|
| 842 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | + * |
|
| 844 | + * @since 4.3.0 |
|
| 845 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | + * @see EE_Register_Admin_Page::register() |
|
| 847 | + * @param $page_basename |
|
| 848 | + * @param $page_path |
|
| 849 | + * @param array $config |
|
| 850 | + * @return void |
|
| 851 | + * @throws EE_Error |
|
| 852 | + */ |
|
| 853 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | + { |
|
| 855 | + EE_Error::doing_it_wrong( |
|
| 856 | + __METHOD__, |
|
| 857 | + sprintf( |
|
| 858 | + esc_html__( |
|
| 859 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | + 'event_espresso' |
|
| 861 | + ), |
|
| 862 | + $page_basename |
|
| 863 | + ), |
|
| 864 | + '4.3' |
|
| 865 | + ); |
|
| 866 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | + $config['page_path'] = $page_path; |
|
| 868 | + } |
|
| 869 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * @deprecated 4.8.41 |
|
| 875 | + * @access public |
|
| 876 | + * @param int $post_ID |
|
| 877 | + * @param \WP_Post $post |
|
| 878 | + * @return void |
|
| 879 | + */ |
|
| 880 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | + { |
|
| 882 | + EE_Error::doing_it_wrong( |
|
| 883 | + __METHOD__, |
|
| 884 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | + '4.8.41' |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * @deprecated 4.8.41 |
|
| 892 | + * @access public |
|
| 893 | + * @param $option |
|
| 894 | + * @param $old_value |
|
| 895 | + * @param $value |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | + { |
|
| 900 | + EE_Error::doing_it_wrong( |
|
| 901 | + __METHOD__, |
|
| 902 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | + '4.8.41' |
|
| 904 | + ); |
|
| 905 | + } |
|
| 906 | 906 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public static function instance() |
| 33 | 33 | { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 35 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | private function _define_all_constants() |
| 93 | 93 | { |
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 94 | + if ( ! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 99 | 99 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // set $main_file in stone |
| 115 | 115 | static $main_file; |
| 116 | 116 | // if $main_file is not set yet |
| 117 | - if (! $main_file) { |
|
| 117 | + if ( ! $main_file) { |
|
| 118 | 118 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
| 119 | 119 | } |
| 120 | 120 | if ($plugin === $main_file) { |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
| 166 | 166 | { |
| 167 | 167 | return array( |
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
| 171 | 171 | ); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
| 196 | 196 | } |
| 197 | 197 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 198 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | 199 | try { |
| 200 | 200 | //this loads the controller for the admin pages which will setup routing etc |
| 201 | 201 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function enable_hidden_ee_nav_menu_metaboxes() |
| 248 | 248 | { |
| 249 | 249 | global $wp_meta_boxes, $pagenow; |
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 250 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | $user = wp_get_current_user(); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | public function modify_edit_post_link($link, $id) |
| 320 | 320 | { |
| 321 | - if (! $post = get_post($id)) { |
|
| 321 | + if ( ! $post = get_post($id)) { |
|
| 322 | 322 | return $link; |
| 323 | 323 | } |
| 324 | 324 | if ($post->post_type === 'espresso_attendees') { |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | //loop through to remove any critical pages from the array. |
| 546 | 546 | foreach ($critical_pages as $page_id) { |
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 547 | + $needle = 'value="'.$page_id.'"'; |
|
| 548 | 548 | foreach ($split_output as $key => $haystack) { |
| 549 | 549 | if (strpos($haystack, $needle) !== false) { |
| 550 | 550 | unset($split_output[$key]); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | // calls. |
| 571 | 571 | wp_enqueue_script( |
| 572 | 572 | 'ee-inject-wp', |
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 573 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 574 | 574 | array('jquery'), |
| 575 | 575 | EVENT_ESPRESSO_VERSION, |
| 576 | 576 | true |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | // register cookie script for future dependencies |
| 579 | 579 | wp_register_script( |
| 580 | 580 | 'jquery-cookie', |
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 581 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
| 582 | 582 | array('jquery'), |
| 583 | 583 | '2.1', |
| 584 | 584 | true |
@@ -587,16 +587,16 @@ discard block |
||
| 587 | 587 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 588 | 588 | if (apply_filters('FHEE_load_joyride', false)) { |
| 589 | 589 | //joyride style |
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | 591 | wp_register_style( |
| 592 | 592 | 'ee-joyride-css', |
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 594 | 594 | array('joyride-css'), |
| 595 | 595 | EVENT_ESPRESSO_VERSION |
| 596 | 596 | ); |
| 597 | 597 | wp_register_script( |
| 598 | 598 | 'joyride-modernizr', |
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 599 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 600 | 600 | array(), |
| 601 | 601 | '2.1', |
| 602 | 602 | true |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | //joyride JS |
| 605 | 605 | wp_register_script( |
| 606 | 606 | 'jquery-joyride', |
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 607 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 608 | 608 | array('jquery-cookie', 'joyride-modernizr'), |
| 609 | 609 | '2.1', |
| 610 | 610 | true |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | public function get_persistent_admin_notices() |
| 638 | 638 | { |
| 639 | 639 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 640 | - $args = array( |
|
| 640 | + $args = array( |
|
| 641 | 641 | 'page' => EE_Registry::instance()->REQ->is_set('page') |
| 642 | 642 | ? EE_Registry::instance()->REQ->get('page') |
| 643 | 643 | : '', |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
| 651 | 651 | //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
| 652 | 652 | //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
| 653 | - if (! get_option('timezone_string')) { |
|
| 653 | + if ( ! get_option('timezone_string')) { |
|
| 654 | 654 | EE_Error::add_persistent_admin_notice( |
| 655 | 655 | 'datetime_fix_notice', |
| 656 | 656 | sprintf( |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | '</strong>', |
| 663 | 663 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
| 664 | 664 | '</a>', |
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 665 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | 666 | array( |
| 667 | 667 | 'page' => 'espresso_maintenance_settings', |
| 668 | 668 | 'action' => 'datetime_tools' |
| 669 | 669 | ), |
| 670 | 670 | admin_url('admin.php') |
| 671 | - ) . '">' |
|
| 671 | + ).'">' |
|
| 672 | 672 | ) |
| 673 | 673 | ); |
| 674 | 674 | } |
@@ -710,21 +710,21 @@ discard block |
||
| 710 | 710 | ), |
| 711 | 711 | ) |
| 712 | 712 | ); |
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | 714 | array('page' => 'espresso_registrations'), |
| 715 | 715 | admin_url('admin.php') |
| 716 | 716 | ); |
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | 718 | _n('%s Registration', '%s Registrations', $registrations), |
| 719 | 719 | number_format_i18n($registrations) |
| 720 | 720 | ); |
| 721 | 721 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
| 722 | 722 | |
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 723 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | 724 | |
| 725 | 725 | foreach ($items as $type => $item_properties) { |
| 726 | 726 | $elements[] = sprintf( |
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 727 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
| 728 | 728 | $item_properties['url'], |
| 729 | 729 | $item_properties['title'], |
| 730 | 730 | $item_properties['text'] |
@@ -750,10 +750,10 @@ discard block |
||
| 750 | 750 | // check for date_format or time_format |
| 751 | 751 | switch ($option) { |
| 752 | 752 | case 'date_format': |
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 753 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 754 | 754 | break; |
| 755 | 755 | case 'time_format': |
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 756 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 757 | 757 | break; |
| 758 | 758 | default: |
| 759 | 759 | $date_time_format = false; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | |
| 778 | 778 | foreach ($error_msg as $error) { |
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 779 | + $msg .= '<li>'.$error.'</li>'; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | $msg .= '</ul></p><p>' |
@@ -15,753 +15,753 @@ |
||
| 15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 21 | - * |
|
| 22 | - * @type string unix_timestamp_regex |
|
| 23 | - */ |
|
| 24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @type string mysql_timestamp_format |
|
| 28 | - */ |
|
| 29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @type string mysql_date_format |
|
| 33 | - */ |
|
| 34 | - const mysql_date_format = 'Y-m-d'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @type string mysql_time_format |
|
| 38 | - */ |
|
| 39 | - const mysql_time_format = 'H:i:s'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Const for using in the default value. If the field's default is set to this, |
|
| 43 | - * then we will return the time of calling `get_default_value()`, not |
|
| 44 | - * just the current time at construction |
|
| 45 | - */ |
|
| 46 | - const now = 'now'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The following properties hold the default formats for date and time. |
|
| 50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 51 | - * However they can also be overridden later by the set_format() method |
|
| 52 | - * (and corresponding set_date_format, set_time_format methods); |
|
| 53 | - */ |
|
| 54 | - /** |
|
| 55 | - * @type string $_date_format |
|
| 56 | - */ |
|
| 57 | - protected $_date_format = ''; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type string $_time_format |
|
| 61 | - */ |
|
| 62 | - protected $_time_format = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type string $_pretty_date_format |
|
| 66 | - */ |
|
| 67 | - protected $_pretty_date_format = ''; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type string $_pretty_time_format |
|
| 71 | - */ |
|
| 72 | - protected $_pretty_time_format = ''; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type DateTimeZone $_DateTimeZone |
|
| 76 | - */ |
|
| 77 | - protected $_DateTimeZone; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
| 81 | - */ |
|
| 82 | - protected $_UTC_DateTimeZone; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
| 86 | - */ |
|
| 87 | - protected $_blog_DateTimeZone; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 93 | - * and time returned via getters. |
|
| 94 | - * |
|
| 95 | - * @var mixed (null|string) |
|
| 96 | - */ |
|
| 97 | - protected $_date_time_output; |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * timezone string |
|
| 102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | - * |
|
| 106 | - * @var string |
|
| 107 | - */ |
|
| 108 | - protected $_timezone_string; |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 113 | - * offsets for comparison purposes). |
|
| 114 | - * |
|
| 115 | - * @var int |
|
| 116 | - */ |
|
| 117 | - protected $_blog_offset; |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param string $table_column |
|
| 123 | - * @param string $nice_name |
|
| 124 | - * @param bool $nullable |
|
| 125 | - * @param string $default_value |
|
| 126 | - * @param string $timezone_string |
|
| 127 | - * @param string $date_format |
|
| 128 | - * @param string $time_format |
|
| 129 | - * @param string $pretty_date_format |
|
| 130 | - * @param string $pretty_time_format |
|
| 131 | - * @throws EE_Error |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - */ |
|
| 134 | - public function __construct( |
|
| 135 | - $table_column, |
|
| 136 | - $nice_name, |
|
| 137 | - $nullable, |
|
| 138 | - $default_value, |
|
| 139 | - $timezone_string = '', |
|
| 140 | - $date_format = '', |
|
| 141 | - $time_format = '', |
|
| 142 | - $pretty_date_format = '', |
|
| 143 | - $pretty_time_format = '' |
|
| 144 | - ) { |
|
| 145 | - |
|
| 146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 150 | - |
|
| 151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 152 | - $this->set_timezone($timezone_string); |
|
| 153 | - $this->setSchemaFormat('date-time'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return DateTimeZone |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - */ |
|
| 161 | - public function get_UTC_DateTimeZone() |
|
| 162 | - { |
|
| 163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 164 | - ? $this->_UTC_DateTimeZone |
|
| 165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return DateTimeZone |
|
| 171 | - * @throws \EE_Error |
|
| 172 | - */ |
|
| 173 | - public function get_blog_DateTimeZone() |
|
| 174 | - { |
|
| 175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 176 | - ? $this->_blog_DateTimeZone |
|
| 177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 183 | - * |
|
| 184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 185 | - * timestamp |
|
| 186 | - * @return DateTime |
|
| 187 | - */ |
|
| 188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 189 | - { |
|
| 190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 197 | - * |
|
| 198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 199 | - * @return string The final assembled format string. |
|
| 200 | - */ |
|
| 201 | - protected function _get_date_time_output($pretty = false) |
|
| 202 | - { |
|
| 203 | - |
|
| 204 | - switch ($this->_date_time_output) { |
|
| 205 | - case 'time' : |
|
| 206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 207 | - break; |
|
| 208 | - |
|
| 209 | - case 'date' : |
|
| 210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 211 | - break; |
|
| 212 | - |
|
| 213 | - default : |
|
| 214 | - return $pretty |
|
| 215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 223 | - * returned (using the format properties) |
|
| 224 | - * |
|
| 225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
| 226 | - * Any other value will be set but will always result |
|
| 227 | - * in both 'date' and 'time' being returned. |
|
| 228 | - * @return void |
|
| 229 | - */ |
|
| 230 | - public function set_date_time_output($what = null) |
|
| 231 | - { |
|
| 232 | - $this->_date_time_output = $what; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 240 | - * We also set some other properties in this method. |
|
| 241 | - * |
|
| 242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
| 243 | - * http://www.php.net/manual/en/timezones.php |
|
| 244 | - * @return void |
|
| 245 | - * @throws \EE_Error |
|
| 246 | - */ |
|
| 247 | - public function set_timezone($timezone_string) |
|
| 248 | - { |
|
| 249 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 250 | - // leave the timezone AS-IS if we already have one and |
|
| 251 | - // the function arg didn't provide one |
|
| 252 | - return; |
|
| 253 | - } |
|
| 254 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 255 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 256 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * _create_timezone_object_from_timezone_name |
|
| 262 | - * |
|
| 263 | - * @access protected |
|
| 264 | - * @param string $timezone_string |
|
| 265 | - * @return \DateTimeZone |
|
| 266 | - * @throws \EE_Error |
|
| 267 | - */ |
|
| 268 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 269 | - { |
|
| 270 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * This just returns whatever is set for the current timezone. |
|
| 276 | - * |
|
| 277 | - * @access public |
|
| 278 | - * @return string timezone string |
|
| 279 | - */ |
|
| 280 | - public function get_timezone() |
|
| 281 | - { |
|
| 282 | - return $this->_timezone_string; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * set the $_date_format property |
|
| 288 | - * |
|
| 289 | - * @access public |
|
| 290 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 291 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 292 | - * @return void |
|
| 293 | - */ |
|
| 294 | - public function set_date_format($format, $pretty = false) |
|
| 295 | - { |
|
| 296 | - if ($pretty) { |
|
| 297 | - $this->_pretty_date_format = $format; |
|
| 298 | - } else { |
|
| 299 | - $this->_date_format = $format; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * return the $_date_format property value. |
|
| 306 | - * |
|
| 307 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - public function get_date_format($pretty = false) |
|
| 311 | - { |
|
| 312 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * set the $_time_format property |
|
| 318 | - * |
|
| 319 | - * @access public |
|
| 320 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 321 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - public function set_time_format($format, $pretty = false) |
|
| 325 | - { |
|
| 326 | - if ($pretty) { |
|
| 327 | - $this->_pretty_time_format = $format; |
|
| 328 | - } else { |
|
| 329 | - $this->_time_format = $format; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * return the $_time_format property value. |
|
| 336 | - * |
|
| 337 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - public function get_time_format($pretty = false) |
|
| 341 | - { |
|
| 342 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * set the $_pretty_date_format property |
|
| 348 | - * |
|
| 349 | - * @access public |
|
| 350 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 351 | - * @return void |
|
| 352 | - */ |
|
| 353 | - public function set_pretty_date_format($format) |
|
| 354 | - { |
|
| 355 | - $this->_pretty_date_format = $format; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * set the $_pretty_time_format property |
|
| 361 | - * |
|
| 362 | - * @access public |
|
| 363 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 364 | - * @return void |
|
| 365 | - */ |
|
| 366 | - public function set_pretty_time_format($format) |
|
| 367 | - { |
|
| 368 | - $this->_pretty_time_format = $format; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Only sets the time portion of the datetime. |
|
| 374 | - * |
|
| 375 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 376 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 377 | - * @return DateTime |
|
| 378 | - */ |
|
| 379 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 380 | - { |
|
| 381 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 382 | - // Otherwise parse the string. |
|
| 383 | - if ($time_to_set_string instanceof DateTime) { |
|
| 384 | - $parsed = array( |
|
| 385 | - 'hour' => $time_to_set_string->format('H'), |
|
| 386 | - 'minute' => $time_to_set_string->format('i'), |
|
| 387 | - 'second' => $time_to_set_string->format('s'), |
|
| 388 | - ); |
|
| 389 | - } else { |
|
| 390 | - //parse incoming string |
|
| 391 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - //make sure $current is in the correct timezone. |
|
| 395 | - $current->setTimezone($this->_DateTimeZone); |
|
| 396 | - |
|
| 397 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Only sets the date portion of the datetime. |
|
| 403 | - * |
|
| 404 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 405 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 406 | - * @return DateTime |
|
| 407 | - */ |
|
| 408 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 409 | - { |
|
| 410 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 411 | - // Otherwise parse the string. |
|
| 412 | - if ($date_to_set_string instanceof DateTime) { |
|
| 413 | - $parsed = array( |
|
| 414 | - 'year' => $date_to_set_string->format('Y'), |
|
| 415 | - 'month' => $date_to_set_string->format('m'), |
|
| 416 | - 'day' => $date_to_set_string->format('d'), |
|
| 417 | - ); |
|
| 418 | - } else { |
|
| 419 | - //parse incoming string |
|
| 420 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - //make sure $current is in the correct timezone |
|
| 424 | - $current->setTimezone($this->_DateTimeZone); |
|
| 425 | - |
|
| 426 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 432 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
| 433 | - * |
|
| 434 | - * @param DateTime $DateTime |
|
| 435 | - * @return string formatted date time for given timezone |
|
| 436 | - * @throws \EE_Error |
|
| 437 | - */ |
|
| 438 | - public function prepare_for_get($DateTime) |
|
| 439 | - { |
|
| 440 | - return $this->_prepare_for_display($DateTime); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 446 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 447 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 448 | - * abbreviation to the date_string. |
|
| 449 | - * |
|
| 450 | - * @param mixed $DateTime |
|
| 451 | - * @param null $schema |
|
| 452 | - * @return string |
|
| 453 | - * @throws \EE_Error |
|
| 454 | - */ |
|
| 455 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 456 | - { |
|
| 457 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 463 | - * timezone). |
|
| 464 | - * |
|
| 465 | - * @param DateTime $DateTime |
|
| 466 | - * @param bool|string $schema |
|
| 467 | - * @return string |
|
| 468 | - * @throws \EE_Error |
|
| 469 | - */ |
|
| 470 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
| 471 | - { |
|
| 472 | - if (! $DateTime instanceof DateTime) { |
|
| 473 | - if ($this->_nullable) { |
|
| 474 | - return ''; |
|
| 475 | - } else { |
|
| 476 | - if (WP_DEBUG) { |
|
| 477 | - throw new EE_Error( |
|
| 478 | - sprintf( |
|
| 479 | - __( |
|
| 480 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 481 | - 'event_espresso' |
|
| 482 | - ), |
|
| 483 | - $this->_nicename |
|
| 484 | - ) |
|
| 485 | - ); |
|
| 486 | - } else { |
|
| 487 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 488 | - EE_Error::add_error( |
|
| 489 | - sprintf( |
|
| 490 | - __( |
|
| 491 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 492 | - 'event_espresso' |
|
| 493 | - ), |
|
| 494 | - $this->_nicename |
|
| 495 | - ) |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - $format_string = $this->_get_date_time_output($schema); |
|
| 501 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 502 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 503 | - if ($schema) { |
|
| 504 | - if ($this->_display_timezone()) { |
|
| 505 | - //must be explicit because schema could equal true. |
|
| 506 | - if ($schema === 'no_html') { |
|
| 507 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 508 | - } else { |
|
| 509 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 510 | - } |
|
| 511 | - } else { |
|
| 512 | - $timezone_string = ''; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 516 | - } else { |
|
| 517 | - return $DateTime->format($format_string); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 524 | - * timezone). |
|
| 525 | - * |
|
| 526 | - * @param mixed $datetime_value u |
|
| 527 | - * @return string mysql timestamp in UTC |
|
| 528 | - * @throws \EE_Error |
|
| 529 | - */ |
|
| 530 | - public function prepare_for_use_in_db($datetime_value) |
|
| 531 | - { |
|
| 532 | - //we allow an empty value or DateTime object, but nothing else. |
|
| 533 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 534 | - throw new EE_Error( |
|
| 535 | - sprintf( |
|
| 536 | - __( |
|
| 537 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
| 18 | + /** |
|
| 19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 21 | + * |
|
| 22 | + * @type string unix_timestamp_regex |
|
| 23 | + */ |
|
| 24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @type string mysql_timestamp_format |
|
| 28 | + */ |
|
| 29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @type string mysql_date_format |
|
| 33 | + */ |
|
| 34 | + const mysql_date_format = 'Y-m-d'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @type string mysql_time_format |
|
| 38 | + */ |
|
| 39 | + const mysql_time_format = 'H:i:s'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Const for using in the default value. If the field's default is set to this, |
|
| 43 | + * then we will return the time of calling `get_default_value()`, not |
|
| 44 | + * just the current time at construction |
|
| 45 | + */ |
|
| 46 | + const now = 'now'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The following properties hold the default formats for date and time. |
|
| 50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 51 | + * However they can also be overridden later by the set_format() method |
|
| 52 | + * (and corresponding set_date_format, set_time_format methods); |
|
| 53 | + */ |
|
| 54 | + /** |
|
| 55 | + * @type string $_date_format |
|
| 56 | + */ |
|
| 57 | + protected $_date_format = ''; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type string $_time_format |
|
| 61 | + */ |
|
| 62 | + protected $_time_format = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type string $_pretty_date_format |
|
| 66 | + */ |
|
| 67 | + protected $_pretty_date_format = ''; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type string $_pretty_time_format |
|
| 71 | + */ |
|
| 72 | + protected $_pretty_time_format = ''; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type DateTimeZone $_DateTimeZone |
|
| 76 | + */ |
|
| 77 | + protected $_DateTimeZone; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
| 81 | + */ |
|
| 82 | + protected $_UTC_DateTimeZone; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
| 86 | + */ |
|
| 87 | + protected $_blog_DateTimeZone; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 93 | + * and time returned via getters. |
|
| 94 | + * |
|
| 95 | + * @var mixed (null|string) |
|
| 96 | + */ |
|
| 97 | + protected $_date_time_output; |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * timezone string |
|
| 102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | + * |
|
| 106 | + * @var string |
|
| 107 | + */ |
|
| 108 | + protected $_timezone_string; |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 113 | + * offsets for comparison purposes). |
|
| 114 | + * |
|
| 115 | + * @var int |
|
| 116 | + */ |
|
| 117 | + protected $_blog_offset; |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param string $table_column |
|
| 123 | + * @param string $nice_name |
|
| 124 | + * @param bool $nullable |
|
| 125 | + * @param string $default_value |
|
| 126 | + * @param string $timezone_string |
|
| 127 | + * @param string $date_format |
|
| 128 | + * @param string $time_format |
|
| 129 | + * @param string $pretty_date_format |
|
| 130 | + * @param string $pretty_time_format |
|
| 131 | + * @throws EE_Error |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + */ |
|
| 134 | + public function __construct( |
|
| 135 | + $table_column, |
|
| 136 | + $nice_name, |
|
| 137 | + $nullable, |
|
| 138 | + $default_value, |
|
| 139 | + $timezone_string = '', |
|
| 140 | + $date_format = '', |
|
| 141 | + $time_format = '', |
|
| 142 | + $pretty_date_format = '', |
|
| 143 | + $pretty_time_format = '' |
|
| 144 | + ) { |
|
| 145 | + |
|
| 146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 150 | + |
|
| 151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 152 | + $this->set_timezone($timezone_string); |
|
| 153 | + $this->setSchemaFormat('date-time'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return DateTimeZone |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + */ |
|
| 161 | + public function get_UTC_DateTimeZone() |
|
| 162 | + { |
|
| 163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 164 | + ? $this->_UTC_DateTimeZone |
|
| 165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return DateTimeZone |
|
| 171 | + * @throws \EE_Error |
|
| 172 | + */ |
|
| 173 | + public function get_blog_DateTimeZone() |
|
| 174 | + { |
|
| 175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 176 | + ? $this->_blog_DateTimeZone |
|
| 177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 183 | + * |
|
| 184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 185 | + * timestamp |
|
| 186 | + * @return DateTime |
|
| 187 | + */ |
|
| 188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 189 | + { |
|
| 190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 197 | + * |
|
| 198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 199 | + * @return string The final assembled format string. |
|
| 200 | + */ |
|
| 201 | + protected function _get_date_time_output($pretty = false) |
|
| 202 | + { |
|
| 203 | + |
|
| 204 | + switch ($this->_date_time_output) { |
|
| 205 | + case 'time' : |
|
| 206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 207 | + break; |
|
| 208 | + |
|
| 209 | + case 'date' : |
|
| 210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 211 | + break; |
|
| 212 | + |
|
| 213 | + default : |
|
| 214 | + return $pretty |
|
| 215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 223 | + * returned (using the format properties) |
|
| 224 | + * |
|
| 225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
| 226 | + * Any other value will be set but will always result |
|
| 227 | + * in both 'date' and 'time' being returned. |
|
| 228 | + * @return void |
|
| 229 | + */ |
|
| 230 | + public function set_date_time_output($what = null) |
|
| 231 | + { |
|
| 232 | + $this->_date_time_output = $what; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 240 | + * We also set some other properties in this method. |
|
| 241 | + * |
|
| 242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
| 243 | + * http://www.php.net/manual/en/timezones.php |
|
| 244 | + * @return void |
|
| 245 | + * @throws \EE_Error |
|
| 246 | + */ |
|
| 247 | + public function set_timezone($timezone_string) |
|
| 248 | + { |
|
| 249 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 250 | + // leave the timezone AS-IS if we already have one and |
|
| 251 | + // the function arg didn't provide one |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 255 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 256 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * _create_timezone_object_from_timezone_name |
|
| 262 | + * |
|
| 263 | + * @access protected |
|
| 264 | + * @param string $timezone_string |
|
| 265 | + * @return \DateTimeZone |
|
| 266 | + * @throws \EE_Error |
|
| 267 | + */ |
|
| 268 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 269 | + { |
|
| 270 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * This just returns whatever is set for the current timezone. |
|
| 276 | + * |
|
| 277 | + * @access public |
|
| 278 | + * @return string timezone string |
|
| 279 | + */ |
|
| 280 | + public function get_timezone() |
|
| 281 | + { |
|
| 282 | + return $this->_timezone_string; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * set the $_date_format property |
|
| 288 | + * |
|
| 289 | + * @access public |
|
| 290 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 291 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 292 | + * @return void |
|
| 293 | + */ |
|
| 294 | + public function set_date_format($format, $pretty = false) |
|
| 295 | + { |
|
| 296 | + if ($pretty) { |
|
| 297 | + $this->_pretty_date_format = $format; |
|
| 298 | + } else { |
|
| 299 | + $this->_date_format = $format; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * return the $_date_format property value. |
|
| 306 | + * |
|
| 307 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + public function get_date_format($pretty = false) |
|
| 311 | + { |
|
| 312 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * set the $_time_format property |
|
| 318 | + * |
|
| 319 | + * @access public |
|
| 320 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 321 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + public function set_time_format($format, $pretty = false) |
|
| 325 | + { |
|
| 326 | + if ($pretty) { |
|
| 327 | + $this->_pretty_time_format = $format; |
|
| 328 | + } else { |
|
| 329 | + $this->_time_format = $format; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * return the $_time_format property value. |
|
| 336 | + * |
|
| 337 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + public function get_time_format($pretty = false) |
|
| 341 | + { |
|
| 342 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * set the $_pretty_date_format property |
|
| 348 | + * |
|
| 349 | + * @access public |
|
| 350 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 351 | + * @return void |
|
| 352 | + */ |
|
| 353 | + public function set_pretty_date_format($format) |
|
| 354 | + { |
|
| 355 | + $this->_pretty_date_format = $format; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * set the $_pretty_time_format property |
|
| 361 | + * |
|
| 362 | + * @access public |
|
| 363 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 364 | + * @return void |
|
| 365 | + */ |
|
| 366 | + public function set_pretty_time_format($format) |
|
| 367 | + { |
|
| 368 | + $this->_pretty_time_format = $format; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Only sets the time portion of the datetime. |
|
| 374 | + * |
|
| 375 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 376 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 377 | + * @return DateTime |
|
| 378 | + */ |
|
| 379 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 380 | + { |
|
| 381 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 382 | + // Otherwise parse the string. |
|
| 383 | + if ($time_to_set_string instanceof DateTime) { |
|
| 384 | + $parsed = array( |
|
| 385 | + 'hour' => $time_to_set_string->format('H'), |
|
| 386 | + 'minute' => $time_to_set_string->format('i'), |
|
| 387 | + 'second' => $time_to_set_string->format('s'), |
|
| 388 | + ); |
|
| 389 | + } else { |
|
| 390 | + //parse incoming string |
|
| 391 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + //make sure $current is in the correct timezone. |
|
| 395 | + $current->setTimezone($this->_DateTimeZone); |
|
| 396 | + |
|
| 397 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Only sets the date portion of the datetime. |
|
| 403 | + * |
|
| 404 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 405 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 406 | + * @return DateTime |
|
| 407 | + */ |
|
| 408 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 409 | + { |
|
| 410 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 411 | + // Otherwise parse the string. |
|
| 412 | + if ($date_to_set_string instanceof DateTime) { |
|
| 413 | + $parsed = array( |
|
| 414 | + 'year' => $date_to_set_string->format('Y'), |
|
| 415 | + 'month' => $date_to_set_string->format('m'), |
|
| 416 | + 'day' => $date_to_set_string->format('d'), |
|
| 417 | + ); |
|
| 418 | + } else { |
|
| 419 | + //parse incoming string |
|
| 420 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + //make sure $current is in the correct timezone |
|
| 424 | + $current->setTimezone($this->_DateTimeZone); |
|
| 425 | + |
|
| 426 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 432 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
| 433 | + * |
|
| 434 | + * @param DateTime $DateTime |
|
| 435 | + * @return string formatted date time for given timezone |
|
| 436 | + * @throws \EE_Error |
|
| 437 | + */ |
|
| 438 | + public function prepare_for_get($DateTime) |
|
| 439 | + { |
|
| 440 | + return $this->_prepare_for_display($DateTime); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 446 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 447 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 448 | + * abbreviation to the date_string. |
|
| 449 | + * |
|
| 450 | + * @param mixed $DateTime |
|
| 451 | + * @param null $schema |
|
| 452 | + * @return string |
|
| 453 | + * @throws \EE_Error |
|
| 454 | + */ |
|
| 455 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 456 | + { |
|
| 457 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 463 | + * timezone). |
|
| 464 | + * |
|
| 465 | + * @param DateTime $DateTime |
|
| 466 | + * @param bool|string $schema |
|
| 467 | + * @return string |
|
| 468 | + * @throws \EE_Error |
|
| 469 | + */ |
|
| 470 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
| 471 | + { |
|
| 472 | + if (! $DateTime instanceof DateTime) { |
|
| 473 | + if ($this->_nullable) { |
|
| 474 | + return ''; |
|
| 475 | + } else { |
|
| 476 | + if (WP_DEBUG) { |
|
| 477 | + throw new EE_Error( |
|
| 478 | + sprintf( |
|
| 479 | + __( |
|
| 480 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 481 | + 'event_espresso' |
|
| 482 | + ), |
|
| 483 | + $this->_nicename |
|
| 484 | + ) |
|
| 485 | + ); |
|
| 486 | + } else { |
|
| 487 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 488 | + EE_Error::add_error( |
|
| 489 | + sprintf( |
|
| 490 | + __( |
|
| 491 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 492 | + 'event_espresso' |
|
| 493 | + ), |
|
| 494 | + $this->_nicename |
|
| 495 | + ) |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + $format_string = $this->_get_date_time_output($schema); |
|
| 501 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 502 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 503 | + if ($schema) { |
|
| 504 | + if ($this->_display_timezone()) { |
|
| 505 | + //must be explicit because schema could equal true. |
|
| 506 | + if ($schema === 'no_html') { |
|
| 507 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 508 | + } else { |
|
| 509 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 510 | + } |
|
| 511 | + } else { |
|
| 512 | + $timezone_string = ''; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $DateTime->format($format_string) . $timezone_string; |
|
| 516 | + } else { |
|
| 517 | + return $DateTime->format($format_string); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 524 | + * timezone). |
|
| 525 | + * |
|
| 526 | + * @param mixed $datetime_value u |
|
| 527 | + * @return string mysql timestamp in UTC |
|
| 528 | + * @throws \EE_Error |
|
| 529 | + */ |
|
| 530 | + public function prepare_for_use_in_db($datetime_value) |
|
| 531 | + { |
|
| 532 | + //we allow an empty value or DateTime object, but nothing else. |
|
| 533 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 534 | + throw new EE_Error( |
|
| 535 | + sprintf( |
|
| 536 | + __( |
|
| 537 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
| 538 | 538 | DateTime object, instead of: %1$s %2$s', |
| 539 | - 'event_espresso' |
|
| 540 | - ), |
|
| 541 | - '<br />', |
|
| 542 | - print_r($datetime_value, true) |
|
| 543 | - ) |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if ($datetime_value instanceof DateTime) { |
|
| 548 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 549 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 553 | - EE_Datetime_Field::mysql_timestamp_format |
|
| 554 | - ); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 558 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 564 | - * allowed) |
|
| 565 | - * |
|
| 566 | - * @param string $datetime_string mysql timestamp in UTC |
|
| 567 | - * @return mixed null | DateTime |
|
| 568 | - * @throws \EE_Error |
|
| 569 | - */ |
|
| 570 | - public function prepare_for_set_from_db($datetime_string) |
|
| 571 | - { |
|
| 572 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 573 | - if (empty($datetime_string) && $this->_nullable) { |
|
| 574 | - return null; |
|
| 575 | - } |
|
| 576 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 577 | - if (empty($datetime_string)) { |
|
| 578 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 579 | - } else { |
|
| 580 | - $DateTime = DateTime::createFromFormat( |
|
| 581 | - EE_Datetime_Field::mysql_timestamp_format, |
|
| 582 | - $datetime_string, |
|
| 583 | - $this->get_UTC_DateTimeZone() |
|
| 584 | - ); |
|
| 585 | - if ($DateTime instanceof \DateTime) { |
|
| 586 | - $DateTime = new DbSafeDateTime( |
|
| 587 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 588 | - $this->get_UTC_DateTimeZone() |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 594 | - // if still no datetime object, then let's just use now |
|
| 595 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 596 | - } |
|
| 597 | - // THEN apply the field's set DateTimeZone |
|
| 598 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 599 | - |
|
| 600 | - return $DateTime; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 606 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 607 | - * If so, then true. |
|
| 608 | - * |
|
| 609 | - * @return bool true for yes false for no |
|
| 610 | - * @throws \EE_Error |
|
| 611 | - */ |
|
| 612 | - protected function _display_timezone() |
|
| 613 | - { |
|
| 614 | - |
|
| 615 | - // first let's do a comparison of timezone strings. |
|
| 616 | - // If they match then we can get out without any further calculations |
|
| 617 | - $blog_string = get_option('timezone_string'); |
|
| 618 | - if ($blog_string === $this->_timezone_string) { |
|
| 619 | - return false; |
|
| 620 | - } |
|
| 621 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 622 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 623 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 624 | - // now compare |
|
| 625 | - return $blog_offset !== $this_offset; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 631 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 632 | - * with. |
|
| 633 | - * |
|
| 634 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 635 | - * in the format that is set on the date_field (or DateTime |
|
| 636 | - * object)! |
|
| 637 | - * @return DateTime |
|
| 638 | - */ |
|
| 639 | - protected function _get_date_object($date_string) |
|
| 640 | - { |
|
| 641 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 642 | - if ($this->_nullable && empty($date_string)) { |
|
| 643 | - return null; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // if incoming date |
|
| 647 | - if ($date_string instanceof DateTime) { |
|
| 648 | - $date_string->setTimezone($this->_DateTimeZone); |
|
| 649 | - |
|
| 650 | - return $date_string; |
|
| 651 | - } |
|
| 652 | - // if empty date_string and made it here. |
|
| 653 | - // Return a datetime object for now in the given timezone. |
|
| 654 | - if (empty($date_string)) { |
|
| 655 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 656 | - } |
|
| 657 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 658 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 659 | - try { |
|
| 660 | - // This is operating under the assumption that the incoming Unix timestamp |
|
| 661 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 662 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 663 | - $DateTime->setTimestamp($date_string); |
|
| 664 | - |
|
| 665 | - return $DateTime; |
|
| 666 | - } catch (Exception $e) { |
|
| 667 | - // should be rare, but if things got fooled then let's just continue |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 671 | - //create the DateTime object. |
|
| 672 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 673 | - try { |
|
| 674 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 675 | - if ($DateTime instanceof DateTime) { |
|
| 676 | - $DateTime = new DbSafeDateTime( |
|
| 677 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 678 | - $this->_DateTimeZone |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 682 | - throw new EE_Error( |
|
| 683 | - sprintf( |
|
| 684 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 685 | - $date_string, |
|
| 686 | - $format |
|
| 687 | - ) |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - } catch (Exception $e) { |
|
| 691 | - // if we made it here then likely then something went really wrong. |
|
| 692 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 693 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $DateTime; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * get_timezone_transitions |
|
| 703 | - * |
|
| 704 | - * @param \DateTimeZone $DateTimeZone |
|
| 705 | - * @param int $time |
|
| 706 | - * @param bool $first_only |
|
| 707 | - * @return mixed |
|
| 708 | - */ |
|
| 709 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 710 | - { |
|
| 711 | - return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * get_timezone_offset |
|
| 718 | - * |
|
| 719 | - * @param \DateTimeZone $DateTimeZone |
|
| 720 | - * @param int $time |
|
| 721 | - * @return mixed |
|
| 722 | - * @throws \DomainException |
|
| 723 | - */ |
|
| 724 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 725 | - { |
|
| 726 | - return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 732 | - * |
|
| 733 | - * @param string $timezone_string |
|
| 734 | - * @return string abbreviation |
|
| 735 | - * @throws \EE_Error |
|
| 736 | - */ |
|
| 737 | - public function get_timezone_abbrev($timezone_string) |
|
| 738 | - { |
|
| 739 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 740 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 741 | - |
|
| 742 | - return $dateTime->format('T'); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * Overrides the parent to allow for having a dynamic "now" value |
|
| 747 | - * |
|
| 748 | - * @return mixed |
|
| 749 | - */ |
|
| 750 | - public function get_default_value() |
|
| 751 | - { |
|
| 752 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 753 | - return time(); |
|
| 754 | - } else { |
|
| 755 | - return parent::get_default_value(); |
|
| 756 | - } |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - |
|
| 760 | - public function getSchemaDescription() |
|
| 761 | - { |
|
| 762 | - return sprintf( |
|
| 763 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
| 764 | - $this->get_nicename() |
|
| 765 | - ); |
|
| 766 | - } |
|
| 539 | + 'event_espresso' |
|
| 540 | + ), |
|
| 541 | + '<br />', |
|
| 542 | + print_r($datetime_value, true) |
|
| 543 | + ) |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($datetime_value instanceof DateTime) { |
|
| 548 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 549 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 553 | + EE_Datetime_Field::mysql_timestamp_format |
|
| 554 | + ); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 558 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 564 | + * allowed) |
|
| 565 | + * |
|
| 566 | + * @param string $datetime_string mysql timestamp in UTC |
|
| 567 | + * @return mixed null | DateTime |
|
| 568 | + * @throws \EE_Error |
|
| 569 | + */ |
|
| 570 | + public function prepare_for_set_from_db($datetime_string) |
|
| 571 | + { |
|
| 572 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 573 | + if (empty($datetime_string) && $this->_nullable) { |
|
| 574 | + return null; |
|
| 575 | + } |
|
| 576 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 577 | + if (empty($datetime_string)) { |
|
| 578 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 579 | + } else { |
|
| 580 | + $DateTime = DateTime::createFromFormat( |
|
| 581 | + EE_Datetime_Field::mysql_timestamp_format, |
|
| 582 | + $datetime_string, |
|
| 583 | + $this->get_UTC_DateTimeZone() |
|
| 584 | + ); |
|
| 585 | + if ($DateTime instanceof \DateTime) { |
|
| 586 | + $DateTime = new DbSafeDateTime( |
|
| 587 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 588 | + $this->get_UTC_DateTimeZone() |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 594 | + // if still no datetime object, then let's just use now |
|
| 595 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 596 | + } |
|
| 597 | + // THEN apply the field's set DateTimeZone |
|
| 598 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 599 | + |
|
| 600 | + return $DateTime; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 606 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 607 | + * If so, then true. |
|
| 608 | + * |
|
| 609 | + * @return bool true for yes false for no |
|
| 610 | + * @throws \EE_Error |
|
| 611 | + */ |
|
| 612 | + protected function _display_timezone() |
|
| 613 | + { |
|
| 614 | + |
|
| 615 | + // first let's do a comparison of timezone strings. |
|
| 616 | + // If they match then we can get out without any further calculations |
|
| 617 | + $blog_string = get_option('timezone_string'); |
|
| 618 | + if ($blog_string === $this->_timezone_string) { |
|
| 619 | + return false; |
|
| 620 | + } |
|
| 621 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 622 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 623 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 624 | + // now compare |
|
| 625 | + return $blog_offset !== $this_offset; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 631 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 632 | + * with. |
|
| 633 | + * |
|
| 634 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 635 | + * in the format that is set on the date_field (or DateTime |
|
| 636 | + * object)! |
|
| 637 | + * @return DateTime |
|
| 638 | + */ |
|
| 639 | + protected function _get_date_object($date_string) |
|
| 640 | + { |
|
| 641 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 642 | + if ($this->_nullable && empty($date_string)) { |
|
| 643 | + return null; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // if incoming date |
|
| 647 | + if ($date_string instanceof DateTime) { |
|
| 648 | + $date_string->setTimezone($this->_DateTimeZone); |
|
| 649 | + |
|
| 650 | + return $date_string; |
|
| 651 | + } |
|
| 652 | + // if empty date_string and made it here. |
|
| 653 | + // Return a datetime object for now in the given timezone. |
|
| 654 | + if (empty($date_string)) { |
|
| 655 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 656 | + } |
|
| 657 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 658 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 659 | + try { |
|
| 660 | + // This is operating under the assumption that the incoming Unix timestamp |
|
| 661 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 662 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 663 | + $DateTime->setTimestamp($date_string); |
|
| 664 | + |
|
| 665 | + return $DateTime; |
|
| 666 | + } catch (Exception $e) { |
|
| 667 | + // should be rare, but if things got fooled then let's just continue |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 671 | + //create the DateTime object. |
|
| 672 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 673 | + try { |
|
| 674 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 675 | + if ($DateTime instanceof DateTime) { |
|
| 676 | + $DateTime = new DbSafeDateTime( |
|
| 677 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 678 | + $this->_DateTimeZone |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 682 | + throw new EE_Error( |
|
| 683 | + sprintf( |
|
| 684 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 685 | + $date_string, |
|
| 686 | + $format |
|
| 687 | + ) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + } catch (Exception $e) { |
|
| 691 | + // if we made it here then likely then something went really wrong. |
|
| 692 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 693 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $DateTime; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * get_timezone_transitions |
|
| 703 | + * |
|
| 704 | + * @param \DateTimeZone $DateTimeZone |
|
| 705 | + * @param int $time |
|
| 706 | + * @param bool $first_only |
|
| 707 | + * @return mixed |
|
| 708 | + */ |
|
| 709 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 710 | + { |
|
| 711 | + return EEH_DTT_Helper::get_timezone_transitions($DateTimeZone, $time, $first_only); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * get_timezone_offset |
|
| 718 | + * |
|
| 719 | + * @param \DateTimeZone $DateTimeZone |
|
| 720 | + * @param int $time |
|
| 721 | + * @return mixed |
|
| 722 | + * @throws \DomainException |
|
| 723 | + */ |
|
| 724 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 725 | + { |
|
| 726 | + return EEH_DTT_Helper::get_timezone_offset($DateTimeZone, $time); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 732 | + * |
|
| 733 | + * @param string $timezone_string |
|
| 734 | + * @return string abbreviation |
|
| 735 | + * @throws \EE_Error |
|
| 736 | + */ |
|
| 737 | + public function get_timezone_abbrev($timezone_string) |
|
| 738 | + { |
|
| 739 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 740 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 741 | + |
|
| 742 | + return $dateTime->format('T'); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * Overrides the parent to allow for having a dynamic "now" value |
|
| 747 | + * |
|
| 748 | + * @return mixed |
|
| 749 | + */ |
|
| 750 | + public function get_default_value() |
|
| 751 | + { |
|
| 752 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 753 | + return time(); |
|
| 754 | + } else { |
|
| 755 | + return parent::get_default_value(); |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + |
|
| 760 | + public function getSchemaDescription() |
|
| 761 | + { |
|
| 762 | + return sprintf( |
|
| 763 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
| 764 | + $this->get_nicename() |
|
| 765 | + ); |
|
| 766 | + } |
|
| 767 | 767 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | * there's a single shared message template group among all the events. Otherwise it returns null. |
| 460 | 460 | * |
| 461 | 461 | * @param array $event_ids |
| 462 | - * @return EE_Message_Template_Group|null |
|
| 462 | + * @return null|EE_Base_Class |
|
| 463 | 463 | * @throws EE_Error |
| 464 | 464 | * @throws InvalidArgumentException |
| 465 | 465 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | /** |
| 496 | 496 | * Retrieves the global message template group for the current messenger and message type. |
| 497 | 497 | * |
| 498 | - * @return EE_Message_Template_Group|null |
|
| 498 | + * @return null|EE_Base_Class |
|
| 499 | 499 | * @throws EE_Error |
| 500 | 500 | * @throws InvalidArgumentException |
| 501 | 501 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | * @param EE_Messages_Addressee $recipient |
| 642 | 642 | * @param array $templates formatted array of templates used for parsing data. |
| 643 | 643 | * @param EE_Message_Template_Group $message_template_group |
| 644 | - * @return bool|EE_Message |
|
| 644 | + * @return EE_Message |
|
| 645 | 645 | * @throws EE_Error |
| 646 | 646 | */ |
| 647 | 647 | protected function _setup_message_object( |
@@ -13,970 +13,970 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @type EE_Messages_Data_Handler_Collection |
|
| 18 | - */ |
|
| 19 | - protected $_data_handler_collection; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @type EE_Message_Template_Group_Collection |
|
| 23 | - */ |
|
| 24 | - protected $_template_collection; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * This will hold the data handler for the current EE_Message being generated. |
|
| 28 | - * |
|
| 29 | - * @type EE_Messages_incoming_data |
|
| 30 | - */ |
|
| 31 | - protected $_current_data_handler; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
| 35 | - * |
|
| 36 | - * @type EE_Messages_Queue |
|
| 37 | - */ |
|
| 38 | - protected $_generation_queue; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
| 42 | - * |
|
| 43 | - * @type EE_Messages_Queue |
|
| 44 | - */ |
|
| 45 | - protected $_ready_queue; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * This is a container for any error messages that get created through the generation |
|
| 49 | - * process. |
|
| 50 | - * |
|
| 51 | - * @type array |
|
| 52 | - */ |
|
| 53 | - protected $_error_msg = array(); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
| 57 | - * |
|
| 58 | - * @type bool |
|
| 59 | - */ |
|
| 60 | - protected $_verified = false; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
| 64 | - * |
|
| 65 | - * @type EE_messenger |
|
| 66 | - */ |
|
| 67 | - protected $_current_messenger; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
| 71 | - * |
|
| 72 | - * @type EE_message_type |
|
| 73 | - */ |
|
| 74 | - protected $_current_message_type; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @type EEH_Parse_Shortcodes |
|
| 78 | - */ |
|
| 79 | - protected $_shortcode_parser; |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param EE_Messages_Queue $generation_queue |
|
| 84 | - * @param \EE_Messages_Queue $ready_queue |
|
| 85 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
| 86 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
| 87 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
| 88 | - */ |
|
| 89 | - public function __construct( |
|
| 90 | - EE_Messages_Queue $generation_queue, |
|
| 91 | - EE_Messages_Queue $ready_queue, |
|
| 92 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
| 93 | - EE_Message_Template_Group_Collection $template_collection, |
|
| 94 | - EEH_Parse_Shortcodes $shortcode_parser |
|
| 95 | - ) { |
|
| 96 | - $this->_generation_queue = $generation_queue; |
|
| 97 | - $this->_ready_queue = $ready_queue; |
|
| 98 | - $this->_data_handler_collection = $data_handler_collection; |
|
| 99 | - $this->_template_collection = $template_collection; |
|
| 100 | - $this->_shortcode_parser = $shortcode_parser; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return EE_Messages_Queue |
|
| 106 | - */ |
|
| 107 | - public function generation_queue() |
|
| 108 | - { |
|
| 109 | - return $this->_generation_queue; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
| 115 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
| 116 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
| 117 | - * for the caller to decide what to do with it. |
|
| 118 | - * |
|
| 119 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
| 120 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
| 121 | - * @throws EE_Error |
|
| 122 | - * @throws ReflectionException |
|
| 123 | - */ |
|
| 124 | - public function generate($save = true) |
|
| 125 | - { |
|
| 126 | - //iterate through the messages in the queue, generate, and add to new queue. |
|
| 127 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
| 128 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
| 129 | - //reset "current" properties |
|
| 130 | - $this->_reset_current_properties(); |
|
| 131 | - |
|
| 132 | - /** @type EE_Message $msg */ |
|
| 133 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
| 137 | - * an object is removed from the repo then valid for the next object will fail. |
|
| 138 | - */ |
|
| 139 | - $this->_generation_queue->get_message_repository()->next(); |
|
| 140 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
| 141 | - //restore pointer to current item |
|
| 142 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
| 143 | - |
|
| 144 | - //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
| 145 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
| 146 | - //we keep this item in the db just remove from the repo. |
|
| 147 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
| 148 | - //next item |
|
| 149 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
| 150 | - continue; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if ($this->_verify()) { |
|
| 154 | - //let's get generating! |
|
| 155 | - $this->_generate(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - //don't persist debug_only messages if the messages system is not in debug mode. |
|
| 159 | - if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
| 160 | - && ! EEM_Message::debug() |
|
| 161 | - ) { |
|
| 162 | - do_action( |
|
| 163 | - 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
| 164 | - $msg, |
|
| 165 | - $this->_error_msg, |
|
| 166 | - $this->_current_messenger, |
|
| 167 | - $this->_current_message_type, |
|
| 168 | - $this->_current_data_handler |
|
| 169 | - ); |
|
| 170 | - $this->_generation_queue->get_message_repository()->delete(); |
|
| 171 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
| 172 | - continue; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - //if there are error messages then let's set the status and the error message. |
|
| 176 | - if ($this->_error_msg) { |
|
| 177 | - //if the status is already debug only, then let's leave it at that. |
|
| 178 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
| 179 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
| 180 | - } |
|
| 181 | - do_action( |
|
| 182 | - 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
| 183 | - $msg, |
|
| 184 | - $this->_error_msg, |
|
| 185 | - $this->_current_messenger, |
|
| 186 | - $this->_current_message_type, |
|
| 187 | - $this->_current_data_handler |
|
| 188 | - ); |
|
| 189 | - $msg->set_error_message( |
|
| 190 | - esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
| 191 | - . "\n" |
|
| 192 | - . implode("\n", $this->_error_msg) |
|
| 193 | - ); |
|
| 194 | - $msg->set_modified(time()); |
|
| 195 | - } else { |
|
| 196 | - do_action( |
|
| 197 | - 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
| 198 | - $msg, |
|
| 199 | - $this->_error_msg, |
|
| 200 | - $this->_current_messenger, |
|
| 201 | - $this->_current_message_type, |
|
| 202 | - $this->_current_data_handler |
|
| 203 | - ); |
|
| 204 | - //remove from db |
|
| 205 | - $this->_generation_queue->get_message_repository()->delete(); |
|
| 206 | - } |
|
| 207 | - //next item |
|
| 208 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - //generation queue is ALWAYS saved to record any errors in the generation process. |
|
| 212 | - $this->_generation_queue->save(); |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * save _ready_queue if flag set. |
|
| 216 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
| 217 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
| 218 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
| 219 | - * irrelevant. |
|
| 220 | - */ |
|
| 221 | - if ($save) { |
|
| 222 | - $this->_ready_queue->save(); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - //final reset of properties |
|
| 226 | - $this->_reset_current_properties(); |
|
| 227 | - |
|
| 228 | - return $this->_ready_queue; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
| 234 | - * in the generation queue. |
|
| 235 | - */ |
|
| 236 | - protected function _reset_current_properties() |
|
| 237 | - { |
|
| 238 | - $this->_verified = false; |
|
| 239 | - //make sure any _data value in the current message type is reset |
|
| 240 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
| 241 | - $this->_current_message_type->reset_data(); |
|
| 242 | - } |
|
| 243 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
| 249 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
| 250 | - * _generating_queue. |
|
| 251 | - * |
|
| 252 | - * @return bool Whether the message was successfully generated or not. |
|
| 253 | - * @throws EE_Error |
|
| 254 | - * @throws InvalidArgumentException |
|
| 255 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 256 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 257 | - */ |
|
| 258 | - protected function _generate() |
|
| 259 | - { |
|
| 260 | - //double check verification has run and that everything is ready to work with (saves us having to validate |
|
| 261 | - // everything again). |
|
| 262 | - if (! $this->_verified) { |
|
| 263 | - return false; //get out because we don't have a valid setup to work with. |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - try { |
|
| 268 | - $addressees = $this->_current_message_type->get_addressees( |
|
| 269 | - $this->_current_data_handler, |
|
| 270 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
| 271 | - ); |
|
| 272 | - } catch (EE_Error $e) { |
|
| 273 | - $this->_error_msg[] = $e->getMessage(); |
|
| 274 | - return false; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - //if no addressees then get out because there is nothing to generation (possible bad data). |
|
| 279 | - if (! $this->_valid_addressees($addressees)) { |
|
| 280 | - do_action( |
|
| 281 | - 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
| 282 | - $this->_generation_queue->get_message_repository()->current(), |
|
| 283 | - $addressees, |
|
| 284 | - $this->_current_messenger, |
|
| 285 | - $this->_current_message_type, |
|
| 286 | - $this->_current_data_handler |
|
| 287 | - ); |
|
| 288 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
| 289 | - EEM_Message::status_debug_only |
|
| 290 | - ); |
|
| 291 | - $this->_error_msg[] = esc_html__( |
|
| 292 | - 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
| 293 | - 'event_espresso' |
|
| 294 | - ); |
|
| 295 | - return false; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $message_template_group = $this->_get_message_template_group(); |
|
| 299 | - |
|
| 300 | - //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
| 301 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 302 | - $this->_error_msg[] = esc_html__( |
|
| 303 | - 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
| 304 | - 'event_espresso' |
|
| 305 | - ); |
|
| 306 | - return false; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - //get formatted templates for using to parse and setup EE_Message objects. |
|
| 310 | - $templates = $this->_get_templates($message_template_group); |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - //setup new EE_Message objects (and add to _ready_queue) |
|
| 314 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Retrieves the message template group being used for generating messages. |
|
| 320 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
| 321 | - * |
|
| 322 | - * @return EE_Message_Template_Group|null |
|
| 323 | - * @throws EE_Error |
|
| 324 | - * @throws InvalidArgumentException |
|
| 325 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 326 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 327 | - */ |
|
| 328 | - protected function _get_message_template_group() |
|
| 329 | - { |
|
| 330 | - //first see if there is a specific message template group requested (current message in the queue has a specific |
|
| 331 | - //GRP_ID |
|
| 332 | - $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
| 333 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 334 | - return $message_template_group; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
| 338 | - //in the collection. |
|
| 339 | - $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
| 340 | - $message_template_group = $this->_template_collection->get_by_key( |
|
| 341 | - $this->_template_collection->getKey( |
|
| 342 | - $this->_current_messenger->name, |
|
| 343 | - $this->_current_message_type->name, |
|
| 344 | - $event_ids |
|
| 345 | - ) |
|
| 346 | - ); |
|
| 347 | - |
|
| 348 | - //if we have a message template group then no need to hit the database, just return it. |
|
| 349 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 350 | - return $message_template_group; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
| 354 | - //there is no override set. |
|
| 355 | - $global_message_template_group = |
|
| 356 | - $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
| 357 | - |
|
| 358 | - if ($global_message_template_group instanceof EE_Message_Template_Group |
|
| 359 | - && $global_message_template_group->get('MTP_is_override') |
|
| 360 | - ) { |
|
| 361 | - return $global_message_template_group; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - //if we're still here, that means there was no message template group for the events in the collection and |
|
| 365 | - //the global message template group for the messenger and message type is not set for override. So next step is |
|
| 366 | - //to see if there is a common shared custom message template group for this set of events. |
|
| 367 | - $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
| 368 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 369 | - return $message_template_group; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
| 373 | - //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
| 374 | - //and return it. |
|
| 375 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 376 | - $this->_template_collection->add( |
|
| 377 | - $global_message_template_group, |
|
| 378 | - $event_ids |
|
| 379 | - ); |
|
| 380 | - return $global_message_template_group; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - //if we land here that means there's NO active message template group for this set. |
|
| 384 | - //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
| 385 | - //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
| 386 | - //this should likely bit hit rarely enough that it's not a significant issue. |
|
| 387 | - return null; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
| 393 | - * requested for that message. |
|
| 394 | - * |
|
| 395 | - * @return EE_Message_Template_Group|null |
|
| 396 | - * @throws EE_Error |
|
| 397 | - * @throws InvalidArgumentException |
|
| 398 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 399 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 400 | - */ |
|
| 401 | - protected function _specific_message_template_group_from_queue() |
|
| 402 | - { |
|
| 403 | - //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
| 404 | - //so let's use that. |
|
| 405 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
| 406 | - |
|
| 407 | - if ($GRP_ID) { |
|
| 408 | - //attempt to retrieve from repo first |
|
| 409 | - $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
| 410 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 411 | - return $message_template_group; //got it! |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
| 415 | - //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
| 416 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 417 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 418 | - $this->_template_collection->add($message_template_group); |
|
| 419 | - return $message_template_group; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - return null; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Returns whether the event ids passed in all share the same message template group for the current message type |
|
| 428 | - * and messenger. |
|
| 429 | - * |
|
| 430 | - * @param array $event_ids |
|
| 431 | - * @return bool true means they DO share the same message template group, false means they don't. |
|
| 432 | - * @throws EE_Error |
|
| 433 | - * @throws InvalidArgumentException |
|
| 434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | - */ |
|
| 437 | - protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
| 438 | - { |
|
| 439 | - foreach ($this->_current_data_handler->events as $event) { |
|
| 440 | - $event_ids[$event['ID']] = $event['ID']; |
|
| 441 | - } |
|
| 442 | - $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
| 443 | - array( |
|
| 444 | - array( |
|
| 445 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
| 446 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
| 447 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
| 448 | - ), |
|
| 449 | - ), |
|
| 450 | - 'GRP_ID', |
|
| 451 | - true |
|
| 452 | - ); |
|
| 453 | - return $count_of_message_template_groups === 1; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
| 459 | - * there's a single shared message template group among all the events. Otherwise it returns null. |
|
| 460 | - * |
|
| 461 | - * @param array $event_ids |
|
| 462 | - * @return EE_Message_Template_Group|null |
|
| 463 | - * @throws EE_Error |
|
| 464 | - * @throws InvalidArgumentException |
|
| 465 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 466 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 467 | - */ |
|
| 468 | - protected function _get_shared_message_template_for_events(array $event_ids) |
|
| 469 | - { |
|
| 470 | - $message_template_group = null; |
|
| 471 | - if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
| 472 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
| 473 | - array( |
|
| 474 | - array( |
|
| 475 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
| 476 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
| 477 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
| 478 | - 'MTP_is_active' => true, |
|
| 479 | - ), |
|
| 480 | - 'group_by' => 'GRP_ID', |
|
| 481 | - ) |
|
| 482 | - ); |
|
| 483 | - //store this in the collection if its valid |
|
| 484 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 485 | - $this->_template_collection->add( |
|
| 486 | - $message_template_group, |
|
| 487 | - $event_ids |
|
| 488 | - ); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - return $message_template_group; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Retrieves the global message template group for the current messenger and message type. |
|
| 497 | - * |
|
| 498 | - * @return EE_Message_Template_Group|null |
|
| 499 | - * @throws EE_Error |
|
| 500 | - * @throws InvalidArgumentException |
|
| 501 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 502 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 503 | - */ |
|
| 504 | - protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
| 505 | - { |
|
| 506 | - //first check the collection (we use an array with 0 in it to represent global groups). |
|
| 507 | - $global_message_template_group = $this->_template_collection->get_by_key( |
|
| 508 | - $this->_template_collection->getKey( |
|
| 509 | - $this->_current_messenger->name, |
|
| 510 | - $this->_current_message_type->name, |
|
| 511 | - array(0) |
|
| 512 | - ) |
|
| 513 | - ); |
|
| 514 | - |
|
| 515 | - //if we don't have a group lets hit the db. |
|
| 516 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 517 | - $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
| 518 | - array( |
|
| 519 | - array( |
|
| 520 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
| 521 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
| 522 | - 'MTP_is_active' => true, |
|
| 523 | - 'MTP_is_global' => true, |
|
| 524 | - ), |
|
| 525 | - ) |
|
| 526 | - ); |
|
| 527 | - //if we have a group, add it to the collection. |
|
| 528 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 529 | - $this->_template_collection->add( |
|
| 530 | - $global_message_template_group, |
|
| 531 | - array(0) |
|
| 532 | - ); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - return $global_message_template_group; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Returns an array of event ids for all the events within the current data handler. |
|
| 541 | - * |
|
| 542 | - * @return array |
|
| 543 | - */ |
|
| 544 | - protected function _get_event_ids_from_current_data_handler() |
|
| 545 | - { |
|
| 546 | - $event_ids = array(); |
|
| 547 | - foreach ($this->_current_data_handler->events as $event) { |
|
| 548 | - $event_ids[$event['ID']] = $event['ID']; |
|
| 549 | - } |
|
| 550 | - return $event_ids; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Retrieves formatted array of template information for each context specific to the given |
|
| 556 | - * EE_Message_Template_Group |
|
| 557 | - * |
|
| 558 | - * @param EE_Message_Template_Group $message_template_group |
|
| 559 | - * @return array The returned array is in this structure: |
|
| 560 | - * array( |
|
| 561 | - * 'field_name' => array( |
|
| 562 | - * 'context' => 'content' |
|
| 563 | - * ) |
|
| 564 | - * ) |
|
| 565 | - * @throws EE_Error |
|
| 566 | - */ |
|
| 567 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
| 568 | - { |
|
| 569 | - $templates = array(); |
|
| 570 | - $context_templates = $message_template_group->context_templates(); |
|
| 571 | - foreach ($context_templates as $context => $template_fields) { |
|
| 572 | - foreach ($template_fields as $template_field => $template_obj) { |
|
| 573 | - if (! $template_obj instanceof EE_Message_Template) { |
|
| 574 | - continue; |
|
| 575 | - } |
|
| 576 | - $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - return $templates; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
| 585 | - * |
|
| 586 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
| 587 | - * context. |
|
| 588 | - * @param array $templates formatted array of templates used for parsing data. |
|
| 589 | - * @param EE_Message_Template_Group $message_template_group |
|
| 590 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
| 591 | - * method will attempt to generate ALL EE_Message objects and add to |
|
| 592 | - * the _ready_queue. Successfully generated messages get added to the |
|
| 593 | - * queue with EEM_Message::status_idle, unsuccessfully generated |
|
| 594 | - * messages will get added to the queue as EEM_Message::status_failed. |
|
| 595 | - * Very rarely should "false" be returned from this method. |
|
| 596 | - * @throws EE_Error |
|
| 597 | - */ |
|
| 598 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
| 599 | - { |
|
| 600 | - |
|
| 601 | - //if templates are empty then get out because we can't generate anything. |
|
| 602 | - if (! $templates) { |
|
| 603 | - $this->_error_msg[] = esc_html__( |
|
| 604 | - 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
| 605 | - 'event_espresso' |
|
| 606 | - ); |
|
| 607 | - return false; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
| 611 | - //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
| 612 | - $generated_count = 0; |
|
| 613 | - foreach ($addressees as $context => $recipients) { |
|
| 614 | - foreach ($recipients as $recipient) { |
|
| 615 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
| 616 | - if ($message instanceof EE_Message) { |
|
| 617 | - $this->_ready_queue->add( |
|
| 618 | - $message, |
|
| 619 | - array(), |
|
| 620 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
| 621 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
| 622 | - ); |
|
| 623 | - $generated_count++; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - //if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
| 627 | - // generation. |
|
| 628 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
| 629 | - break 2; |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - //if there are no generated messages then something else fatal went wrong. |
|
| 635 | - return $generated_count > 0; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * @param string $context The context for the generated message. |
|
| 641 | - * @param EE_Messages_Addressee $recipient |
|
| 642 | - * @param array $templates formatted array of templates used for parsing data. |
|
| 643 | - * @param EE_Message_Template_Group $message_template_group |
|
| 644 | - * @return bool|EE_Message |
|
| 645 | - * @throws EE_Error |
|
| 646 | - */ |
|
| 647 | - protected function _setup_message_object( |
|
| 648 | - $context, |
|
| 649 | - EE_Messages_Addressee $recipient, |
|
| 650 | - $templates, |
|
| 651 | - EE_Message_Template_Group $message_template_group |
|
| 652 | - ) { |
|
| 653 | - //stuff we already know |
|
| 654 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
| 655 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
| 656 | - ? $this->_current_data_handler->txn->ID() |
|
| 657 | - : $transaction_id; |
|
| 658 | - $message_fields = array( |
|
| 659 | - 'GRP_ID' => $message_template_group->ID(), |
|
| 660 | - 'TXN_ID' => $transaction_id, |
|
| 661 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
| 662 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
| 663 | - 'MSG_context' => $context, |
|
| 664 | - ); |
|
| 665 | - |
|
| 666 | - //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
| 667 | - // the info from the att_obj found in the EE_Messages_Addressee object. |
|
| 668 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
| 669 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
| 670 | - ? $recipient->att_obj->ID() |
|
| 671 | - : 0; |
|
| 672 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
| 673 | - } else { |
|
| 674 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
| 675 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
| 676 | - } |
|
| 677 | - $message = EE_Message_Factory::create($message_fields); |
|
| 678 | - |
|
| 679 | - //grab valid shortcodes for shortcode parser |
|
| 680 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
| 681 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
| 682 | - |
|
| 683 | - //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
| 684 | - if (( |
|
| 685 | - ( |
|
| 686 | - empty($templates['to'][$context]) |
|
| 687 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
| 688 | - ) |
|
| 689 | - || ! $message_template_group->is_context_active($context) |
|
| 690 | - ) |
|
| 691 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
| 692 | - ) { |
|
| 693 | - //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
| 694 | - //field. |
|
| 695 | - return false; |
|
| 696 | - } |
|
| 697 | - $error_msg = array(); |
|
| 698 | - foreach ($templates as $field => $field_context) { |
|
| 699 | - $error_msg = array(); |
|
| 700 | - //let's setup the valid shortcodes for the incoming context. |
|
| 701 | - $valid_shortcodes = $mt_shortcodes[$context]; |
|
| 702 | - //merge in valid shortcodes for the field. |
|
| 703 | - $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
| 704 | - if (isset($templates[$field][$context])) { |
|
| 705 | - //prefix field. |
|
| 706 | - $column_name = 'MSG_' . $field; |
|
| 707 | - try { |
|
| 708 | - $content = $this->_shortcode_parser->parse_message_template( |
|
| 709 | - $templates[$field][$context], |
|
| 710 | - $recipient, |
|
| 711 | - $shortcodes, |
|
| 712 | - $this->_current_message_type, |
|
| 713 | - $this->_current_messenger, |
|
| 714 | - $message |
|
| 715 | - ); |
|
| 716 | - $message->set_field_or_extra_meta($column_name, $content); |
|
| 717 | - } catch (EE_Error $e) { |
|
| 718 | - $error_msg[] = sprintf( |
|
| 719 | - esc_html__( |
|
| 720 | - 'There was a problem generating the content for the field %s: %s', |
|
| 721 | - 'event_espresso' |
|
| 722 | - ), |
|
| 723 | - $field, |
|
| 724 | - $e->getMessage() |
|
| 725 | - ); |
|
| 726 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
| 732 | - $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
| 733 | - . "\n" |
|
| 734 | - . implode("\n", $error_msg); |
|
| 735 | - $message->set_error_message($error_msg); |
|
| 736 | - } else { |
|
| 737 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
| 738 | - } |
|
| 739 | - return $message; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
| 745 | - * error message if either is missing. |
|
| 746 | - * |
|
| 747 | - * @return bool true means there were no errors, false means there were errors. |
|
| 748 | - * @throws EE_Error |
|
| 749 | - * @throws ReflectionException |
|
| 750 | - */ |
|
| 751 | - protected function _verify() |
|
| 752 | - { |
|
| 753 | - //reset error message to an empty array. |
|
| 754 | - $this->_error_msg = array(); |
|
| 755 | - $valid = true; |
|
| 756 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
| 757 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
| 758 | - |
|
| 759 | - //set the verified flag so we know everything has been validated. |
|
| 760 | - $this->_verified = $valid; |
|
| 761 | - |
|
| 762 | - return $valid; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
| 768 | - * EE_Messages_Addressee objects. |
|
| 769 | - * |
|
| 770 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
| 771 | - * @return bool |
|
| 772 | - */ |
|
| 773 | - protected function _valid_addressees($addressees) |
|
| 774 | - { |
|
| 775 | - if (! $addressees || ! is_array($addressees)) { |
|
| 776 | - return false; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - foreach ($addressees as $addressee_array) { |
|
| 780 | - foreach ($addressee_array as $addressee) { |
|
| 781 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
| 782 | - return false; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - return true; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
| 792 | - * queue. This process sets error messages if something is wrong. |
|
| 793 | - * |
|
| 794 | - * @return bool true is if there are no errors. false is if there is. |
|
| 795 | - */ |
|
| 796 | - protected function _validate_messenger_and_message_type() |
|
| 797 | - { |
|
| 798 | - |
|
| 799 | - //first are there any existing error messages? If so then return. |
|
| 800 | - if ($this->_error_msg) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - /** @type EE_Message $message */ |
|
| 804 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
| 805 | - try { |
|
| 806 | - $this->_current_messenger = $message->valid_messenger(true) |
|
| 807 | - ? $message->messenger_object() |
|
| 808 | - : null; |
|
| 809 | - } catch (Exception $e) { |
|
| 810 | - $this->_error_msg[] = $e->getMessage(); |
|
| 811 | - } |
|
| 812 | - try { |
|
| 813 | - $this->_current_message_type = $message->valid_message_type(true) |
|
| 814 | - ? $message->message_type_object() |
|
| 815 | - : null; |
|
| 816 | - } catch (Exception $e) { |
|
| 817 | - $this->_error_msg[] = $e->getMessage(); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Check if there is any generation data, but only if this is not for a preview. |
|
| 822 | - */ |
|
| 823 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
| 824 | - && ( |
|
| 825 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
| 826 | - && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
| 827 | - !== 'EE_Messages_Preview_incoming_data' |
|
| 828 | - ) |
|
| 829 | - ) { |
|
| 830 | - $this->_error_msg[] = esc_html__( |
|
| 831 | - 'There is no generation data for this message. Unable to generate.', |
|
| 832 | - 'event_espresso' |
|
| 833 | - ); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - return empty($this->_error_msg); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
| 842 | - * data handler. |
|
| 843 | - * |
|
| 844 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
| 845 | - * @throws EE_Error |
|
| 846 | - * @throws ReflectionException |
|
| 847 | - */ |
|
| 848 | - protected function _validate_and_setup_data() |
|
| 849 | - { |
|
| 850 | - |
|
| 851 | - //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
| 852 | - //be used anyways. |
|
| 853 | - if ($this->_error_msg) { |
|
| 854 | - return false; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
| 858 | - |
|
| 859 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
| 860 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
| 861 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
| 862 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
| 863 | - |
|
| 864 | - //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
| 865 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
| 866 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - //First get the class name for the data handler (and also verifies it exists. |
|
| 870 | - if (! class_exists($data_handler_class_name)) { |
|
| 871 | - $this->_error_msg[] = sprintf( |
|
| 872 | - esc_html__( |
|
| 873 | - 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
| 874 | - 'event_espresso' |
|
| 875 | - ), |
|
| 876 | - 'EE_Messages_incoming_data', |
|
| 877 | - $data_handler_class_name |
|
| 878 | - ); |
|
| 879 | - return false; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - //convert generation_data for data_handler_instantiation. |
|
| 883 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
| 884 | - |
|
| 885 | - //note, this may set error messages as well. |
|
| 886 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
| 887 | - |
|
| 888 | - return empty($this->_error_msg); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
| 894 | - * adds it to the _data repository. |
|
| 895 | - * |
|
| 896 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
| 897 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
| 898 | - * instantiated. |
|
| 899 | - * @return void . |
|
| 900 | - * @throws EE_Error |
|
| 901 | - * @throws ReflectionException |
|
| 902 | - */ |
|
| 903 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
| 904 | - { |
|
| 905 | - //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
| 906 | - //is already a ready data handler in the repository. |
|
| 907 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
| 908 | - $this->_data_handler_collection->get_key( |
|
| 909 | - $data_handler_class_name, |
|
| 910 | - $generating_data |
|
| 911 | - ) |
|
| 912 | - ); |
|
| 913 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
| 914 | - //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
| 915 | - try { |
|
| 916 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
| 917 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
| 918 | - } catch (EE_Error $e) { |
|
| 919 | - $this->_error_msg[] = $e->get_error(); |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
| 927 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
| 928 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
| 929 | - * and that preps the data for later instantiation when generating. |
|
| 930 | - * |
|
| 931 | - * @param EE_Message_To_Generate $message_to_generate |
|
| 932 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
| 933 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
| 934 | - */ |
|
| 935 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
| 936 | - { |
|
| 937 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
| 938 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
| 939 | - if (! $message_to_generate->valid()) { |
|
| 940 | - return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
| 941 | - } |
|
| 942 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
| 948 | - * |
|
| 949 | - * @param EE_Message_To_Generate $message_to_generate |
|
| 950 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
| 951 | - * @throws InvalidArgumentException |
|
| 952 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 953 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 954 | - */ |
|
| 955 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
| 956 | - { |
|
| 957 | - //prep data |
|
| 958 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
| 959 | - |
|
| 960 | - $message = $message_to_generate->get_EE_Message(); |
|
| 961 | - |
|
| 962 | - //is there a GRP_ID in the request? |
|
| 963 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
| 964 | - $message->set_GRP_ID($GRP_ID); |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - if ($data === false) { |
|
| 968 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
| 969 | - $message->set_error_message( |
|
| 970 | - esc_html__( |
|
| 971 | - 'Unable to prepare data for persistence to the database.', |
|
| 972 | - 'event_espresso' |
|
| 973 | - ) |
|
| 974 | - ); |
|
| 975 | - } else { |
|
| 976 | - //make sure that the data handler is cached on the message as well |
|
| 977 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
| 981 | - } |
|
| 16 | + /** |
|
| 17 | + * @type EE_Messages_Data_Handler_Collection |
|
| 18 | + */ |
|
| 19 | + protected $_data_handler_collection; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @type EE_Message_Template_Group_Collection |
|
| 23 | + */ |
|
| 24 | + protected $_template_collection; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * This will hold the data handler for the current EE_Message being generated. |
|
| 28 | + * |
|
| 29 | + * @type EE_Messages_incoming_data |
|
| 30 | + */ |
|
| 31 | + protected $_current_data_handler; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
| 35 | + * |
|
| 36 | + * @type EE_Messages_Queue |
|
| 37 | + */ |
|
| 38 | + protected $_generation_queue; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
| 42 | + * |
|
| 43 | + * @type EE_Messages_Queue |
|
| 44 | + */ |
|
| 45 | + protected $_ready_queue; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * This is a container for any error messages that get created through the generation |
|
| 49 | + * process. |
|
| 50 | + * |
|
| 51 | + * @type array |
|
| 52 | + */ |
|
| 53 | + protected $_error_msg = array(); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
| 57 | + * |
|
| 58 | + * @type bool |
|
| 59 | + */ |
|
| 60 | + protected $_verified = false; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
| 64 | + * |
|
| 65 | + * @type EE_messenger |
|
| 66 | + */ |
|
| 67 | + protected $_current_messenger; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
| 71 | + * |
|
| 72 | + * @type EE_message_type |
|
| 73 | + */ |
|
| 74 | + protected $_current_message_type; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @type EEH_Parse_Shortcodes |
|
| 78 | + */ |
|
| 79 | + protected $_shortcode_parser; |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param EE_Messages_Queue $generation_queue |
|
| 84 | + * @param \EE_Messages_Queue $ready_queue |
|
| 85 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
| 86 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
| 87 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
| 88 | + */ |
|
| 89 | + public function __construct( |
|
| 90 | + EE_Messages_Queue $generation_queue, |
|
| 91 | + EE_Messages_Queue $ready_queue, |
|
| 92 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
| 93 | + EE_Message_Template_Group_Collection $template_collection, |
|
| 94 | + EEH_Parse_Shortcodes $shortcode_parser |
|
| 95 | + ) { |
|
| 96 | + $this->_generation_queue = $generation_queue; |
|
| 97 | + $this->_ready_queue = $ready_queue; |
|
| 98 | + $this->_data_handler_collection = $data_handler_collection; |
|
| 99 | + $this->_template_collection = $template_collection; |
|
| 100 | + $this->_shortcode_parser = $shortcode_parser; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return EE_Messages_Queue |
|
| 106 | + */ |
|
| 107 | + public function generation_queue() |
|
| 108 | + { |
|
| 109 | + return $this->_generation_queue; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
| 115 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
| 116 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
| 117 | + * for the caller to decide what to do with it. |
|
| 118 | + * |
|
| 119 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
| 120 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
| 121 | + * @throws EE_Error |
|
| 122 | + * @throws ReflectionException |
|
| 123 | + */ |
|
| 124 | + public function generate($save = true) |
|
| 125 | + { |
|
| 126 | + //iterate through the messages in the queue, generate, and add to new queue. |
|
| 127 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
| 128 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
| 129 | + //reset "current" properties |
|
| 130 | + $this->_reset_current_properties(); |
|
| 131 | + |
|
| 132 | + /** @type EE_Message $msg */ |
|
| 133 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
| 137 | + * an object is removed from the repo then valid for the next object will fail. |
|
| 138 | + */ |
|
| 139 | + $this->_generation_queue->get_message_repository()->next(); |
|
| 140 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
| 141 | + //restore pointer to current item |
|
| 142 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
| 143 | + |
|
| 144 | + //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
| 145 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
| 146 | + //we keep this item in the db just remove from the repo. |
|
| 147 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
| 148 | + //next item |
|
| 149 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if ($this->_verify()) { |
|
| 154 | + //let's get generating! |
|
| 155 | + $this->_generate(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + //don't persist debug_only messages if the messages system is not in debug mode. |
|
| 159 | + if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
| 160 | + && ! EEM_Message::debug() |
|
| 161 | + ) { |
|
| 162 | + do_action( |
|
| 163 | + 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
| 164 | + $msg, |
|
| 165 | + $this->_error_msg, |
|
| 166 | + $this->_current_messenger, |
|
| 167 | + $this->_current_message_type, |
|
| 168 | + $this->_current_data_handler |
|
| 169 | + ); |
|
| 170 | + $this->_generation_queue->get_message_repository()->delete(); |
|
| 171 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + //if there are error messages then let's set the status and the error message. |
|
| 176 | + if ($this->_error_msg) { |
|
| 177 | + //if the status is already debug only, then let's leave it at that. |
|
| 178 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
| 179 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
| 180 | + } |
|
| 181 | + do_action( |
|
| 182 | + 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
| 183 | + $msg, |
|
| 184 | + $this->_error_msg, |
|
| 185 | + $this->_current_messenger, |
|
| 186 | + $this->_current_message_type, |
|
| 187 | + $this->_current_data_handler |
|
| 188 | + ); |
|
| 189 | + $msg->set_error_message( |
|
| 190 | + esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
| 191 | + . "\n" |
|
| 192 | + . implode("\n", $this->_error_msg) |
|
| 193 | + ); |
|
| 194 | + $msg->set_modified(time()); |
|
| 195 | + } else { |
|
| 196 | + do_action( |
|
| 197 | + 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
| 198 | + $msg, |
|
| 199 | + $this->_error_msg, |
|
| 200 | + $this->_current_messenger, |
|
| 201 | + $this->_current_message_type, |
|
| 202 | + $this->_current_data_handler |
|
| 203 | + ); |
|
| 204 | + //remove from db |
|
| 205 | + $this->_generation_queue->get_message_repository()->delete(); |
|
| 206 | + } |
|
| 207 | + //next item |
|
| 208 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + //generation queue is ALWAYS saved to record any errors in the generation process. |
|
| 212 | + $this->_generation_queue->save(); |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * save _ready_queue if flag set. |
|
| 216 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
| 217 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
| 218 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
| 219 | + * irrelevant. |
|
| 220 | + */ |
|
| 221 | + if ($save) { |
|
| 222 | + $this->_ready_queue->save(); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + //final reset of properties |
|
| 226 | + $this->_reset_current_properties(); |
|
| 227 | + |
|
| 228 | + return $this->_ready_queue; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
| 234 | + * in the generation queue. |
|
| 235 | + */ |
|
| 236 | + protected function _reset_current_properties() |
|
| 237 | + { |
|
| 238 | + $this->_verified = false; |
|
| 239 | + //make sure any _data value in the current message type is reset |
|
| 240 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
| 241 | + $this->_current_message_type->reset_data(); |
|
| 242 | + } |
|
| 243 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
| 249 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
| 250 | + * _generating_queue. |
|
| 251 | + * |
|
| 252 | + * @return bool Whether the message was successfully generated or not. |
|
| 253 | + * @throws EE_Error |
|
| 254 | + * @throws InvalidArgumentException |
|
| 255 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 256 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 257 | + */ |
|
| 258 | + protected function _generate() |
|
| 259 | + { |
|
| 260 | + //double check verification has run and that everything is ready to work with (saves us having to validate |
|
| 261 | + // everything again). |
|
| 262 | + if (! $this->_verified) { |
|
| 263 | + return false; //get out because we don't have a valid setup to work with. |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + try { |
|
| 268 | + $addressees = $this->_current_message_type->get_addressees( |
|
| 269 | + $this->_current_data_handler, |
|
| 270 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
| 271 | + ); |
|
| 272 | + } catch (EE_Error $e) { |
|
| 273 | + $this->_error_msg[] = $e->getMessage(); |
|
| 274 | + return false; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + //if no addressees then get out because there is nothing to generation (possible bad data). |
|
| 279 | + if (! $this->_valid_addressees($addressees)) { |
|
| 280 | + do_action( |
|
| 281 | + 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
| 282 | + $this->_generation_queue->get_message_repository()->current(), |
|
| 283 | + $addressees, |
|
| 284 | + $this->_current_messenger, |
|
| 285 | + $this->_current_message_type, |
|
| 286 | + $this->_current_data_handler |
|
| 287 | + ); |
|
| 288 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
| 289 | + EEM_Message::status_debug_only |
|
| 290 | + ); |
|
| 291 | + $this->_error_msg[] = esc_html__( |
|
| 292 | + 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
| 293 | + 'event_espresso' |
|
| 294 | + ); |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $message_template_group = $this->_get_message_template_group(); |
|
| 299 | + |
|
| 300 | + //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
| 301 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 302 | + $this->_error_msg[] = esc_html__( |
|
| 303 | + 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
| 304 | + 'event_espresso' |
|
| 305 | + ); |
|
| 306 | + return false; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + //get formatted templates for using to parse and setup EE_Message objects. |
|
| 310 | + $templates = $this->_get_templates($message_template_group); |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + //setup new EE_Message objects (and add to _ready_queue) |
|
| 314 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Retrieves the message template group being used for generating messages. |
|
| 320 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
| 321 | + * |
|
| 322 | + * @return EE_Message_Template_Group|null |
|
| 323 | + * @throws EE_Error |
|
| 324 | + * @throws InvalidArgumentException |
|
| 325 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 326 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 327 | + */ |
|
| 328 | + protected function _get_message_template_group() |
|
| 329 | + { |
|
| 330 | + //first see if there is a specific message template group requested (current message in the queue has a specific |
|
| 331 | + //GRP_ID |
|
| 332 | + $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
| 333 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 334 | + return $message_template_group; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
| 338 | + //in the collection. |
|
| 339 | + $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
| 340 | + $message_template_group = $this->_template_collection->get_by_key( |
|
| 341 | + $this->_template_collection->getKey( |
|
| 342 | + $this->_current_messenger->name, |
|
| 343 | + $this->_current_message_type->name, |
|
| 344 | + $event_ids |
|
| 345 | + ) |
|
| 346 | + ); |
|
| 347 | + |
|
| 348 | + //if we have a message template group then no need to hit the database, just return it. |
|
| 349 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 350 | + return $message_template_group; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
| 354 | + //there is no override set. |
|
| 355 | + $global_message_template_group = |
|
| 356 | + $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
| 357 | + |
|
| 358 | + if ($global_message_template_group instanceof EE_Message_Template_Group |
|
| 359 | + && $global_message_template_group->get('MTP_is_override') |
|
| 360 | + ) { |
|
| 361 | + return $global_message_template_group; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + //if we're still here, that means there was no message template group for the events in the collection and |
|
| 365 | + //the global message template group for the messenger and message type is not set for override. So next step is |
|
| 366 | + //to see if there is a common shared custom message template group for this set of events. |
|
| 367 | + $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
| 368 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 369 | + return $message_template_group; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
| 373 | + //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
| 374 | + //and return it. |
|
| 375 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 376 | + $this->_template_collection->add( |
|
| 377 | + $global_message_template_group, |
|
| 378 | + $event_ids |
|
| 379 | + ); |
|
| 380 | + return $global_message_template_group; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + //if we land here that means there's NO active message template group for this set. |
|
| 384 | + //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
| 385 | + //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
| 386 | + //this should likely bit hit rarely enough that it's not a significant issue. |
|
| 387 | + return null; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
| 393 | + * requested for that message. |
|
| 394 | + * |
|
| 395 | + * @return EE_Message_Template_Group|null |
|
| 396 | + * @throws EE_Error |
|
| 397 | + * @throws InvalidArgumentException |
|
| 398 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 399 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 400 | + */ |
|
| 401 | + protected function _specific_message_template_group_from_queue() |
|
| 402 | + { |
|
| 403 | + //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
| 404 | + //so let's use that. |
|
| 405 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
| 406 | + |
|
| 407 | + if ($GRP_ID) { |
|
| 408 | + //attempt to retrieve from repo first |
|
| 409 | + $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
| 410 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 411 | + return $message_template_group; //got it! |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
| 415 | + //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
| 416 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 417 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 418 | + $this->_template_collection->add($message_template_group); |
|
| 419 | + return $message_template_group; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + return null; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Returns whether the event ids passed in all share the same message template group for the current message type |
|
| 428 | + * and messenger. |
|
| 429 | + * |
|
| 430 | + * @param array $event_ids |
|
| 431 | + * @return bool true means they DO share the same message template group, false means they don't. |
|
| 432 | + * @throws EE_Error |
|
| 433 | + * @throws InvalidArgumentException |
|
| 434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | + */ |
|
| 437 | + protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
| 438 | + { |
|
| 439 | + foreach ($this->_current_data_handler->events as $event) { |
|
| 440 | + $event_ids[$event['ID']] = $event['ID']; |
|
| 441 | + } |
|
| 442 | + $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
| 443 | + array( |
|
| 444 | + array( |
|
| 445 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
| 446 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
| 447 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
| 448 | + ), |
|
| 449 | + ), |
|
| 450 | + 'GRP_ID', |
|
| 451 | + true |
|
| 452 | + ); |
|
| 453 | + return $count_of_message_template_groups === 1; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
| 459 | + * there's a single shared message template group among all the events. Otherwise it returns null. |
|
| 460 | + * |
|
| 461 | + * @param array $event_ids |
|
| 462 | + * @return EE_Message_Template_Group|null |
|
| 463 | + * @throws EE_Error |
|
| 464 | + * @throws InvalidArgumentException |
|
| 465 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 466 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 467 | + */ |
|
| 468 | + protected function _get_shared_message_template_for_events(array $event_ids) |
|
| 469 | + { |
|
| 470 | + $message_template_group = null; |
|
| 471 | + if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
| 472 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
| 473 | + array( |
|
| 474 | + array( |
|
| 475 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
| 476 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
| 477 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
| 478 | + 'MTP_is_active' => true, |
|
| 479 | + ), |
|
| 480 | + 'group_by' => 'GRP_ID', |
|
| 481 | + ) |
|
| 482 | + ); |
|
| 483 | + //store this in the collection if its valid |
|
| 484 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
| 485 | + $this->_template_collection->add( |
|
| 486 | + $message_template_group, |
|
| 487 | + $event_ids |
|
| 488 | + ); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + return $message_template_group; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Retrieves the global message template group for the current messenger and message type. |
|
| 497 | + * |
|
| 498 | + * @return EE_Message_Template_Group|null |
|
| 499 | + * @throws EE_Error |
|
| 500 | + * @throws InvalidArgumentException |
|
| 501 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 502 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 503 | + */ |
|
| 504 | + protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
| 505 | + { |
|
| 506 | + //first check the collection (we use an array with 0 in it to represent global groups). |
|
| 507 | + $global_message_template_group = $this->_template_collection->get_by_key( |
|
| 508 | + $this->_template_collection->getKey( |
|
| 509 | + $this->_current_messenger->name, |
|
| 510 | + $this->_current_message_type->name, |
|
| 511 | + array(0) |
|
| 512 | + ) |
|
| 513 | + ); |
|
| 514 | + |
|
| 515 | + //if we don't have a group lets hit the db. |
|
| 516 | + if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 517 | + $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
| 518 | + array( |
|
| 519 | + array( |
|
| 520 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
| 521 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
| 522 | + 'MTP_is_active' => true, |
|
| 523 | + 'MTP_is_global' => true, |
|
| 524 | + ), |
|
| 525 | + ) |
|
| 526 | + ); |
|
| 527 | + //if we have a group, add it to the collection. |
|
| 528 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 529 | + $this->_template_collection->add( |
|
| 530 | + $global_message_template_group, |
|
| 531 | + array(0) |
|
| 532 | + ); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + return $global_message_template_group; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Returns an array of event ids for all the events within the current data handler. |
|
| 541 | + * |
|
| 542 | + * @return array |
|
| 543 | + */ |
|
| 544 | + protected function _get_event_ids_from_current_data_handler() |
|
| 545 | + { |
|
| 546 | + $event_ids = array(); |
|
| 547 | + foreach ($this->_current_data_handler->events as $event) { |
|
| 548 | + $event_ids[$event['ID']] = $event['ID']; |
|
| 549 | + } |
|
| 550 | + return $event_ids; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Retrieves formatted array of template information for each context specific to the given |
|
| 556 | + * EE_Message_Template_Group |
|
| 557 | + * |
|
| 558 | + * @param EE_Message_Template_Group $message_template_group |
|
| 559 | + * @return array The returned array is in this structure: |
|
| 560 | + * array( |
|
| 561 | + * 'field_name' => array( |
|
| 562 | + * 'context' => 'content' |
|
| 563 | + * ) |
|
| 564 | + * ) |
|
| 565 | + * @throws EE_Error |
|
| 566 | + */ |
|
| 567 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
| 568 | + { |
|
| 569 | + $templates = array(); |
|
| 570 | + $context_templates = $message_template_group->context_templates(); |
|
| 571 | + foreach ($context_templates as $context => $template_fields) { |
|
| 572 | + foreach ($template_fields as $template_field => $template_obj) { |
|
| 573 | + if (! $template_obj instanceof EE_Message_Template) { |
|
| 574 | + continue; |
|
| 575 | + } |
|
| 576 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + return $templates; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
| 585 | + * |
|
| 586 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
| 587 | + * context. |
|
| 588 | + * @param array $templates formatted array of templates used for parsing data. |
|
| 589 | + * @param EE_Message_Template_Group $message_template_group |
|
| 590 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
| 591 | + * method will attempt to generate ALL EE_Message objects and add to |
|
| 592 | + * the _ready_queue. Successfully generated messages get added to the |
|
| 593 | + * queue with EEM_Message::status_idle, unsuccessfully generated |
|
| 594 | + * messages will get added to the queue as EEM_Message::status_failed. |
|
| 595 | + * Very rarely should "false" be returned from this method. |
|
| 596 | + * @throws EE_Error |
|
| 597 | + */ |
|
| 598 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
| 599 | + { |
|
| 600 | + |
|
| 601 | + //if templates are empty then get out because we can't generate anything. |
|
| 602 | + if (! $templates) { |
|
| 603 | + $this->_error_msg[] = esc_html__( |
|
| 604 | + 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
| 605 | + 'event_espresso' |
|
| 606 | + ); |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
| 611 | + //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
| 612 | + $generated_count = 0; |
|
| 613 | + foreach ($addressees as $context => $recipients) { |
|
| 614 | + foreach ($recipients as $recipient) { |
|
| 615 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
| 616 | + if ($message instanceof EE_Message) { |
|
| 617 | + $this->_ready_queue->add( |
|
| 618 | + $message, |
|
| 619 | + array(), |
|
| 620 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
| 621 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
| 622 | + ); |
|
| 623 | + $generated_count++; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + //if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
| 627 | + // generation. |
|
| 628 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
| 629 | + break 2; |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + //if there are no generated messages then something else fatal went wrong. |
|
| 635 | + return $generated_count > 0; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * @param string $context The context for the generated message. |
|
| 641 | + * @param EE_Messages_Addressee $recipient |
|
| 642 | + * @param array $templates formatted array of templates used for parsing data. |
|
| 643 | + * @param EE_Message_Template_Group $message_template_group |
|
| 644 | + * @return bool|EE_Message |
|
| 645 | + * @throws EE_Error |
|
| 646 | + */ |
|
| 647 | + protected function _setup_message_object( |
|
| 648 | + $context, |
|
| 649 | + EE_Messages_Addressee $recipient, |
|
| 650 | + $templates, |
|
| 651 | + EE_Message_Template_Group $message_template_group |
|
| 652 | + ) { |
|
| 653 | + //stuff we already know |
|
| 654 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
| 655 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
| 656 | + ? $this->_current_data_handler->txn->ID() |
|
| 657 | + : $transaction_id; |
|
| 658 | + $message_fields = array( |
|
| 659 | + 'GRP_ID' => $message_template_group->ID(), |
|
| 660 | + 'TXN_ID' => $transaction_id, |
|
| 661 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
| 662 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
| 663 | + 'MSG_context' => $context, |
|
| 664 | + ); |
|
| 665 | + |
|
| 666 | + //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
| 667 | + // the info from the att_obj found in the EE_Messages_Addressee object. |
|
| 668 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
| 669 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
| 670 | + ? $recipient->att_obj->ID() |
|
| 671 | + : 0; |
|
| 672 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
| 673 | + } else { |
|
| 674 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
| 675 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
| 676 | + } |
|
| 677 | + $message = EE_Message_Factory::create($message_fields); |
|
| 678 | + |
|
| 679 | + //grab valid shortcodes for shortcode parser |
|
| 680 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
| 681 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
| 682 | + |
|
| 683 | + //if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
| 684 | + if (( |
|
| 685 | + ( |
|
| 686 | + empty($templates['to'][$context]) |
|
| 687 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
| 688 | + ) |
|
| 689 | + || ! $message_template_group->is_context_active($context) |
|
| 690 | + ) |
|
| 691 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
| 692 | + ) { |
|
| 693 | + //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
| 694 | + //field. |
|
| 695 | + return false; |
|
| 696 | + } |
|
| 697 | + $error_msg = array(); |
|
| 698 | + foreach ($templates as $field => $field_context) { |
|
| 699 | + $error_msg = array(); |
|
| 700 | + //let's setup the valid shortcodes for the incoming context. |
|
| 701 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
| 702 | + //merge in valid shortcodes for the field. |
|
| 703 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
| 704 | + if (isset($templates[$field][$context])) { |
|
| 705 | + //prefix field. |
|
| 706 | + $column_name = 'MSG_' . $field; |
|
| 707 | + try { |
|
| 708 | + $content = $this->_shortcode_parser->parse_message_template( |
|
| 709 | + $templates[$field][$context], |
|
| 710 | + $recipient, |
|
| 711 | + $shortcodes, |
|
| 712 | + $this->_current_message_type, |
|
| 713 | + $this->_current_messenger, |
|
| 714 | + $message |
|
| 715 | + ); |
|
| 716 | + $message->set_field_or_extra_meta($column_name, $content); |
|
| 717 | + } catch (EE_Error $e) { |
|
| 718 | + $error_msg[] = sprintf( |
|
| 719 | + esc_html__( |
|
| 720 | + 'There was a problem generating the content for the field %s: %s', |
|
| 721 | + 'event_espresso' |
|
| 722 | + ), |
|
| 723 | + $field, |
|
| 724 | + $e->getMessage() |
|
| 725 | + ); |
|
| 726 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
| 732 | + $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
| 733 | + . "\n" |
|
| 734 | + . implode("\n", $error_msg); |
|
| 735 | + $message->set_error_message($error_msg); |
|
| 736 | + } else { |
|
| 737 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
| 738 | + } |
|
| 739 | + return $message; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
| 745 | + * error message if either is missing. |
|
| 746 | + * |
|
| 747 | + * @return bool true means there were no errors, false means there were errors. |
|
| 748 | + * @throws EE_Error |
|
| 749 | + * @throws ReflectionException |
|
| 750 | + */ |
|
| 751 | + protected function _verify() |
|
| 752 | + { |
|
| 753 | + //reset error message to an empty array. |
|
| 754 | + $this->_error_msg = array(); |
|
| 755 | + $valid = true; |
|
| 756 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
| 757 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
| 758 | + |
|
| 759 | + //set the verified flag so we know everything has been validated. |
|
| 760 | + $this->_verified = $valid; |
|
| 761 | + |
|
| 762 | + return $valid; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
| 768 | + * EE_Messages_Addressee objects. |
|
| 769 | + * |
|
| 770 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
| 771 | + * @return bool |
|
| 772 | + */ |
|
| 773 | + protected function _valid_addressees($addressees) |
|
| 774 | + { |
|
| 775 | + if (! $addressees || ! is_array($addressees)) { |
|
| 776 | + return false; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + foreach ($addressees as $addressee_array) { |
|
| 780 | + foreach ($addressee_array as $addressee) { |
|
| 781 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
| 782 | + return false; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + return true; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
| 792 | + * queue. This process sets error messages if something is wrong. |
|
| 793 | + * |
|
| 794 | + * @return bool true is if there are no errors. false is if there is. |
|
| 795 | + */ |
|
| 796 | + protected function _validate_messenger_and_message_type() |
|
| 797 | + { |
|
| 798 | + |
|
| 799 | + //first are there any existing error messages? If so then return. |
|
| 800 | + if ($this->_error_msg) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + /** @type EE_Message $message */ |
|
| 804 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
| 805 | + try { |
|
| 806 | + $this->_current_messenger = $message->valid_messenger(true) |
|
| 807 | + ? $message->messenger_object() |
|
| 808 | + : null; |
|
| 809 | + } catch (Exception $e) { |
|
| 810 | + $this->_error_msg[] = $e->getMessage(); |
|
| 811 | + } |
|
| 812 | + try { |
|
| 813 | + $this->_current_message_type = $message->valid_message_type(true) |
|
| 814 | + ? $message->message_type_object() |
|
| 815 | + : null; |
|
| 816 | + } catch (Exception $e) { |
|
| 817 | + $this->_error_msg[] = $e->getMessage(); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Check if there is any generation data, but only if this is not for a preview. |
|
| 822 | + */ |
|
| 823 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
| 824 | + && ( |
|
| 825 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
| 826 | + && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
| 827 | + !== 'EE_Messages_Preview_incoming_data' |
|
| 828 | + ) |
|
| 829 | + ) { |
|
| 830 | + $this->_error_msg[] = esc_html__( |
|
| 831 | + 'There is no generation data for this message. Unable to generate.', |
|
| 832 | + 'event_espresso' |
|
| 833 | + ); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + return empty($this->_error_msg); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
| 842 | + * data handler. |
|
| 843 | + * |
|
| 844 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
| 845 | + * @throws EE_Error |
|
| 846 | + * @throws ReflectionException |
|
| 847 | + */ |
|
| 848 | + protected function _validate_and_setup_data() |
|
| 849 | + { |
|
| 850 | + |
|
| 851 | + //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
| 852 | + //be used anyways. |
|
| 853 | + if ($this->_error_msg) { |
|
| 854 | + return false; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
| 858 | + |
|
| 859 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
| 860 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
| 861 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
| 862 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
| 863 | + |
|
| 864 | + //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
| 865 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
| 866 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + //First get the class name for the data handler (and also verifies it exists. |
|
| 870 | + if (! class_exists($data_handler_class_name)) { |
|
| 871 | + $this->_error_msg[] = sprintf( |
|
| 872 | + esc_html__( |
|
| 873 | + 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
| 874 | + 'event_espresso' |
|
| 875 | + ), |
|
| 876 | + 'EE_Messages_incoming_data', |
|
| 877 | + $data_handler_class_name |
|
| 878 | + ); |
|
| 879 | + return false; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + //convert generation_data for data_handler_instantiation. |
|
| 883 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
| 884 | + |
|
| 885 | + //note, this may set error messages as well. |
|
| 886 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
| 887 | + |
|
| 888 | + return empty($this->_error_msg); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
| 894 | + * adds it to the _data repository. |
|
| 895 | + * |
|
| 896 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
| 897 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
| 898 | + * instantiated. |
|
| 899 | + * @return void . |
|
| 900 | + * @throws EE_Error |
|
| 901 | + * @throws ReflectionException |
|
| 902 | + */ |
|
| 903 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
| 904 | + { |
|
| 905 | + //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
| 906 | + //is already a ready data handler in the repository. |
|
| 907 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
| 908 | + $this->_data_handler_collection->get_key( |
|
| 909 | + $data_handler_class_name, |
|
| 910 | + $generating_data |
|
| 911 | + ) |
|
| 912 | + ); |
|
| 913 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
| 914 | + //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
| 915 | + try { |
|
| 916 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
| 917 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
| 918 | + } catch (EE_Error $e) { |
|
| 919 | + $this->_error_msg[] = $e->get_error(); |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
| 927 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
| 928 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
| 929 | + * and that preps the data for later instantiation when generating. |
|
| 930 | + * |
|
| 931 | + * @param EE_Message_To_Generate $message_to_generate |
|
| 932 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
| 933 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
| 934 | + */ |
|
| 935 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
| 936 | + { |
|
| 937 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
| 938 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
| 939 | + if (! $message_to_generate->valid()) { |
|
| 940 | + return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
| 941 | + } |
|
| 942 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
| 948 | + * |
|
| 949 | + * @param EE_Message_To_Generate $message_to_generate |
|
| 950 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
| 951 | + * @throws InvalidArgumentException |
|
| 952 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 953 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 954 | + */ |
|
| 955 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
| 956 | + { |
|
| 957 | + //prep data |
|
| 958 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
| 959 | + |
|
| 960 | + $message = $message_to_generate->get_EE_Message(); |
|
| 961 | + |
|
| 962 | + //is there a GRP_ID in the request? |
|
| 963 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
| 964 | + $message->set_GRP_ID($GRP_ID); |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + if ($data === false) { |
|
| 968 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
| 969 | + $message->set_error_message( |
|
| 970 | + esc_html__( |
|
| 971 | + 'Unable to prepare data for persistence to the database.', |
|
| 972 | + 'event_espresso' |
|
| 973 | + ) |
|
| 974 | + ); |
|
| 975 | + } else { |
|
| 976 | + //make sure that the data handler is cached on the message as well |
|
| 977 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
| 981 | + } |
|
| 982 | 982 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | { |
| 260 | 260 | //double check verification has run and that everything is ready to work with (saves us having to validate |
| 261 | 261 | // everything again). |
| 262 | - if (! $this->_verified) { |
|
| 262 | + if ( ! $this->_verified) { |
|
| 263 | 263 | return false; //get out because we don't have a valid setup to work with. |
| 264 | 264 | } |
| 265 | 265 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | |
| 278 | 278 | //if no addressees then get out because there is nothing to generation (possible bad data). |
| 279 | - if (! $this->_valid_addressees($addressees)) { |
|
| 279 | + if ( ! $this->_valid_addressees($addressees)) { |
|
| 280 | 280 | do_action( |
| 281 | 281 | 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
| 282 | 282 | $this->_generation_queue->get_message_repository()->current(), |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $message_template_group = $this->_get_message_template_group(); |
| 299 | 299 | |
| 300 | 300 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
| 301 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 301 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 302 | 302 | $this->_error_msg[] = esc_html__( |
| 303 | 303 | 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
| 304 | 304 | 'event_espresso' |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | //attempt to retrieve from repo first |
| 409 | 409 | $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
| 410 | 410 | if ($message_template_group instanceof EE_Message_Template_Group) { |
| 411 | - return $message_template_group; //got it! |
|
| 411 | + return $message_template_group; //got it! |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | 515 | //if we don't have a group lets hit the db. |
| 516 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 516 | + if ( ! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
| 517 | 517 | $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
| 518 | 518 | array( |
| 519 | 519 | array( |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | $context_templates = $message_template_group->context_templates(); |
| 571 | 571 | foreach ($context_templates as $context => $template_fields) { |
| 572 | 572 | foreach ($template_fields as $template_field => $template_obj) { |
| 573 | - if (! $template_obj instanceof EE_Message_Template) { |
|
| 573 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
| 574 | 574 | continue; |
| 575 | 575 | } |
| 576 | 576 | $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | { |
| 600 | 600 | |
| 601 | 601 | //if templates are empty then get out because we can't generate anything. |
| 602 | - if (! $templates) { |
|
| 602 | + if ( ! $templates) { |
|
| 603 | 603 | $this->_error_msg[] = esc_html__( |
| 604 | 604 | 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
| 605 | 605 | 'event_espresso' |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
| 704 | 704 | if (isset($templates[$field][$context])) { |
| 705 | 705 | //prefix field. |
| 706 | - $column_name = 'MSG_' . $field; |
|
| 706 | + $column_name = 'MSG_'.$field; |
|
| 707 | 707 | try { |
| 708 | 708 | $content = $this->_shortcode_parser->parse_message_template( |
| 709 | 709 | $templates[$field][$context], |
@@ -772,13 +772,13 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | protected function _valid_addressees($addressees) |
| 774 | 774 | { |
| 775 | - if (! $addressees || ! is_array($addressees)) { |
|
| 775 | + if ( ! $addressees || ! is_array($addressees)) { |
|
| 776 | 776 | return false; |
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | foreach ($addressees as $addressee_array) { |
| 780 | 780 | foreach ($addressee_array as $addressee) { |
| 781 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
| 781 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
| 782 | 782 | return false; |
| 783 | 783 | } |
| 784 | 784 | } |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | /** |
| 821 | 821 | * Check if there is any generation data, but only if this is not for a preview. |
| 822 | 822 | */ |
| 823 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
| 823 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
| 824 | 824 | && ( |
| 825 | 825 | ! $this->_generation_queue->get_message_repository()->is_preview() |
| 826 | 826 | && $this->_generation_queue->get_message_repository()->get_data_handler() |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
| 860 | 860 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
| 861 | 861 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
| 862 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
| 862 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
| 863 | 863 | |
| 864 | 864 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
| 865 | 865 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | //First get the class name for the data handler (and also verifies it exists. |
| 870 | - if (! class_exists($data_handler_class_name)) { |
|
| 870 | + if ( ! class_exists($data_handler_class_name)) { |
|
| 871 | 871 | $this->_error_msg[] = sprintf( |
| 872 | 872 | esc_html__( |
| 873 | 873 | 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | $generating_data |
| 911 | 911 | ) |
| 912 | 912 | ); |
| 913 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
| 913 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
| 914 | 914 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
| 915 | 915 | try { |
| 916 | 916 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | { |
| 937 | 937 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
| 938 | 938 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
| 939 | - if (! $message_to_generate->valid()) { |
|
| 939 | + if ( ! $message_to_generate->valid()) { |
|
| 940 | 940 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
| 941 | 941 | } |
| 942 | 942 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -10,22 +10,22 @@ discard block |
||
| 10 | 10 | * @var int $message_template_group_id The ID for the message template group this context belongs to. |
| 11 | 11 | */ |
| 12 | 12 | $active_message = sprintf( |
| 13 | - esc_html__( |
|
| 14 | - 'The template for %1$s is currently %2$sactive%3$s.', |
|
| 15 | - 'event_espresso' |
|
| 16 | - ), |
|
| 17 | - $context_label, |
|
| 18 | - '<strong>', |
|
| 19 | - '</strong>' |
|
| 13 | + esc_html__( |
|
| 14 | + 'The template for %1$s is currently %2$sactive%3$s.', |
|
| 15 | + 'event_espresso' |
|
| 16 | + ), |
|
| 17 | + $context_label, |
|
| 18 | + '<strong>', |
|
| 19 | + '</strong>' |
|
| 20 | 20 | ); |
| 21 | 21 | $inactive_message = sprintf( |
| 22 | - esc_html__( |
|
| 23 | - 'The template for %1$s is currently %2$sinactive%3$s.', |
|
| 24 | - 'event_espresso' |
|
| 25 | - ), |
|
| 26 | - $context_label, |
|
| 27 | - '<strong>', |
|
| 28 | - '</strong>' |
|
| 22 | + esc_html__( |
|
| 23 | + 'The template for %1$s is currently %2$sinactive%3$s.', |
|
| 24 | + 'event_espresso' |
|
| 25 | + ), |
|
| 26 | + $context_label, |
|
| 27 | + '<strong>', |
|
| 28 | + '</strong>' |
|
| 29 | 29 | ); |
| 30 | 30 | ?> |
| 31 | 31 | <div class="context-active-control-container"> |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span> |
| 35 | 35 | <span class="ee-on-off-toggle-label"> |
| 36 | 36 | <?php |
| 37 | - echo $is_active ? $active_message : $inactive_message; |
|
| 38 | - ?> |
|
| 37 | + echo $is_active ? $active_message : $inactive_message; |
|
| 38 | + ?> |
|
| 39 | 39 | </span> |
| 40 | 40 | <div class="hidden js-data"> |
| 41 | 41 | <span class="ee-active-message"><?php echo $active_message; ?></span> |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | </div> |
| 44 | 44 | <div class="switch"> |
| 45 | 45 | <?php |
| 46 | - $checked = $is_active ? ' checked="checked"' : ''; |
|
| 47 | - ?> |
|
| 46 | + $checked = $is_active ? ' checked="checked"' : ''; |
|
| 47 | + ?> |
|
| 48 | 48 | <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>"> |
| 49 | 49 | <label for="ee-on-off-toggle-<?php echo $context; ?>"></label> |
| 50 | 50 | </div> |
@@ -13,373 +13,373 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @return Messages_Admin_Page |
|
| 18 | - */ |
|
| 19 | - public function get_admin_page() |
|
| 20 | - { |
|
| 21 | - return $this->_admin_page; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Setup data object |
|
| 27 | - */ |
|
| 28 | - protected function _setup_data() |
|
| 29 | - { |
|
| 30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | - $this->_per_page, |
|
| 32 | - $this->_view, |
|
| 33 | - false |
|
| 34 | - ); |
|
| 35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 36 | - $this->_per_page, |
|
| 37 | - $this->_view, |
|
| 38 | - true, |
|
| 39 | - true |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Set internal properties |
|
| 46 | - */ |
|
| 47 | - protected function _set_properties() |
|
| 48 | - { |
|
| 49 | - $this->_wp_list_args = array( |
|
| 50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 52 | - 'ajax' => true, //for now, |
|
| 53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 54 | - ); |
|
| 55 | - $this->_columns = array( |
|
| 56 | - //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
| 60 | - ); |
|
| 61 | - |
|
| 62 | - $this->_sortable_columns = array( |
|
| 63 | - 'messenger' => array('MTP_messenger' => true), |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - $this->_hidden_columns = array(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 72 | - * message_type or messenger object before generating the row. |
|
| 73 | - * |
|
| 74 | - * @param EE_Message_Template_Group $item |
|
| 75 | - * @return string |
|
| 76 | - * @throws EE_Error |
|
| 77 | - */ |
|
| 78 | - public function single_row($item) |
|
| 79 | - { |
|
| 80 | - $message_type = $item->message_type_obj(); |
|
| 81 | - $messenger = $item->messenger_obj(); |
|
| 82 | - |
|
| 83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | - echo ''; |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - parent::single_row($item); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return array |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - protected function _get_table_filters() |
|
| 97 | - { |
|
| 98 | - $filters = array(); |
|
| 99 | - |
|
| 100 | - //get select inputs |
|
| 101 | - $select_inputs = array( |
|
| 102 | - $this->_get_messengers_dropdown_filter(), |
|
| 103 | - $this->_get_message_types_dropdown_filter(), |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - //set filters to select inputs if they aren't empty |
|
| 107 | - foreach ($select_inputs as $select_input) { |
|
| 108 | - if ($select_input) { |
|
| 109 | - $filters[] = $select_input; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return $filters; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * We're just removing the search box for message templates, not needed. |
|
| 117 | - * |
|
| 118 | - * @param string $text |
|
| 119 | - * @param string $input_id |
|
| 120 | - * @return string ; |
|
| 121 | - */ |
|
| 122 | - public function search_box($text, $input_id) |
|
| 123 | - { |
|
| 124 | - return ''; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Add counts to the _views property |
|
| 130 | - */ |
|
| 131 | - protected function _add_view_counts() |
|
| 132 | - { |
|
| 133 | - foreach ($this->_views as $view => $args) { |
|
| 134 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | - $this->_per_page, |
|
| 136 | - $view, |
|
| 137 | - true, |
|
| 138 | - true |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param EE_Message_Template_Group $item |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - public function column_cb($item) |
|
| 149 | - { |
|
| 150 | - return ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param EE_Message_Template_Group $item |
|
| 156 | - * @return string |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - public function column_description($item) |
|
| 160 | - { |
|
| 161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param EE_Message_Template_Group $item |
|
| 167 | - * @return string |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function column_messenger($item) |
|
| 171 | - { |
|
| 172 | - //Return the name contents |
|
| 173 | - return sprintf( |
|
| 174 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
| 175 | - /* $1%s */ |
|
| 176 | - $this->_get_name_link_for_messenger($item), |
|
| 177 | - /* $2%s */ |
|
| 178 | - $item->GRP_ID(), |
|
| 179 | - /* %4$s */ |
|
| 180 | - $this->_get_context_links($item), |
|
| 181 | - /* $3%s */ |
|
| 182 | - $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * column_message_type |
|
| 188 | - * |
|
| 189 | - * @param EE_Message_Template_Group $item message info for the row |
|
| 190 | - * @return string message_type name |
|
| 191 | - * @throws EE_Error |
|
| 192 | - */ |
|
| 193 | - public function column_message_type($item) |
|
| 194 | - { |
|
| 195 | - return ucwords($item->message_type_obj()->label['singular']); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Generate dropdown filter select input for messengers |
|
| 201 | - * |
|
| 202 | - * @param bool $global |
|
| 203 | - * @return string |
|
| 204 | - * @throws EE_Error |
|
| 205 | - */ |
|
| 206 | - protected function _get_messengers_dropdown_filter($global = true) |
|
| 207 | - { |
|
| 208 | - $messenger_options = array(); |
|
| 209 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 210 | - array( |
|
| 211 | - array( |
|
| 212 | - 'MTP_is_active' => true, |
|
| 213 | - 'MTP_is_global' => $global, |
|
| 214 | - ), |
|
| 215 | - 'group_by' => 'MTP_messenger', |
|
| 216 | - ) |
|
| 217 | - ); |
|
| 218 | - |
|
| 219 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 220 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 221 | - $messenger = $active_message_template_group->messenger_obj(); |
|
| 222 | - $messenger_label = $messenger instanceof EE_messenger |
|
| 223 | - ? $messenger->label['singular'] |
|
| 224 | - : $active_message_template_group->messenger(); |
|
| 225 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Generate dropdown filter select input for message types |
|
| 234 | - * |
|
| 235 | - * @param bool $global |
|
| 236 | - * @return string |
|
| 237 | - * @throws EE_Error |
|
| 238 | - */ |
|
| 239 | - protected function _get_message_types_dropdown_filter($global = true) |
|
| 240 | - { |
|
| 241 | - $message_type_options = array(); |
|
| 242 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 243 | - array( |
|
| 244 | - array( |
|
| 245 | - 'MTP_is_active' => true, |
|
| 246 | - 'MTP_is_global' => true, |
|
| 247 | - ), |
|
| 248 | - 'group_by' => 'MTP_message_type', |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - |
|
| 252 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 253 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 254 | - $message_type = $active_message_template_group->message_type_obj(); |
|
| 255 | - $message_type_label = $message_type instanceof EE_message_type |
|
| 256 | - ? $message_type->label['singular'] |
|
| 257 | - : $active_message_template_group->message_type(); |
|
| 258 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Return the edit url for the message template group. |
|
| 267 | - * @param EE_Message_Template_Group $item |
|
| 268 | - * @return string |
|
| 269 | - * @throws EE_Error |
|
| 270 | - */ |
|
| 271 | - protected function _get_edit_url(EE_Message_Template_Group $item) |
|
| 272 | - { |
|
| 273 | - $edit_url = ''; |
|
| 274 | - // edit link but only if item isn't trashed. |
|
| 275 | - if (! $item->get('MTP_deleted') |
|
| 276 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 277 | - 'ee_edit_message', |
|
| 278 | - 'espresso_messages_edit_message_template', |
|
| 279 | - $item->ID() |
|
| 280 | - )) { |
|
| 281 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 282 | - array( |
|
| 283 | - 'action' => 'edit_message_template', |
|
| 284 | - 'id' => $item->GRP_ID(), |
|
| 285 | - ), |
|
| 286 | - EE_MSG_ADMIN_URL |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - return $edit_url; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the context link string for the messenger column. |
|
| 295 | - * @param EE_Message_Template_Group $item |
|
| 296 | - * @return string |
|
| 297 | - * @throws EE_Error |
|
| 298 | - */ |
|
| 299 | - protected function _get_context_links(EE_Message_Template_Group $item) |
|
| 300 | - { |
|
| 301 | - //first check if we even show the context links or not. |
|
| 302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 303 | - 'ee_edit_message', |
|
| 304 | - 'espresso_messages_edit_message_template', |
|
| 305 | - $item->ID() |
|
| 306 | - ) |
|
| 307 | - || $item->get('MTP_deleted') |
|
| 308 | - ) { |
|
| 309 | - return ''; |
|
| 310 | - } |
|
| 311 | - //we want to display the contexts in here so we need to set them up |
|
| 312 | - $c_label = $item->context_label(); |
|
| 313 | - $c_configs = $item->contexts_config(); |
|
| 314 | - $ctxt = array(); |
|
| 315 | - $context_templates = $item->context_templates(); |
|
| 316 | - foreach ($context_templates as $context => $template_fields) { |
|
| 317 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
| 318 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
| 319 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
| 320 | - : null; |
|
| 321 | - $inactive_class = ( |
|
| 322 | - empty($mtp_to) |
|
| 323 | - && ! empty($context_templates[$context]['to']) |
|
| 324 | - ) |
|
| 325 | - || ! $item->is_context_active($context) |
|
| 326 | - ? ' mtp-inactive' |
|
| 327 | - : ''; |
|
| 328 | - $context_title = ucwords($c_configs[$context]['label']); |
|
| 329 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 330 | - 'action' => 'edit_message_template', |
|
| 331 | - 'id' => $item->GRP_ID(), |
|
| 332 | - 'context' => $context, |
|
| 333 | - ), EE_MSG_ADMIN_URL); |
|
| 334 | - $ctxt[] = '<a' |
|
| 335 | - . ' href="' . $edit_link . '"' |
|
| 336 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"' |
|
| 337 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 338 | - . $context_title |
|
| 339 | - . '</a>'; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Get the Name string from the messenger column (linked to edit if the context allows for that). |
|
| 348 | - * @param EE_Message_Template_Group $item |
|
| 349 | - * @return string |
|
| 350 | - * @throws EE_Error |
|
| 351 | - */ |
|
| 352 | - protected function _get_name_link_for_messenger(EE_Message_Template_Group $item) |
|
| 353 | - { |
|
| 354 | - $edit_url = $this->_get_edit_url($item); |
|
| 355 | - return $edit_url |
|
| 356 | - ? '<a href="' . $edit_url . '"' |
|
| 357 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
| 358 | - . ucwords($item->messenger_obj()->label['singular']) |
|
| 359 | - . '</a>' |
|
| 360 | - : ucwords($item->messenger_obj()->label['singular']); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Return the actions array for the messenger column. |
|
| 366 | - * @param EE_Message_Template_Group $item |
|
| 367 | - * @return array |
|
| 368 | - * @throws EE_Error |
|
| 369 | - */ |
|
| 370 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
| 371 | - { |
|
| 372 | - $actions = array(); |
|
| 373 | - if ($edit_url = $this->_get_edit_url($item)) { |
|
| 374 | - $actions = array( |
|
| 375 | - 'edit' => '<a href="' . $edit_url . '"' |
|
| 376 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
| 377 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
| 378 | - . esc_html__('Edit', 'event_espresso') |
|
| 379 | - . '</a>' |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - return $actions; |
|
| 383 | - } |
|
| 16 | + /** |
|
| 17 | + * @return Messages_Admin_Page |
|
| 18 | + */ |
|
| 19 | + public function get_admin_page() |
|
| 20 | + { |
|
| 21 | + return $this->_admin_page; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Setup data object |
|
| 27 | + */ |
|
| 28 | + protected function _setup_data() |
|
| 29 | + { |
|
| 30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | + $this->_per_page, |
|
| 32 | + $this->_view, |
|
| 33 | + false |
|
| 34 | + ); |
|
| 35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 36 | + $this->_per_page, |
|
| 37 | + $this->_view, |
|
| 38 | + true, |
|
| 39 | + true |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Set internal properties |
|
| 46 | + */ |
|
| 47 | + protected function _set_properties() |
|
| 48 | + { |
|
| 49 | + $this->_wp_list_args = array( |
|
| 50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 52 | + 'ajax' => true, //for now, |
|
| 53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 54 | + ); |
|
| 55 | + $this->_columns = array( |
|
| 56 | + //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
| 60 | + ); |
|
| 61 | + |
|
| 62 | + $this->_sortable_columns = array( |
|
| 63 | + 'messenger' => array('MTP_messenger' => true), |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + $this->_hidden_columns = array(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 72 | + * message_type or messenger object before generating the row. |
|
| 73 | + * |
|
| 74 | + * @param EE_Message_Template_Group $item |
|
| 75 | + * @return string |
|
| 76 | + * @throws EE_Error |
|
| 77 | + */ |
|
| 78 | + public function single_row($item) |
|
| 79 | + { |
|
| 80 | + $message_type = $item->message_type_obj(); |
|
| 81 | + $messenger = $item->messenger_obj(); |
|
| 82 | + |
|
| 83 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | + echo ''; |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + parent::single_row($item); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return array |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + protected function _get_table_filters() |
|
| 97 | + { |
|
| 98 | + $filters = array(); |
|
| 99 | + |
|
| 100 | + //get select inputs |
|
| 101 | + $select_inputs = array( |
|
| 102 | + $this->_get_messengers_dropdown_filter(), |
|
| 103 | + $this->_get_message_types_dropdown_filter(), |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + //set filters to select inputs if they aren't empty |
|
| 107 | + foreach ($select_inputs as $select_input) { |
|
| 108 | + if ($select_input) { |
|
| 109 | + $filters[] = $select_input; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return $filters; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * We're just removing the search box for message templates, not needed. |
|
| 117 | + * |
|
| 118 | + * @param string $text |
|
| 119 | + * @param string $input_id |
|
| 120 | + * @return string ; |
|
| 121 | + */ |
|
| 122 | + public function search_box($text, $input_id) |
|
| 123 | + { |
|
| 124 | + return ''; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Add counts to the _views property |
|
| 130 | + */ |
|
| 131 | + protected function _add_view_counts() |
|
| 132 | + { |
|
| 133 | + foreach ($this->_views as $view => $args) { |
|
| 134 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | + $this->_per_page, |
|
| 136 | + $view, |
|
| 137 | + true, |
|
| 138 | + true |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param EE_Message_Template_Group $item |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + public function column_cb($item) |
|
| 149 | + { |
|
| 150 | + return ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param EE_Message_Template_Group $item |
|
| 156 | + * @return string |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + public function column_description($item) |
|
| 160 | + { |
|
| 161 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param EE_Message_Template_Group $item |
|
| 167 | + * @return string |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function column_messenger($item) |
|
| 171 | + { |
|
| 172 | + //Return the name contents |
|
| 173 | + return sprintf( |
|
| 174 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
| 175 | + /* $1%s */ |
|
| 176 | + $this->_get_name_link_for_messenger($item), |
|
| 177 | + /* $2%s */ |
|
| 178 | + $item->GRP_ID(), |
|
| 179 | + /* %4$s */ |
|
| 180 | + $this->_get_context_links($item), |
|
| 181 | + /* $3%s */ |
|
| 182 | + $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * column_message_type |
|
| 188 | + * |
|
| 189 | + * @param EE_Message_Template_Group $item message info for the row |
|
| 190 | + * @return string message_type name |
|
| 191 | + * @throws EE_Error |
|
| 192 | + */ |
|
| 193 | + public function column_message_type($item) |
|
| 194 | + { |
|
| 195 | + return ucwords($item->message_type_obj()->label['singular']); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Generate dropdown filter select input for messengers |
|
| 201 | + * |
|
| 202 | + * @param bool $global |
|
| 203 | + * @return string |
|
| 204 | + * @throws EE_Error |
|
| 205 | + */ |
|
| 206 | + protected function _get_messengers_dropdown_filter($global = true) |
|
| 207 | + { |
|
| 208 | + $messenger_options = array(); |
|
| 209 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 210 | + array( |
|
| 211 | + array( |
|
| 212 | + 'MTP_is_active' => true, |
|
| 213 | + 'MTP_is_global' => $global, |
|
| 214 | + ), |
|
| 215 | + 'group_by' => 'MTP_messenger', |
|
| 216 | + ) |
|
| 217 | + ); |
|
| 218 | + |
|
| 219 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 220 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 221 | + $messenger = $active_message_template_group->messenger_obj(); |
|
| 222 | + $messenger_label = $messenger instanceof EE_messenger |
|
| 223 | + ? $messenger->label['singular'] |
|
| 224 | + : $active_message_template_group->messenger(); |
|
| 225 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Generate dropdown filter select input for message types |
|
| 234 | + * |
|
| 235 | + * @param bool $global |
|
| 236 | + * @return string |
|
| 237 | + * @throws EE_Error |
|
| 238 | + */ |
|
| 239 | + protected function _get_message_types_dropdown_filter($global = true) |
|
| 240 | + { |
|
| 241 | + $message_type_options = array(); |
|
| 242 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 243 | + array( |
|
| 244 | + array( |
|
| 245 | + 'MTP_is_active' => true, |
|
| 246 | + 'MTP_is_global' => true, |
|
| 247 | + ), |
|
| 248 | + 'group_by' => 'MTP_message_type', |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + |
|
| 252 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 253 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 254 | + $message_type = $active_message_template_group->message_type_obj(); |
|
| 255 | + $message_type_label = $message_type instanceof EE_message_type |
|
| 256 | + ? $message_type->label['singular'] |
|
| 257 | + : $active_message_template_group->message_type(); |
|
| 258 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Return the edit url for the message template group. |
|
| 267 | + * @param EE_Message_Template_Group $item |
|
| 268 | + * @return string |
|
| 269 | + * @throws EE_Error |
|
| 270 | + */ |
|
| 271 | + protected function _get_edit_url(EE_Message_Template_Group $item) |
|
| 272 | + { |
|
| 273 | + $edit_url = ''; |
|
| 274 | + // edit link but only if item isn't trashed. |
|
| 275 | + if (! $item->get('MTP_deleted') |
|
| 276 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 277 | + 'ee_edit_message', |
|
| 278 | + 'espresso_messages_edit_message_template', |
|
| 279 | + $item->ID() |
|
| 280 | + )) { |
|
| 281 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 282 | + array( |
|
| 283 | + 'action' => 'edit_message_template', |
|
| 284 | + 'id' => $item->GRP_ID(), |
|
| 285 | + ), |
|
| 286 | + EE_MSG_ADMIN_URL |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + return $edit_url; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the context link string for the messenger column. |
|
| 295 | + * @param EE_Message_Template_Group $item |
|
| 296 | + * @return string |
|
| 297 | + * @throws EE_Error |
|
| 298 | + */ |
|
| 299 | + protected function _get_context_links(EE_Message_Template_Group $item) |
|
| 300 | + { |
|
| 301 | + //first check if we even show the context links or not. |
|
| 302 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 303 | + 'ee_edit_message', |
|
| 304 | + 'espresso_messages_edit_message_template', |
|
| 305 | + $item->ID() |
|
| 306 | + ) |
|
| 307 | + || $item->get('MTP_deleted') |
|
| 308 | + ) { |
|
| 309 | + return ''; |
|
| 310 | + } |
|
| 311 | + //we want to display the contexts in here so we need to set them up |
|
| 312 | + $c_label = $item->context_label(); |
|
| 313 | + $c_configs = $item->contexts_config(); |
|
| 314 | + $ctxt = array(); |
|
| 315 | + $context_templates = $item->context_templates(); |
|
| 316 | + foreach ($context_templates as $context => $template_fields) { |
|
| 317 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
| 318 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
| 319 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
| 320 | + : null; |
|
| 321 | + $inactive_class = ( |
|
| 322 | + empty($mtp_to) |
|
| 323 | + && ! empty($context_templates[$context]['to']) |
|
| 324 | + ) |
|
| 325 | + || ! $item->is_context_active($context) |
|
| 326 | + ? ' mtp-inactive' |
|
| 327 | + : ''; |
|
| 328 | + $context_title = ucwords($c_configs[$context]['label']); |
|
| 329 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 330 | + 'action' => 'edit_message_template', |
|
| 331 | + 'id' => $item->GRP_ID(), |
|
| 332 | + 'context' => $context, |
|
| 333 | + ), EE_MSG_ADMIN_URL); |
|
| 334 | + $ctxt[] = '<a' |
|
| 335 | + . ' href="' . $edit_link . '"' |
|
| 336 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"' |
|
| 337 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 338 | + . $context_title |
|
| 339 | + . '</a>'; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Get the Name string from the messenger column (linked to edit if the context allows for that). |
|
| 348 | + * @param EE_Message_Template_Group $item |
|
| 349 | + * @return string |
|
| 350 | + * @throws EE_Error |
|
| 351 | + */ |
|
| 352 | + protected function _get_name_link_for_messenger(EE_Message_Template_Group $item) |
|
| 353 | + { |
|
| 354 | + $edit_url = $this->_get_edit_url($item); |
|
| 355 | + return $edit_url |
|
| 356 | + ? '<a href="' . $edit_url . '"' |
|
| 357 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
| 358 | + . ucwords($item->messenger_obj()->label['singular']) |
|
| 359 | + . '</a>' |
|
| 360 | + : ucwords($item->messenger_obj()->label['singular']); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Return the actions array for the messenger column. |
|
| 366 | + * @param EE_Message_Template_Group $item |
|
| 367 | + * @return array |
|
| 368 | + * @throws EE_Error |
|
| 369 | + */ |
|
| 370 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
| 371 | + { |
|
| 372 | + $actions = array(); |
|
| 373 | + if ($edit_url = $this->_get_edit_url($item)) { |
|
| 374 | + $actions = array( |
|
| 375 | + 'edit' => '<a href="' . $edit_url . '"' |
|
| 376 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
| 377 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
| 378 | + . esc_html__('Edit', 'event_espresso') |
|
| 379 | + . '</a>' |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + return $actions; |
|
| 383 | + } |
|
| 384 | 384 | } |
| 385 | 385 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | protected function _setup_data() |
| 29 | 29 | { |
| 30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | 31 | $this->_per_page, |
| 32 | 32 | $this->_view, |
| 33 | 33 | false |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | 'ajax' => true, //for now, |
| 53 | 53 | 'screen' => $this->get_admin_page()->get_current_screen()->id, |
| 54 | 54 | ); |
| 55 | - $this->_columns = array( |
|
| 55 | + $this->_columns = array( |
|
| 56 | 56 | //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
| 57 | 57 | 'message_type' => esc_html__('Message Type', 'event_espresso'), |
| 58 | 58 | 'messenger' => esc_html__('Messenger', 'event_espresso'), |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $message_type = $item->message_type_obj(); |
| 81 | 81 | $messenger = $item->messenger_obj(); |
| 82 | 82 | |
| 83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 83 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | 84 | echo ''; |
| 85 | 85 | return; |
| 86 | 86 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function column_description($item) |
| 160 | 160 | { |
| 161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 161 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | $edit_url = ''; |
| 274 | 274 | // edit link but only if item isn't trashed. |
| 275 | - if (! $item->get('MTP_deleted') |
|
| 275 | + if ( ! $item->get('MTP_deleted') |
|
| 276 | 276 | && EE_Registry::instance()->CAP->current_user_can( |
| 277 | 277 | 'ee_edit_message', |
| 278 | 278 | 'espresso_messages_edit_message_template', |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | protected function _get_context_links(EE_Message_Template_Group $item) |
| 300 | 300 | { |
| 301 | 301 | //first check if we even show the context links or not. |
| 302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 302 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 303 | 303 | 'ee_edit_message', |
| 304 | 304 | 'espresso_messages_edit_message_template', |
| 305 | 305 | $item->ID() |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | && $context_templates[$context]['to'] instanceof EE_Message_Template |
| 319 | 319 | ? $context_templates[$context]['to']->get('MTP_content') |
| 320 | 320 | : null; |
| 321 | - $inactive_class = ( |
|
| 321 | + $inactive_class = ( |
|
| 322 | 322 | empty($mtp_to) |
| 323 | 323 | && ! empty($context_templates[$context]['to']) |
| 324 | 324 | ) |
@@ -331,15 +331,15 @@ discard block |
||
| 331 | 331 | 'id' => $item->GRP_ID(), |
| 332 | 332 | 'context' => $context, |
| 333 | 333 | ), EE_MSG_ADMIN_URL); |
| 334 | - $ctxt[] = '<a' |
|
| 335 | - . ' href="' . $edit_link . '"' |
|
| 336 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' .$inactive_class . '"' |
|
| 337 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 334 | + $ctxt[] = '<a' |
|
| 335 | + . ' href="'.$edit_link.'"' |
|
| 336 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"' |
|
| 337 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
| 338 | 338 | . $context_title |
| 339 | 339 | . '</a>'; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 342 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | { |
| 354 | 354 | $edit_url = $this->_get_edit_url($item); |
| 355 | 355 | return $edit_url |
| 356 | - ? '<a href="' . $edit_url . '"' |
|
| 357 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
| 356 | + ? '<a href="'.$edit_url.'"' |
|
| 357 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
| 358 | 358 | . ucwords($item->messenger_obj()->label['singular']) |
| 359 | 359 | . '</a>' |
| 360 | 360 | : ucwords($item->messenger_obj()->label['singular']); |
@@ -372,9 +372,9 @@ discard block |
||
| 372 | 372 | $actions = array(); |
| 373 | 373 | if ($edit_url = $this->_get_edit_url($item)) { |
| 374 | 374 | $actions = array( |
| 375 | - 'edit' => '<a href="' . $edit_url . '"' |
|
| 376 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
| 377 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
| 375 | + 'edit' => '<a href="'.$edit_url.'"' |
|
| 376 | + . ' class="'.$item->message_type().'-edit-link"' |
|
| 377 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
| 378 | 378 | . esc_html__('Edit', 'event_espresso') |
| 379 | 379 | . '</a>' |
| 380 | 380 | ); |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | $event_label = 'Testing Context Deactivation'; |
| 9 | 9 | |
| 10 | 10 | $I->wantTo( |
| 11 | - 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
| 12 | - . ' expected' |
|
| 11 | + 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
| 12 | + . ' expected' |
|
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | 15 | $I->loginAsAdmin(); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $I->see('The template for Primary Registrant Recipient is currently inactive.'); |
| 35 | 35 | |
| 36 | 36 | $I->amGoingTo( |
| 37 | - 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
| 37 | + 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
| 38 | 38 | ); |
| 39 | 39 | $I->amOnDefaultEventsListTablePage(); |
| 40 | 40 | $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR); |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR); |
| 45 | 45 | $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR); |
| 46 | 46 | $test_registration_details = array( |
| 47 | - 'fname' => 'ContextTestGuy', |
|
| 48 | - 'lname' => 'ContextTestDude', |
|
| 49 | - 'email' => '[email protected]', |
|
| 47 | + 'fname' => 'ContextTestGuy', |
|
| 48 | + 'lname' => 'ContextTestDude', |
|
| 49 | + 'email' => '[email protected]', |
|
| 50 | 50 | ); |
| 51 | 51 | $I->logOut(); |
| 52 | 52 | $I->amOnUrl($event_link); |
@@ -63,48 +63,48 @@ discard block |
||
| 63 | 63 | $I->amOnMessagesActivityListTablePage(); |
| 64 | 64 | //verify registrant context |
| 65 | 65 | $I->see( |
| 66 | - $test_registration_details['email'], |
|
| 67 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 68 | - 'to', |
|
| 69 | - 'Registration Approved', |
|
| 70 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 71 | - '', |
|
| 72 | - 'Registrant' |
|
| 73 | - ) |
|
| 66 | + $test_registration_details['email'], |
|
| 67 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 68 | + 'to', |
|
| 69 | + 'Registration Approved', |
|
| 70 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 71 | + '', |
|
| 72 | + 'Registrant' |
|
| 73 | + ) |
|
| 74 | 74 | ); |
| 75 | 75 | $I->deleteMessageInMessagesListTableFor( |
| 76 | - 'Registration Approved', |
|
| 77 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 78 | - 'Email', |
|
| 79 | - 'Registrant' |
|
| 76 | + 'Registration Approved', |
|
| 77 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 78 | + 'Email', |
|
| 79 | + 'Registrant' |
|
| 80 | 80 | ); |
| 81 | 81 | //verify admin context |
| 82 | 82 | $I->see( |
| 83 | - '[email protected]', |
|
| 84 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 85 | - 'to', |
|
| 86 | - 'Registration Approved', |
|
| 87 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 88 | - ) |
|
| 83 | + '[email protected]', |
|
| 84 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 85 | + 'to', |
|
| 86 | + 'Registration Approved', |
|
| 87 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 88 | + ) |
|
| 89 | 89 | ); |
| 90 | 90 | $I->deleteMessageInMessagesListTableFor( |
| 91 | - 'Registration Approved' |
|
| 91 | + 'Registration Approved' |
|
| 92 | 92 | ); |
| 93 | 93 | //verify primary registrant context is NOT present. |
| 94 | 94 | $I->dontSee( |
| 95 | - $test_registration_details['email'], |
|
| 96 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 97 | - 'to', |
|
| 98 | - 'Registration Approved', |
|
| 99 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 100 | - '', |
|
| 101 | - 'Primary Registrant' |
|
| 102 | - ) |
|
| 95 | + $test_registration_details['email'], |
|
| 96 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 97 | + 'to', |
|
| 98 | + 'Registration Approved', |
|
| 99 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 100 | + '', |
|
| 101 | + 'Primary Registrant' |
|
| 102 | + ) |
|
| 103 | 103 | ); |
| 104 | 104 | |
| 105 | 105 | $I->amGoingTo( |
| 106 | - 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
| 107 | - . ' field to an empty string to verify the message does not send for that context.' |
|
| 106 | + 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
| 107 | + . ' field to an empty string to verify the message does not send for that context.' |
|
| 108 | 108 | ); |
| 109 | 109 | $I->amOnDefaultMessageTemplateListTablePage(); |
| 110 | 110 | $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee'); |
@@ -128,41 +128,41 @@ discard block |
||
| 128 | 128 | $I->amOnMessagesActivityListTablePage(); |
| 129 | 129 | //verify registrant context |
| 130 | 130 | $I->see( |
| 131 | - $test_registration_details['email'], |
|
| 132 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 133 | - 'to', |
|
| 134 | - 'Registration Approved', |
|
| 135 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 136 | - '', |
|
| 137 | - 'Registrant' |
|
| 138 | - ) |
|
| 131 | + $test_registration_details['email'], |
|
| 132 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 133 | + 'to', |
|
| 134 | + 'Registration Approved', |
|
| 135 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 136 | + '', |
|
| 137 | + 'Registrant' |
|
| 138 | + ) |
|
| 139 | 139 | ); |
| 140 | 140 | $I->deleteMessageInMessagesListTableFor( |
| 141 | - 'Registration Approved', |
|
| 142 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 143 | - 'Email', |
|
| 144 | - 'Registrant' |
|
| 141 | + 'Registration Approved', |
|
| 142 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 143 | + 'Email', |
|
| 144 | + 'Registrant' |
|
| 145 | 145 | ); |
| 146 | 146 | //verify admin context |
| 147 | 147 | $I->see( |
| 148 | - '[email protected]', |
|
| 149 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 150 | - 'to', |
|
| 151 | - 'Registration Approved', |
|
| 152 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 153 | - ) |
|
| 148 | + '[email protected]', |
|
| 149 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 150 | + 'to', |
|
| 151 | + 'Registration Approved', |
|
| 152 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 153 | + ) |
|
| 154 | 154 | ); |
| 155 | 155 | $I->deleteMessageInMessagesListTableFor( |
| 156 | - 'Registration Approved' |
|
| 156 | + 'Registration Approved' |
|
| 157 | 157 | ); |
| 158 | 158 | //verify primary registrant context is NOT present. |
| 159 | 159 | $I->dontSee( |
| 160 | - $test_registration_details['email'], |
|
| 161 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 162 | - 'to', |
|
| 163 | - 'Registration Approved', |
|
| 164 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 165 | - '', |
|
| 166 | - 'Primary Registrant' |
|
| 167 | - ) |
|
| 160 | + $test_registration_details['email'], |
|
| 161 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 162 | + 'to', |
|
| 163 | + 'Registration Approved', |
|
| 164 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 165 | + '', |
|
| 166 | + 'Primary Registrant' |
|
| 167 | + ) |
|
| 168 | 168 | ); |
| 169 | 169 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\orm\ModelFieldFactory; |
| 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 | require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
| 7 | 7 | |
@@ -18,789 +18,789 @@ discard block |
||
| 18 | 18 | class EEM_Event extends EEM_CPT_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 23 | - * event |
|
| 24 | - */ |
|
| 25 | - const sold_out = 'sold_out'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 29 | - * date) |
|
| 30 | - */ |
|
| 31 | - const postponed = 'postponed'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * constant used by status(), indicating that the event will no longer occur |
|
| 35 | - */ |
|
| 36 | - const cancelled = 'cancelled'; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected static $_default_reg_status; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * This is the default for the additional limit field. |
|
| 47 | - * @var int |
|
| 48 | - */ |
|
| 49 | - protected static $_default_additional_limit = 10; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * private instance of the Event object |
|
| 54 | - * |
|
| 55 | - * @var EEM_Event |
|
| 56 | - */ |
|
| 57 | - protected static $_instance; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 64 | - * |
|
| 65 | - * @param string $timezone |
|
| 66 | - * @throws \EE_Error |
|
| 67 | - */ |
|
| 68 | - protected function __construct($timezone = null) |
|
| 69 | - { |
|
| 70 | - EE_Registry::instance()->load_model('Registration'); |
|
| 71 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 72 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 73 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 74 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 75 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 76 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 77 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 78 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 79 | - $this->_custom_stati = apply_filters( |
|
| 80 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
| 81 | - array( |
|
| 82 | - EEM_Event::cancelled => array( |
|
| 83 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 84 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 85 | - ), |
|
| 86 | - EEM_Event::postponed => array( |
|
| 87 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 88 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 89 | - ), |
|
| 90 | - EEM_Event::sold_out => array( |
|
| 91 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 92 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 93 | - ), |
|
| 94 | - ) |
|
| 95 | - ); |
|
| 96 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 97 | - : self::$_default_reg_status; |
|
| 98 | - $this->_tables = array( |
|
| 99 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 100 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 101 | - ); |
|
| 102 | - $this->_fields = array( |
|
| 103 | - 'Event_CPT' => array( |
|
| 104 | - 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
| 105 | - esc_html__('Post ID for Event', 'event_espresso')), |
|
| 106 | - 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
| 107 | - false, |
|
| 108 | - ''), |
|
| 109 | - 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
| 110 | - esc_html__('Event Description', 'event_espresso'), |
|
| 111 | - false, ''), |
|
| 112 | - 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
| 113 | - ''), |
|
| 114 | - 'EVT_created' => new EE_Datetime_Field('post_date', |
|
| 115 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 116 | - false, EE_Datetime_Field::now), |
|
| 117 | - 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
| 118 | - esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
| 119 | - 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
| 120 | - esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 121 | - 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
| 122 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
| 123 | - false), |
|
| 124 | - 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
| 125 | - false, |
|
| 126 | - 0), |
|
| 127 | - 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
| 128 | - false, |
|
| 129 | - 1), |
|
| 130 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 131 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 132 | - 'status' => new EE_WP_Post_Status_Field('post_status', |
|
| 133 | - esc_html__('Event Status', 'event_espresso'), |
|
| 134 | - false, 'draft', $this->_custom_stati), |
|
| 135 | - ), |
|
| 136 | - 'Event_Meta' => array( |
|
| 137 | - 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
| 138 | - esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
| 139 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
| 140 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
| 141 | - 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
| 142 | - esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
| 143 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
| 144 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
| 145 | - 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
| 146 | - esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
| 147 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 148 | - 'EVT_additional_limit', |
|
| 149 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 150 | - true, |
|
| 151 | - self::$_default_additional_limit |
|
| 152 | - ), |
|
| 153 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 154 | - 'EVT_default_registration_status', |
|
| 155 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
| 156 | - EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
| 157 | - ), |
|
| 158 | - 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
| 159 | - esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
| 160 | - 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
| 161 | - esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
| 162 | - 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
| 163 | - esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
| 164 | - 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
| 165 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
| 166 | - 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
| 167 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
| 168 | - 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
| 169 | - esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
| 170 | - ), |
|
| 171 | - ); |
|
| 172 | - $this->_model_relations = array( |
|
| 173 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 174 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
| 175 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 176 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 177 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 178 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 179 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 180 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 181 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 182 | - ); |
|
| 183 | - //this model is generally available for reading |
|
| 184 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 185 | - parent::__construct($timezone); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param string $default_reg_status |
|
| 192 | - */ |
|
| 193 | - public static function set_default_reg_status($default_reg_status) |
|
| 194 | - { |
|
| 195 | - self::$_default_reg_status = $default_reg_status; |
|
| 196 | - // if EEM_Event has already been instantiated, |
|
| 197 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 198 | - if (self::$_instance instanceof EEM_Event) { |
|
| 199 | - $default_reg_status = new EE_Enum_Text_Field( |
|
| 200 | - 'EVT_default_registration_status', |
|
| 201 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 202 | - false, |
|
| 203 | - $default_reg_status, |
|
| 204 | - EEM_Registration::reg_status_array() |
|
| 205 | - ); |
|
| 206 | - $default_reg_status->_construct_finalize( |
|
| 207 | - 'Event_Meta', |
|
| 208 | - 'EVT_default_registration_status', |
|
| 209 | - 'EEM_Event' |
|
| 210 | - ); |
|
| 211 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Used to override the default for the additional limit field. |
|
| 218 | - * @param $additional_limit |
|
| 219 | - */ |
|
| 220 | - public static function set_default_additional_limit($additional_limit) |
|
| 221 | - { |
|
| 222 | - self::$_default_additional_limit = (int) $additional_limit; |
|
| 223 | - if (self::$_instance instanceof EEM_Event) { |
|
| 224 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 225 | - 'EVT_additional_limit', |
|
| 226 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 227 | - true, |
|
| 228 | - self::$_default_additional_limit |
|
| 229 | - ); |
|
| 230 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 231 | - 'Event_Meta', |
|
| 232 | - 'EVT_additional_limit', |
|
| 233 | - 'EEM_Event' |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Return what is currently set as the default additional limit for the event. |
|
| 241 | - * @return int |
|
| 242 | - */ |
|
| 243 | - public static function get_default_additional_limit() |
|
| 244 | - { |
|
| 245 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * get_question_groups |
|
| 251 | - * |
|
| 252 | - * @return array |
|
| 253 | - * @throws \EE_Error |
|
| 254 | - */ |
|
| 255 | - public function get_all_question_groups() |
|
| 256 | - { |
|
| 257 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 258 | - array( |
|
| 259 | - array('QSG_deleted' => false), |
|
| 260 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * get_question_groups |
|
| 269 | - * |
|
| 270 | - * @param int $EVT_ID |
|
| 271 | - * @return array|bool |
|
| 272 | - * @throws \EE_Error |
|
| 273 | - */ |
|
| 274 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
| 275 | - { |
|
| 276 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 277 | - EE_Error::add_error( |
|
| 278 | - esc_html__( |
|
| 279 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 280 | - 'event_espresso' |
|
| 281 | - ), |
|
| 282 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 283 | - ); |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 287 | - array( |
|
| 288 | - array('EVT_ID' => $EVT_ID), |
|
| 289 | - ) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * get_question_groups |
|
| 297 | - * |
|
| 298 | - * @param int $EVT_ID |
|
| 299 | - * @param boolean $for_primary_attendee |
|
| 300 | - * @return array|bool |
|
| 301 | - * @throws \EE_Error |
|
| 302 | - */ |
|
| 303 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 304 | - { |
|
| 305 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 306 | - EE_Error::add_error( |
|
| 307 | - esc_html__( |
|
| 308 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 309 | - 'event_espresso' |
|
| 310 | - ), |
|
| 311 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 312 | - ); |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 316 | - array( |
|
| 317 | - array( |
|
| 318 | - 'EVT_ID' => $EVT_ID, |
|
| 319 | - 'EQG_primary' => $for_primary_attendee, |
|
| 320 | - ), |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * get_question_groups |
|
| 329 | - * |
|
| 330 | - * @param int $EVT_ID |
|
| 331 | - * @param EE_Registration $registration |
|
| 332 | - * @return array|bool |
|
| 333 | - * @throws \EE_Error |
|
| 334 | - */ |
|
| 335 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 336 | - { |
|
| 337 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 338 | - EE_Error::add_error( |
|
| 339 | - esc_html__( |
|
| 340 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 341 | - 'event_espresso' |
|
| 342 | - ), |
|
| 343 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 344 | - ); |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - $where_params = array( |
|
| 348 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 349 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
| 350 | - 'QSG_deleted' => false, |
|
| 351 | - ); |
|
| 352 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 353 | - array( |
|
| 354 | - $where_params, |
|
| 355 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 356 | - ) |
|
| 357 | - ); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * get_question_target_db_column |
|
| 364 | - * |
|
| 365 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
| 366 | - * @return array|bool |
|
| 367 | - * @throws \EE_Error |
|
| 368 | - */ |
|
| 369 | - public function get_questions_in_groups($QSG_IDs = '') |
|
| 370 | - { |
|
| 371 | - if (empty($QSG_IDs)) { |
|
| 372 | - EE_Error::add_error( |
|
| 373 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 374 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 375 | - ); |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 379 | - array( |
|
| 380 | - array( |
|
| 381 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 382 | - 'QST_deleted' => false, |
|
| 383 | - 'QST_admin_only' => is_admin(), |
|
| 384 | - ), |
|
| 385 | - 'order_by' => 'QST_order', |
|
| 386 | - ) |
|
| 387 | - ); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * get_options_for_question |
|
| 394 | - * |
|
| 395 | - * @param string $QST_IDs csv list of $QST IDs |
|
| 396 | - * @return array|bool |
|
| 397 | - * @throws \EE_Error |
|
| 398 | - */ |
|
| 399 | - public function get_options_for_question($QST_IDs) |
|
| 400 | - { |
|
| 401 | - if (empty($QST_IDs)) { |
|
| 402 | - EE_Error::add_error( |
|
| 403 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 404 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 405 | - ); |
|
| 406 | - return false; |
|
| 407 | - } |
|
| 408 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 409 | - array( |
|
| 410 | - array( |
|
| 411 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 412 | - 'QSO_deleted' => false, |
|
| 413 | - ), |
|
| 414 | - 'order_by' => 'QSO_ID', |
|
| 415 | - ) |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Gets all events that are published |
|
| 427 | - * and have event start time earlier than now and an event end time later than now |
|
| 428 | - * |
|
| 429 | - * @param array $query_params An array of query params to further filter on |
|
| 430 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 431 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 432 | - * @return EE_Event[]|int |
|
| 433 | - * @throws \EE_Error |
|
| 434 | - */ |
|
| 435 | - public function get_active_events($query_params, $count = false) |
|
| 436 | - { |
|
| 437 | - if (array_key_exists(0, $query_params)) { |
|
| 438 | - $where_params = $query_params[0]; |
|
| 439 | - unset($query_params[0]); |
|
| 440 | - } else { |
|
| 441 | - $where_params = array(); |
|
| 442 | - } |
|
| 443 | - // if we have count make sure we don't include group by |
|
| 444 | - if ($count && isset($query_params['group_by'])) { |
|
| 445 | - unset($query_params['group_by']); |
|
| 446 | - } |
|
| 447 | - // let's add specific query_params for active_events |
|
| 448 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 449 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 450 | - //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 451 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 452 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 453 | - '<', |
|
| 454 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 455 | - ); |
|
| 456 | - } else { |
|
| 457 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 458 | - '<', |
|
| 459 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 463 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 464 | - '>', |
|
| 465 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 466 | - ); |
|
| 467 | - } else { |
|
| 468 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 469 | - '>', |
|
| 470 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 471 | - ); |
|
| 472 | - } |
|
| 473 | - $query_params[0] = $where_params; |
|
| 474 | - // don't use $query_params with count() |
|
| 475 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 476 | - return $count |
|
| 477 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 478 | - : $this->get_all($query_params); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * get all events that are published and have an event start time later than now |
|
| 485 | - * |
|
| 486 | - * @param array $query_params An array of query params to further filter on |
|
| 487 | - * (Note that status and DTT_EVT_start will be overridden) |
|
| 488 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 489 | - * @return EE_Event[]|int |
|
| 490 | - * @throws \EE_Error |
|
| 491 | - */ |
|
| 492 | - public function get_upcoming_events($query_params, $count = false) |
|
| 493 | - { |
|
| 494 | - if (array_key_exists(0, $query_params)) { |
|
| 495 | - $where_params = $query_params[0]; |
|
| 496 | - unset($query_params[0]); |
|
| 497 | - } else { |
|
| 498 | - $where_params = array(); |
|
| 499 | - } |
|
| 500 | - // if we have count make sure we don't include group by |
|
| 501 | - if ($count && isset($query_params['group_by'])) { |
|
| 502 | - unset($query_params['group_by']); |
|
| 503 | - } |
|
| 504 | - // let's add specific query_params for active_events |
|
| 505 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 506 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 507 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 508 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 509 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 510 | - '>', |
|
| 511 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 512 | - ); |
|
| 513 | - } else { |
|
| 514 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 515 | - '>', |
|
| 516 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - $query_params[0] = $where_params; |
|
| 520 | - // don't use $query_params with count() |
|
| 521 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 522 | - return $count |
|
| 523 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 524 | - : $this->get_all($query_params); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Gets all events that are published |
|
| 531 | - * and have an event end time later than now |
|
| 532 | - * |
|
| 533 | - * @param array $query_params An array of query params to further filter on |
|
| 534 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 535 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 536 | - * @return EE_Event[]|int |
|
| 537 | - * @throws \EE_Error |
|
| 538 | - */ |
|
| 539 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 540 | - { |
|
| 541 | - if (array_key_exists(0, $query_params)) { |
|
| 542 | - $where_params = $query_params[0]; |
|
| 543 | - unset($query_params[0]); |
|
| 544 | - } else { |
|
| 545 | - $where_params = array(); |
|
| 546 | - } |
|
| 547 | - // if we have count make sure we don't include group by |
|
| 548 | - if ($count && isset($query_params['group_by'])) { |
|
| 549 | - unset($query_params['group_by']); |
|
| 550 | - } |
|
| 551 | - // let's add specific query_params for active_events |
|
| 552 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 553 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 554 | - // add where params for DTT_EVT_end |
|
| 555 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 556 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 557 | - '>', |
|
| 558 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 559 | - ); |
|
| 560 | - } else { |
|
| 561 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 562 | - '>', |
|
| 563 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 564 | - ); |
|
| 565 | - } |
|
| 566 | - $query_params[0] = $where_params; |
|
| 567 | - // don't use $query_params with count() |
|
| 568 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 569 | - return $count |
|
| 570 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 571 | - : $this->get_all($query_params); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * This only returns events that are expired. |
|
| 578 | - * They may still be published but all their datetimes have expired. |
|
| 579 | - * |
|
| 580 | - * @param array $query_params An array of query params to further filter on |
|
| 581 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 582 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 583 | - * @return EE_Event[]|int |
|
| 584 | - * @throws \EE_Error |
|
| 585 | - */ |
|
| 586 | - public function get_expired_events($query_params, $count = false) |
|
| 587 | - { |
|
| 588 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 589 | - // if we have count make sure we don't include group by |
|
| 590 | - if ($count && isset($query_params['group_by'])) { |
|
| 591 | - unset($query_params['group_by']); |
|
| 592 | - } |
|
| 593 | - // let's add specific query_params for active_events |
|
| 594 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 595 | - if (isset($where_params['status'])) { |
|
| 596 | - unset($where_params['status']); |
|
| 597 | - } |
|
| 598 | - $exclude_query = $query_params; |
|
| 599 | - if (isset($exclude_query[0])) { |
|
| 600 | - unset($exclude_query[0]); |
|
| 601 | - } |
|
| 602 | - $exclude_query[0] = array( |
|
| 603 | - 'Datetime.DTT_EVT_end' => array( |
|
| 604 | - '>', |
|
| 605 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 606 | - ), |
|
| 607 | - ); |
|
| 608 | - // first get all events that have datetimes where its not expired. |
|
| 609 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 610 | - $event_ids = array_keys($event_ids); |
|
| 611 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 612 | - $and_condition = array( |
|
| 613 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 614 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 615 | - ); |
|
| 616 | - if (isset($where_params['OR'])) { |
|
| 617 | - $and_condition['OR'] = $where_params['OR']; |
|
| 618 | - unset($where_params['OR']); |
|
| 619 | - } |
|
| 620 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 621 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 622 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 623 | - } |
|
| 624 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 625 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 626 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 627 | - } |
|
| 628 | - // merge remaining $where params with the and conditions. |
|
| 629 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 630 | - $query_params[0] = $where_params; |
|
| 631 | - // don't use $query_params with count() |
|
| 632 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 633 | - return $count |
|
| 634 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 635 | - : $this->get_all($query_params); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * This basically just returns the events that do not have the publish status. |
|
| 642 | - * |
|
| 643 | - * @param array $query_params An array of query params to further filter on |
|
| 644 | - * (note that status will be overwritten) |
|
| 645 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
| 646 | - * @return EE_Event[]|int |
|
| 647 | - * @throws \EE_Error |
|
| 648 | - */ |
|
| 649 | - public function get_inactive_events($query_params, $count = false) |
|
| 650 | - { |
|
| 651 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 652 | - // let's add in specific query_params for inactive events. |
|
| 653 | - if (isset($where_params['status'])) { |
|
| 654 | - unset($where_params['status']); |
|
| 655 | - } |
|
| 656 | - // if we have count make sure we don't include group by |
|
| 657 | - if ($count && isset($query_params['group_by'])) { |
|
| 658 | - unset($query_params['group_by']); |
|
| 659 | - } |
|
| 660 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 661 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 662 | - if (isset($where_params['OR'])) { |
|
| 663 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
| 664 | - unset($where_params['OR']); |
|
| 665 | - } |
|
| 666 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 667 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 668 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 669 | - } |
|
| 670 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 671 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 672 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 673 | - } |
|
| 674 | - $query_params[0] = $where_params; |
|
| 675 | - // don't use $query_params with count() |
|
| 676 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 677 | - return $count |
|
| 678 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 679 | - : $this->get_all($query_params); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 686 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 687 | - * attached to the event. See parent for param descriptions |
|
| 688 | - * |
|
| 689 | - * @param $id_or_obj |
|
| 690 | - * @param $other_model_id_or_obj |
|
| 691 | - * @param string $relationName |
|
| 692 | - * @param array $where_query |
|
| 693 | - * @return EE_Base_Class |
|
| 694 | - * @throws EE_Error |
|
| 695 | - */ |
|
| 696 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 697 | - { |
|
| 698 | - if ($relationName === 'Price') { |
|
| 699 | - //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 700 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 701 | - //if EVT_ID = 0, then this is a default |
|
| 702 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 703 | - //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 704 | - $prc_chk->set('PRC_ID', 0); |
|
| 705 | - } |
|
| 706 | - //run parent |
|
| 707 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 708 | - } |
|
| 709 | - //otherwise carry on as normal |
|
| 710 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /******************** DEPRECATED METHODS ********************/ |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * _get_question_target_db_column |
|
| 721 | - * |
|
| 722 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 723 | - * EE_Registration_Custom_Questions_Form located in |
|
| 724 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 725 | - * @access public |
|
| 726 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 727 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 728 | - * registration). |
|
| 729 | - * @throws EE_Error |
|
| 730 | - * @return array |
|
| 731 | - */ |
|
| 732 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 733 | - { |
|
| 734 | - if (empty($EVT_ID)) { |
|
| 735 | - throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 736 | - 'event_espresso')); |
|
| 737 | - } |
|
| 738 | - $questions = array(); |
|
| 739 | - // get all question groups for event |
|
| 740 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 741 | - if (! empty($qgs)) { |
|
| 742 | - foreach ($qgs as $qg) { |
|
| 743 | - $qsts = $qg->questions(); |
|
| 744 | - $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 745 | - $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 746 | - foreach ($qsts as $qst) { |
|
| 747 | - if ($qst->is_system_question()) { |
|
| 748 | - continue; |
|
| 749 | - } |
|
| 750 | - $answer = EEM_Answer::instance()->get_one(array( |
|
| 751 | - array( |
|
| 752 | - 'QST_ID' => $qst->ID(), |
|
| 753 | - 'REG_ID' => $registration->ID(), |
|
| 754 | - ), |
|
| 755 | - )); |
|
| 756 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 757 | - $qst_name = $qstn_id = $qst->ID(); |
|
| 758 | - $ans_id = $answer->ID(); |
|
| 759 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 760 | - $input_name = ''; |
|
| 761 | - $input_id = sanitize_key($qst->display_text()); |
|
| 762 | - $input_class = ''; |
|
| 763 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 764 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
| 765 | - . $input_name |
|
| 766 | - . $qst_name; |
|
| 767 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 768 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 769 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 770 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 771 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 772 | - //leave responses as-is, don't convert stuff into html entities please! |
|
| 773 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 774 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 775 | - $QSOs = $qst->options(true, $answer->value()); |
|
| 776 | - if (is_array($QSOs)) { |
|
| 777 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 778 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - return $questions; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 791 | - * or an stdClass where each property is the name of a column, |
|
| 792 | - * @return EE_Base_Class |
|
| 793 | - * @throws \EE_Error |
|
| 794 | - */ |
|
| 795 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 796 | - { |
|
| 797 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 798 | - if($classInstance instanceof EE_Event) { |
|
| 799 | - //events have their timezone defined in the DB, so use it immediately |
|
| 800 | - $this->set_timezone($classInstance->get_timezone()); |
|
| 801 | - } |
|
| 802 | - return $classInstance; |
|
| 803 | - } |
|
| 21 | + /** |
|
| 22 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 23 | + * event |
|
| 24 | + */ |
|
| 25 | + const sold_out = 'sold_out'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 29 | + * date) |
|
| 30 | + */ |
|
| 31 | + const postponed = 'postponed'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * constant used by status(), indicating that the event will no longer occur |
|
| 35 | + */ |
|
| 36 | + const cancelled = 'cancelled'; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected static $_default_reg_status; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * This is the default for the additional limit field. |
|
| 47 | + * @var int |
|
| 48 | + */ |
|
| 49 | + protected static $_default_additional_limit = 10; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * private instance of the Event object |
|
| 54 | + * |
|
| 55 | + * @var EEM_Event |
|
| 56 | + */ |
|
| 57 | + protected static $_instance; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 64 | + * |
|
| 65 | + * @param string $timezone |
|
| 66 | + * @throws \EE_Error |
|
| 67 | + */ |
|
| 68 | + protected function __construct($timezone = null) |
|
| 69 | + { |
|
| 70 | + EE_Registry::instance()->load_model('Registration'); |
|
| 71 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 72 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 73 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 74 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 75 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 76 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 77 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 78 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 79 | + $this->_custom_stati = apply_filters( |
|
| 80 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
| 81 | + array( |
|
| 82 | + EEM_Event::cancelled => array( |
|
| 83 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 84 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 85 | + ), |
|
| 86 | + EEM_Event::postponed => array( |
|
| 87 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 88 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 89 | + ), |
|
| 90 | + EEM_Event::sold_out => array( |
|
| 91 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 92 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 93 | + ), |
|
| 94 | + ) |
|
| 95 | + ); |
|
| 96 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 97 | + : self::$_default_reg_status; |
|
| 98 | + $this->_tables = array( |
|
| 99 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 100 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 101 | + ); |
|
| 102 | + $this->_fields = array( |
|
| 103 | + 'Event_CPT' => array( |
|
| 104 | + 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
| 105 | + esc_html__('Post ID for Event', 'event_espresso')), |
|
| 106 | + 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
| 107 | + false, |
|
| 108 | + ''), |
|
| 109 | + 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
| 110 | + esc_html__('Event Description', 'event_espresso'), |
|
| 111 | + false, ''), |
|
| 112 | + 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
| 113 | + ''), |
|
| 114 | + 'EVT_created' => new EE_Datetime_Field('post_date', |
|
| 115 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 116 | + false, EE_Datetime_Field::now), |
|
| 117 | + 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
| 118 | + esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
| 119 | + 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
| 120 | + esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 121 | + 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
| 122 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
| 123 | + false), |
|
| 124 | + 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
| 125 | + false, |
|
| 126 | + 0), |
|
| 127 | + 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
| 128 | + false, |
|
| 129 | + 1), |
|
| 130 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 131 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 132 | + 'status' => new EE_WP_Post_Status_Field('post_status', |
|
| 133 | + esc_html__('Event Status', 'event_espresso'), |
|
| 134 | + false, 'draft', $this->_custom_stati), |
|
| 135 | + ), |
|
| 136 | + 'Event_Meta' => array( |
|
| 137 | + 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
| 138 | + esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
| 139 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
| 140 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
| 141 | + 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
| 142 | + esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
| 143 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
| 144 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
| 145 | + 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
| 146 | + esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
| 147 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 148 | + 'EVT_additional_limit', |
|
| 149 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 150 | + true, |
|
| 151 | + self::$_default_additional_limit |
|
| 152 | + ), |
|
| 153 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 154 | + 'EVT_default_registration_status', |
|
| 155 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
| 156 | + EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
| 157 | + ), |
|
| 158 | + 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
| 159 | + esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
| 160 | + 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
| 161 | + esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
| 162 | + 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
| 163 | + esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
| 164 | + 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
| 165 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
| 166 | + 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
| 167 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
| 168 | + 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
| 169 | + esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
| 170 | + ), |
|
| 171 | + ); |
|
| 172 | + $this->_model_relations = array( |
|
| 173 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 174 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
| 175 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 176 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 177 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 178 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 179 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 180 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 181 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 182 | + ); |
|
| 183 | + //this model is generally available for reading |
|
| 184 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 185 | + parent::__construct($timezone); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param string $default_reg_status |
|
| 192 | + */ |
|
| 193 | + public static function set_default_reg_status($default_reg_status) |
|
| 194 | + { |
|
| 195 | + self::$_default_reg_status = $default_reg_status; |
|
| 196 | + // if EEM_Event has already been instantiated, |
|
| 197 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 198 | + if (self::$_instance instanceof EEM_Event) { |
|
| 199 | + $default_reg_status = new EE_Enum_Text_Field( |
|
| 200 | + 'EVT_default_registration_status', |
|
| 201 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 202 | + false, |
|
| 203 | + $default_reg_status, |
|
| 204 | + EEM_Registration::reg_status_array() |
|
| 205 | + ); |
|
| 206 | + $default_reg_status->_construct_finalize( |
|
| 207 | + 'Event_Meta', |
|
| 208 | + 'EVT_default_registration_status', |
|
| 209 | + 'EEM_Event' |
|
| 210 | + ); |
|
| 211 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Used to override the default for the additional limit field. |
|
| 218 | + * @param $additional_limit |
|
| 219 | + */ |
|
| 220 | + public static function set_default_additional_limit($additional_limit) |
|
| 221 | + { |
|
| 222 | + self::$_default_additional_limit = (int) $additional_limit; |
|
| 223 | + if (self::$_instance instanceof EEM_Event) { |
|
| 224 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 225 | + 'EVT_additional_limit', |
|
| 226 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 227 | + true, |
|
| 228 | + self::$_default_additional_limit |
|
| 229 | + ); |
|
| 230 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 231 | + 'Event_Meta', |
|
| 232 | + 'EVT_additional_limit', |
|
| 233 | + 'EEM_Event' |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Return what is currently set as the default additional limit for the event. |
|
| 241 | + * @return int |
|
| 242 | + */ |
|
| 243 | + public static function get_default_additional_limit() |
|
| 244 | + { |
|
| 245 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * get_question_groups |
|
| 251 | + * |
|
| 252 | + * @return array |
|
| 253 | + * @throws \EE_Error |
|
| 254 | + */ |
|
| 255 | + public function get_all_question_groups() |
|
| 256 | + { |
|
| 257 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 258 | + array( |
|
| 259 | + array('QSG_deleted' => false), |
|
| 260 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * get_question_groups |
|
| 269 | + * |
|
| 270 | + * @param int $EVT_ID |
|
| 271 | + * @return array|bool |
|
| 272 | + * @throws \EE_Error |
|
| 273 | + */ |
|
| 274 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
| 275 | + { |
|
| 276 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 277 | + EE_Error::add_error( |
|
| 278 | + esc_html__( |
|
| 279 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 280 | + 'event_espresso' |
|
| 281 | + ), |
|
| 282 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 283 | + ); |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 287 | + array( |
|
| 288 | + array('EVT_ID' => $EVT_ID), |
|
| 289 | + ) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * get_question_groups |
|
| 297 | + * |
|
| 298 | + * @param int $EVT_ID |
|
| 299 | + * @param boolean $for_primary_attendee |
|
| 300 | + * @return array|bool |
|
| 301 | + * @throws \EE_Error |
|
| 302 | + */ |
|
| 303 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 304 | + { |
|
| 305 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 306 | + EE_Error::add_error( |
|
| 307 | + esc_html__( |
|
| 308 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 309 | + 'event_espresso' |
|
| 310 | + ), |
|
| 311 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 312 | + ); |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 316 | + array( |
|
| 317 | + array( |
|
| 318 | + 'EVT_ID' => $EVT_ID, |
|
| 319 | + 'EQG_primary' => $for_primary_attendee, |
|
| 320 | + ), |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * get_question_groups |
|
| 329 | + * |
|
| 330 | + * @param int $EVT_ID |
|
| 331 | + * @param EE_Registration $registration |
|
| 332 | + * @return array|bool |
|
| 333 | + * @throws \EE_Error |
|
| 334 | + */ |
|
| 335 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 336 | + { |
|
| 337 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 338 | + EE_Error::add_error( |
|
| 339 | + esc_html__( |
|
| 340 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 341 | + 'event_espresso' |
|
| 342 | + ), |
|
| 343 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 344 | + ); |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + $where_params = array( |
|
| 348 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 349 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
| 350 | + 'QSG_deleted' => false, |
|
| 351 | + ); |
|
| 352 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 353 | + array( |
|
| 354 | + $where_params, |
|
| 355 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 356 | + ) |
|
| 357 | + ); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * get_question_target_db_column |
|
| 364 | + * |
|
| 365 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
| 366 | + * @return array|bool |
|
| 367 | + * @throws \EE_Error |
|
| 368 | + */ |
|
| 369 | + public function get_questions_in_groups($QSG_IDs = '') |
|
| 370 | + { |
|
| 371 | + if (empty($QSG_IDs)) { |
|
| 372 | + EE_Error::add_error( |
|
| 373 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 374 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 375 | + ); |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 379 | + array( |
|
| 380 | + array( |
|
| 381 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 382 | + 'QST_deleted' => false, |
|
| 383 | + 'QST_admin_only' => is_admin(), |
|
| 384 | + ), |
|
| 385 | + 'order_by' => 'QST_order', |
|
| 386 | + ) |
|
| 387 | + ); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * get_options_for_question |
|
| 394 | + * |
|
| 395 | + * @param string $QST_IDs csv list of $QST IDs |
|
| 396 | + * @return array|bool |
|
| 397 | + * @throws \EE_Error |
|
| 398 | + */ |
|
| 399 | + public function get_options_for_question($QST_IDs) |
|
| 400 | + { |
|
| 401 | + if (empty($QST_IDs)) { |
|
| 402 | + EE_Error::add_error( |
|
| 403 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 404 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 405 | + ); |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 408 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 409 | + array( |
|
| 410 | + array( |
|
| 411 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 412 | + 'QSO_deleted' => false, |
|
| 413 | + ), |
|
| 414 | + 'order_by' => 'QSO_ID', |
|
| 415 | + ) |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Gets all events that are published |
|
| 427 | + * and have event start time earlier than now and an event end time later than now |
|
| 428 | + * |
|
| 429 | + * @param array $query_params An array of query params to further filter on |
|
| 430 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 431 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 432 | + * @return EE_Event[]|int |
|
| 433 | + * @throws \EE_Error |
|
| 434 | + */ |
|
| 435 | + public function get_active_events($query_params, $count = false) |
|
| 436 | + { |
|
| 437 | + if (array_key_exists(0, $query_params)) { |
|
| 438 | + $where_params = $query_params[0]; |
|
| 439 | + unset($query_params[0]); |
|
| 440 | + } else { |
|
| 441 | + $where_params = array(); |
|
| 442 | + } |
|
| 443 | + // if we have count make sure we don't include group by |
|
| 444 | + if ($count && isset($query_params['group_by'])) { |
|
| 445 | + unset($query_params['group_by']); |
|
| 446 | + } |
|
| 447 | + // let's add specific query_params for active_events |
|
| 448 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 449 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 450 | + //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 451 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 452 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 453 | + '<', |
|
| 454 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 455 | + ); |
|
| 456 | + } else { |
|
| 457 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 458 | + '<', |
|
| 459 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 463 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 464 | + '>', |
|
| 465 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 466 | + ); |
|
| 467 | + } else { |
|
| 468 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 469 | + '>', |
|
| 470 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 471 | + ); |
|
| 472 | + } |
|
| 473 | + $query_params[0] = $where_params; |
|
| 474 | + // don't use $query_params with count() |
|
| 475 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 476 | + return $count |
|
| 477 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 478 | + : $this->get_all($query_params); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * get all events that are published and have an event start time later than now |
|
| 485 | + * |
|
| 486 | + * @param array $query_params An array of query params to further filter on |
|
| 487 | + * (Note that status and DTT_EVT_start will be overridden) |
|
| 488 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 489 | + * @return EE_Event[]|int |
|
| 490 | + * @throws \EE_Error |
|
| 491 | + */ |
|
| 492 | + public function get_upcoming_events($query_params, $count = false) |
|
| 493 | + { |
|
| 494 | + if (array_key_exists(0, $query_params)) { |
|
| 495 | + $where_params = $query_params[0]; |
|
| 496 | + unset($query_params[0]); |
|
| 497 | + } else { |
|
| 498 | + $where_params = array(); |
|
| 499 | + } |
|
| 500 | + // if we have count make sure we don't include group by |
|
| 501 | + if ($count && isset($query_params['group_by'])) { |
|
| 502 | + unset($query_params['group_by']); |
|
| 503 | + } |
|
| 504 | + // let's add specific query_params for active_events |
|
| 505 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 506 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 507 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 508 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 509 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 510 | + '>', |
|
| 511 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 512 | + ); |
|
| 513 | + } else { |
|
| 514 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 515 | + '>', |
|
| 516 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + $query_params[0] = $where_params; |
|
| 520 | + // don't use $query_params with count() |
|
| 521 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 522 | + return $count |
|
| 523 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 524 | + : $this->get_all($query_params); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Gets all events that are published |
|
| 531 | + * and have an event end time later than now |
|
| 532 | + * |
|
| 533 | + * @param array $query_params An array of query params to further filter on |
|
| 534 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 535 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 536 | + * @return EE_Event[]|int |
|
| 537 | + * @throws \EE_Error |
|
| 538 | + */ |
|
| 539 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 540 | + { |
|
| 541 | + if (array_key_exists(0, $query_params)) { |
|
| 542 | + $where_params = $query_params[0]; |
|
| 543 | + unset($query_params[0]); |
|
| 544 | + } else { |
|
| 545 | + $where_params = array(); |
|
| 546 | + } |
|
| 547 | + // if we have count make sure we don't include group by |
|
| 548 | + if ($count && isset($query_params['group_by'])) { |
|
| 549 | + unset($query_params['group_by']); |
|
| 550 | + } |
|
| 551 | + // let's add specific query_params for active_events |
|
| 552 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 553 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 554 | + // add where params for DTT_EVT_end |
|
| 555 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 556 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 557 | + '>', |
|
| 558 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 559 | + ); |
|
| 560 | + } else { |
|
| 561 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 562 | + '>', |
|
| 563 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 564 | + ); |
|
| 565 | + } |
|
| 566 | + $query_params[0] = $where_params; |
|
| 567 | + // don't use $query_params with count() |
|
| 568 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 569 | + return $count |
|
| 570 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 571 | + : $this->get_all($query_params); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * This only returns events that are expired. |
|
| 578 | + * They may still be published but all their datetimes have expired. |
|
| 579 | + * |
|
| 580 | + * @param array $query_params An array of query params to further filter on |
|
| 581 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 582 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 583 | + * @return EE_Event[]|int |
|
| 584 | + * @throws \EE_Error |
|
| 585 | + */ |
|
| 586 | + public function get_expired_events($query_params, $count = false) |
|
| 587 | + { |
|
| 588 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 589 | + // if we have count make sure we don't include group by |
|
| 590 | + if ($count && isset($query_params['group_by'])) { |
|
| 591 | + unset($query_params['group_by']); |
|
| 592 | + } |
|
| 593 | + // let's add specific query_params for active_events |
|
| 594 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 595 | + if (isset($where_params['status'])) { |
|
| 596 | + unset($where_params['status']); |
|
| 597 | + } |
|
| 598 | + $exclude_query = $query_params; |
|
| 599 | + if (isset($exclude_query[0])) { |
|
| 600 | + unset($exclude_query[0]); |
|
| 601 | + } |
|
| 602 | + $exclude_query[0] = array( |
|
| 603 | + 'Datetime.DTT_EVT_end' => array( |
|
| 604 | + '>', |
|
| 605 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 606 | + ), |
|
| 607 | + ); |
|
| 608 | + // first get all events that have datetimes where its not expired. |
|
| 609 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 610 | + $event_ids = array_keys($event_ids); |
|
| 611 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 612 | + $and_condition = array( |
|
| 613 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 614 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 615 | + ); |
|
| 616 | + if (isset($where_params['OR'])) { |
|
| 617 | + $and_condition['OR'] = $where_params['OR']; |
|
| 618 | + unset($where_params['OR']); |
|
| 619 | + } |
|
| 620 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 621 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 622 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 623 | + } |
|
| 624 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 625 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 626 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 627 | + } |
|
| 628 | + // merge remaining $where params with the and conditions. |
|
| 629 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 630 | + $query_params[0] = $where_params; |
|
| 631 | + // don't use $query_params with count() |
|
| 632 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 633 | + return $count |
|
| 634 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 635 | + : $this->get_all($query_params); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * This basically just returns the events that do not have the publish status. |
|
| 642 | + * |
|
| 643 | + * @param array $query_params An array of query params to further filter on |
|
| 644 | + * (note that status will be overwritten) |
|
| 645 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
| 646 | + * @return EE_Event[]|int |
|
| 647 | + * @throws \EE_Error |
|
| 648 | + */ |
|
| 649 | + public function get_inactive_events($query_params, $count = false) |
|
| 650 | + { |
|
| 651 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 652 | + // let's add in specific query_params for inactive events. |
|
| 653 | + if (isset($where_params['status'])) { |
|
| 654 | + unset($where_params['status']); |
|
| 655 | + } |
|
| 656 | + // if we have count make sure we don't include group by |
|
| 657 | + if ($count && isset($query_params['group_by'])) { |
|
| 658 | + unset($query_params['group_by']); |
|
| 659 | + } |
|
| 660 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 661 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 662 | + if (isset($where_params['OR'])) { |
|
| 663 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
| 664 | + unset($where_params['OR']); |
|
| 665 | + } |
|
| 666 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 667 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 668 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 669 | + } |
|
| 670 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 671 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 672 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 673 | + } |
|
| 674 | + $query_params[0] = $where_params; |
|
| 675 | + // don't use $query_params with count() |
|
| 676 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 677 | + return $count |
|
| 678 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 679 | + : $this->get_all($query_params); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 686 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 687 | + * attached to the event. See parent for param descriptions |
|
| 688 | + * |
|
| 689 | + * @param $id_or_obj |
|
| 690 | + * @param $other_model_id_or_obj |
|
| 691 | + * @param string $relationName |
|
| 692 | + * @param array $where_query |
|
| 693 | + * @return EE_Base_Class |
|
| 694 | + * @throws EE_Error |
|
| 695 | + */ |
|
| 696 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 697 | + { |
|
| 698 | + if ($relationName === 'Price') { |
|
| 699 | + //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 700 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 701 | + //if EVT_ID = 0, then this is a default |
|
| 702 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 703 | + //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 704 | + $prc_chk->set('PRC_ID', 0); |
|
| 705 | + } |
|
| 706 | + //run parent |
|
| 707 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 708 | + } |
|
| 709 | + //otherwise carry on as normal |
|
| 710 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /******************** DEPRECATED METHODS ********************/ |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * _get_question_target_db_column |
|
| 721 | + * |
|
| 722 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 723 | + * EE_Registration_Custom_Questions_Form located in |
|
| 724 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 725 | + * @access public |
|
| 726 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 727 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 728 | + * registration). |
|
| 729 | + * @throws EE_Error |
|
| 730 | + * @return array |
|
| 731 | + */ |
|
| 732 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 733 | + { |
|
| 734 | + if (empty($EVT_ID)) { |
|
| 735 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 736 | + 'event_espresso')); |
|
| 737 | + } |
|
| 738 | + $questions = array(); |
|
| 739 | + // get all question groups for event |
|
| 740 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 741 | + if (! empty($qgs)) { |
|
| 742 | + foreach ($qgs as $qg) { |
|
| 743 | + $qsts = $qg->questions(); |
|
| 744 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 745 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 746 | + foreach ($qsts as $qst) { |
|
| 747 | + if ($qst->is_system_question()) { |
|
| 748 | + continue; |
|
| 749 | + } |
|
| 750 | + $answer = EEM_Answer::instance()->get_one(array( |
|
| 751 | + array( |
|
| 752 | + 'QST_ID' => $qst->ID(), |
|
| 753 | + 'REG_ID' => $registration->ID(), |
|
| 754 | + ), |
|
| 755 | + )); |
|
| 756 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 757 | + $qst_name = $qstn_id = $qst->ID(); |
|
| 758 | + $ans_id = $answer->ID(); |
|
| 759 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 760 | + $input_name = ''; |
|
| 761 | + $input_id = sanitize_key($qst->display_text()); |
|
| 762 | + $input_class = ''; |
|
| 763 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 764 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
| 765 | + . $input_name |
|
| 766 | + . $qst_name; |
|
| 767 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 768 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 769 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 770 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 771 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 772 | + //leave responses as-is, don't convert stuff into html entities please! |
|
| 773 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 774 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 775 | + $QSOs = $qst->options(true, $answer->value()); |
|
| 776 | + if (is_array($QSOs)) { |
|
| 777 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 778 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + return $questions; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 791 | + * or an stdClass where each property is the name of a column, |
|
| 792 | + * @return EE_Base_Class |
|
| 793 | + * @throws \EE_Error |
|
| 794 | + */ |
|
| 795 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 796 | + { |
|
| 797 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 798 | + if($classInstance instanceof EE_Event) { |
|
| 799 | + //events have their timezone defined in the DB, so use it immediately |
|
| 800 | + $this->set_timezone($classInstance->get_timezone()); |
|
| 801 | + } |
|
| 802 | + return $classInstance; |
|
| 803 | + } |
|
| 804 | 804 | } |
| 805 | 805 | // End of file EEM_Event.model.php |
| 806 | 806 | // Location: /includes/models/EEM_Event.model.php |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\orm\ModelFieldFactory; |
| 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 | -require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
|
| 6 | +require_once(EE_MODELS.'EEM_CPT_Base.model.php'); |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
| 159 | 159 | esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
| 160 | 160 | 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
| 161 | - esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
| 161 | + esc_html__('Event Phone Number', 'event_espresso'), false, ''), |
|
| 162 | 162 | 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
| 163 | 163 | esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
| 164 | 164 | 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
| 165 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
| 165 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false, ''), |
|
| 166 | 166 | 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
| 167 | 167 | esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
| 168 | 168 | 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public function get_all_event_question_groups($EVT_ID = 0) |
| 275 | 275 | { |
| 276 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 276 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 277 | 277 | EE_Error::add_error( |
| 278 | 278 | esc_html__( |
| 279 | 279 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
| 304 | 304 | { |
| 305 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 305 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 306 | 306 | EE_Error::add_error( |
| 307 | 307 | esc_html__( |
| 308 | 308 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
| 336 | 336 | { |
| 337 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 337 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 338 | 338 | EE_Error::add_error( |
| 339 | 339 | esc_html__( |
| 340 | 340 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | $questions = array(); |
| 739 | 739 | // get all question groups for event |
| 740 | 740 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
| 741 | - if (! empty($qgs)) { |
|
| 741 | + if ( ! empty($qgs)) { |
|
| 742 | 742 | foreach ($qgs as $qg) { |
| 743 | 743 | $qsts = $qg->questions(); |
| 744 | 744 | $questions[$qg->ID()] = $qg->model_field_array(); |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
| 757 | 757 | $qst_name = $qstn_id = $qst->ID(); |
| 758 | 758 | $ans_id = $answer->ID(); |
| 759 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 759 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
| 760 | 760 | $input_name = ''; |
| 761 | 761 | $input_id = sanitize_key($qst->display_text()); |
| 762 | 762 | $input_class = ''; |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
| 765 | 765 | . $input_name |
| 766 | 766 | . $qst_name; |
| 767 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 767 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
| 768 | 768 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
| 769 | 769 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
| 770 | 770 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | public function instantiate_class_from_array_or_object($cols_n_values) |
| 796 | 796 | { |
| 797 | 797 | $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
| 798 | - if($classInstance instanceof EE_Event) { |
|
| 798 | + if ($classInstance instanceof EE_Event) { |
|
| 799 | 799 | //events have their timezone defined in the DB, so use it immediately |
| 800 | 800 | $this->set_timezone($classInstance->get_timezone()); |
| 801 | 801 | } |
@@ -3065,7 +3065,7 @@ |
||
| 3065 | 3065 | * |
| 3066 | 3066 | * @param int $GRP_ID The group being deleted |
| 3067 | 3067 | * @param bool $include_group whether to delete the Message Template Group as well. |
| 3068 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3068 | + * @return integer boolean to indicate the success of the deletes or not. |
|
| 3069 | 3069 | * @throws EE_Error |
| 3070 | 3070 | * @throws InvalidArgumentException |
| 3071 | 3071 | * @throws InvalidDataTypeException |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $this->_admin_base_url = EE_MSG_ADMIN_URL; |
| 94 | 94 | $this->_admin_base_path = EE_MSG_ADMIN; |
| 95 | 95 | |
| 96 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 96 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array(); |
|
| 97 | 97 | |
| 98 | 98 | $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
| 99 | 99 | $this->_load_message_resource_manager(); |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
| 253 | 253 | $messenger_options |
| 254 | 254 | ); |
| 255 | - $input = new EE_Select_Input( |
|
| 255 | + $input = new EE_Select_Input( |
|
| 256 | 256 | $messenger_options, |
| 257 | 257 | array( |
| 258 | 258 | 'html_name' => 'ee_messenger_filter_by', |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
| 291 | 291 | $message_type_options |
| 292 | 292 | ); |
| 293 | - $input = new EE_Select_Input( |
|
| 293 | + $input = new EE_Select_Input( |
|
| 294 | 294 | $message_type_options, |
| 295 | 295 | array( |
| 296 | 296 | 'html_name' => 'ee_message_type_filter_by', |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
| 329 | 329 | $context_options |
| 330 | 330 | ); |
| 331 | - $input = new EE_Select_Input( |
|
| 331 | + $input = new EE_Select_Input( |
|
| 332 | 332 | $context_options, |
| 333 | 333 | array( |
| 334 | 334 | 'html_name' => 'ee_context_filter_by', |
@@ -710,53 +710,53 @@ discard block |
||
| 710 | 710 | |
| 711 | 711 | public function messages_help_tab() |
| 712 | 712 | { |
| 713 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 713 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php'); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | |
| 717 | 717 | public function messengers_help_tab() |
| 718 | 718 | { |
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php'); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
| 723 | 723 | public function message_types_help_tab() |
| 724 | 724 | { |
| 725 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 725 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php'); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | |
| 729 | 729 | public function messages_overview_help_tab() |
| 730 | 730 | { |
| 731 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 731 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | |
| 735 | 735 | public function message_templates_help_tab() |
| 736 | 736 | { |
| 737 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 737 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php'); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | |
| 741 | 741 | public function edit_message_template_help_tab() |
| 742 | 742 | { |
| 743 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 743 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="' |
|
| 744 | 744 | . esc_attr__('Editor Title', 'event_espresso') |
| 745 | 745 | . '" />'; |
| 746 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 746 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="' |
|
| 747 | 747 | . esc_attr__('Context Switcher and Preview', 'event_espresso') |
| 748 | 748 | . '" />'; |
| 749 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 749 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="' |
|
| 750 | 750 | . esc_attr__('Message Template Form Fields', 'event_espresso') |
| 751 | 751 | . '" />'; |
| 752 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 752 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="' |
|
| 753 | 753 | . esc_attr__('Shortcodes Metabox', 'event_espresso') |
| 754 | 754 | . '" />'; |
| 755 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 755 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="' |
|
| 756 | 756 | . esc_attr__('Publish Metabox', 'event_espresso') |
| 757 | 757 | . '" />'; |
| 758 | 758 | EEH_Template::display_template( |
| 759 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 759 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 760 | 760 | $args |
| 761 | 761 | ); |
| 762 | 762 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | $this->_set_shortcodes(); |
| 768 | 768 | $args['shortcodes'] = $this->_shortcodes; |
| 769 | 769 | EEH_Template::display_template( |
| 770 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 770 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 771 | 771 | $args |
| 772 | 772 | ); |
| 773 | 773 | } |
@@ -775,16 +775,16 @@ discard block |
||
| 775 | 775 | |
| 776 | 776 | public function preview_message_help_tab() |
| 777 | 777 | { |
| 778 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 778 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php'); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
| 782 | 782 | public function settings_help_tab() |
| 783 | 783 | { |
| 784 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 785 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 786 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 787 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 784 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png' |
|
| 785 | + . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'; |
|
| 786 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
| 787 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'; |
|
| 788 | 788 | $args['img3'] = '<div class="switch">' |
| 789 | 789 | . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
| 790 | 790 | . ' type="checkbox" checked="checked">' |
@@ -795,18 +795,18 @@ discard block |
||
| 795 | 795 | . ' type="checkbox">' |
| 796 | 796 | . '<label for="ee-on-off-toggle-on"></label>' |
| 797 | 797 | . '</div>'; |
| 798 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 798 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | |
| 802 | 802 | public function load_scripts_styles() |
| 803 | 803 | { |
| 804 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 804 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 805 | 805 | wp_enqueue_style('espresso_ee_msg'); |
| 806 | 806 | |
| 807 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 807 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js', |
|
| 808 | 808 | array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
| 809 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 809 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js', |
|
| 810 | 810 | array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
| 811 | 811 | } |
| 812 | 812 | |
@@ -838,7 +838,7 @@ discard block |
||
| 838 | 838 | |
| 839 | 839 | $this->_set_shortcodes(); |
| 840 | 840 | |
| 841 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 841 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 842 | 842 | esc_html__( |
| 843 | 843 | 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
| 844 | 844 | 'event_espresso' |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | |
| 854 | 854 | wp_register_script( |
| 855 | 855 | 'ee_msgs_edit_js', |
| 856 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 856 | + EE_MSG_ASSETS_URL.'ee_message_editor.js', |
|
| 857 | 857 | array('jquery'), |
| 858 | 858 | EVENT_ESPRESSO_VERSION |
| 859 | 859 | ); |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | { |
| 897 | 897 | wp_register_style( |
| 898 | 898 | 'ee-message-settings', |
| 899 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 899 | + EE_MSG_ASSETS_URL.'ee_message_settings.css', |
|
| 900 | 900 | array(), |
| 901 | 901 | EVENT_ESPRESSO_VERSION |
| 902 | 902 | ); |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | } |
| 983 | 983 | $status_bulk_actions = $common_bulk_actions; |
| 984 | 984 | //unset bulk actions not applying to status |
| 985 | - if (! empty($status_bulk_actions)) { |
|
| 985 | + if ( ! empty($status_bulk_actions)) { |
|
| 986 | 986 | switch ($status) { |
| 987 | 987 | case EEM_Message::status_idle: |
| 988 | 988 | case EEM_Message::status_resend: |
@@ -1007,7 +1007,7 @@ discard block |
||
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | //skip adding messenger executing status to views because it will be included with the Failed view. |
| 1010 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1010 | + if ($status === EEM_Message::status_messenger_executing) { |
|
| 1011 | 1011 | continue; |
| 1012 | 1012 | } |
| 1013 | 1013 | |
@@ -1059,37 +1059,37 @@ discard block |
||
| 1059 | 1059 | /** @type array $status_items status legend setup */ |
| 1060 | 1060 | $status_items = array( |
| 1061 | 1061 | 'sent_status' => array( |
| 1062 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1062 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent, |
|
| 1063 | 1063 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
| 1064 | 1064 | ), |
| 1065 | 1065 | 'idle_status' => array( |
| 1066 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1066 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle, |
|
| 1067 | 1067 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
| 1068 | 1068 | ), |
| 1069 | 1069 | 'failed_status' => array( |
| 1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1070 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed, |
|
| 1071 | 1071 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
| 1072 | 1072 | ), |
| 1073 | 1073 | 'messenger_executing_status' => array( |
| 1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1074 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing, |
|
| 1075 | 1075 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
| 1076 | 1076 | ), |
| 1077 | 1077 | 'resend_status' => array( |
| 1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1078 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend, |
|
| 1079 | 1079 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
| 1080 | 1080 | ), |
| 1081 | 1081 | 'incomplete_status' => array( |
| 1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1082 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete, |
|
| 1083 | 1083 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
| 1084 | 1084 | ), |
| 1085 | 1085 | 'retry_status' => array( |
| 1086 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1086 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry, |
|
| 1087 | 1087 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
| 1088 | 1088 | ) |
| 1089 | 1089 | ); |
| 1090 | 1090 | if (EEM_Message::debug()) { |
| 1091 | 1091 | $status_items['debug_only_status'] = array( |
| 1092 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1092 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only, |
|
| 1093 | 1093 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
| 1094 | 1094 | ); |
| 1095 | 1095 | } |
@@ -1101,8 +1101,8 @@ discard block |
||
| 1101 | 1101 | protected function _custom_mtps_preview() |
| 1102 | 1102 | { |
| 1103 | 1103 | $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
| 1104 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1105 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1104 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"' |
|
| 1105 | + . ' alt="'.esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso').'" />'; |
|
| 1106 | 1106 | $this->_template_args['preview_text'] = '<strong>' |
| 1107 | 1107 | . esc_html__( |
| 1108 | 1108 | 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
@@ -1384,7 +1384,7 @@ discard block |
||
| 1384 | 1384 | //let's verify if we need this extra field via the shortcodes parameter. |
| 1385 | 1385 | $continue = false; |
| 1386 | 1386 | if (isset($extra_array['shortcodes_required'])) { |
| 1387 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1387 | + foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { |
|
| 1388 | 1388 | if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
| 1389 | 1389 | $continue = true; |
| 1390 | 1390 | } |
@@ -1394,7 +1394,7 @@ discard block |
||
| 1394 | 1394 | } |
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | - $field_id = $reference_field |
|
| 1397 | + $field_id = $reference_field |
|
| 1398 | 1398 | . '-' |
| 1399 | 1399 | . $extra_field |
| 1400 | 1400 | . '-content'; |
@@ -1402,8 +1402,8 @@ discard block |
||
| 1402 | 1402 | $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
| 1403 | 1403 | . $reference_field |
| 1404 | 1404 | . '][content][' |
| 1405 | - . $extra_field . ']'; |
|
| 1406 | - $css_class = isset($extra_array['css_class']) |
|
| 1405 | + . $extra_field.']'; |
|
| 1406 | + $css_class = isset($extra_array['css_class']) |
|
| 1407 | 1407 | ? $extra_array['css_class'] |
| 1408 | 1408 | : ''; |
| 1409 | 1409 | |
@@ -1414,7 +1414,7 @@ discard block |
||
| 1414 | 1414 | is_array($validators[$extra_field]) |
| 1415 | 1415 | && isset($validators[$extra_field]['msg']) |
| 1416 | 1416 | ) |
| 1417 | - ? 'validate-error ' . $css_class |
|
| 1417 | + ? 'validate-error '.$css_class |
|
| 1418 | 1418 | : $css_class; |
| 1419 | 1419 | |
| 1420 | 1420 | $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
@@ -1450,11 +1450,11 @@ discard block |
||
| 1450 | 1450 | |
| 1451 | 1451 | }/**/ |
| 1452 | 1452 | } |
| 1453 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1454 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1453 | + $templatefield_MTP_id = $reference_field.'-MTP_ID'; |
|
| 1454 | + $templatefield_templatename_id = $reference_field.'-name'; |
|
| 1455 | 1455 | |
| 1456 | 1456 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1457 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1457 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]', |
|
| 1458 | 1458 | 'label' => null, |
| 1459 | 1459 | 'input' => 'hidden', |
| 1460 | 1460 | 'type' => 'int', |
@@ -1467,7 +1467,7 @@ discard block |
||
| 1467 | 1467 | ); |
| 1468 | 1468 | |
| 1469 | 1469 | $template_form_fields[$templatefield_templatename_id] = array( |
| 1470 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1470 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]', |
|
| 1471 | 1471 | 'label' => null, |
| 1472 | 1472 | 'input' => 'hidden', |
| 1473 | 1473 | 'type' => 'string', |
@@ -1481,9 +1481,9 @@ discard block |
||
| 1481 | 1481 | } |
| 1482 | 1482 | continue; //skip the next stuff, we got the necessary fields here for this dataset. |
| 1483 | 1483 | } else { |
| 1484 | - $field_id = $template_field . '-content'; |
|
| 1484 | + $field_id = $template_field.'-content'; |
|
| 1485 | 1485 | $template_form_fields[$field_id] = $field_setup_array; |
| 1486 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1486 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$template_field.'][content]'; |
|
| 1487 | 1487 | $message_template = isset($message_templates[$context][$template_field]) |
| 1488 | 1488 | ? $message_templates[$context][$template_field] |
| 1489 | 1489 | : null; |
@@ -1506,7 +1506,7 @@ discard block |
||
| 1506 | 1506 | $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
| 1507 | 1507 | && in_array($template_field, $v_fields, true) |
| 1508 | 1508 | && isset($validators[$template_field]['msg']) |
| 1509 | - ? 'validate-error ' . $css_class |
|
| 1509 | + ? 'validate-error '.$css_class |
|
| 1510 | 1510 | : $css_class; |
| 1511 | 1511 | |
| 1512 | 1512 | //shortcode selector |
@@ -1517,12 +1517,12 @@ discard block |
||
| 1517 | 1517 | |
| 1518 | 1518 | //k took care of content field(s) now let's take care of others. |
| 1519 | 1519 | |
| 1520 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1521 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1520 | + $templatefield_MTP_id = $template_field.'-MTP_ID'; |
|
| 1521 | + $templatefield_field_templatename_id = $template_field.'-name'; |
|
| 1522 | 1522 | |
| 1523 | 1523 | //foreach template field there are actually two form fields created |
| 1524 | 1524 | $template_form_fields[$templatefield_MTP_id] = array( |
| 1525 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1525 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]', |
|
| 1526 | 1526 | 'label' => null, |
| 1527 | 1527 | 'input' => 'hidden', |
| 1528 | 1528 | 'type' => 'int', |
@@ -1535,7 +1535,7 @@ discard block |
||
| 1535 | 1535 | ); |
| 1536 | 1536 | |
| 1537 | 1537 | $template_form_fields[$templatefield_field_templatename_id] = array( |
| 1538 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1538 | + 'name' => 'MTP_template_fields['.$template_field.'][name]', |
|
| 1539 | 1539 | 'label' => null, |
| 1540 | 1540 | 'input' => 'hidden', |
| 1541 | 1541 | 'type' => 'string', |
@@ -1653,7 +1653,7 @@ discard block |
||
| 1653 | 1653 | 'format' => '%d', |
| 1654 | 1654 | 'db-col' => 'MTP_deleted' |
| 1655 | 1655 | ); |
| 1656 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1656 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1657 | 1657 | 'name' => 'MTP_user_id', |
| 1658 | 1658 | 'label' => esc_html__('Author', 'event_espresso'), |
| 1659 | 1659 | 'input' => 'hidden', |
@@ -1672,17 +1672,17 @@ discard block |
||
| 1672 | 1672 | 'value' => $action |
| 1673 | 1673 | ); |
| 1674 | 1674 | |
| 1675 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1675 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1676 | 1676 | 'name' => 'id', |
| 1677 | 1677 | 'input' => 'hidden', |
| 1678 | 1678 | 'type' => 'int', |
| 1679 | 1679 | 'value' => $GRP_ID |
| 1680 | 1680 | ); |
| 1681 | 1681 | $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
| 1682 | - 'name' => $action . '_nonce', |
|
| 1682 | + 'name' => $action.'_nonce', |
|
| 1683 | 1683 | 'input' => 'hidden', |
| 1684 | 1684 | 'type' => 'string', |
| 1685 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1685 | + 'value' => wp_create_nonce($action.'_nonce') |
|
| 1686 | 1686 | ); |
| 1687 | 1687 | |
| 1688 | 1688 | if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
@@ -1714,7 +1714,7 @@ discard block |
||
| 1714 | 1714 | ); |
| 1715 | 1715 | |
| 1716 | 1716 | //add preview button |
| 1717 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1717 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1718 | 1718 | array( |
| 1719 | 1719 | 'message_type' => $message_template_group->message_type(), |
| 1720 | 1720 | 'messenger' => $message_template_group->messenger(), |
@@ -1724,7 +1724,7 @@ discard block |
||
| 1724 | 1724 | ), |
| 1725 | 1725 | $this->_admin_base_url |
| 1726 | 1726 | ); |
| 1727 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1727 | + $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">' |
|
| 1728 | 1728 | . esc_html__('Preview', 'event_espresso') |
| 1729 | 1729 | . '</a>'; |
| 1730 | 1730 | |
@@ -1761,7 +1761,7 @@ discard block |
||
| 1761 | 1761 | |
| 1762 | 1762 | $this->_template_path = $this->_template_args['GRP_ID'] |
| 1763 | 1763 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
| 1764 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1764 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1765 | 1765 | |
| 1766 | 1766 | //send along EE_Message_Template_Group object for further template use. |
| 1767 | 1767 | $this->_template_args['MTP'] = $message_template_group; |
@@ -1816,7 +1816,7 @@ discard block |
||
| 1816 | 1816 | ) { |
| 1817 | 1817 | $template_args = array( |
| 1818 | 1818 | 'context' => $context, |
| 1819 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1819 | + 'nonce' => wp_create_nonce('activate_'.$context.'_toggle_nonce'), |
|
| 1820 | 1820 | 'is_active' => $message_template_group->is_context_active($context), |
| 1821 | 1821 | 'on_off_action' => $message_template_group->is_context_active($context) |
| 1822 | 1822 | ? 'context-off' |
@@ -1825,7 +1825,7 @@ discard block |
||
| 1825 | 1825 | 'message_template_group_id' => $message_template_group->ID() |
| 1826 | 1826 | ); |
| 1827 | 1827 | return EEH_Template::display_template( |
| 1828 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1828 | + EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php', |
|
| 1829 | 1829 | $template_args, |
| 1830 | 1830 | true |
| 1831 | 1831 | ); |
@@ -1845,7 +1845,7 @@ discard block |
||
| 1845 | 1845 | { |
| 1846 | 1846 | $success = true; |
| 1847 | 1847 | //check for required data |
| 1848 | - if (!isset( |
|
| 1848 | + if ( ! isset( |
|
| 1849 | 1849 | $this->_req_data['message_template_group_id'], |
| 1850 | 1850 | $this->_req_data['context'], |
| 1851 | 1851 | $this->_req_data['status'] |
@@ -1862,10 +1862,10 @@ discard block |
||
| 1862 | 1862 | $nonce = isset($this->_req_data['toggle_context_nonce']) |
| 1863 | 1863 | ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
| 1864 | 1864 | : ''; |
| 1865 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1865 | + $nonce_ref = 'activate_'.$this->_req_data['context'].'_toggle_nonce'; |
|
| 1866 | 1866 | $this->_verify_nonce($nonce, $nonce_ref); |
| 1867 | 1867 | $status = $this->_req_data['status']; |
| 1868 | - if ($status !== 'off' && $status !=='on') { |
|
| 1868 | + if ($status !== 'off' && $status !== 'on') { |
|
| 1869 | 1869 | EE_Error::add_error( |
| 1870 | 1870 | sprintf( |
| 1871 | 1871 | esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
@@ -1880,7 +1880,7 @@ discard block |
||
| 1880 | 1880 | $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
| 1881 | 1881 | $this->_req_data['message_template_group_id'] |
| 1882 | 1882 | ); |
| 1883 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1883 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1884 | 1884 | EE_Error::add_error( |
| 1885 | 1885 | sprintf( |
| 1886 | 1886 | esc_html__( |
@@ -2124,7 +2124,7 @@ discard block |
||
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | 2126 | //let's add a button to go back to the edit view |
| 2127 | - $query_args = array( |
|
| 2127 | + $query_args = array( |
|
| 2128 | 2128 | 'id' => $this->_req_data['GRP_ID'], |
| 2129 | 2129 | 'context' => $this->_req_data['context'], |
| 2130 | 2130 | 'action' => 'edit_message_template' |
@@ -2150,7 +2150,7 @@ discard block |
||
| 2150 | 2150 | ); |
| 2151 | 2151 | //setup display of preview. |
| 2152 | 2152 | $this->_admin_page_title = $preview_title; |
| 2153 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2153 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview); |
|
| 2154 | 2154 | $this->_template_args['data']['force_json'] = true; |
| 2155 | 2155 | |
| 2156 | 2156 | return ''; |
@@ -2256,7 +2256,7 @@ discard block |
||
| 2256 | 2256 | } |
| 2257 | 2257 | |
| 2258 | 2258 | //setup variation select values for the currently selected template. |
| 2259 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2259 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2260 | 2260 | $this->_message_template_group->messenger(), |
| 2261 | 2261 | $this->_message_template_group->message_type() |
| 2262 | 2262 | ); |
@@ -2270,12 +2270,12 @@ discard block |
||
| 2270 | 2270 | |
| 2271 | 2271 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
| 2272 | 2272 | |
| 2273 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2273 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2274 | 2274 | 'MTP_template_pack', |
| 2275 | 2275 | $tp_select_values, |
| 2276 | 2276 | $this->_message_template_group->get_template_pack_name() |
| 2277 | 2277 | ); |
| 2278 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2278 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2279 | 2279 | 'MTP_template_variation', |
| 2280 | 2280 | $variations_select_values, |
| 2281 | 2281 | $this->_message_template_group->get_template_pack_variation() |
@@ -2285,7 +2285,7 @@ discard block |
||
| 2285 | 2285 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
| 2286 | 2286 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
| 2287 | 2287 | |
| 2288 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2288 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php'; |
|
| 2289 | 2289 | |
| 2290 | 2290 | EEH_Template::display_template($template, $template_args); |
| 2291 | 2291 | } |
@@ -2314,14 +2314,14 @@ discard block |
||
| 2314 | 2314 | if ( ! empty($fields)) { |
| 2315 | 2315 | //yup there be fields |
| 2316 | 2316 | foreach ($fields as $field => $config) { |
| 2317 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2317 | + $field_id = $this->_message_template_group->messenger().'_'.$field; |
|
| 2318 | 2318 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
| 2319 | 2319 | $default = isset($config['default']) ? $config['default'] : ''; |
| 2320 | 2320 | $default = isset($config['value']) ? $config['value'] : $default; |
| 2321 | 2321 | |
| 2322 | 2322 | // if type is hidden and the value is empty |
| 2323 | 2323 | // something may have gone wrong so let's correct with the defaults |
| 2324 | - $fix = $config['input'] === 'hidden' |
|
| 2324 | + $fix = $config['input'] === 'hidden' |
|
| 2325 | 2325 | && isset($existing[$field]) |
| 2326 | 2326 | && empty($existing[$field]) |
| 2327 | 2327 | ? $default |
@@ -2331,7 +2331,7 @@ discard block |
||
| 2331 | 2331 | : $fix; |
| 2332 | 2332 | |
| 2333 | 2333 | $template_form_fields[$field_id] = array( |
| 2334 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2334 | + 'name' => 'test_settings_fld['.$field.']', |
|
| 2335 | 2335 | 'label' => $config['label'], |
| 2336 | 2336 | 'input' => $config['input'], |
| 2337 | 2337 | 'type' => $config['type'], |
@@ -2399,7 +2399,7 @@ discard block |
||
| 2399 | 2399 | ); |
| 2400 | 2400 | |
| 2401 | 2401 | return EEH_Template::display_template( |
| 2402 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2402 | + EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php', |
|
| 2403 | 2403 | $template_args, |
| 2404 | 2404 | true |
| 2405 | 2405 | ); |
@@ -2424,7 +2424,7 @@ discard block |
||
| 2424 | 2424 | //$messenger = $this->_message_template_group->messenger_obj(); |
| 2425 | 2425 | //now let's set the content depending on the status of the shortcodes array |
| 2426 | 2426 | if (empty($shortcodes)) { |
| 2427 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2427 | + $content = '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>'; |
|
| 2428 | 2428 | echo $content; |
| 2429 | 2429 | } else { |
| 2430 | 2430 | //$alt = 0; |
@@ -2561,7 +2561,7 @@ discard block |
||
| 2561 | 2561 | <?php |
| 2562 | 2562 | } |
| 2563 | 2563 | //setup nonce_url |
| 2564 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2564 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false); |
|
| 2565 | 2565 | ?> |
| 2566 | 2566 | <select name="context"> |
| 2567 | 2567 | <?php |
@@ -2662,7 +2662,7 @@ discard block |
||
| 2662 | 2662 | $context = ucwords(str_replace('_', ' ', $context_slug)); |
| 2663 | 2663 | |
| 2664 | 2664 | $item_desc = $messenger_label && $message_type_label |
| 2665 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2665 | + ? $messenger_label.' '.$message_type_label.' '.$context.' ' |
|
| 2666 | 2666 | : ''; |
| 2667 | 2667 | $item_desc .= 'Message Template'; |
| 2668 | 2668 | $query_args = array(); |
@@ -2764,7 +2764,7 @@ discard block |
||
| 2764 | 2764 | //default setup for it. |
| 2765 | 2765 | //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
| 2766 | 2766 | $updated = $MTP->insert($message_template_fields); |
| 2767 | - if (! $updated || is_wp_error($updated)) { |
|
| 2767 | + if ( ! $updated || is_wp_error($updated)) { |
|
| 2768 | 2768 | EE_Error::add_error( |
| 2769 | 2769 | sprintf( |
| 2770 | 2770 | esc_html__('%s field could not be updated.', 'event_espresso'), |
@@ -3125,7 +3125,7 @@ discard block |
||
| 3125 | 3125 | : 'email'; |
| 3126 | 3126 | |
| 3127 | 3127 | //let's setup the messenger tabs |
| 3128 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3128 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3129 | 3129 | $this->_m_mt_settings['messenger_tabs'], |
| 3130 | 3130 | 'messenger_links', |
| 3131 | 3131 | '|', |
@@ -3193,10 +3193,10 @@ discard block |
||
| 3193 | 3193 | |
| 3194 | 3194 | $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
| 3195 | 3195 | 'label' => ucwords($message_type->label['singular']), |
| 3196 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3197 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3198 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3199 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3196 | + 'class' => 'message-type-'.$a_or_i, |
|
| 3197 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name, |
|
| 3198 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'), |
|
| 3199 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings', |
|
| 3200 | 3200 | 'title' => $a_or_i === 'active' |
| 3201 | 3201 | ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
| 3202 | 3202 | : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
@@ -3232,9 +3232,9 @@ discard block |
||
| 3232 | 3232 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
| 3233 | 3233 | |
| 3234 | 3234 | foreach ($fields as $fldname => $fldprops) { |
| 3235 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3235 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname; |
|
| 3236 | 3236 | $template_form_field[$field_id] = array( |
| 3237 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3237 | + 'name' => 'message_type_settings['.$fldname.']', |
|
| 3238 | 3238 | 'label' => $fldprops['label'], |
| 3239 | 3239 | 'input' => $fldprops['field_type'], |
| 3240 | 3240 | 'type' => $fldprops['value_type'], |
@@ -3285,12 +3285,12 @@ discard block |
||
| 3285 | 3285 | $settings_template_args['hidden_fields'], |
| 3286 | 3286 | 'array' |
| 3287 | 3287 | ); |
| 3288 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3288 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3289 | 3289 | ? ' hidden' |
| 3290 | 3290 | : ''; |
| 3291 | 3291 | |
| 3292 | 3292 | |
| 3293 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3293 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php'; |
|
| 3294 | 3294 | $content = EEH_Template::display_template($template, $settings_template_args, true); |
| 3295 | 3295 | |
| 3296 | 3296 | return $content; |
@@ -3325,11 +3325,11 @@ discard block |
||
| 3325 | 3325 | ) |
| 3326 | 3326 | ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
| 3327 | 3327 | : ''; |
| 3328 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3328 | + $m_boxes[$messenger.'_a_box'] = sprintf( |
|
| 3329 | 3329 | esc_html__('%s Settings', 'event_espresso'), |
| 3330 | 3330 | $tab_array['label'] |
| 3331 | 3331 | ); |
| 3332 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3332 | + $m_template_args[$messenger.'_a_box'] = array( |
|
| 3333 | 3333 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 3334 | 3334 | 'inactive_message_types' => isset( |
| 3335 | 3335 | $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
@@ -3345,8 +3345,8 @@ discard block |
||
| 3345 | 3345 | // message type meta boxes |
| 3346 | 3346 | // (which is really just the inactive container for each messenger |
| 3347 | 3347 | // showing inactive message types for that messenger) |
| 3348 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3349 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3348 | + $mt_boxes[$messenger.'_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3349 | + $mt_template_args[$messenger.'_i_box'] = array( |
|
| 3350 | 3350 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
| 3351 | 3351 | 'inactive_message_types' => isset( |
| 3352 | 3352 | $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
@@ -3364,14 +3364,14 @@ discard block |
||
| 3364 | 3364 | |
| 3365 | 3365 | |
| 3366 | 3366 | //register messenger metaboxes |
| 3367 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3367 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3368 | 3368 | foreach ($m_boxes as $box => $label) { |
| 3369 | 3369 | $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
| 3370 | 3370 | $msgr = str_replace('_a_box', '', $box); |
| 3371 | 3371 | add_meta_box( |
| 3372 | - 'espresso_' . $msgr . '_settings', |
|
| 3372 | + 'espresso_'.$msgr.'_settings', |
|
| 3373 | 3373 | $label, |
| 3374 | - function ($post, $metabox) { |
|
| 3374 | + function($post, $metabox) { |
|
| 3375 | 3375 | echo EEH_Template::display_template( |
| 3376 | 3376 | $metabox["args"]["template_path"], |
| 3377 | 3377 | $metabox["args"]["template_args"], |
@@ -3386,17 +3386,17 @@ discard block |
||
| 3386 | 3386 | } |
| 3387 | 3387 | |
| 3388 | 3388 | //register message type metaboxes |
| 3389 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3389 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3390 | 3390 | foreach ($mt_boxes as $box => $label) { |
| 3391 | 3391 | $callback_args = array( |
| 3392 | 3392 | 'template_path' => $mt_template_path, |
| 3393 | 3393 | 'template_args' => $mt_template_args[$box] |
| 3394 | 3394 | ); |
| 3395 | - $mt = str_replace('_i_box', '', $box); |
|
| 3395 | + $mt = str_replace('_i_box', '', $box); |
|
| 3396 | 3396 | add_meta_box( |
| 3397 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3397 | + 'espresso_'.$mt.'_inactive_mts', |
|
| 3398 | 3398 | $label, |
| 3399 | - function ($post, $metabox) { |
|
| 3399 | + function($post, $metabox) { |
|
| 3400 | 3400 | echo EEH_Template::display_template( |
| 3401 | 3401 | $metabox["args"]["template_path"], |
| 3402 | 3402 | $metabox["args"]["template_args"], |
@@ -3543,7 +3543,7 @@ discard block |
||
| 3543 | 3543 | if ($form->is_valid()) { |
| 3544 | 3544 | $valid_data = $form->valid_data(); |
| 3545 | 3545 | foreach ($valid_data as $property => $value) { |
| 3546 | - $setter = 'set_' . $property; |
|
| 3546 | + $setter = 'set_'.$property; |
|
| 3547 | 3547 | if (method_exists($network_config, $setter)) { |
| 3548 | 3548 | $network_config->{$setter}($value); |
| 3549 | 3549 | } else if ( |
@@ -3578,8 +3578,8 @@ discard block |
||
| 3578 | 3578 | */ |
| 3579 | 3579 | protected function _get_mt_tabs($tab_array) |
| 3580 | 3580 | { |
| 3581 | - $tab_array = (array)$tab_array; |
|
| 3582 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3581 | + $tab_array = (array) $tab_array; |
|
| 3582 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3583 | 3583 | $tabs = ''; |
| 3584 | 3584 | |
| 3585 | 3585 | foreach ($tab_array as $tab) { |
@@ -3612,9 +3612,9 @@ discard block |
||
| 3612 | 3612 | $existing_settings = $messenger->get_existing_admin_settings(); |
| 3613 | 3613 | |
| 3614 | 3614 | foreach ($fields as $fldname => $fldprops) { |
| 3615 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3615 | + $field_id = $messenger->name.'-'.$fldname; |
|
| 3616 | 3616 | $template_form_field[$field_id] = array( |
| 3617 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3617 | + 'name' => 'messenger_settings['.$field_id.']', |
|
| 3618 | 3618 | 'label' => $fldprops['label'], |
| 3619 | 3619 | 'input' => $fldprops['field_type'], |
| 3620 | 3620 | 'type' => $fldprops['value_type'], |
@@ -3649,7 +3649,7 @@ discard block |
||
| 3649 | 3649 | //make sure any active message types that are existing are included in the hidden fields |
| 3650 | 3650 | if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
| 3651 | 3651 | foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
| 3652 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3652 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array( |
|
| 3653 | 3653 | 'type' => 'hidden', |
| 3654 | 3654 | 'value' => $mt |
| 3655 | 3655 | ); |
@@ -3678,9 +3678,9 @@ discard block |
||
| 3678 | 3678 | |
| 3679 | 3679 | |
| 3680 | 3680 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
| 3681 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3681 | + $settings_template_args['nonce'] = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); |
|
| 3682 | 3682 | $settings_template_args['on_off_status'] = $active ? true : false; |
| 3683 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3683 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php'; |
|
| 3684 | 3684 | $content = EEH_Template::display_template( |
| 3685 | 3685 | $template, |
| 3686 | 3686 | $settings_template_args, |
@@ -3720,7 +3720,7 @@ discard block |
||
| 3720 | 3720 | $nonce = isset($this->_req_data['activate_nonce']) |
| 3721 | 3721 | ? sanitize_text_field($this->_req_data['activate_nonce']) |
| 3722 | 3722 | : ''; |
| 3723 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3723 | + $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce'; |
|
| 3724 | 3724 | |
| 3725 | 3725 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3726 | 3726 | |
@@ -3836,7 +3836,7 @@ discard block |
||
| 3836 | 3836 | |
| 3837 | 3837 | //do a nonce check here since we're not arriving via a normal route |
| 3838 | 3838 | $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
| 3839 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3839 | + $nonce_ref = $this->_req_data['message_type'].'_nonce'; |
|
| 3840 | 3840 | |
| 3841 | 3841 | $this->_verify_nonce($nonce, $nonce_ref); |
| 3842 | 3842 | |
@@ -4197,7 +4197,7 @@ discard block |
||
| 4197 | 4197 | $message_type = $message_types[$this->_req_data['message_type']]; |
| 4198 | 4198 | $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
| 4199 | 4199 | |
| 4200 | - $content = $this->_message_type_settings_content( |
|
| 4200 | + $content = $this->_message_type_settings_content( |
|
| 4201 | 4201 | $message_type, |
| 4202 | 4202 | $messenger, |
| 4203 | 4203 | true |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('NO direct script access allowed'); |
|
| 8 | + exit('NO direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /** |
@@ -23,2557 +23,2557 @@ discard block |
||
| 23 | 23 | class Messages_Admin_Page extends EE_Admin_Page |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | - */ |
|
| 29 | - protected $_message_resource_manager; |
|
| 26 | + /** |
|
| 27 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 28 | + */ |
|
| 29 | + protected $_message_resource_manager; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @type string $_active_message_type_name |
|
| 33 | - */ |
|
| 34 | - protected $_active_message_type_name = ''; |
|
| 31 | + /** |
|
| 32 | + * @type string $_active_message_type_name |
|
| 33 | + */ |
|
| 34 | + protected $_active_message_type_name = ''; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @type EE_messenger $_active_messenger |
|
| 38 | - */ |
|
| 39 | - protected $_active_messenger; |
|
| 40 | - protected $_activate_state; |
|
| 41 | - protected $_activate_meta_box_type; |
|
| 42 | - protected $_current_message_meta_box; |
|
| 43 | - protected $_current_message_meta_box_object; |
|
| 44 | - protected $_context_switcher; |
|
| 45 | - protected $_shortcodes = array(); |
|
| 46 | - protected $_active_messengers = array(); |
|
| 47 | - protected $_active_message_types = array(); |
|
| 36 | + /** |
|
| 37 | + * @type EE_messenger $_active_messenger |
|
| 38 | + */ |
|
| 39 | + protected $_active_messenger; |
|
| 40 | + protected $_activate_state; |
|
| 41 | + protected $_activate_meta_box_type; |
|
| 42 | + protected $_current_message_meta_box; |
|
| 43 | + protected $_current_message_meta_box_object; |
|
| 44 | + protected $_context_switcher; |
|
| 45 | + protected $_shortcodes = array(); |
|
| 46 | + protected $_active_messengers = array(); |
|
| 47 | + protected $_active_message_types = array(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | - */ |
|
| 52 | - protected $_message_template_group; |
|
| 53 | - protected $_m_mt_settings = array(); |
|
| 49 | + /** |
|
| 50 | + * @var EE_Message_Template_Group $_message_template_group |
|
| 51 | + */ |
|
| 52 | + protected $_message_template_group; |
|
| 53 | + protected $_m_mt_settings = array(); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | - * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | - * |
|
| 60 | - * @since 4.5.0 |
|
| 61 | - * |
|
| 62 | - * @var EE_Messages_Template_Pack |
|
| 63 | - */ |
|
| 64 | - protected $_template_pack; |
|
| 56 | + /** |
|
| 57 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is. |
|
| 58 | + * IF there is no group then it gets automatically set to the Default template pack. |
|
| 59 | + * |
|
| 60 | + * @since 4.5.0 |
|
| 61 | + * |
|
| 62 | + * @var EE_Messages_Template_Pack |
|
| 63 | + */ |
|
| 64 | + protected $_template_pack; |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | - * group is. If there is no group then it automatically gets set to default. |
|
| 70 | - * |
|
| 71 | - * @since 4.5.0 |
|
| 72 | - * |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - protected $_variation; |
|
| 67 | + /** |
|
| 68 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the |
|
| 69 | + * group is. If there is no group then it automatically gets set to default. |
|
| 70 | + * |
|
| 71 | + * @since 4.5.0 |
|
| 72 | + * |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + protected $_variation; |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param bool $routing |
|
| 80 | - */ |
|
| 81 | - public function __construct($routing = true) |
|
| 82 | - { |
|
| 83 | - //make sure messages autoloader is running |
|
| 84 | - EED_Messages::set_autoloaders(); |
|
| 85 | - parent::__construct($routing); |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * @param bool $routing |
|
| 80 | + */ |
|
| 81 | + public function __construct($routing = true) |
|
| 82 | + { |
|
| 83 | + //make sure messages autoloader is running |
|
| 84 | + EED_Messages::set_autoloaders(); |
|
| 85 | + parent::__construct($routing); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - protected function _init_page_props() |
|
| 90 | - { |
|
| 91 | - $this->page_slug = EE_MSG_PG_SLUG; |
|
| 92 | - $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 93 | - $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 94 | - $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 95 | - |
|
| 96 | - $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 97 | - |
|
| 98 | - $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 99 | - $this->_load_message_resource_manager(); |
|
| 100 | - } |
|
| 89 | + protected function _init_page_props() |
|
| 90 | + { |
|
| 91 | + $this->page_slug = EE_MSG_PG_SLUG; |
|
| 92 | + $this->page_label = esc_html__('Messages Settings', 'event_espresso'); |
|
| 93 | + $this->_admin_base_url = EE_MSG_ADMIN_URL; |
|
| 94 | + $this->_admin_base_path = EE_MSG_ADMIN; |
|
| 95 | + |
|
| 96 | + $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array(); |
|
| 97 | + |
|
| 98 | + $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null; |
|
| 99 | + $this->_load_message_resource_manager(); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 105 | - * |
|
| 106 | - * @throws EE_Error |
|
| 107 | - * @throws InvalidDataTypeException |
|
| 108 | - * @throws InvalidInterfaceException |
|
| 109 | - * @throws InvalidArgumentException |
|
| 110 | - * @throws ReflectionException |
|
| 111 | - */ |
|
| 112 | - protected function _load_message_resource_manager() |
|
| 113 | - { |
|
| 114 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 115 | - } |
|
| 103 | + /** |
|
| 104 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods) |
|
| 105 | + * |
|
| 106 | + * @throws EE_Error |
|
| 107 | + * @throws InvalidDataTypeException |
|
| 108 | + * @throws InvalidInterfaceException |
|
| 109 | + * @throws InvalidArgumentException |
|
| 110 | + * @throws ReflectionException |
|
| 111 | + */ |
|
| 112 | + protected function _load_message_resource_manager() |
|
| 113 | + { |
|
| 114 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @deprecated 4.9.9.rc.014 |
|
| 120 | - * @return array |
|
| 121 | - * @throws EE_Error |
|
| 122 | - * @throws InvalidArgumentException |
|
| 123 | - * @throws InvalidDataTypeException |
|
| 124 | - * @throws InvalidInterfaceException |
|
| 125 | - */ |
|
| 126 | - public function get_messengers_for_list_table() |
|
| 127 | - { |
|
| 128 | - EE_Error::doing_it_wrong( |
|
| 129 | - __METHOD__, |
|
| 130 | - sprintf( |
|
| 131 | - esc_html__( |
|
| 132 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 133 | - 'event_espresso' |
|
| 134 | - ), |
|
| 135 | - 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 136 | - ), |
|
| 137 | - '4.9.9.rc.014' |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - $m_values = array(); |
|
| 141 | - $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 142 | - //setup messengers for selects |
|
| 143 | - $i = 1; |
|
| 144 | - foreach ($active_messengers as $active_messenger) { |
|
| 145 | - if ($active_messenger instanceof EE_Message) { |
|
| 146 | - $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 147 | - $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 148 | - $i++; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $m_values; |
|
| 153 | - } |
|
| 118 | + /** |
|
| 119 | + * @deprecated 4.9.9.rc.014 |
|
| 120 | + * @return array |
|
| 121 | + * @throws EE_Error |
|
| 122 | + * @throws InvalidArgumentException |
|
| 123 | + * @throws InvalidDataTypeException |
|
| 124 | + * @throws InvalidInterfaceException |
|
| 125 | + */ |
|
| 126 | + public function get_messengers_for_list_table() |
|
| 127 | + { |
|
| 128 | + EE_Error::doing_it_wrong( |
|
| 129 | + __METHOD__, |
|
| 130 | + sprintf( |
|
| 131 | + esc_html__( |
|
| 132 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s', |
|
| 133 | + 'event_espresso' |
|
| 134 | + ), |
|
| 135 | + 'Messages_Admin_Page::get_messengers_select_input()' |
|
| 136 | + ), |
|
| 137 | + '4.9.9.rc.014' |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + $m_values = array(); |
|
| 141 | + $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
| 142 | + //setup messengers for selects |
|
| 143 | + $i = 1; |
|
| 144 | + foreach ($active_messengers as $active_messenger) { |
|
| 145 | + if ($active_messenger instanceof EE_Message) { |
|
| 146 | + $m_values[$i]['id'] = $active_messenger->messenger(); |
|
| 147 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label()); |
|
| 148 | + $i++; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $m_values; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @deprecated 4.9.9.rc.014 |
|
| 158 | - * @return array |
|
| 159 | - * @throws EE_Error |
|
| 160 | - * @throws InvalidArgumentException |
|
| 161 | - * @throws InvalidDataTypeException |
|
| 162 | - * @throws InvalidInterfaceException |
|
| 163 | - */ |
|
| 164 | - public function get_message_types_for_list_table() |
|
| 165 | - { |
|
| 166 | - EE_Error::doing_it_wrong( |
|
| 167 | - __METHOD__, |
|
| 168 | - sprintf( |
|
| 169 | - esc_html__( |
|
| 170 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 171 | - 'event_espresso' |
|
| 172 | - ), |
|
| 173 | - 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 174 | - ), |
|
| 175 | - '4.9.9.rc.014' |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - $mt_values = array(); |
|
| 179 | - $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 180 | - $i = 1; |
|
| 181 | - foreach ($active_messages as $active_message) { |
|
| 182 | - if ($active_message instanceof EE_Message) { |
|
| 183 | - $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 184 | - $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 185 | - $i++; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $mt_values; |
|
| 190 | - } |
|
| 156 | + /** |
|
| 157 | + * @deprecated 4.9.9.rc.014 |
|
| 158 | + * @return array |
|
| 159 | + * @throws EE_Error |
|
| 160 | + * @throws InvalidArgumentException |
|
| 161 | + * @throws InvalidDataTypeException |
|
| 162 | + * @throws InvalidInterfaceException |
|
| 163 | + */ |
|
| 164 | + public function get_message_types_for_list_table() |
|
| 165 | + { |
|
| 166 | + EE_Error::doing_it_wrong( |
|
| 167 | + __METHOD__, |
|
| 168 | + sprintf( |
|
| 169 | + esc_html__( |
|
| 170 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s', |
|
| 171 | + 'event_espresso' |
|
| 172 | + ), |
|
| 173 | + 'Messages_Admin_Page::get_message_types_select_input()' |
|
| 174 | + ), |
|
| 175 | + '4.9.9.rc.014' |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + $mt_values = array(); |
|
| 179 | + $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
| 180 | + $i = 1; |
|
| 181 | + foreach ($active_messages as $active_message) { |
|
| 182 | + if ($active_message instanceof EE_Message) { |
|
| 183 | + $mt_values[$i]['id'] = $active_message->message_type(); |
|
| 184 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label()); |
|
| 185 | + $i++; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $mt_values; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @deprecated 4.9.9.rc.014 |
|
| 195 | - * @return array |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @throws InvalidArgumentException |
|
| 198 | - * @throws InvalidDataTypeException |
|
| 199 | - * @throws InvalidInterfaceException |
|
| 200 | - */ |
|
| 201 | - public function get_contexts_for_message_types_for_list_table() |
|
| 202 | - { |
|
| 203 | - EE_Error::doing_it_wrong( |
|
| 204 | - __METHOD__, |
|
| 205 | - sprintf( |
|
| 206 | - esc_html__( |
|
| 207 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 208 | - 'event_espresso' |
|
| 209 | - ), |
|
| 210 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 211 | - ), |
|
| 212 | - '4.9.9.rc.014' |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - $contexts = array(); |
|
| 216 | - $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 217 | - foreach ($active_message_contexts as $active_message) { |
|
| 218 | - if ($active_message instanceof EE_Message) { |
|
| 219 | - $message_type = $active_message->message_type_object(); |
|
| 220 | - if ($message_type instanceof EE_message_type) { |
|
| 221 | - $message_type_contexts = $message_type->get_contexts(); |
|
| 222 | - foreach ($message_type_contexts as $context => $context_details) { |
|
| 223 | - $contexts[$context] = $context_details['label']; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $contexts; |
|
| 230 | - } |
|
| 193 | + /** |
|
| 194 | + * @deprecated 4.9.9.rc.014 |
|
| 195 | + * @return array |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @throws InvalidArgumentException |
|
| 198 | + * @throws InvalidDataTypeException |
|
| 199 | + * @throws InvalidInterfaceException |
|
| 200 | + */ |
|
| 201 | + public function get_contexts_for_message_types_for_list_table() |
|
| 202 | + { |
|
| 203 | + EE_Error::doing_it_wrong( |
|
| 204 | + __METHOD__, |
|
| 205 | + sprintf( |
|
| 206 | + esc_html__( |
|
| 207 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s', |
|
| 208 | + 'event_espresso' |
|
| 209 | + ), |
|
| 210 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()' |
|
| 211 | + ), |
|
| 212 | + '4.9.9.rc.014' |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + $contexts = array(); |
|
| 216 | + $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
| 217 | + foreach ($active_message_contexts as $active_message) { |
|
| 218 | + if ($active_message instanceof EE_Message) { |
|
| 219 | + $message_type = $active_message->message_type_object(); |
|
| 220 | + if ($message_type instanceof EE_message_type) { |
|
| 221 | + $message_type_contexts = $message_type->get_contexts(); |
|
| 222 | + foreach ($message_type_contexts as $context => $context_details) { |
|
| 223 | + $contexts[$context] = $context_details['label']; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $contexts; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Generate select input with provided messenger options array. |
|
| 235 | - * |
|
| 236 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 237 | - * labels. |
|
| 238 | - * @return string |
|
| 239 | - * @throws EE_Error |
|
| 240 | - */ |
|
| 241 | - public function get_messengers_select_input($messenger_options) |
|
| 242 | - { |
|
| 243 | - //if empty or just one value then just return an empty string |
|
| 244 | - if (empty($messenger_options) |
|
| 245 | - || ! is_array($messenger_options) |
|
| 246 | - || count($messenger_options) === 1 |
|
| 247 | - ) { |
|
| 248 | - return ''; |
|
| 249 | - } |
|
| 250 | - //merge in default |
|
| 251 | - $messenger_options = array_merge( |
|
| 252 | - array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 253 | - $messenger_options |
|
| 254 | - ); |
|
| 255 | - $input = new EE_Select_Input( |
|
| 256 | - $messenger_options, |
|
| 257 | - array( |
|
| 258 | - 'html_name' => 'ee_messenger_filter_by', |
|
| 259 | - 'html_id' => 'ee_messenger_filter_by', |
|
| 260 | - 'html_class' => 'wide', |
|
| 261 | - 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 262 | - ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | - : 'none_selected' |
|
| 264 | - ) |
|
| 265 | - ); |
|
| 266 | - |
|
| 267 | - return $input->get_html_for_input(); |
|
| 268 | - } |
|
| 233 | + /** |
|
| 234 | + * Generate select input with provided messenger options array. |
|
| 235 | + * |
|
| 236 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger |
|
| 237 | + * labels. |
|
| 238 | + * @return string |
|
| 239 | + * @throws EE_Error |
|
| 240 | + */ |
|
| 241 | + public function get_messengers_select_input($messenger_options) |
|
| 242 | + { |
|
| 243 | + //if empty or just one value then just return an empty string |
|
| 244 | + if (empty($messenger_options) |
|
| 245 | + || ! is_array($messenger_options) |
|
| 246 | + || count($messenger_options) === 1 |
|
| 247 | + ) { |
|
| 248 | + return ''; |
|
| 249 | + } |
|
| 250 | + //merge in default |
|
| 251 | + $messenger_options = array_merge( |
|
| 252 | + array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')), |
|
| 253 | + $messenger_options |
|
| 254 | + ); |
|
| 255 | + $input = new EE_Select_Input( |
|
| 256 | + $messenger_options, |
|
| 257 | + array( |
|
| 258 | + 'html_name' => 'ee_messenger_filter_by', |
|
| 259 | + 'html_id' => 'ee_messenger_filter_by', |
|
| 260 | + 'html_class' => 'wide', |
|
| 261 | + 'default' => isset($this->_req_data['ee_messenger_filter_by']) |
|
| 262 | + ? sanitize_title($this->_req_data['ee_messenger_filter_by']) |
|
| 263 | + : 'none_selected' |
|
| 264 | + ) |
|
| 265 | + ); |
|
| 266 | + |
|
| 267 | + return $input->get_html_for_input(); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Generate select input with provided message type options array. |
|
| 273 | - * |
|
| 274 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 275 | - * message type labels |
|
| 276 | - * @return string |
|
| 277 | - * @throws EE_Error |
|
| 278 | - */ |
|
| 279 | - public function get_message_types_select_input($message_type_options) |
|
| 280 | - { |
|
| 281 | - //if empty or count of options is 1 then just return an empty string |
|
| 282 | - if (empty($message_type_options) |
|
| 283 | - || ! is_array($message_type_options) |
|
| 284 | - || count($message_type_options) === 1 |
|
| 285 | - ) { |
|
| 286 | - return ''; |
|
| 287 | - } |
|
| 288 | - //merge in default |
|
| 289 | - $message_type_options = array_merge( |
|
| 290 | - array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 291 | - $message_type_options |
|
| 292 | - ); |
|
| 293 | - $input = new EE_Select_Input( |
|
| 294 | - $message_type_options, |
|
| 295 | - array( |
|
| 296 | - 'html_name' => 'ee_message_type_filter_by', |
|
| 297 | - 'html_id' => 'ee_message_type_filter_by', |
|
| 298 | - 'html_class' => 'wide', |
|
| 299 | - 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 300 | - ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | - : 'none_selected', |
|
| 302 | - ) |
|
| 303 | - ); |
|
| 304 | - |
|
| 305 | - return $input->get_html_for_input(); |
|
| 306 | - } |
|
| 271 | + /** |
|
| 272 | + * Generate select input with provided message type options array. |
|
| 273 | + * |
|
| 274 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the |
|
| 275 | + * message type labels |
|
| 276 | + * @return string |
|
| 277 | + * @throws EE_Error |
|
| 278 | + */ |
|
| 279 | + public function get_message_types_select_input($message_type_options) |
|
| 280 | + { |
|
| 281 | + //if empty or count of options is 1 then just return an empty string |
|
| 282 | + if (empty($message_type_options) |
|
| 283 | + || ! is_array($message_type_options) |
|
| 284 | + || count($message_type_options) === 1 |
|
| 285 | + ) { |
|
| 286 | + return ''; |
|
| 287 | + } |
|
| 288 | + //merge in default |
|
| 289 | + $message_type_options = array_merge( |
|
| 290 | + array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')), |
|
| 291 | + $message_type_options |
|
| 292 | + ); |
|
| 293 | + $input = new EE_Select_Input( |
|
| 294 | + $message_type_options, |
|
| 295 | + array( |
|
| 296 | + 'html_name' => 'ee_message_type_filter_by', |
|
| 297 | + 'html_id' => 'ee_message_type_filter_by', |
|
| 298 | + 'html_class' => 'wide', |
|
| 299 | + 'default' => isset($this->_req_data['ee_message_type_filter_by']) |
|
| 300 | + ? sanitize_title($this->_req_data['ee_message_type_filter_by']) |
|
| 301 | + : 'none_selected', |
|
| 302 | + ) |
|
| 303 | + ); |
|
| 304 | + |
|
| 305 | + return $input->get_html_for_input(); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Generate select input with provide message type contexts array. |
|
| 311 | - * |
|
| 312 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 313 | - * context label. |
|
| 314 | - * @return string |
|
| 315 | - * @throws EE_Error |
|
| 316 | - */ |
|
| 317 | - public function get_contexts_for_message_types_select_input($context_options) |
|
| 318 | - { |
|
| 319 | - //if empty or count of options is one then just return empty string |
|
| 320 | - if (empty($context_options) |
|
| 321 | - || ! is_array($context_options) |
|
| 322 | - || count($context_options) === 1 |
|
| 323 | - ) { |
|
| 324 | - return ''; |
|
| 325 | - } |
|
| 326 | - //merge in default |
|
| 327 | - $context_options = array_merge( |
|
| 328 | - array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 329 | - $context_options |
|
| 330 | - ); |
|
| 331 | - $input = new EE_Select_Input( |
|
| 332 | - $context_options, |
|
| 333 | - array( |
|
| 334 | - 'html_name' => 'ee_context_filter_by', |
|
| 335 | - 'html_id' => 'ee_context_filter_by', |
|
| 336 | - 'html_class' => 'wide', |
|
| 337 | - 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 338 | - ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 339 | - : 'none_selected', |
|
| 340 | - ) |
|
| 341 | - ); |
|
| 342 | - |
|
| 343 | - return $input->get_html_for_input(); |
|
| 344 | - } |
|
| 309 | + /** |
|
| 310 | + * Generate select input with provide message type contexts array. |
|
| 311 | + * |
|
| 312 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the |
|
| 313 | + * context label. |
|
| 314 | + * @return string |
|
| 315 | + * @throws EE_Error |
|
| 316 | + */ |
|
| 317 | + public function get_contexts_for_message_types_select_input($context_options) |
|
| 318 | + { |
|
| 319 | + //if empty or count of options is one then just return empty string |
|
| 320 | + if (empty($context_options) |
|
| 321 | + || ! is_array($context_options) |
|
| 322 | + || count($context_options) === 1 |
|
| 323 | + ) { |
|
| 324 | + return ''; |
|
| 325 | + } |
|
| 326 | + //merge in default |
|
| 327 | + $context_options = array_merge( |
|
| 328 | + array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')), |
|
| 329 | + $context_options |
|
| 330 | + ); |
|
| 331 | + $input = new EE_Select_Input( |
|
| 332 | + $context_options, |
|
| 333 | + array( |
|
| 334 | + 'html_name' => 'ee_context_filter_by', |
|
| 335 | + 'html_id' => 'ee_context_filter_by', |
|
| 336 | + 'html_class' => 'wide', |
|
| 337 | + 'default' => isset($this->_req_data['ee_context_filter_by']) |
|
| 338 | + ? sanitize_title($this->_req_data['ee_context_filter_by']) |
|
| 339 | + : 'none_selected', |
|
| 340 | + ) |
|
| 341 | + ); |
|
| 342 | + |
|
| 343 | + return $input->get_html_for_input(); |
|
| 344 | + } |
|
| 345 | 345 | |
| 346 | 346 | |
| 347 | - protected function _ajax_hooks() |
|
| 348 | - { |
|
| 349 | - add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 350 | - add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 351 | - add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 352 | - add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 353 | - add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 354 | - add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 355 | - } |
|
| 347 | + protected function _ajax_hooks() |
|
| 348 | + { |
|
| 349 | + add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle')); |
|
| 350 | + add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle')); |
|
| 351 | + add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings')); |
|
| 352 | + add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form')); |
|
| 353 | + add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack')); |
|
| 354 | + add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template')); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | |
| 358 | - protected function _define_page_props() |
|
| 359 | - { |
|
| 360 | - $this->_admin_page_title = $this->page_label; |
|
| 361 | - $this->_labels = array( |
|
| 362 | - 'buttons' => array( |
|
| 363 | - 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 364 | - 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 365 | - 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 366 | - ), |
|
| 367 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 368 | - ); |
|
| 369 | - } |
|
| 358 | + protected function _define_page_props() |
|
| 359 | + { |
|
| 360 | + $this->_admin_page_title = $this->page_label; |
|
| 361 | + $this->_labels = array( |
|
| 362 | + 'buttons' => array( |
|
| 363 | + 'add' => esc_html__('Add New Message Template', 'event_espresso'), |
|
| 364 | + 'edit' => esc_html__('Edit Message Template', 'event_espresso'), |
|
| 365 | + 'delete' => esc_html__('Delete Message Template', 'event_espresso') |
|
| 366 | + ), |
|
| 367 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 368 | + ); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | 371 | |
| 372 | - /** |
|
| 373 | - * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 374 | - * @access protected |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - protected function _set_page_routes() |
|
| 378 | - { |
|
| 379 | - $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 380 | - ? $this->_req_data['GRP_ID'] |
|
| 381 | - : 0; |
|
| 382 | - $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 383 | - ? $this->_req_data['id'] |
|
| 384 | - : $grp_id; |
|
| 385 | - $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 386 | - ? $this->_req_data['MSG_ID'] |
|
| 387 | - : 0; |
|
| 388 | - |
|
| 389 | - $this->_page_routes = array( |
|
| 390 | - 'default' => array( |
|
| 391 | - 'func' => '_message_queue_list_table', |
|
| 392 | - 'capability' => 'ee_read_global_messages' |
|
| 393 | - ), |
|
| 394 | - 'global_mtps' => array( |
|
| 395 | - 'func' => '_ee_default_messages_overview_list_table', |
|
| 396 | - 'capability' => 'ee_read_global_messages' |
|
| 397 | - ), |
|
| 398 | - 'custom_mtps' => array( |
|
| 399 | - 'func' => '_custom_mtps_preview', |
|
| 400 | - 'capability' => 'ee_read_messages' |
|
| 401 | - ), |
|
| 402 | - 'add_new_message_template' => array( |
|
| 403 | - 'func' => '_add_message_template', |
|
| 404 | - 'capability' => 'ee_edit_messages', |
|
| 405 | - 'noheader' => true |
|
| 406 | - ), |
|
| 407 | - 'edit_message_template' => array( |
|
| 408 | - 'func' => '_edit_message_template', |
|
| 409 | - 'capability' => 'ee_edit_message', |
|
| 410 | - 'obj_id' => $grp_id |
|
| 411 | - ), |
|
| 412 | - 'preview_message' => array( |
|
| 413 | - 'func' => '_preview_message', |
|
| 414 | - 'capability' => 'ee_read_message', |
|
| 415 | - 'obj_id' => $grp_id, |
|
| 416 | - 'noheader' => true, |
|
| 417 | - 'headers_sent_route' => 'display_preview_message' |
|
| 418 | - ), |
|
| 419 | - 'display_preview_message' => array( |
|
| 420 | - 'func' => '_display_preview_message', |
|
| 421 | - 'capability' => 'ee_read_message', |
|
| 422 | - 'obj_id' => $grp_id |
|
| 423 | - ), |
|
| 424 | - 'insert_message_template' => array( |
|
| 425 | - 'func' => '_insert_or_update_message_template', |
|
| 426 | - 'capability' => 'ee_edit_messages', |
|
| 427 | - 'args' => array('new_template' => true), |
|
| 428 | - 'noheader' => true |
|
| 429 | - ), |
|
| 430 | - 'update_message_template' => array( |
|
| 431 | - 'func' => '_insert_or_update_message_template', |
|
| 432 | - 'capability' => 'ee_edit_message', |
|
| 433 | - 'obj_id' => $grp_id, |
|
| 434 | - 'args' => array('new_template' => false), |
|
| 435 | - 'noheader' => true |
|
| 436 | - ), |
|
| 437 | - 'trash_message_template' => array( |
|
| 438 | - 'func' => '_trash_or_restore_message_template', |
|
| 439 | - 'capability' => 'ee_delete_message', |
|
| 440 | - 'obj_id' => $grp_id, |
|
| 441 | - 'args' => array('trash' => true, 'all' => true), |
|
| 442 | - 'noheader' => true |
|
| 443 | - ), |
|
| 444 | - 'trash_message_template_context' => array( |
|
| 445 | - 'func' => '_trash_or_restore_message_template', |
|
| 446 | - 'capability' => 'ee_delete_message', |
|
| 447 | - 'obj_id' => $grp_id, |
|
| 448 | - 'args' => array('trash' => true), |
|
| 449 | - 'noheader' => true |
|
| 450 | - ), |
|
| 451 | - 'restore_message_template' => array( |
|
| 452 | - 'func' => '_trash_or_restore_message_template', |
|
| 453 | - 'capability' => 'ee_delete_message', |
|
| 454 | - 'obj_id' => $grp_id, |
|
| 455 | - 'args' => array('trash' => false, 'all' => true), |
|
| 456 | - 'noheader' => true |
|
| 457 | - ), |
|
| 458 | - 'restore_message_template_context' => array( |
|
| 459 | - 'func' => '_trash_or_restore_message_template', |
|
| 460 | - 'capability' => 'ee_delete_message', |
|
| 461 | - 'obj_id' => $grp_id, |
|
| 462 | - 'args' => array('trash' => false), |
|
| 463 | - 'noheader' => true |
|
| 464 | - ), |
|
| 465 | - 'delete_message_template' => array( |
|
| 466 | - 'func' => '_delete_message_template', |
|
| 467 | - 'capability' => 'ee_delete_message', |
|
| 468 | - 'obj_id' => $grp_id, |
|
| 469 | - 'noheader' => true |
|
| 470 | - ), |
|
| 471 | - 'reset_to_default' => array( |
|
| 472 | - 'func' => '_reset_to_default_template', |
|
| 473 | - 'capability' => 'ee_edit_message', |
|
| 474 | - 'obj_id' => $grp_id, |
|
| 475 | - 'noheader' => true |
|
| 476 | - ), |
|
| 477 | - 'settings' => array( |
|
| 478 | - 'func' => '_settings', |
|
| 479 | - 'capability' => 'manage_options' |
|
| 480 | - ), |
|
| 481 | - 'update_global_settings' => array( |
|
| 482 | - 'func' => '_update_global_settings', |
|
| 483 | - 'capability' => 'manage_options', |
|
| 484 | - 'noheader' => true |
|
| 485 | - ), |
|
| 486 | - 'generate_now' => array( |
|
| 487 | - 'func' => '_generate_now', |
|
| 488 | - 'capability' => 'ee_send_message', |
|
| 489 | - 'noheader' => true |
|
| 490 | - ), |
|
| 491 | - 'generate_and_send_now' => array( |
|
| 492 | - 'func' => '_generate_and_send_now', |
|
| 493 | - 'capability' => 'ee_send_message', |
|
| 494 | - 'noheader' => true |
|
| 495 | - ), |
|
| 496 | - 'queue_for_resending' => array( |
|
| 497 | - 'func' => '_queue_for_resending', |
|
| 498 | - 'capability' => 'ee_send_message', |
|
| 499 | - 'noheader' => true |
|
| 500 | - ), |
|
| 501 | - 'send_now' => array( |
|
| 502 | - 'func' => '_send_now', |
|
| 503 | - 'capability' => 'ee_send_message', |
|
| 504 | - 'noheader' => true |
|
| 505 | - ), |
|
| 506 | - 'delete_ee_message' => array( |
|
| 507 | - 'func' => '_delete_ee_messages', |
|
| 508 | - 'capability' => 'ee_delete_messages', |
|
| 509 | - 'noheader' => true |
|
| 510 | - ), |
|
| 511 | - 'delete_ee_messages' => array( |
|
| 512 | - 'func' => '_delete_ee_messages', |
|
| 513 | - 'capability' => 'ee_delete_messages', |
|
| 514 | - 'noheader' => true, |
|
| 515 | - 'obj_id' => $msg_id |
|
| 516 | - ) |
|
| 517 | - ); |
|
| 518 | - } |
|
| 372 | + /** |
|
| 373 | + * an array for storing key => value pairs of request actions and their corresponding methods |
|
| 374 | + * @access protected |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + protected function _set_page_routes() |
|
| 378 | + { |
|
| 379 | + $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID']) |
|
| 380 | + ? $this->_req_data['GRP_ID'] |
|
| 381 | + : 0; |
|
| 382 | + $grp_id = empty($grp_id) && ! empty($this->_req_data['id']) |
|
| 383 | + ? $this->_req_data['id'] |
|
| 384 | + : $grp_id; |
|
| 385 | + $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID']) |
|
| 386 | + ? $this->_req_data['MSG_ID'] |
|
| 387 | + : 0; |
|
| 388 | + |
|
| 389 | + $this->_page_routes = array( |
|
| 390 | + 'default' => array( |
|
| 391 | + 'func' => '_message_queue_list_table', |
|
| 392 | + 'capability' => 'ee_read_global_messages' |
|
| 393 | + ), |
|
| 394 | + 'global_mtps' => array( |
|
| 395 | + 'func' => '_ee_default_messages_overview_list_table', |
|
| 396 | + 'capability' => 'ee_read_global_messages' |
|
| 397 | + ), |
|
| 398 | + 'custom_mtps' => array( |
|
| 399 | + 'func' => '_custom_mtps_preview', |
|
| 400 | + 'capability' => 'ee_read_messages' |
|
| 401 | + ), |
|
| 402 | + 'add_new_message_template' => array( |
|
| 403 | + 'func' => '_add_message_template', |
|
| 404 | + 'capability' => 'ee_edit_messages', |
|
| 405 | + 'noheader' => true |
|
| 406 | + ), |
|
| 407 | + 'edit_message_template' => array( |
|
| 408 | + 'func' => '_edit_message_template', |
|
| 409 | + 'capability' => 'ee_edit_message', |
|
| 410 | + 'obj_id' => $grp_id |
|
| 411 | + ), |
|
| 412 | + 'preview_message' => array( |
|
| 413 | + 'func' => '_preview_message', |
|
| 414 | + 'capability' => 'ee_read_message', |
|
| 415 | + 'obj_id' => $grp_id, |
|
| 416 | + 'noheader' => true, |
|
| 417 | + 'headers_sent_route' => 'display_preview_message' |
|
| 418 | + ), |
|
| 419 | + 'display_preview_message' => array( |
|
| 420 | + 'func' => '_display_preview_message', |
|
| 421 | + 'capability' => 'ee_read_message', |
|
| 422 | + 'obj_id' => $grp_id |
|
| 423 | + ), |
|
| 424 | + 'insert_message_template' => array( |
|
| 425 | + 'func' => '_insert_or_update_message_template', |
|
| 426 | + 'capability' => 'ee_edit_messages', |
|
| 427 | + 'args' => array('new_template' => true), |
|
| 428 | + 'noheader' => true |
|
| 429 | + ), |
|
| 430 | + 'update_message_template' => array( |
|
| 431 | + 'func' => '_insert_or_update_message_template', |
|
| 432 | + 'capability' => 'ee_edit_message', |
|
| 433 | + 'obj_id' => $grp_id, |
|
| 434 | + 'args' => array('new_template' => false), |
|
| 435 | + 'noheader' => true |
|
| 436 | + ), |
|
| 437 | + 'trash_message_template' => array( |
|
| 438 | + 'func' => '_trash_or_restore_message_template', |
|
| 439 | + 'capability' => 'ee_delete_message', |
|
| 440 | + 'obj_id' => $grp_id, |
|
| 441 | + 'args' => array('trash' => true, 'all' => true), |
|
| 442 | + 'noheader' => true |
|
| 443 | + ), |
|
| 444 | + 'trash_message_template_context' => array( |
|
| 445 | + 'func' => '_trash_or_restore_message_template', |
|
| 446 | + 'capability' => 'ee_delete_message', |
|
| 447 | + 'obj_id' => $grp_id, |
|
| 448 | + 'args' => array('trash' => true), |
|
| 449 | + 'noheader' => true |
|
| 450 | + ), |
|
| 451 | + 'restore_message_template' => array( |
|
| 452 | + 'func' => '_trash_or_restore_message_template', |
|
| 453 | + 'capability' => 'ee_delete_message', |
|
| 454 | + 'obj_id' => $grp_id, |
|
| 455 | + 'args' => array('trash' => false, 'all' => true), |
|
| 456 | + 'noheader' => true |
|
| 457 | + ), |
|
| 458 | + 'restore_message_template_context' => array( |
|
| 459 | + 'func' => '_trash_or_restore_message_template', |
|
| 460 | + 'capability' => 'ee_delete_message', |
|
| 461 | + 'obj_id' => $grp_id, |
|
| 462 | + 'args' => array('trash' => false), |
|
| 463 | + 'noheader' => true |
|
| 464 | + ), |
|
| 465 | + 'delete_message_template' => array( |
|
| 466 | + 'func' => '_delete_message_template', |
|
| 467 | + 'capability' => 'ee_delete_message', |
|
| 468 | + 'obj_id' => $grp_id, |
|
| 469 | + 'noheader' => true |
|
| 470 | + ), |
|
| 471 | + 'reset_to_default' => array( |
|
| 472 | + 'func' => '_reset_to_default_template', |
|
| 473 | + 'capability' => 'ee_edit_message', |
|
| 474 | + 'obj_id' => $grp_id, |
|
| 475 | + 'noheader' => true |
|
| 476 | + ), |
|
| 477 | + 'settings' => array( |
|
| 478 | + 'func' => '_settings', |
|
| 479 | + 'capability' => 'manage_options' |
|
| 480 | + ), |
|
| 481 | + 'update_global_settings' => array( |
|
| 482 | + 'func' => '_update_global_settings', |
|
| 483 | + 'capability' => 'manage_options', |
|
| 484 | + 'noheader' => true |
|
| 485 | + ), |
|
| 486 | + 'generate_now' => array( |
|
| 487 | + 'func' => '_generate_now', |
|
| 488 | + 'capability' => 'ee_send_message', |
|
| 489 | + 'noheader' => true |
|
| 490 | + ), |
|
| 491 | + 'generate_and_send_now' => array( |
|
| 492 | + 'func' => '_generate_and_send_now', |
|
| 493 | + 'capability' => 'ee_send_message', |
|
| 494 | + 'noheader' => true |
|
| 495 | + ), |
|
| 496 | + 'queue_for_resending' => array( |
|
| 497 | + 'func' => '_queue_for_resending', |
|
| 498 | + 'capability' => 'ee_send_message', |
|
| 499 | + 'noheader' => true |
|
| 500 | + ), |
|
| 501 | + 'send_now' => array( |
|
| 502 | + 'func' => '_send_now', |
|
| 503 | + 'capability' => 'ee_send_message', |
|
| 504 | + 'noheader' => true |
|
| 505 | + ), |
|
| 506 | + 'delete_ee_message' => array( |
|
| 507 | + 'func' => '_delete_ee_messages', |
|
| 508 | + 'capability' => 'ee_delete_messages', |
|
| 509 | + 'noheader' => true |
|
| 510 | + ), |
|
| 511 | + 'delete_ee_messages' => array( |
|
| 512 | + 'func' => '_delete_ee_messages', |
|
| 513 | + 'capability' => 'ee_delete_messages', |
|
| 514 | + 'noheader' => true, |
|
| 515 | + 'obj_id' => $msg_id |
|
| 516 | + ) |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | 520 | |
| 521 | - protected function _set_page_config() |
|
| 522 | - { |
|
| 523 | - $this->_page_config = array( |
|
| 524 | - 'default' => array( |
|
| 525 | - 'nav' => array( |
|
| 526 | - 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 527 | - 'order' => 10 |
|
| 528 | - ), |
|
| 529 | - 'list_table' => 'EE_Message_List_Table', |
|
| 530 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 531 | - 'require_nonce' => false |
|
| 532 | - ), |
|
| 533 | - 'global_mtps' => array( |
|
| 534 | - 'nav' => array( |
|
| 535 | - 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 536 | - 'order' => 20 |
|
| 537 | - ), |
|
| 538 | - 'list_table' => 'Messages_Template_List_Table', |
|
| 539 | - 'help_tabs' => array( |
|
| 540 | - 'messages_overview_help_tab' => array( |
|
| 541 | - 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 542 | - 'filename' => 'messages_overview' |
|
| 543 | - ), |
|
| 544 | - 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 545 | - 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 546 | - 'filename' => 'messages_overview_table_column_headings' |
|
| 547 | - ), |
|
| 548 | - 'messages_overview_messages_filters_help_tab' => array( |
|
| 549 | - 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 550 | - 'filename' => 'messages_overview_filters' |
|
| 551 | - ), |
|
| 552 | - 'messages_overview_messages_views_help_tab' => array( |
|
| 553 | - 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 554 | - 'filename' => 'messages_overview_views' |
|
| 555 | - ), |
|
| 556 | - 'message_overview_message_types_help_tab' => array( |
|
| 557 | - 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 558 | - 'filename' => 'messages_overview_types' |
|
| 559 | - ), |
|
| 560 | - 'messages_overview_messengers_help_tab' => array( |
|
| 561 | - 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 562 | - 'filename' => 'messages_overview_messengers', |
|
| 563 | - ), |
|
| 564 | - ), |
|
| 565 | - 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 566 | - 'require_nonce' => false |
|
| 567 | - ), |
|
| 568 | - 'custom_mtps' => array( |
|
| 569 | - 'nav' => array( |
|
| 570 | - 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 571 | - 'order' => 30 |
|
| 572 | - ), |
|
| 573 | - 'help_tabs' => array(), |
|
| 574 | - 'help_tour' => array(), |
|
| 575 | - 'require_nonce' => false |
|
| 576 | - ), |
|
| 577 | - 'add_new_message_template' => array( |
|
| 578 | - 'nav' => array( |
|
| 579 | - 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 580 | - 'order' => 5, |
|
| 581 | - 'persistent' => false |
|
| 582 | - ), |
|
| 583 | - 'require_nonce' => false |
|
| 584 | - ), |
|
| 585 | - 'edit_message_template' => array( |
|
| 586 | - 'labels' => array( |
|
| 587 | - 'buttons' => array( |
|
| 588 | - 'reset' => esc_html__('Reset Templates'), |
|
| 589 | - ), |
|
| 590 | - 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 591 | - ), |
|
| 592 | - 'nav' => array( |
|
| 593 | - 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 594 | - 'order' => 5, |
|
| 595 | - 'persistent' => false, |
|
| 596 | - 'url' => '' |
|
| 597 | - ), |
|
| 598 | - 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 599 | - 'has_metaboxes' => true, |
|
| 600 | - 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 601 | - 'help_tabs' => array( |
|
| 602 | - 'edit_message_template' => array( |
|
| 603 | - 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 604 | - 'callback' => 'edit_message_template_help_tab' |
|
| 605 | - ), |
|
| 606 | - 'message_templates_help_tab' => array( |
|
| 607 | - 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 608 | - 'filename' => 'messages_templates' |
|
| 609 | - ), |
|
| 610 | - 'message_template_shortcodes' => array( |
|
| 611 | - 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 612 | - 'callback' => 'message_template_shortcodes_help_tab' |
|
| 613 | - ), |
|
| 614 | - 'message_preview_help_tab' => array( |
|
| 615 | - 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 616 | - 'filename' => 'messages_preview' |
|
| 617 | - ), |
|
| 618 | - 'messages_overview_other_help_tab' => array( |
|
| 619 | - 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 620 | - 'filename' => 'messages_overview_other', |
|
| 621 | - ), |
|
| 622 | - ), |
|
| 623 | - 'require_nonce' => false |
|
| 624 | - ), |
|
| 625 | - 'display_preview_message' => array( |
|
| 626 | - 'nav' => array( |
|
| 627 | - 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 628 | - 'order' => 5, |
|
| 629 | - 'url' => '', |
|
| 630 | - 'persistent' => false |
|
| 631 | - ), |
|
| 632 | - 'help_tabs' => array( |
|
| 633 | - 'preview_message' => array( |
|
| 634 | - 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 635 | - 'callback' => 'preview_message_help_tab' |
|
| 636 | - ) |
|
| 637 | - ), |
|
| 638 | - 'require_nonce' => false |
|
| 639 | - ), |
|
| 640 | - 'settings' => array( |
|
| 641 | - 'nav' => array( |
|
| 642 | - 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 643 | - 'order' => 40 |
|
| 644 | - ), |
|
| 645 | - 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 646 | - 'help_tabs' => array( |
|
| 647 | - 'messages_settings_help_tab' => array( |
|
| 648 | - 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 649 | - 'filename' => 'messages_settings' |
|
| 650 | - ), |
|
| 651 | - 'messages_settings_message_types_help_tab' => array( |
|
| 652 | - 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 653 | - 'filename' => 'messages_settings_message_types' |
|
| 654 | - ), |
|
| 655 | - 'messages_settings_messengers_help_tab' => array( |
|
| 656 | - 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 657 | - 'filename' => 'messages_settings_messengers' |
|
| 658 | - ), |
|
| 659 | - ), |
|
| 660 | - 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 661 | - 'require_nonce' => false |
|
| 662 | - ) |
|
| 663 | - ); |
|
| 664 | - } |
|
| 521 | + protected function _set_page_config() |
|
| 522 | + { |
|
| 523 | + $this->_page_config = array( |
|
| 524 | + 'default' => array( |
|
| 525 | + 'nav' => array( |
|
| 526 | + 'label' => esc_html__('Message Activity', 'event_espresso'), |
|
| 527 | + 'order' => 10 |
|
| 528 | + ), |
|
| 529 | + 'list_table' => 'EE_Message_List_Table', |
|
| 530 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ), |
|
| 531 | + 'require_nonce' => false |
|
| 532 | + ), |
|
| 533 | + 'global_mtps' => array( |
|
| 534 | + 'nav' => array( |
|
| 535 | + 'label' => esc_html__('Default Message Templates', 'event_espresso'), |
|
| 536 | + 'order' => 20 |
|
| 537 | + ), |
|
| 538 | + 'list_table' => 'Messages_Template_List_Table', |
|
| 539 | + 'help_tabs' => array( |
|
| 540 | + 'messages_overview_help_tab' => array( |
|
| 541 | + 'title' => esc_html__('Messages Overview', 'event_espresso'), |
|
| 542 | + 'filename' => 'messages_overview' |
|
| 543 | + ), |
|
| 544 | + 'messages_overview_messages_table_column_headings_help_tab' => array( |
|
| 545 | + 'title' => esc_html__('Messages Table Column Headings', 'event_espresso'), |
|
| 546 | + 'filename' => 'messages_overview_table_column_headings' |
|
| 547 | + ), |
|
| 548 | + 'messages_overview_messages_filters_help_tab' => array( |
|
| 549 | + 'title' => esc_html__('Message Filters', 'event_espresso'), |
|
| 550 | + 'filename' => 'messages_overview_filters' |
|
| 551 | + ), |
|
| 552 | + 'messages_overview_messages_views_help_tab' => array( |
|
| 553 | + 'title' => esc_html__('Message Views', 'event_espresso'), |
|
| 554 | + 'filename' => 'messages_overview_views' |
|
| 555 | + ), |
|
| 556 | + 'message_overview_message_types_help_tab' => array( |
|
| 557 | + 'title' => esc_html__('Message Types', 'event_espresso'), |
|
| 558 | + 'filename' => 'messages_overview_types' |
|
| 559 | + ), |
|
| 560 | + 'messages_overview_messengers_help_tab' => array( |
|
| 561 | + 'title' => esc_html__('Messengers', 'event_espresso'), |
|
| 562 | + 'filename' => 'messages_overview_messengers', |
|
| 563 | + ), |
|
| 564 | + ), |
|
| 565 | + 'help_tour' => array('Messages_Overview_Help_Tour'), |
|
| 566 | + 'require_nonce' => false |
|
| 567 | + ), |
|
| 568 | + 'custom_mtps' => array( |
|
| 569 | + 'nav' => array( |
|
| 570 | + 'label' => esc_html__('Custom Message Templates', 'event_espresso'), |
|
| 571 | + 'order' => 30 |
|
| 572 | + ), |
|
| 573 | + 'help_tabs' => array(), |
|
| 574 | + 'help_tour' => array(), |
|
| 575 | + 'require_nonce' => false |
|
| 576 | + ), |
|
| 577 | + 'add_new_message_template' => array( |
|
| 578 | + 'nav' => array( |
|
| 579 | + 'label' => esc_html__('Add New Message Templates', 'event_espresso'), |
|
| 580 | + 'order' => 5, |
|
| 581 | + 'persistent' => false |
|
| 582 | + ), |
|
| 583 | + 'require_nonce' => false |
|
| 584 | + ), |
|
| 585 | + 'edit_message_template' => array( |
|
| 586 | + 'labels' => array( |
|
| 587 | + 'buttons' => array( |
|
| 588 | + 'reset' => esc_html__('Reset Templates'), |
|
| 589 | + ), |
|
| 590 | + 'publishbox' => esc_html__('Update Actions', 'event_espresso') |
|
| 591 | + ), |
|
| 592 | + 'nav' => array( |
|
| 593 | + 'label' => esc_html__('Edit Message Templates', 'event_espresso'), |
|
| 594 | + 'order' => 5, |
|
| 595 | + 'persistent' => false, |
|
| 596 | + 'url' => '' |
|
| 597 | + ), |
|
| 598 | + 'metaboxes' => array('_publish_post_box', '_register_edit_meta_boxes'), |
|
| 599 | + 'has_metaboxes' => true, |
|
| 600 | + 'help_tour' => array('Message_Templates_Edit_Help_Tour'), |
|
| 601 | + 'help_tabs' => array( |
|
| 602 | + 'edit_message_template' => array( |
|
| 603 | + 'title' => esc_html__('Message Template Editor', 'event_espresso'), |
|
| 604 | + 'callback' => 'edit_message_template_help_tab' |
|
| 605 | + ), |
|
| 606 | + 'message_templates_help_tab' => array( |
|
| 607 | + 'title' => esc_html__('Message Templates', 'event_espresso'), |
|
| 608 | + 'filename' => 'messages_templates' |
|
| 609 | + ), |
|
| 610 | + 'message_template_shortcodes' => array( |
|
| 611 | + 'title' => esc_html__('Message Shortcodes', 'event_espresso'), |
|
| 612 | + 'callback' => 'message_template_shortcodes_help_tab' |
|
| 613 | + ), |
|
| 614 | + 'message_preview_help_tab' => array( |
|
| 615 | + 'title' => esc_html__('Message Preview', 'event_espresso'), |
|
| 616 | + 'filename' => 'messages_preview' |
|
| 617 | + ), |
|
| 618 | + 'messages_overview_other_help_tab' => array( |
|
| 619 | + 'title' => esc_html__('Messages Other', 'event_espresso'), |
|
| 620 | + 'filename' => 'messages_overview_other', |
|
| 621 | + ), |
|
| 622 | + ), |
|
| 623 | + 'require_nonce' => false |
|
| 624 | + ), |
|
| 625 | + 'display_preview_message' => array( |
|
| 626 | + 'nav' => array( |
|
| 627 | + 'label' => esc_html__('Message Preview', 'event_espresso'), |
|
| 628 | + 'order' => 5, |
|
| 629 | + 'url' => '', |
|
| 630 | + 'persistent' => false |
|
| 631 | + ), |
|
| 632 | + 'help_tabs' => array( |
|
| 633 | + 'preview_message' => array( |
|
| 634 | + 'title' => esc_html__('About Previews', 'event_espresso'), |
|
| 635 | + 'callback' => 'preview_message_help_tab' |
|
| 636 | + ) |
|
| 637 | + ), |
|
| 638 | + 'require_nonce' => false |
|
| 639 | + ), |
|
| 640 | + 'settings' => array( |
|
| 641 | + 'nav' => array( |
|
| 642 | + 'label' => esc_html__('Settings', 'event_espresso'), |
|
| 643 | + 'order' => 40 |
|
| 644 | + ), |
|
| 645 | + 'metaboxes' => array('_messages_settings_metaboxes'), |
|
| 646 | + 'help_tabs' => array( |
|
| 647 | + 'messages_settings_help_tab' => array( |
|
| 648 | + 'title' => esc_html__('Messages Settings', 'event_espresso'), |
|
| 649 | + 'filename' => 'messages_settings' |
|
| 650 | + ), |
|
| 651 | + 'messages_settings_message_types_help_tab' => array( |
|
| 652 | + 'title' => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), |
|
| 653 | + 'filename' => 'messages_settings_message_types' |
|
| 654 | + ), |
|
| 655 | + 'messages_settings_messengers_help_tab' => array( |
|
| 656 | + 'title' => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), |
|
| 657 | + 'filename' => 'messages_settings_messengers' |
|
| 658 | + ), |
|
| 659 | + ), |
|
| 660 | + 'help_tour' => array('Messages_Settings_Help_Tour'), |
|
| 661 | + 'require_nonce' => false |
|
| 662 | + ) |
|
| 663 | + ); |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | |
| 667 | - protected function _add_screen_options() |
|
| 668 | - { |
|
| 669 | - //todo |
|
| 670 | - } |
|
| 667 | + protected function _add_screen_options() |
|
| 668 | + { |
|
| 669 | + //todo |
|
| 670 | + } |
|
| 671 | 671 | |
| 672 | 672 | |
| 673 | - protected function _add_screen_options_global_mtps() |
|
| 674 | - { |
|
| 675 | - /** |
|
| 676 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 677 | - * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 678 | - */ |
|
| 679 | - $page_title = $this->_admin_page_title; |
|
| 680 | - $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 681 | - $this->_per_page_screen_option(); |
|
| 682 | - $this->_admin_page_title = $page_title; |
|
| 683 | - } |
|
| 673 | + protected function _add_screen_options_global_mtps() |
|
| 674 | + { |
|
| 675 | + /** |
|
| 676 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options |
|
| 677 | + * uses the $_admin_page_title property and we want different outputs in the different spots. |
|
| 678 | + */ |
|
| 679 | + $page_title = $this->_admin_page_title; |
|
| 680 | + $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); |
|
| 681 | + $this->_per_page_screen_option(); |
|
| 682 | + $this->_admin_page_title = $page_title; |
|
| 683 | + } |
|
| 684 | 684 | |
| 685 | 685 | |
| 686 | - protected function _add_screen_options_default() |
|
| 687 | - { |
|
| 688 | - $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 689 | - $this->_per_page_screen_option(); |
|
| 690 | - } |
|
| 686 | + protected function _add_screen_options_default() |
|
| 687 | + { |
|
| 688 | + $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); |
|
| 689 | + $this->_per_page_screen_option(); |
|
| 690 | + } |
|
| 691 | 691 | |
| 692 | 692 | |
| 693 | - //none of the below group are currently used for Messages |
|
| 694 | - protected function _add_feature_pointers() |
|
| 695 | - { |
|
| 696 | - } |
|
| 693 | + //none of the below group are currently used for Messages |
|
| 694 | + protected function _add_feature_pointers() |
|
| 695 | + { |
|
| 696 | + } |
|
| 697 | 697 | |
| 698 | - public function admin_init() |
|
| 699 | - { |
|
| 700 | - } |
|
| 698 | + public function admin_init() |
|
| 699 | + { |
|
| 700 | + } |
|
| 701 | 701 | |
| 702 | - public function admin_notices() |
|
| 703 | - { |
|
| 704 | - } |
|
| 702 | + public function admin_notices() |
|
| 703 | + { |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - public function admin_footer_scripts() |
|
| 707 | - { |
|
| 708 | - } |
|
| 706 | + public function admin_footer_scripts() |
|
| 707 | + { |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | 710 | |
| 711 | - public function messages_help_tab() |
|
| 712 | - { |
|
| 713 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 714 | - } |
|
| 711 | + public function messages_help_tab() |
|
| 712 | + { |
|
| 713 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php'); |
|
| 714 | + } |
|
| 715 | 715 | |
| 716 | 716 | |
| 717 | - public function messengers_help_tab() |
|
| 718 | - { |
|
| 719 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 720 | - } |
|
| 717 | + public function messengers_help_tab() |
|
| 718 | + { |
|
| 719 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php'); |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | 722 | |
| 723 | - public function message_types_help_tab() |
|
| 724 | - { |
|
| 725 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 726 | - } |
|
| 723 | + public function message_types_help_tab() |
|
| 724 | + { |
|
| 725 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php'); |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | 728 | |
| 729 | - public function messages_overview_help_tab() |
|
| 730 | - { |
|
| 731 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 732 | - } |
|
| 729 | + public function messages_overview_help_tab() |
|
| 730 | + { |
|
| 731 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php'); |
|
| 732 | + } |
|
| 733 | 733 | |
| 734 | 734 | |
| 735 | - public function message_templates_help_tab() |
|
| 736 | - { |
|
| 737 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 738 | - } |
|
| 735 | + public function message_templates_help_tab() |
|
| 736 | + { |
|
| 737 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php'); |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | |
| 741 | - public function edit_message_template_help_tab() |
|
| 742 | - { |
|
| 743 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 744 | - . esc_attr__('Editor Title', 'event_espresso') |
|
| 745 | - . '" />'; |
|
| 746 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 747 | - . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 748 | - . '" />'; |
|
| 749 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 750 | - . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 751 | - . '" />'; |
|
| 752 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 753 | - . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 754 | - . '" />'; |
|
| 755 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 756 | - . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 757 | - . '" />'; |
|
| 758 | - EEH_Template::display_template( |
|
| 759 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 760 | - $args |
|
| 761 | - ); |
|
| 762 | - } |
|
| 741 | + public function edit_message_template_help_tab() |
|
| 742 | + { |
|
| 743 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' |
|
| 744 | + . esc_attr__('Editor Title', 'event_espresso') |
|
| 745 | + . '" />'; |
|
| 746 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' |
|
| 747 | + . esc_attr__('Context Switcher and Preview', 'event_espresso') |
|
| 748 | + . '" />'; |
|
| 749 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' |
|
| 750 | + . esc_attr__('Message Template Form Fields', 'event_espresso') |
|
| 751 | + . '" />'; |
|
| 752 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' |
|
| 753 | + . esc_attr__('Shortcodes Metabox', 'event_espresso') |
|
| 754 | + . '" />'; |
|
| 755 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' |
|
| 756 | + . esc_attr__('Publish Metabox', 'event_espresso') |
|
| 757 | + . '" />'; |
|
| 758 | + EEH_Template::display_template( |
|
| 759 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php', |
|
| 760 | + $args |
|
| 761 | + ); |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | - public function message_template_shortcodes_help_tab() |
|
| 766 | - { |
|
| 767 | - $this->_set_shortcodes(); |
|
| 768 | - $args['shortcodes'] = $this->_shortcodes; |
|
| 769 | - EEH_Template::display_template( |
|
| 770 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 771 | - $args |
|
| 772 | - ); |
|
| 773 | - } |
|
| 765 | + public function message_template_shortcodes_help_tab() |
|
| 766 | + { |
|
| 767 | + $this->_set_shortcodes(); |
|
| 768 | + $args['shortcodes'] = $this->_shortcodes; |
|
| 769 | + EEH_Template::display_template( |
|
| 770 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php', |
|
| 771 | + $args |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | 775 | |
| 776 | - public function preview_message_help_tab() |
|
| 777 | - { |
|
| 778 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 779 | - } |
|
| 776 | + public function preview_message_help_tab() |
|
| 777 | + { |
|
| 778 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php'); |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | 781 | |
| 782 | - public function settings_help_tab() |
|
| 783 | - { |
|
| 784 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 785 | - . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 786 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 787 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 788 | - $args['img3'] = '<div class="switch">' |
|
| 789 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 790 | - . ' type="checkbox" checked="checked">' |
|
| 791 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 792 | - . '</div>'; |
|
| 793 | - $args['img4'] = '<div class="switch">' |
|
| 794 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 795 | - . ' type="checkbox">' |
|
| 796 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
| 797 | - . '</div>'; |
|
| 798 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 799 | - } |
|
| 782 | + public function settings_help_tab() |
|
| 783 | + { |
|
| 784 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' |
|
| 785 | + . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; |
|
| 786 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
| 787 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; |
|
| 788 | + $args['img3'] = '<div class="switch">' |
|
| 789 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 790 | + . ' type="checkbox" checked="checked">' |
|
| 791 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 792 | + . '</div>'; |
|
| 793 | + $args['img4'] = '<div class="switch">' |
|
| 794 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat"' |
|
| 795 | + . ' type="checkbox">' |
|
| 796 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
| 797 | + . '</div>'; |
|
| 798 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args); |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | 801 | |
| 802 | - public function load_scripts_styles() |
|
| 803 | - { |
|
| 804 | - wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 805 | - wp_enqueue_style('espresso_ee_msg'); |
|
| 806 | - |
|
| 807 | - wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 808 | - array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 809 | - wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 810 | - array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 811 | - } |
|
| 802 | + public function load_scripts_styles() |
|
| 803 | + { |
|
| 804 | + wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); |
|
| 805 | + wp_enqueue_style('espresso_ee_msg'); |
|
| 806 | + |
|
| 807 | + wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js', |
|
| 808 | + array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true); |
|
| 809 | + wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js', |
|
| 810 | + array('ee-dialog'), EVENT_ESPRESSO_VERSION); |
|
| 811 | + } |
|
| 812 | 812 | |
| 813 | 813 | |
| 814 | - public function load_scripts_styles_default() |
|
| 815 | - { |
|
| 816 | - wp_enqueue_script('ee-msg-list-table-js'); |
|
| 817 | - } |
|
| 814 | + public function load_scripts_styles_default() |
|
| 815 | + { |
|
| 816 | + wp_enqueue_script('ee-msg-list-table-js'); |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | 819 | |
| 820 | - public function wp_editor_css($mce_css) |
|
| 821 | - { |
|
| 822 | - //if we're on the edit_message_template route |
|
| 823 | - if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 824 | - $message_type_name = $this->_active_message_type_name; |
|
| 820 | + public function wp_editor_css($mce_css) |
|
| 821 | + { |
|
| 822 | + //if we're on the edit_message_template route |
|
| 823 | + if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { |
|
| 824 | + $message_type_name = $this->_active_message_type_name; |
|
| 825 | 825 | |
| 826 | - //we're going to REPLACE the existing mce css |
|
| 827 | - //we need to get the css file location from the active messenger |
|
| 828 | - $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 829 | - 'wpeditor', $this->_variation); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - return $mce_css; |
|
| 833 | - } |
|
| 826 | + //we're going to REPLACE the existing mce css |
|
| 827 | + //we need to get the css file location from the active messenger |
|
| 828 | + $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, |
|
| 829 | + 'wpeditor', $this->_variation); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + return $mce_css; |
|
| 833 | + } |
|
| 834 | 834 | |
| 835 | 835 | |
| 836 | - public function load_scripts_styles_edit_message_template() |
|
| 837 | - { |
|
| 838 | - |
|
| 839 | - $this->_set_shortcodes(); |
|
| 840 | - |
|
| 841 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 842 | - esc_html__( |
|
| 843 | - 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 844 | - 'event_espresso' |
|
| 845 | - ), |
|
| 846 | - $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 847 | - $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 848 | - ); |
|
| 849 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 850 | - 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 851 | - 'event_espresso' |
|
| 852 | - ); |
|
| 853 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 854 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 855 | - 'event_espresso' |
|
| 856 | - ); |
|
| 857 | - |
|
| 858 | - wp_register_script( |
|
| 859 | - 'ee_msgs_edit_js', |
|
| 860 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 861 | - array('jquery'), |
|
| 862 | - EVENT_ESPRESSO_VERSION |
|
| 863 | - ); |
|
| 864 | - |
|
| 865 | - wp_enqueue_script('ee_admin_js'); |
|
| 866 | - wp_enqueue_script('ee_msgs_edit_js'); |
|
| 867 | - |
|
| 868 | - //add in special css for tiny_mce |
|
| 869 | - add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 870 | - } |
|
| 836 | + public function load_scripts_styles_edit_message_template() |
|
| 837 | + { |
|
| 838 | + |
|
| 839 | + $this->_set_shortcodes(); |
|
| 840 | + |
|
| 841 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf( |
|
| 842 | + esc_html__( |
|
| 843 | + 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.', |
|
| 844 | + 'event_espresso' |
|
| 845 | + ), |
|
| 846 | + $this->_message_template_group->messenger_obj()->label['singular'], |
|
| 847 | + $this->_message_template_group->message_type_obj()->label['singular'] |
|
| 848 | + ); |
|
| 849 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__( |
|
| 850 | + 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?', |
|
| 851 | + 'event_espresso' |
|
| 852 | + ); |
|
| 853 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__( |
|
| 854 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 855 | + 'event_espresso' |
|
| 856 | + ); |
|
| 857 | + |
|
| 858 | + wp_register_script( |
|
| 859 | + 'ee_msgs_edit_js', |
|
| 860 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js', |
|
| 861 | + array('jquery'), |
|
| 862 | + EVENT_ESPRESSO_VERSION |
|
| 863 | + ); |
|
| 864 | + |
|
| 865 | + wp_enqueue_script('ee_admin_js'); |
|
| 866 | + wp_enqueue_script('ee_msgs_edit_js'); |
|
| 867 | + |
|
| 868 | + //add in special css for tiny_mce |
|
| 869 | + add_filter('mce_css', array($this, 'wp_editor_css')); |
|
| 870 | + } |
|
| 871 | 871 | |
| 872 | 872 | |
| 873 | - public function load_scripts_styles_display_preview_message() |
|
| 874 | - { |
|
| 875 | - |
|
| 876 | - $this->_set_message_template_group(); |
|
| 877 | - |
|
| 878 | - if (isset($this->_req_data['messenger'])) { |
|
| 879 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 880 | - $this->_req_data['messenger'] |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - wp_enqueue_style('espresso_preview_css', |
|
| 888 | - $this->_active_messenger->get_variation( |
|
| 889 | - $this->_template_pack, |
|
| 890 | - $message_type_name, |
|
| 891 | - true, |
|
| 892 | - 'preview', |
|
| 893 | - $this->_variation |
|
| 894 | - ) |
|
| 895 | - ); |
|
| 896 | - } |
|
| 873 | + public function load_scripts_styles_display_preview_message() |
|
| 874 | + { |
|
| 875 | + |
|
| 876 | + $this->_set_message_template_group(); |
|
| 877 | + |
|
| 878 | + if (isset($this->_req_data['messenger'])) { |
|
| 879 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 880 | + $this->_req_data['messenger'] |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : ''; |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + wp_enqueue_style('espresso_preview_css', |
|
| 888 | + $this->_active_messenger->get_variation( |
|
| 889 | + $this->_template_pack, |
|
| 890 | + $message_type_name, |
|
| 891 | + true, |
|
| 892 | + 'preview', |
|
| 893 | + $this->_variation |
|
| 894 | + ) |
|
| 895 | + ); |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | 898 | |
| 899 | - public function load_scripts_styles_settings() |
|
| 900 | - { |
|
| 901 | - wp_register_style( |
|
| 902 | - 'ee-message-settings', |
|
| 903 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 904 | - array(), |
|
| 905 | - EVENT_ESPRESSO_VERSION |
|
| 906 | - ); |
|
| 907 | - wp_enqueue_style('ee-text-links'); |
|
| 908 | - wp_enqueue_style('ee-message-settings'); |
|
| 909 | - wp_enqueue_script('ee-messages-settings'); |
|
| 910 | - } |
|
| 899 | + public function load_scripts_styles_settings() |
|
| 900 | + { |
|
| 901 | + wp_register_style( |
|
| 902 | + 'ee-message-settings', |
|
| 903 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css', |
|
| 904 | + array(), |
|
| 905 | + EVENT_ESPRESSO_VERSION |
|
| 906 | + ); |
|
| 907 | + wp_enqueue_style('ee-text-links'); |
|
| 908 | + wp_enqueue_style('ee-message-settings'); |
|
| 909 | + wp_enqueue_script('ee-messages-settings'); |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | 912 | |
| 913 | - /** |
|
| 914 | - * set views array for List Table |
|
| 915 | - */ |
|
| 916 | - public function _set_list_table_views_global_mtps() |
|
| 917 | - { |
|
| 918 | - $this->_views = array( |
|
| 919 | - 'in_use' => array( |
|
| 920 | - 'slug' => 'in_use', |
|
| 921 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 922 | - 'count' => 0, |
|
| 923 | - ) |
|
| 924 | - ); |
|
| 925 | - } |
|
| 913 | + /** |
|
| 914 | + * set views array for List Table |
|
| 915 | + */ |
|
| 916 | + public function _set_list_table_views_global_mtps() |
|
| 917 | + { |
|
| 918 | + $this->_views = array( |
|
| 919 | + 'in_use' => array( |
|
| 920 | + 'slug' => 'in_use', |
|
| 921 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 922 | + 'count' => 0, |
|
| 923 | + ) |
|
| 924 | + ); |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | 927 | |
| 928 | - /** |
|
| 929 | - * Set views array for the Custom Template List Table |
|
| 930 | - */ |
|
| 931 | - public function _set_list_table_views_custom_mtps() |
|
| 932 | - { |
|
| 933 | - $this->_set_list_table_views_global_mtps(); |
|
| 934 | - $this->_views['in_use']['bulk_action'] = array( |
|
| 935 | - 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 936 | - ); |
|
| 937 | - } |
|
| 928 | + /** |
|
| 929 | + * Set views array for the Custom Template List Table |
|
| 930 | + */ |
|
| 931 | + public function _set_list_table_views_custom_mtps() |
|
| 932 | + { |
|
| 933 | + $this->_set_list_table_views_global_mtps(); |
|
| 934 | + $this->_views['in_use']['bulk_action'] = array( |
|
| 935 | + 'trash_message_template' => esc_html__('Move to Trash', 'event_espresso') |
|
| 936 | + ); |
|
| 937 | + } |
|
| 938 | 938 | |
| 939 | 939 | |
| 940 | - /** |
|
| 941 | - * set views array for message queue list table |
|
| 942 | - * |
|
| 943 | - * @throws InvalidDataTypeException |
|
| 944 | - * @throws InvalidInterfaceException |
|
| 945 | - * @throws InvalidArgumentException |
|
| 946 | - * @throws EE_Error |
|
| 947 | - * @throws ReflectionException |
|
| 948 | - */ |
|
| 949 | - public function _set_list_table_views_default() |
|
| 950 | - { |
|
| 951 | - EE_Registry::instance()->load_helper('Template'); |
|
| 952 | - |
|
| 953 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 954 | - 'ee_send_message', |
|
| 955 | - 'message_list_table_bulk_actions' |
|
| 956 | - ) |
|
| 957 | - ? array( |
|
| 958 | - 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 959 | - 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 960 | - 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 961 | - 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 962 | - ) |
|
| 963 | - : array(); |
|
| 964 | - |
|
| 965 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 966 | - 'ee_delete_messages', |
|
| 967 | - 'message_list_table_bulk_actions' |
|
| 968 | - ) |
|
| 969 | - ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 970 | - : array(); |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - $this->_views = array( |
|
| 974 | - 'all' => array( |
|
| 975 | - 'slug' => 'all', |
|
| 976 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 977 | - 'count' => 0, |
|
| 978 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 979 | - ) |
|
| 980 | - ); |
|
| 981 | - |
|
| 982 | - |
|
| 983 | - foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 984 | - if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 985 | - continue; |
|
| 986 | - } |
|
| 987 | - $status_bulk_actions = $common_bulk_actions; |
|
| 988 | - //unset bulk actions not applying to status |
|
| 989 | - if (! empty($status_bulk_actions)) { |
|
| 990 | - switch ($status) { |
|
| 991 | - case EEM_Message::status_idle: |
|
| 992 | - case EEM_Message::status_resend: |
|
| 993 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 994 | - break; |
|
| 940 | + /** |
|
| 941 | + * set views array for message queue list table |
|
| 942 | + * |
|
| 943 | + * @throws InvalidDataTypeException |
|
| 944 | + * @throws InvalidInterfaceException |
|
| 945 | + * @throws InvalidArgumentException |
|
| 946 | + * @throws EE_Error |
|
| 947 | + * @throws ReflectionException |
|
| 948 | + */ |
|
| 949 | + public function _set_list_table_views_default() |
|
| 950 | + { |
|
| 951 | + EE_Registry::instance()->load_helper('Template'); |
|
| 952 | + |
|
| 953 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can( |
|
| 954 | + 'ee_send_message', |
|
| 955 | + 'message_list_table_bulk_actions' |
|
| 956 | + ) |
|
| 957 | + ? array( |
|
| 958 | + 'generate_now' => esc_html__('Generate Now', 'event_espresso'), |
|
| 959 | + 'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), |
|
| 960 | + 'queue_for_resending' => esc_html__('Queue for Resending', 'event_espresso'), |
|
| 961 | + 'send_now' => esc_html__('Send Now', 'event_espresso') |
|
| 962 | + ) |
|
| 963 | + : array(); |
|
| 964 | + |
|
| 965 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can( |
|
| 966 | + 'ee_delete_messages', |
|
| 967 | + 'message_list_table_bulk_actions' |
|
| 968 | + ) |
|
| 969 | + ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')) |
|
| 970 | + : array(); |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + $this->_views = array( |
|
| 974 | + 'all' => array( |
|
| 975 | + 'slug' => 'all', |
|
| 976 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 977 | + 'count' => 0, |
|
| 978 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action) |
|
| 979 | + ) |
|
| 980 | + ); |
|
| 981 | + |
|
| 982 | + |
|
| 983 | + foreach (EEM_Message::instance()->all_statuses() as $status) { |
|
| 984 | + if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { |
|
| 985 | + continue; |
|
| 986 | + } |
|
| 987 | + $status_bulk_actions = $common_bulk_actions; |
|
| 988 | + //unset bulk actions not applying to status |
|
| 989 | + if (! empty($status_bulk_actions)) { |
|
| 990 | + switch ($status) { |
|
| 991 | + case EEM_Message::status_idle: |
|
| 992 | + case EEM_Message::status_resend: |
|
| 993 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now']; |
|
| 994 | + break; |
|
| 995 | 995 | |
| 996 | - case EEM_Message::status_failed: |
|
| 997 | - case EEM_Message::status_debug_only: |
|
| 998 | - case EEM_Message::status_messenger_executing: |
|
| 999 | - $status_bulk_actions = array(); |
|
| 1000 | - break; |
|
| 996 | + case EEM_Message::status_failed: |
|
| 997 | + case EEM_Message::status_debug_only: |
|
| 998 | + case EEM_Message::status_messenger_executing: |
|
| 999 | + $status_bulk_actions = array(); |
|
| 1000 | + break; |
|
| 1001 | 1001 | |
| 1002 | - case EEM_Message::status_incomplete: |
|
| 1003 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1004 | - break; |
|
| 1002 | + case EEM_Message::status_incomplete: |
|
| 1003 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']); |
|
| 1004 | + break; |
|
| 1005 | 1005 | |
| 1006 | - case EEM_Message::status_retry: |
|
| 1007 | - case EEM_Message::status_sent: |
|
| 1008 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1009 | - break; |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 1006 | + case EEM_Message::status_retry: |
|
| 1007 | + case EEM_Message::status_sent: |
|
| 1008 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']); |
|
| 1009 | + break; |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | 1012 | |
| 1013 | - //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1014 | - if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1015 | - continue; |
|
| 1016 | - } |
|
| 1013 | + //skip adding messenger executing status to views because it will be included with the Failed view. |
|
| 1014 | + if ( $status === EEM_Message::status_messenger_executing ) { |
|
| 1015 | + continue; |
|
| 1016 | + } |
|
| 1017 | 1017 | |
| 1018 | - $this->_views[strtolower($status)] = array( |
|
| 1019 | - 'slug' => strtolower($status), |
|
| 1020 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1021 | - 'count' => 0, |
|
| 1022 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1023 | - ); |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1018 | + $this->_views[strtolower($status)] = array( |
|
| 1019 | + 'slug' => strtolower($status), |
|
| 1020 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
| 1021 | + 'count' => 0, |
|
| 1022 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action) |
|
| 1023 | + ); |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | 1027 | |
| 1028 | - protected function _ee_default_messages_overview_list_table() |
|
| 1029 | - { |
|
| 1030 | - $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1031 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1032 | - } |
|
| 1028 | + protected function _ee_default_messages_overview_list_table() |
|
| 1029 | + { |
|
| 1030 | + $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); |
|
| 1031 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1032 | + } |
|
| 1033 | 1033 | |
| 1034 | 1034 | |
| 1035 | - protected function _message_queue_list_table() |
|
| 1036 | - { |
|
| 1037 | - $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1038 | - $this->_template_args['per_column'] = 6; |
|
| 1039 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1040 | - $this->_template_args['before_list_table'] = '<h3>' |
|
| 1041 | - . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1042 | - . '</h3>'; |
|
| 1043 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1044 | - } |
|
| 1035 | + protected function _message_queue_list_table() |
|
| 1036 | + { |
|
| 1037 | + $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso'); |
|
| 1038 | + $this->_template_args['per_column'] = 6; |
|
| 1039 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items()); |
|
| 1040 | + $this->_template_args['before_list_table'] = '<h3>' |
|
| 1041 | + . EEM_Message::instance()->get_pretty_label_for_results() |
|
| 1042 | + . '</h3>'; |
|
| 1043 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | - protected function _message_legend_items() |
|
| 1048 | - { |
|
| 1049 | - |
|
| 1050 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1051 | - $action_items = array(); |
|
| 1052 | - |
|
| 1053 | - foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1054 | - if ($action_item === 'see_notifications_for') { |
|
| 1055 | - continue; |
|
| 1056 | - } |
|
| 1057 | - $action_items[$action_item] = array( |
|
| 1058 | - 'class' => $action_details['css_class'], |
|
| 1059 | - 'desc' => $action_details['label'] |
|
| 1060 | - ); |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - /** @type array $status_items status legend setup */ |
|
| 1064 | - $status_items = array( |
|
| 1065 | - 'sent_status' => array( |
|
| 1066 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1067 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1068 | - ), |
|
| 1069 | - 'idle_status' => array( |
|
| 1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1071 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1072 | - ), |
|
| 1073 | - 'failed_status' => array( |
|
| 1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1075 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1076 | - ), |
|
| 1077 | - 'messenger_executing_status' => array( |
|
| 1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1079 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1080 | - ), |
|
| 1081 | - 'resend_status' => array( |
|
| 1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1083 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1084 | - ), |
|
| 1085 | - 'incomplete_status' => array( |
|
| 1086 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1087 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1088 | - ), |
|
| 1089 | - 'retry_status' => array( |
|
| 1090 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1091 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1092 | - ) |
|
| 1093 | - ); |
|
| 1094 | - if (EEM_Message::debug()) { |
|
| 1095 | - $status_items['debug_only_status'] = array( |
|
| 1096 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1097 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1098 | - ); |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - return array_merge($action_items, $status_items); |
|
| 1102 | - } |
|
| 1047 | + protected function _message_legend_items() |
|
| 1048 | + { |
|
| 1049 | + |
|
| 1050 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons(); |
|
| 1051 | + $action_items = array(); |
|
| 1052 | + |
|
| 1053 | + foreach ($action_css_classes as $action_item => $action_details) { |
|
| 1054 | + if ($action_item === 'see_notifications_for') { |
|
| 1055 | + continue; |
|
| 1056 | + } |
|
| 1057 | + $action_items[$action_item] = array( |
|
| 1058 | + 'class' => $action_details['css_class'], |
|
| 1059 | + 'desc' => $action_details['label'] |
|
| 1060 | + ); |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + /** @type array $status_items status legend setup */ |
|
| 1064 | + $status_items = array( |
|
| 1065 | + 'sent_status' => array( |
|
| 1066 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent, |
|
| 1067 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence') |
|
| 1068 | + ), |
|
| 1069 | + 'idle_status' => array( |
|
| 1070 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle, |
|
| 1071 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence') |
|
| 1072 | + ), |
|
| 1073 | + 'failed_status' => array( |
|
| 1074 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed, |
|
| 1075 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence') |
|
| 1076 | + ), |
|
| 1077 | + 'messenger_executing_status' => array( |
|
| 1078 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing, |
|
| 1079 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence') |
|
| 1080 | + ), |
|
| 1081 | + 'resend_status' => array( |
|
| 1082 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend, |
|
| 1083 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence') |
|
| 1084 | + ), |
|
| 1085 | + 'incomplete_status' => array( |
|
| 1086 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete, |
|
| 1087 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence') |
|
| 1088 | + ), |
|
| 1089 | + 'retry_status' => array( |
|
| 1090 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry, |
|
| 1091 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence') |
|
| 1092 | + ) |
|
| 1093 | + ); |
|
| 1094 | + if (EEM_Message::debug()) { |
|
| 1095 | + $status_items['debug_only_status'] = array( |
|
| 1096 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only, |
|
| 1097 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence') |
|
| 1098 | + ); |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + return array_merge($action_items, $status_items); |
|
| 1102 | + } |
|
| 1103 | 1103 | |
| 1104 | 1104 | |
| 1105 | - protected function _custom_mtps_preview() |
|
| 1106 | - { |
|
| 1107 | - $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1108 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1109 | - . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1110 | - $this->_template_args['preview_text'] = '<strong>' |
|
| 1111 | - . esc_html__( |
|
| 1112 | - 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1113 | - 'event_espresso' |
|
| 1114 | - ) |
|
| 1115 | - . '</strong>'; |
|
| 1105 | + protected function _custom_mtps_preview() |
|
| 1106 | + { |
|
| 1107 | + $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); |
|
| 1108 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"' |
|
| 1109 | + . ' alt="' . esc_attr__('Preview Custom Message Templates screenshot', 'event_espresso') . '" />'; |
|
| 1110 | + $this->_template_args['preview_text'] = '<strong>' |
|
| 1111 | + . esc_html__( |
|
| 1112 | + 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.', |
|
| 1113 | + 'event_espresso' |
|
| 1114 | + ) |
|
| 1115 | + . '</strong>'; |
|
| 1116 | 1116 | |
| 1117 | - $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1118 | - } |
|
| 1117 | + $this->display_admin_caf_preview_page('custom_message_types', false); |
|
| 1118 | + } |
|
| 1119 | 1119 | |
| 1120 | 1120 | |
| 1121 | - /** |
|
| 1122 | - * get_message_templates |
|
| 1123 | - * This gets all the message templates for listing on the overview list. |
|
| 1124 | - * |
|
| 1125 | - * @access public |
|
| 1126 | - * @param int $perpage the amount of templates groups to show per page |
|
| 1127 | - * @param string $type the current _view we're getting templates for |
|
| 1128 | - * @param bool $count return count? |
|
| 1129 | - * @param bool $all disregard any paging info (get all data); |
|
| 1130 | - * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1131 | - * @return array |
|
| 1132 | - * @throws EE_Error |
|
| 1133 | - * @throws InvalidArgumentException |
|
| 1134 | - * @throws InvalidDataTypeException |
|
| 1135 | - * @throws InvalidInterfaceException |
|
| 1136 | - */ |
|
| 1137 | - public function get_message_templates( |
|
| 1138 | - $perpage = 10, |
|
| 1139 | - $type = 'in_use', |
|
| 1140 | - $count = false, |
|
| 1141 | - $all = false, |
|
| 1142 | - $global = true) |
|
| 1143 | - { |
|
| 1144 | - |
|
| 1145 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 1146 | - |
|
| 1147 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1148 | - $orderby = $this->_req_data['orderby']; |
|
| 1149 | - |
|
| 1150 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1151 | - ? $this->_req_data['order'] |
|
| 1152 | - : 'ASC'; |
|
| 1153 | - |
|
| 1154 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1155 | - ? $this->_req_data['paged'] |
|
| 1156 | - : 1; |
|
| 1157 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1158 | - ? $this->_req_data['perpage'] |
|
| 1159 | - : $perpage; |
|
| 1160 | - |
|
| 1161 | - $offset = ($current_page - 1) * $per_page; |
|
| 1162 | - $limit = $all ? null : array($offset, $per_page); |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - //options will match what is in the _views array property |
|
| 1166 | - switch ($type) { |
|
| 1167 | - case 'in_use': |
|
| 1168 | - $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1169 | - break; |
|
| 1170 | - default: |
|
| 1171 | - $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - return $templates; |
|
| 1175 | - } |
|
| 1121 | + /** |
|
| 1122 | + * get_message_templates |
|
| 1123 | + * This gets all the message templates for listing on the overview list. |
|
| 1124 | + * |
|
| 1125 | + * @access public |
|
| 1126 | + * @param int $perpage the amount of templates groups to show per page |
|
| 1127 | + * @param string $type the current _view we're getting templates for |
|
| 1128 | + * @param bool $count return count? |
|
| 1129 | + * @param bool $all disregard any paging info (get all data); |
|
| 1130 | + * @param bool $global whether to return just global (true) or custom templates (false) |
|
| 1131 | + * @return array |
|
| 1132 | + * @throws EE_Error |
|
| 1133 | + * @throws InvalidArgumentException |
|
| 1134 | + * @throws InvalidDataTypeException |
|
| 1135 | + * @throws InvalidInterfaceException |
|
| 1136 | + */ |
|
| 1137 | + public function get_message_templates( |
|
| 1138 | + $perpage = 10, |
|
| 1139 | + $type = 'in_use', |
|
| 1140 | + $count = false, |
|
| 1141 | + $all = false, |
|
| 1142 | + $global = true) |
|
| 1143 | + { |
|
| 1144 | + |
|
| 1145 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 1146 | + |
|
| 1147 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby']; |
|
| 1148 | + $orderby = $this->_req_data['orderby']; |
|
| 1149 | + |
|
| 1150 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 1151 | + ? $this->_req_data['order'] |
|
| 1152 | + : 'ASC'; |
|
| 1153 | + |
|
| 1154 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 1155 | + ? $this->_req_data['paged'] |
|
| 1156 | + : 1; |
|
| 1157 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 1158 | + ? $this->_req_data['perpage'] |
|
| 1159 | + : $perpage; |
|
| 1160 | + |
|
| 1161 | + $offset = ($current_page - 1) * $per_page; |
|
| 1162 | + $limit = $all ? null : array($offset, $per_page); |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + //options will match what is in the _views array property |
|
| 1166 | + switch ($type) { |
|
| 1167 | + case 'in_use': |
|
| 1168 | + $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true); |
|
| 1169 | + break; |
|
| 1170 | + default: |
|
| 1171 | + $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global); |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + return $templates; |
|
| 1175 | + } |
|
| 1176 | 1176 | |
| 1177 | 1177 | |
| 1178 | - /** |
|
| 1179 | - * filters etc might need a list of installed message_types |
|
| 1180 | - * @return array an array of message type objects |
|
| 1181 | - */ |
|
| 1182 | - public function get_installed_message_types() |
|
| 1183 | - { |
|
| 1184 | - $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1185 | - $installed = array(); |
|
| 1186 | - |
|
| 1187 | - foreach ($installed_message_types as $message_type) { |
|
| 1188 | - $installed[$message_type->name] = $message_type; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - return $installed; |
|
| 1192 | - } |
|
| 1178 | + /** |
|
| 1179 | + * filters etc might need a list of installed message_types |
|
| 1180 | + * @return array an array of message type objects |
|
| 1181 | + */ |
|
| 1182 | + public function get_installed_message_types() |
|
| 1183 | + { |
|
| 1184 | + $installed_message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 1185 | + $installed = array(); |
|
| 1186 | + |
|
| 1187 | + foreach ($installed_message_types as $message_type) { |
|
| 1188 | + $installed[$message_type->name] = $message_type; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + return $installed; |
|
| 1192 | + } |
|
| 1193 | 1193 | |
| 1194 | 1194 | |
| 1195 | - /** |
|
| 1196 | - * _add_message_template |
|
| 1197 | - * |
|
| 1198 | - * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1199 | - * |
|
| 1200 | - * @param string $message_type |
|
| 1201 | - * @param string $messenger |
|
| 1202 | - * @param string $GRP_ID |
|
| 1203 | - * |
|
| 1204 | - * @throws EE_error |
|
| 1205 | - */ |
|
| 1206 | - protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1207 | - { |
|
| 1208 | - //set values override any request data |
|
| 1209 | - $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1210 | - $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1211 | - ? $this->_req_data['message_type'] |
|
| 1212 | - : $message_type; |
|
| 1213 | - |
|
| 1214 | - $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1215 | - $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1216 | - ? $this->_req_data['messenger'] |
|
| 1217 | - : $messenger; |
|
| 1218 | - |
|
| 1219 | - $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1220 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1221 | - |
|
| 1222 | - //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1223 | - if (empty($message_type) || empty($messenger)) { |
|
| 1224 | - throw new EE_Error( |
|
| 1225 | - esc_html__( |
|
| 1226 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1227 | - 'event_espresso' |
|
| 1228 | - ) |
|
| 1229 | - ); |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - //we need the GRP_ID for the template being used as the base for the new template |
|
| 1233 | - if (empty($GRP_ID)) { |
|
| 1234 | - throw new EE_Error( |
|
| 1235 | - esc_html__( |
|
| 1236 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1237 | - 'event_espresso' |
|
| 1238 | - ) |
|
| 1239 | - ); |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - //let's just make sure the template gets generated! |
|
| 1243 | - |
|
| 1244 | - //we need to reassign some variables for what the insert is expecting |
|
| 1245 | - $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1246 | - $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1247 | - $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1248 | - $this->_insert_or_update_message_template(true); |
|
| 1249 | - } |
|
| 1195 | + /** |
|
| 1196 | + * _add_message_template |
|
| 1197 | + * |
|
| 1198 | + * This is used when creating a custom template. All Custom Templates start based off another template. |
|
| 1199 | + * |
|
| 1200 | + * @param string $message_type |
|
| 1201 | + * @param string $messenger |
|
| 1202 | + * @param string $GRP_ID |
|
| 1203 | + * |
|
| 1204 | + * @throws EE_error |
|
| 1205 | + */ |
|
| 1206 | + protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '') |
|
| 1207 | + { |
|
| 1208 | + //set values override any request data |
|
| 1209 | + $message_type = ! empty($message_type) ? $message_type : ''; |
|
| 1210 | + $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) |
|
| 1211 | + ? $this->_req_data['message_type'] |
|
| 1212 | + : $message_type; |
|
| 1213 | + |
|
| 1214 | + $messenger = ! empty($messenger) ? $messenger : ''; |
|
| 1215 | + $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) |
|
| 1216 | + ? $this->_req_data['messenger'] |
|
| 1217 | + : $messenger; |
|
| 1218 | + |
|
| 1219 | + $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : ''; |
|
| 1220 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID; |
|
| 1221 | + |
|
| 1222 | + //we need messenger and message type. They should be coming from the event editor. If not here then return error |
|
| 1223 | + if (empty($message_type) || empty($messenger)) { |
|
| 1224 | + throw new EE_Error( |
|
| 1225 | + esc_html__( |
|
| 1226 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type', |
|
| 1227 | + 'event_espresso' |
|
| 1228 | + ) |
|
| 1229 | + ); |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + //we need the GRP_ID for the template being used as the base for the new template |
|
| 1233 | + if (empty($GRP_ID)) { |
|
| 1234 | + throw new EE_Error( |
|
| 1235 | + esc_html__( |
|
| 1236 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed', |
|
| 1237 | + 'event_espresso' |
|
| 1238 | + ) |
|
| 1239 | + ); |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + //let's just make sure the template gets generated! |
|
| 1243 | + |
|
| 1244 | + //we need to reassign some variables for what the insert is expecting |
|
| 1245 | + $this->_req_data['MTP_messenger'] = $messenger; |
|
| 1246 | + $this->_req_data['MTP_message_type'] = $message_type; |
|
| 1247 | + $this->_req_data['GRP_ID'] = $GRP_ID; |
|
| 1248 | + $this->_insert_or_update_message_template(true); |
|
| 1249 | + } |
|
| 1250 | 1250 | |
| 1251 | 1251 | |
| 1252 | - /** |
|
| 1253 | - * public wrapper for the _add_message_template method |
|
| 1254 | - * |
|
| 1255 | - * @param string $message_type message type slug |
|
| 1256 | - * @param string $messenger messenger slug |
|
| 1257 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1258 | - * off of. |
|
| 1259 | - * @throws EE_error |
|
| 1260 | - */ |
|
| 1261 | - public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1262 | - { |
|
| 1263 | - $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1264 | - } |
|
| 1252 | + /** |
|
| 1253 | + * public wrapper for the _add_message_template method |
|
| 1254 | + * |
|
| 1255 | + * @param string $message_type message type slug |
|
| 1256 | + * @param string $messenger messenger slug |
|
| 1257 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based |
|
| 1258 | + * off of. |
|
| 1259 | + * @throws EE_error |
|
| 1260 | + */ |
|
| 1261 | + public function add_message_template($message_type, $messenger, $GRP_ID) |
|
| 1262 | + { |
|
| 1263 | + $this->_add_message_template($message_type, $messenger, $GRP_ID); |
|
| 1264 | + } |
|
| 1265 | 1265 | |
| 1266 | 1266 | |
| 1267 | - /** |
|
| 1268 | - * _edit_message_template |
|
| 1269 | - * |
|
| 1270 | - * @access protected |
|
| 1271 | - * @return void |
|
| 1272 | - * @throws InvalidIdentifierException |
|
| 1273 | - * @throws DomainException |
|
| 1274 | - * @throws EE_Error |
|
| 1275 | - * @throws InvalidArgumentException |
|
| 1276 | - * @throws ReflectionException |
|
| 1277 | - * @throws InvalidDataTypeException |
|
| 1278 | - * @throws InvalidInterfaceException |
|
| 1279 | - */ |
|
| 1280 | - protected function _edit_message_template() |
|
| 1281 | - { |
|
| 1282 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1283 | - $template_fields = ''; |
|
| 1284 | - $sidebar_fields = ''; |
|
| 1285 | - //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1286 | - // valid html in the templates. |
|
| 1287 | - add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1288 | - |
|
| 1289 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1290 | - ? absint($this->_req_data['id']) |
|
| 1291 | - : false; |
|
| 1292 | - |
|
| 1293 | - $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1294 | - $message_template_group = $this->_message_template_group; |
|
| 1295 | - $c_label = $message_template_group->context_label(); |
|
| 1296 | - $c_config = $message_template_group->contexts_config(); |
|
| 1297 | - |
|
| 1298 | - reset($c_config); |
|
| 1299 | - $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1300 | - ? strtolower($this->_req_data['context']) |
|
| 1301 | - : key($c_config); |
|
| 1302 | - |
|
| 1303 | - |
|
| 1304 | - if (empty($GRP_ID)) { |
|
| 1305 | - $action = 'insert_message_template'; |
|
| 1306 | - $edit_message_template_form_url = add_query_arg( |
|
| 1307 | - array('action' => $action, 'noheader' => true), |
|
| 1308 | - EE_MSG_ADMIN_URL |
|
| 1309 | - ); |
|
| 1310 | - } else { |
|
| 1311 | - $action = 'update_message_template'; |
|
| 1312 | - $edit_message_template_form_url = add_query_arg( |
|
| 1313 | - array('action' => $action, 'noheader' => true), |
|
| 1314 | - EE_MSG_ADMIN_URL |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - //set active messenger for this view |
|
| 1319 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1320 | - $message_template_group->messenger() |
|
| 1321 | - ); |
|
| 1322 | - $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - //Do we have any validation errors? |
|
| 1326 | - $validators = $this->_get_transient(); |
|
| 1327 | - $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1328 | - |
|
| 1329 | - |
|
| 1330 | - //we need to assemble the title from Various details |
|
| 1331 | - $context_label = sprintf( |
|
| 1332 | - esc_html__('(%s %s)', 'event_espresso'), |
|
| 1333 | - $c_config[$context]['label'], |
|
| 1334 | - ucwords($c_label['label']) |
|
| 1335 | - ); |
|
| 1336 | - |
|
| 1337 | - $title = sprintf( |
|
| 1338 | - esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1339 | - ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1340 | - ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1341 | - $context_label |
|
| 1342 | - ); |
|
| 1343 | - |
|
| 1344 | - $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1345 | - $this->_template_args['message_template'] = $message_template_group; |
|
| 1346 | - $this->_template_args['is_extra_fields'] = false; |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - //let's get EEH_MSG_Template so we can get template form fields |
|
| 1350 | - $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1351 | - $message_template_group->messenger(), |
|
| 1352 | - $message_template_group->message_type() |
|
| 1353 | - ); |
|
| 1354 | - |
|
| 1355 | - if ( ! $template_field_structure) { |
|
| 1356 | - $template_field_structure = false; |
|
| 1357 | - $template_fields = esc_html__( |
|
| 1358 | - 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1359 | - 'event_espresso' |
|
| 1360 | - ); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - |
|
| 1364 | - $message_templates = $message_template_group->context_templates(); |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1368 | - // will get handled in the "extra" array. |
|
| 1369 | - if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1370 | - foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1371 | - unset($template_field_structure[$context][$reference_field]); |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1376 | - if ( ! empty($template_field_structure)) { |
|
| 1377 | - foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1378 | - //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1379 | - // the extra array and reset them. |
|
| 1380 | - if ($template_field === 'extra') { |
|
| 1381 | - $this->_template_args['is_extra_fields'] = true; |
|
| 1382 | - foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1383 | - $message_template = $message_templates[$context][$reference_field]; |
|
| 1384 | - $content = $message_template instanceof EE_Message_Template |
|
| 1385 | - ? $message_template->get('MTP_content') |
|
| 1386 | - : ''; |
|
| 1387 | - foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1388 | - //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1389 | - $continue = false; |
|
| 1390 | - if (isset($extra_array['shortcodes_required'])) { |
|
| 1391 | - foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1392 | - if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1393 | - $continue = true; |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - if ($continue) { |
|
| 1397 | - continue; |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1267 | + /** |
|
| 1268 | + * _edit_message_template |
|
| 1269 | + * |
|
| 1270 | + * @access protected |
|
| 1271 | + * @return void |
|
| 1272 | + * @throws InvalidIdentifierException |
|
| 1273 | + * @throws DomainException |
|
| 1274 | + * @throws EE_Error |
|
| 1275 | + * @throws InvalidArgumentException |
|
| 1276 | + * @throws ReflectionException |
|
| 1277 | + * @throws InvalidDataTypeException |
|
| 1278 | + * @throws InvalidInterfaceException |
|
| 1279 | + */ |
|
| 1280 | + protected function _edit_message_template() |
|
| 1281 | + { |
|
| 1282 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1283 | + $template_fields = ''; |
|
| 1284 | + $sidebar_fields = ''; |
|
| 1285 | + //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have |
|
| 1286 | + // valid html in the templates. |
|
| 1287 | + add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2); |
|
| 1288 | + |
|
| 1289 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 1290 | + ? absint($this->_req_data['id']) |
|
| 1291 | + : false; |
|
| 1292 | + |
|
| 1293 | + $this->_set_shortcodes(); //this also sets the _message_template property. |
|
| 1294 | + $message_template_group = $this->_message_template_group; |
|
| 1295 | + $c_label = $message_template_group->context_label(); |
|
| 1296 | + $c_config = $message_template_group->contexts_config(); |
|
| 1297 | + |
|
| 1298 | + reset($c_config); |
|
| 1299 | + $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context']) |
|
| 1300 | + ? strtolower($this->_req_data['context']) |
|
| 1301 | + : key($c_config); |
|
| 1302 | + |
|
| 1303 | + |
|
| 1304 | + if (empty($GRP_ID)) { |
|
| 1305 | + $action = 'insert_message_template'; |
|
| 1306 | + $edit_message_template_form_url = add_query_arg( |
|
| 1307 | + array('action' => $action, 'noheader' => true), |
|
| 1308 | + EE_MSG_ADMIN_URL |
|
| 1309 | + ); |
|
| 1310 | + } else { |
|
| 1311 | + $action = 'update_message_template'; |
|
| 1312 | + $edit_message_template_form_url = add_query_arg( |
|
| 1313 | + array('action' => $action, 'noheader' => true), |
|
| 1314 | + EE_MSG_ADMIN_URL |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + //set active messenger for this view |
|
| 1319 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 1320 | + $message_template_group->messenger() |
|
| 1321 | + ); |
|
| 1322 | + $this->_active_message_type_name = $message_template_group->message_type(); |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + //Do we have any validation errors? |
|
| 1326 | + $validators = $this->_get_transient(); |
|
| 1327 | + $v_fields = ! empty($validators) ? array_keys($validators) : array(); |
|
| 1328 | + |
|
| 1329 | + |
|
| 1330 | + //we need to assemble the title from Various details |
|
| 1331 | + $context_label = sprintf( |
|
| 1332 | + esc_html__('(%s %s)', 'event_espresso'), |
|
| 1333 | + $c_config[$context]['label'], |
|
| 1334 | + ucwords($c_label['label']) |
|
| 1335 | + ); |
|
| 1336 | + |
|
| 1337 | + $title = sprintf( |
|
| 1338 | + esc_html__(' %s %s Template %s', 'event_espresso'), |
|
| 1339 | + ucwords($message_template_group->messenger_obj()->label['singular']), |
|
| 1340 | + ucwords($message_template_group->message_type_obj()->label['singular']), |
|
| 1341 | + $context_label |
|
| 1342 | + ); |
|
| 1343 | + |
|
| 1344 | + $this->_template_args['GRP_ID'] = $GRP_ID; |
|
| 1345 | + $this->_template_args['message_template'] = $message_template_group; |
|
| 1346 | + $this->_template_args['is_extra_fields'] = false; |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + //let's get EEH_MSG_Template so we can get template form fields |
|
| 1350 | + $template_field_structure = EEH_MSG_Template::get_fields( |
|
| 1351 | + $message_template_group->messenger(), |
|
| 1352 | + $message_template_group->message_type() |
|
| 1353 | + ); |
|
| 1354 | + |
|
| 1355 | + if ( ! $template_field_structure) { |
|
| 1356 | + $template_field_structure = false; |
|
| 1357 | + $template_fields = esc_html__( |
|
| 1358 | + 'There was an error in assembling the fields for this display (you should see an error message)', |
|
| 1359 | + 'event_espresso' |
|
| 1360 | + ); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + |
|
| 1364 | + $message_templates = $message_template_group->context_templates(); |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + //if we have the extra key.. then we need to remove the content index from the template_field_structure as it |
|
| 1368 | + // will get handled in the "extra" array. |
|
| 1369 | + if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { |
|
| 1370 | + foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { |
|
| 1371 | + unset($template_field_structure[$context][$reference_field]); |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + //let's loop through the template_field_structure and actually assemble the input fields! |
|
| 1376 | + if ( ! empty($template_field_structure)) { |
|
| 1377 | + foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { |
|
| 1378 | + //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in |
|
| 1379 | + // the extra array and reset them. |
|
| 1380 | + if ($template_field === 'extra') { |
|
| 1381 | + $this->_template_args['is_extra_fields'] = true; |
|
| 1382 | + foreach ($field_setup_array as $reference_field => $new_fields_array) { |
|
| 1383 | + $message_template = $message_templates[$context][$reference_field]; |
|
| 1384 | + $content = $message_template instanceof EE_Message_Template |
|
| 1385 | + ? $message_template->get('MTP_content') |
|
| 1386 | + : ''; |
|
| 1387 | + foreach ($new_fields_array as $extra_field => $extra_array) { |
|
| 1388 | + //let's verify if we need this extra field via the shortcodes parameter. |
|
| 1389 | + $continue = false; |
|
| 1390 | + if (isset($extra_array['shortcodes_required'])) { |
|
| 1391 | + foreach ((array)$extra_array['shortcodes_required'] as $shortcode) { |
|
| 1392 | + if ( ! array_key_exists($shortcode, $this->_shortcodes)) { |
|
| 1393 | + $continue = true; |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + if ($continue) { |
|
| 1397 | + continue; |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | 1400 | |
| 1401 | - $field_id = $reference_field |
|
| 1402 | - . '-' |
|
| 1403 | - . $extra_field |
|
| 1404 | - . '-content'; |
|
| 1405 | - $template_form_fields[$field_id] = $extra_array; |
|
| 1406 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1407 | - . $reference_field |
|
| 1408 | - . '][content][' |
|
| 1409 | - . $extra_field . ']'; |
|
| 1410 | - $css_class = isset($extra_array['css_class']) |
|
| 1411 | - ? $extra_array['css_class'] |
|
| 1412 | - : ''; |
|
| 1401 | + $field_id = $reference_field |
|
| 1402 | + . '-' |
|
| 1403 | + . $extra_field |
|
| 1404 | + . '-content'; |
|
| 1405 | + $template_form_fields[$field_id] = $extra_array; |
|
| 1406 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' |
|
| 1407 | + . $reference_field |
|
| 1408 | + . '][content][' |
|
| 1409 | + . $extra_field . ']'; |
|
| 1410 | + $css_class = isset($extra_array['css_class']) |
|
| 1411 | + ? $extra_array['css_class'] |
|
| 1412 | + : ''; |
|
| 1413 | 1413 | |
| 1414 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1415 | - && in_array($extra_field, $v_fields, true) |
|
| 1416 | - && |
|
| 1417 | - ( |
|
| 1418 | - is_array($validators[$extra_field]) |
|
| 1419 | - && isset($validators[$extra_field]['msg']) |
|
| 1420 | - ) |
|
| 1421 | - ? 'validate-error ' . $css_class |
|
| 1422 | - : $css_class; |
|
| 1414 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1415 | + && in_array($extra_field, $v_fields, true) |
|
| 1416 | + && |
|
| 1417 | + ( |
|
| 1418 | + is_array($validators[$extra_field]) |
|
| 1419 | + && isset($validators[$extra_field]['msg']) |
|
| 1420 | + ) |
|
| 1421 | + ? 'validate-error ' . $css_class |
|
| 1422 | + : $css_class; |
|
| 1423 | 1423 | |
| 1424 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1425 | - && isset($content[$extra_field]) |
|
| 1426 | - ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1427 | - : ''; |
|
| 1424 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1425 | + && isset($content[$extra_field]) |
|
| 1426 | + ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8")) |
|
| 1427 | + : ''; |
|
| 1428 | 1428 | |
| 1429 | - //do we have a validation error? if we do then let's use that value instead |
|
| 1430 | - $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1431 | - ? $validators[$extra_field]['value'] |
|
| 1432 | - : $template_form_fields[$field_id]['value']; |
|
| 1429 | + //do we have a validation error? if we do then let's use that value instead |
|
| 1430 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) |
|
| 1431 | + ? $validators[$extra_field]['value'] |
|
| 1432 | + : $template_form_fields[$field_id]['value']; |
|
| 1433 | 1433 | |
| 1434 | 1434 | |
| 1435 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1435 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1436 | 1436 | |
| 1437 | - //shortcode selector |
|
| 1438 | - $field_name_to_use = $extra_field === 'main' |
|
| 1439 | - ? 'content' |
|
| 1440 | - : $extra_field; |
|
| 1441 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1442 | - $field_name_to_use, |
|
| 1443 | - $field_id |
|
| 1444 | - ); |
|
| 1437 | + //shortcode selector |
|
| 1438 | + $field_name_to_use = $extra_field === 'main' |
|
| 1439 | + ? 'content' |
|
| 1440 | + : $extra_field; |
|
| 1441 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1442 | + $field_name_to_use, |
|
| 1443 | + $field_id |
|
| 1444 | + ); |
|
| 1445 | 1445 | |
| 1446 | - if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1447 | - //we want to decode the entities |
|
| 1448 | - $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1449 | - html_entity_decode( |
|
| 1450 | - $template_form_fields[$field_id]['value'], |
|
| 1451 | - ENT_QUOTES, |
|
| 1452 | - "UTF-8") |
|
| 1453 | - ); |
|
| 1446 | + if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') { |
|
| 1447 | + //we want to decode the entities |
|
| 1448 | + $template_form_fields[$field_id]['value'] = stripslashes( |
|
| 1449 | + html_entity_decode( |
|
| 1450 | + $template_form_fields[$field_id]['value'], |
|
| 1451 | + ENT_QUOTES, |
|
| 1452 | + "UTF-8") |
|
| 1453 | + ); |
|
| 1454 | 1454 | |
| 1455 | - }/**/ |
|
| 1456 | - } |
|
| 1457 | - $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1458 | - $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1455 | + }/**/ |
|
| 1456 | + } |
|
| 1457 | + $templatefield_MTP_id = $reference_field . '-MTP_ID'; |
|
| 1458 | + $templatefield_templatename_id = $reference_field . '-name'; |
|
| 1459 | 1459 | |
| 1460 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1461 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1462 | - 'label' => null, |
|
| 1463 | - 'input' => 'hidden', |
|
| 1464 | - 'type' => 'int', |
|
| 1465 | - 'required' => false, |
|
| 1466 | - 'validation' => false, |
|
| 1467 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1468 | - 'css_class' => '', |
|
| 1469 | - 'format' => '%d', |
|
| 1470 | - 'db-col' => 'MTP_ID' |
|
| 1471 | - ); |
|
| 1460 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1461 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]', |
|
| 1462 | + 'label' => null, |
|
| 1463 | + 'input' => 'hidden', |
|
| 1464 | + 'type' => 'int', |
|
| 1465 | + 'required' => false, |
|
| 1466 | + 'validation' => false, |
|
| 1467 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '', |
|
| 1468 | + 'css_class' => '', |
|
| 1469 | + 'format' => '%d', |
|
| 1470 | + 'db-col' => 'MTP_ID' |
|
| 1471 | + ); |
|
| 1472 | 1472 | |
| 1473 | - $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1474 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1475 | - 'label' => null, |
|
| 1476 | - 'input' => 'hidden', |
|
| 1477 | - 'type' => 'string', |
|
| 1478 | - 'required' => false, |
|
| 1479 | - 'validation' => true, |
|
| 1480 | - 'value' => $reference_field, |
|
| 1481 | - 'css_class' => '', |
|
| 1482 | - 'format' => '%s', |
|
| 1483 | - 'db-col' => 'MTP_template_field' |
|
| 1484 | - ); |
|
| 1485 | - } |
|
| 1486 | - continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1487 | - } else { |
|
| 1488 | - $field_id = $template_field . '-content'; |
|
| 1489 | - $template_form_fields[$field_id] = $field_setup_array; |
|
| 1490 | - $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1491 | - $message_template = isset($message_templates[$context][$template_field]) |
|
| 1492 | - ? $message_templates[$context][$template_field] |
|
| 1493 | - : null; |
|
| 1494 | - $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1495 | - && is_array($message_templates[$context]) |
|
| 1496 | - && $message_template instanceof EE_Message_Template |
|
| 1497 | - ? $message_template->get('MTP_content') |
|
| 1498 | - : ''; |
|
| 1473 | + $template_form_fields[$templatefield_templatename_id] = array( |
|
| 1474 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]', |
|
| 1475 | + 'label' => null, |
|
| 1476 | + 'input' => 'hidden', |
|
| 1477 | + 'type' => 'string', |
|
| 1478 | + 'required' => false, |
|
| 1479 | + 'validation' => true, |
|
| 1480 | + 'value' => $reference_field, |
|
| 1481 | + 'css_class' => '', |
|
| 1482 | + 'format' => '%s', |
|
| 1483 | + 'db-col' => 'MTP_template_field' |
|
| 1484 | + ); |
|
| 1485 | + } |
|
| 1486 | + continue; //skip the next stuff, we got the necessary fields here for this dataset. |
|
| 1487 | + } else { |
|
| 1488 | + $field_id = $template_field . '-content'; |
|
| 1489 | + $template_form_fields[$field_id] = $field_setup_array; |
|
| 1490 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; |
|
| 1491 | + $message_template = isset($message_templates[$context][$template_field]) |
|
| 1492 | + ? $message_templates[$context][$template_field] |
|
| 1493 | + : null; |
|
| 1494 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates) |
|
| 1495 | + && is_array($message_templates[$context]) |
|
| 1496 | + && $message_template instanceof EE_Message_Template |
|
| 1497 | + ? $message_template->get('MTP_content') |
|
| 1498 | + : ''; |
|
| 1499 | 1499 | |
| 1500 | - //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1501 | - $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1502 | - ? $validators[$template_field]['value'] |
|
| 1503 | - : $template_form_fields[$field_id]['value']; |
|
| 1500 | + //do we have a validator error for this field? if we do then we'll use that value instead |
|
| 1501 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field]) |
|
| 1502 | + ? $validators[$template_field]['value'] |
|
| 1503 | + : $template_form_fields[$field_id]['value']; |
|
| 1504 | 1504 | |
| 1505 | 1505 | |
| 1506 | - $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1507 | - $css_class = isset($field_setup_array['css_class']) |
|
| 1508 | - ? $field_setup_array['css_class'] |
|
| 1509 | - : ''; |
|
| 1510 | - $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1511 | - && in_array($template_field, $v_fields, true) |
|
| 1512 | - && isset($validators[$template_field]['msg']) |
|
| 1513 | - ? 'validate-error ' . $css_class |
|
| 1514 | - : $css_class; |
|
| 1506 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content'; |
|
| 1507 | + $css_class = isset($field_setup_array['css_class']) |
|
| 1508 | + ? $field_setup_array['css_class'] |
|
| 1509 | + : ''; |
|
| 1510 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields) |
|
| 1511 | + && in_array($template_field, $v_fields, true) |
|
| 1512 | + && isset($validators[$template_field]['msg']) |
|
| 1513 | + ? 'validate-error ' . $css_class |
|
| 1514 | + : $css_class; |
|
| 1515 | 1515 | |
| 1516 | - //shortcode selector |
|
| 1517 | - $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1518 | - $template_field, $field_id |
|
| 1519 | - ); |
|
| 1520 | - } |
|
| 1516 | + //shortcode selector |
|
| 1517 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector( |
|
| 1518 | + $template_field, $field_id |
|
| 1519 | + ); |
|
| 1520 | + } |
|
| 1521 | 1521 | |
| 1522 | - //k took care of content field(s) now let's take care of others. |
|
| 1522 | + //k took care of content field(s) now let's take care of others. |
|
| 1523 | 1523 | |
| 1524 | - $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1525 | - $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1524 | + $templatefield_MTP_id = $template_field . '-MTP_ID'; |
|
| 1525 | + $templatefield_field_templatename_id = $template_field . '-name'; |
|
| 1526 | 1526 | |
| 1527 | - //foreach template field there are actually two form fields created |
|
| 1528 | - $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1529 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1530 | - 'label' => null, |
|
| 1531 | - 'input' => 'hidden', |
|
| 1532 | - 'type' => 'int', |
|
| 1533 | - 'required' => false, |
|
| 1534 | - 'validation' => true, |
|
| 1535 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1536 | - 'css_class' => '', |
|
| 1537 | - 'format' => '%d', |
|
| 1538 | - 'db-col' => 'MTP_ID' |
|
| 1539 | - ); |
|
| 1527 | + //foreach template field there are actually two form fields created |
|
| 1528 | + $template_form_fields[$templatefield_MTP_id] = array( |
|
| 1529 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]', |
|
| 1530 | + 'label' => null, |
|
| 1531 | + 'input' => 'hidden', |
|
| 1532 | + 'type' => 'int', |
|
| 1533 | + 'required' => false, |
|
| 1534 | + 'validation' => true, |
|
| 1535 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '', |
|
| 1536 | + 'css_class' => '', |
|
| 1537 | + 'format' => '%d', |
|
| 1538 | + 'db-col' => 'MTP_ID' |
|
| 1539 | + ); |
|
| 1540 | 1540 | |
| 1541 | - $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1542 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1543 | - 'label' => null, |
|
| 1544 | - 'input' => 'hidden', |
|
| 1545 | - 'type' => 'string', |
|
| 1546 | - 'required' => false, |
|
| 1547 | - 'validation' => true, |
|
| 1548 | - 'value' => $template_field, |
|
| 1549 | - 'css_class' => '', |
|
| 1550 | - 'format' => '%s', |
|
| 1551 | - 'db-col' => 'MTP_template_field' |
|
| 1552 | - ); |
|
| 1541 | + $template_form_fields[$templatefield_field_templatename_id] = array( |
|
| 1542 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]', |
|
| 1543 | + 'label' => null, |
|
| 1544 | + 'input' => 'hidden', |
|
| 1545 | + 'type' => 'string', |
|
| 1546 | + 'required' => false, |
|
| 1547 | + 'validation' => true, |
|
| 1548 | + 'value' => $template_field, |
|
| 1549 | + 'css_class' => '', |
|
| 1550 | + 'format' => '%s', |
|
| 1551 | + 'db-col' => 'MTP_template_field' |
|
| 1552 | + ); |
|
| 1553 | 1553 | |
| 1554 | - } |
|
| 1554 | + } |
|
| 1555 | 1555 | |
| 1556 | - //add other fields |
|
| 1557 | - $template_form_fields['ee-msg-current-context'] = array( |
|
| 1558 | - 'name' => 'MTP_context', |
|
| 1559 | - 'label' => null, |
|
| 1560 | - 'input' => 'hidden', |
|
| 1561 | - 'type' => 'string', |
|
| 1562 | - 'required' => false, |
|
| 1563 | - 'validation' => true, |
|
| 1564 | - 'value' => $context, |
|
| 1565 | - 'css_class' => '', |
|
| 1566 | - 'format' => '%s', |
|
| 1567 | - 'db-col' => 'MTP_context' |
|
| 1568 | - ); |
|
| 1556 | + //add other fields |
|
| 1557 | + $template_form_fields['ee-msg-current-context'] = array( |
|
| 1558 | + 'name' => 'MTP_context', |
|
| 1559 | + 'label' => null, |
|
| 1560 | + 'input' => 'hidden', |
|
| 1561 | + 'type' => 'string', |
|
| 1562 | + 'required' => false, |
|
| 1563 | + 'validation' => true, |
|
| 1564 | + 'value' => $context, |
|
| 1565 | + 'css_class' => '', |
|
| 1566 | + 'format' => '%s', |
|
| 1567 | + 'db-col' => 'MTP_context' |
|
| 1568 | + ); |
|
| 1569 | 1569 | |
| 1570 | - $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1571 | - 'name' => 'GRP_ID', |
|
| 1572 | - 'label' => null, |
|
| 1573 | - 'input' => 'hidden', |
|
| 1574 | - 'type' => 'int', |
|
| 1575 | - 'required' => false, |
|
| 1576 | - 'validation' => true, |
|
| 1577 | - 'value' => $GRP_ID, |
|
| 1578 | - 'css_class' => '', |
|
| 1579 | - 'format' => '%d', |
|
| 1580 | - 'db-col' => 'GRP_ID' |
|
| 1581 | - ); |
|
| 1570 | + $template_form_fields['ee-msg-grp-id'] = array( |
|
| 1571 | + 'name' => 'GRP_ID', |
|
| 1572 | + 'label' => null, |
|
| 1573 | + 'input' => 'hidden', |
|
| 1574 | + 'type' => 'int', |
|
| 1575 | + 'required' => false, |
|
| 1576 | + 'validation' => true, |
|
| 1577 | + 'value' => $GRP_ID, |
|
| 1578 | + 'css_class' => '', |
|
| 1579 | + 'format' => '%d', |
|
| 1580 | + 'db-col' => 'GRP_ID' |
|
| 1581 | + ); |
|
| 1582 | 1582 | |
| 1583 | - $template_form_fields['ee-msg-messenger'] = array( |
|
| 1584 | - 'name' => 'MTP_messenger', |
|
| 1585 | - 'label' => null, |
|
| 1586 | - 'input' => 'hidden', |
|
| 1587 | - 'type' => 'string', |
|
| 1588 | - 'required' => false, |
|
| 1589 | - 'validation' => true, |
|
| 1590 | - 'value' => $message_template_group->messenger(), |
|
| 1591 | - 'css_class' => '', |
|
| 1592 | - 'format' => '%s', |
|
| 1593 | - 'db-col' => 'MTP_messenger' |
|
| 1594 | - ); |
|
| 1583 | + $template_form_fields['ee-msg-messenger'] = array( |
|
| 1584 | + 'name' => 'MTP_messenger', |
|
| 1585 | + 'label' => null, |
|
| 1586 | + 'input' => 'hidden', |
|
| 1587 | + 'type' => 'string', |
|
| 1588 | + 'required' => false, |
|
| 1589 | + 'validation' => true, |
|
| 1590 | + 'value' => $message_template_group->messenger(), |
|
| 1591 | + 'css_class' => '', |
|
| 1592 | + 'format' => '%s', |
|
| 1593 | + 'db-col' => 'MTP_messenger' |
|
| 1594 | + ); |
|
| 1595 | 1595 | |
| 1596 | - $template_form_fields['ee-msg-message-type'] = array( |
|
| 1597 | - 'name' => 'MTP_message_type', |
|
| 1598 | - 'label' => null, |
|
| 1599 | - 'input' => 'hidden', |
|
| 1600 | - 'type' => 'string', |
|
| 1601 | - 'required' => false, |
|
| 1602 | - 'validation' => true, |
|
| 1603 | - 'value' => $message_template_group->message_type(), |
|
| 1604 | - 'css_class' => '', |
|
| 1605 | - 'format' => '%s', |
|
| 1606 | - 'db-col' => 'MTP_message_type' |
|
| 1607 | - ); |
|
| 1596 | + $template_form_fields['ee-msg-message-type'] = array( |
|
| 1597 | + 'name' => 'MTP_message_type', |
|
| 1598 | + 'label' => null, |
|
| 1599 | + 'input' => 'hidden', |
|
| 1600 | + 'type' => 'string', |
|
| 1601 | + 'required' => false, |
|
| 1602 | + 'validation' => true, |
|
| 1603 | + 'value' => $message_template_group->message_type(), |
|
| 1604 | + 'css_class' => '', |
|
| 1605 | + 'format' => '%s', |
|
| 1606 | + 'db-col' => 'MTP_message_type' |
|
| 1607 | + ); |
|
| 1608 | 1608 | |
| 1609 | - $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1610 | - 'name' => 'MTP_is_global', |
|
| 1611 | - 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1612 | - 'input' => 'hidden', |
|
| 1613 | - 'type' => 'int', |
|
| 1614 | - 'required' => false, |
|
| 1615 | - 'validation' => true, |
|
| 1616 | - 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1617 | - 'css_class' => '', |
|
| 1618 | - 'format' => '%d', |
|
| 1619 | - 'db-col' => 'MTP_is_global' |
|
| 1620 | - ); |
|
| 1609 | + $sidebar_form_fields['ee-msg-is-global'] = array( |
|
| 1610 | + 'name' => 'MTP_is_global', |
|
| 1611 | + 'label' => esc_html__('Global Template', 'event_espresso'), |
|
| 1612 | + 'input' => 'hidden', |
|
| 1613 | + 'type' => 'int', |
|
| 1614 | + 'required' => false, |
|
| 1615 | + 'validation' => true, |
|
| 1616 | + 'value' => $message_template_group->get('MTP_is_global'), |
|
| 1617 | + 'css_class' => '', |
|
| 1618 | + 'format' => '%d', |
|
| 1619 | + 'db-col' => 'MTP_is_global' |
|
| 1620 | + ); |
|
| 1621 | 1621 | |
| 1622 | - $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1623 | - 'name' => 'MTP_is_override', |
|
| 1624 | - 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1625 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1626 | - 'type' => 'int', |
|
| 1627 | - 'required' => false, |
|
| 1628 | - 'validation' => true, |
|
| 1629 | - 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1630 | - 'css_class' => '', |
|
| 1631 | - 'format' => '%d', |
|
| 1632 | - 'db-col' => 'MTP_is_override' |
|
| 1633 | - ); |
|
| 1622 | + $sidebar_form_fields['ee-msg-is-override'] = array( |
|
| 1623 | + 'name' => 'MTP_is_override', |
|
| 1624 | + 'label' => esc_html__('Override all custom', 'event_espresso'), |
|
| 1625 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden', |
|
| 1626 | + 'type' => 'int', |
|
| 1627 | + 'required' => false, |
|
| 1628 | + 'validation' => true, |
|
| 1629 | + 'value' => $message_template_group->get('MTP_is_override'), |
|
| 1630 | + 'css_class' => '', |
|
| 1631 | + 'format' => '%d', |
|
| 1632 | + 'db-col' => 'MTP_is_override' |
|
| 1633 | + ); |
|
| 1634 | 1634 | |
| 1635 | - $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1636 | - 'name' => 'MTP_is_active', |
|
| 1637 | - 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1638 | - 'input' => 'hidden', |
|
| 1639 | - 'type' => 'int', |
|
| 1640 | - 'required' => false, |
|
| 1641 | - 'validation' => true, |
|
| 1642 | - 'value' => $message_template_group->is_active(), |
|
| 1643 | - 'css_class' => '', |
|
| 1644 | - 'format' => '%d', |
|
| 1645 | - 'db-col' => 'MTP_is_active' |
|
| 1646 | - ); |
|
| 1635 | + $sidebar_form_fields['ee-msg-is-active'] = array( |
|
| 1636 | + 'name' => 'MTP_is_active', |
|
| 1637 | + 'label' => esc_html__('Active Template', 'event_espresso'), |
|
| 1638 | + 'input' => 'hidden', |
|
| 1639 | + 'type' => 'int', |
|
| 1640 | + 'required' => false, |
|
| 1641 | + 'validation' => true, |
|
| 1642 | + 'value' => $message_template_group->is_active(), |
|
| 1643 | + 'css_class' => '', |
|
| 1644 | + 'format' => '%d', |
|
| 1645 | + 'db-col' => 'MTP_is_active' |
|
| 1646 | + ); |
|
| 1647 | 1647 | |
| 1648 | - $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1649 | - 'name' => 'MTP_deleted', |
|
| 1650 | - 'label' => null, |
|
| 1651 | - 'input' => 'hidden', |
|
| 1652 | - 'type' => 'int', |
|
| 1653 | - 'required' => false, |
|
| 1654 | - 'validation' => true, |
|
| 1655 | - 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1656 | - 'css_class' => '', |
|
| 1657 | - 'format' => '%d', |
|
| 1658 | - 'db-col' => 'MTP_deleted' |
|
| 1659 | - ); |
|
| 1660 | - $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1661 | - 'name' => 'MTP_user_id', |
|
| 1662 | - 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1663 | - 'input' => 'hidden', |
|
| 1664 | - 'type' => 'int', |
|
| 1665 | - 'required' => false, |
|
| 1666 | - 'validation' => false, |
|
| 1667 | - 'value' => $message_template_group->user(), |
|
| 1668 | - 'format' => '%d', |
|
| 1669 | - 'db-col' => 'MTP_user_id' |
|
| 1670 | - ); |
|
| 1648 | + $sidebar_form_fields['ee-msg-deleted'] = array( |
|
| 1649 | + 'name' => 'MTP_deleted', |
|
| 1650 | + 'label' => null, |
|
| 1651 | + 'input' => 'hidden', |
|
| 1652 | + 'type' => 'int', |
|
| 1653 | + 'required' => false, |
|
| 1654 | + 'validation' => true, |
|
| 1655 | + 'value' => $message_template_group->get('MTP_deleted'), |
|
| 1656 | + 'css_class' => '', |
|
| 1657 | + 'format' => '%d', |
|
| 1658 | + 'db-col' => 'MTP_deleted' |
|
| 1659 | + ); |
|
| 1660 | + $sidebar_form_fields['ee-msg-author'] = array( |
|
| 1661 | + 'name' => 'MTP_user_id', |
|
| 1662 | + 'label' => esc_html__('Author', 'event_espresso'), |
|
| 1663 | + 'input' => 'hidden', |
|
| 1664 | + 'type' => 'int', |
|
| 1665 | + 'required' => false, |
|
| 1666 | + 'validation' => false, |
|
| 1667 | + 'value' => $message_template_group->user(), |
|
| 1668 | + 'format' => '%d', |
|
| 1669 | + 'db-col' => 'MTP_user_id' |
|
| 1670 | + ); |
|
| 1671 | 1671 | |
| 1672 | - $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1673 | - 'name' => 'action', |
|
| 1674 | - 'input' => 'hidden', |
|
| 1675 | - 'type' => 'string', |
|
| 1676 | - 'value' => $action |
|
| 1677 | - ); |
|
| 1672 | + $sidebar_form_fields['ee-msg-route'] = array( |
|
| 1673 | + 'name' => 'action', |
|
| 1674 | + 'input' => 'hidden', |
|
| 1675 | + 'type' => 'string', |
|
| 1676 | + 'value' => $action |
|
| 1677 | + ); |
|
| 1678 | 1678 | |
| 1679 | - $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1680 | - 'name' => 'id', |
|
| 1681 | - 'input' => 'hidden', |
|
| 1682 | - 'type' => 'int', |
|
| 1683 | - 'value' => $GRP_ID |
|
| 1684 | - ); |
|
| 1685 | - $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1686 | - 'name' => $action . '_nonce', |
|
| 1687 | - 'input' => 'hidden', |
|
| 1688 | - 'type' => 'string', |
|
| 1689 | - 'value' => wp_create_nonce($action . '_nonce') |
|
| 1690 | - ); |
|
| 1679 | + $sidebar_form_fields['ee-msg-id'] = array( |
|
| 1680 | + 'name' => 'id', |
|
| 1681 | + 'input' => 'hidden', |
|
| 1682 | + 'type' => 'int', |
|
| 1683 | + 'value' => $GRP_ID |
|
| 1684 | + ); |
|
| 1685 | + $sidebar_form_fields['ee-msg-evt-nonce'] = array( |
|
| 1686 | + 'name' => $action . '_nonce', |
|
| 1687 | + 'input' => 'hidden', |
|
| 1688 | + 'type' => 'string', |
|
| 1689 | + 'value' => wp_create_nonce($action . '_nonce') |
|
| 1690 | + ); |
|
| 1691 | 1691 | |
| 1692 | - if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1693 | - $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1694 | - 'name' => 'template_switch', |
|
| 1695 | - 'input' => 'hidden', |
|
| 1696 | - 'type' => 'int', |
|
| 1697 | - 'value' => 1 |
|
| 1698 | - ); |
|
| 1699 | - } |
|
| 1692 | + if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) { |
|
| 1693 | + $sidebar_form_fields['ee-msg-template-switch'] = array( |
|
| 1694 | + 'name' => 'template_switch', |
|
| 1695 | + 'input' => 'hidden', |
|
| 1696 | + 'type' => 'int', |
|
| 1697 | + 'value' => 1 |
|
| 1698 | + ); |
|
| 1699 | + } |
|
| 1700 | 1700 | |
| 1701 | 1701 | |
| 1702 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1703 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1702 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields); |
|
| 1703 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields); |
|
| 1704 | 1704 | |
| 1705 | 1705 | |
| 1706 | - } //end if ( !empty($template_field_structure) ) |
|
| 1707 | - |
|
| 1708 | - //set extra content for publish box |
|
| 1709 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1710 | - $this->_set_publish_post_box_vars( |
|
| 1711 | - 'id', |
|
| 1712 | - $GRP_ID, |
|
| 1713 | - false, |
|
| 1714 | - add_query_arg( |
|
| 1715 | - array('action' => 'global_mtps'), |
|
| 1716 | - $this->_admin_base_url |
|
| 1717 | - ) |
|
| 1718 | - ); |
|
| 1719 | - |
|
| 1720 | - //add preview button |
|
| 1721 | - $preview_url = parent::add_query_args_and_nonce( |
|
| 1722 | - array( |
|
| 1723 | - 'message_type' => $message_template_group->message_type(), |
|
| 1724 | - 'messenger' => $message_template_group->messenger(), |
|
| 1725 | - 'context' => $context, |
|
| 1726 | - 'GRP_ID' => $GRP_ID, |
|
| 1727 | - 'action' => 'preview_message' |
|
| 1728 | - ), |
|
| 1729 | - $this->_admin_base_url |
|
| 1730 | - ); |
|
| 1731 | - $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1732 | - . esc_html__('Preview', 'event_espresso') |
|
| 1733 | - . '</a>'; |
|
| 1734 | - |
|
| 1735 | - |
|
| 1736 | - //setup context switcher |
|
| 1737 | - $context_switcher_args = array( |
|
| 1738 | - 'page' => 'espresso_messages', |
|
| 1739 | - 'action' => 'edit_message_template', |
|
| 1740 | - 'id' => $GRP_ID, |
|
| 1741 | - 'context' => $context, |
|
| 1742 | - 'extra' => $preview_button |
|
| 1743 | - ); |
|
| 1744 | - $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1745 | - |
|
| 1746 | - |
|
| 1747 | - //main box |
|
| 1748 | - $this->_template_args['template_fields'] = $template_fields; |
|
| 1749 | - $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1750 | - $this->_template_args['action'] = $action; |
|
| 1751 | - $this->_template_args['context'] = $context; |
|
| 1752 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1753 | - $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1754 | - $this->_learn_more_about_message_templates_link(); |
|
| 1755 | - |
|
| 1756 | - |
|
| 1757 | - $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1758 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1759 | - $message_template_group, |
|
| 1760 | - $context, |
|
| 1761 | - $context_label |
|
| 1762 | - ); |
|
| 1763 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1764 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1765 | - |
|
| 1766 | - $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1767 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1768 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1769 | - |
|
| 1770 | - //send along EE_Message_Template_Group object for further template use. |
|
| 1771 | - $this->_template_args['MTP'] = $message_template_group; |
|
| 1772 | - |
|
| 1773 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1774 | - $this->_template_path, |
|
| 1775 | - $this->_template_args, |
|
| 1776 | - true |
|
| 1777 | - ); |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - //finally, let's set the admin_page title |
|
| 1781 | - $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1782 | - |
|
| 1783 | - |
|
| 1784 | - //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1785 | - $this->_set_shortcodes(); |
|
| 1786 | - |
|
| 1787 | - |
|
| 1788 | - //final template wrapper |
|
| 1789 | - $this->display_admin_page_with_sidebar(); |
|
| 1790 | - } |
|
| 1706 | + } //end if ( !empty($template_field_structure) ) |
|
| 1707 | + |
|
| 1708 | + //set extra content for publish box |
|
| 1709 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields; |
|
| 1710 | + $this->_set_publish_post_box_vars( |
|
| 1711 | + 'id', |
|
| 1712 | + $GRP_ID, |
|
| 1713 | + false, |
|
| 1714 | + add_query_arg( |
|
| 1715 | + array('action' => 'global_mtps'), |
|
| 1716 | + $this->_admin_base_url |
|
| 1717 | + ) |
|
| 1718 | + ); |
|
| 1719 | + |
|
| 1720 | + //add preview button |
|
| 1721 | + $preview_url = parent::add_query_args_and_nonce( |
|
| 1722 | + array( |
|
| 1723 | + 'message_type' => $message_template_group->message_type(), |
|
| 1724 | + 'messenger' => $message_template_group->messenger(), |
|
| 1725 | + 'context' => $context, |
|
| 1726 | + 'GRP_ID' => $GRP_ID, |
|
| 1727 | + 'action' => 'preview_message' |
|
| 1728 | + ), |
|
| 1729 | + $this->_admin_base_url |
|
| 1730 | + ); |
|
| 1731 | + $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' |
|
| 1732 | + . esc_html__('Preview', 'event_espresso') |
|
| 1733 | + . '</a>'; |
|
| 1734 | + |
|
| 1735 | + |
|
| 1736 | + //setup context switcher |
|
| 1737 | + $context_switcher_args = array( |
|
| 1738 | + 'page' => 'espresso_messages', |
|
| 1739 | + 'action' => 'edit_message_template', |
|
| 1740 | + 'id' => $GRP_ID, |
|
| 1741 | + 'context' => $context, |
|
| 1742 | + 'extra' => $preview_button |
|
| 1743 | + ); |
|
| 1744 | + $this->_set_context_switcher($message_template_group, $context_switcher_args); |
|
| 1745 | + |
|
| 1746 | + |
|
| 1747 | + //main box |
|
| 1748 | + $this->_template_args['template_fields'] = $template_fields; |
|
| 1749 | + $this->_template_args['sidebar_box_id'] = 'details'; |
|
| 1750 | + $this->_template_args['action'] = $action; |
|
| 1751 | + $this->_template_args['context'] = $context; |
|
| 1752 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url; |
|
| 1753 | + $this->_template_args['learn_more_about_message_templates_link'] = |
|
| 1754 | + $this->_learn_more_about_message_templates_link(); |
|
| 1755 | + |
|
| 1756 | + |
|
| 1757 | + $this->_template_args['before_admin_page_content'] = $this->add_context_switcher(); |
|
| 1758 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element( |
|
| 1759 | + $message_template_group, |
|
| 1760 | + $context, |
|
| 1761 | + $context_label |
|
| 1762 | + ); |
|
| 1763 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before(); |
|
| 1764 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after(); |
|
| 1765 | + |
|
| 1766 | + $this->_template_path = $this->_template_args['GRP_ID'] |
|
| 1767 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php' |
|
| 1768 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php'; |
|
| 1769 | + |
|
| 1770 | + //send along EE_Message_Template_Group object for further template use. |
|
| 1771 | + $this->_template_args['MTP'] = $message_template_group; |
|
| 1772 | + |
|
| 1773 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 1774 | + $this->_template_path, |
|
| 1775 | + $this->_template_args, |
|
| 1776 | + true |
|
| 1777 | + ); |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + //finally, let's set the admin_page title |
|
| 1781 | + $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title); |
|
| 1782 | + |
|
| 1783 | + |
|
| 1784 | + //we need to take care of setting the shortcodes property for use elsewhere. |
|
| 1785 | + $this->_set_shortcodes(); |
|
| 1786 | + |
|
| 1787 | + |
|
| 1788 | + //final template wrapper |
|
| 1789 | + $this->display_admin_page_with_sidebar(); |
|
| 1790 | + } |
|
| 1791 | 1791 | |
| 1792 | 1792 | |
| 1793 | - public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1794 | - { |
|
| 1795 | - return $mceInit; |
|
| 1796 | - } |
|
| 1793 | + public function filter_tinymce_init($mceInit, $editor_id) |
|
| 1794 | + { |
|
| 1795 | + return $mceInit; |
|
| 1796 | + } |
|
| 1797 | 1797 | |
| 1798 | 1798 | |
| 1799 | - public function add_context_switcher() |
|
| 1800 | - { |
|
| 1801 | - return $this->_context_switcher; |
|
| 1802 | - } |
|
| 1799 | + public function add_context_switcher() |
|
| 1800 | + { |
|
| 1801 | + return $this->_context_switcher; |
|
| 1802 | + } |
|
| 1803 | 1803 | |
| 1804 | 1804 | |
| 1805 | - /** |
|
| 1806 | - * Adds the activation/deactivation toggle for the message template context. |
|
| 1807 | - * |
|
| 1808 | - * @param EE_Message_Template_Group $message_template_group |
|
| 1809 | - * @param string $context |
|
| 1810 | - * @param string $context_label |
|
| 1811 | - * @return string |
|
| 1812 | - * @throws DomainException |
|
| 1813 | - * @throws EE_Error |
|
| 1814 | - * @throws InvalidIdentifierException |
|
| 1815 | - */ |
|
| 1816 | - protected function add_active_context_element( |
|
| 1817 | - EE_Message_Template_Group $message_template_group, |
|
| 1818 | - $context, |
|
| 1819 | - $context_label |
|
| 1820 | - ) { |
|
| 1821 | - $template_args = array( |
|
| 1822 | - 'context' => $context, |
|
| 1823 | - 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1824 | - 'is_active' => $message_template_group->is_context_active($context), |
|
| 1825 | - 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1826 | - ? 'context-off' |
|
| 1827 | - : 'context-on', |
|
| 1828 | - 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1829 | - 'message_template_group_id' => $message_template_group->ID() |
|
| 1830 | - ); |
|
| 1831 | - return EEH_Template::display_template( |
|
| 1832 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1833 | - $template_args, |
|
| 1834 | - true |
|
| 1835 | - ); |
|
| 1836 | - } |
|
| 1805 | + /** |
|
| 1806 | + * Adds the activation/deactivation toggle for the message template context. |
|
| 1807 | + * |
|
| 1808 | + * @param EE_Message_Template_Group $message_template_group |
|
| 1809 | + * @param string $context |
|
| 1810 | + * @param string $context_label |
|
| 1811 | + * @return string |
|
| 1812 | + * @throws DomainException |
|
| 1813 | + * @throws EE_Error |
|
| 1814 | + * @throws InvalidIdentifierException |
|
| 1815 | + */ |
|
| 1816 | + protected function add_active_context_element( |
|
| 1817 | + EE_Message_Template_Group $message_template_group, |
|
| 1818 | + $context, |
|
| 1819 | + $context_label |
|
| 1820 | + ) { |
|
| 1821 | + $template_args = array( |
|
| 1822 | + 'context' => $context, |
|
| 1823 | + 'nonce' => wp_create_nonce('activate_' . $context . '_toggle_nonce'), |
|
| 1824 | + 'is_active' => $message_template_group->is_context_active($context), |
|
| 1825 | + 'on_off_action' => $message_template_group->is_context_active($context) |
|
| 1826 | + ? 'context-off' |
|
| 1827 | + : 'context-on', |
|
| 1828 | + 'context_label' => str_replace(array('(', ')'), '', $context_label), |
|
| 1829 | + 'message_template_group_id' => $message_template_group->ID() |
|
| 1830 | + ); |
|
| 1831 | + return EEH_Template::display_template( |
|
| 1832 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php', |
|
| 1833 | + $template_args, |
|
| 1834 | + true |
|
| 1835 | + ); |
|
| 1836 | + } |
|
| 1837 | 1837 | |
| 1838 | 1838 | |
| 1839 | - /** |
|
| 1840 | - * Ajax callback for `toggle_context_template` ajax action. |
|
| 1841 | - * Handles toggling the message context on or off. |
|
| 1842 | - * @throws EE_Error |
|
| 1843 | - * @throws InvalidArgumentException |
|
| 1844 | - * @throws InvalidDataTypeException |
|
| 1845 | - * @throws InvalidIdentifierException |
|
| 1846 | - * @throws InvalidInterfaceException |
|
| 1847 | - */ |
|
| 1848 | - public function toggle_context_template() |
|
| 1849 | - { |
|
| 1850 | - $success = true; |
|
| 1851 | - //check for required data |
|
| 1852 | - if (!isset( |
|
| 1853 | - $this->_req_data['message_template_group_id'], |
|
| 1854 | - $this->_req_data['context'], |
|
| 1855 | - $this->_req_data['status'] |
|
| 1856 | - )) { |
|
| 1857 | - EE_Error::add_error( |
|
| 1858 | - esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1859 | - __FILE__, |
|
| 1860 | - __FUNCTION__, |
|
| 1861 | - __LINE__ |
|
| 1862 | - ); |
|
| 1863 | - $success = false; |
|
| 1864 | - } |
|
| 1839 | + /** |
|
| 1840 | + * Ajax callback for `toggle_context_template` ajax action. |
|
| 1841 | + * Handles toggling the message context on or off. |
|
| 1842 | + * @throws EE_Error |
|
| 1843 | + * @throws InvalidArgumentException |
|
| 1844 | + * @throws InvalidDataTypeException |
|
| 1845 | + * @throws InvalidIdentifierException |
|
| 1846 | + * @throws InvalidInterfaceException |
|
| 1847 | + */ |
|
| 1848 | + public function toggle_context_template() |
|
| 1849 | + { |
|
| 1850 | + $success = true; |
|
| 1851 | + //check for required data |
|
| 1852 | + if (!isset( |
|
| 1853 | + $this->_req_data['message_template_group_id'], |
|
| 1854 | + $this->_req_data['context'], |
|
| 1855 | + $this->_req_data['status'] |
|
| 1856 | + )) { |
|
| 1857 | + EE_Error::add_error( |
|
| 1858 | + esc_html__('Required data for doing this action is not available.', 'event_espresso'), |
|
| 1859 | + __FILE__, |
|
| 1860 | + __FUNCTION__, |
|
| 1861 | + __LINE__ |
|
| 1862 | + ); |
|
| 1863 | + $success = false; |
|
| 1864 | + } |
|
| 1865 | 1865 | |
| 1866 | - $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1867 | - ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1868 | - : ''; |
|
| 1869 | - $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1870 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1871 | - $status = $this->_req_data['status']; |
|
| 1872 | - if ($status !== 'off' && $status !=='on') { |
|
| 1873 | - EE_Error::add_error( |
|
| 1874 | - sprintf( |
|
| 1875 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1876 | - $this->_req_data['status'] |
|
| 1877 | - ), |
|
| 1878 | - __FILE__, |
|
| 1879 | - __FUNCTION__, |
|
| 1880 | - __LINE__ |
|
| 1881 | - ); |
|
| 1882 | - $success = false; |
|
| 1883 | - } |
|
| 1884 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1885 | - $this->_req_data['message_template_group_id'] |
|
| 1886 | - ); |
|
| 1887 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1888 | - EE_Error::add_error( |
|
| 1889 | - sprintf( |
|
| 1890 | - esc_html__( |
|
| 1891 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1892 | - 'event_espresso' |
|
| 1893 | - ), |
|
| 1894 | - $this->_req_data['message_template_group_id'], |
|
| 1895 | - 'EE_Message_Template_Group' |
|
| 1896 | - ), |
|
| 1897 | - __FILE__, |
|
| 1898 | - __FUNCTION__, |
|
| 1899 | - __LINE__ |
|
| 1900 | - ); |
|
| 1901 | - $success = false; |
|
| 1902 | - } |
|
| 1903 | - if ($success) { |
|
| 1904 | - $success = $status === 'off' |
|
| 1905 | - ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1906 | - : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1907 | - } |
|
| 1908 | - $this->_template_args['success'] = $success; |
|
| 1909 | - $this->_return_json(); |
|
| 1910 | - } |
|
| 1866 | + $nonce = isset($this->_req_data['toggle_context_nonce']) |
|
| 1867 | + ? sanitize_text_field($this->_req_data['toggle_context_nonce']) |
|
| 1868 | + : ''; |
|
| 1869 | + $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce'; |
|
| 1870 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 1871 | + $status = $this->_req_data['status']; |
|
| 1872 | + if ($status !== 'off' && $status !=='on') { |
|
| 1873 | + EE_Error::add_error( |
|
| 1874 | + sprintf( |
|
| 1875 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 1876 | + $this->_req_data['status'] |
|
| 1877 | + ), |
|
| 1878 | + __FILE__, |
|
| 1879 | + __FUNCTION__, |
|
| 1880 | + __LINE__ |
|
| 1881 | + ); |
|
| 1882 | + $success = false; |
|
| 1883 | + } |
|
| 1884 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 1885 | + $this->_req_data['message_template_group_id'] |
|
| 1886 | + ); |
|
| 1887 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
| 1888 | + EE_Error::add_error( |
|
| 1889 | + sprintf( |
|
| 1890 | + esc_html__( |
|
| 1891 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"', |
|
| 1892 | + 'event_espresso' |
|
| 1893 | + ), |
|
| 1894 | + $this->_req_data['message_template_group_id'], |
|
| 1895 | + 'EE_Message_Template_Group' |
|
| 1896 | + ), |
|
| 1897 | + __FILE__, |
|
| 1898 | + __FUNCTION__, |
|
| 1899 | + __LINE__ |
|
| 1900 | + ); |
|
| 1901 | + $success = false; |
|
| 1902 | + } |
|
| 1903 | + if ($success) { |
|
| 1904 | + $success = $status === 'off' |
|
| 1905 | + ? $message_template_group->deactivate_context($this->_req_data['context']) |
|
| 1906 | + : $message_template_group->activate_context($this->_req_data['context']); |
|
| 1907 | + } |
|
| 1908 | + $this->_template_args['success'] = $success; |
|
| 1909 | + $this->_return_json(); |
|
| 1910 | + } |
|
| 1911 | 1911 | |
| 1912 | 1912 | |
| 1913 | 1913 | |
| 1914 | - public function _add_form_element_before() |
|
| 1915 | - { |
|
| 1916 | - return '<form method="post" action="' |
|
| 1917 | - . $this->_template_args["edit_message_template_form_url"] |
|
| 1918 | - . '" id="ee-msg-edit-frm">'; |
|
| 1919 | - } |
|
| 1914 | + public function _add_form_element_before() |
|
| 1915 | + { |
|
| 1916 | + return '<form method="post" action="' |
|
| 1917 | + . $this->_template_args["edit_message_template_form_url"] |
|
| 1918 | + . '" id="ee-msg-edit-frm">'; |
|
| 1919 | + } |
|
| 1920 | 1920 | |
| 1921 | - public function _add_form_element_after() |
|
| 1922 | - { |
|
| 1923 | - return '</form>'; |
|
| 1924 | - } |
|
| 1921 | + public function _add_form_element_after() |
|
| 1922 | + { |
|
| 1923 | + return '</form>'; |
|
| 1924 | + } |
|
| 1925 | 1925 | |
| 1926 | 1926 | |
| 1927 | - /** |
|
| 1928 | - * This executes switching the template pack for a message template. |
|
| 1929 | - * |
|
| 1930 | - * @since 4.5.0 |
|
| 1931 | - * @throws EE_Error |
|
| 1932 | - * @throws InvalidDataTypeException |
|
| 1933 | - * @throws InvalidInterfaceException |
|
| 1934 | - * @throws InvalidArgumentException |
|
| 1935 | - * @throws ReflectionException |
|
| 1936 | - */ |
|
| 1937 | - public function switch_template_pack() |
|
| 1938 | - { |
|
| 1939 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1940 | - $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1941 | - |
|
| 1942 | - //verify we have needed values. |
|
| 1943 | - if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1944 | - $this->_template_args['error'] = true; |
|
| 1945 | - EE_Error::add_error( |
|
| 1946 | - esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1947 | - __FILE__, |
|
| 1948 | - __FUNCTION__, |
|
| 1949 | - __LINE__ |
|
| 1950 | - ); |
|
| 1951 | - } else { |
|
| 1952 | - //get template, set the new template_pack and then reset to default |
|
| 1953 | - /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1954 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1927 | + /** |
|
| 1928 | + * This executes switching the template pack for a message template. |
|
| 1929 | + * |
|
| 1930 | + * @since 4.5.0 |
|
| 1931 | + * @throws EE_Error |
|
| 1932 | + * @throws InvalidDataTypeException |
|
| 1933 | + * @throws InvalidInterfaceException |
|
| 1934 | + * @throws InvalidArgumentException |
|
| 1935 | + * @throws ReflectionException |
|
| 1936 | + */ |
|
| 1937 | + public function switch_template_pack() |
|
| 1938 | + { |
|
| 1939 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 1940 | + $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : ''; |
|
| 1941 | + |
|
| 1942 | + //verify we have needed values. |
|
| 1943 | + if (empty($GRP_ID) || empty($template_pack)) { |
|
| 1944 | + $this->_template_args['error'] = true; |
|
| 1945 | + EE_Error::add_error( |
|
| 1946 | + esc_html__('The required date for switching templates is not available.', 'event_espresso'), |
|
| 1947 | + __FILE__, |
|
| 1948 | + __FUNCTION__, |
|
| 1949 | + __LINE__ |
|
| 1950 | + ); |
|
| 1951 | + } else { |
|
| 1952 | + //get template, set the new template_pack and then reset to default |
|
| 1953 | + /** @type EE_Message_Template_Group $message_template_group */ |
|
| 1954 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
| 1955 | 1955 | |
| 1956 | - $message_template_group->set_template_pack_name($template_pack); |
|
| 1957 | - $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1958 | - $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1956 | + $message_template_group->set_template_pack_name($template_pack); |
|
| 1957 | + $this->_req_data['msgr'] = $message_template_group->messenger(); |
|
| 1958 | + $this->_req_data['mt'] = $message_template_group->message_type(); |
|
| 1959 | 1959 | |
| 1960 | - $query_args = $this->_reset_to_default_template(); |
|
| 1960 | + $query_args = $this->_reset_to_default_template(); |
|
| 1961 | 1961 | |
| 1962 | - if (empty($query_args['id'])) { |
|
| 1963 | - EE_Error::add_error( |
|
| 1964 | - esc_html__( |
|
| 1965 | - 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1966 | - 'event_espresso' |
|
| 1967 | - ), |
|
| 1968 | - __FILE__, |
|
| 1969 | - __FUNCTION__, |
|
| 1970 | - __LINE__ |
|
| 1971 | - ); |
|
| 1972 | - $this->_template_args['error'] = true; |
|
| 1973 | - } else { |
|
| 1974 | - $template_label = $message_template_group->get_template_pack()->label; |
|
| 1975 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1976 | - EE_Error::add_success( |
|
| 1977 | - sprintf( |
|
| 1978 | - esc_html__( |
|
| 1979 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1980 | - 'event_espresso' |
|
| 1981 | - ), |
|
| 1982 | - $template_label, |
|
| 1983 | - $template_pack_labels->template_pack |
|
| 1984 | - ) |
|
| 1985 | - ); |
|
| 1986 | - //generate the redirect url for js. |
|
| 1987 | - $url = self::add_query_args_and_nonce($query_args, |
|
| 1988 | - $this->_admin_base_url); |
|
| 1989 | - $this->_template_args['data']['redirect_url'] = $url; |
|
| 1990 | - $this->_template_args['success'] = true; |
|
| 1991 | - } |
|
| 1962 | + if (empty($query_args['id'])) { |
|
| 1963 | + EE_Error::add_error( |
|
| 1964 | + esc_html__( |
|
| 1965 | + 'Something went wrong with switching the template pack. Please try again or contact EE support', |
|
| 1966 | + 'event_espresso' |
|
| 1967 | + ), |
|
| 1968 | + __FILE__, |
|
| 1969 | + __FUNCTION__, |
|
| 1970 | + __LINE__ |
|
| 1971 | + ); |
|
| 1972 | + $this->_template_args['error'] = true; |
|
| 1973 | + } else { |
|
| 1974 | + $template_label = $message_template_group->get_template_pack()->label; |
|
| 1975 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels(); |
|
| 1976 | + EE_Error::add_success( |
|
| 1977 | + sprintf( |
|
| 1978 | + esc_html__( |
|
| 1979 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.', |
|
| 1980 | + 'event_espresso' |
|
| 1981 | + ), |
|
| 1982 | + $template_label, |
|
| 1983 | + $template_pack_labels->template_pack |
|
| 1984 | + ) |
|
| 1985 | + ); |
|
| 1986 | + //generate the redirect url for js. |
|
| 1987 | + $url = self::add_query_args_and_nonce($query_args, |
|
| 1988 | + $this->_admin_base_url); |
|
| 1989 | + $this->_template_args['data']['redirect_url'] = $url; |
|
| 1990 | + $this->_template_args['success'] = true; |
|
| 1991 | + } |
|
| 1992 | 1992 | |
| 1993 | - $this->_return_json(); |
|
| 1993 | + $this->_return_json(); |
|
| 1994 | 1994 | |
| 1995 | - } |
|
| 1996 | - } |
|
| 1995 | + } |
|
| 1996 | + } |
|
| 1997 | 1997 | |
| 1998 | 1998 | |
| 1999 | - /** |
|
| 2000 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2001 | - * they want. |
|
| 2002 | - * |
|
| 2003 | - * @access protected |
|
| 2004 | - * @return array|null |
|
| 2005 | - * @throws EE_Error |
|
| 2006 | - * @throws InvalidArgumentException |
|
| 2007 | - * @throws InvalidDataTypeException |
|
| 2008 | - * @throws InvalidInterfaceException |
|
| 2009 | - */ |
|
| 2010 | - protected function _reset_to_default_template() |
|
| 2011 | - { |
|
| 2012 | - |
|
| 2013 | - $templates = array(); |
|
| 2014 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2015 | - //we need to make sure we've got the info we need. |
|
| 2016 | - if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2017 | - EE_Error::add_error( |
|
| 2018 | - esc_html__( |
|
| 2019 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2020 | - 'event_espresso' |
|
| 2021 | - ), |
|
| 2022 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2023 | - ); |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - // all templates will be reset to whatever the defaults are |
|
| 2027 | - // for the global template matching the messenger and message type. |
|
| 2028 | - $success = ! empty($GRP_ID) ? true : false; |
|
| 2029 | - |
|
| 2030 | - if ($success) { |
|
| 1999 | + /** |
|
| 2000 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if |
|
| 2001 | + * they want. |
|
| 2002 | + * |
|
| 2003 | + * @access protected |
|
| 2004 | + * @return array|null |
|
| 2005 | + * @throws EE_Error |
|
| 2006 | + * @throws InvalidArgumentException |
|
| 2007 | + * @throws InvalidDataTypeException |
|
| 2008 | + * @throws InvalidInterfaceException |
|
| 2009 | + */ |
|
| 2010 | + protected function _reset_to_default_template() |
|
| 2011 | + { |
|
| 2012 | + |
|
| 2013 | + $templates = array(); |
|
| 2014 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2015 | + //we need to make sure we've got the info we need. |
|
| 2016 | + if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) { |
|
| 2017 | + EE_Error::add_error( |
|
| 2018 | + esc_html__( |
|
| 2019 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.', |
|
| 2020 | + 'event_espresso' |
|
| 2021 | + ), |
|
| 2022 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2023 | + ); |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + // all templates will be reset to whatever the defaults are |
|
| 2027 | + // for the global template matching the messenger and message type. |
|
| 2028 | + $success = ! empty($GRP_ID) ? true : false; |
|
| 2029 | + |
|
| 2030 | + if ($success) { |
|
| 2031 | 2031 | |
| 2032 | - //let's first determine if the incoming template is a global template, |
|
| 2033 | - // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2034 | - //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2032 | + //let's first determine if the incoming template is a global template, |
|
| 2033 | + // if it isn't then we need to get the global template matching messenger and message type. |
|
| 2034 | + //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
| 2035 | 2035 | |
| 2036 | 2036 | |
| 2037 | - //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2038 | - $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2037 | + //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group. |
|
| 2038 | + $success = $this->_delete_mtp_permanently($GRP_ID, false); |
|
| 2039 | 2039 | |
| 2040 | - if ($success) { |
|
| 2041 | - // if successfully deleted, lets generate the new ones. |
|
| 2042 | - // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2043 | - // will use the related global template defaults for regeneration. |
|
| 2044 | - // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2045 | - // HOWEVER, we DO keep the template pack and template variation set |
|
| 2046 | - // for the current custom template when resetting. |
|
| 2047 | - $templates = $this->_generate_new_templates( |
|
| 2048 | - $this->_req_data['msgr'], |
|
| 2049 | - $this->_req_data['mt'], |
|
| 2050 | - $GRP_ID, |
|
| 2051 | - true |
|
| 2052 | - ); |
|
| 2053 | - } |
|
| 2040 | + if ($success) { |
|
| 2041 | + // if successfully deleted, lets generate the new ones. |
|
| 2042 | + // Note. We set GLOBAL to true, because resets on ANY template |
|
| 2043 | + // will use the related global template defaults for regeneration. |
|
| 2044 | + // This means that if a custom template is reset it resets to whatever the related global template is. |
|
| 2045 | + // HOWEVER, we DO keep the template pack and template variation set |
|
| 2046 | + // for the current custom template when resetting. |
|
| 2047 | + $templates = $this->_generate_new_templates( |
|
| 2048 | + $this->_req_data['msgr'], |
|
| 2049 | + $this->_req_data['mt'], |
|
| 2050 | + $GRP_ID, |
|
| 2051 | + true |
|
| 2052 | + ); |
|
| 2053 | + } |
|
| 2054 | 2054 | |
| 2055 | - } |
|
| 2056 | - |
|
| 2057 | - //any error messages? |
|
| 2058 | - if ( ! $success) { |
|
| 2059 | - EE_Error::add_error( |
|
| 2060 | - esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2061 | - 'event_espresso'), |
|
| 2062 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2063 | - ); |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - //all good, let's add a success message! |
|
| 2067 | - if ($success && ! empty($templates)) { |
|
| 2068 | - //the info for the template we generated is the first element in the returned array |
|
| 2069 | - // $templates = $templates[0]; |
|
| 2070 | - EE_Error::overwrite_success(); |
|
| 2071 | - EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2072 | - } |
|
| 2073 | - |
|
| 2074 | - |
|
| 2075 | - $query_args = array( |
|
| 2076 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2077 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2078 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2079 | - ); |
|
| 2080 | - |
|
| 2081 | - //if called via ajax then we return query args otherwise redirect |
|
| 2082 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2083 | - return $query_args; |
|
| 2084 | - } else { |
|
| 2085 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + //any error messages? |
|
| 2058 | + if ( ! $success) { |
|
| 2059 | + EE_Error::add_error( |
|
| 2060 | + esc_html__('Something went wrong with deleting existing templates. Unable to reset to default', |
|
| 2061 | + 'event_espresso'), |
|
| 2062 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2063 | + ); |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + //all good, let's add a success message! |
|
| 2067 | + if ($success && ! empty($templates)) { |
|
| 2068 | + //the info for the template we generated is the first element in the returned array |
|
| 2069 | + // $templates = $templates[0]; |
|
| 2070 | + EE_Error::overwrite_success(); |
|
| 2071 | + EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso')); |
|
| 2072 | + } |
|
| 2073 | + |
|
| 2074 | + |
|
| 2075 | + $query_args = array( |
|
| 2076 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null, |
|
| 2077 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null, |
|
| 2078 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps' |
|
| 2079 | + ); |
|
| 2080 | + |
|
| 2081 | + //if called via ajax then we return query args otherwise redirect |
|
| 2082 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2083 | + return $query_args; |
|
| 2084 | + } else { |
|
| 2085 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2086 | 2086 | |
| 2087 | - return null; |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2087 | + return null; |
|
| 2088 | + } |
|
| 2089 | + } |
|
| 2090 | 2090 | |
| 2091 | 2091 | |
| 2092 | - /** |
|
| 2093 | - * Retrieve and set the message preview for display. |
|
| 2094 | - * |
|
| 2095 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2096 | - * @return string |
|
| 2097 | - * @throws EE_Error |
|
| 2098 | - * @throws InvalidArgumentException |
|
| 2099 | - * @throws InvalidDataTypeException |
|
| 2100 | - * @throws InvalidInterfaceException |
|
| 2101 | - */ |
|
| 2102 | - public function _preview_message($send = false) |
|
| 2103 | - { |
|
| 2104 | - //first make sure we've got the necessary parameters |
|
| 2105 | - if ( |
|
| 2106 | - ! isset( |
|
| 2107 | - $this->_req_data['message_type'], |
|
| 2108 | - $this->_req_data['messenger'], |
|
| 2109 | - $this->_req_data['messenger'], |
|
| 2110 | - $this->_req_data['GRP_ID'] |
|
| 2111 | - ) |
|
| 2112 | - ) { |
|
| 2113 | - EE_Error::add_error( |
|
| 2114 | - esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2115 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2116 | - ); |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2120 | - |
|
| 2121 | - |
|
| 2122 | - //get the preview! |
|
| 2123 | - $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2124 | - $this->_req_data['messenger'], $send); |
|
| 2125 | - |
|
| 2126 | - if ($send) { |
|
| 2127 | - return $preview; |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - //let's add a button to go back to the edit view |
|
| 2131 | - $query_args = array( |
|
| 2132 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2133 | - 'context' => $this->_req_data['context'], |
|
| 2134 | - 'action' => 'edit_message_template' |
|
| 2135 | - ); |
|
| 2136 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2137 | - $preview_button = '<a href="' |
|
| 2138 | - . $go_back_url |
|
| 2139 | - . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2140 | - . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2141 | - . '</a>'; |
|
| 2142 | - $message_types = $this->get_installed_message_types(); |
|
| 2143 | - $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2144 | - $this->_req_data['messenger'] |
|
| 2145 | - ); |
|
| 2146 | - $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2147 | - ? ucwords($active_messenger->label['singular']) |
|
| 2148 | - : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2149 | - //let's provide a helpful title for context |
|
| 2150 | - $preview_title = sprintf( |
|
| 2151 | - esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2152 | - $active_messenger_label, |
|
| 2153 | - ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2154 | - ); |
|
| 2155 | - //setup display of preview. |
|
| 2156 | - $this->_admin_page_title = $preview_title; |
|
| 2157 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2158 | - $this->_template_args['data']['force_json'] = true; |
|
| 2159 | - |
|
| 2160 | - return ''; |
|
| 2161 | - } |
|
| 2092 | + /** |
|
| 2093 | + * Retrieve and set the message preview for display. |
|
| 2094 | + * |
|
| 2095 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview. |
|
| 2096 | + * @return string |
|
| 2097 | + * @throws EE_Error |
|
| 2098 | + * @throws InvalidArgumentException |
|
| 2099 | + * @throws InvalidDataTypeException |
|
| 2100 | + * @throws InvalidInterfaceException |
|
| 2101 | + */ |
|
| 2102 | + public function _preview_message($send = false) |
|
| 2103 | + { |
|
| 2104 | + //first make sure we've got the necessary parameters |
|
| 2105 | + if ( |
|
| 2106 | + ! isset( |
|
| 2107 | + $this->_req_data['message_type'], |
|
| 2108 | + $this->_req_data['messenger'], |
|
| 2109 | + $this->_req_data['messenger'], |
|
| 2110 | + $this->_req_data['GRP_ID'] |
|
| 2111 | + ) |
|
| 2112 | + ) { |
|
| 2113 | + EE_Error::add_error( |
|
| 2114 | + esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), |
|
| 2115 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2116 | + ); |
|
| 2117 | + } |
|
| 2118 | + |
|
| 2119 | + EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']); |
|
| 2120 | + |
|
| 2121 | + |
|
| 2122 | + //get the preview! |
|
| 2123 | + $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'], |
|
| 2124 | + $this->_req_data['messenger'], $send); |
|
| 2125 | + |
|
| 2126 | + if ($send) { |
|
| 2127 | + return $preview; |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + //let's add a button to go back to the edit view |
|
| 2131 | + $query_args = array( |
|
| 2132 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2133 | + 'context' => $this->_req_data['context'], |
|
| 2134 | + 'action' => 'edit_message_template' |
|
| 2135 | + ); |
|
| 2136 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 2137 | + $preview_button = '<a href="' |
|
| 2138 | + . $go_back_url |
|
| 2139 | + . '" class="button-secondary messages-preview-go-back-button">' |
|
| 2140 | + . esc_html__('Go Back to Edit', 'event_espresso') |
|
| 2141 | + . '</a>'; |
|
| 2142 | + $message_types = $this->get_installed_message_types(); |
|
| 2143 | + $active_messenger = $this->_message_resource_manager->get_active_messenger( |
|
| 2144 | + $this->_req_data['messenger'] |
|
| 2145 | + ); |
|
| 2146 | + $active_messenger_label = $active_messenger instanceof EE_messenger |
|
| 2147 | + ? ucwords($active_messenger->label['singular']) |
|
| 2148 | + : esc_html__('Unknown Messenger', 'event_espresso'); |
|
| 2149 | + //let's provide a helpful title for context |
|
| 2150 | + $preview_title = sprintf( |
|
| 2151 | + esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), |
|
| 2152 | + $active_messenger_label, |
|
| 2153 | + ucwords($message_types[$this->_req_data['message_type']]->label['singular']) |
|
| 2154 | + ); |
|
| 2155 | + //setup display of preview. |
|
| 2156 | + $this->_admin_page_title = $preview_title; |
|
| 2157 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview); |
|
| 2158 | + $this->_template_args['data']['force_json'] = true; |
|
| 2159 | + |
|
| 2160 | + return ''; |
|
| 2161 | + } |
|
| 2162 | 2162 | |
| 2163 | 2163 | |
| 2164 | - /** |
|
| 2165 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2166 | - * gets called automatically. |
|
| 2167 | - * |
|
| 2168 | - * @since 4.5.0 |
|
| 2169 | - * |
|
| 2170 | - * @return string |
|
| 2171 | - */ |
|
| 2172 | - protected function _display_preview_message() |
|
| 2173 | - { |
|
| 2174 | - $this->display_admin_page_with_no_sidebar(); |
|
| 2175 | - } |
|
| 2164 | + /** |
|
| 2165 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it |
|
| 2166 | + * gets called automatically. |
|
| 2167 | + * |
|
| 2168 | + * @since 4.5.0 |
|
| 2169 | + * |
|
| 2170 | + * @return string |
|
| 2171 | + */ |
|
| 2172 | + protected function _display_preview_message() |
|
| 2173 | + { |
|
| 2174 | + $this->display_admin_page_with_no_sidebar(); |
|
| 2175 | + } |
|
| 2176 | 2176 | |
| 2177 | 2177 | |
| 2178 | - /** |
|
| 2179 | - * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2180 | - * |
|
| 2181 | - * @access protected |
|
| 2182 | - * @return void |
|
| 2183 | - */ |
|
| 2184 | - protected function _register_edit_meta_boxes() |
|
| 2185 | - { |
|
| 2186 | - add_meta_box( |
|
| 2187 | - 'mtp_valid_shortcodes', |
|
| 2188 | - esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2189 | - array($this, 'shortcode_meta_box'), |
|
| 2190 | - $this->_current_screen->id, |
|
| 2191 | - 'side', |
|
| 2192 | - 'default'); |
|
| 2193 | - add_meta_box( |
|
| 2194 | - 'mtp_extra_actions', |
|
| 2195 | - esc_html__('Extra Actions', 'event_espresso'), |
|
| 2196 | - array($this, 'extra_actions_meta_box'), |
|
| 2197 | - $this->_current_screen->id, |
|
| 2198 | - 'side', |
|
| 2199 | - 'high' |
|
| 2200 | - ); |
|
| 2201 | - add_meta_box( |
|
| 2202 | - 'mtp_templates', |
|
| 2203 | - esc_html__('Template Styles', 'event_espresso'), |
|
| 2204 | - array($this, 'template_pack_meta_box'), |
|
| 2205 | - $this->_current_screen->id, |
|
| 2206 | - 'side', |
|
| 2207 | - 'high' |
|
| 2208 | - ); |
|
| 2209 | - } |
|
| 2178 | + /** |
|
| 2179 | + * registers metaboxes that should show up on the "edit_message_template" page |
|
| 2180 | + * |
|
| 2181 | + * @access protected |
|
| 2182 | + * @return void |
|
| 2183 | + */ |
|
| 2184 | + protected function _register_edit_meta_boxes() |
|
| 2185 | + { |
|
| 2186 | + add_meta_box( |
|
| 2187 | + 'mtp_valid_shortcodes', |
|
| 2188 | + esc_html__('Valid Shortcodes', 'event_espresso'), |
|
| 2189 | + array($this, 'shortcode_meta_box'), |
|
| 2190 | + $this->_current_screen->id, |
|
| 2191 | + 'side', |
|
| 2192 | + 'default'); |
|
| 2193 | + add_meta_box( |
|
| 2194 | + 'mtp_extra_actions', |
|
| 2195 | + esc_html__('Extra Actions', 'event_espresso'), |
|
| 2196 | + array($this, 'extra_actions_meta_box'), |
|
| 2197 | + $this->_current_screen->id, |
|
| 2198 | + 'side', |
|
| 2199 | + 'high' |
|
| 2200 | + ); |
|
| 2201 | + add_meta_box( |
|
| 2202 | + 'mtp_templates', |
|
| 2203 | + esc_html__('Template Styles', 'event_espresso'), |
|
| 2204 | + array($this, 'template_pack_meta_box'), |
|
| 2205 | + $this->_current_screen->id, |
|
| 2206 | + 'side', |
|
| 2207 | + 'high' |
|
| 2208 | + ); |
|
| 2209 | + } |
|
| 2210 | 2210 | |
| 2211 | 2211 | |
| 2212 | - /** |
|
| 2213 | - * metabox content for all template pack and variation selection. |
|
| 2214 | - * |
|
| 2215 | - * @since 4.5.0 |
|
| 2216 | - * @return string |
|
| 2217 | - * @throws DomainException |
|
| 2218 | - * @throws EE_Error |
|
| 2219 | - * @throws InvalidArgumentException |
|
| 2220 | - * @throws ReflectionException |
|
| 2221 | - * @throws InvalidDataTypeException |
|
| 2222 | - * @throws InvalidInterfaceException |
|
| 2223 | - */ |
|
| 2224 | - public function template_pack_meta_box() |
|
| 2225 | - { |
|
| 2226 | - $this->_set_message_template_group(); |
|
| 2227 | - |
|
| 2228 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2229 | - |
|
| 2230 | - $tp_select_values = array(); |
|
| 2231 | - |
|
| 2232 | - foreach ($tp_collection as $tp) { |
|
| 2233 | - //only include template packs that support this messenger and message type! |
|
| 2234 | - $supports = $tp->get_supports(); |
|
| 2235 | - if ( |
|
| 2236 | - ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2237 | - || ! in_array( |
|
| 2238 | - $this->_message_template_group->message_type(), |
|
| 2239 | - $supports[$this->_message_template_group->messenger()], |
|
| 2240 | - true |
|
| 2241 | - ) |
|
| 2242 | - ) { |
|
| 2243 | - //not supported |
|
| 2244 | - continue; |
|
| 2245 | - } |
|
| 2212 | + /** |
|
| 2213 | + * metabox content for all template pack and variation selection. |
|
| 2214 | + * |
|
| 2215 | + * @since 4.5.0 |
|
| 2216 | + * @return string |
|
| 2217 | + * @throws DomainException |
|
| 2218 | + * @throws EE_Error |
|
| 2219 | + * @throws InvalidArgumentException |
|
| 2220 | + * @throws ReflectionException |
|
| 2221 | + * @throws InvalidDataTypeException |
|
| 2222 | + * @throws InvalidInterfaceException |
|
| 2223 | + */ |
|
| 2224 | + public function template_pack_meta_box() |
|
| 2225 | + { |
|
| 2226 | + $this->_set_message_template_group(); |
|
| 2227 | + |
|
| 2228 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 2229 | + |
|
| 2230 | + $tp_select_values = array(); |
|
| 2231 | + |
|
| 2232 | + foreach ($tp_collection as $tp) { |
|
| 2233 | + //only include template packs that support this messenger and message type! |
|
| 2234 | + $supports = $tp->get_supports(); |
|
| 2235 | + if ( |
|
| 2236 | + ! isset($supports[$this->_message_template_group->messenger()]) |
|
| 2237 | + || ! in_array( |
|
| 2238 | + $this->_message_template_group->message_type(), |
|
| 2239 | + $supports[$this->_message_template_group->messenger()], |
|
| 2240 | + true |
|
| 2241 | + ) |
|
| 2242 | + ) { |
|
| 2243 | + //not supported |
|
| 2244 | + continue; |
|
| 2245 | + } |
|
| 2246 | 2246 | |
| 2247 | - $tp_select_values[] = array( |
|
| 2248 | - 'text' => $tp->label, |
|
| 2249 | - 'id' => $tp->dbref |
|
| 2250 | - ); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2254 | - // the default template pack. This still allows for the odd template pack to override. |
|
| 2255 | - if (empty($tp_select_values)) { |
|
| 2256 | - $tp_select_values[] = array( |
|
| 2257 | - 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2258 | - 'id' => 'default' |
|
| 2259 | - ); |
|
| 2260 | - } |
|
| 2261 | - |
|
| 2262 | - //setup variation select values for the currently selected template. |
|
| 2263 | - $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2264 | - $this->_message_template_group->messenger(), |
|
| 2265 | - $this->_message_template_group->message_type() |
|
| 2266 | - ); |
|
| 2267 | - $variations_select_values = array(); |
|
| 2268 | - foreach ($variations as $variation => $label) { |
|
| 2269 | - $variations_select_values[] = array( |
|
| 2270 | - 'text' => $label, |
|
| 2271 | - 'id' => $variation |
|
| 2272 | - ); |
|
| 2273 | - } |
|
| 2274 | - |
|
| 2275 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2276 | - |
|
| 2277 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2278 | - 'MTP_template_pack', |
|
| 2279 | - $tp_select_values, |
|
| 2280 | - $this->_message_template_group->get_template_pack_name() |
|
| 2281 | - ); |
|
| 2282 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2283 | - 'MTP_template_variation', |
|
| 2284 | - $variations_select_values, |
|
| 2285 | - $this->_message_template_group->get_template_pack_variation() |
|
| 2286 | - ); |
|
| 2287 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2288 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2289 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2290 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2291 | - |
|
| 2292 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2293 | - |
|
| 2294 | - EEH_Template::display_template($template, $template_args); |
|
| 2295 | - } |
|
| 2247 | + $tp_select_values[] = array( |
|
| 2248 | + 'text' => $tp->label, |
|
| 2249 | + 'id' => $tp->dbref |
|
| 2250 | + ); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by |
|
| 2254 | + // the default template pack. This still allows for the odd template pack to override. |
|
| 2255 | + if (empty($tp_select_values)) { |
|
| 2256 | + $tp_select_values[] = array( |
|
| 2257 | + 'text' => esc_html__('Default', 'event_espresso'), |
|
| 2258 | + 'id' => 'default' |
|
| 2259 | + ); |
|
| 2260 | + } |
|
| 2261 | + |
|
| 2262 | + //setup variation select values for the currently selected template. |
|
| 2263 | + $variations = $this->_message_template_group->get_template_pack()->get_variations( |
|
| 2264 | + $this->_message_template_group->messenger(), |
|
| 2265 | + $this->_message_template_group->message_type() |
|
| 2266 | + ); |
|
| 2267 | + $variations_select_values = array(); |
|
| 2268 | + foreach ($variations as $variation => $label) { |
|
| 2269 | + $variations_select_values[] = array( |
|
| 2270 | + 'text' => $label, |
|
| 2271 | + 'id' => $variation |
|
| 2272 | + ); |
|
| 2273 | + } |
|
| 2274 | + |
|
| 2275 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels(); |
|
| 2276 | + |
|
| 2277 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input( |
|
| 2278 | + 'MTP_template_pack', |
|
| 2279 | + $tp_select_values, |
|
| 2280 | + $this->_message_template_group->get_template_pack_name() |
|
| 2281 | + ); |
|
| 2282 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input( |
|
| 2283 | + 'MTP_template_variation', |
|
| 2284 | + $variations_select_values, |
|
| 2285 | + $this->_message_template_group->get_template_pack_variation() |
|
| 2286 | + ); |
|
| 2287 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack; |
|
| 2288 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation; |
|
| 2289 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description; |
|
| 2290 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description; |
|
| 2291 | + |
|
| 2292 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php'; |
|
| 2293 | + |
|
| 2294 | + EEH_Template::display_template($template, $template_args); |
|
| 2295 | + } |
|
| 2296 | 2296 | |
| 2297 | 2297 | |
| 2298 | - /** |
|
| 2299 | - * This meta box holds any extra actions related to Message Templates |
|
| 2300 | - * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2301 | - * |
|
| 2302 | - * @access public |
|
| 2303 | - * @return void |
|
| 2304 | - * @throws EE_Error |
|
| 2305 | - */ |
|
| 2306 | - public function extra_actions_meta_box() |
|
| 2307 | - { |
|
| 2308 | - $template_form_fields = array(); |
|
| 2309 | - |
|
| 2310 | - $extra_args = array( |
|
| 2311 | - 'msgr' => $this->_message_template_group->messenger(), |
|
| 2312 | - 'mt' => $this->_message_template_group->message_type(), |
|
| 2313 | - 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2314 | - ); |
|
| 2315 | - //first we need to see if there are any fields |
|
| 2316 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2317 | - |
|
| 2318 | - if ( ! empty($fields)) { |
|
| 2319 | - //yup there be fields |
|
| 2320 | - foreach ($fields as $field => $config) { |
|
| 2321 | - $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2322 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2323 | - $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2324 | - $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2298 | + /** |
|
| 2299 | + * This meta box holds any extra actions related to Message Templates |
|
| 2300 | + * For now, this includes Resetting templates to defaults and sending a test email. |
|
| 2301 | + * |
|
| 2302 | + * @access public |
|
| 2303 | + * @return void |
|
| 2304 | + * @throws EE_Error |
|
| 2305 | + */ |
|
| 2306 | + public function extra_actions_meta_box() |
|
| 2307 | + { |
|
| 2308 | + $template_form_fields = array(); |
|
| 2309 | + |
|
| 2310 | + $extra_args = array( |
|
| 2311 | + 'msgr' => $this->_message_template_group->messenger(), |
|
| 2312 | + 'mt' => $this->_message_template_group->message_type(), |
|
| 2313 | + 'GRP_ID' => $this->_message_template_group->GRP_ID() |
|
| 2314 | + ); |
|
| 2315 | + //first we need to see if there are any fields |
|
| 2316 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields(); |
|
| 2317 | + |
|
| 2318 | + if ( ! empty($fields)) { |
|
| 2319 | + //yup there be fields |
|
| 2320 | + foreach ($fields as $field => $config) { |
|
| 2321 | + $field_id = $this->_message_template_group->messenger() . '_' . $field; |
|
| 2322 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings(); |
|
| 2323 | + $default = isset($config['default']) ? $config['default'] : ''; |
|
| 2324 | + $default = isset($config['value']) ? $config['value'] : $default; |
|
| 2325 | 2325 | |
| 2326 | - // if type is hidden and the value is empty |
|
| 2327 | - // something may have gone wrong so let's correct with the defaults |
|
| 2328 | - $fix = $config['input'] === 'hidden' |
|
| 2329 | - && isset($existing[$field]) |
|
| 2330 | - && empty($existing[$field]) |
|
| 2331 | - ? $default |
|
| 2332 | - : ''; |
|
| 2333 | - $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2334 | - ? $existing[$field] |
|
| 2335 | - : $fix; |
|
| 2326 | + // if type is hidden and the value is empty |
|
| 2327 | + // something may have gone wrong so let's correct with the defaults |
|
| 2328 | + $fix = $config['input'] === 'hidden' |
|
| 2329 | + && isset($existing[$field]) |
|
| 2330 | + && empty($existing[$field]) |
|
| 2331 | + ? $default |
|
| 2332 | + : ''; |
|
| 2333 | + $existing[$field] = isset($existing[$field]) && empty($fix) |
|
| 2334 | + ? $existing[$field] |
|
| 2335 | + : $fix; |
|
| 2336 | 2336 | |
| 2337 | - $template_form_fields[$field_id] = array( |
|
| 2338 | - 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2339 | - 'label' => $config['label'], |
|
| 2340 | - 'input' => $config['input'], |
|
| 2341 | - 'type' => $config['type'], |
|
| 2342 | - 'required' => $config['required'], |
|
| 2343 | - 'validation' => $config['validation'], |
|
| 2344 | - 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2345 | - 'css_class' => $config['css_class'], |
|
| 2346 | - 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2347 | - 'default' => $default, |
|
| 2348 | - 'format' => $config['format'] |
|
| 2349 | - ); |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - |
|
| 2353 | - $test_settings_fields = ! empty($template_form_fields) |
|
| 2354 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2355 | - : ''; |
|
| 2356 | - |
|
| 2357 | - $test_settings_html = ''; |
|
| 2358 | - //print out $test_settings_fields |
|
| 2359 | - if ( ! empty($test_settings_fields)) { |
|
| 2360 | - echo $test_settings_fields; |
|
| 2361 | - $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2362 | - $test_settings_html .= 'name="test_button" value="'; |
|
| 2363 | - $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2364 | - $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2365 | - } |
|
| 2366 | - |
|
| 2367 | - //and button |
|
| 2368 | - $test_settings_html .= '<p>' |
|
| 2369 | - . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2370 | - . '</p>'; |
|
| 2371 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2372 | - $test_settings_html .= $this->get_action_link_or_button( |
|
| 2373 | - 'reset_to_default', |
|
| 2374 | - 'reset', |
|
| 2375 | - $extra_args, |
|
| 2376 | - 'button-primary reset-default-button' |
|
| 2377 | - ); |
|
| 2378 | - $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2379 | - echo $test_settings_html; |
|
| 2380 | - } |
|
| 2337 | + $template_form_fields[$field_id] = array( |
|
| 2338 | + 'name' => 'test_settings_fld[' . $field . ']', |
|
| 2339 | + 'label' => $config['label'], |
|
| 2340 | + 'input' => $config['input'], |
|
| 2341 | + 'type' => $config['type'], |
|
| 2342 | + 'required' => $config['required'], |
|
| 2343 | + 'validation' => $config['validation'], |
|
| 2344 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default, |
|
| 2345 | + 'css_class' => $config['css_class'], |
|
| 2346 | + 'options' => isset($config['options']) ? $config['options'] : array(), |
|
| 2347 | + 'default' => $default, |
|
| 2348 | + 'format' => $config['format'] |
|
| 2349 | + ); |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + |
|
| 2353 | + $test_settings_fields = ! empty($template_form_fields) |
|
| 2354 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds') |
|
| 2355 | + : ''; |
|
| 2356 | + |
|
| 2357 | + $test_settings_html = ''; |
|
| 2358 | + //print out $test_settings_fields |
|
| 2359 | + if ( ! empty($test_settings_fields)) { |
|
| 2360 | + echo $test_settings_fields; |
|
| 2361 | + $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" '; |
|
| 2362 | + $test_settings_html .= 'name="test_button" value="'; |
|
| 2363 | + $test_settings_html .= esc_html__('Test Send', 'event_espresso'); |
|
| 2364 | + $test_settings_html .= '" /><div style="clear:both"></div>'; |
|
| 2365 | + } |
|
| 2366 | + |
|
| 2367 | + //and button |
|
| 2368 | + $test_settings_html .= '<p>' |
|
| 2369 | + . esc_html__('Need to reset this message type and start over?', 'event_espresso') |
|
| 2370 | + . '</p>'; |
|
| 2371 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">'; |
|
| 2372 | + $test_settings_html .= $this->get_action_link_or_button( |
|
| 2373 | + 'reset_to_default', |
|
| 2374 | + 'reset', |
|
| 2375 | + $extra_args, |
|
| 2376 | + 'button-primary reset-default-button' |
|
| 2377 | + ); |
|
| 2378 | + $test_settings_html .= '</div><div style="clear:both"></div>'; |
|
| 2379 | + echo $test_settings_html; |
|
| 2380 | + } |
|
| 2381 | 2381 | |
| 2382 | 2382 | |
| 2383 | - /** |
|
| 2384 | - * This returns the shortcode selector skeleton for a given context and field. |
|
| 2385 | - * |
|
| 2386 | - * @since 4.9.rc.000 |
|
| 2387 | - * @param string $field The name of the field retrieving shortcodes for. |
|
| 2388 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2389 | - * @return string |
|
| 2390 | - * @throws DomainException |
|
| 2391 | - * @throws EE_Error |
|
| 2392 | - * @throws InvalidArgumentException |
|
| 2393 | - * @throws ReflectionException |
|
| 2394 | - * @throws InvalidDataTypeException |
|
| 2395 | - * @throws InvalidInterfaceException |
|
| 2396 | - */ |
|
| 2397 | - protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2398 | - { |
|
| 2399 | - $template_args = array( |
|
| 2400 | - 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2401 | - 'fieldname' => $field, |
|
| 2402 | - 'linked_input_id' => $linked_input_id |
|
| 2403 | - ); |
|
| 2404 | - |
|
| 2405 | - return EEH_Template::display_template( |
|
| 2406 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2407 | - $template_args, |
|
| 2408 | - true |
|
| 2409 | - ); |
|
| 2410 | - } |
|
| 2383 | + /** |
|
| 2384 | + * This returns the shortcode selector skeleton for a given context and field. |
|
| 2385 | + * |
|
| 2386 | + * @since 4.9.rc.000 |
|
| 2387 | + * @param string $field The name of the field retrieving shortcodes for. |
|
| 2388 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to. |
|
| 2389 | + * @return string |
|
| 2390 | + * @throws DomainException |
|
| 2391 | + * @throws EE_Error |
|
| 2392 | + * @throws InvalidArgumentException |
|
| 2393 | + * @throws ReflectionException |
|
| 2394 | + * @throws InvalidDataTypeException |
|
| 2395 | + * @throws InvalidInterfaceException |
|
| 2396 | + */ |
|
| 2397 | + protected function _get_shortcode_selector($field, $linked_input_id) |
|
| 2398 | + { |
|
| 2399 | + $template_args = array( |
|
| 2400 | + 'shortcodes' => $this->_get_shortcodes(array($field), true), |
|
| 2401 | + 'fieldname' => $field, |
|
| 2402 | + 'linked_input_id' => $linked_input_id |
|
| 2403 | + ); |
|
| 2404 | + |
|
| 2405 | + return EEH_Template::display_template( |
|
| 2406 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php', |
|
| 2407 | + $template_args, |
|
| 2408 | + true |
|
| 2409 | + ); |
|
| 2410 | + } |
|
| 2411 | 2411 | |
| 2412 | 2412 | |
| 2413 | - /** |
|
| 2414 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2415 | - * page) |
|
| 2416 | - * |
|
| 2417 | - * @access public |
|
| 2418 | - * @return void |
|
| 2419 | - * @throws EE_Error |
|
| 2420 | - * @throws InvalidArgumentException |
|
| 2421 | - * @throws ReflectionException |
|
| 2422 | - * @throws InvalidDataTypeException |
|
| 2423 | - * @throws InvalidInterfaceException |
|
| 2424 | - */ |
|
| 2425 | - public function shortcode_meta_box() |
|
| 2426 | - { |
|
| 2427 | - $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2428 | - //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2429 | - //now let's set the content depending on the status of the shortcodes array |
|
| 2430 | - if (empty($shortcodes)) { |
|
| 2431 | - $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2432 | - echo $content; |
|
| 2433 | - } else { |
|
| 2434 | - //$alt = 0; |
|
| 2435 | - ?> |
|
| 2413 | + /** |
|
| 2414 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template |
|
| 2415 | + * page) |
|
| 2416 | + * |
|
| 2417 | + * @access public |
|
| 2418 | + * @return void |
|
| 2419 | + * @throws EE_Error |
|
| 2420 | + * @throws InvalidArgumentException |
|
| 2421 | + * @throws ReflectionException |
|
| 2422 | + * @throws InvalidDataTypeException |
|
| 2423 | + * @throws InvalidInterfaceException |
|
| 2424 | + */ |
|
| 2425 | + public function shortcode_meta_box() |
|
| 2426 | + { |
|
| 2427 | + $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set |
|
| 2428 | + //$messenger = $this->_message_template_group->messenger_obj(); |
|
| 2429 | + //now let's set the content depending on the status of the shortcodes array |
|
| 2430 | + if (empty($shortcodes)) { |
|
| 2431 | + $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; |
|
| 2432 | + echo $content; |
|
| 2433 | + } else { |
|
| 2434 | + //$alt = 0; |
|
| 2435 | + ?> |
|
| 2436 | 2436 | <div style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div> |
| 2437 | 2437 | <p class="small-text"><?php printf( |
| 2438 | - esc_html__( |
|
| 2439 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2440 | - 'event_espresso' |
|
| 2441 | - ), |
|
| 2442 | - '<span class="dashicons dashicons-menu"></span>' |
|
| 2443 | - ); ?></p> |
|
| 2438 | + esc_html__( |
|
| 2439 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.', |
|
| 2440 | + 'event_espresso' |
|
| 2441 | + ), |
|
| 2442 | + '<span class="dashicons dashicons-menu"></span>' |
|
| 2443 | + ); ?></p> |
|
| 2444 | 2444 | <?php |
| 2445 | - } |
|
| 2445 | + } |
|
| 2446 | 2446 | |
| 2447 | 2447 | |
| 2448 | - } |
|
| 2448 | + } |
|
| 2449 | 2449 | |
| 2450 | 2450 | |
| 2451 | - /** |
|
| 2452 | - * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2453 | - * |
|
| 2454 | - * @access protected |
|
| 2455 | - * @return void |
|
| 2456 | - * @throws EE_Error |
|
| 2457 | - * @throws InvalidArgumentException |
|
| 2458 | - * @throws ReflectionException |
|
| 2459 | - * @throws InvalidDataTypeException |
|
| 2460 | - * @throws InvalidInterfaceException |
|
| 2461 | - */ |
|
| 2462 | - protected function _set_shortcodes() |
|
| 2463 | - { |
|
| 2464 | - |
|
| 2465 | - //no need to run this if the property is already set |
|
| 2466 | - if ( ! empty($this->_shortcodes)) { |
|
| 2467 | - return; |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2471 | - } |
|
| 2451 | + /** |
|
| 2452 | + * used to set the $_shortcodes property for when its needed elsewhere. |
|
| 2453 | + * |
|
| 2454 | + * @access protected |
|
| 2455 | + * @return void |
|
| 2456 | + * @throws EE_Error |
|
| 2457 | + * @throws InvalidArgumentException |
|
| 2458 | + * @throws ReflectionException |
|
| 2459 | + * @throws InvalidDataTypeException |
|
| 2460 | + * @throws InvalidInterfaceException |
|
| 2461 | + */ |
|
| 2462 | + protected function _set_shortcodes() |
|
| 2463 | + { |
|
| 2464 | + |
|
| 2465 | + //no need to run this if the property is already set |
|
| 2466 | + if ( ! empty($this->_shortcodes)) { |
|
| 2467 | + return; |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + $this->_shortcodes = $this->_get_shortcodes(); |
|
| 2471 | + } |
|
| 2472 | 2472 | |
| 2473 | 2473 | |
| 2474 | - /** |
|
| 2475 | - * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2476 | - * property) |
|
| 2477 | - * |
|
| 2478 | - * @access protected |
|
| 2479 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2480 | - * for. Defaults to all (for the given context) |
|
| 2481 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2482 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2483 | - * true just an array of shortcode/label pairs. |
|
| 2484 | - * @throws EE_Error |
|
| 2485 | - * @throws InvalidArgumentException |
|
| 2486 | - * @throws ReflectionException |
|
| 2487 | - * @throws InvalidDataTypeException |
|
| 2488 | - * @throws InvalidInterfaceException |
|
| 2489 | - */ |
|
| 2490 | - protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2491 | - { |
|
| 2492 | - $this->_set_message_template_group(); |
|
| 2493 | - |
|
| 2494 | - //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2495 | - $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2496 | - ? absint($this->_req_data['id']) |
|
| 2497 | - : false; |
|
| 2498 | - $context = isset($this->_req_data['context']) |
|
| 2499 | - ? $this->_req_data['context'] |
|
| 2500 | - : key($this->_message_template_group->contexts_config()); |
|
| 2501 | - |
|
| 2502 | - return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2503 | - } |
|
| 2474 | + /** |
|
| 2475 | + * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes |
|
| 2476 | + * property) |
|
| 2477 | + * |
|
| 2478 | + * @access protected |
|
| 2479 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes |
|
| 2480 | + * for. Defaults to all (for the given context) |
|
| 2481 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes |
|
| 2482 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is |
|
| 2483 | + * true just an array of shortcode/label pairs. |
|
| 2484 | + * @throws EE_Error |
|
| 2485 | + * @throws InvalidArgumentException |
|
| 2486 | + * @throws ReflectionException |
|
| 2487 | + * @throws InvalidDataTypeException |
|
| 2488 | + * @throws InvalidInterfaceException |
|
| 2489 | + */ |
|
| 2490 | + protected function _get_shortcodes($fields = array(), $merged = true) |
|
| 2491 | + { |
|
| 2492 | + $this->_set_message_template_group(); |
|
| 2493 | + |
|
| 2494 | + //we need the messenger and message template to retrieve the valid shortcodes array. |
|
| 2495 | + $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) |
|
| 2496 | + ? absint($this->_req_data['id']) |
|
| 2497 | + : false; |
|
| 2498 | + $context = isset($this->_req_data['context']) |
|
| 2499 | + ? $this->_req_data['context'] |
|
| 2500 | + : key($this->_message_template_group->contexts_config()); |
|
| 2501 | + |
|
| 2502 | + return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array(); |
|
| 2503 | + } |
|
| 2504 | 2504 | |
| 2505 | 2505 | |
| 2506 | - /** |
|
| 2507 | - * This sets the _message_template property (containing the called message_template object) |
|
| 2508 | - * |
|
| 2509 | - * @access protected |
|
| 2510 | - * @return void |
|
| 2511 | - * @throws EE_Error |
|
| 2512 | - * @throws InvalidArgumentException |
|
| 2513 | - * @throws ReflectionException |
|
| 2514 | - * @throws InvalidDataTypeException |
|
| 2515 | - * @throws InvalidInterfaceException |
|
| 2516 | - */ |
|
| 2517 | - protected function _set_message_template_group() |
|
| 2518 | - { |
|
| 2519 | - |
|
| 2520 | - if ( ! empty($this->_message_template_group)) { |
|
| 2521 | - return; |
|
| 2522 | - } //get out if this is already set. |
|
| 2523 | - |
|
| 2524 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2525 | - $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2526 | - |
|
| 2527 | - //let's get the message templates |
|
| 2528 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2529 | - |
|
| 2530 | - if (empty($GRP_ID)) { |
|
| 2531 | - $this->_message_template_group = $MTP->create_default_object(); |
|
| 2532 | - } else { |
|
| 2533 | - $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2534 | - } |
|
| 2535 | - |
|
| 2536 | - $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2537 | - $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2538 | - |
|
| 2539 | - } |
|
| 2506 | + /** |
|
| 2507 | + * This sets the _message_template property (containing the called message_template object) |
|
| 2508 | + * |
|
| 2509 | + * @access protected |
|
| 2510 | + * @return void |
|
| 2511 | + * @throws EE_Error |
|
| 2512 | + * @throws InvalidArgumentException |
|
| 2513 | + * @throws ReflectionException |
|
| 2514 | + * @throws InvalidDataTypeException |
|
| 2515 | + * @throws InvalidInterfaceException |
|
| 2516 | + */ |
|
| 2517 | + protected function _set_message_template_group() |
|
| 2518 | + { |
|
| 2519 | + |
|
| 2520 | + if ( ! empty($this->_message_template_group)) { |
|
| 2521 | + return; |
|
| 2522 | + } //get out if this is already set. |
|
| 2523 | + |
|
| 2524 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false; |
|
| 2525 | + $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID; |
|
| 2526 | + |
|
| 2527 | + //let's get the message templates |
|
| 2528 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2529 | + |
|
| 2530 | + if (empty($GRP_ID)) { |
|
| 2531 | + $this->_message_template_group = $MTP->create_default_object(); |
|
| 2532 | + } else { |
|
| 2533 | + $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID); |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + $this->_template_pack = $this->_message_template_group->get_template_pack(); |
|
| 2537 | + $this->_variation = $this->_message_template_group->get_template_pack_variation(); |
|
| 2538 | + |
|
| 2539 | + } |
|
| 2540 | 2540 | |
| 2541 | 2541 | |
| 2542 | - /** |
|
| 2543 | - * sets up a context switcher for edit forms |
|
| 2544 | - * |
|
| 2545 | - * @access protected |
|
| 2546 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2547 | - * @param array $args various things the context switcher needs. |
|
| 2548 | - * @throws EE_Error |
|
| 2549 | - */ |
|
| 2550 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2551 | - { |
|
| 2552 | - $context_details = $template_group_object->contexts_config(); |
|
| 2553 | - $context_label = $template_group_object->context_label(); |
|
| 2554 | - ob_start(); |
|
| 2555 | - ?> |
|
| 2542 | + /** |
|
| 2543 | + * sets up a context switcher for edit forms |
|
| 2544 | + * |
|
| 2545 | + * @access protected |
|
| 2546 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form |
|
| 2547 | + * @param array $args various things the context switcher needs. |
|
| 2548 | + * @throws EE_Error |
|
| 2549 | + */ |
|
| 2550 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args) |
|
| 2551 | + { |
|
| 2552 | + $context_details = $template_group_object->contexts_config(); |
|
| 2553 | + $context_label = $template_group_object->context_label(); |
|
| 2554 | + ob_start(); |
|
| 2555 | + ?> |
|
| 2556 | 2556 | <div class="ee-msg-switcher-container"> |
| 2557 | 2557 | <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm"> |
| 2558 | 2558 | <?php |
| 2559 | - foreach ($args as $name => $value) { |
|
| 2560 | - if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2561 | - continue; |
|
| 2562 | - } |
|
| 2563 | - ?> |
|
| 2559 | + foreach ($args as $name => $value) { |
|
| 2560 | + if ($name === 'context' || empty($value) || $name === 'extra') { |
|
| 2561 | + continue; |
|
| 2562 | + } |
|
| 2563 | + ?> |
|
| 2564 | 2564 | <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/> |
| 2565 | 2565 | <?php |
| 2566 | - } |
|
| 2567 | - //setup nonce_url |
|
| 2568 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2569 | - ?> |
|
| 2566 | + } |
|
| 2567 | + //setup nonce_url |
|
| 2568 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false); |
|
| 2569 | + ?> |
|
| 2570 | 2570 | <select name="context"> |
| 2571 | 2571 | <?php |
| 2572 | - $context_templates = $template_group_object->context_templates(); |
|
| 2573 | - if (is_array($context_templates)) : |
|
| 2574 | - foreach ($context_templates as $context => $template_fields) : |
|
| 2575 | - $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2576 | - ?> |
|
| 2572 | + $context_templates = $template_group_object->context_templates(); |
|
| 2573 | + if (is_array($context_templates)) : |
|
| 2574 | + foreach ($context_templates as $context => $template_fields) : |
|
| 2575 | + $checked = ($context === $args['context']) ? 'selected="selected"' : ''; |
|
| 2576 | + ?> |
|
| 2577 | 2577 | <option value="<?php echo $context; ?>" <?php echo $checked; ?>> |
| 2578 | 2578 | <?php echo $context_details[$context]['label']; ?> |
| 2579 | 2579 | </option> |
@@ -2586,1823 +2586,1823 @@ discard block |
||
| 2586 | 2586 | <?php echo $args['extra']; ?> |
| 2587 | 2587 | </div> <!-- end .ee-msg-switcher-container --> |
| 2588 | 2588 | <?php |
| 2589 | - $output = ob_get_contents(); |
|
| 2590 | - ob_clean(); |
|
| 2591 | - $this->_context_switcher = $output; |
|
| 2592 | - } |
|
| 2589 | + $output = ob_get_contents(); |
|
| 2590 | + ob_clean(); |
|
| 2591 | + $this->_context_switcher = $output; |
|
| 2592 | + } |
|
| 2593 | 2593 | |
| 2594 | 2594 | |
| 2595 | - /** |
|
| 2596 | - * utility for sanitizing new values coming in. |
|
| 2597 | - * Note: this is only used when updating a context. |
|
| 2598 | - * |
|
| 2599 | - * @access protected |
|
| 2600 | - * |
|
| 2601 | - * @param int $index This helps us know which template field to select from the request array. |
|
| 2602 | - * |
|
| 2603 | - * @return array |
|
| 2604 | - */ |
|
| 2605 | - protected function _set_message_template_column_values($index) |
|
| 2606 | - { |
|
| 2607 | - if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2608 | - foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2609 | - $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2610 | - } |
|
| 2611 | - } |
|
| 2612 | - |
|
| 2613 | - |
|
| 2614 | - $set_column_values = array( |
|
| 2615 | - 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2616 | - 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2617 | - 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2618 | - 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2619 | - 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2620 | - 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2621 | - 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2622 | - 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2623 | - 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2624 | - ? absint($this->_req_data['MTP_is_global']) |
|
| 2625 | - : 0, |
|
| 2626 | - 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2627 | - ? absint($this->_req_data['MTP_is_override']) |
|
| 2628 | - : 0, |
|
| 2629 | - 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2630 | - 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2631 | - ); |
|
| 2632 | - |
|
| 2633 | - |
|
| 2634 | - return $set_column_values; |
|
| 2635 | - } |
|
| 2595 | + /** |
|
| 2596 | + * utility for sanitizing new values coming in. |
|
| 2597 | + * Note: this is only used when updating a context. |
|
| 2598 | + * |
|
| 2599 | + * @access protected |
|
| 2600 | + * |
|
| 2601 | + * @param int $index This helps us know which template field to select from the request array. |
|
| 2602 | + * |
|
| 2603 | + * @return array |
|
| 2604 | + */ |
|
| 2605 | + protected function _set_message_template_column_values($index) |
|
| 2606 | + { |
|
| 2607 | + if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) { |
|
| 2608 | + foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) { |
|
| 2609 | + $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value; |
|
| 2610 | + } |
|
| 2611 | + } |
|
| 2612 | + |
|
| 2613 | + |
|
| 2614 | + $set_column_values = array( |
|
| 2615 | + 'MTP_ID' => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']), |
|
| 2616 | + 'GRP_ID' => absint($this->_req_data['GRP_ID']), |
|
| 2617 | + 'MTP_user_id' => absint($this->_req_data['MTP_user_id']), |
|
| 2618 | + 'MTP_messenger' => strtolower($this->_req_data['MTP_messenger']), |
|
| 2619 | + 'MTP_message_type' => strtolower($this->_req_data['MTP_message_type']), |
|
| 2620 | + 'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']), |
|
| 2621 | + 'MTP_context' => strtolower($this->_req_data['MTP_context']), |
|
| 2622 | + 'MTP_content' => $this->_req_data['MTP_template_fields'][$index]['content'], |
|
| 2623 | + 'MTP_is_global' => isset($this->_req_data['MTP_is_global']) |
|
| 2624 | + ? absint($this->_req_data['MTP_is_global']) |
|
| 2625 | + : 0, |
|
| 2626 | + 'MTP_is_override' => isset($this->_req_data['MTP_is_override']) |
|
| 2627 | + ? absint($this->_req_data['MTP_is_override']) |
|
| 2628 | + : 0, |
|
| 2629 | + 'MTP_deleted' => absint($this->_req_data['MTP_deleted']), |
|
| 2630 | + 'MTP_is_active' => absint($this->_req_data['MTP_is_active']) |
|
| 2631 | + ); |
|
| 2632 | + |
|
| 2633 | + |
|
| 2634 | + return $set_column_values; |
|
| 2635 | + } |
|
| 2636 | 2636 | |
| 2637 | 2637 | |
| 2638 | - protected function _insert_or_update_message_template($new = false) |
|
| 2639 | - { |
|
| 2640 | - |
|
| 2641 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2642 | - $success = 0; |
|
| 2643 | - $override = false; |
|
| 2644 | - |
|
| 2645 | - //setup notices description |
|
| 2646 | - $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2647 | - |
|
| 2648 | - //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2649 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2650 | - $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2651 | - ? ucwords($messenger_object->label['singular']) |
|
| 2652 | - : ''; |
|
| 2653 | - |
|
| 2654 | - $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2655 | - ? $this->_req_data['MTP_message_type'] |
|
| 2656 | - : ''; |
|
| 2657 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2658 | - |
|
| 2659 | - $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2660 | - ? ucwords($message_type_object->label['singular']) |
|
| 2661 | - : ''; |
|
| 2662 | - |
|
| 2663 | - $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2664 | - ? $this->_req_data['MTP_context'] |
|
| 2665 | - : ''; |
|
| 2666 | - $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2667 | - |
|
| 2668 | - $item_desc = $messenger_label && $message_type_label |
|
| 2669 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2670 | - : ''; |
|
| 2671 | - $item_desc .= 'Message Template'; |
|
| 2672 | - $query_args = array(); |
|
| 2673 | - $edit_array = array(); |
|
| 2674 | - $action_desc = ''; |
|
| 2675 | - |
|
| 2676 | - //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2677 | - // user to edit. |
|
| 2678 | - if ($new) { |
|
| 2679 | - $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2680 | - if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2681 | - if (empty($edit_array)) { |
|
| 2682 | - $success = 0; |
|
| 2683 | - } else { |
|
| 2684 | - $success = 1; |
|
| 2685 | - $edit_array = $edit_array[0]; |
|
| 2686 | - $query_args = array( |
|
| 2687 | - 'id' => $edit_array['GRP_ID'], |
|
| 2688 | - 'context' => $edit_array['MTP_context'], |
|
| 2689 | - 'action' => 'edit_message_template' |
|
| 2690 | - ); |
|
| 2691 | - } |
|
| 2692 | - } |
|
| 2693 | - $action_desc = 'created'; |
|
| 2694 | - } else { |
|
| 2695 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2696 | - $MTP = EEM_Message_Template::instance(); |
|
| 2638 | + protected function _insert_or_update_message_template($new = false) |
|
| 2639 | + { |
|
| 2640 | + |
|
| 2641 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2642 | + $success = 0; |
|
| 2643 | + $override = false; |
|
| 2644 | + |
|
| 2645 | + //setup notices description |
|
| 2646 | + $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : ''; |
|
| 2647 | + |
|
| 2648 | + //need the message type and messenger objects to be able to use the labels for the notices |
|
| 2649 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug); |
|
| 2650 | + $messenger_label = $messenger_object instanceof EE_messenger |
|
| 2651 | + ? ucwords($messenger_object->label['singular']) |
|
| 2652 | + : ''; |
|
| 2653 | + |
|
| 2654 | + $message_type_slug = ! empty($this->_req_data['MTP_message_type']) |
|
| 2655 | + ? $this->_req_data['MTP_message_type'] |
|
| 2656 | + : ''; |
|
| 2657 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug); |
|
| 2658 | + |
|
| 2659 | + $message_type_label = $message_type_object instanceof EE_message_type |
|
| 2660 | + ? ucwords($message_type_object->label['singular']) |
|
| 2661 | + : ''; |
|
| 2662 | + |
|
| 2663 | + $context_slug = ! empty($this->_req_data['MTP_context']) |
|
| 2664 | + ? $this->_req_data['MTP_context'] |
|
| 2665 | + : ''; |
|
| 2666 | + $context = ucwords(str_replace('_', ' ', $context_slug)); |
|
| 2667 | + |
|
| 2668 | + $item_desc = $messenger_label && $message_type_label |
|
| 2669 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' |
|
| 2670 | + : ''; |
|
| 2671 | + $item_desc .= 'Message Template'; |
|
| 2672 | + $query_args = array(); |
|
| 2673 | + $edit_array = array(); |
|
| 2674 | + $action_desc = ''; |
|
| 2675 | + |
|
| 2676 | + //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for |
|
| 2677 | + // user to edit. |
|
| 2678 | + if ($new) { |
|
| 2679 | + $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0; |
|
| 2680 | + if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) { |
|
| 2681 | + if (empty($edit_array)) { |
|
| 2682 | + $success = 0; |
|
| 2683 | + } else { |
|
| 2684 | + $success = 1; |
|
| 2685 | + $edit_array = $edit_array[0]; |
|
| 2686 | + $query_args = array( |
|
| 2687 | + 'id' => $edit_array['GRP_ID'], |
|
| 2688 | + 'context' => $edit_array['MTP_context'], |
|
| 2689 | + 'action' => 'edit_message_template' |
|
| 2690 | + ); |
|
| 2691 | + } |
|
| 2692 | + } |
|
| 2693 | + $action_desc = 'created'; |
|
| 2694 | + } else { |
|
| 2695 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 2696 | + $MTP = EEM_Message_Template::instance(); |
|
| 2697 | 2697 | |
| 2698 | 2698 | |
| 2699 | - //run update for each template field in displayed context |
|
| 2700 | - if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2701 | - EE_Error::add_error( |
|
| 2702 | - esc_html__( |
|
| 2703 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2704 | - 'event_espresso' |
|
| 2705 | - ), |
|
| 2706 | - __FILE__, |
|
| 2707 | - __FUNCTION__, |
|
| 2708 | - __LINE__ |
|
| 2709 | - ); |
|
| 2710 | - $success = 0; |
|
| 2699 | + //run update for each template field in displayed context |
|
| 2700 | + if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) { |
|
| 2701 | + EE_Error::add_error( |
|
| 2702 | + esc_html__( |
|
| 2703 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.', |
|
| 2704 | + 'event_espresso' |
|
| 2705 | + ), |
|
| 2706 | + __FILE__, |
|
| 2707 | + __FUNCTION__, |
|
| 2708 | + __LINE__ |
|
| 2709 | + ); |
|
| 2710 | + $success = 0; |
|
| 2711 | 2711 | |
| 2712 | - } else { |
|
| 2713 | - //first validate all fields! |
|
| 2714 | - $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2715 | - $message_type_slug); |
|
| 2712 | + } else { |
|
| 2713 | + //first validate all fields! |
|
| 2714 | + $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug, |
|
| 2715 | + $message_type_slug); |
|
| 2716 | 2716 | |
| 2717 | - //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2718 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2719 | - // WE need to make sure there is no actual error messages in validates. |
|
| 2720 | - if (is_array($validates) && ! empty($validates)) { |
|
| 2721 | - //add the transient so when the form loads we know which fields to highlight |
|
| 2722 | - $this->_add_transient('edit_message_template', $validates); |
|
| 2717 | + //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an |
|
| 2718 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array. |
|
| 2719 | + // WE need to make sure there is no actual error messages in validates. |
|
| 2720 | + if (is_array($validates) && ! empty($validates)) { |
|
| 2721 | + //add the transient so when the form loads we know which fields to highlight |
|
| 2722 | + $this->_add_transient('edit_message_template', $validates); |
|
| 2723 | 2723 | |
| 2724 | - $success = 0; |
|
| 2724 | + $success = 0; |
|
| 2725 | 2725 | |
| 2726 | - //setup notices |
|
| 2727 | - foreach ($validates as $field => $error) { |
|
| 2728 | - if (isset($error['msg'])) { |
|
| 2729 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2730 | - } |
|
| 2731 | - } |
|
| 2726 | + //setup notices |
|
| 2727 | + foreach ($validates as $field => $error) { |
|
| 2728 | + if (isset($error['msg'])) { |
|
| 2729 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__); |
|
| 2730 | + } |
|
| 2731 | + } |
|
| 2732 | 2732 | |
| 2733 | - } else { |
|
| 2734 | - $set_column_values = array(); |
|
| 2735 | - foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2736 | - $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2733 | + } else { |
|
| 2734 | + $set_column_values = array(); |
|
| 2735 | + foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) { |
|
| 2736 | + $set_column_values = $this->_set_message_template_column_values($template_field); |
|
| 2737 | 2737 | |
| 2738 | - $where_cols_n_values = array( |
|
| 2739 | - 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2740 | - ); |
|
| 2738 | + $where_cols_n_values = array( |
|
| 2739 | + 'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'] |
|
| 2740 | + ); |
|
| 2741 | 2741 | |
| 2742 | - $message_template_fields = array( |
|
| 2743 | - 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2744 | - 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2745 | - 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2746 | - 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2747 | - ); |
|
| 2748 | - if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2749 | - if ($updated === false) { |
|
| 2750 | - EE_Error::add_error( |
|
| 2751 | - sprintf( |
|
| 2752 | - esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2753 | - $template_field |
|
| 2754 | - ), |
|
| 2755 | - __FILE__, |
|
| 2756 | - __FUNCTION__, |
|
| 2757 | - __LINE__ |
|
| 2758 | - ); |
|
| 2759 | - } else { |
|
| 2760 | - $success = 1; |
|
| 2761 | - } |
|
| 2762 | - } else { |
|
| 2763 | - //only do this logic if we don't have a MTP_ID for this field |
|
| 2764 | - if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2765 | - //this has already been through the template field validator and sanitized, so it will be |
|
| 2766 | - //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2767 | - //message template field in a messenger/message type and existing users don't have the |
|
| 2768 | - //default setup for it. |
|
| 2769 | - //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2770 | - $updated = $MTP->insert($message_template_fields); |
|
| 2771 | - if (! $updated || is_wp_error($updated)) { |
|
| 2772 | - EE_Error::add_error( |
|
| 2773 | - sprintf( |
|
| 2774 | - esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2775 | - $template_field |
|
| 2776 | - ), |
|
| 2777 | - __FILE__, |
|
| 2778 | - __FUNCTION__, |
|
| 2779 | - __LINE__ |
|
| 2780 | - ); |
|
| 2781 | - $success = 0; |
|
| 2782 | - } else { |
|
| 2783 | - $success = 1; |
|
| 2784 | - } |
|
| 2785 | - } |
|
| 2786 | - } |
|
| 2787 | - $action_desc = 'updated'; |
|
| 2788 | - } |
|
| 2742 | + $message_template_fields = array( |
|
| 2743 | + 'GRP_ID' => $set_column_values['GRP_ID'], |
|
| 2744 | + 'MTP_template_field' => $set_column_values['MTP_template_field'], |
|
| 2745 | + 'MTP_context' => $set_column_values['MTP_context'], |
|
| 2746 | + 'MTP_content' => $set_column_values['MTP_content'] |
|
| 2747 | + ); |
|
| 2748 | + if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) { |
|
| 2749 | + if ($updated === false) { |
|
| 2750 | + EE_Error::add_error( |
|
| 2751 | + sprintf( |
|
| 2752 | + esc_html__('%s field was NOT updated for some reason', 'event_espresso'), |
|
| 2753 | + $template_field |
|
| 2754 | + ), |
|
| 2755 | + __FILE__, |
|
| 2756 | + __FUNCTION__, |
|
| 2757 | + __LINE__ |
|
| 2758 | + ); |
|
| 2759 | + } else { |
|
| 2760 | + $success = 1; |
|
| 2761 | + } |
|
| 2762 | + } else { |
|
| 2763 | + //only do this logic if we don't have a MTP_ID for this field |
|
| 2764 | + if (empty($this->_req_data['MTP_template_fields'][$template_field]['MTP_ID'])) { |
|
| 2765 | + //this has already been through the template field validator and sanitized, so it will be |
|
| 2766 | + //safe to insert this field. Why insert? This typically happens when we introduce a new |
|
| 2767 | + //message template field in a messenger/message type and existing users don't have the |
|
| 2768 | + //default setup for it. |
|
| 2769 | + //@link https://events.codebasehq.com/projects/event-espresso/tickets/9465 |
|
| 2770 | + $updated = $MTP->insert($message_template_fields); |
|
| 2771 | + if (! $updated || is_wp_error($updated)) { |
|
| 2772 | + EE_Error::add_error( |
|
| 2773 | + sprintf( |
|
| 2774 | + esc_html__('%s field could not be updated.', 'event_espresso'), |
|
| 2775 | + $template_field |
|
| 2776 | + ), |
|
| 2777 | + __FILE__, |
|
| 2778 | + __FUNCTION__, |
|
| 2779 | + __LINE__ |
|
| 2780 | + ); |
|
| 2781 | + $success = 0; |
|
| 2782 | + } else { |
|
| 2783 | + $success = 1; |
|
| 2784 | + } |
|
| 2785 | + } |
|
| 2786 | + } |
|
| 2787 | + $action_desc = 'updated'; |
|
| 2788 | + } |
|
| 2789 | 2789 | |
| 2790 | - //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2791 | - $mtpg_fields = array( |
|
| 2792 | - 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2793 | - 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2794 | - 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2795 | - 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2796 | - 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2797 | - 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2798 | - 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2799 | - 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2800 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2801 | - : '', |
|
| 2802 | - 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2803 | - ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2804 | - : '' |
|
| 2805 | - ); |
|
| 2790 | + //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs) |
|
| 2791 | + $mtpg_fields = array( |
|
| 2792 | + 'MTP_user_id' => $set_column_values['MTP_user_id'], |
|
| 2793 | + 'MTP_messenger' => $set_column_values['MTP_messenger'], |
|
| 2794 | + 'MTP_message_type' => $set_column_values['MTP_message_type'], |
|
| 2795 | + 'MTP_is_global' => $set_column_values['MTP_is_global'], |
|
| 2796 | + 'MTP_is_override' => $set_column_values['MTP_is_override'], |
|
| 2797 | + 'MTP_deleted' => $set_column_values['MTP_deleted'], |
|
| 2798 | + 'MTP_is_active' => $set_column_values['MTP_is_active'], |
|
| 2799 | + 'MTP_name' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name']) |
|
| 2800 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_name'] |
|
| 2801 | + : '', |
|
| 2802 | + 'MTP_description' => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description']) |
|
| 2803 | + ? $this->_req_data['ee_msg_non_global_fields']['MTP_description'] |
|
| 2804 | + : '' |
|
| 2805 | + ); |
|
| 2806 | 2806 | |
| 2807 | - $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2808 | - $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2807 | + $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']); |
|
| 2808 | + $updated = $MTPG->update($mtpg_fields, array($mtpg_where)); |
|
| 2809 | 2809 | |
| 2810 | - if ($updated === false) { |
|
| 2811 | - EE_Error::add_error( |
|
| 2812 | - sprintf( |
|
| 2813 | - esc_html__( |
|
| 2814 | - 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2815 | - 'event_espresso' |
|
| 2816 | - ), |
|
| 2817 | - $set_column_values['GRP_ID'] |
|
| 2818 | - ), |
|
| 2819 | - __FILE__, |
|
| 2820 | - __FUNCTION__, |
|
| 2821 | - __LINE__ |
|
| 2822 | - ); |
|
| 2823 | - } else { |
|
| 2824 | - //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2825 | - $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2826 | - ? $this->_req_data['MTP_template_pack'] |
|
| 2827 | - : 'default'; |
|
| 2810 | + if ($updated === false) { |
|
| 2811 | + EE_Error::add_error( |
|
| 2812 | + sprintf( |
|
| 2813 | + esc_html__( |
|
| 2814 | + 'The Message Template Group (%d) was NOT updated for some reason', |
|
| 2815 | + 'event_espresso' |
|
| 2816 | + ), |
|
| 2817 | + $set_column_values['GRP_ID'] |
|
| 2818 | + ), |
|
| 2819 | + __FILE__, |
|
| 2820 | + __FUNCTION__, |
|
| 2821 | + __LINE__ |
|
| 2822 | + ); |
|
| 2823 | + } else { |
|
| 2824 | + //k now we need to ensure the template_pack and template_variation fields are set. |
|
| 2825 | + $template_pack = ! empty($this->_req_data['MTP_template_pack']) |
|
| 2826 | + ? $this->_req_data['MTP_template_pack'] |
|
| 2827 | + : 'default'; |
|
| 2828 | 2828 | |
| 2829 | - $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2830 | - ? $this->_req_data['MTP_template_variation'] |
|
| 2831 | - : 'default'; |
|
| 2829 | + $template_variation = ! empty($this->_req_data['MTP_template_variation']) |
|
| 2830 | + ? $this->_req_data['MTP_template_variation'] |
|
| 2831 | + : 'default'; |
|
| 2832 | 2832 | |
| 2833 | - $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2834 | - if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2835 | - $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2836 | - $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2837 | - } |
|
| 2838 | - $success = 1; |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - } |
|
| 2833 | + $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']); |
|
| 2834 | + if ($mtpg_obj instanceof EE_Message_Template_Group) { |
|
| 2835 | + $mtpg_obj->set_template_pack_name($template_pack); |
|
| 2836 | + $mtpg_obj->set_template_pack_variation($template_variation); |
|
| 2837 | + } |
|
| 2838 | + $success = 1; |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + } |
|
| 2842 | 2842 | |
| 2843 | - } |
|
| 2844 | - |
|
| 2845 | - //we return things differently if doing ajax |
|
| 2846 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2847 | - $this->_template_args['success'] = $success; |
|
| 2848 | - $this->_template_args['error'] = ! $success ? true : false; |
|
| 2849 | - $this->_template_args['content'] = ''; |
|
| 2850 | - $this->_template_args['data'] = array( |
|
| 2851 | - 'grpID' => $edit_array['GRP_ID'], |
|
| 2852 | - 'templateName' => $edit_array['template_name'] |
|
| 2853 | - ); |
|
| 2854 | - if ($success) { |
|
| 2855 | - EE_Error::overwrite_success(); |
|
| 2856 | - EE_Error::add_success( |
|
| 2857 | - esc_html__( |
|
| 2858 | - 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2859 | - 'event_espresso' |
|
| 2860 | - ) |
|
| 2861 | - ); |
|
| 2862 | - } |
|
| 2843 | + } |
|
| 2844 | + |
|
| 2845 | + //we return things differently if doing ajax |
|
| 2846 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 2847 | + $this->_template_args['success'] = $success; |
|
| 2848 | + $this->_template_args['error'] = ! $success ? true : false; |
|
| 2849 | + $this->_template_args['content'] = ''; |
|
| 2850 | + $this->_template_args['data'] = array( |
|
| 2851 | + 'grpID' => $edit_array['GRP_ID'], |
|
| 2852 | + 'templateName' => $edit_array['template_name'] |
|
| 2853 | + ); |
|
| 2854 | + if ($success) { |
|
| 2855 | + EE_Error::overwrite_success(); |
|
| 2856 | + EE_Error::add_success( |
|
| 2857 | + esc_html__( |
|
| 2858 | + 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.', |
|
| 2859 | + 'event_espresso' |
|
| 2860 | + ) |
|
| 2861 | + ); |
|
| 2862 | + } |
|
| 2863 | 2863 | |
| 2864 | - $this->_return_json(); |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - |
|
| 2868 | - //was a test send triggered? |
|
| 2869 | - if (isset($this->_req_data['test_button'])) { |
|
| 2870 | - EE_Error::overwrite_success(); |
|
| 2871 | - $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2872 | - $override = true; |
|
| 2873 | - } |
|
| 2874 | - |
|
| 2875 | - if (empty($query_args)) { |
|
| 2876 | - $query_args = array( |
|
| 2877 | - 'id' => $this->_req_data['GRP_ID'], |
|
| 2878 | - 'context' => $context_slug, |
|
| 2879 | - 'action' => 'edit_message_template' |
|
| 2880 | - ); |
|
| 2881 | - } |
|
| 2882 | - |
|
| 2883 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2884 | - } |
|
| 2864 | + $this->_return_json(); |
|
| 2865 | + } |
|
| 2866 | + |
|
| 2867 | + |
|
| 2868 | + //was a test send triggered? |
|
| 2869 | + if (isset($this->_req_data['test_button'])) { |
|
| 2870 | + EE_Error::overwrite_success(); |
|
| 2871 | + $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug); |
|
| 2872 | + $override = true; |
|
| 2873 | + } |
|
| 2874 | + |
|
| 2875 | + if (empty($query_args)) { |
|
| 2876 | + $query_args = array( |
|
| 2877 | + 'id' => $this->_req_data['GRP_ID'], |
|
| 2878 | + 'context' => $context_slug, |
|
| 2879 | + 'action' => 'edit_message_template' |
|
| 2880 | + ); |
|
| 2881 | + } |
|
| 2882 | + |
|
| 2883 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override); |
|
| 2884 | + } |
|
| 2885 | 2885 | |
| 2886 | 2886 | |
| 2887 | - /** |
|
| 2888 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2889 | - * |
|
| 2890 | - * @param string $context what context being tested |
|
| 2891 | - * @param string $messenger messenger being tested |
|
| 2892 | - * @param string $message_type message type being tested |
|
| 2893 | - * @throws EE_Error |
|
| 2894 | - * @throws InvalidArgumentException |
|
| 2895 | - * @throws InvalidDataTypeException |
|
| 2896 | - * @throws InvalidInterfaceException |
|
| 2897 | - */ |
|
| 2898 | - protected function _do_test_send($context, $messenger, $message_type) |
|
| 2899 | - { |
|
| 2900 | - //set things up for preview |
|
| 2901 | - $this->_req_data['messenger'] = $messenger; |
|
| 2902 | - $this->_req_data['message_type'] = $message_type; |
|
| 2903 | - $this->_req_data['context'] = $context; |
|
| 2904 | - $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2905 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2906 | - |
|
| 2907 | - //let's save any existing fields that might be required by the messenger |
|
| 2908 | - if ( |
|
| 2909 | - isset($this->_req_data['test_settings_fld']) |
|
| 2910 | - && $active_messenger instanceof EE_messenger |
|
| 2911 | - && apply_filters( |
|
| 2912 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2913 | - true, |
|
| 2914 | - $this->_req_data['test_settings_fld'], |
|
| 2915 | - $active_messenger |
|
| 2916 | - ) |
|
| 2917 | - ) { |
|
| 2918 | - $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2919 | - } |
|
| 2920 | - |
|
| 2921 | - $success = $this->_preview_message(true); |
|
| 2922 | - |
|
| 2923 | - if ($success) { |
|
| 2924 | - EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2925 | - } else { |
|
| 2926 | - EE_Error::add_error( |
|
| 2927 | - esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2928 | - __FILE__, |
|
| 2929 | - __FUNCTION__, |
|
| 2930 | - __LINE__ |
|
| 2931 | - ); |
|
| 2932 | - } |
|
| 2933 | - } |
|
| 2887 | + /** |
|
| 2888 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested |
|
| 2889 | + * |
|
| 2890 | + * @param string $context what context being tested |
|
| 2891 | + * @param string $messenger messenger being tested |
|
| 2892 | + * @param string $message_type message type being tested |
|
| 2893 | + * @throws EE_Error |
|
| 2894 | + * @throws InvalidArgumentException |
|
| 2895 | + * @throws InvalidDataTypeException |
|
| 2896 | + * @throws InvalidInterfaceException |
|
| 2897 | + */ |
|
| 2898 | + protected function _do_test_send($context, $messenger, $message_type) |
|
| 2899 | + { |
|
| 2900 | + //set things up for preview |
|
| 2901 | + $this->_req_data['messenger'] = $messenger; |
|
| 2902 | + $this->_req_data['message_type'] = $message_type; |
|
| 2903 | + $this->_req_data['context'] = $context; |
|
| 2904 | + $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : ''; |
|
| 2905 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 2906 | + |
|
| 2907 | + //let's save any existing fields that might be required by the messenger |
|
| 2908 | + if ( |
|
| 2909 | + isset($this->_req_data['test_settings_fld']) |
|
| 2910 | + && $active_messenger instanceof EE_messenger |
|
| 2911 | + && apply_filters( |
|
| 2912 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings', |
|
| 2913 | + true, |
|
| 2914 | + $this->_req_data['test_settings_fld'], |
|
| 2915 | + $active_messenger |
|
| 2916 | + ) |
|
| 2917 | + ) { |
|
| 2918 | + $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']); |
|
| 2919 | + } |
|
| 2920 | + |
|
| 2921 | + $success = $this->_preview_message(true); |
|
| 2922 | + |
|
| 2923 | + if ($success) { |
|
| 2924 | + EE_Error::add_success(__('Test message sent', 'event_espresso')); |
|
| 2925 | + } else { |
|
| 2926 | + EE_Error::add_error( |
|
| 2927 | + esc_html__('The test message was not sent', 'event_espresso'), |
|
| 2928 | + __FILE__, |
|
| 2929 | + __FUNCTION__, |
|
| 2930 | + __LINE__ |
|
| 2931 | + ); |
|
| 2932 | + } |
|
| 2933 | + } |
|
| 2934 | 2934 | |
| 2935 | 2935 | |
| 2936 | - /** |
|
| 2937 | - * _generate_new_templates |
|
| 2938 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2939 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2940 | - * for the event. |
|
| 2941 | - * |
|
| 2942 | - * |
|
| 2943 | - * @param string $messenger the messenger we are generating templates for |
|
| 2944 | - * @param array $message_types array of message types that the templates are generated for. |
|
| 2945 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2946 | - * indicate the message_template_group being used as the base. |
|
| 2947 | - * |
|
| 2948 | - * @param bool $global |
|
| 2949 | - * |
|
| 2950 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2951 | - * encountering problems. |
|
| 2952 | - * @throws EE_Error |
|
| 2953 | - */ |
|
| 2954 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2955 | - { |
|
| 2956 | - |
|
| 2957 | - //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2958 | - // just don't generate any templates. |
|
| 2959 | - if (empty($message_types)) { |
|
| 2960 | - return true; |
|
| 2961 | - } |
|
| 2962 | - |
|
| 2963 | - return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2964 | - } |
|
| 2936 | + /** |
|
| 2937 | + * _generate_new_templates |
|
| 2938 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will |
|
| 2939 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context |
|
| 2940 | + * for the event. |
|
| 2941 | + * |
|
| 2942 | + * |
|
| 2943 | + * @param string $messenger the messenger we are generating templates for |
|
| 2944 | + * @param array $message_types array of message types that the templates are generated for. |
|
| 2945 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to |
|
| 2946 | + * indicate the message_template_group being used as the base. |
|
| 2947 | + * |
|
| 2948 | + * @param bool $global |
|
| 2949 | + * |
|
| 2950 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if |
|
| 2951 | + * encountering problems. |
|
| 2952 | + * @throws EE_Error |
|
| 2953 | + */ |
|
| 2954 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false) |
|
| 2955 | + { |
|
| 2956 | + |
|
| 2957 | + //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we |
|
| 2958 | + // just don't generate any templates. |
|
| 2959 | + if (empty($message_types)) { |
|
| 2960 | + return true; |
|
| 2961 | + } |
|
| 2962 | + |
|
| 2963 | + return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global); |
|
| 2964 | + } |
|
| 2965 | 2965 | |
| 2966 | 2966 | |
| 2967 | - /** |
|
| 2968 | - * [_trash_or_restore_message_template] |
|
| 2969 | - * |
|
| 2970 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2971 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2972 | - * an individual context (FALSE). |
|
| 2973 | - * @return void |
|
| 2974 | - * @throws EE_Error |
|
| 2975 | - * @throws InvalidArgumentException |
|
| 2976 | - * @throws InvalidDataTypeException |
|
| 2977 | - * @throws InvalidInterfaceException |
|
| 2978 | - */ |
|
| 2979 | - protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2980 | - { |
|
| 2981 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2982 | - $MTP = EEM_Message_Template_Group::instance(); |
|
| 2983 | - |
|
| 2984 | - $success = 1; |
|
| 2985 | - |
|
| 2986 | - //incoming GRP_IDs |
|
| 2987 | - if ($all) { |
|
| 2988 | - //Checkboxes |
|
| 2989 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2990 | - //if array has more than one element then success message should be plural. |
|
| 2991 | - //todo: what about nonce? |
|
| 2992 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2967 | + /** |
|
| 2968 | + * [_trash_or_restore_message_template] |
|
| 2969 | + * |
|
| 2970 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE) |
|
| 2971 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just |
|
| 2972 | + * an individual context (FALSE). |
|
| 2973 | + * @return void |
|
| 2974 | + * @throws EE_Error |
|
| 2975 | + * @throws InvalidArgumentException |
|
| 2976 | + * @throws InvalidDataTypeException |
|
| 2977 | + * @throws InvalidInterfaceException |
|
| 2978 | + */ |
|
| 2979 | + protected function _trash_or_restore_message_template($trash = true, $all = false) |
|
| 2980 | + { |
|
| 2981 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2982 | + $MTP = EEM_Message_Template_Group::instance(); |
|
| 2983 | + |
|
| 2984 | + $success = 1; |
|
| 2985 | + |
|
| 2986 | + //incoming GRP_IDs |
|
| 2987 | + if ($all) { |
|
| 2988 | + //Checkboxes |
|
| 2989 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2990 | + //if array has more than one element then success message should be plural. |
|
| 2991 | + //todo: what about nonce? |
|
| 2992 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2993 | 2993 | |
| 2994 | - //cycle through checkboxes |
|
| 2995 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2996 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2997 | - if ( ! $trashed_or_restored) { |
|
| 2998 | - $success = 0; |
|
| 2999 | - } |
|
| 3000 | - } |
|
| 3001 | - } else { |
|
| 3002 | - //grab single GRP_ID and handle |
|
| 3003 | - $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3004 | - if ( ! empty($GRP_ID)) { |
|
| 3005 | - $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3006 | - if ( ! $trashed_or_restored) { |
|
| 3007 | - $success = 0; |
|
| 3008 | - } |
|
| 3009 | - } else { |
|
| 3010 | - $success = 0; |
|
| 3011 | - } |
|
| 3012 | - } |
|
| 2994 | + //cycle through checkboxes |
|
| 2995 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2996 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 2997 | + if ( ! $trashed_or_restored) { |
|
| 2998 | + $success = 0; |
|
| 2999 | + } |
|
| 3000 | + } |
|
| 3001 | + } else { |
|
| 3002 | + //grab single GRP_ID and handle |
|
| 3003 | + $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 3004 | + if ( ! empty($GRP_ID)) { |
|
| 3005 | + $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID); |
|
| 3006 | + if ( ! $trashed_or_restored) { |
|
| 3007 | + $success = 0; |
|
| 3008 | + } |
|
| 3009 | + } else { |
|
| 3010 | + $success = 0; |
|
| 3011 | + } |
|
| 3012 | + } |
|
| 3013 | 3013 | |
| 3014 | - } |
|
| 3014 | + } |
|
| 3015 | 3015 | |
| 3016 | - $action_desc = $trash |
|
| 3017 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3018 | - : esc_html__('restored', 'event_espresso'); |
|
| 3016 | + $action_desc = $trash |
|
| 3017 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3018 | + : esc_html__('restored', 'event_espresso'); |
|
| 3019 | 3019 | |
| 3020 | - $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3020 | + $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched') : $action_desc; |
|
| 3021 | 3021 | |
| 3022 | - $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3023 | - 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3022 | + $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success, |
|
| 3023 | + 'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); |
|
| 3024 | 3024 | |
| 3025 | - $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3026 | - 'event_espresso') : $item_desc; |
|
| 3025 | + $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success, |
|
| 3026 | + 'event_espresso') : $item_desc; |
|
| 3027 | 3027 | |
| 3028 | - $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3028 | + $this->_redirect_after_action($success, $item_desc, $action_desc, array()); |
|
| 3029 | 3029 | |
| 3030 | - } |
|
| 3030 | + } |
|
| 3031 | 3031 | |
| 3032 | 3032 | |
| 3033 | - /** |
|
| 3034 | - * [_delete_message_template] |
|
| 3035 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3036 | - * |
|
| 3037 | - * @return void |
|
| 3038 | - * @throws EE_Error |
|
| 3039 | - * @throws InvalidArgumentException |
|
| 3040 | - * @throws InvalidDataTypeException |
|
| 3041 | - * @throws InvalidInterfaceException |
|
| 3042 | - */ |
|
| 3043 | - protected function _delete_message_template() |
|
| 3044 | - { |
|
| 3045 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3046 | - |
|
| 3047 | - //checkboxes |
|
| 3048 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3049 | - //if array has more than one element then success message should be plural |
|
| 3050 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3033 | + /** |
|
| 3034 | + * [_delete_message_template] |
|
| 3035 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group. |
|
| 3036 | + * |
|
| 3037 | + * @return void |
|
| 3038 | + * @throws EE_Error |
|
| 3039 | + * @throws InvalidArgumentException |
|
| 3040 | + * @throws InvalidDataTypeException |
|
| 3041 | + * @throws InvalidInterfaceException |
|
| 3042 | + */ |
|
| 3043 | + protected function _delete_message_template() |
|
| 3044 | + { |
|
| 3045 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3046 | + |
|
| 3047 | + //checkboxes |
|
| 3048 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3049 | + //if array has more than one element then success message should be plural |
|
| 3050 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3051 | 3051 | |
| 3052 | - //cycle through bulk action checkboxes |
|
| 3053 | - while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3054 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3055 | - } |
|
| 3056 | - } else { |
|
| 3057 | - //grab single grp_id and delete |
|
| 3058 | - $GRP_ID = absint($this->_req_data['id']); |
|
| 3059 | - $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3060 | - } |
|
| 3061 | - |
|
| 3062 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3063 | - |
|
| 3064 | - } |
|
| 3052 | + //cycle through bulk action checkboxes |
|
| 3053 | + while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3054 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3055 | + } |
|
| 3056 | + } else { |
|
| 3057 | + //grab single grp_id and delete |
|
| 3058 | + $GRP_ID = absint($this->_req_data['id']); |
|
| 3059 | + $success = $this->_delete_mtp_permanently($GRP_ID); |
|
| 3060 | + } |
|
| 3061 | + |
|
| 3062 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', array()); |
|
| 3063 | + |
|
| 3064 | + } |
|
| 3065 | 3065 | |
| 3066 | 3066 | |
| 3067 | - /** |
|
| 3068 | - * helper for permanently deleting a mtP group and all related message_templates |
|
| 3069 | - * |
|
| 3070 | - * @param int $GRP_ID The group being deleted |
|
| 3071 | - * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3072 | - * @return bool boolean to indicate the success of the deletes or not. |
|
| 3073 | - * @throws EE_Error |
|
| 3074 | - * @throws InvalidArgumentException |
|
| 3075 | - * @throws InvalidDataTypeException |
|
| 3076 | - * @throws InvalidInterfaceException |
|
| 3077 | - */ |
|
| 3078 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3079 | - { |
|
| 3080 | - $success = 1; |
|
| 3081 | - $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3082 | - //first let's GET this group |
|
| 3083 | - $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3084 | - //then delete permanently all the related Message Templates |
|
| 3085 | - $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3086 | - |
|
| 3087 | - if ($deleted === 0) { |
|
| 3088 | - $success = 0; |
|
| 3089 | - } |
|
| 3090 | - |
|
| 3091 | - //now delete permanently this particular group |
|
| 3092 | - |
|
| 3093 | - if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3094 | - $success = 0; |
|
| 3095 | - } |
|
| 3096 | - |
|
| 3097 | - return $success; |
|
| 3098 | - } |
|
| 3067 | + /** |
|
| 3068 | + * helper for permanently deleting a mtP group and all related message_templates |
|
| 3069 | + * |
|
| 3070 | + * @param int $GRP_ID The group being deleted |
|
| 3071 | + * @param bool $include_group whether to delete the Message Template Group as well. |
|
| 3072 | + * @return bool boolean to indicate the success of the deletes or not. |
|
| 3073 | + * @throws EE_Error |
|
| 3074 | + * @throws InvalidArgumentException |
|
| 3075 | + * @throws InvalidDataTypeException |
|
| 3076 | + * @throws InvalidInterfaceException |
|
| 3077 | + */ |
|
| 3078 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true) |
|
| 3079 | + { |
|
| 3080 | + $success = 1; |
|
| 3081 | + $MTPG = EEM_Message_Template_Group::instance(); |
|
| 3082 | + //first let's GET this group |
|
| 3083 | + $MTG = $MTPG->get_one_by_ID($GRP_ID); |
|
| 3084 | + //then delete permanently all the related Message Templates |
|
| 3085 | + $deleted = $MTG->delete_related_permanently('Message_Template'); |
|
| 3086 | + |
|
| 3087 | + if ($deleted === 0) { |
|
| 3088 | + $success = 0; |
|
| 3089 | + } |
|
| 3090 | + |
|
| 3091 | + //now delete permanently this particular group |
|
| 3092 | + |
|
| 3093 | + if ($include_group && ! $MTG->delete_permanently()) { |
|
| 3094 | + $success = 0; |
|
| 3095 | + } |
|
| 3096 | + |
|
| 3097 | + return $success; |
|
| 3098 | + } |
|
| 3099 | 3099 | |
| 3100 | 3100 | |
| 3101 | - /** |
|
| 3102 | - * _learn_more_about_message_templates_link |
|
| 3103 | - * @access protected |
|
| 3104 | - * @return string |
|
| 3105 | - */ |
|
| 3106 | - protected function _learn_more_about_message_templates_link() |
|
| 3107 | - { |
|
| 3108 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3109 | - . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3110 | - . '</a>'; |
|
| 3111 | - } |
|
| 3101 | + /** |
|
| 3102 | + * _learn_more_about_message_templates_link |
|
| 3103 | + * @access protected |
|
| 3104 | + * @return string |
|
| 3105 | + */ |
|
| 3106 | + protected function _learn_more_about_message_templates_link() |
|
| 3107 | + { |
|
| 3108 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' |
|
| 3109 | + . esc_html__('learn more about how message templates works', 'event_espresso') |
|
| 3110 | + . '</a>'; |
|
| 3111 | + } |
|
| 3112 | 3112 | |
| 3113 | 3113 | |
| 3114 | - /** |
|
| 3115 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3116 | - * ajax and other routes. |
|
| 3117 | - * |
|
| 3118 | - * @return void |
|
| 3119 | - * @throws DomainException |
|
| 3120 | - */ |
|
| 3121 | - protected function _settings() |
|
| 3122 | - { |
|
| 3123 | - |
|
| 3124 | - |
|
| 3125 | - $this->_set_m_mt_settings(); |
|
| 3126 | - |
|
| 3127 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3128 | - ? $this->_req_data['selected_messenger'] |
|
| 3129 | - : 'email'; |
|
| 3130 | - |
|
| 3131 | - //let's setup the messenger tabs |
|
| 3132 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3133 | - $this->_m_mt_settings['messenger_tabs'], |
|
| 3134 | - 'messenger_links', |
|
| 3135 | - '|', |
|
| 3136 | - $selected_messenger |
|
| 3137 | - ); |
|
| 3138 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3139 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3140 | - |
|
| 3141 | - $this->display_admin_page_with_sidebar(); |
|
| 3142 | - |
|
| 3143 | - } |
|
| 3114 | + /** |
|
| 3115 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by |
|
| 3116 | + * ajax and other routes. |
|
| 3117 | + * |
|
| 3118 | + * @return void |
|
| 3119 | + * @throws DomainException |
|
| 3120 | + */ |
|
| 3121 | + protected function _settings() |
|
| 3122 | + { |
|
| 3123 | + |
|
| 3124 | + |
|
| 3125 | + $this->_set_m_mt_settings(); |
|
| 3126 | + |
|
| 3127 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3128 | + ? $this->_req_data['selected_messenger'] |
|
| 3129 | + : 'email'; |
|
| 3130 | + |
|
| 3131 | + //let's setup the messenger tabs |
|
| 3132 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( |
|
| 3133 | + $this->_m_mt_settings['messenger_tabs'], |
|
| 3134 | + 'messenger_links', |
|
| 3135 | + '|', |
|
| 3136 | + $selected_messenger |
|
| 3137 | + ); |
|
| 3138 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">'; |
|
| 3139 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->'; |
|
| 3140 | + |
|
| 3141 | + $this->display_admin_page_with_sidebar(); |
|
| 3142 | + |
|
| 3143 | + } |
|
| 3144 | 3144 | |
| 3145 | 3145 | |
| 3146 | - /** |
|
| 3147 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3148 | - * |
|
| 3149 | - * @access protected |
|
| 3150 | - * @return void |
|
| 3151 | - * @throws DomainException |
|
| 3152 | - */ |
|
| 3153 | - protected function _set_m_mt_settings() |
|
| 3154 | - { |
|
| 3155 | - //first if this is already set then lets get out no need to regenerate data. |
|
| 3156 | - if ( ! empty($this->_m_mt_settings)) { |
|
| 3157 | - return; |
|
| 3158 | - } |
|
| 3159 | - |
|
| 3160 | - //get all installed messengers and message_types |
|
| 3161 | - /** @type EE_messenger[] $messengers */ |
|
| 3162 | - $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3163 | - /** @type EE_message_type[] $message_types */ |
|
| 3164 | - $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3165 | - |
|
| 3166 | - |
|
| 3167 | - //assemble the array for the _tab_text_links helper |
|
| 3168 | - |
|
| 3169 | - foreach ($messengers as $messenger) { |
|
| 3170 | - $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3171 | - 'label' => ucwords($messenger->label['singular']), |
|
| 3172 | - 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3173 | - ? 'messenger-active' |
|
| 3174 | - : '', |
|
| 3175 | - 'href' => $messenger->name, |
|
| 3176 | - 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3177 | - 'slug' => $messenger->name, |
|
| 3178 | - 'obj' => $messenger |
|
| 3179 | - ); |
|
| 3146 | + /** |
|
| 3147 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page) |
|
| 3148 | + * |
|
| 3149 | + * @access protected |
|
| 3150 | + * @return void |
|
| 3151 | + * @throws DomainException |
|
| 3152 | + */ |
|
| 3153 | + protected function _set_m_mt_settings() |
|
| 3154 | + { |
|
| 3155 | + //first if this is already set then lets get out no need to regenerate data. |
|
| 3156 | + if ( ! empty($this->_m_mt_settings)) { |
|
| 3157 | + return; |
|
| 3158 | + } |
|
| 3159 | + |
|
| 3160 | + //get all installed messengers and message_types |
|
| 3161 | + /** @type EE_messenger[] $messengers */ |
|
| 3162 | + $messengers = $this->_message_resource_manager->installed_messengers(); |
|
| 3163 | + /** @type EE_message_type[] $message_types */ |
|
| 3164 | + $message_types = $this->_message_resource_manager->installed_message_types(); |
|
| 3165 | + |
|
| 3166 | + |
|
| 3167 | + //assemble the array for the _tab_text_links helper |
|
| 3168 | + |
|
| 3169 | + foreach ($messengers as $messenger) { |
|
| 3170 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array( |
|
| 3171 | + 'label' => ucwords($messenger->label['singular']), |
|
| 3172 | + 'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) |
|
| 3173 | + ? 'messenger-active' |
|
| 3174 | + : '', |
|
| 3175 | + 'href' => $messenger->name, |
|
| 3176 | + 'title' => esc_html__('Modify this Messenger', 'event_espresso'), |
|
| 3177 | + 'slug' => $messenger->name, |
|
| 3178 | + 'obj' => $messenger |
|
| 3179 | + ); |
|
| 3180 | 3180 | |
| 3181 | 3181 | |
| 3182 | - $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3182 | + $message_types_for_messenger = $messenger->get_valid_message_types(); |
|
| 3183 | 3183 | |
| 3184 | - foreach ($message_types as $message_type) { |
|
| 3185 | - //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3186 | - // it shouldn't show in either the inactive OR active metabox. |
|
| 3187 | - if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3188 | - continue; |
|
| 3189 | - } |
|
| 3184 | + foreach ($message_types as $message_type) { |
|
| 3185 | + //first we need to verify that this message type is valid with this messenger. Cause if it isn't then |
|
| 3186 | + // it shouldn't show in either the inactive OR active metabox. |
|
| 3187 | + if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { |
|
| 3188 | + continue; |
|
| 3189 | + } |
|
| 3190 | 3190 | |
| 3191 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3192 | - $messenger->name, |
|
| 3193 | - $message_type->name |
|
| 3194 | - ) |
|
| 3195 | - ? 'active' |
|
| 3196 | - : 'inactive'; |
|
| 3191 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3192 | + $messenger->name, |
|
| 3193 | + $message_type->name |
|
| 3194 | + ) |
|
| 3195 | + ? 'active' |
|
| 3196 | + : 'inactive'; |
|
| 3197 | 3197 | |
| 3198 | - $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3199 | - 'label' => ucwords($message_type->label['singular']), |
|
| 3200 | - 'class' => 'message-type-' . $a_or_i, |
|
| 3201 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3202 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3203 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3204 | - 'title' => $a_or_i === 'active' |
|
| 3205 | - ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3206 | - : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3207 | - 'content' => $a_or_i === 'active' |
|
| 3208 | - ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3209 | - : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3210 | - 'slug' => $message_type->name, |
|
| 3211 | - 'active' => $a_or_i === 'active', |
|
| 3212 | - 'obj' => $message_type |
|
| 3213 | - ); |
|
| 3214 | - } |
|
| 3215 | - } |
|
| 3216 | - } |
|
| 3198 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array( |
|
| 3199 | + 'label' => ucwords($message_type->label['singular']), |
|
| 3200 | + 'class' => 'message-type-' . $a_or_i, |
|
| 3201 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name, |
|
| 3202 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'), |
|
| 3203 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings', |
|
| 3204 | + 'title' => $a_or_i === 'active' |
|
| 3205 | + ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') |
|
| 3206 | + : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), |
|
| 3207 | + 'content' => $a_or_i === 'active' |
|
| 3208 | + ? $this->_message_type_settings_content($message_type, $messenger, true) |
|
| 3209 | + : $this->_message_type_settings_content($message_type, $messenger), |
|
| 3210 | + 'slug' => $message_type->name, |
|
| 3211 | + 'active' => $a_or_i === 'active', |
|
| 3212 | + 'obj' => $message_type |
|
| 3213 | + ); |
|
| 3214 | + } |
|
| 3215 | + } |
|
| 3216 | + } |
|
| 3217 | 3217 | |
| 3218 | 3218 | |
| 3219 | - /** |
|
| 3220 | - * This just prepares the content for the message type settings |
|
| 3221 | - * |
|
| 3222 | - * @param EE_message_type $message_type The message type object |
|
| 3223 | - * @param EE_messenger $messenger The messenger object |
|
| 3224 | - * @param boolean $active Whether the message type is active or not |
|
| 3225 | - * @return string html output for the content |
|
| 3226 | - * @throws DomainException |
|
| 3227 | - */ |
|
| 3228 | - protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3229 | - { |
|
| 3230 | - //get message type fields |
|
| 3231 | - $fields = $message_type->get_admin_settings_fields(); |
|
| 3232 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3233 | - |
|
| 3234 | - if ( ! empty($fields) && $active) { |
|
| 3219 | + /** |
|
| 3220 | + * This just prepares the content for the message type settings |
|
| 3221 | + * |
|
| 3222 | + * @param EE_message_type $message_type The message type object |
|
| 3223 | + * @param EE_messenger $messenger The messenger object |
|
| 3224 | + * @param boolean $active Whether the message type is active or not |
|
| 3225 | + * @return string html output for the content |
|
| 3226 | + * @throws DomainException |
|
| 3227 | + */ |
|
| 3228 | + protected function _message_type_settings_content($message_type, $messenger, $active = false) |
|
| 3229 | + { |
|
| 3230 | + //get message type fields |
|
| 3231 | + $fields = $message_type->get_admin_settings_fields(); |
|
| 3232 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3233 | + |
|
| 3234 | + if ( ! empty($fields) && $active) { |
|
| 3235 | 3235 | |
| 3236 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3236 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name); |
|
| 3237 | 3237 | |
| 3238 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3239 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3240 | - $template_form_field[$field_id] = array( |
|
| 3241 | - 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3242 | - 'label' => $fldprops['label'], |
|
| 3243 | - 'input' => $fldprops['field_type'], |
|
| 3244 | - 'type' => $fldprops['value_type'], |
|
| 3245 | - 'required' => $fldprops['required'], |
|
| 3246 | - 'validation' => $fldprops['validation'], |
|
| 3247 | - 'value' => isset($existing_settings[$fldname]) |
|
| 3248 | - ? $existing_settings[$fldname] |
|
| 3249 | - : $fldprops['default'], |
|
| 3250 | - 'options' => isset($fldprops['options']) |
|
| 3251 | - ? $fldprops['options'] |
|
| 3252 | - : array(), |
|
| 3253 | - 'default' => isset($existing_settings[$fldname]) |
|
| 3254 | - ? $existing_settings[$fldname] |
|
| 3255 | - : $fldprops['default'], |
|
| 3256 | - 'css_class' => 'no-drag', |
|
| 3257 | - 'format' => $fldprops['format'] |
|
| 3258 | - ); |
|
| 3259 | - } |
|
| 3238 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3239 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname; |
|
| 3240 | + $template_form_field[$field_id] = array( |
|
| 3241 | + 'name' => 'message_type_settings[' . $fldname . ']', |
|
| 3242 | + 'label' => $fldprops['label'], |
|
| 3243 | + 'input' => $fldprops['field_type'], |
|
| 3244 | + 'type' => $fldprops['value_type'], |
|
| 3245 | + 'required' => $fldprops['required'], |
|
| 3246 | + 'validation' => $fldprops['validation'], |
|
| 3247 | + 'value' => isset($existing_settings[$fldname]) |
|
| 3248 | + ? $existing_settings[$fldname] |
|
| 3249 | + : $fldprops['default'], |
|
| 3250 | + 'options' => isset($fldprops['options']) |
|
| 3251 | + ? $fldprops['options'] |
|
| 3252 | + : array(), |
|
| 3253 | + 'default' => isset($existing_settings[$fldname]) |
|
| 3254 | + ? $existing_settings[$fldname] |
|
| 3255 | + : $fldprops['default'], |
|
| 3256 | + 'css_class' => 'no-drag', |
|
| 3257 | + 'format' => $fldprops['format'] |
|
| 3258 | + ); |
|
| 3259 | + } |
|
| 3260 | 3260 | |
| 3261 | 3261 | |
| 3262 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3263 | - ? $this->_generate_admin_form_fields( |
|
| 3264 | - $template_form_field, |
|
| 3265 | - 'string', |
|
| 3266 | - 'ee_mt_activate_form' |
|
| 3267 | - ) |
|
| 3268 | - : ''; |
|
| 3269 | - } |
|
| 3270 | - |
|
| 3271 | - $settings_template_args['description'] = $message_type->description; |
|
| 3272 | - //we also need some hidden fields |
|
| 3273 | - $settings_template_args['hidden_fields'] = array( |
|
| 3274 | - 'message_type_settings[messenger]' => array( |
|
| 3275 | - 'type' => 'hidden', |
|
| 3276 | - 'value' => $messenger->name |
|
| 3277 | - ), |
|
| 3278 | - 'message_type_settings[message_type]' => array( |
|
| 3279 | - 'type' => 'hidden', |
|
| 3280 | - 'value' => $message_type->name |
|
| 3281 | - ), |
|
| 3282 | - 'type' => array( |
|
| 3283 | - 'type' => 'hidden', |
|
| 3284 | - 'value' => 'message_type' |
|
| 3285 | - ) |
|
| 3286 | - ); |
|
| 3287 | - |
|
| 3288 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3289 | - $settings_template_args['hidden_fields'], |
|
| 3290 | - 'array' |
|
| 3291 | - ); |
|
| 3292 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3293 | - ? ' hidden' |
|
| 3294 | - : ''; |
|
| 3295 | - |
|
| 3296 | - |
|
| 3297 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3298 | - $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3299 | - |
|
| 3300 | - return $content; |
|
| 3301 | - } |
|
| 3262 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3263 | + ? $this->_generate_admin_form_fields( |
|
| 3264 | + $template_form_field, |
|
| 3265 | + 'string', |
|
| 3266 | + 'ee_mt_activate_form' |
|
| 3267 | + ) |
|
| 3268 | + : ''; |
|
| 3269 | + } |
|
| 3270 | + |
|
| 3271 | + $settings_template_args['description'] = $message_type->description; |
|
| 3272 | + //we also need some hidden fields |
|
| 3273 | + $settings_template_args['hidden_fields'] = array( |
|
| 3274 | + 'message_type_settings[messenger]' => array( |
|
| 3275 | + 'type' => 'hidden', |
|
| 3276 | + 'value' => $messenger->name |
|
| 3277 | + ), |
|
| 3278 | + 'message_type_settings[message_type]' => array( |
|
| 3279 | + 'type' => 'hidden', |
|
| 3280 | + 'value' => $message_type->name |
|
| 3281 | + ), |
|
| 3282 | + 'type' => array( |
|
| 3283 | + 'type' => 'hidden', |
|
| 3284 | + 'value' => 'message_type' |
|
| 3285 | + ) |
|
| 3286 | + ); |
|
| 3287 | + |
|
| 3288 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3289 | + $settings_template_args['hidden_fields'], |
|
| 3290 | + 'array' |
|
| 3291 | + ); |
|
| 3292 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3293 | + ? ' hidden' |
|
| 3294 | + : ''; |
|
| 3295 | + |
|
| 3296 | + |
|
| 3297 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php'; |
|
| 3298 | + $content = EEH_Template::display_template($template, $settings_template_args, true); |
|
| 3299 | + |
|
| 3300 | + return $content; |
|
| 3301 | + } |
|
| 3302 | 3302 | |
| 3303 | 3303 | |
| 3304 | - /** |
|
| 3305 | - * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3306 | - * |
|
| 3307 | - * @access protected |
|
| 3308 | - * @return void |
|
| 3309 | - * @throws DomainException |
|
| 3310 | - */ |
|
| 3311 | - protected function _messages_settings_metaboxes() |
|
| 3312 | - { |
|
| 3313 | - $this->_set_m_mt_settings(); |
|
| 3314 | - $m_boxes = $mt_boxes = array(); |
|
| 3315 | - $m_template_args = $mt_template_args = array(); |
|
| 3316 | - |
|
| 3317 | - $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3318 | - ? $this->_req_data['selected_messenger'] |
|
| 3319 | - : 'email'; |
|
| 3320 | - |
|
| 3321 | - if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3322 | - foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3323 | - $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3324 | - $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3325 | - //messenger meta boxes |
|
| 3326 | - $active = $selected_messenger === $messenger; |
|
| 3327 | - $active_mt_tabs = isset( |
|
| 3328 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3329 | - ) |
|
| 3330 | - ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3331 | - : ''; |
|
| 3332 | - $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3333 | - esc_html__('%s Settings', 'event_espresso'), |
|
| 3334 | - $tab_array['label'] |
|
| 3335 | - ); |
|
| 3336 | - $m_template_args[$messenger . '_a_box'] = array( |
|
| 3337 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3338 | - 'inactive_message_types' => isset( |
|
| 3339 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3340 | - ) |
|
| 3341 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3342 | - : '', |
|
| 3343 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3344 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3345 | - 'hide_on_message' => $hide_on_message, |
|
| 3346 | - 'messenger' => $messenger, |
|
| 3347 | - 'active' => $active |
|
| 3348 | - ); |
|
| 3349 | - // message type meta boxes |
|
| 3350 | - // (which is really just the inactive container for each messenger |
|
| 3351 | - // showing inactive message types for that messenger) |
|
| 3352 | - $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3353 | - $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3354 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3355 | - 'inactive_message_types' => isset( |
|
| 3356 | - $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3357 | - ) |
|
| 3358 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3359 | - : '', |
|
| 3360 | - 'hidden' => $active ? '' : ' hidden', |
|
| 3361 | - 'hide_on_message' => $hide_on_message, |
|
| 3362 | - 'hide_off_message' => $hide_off_message, |
|
| 3363 | - 'messenger' => $messenger, |
|
| 3364 | - 'active' => $active |
|
| 3365 | - ); |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3368 | - |
|
| 3369 | - |
|
| 3370 | - //register messenger metaboxes |
|
| 3371 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3372 | - foreach ($m_boxes as $box => $label) { |
|
| 3373 | - $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3374 | - $msgr = str_replace('_a_box', '', $box); |
|
| 3375 | - add_meta_box( |
|
| 3376 | - 'espresso_' . $msgr . '_settings', |
|
| 3377 | - $label, |
|
| 3378 | - function ($post, $metabox) { |
|
| 3379 | - echo EEH_Template::display_template( |
|
| 3380 | - $metabox["args"]["template_path"], |
|
| 3381 | - $metabox["args"]["template_args"], |
|
| 3382 | - true |
|
| 3383 | - ); |
|
| 3384 | - }, |
|
| 3385 | - $this->_current_screen->id, |
|
| 3386 | - 'normal', |
|
| 3387 | - 'high', |
|
| 3388 | - $callback_args |
|
| 3389 | - ); |
|
| 3390 | - } |
|
| 3391 | - |
|
| 3392 | - //register message type metaboxes |
|
| 3393 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3394 | - foreach ($mt_boxes as $box => $label) { |
|
| 3395 | - $callback_args = array( |
|
| 3396 | - 'template_path' => $mt_template_path, |
|
| 3397 | - 'template_args' => $mt_template_args[$box] |
|
| 3398 | - ); |
|
| 3399 | - $mt = str_replace('_i_box', '', $box); |
|
| 3400 | - add_meta_box( |
|
| 3401 | - 'espresso_' . $mt . '_inactive_mts', |
|
| 3402 | - $label, |
|
| 3403 | - function ($post, $metabox) { |
|
| 3404 | - echo EEH_Template::display_template( |
|
| 3405 | - $metabox["args"]["template_path"], |
|
| 3406 | - $metabox["args"]["template_args"], |
|
| 3407 | - true |
|
| 3408 | - ); |
|
| 3409 | - }, |
|
| 3410 | - $this->_current_screen->id, |
|
| 3411 | - 'side', |
|
| 3412 | - 'high', |
|
| 3413 | - $callback_args |
|
| 3414 | - ); |
|
| 3415 | - } |
|
| 3416 | - |
|
| 3417 | - //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3418 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3419 | - if (is_main_site()) { |
|
| 3420 | - add_meta_box( |
|
| 3421 | - 'espresso_global_message_settings', |
|
| 3422 | - esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3423 | - array($this, 'global_messages_settings_metabox_content'), |
|
| 3424 | - $this->_current_screen->id, |
|
| 3425 | - 'normal', |
|
| 3426 | - 'low', |
|
| 3427 | - array() |
|
| 3428 | - ); |
|
| 3429 | - } |
|
| 3430 | - |
|
| 3431 | - } |
|
| 3304 | + /** |
|
| 3305 | + * Generate all the metaboxes for the message types and register them for the messages settings page. |
|
| 3306 | + * |
|
| 3307 | + * @access protected |
|
| 3308 | + * @return void |
|
| 3309 | + * @throws DomainException |
|
| 3310 | + */ |
|
| 3311 | + protected function _messages_settings_metaboxes() |
|
| 3312 | + { |
|
| 3313 | + $this->_set_m_mt_settings(); |
|
| 3314 | + $m_boxes = $mt_boxes = array(); |
|
| 3315 | + $m_template_args = $mt_template_args = array(); |
|
| 3316 | + |
|
| 3317 | + $selected_messenger = isset($this->_req_data['selected_messenger']) |
|
| 3318 | + ? $this->_req_data['selected_messenger'] |
|
| 3319 | + : 'email'; |
|
| 3320 | + |
|
| 3321 | + if (isset($this->_m_mt_settings['messenger_tabs'])) { |
|
| 3322 | + foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { |
|
| 3323 | + $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden'; |
|
| 3324 | + $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : ''; |
|
| 3325 | + //messenger meta boxes |
|
| 3326 | + $active = $selected_messenger === $messenger; |
|
| 3327 | + $active_mt_tabs = isset( |
|
| 3328 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3329 | + ) |
|
| 3330 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active'] |
|
| 3331 | + : ''; |
|
| 3332 | + $m_boxes[$messenger . '_a_box'] = sprintf( |
|
| 3333 | + esc_html__('%s Settings', 'event_espresso'), |
|
| 3334 | + $tab_array['label'] |
|
| 3335 | + ); |
|
| 3336 | + $m_template_args[$messenger . '_a_box'] = array( |
|
| 3337 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3338 | + 'inactive_message_types' => isset( |
|
| 3339 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3340 | + ) |
|
| 3341 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3342 | + : '', |
|
| 3343 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']), |
|
| 3344 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3345 | + 'hide_on_message' => $hide_on_message, |
|
| 3346 | + 'messenger' => $messenger, |
|
| 3347 | + 'active' => $active |
|
| 3348 | + ); |
|
| 3349 | + // message type meta boxes |
|
| 3350 | + // (which is really just the inactive container for each messenger |
|
| 3351 | + // showing inactive message types for that messenger) |
|
| 3352 | + $mt_boxes[$messenger . '_i_box'] = esc_html__('Inactive Message Types', 'event_espresso'); |
|
| 3353 | + $mt_template_args[$messenger . '_i_box'] = array( |
|
| 3354 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '', |
|
| 3355 | + 'inactive_message_types' => isset( |
|
| 3356 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'] |
|
| 3357 | + ) |
|
| 3358 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']) |
|
| 3359 | + : '', |
|
| 3360 | + 'hidden' => $active ? '' : ' hidden', |
|
| 3361 | + 'hide_on_message' => $hide_on_message, |
|
| 3362 | + 'hide_off_message' => $hide_off_message, |
|
| 3363 | + 'messenger' => $messenger, |
|
| 3364 | + 'active' => $active |
|
| 3365 | + ); |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3368 | + |
|
| 3369 | + |
|
| 3370 | + //register messenger metaboxes |
|
| 3371 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php'; |
|
| 3372 | + foreach ($m_boxes as $box => $label) { |
|
| 3373 | + $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]); |
|
| 3374 | + $msgr = str_replace('_a_box', '', $box); |
|
| 3375 | + add_meta_box( |
|
| 3376 | + 'espresso_' . $msgr . '_settings', |
|
| 3377 | + $label, |
|
| 3378 | + function ($post, $metabox) { |
|
| 3379 | + echo EEH_Template::display_template( |
|
| 3380 | + $metabox["args"]["template_path"], |
|
| 3381 | + $metabox["args"]["template_args"], |
|
| 3382 | + true |
|
| 3383 | + ); |
|
| 3384 | + }, |
|
| 3385 | + $this->_current_screen->id, |
|
| 3386 | + 'normal', |
|
| 3387 | + 'high', |
|
| 3388 | + $callback_args |
|
| 3389 | + ); |
|
| 3390 | + } |
|
| 3391 | + |
|
| 3392 | + //register message type metaboxes |
|
| 3393 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php'; |
|
| 3394 | + foreach ($mt_boxes as $box => $label) { |
|
| 3395 | + $callback_args = array( |
|
| 3396 | + 'template_path' => $mt_template_path, |
|
| 3397 | + 'template_args' => $mt_template_args[$box] |
|
| 3398 | + ); |
|
| 3399 | + $mt = str_replace('_i_box', '', $box); |
|
| 3400 | + add_meta_box( |
|
| 3401 | + 'espresso_' . $mt . '_inactive_mts', |
|
| 3402 | + $label, |
|
| 3403 | + function ($post, $metabox) { |
|
| 3404 | + echo EEH_Template::display_template( |
|
| 3405 | + $metabox["args"]["template_path"], |
|
| 3406 | + $metabox["args"]["template_args"], |
|
| 3407 | + true |
|
| 3408 | + ); |
|
| 3409 | + }, |
|
| 3410 | + $this->_current_screen->id, |
|
| 3411 | + 'side', |
|
| 3412 | + 'high', |
|
| 3413 | + $callback_args |
|
| 3414 | + ); |
|
| 3415 | + } |
|
| 3416 | + |
|
| 3417 | + //register metabox for global messages settings but only when on the main site. On single site installs this |
|
| 3418 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site. |
|
| 3419 | + if (is_main_site()) { |
|
| 3420 | + add_meta_box( |
|
| 3421 | + 'espresso_global_message_settings', |
|
| 3422 | + esc_html__('Global Message Settings', 'event_espresso'), |
|
| 3423 | + array($this, 'global_messages_settings_metabox_content'), |
|
| 3424 | + $this->_current_screen->id, |
|
| 3425 | + 'normal', |
|
| 3426 | + 'low', |
|
| 3427 | + array() |
|
| 3428 | + ); |
|
| 3429 | + } |
|
| 3430 | + |
|
| 3431 | + } |
|
| 3432 | 3432 | |
| 3433 | 3433 | |
| 3434 | - /** |
|
| 3435 | - * This generates the content for the global messages settings metabox. |
|
| 3436 | - * |
|
| 3437 | - * @return string |
|
| 3438 | - * @throws EE_Error |
|
| 3439 | - * @throws InvalidArgumentException |
|
| 3440 | - * @throws ReflectionException |
|
| 3441 | - * @throws InvalidDataTypeException |
|
| 3442 | - * @throws InvalidInterfaceException |
|
| 3443 | - */ |
|
| 3444 | - public function global_messages_settings_metabox_content() |
|
| 3445 | - { |
|
| 3446 | - $form = $this->_generate_global_settings_form(); |
|
| 3447 | - echo $form->form_open( |
|
| 3448 | - $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3449 | - 'POST' |
|
| 3450 | - ) |
|
| 3451 | - . $form->get_html() |
|
| 3452 | - . $form->form_close(); |
|
| 3453 | - } |
|
| 3434 | + /** |
|
| 3435 | + * This generates the content for the global messages settings metabox. |
|
| 3436 | + * |
|
| 3437 | + * @return string |
|
| 3438 | + * @throws EE_Error |
|
| 3439 | + * @throws InvalidArgumentException |
|
| 3440 | + * @throws ReflectionException |
|
| 3441 | + * @throws InvalidDataTypeException |
|
| 3442 | + * @throws InvalidInterfaceException |
|
| 3443 | + */ |
|
| 3444 | + public function global_messages_settings_metabox_content() |
|
| 3445 | + { |
|
| 3446 | + $form = $this->_generate_global_settings_form(); |
|
| 3447 | + echo $form->form_open( |
|
| 3448 | + $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL), |
|
| 3449 | + 'POST' |
|
| 3450 | + ) |
|
| 3451 | + . $form->get_html() |
|
| 3452 | + . $form->form_close(); |
|
| 3453 | + } |
|
| 3454 | 3454 | |
| 3455 | 3455 | |
| 3456 | - /** |
|
| 3457 | - * This generates and returns the form object for the global messages settings. |
|
| 3458 | - * |
|
| 3459 | - * @return EE_Form_Section_Proper |
|
| 3460 | - * @throws EE_Error |
|
| 3461 | - * @throws InvalidArgumentException |
|
| 3462 | - * @throws ReflectionException |
|
| 3463 | - * @throws InvalidDataTypeException |
|
| 3464 | - * @throws InvalidInterfaceException |
|
| 3465 | - */ |
|
| 3466 | - protected function _generate_global_settings_form() |
|
| 3467 | - { |
|
| 3468 | - EE_Registry::instance()->load_helper('HTML'); |
|
| 3469 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3470 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3471 | - |
|
| 3472 | - return new EE_Form_Section_Proper( |
|
| 3473 | - array( |
|
| 3474 | - 'name' => 'global_messages_settings', |
|
| 3475 | - 'html_id' => 'global_messages_settings', |
|
| 3476 | - 'html_class' => 'form-table', |
|
| 3477 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3478 | - 'subsections' => apply_filters( |
|
| 3479 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3480 | - array( |
|
| 3481 | - 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3482 | - array( |
|
| 3483 | - true => esc_html__("On the same request", "event_espresso"), |
|
| 3484 | - false => esc_html__("On a separate request", "event_espresso") |
|
| 3485 | - ), |
|
| 3486 | - array( |
|
| 3487 | - 'default' => $network_config->do_messages_on_same_request, |
|
| 3488 | - 'html_label_text' => esc_html__( |
|
| 3489 | - 'Generate and send all messages:', |
|
| 3490 | - 'event_espresso' |
|
| 3491 | - ), |
|
| 3492 | - 'html_help_text' => esc_html__( |
|
| 3493 | - 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3494 | - 'event_espresso' |
|
| 3495 | - ), |
|
| 3496 | - ) |
|
| 3497 | - ), |
|
| 3498 | - 'delete_threshold' => new EE_Select_Input( |
|
| 3499 | - array( |
|
| 3500 | - 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3501 | - 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3502 | - 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3503 | - 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3504 | - 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3505 | - 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3506 | - 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3507 | - ), |
|
| 3508 | - array( |
|
| 3509 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3510 | - 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3511 | - 'html_help_text' => esc_html__( |
|
| 3512 | - 'You can control how long a record of processed messages is kept via this option.', |
|
| 3513 | - 'event_espresso' |
|
| 3514 | - ), |
|
| 3515 | - ) |
|
| 3516 | - ), |
|
| 3517 | - 'update_settings' => new EE_Submit_Input( |
|
| 3518 | - array( |
|
| 3519 | - 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3520 | - 'html_label_text' => ' ' |
|
| 3521 | - ) |
|
| 3522 | - ) |
|
| 3523 | - ) |
|
| 3524 | - ) |
|
| 3525 | - ) |
|
| 3526 | - ); |
|
| 3527 | - } |
|
| 3456 | + /** |
|
| 3457 | + * This generates and returns the form object for the global messages settings. |
|
| 3458 | + * |
|
| 3459 | + * @return EE_Form_Section_Proper |
|
| 3460 | + * @throws EE_Error |
|
| 3461 | + * @throws InvalidArgumentException |
|
| 3462 | + * @throws ReflectionException |
|
| 3463 | + * @throws InvalidDataTypeException |
|
| 3464 | + * @throws InvalidInterfaceException |
|
| 3465 | + */ |
|
| 3466 | + protected function _generate_global_settings_form() |
|
| 3467 | + { |
|
| 3468 | + EE_Registry::instance()->load_helper('HTML'); |
|
| 3469 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3470 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3471 | + |
|
| 3472 | + return new EE_Form_Section_Proper( |
|
| 3473 | + array( |
|
| 3474 | + 'name' => 'global_messages_settings', |
|
| 3475 | + 'html_id' => 'global_messages_settings', |
|
| 3476 | + 'html_class' => 'form-table', |
|
| 3477 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 3478 | + 'subsections' => apply_filters( |
|
| 3479 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections', |
|
| 3480 | + array( |
|
| 3481 | + 'do_messages_on_same_request' => new EE_Select_Input( |
|
| 3482 | + array( |
|
| 3483 | + true => esc_html__("On the same request", "event_espresso"), |
|
| 3484 | + false => esc_html__("On a separate request", "event_espresso") |
|
| 3485 | + ), |
|
| 3486 | + array( |
|
| 3487 | + 'default' => $network_config->do_messages_on_same_request, |
|
| 3488 | + 'html_label_text' => esc_html__( |
|
| 3489 | + 'Generate and send all messages:', |
|
| 3490 | + 'event_espresso' |
|
| 3491 | + ), |
|
| 3492 | + 'html_help_text' => esc_html__( |
|
| 3493 | + 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.', |
|
| 3494 | + 'event_espresso' |
|
| 3495 | + ), |
|
| 3496 | + ) |
|
| 3497 | + ), |
|
| 3498 | + 'delete_threshold' => new EE_Select_Input( |
|
| 3499 | + array( |
|
| 3500 | + 0 => esc_html__('Forever', 'event_espresso'), |
|
| 3501 | + 3 => esc_html__('3 Months', 'event_espresso'), |
|
| 3502 | + 6 => esc_html__('6 Months', 'event_espresso'), |
|
| 3503 | + 9 => esc_html__('9 Months', 'event_espresso'), |
|
| 3504 | + 12 => esc_html__('12 Months', 'event_espresso'), |
|
| 3505 | + 24 => esc_html__('24 Months', 'event_espresso'), |
|
| 3506 | + 36 => esc_html__('36 Months', 'event_espresso') |
|
| 3507 | + ), |
|
| 3508 | + array( |
|
| 3509 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold, |
|
| 3510 | + 'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), |
|
| 3511 | + 'html_help_text' => esc_html__( |
|
| 3512 | + 'You can control how long a record of processed messages is kept via this option.', |
|
| 3513 | + 'event_espresso' |
|
| 3514 | + ), |
|
| 3515 | + ) |
|
| 3516 | + ), |
|
| 3517 | + 'update_settings' => new EE_Submit_Input( |
|
| 3518 | + array( |
|
| 3519 | + 'default' => esc_html__('Update', 'event_espresso'), |
|
| 3520 | + 'html_label_text' => ' ' |
|
| 3521 | + ) |
|
| 3522 | + ) |
|
| 3523 | + ) |
|
| 3524 | + ) |
|
| 3525 | + ) |
|
| 3526 | + ); |
|
| 3527 | + } |
|
| 3528 | 3528 | |
| 3529 | 3529 | |
| 3530 | - /** |
|
| 3531 | - * This handles updating the global settings set on the admin page. |
|
| 3532 | - * |
|
| 3533 | - * @throws EE_Error |
|
| 3534 | - * @throws InvalidDataTypeException |
|
| 3535 | - * @throws InvalidInterfaceException |
|
| 3536 | - * @throws InvalidArgumentException |
|
| 3537 | - * @throws ReflectionException |
|
| 3538 | - */ |
|
| 3539 | - protected function _update_global_settings() |
|
| 3540 | - { |
|
| 3541 | - /** @var EE_Network_Core_Config $network_config */ |
|
| 3542 | - $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3543 | - $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3544 | - $form = $this->_generate_global_settings_form(); |
|
| 3545 | - if ($form->was_submitted()) { |
|
| 3546 | - $form->receive_form_submission(); |
|
| 3547 | - if ($form->is_valid()) { |
|
| 3548 | - $valid_data = $form->valid_data(); |
|
| 3549 | - foreach ($valid_data as $property => $value) { |
|
| 3550 | - $setter = 'set_' . $property; |
|
| 3551 | - if (method_exists($network_config, $setter)) { |
|
| 3552 | - $network_config->{$setter}($value); |
|
| 3553 | - } else if ( |
|
| 3554 | - property_exists($network_config, $property) |
|
| 3555 | - && $network_config->{$property} !== $value |
|
| 3556 | - ) { |
|
| 3557 | - $network_config->{$property} = $value; |
|
| 3558 | - } else if ( |
|
| 3559 | - property_exists($messages_config, $property) |
|
| 3560 | - && $messages_config->{$property} !== $value |
|
| 3561 | - ) { |
|
| 3562 | - $messages_config->{$property} = $value; |
|
| 3563 | - } |
|
| 3564 | - } |
|
| 3565 | - //only update if the form submission was valid! |
|
| 3566 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3567 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3568 | - EE_Error::overwrite_success(); |
|
| 3569 | - EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3570 | - } |
|
| 3571 | - } |
|
| 3572 | - $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3573 | - } |
|
| 3530 | + /** |
|
| 3531 | + * This handles updating the global settings set on the admin page. |
|
| 3532 | + * |
|
| 3533 | + * @throws EE_Error |
|
| 3534 | + * @throws InvalidDataTypeException |
|
| 3535 | + * @throws InvalidInterfaceException |
|
| 3536 | + * @throws InvalidArgumentException |
|
| 3537 | + * @throws ReflectionException |
|
| 3538 | + */ |
|
| 3539 | + protected function _update_global_settings() |
|
| 3540 | + { |
|
| 3541 | + /** @var EE_Network_Core_Config $network_config */ |
|
| 3542 | + $network_config = EE_Registry::instance()->NET_CFG->core; |
|
| 3543 | + $messages_config = EE_Registry::instance()->CFG->messages; |
|
| 3544 | + $form = $this->_generate_global_settings_form(); |
|
| 3545 | + if ($form->was_submitted()) { |
|
| 3546 | + $form->receive_form_submission(); |
|
| 3547 | + if ($form->is_valid()) { |
|
| 3548 | + $valid_data = $form->valid_data(); |
|
| 3549 | + foreach ($valid_data as $property => $value) { |
|
| 3550 | + $setter = 'set_' . $property; |
|
| 3551 | + if (method_exists($network_config, $setter)) { |
|
| 3552 | + $network_config->{$setter}($value); |
|
| 3553 | + } else if ( |
|
| 3554 | + property_exists($network_config, $property) |
|
| 3555 | + && $network_config->{$property} !== $value |
|
| 3556 | + ) { |
|
| 3557 | + $network_config->{$property} = $value; |
|
| 3558 | + } else if ( |
|
| 3559 | + property_exists($messages_config, $property) |
|
| 3560 | + && $messages_config->{$property} !== $value |
|
| 3561 | + ) { |
|
| 3562 | + $messages_config->{$property} = $value; |
|
| 3563 | + } |
|
| 3564 | + } |
|
| 3565 | + //only update if the form submission was valid! |
|
| 3566 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 3567 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 3568 | + EE_Error::overwrite_success(); |
|
| 3569 | + EE_Error::add_success(__('Global message settings were updated', 'event_espresso')); |
|
| 3570 | + } |
|
| 3571 | + } |
|
| 3572 | + $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true); |
|
| 3573 | + } |
|
| 3574 | 3574 | |
| 3575 | 3575 | |
| 3576 | - /** |
|
| 3577 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3578 | - * |
|
| 3579 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3580 | - * @return string html formatted tabs |
|
| 3581 | - * @throws DomainException |
|
| 3582 | - */ |
|
| 3583 | - protected function _get_mt_tabs($tab_array) |
|
| 3584 | - { |
|
| 3585 | - $tab_array = (array)$tab_array; |
|
| 3586 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3587 | - $tabs = ''; |
|
| 3588 | - |
|
| 3589 | - foreach ($tab_array as $tab) { |
|
| 3590 | - $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3591 | - } |
|
| 3592 | - |
|
| 3593 | - return $tabs; |
|
| 3594 | - } |
|
| 3576 | + /** |
|
| 3577 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate |
|
| 3578 | + * |
|
| 3579 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs |
|
| 3580 | + * @return string html formatted tabs |
|
| 3581 | + * @throws DomainException |
|
| 3582 | + */ |
|
| 3583 | + protected function _get_mt_tabs($tab_array) |
|
| 3584 | + { |
|
| 3585 | + $tab_array = (array)$tab_array; |
|
| 3586 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php'; |
|
| 3587 | + $tabs = ''; |
|
| 3588 | + |
|
| 3589 | + foreach ($tab_array as $tab) { |
|
| 3590 | + $tabs .= EEH_Template::display_template($template, $tab, true); |
|
| 3591 | + } |
|
| 3592 | + |
|
| 3593 | + return $tabs; |
|
| 3594 | + } |
|
| 3595 | 3595 | |
| 3596 | 3596 | |
| 3597 | - /** |
|
| 3598 | - * This prepares the content of the messenger meta box admin settings |
|
| 3599 | - * |
|
| 3600 | - * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3601 | - * @return string html formatted content |
|
| 3602 | - * @throws DomainException |
|
| 3603 | - */ |
|
| 3604 | - protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3605 | - { |
|
| 3597 | + /** |
|
| 3598 | + * This prepares the content of the messenger meta box admin settings |
|
| 3599 | + * |
|
| 3600 | + * @param EE_messenger $messenger The messenger we're setting up content for |
|
| 3601 | + * @return string html formatted content |
|
| 3602 | + * @throws DomainException |
|
| 3603 | + */ |
|
| 3604 | + protected function _get_messenger_box_content(EE_messenger $messenger) |
|
| 3605 | + { |
|
| 3606 | 3606 | |
| 3607 | - $fields = $messenger->get_admin_settings_fields(); |
|
| 3608 | - $settings_template_args['template_form_fields'] = ''; |
|
| 3607 | + $fields = $messenger->get_admin_settings_fields(); |
|
| 3608 | + $settings_template_args['template_form_fields'] = ''; |
|
| 3609 | 3609 | |
| 3610 | - //is $messenger active? |
|
| 3611 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3610 | + //is $messenger active? |
|
| 3611 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3612 | 3612 | |
| 3613 | 3613 | |
| 3614 | - if ( ! empty($fields)) { |
|
| 3614 | + if ( ! empty($fields)) { |
|
| 3615 | 3615 | |
| 3616 | - $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3616 | + $existing_settings = $messenger->get_existing_admin_settings(); |
|
| 3617 | 3617 | |
| 3618 | - foreach ($fields as $fldname => $fldprops) { |
|
| 3619 | - $field_id = $messenger->name . '-' . $fldname; |
|
| 3620 | - $template_form_field[$field_id] = array( |
|
| 3621 | - 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3622 | - 'label' => $fldprops['label'], |
|
| 3623 | - 'input' => $fldprops['field_type'], |
|
| 3624 | - 'type' => $fldprops['value_type'], |
|
| 3625 | - 'required' => $fldprops['required'], |
|
| 3626 | - 'validation' => $fldprops['validation'], |
|
| 3627 | - 'value' => isset($existing_settings[$field_id]) |
|
| 3628 | - ? $existing_settings[$field_id] |
|
| 3629 | - : $fldprops['default'], |
|
| 3630 | - 'css_class' => '', |
|
| 3631 | - 'format' => $fldprops['format'] |
|
| 3632 | - ); |
|
| 3633 | - } |
|
| 3618 | + foreach ($fields as $fldname => $fldprops) { |
|
| 3619 | + $field_id = $messenger->name . '-' . $fldname; |
|
| 3620 | + $template_form_field[$field_id] = array( |
|
| 3621 | + 'name' => 'messenger_settings[' . $field_id . ']', |
|
| 3622 | + 'label' => $fldprops['label'], |
|
| 3623 | + 'input' => $fldprops['field_type'], |
|
| 3624 | + 'type' => $fldprops['value_type'], |
|
| 3625 | + 'required' => $fldprops['required'], |
|
| 3626 | + 'validation' => $fldprops['validation'], |
|
| 3627 | + 'value' => isset($existing_settings[$field_id]) |
|
| 3628 | + ? $existing_settings[$field_id] |
|
| 3629 | + : $fldprops['default'], |
|
| 3630 | + 'css_class' => '', |
|
| 3631 | + 'format' => $fldprops['format'] |
|
| 3632 | + ); |
|
| 3633 | + } |
|
| 3634 | 3634 | |
| 3635 | 3635 | |
| 3636 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3637 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3638 | - : ''; |
|
| 3639 | - } |
|
| 3640 | - |
|
| 3641 | - //we also need some hidden fields |
|
| 3642 | - $settings_template_args['hidden_fields'] = array( |
|
| 3643 | - 'messenger_settings[messenger]' => array( |
|
| 3644 | - 'type' => 'hidden', |
|
| 3645 | - 'value' => $messenger->name |
|
| 3646 | - ), |
|
| 3647 | - 'type' => array( |
|
| 3648 | - 'type' => 'hidden', |
|
| 3649 | - 'value' => 'messenger' |
|
| 3650 | - ) |
|
| 3651 | - ); |
|
| 3652 | - |
|
| 3653 | - //make sure any active message types that are existing are included in the hidden fields |
|
| 3654 | - if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3655 | - foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3656 | - $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3657 | - 'type' => 'hidden', |
|
| 3658 | - 'value' => $mt |
|
| 3659 | - ); |
|
| 3660 | - } |
|
| 3661 | - } |
|
| 3662 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3663 | - $settings_template_args['hidden_fields'], |
|
| 3664 | - 'array' |
|
| 3665 | - ); |
|
| 3666 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3667 | - |
|
| 3668 | - $settings_template_args['messenger'] = $messenger->name; |
|
| 3669 | - $settings_template_args['description'] = $messenger->description; |
|
| 3670 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3671 | - |
|
| 3672 | - |
|
| 3673 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3674 | - $messenger->name |
|
| 3675 | - ) |
|
| 3676 | - ? $settings_template_args['show_hide_edit_form'] |
|
| 3677 | - : ' hidden'; |
|
| 3678 | - |
|
| 3679 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3680 | - ? ' hidden' |
|
| 3681 | - : $settings_template_args['show_hide_edit_form']; |
|
| 3682 | - |
|
| 3683 | - |
|
| 3684 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3685 | - $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3686 | - $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3687 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3688 | - $content = EEH_Template::display_template( |
|
| 3689 | - $template, |
|
| 3690 | - $settings_template_args, |
|
| 3691 | - true |
|
| 3692 | - ); |
|
| 3693 | - |
|
| 3694 | - return $content; |
|
| 3695 | - } |
|
| 3636 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field) |
|
| 3637 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form') |
|
| 3638 | + : ''; |
|
| 3639 | + } |
|
| 3640 | + |
|
| 3641 | + //we also need some hidden fields |
|
| 3642 | + $settings_template_args['hidden_fields'] = array( |
|
| 3643 | + 'messenger_settings[messenger]' => array( |
|
| 3644 | + 'type' => 'hidden', |
|
| 3645 | + 'value' => $messenger->name |
|
| 3646 | + ), |
|
| 3647 | + 'type' => array( |
|
| 3648 | + 'type' => 'hidden', |
|
| 3649 | + 'value' => 'messenger' |
|
| 3650 | + ) |
|
| 3651 | + ); |
|
| 3652 | + |
|
| 3653 | + //make sure any active message types that are existing are included in the hidden fields |
|
| 3654 | + if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { |
|
| 3655 | + foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { |
|
| 3656 | + $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array( |
|
| 3657 | + 'type' => 'hidden', |
|
| 3658 | + 'value' => $mt |
|
| 3659 | + ); |
|
| 3660 | + } |
|
| 3661 | + } |
|
| 3662 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields( |
|
| 3663 | + $settings_template_args['hidden_fields'], |
|
| 3664 | + 'array' |
|
| 3665 | + ); |
|
| 3666 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name); |
|
| 3667 | + |
|
| 3668 | + $settings_template_args['messenger'] = $messenger->name; |
|
| 3669 | + $settings_template_args['description'] = $messenger->description; |
|
| 3670 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden'; |
|
| 3671 | + |
|
| 3672 | + |
|
| 3673 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active( |
|
| 3674 | + $messenger->name |
|
| 3675 | + ) |
|
| 3676 | + ? $settings_template_args['show_hide_edit_form'] |
|
| 3677 | + : ' hidden'; |
|
| 3678 | + |
|
| 3679 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields']) |
|
| 3680 | + ? ' hidden' |
|
| 3681 | + : $settings_template_args['show_hide_edit_form']; |
|
| 3682 | + |
|
| 3683 | + |
|
| 3684 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on'; |
|
| 3685 | + $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); |
|
| 3686 | + $settings_template_args['on_off_status'] = $active ? true : false; |
|
| 3687 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php'; |
|
| 3688 | + $content = EEH_Template::display_template( |
|
| 3689 | + $template, |
|
| 3690 | + $settings_template_args, |
|
| 3691 | + true |
|
| 3692 | + ); |
|
| 3693 | + |
|
| 3694 | + return $content; |
|
| 3695 | + } |
|
| 3696 | 3696 | |
| 3697 | 3697 | |
| 3698 | - /** |
|
| 3699 | - * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3700 | - * |
|
| 3701 | - * @throws DomainException |
|
| 3702 | - * @throws EE_Error |
|
| 3703 | - * @throws InvalidDataTypeException |
|
| 3704 | - * @throws InvalidInterfaceException |
|
| 3705 | - * @throws InvalidArgumentException |
|
| 3706 | - * @throws ReflectionException |
|
| 3707 | - */ |
|
| 3708 | - public function activate_messenger_toggle() |
|
| 3709 | - { |
|
| 3710 | - $success = true; |
|
| 3711 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3712 | - //let's check that we have required data |
|
| 3713 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3714 | - EE_Error::add_error( |
|
| 3715 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3716 | - __FILE__, |
|
| 3717 | - __FUNCTION__, |
|
| 3718 | - __LINE__ |
|
| 3719 | - ); |
|
| 3720 | - $success = false; |
|
| 3721 | - } |
|
| 3722 | - |
|
| 3723 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3724 | - $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3725 | - ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3726 | - : ''; |
|
| 3727 | - $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3728 | - |
|
| 3729 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3730 | - |
|
| 3731 | - |
|
| 3732 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3733 | - EE_Error::add_error( |
|
| 3734 | - esc_html__( |
|
| 3735 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3736 | - 'event_espresso' |
|
| 3737 | - ), |
|
| 3738 | - __FILE__, |
|
| 3739 | - __FUNCTION__, |
|
| 3740 | - __LINE__ |
|
| 3741 | - ); |
|
| 3742 | - $success = false; |
|
| 3743 | - } |
|
| 3744 | - |
|
| 3745 | - //do check to verify we have a valid status. |
|
| 3746 | - $status = $this->_req_data['status']; |
|
| 3747 | - |
|
| 3748 | - if ($status !== 'off' && $status !== 'on') { |
|
| 3749 | - EE_Error::add_error( |
|
| 3750 | - sprintf( |
|
| 3751 | - esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3752 | - $this->_req_data['status'] |
|
| 3753 | - ), |
|
| 3754 | - __FILE__, |
|
| 3755 | - __FUNCTION__, |
|
| 3756 | - __LINE__ |
|
| 3757 | - ); |
|
| 3758 | - $success = false; |
|
| 3759 | - } |
|
| 3760 | - |
|
| 3761 | - if ($success) { |
|
| 3762 | - //made it here? Stop dawdling then!! |
|
| 3763 | - $success = $status === 'off' |
|
| 3764 | - ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3765 | - : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3766 | - } |
|
| 3767 | - |
|
| 3768 | - $this->_template_args['success'] = $success; |
|
| 3769 | - |
|
| 3770 | - //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3771 | - $this->_return_json(); |
|
| 3772 | - |
|
| 3773 | - } |
|
| 3698 | + /** |
|
| 3699 | + * used by ajax on the messages settings page to activate|deactivate the messenger |
|
| 3700 | + * |
|
| 3701 | + * @throws DomainException |
|
| 3702 | + * @throws EE_Error |
|
| 3703 | + * @throws InvalidDataTypeException |
|
| 3704 | + * @throws InvalidInterfaceException |
|
| 3705 | + * @throws InvalidArgumentException |
|
| 3706 | + * @throws ReflectionException |
|
| 3707 | + */ |
|
| 3708 | + public function activate_messenger_toggle() |
|
| 3709 | + { |
|
| 3710 | + $success = true; |
|
| 3711 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3712 | + //let's check that we have required data |
|
| 3713 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3714 | + EE_Error::add_error( |
|
| 3715 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3716 | + __FILE__, |
|
| 3717 | + __FUNCTION__, |
|
| 3718 | + __LINE__ |
|
| 3719 | + ); |
|
| 3720 | + $success = false; |
|
| 3721 | + } |
|
| 3722 | + |
|
| 3723 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3724 | + $nonce = isset($this->_req_data['activate_nonce']) |
|
| 3725 | + ? sanitize_text_field($this->_req_data['activate_nonce']) |
|
| 3726 | + : ''; |
|
| 3727 | + $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce'; |
|
| 3728 | + |
|
| 3729 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3730 | + |
|
| 3731 | + |
|
| 3732 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3733 | + EE_Error::add_error( |
|
| 3734 | + esc_html__( |
|
| 3735 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3736 | + 'event_espresso' |
|
| 3737 | + ), |
|
| 3738 | + __FILE__, |
|
| 3739 | + __FUNCTION__, |
|
| 3740 | + __LINE__ |
|
| 3741 | + ); |
|
| 3742 | + $success = false; |
|
| 3743 | + } |
|
| 3744 | + |
|
| 3745 | + //do check to verify we have a valid status. |
|
| 3746 | + $status = $this->_req_data['status']; |
|
| 3747 | + |
|
| 3748 | + if ($status !== 'off' && $status !== 'on') { |
|
| 3749 | + EE_Error::add_error( |
|
| 3750 | + sprintf( |
|
| 3751 | + esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), |
|
| 3752 | + $this->_req_data['status'] |
|
| 3753 | + ), |
|
| 3754 | + __FILE__, |
|
| 3755 | + __FUNCTION__, |
|
| 3756 | + __LINE__ |
|
| 3757 | + ); |
|
| 3758 | + $success = false; |
|
| 3759 | + } |
|
| 3760 | + |
|
| 3761 | + if ($success) { |
|
| 3762 | + //made it here? Stop dawdling then!! |
|
| 3763 | + $success = $status === 'off' |
|
| 3764 | + ? $this->_deactivate_messenger($this->_req_data['messenger']) |
|
| 3765 | + : $this->_activate_messenger($this->_req_data['messenger']); |
|
| 3766 | + } |
|
| 3767 | + |
|
| 3768 | + $this->_template_args['success'] = $success; |
|
| 3769 | + |
|
| 3770 | + //no special instructions so let's just do the json return (which should automatically do all the special stuff). |
|
| 3771 | + $this->_return_json(); |
|
| 3772 | + |
|
| 3773 | + } |
|
| 3774 | 3774 | |
| 3775 | 3775 | |
| 3776 | - /** |
|
| 3777 | - * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3778 | - * |
|
| 3779 | - * @throws DomainException |
|
| 3780 | - * @throws EE_Error |
|
| 3781 | - * @throws ReflectionException |
|
| 3782 | - * @throws InvalidDataTypeException |
|
| 3783 | - * @throws InvalidInterfaceException |
|
| 3784 | - * @throws InvalidArgumentException |
|
| 3785 | - */ |
|
| 3786 | - public function activate_mt_toggle() |
|
| 3787 | - { |
|
| 3788 | - $success = true; |
|
| 3789 | - $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3790 | - |
|
| 3791 | - //let's make sure we have the necessary data |
|
| 3792 | - if ( ! isset($this->_req_data['message_type'])) { |
|
| 3793 | - EE_Error::add_error( |
|
| 3794 | - esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3795 | - __FILE__, |
|
| 3796 | - __FUNCTION__, |
|
| 3797 | - __LINE__ |
|
| 3798 | - ); |
|
| 3799 | - $success = false; |
|
| 3800 | - } |
|
| 3801 | - |
|
| 3802 | - if ( ! isset($this->_req_data['messenger'])) { |
|
| 3803 | - EE_Error::add_error( |
|
| 3804 | - esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3805 | - __FILE__, |
|
| 3806 | - __FUNCTION__, |
|
| 3807 | - __LINE__ |
|
| 3808 | - ); |
|
| 3809 | - $success = false; |
|
| 3810 | - } |
|
| 3811 | - |
|
| 3812 | - if ( ! isset($this->_req_data['status'])) { |
|
| 3813 | - EE_Error::add_error( |
|
| 3814 | - esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3815 | - 'event_espresso'), |
|
| 3816 | - __FILE__, |
|
| 3817 | - __FUNCTION__, |
|
| 3818 | - __LINE__ |
|
| 3819 | - ); |
|
| 3820 | - $success = false; |
|
| 3821 | - } |
|
| 3822 | - |
|
| 3823 | - |
|
| 3824 | - //do check to verify we have a valid status. |
|
| 3825 | - $status = $this->_req_data['status']; |
|
| 3826 | - |
|
| 3827 | - if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3828 | - EE_Error::add_error( |
|
| 3829 | - sprintf( |
|
| 3830 | - esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3831 | - $this->_req_data['status'] |
|
| 3832 | - ), |
|
| 3833 | - __FILE__, |
|
| 3834 | - __FUNCTION__, |
|
| 3835 | - __LINE__ |
|
| 3836 | - ); |
|
| 3837 | - $success = false; |
|
| 3838 | - } |
|
| 3839 | - |
|
| 3840 | - |
|
| 3841 | - //do a nonce check here since we're not arriving via a normal route |
|
| 3842 | - $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3843 | - $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3844 | - |
|
| 3845 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3846 | - |
|
| 3847 | - if ($success) { |
|
| 3848 | - //made it here? um, what are you waiting for then? |
|
| 3849 | - $success = $status === 'deactivate' |
|
| 3850 | - ? $this->_deactivate_message_type_for_messenger( |
|
| 3851 | - $this->_req_data['messenger'], |
|
| 3852 | - $this->_req_data['message_type'] |
|
| 3853 | - ) |
|
| 3854 | - : $this->_activate_message_type_for_messenger( |
|
| 3855 | - $this->_req_data['messenger'], |
|
| 3856 | - $this->_req_data['message_type'] |
|
| 3857 | - ); |
|
| 3858 | - } |
|
| 3859 | - |
|
| 3860 | - $this->_template_args['success'] = $success; |
|
| 3861 | - $this->_return_json(); |
|
| 3862 | - } |
|
| 3776 | + /** |
|
| 3777 | + * used by ajax from the messages settings page to activate|deactivate a message type |
|
| 3778 | + * |
|
| 3779 | + * @throws DomainException |
|
| 3780 | + * @throws EE_Error |
|
| 3781 | + * @throws ReflectionException |
|
| 3782 | + * @throws InvalidDataTypeException |
|
| 3783 | + * @throws InvalidInterfaceException |
|
| 3784 | + * @throws InvalidArgumentException |
|
| 3785 | + */ |
|
| 3786 | + public function activate_mt_toggle() |
|
| 3787 | + { |
|
| 3788 | + $success = true; |
|
| 3789 | + $this->_prep_default_response_for_messenger_or_message_type_toggle(); |
|
| 3790 | + |
|
| 3791 | + //let's make sure we have the necessary data |
|
| 3792 | + if ( ! isset($this->_req_data['message_type'])) { |
|
| 3793 | + EE_Error::add_error( |
|
| 3794 | + esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), |
|
| 3795 | + __FILE__, |
|
| 3796 | + __FUNCTION__, |
|
| 3797 | + __LINE__ |
|
| 3798 | + ); |
|
| 3799 | + $success = false; |
|
| 3800 | + } |
|
| 3801 | + |
|
| 3802 | + if ( ! isset($this->_req_data['messenger'])) { |
|
| 3803 | + EE_Error::add_error( |
|
| 3804 | + esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), |
|
| 3805 | + __FILE__, |
|
| 3806 | + __FUNCTION__, |
|
| 3807 | + __LINE__ |
|
| 3808 | + ); |
|
| 3809 | + $success = false; |
|
| 3810 | + } |
|
| 3811 | + |
|
| 3812 | + if ( ! isset($this->_req_data['status'])) { |
|
| 3813 | + EE_Error::add_error( |
|
| 3814 | + esc_html__('Messenger status needed to know whether activation or deactivation is happening. No status is given', |
|
| 3815 | + 'event_espresso'), |
|
| 3816 | + __FILE__, |
|
| 3817 | + __FUNCTION__, |
|
| 3818 | + __LINE__ |
|
| 3819 | + ); |
|
| 3820 | + $success = false; |
|
| 3821 | + } |
|
| 3822 | + |
|
| 3823 | + |
|
| 3824 | + //do check to verify we have a valid status. |
|
| 3825 | + $status = $this->_req_data['status']; |
|
| 3826 | + |
|
| 3827 | + if ($status !== 'activate' && $status !== 'deactivate') { |
|
| 3828 | + EE_Error::add_error( |
|
| 3829 | + sprintf( |
|
| 3830 | + esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), |
|
| 3831 | + $this->_req_data['status'] |
|
| 3832 | + ), |
|
| 3833 | + __FILE__, |
|
| 3834 | + __FUNCTION__, |
|
| 3835 | + __LINE__ |
|
| 3836 | + ); |
|
| 3837 | + $success = false; |
|
| 3838 | + } |
|
| 3839 | + |
|
| 3840 | + |
|
| 3841 | + //do a nonce check here since we're not arriving via a normal route |
|
| 3842 | + $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : ''; |
|
| 3843 | + $nonce_ref = $this->_req_data['message_type'] . '_nonce'; |
|
| 3844 | + |
|
| 3845 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 3846 | + |
|
| 3847 | + if ($success) { |
|
| 3848 | + //made it here? um, what are you waiting for then? |
|
| 3849 | + $success = $status === 'deactivate' |
|
| 3850 | + ? $this->_deactivate_message_type_for_messenger( |
|
| 3851 | + $this->_req_data['messenger'], |
|
| 3852 | + $this->_req_data['message_type'] |
|
| 3853 | + ) |
|
| 3854 | + : $this->_activate_message_type_for_messenger( |
|
| 3855 | + $this->_req_data['messenger'], |
|
| 3856 | + $this->_req_data['message_type'] |
|
| 3857 | + ); |
|
| 3858 | + } |
|
| 3859 | + |
|
| 3860 | + $this->_template_args['success'] = $success; |
|
| 3861 | + $this->_return_json(); |
|
| 3862 | + } |
|
| 3863 | 3863 | |
| 3864 | 3864 | |
| 3865 | - /** |
|
| 3866 | - * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3867 | - * |
|
| 3868 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3869 | - * @return bool |
|
| 3870 | - * @throws DomainException |
|
| 3871 | - * @throws EE_Error |
|
| 3872 | - * @throws InvalidArgumentException |
|
| 3873 | - * @throws ReflectionException |
|
| 3874 | - * @throws InvalidDataTypeException |
|
| 3875 | - * @throws InvalidInterfaceException |
|
| 3876 | - */ |
|
| 3877 | - protected function _activate_messenger($messenger_name) |
|
| 3878 | - { |
|
| 3879 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3880 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3881 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3882 | - ? $active_messenger->get_default_message_types() |
|
| 3883 | - : array(); |
|
| 3884 | - |
|
| 3885 | - //ensure is active |
|
| 3886 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3887 | - |
|
| 3888 | - //set response_data for reload |
|
| 3889 | - foreach ($message_types_to_activate as $message_type_name) { |
|
| 3890 | - /** @var EE_message_type $message_type */ |
|
| 3891 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3892 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3893 | - $messenger_name, |
|
| 3894 | - $message_type_name |
|
| 3895 | - ) |
|
| 3896 | - && $message_type instanceof EE_message_type |
|
| 3897 | - ) { |
|
| 3898 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3899 | - if ($message_type->get_admin_settings_fields()) { |
|
| 3900 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3901 | - } |
|
| 3902 | - } |
|
| 3903 | - } |
|
| 3904 | - |
|
| 3905 | - //add success message for activating messenger |
|
| 3906 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3907 | - |
|
| 3908 | - } |
|
| 3865 | + /** |
|
| 3866 | + * Takes care of processing activating a messenger and preparing the appropriate response. |
|
| 3867 | + * |
|
| 3868 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3869 | + * @return bool |
|
| 3870 | + * @throws DomainException |
|
| 3871 | + * @throws EE_Error |
|
| 3872 | + * @throws InvalidArgumentException |
|
| 3873 | + * @throws ReflectionException |
|
| 3874 | + * @throws InvalidDataTypeException |
|
| 3875 | + * @throws InvalidInterfaceException |
|
| 3876 | + */ |
|
| 3877 | + protected function _activate_messenger($messenger_name) |
|
| 3878 | + { |
|
| 3879 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3880 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3881 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger |
|
| 3882 | + ? $active_messenger->get_default_message_types() |
|
| 3883 | + : array(); |
|
| 3884 | + |
|
| 3885 | + //ensure is active |
|
| 3886 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate); |
|
| 3887 | + |
|
| 3888 | + //set response_data for reload |
|
| 3889 | + foreach ($message_types_to_activate as $message_type_name) { |
|
| 3890 | + /** @var EE_message_type $message_type */ |
|
| 3891 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3892 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger( |
|
| 3893 | + $messenger_name, |
|
| 3894 | + $message_type_name |
|
| 3895 | + ) |
|
| 3896 | + && $message_type instanceof EE_message_type |
|
| 3897 | + ) { |
|
| 3898 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3899 | + if ($message_type->get_admin_settings_fields()) { |
|
| 3900 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3901 | + } |
|
| 3902 | + } |
|
| 3903 | + } |
|
| 3904 | + |
|
| 3905 | + //add success message for activating messenger |
|
| 3906 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger); |
|
| 3907 | + |
|
| 3908 | + } |
|
| 3909 | 3909 | |
| 3910 | 3910 | |
| 3911 | - /** |
|
| 3912 | - * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3913 | - * |
|
| 3914 | - * @param string $messenger_name The name of the messenger being activated |
|
| 3915 | - * @return bool |
|
| 3916 | - * @throws DomainException |
|
| 3917 | - * @throws EE_Error |
|
| 3918 | - * @throws InvalidArgumentException |
|
| 3919 | - * @throws ReflectionException |
|
| 3920 | - * @throws InvalidDataTypeException |
|
| 3921 | - * @throws InvalidInterfaceException |
|
| 3922 | - */ |
|
| 3923 | - protected function _deactivate_messenger($messenger_name) |
|
| 3924 | - { |
|
| 3925 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3926 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3927 | - $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3928 | - |
|
| 3929 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3930 | - } |
|
| 3911 | + /** |
|
| 3912 | + * Takes care of processing deactivating a messenger and preparing the appropriate response. |
|
| 3913 | + * |
|
| 3914 | + * @param string $messenger_name The name of the messenger being activated |
|
| 3915 | + * @return bool |
|
| 3916 | + * @throws DomainException |
|
| 3917 | + * @throws EE_Error |
|
| 3918 | + * @throws InvalidArgumentException |
|
| 3919 | + * @throws ReflectionException |
|
| 3920 | + * @throws InvalidDataTypeException |
|
| 3921 | + * @throws InvalidInterfaceException |
|
| 3922 | + */ |
|
| 3923 | + protected function _deactivate_messenger($messenger_name) |
|
| 3924 | + { |
|
| 3925 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3926 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3927 | + $this->_message_resource_manager->deactivate_messenger($messenger_name); |
|
| 3928 | + |
|
| 3929 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger); |
|
| 3930 | + } |
|
| 3931 | 3931 | |
| 3932 | 3932 | |
| 3933 | - /** |
|
| 3934 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3935 | - * |
|
| 3936 | - * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3937 | - * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3938 | - * @return bool |
|
| 3939 | - * @throws DomainException |
|
| 3940 | - * @throws EE_Error |
|
| 3941 | - * @throws InvalidArgumentException |
|
| 3942 | - * @throws ReflectionException |
|
| 3943 | - * @throws InvalidDataTypeException |
|
| 3944 | - * @throws InvalidInterfaceException |
|
| 3945 | - */ |
|
| 3946 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3947 | - { |
|
| 3948 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3949 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3950 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3951 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3952 | - |
|
| 3953 | - //ensure is active |
|
| 3954 | - $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3955 | - |
|
| 3956 | - //set response for load |
|
| 3957 | - if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3958 | - $message_type_name) |
|
| 3959 | - ) { |
|
| 3960 | - $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3961 | - if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3962 | - $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3963 | - } |
|
| 3964 | - } |
|
| 3965 | - |
|
| 3966 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3967 | - $message_type_to_activate); |
|
| 3968 | - } |
|
| 3933 | + /** |
|
| 3934 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response. |
|
| 3935 | + * |
|
| 3936 | + * @param string $messenger_name The name of the messenger the message type is being activated for. |
|
| 3937 | + * @param string $message_type_name The name of the message type being activated for the messenger |
|
| 3938 | + * @return bool |
|
| 3939 | + * @throws DomainException |
|
| 3940 | + * @throws EE_Error |
|
| 3941 | + * @throws InvalidArgumentException |
|
| 3942 | + * @throws ReflectionException |
|
| 3943 | + * @throws InvalidDataTypeException |
|
| 3944 | + * @throws InvalidInterfaceException |
|
| 3945 | + */ |
|
| 3946 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3947 | + { |
|
| 3948 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3949 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3950 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3951 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3952 | + |
|
| 3953 | + //ensure is active |
|
| 3954 | + $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name); |
|
| 3955 | + |
|
| 3956 | + //set response for load |
|
| 3957 | + if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name, |
|
| 3958 | + $message_type_name) |
|
| 3959 | + ) { |
|
| 3960 | + $this->_template_args['data']['active_mts'][] = $message_type_name; |
|
| 3961 | + if ($message_type_to_activate->get_admin_settings_fields()) { |
|
| 3962 | + $this->_template_args['data']['mt_reload'][] = $message_type_name; |
|
| 3963 | + } |
|
| 3964 | + } |
|
| 3965 | + |
|
| 3966 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger, |
|
| 3967 | + $message_type_to_activate); |
|
| 3968 | + } |
|
| 3969 | 3969 | |
| 3970 | 3970 | |
| 3971 | - /** |
|
| 3972 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3973 | - * |
|
| 3974 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3975 | - * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3976 | - * @return bool |
|
| 3977 | - * @throws DomainException |
|
| 3978 | - * @throws EE_Error |
|
| 3979 | - * @throws InvalidArgumentException |
|
| 3980 | - * @throws ReflectionException |
|
| 3981 | - * @throws InvalidDataTypeException |
|
| 3982 | - * @throws InvalidInterfaceException |
|
| 3983 | - */ |
|
| 3984 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3985 | - { |
|
| 3986 | - /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3987 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3988 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3989 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3990 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3991 | - |
|
| 3992 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3993 | - $message_type_to_deactivate); |
|
| 3994 | - } |
|
| 3971 | + /** |
|
| 3972 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response. |
|
| 3973 | + * |
|
| 3974 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for. |
|
| 3975 | + * @param string $message_type_name The name of the message type being deactivated for the messenger |
|
| 3976 | + * @return bool |
|
| 3977 | + * @throws DomainException |
|
| 3978 | + * @throws EE_Error |
|
| 3979 | + * @throws InvalidArgumentException |
|
| 3980 | + * @throws ReflectionException |
|
| 3981 | + * @throws InvalidDataTypeException |
|
| 3982 | + * @throws InvalidInterfaceException |
|
| 3983 | + */ |
|
| 3984 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name) |
|
| 3985 | + { |
|
| 3986 | + /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */ |
|
| 3987 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name); |
|
| 3988 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */ |
|
| 3989 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name); |
|
| 3990 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name); |
|
| 3991 | + |
|
| 3992 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger, |
|
| 3993 | + $message_type_to_deactivate); |
|
| 3994 | + } |
|
| 3995 | 3995 | |
| 3996 | 3996 | |
| 3997 | - /** |
|
| 3998 | - * This just initializes the defaults for activating messenger and message type responses. |
|
| 3999 | - */ |
|
| 4000 | - protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4001 | - { |
|
| 4002 | - $this->_template_args['data']['active_mts'] = array(); |
|
| 4003 | - $this->_template_args['data']['mt_reload'] = array(); |
|
| 4004 | - } |
|
| 3997 | + /** |
|
| 3998 | + * This just initializes the defaults for activating messenger and message type responses. |
|
| 3999 | + */ |
|
| 4000 | + protected function _prep_default_response_for_messenger_or_message_type_toggle() |
|
| 4001 | + { |
|
| 4002 | + $this->_template_args['data']['active_mts'] = array(); |
|
| 4003 | + $this->_template_args['data']['mt_reload'] = array(); |
|
| 4004 | + } |
|
| 4005 | 4005 | |
| 4006 | 4006 | |
| 4007 | - /** |
|
| 4008 | - * Setup appropriate response for activating a messenger and/or message types |
|
| 4009 | - * |
|
| 4010 | - * @param EE_messenger $messenger |
|
| 4011 | - * @param EE_message_type|null $message_type |
|
| 4012 | - * @return bool |
|
| 4013 | - * @throws DomainException |
|
| 4014 | - * @throws EE_Error |
|
| 4015 | - * @throws InvalidArgumentException |
|
| 4016 | - * @throws ReflectionException |
|
| 4017 | - * @throws InvalidDataTypeException |
|
| 4018 | - * @throws InvalidInterfaceException |
|
| 4019 | - */ |
|
| 4020 | - protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4021 | - $messenger, |
|
| 4022 | - EE_Message_Type $message_type = null |
|
| 4023 | - ) { |
|
| 4024 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4025 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4026 | - EE_Error::add_error( |
|
| 4027 | - esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4028 | - __FILE__, |
|
| 4029 | - __FUNCTION__, |
|
| 4030 | - __LINE__ |
|
| 4031 | - ); |
|
| 4007 | + /** |
|
| 4008 | + * Setup appropriate response for activating a messenger and/or message types |
|
| 4009 | + * |
|
| 4010 | + * @param EE_messenger $messenger |
|
| 4011 | + * @param EE_message_type|null $message_type |
|
| 4012 | + * @return bool |
|
| 4013 | + * @throws DomainException |
|
| 4014 | + * @throws EE_Error |
|
| 4015 | + * @throws InvalidArgumentException |
|
| 4016 | + * @throws ReflectionException |
|
| 4017 | + * @throws InvalidDataTypeException |
|
| 4018 | + * @throws InvalidInterfaceException |
|
| 4019 | + */ |
|
| 4020 | + protected function _setup_response_message_for_activating_messenger_with_message_types( |
|
| 4021 | + $messenger, |
|
| 4022 | + EE_Message_Type $message_type = null |
|
| 4023 | + ) { |
|
| 4024 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4025 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4026 | + EE_Error::add_error( |
|
| 4027 | + esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), |
|
| 4028 | + __FILE__, |
|
| 4029 | + __FUNCTION__, |
|
| 4030 | + __LINE__ |
|
| 4031 | + ); |
|
| 4032 | 4032 | |
| 4033 | - return false; |
|
| 4034 | - } |
|
| 4035 | - //activated |
|
| 4036 | - if ($this->_template_args['data']['active_mts']) { |
|
| 4037 | - EE_Error::overwrite_success(); |
|
| 4038 | - //activated a message type with the messenger |
|
| 4039 | - if ($message_type instanceof EE_message_type) { |
|
| 4040 | - EE_Error::add_success( |
|
| 4041 | - sprintf( |
|
| 4042 | - esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4043 | - ucwords($message_type->label['singular']), |
|
| 4044 | - ucwords($messenger->label['singular']) |
|
| 4045 | - ) |
|
| 4046 | - ); |
|
| 4033 | + return false; |
|
| 4034 | + } |
|
| 4035 | + //activated |
|
| 4036 | + if ($this->_template_args['data']['active_mts']) { |
|
| 4037 | + EE_Error::overwrite_success(); |
|
| 4038 | + //activated a message type with the messenger |
|
| 4039 | + if ($message_type instanceof EE_message_type) { |
|
| 4040 | + EE_Error::add_success( |
|
| 4041 | + sprintf( |
|
| 4042 | + esc_html__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), |
|
| 4043 | + ucwords($message_type->label['singular']), |
|
| 4044 | + ucwords($messenger->label['singular']) |
|
| 4045 | + ) |
|
| 4046 | + ); |
|
| 4047 | 4047 | |
| 4048 | - //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4049 | - if ($message_type->name === 'invoice') { |
|
| 4050 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4051 | - $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4052 | - if ($pm instanceof EE_Payment_Method) { |
|
| 4053 | - EE_Error::add_attention( |
|
| 4054 | - esc_html__( |
|
| 4055 | - 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4056 | - 'event_espresso' |
|
| 4057 | - ) |
|
| 4058 | - ); |
|
| 4059 | - } |
|
| 4060 | - } |
|
| 4061 | - //just toggles the entire messenger |
|
| 4062 | - } else { |
|
| 4063 | - EE_Error::add_success( |
|
| 4064 | - sprintf( |
|
| 4065 | - esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4066 | - ucwords($messenger->label['singular']) |
|
| 4067 | - ) |
|
| 4068 | - ); |
|
| 4069 | - } |
|
| 4048 | + //if message type was invoice then let's make sure we activate the invoice payment method. |
|
| 4049 | + if ($message_type->name === 'invoice') { |
|
| 4050 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4051 | + $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 4052 | + if ($pm instanceof EE_Payment_Method) { |
|
| 4053 | + EE_Error::add_attention( |
|
| 4054 | + esc_html__( |
|
| 4055 | + 'Activating the invoice message type also automatically activates the invoice payment method. If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', |
|
| 4056 | + 'event_espresso' |
|
| 4057 | + ) |
|
| 4058 | + ); |
|
| 4059 | + } |
|
| 4060 | + } |
|
| 4061 | + //just toggles the entire messenger |
|
| 4062 | + } else { |
|
| 4063 | + EE_Error::add_success( |
|
| 4064 | + sprintf( |
|
| 4065 | + esc_html__('%s messenger has been successfully activated', 'event_espresso'), |
|
| 4066 | + ucwords($messenger->label['singular']) |
|
| 4067 | + ) |
|
| 4068 | + ); |
|
| 4069 | + } |
|
| 4070 | 4070 | |
| 4071 | - return true; |
|
| 4071 | + return true; |
|
| 4072 | 4072 | |
| 4073 | - //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4074 | - //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4075 | - //in which case we just give a success message for the messenger being successfully activated. |
|
| 4076 | - } else { |
|
| 4077 | - if ( ! $messenger->get_default_message_types()) { |
|
| 4078 | - //messenger doesn't have any default message types so still a success. |
|
| 4079 | - EE_Error::add_success( |
|
| 4080 | - sprintf( |
|
| 4081 | - esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4082 | - ucwords($messenger->label['singular']) |
|
| 4083 | - ) |
|
| 4084 | - ); |
|
| 4073 | + //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active |
|
| 4074 | + //message types after the activation process. However its possible some messengers don't HAVE any default_message_types |
|
| 4075 | + //in which case we just give a success message for the messenger being successfully activated. |
|
| 4076 | + } else { |
|
| 4077 | + if ( ! $messenger->get_default_message_types()) { |
|
| 4078 | + //messenger doesn't have any default message types so still a success. |
|
| 4079 | + EE_Error::add_success( |
|
| 4080 | + sprintf( |
|
| 4081 | + esc_html__('%s messenger was successfully activated.', 'event_espresso'), |
|
| 4082 | + ucwords($messenger->label['singular']) |
|
| 4083 | + ) |
|
| 4084 | + ); |
|
| 4085 | 4085 | |
| 4086 | - return true; |
|
| 4087 | - } else { |
|
| 4088 | - EE_Error::add_error( |
|
| 4089 | - $message_type instanceof EE_message_type |
|
| 4090 | - ? sprintf( |
|
| 4091 | - esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4092 | - ucwords($message_type->label['singular']), |
|
| 4093 | - ucwords($messenger->label['singular']) |
|
| 4094 | - ) |
|
| 4095 | - : sprintf( |
|
| 4096 | - esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4097 | - ucwords($messenger->label['singular']) |
|
| 4098 | - ), |
|
| 4099 | - __FILE__, |
|
| 4100 | - __FUNCTION__, |
|
| 4101 | - __LINE__ |
|
| 4102 | - ); |
|
| 4086 | + return true; |
|
| 4087 | + } else { |
|
| 4088 | + EE_Error::add_error( |
|
| 4089 | + $message_type instanceof EE_message_type |
|
| 4090 | + ? sprintf( |
|
| 4091 | + esc_html__('%s message type was not successfully activated with the %s messenger', 'event_espresso'), |
|
| 4092 | + ucwords($message_type->label['singular']), |
|
| 4093 | + ucwords($messenger->label['singular']) |
|
| 4094 | + ) |
|
| 4095 | + : sprintf( |
|
| 4096 | + esc_html__('%s messenger was not successfully activated', 'event_espresso'), |
|
| 4097 | + ucwords($messenger->label['singular']) |
|
| 4098 | + ), |
|
| 4099 | + __FILE__, |
|
| 4100 | + __FUNCTION__, |
|
| 4101 | + __LINE__ |
|
| 4102 | + ); |
|
| 4103 | 4103 | |
| 4104 | - return false; |
|
| 4105 | - } |
|
| 4106 | - } |
|
| 4107 | - } |
|
| 4104 | + return false; |
|
| 4105 | + } |
|
| 4106 | + } |
|
| 4107 | + } |
|
| 4108 | 4108 | |
| 4109 | 4109 | |
| 4110 | - /** |
|
| 4111 | - * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4112 | - * |
|
| 4113 | - * @param EE_messenger $messenger |
|
| 4114 | - * @param EE_message_type|null $message_type |
|
| 4115 | - * @return bool |
|
| 4116 | - * @throws DomainException |
|
| 4117 | - * @throws EE_Error |
|
| 4118 | - * @throws InvalidArgumentException |
|
| 4119 | - * @throws ReflectionException |
|
| 4120 | - * @throws InvalidDataTypeException |
|
| 4121 | - * @throws InvalidInterfaceException |
|
| 4122 | - */ |
|
| 4123 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4124 | - $messenger, |
|
| 4125 | - EE_message_type $message_type = null |
|
| 4126 | - ) { |
|
| 4127 | - EE_Error::overwrite_success(); |
|
| 4128 | - |
|
| 4129 | - //if $messenger isn't a valid messenger object then get out. |
|
| 4130 | - if ( ! $messenger instanceof EE_Messenger) { |
|
| 4131 | - EE_Error::add_error( |
|
| 4132 | - esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4133 | - __FILE__, |
|
| 4134 | - __FUNCTION__, |
|
| 4135 | - __LINE__ |
|
| 4136 | - ); |
|
| 4110 | + /** |
|
| 4111 | + * This sets up the appropriate response for deactivating a messenger and/or message type. |
|
| 4112 | + * |
|
| 4113 | + * @param EE_messenger $messenger |
|
| 4114 | + * @param EE_message_type|null $message_type |
|
| 4115 | + * @return bool |
|
| 4116 | + * @throws DomainException |
|
| 4117 | + * @throws EE_Error |
|
| 4118 | + * @throws InvalidArgumentException |
|
| 4119 | + * @throws ReflectionException |
|
| 4120 | + * @throws InvalidDataTypeException |
|
| 4121 | + * @throws InvalidInterfaceException |
|
| 4122 | + */ |
|
| 4123 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types( |
|
| 4124 | + $messenger, |
|
| 4125 | + EE_message_type $message_type = null |
|
| 4126 | + ) { |
|
| 4127 | + EE_Error::overwrite_success(); |
|
| 4128 | + |
|
| 4129 | + //if $messenger isn't a valid messenger object then get out. |
|
| 4130 | + if ( ! $messenger instanceof EE_Messenger) { |
|
| 4131 | + EE_Error::add_error( |
|
| 4132 | + esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), |
|
| 4133 | + __FILE__, |
|
| 4134 | + __FUNCTION__, |
|
| 4135 | + __LINE__ |
|
| 4136 | + ); |
|
| 4137 | 4137 | |
| 4138 | - return false; |
|
| 4139 | - } |
|
| 4140 | - |
|
| 4141 | - if ($message_type instanceof EE_message_type) { |
|
| 4142 | - $message_type_name = $message_type->name; |
|
| 4143 | - EE_Error::add_success( |
|
| 4144 | - sprintf( |
|
| 4145 | - esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4146 | - ucwords($message_type->label['singular']), |
|
| 4147 | - ucwords($messenger->label['singular']) |
|
| 4148 | - ) |
|
| 4149 | - ); |
|
| 4150 | - } else { |
|
| 4151 | - $message_type_name = ''; |
|
| 4152 | - EE_Error::add_success( |
|
| 4153 | - sprintf( |
|
| 4154 | - esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4155 | - ucwords($messenger->label['singular']) |
|
| 4156 | - ) |
|
| 4157 | - ); |
|
| 4158 | - } |
|
| 4159 | - |
|
| 4160 | - //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4161 | - if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4162 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4163 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4164 | - if ($count_updated > 0) { |
|
| 4165 | - $msg = $message_type_name === 'invoice' |
|
| 4166 | - ? esc_html__( |
|
| 4167 | - 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4168 | - 'event_espresso' |
|
| 4169 | - ) |
|
| 4170 | - : esc_html__( |
|
| 4171 | - 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4172 | - 'event_espresso' |
|
| 4173 | - ); |
|
| 4174 | - EE_Error::add_attention($msg); |
|
| 4175 | - } |
|
| 4176 | - } |
|
| 4177 | - |
|
| 4178 | - return true; |
|
| 4179 | - } |
|
| 4138 | + return false; |
|
| 4139 | + } |
|
| 4140 | + |
|
| 4141 | + if ($message_type instanceof EE_message_type) { |
|
| 4142 | + $message_type_name = $message_type->name; |
|
| 4143 | + EE_Error::add_success( |
|
| 4144 | + sprintf( |
|
| 4145 | + esc_html__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), |
|
| 4146 | + ucwords($message_type->label['singular']), |
|
| 4147 | + ucwords($messenger->label['singular']) |
|
| 4148 | + ) |
|
| 4149 | + ); |
|
| 4150 | + } else { |
|
| 4151 | + $message_type_name = ''; |
|
| 4152 | + EE_Error::add_success( |
|
| 4153 | + sprintf( |
|
| 4154 | + esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), |
|
| 4155 | + ucwords($messenger->label['singular']) |
|
| 4156 | + ) |
|
| 4157 | + ); |
|
| 4158 | + } |
|
| 4159 | + |
|
| 4160 | + //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method. |
|
| 4161 | + if ($messenger->name === 'html' || $message_type_name === 'invoice') { |
|
| 4162 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 4163 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); |
|
| 4164 | + if ($count_updated > 0) { |
|
| 4165 | + $msg = $message_type_name === 'invoice' |
|
| 4166 | + ? esc_html__( |
|
| 4167 | + 'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4168 | + 'event_espresso' |
|
| 4169 | + ) |
|
| 4170 | + : esc_html__( |
|
| 4171 | + 'Deactivating the html messenger also automatically deactivates the invoice payment method. In order for invoices to be generated the html messenger must be be active. If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', |
|
| 4172 | + 'event_espresso' |
|
| 4173 | + ); |
|
| 4174 | + EE_Error::add_attention($msg); |
|
| 4175 | + } |
|
| 4176 | + } |
|
| 4177 | + |
|
| 4178 | + return true; |
|
| 4179 | + } |
|
| 4180 | 4180 | |
| 4181 | 4181 | |
| 4182 | - /** |
|
| 4183 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4184 | - * |
|
| 4185 | - * @throws DomainException |
|
| 4186 | - */ |
|
| 4187 | - public function update_mt_form() |
|
| 4188 | - { |
|
| 4189 | - if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4190 | - EE_Error::add_error( |
|
| 4191 | - esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4192 | - __FILE__, |
|
| 4193 | - __FUNCTION__, |
|
| 4194 | - __LINE__ |
|
| 4195 | - ); |
|
| 4196 | - $this->_return_json(); |
|
| 4197 | - } |
|
| 4198 | - |
|
| 4199 | - $message_types = $this->get_installed_message_types(); |
|
| 4200 | - |
|
| 4201 | - $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4202 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4203 | - |
|
| 4204 | - $content = $this->_message_type_settings_content( |
|
| 4205 | - $message_type, |
|
| 4206 | - $messenger, |
|
| 4207 | - true |
|
| 4208 | - ); |
|
| 4209 | - $this->_template_args['success'] = true; |
|
| 4210 | - $this->_template_args['content'] = $content; |
|
| 4211 | - $this->_return_json(); |
|
| 4212 | - } |
|
| 4182 | + /** |
|
| 4183 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax) |
|
| 4184 | + * |
|
| 4185 | + * @throws DomainException |
|
| 4186 | + */ |
|
| 4187 | + public function update_mt_form() |
|
| 4188 | + { |
|
| 4189 | + if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) { |
|
| 4190 | + EE_Error::add_error( |
|
| 4191 | + esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), |
|
| 4192 | + __FILE__, |
|
| 4193 | + __FUNCTION__, |
|
| 4194 | + __LINE__ |
|
| 4195 | + ); |
|
| 4196 | + $this->_return_json(); |
|
| 4197 | + } |
|
| 4198 | + |
|
| 4199 | + $message_types = $this->get_installed_message_types(); |
|
| 4200 | + |
|
| 4201 | + $message_type = $message_types[$this->_req_data['message_type']]; |
|
| 4202 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']); |
|
| 4203 | + |
|
| 4204 | + $content = $this->_message_type_settings_content( |
|
| 4205 | + $message_type, |
|
| 4206 | + $messenger, |
|
| 4207 | + true |
|
| 4208 | + ); |
|
| 4209 | + $this->_template_args['success'] = true; |
|
| 4210 | + $this->_template_args['content'] = $content; |
|
| 4211 | + $this->_return_json(); |
|
| 4212 | + } |
|
| 4213 | 4213 | |
| 4214 | 4214 | |
| 4215 | - /** |
|
| 4216 | - * this handles saving the settings for a messenger or message type |
|
| 4217 | - * |
|
| 4218 | - */ |
|
| 4219 | - public function save_settings() |
|
| 4220 | - { |
|
| 4221 | - if ( ! isset($this->_req_data['type'])) { |
|
| 4222 | - EE_Error::add_error( |
|
| 4223 | - esc_html__( |
|
| 4224 | - 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4225 | - 'event_espresso' |
|
| 4226 | - ), |
|
| 4227 | - __FILE__, |
|
| 4228 | - __FUNCTION__, |
|
| 4229 | - __LINE__ |
|
| 4230 | - ); |
|
| 4231 | - $this->_template_args['error'] = true; |
|
| 4232 | - $this->_return_json(); |
|
| 4233 | - } |
|
| 4234 | - |
|
| 4235 | - |
|
| 4236 | - if ($this->_req_data['type'] === 'messenger') { |
|
| 4237 | - //this should be an array. |
|
| 4238 | - $settings = $this->_req_data['messenger_settings']; |
|
| 4239 | - $messenger = $settings['messenger']; |
|
| 4240 | - //let's setup the settings data |
|
| 4241 | - foreach ($settings as $key => $value) { |
|
| 4242 | - switch ($key) { |
|
| 4243 | - case 'messenger' : |
|
| 4244 | - unset($settings['messenger']); |
|
| 4245 | - break; |
|
| 4246 | - case 'message_types' : |
|
| 4247 | - unset($settings['message_types']); |
|
| 4248 | - break; |
|
| 4249 | - default : |
|
| 4250 | - $settings[$key] = $value; |
|
| 4251 | - break; |
|
| 4252 | - } |
|
| 4253 | - } |
|
| 4254 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4255 | - } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4256 | - $settings = $this->_req_data['message_type_settings']; |
|
| 4257 | - $messenger = $settings['messenger']; |
|
| 4258 | - $message_type = $settings['message_type']; |
|
| 4215 | + /** |
|
| 4216 | + * this handles saving the settings for a messenger or message type |
|
| 4217 | + * |
|
| 4218 | + */ |
|
| 4219 | + public function save_settings() |
|
| 4220 | + { |
|
| 4221 | + if ( ! isset($this->_req_data['type'])) { |
|
| 4222 | + EE_Error::add_error( |
|
| 4223 | + esc_html__( |
|
| 4224 | + 'Cannot save settings because type is unknown (messenger settings or messsage type settings?)', |
|
| 4225 | + 'event_espresso' |
|
| 4226 | + ), |
|
| 4227 | + __FILE__, |
|
| 4228 | + __FUNCTION__, |
|
| 4229 | + __LINE__ |
|
| 4230 | + ); |
|
| 4231 | + $this->_template_args['error'] = true; |
|
| 4232 | + $this->_return_json(); |
|
| 4233 | + } |
|
| 4234 | + |
|
| 4235 | + |
|
| 4236 | + if ($this->_req_data['type'] === 'messenger') { |
|
| 4237 | + //this should be an array. |
|
| 4238 | + $settings = $this->_req_data['messenger_settings']; |
|
| 4239 | + $messenger = $settings['messenger']; |
|
| 4240 | + //let's setup the settings data |
|
| 4241 | + foreach ($settings as $key => $value) { |
|
| 4242 | + switch ($key) { |
|
| 4243 | + case 'messenger' : |
|
| 4244 | + unset($settings['messenger']); |
|
| 4245 | + break; |
|
| 4246 | + case 'message_types' : |
|
| 4247 | + unset($settings['message_types']); |
|
| 4248 | + break; |
|
| 4249 | + default : |
|
| 4250 | + $settings[$key] = $value; |
|
| 4251 | + break; |
|
| 4252 | + } |
|
| 4253 | + } |
|
| 4254 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings); |
|
| 4255 | + } elseif ($this->_req_data['type'] === 'message_type') { |
|
| 4256 | + $settings = $this->_req_data['message_type_settings']; |
|
| 4257 | + $messenger = $settings['messenger']; |
|
| 4258 | + $message_type = $settings['message_type']; |
|
| 4259 | 4259 | |
| 4260 | - foreach ($settings as $key => $value) { |
|
| 4261 | - switch ($key) { |
|
| 4262 | - case 'messenger' : |
|
| 4263 | - unset($settings['messenger']); |
|
| 4264 | - break; |
|
| 4265 | - case 'message_type' : |
|
| 4266 | - unset($settings['message_type']); |
|
| 4267 | - break; |
|
| 4268 | - default : |
|
| 4269 | - $settings[$key] = $value; |
|
| 4270 | - break; |
|
| 4271 | - } |
|
| 4272 | - } |
|
| 4260 | + foreach ($settings as $key => $value) { |
|
| 4261 | + switch ($key) { |
|
| 4262 | + case 'messenger' : |
|
| 4263 | + unset($settings['messenger']); |
|
| 4264 | + break; |
|
| 4265 | + case 'message_type' : |
|
| 4266 | + unset($settings['message_type']); |
|
| 4267 | + break; |
|
| 4268 | + default : |
|
| 4269 | + $settings[$key] = $value; |
|
| 4270 | + break; |
|
| 4271 | + } |
|
| 4272 | + } |
|
| 4273 | 4273 | |
| 4274 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4275 | - } |
|
| 4276 | - |
|
| 4277 | - //okay we should have the data all setup. Now we just update! |
|
| 4278 | - $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4279 | - |
|
| 4280 | - if ($success) { |
|
| 4281 | - EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4282 | - } else { |
|
| 4283 | - EE_Error::add_error( |
|
| 4284 | - esc_html__( |
|
| 4285 | - 'Settings did not get updated', |
|
| 4286 | - 'event_espresso' |
|
| 4287 | - ), |
|
| 4288 | - __FILE__, |
|
| 4289 | - __FUNCTION__, |
|
| 4290 | - __LINE__ |
|
| 4291 | - ); |
|
| 4292 | - } |
|
| 4293 | - |
|
| 4294 | - $this->_template_args['success'] = $success; |
|
| 4295 | - $this->_return_json(); |
|
| 4296 | - } |
|
| 4274 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings); |
|
| 4275 | + } |
|
| 4276 | + |
|
| 4277 | + //okay we should have the data all setup. Now we just update! |
|
| 4278 | + $success = $this->_message_resource_manager->update_active_messengers_option(); |
|
| 4279 | + |
|
| 4280 | + if ($success) { |
|
| 4281 | + EE_Error::add_success(__('Settings updated', 'event_espresso')); |
|
| 4282 | + } else { |
|
| 4283 | + EE_Error::add_error( |
|
| 4284 | + esc_html__( |
|
| 4285 | + 'Settings did not get updated', |
|
| 4286 | + 'event_espresso' |
|
| 4287 | + ), |
|
| 4288 | + __FILE__, |
|
| 4289 | + __FUNCTION__, |
|
| 4290 | + __LINE__ |
|
| 4291 | + ); |
|
| 4292 | + } |
|
| 4293 | + |
|
| 4294 | + $this->_template_args['success'] = $success; |
|
| 4295 | + $this->_return_json(); |
|
| 4296 | + } |
|
| 4297 | 4297 | |
| 4298 | 4298 | |
| 4299 | 4299 | |
| 4300 | 4300 | |
| 4301 | - /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4301 | + /** EE MESSAGE PROCESSING ACTIONS **/ |
|
| 4302 | 4302 | |
| 4303 | 4303 | |
| 4304 | - /** |
|
| 4305 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4306 | - * However, this does not send immediately, it just queues for sending. |
|
| 4307 | - * |
|
| 4308 | - * @since 4.9.0 |
|
| 4309 | - */ |
|
| 4310 | - protected function _generate_now() |
|
| 4311 | - { |
|
| 4312 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4313 | - EED_Messages::generate_now($msg_ids); |
|
| 4314 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4315 | - } |
|
| 4304 | + /** |
|
| 4305 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete |
|
| 4306 | + * However, this does not send immediately, it just queues for sending. |
|
| 4307 | + * |
|
| 4308 | + * @since 4.9.0 |
|
| 4309 | + */ |
|
| 4310 | + protected function _generate_now() |
|
| 4311 | + { |
|
| 4312 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4313 | + EED_Messages::generate_now($msg_ids); |
|
| 4314 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4315 | + } |
|
| 4316 | 4316 | |
| 4317 | 4317 | |
| 4318 | - /** |
|
| 4319 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4320 | - * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4321 | - * |
|
| 4322 | - * @since 4.9.0 |
|
| 4323 | - * |
|
| 4324 | - */ |
|
| 4325 | - protected function _generate_and_send_now() |
|
| 4326 | - { |
|
| 4327 | - $this->_generate_now(); |
|
| 4328 | - $this->_send_now(); |
|
| 4329 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4330 | - } |
|
| 4318 | + /** |
|
| 4319 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that |
|
| 4320 | + * are EEM_Message::status_resend or EEM_Message::status_idle |
|
| 4321 | + * |
|
| 4322 | + * @since 4.9.0 |
|
| 4323 | + * |
|
| 4324 | + */ |
|
| 4325 | + protected function _generate_and_send_now() |
|
| 4326 | + { |
|
| 4327 | + $this->_generate_now(); |
|
| 4328 | + $this->_send_now(); |
|
| 4329 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4330 | + } |
|
| 4331 | 4331 | |
| 4332 | 4332 | |
| 4333 | - /** |
|
| 4334 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4335 | - * |
|
| 4336 | - * @since 4.9.0 |
|
| 4337 | - */ |
|
| 4338 | - protected function _queue_for_resending() |
|
| 4339 | - { |
|
| 4340 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4341 | - EED_Messages::queue_for_resending($msg_ids); |
|
| 4342 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4343 | - } |
|
| 4333 | + /** |
|
| 4334 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending. |
|
| 4335 | + * |
|
| 4336 | + * @since 4.9.0 |
|
| 4337 | + */ |
|
| 4338 | + protected function _queue_for_resending() |
|
| 4339 | + { |
|
| 4340 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4341 | + EED_Messages::queue_for_resending($msg_ids); |
|
| 4342 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4343 | + } |
|
| 4344 | 4344 | |
| 4345 | 4345 | |
| 4346 | - /** |
|
| 4347 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4348 | - * |
|
| 4349 | - * @since 4.9.0 |
|
| 4350 | - */ |
|
| 4351 | - protected function _send_now() |
|
| 4352 | - { |
|
| 4353 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4354 | - EED_Messages::send_now($msg_ids); |
|
| 4355 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | - } |
|
| 4346 | + /** |
|
| 4347 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue |
|
| 4348 | + * |
|
| 4349 | + * @since 4.9.0 |
|
| 4350 | + */ |
|
| 4351 | + protected function _send_now() |
|
| 4352 | + { |
|
| 4353 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4354 | + EED_Messages::send_now($msg_ids); |
|
| 4355 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4356 | + } |
|
| 4357 | 4357 | |
| 4358 | 4358 | |
| 4359 | - /** |
|
| 4360 | - * Deletes EE_messages for IDs in the request. |
|
| 4361 | - * |
|
| 4362 | - * @since 4.9.0 |
|
| 4363 | - * @throws EE_Error |
|
| 4364 | - * @throws InvalidDataTypeException |
|
| 4365 | - * @throws InvalidInterfaceException |
|
| 4366 | - * @throws InvalidArgumentException |
|
| 4367 | - */ |
|
| 4368 | - protected function _delete_ee_messages() |
|
| 4369 | - { |
|
| 4370 | - $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4371 | - $deleted_count = 0; |
|
| 4372 | - foreach ($msg_ids as $msg_id) { |
|
| 4373 | - if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4374 | - $deleted_count++; |
|
| 4375 | - } |
|
| 4376 | - } |
|
| 4377 | - if ($deleted_count) { |
|
| 4378 | - $this->_redirect_after_action( |
|
| 4379 | - true, |
|
| 4380 | - _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 4381 | - esc_html__('deleted', 'event_espresso') |
|
| 4382 | - ); |
|
| 4383 | - } else { |
|
| 4384 | - EE_Error::add_error( |
|
| 4385 | - _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4386 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 4387 | - ); |
|
| 4388 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4389 | - } |
|
| 4390 | - } |
|
| 4359 | + /** |
|
| 4360 | + * Deletes EE_messages for IDs in the request. |
|
| 4361 | + * |
|
| 4362 | + * @since 4.9.0 |
|
| 4363 | + * @throws EE_Error |
|
| 4364 | + * @throws InvalidDataTypeException |
|
| 4365 | + * @throws InvalidInterfaceException |
|
| 4366 | + * @throws InvalidArgumentException |
|
| 4367 | + */ |
|
| 4368 | + protected function _delete_ee_messages() |
|
| 4369 | + { |
|
| 4370 | + $msg_ids = $this->_get_msg_ids_from_request(); |
|
| 4371 | + $deleted_count = 0; |
|
| 4372 | + foreach ($msg_ids as $msg_id) { |
|
| 4373 | + if (EEM_Message::instance()->delete_by_ID($msg_id)) { |
|
| 4374 | + $deleted_count++; |
|
| 4375 | + } |
|
| 4376 | + } |
|
| 4377 | + if ($deleted_count) { |
|
| 4378 | + $this->_redirect_after_action( |
|
| 4379 | + true, |
|
| 4380 | + _n('message', 'messages', $deleted_count, 'event_espresso'), |
|
| 4381 | + esc_html__('deleted', 'event_espresso') |
|
| 4382 | + ); |
|
| 4383 | + } else { |
|
| 4384 | + EE_Error::add_error( |
|
| 4385 | + _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'), |
|
| 4386 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 4387 | + ); |
|
| 4388 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 4389 | + } |
|
| 4390 | + } |
|
| 4391 | 4391 | |
| 4392 | 4392 | |
| 4393 | - /** |
|
| 4394 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4395 | - * @since 4.9.0 |
|
| 4396 | - * @return array |
|
| 4397 | - */ |
|
| 4398 | - protected function _get_msg_ids_from_request() |
|
| 4399 | - { |
|
| 4400 | - if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4401 | - return array(); |
|
| 4402 | - } |
|
| 4403 | - |
|
| 4404 | - return is_array($this->_req_data['MSG_ID']) |
|
| 4405 | - ? array_keys($this->_req_data['MSG_ID']) |
|
| 4406 | - : array($this->_req_data['MSG_ID']); |
|
| 4407 | - } |
|
| 4393 | + /** |
|
| 4394 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present. |
|
| 4395 | + * @since 4.9.0 |
|
| 4396 | + * @return array |
|
| 4397 | + */ |
|
| 4398 | + protected function _get_msg_ids_from_request() |
|
| 4399 | + { |
|
| 4400 | + if ( ! isset($this->_req_data['MSG_ID'])) { |
|
| 4401 | + return array(); |
|
| 4402 | + } |
|
| 4403 | + |
|
| 4404 | + return is_array($this->_req_data['MSG_ID']) |
|
| 4405 | + ? array_keys($this->_req_data['MSG_ID']) |
|
| 4406 | + : array($this->_req_data['MSG_ID']); |
|
| 4407 | + } |
|
| 4408 | 4408 | } |