@@ -944,7 +944,7 @@ |
||
| 944 | 944 | * this method will add that "1" into your date regardless of the format. |
| 945 | 945 | * |
| 946 | 946 | * @param string $month |
| 947 | - * @return string |
|
| 947 | + * @return integer |
|
| 948 | 948 | */ |
| 949 | 949 | public static function first_of_month_timestamp($month = '') |
| 950 | 950 | { |
@@ -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,233 +26,233 @@ 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 | - $gmt_offset = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset'); |
|
| 105 | - if ($gmt_offset !== '') { |
|
| 106 | - // convert GMT offset to seconds |
|
| 107 | - $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 108 | - // account for WP offsets that aren't valid UTC |
|
| 109 | - $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset); |
|
| 110 | - // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 111 | - $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 112 | - } |
|
| 113 | - // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 114 | - $timezone_string = $timezone_string !== false |
|
| 115 | - ? $timezone_string |
|
| 116 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 117 | - return $timezone_string; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Gets the site's GMT offset based on either the timezone string |
|
| 122 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 123 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 124 | - * |
|
| 125 | - * @return int seconds offset |
|
| 126 | - */ |
|
| 127 | - public static function get_site_timezone_gmt_offset() |
|
| 128 | - { |
|
| 129 | - $timezone_string = get_option('timezone_string'); |
|
| 130 | - if ($timezone_string) { |
|
| 131 | - try { |
|
| 132 | - $timezone = new DateTimeZone($timezone_string); |
|
| 133 | - return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 134 | - } catch (Exception $e) { |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - $offset = get_option('gmt_offset'); |
|
| 138 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * _create_timezone_object_from_timezone_name |
|
| 144 | - * |
|
| 145 | - * @access public |
|
| 146 | - * @param int $gmt_offset |
|
| 147 | - * @return int |
|
| 148 | - */ |
|
| 149 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 150 | - { |
|
| 151 | - //make sure $gmt_offset is int |
|
| 152 | - $gmt_offset = (int)$gmt_offset; |
|
| 153 | - switch ($gmt_offset) { |
|
| 154 | - |
|
| 155 | - // case -30600 : |
|
| 156 | - // $gmt_offset = -28800; |
|
| 157 | - // break; |
|
| 158 | - |
|
| 159 | - case -27000 : |
|
| 160 | - $gmt_offset = -25200; |
|
| 161 | - break; |
|
| 162 | - |
|
| 163 | - case -23400 : |
|
| 164 | - $gmt_offset = -21600; |
|
| 165 | - break; |
|
| 166 | - |
|
| 167 | - case -19800 : |
|
| 168 | - $gmt_offset = -18000; |
|
| 169 | - break; |
|
| 170 | - |
|
| 171 | - case -9000 : |
|
| 172 | - $gmt_offset = -7200; |
|
| 173 | - break; |
|
| 174 | - |
|
| 175 | - case -5400 : |
|
| 176 | - $gmt_offset = -3600; |
|
| 177 | - break; |
|
| 178 | - |
|
| 179 | - case -1800 : |
|
| 180 | - $gmt_offset = 0; |
|
| 181 | - break; |
|
| 182 | - |
|
| 183 | - case 1800 : |
|
| 184 | - $gmt_offset = 3600; |
|
| 185 | - break; |
|
| 186 | - |
|
| 187 | - case 49500 : |
|
| 188 | - $gmt_offset = 50400; |
|
| 189 | - break; |
|
| 190 | - |
|
| 191 | - } |
|
| 192 | - return $gmt_offset; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * get_timezone_string_from_abbreviations_list |
|
| 198 | - * |
|
| 199 | - * @access public |
|
| 200 | - * @param int $gmt_offset |
|
| 201 | - * @return string |
|
| 202 | - * @throws \EE_Error |
|
| 203 | - */ |
|
| 204 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0) |
|
| 205 | - { |
|
| 206 | - $abbreviations = timezone_abbreviations_list(); |
|
| 207 | - foreach ($abbreviations as $abbreviation) { |
|
| 208 | - foreach ($abbreviation as $city) { |
|
| 209 | - if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 210 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 211 | - if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) { |
|
| 212 | - return $city['timezone_id']; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - throw new EE_Error( |
|
| 218 | - sprintf( |
|
| 219 | - __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 220 | - 'event_espresso'), |
|
| 221 | - $gmt_offset, |
|
| 222 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 223 | - '</a>' |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @access public |
|
| 231 | - * @param string $timezone_string |
|
| 232 | - */ |
|
| 233 | - public static function timezone_select_input($timezone_string = '') |
|
| 234 | - { |
|
| 235 | - // get WP date time format |
|
| 236 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 237 | - // if passed a value, then use that, else get WP option |
|
| 238 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 239 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 240 | - $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 241 | - $gmt_offset = get_option('gmt_offset'); |
|
| 242 | - |
|
| 243 | - $check_zone_info = true; |
|
| 244 | - if (empty($timezone_string)) { |
|
| 245 | - // Create a UTC+- zone if no timezone string exists |
|
| 246 | - $check_zone_info = false; |
|
| 247 | - if ($gmt_offset > 0) { |
|
| 248 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 249 | - } elseif ($gmt_offset < 0) { |
|
| 250 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 251 | - } else { |
|
| 252 | - $timezone_string = 'UTC'; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - ?> |
|
| 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 | + $gmt_offset = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset'); |
|
| 105 | + if ($gmt_offset !== '') { |
|
| 106 | + // convert GMT offset to seconds |
|
| 107 | + $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 108 | + // account for WP offsets that aren't valid UTC |
|
| 109 | + $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset); |
|
| 110 | + // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 111 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 112 | + } |
|
| 113 | + // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 114 | + $timezone_string = $timezone_string !== false |
|
| 115 | + ? $timezone_string |
|
| 116 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 117 | + return $timezone_string; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Gets the site's GMT offset based on either the timezone string |
|
| 122 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 123 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 124 | + * |
|
| 125 | + * @return int seconds offset |
|
| 126 | + */ |
|
| 127 | + public static function get_site_timezone_gmt_offset() |
|
| 128 | + { |
|
| 129 | + $timezone_string = get_option('timezone_string'); |
|
| 130 | + if ($timezone_string) { |
|
| 131 | + try { |
|
| 132 | + $timezone = new DateTimeZone($timezone_string); |
|
| 133 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 134 | + } catch (Exception $e) { |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + $offset = get_option('gmt_offset'); |
|
| 138 | + return (int)($offset * HOUR_IN_SECONDS); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * _create_timezone_object_from_timezone_name |
|
| 144 | + * |
|
| 145 | + * @access public |
|
| 146 | + * @param int $gmt_offset |
|
| 147 | + * @return int |
|
| 148 | + */ |
|
| 149 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 150 | + { |
|
| 151 | + //make sure $gmt_offset is int |
|
| 152 | + $gmt_offset = (int)$gmt_offset; |
|
| 153 | + switch ($gmt_offset) { |
|
| 154 | + |
|
| 155 | + // case -30600 : |
|
| 156 | + // $gmt_offset = -28800; |
|
| 157 | + // break; |
|
| 158 | + |
|
| 159 | + case -27000 : |
|
| 160 | + $gmt_offset = -25200; |
|
| 161 | + break; |
|
| 162 | + |
|
| 163 | + case -23400 : |
|
| 164 | + $gmt_offset = -21600; |
|
| 165 | + break; |
|
| 166 | + |
|
| 167 | + case -19800 : |
|
| 168 | + $gmt_offset = -18000; |
|
| 169 | + break; |
|
| 170 | + |
|
| 171 | + case -9000 : |
|
| 172 | + $gmt_offset = -7200; |
|
| 173 | + break; |
|
| 174 | + |
|
| 175 | + case -5400 : |
|
| 176 | + $gmt_offset = -3600; |
|
| 177 | + break; |
|
| 178 | + |
|
| 179 | + case -1800 : |
|
| 180 | + $gmt_offset = 0; |
|
| 181 | + break; |
|
| 182 | + |
|
| 183 | + case 1800 : |
|
| 184 | + $gmt_offset = 3600; |
|
| 185 | + break; |
|
| 186 | + |
|
| 187 | + case 49500 : |
|
| 188 | + $gmt_offset = 50400; |
|
| 189 | + break; |
|
| 190 | + |
|
| 191 | + } |
|
| 192 | + return $gmt_offset; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * get_timezone_string_from_abbreviations_list |
|
| 198 | + * |
|
| 199 | + * @access public |
|
| 200 | + * @param int $gmt_offset |
|
| 201 | + * @return string |
|
| 202 | + * @throws \EE_Error |
|
| 203 | + */ |
|
| 204 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0) |
|
| 205 | + { |
|
| 206 | + $abbreviations = timezone_abbreviations_list(); |
|
| 207 | + foreach ($abbreviations as $abbreviation) { |
|
| 208 | + foreach ($abbreviation as $city) { |
|
| 209 | + if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 210 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 211 | + if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) { |
|
| 212 | + return $city['timezone_id']; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + throw new EE_Error( |
|
| 218 | + sprintf( |
|
| 219 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 220 | + 'event_espresso'), |
|
| 221 | + $gmt_offset, |
|
| 222 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 223 | + '</a>' |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @access public |
|
| 231 | + * @param string $timezone_string |
|
| 232 | + */ |
|
| 233 | + public static function timezone_select_input($timezone_string = '') |
|
| 234 | + { |
|
| 235 | + // get WP date time format |
|
| 236 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 237 | + // if passed a value, then use that, else get WP option |
|
| 238 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 239 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 240 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 241 | + $gmt_offset = get_option('gmt_offset'); |
|
| 242 | + |
|
| 243 | + $check_zone_info = true; |
|
| 244 | + if (empty($timezone_string)) { |
|
| 245 | + // Create a UTC+- zone if no timezone string exists |
|
| 246 | + $check_zone_info = false; |
|
| 247 | + if ($gmt_offset > 0) { |
|
| 248 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
| 249 | + } elseif ($gmt_offset < 0) { |
|
| 250 | + $timezone_string = 'UTC' . $gmt_offset; |
|
| 251 | + } else { |
|
| 252 | + $timezone_string = 'UTC'; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + ?> |
|
| 256 | 256 | |
| 257 | 257 | <p> |
| 258 | 258 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
@@ -265,13 +265,13 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | <p> |
| 267 | 267 | <span><?php |
| 268 | - printf( |
|
| 269 | - __('%1$sUTC%2$s time is %3$s'), |
|
| 270 | - '<abbr title="Coordinated Universal Time">', |
|
| 271 | - '</abbr>', |
|
| 272 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 273 | - ); |
|
| 274 | - ?></span> |
|
| 268 | + printf( |
|
| 269 | + __('%1$sUTC%2$s time is %3$s'), |
|
| 270 | + '<abbr title="Coordinated Universal Time">', |
|
| 271 | + '</abbr>', |
|
| 272 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 273 | + ); |
|
| 274 | + ?></span> |
|
| 275 | 275 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
| 276 | 276 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
| 277 | 277 | <?php endif; ?> |
@@ -280,687 +280,687 @@ discard block |
||
| 280 | 280 | <br/> |
| 281 | 281 | <span> |
| 282 | 282 | <?php |
| 283 | - // Set TZ so localtime works. |
|
| 284 | - date_default_timezone_set($timezone_string); |
|
| 285 | - $now = localtime(time(), true); |
|
| 286 | - if ($now['tm_isdst']) { |
|
| 287 | - _e('This timezone is currently in daylight saving time.'); |
|
| 288 | - } else { |
|
| 289 | - _e('This timezone is currently in standard time.'); |
|
| 290 | - } |
|
| 291 | - ?> |
|
| 283 | + // Set TZ so localtime works. |
|
| 284 | + date_default_timezone_set($timezone_string); |
|
| 285 | + $now = localtime(time(), true); |
|
| 286 | + if ($now['tm_isdst']) { |
|
| 287 | + _e('This timezone is currently in daylight saving time.'); |
|
| 288 | + } else { |
|
| 289 | + _e('This timezone is currently in standard time.'); |
|
| 290 | + } |
|
| 291 | + ?> |
|
| 292 | 292 | <br/> |
| 293 | 293 | <?php |
| 294 | - if (function_exists('timezone_transitions_get')) { |
|
| 295 | - $found = false; |
|
| 296 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 297 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 298 | - $right_now = time(); |
|
| 299 | - $tr['isdst'] = false; |
|
| 300 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 301 | - if ($tr['ts'] > $right_now) { |
|
| 302 | - $found = true; |
|
| 303 | - break; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - if ($found) { |
|
| 308 | - $message = $tr['isdst'] ? |
|
| 309 | - __(' Daylight saving time begins on: %s.') : |
|
| 310 | - __(' Standard time begins on: %s.'); |
|
| 311 | - // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 312 | - printf($message, |
|
| 313 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 314 | - } else { |
|
| 315 | - _e('This timezone does not observe daylight saving time.'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - // Set back to UTC. |
|
| 319 | - date_default_timezone_set('UTC'); |
|
| 320 | - ?> |
|
| 294 | + if (function_exists('timezone_transitions_get')) { |
|
| 295 | + $found = false; |
|
| 296 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 297 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 298 | + $right_now = time(); |
|
| 299 | + $tr['isdst'] = false; |
|
| 300 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 301 | + if ($tr['ts'] > $right_now) { |
|
| 302 | + $found = true; |
|
| 303 | + break; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + if ($found) { |
|
| 308 | + $message = $tr['isdst'] ? |
|
| 309 | + __(' Daylight saving time begins on: %s.') : |
|
| 310 | + __(' Standard time begins on: %s.'); |
|
| 311 | + // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 312 | + printf($message, |
|
| 313 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 314 | + } else { |
|
| 315 | + _e('This timezone does not observe daylight saving time.'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + // Set back to UTC. |
|
| 319 | + date_default_timezone_set('UTC'); |
|
| 320 | + ?> |
|
| 321 | 321 | </span></p> |
| 322 | 322 | <?php |
| 323 | - endif; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 329 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 330 | - * the site is used. |
|
| 331 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 332 | - * computed timestamp (i.e. date_i18n() ) |
|
| 333 | - * |
|
| 334 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 335 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 336 | - * site will be used. |
|
| 337 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 338 | - */ |
|
| 339 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 340 | - { |
|
| 341 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 342 | - $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 343 | - $TimeZone = new DateTimeZone($timezone_string); |
|
| 344 | - |
|
| 345 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 346 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 347 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * _set_date_time_field |
|
| 353 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 354 | - * |
|
| 355 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 356 | - * @param DateTime $DateTime PHP DateTime object |
|
| 357 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 358 | - * @return EE_Base_Class |
|
| 359 | - */ |
|
| 360 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 361 | - { |
|
| 362 | - // grab current datetime format |
|
| 363 | - $current_format = $obj->get_format(); |
|
| 364 | - // set new full timestamp format |
|
| 365 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 366 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 367 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 368 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 369 | - // reset datetime formats |
|
| 370 | - $obj->set_date_format($current_format[0]); |
|
| 371 | - $obj->set_time_format($current_format[1]); |
|
| 372 | - return $obj; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * date_time_add |
|
| 378 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 379 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 380 | - * |
|
| 381 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 382 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 383 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 384 | - * minutes, seconds) defaults to years |
|
| 385 | - * @param integer $value what you want to increment the time by |
|
| 386 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 387 | - * (chaining) |
|
| 388 | - */ |
|
| 389 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 390 | - { |
|
| 391 | - //get the raw UTC date. |
|
| 392 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 393 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 394 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * date_time_subtract |
|
| 400 | - * same as date_time_add except subtracting value instead of adding. |
|
| 401 | - * |
|
| 402 | - * @param \EE_Base_Class $obj |
|
| 403 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 404 | - * @param string $period |
|
| 405 | - * @param int $value |
|
| 406 | - * @return \EE_Base_Class |
|
| 407 | - */ |
|
| 408 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 409 | - { |
|
| 410 | - //get the raw UTC date |
|
| 411 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 412 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 413 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 419 | - * |
|
| 420 | - * @param DateTime $DateTime DateTime object |
|
| 421 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 422 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 423 | - * @param integer $value What you want to increment the date by |
|
| 424 | - * @param string $operand What operand you wish to use for the calculation |
|
| 425 | - * @return \DateTime return whatever type came in. |
|
| 426 | - * @throws \EE_Error |
|
| 427 | - */ |
|
| 428 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 429 | - { |
|
| 430 | - if (! $DateTime instanceof DateTime) { |
|
| 431 | - throw new EE_Error( |
|
| 432 | - sprintf( |
|
| 433 | - __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 434 | - print_r($DateTime, true) |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - switch ($period) { |
|
| 439 | - case 'years' : |
|
| 440 | - $value = 'P' . $value . 'Y'; |
|
| 441 | - break; |
|
| 442 | - case 'months' : |
|
| 443 | - $value = 'P' . $value . 'M'; |
|
| 444 | - break; |
|
| 445 | - case 'weeks' : |
|
| 446 | - $value = 'P' . $value . 'W'; |
|
| 447 | - break; |
|
| 448 | - case 'days' : |
|
| 449 | - $value = 'P' . $value . 'D'; |
|
| 450 | - break; |
|
| 451 | - case 'hours' : |
|
| 452 | - $value = 'PT' . $value . 'H'; |
|
| 453 | - break; |
|
| 454 | - case 'minutes' : |
|
| 455 | - $value = 'PT' . $value . 'M'; |
|
| 456 | - break; |
|
| 457 | - case 'seconds' : |
|
| 458 | - $value = 'PT' . $value . 'S'; |
|
| 459 | - break; |
|
| 460 | - } |
|
| 461 | - switch ($operand) { |
|
| 462 | - case '+': |
|
| 463 | - $DateTime->add(new DateInterval($value)); |
|
| 464 | - break; |
|
| 465 | - case '-': |
|
| 466 | - $DateTime->sub(new DateInterval($value)); |
|
| 467 | - break; |
|
| 468 | - } |
|
| 469 | - return $DateTime; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 475 | - * |
|
| 476 | - * @param int $timestamp Unix timestamp |
|
| 477 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 478 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 479 | - * @param integer $value What you want to increment the date by |
|
| 480 | - * @param string $operand What operand you wish to use for the calculation |
|
| 481 | - * @return \DateTime return whatever type came in. |
|
| 482 | - * @throws \EE_Error |
|
| 483 | - */ |
|
| 484 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 485 | - { |
|
| 486 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 487 | - throw new EE_Error( |
|
| 488 | - sprintf( |
|
| 489 | - __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 490 | - print_r($timestamp, true) |
|
| 491 | - ) |
|
| 492 | - ); |
|
| 493 | - } |
|
| 494 | - switch ($period) { |
|
| 495 | - case 'years' : |
|
| 496 | - $value = YEAR_IN_SECONDS * $value; |
|
| 497 | - break; |
|
| 498 | - case 'months' : |
|
| 499 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 500 | - break; |
|
| 501 | - case 'weeks' : |
|
| 502 | - $value = WEEK_IN_SECONDS * $value; |
|
| 503 | - break; |
|
| 504 | - case 'days' : |
|
| 505 | - $value = DAY_IN_SECONDS * $value; |
|
| 506 | - break; |
|
| 507 | - case 'hours' : |
|
| 508 | - $value = HOUR_IN_SECONDS * $value; |
|
| 509 | - break; |
|
| 510 | - case 'minutes' : |
|
| 511 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 512 | - break; |
|
| 513 | - } |
|
| 514 | - switch ($operand) { |
|
| 515 | - case '+': |
|
| 516 | - $timestamp += $value; |
|
| 517 | - break; |
|
| 518 | - case '-': |
|
| 519 | - $timestamp -= $value; |
|
| 520 | - break; |
|
| 521 | - } |
|
| 522 | - return $timestamp; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 528 | - * parameters and returns the new timestamp or DateTime. |
|
| 529 | - * |
|
| 530 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 531 | - * @param string $period a value to indicate what interval is being used in the |
|
| 532 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 533 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 534 | - * @param integer $value What you want to increment the date by |
|
| 535 | - * @param string $operand What operand you wish to use for the calculation |
|
| 536 | - * @return mixed string|DateTime return whatever type came in. |
|
| 537 | - */ |
|
| 538 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 539 | - { |
|
| 540 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 541 | - return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 542 | - } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 543 | - return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 544 | - } else { |
|
| 545 | - //error |
|
| 546 | - return $DateTime_or_timestamp; |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 553 | - * and spit out the js and moment.js equivalent formats. |
|
| 554 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 555 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 556 | - * time picker. |
|
| 557 | - * |
|
| 558 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 559 | - * @param null $date_format_string |
|
| 560 | - * @param null $time_format_string |
|
| 561 | - * @return array |
|
| 562 | - * array( |
|
| 563 | - * 'js' => array ( |
|
| 564 | - * 'date' => //date format |
|
| 565 | - * 'time' => //time format |
|
| 566 | - * ), |
|
| 567 | - * 'moment' => //date and time format. |
|
| 568 | - * ) |
|
| 569 | - */ |
|
| 570 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 571 | - $date_format_string = null, |
|
| 572 | - $time_format_string = null |
|
| 573 | - ) { |
|
| 574 | - if ($date_format_string === null) { |
|
| 575 | - $date_format_string = get_option('date_format'); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if ($time_format_string === null) { |
|
| 579 | - $time_format_string = get_option('time_format'); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 583 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 584 | - |
|
| 585 | - return array( |
|
| 586 | - 'js' => array( |
|
| 587 | - 'date' => $date_format['js'], |
|
| 588 | - 'time' => $time_format['js'], |
|
| 589 | - ), |
|
| 590 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * This converts incoming format string into js and moment variations. |
|
| 597 | - * |
|
| 598 | - * @param string $format_string incoming php format string |
|
| 599 | - * @return array js and moment formats. |
|
| 600 | - */ |
|
| 601 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 602 | - { |
|
| 603 | - /** |
|
| 604 | - * This is a map of symbols for formats. |
|
| 605 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 606 | - * |
|
| 607 | - * @var array |
|
| 608 | - */ |
|
| 609 | - $symbols_map = array( |
|
| 610 | - // Day |
|
| 611 | - //01 |
|
| 612 | - 'd' => array( |
|
| 613 | - 'js' => 'dd', |
|
| 614 | - 'moment' => 'DD', |
|
| 615 | - ), |
|
| 616 | - //Mon |
|
| 617 | - 'D' => array( |
|
| 618 | - 'js' => 'D', |
|
| 619 | - 'moment' => 'ddd', |
|
| 620 | - ), |
|
| 621 | - //1,2,...31 |
|
| 622 | - 'j' => array( |
|
| 623 | - 'js' => 'd', |
|
| 624 | - 'moment' => 'D', |
|
| 625 | - ), |
|
| 626 | - //Monday |
|
| 627 | - 'l' => array( |
|
| 628 | - 'js' => 'DD', |
|
| 629 | - 'moment' => 'dddd', |
|
| 630 | - ), |
|
| 631 | - //ISO numeric representation of the day of the week (1-6) |
|
| 632 | - 'N' => array( |
|
| 633 | - 'js' => '', |
|
| 634 | - 'moment' => 'E', |
|
| 635 | - ), |
|
| 636 | - //st,nd.rd |
|
| 637 | - 'S' => array( |
|
| 638 | - 'js' => '', |
|
| 639 | - 'moment' => 'o', |
|
| 640 | - ), |
|
| 641 | - //numeric representation of day of week (0-6) |
|
| 642 | - 'w' => array( |
|
| 643 | - 'js' => '', |
|
| 644 | - 'moment' => 'd', |
|
| 645 | - ), |
|
| 646 | - //day of year starting from 0 (0-365) |
|
| 647 | - 'z' => array( |
|
| 648 | - 'js' => 'o', |
|
| 649 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 650 | - ), |
|
| 651 | - // Week |
|
| 652 | - //ISO-8601 week number of year (weeks starting on monday) |
|
| 653 | - 'W' => array( |
|
| 654 | - 'js' => '', |
|
| 655 | - 'moment' => 'w', |
|
| 656 | - ), |
|
| 657 | - // Month |
|
| 658 | - // January...December |
|
| 659 | - 'F' => array( |
|
| 660 | - 'js' => 'MM', |
|
| 661 | - 'moment' => 'MMMM', |
|
| 662 | - ), |
|
| 663 | - //01...12 |
|
| 664 | - 'm' => array( |
|
| 665 | - 'js' => 'mm', |
|
| 666 | - 'moment' => 'MM', |
|
| 667 | - ), |
|
| 668 | - //Jan...Dec |
|
| 669 | - 'M' => array( |
|
| 670 | - 'js' => 'M', |
|
| 671 | - 'moment' => 'MMM', |
|
| 672 | - ), |
|
| 673 | - //1-12 |
|
| 674 | - 'n' => array( |
|
| 675 | - 'js' => 'm', |
|
| 676 | - 'moment' => 'M', |
|
| 677 | - ), |
|
| 678 | - //number of days in given month |
|
| 679 | - 't' => array( |
|
| 680 | - 'js' => '', |
|
| 681 | - 'moment' => '', |
|
| 682 | - ), |
|
| 683 | - // Year |
|
| 684 | - //whether leap year or not 1/0 |
|
| 685 | - 'L' => array( |
|
| 686 | - 'js' => '', |
|
| 687 | - 'moment' => '', |
|
| 688 | - ), |
|
| 689 | - //ISO-8601 year number |
|
| 690 | - 'o' => array( |
|
| 691 | - 'js' => '', |
|
| 692 | - 'moment' => 'GGGG', |
|
| 693 | - ), |
|
| 694 | - //1999...2003 |
|
| 695 | - 'Y' => array( |
|
| 696 | - 'js' => 'yy', |
|
| 697 | - 'moment' => 'YYYY', |
|
| 698 | - ), |
|
| 699 | - //99...03 |
|
| 700 | - 'y' => array( |
|
| 701 | - 'js' => 'y', |
|
| 702 | - 'moment' => 'YY', |
|
| 703 | - ), |
|
| 704 | - // Time |
|
| 705 | - // am/pm |
|
| 706 | - 'a' => array( |
|
| 707 | - 'js' => 'tt', |
|
| 708 | - 'moment' => 'a', |
|
| 709 | - ), |
|
| 710 | - // AM/PM |
|
| 711 | - 'A' => array( |
|
| 712 | - 'js' => 'TT', |
|
| 713 | - 'moment' => 'A', |
|
| 714 | - ), |
|
| 715 | - // Swatch Internet Time?!? |
|
| 716 | - 'B' => array( |
|
| 717 | - 'js' => '', |
|
| 718 | - 'moment' => '', |
|
| 719 | - ), |
|
| 720 | - //1...12 |
|
| 721 | - 'g' => array( |
|
| 722 | - 'js' => 'h', |
|
| 723 | - 'moment' => 'h', |
|
| 724 | - ), |
|
| 725 | - //0...23 |
|
| 726 | - 'G' => array( |
|
| 727 | - 'js' => 'H', |
|
| 728 | - 'moment' => 'H', |
|
| 729 | - ), |
|
| 730 | - //01...12 |
|
| 731 | - 'h' => array( |
|
| 732 | - 'js' => 'hh', |
|
| 733 | - 'moment' => 'hh', |
|
| 734 | - ), |
|
| 735 | - //00...23 |
|
| 736 | - 'H' => array( |
|
| 737 | - 'js' => 'HH', |
|
| 738 | - 'moment' => 'HH', |
|
| 739 | - ), |
|
| 740 | - //00..59 |
|
| 741 | - 'i' => array( |
|
| 742 | - 'js' => 'mm', |
|
| 743 | - 'moment' => 'mm', |
|
| 744 | - ), |
|
| 745 | - //seconds... 00...59 |
|
| 746 | - 's' => array( |
|
| 747 | - 'js' => 'ss', |
|
| 748 | - 'moment' => 'ss', |
|
| 749 | - ), |
|
| 750 | - //microseconds |
|
| 751 | - 'u' => array( |
|
| 752 | - 'js' => '', |
|
| 753 | - 'moment' => '', |
|
| 754 | - ), |
|
| 755 | - ); |
|
| 756 | - $jquery_ui_format = ""; |
|
| 757 | - $moment_format = ""; |
|
| 758 | - $escaping = false; |
|
| 759 | - for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 760 | - $char = $format_string[$i]; |
|
| 761 | - if ($char === '\\') { // PHP date format escaping character |
|
| 762 | - $i++; |
|
| 763 | - if ($escaping) { |
|
| 764 | - $jquery_ui_format .= $format_string[$i]; |
|
| 765 | - $moment_format .= $format_string[$i]; |
|
| 766 | - } else { |
|
| 767 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 768 | - $moment_format .= $format_string[$i]; |
|
| 769 | - } |
|
| 770 | - $escaping = true; |
|
| 771 | - } else { |
|
| 772 | - if ($escaping) { |
|
| 773 | - $jquery_ui_format .= "'"; |
|
| 774 | - $moment_format .= "'"; |
|
| 775 | - $escaping = false; |
|
| 776 | - } |
|
| 777 | - if (isset($symbols_map[$char])) { |
|
| 778 | - $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 779 | - $moment_format .= $symbols_map[$char]['moment']; |
|
| 780 | - } else { |
|
| 781 | - $jquery_ui_format .= $char; |
|
| 782 | - $moment_format .= $char; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 792 | - * |
|
| 793 | - * @param string $format_string Incoming format string for php date(). |
|
| 794 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 795 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 796 | - * indicate failed validations. |
|
| 797 | - */ |
|
| 798 | - public static function validate_format_string($format_string) |
|
| 799 | - { |
|
| 800 | - $error_msg = array(); |
|
| 801 | - //time format checks |
|
| 802 | - switch (true) { |
|
| 803 | - case strpos($format_string, 'h') !== false : |
|
| 804 | - case strpos($format_string, 'g') !== false : |
|
| 805 | - /** |
|
| 806 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 807 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 808 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 809 | - */ |
|
| 810 | - if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 811 | - $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".', |
|
| 812 | - 'event_espresso'); |
|
| 813 | - } |
|
| 814 | - break; |
|
| 815 | - |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - return empty($error_msg) ? true : $error_msg; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 824 | - * very next day then this method will return true. |
|
| 825 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 826 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 827 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 828 | - * |
|
| 829 | - * @param mixed $date_1 |
|
| 830 | - * @param mixed $date_2 |
|
| 831 | - * @return bool |
|
| 832 | - */ |
|
| 833 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 834 | - { |
|
| 835 | - |
|
| 836 | - if ( |
|
| 837 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 838 | - ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 839 | - ) { |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 848 | - * Functions. |
|
| 849 | - * |
|
| 850 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 851 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 852 | - * @return string |
|
| 853 | - */ |
|
| 854 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 855 | - { |
|
| 856 | - try { |
|
| 857 | - /** need to account for timezone offset on the selects */ |
|
| 858 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 859 | - } catch (Exception $e) { |
|
| 860 | - $DateTimeZone = null; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 865 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 866 | - */ |
|
| 867 | - $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 868 | - $query_interval = $offset < 0 |
|
| 869 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 870 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 871 | - return $query_interval; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 876 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 877 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 878 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 879 | - * (although note that we remove any HTML that may be added) |
|
| 880 | - * |
|
| 881 | - * @return string |
|
| 882 | - */ |
|
| 883 | - public static function get_timezone_string_for_display() |
|
| 884 | - { |
|
| 885 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 886 | - if (! empty($pretty_timezone)) { |
|
| 887 | - return esc_html($pretty_timezone); |
|
| 888 | - } |
|
| 889 | - $timezone_string = get_option('timezone_string'); |
|
| 890 | - if ($timezone_string) { |
|
| 891 | - static $mo_loaded = false; |
|
| 892 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 893 | - if (! $mo_loaded) { |
|
| 894 | - $locale = get_locale(); |
|
| 895 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 896 | - load_textdomain('continents-cities', $mofile); |
|
| 897 | - $mo_loaded = true; |
|
| 898 | - } |
|
| 899 | - //well that was easy. |
|
| 900 | - $parts = explode('/', $timezone_string); |
|
| 901 | - //remove the continent |
|
| 902 | - unset($parts[0]); |
|
| 903 | - $t_parts = array(); |
|
| 904 | - foreach ($parts as $part) { |
|
| 905 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 906 | - } |
|
| 907 | - return implode(' - ', $t_parts); |
|
| 908 | - } |
|
| 909 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 910 | - $gmt_offset = get_option('gmt_offset'); |
|
| 911 | - if (intval($gmt_offset) >= 0) { |
|
| 912 | - $prefix = '+'; |
|
| 913 | - } else { |
|
| 914 | - $prefix = ''; |
|
| 915 | - } |
|
| 916 | - $parts = explode('.', (string)$gmt_offset); |
|
| 917 | - if (count($parts) === 1) { |
|
| 918 | - $parts[1] = '00'; |
|
| 919 | - } else { |
|
| 920 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 921 | - //to minutes, eg 30 or 15, respectively |
|
| 922 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 923 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 924 | - } |
|
| 925 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 932 | - * for a month using a string like "February" or "February 2017", |
|
| 933 | - * and you don't specify a day as part of your string, |
|
| 934 | - * then PHP will use whatever the current day of the month is. |
|
| 935 | - * IF the current day of the month happens to be the 30th or 31st, |
|
| 936 | - * then PHP gets really confused by a date like February 30, |
|
| 937 | - * so instead of saying |
|
| 938 | - * "Hey February only has 28 days (this year)... |
|
| 939 | - * ...you must have meant the last day of the month!" |
|
| 940 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 941 | - * because someone requesting February 30th obviously meant March 1st! |
|
| 942 | - * The way around this is to always set the day to the first, |
|
| 943 | - * so that the month will stay on the month you wanted. |
|
| 944 | - * this method will add that "1" into your date regardless of the format. |
|
| 945 | - * |
|
| 946 | - * @param string $month |
|
| 947 | - * @return string |
|
| 948 | - */ |
|
| 949 | - public static function first_of_month_timestamp($month = '') |
|
| 950 | - { |
|
| 951 | - $month = (string)$month; |
|
| 952 | - $year = ''; |
|
| 953 | - // check if the incoming string has a year in it or not |
|
| 954 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 955 | - $year = $matches[0]; |
|
| 956 | - // ten remove that from the month string as well as any spaces |
|
| 957 | - $month = trim(str_replace($year, '', $month)); |
|
| 958 | - // add a space before the year |
|
| 959 | - $year = " {$year}"; |
|
| 960 | - } |
|
| 961 | - // return timestamp for something like "February 1 2017" |
|
| 962 | - return strtotime("{$month} 1{$year}"); |
|
| 963 | - } |
|
| 323 | + endif; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 329 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 330 | + * the site is used. |
|
| 331 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 332 | + * computed timestamp (i.e. date_i18n() ) |
|
| 333 | + * |
|
| 334 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 335 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 336 | + * site will be used. |
|
| 337 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 338 | + */ |
|
| 339 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 340 | + { |
|
| 341 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 342 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 343 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 344 | + |
|
| 345 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 346 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 347 | + return (int)$DateTime->format('U') + (int)$offset; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * _set_date_time_field |
|
| 353 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 354 | + * |
|
| 355 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 356 | + * @param DateTime $DateTime PHP DateTime object |
|
| 357 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 358 | + * @return EE_Base_Class |
|
| 359 | + */ |
|
| 360 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 361 | + { |
|
| 362 | + // grab current datetime format |
|
| 363 | + $current_format = $obj->get_format(); |
|
| 364 | + // set new full timestamp format |
|
| 365 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 366 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 367 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 368 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 369 | + // reset datetime formats |
|
| 370 | + $obj->set_date_format($current_format[0]); |
|
| 371 | + $obj->set_time_format($current_format[1]); |
|
| 372 | + return $obj; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * date_time_add |
|
| 378 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 379 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 380 | + * |
|
| 381 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 382 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 383 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 384 | + * minutes, seconds) defaults to years |
|
| 385 | + * @param integer $value what you want to increment the time by |
|
| 386 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 387 | + * (chaining) |
|
| 388 | + */ |
|
| 389 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 390 | + { |
|
| 391 | + //get the raw UTC date. |
|
| 392 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 393 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 394 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * date_time_subtract |
|
| 400 | + * same as date_time_add except subtracting value instead of adding. |
|
| 401 | + * |
|
| 402 | + * @param \EE_Base_Class $obj |
|
| 403 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 404 | + * @param string $period |
|
| 405 | + * @param int $value |
|
| 406 | + * @return \EE_Base_Class |
|
| 407 | + */ |
|
| 408 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 409 | + { |
|
| 410 | + //get the raw UTC date |
|
| 411 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 412 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 413 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 419 | + * |
|
| 420 | + * @param DateTime $DateTime DateTime object |
|
| 421 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 422 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 423 | + * @param integer $value What you want to increment the date by |
|
| 424 | + * @param string $operand What operand you wish to use for the calculation |
|
| 425 | + * @return \DateTime return whatever type came in. |
|
| 426 | + * @throws \EE_Error |
|
| 427 | + */ |
|
| 428 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 429 | + { |
|
| 430 | + if (! $DateTime instanceof DateTime) { |
|
| 431 | + throw new EE_Error( |
|
| 432 | + sprintf( |
|
| 433 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 434 | + print_r($DateTime, true) |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + switch ($period) { |
|
| 439 | + case 'years' : |
|
| 440 | + $value = 'P' . $value . 'Y'; |
|
| 441 | + break; |
|
| 442 | + case 'months' : |
|
| 443 | + $value = 'P' . $value . 'M'; |
|
| 444 | + break; |
|
| 445 | + case 'weeks' : |
|
| 446 | + $value = 'P' . $value . 'W'; |
|
| 447 | + break; |
|
| 448 | + case 'days' : |
|
| 449 | + $value = 'P' . $value . 'D'; |
|
| 450 | + break; |
|
| 451 | + case 'hours' : |
|
| 452 | + $value = 'PT' . $value . 'H'; |
|
| 453 | + break; |
|
| 454 | + case 'minutes' : |
|
| 455 | + $value = 'PT' . $value . 'M'; |
|
| 456 | + break; |
|
| 457 | + case 'seconds' : |
|
| 458 | + $value = 'PT' . $value . 'S'; |
|
| 459 | + break; |
|
| 460 | + } |
|
| 461 | + switch ($operand) { |
|
| 462 | + case '+': |
|
| 463 | + $DateTime->add(new DateInterval($value)); |
|
| 464 | + break; |
|
| 465 | + case '-': |
|
| 466 | + $DateTime->sub(new DateInterval($value)); |
|
| 467 | + break; |
|
| 468 | + } |
|
| 469 | + return $DateTime; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 475 | + * |
|
| 476 | + * @param int $timestamp Unix timestamp |
|
| 477 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 478 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 479 | + * @param integer $value What you want to increment the date by |
|
| 480 | + * @param string $operand What operand you wish to use for the calculation |
|
| 481 | + * @return \DateTime return whatever type came in. |
|
| 482 | + * @throws \EE_Error |
|
| 483 | + */ |
|
| 484 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 485 | + { |
|
| 486 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 487 | + throw new EE_Error( |
|
| 488 | + sprintf( |
|
| 489 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 490 | + print_r($timestamp, true) |
|
| 491 | + ) |
|
| 492 | + ); |
|
| 493 | + } |
|
| 494 | + switch ($period) { |
|
| 495 | + case 'years' : |
|
| 496 | + $value = YEAR_IN_SECONDS * $value; |
|
| 497 | + break; |
|
| 498 | + case 'months' : |
|
| 499 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 500 | + break; |
|
| 501 | + case 'weeks' : |
|
| 502 | + $value = WEEK_IN_SECONDS * $value; |
|
| 503 | + break; |
|
| 504 | + case 'days' : |
|
| 505 | + $value = DAY_IN_SECONDS * $value; |
|
| 506 | + break; |
|
| 507 | + case 'hours' : |
|
| 508 | + $value = HOUR_IN_SECONDS * $value; |
|
| 509 | + break; |
|
| 510 | + case 'minutes' : |
|
| 511 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 512 | + break; |
|
| 513 | + } |
|
| 514 | + switch ($operand) { |
|
| 515 | + case '+': |
|
| 516 | + $timestamp += $value; |
|
| 517 | + break; |
|
| 518 | + case '-': |
|
| 519 | + $timestamp -= $value; |
|
| 520 | + break; |
|
| 521 | + } |
|
| 522 | + return $timestamp; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 528 | + * parameters and returns the new timestamp or DateTime. |
|
| 529 | + * |
|
| 530 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 531 | + * @param string $period a value to indicate what interval is being used in the |
|
| 532 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 533 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 534 | + * @param integer $value What you want to increment the date by |
|
| 535 | + * @param string $operand What operand you wish to use for the calculation |
|
| 536 | + * @return mixed string|DateTime return whatever type came in. |
|
| 537 | + */ |
|
| 538 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 539 | + { |
|
| 540 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 541 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 542 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 543 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 544 | + } else { |
|
| 545 | + //error |
|
| 546 | + return $DateTime_or_timestamp; |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 553 | + * and spit out the js and moment.js equivalent formats. |
|
| 554 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 555 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 556 | + * time picker. |
|
| 557 | + * |
|
| 558 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 559 | + * @param null $date_format_string |
|
| 560 | + * @param null $time_format_string |
|
| 561 | + * @return array |
|
| 562 | + * array( |
|
| 563 | + * 'js' => array ( |
|
| 564 | + * 'date' => //date format |
|
| 565 | + * 'time' => //time format |
|
| 566 | + * ), |
|
| 567 | + * 'moment' => //date and time format. |
|
| 568 | + * ) |
|
| 569 | + */ |
|
| 570 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 571 | + $date_format_string = null, |
|
| 572 | + $time_format_string = null |
|
| 573 | + ) { |
|
| 574 | + if ($date_format_string === null) { |
|
| 575 | + $date_format_string = get_option('date_format'); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if ($time_format_string === null) { |
|
| 579 | + $time_format_string = get_option('time_format'); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 583 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 584 | + |
|
| 585 | + return array( |
|
| 586 | + 'js' => array( |
|
| 587 | + 'date' => $date_format['js'], |
|
| 588 | + 'time' => $time_format['js'], |
|
| 589 | + ), |
|
| 590 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * This converts incoming format string into js and moment variations. |
|
| 597 | + * |
|
| 598 | + * @param string $format_string incoming php format string |
|
| 599 | + * @return array js and moment formats. |
|
| 600 | + */ |
|
| 601 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 602 | + { |
|
| 603 | + /** |
|
| 604 | + * This is a map of symbols for formats. |
|
| 605 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 606 | + * |
|
| 607 | + * @var array |
|
| 608 | + */ |
|
| 609 | + $symbols_map = array( |
|
| 610 | + // Day |
|
| 611 | + //01 |
|
| 612 | + 'd' => array( |
|
| 613 | + 'js' => 'dd', |
|
| 614 | + 'moment' => 'DD', |
|
| 615 | + ), |
|
| 616 | + //Mon |
|
| 617 | + 'D' => array( |
|
| 618 | + 'js' => 'D', |
|
| 619 | + 'moment' => 'ddd', |
|
| 620 | + ), |
|
| 621 | + //1,2,...31 |
|
| 622 | + 'j' => array( |
|
| 623 | + 'js' => 'd', |
|
| 624 | + 'moment' => 'D', |
|
| 625 | + ), |
|
| 626 | + //Monday |
|
| 627 | + 'l' => array( |
|
| 628 | + 'js' => 'DD', |
|
| 629 | + 'moment' => 'dddd', |
|
| 630 | + ), |
|
| 631 | + //ISO numeric representation of the day of the week (1-6) |
|
| 632 | + 'N' => array( |
|
| 633 | + 'js' => '', |
|
| 634 | + 'moment' => 'E', |
|
| 635 | + ), |
|
| 636 | + //st,nd.rd |
|
| 637 | + 'S' => array( |
|
| 638 | + 'js' => '', |
|
| 639 | + 'moment' => 'o', |
|
| 640 | + ), |
|
| 641 | + //numeric representation of day of week (0-6) |
|
| 642 | + 'w' => array( |
|
| 643 | + 'js' => '', |
|
| 644 | + 'moment' => 'd', |
|
| 645 | + ), |
|
| 646 | + //day of year starting from 0 (0-365) |
|
| 647 | + 'z' => array( |
|
| 648 | + 'js' => 'o', |
|
| 649 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 650 | + ), |
|
| 651 | + // Week |
|
| 652 | + //ISO-8601 week number of year (weeks starting on monday) |
|
| 653 | + 'W' => array( |
|
| 654 | + 'js' => '', |
|
| 655 | + 'moment' => 'w', |
|
| 656 | + ), |
|
| 657 | + // Month |
|
| 658 | + // January...December |
|
| 659 | + 'F' => array( |
|
| 660 | + 'js' => 'MM', |
|
| 661 | + 'moment' => 'MMMM', |
|
| 662 | + ), |
|
| 663 | + //01...12 |
|
| 664 | + 'm' => array( |
|
| 665 | + 'js' => 'mm', |
|
| 666 | + 'moment' => 'MM', |
|
| 667 | + ), |
|
| 668 | + //Jan...Dec |
|
| 669 | + 'M' => array( |
|
| 670 | + 'js' => 'M', |
|
| 671 | + 'moment' => 'MMM', |
|
| 672 | + ), |
|
| 673 | + //1-12 |
|
| 674 | + 'n' => array( |
|
| 675 | + 'js' => 'm', |
|
| 676 | + 'moment' => 'M', |
|
| 677 | + ), |
|
| 678 | + //number of days in given month |
|
| 679 | + 't' => array( |
|
| 680 | + 'js' => '', |
|
| 681 | + 'moment' => '', |
|
| 682 | + ), |
|
| 683 | + // Year |
|
| 684 | + //whether leap year or not 1/0 |
|
| 685 | + 'L' => array( |
|
| 686 | + 'js' => '', |
|
| 687 | + 'moment' => '', |
|
| 688 | + ), |
|
| 689 | + //ISO-8601 year number |
|
| 690 | + 'o' => array( |
|
| 691 | + 'js' => '', |
|
| 692 | + 'moment' => 'GGGG', |
|
| 693 | + ), |
|
| 694 | + //1999...2003 |
|
| 695 | + 'Y' => array( |
|
| 696 | + 'js' => 'yy', |
|
| 697 | + 'moment' => 'YYYY', |
|
| 698 | + ), |
|
| 699 | + //99...03 |
|
| 700 | + 'y' => array( |
|
| 701 | + 'js' => 'y', |
|
| 702 | + 'moment' => 'YY', |
|
| 703 | + ), |
|
| 704 | + // Time |
|
| 705 | + // am/pm |
|
| 706 | + 'a' => array( |
|
| 707 | + 'js' => 'tt', |
|
| 708 | + 'moment' => 'a', |
|
| 709 | + ), |
|
| 710 | + // AM/PM |
|
| 711 | + 'A' => array( |
|
| 712 | + 'js' => 'TT', |
|
| 713 | + 'moment' => 'A', |
|
| 714 | + ), |
|
| 715 | + // Swatch Internet Time?!? |
|
| 716 | + 'B' => array( |
|
| 717 | + 'js' => '', |
|
| 718 | + 'moment' => '', |
|
| 719 | + ), |
|
| 720 | + //1...12 |
|
| 721 | + 'g' => array( |
|
| 722 | + 'js' => 'h', |
|
| 723 | + 'moment' => 'h', |
|
| 724 | + ), |
|
| 725 | + //0...23 |
|
| 726 | + 'G' => array( |
|
| 727 | + 'js' => 'H', |
|
| 728 | + 'moment' => 'H', |
|
| 729 | + ), |
|
| 730 | + //01...12 |
|
| 731 | + 'h' => array( |
|
| 732 | + 'js' => 'hh', |
|
| 733 | + 'moment' => 'hh', |
|
| 734 | + ), |
|
| 735 | + //00...23 |
|
| 736 | + 'H' => array( |
|
| 737 | + 'js' => 'HH', |
|
| 738 | + 'moment' => 'HH', |
|
| 739 | + ), |
|
| 740 | + //00..59 |
|
| 741 | + 'i' => array( |
|
| 742 | + 'js' => 'mm', |
|
| 743 | + 'moment' => 'mm', |
|
| 744 | + ), |
|
| 745 | + //seconds... 00...59 |
|
| 746 | + 's' => array( |
|
| 747 | + 'js' => 'ss', |
|
| 748 | + 'moment' => 'ss', |
|
| 749 | + ), |
|
| 750 | + //microseconds |
|
| 751 | + 'u' => array( |
|
| 752 | + 'js' => '', |
|
| 753 | + 'moment' => '', |
|
| 754 | + ), |
|
| 755 | + ); |
|
| 756 | + $jquery_ui_format = ""; |
|
| 757 | + $moment_format = ""; |
|
| 758 | + $escaping = false; |
|
| 759 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 760 | + $char = $format_string[$i]; |
|
| 761 | + if ($char === '\\') { // PHP date format escaping character |
|
| 762 | + $i++; |
|
| 763 | + if ($escaping) { |
|
| 764 | + $jquery_ui_format .= $format_string[$i]; |
|
| 765 | + $moment_format .= $format_string[$i]; |
|
| 766 | + } else { |
|
| 767 | + $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 768 | + $moment_format .= $format_string[$i]; |
|
| 769 | + } |
|
| 770 | + $escaping = true; |
|
| 771 | + } else { |
|
| 772 | + if ($escaping) { |
|
| 773 | + $jquery_ui_format .= "'"; |
|
| 774 | + $moment_format .= "'"; |
|
| 775 | + $escaping = false; |
|
| 776 | + } |
|
| 777 | + if (isset($symbols_map[$char])) { |
|
| 778 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 779 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 780 | + } else { |
|
| 781 | + $jquery_ui_format .= $char; |
|
| 782 | + $moment_format .= $char; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 792 | + * |
|
| 793 | + * @param string $format_string Incoming format string for php date(). |
|
| 794 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 795 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 796 | + * indicate failed validations. |
|
| 797 | + */ |
|
| 798 | + public static function validate_format_string($format_string) |
|
| 799 | + { |
|
| 800 | + $error_msg = array(); |
|
| 801 | + //time format checks |
|
| 802 | + switch (true) { |
|
| 803 | + case strpos($format_string, 'h') !== false : |
|
| 804 | + case strpos($format_string, 'g') !== false : |
|
| 805 | + /** |
|
| 806 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 807 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 808 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 809 | + */ |
|
| 810 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 811 | + $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".', |
|
| 812 | + 'event_espresso'); |
|
| 813 | + } |
|
| 814 | + break; |
|
| 815 | + |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + return empty($error_msg) ? true : $error_msg; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 824 | + * very next day then this method will return true. |
|
| 825 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 826 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 827 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 828 | + * |
|
| 829 | + * @param mixed $date_1 |
|
| 830 | + * @param mixed $date_2 |
|
| 831 | + * @return bool |
|
| 832 | + */ |
|
| 833 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 834 | + { |
|
| 835 | + |
|
| 836 | + if ( |
|
| 837 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 838 | + ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 839 | + ) { |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 848 | + * Functions. |
|
| 849 | + * |
|
| 850 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 851 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 852 | + * @return string |
|
| 853 | + */ |
|
| 854 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 855 | + { |
|
| 856 | + try { |
|
| 857 | + /** need to account for timezone offset on the selects */ |
|
| 858 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 859 | + } catch (Exception $e) { |
|
| 860 | + $DateTimeZone = null; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 865 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 866 | + */ |
|
| 867 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 868 | + $query_interval = $offset < 0 |
|
| 869 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 870 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 871 | + return $query_interval; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 876 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 877 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 878 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 879 | + * (although note that we remove any HTML that may be added) |
|
| 880 | + * |
|
| 881 | + * @return string |
|
| 882 | + */ |
|
| 883 | + public static function get_timezone_string_for_display() |
|
| 884 | + { |
|
| 885 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 886 | + if (! empty($pretty_timezone)) { |
|
| 887 | + return esc_html($pretty_timezone); |
|
| 888 | + } |
|
| 889 | + $timezone_string = get_option('timezone_string'); |
|
| 890 | + if ($timezone_string) { |
|
| 891 | + static $mo_loaded = false; |
|
| 892 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 893 | + if (! $mo_loaded) { |
|
| 894 | + $locale = get_locale(); |
|
| 895 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 896 | + load_textdomain('continents-cities', $mofile); |
|
| 897 | + $mo_loaded = true; |
|
| 898 | + } |
|
| 899 | + //well that was easy. |
|
| 900 | + $parts = explode('/', $timezone_string); |
|
| 901 | + //remove the continent |
|
| 902 | + unset($parts[0]); |
|
| 903 | + $t_parts = array(); |
|
| 904 | + foreach ($parts as $part) { |
|
| 905 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 906 | + } |
|
| 907 | + return implode(' - ', $t_parts); |
|
| 908 | + } |
|
| 909 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 910 | + $gmt_offset = get_option('gmt_offset'); |
|
| 911 | + if (intval($gmt_offset) >= 0) { |
|
| 912 | + $prefix = '+'; |
|
| 913 | + } else { |
|
| 914 | + $prefix = ''; |
|
| 915 | + } |
|
| 916 | + $parts = explode('.', (string)$gmt_offset); |
|
| 917 | + if (count($parts) === 1) { |
|
| 918 | + $parts[1] = '00'; |
|
| 919 | + } else { |
|
| 920 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 921 | + //to minutes, eg 30 or 15, respectively |
|
| 922 | + $hour_fraction = (float)('0.' . $parts[1]); |
|
| 923 | + $parts[1] = (string)$hour_fraction * 60; |
|
| 924 | + } |
|
| 925 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 932 | + * for a month using a string like "February" or "February 2017", |
|
| 933 | + * and you don't specify a day as part of your string, |
|
| 934 | + * then PHP will use whatever the current day of the month is. |
|
| 935 | + * IF the current day of the month happens to be the 30th or 31st, |
|
| 936 | + * then PHP gets really confused by a date like February 30, |
|
| 937 | + * so instead of saying |
|
| 938 | + * "Hey February only has 28 days (this year)... |
|
| 939 | + * ...you must have meant the last day of the month!" |
|
| 940 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 941 | + * because someone requesting February 30th obviously meant March 1st! |
|
| 942 | + * The way around this is to always set the day to the first, |
|
| 943 | + * so that the month will stay on the month you wanted. |
|
| 944 | + * this method will add that "1" into your date regardless of the format. |
|
| 945 | + * |
|
| 946 | + * @param string $month |
|
| 947 | + * @return string |
|
| 948 | + */ |
|
| 949 | + public static function first_of_month_timestamp($month = '') |
|
| 950 | + { |
|
| 951 | + $month = (string)$month; |
|
| 952 | + $year = ''; |
|
| 953 | + // check if the incoming string has a year in it or not |
|
| 954 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 955 | + $year = $matches[0]; |
|
| 956 | + // ten remove that from the month string as well as any spaces |
|
| 957 | + $month = trim(str_replace($year, '', $month)); |
|
| 958 | + // add a space before the year |
|
| 959 | + $year = " {$year}"; |
|
| 960 | + } |
|
| 961 | + // return timestamp for something like "February 1 2017" |
|
| 962 | + return strtotime("{$month} 1{$year}"); |
|
| 963 | + } |
|
| 964 | 964 | |
| 965 | 965 | |
| 966 | 966 | }// end class EEH_DTT_Helper |
| 967 | 967 | \ No newline at end of file |
@@ -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( |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | $offset = get_option('gmt_offset'); |
| 138 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 138 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
| 150 | 150 | { |
| 151 | 151 | //make sure $gmt_offset is int |
| 152 | - $gmt_offset = (int)$gmt_offset; |
|
| 152 | + $gmt_offset = (int) $gmt_offset; |
|
| 153 | 153 | switch ($gmt_offset) { |
| 154 | 154 | |
| 155 | 155 | // case -30600 : |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | public static function timezone_select_input($timezone_string = '') |
| 234 | 234 | { |
| 235 | 235 | // get WP date time format |
| 236 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 236 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 237 | 237 | // if passed a value, then use that, else get WP option |
| 238 | 238 | $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
| 239 | 239 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | // Create a UTC+- zone if no timezone string exists |
| 246 | 246 | $check_zone_info = false; |
| 247 | 247 | if ($gmt_offset > 0) { |
| 248 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 248 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 249 | 249 | } elseif ($gmt_offset < 0) { |
| 250 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 250 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 251 | 251 | } else { |
| 252 | 252 | $timezone_string = 'UTC'; |
| 253 | 253 | } |
@@ -269,11 +269,11 @@ discard block |
||
| 269 | 269 | __('%1$sUTC%2$s time is %3$s'), |
| 270 | 270 | '<abbr title="Coordinated Universal Time">', |
| 271 | 271 | '</abbr>', |
| 272 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 272 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 273 | 273 | ); |
| 274 | 274 | ?></span> |
| 275 | - <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 276 | - <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
| 275 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 276 | + <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 277 | 277 | <?php endif; ?> |
| 278 | 278 | |
| 279 | 279 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -306,11 +306,10 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | if ($found) { |
| 308 | 308 | $message = $tr['isdst'] ? |
| 309 | - __(' Daylight saving time begins on: %s.') : |
|
| 310 | - __(' Standard time begins on: %s.'); |
|
| 309 | + __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.'); |
|
| 311 | 310 | // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
| 312 | 311 | printf($message, |
| 313 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 312 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
| 314 | 313 | } else { |
| 315 | 314 | _e('This timezone does not observe daylight saving time.'); |
| 316 | 315 | } |
@@ -338,13 +337,13 @@ discard block |
||
| 338 | 337 | */ |
| 339 | 338 | public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
| 340 | 339 | { |
| 341 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 340 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 342 | 341 | $timezone_string = self::get_valid_timezone_string($timezone_string); |
| 343 | 342 | $TimeZone = new DateTimeZone($timezone_string); |
| 344 | 343 | |
| 345 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 344 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 346 | 345 | $offset = timezone_offset_get($TimeZone, $DateTime); |
| 347 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 346 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 348 | 347 | } |
| 349 | 348 | |
| 350 | 349 | |
@@ -427,7 +426,7 @@ discard block |
||
| 427 | 426 | */ |
| 428 | 427 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 429 | 428 | { |
| 430 | - if (! $DateTime instanceof DateTime) { |
|
| 429 | + if ( ! $DateTime instanceof DateTime) { |
|
| 431 | 430 | throw new EE_Error( |
| 432 | 431 | sprintf( |
| 433 | 432 | __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -437,25 +436,25 @@ discard block |
||
| 437 | 436 | } |
| 438 | 437 | switch ($period) { |
| 439 | 438 | case 'years' : |
| 440 | - $value = 'P' . $value . 'Y'; |
|
| 439 | + $value = 'P'.$value.'Y'; |
|
| 441 | 440 | break; |
| 442 | 441 | case 'months' : |
| 443 | - $value = 'P' . $value . 'M'; |
|
| 442 | + $value = 'P'.$value.'M'; |
|
| 444 | 443 | break; |
| 445 | 444 | case 'weeks' : |
| 446 | - $value = 'P' . $value . 'W'; |
|
| 445 | + $value = 'P'.$value.'W'; |
|
| 447 | 446 | break; |
| 448 | 447 | case 'days' : |
| 449 | - $value = 'P' . $value . 'D'; |
|
| 448 | + $value = 'P'.$value.'D'; |
|
| 450 | 449 | break; |
| 451 | 450 | case 'hours' : |
| 452 | - $value = 'PT' . $value . 'H'; |
|
| 451 | + $value = 'PT'.$value.'H'; |
|
| 453 | 452 | break; |
| 454 | 453 | case 'minutes' : |
| 455 | - $value = 'PT' . $value . 'M'; |
|
| 454 | + $value = 'PT'.$value.'M'; |
|
| 456 | 455 | break; |
| 457 | 456 | case 'seconds' : |
| 458 | - $value = 'PT' . $value . 'S'; |
|
| 457 | + $value = 'PT'.$value.'S'; |
|
| 459 | 458 | break; |
| 460 | 459 | } |
| 461 | 460 | switch ($operand) { |
@@ -483,7 +482,7 @@ discard block |
||
| 483 | 482 | */ |
| 484 | 483 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 485 | 484 | { |
| 486 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 485 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 487 | 486 | throw new EE_Error( |
| 488 | 487 | sprintf( |
| 489 | 488 | __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -587,7 +586,7 @@ discard block |
||
| 587 | 586 | 'date' => $date_format['js'], |
| 588 | 587 | 'time' => $time_format['js'], |
| 589 | 588 | ), |
| 590 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 589 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 591 | 590 | ); |
| 592 | 591 | } |
| 593 | 592 | |
@@ -606,7 +605,7 @@ discard block |
||
| 606 | 605 | * |
| 607 | 606 | * @var array |
| 608 | 607 | */ |
| 609 | - $symbols_map = array( |
|
| 608 | + $symbols_map = array( |
|
| 610 | 609 | // Day |
| 611 | 610 | //01 |
| 612 | 611 | 'd' => array( |
@@ -764,7 +763,7 @@ discard block |
||
| 764 | 763 | $jquery_ui_format .= $format_string[$i]; |
| 765 | 764 | $moment_format .= $format_string[$i]; |
| 766 | 765 | } else { |
| 767 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 766 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 768 | 767 | $moment_format .= $format_string[$i]; |
| 769 | 768 | } |
| 770 | 769 | $escaping = true; |
@@ -834,7 +833,7 @@ discard block |
||
| 834 | 833 | { |
| 835 | 834 | |
| 836 | 835 | if ( |
| 837 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 836 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 838 | 837 | ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
| 839 | 838 | ) { |
| 840 | 839 | return false; |
@@ -866,8 +865,8 @@ discard block |
||
| 866 | 865 | */ |
| 867 | 866 | $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
| 868 | 867 | $query_interval = $offset < 0 |
| 869 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 870 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 868 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 869 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 871 | 870 | return $query_interval; |
| 872 | 871 | } |
| 873 | 872 | |
@@ -883,16 +882,16 @@ discard block |
||
| 883 | 882 | public static function get_timezone_string_for_display() |
| 884 | 883 | { |
| 885 | 884 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 886 | - if (! empty($pretty_timezone)) { |
|
| 885 | + if ( ! empty($pretty_timezone)) { |
|
| 887 | 886 | return esc_html($pretty_timezone); |
| 888 | 887 | } |
| 889 | 888 | $timezone_string = get_option('timezone_string'); |
| 890 | 889 | if ($timezone_string) { |
| 891 | 890 | static $mo_loaded = false; |
| 892 | 891 | // Load translations for continents and cities just like wp_timezone_choice does |
| 893 | - if (! $mo_loaded) { |
|
| 892 | + if ( ! $mo_loaded) { |
|
| 894 | 893 | $locale = get_locale(); |
| 895 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 894 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 896 | 895 | load_textdomain('continents-cities', $mofile); |
| 897 | 896 | $mo_loaded = true; |
| 898 | 897 | } |
@@ -913,16 +912,16 @@ discard block |
||
| 913 | 912 | } else { |
| 914 | 913 | $prefix = ''; |
| 915 | 914 | } |
| 916 | - $parts = explode('.', (string)$gmt_offset); |
|
| 915 | + $parts = explode('.', (string) $gmt_offset); |
|
| 917 | 916 | if (count($parts) === 1) { |
| 918 | 917 | $parts[1] = '00'; |
| 919 | 918 | } else { |
| 920 | 919 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 921 | 920 | //to minutes, eg 30 or 15, respectively |
| 922 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 923 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 921 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 922 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 924 | 923 | } |
| 925 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 924 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 926 | 925 | } |
| 927 | 926 | |
| 928 | 927 | |
@@ -948,7 +947,7 @@ discard block |
||
| 948 | 947 | */ |
| 949 | 948 | public static function first_of_month_timestamp($month = '') |
| 950 | 949 | { |
| 951 | - $month = (string)$month; |
|
| 950 | + $month = (string) $month; |
|
| 952 | 951 | $year = ''; |
| 953 | 952 | // check if the incoming string has a year in it or not |
| 954 | 953 | if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @return EED_Events_Archive_Filters |
| 30 | 30 | */ |
| 31 | 31 | public static function instance() { |
| 32 | - return parent::get_instance( __CLASS__ ); |
|
| 32 | + return parent::get_instance(__CLASS__); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * @var $_types |
| 72 | 72 | * @access protected |
| 73 | 73 | */ |
| 74 | - protected static $_types = array( 'grid', 'text', 'dates' ); |
|
| 74 | + protected static $_types = array('grid', 'text', 'dates'); |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | // public static $espresso_event_list_ID = 0; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @access public |
| 126 | 126 | * @return void |
| 127 | 127 | */ |
| 128 | - public function run( $WP ) { |
|
| 128 | + public function run($WP) { |
|
| 129 | 129 | // do_action( 'AHEE__EED_Events_Archive_Filters__before_run' ); |
| 130 | 130 | // // set config |
| 131 | 131 | // if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) { |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | private function _filter_query_parts() { |
| 172 | 172 | // build event list query |
| 173 | - add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 ); |
|
| 174 | - add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 ); |
|
| 175 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 ); |
|
| 173 | + add_filter('posts_join', array($this, 'posts_join'), 1, 2); |
|
| 174 | + add_filter('posts_where', array($this, 'posts_where'), 1, 2); |
|
| 175 | + add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | 184 | public static function set_type() { |
| 185 | - do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' ); |
|
| 186 | - EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types ); |
|
| 187 | - $view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid'; |
|
| 188 | - $elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : ''; |
|
| 189 | - $view = ! empty( $elf_type ) ? $elf_type : $view; |
|
| 190 | - $view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view ); |
|
| 191 | - if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) { |
|
| 185 | + do_action('AHEE__EED_Events_Archive_Filters__before_set_type'); |
|
| 186 | + EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types); |
|
| 187 | + $view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid'; |
|
| 188 | + $elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : ''; |
|
| 189 | + $view = ! empty($elf_type) ? $elf_type : $view; |
|
| 190 | + $view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view); |
|
| 191 | + if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) { |
|
| 192 | 192 | self::$_type = $view; |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | * @param boolean $req_only if TRUE, then ignore defaults and only return $_POST value |
| 201 | 201 | * @return boolean |
| 202 | 202 | */ |
| 203 | - private static function _show_expired( $req_only = FALSE ) { |
|
| 203 | + private static function _show_expired($req_only = FALSE) { |
|
| 204 | 204 | // get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings |
| 205 | - $show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE; |
|
| 205 | + $show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE; |
|
| 206 | 206 | // override default expired option if set via filter |
| 207 | - $show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired; |
|
| 207 | + $show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired; |
|
| 208 | 208 | return $show_expired ? TRUE : FALSE; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return string |
| 216 | 216 | */ |
| 217 | 217 | private static function _event_category_slug() { |
| 218 | - return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : ''; |
|
| 218 | + return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : ''; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | 227 | private static function _display_month() { |
| 228 | - return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : ''; |
|
| 228 | + return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : ''; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | public function get_post_data() { |
| 240 | 240 | $this->_elf_month = EED_Events_Archive_Filters::_display_month(); |
| 241 | 241 | $this->_elf_category = EED_Events_Archive_Filters::_event_category_slug(); |
| 242 | - $this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE ); |
|
| 242 | + $this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE); |
|
| 243 | 243 | // EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 244 | 244 | // echo '<h4>$this->_elf_month : ' . $this->_elf_month . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
| 245 | 245 | // echo '<h4>$this->_elf_category : ' . $this->_elf_category . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
@@ -256,11 +256,11 @@ discard block |
||
| 256 | 256 | * @access public |
| 257 | 257 | * @return void |
| 258 | 258 | */ |
| 259 | - public function posts_join( $SQL, WP_Query $wp_query ) { |
|
| 260 | - if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) { |
|
| 259 | + public function posts_join($SQL, WP_Query $wp_query) { |
|
| 260 | + if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') { |
|
| 261 | 261 | // Category |
| 262 | 262 | // $elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : ''; |
| 263 | - $SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() ); |
|
| 263 | + $SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug()); |
|
| 264 | 264 | } |
| 265 | 265 | return $SQL; |
| 266 | 266 | } |
@@ -273,9 +273,9 @@ discard block |
||
| 273 | 273 | * @param mixed boolean|string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet |
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | - public static function posts_join_sql_for_terms( $join_terms = NULL ) { |
|
| 277 | - $SQL= ''; |
|
| 278 | - if ( ! empty( $join_terms )) { |
|
| 276 | + public static function posts_join_sql_for_terms($join_terms = NULL) { |
|
| 277 | + $SQL = ''; |
|
| 278 | + if ( ! empty($join_terms)) { |
|
| 279 | 279 | global $wpdb; |
| 280 | 280 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
| 281 | 281 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -293,28 +293,28 @@ discard block |
||
| 293 | 293 | * @param array $orderby_params |
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | - public static function posts_join_for_orderby( $orderby_params = array() ) { |
|
| 296 | + public static function posts_join_for_orderby($orderby_params = array()) { |
|
| 297 | 297 | global $wpdb; |
| 298 | - $SQL= ''; |
|
| 299 | - $orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params ); |
|
| 300 | - foreach( $orderby_params as $orderby ) { |
|
| 301 | - switch ( $orderby ) { |
|
| 298 | + $SQL = ''; |
|
| 299 | + $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); |
|
| 300 | + foreach ($orderby_params as $orderby) { |
|
| 301 | + switch ($orderby) { |
|
| 302 | 302 | |
| 303 | 303 | case 'ticket_start' : |
| 304 | 304 | case 'ticket_end' : |
| 305 | - $SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )'; |
|
| 306 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )'; |
|
| 305 | + $SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )'; |
|
| 306 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )'; |
|
| 307 | 307 | break; |
| 308 | 308 | |
| 309 | 309 | case 'venue_title' : |
| 310 | 310 | case 'city' : |
| 311 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )'; |
|
| 312 | - $SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )'; |
|
| 311 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )'; |
|
| 312 | + $SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )'; |
|
| 313 | 313 | break; |
| 314 | 314 | |
| 315 | 315 | case 'state' : |
| 316 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )'; |
|
| 317 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )'; |
|
| 316 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )'; |
|
| 317 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )'; |
|
| 318 | 318 | break; |
| 319 | 319 | |
| 320 | 320 | break; |
@@ -331,16 +331,16 @@ discard block |
||
| 331 | 331 | * @access public |
| 332 | 332 | * @return void |
| 333 | 333 | */ |
| 334 | - public function posts_where( $SQL, WP_Query $wp_query ) { |
|
| 335 | - if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events' ) { |
|
| 334 | + public function posts_where($SQL, WP_Query $wp_query) { |
|
| 335 | + if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') { |
|
| 336 | 336 | // Show Expired ? |
| 337 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() ); |
|
| 337 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired()); |
|
| 338 | 338 | // Category |
| 339 | 339 | //$elf_category = EED_Events_Archive_Filters::_event_category_slug(); |
| 340 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() ); |
|
| 340 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug()); |
|
| 341 | 341 | // Start Date |
| 342 | 342 | //$elf_month = EED_Events_Archive_Filters::_display_month(); |
| 343 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() ); |
|
| 343 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month()); |
|
| 344 | 344 | } |
| 345 | 345 | return $SQL; |
| 346 | 346 | } |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | * @param boolean $show_expired if TRUE, then displayed past events |
| 354 | 354 | * @return string |
| 355 | 355 | */ |
| 356 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
| 357 | - return ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : ''; |
|
| 356 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
| 357 | + return ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : ''; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | |
@@ -365,9 +365,9 @@ discard block |
||
| 365 | 365 | * @param boolean $event_category_slug |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
| 368 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
| 369 | 369 | global $wpdb; |
| 370 | - return ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : ''; |
|
| 370 | + return ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : ''; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -377,15 +377,15 @@ discard block |
||
| 377 | 377 | * @param boolean $month |
| 378 | 378 | * @return string |
| 379 | 379 | */ |
| 380 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
| 381 | - $SQL= ''; |
|
| 382 | - if ( ! empty( $month )) { |
|
| 380 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
| 381 | + $SQL = ''; |
|
| 382 | + if ( ! empty($month)) { |
|
| 383 | 383 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
| 384 | - $SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start'; |
|
| 385 | - $SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"'; |
|
| 384 | + $SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start'; |
|
| 385 | + $SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"'; |
|
| 386 | 386 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
| 387 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end'; |
|
| 388 | - $SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" '; |
|
| 387 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end'; |
|
| 388 | + $SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" '; |
|
| 389 | 389 | } |
| 390 | 390 | return $SQL; |
| 391 | 391 | } |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | * @access public |
| 398 | 398 | * @return void |
| 399 | 399 | */ |
| 400 | - public function posts_orderby( $SQL, WP_Query $wp_query ) { |
|
| 401 | - if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) { |
|
| 402 | - $SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' )); |
|
| 400 | + public function posts_orderby($SQL, WP_Query $wp_query) { |
|
| 401 | + if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') { |
|
| 402 | + $SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date')); |
|
| 403 | 403 | } |
| 404 | 404 | return $SQL; |
| 405 | 405 | } |
@@ -428,54 +428,54 @@ discard block |
||
| 428 | 428 | * @param boolean $orderby_params |
| 429 | 429 | * @return string |
| 430 | 430 | */ |
| 431 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
| 431 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
| 432 | 432 | global $wpdb; |
| 433 | 433 | $SQL = ''; |
| 434 | 434 | $cntr = 1; |
| 435 | - $orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params ); |
|
| 436 | - foreach( $orderby_params as $orderby ) { |
|
| 437 | - $glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', '; |
|
| 438 | - switch ( $orderby ) { |
|
| 435 | + $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); |
|
| 436 | + foreach ($orderby_params as $orderby) { |
|
| 437 | + $glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', '; |
|
| 438 | + switch ($orderby) { |
|
| 439 | 439 | |
| 440 | 440 | case 'id' : |
| 441 | 441 | case 'ID' : |
| 442 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
| 442 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
| 443 | 443 | break; |
| 444 | 444 | |
| 445 | 445 | case 'start_date' : |
| 446 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort; |
|
| 446 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort; |
|
| 447 | 447 | break; |
| 448 | 448 | |
| 449 | 449 | case 'end_date' : |
| 450 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
| 450 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
| 451 | 451 | break; |
| 452 | 452 | |
| 453 | 453 | case 'event_name' : |
| 454 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
| 454 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
| 455 | 455 | break; |
| 456 | 456 | |
| 457 | 457 | case 'category_slug' : |
| 458 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
| 458 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
| 459 | 459 | break; |
| 460 | 460 | |
| 461 | 461 | case 'ticket_start' : |
| 462 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
| 462 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
| 463 | 463 | break; |
| 464 | 464 | |
| 465 | 465 | case 'ticket_end' : |
| 466 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
| 466 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
| 467 | 467 | break; |
| 468 | 468 | |
| 469 | 469 | case 'venue_title' : |
| 470 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
| 470 | + $SQL .= $glue.'venue_title '.$sort; |
|
| 471 | 471 | break; |
| 472 | 472 | |
| 473 | 473 | case 'city' : |
| 474 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
| 474 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
| 475 | 475 | break; |
| 476 | 476 | |
| 477 | 477 | case 'state' : |
| 478 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
| 478 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
| 479 | 479 | break; |
| 480 | 480 | |
| 481 | 481 | } |
@@ -495,26 +495,26 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | public function template_redirect() { |
| 497 | 497 | // add event list filters |
| 498 | - add_action( 'loop_start', array( $this, 'event_list_template_filters' )); |
|
| 498 | + add_action('loop_start', array($this, 'event_list_template_filters')); |
|
| 499 | 499 | // and pagination |
| 500 | - add_action( 'loop_start', array( $this, 'event_list_pagination' )); |
|
| 501 | - add_action( 'loop_end', array( $this, 'event_list_pagination' )); |
|
| 500 | + add_action('loop_start', array($this, 'event_list_pagination')); |
|
| 501 | + add_action('loop_end', array($this, 'event_list_pagination')); |
|
| 502 | 502 | // if NOT a custom template |
| 503 | - if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) { |
|
| 503 | + if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') { |
|
| 504 | 504 | // don't know if theme uses the_excerpt |
| 505 | - add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 ); |
|
| 506 | - add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 ); |
|
| 507 | - add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 ); |
|
| 508 | - add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 ); |
|
| 505 | + add_filter('the_excerpt', array($this, 'event_details'), 100); |
|
| 506 | + add_filter('the_excerpt', array($this, 'event_tickets'), 110); |
|
| 507 | + add_filter('the_excerpt', array($this, 'event_datetimes'), 120); |
|
| 508 | + add_filter('the_excerpt', array($this, 'event_venues'), 130); |
|
| 509 | 509 | // or the_content |
| 510 | - add_filter( 'the_content', array( $this, 'event_details' ), 100 ); |
|
| 511 | - add_filter( 'the_content', array( $this, 'event_tickets' ), 110 ); |
|
| 512 | - add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 ); |
|
| 513 | - add_filter( 'the_content', array( $this, 'event_venues' ), 130 ); |
|
| 510 | + add_filter('the_content', array($this, 'event_details'), 100); |
|
| 511 | + add_filter('the_content', array($this, 'event_tickets'), 110); |
|
| 512 | + add_filter('the_content', array($this, 'event_datetimes'), 120); |
|
| 513 | + add_filter('the_content', array($this, 'event_venues'), 130); |
|
| 514 | 514 | } else { |
| 515 | - remove_all_filters( 'excerpt_length' ); |
|
| 516 | - add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 ); |
|
| 517 | - add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 ); |
|
| 515 | + remove_all_filters('excerpt_length'); |
|
| 516 | + add_filter('excerpt_length', array($this, 'excerpt_length'), 10); |
|
| 517 | + add_filter('excerpt_more', array($this, 'excerpt_more'), 10); |
|
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | * @return void |
| 528 | 528 | */ |
| 529 | 529 | public function event_list_pagination() { |
| 530 | - echo '<div class="ee-pagination-dv clear">' . espresso_event_list_pagination() . '</div>'; |
|
| 530 | + echo '<div class="ee-pagination-dv clear">'.espresso_event_list_pagination().'</div>'; |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | |
@@ -538,8 +538,8 @@ discard block |
||
| 538 | 538 | * @param string $content |
| 539 | 539 | * @return void |
| 540 | 540 | */ |
| 541 | - public function event_details( $content ) { |
|
| 542 | - return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE ); |
|
| 541 | + public function event_details($content) { |
|
| 542 | + return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -550,8 +550,8 @@ discard block |
||
| 550 | 550 | * @param string $content |
| 551 | 551 | * @return void |
| 552 | 552 | */ |
| 553 | - public function event_tickets( $content ) { |
|
| 554 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE ); |
|
| 553 | + public function event_tickets($content) { |
|
| 554 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
| 561 | 561 | * @param string $content |
| 562 | 562 | * @return void |
| 563 | 563 | */ |
| 564 | - public function event_datetimes( $content ) { |
|
| 565 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE ); |
|
| 564 | + public function event_datetimes($content) { |
|
| 565 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
| 572 | 572 | * @param string $content |
| 573 | 573 | * @return void |
| 574 | 574 | */ |
| 575 | - public function event_venues( $content ) { |
|
| 576 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE ); |
|
| 575 | + public function event_venues($content) { |
|
| 576 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
@@ -588,12 +588,12 @@ discard block |
||
| 588 | 588 | * @return void |
| 589 | 589 | */ |
| 590 | 590 | private function _load_assests() { |
| 591 | - do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' ); |
|
| 592 | - add_filter( 'FHEE_load_css', '__return_true' ); |
|
| 593 | - add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
| 594 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
| 595 | - if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
|
| 596 | - add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
|
| 591 | + do_action('AHEE__EED_Events_Archive_Filters__before_load_assests'); |
|
| 592 | + add_filter('FHEE_load_css', '__return_true'); |
|
| 593 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
| 594 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
| 595 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
| 596 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
| 597 | 597 | } |
| 598 | 598 | //add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 ); |
| 599 | 599 | } |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | * @access private |
| 609 | 609 | * @return string |
| 610 | 610 | */ |
| 611 | - private function _get_template( $which = 'part' ) { |
|
| 612 | - return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'; |
|
| 611 | + private function _get_template($which = 'part') { |
|
| 612 | + return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'; |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | |
@@ -620,13 +620,13 @@ discard block |
||
| 620 | 620 | * @access public |
| 621 | 621 | * @return void |
| 622 | 622 | */ |
| 623 | - public function excerpt_length( $length ) { |
|
| 623 | + public function excerpt_length($length) { |
|
| 624 | 624 | |
| 625 | - if ( self::$_type == 'grid' ) { |
|
| 625 | + if (self::$_type == 'grid') { |
|
| 626 | 626 | return 36; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) { |
|
| 629 | + switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) { |
|
| 630 | 630 | case 'tiny' : |
| 631 | 631 | return 12; |
| 632 | 632 | break; |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * @access public |
| 651 | 651 | * @return void |
| 652 | 652 | */ |
| 653 | - public function excerpt_more( $more ) { |
|
| 653 | + public function excerpt_more($more) { |
|
| 654 | 654 | return '…'; |
| 655 | 655 | } |
| 656 | 656 | |
@@ -680,22 +680,22 @@ discard block |
||
| 680 | 680 | */ |
| 681 | 681 | public function wp_enqueue_scripts() { |
| 682 | 682 | // get some style |
| 683 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) { |
|
| 683 | + if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) { |
|
| 684 | 684 | // first check uploads folder |
| 685 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) { |
|
| 686 | - wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' )); |
|
| 685 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) { |
|
| 686 | + wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default')); |
|
| 687 | 687 | } else { |
| 688 | - wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' )); |
|
| 688 | + wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default')); |
|
| 689 | 689 | } |
| 690 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) { |
|
| 691 | - wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE ); |
|
| 690 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) { |
|
| 691 | + wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE); |
|
| 692 | 692 | } else { |
| 693 | - wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE ); |
|
| 693 | + wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE); |
|
| 694 | 694 | } |
| 695 | - wp_enqueue_style( 'archive-espresso_events' ); |
|
| 696 | - wp_enqueue_script( 'jquery-masonry' ); |
|
| 697 | - wp_enqueue_script( 'archive-espresso_events' ); |
|
| 698 | - add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 ); |
|
| 695 | + wp_enqueue_style('archive-espresso_events'); |
|
| 696 | + wp_enqueue_script('jquery-masonry'); |
|
| 697 | + wp_enqueue_script('archive-espresso_events'); |
|
| 698 | + add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1); |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | * @return void |
| 711 | 711 | */ |
| 712 | 712 | public static function localize_grid_event_lists() { |
| 713 | - wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists ); |
|
| 713 | + wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | */ |
| 726 | 726 | public static function template_settings_form() { |
| 727 | 727 | $EE = EE_Registry::instance(); |
| 728 | - $EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config(); |
|
| 729 | - $EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters ); |
|
| 730 | - EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters ); |
|
| 728 | + $EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config(); |
|
| 729 | + $EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters); |
|
| 730 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | |
@@ -741,16 +741,16 @@ discard block |
||
| 741 | 741 | * @static |
| 742 | 742 | * @return void |
| 743 | 743 | */ |
| 744 | - public static function set_default_settings( $CFG ) { |
|
| 744 | + public static function set_default_settings($CFG) { |
|
| 745 | 745 | //EEH_Debug_Tools::printr( $CFG, '$CFG <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 746 | - $CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1; |
|
| 747 | - $CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE; |
|
| 748 | - $CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE; |
|
| 749 | - $CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE; |
|
| 750 | - $CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid'; |
|
| 751 | - $CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium'; |
|
| 752 | - $CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'; |
|
| 753 | - $CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php'; |
|
| 746 | + $CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1; |
|
| 747 | + $CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE; |
|
| 748 | + $CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE; |
|
| 749 | + $CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE; |
|
| 750 | + $CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid'; |
|
| 751 | + $CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium'; |
|
| 752 | + $CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'; |
|
| 753 | + $CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php'; |
|
| 754 | 754 | return $CFG; |
| 755 | 755 | } |
| 756 | 756 | |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | * @access public |
| 763 | 763 | * @return void |
| 764 | 764 | */ |
| 765 | - public function filter_config( $CFG ) { |
|
| 765 | + public function filter_config($CFG) { |
|
| 766 | 766 | return $CFG; |
| 767 | 767 | } |
| 768 | 768 | |
@@ -775,32 +775,32 @@ discard block |
||
| 775 | 775 | * @access public |
| 776 | 776 | * @return void |
| 777 | 777 | */ |
| 778 | - public static function update_template_settings( $CFG, $REQ ) { |
|
| 778 | + public static function update_template_settings($CFG, $REQ) { |
|
| 779 | 779 | // EEH_Debug_Tools::printr( $REQ, '$REQ <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 780 | 780 | // EEH_Debug_Tools::printr( $CFG, '$CFG <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 781 | 781 | //$CFG->template_settings->EED_Events_Archive_Filters = new stdClass(); |
| 782 | - $CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1; |
|
| 783 | - $CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE; |
|
| 784 | - $CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE; |
|
| 785 | - $CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE; |
|
| 786 | - $CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid'; |
|
| 787 | - $CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium'; |
|
| 782 | + $CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1; |
|
| 783 | + $CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE; |
|
| 784 | + $CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE; |
|
| 785 | + $CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE; |
|
| 786 | + $CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid'; |
|
| 787 | + $CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium'; |
|
| 788 | 788 | $CFG->EED_Events_Archive_Filters->templates = array( |
| 789 | - 'full' => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php' |
|
| 789 | + 'full' => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php' |
|
| 790 | 790 | ); |
| 791 | 791 | |
| 792 | - switch ( $CFG->EED_Events_Archive_Filters->default_type ) { |
|
| 792 | + switch ($CFG->EED_Events_Archive_Filters->default_type) { |
|
| 793 | 793 | case 'dates' : |
| 794 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php'; |
|
| 794 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php'; |
|
| 795 | 795 | break; |
| 796 | 796 | case 'text' : |
| 797 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php'; |
|
| 797 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php'; |
|
| 798 | 798 | break; |
| 799 | 799 | default : |
| 800 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php'; |
|
| 800 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php'; |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - $CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters; |
|
| 803 | + $CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters; |
|
| 804 | 804 | return $CFG; |
| 805 | 805 | } |
| 806 | 806 | |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | * @return void |
| 816 | 816 | */ |
| 817 | 817 | public static function get_template_part() { |
| 818 | - switch ( self::$_type ) { |
|
| 818 | + switch (self::$_type) { |
|
| 819 | 819 | case 'dates' : |
| 820 | 820 | return 'archive-espresso_events-dates-view.php'; |
| 821 | 821 | break; |
@@ -839,13 +839,13 @@ discard block |
||
| 839 | 839 | */ |
| 840 | 840 | public function event_list_template_filters() { |
| 841 | 841 | $args = array( |
| 842 | - 'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ), |
|
| 842 | + 'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ), |
|
| 843 | 843 | 'elf_month' => EED_Events_Archive_Filters::_display_month(), |
| 844 | 844 | 'elf_category' => EED_Events_Archive_Filters::_event_category_slug(), |
| 845 | 845 | 'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(), |
| 846 | 846 | 'elf_type' => self::$_type |
| 847 | 847 | ); |
| 848 | - EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args ); |
|
| 848 | + EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | |
@@ -858,16 +858,16 @@ discard block |
||
| 858 | 858 | * @access public |
| 859 | 859 | * @return void |
| 860 | 860 | */ |
| 861 | - public static function event_list_css( $extra_class = '' ) { |
|
| 861 | + public static function event_list_css($extra_class = '') { |
|
| 862 | 862 | $EE = EE_Registry::instance(); |
| 863 | - $event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array(); |
|
| 863 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
| 864 | 864 | $event_list_css[] = 'espresso-event-list-event'; |
| 865 | - if ( self::$_type == 'grid' ) { |
|
| 866 | - $event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium'; |
|
| 867 | - $event_list_css[] = $event_list_grid_size . '-event-list-grid'; |
|
| 865 | + if (self::$_type == 'grid') { |
|
| 866 | + $event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium'; |
|
| 867 | + $event_list_css[] = $event_list_grid_size.'-event-list-grid'; |
|
| 868 | 868 | } |
| 869 | - $event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css ); |
|
| 870 | - return implode( ' ', $event_list_css ); |
|
| 869 | + $event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css); |
|
| 870 | + return implode(' ', $event_list_css); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | |
@@ -893,9 +893,9 @@ discard block |
||
| 893 | 893 | * @access public |
| 894 | 894 | * @return void |
| 895 | 895 | */ |
| 896 | - public static function display_description( $value ) { |
|
| 896 | + public static function display_description($value) { |
|
| 897 | 897 | $EE = EE_Registry::instance(); |
| 898 | - $display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1; |
|
| 898 | + $display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1; |
|
| 899 | 899 | return $display_description === $value ? TRUE : FALSE; |
| 900 | 900 | } |
| 901 | 901 | |
@@ -909,9 +909,9 @@ discard block |
||
| 909 | 909 | */ |
| 910 | 910 | public static function display_venue_details() { |
| 911 | 911 | $EE = EE_Registry::instance(); |
| 912 | - $display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE; |
|
| 912 | + $display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE; |
|
| 913 | 913 | $venue_name = EEH_Venue_View::venue_name(); |
| 914 | - return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE; |
|
| 914 | + return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE; |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | |
@@ -923,9 +923,9 @@ discard block |
||
| 923 | 923 | */ |
| 924 | 924 | public static function display_address() { |
| 925 | 925 | $EE = EE_Registry::instance(); |
| 926 | - $display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE; |
|
| 926 | + $display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE; |
|
| 927 | 927 | $venue_name = EEH_Venue_View::venue_name(); |
| 928 | - return $display_address && ! empty( $venue_name ) ? TRUE : FALSE; |
|
| 928 | + return $display_address && ! empty($venue_name) ? TRUE : FALSE; |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | |
@@ -939,22 +939,22 @@ discard block |
||
| 939 | 939 | public static function pagination() { |
| 940 | 940 | global $wp_query; |
| 941 | 941 | $big = 999999999; // need an unlikely integer |
| 942 | - $pagination = paginate_links( array( |
|
| 943 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 942 | + $pagination = paginate_links(array( |
|
| 943 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 944 | 944 | 'format' => '?paged=%#%', |
| 945 | - 'current' => max( 1, get_query_var('paged') ), |
|
| 945 | + 'current' => max(1, get_query_var('paged')), |
|
| 946 | 946 | 'total' => $wp_query->max_num_pages, |
| 947 | 947 | 'show_all' => TRUE, |
| 948 | 948 | 'end_size' => 10, |
| 949 | 949 | 'mid_size' => 6, |
| 950 | 950 | 'prev_next' => TRUE, |
| 951 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
| 952 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
| 951 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
| 952 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
| 953 | 953 | 'type' => 'plain', |
| 954 | 954 | 'add_args' => FALSE, |
| 955 | 955 | 'add_fragment' => '' |
| 956 | 956 | )); |
| 957 | - return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
| 957 | + return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : ''; |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | * @return void |
| 969 | 969 | */ |
| 970 | 970 | public static function event_list_title() { |
| 971 | - return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' )); |
|
| 971 | + return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso')); |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | |
@@ -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 | |
@@ -17,2576 +17,2576 @@ discard block |
||
| 17 | 17 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This will hold the event object for event_details screen. |
|
| 22 | - * |
|
| 23 | - * @access protected |
|
| 24 | - * @var EE_Event $_event |
|
| 25 | - */ |
|
| 26 | - protected $_event; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This will hold the category object for category_details screen. |
|
| 31 | - * |
|
| 32 | - * @var stdClass $_category |
|
| 33 | - */ |
|
| 34 | - protected $_category; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * This will hold the event model instance |
|
| 39 | - * |
|
| 40 | - * @var EEM_Event $_event_model |
|
| 41 | - */ |
|
| 42 | - protected $_event_model; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Event |
|
| 48 | - */ |
|
| 49 | - protected $_cpt_model_obj = false; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - protected function _init_page_props() |
|
| 54 | - { |
|
| 55 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | - $this->page_label = EVENTS_LABEL; |
|
| 57 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | - $this->_cpt_model_names = array( |
|
| 60 | - 'create_new' => 'EEM_Event', |
|
| 61 | - 'edit' => 'EEM_Event', |
|
| 62 | - ); |
|
| 63 | - $this->_cpt_edit_routes = array( |
|
| 64 | - 'espresso_events' => 'edit', |
|
| 65 | - ); |
|
| 66 | - add_action( |
|
| 67 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | - array($this, 'verify_event_edit') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - protected function _ajax_hooks() |
|
| 75 | - { |
|
| 76 | - //todo: all hooks for events ajax goes in here. |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - protected function _define_page_props() |
|
| 82 | - { |
|
| 83 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | - $this->_labels = array( |
|
| 85 | - 'buttons' => array( |
|
| 86 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | - ), |
|
| 93 | - 'editor_title' => array( |
|
| 94 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | - ), |
|
| 96 | - 'publishbox' => array( |
|
| 97 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | - ), |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - protected function _set_page_routes() |
|
| 109 | - { |
|
| 110 | - //load formatter helper |
|
| 111 | - //load field generator helper |
|
| 112 | - //is there a evt_id in the request? |
|
| 113 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | - ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | - $this->_page_routes = array( |
|
| 117 | - 'default' => array( |
|
| 118 | - 'func' => '_events_overview_list_table', |
|
| 119 | - 'capability' => 'ee_read_events', |
|
| 120 | - ), |
|
| 121 | - 'create_new' => array( |
|
| 122 | - 'func' => '_create_new_cpt_item', |
|
| 123 | - 'capability' => 'ee_edit_events', |
|
| 124 | - ), |
|
| 125 | - 'edit' => array( |
|
| 126 | - 'func' => '_edit_cpt_item', |
|
| 127 | - 'capability' => 'ee_edit_event', |
|
| 128 | - 'obj_id' => $evt_id, |
|
| 129 | - ), |
|
| 130 | - 'copy_event' => array( |
|
| 131 | - 'func' => '_copy_events', |
|
| 132 | - 'capability' => 'ee_edit_event', |
|
| 133 | - 'obj_id' => $evt_id, |
|
| 134 | - 'noheader' => true, |
|
| 135 | - ), |
|
| 136 | - 'trash_event' => array( |
|
| 137 | - 'func' => '_trash_or_restore_event', |
|
| 138 | - 'args' => array('event_status' => 'trash'), |
|
| 139 | - 'capability' => 'ee_delete_event', |
|
| 140 | - 'obj_id' => $evt_id, |
|
| 141 | - 'noheader' => true, |
|
| 142 | - ), |
|
| 143 | - 'trash_events' => array( |
|
| 144 | - 'func' => '_trash_or_restore_events', |
|
| 145 | - 'args' => array('event_status' => 'trash'), |
|
| 146 | - 'capability' => 'ee_delete_events', |
|
| 147 | - 'noheader' => true, |
|
| 148 | - ), |
|
| 149 | - 'restore_event' => array( |
|
| 150 | - 'func' => '_trash_or_restore_event', |
|
| 151 | - 'args' => array('event_status' => 'draft'), |
|
| 152 | - 'capability' => 'ee_delete_event', |
|
| 153 | - 'obj_id' => $evt_id, |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ), |
|
| 156 | - 'restore_events' => array( |
|
| 157 | - 'func' => '_trash_or_restore_events', |
|
| 158 | - 'args' => array('event_status' => 'draft'), |
|
| 159 | - 'capability' => 'ee_delete_events', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ), |
|
| 162 | - 'delete_event' => array( |
|
| 163 | - 'func' => '_delete_event', |
|
| 164 | - 'capability' => 'ee_delete_event', |
|
| 165 | - 'obj_id' => $evt_id, |
|
| 166 | - 'noheader' => true, |
|
| 167 | - ), |
|
| 168 | - 'delete_events' => array( |
|
| 169 | - 'func' => '_delete_events', |
|
| 170 | - 'capability' => 'ee_delete_events', |
|
| 171 | - 'noheader' => true, |
|
| 172 | - ), |
|
| 173 | - 'view_report' => array( |
|
| 174 | - 'func' => '_view_report', |
|
| 175 | - 'capablity' => 'ee_edit_events', |
|
| 176 | - ), |
|
| 177 | - 'default_event_settings' => array( |
|
| 178 | - 'func' => '_default_event_settings', |
|
| 179 | - 'capability' => 'manage_options', |
|
| 180 | - ), |
|
| 181 | - 'update_default_event_settings' => array( |
|
| 182 | - 'func' => '_update_default_event_settings', |
|
| 183 | - 'capability' => 'manage_options', |
|
| 184 | - 'noheader' => true, |
|
| 185 | - ), |
|
| 186 | - 'template_settings' => array( |
|
| 187 | - 'func' => '_template_settings', |
|
| 188 | - 'capability' => 'manage_options', |
|
| 189 | - ), |
|
| 190 | - //event category tab related |
|
| 191 | - 'add_category' => array( |
|
| 192 | - 'func' => '_category_details', |
|
| 193 | - 'capability' => 'ee_edit_event_category', |
|
| 194 | - 'args' => array('add'), |
|
| 195 | - ), |
|
| 196 | - 'edit_category' => array( |
|
| 197 | - 'func' => '_category_details', |
|
| 198 | - 'capability' => 'ee_edit_event_category', |
|
| 199 | - 'args' => array('edit'), |
|
| 200 | - ), |
|
| 201 | - 'delete_categories' => array( |
|
| 202 | - 'func' => '_delete_categories', |
|
| 203 | - 'capability' => 'ee_delete_event_category', |
|
| 204 | - 'noheader' => true, |
|
| 205 | - ), |
|
| 206 | - 'delete_category' => array( |
|
| 207 | - 'func' => '_delete_categories', |
|
| 208 | - 'capability' => 'ee_delete_event_category', |
|
| 209 | - 'noheader' => true, |
|
| 210 | - ), |
|
| 211 | - 'insert_category' => array( |
|
| 212 | - 'func' => '_insert_or_update_category', |
|
| 213 | - 'args' => array('new_category' => true), |
|
| 214 | - 'capability' => 'ee_edit_event_category', |
|
| 215 | - 'noheader' => true, |
|
| 216 | - ), |
|
| 217 | - 'update_category' => array( |
|
| 218 | - 'func' => '_insert_or_update_category', |
|
| 219 | - 'args' => array('new_category' => false), |
|
| 220 | - 'capability' => 'ee_edit_event_category', |
|
| 221 | - 'noheader' => true, |
|
| 222 | - ), |
|
| 223 | - 'category_list' => array( |
|
| 224 | - 'func' => '_category_list_table', |
|
| 225 | - 'capability' => 'ee_manage_event_categories', |
|
| 226 | - ), |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - protected function _set_page_config() |
|
| 233 | - { |
|
| 234 | - $this->_page_config = array( |
|
| 235 | - 'default' => array( |
|
| 236 | - 'nav' => array( |
|
| 237 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | - 'order' => 10, |
|
| 239 | - ), |
|
| 240 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | - 'help_tabs' => array( |
|
| 242 | - 'events_overview_help_tab' => array( |
|
| 243 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | - 'filename' => 'events_overview', |
|
| 245 | - ), |
|
| 246 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | - 'filename' => 'events_overview_table_column_headings', |
|
| 249 | - ), |
|
| 250 | - 'events_overview_filters_help_tab' => array( |
|
| 251 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | - 'filename' => 'events_overview_filters', |
|
| 253 | - ), |
|
| 254 | - 'events_overview_view_help_tab' => array( |
|
| 255 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | - 'filename' => 'events_overview_views', |
|
| 257 | - ), |
|
| 258 | - 'events_overview_other_help_tab' => array( |
|
| 259 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | - 'filename' => 'events_overview_other', |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - 'help_tour' => array( |
|
| 264 | - 'Event_Overview_Help_Tour', |
|
| 265 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | - ), |
|
| 267 | - 'qtips' => array( |
|
| 268 | - 'EE_Event_List_Table_Tips', |
|
| 269 | - ), |
|
| 270 | - 'require_nonce' => false, |
|
| 271 | - ), |
|
| 272 | - 'create_new' => array( |
|
| 273 | - 'nav' => array( |
|
| 274 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | - 'order' => 5, |
|
| 276 | - 'persistent' => false, |
|
| 277 | - ), |
|
| 278 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | - 'help_tabs' => array( |
|
| 280 | - 'event_editor_help_tab' => array( |
|
| 281 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | - 'filename' => 'event_editor', |
|
| 283 | - ), |
|
| 284 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | - ), |
|
| 288 | - 'event_editor_venue_details_help_tab' => array( |
|
| 289 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | - 'filename' => 'event_editor_venue_details', |
|
| 291 | - ), |
|
| 292 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | - 'filename' => 'event_editor_event_datetimes', |
|
| 295 | - ), |
|
| 296 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | - 'filename' => 'event_editor_event_tickets', |
|
| 299 | - ), |
|
| 300 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | - 'filename' => 'event_editor_event_registration_options', |
|
| 303 | - ), |
|
| 304 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | - 'filename' => 'event_editor_tags_categories', |
|
| 307 | - ), |
|
| 308 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | - 'filename' => 'event_editor_questions_registrants', |
|
| 311 | - ), |
|
| 312 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | - 'filename' => 'event_editor_save_new_event', |
|
| 315 | - ), |
|
| 316 | - 'event_editor_other_help_tab' => array( |
|
| 317 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | - 'filename' => 'event_editor_other', |
|
| 319 | - ), |
|
| 320 | - ), |
|
| 321 | - 'help_tour' => array( |
|
| 322 | - 'Event_Editor_Help_Tour', |
|
| 323 | - ), |
|
| 324 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | - 'require_nonce' => false, |
|
| 326 | - ), |
|
| 327 | - 'edit' => array( |
|
| 328 | - 'nav' => array( |
|
| 329 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | - 'order' => 5, |
|
| 331 | - 'persistent' => false, |
|
| 332 | - 'url' => isset($this->_req_data['post']) |
|
| 333 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | - $this->_current_page_view_url |
|
| 336 | - ) |
|
| 337 | - : $this->_admin_base_url, |
|
| 338 | - ), |
|
| 339 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | - 'help_tabs' => array( |
|
| 341 | - 'event_editor_help_tab' => array( |
|
| 342 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | - 'filename' => 'event_editor', |
|
| 344 | - ), |
|
| 345 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | - ), |
|
| 349 | - 'event_editor_venue_details_help_tab' => array( |
|
| 350 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | - 'filename' => 'event_editor_venue_details', |
|
| 352 | - ), |
|
| 353 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | - 'filename' => 'event_editor_event_datetimes', |
|
| 356 | - ), |
|
| 357 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | - 'filename' => 'event_editor_event_tickets', |
|
| 360 | - ), |
|
| 361 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | - 'filename' => 'event_editor_event_registration_options', |
|
| 364 | - ), |
|
| 365 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | - 'filename' => 'event_editor_tags_categories', |
|
| 368 | - ), |
|
| 369 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | - 'filename' => 'event_editor_questions_registrants', |
|
| 372 | - ), |
|
| 373 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | - 'filename' => 'event_editor_save_new_event', |
|
| 376 | - ), |
|
| 377 | - 'event_editor_other_help_tab' => array( |
|
| 378 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | - 'filename' => 'event_editor_other', |
|
| 380 | - ), |
|
| 381 | - ), |
|
| 382 | - /*'help_tour' => array( |
|
| 20 | + /** |
|
| 21 | + * This will hold the event object for event_details screen. |
|
| 22 | + * |
|
| 23 | + * @access protected |
|
| 24 | + * @var EE_Event $_event |
|
| 25 | + */ |
|
| 26 | + protected $_event; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This will hold the category object for category_details screen. |
|
| 31 | + * |
|
| 32 | + * @var stdClass $_category |
|
| 33 | + */ |
|
| 34 | + protected $_category; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * This will hold the event model instance |
|
| 39 | + * |
|
| 40 | + * @var EEM_Event $_event_model |
|
| 41 | + */ |
|
| 42 | + protected $_event_model; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Event |
|
| 48 | + */ |
|
| 49 | + protected $_cpt_model_obj = false; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + protected function _init_page_props() |
|
| 54 | + { |
|
| 55 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | + $this->page_label = EVENTS_LABEL; |
|
| 57 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | + $this->_cpt_model_names = array( |
|
| 60 | + 'create_new' => 'EEM_Event', |
|
| 61 | + 'edit' => 'EEM_Event', |
|
| 62 | + ); |
|
| 63 | + $this->_cpt_edit_routes = array( |
|
| 64 | + 'espresso_events' => 'edit', |
|
| 65 | + ); |
|
| 66 | + add_action( |
|
| 67 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | + array($this, 'verify_event_edit') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + protected function _ajax_hooks() |
|
| 75 | + { |
|
| 76 | + //todo: all hooks for events ajax goes in here. |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + protected function _define_page_props() |
|
| 82 | + { |
|
| 83 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | + $this->_labels = array( |
|
| 85 | + 'buttons' => array( |
|
| 86 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | + ), |
|
| 93 | + 'editor_title' => array( |
|
| 94 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | + ), |
|
| 96 | + 'publishbox' => array( |
|
| 97 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | + ), |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + protected function _set_page_routes() |
|
| 109 | + { |
|
| 110 | + //load formatter helper |
|
| 111 | + //load field generator helper |
|
| 112 | + //is there a evt_id in the request? |
|
| 113 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | + ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | + $this->_page_routes = array( |
|
| 117 | + 'default' => array( |
|
| 118 | + 'func' => '_events_overview_list_table', |
|
| 119 | + 'capability' => 'ee_read_events', |
|
| 120 | + ), |
|
| 121 | + 'create_new' => array( |
|
| 122 | + 'func' => '_create_new_cpt_item', |
|
| 123 | + 'capability' => 'ee_edit_events', |
|
| 124 | + ), |
|
| 125 | + 'edit' => array( |
|
| 126 | + 'func' => '_edit_cpt_item', |
|
| 127 | + 'capability' => 'ee_edit_event', |
|
| 128 | + 'obj_id' => $evt_id, |
|
| 129 | + ), |
|
| 130 | + 'copy_event' => array( |
|
| 131 | + 'func' => '_copy_events', |
|
| 132 | + 'capability' => 'ee_edit_event', |
|
| 133 | + 'obj_id' => $evt_id, |
|
| 134 | + 'noheader' => true, |
|
| 135 | + ), |
|
| 136 | + 'trash_event' => array( |
|
| 137 | + 'func' => '_trash_or_restore_event', |
|
| 138 | + 'args' => array('event_status' => 'trash'), |
|
| 139 | + 'capability' => 'ee_delete_event', |
|
| 140 | + 'obj_id' => $evt_id, |
|
| 141 | + 'noheader' => true, |
|
| 142 | + ), |
|
| 143 | + 'trash_events' => array( |
|
| 144 | + 'func' => '_trash_or_restore_events', |
|
| 145 | + 'args' => array('event_status' => 'trash'), |
|
| 146 | + 'capability' => 'ee_delete_events', |
|
| 147 | + 'noheader' => true, |
|
| 148 | + ), |
|
| 149 | + 'restore_event' => array( |
|
| 150 | + 'func' => '_trash_or_restore_event', |
|
| 151 | + 'args' => array('event_status' => 'draft'), |
|
| 152 | + 'capability' => 'ee_delete_event', |
|
| 153 | + 'obj_id' => $evt_id, |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ), |
|
| 156 | + 'restore_events' => array( |
|
| 157 | + 'func' => '_trash_or_restore_events', |
|
| 158 | + 'args' => array('event_status' => 'draft'), |
|
| 159 | + 'capability' => 'ee_delete_events', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ), |
|
| 162 | + 'delete_event' => array( |
|
| 163 | + 'func' => '_delete_event', |
|
| 164 | + 'capability' => 'ee_delete_event', |
|
| 165 | + 'obj_id' => $evt_id, |
|
| 166 | + 'noheader' => true, |
|
| 167 | + ), |
|
| 168 | + 'delete_events' => array( |
|
| 169 | + 'func' => '_delete_events', |
|
| 170 | + 'capability' => 'ee_delete_events', |
|
| 171 | + 'noheader' => true, |
|
| 172 | + ), |
|
| 173 | + 'view_report' => array( |
|
| 174 | + 'func' => '_view_report', |
|
| 175 | + 'capablity' => 'ee_edit_events', |
|
| 176 | + ), |
|
| 177 | + 'default_event_settings' => array( |
|
| 178 | + 'func' => '_default_event_settings', |
|
| 179 | + 'capability' => 'manage_options', |
|
| 180 | + ), |
|
| 181 | + 'update_default_event_settings' => array( |
|
| 182 | + 'func' => '_update_default_event_settings', |
|
| 183 | + 'capability' => 'manage_options', |
|
| 184 | + 'noheader' => true, |
|
| 185 | + ), |
|
| 186 | + 'template_settings' => array( |
|
| 187 | + 'func' => '_template_settings', |
|
| 188 | + 'capability' => 'manage_options', |
|
| 189 | + ), |
|
| 190 | + //event category tab related |
|
| 191 | + 'add_category' => array( |
|
| 192 | + 'func' => '_category_details', |
|
| 193 | + 'capability' => 'ee_edit_event_category', |
|
| 194 | + 'args' => array('add'), |
|
| 195 | + ), |
|
| 196 | + 'edit_category' => array( |
|
| 197 | + 'func' => '_category_details', |
|
| 198 | + 'capability' => 'ee_edit_event_category', |
|
| 199 | + 'args' => array('edit'), |
|
| 200 | + ), |
|
| 201 | + 'delete_categories' => array( |
|
| 202 | + 'func' => '_delete_categories', |
|
| 203 | + 'capability' => 'ee_delete_event_category', |
|
| 204 | + 'noheader' => true, |
|
| 205 | + ), |
|
| 206 | + 'delete_category' => array( |
|
| 207 | + 'func' => '_delete_categories', |
|
| 208 | + 'capability' => 'ee_delete_event_category', |
|
| 209 | + 'noheader' => true, |
|
| 210 | + ), |
|
| 211 | + 'insert_category' => array( |
|
| 212 | + 'func' => '_insert_or_update_category', |
|
| 213 | + 'args' => array('new_category' => true), |
|
| 214 | + 'capability' => 'ee_edit_event_category', |
|
| 215 | + 'noheader' => true, |
|
| 216 | + ), |
|
| 217 | + 'update_category' => array( |
|
| 218 | + 'func' => '_insert_or_update_category', |
|
| 219 | + 'args' => array('new_category' => false), |
|
| 220 | + 'capability' => 'ee_edit_event_category', |
|
| 221 | + 'noheader' => true, |
|
| 222 | + ), |
|
| 223 | + 'category_list' => array( |
|
| 224 | + 'func' => '_category_list_table', |
|
| 225 | + 'capability' => 'ee_manage_event_categories', |
|
| 226 | + ), |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + protected function _set_page_config() |
|
| 233 | + { |
|
| 234 | + $this->_page_config = array( |
|
| 235 | + 'default' => array( |
|
| 236 | + 'nav' => array( |
|
| 237 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | + 'order' => 10, |
|
| 239 | + ), |
|
| 240 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | + 'help_tabs' => array( |
|
| 242 | + 'events_overview_help_tab' => array( |
|
| 243 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | + 'filename' => 'events_overview', |
|
| 245 | + ), |
|
| 246 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | + 'filename' => 'events_overview_table_column_headings', |
|
| 249 | + ), |
|
| 250 | + 'events_overview_filters_help_tab' => array( |
|
| 251 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | + 'filename' => 'events_overview_filters', |
|
| 253 | + ), |
|
| 254 | + 'events_overview_view_help_tab' => array( |
|
| 255 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | + 'filename' => 'events_overview_views', |
|
| 257 | + ), |
|
| 258 | + 'events_overview_other_help_tab' => array( |
|
| 259 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | + 'filename' => 'events_overview_other', |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + 'help_tour' => array( |
|
| 264 | + 'Event_Overview_Help_Tour', |
|
| 265 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | + ), |
|
| 267 | + 'qtips' => array( |
|
| 268 | + 'EE_Event_List_Table_Tips', |
|
| 269 | + ), |
|
| 270 | + 'require_nonce' => false, |
|
| 271 | + ), |
|
| 272 | + 'create_new' => array( |
|
| 273 | + 'nav' => array( |
|
| 274 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | + 'order' => 5, |
|
| 276 | + 'persistent' => false, |
|
| 277 | + ), |
|
| 278 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | + 'help_tabs' => array( |
|
| 280 | + 'event_editor_help_tab' => array( |
|
| 281 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | + 'filename' => 'event_editor', |
|
| 283 | + ), |
|
| 284 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | + ), |
|
| 288 | + 'event_editor_venue_details_help_tab' => array( |
|
| 289 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | + 'filename' => 'event_editor_venue_details', |
|
| 291 | + ), |
|
| 292 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | + 'filename' => 'event_editor_event_datetimes', |
|
| 295 | + ), |
|
| 296 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | + 'filename' => 'event_editor_event_tickets', |
|
| 299 | + ), |
|
| 300 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | + 'filename' => 'event_editor_event_registration_options', |
|
| 303 | + ), |
|
| 304 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | + 'filename' => 'event_editor_tags_categories', |
|
| 307 | + ), |
|
| 308 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | + 'filename' => 'event_editor_questions_registrants', |
|
| 311 | + ), |
|
| 312 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | + 'filename' => 'event_editor_save_new_event', |
|
| 315 | + ), |
|
| 316 | + 'event_editor_other_help_tab' => array( |
|
| 317 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | + 'filename' => 'event_editor_other', |
|
| 319 | + ), |
|
| 320 | + ), |
|
| 321 | + 'help_tour' => array( |
|
| 322 | + 'Event_Editor_Help_Tour', |
|
| 323 | + ), |
|
| 324 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | + 'require_nonce' => false, |
|
| 326 | + ), |
|
| 327 | + 'edit' => array( |
|
| 328 | + 'nav' => array( |
|
| 329 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | + 'order' => 5, |
|
| 331 | + 'persistent' => false, |
|
| 332 | + 'url' => isset($this->_req_data['post']) |
|
| 333 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | + $this->_current_page_view_url |
|
| 336 | + ) |
|
| 337 | + : $this->_admin_base_url, |
|
| 338 | + ), |
|
| 339 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | + 'help_tabs' => array( |
|
| 341 | + 'event_editor_help_tab' => array( |
|
| 342 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | + 'filename' => 'event_editor', |
|
| 344 | + ), |
|
| 345 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | + ), |
|
| 349 | + 'event_editor_venue_details_help_tab' => array( |
|
| 350 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | + 'filename' => 'event_editor_venue_details', |
|
| 352 | + ), |
|
| 353 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | + 'filename' => 'event_editor_event_datetimes', |
|
| 356 | + ), |
|
| 357 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | + 'filename' => 'event_editor_event_tickets', |
|
| 360 | + ), |
|
| 361 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | + 'filename' => 'event_editor_event_registration_options', |
|
| 364 | + ), |
|
| 365 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | + 'filename' => 'event_editor_tags_categories', |
|
| 368 | + ), |
|
| 369 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | + 'filename' => 'event_editor_questions_registrants', |
|
| 372 | + ), |
|
| 373 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | + 'filename' => 'event_editor_save_new_event', |
|
| 376 | + ), |
|
| 377 | + 'event_editor_other_help_tab' => array( |
|
| 378 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | + 'filename' => 'event_editor_other', |
|
| 380 | + ), |
|
| 381 | + ), |
|
| 382 | + /*'help_tour' => array( |
|
| 383 | 383 | 'Event_Edit_Help_Tour' |
| 384 | 384 | ),*/ |
| 385 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | - 'require_nonce' => false, |
|
| 387 | - ), |
|
| 388 | - 'default_event_settings' => array( |
|
| 389 | - 'nav' => array( |
|
| 390 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | - 'order' => 40, |
|
| 392 | - ), |
|
| 393 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | - 'labels' => array( |
|
| 395 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | - ), |
|
| 397 | - 'help_tabs' => array( |
|
| 398 | - 'default_settings_help_tab' => array( |
|
| 399 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | - 'filename' => 'events_default_settings', |
|
| 401 | - ), |
|
| 402 | - 'default_settings_status_help_tab' => array( |
|
| 403 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | - 'filename' => 'events_default_settings_status', |
|
| 405 | - ), |
|
| 406 | - ), |
|
| 407 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 408 | - 'require_nonce' => false, |
|
| 409 | - ), |
|
| 410 | - //template settings |
|
| 411 | - 'template_settings' => array( |
|
| 412 | - 'nav' => array( |
|
| 413 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 414 | - 'order' => 30, |
|
| 415 | - ), |
|
| 416 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 417 | - 'help_tabs' => array( |
|
| 418 | - 'general_settings_templates_help_tab' => array( |
|
| 419 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 420 | - 'filename' => 'general_settings_templates', |
|
| 421 | - ), |
|
| 422 | - ), |
|
| 423 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 424 | - 'require_nonce' => false, |
|
| 425 | - ), |
|
| 426 | - //event category stuff |
|
| 427 | - 'add_category' => array( |
|
| 428 | - 'nav' => array( |
|
| 429 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 430 | - 'order' => 15, |
|
| 431 | - 'persistent' => false, |
|
| 432 | - ), |
|
| 433 | - 'help_tabs' => array( |
|
| 434 | - 'add_category_help_tab' => array( |
|
| 435 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 436 | - 'filename' => 'events_add_category', |
|
| 437 | - ), |
|
| 438 | - ), |
|
| 439 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 440 | - 'metaboxes' => array('_publish_post_box'), |
|
| 441 | - 'require_nonce' => false, |
|
| 442 | - ), |
|
| 443 | - 'edit_category' => array( |
|
| 444 | - 'nav' => array( |
|
| 445 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 446 | - 'order' => 15, |
|
| 447 | - 'persistent' => false, |
|
| 448 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 449 | - ? add_query_arg( |
|
| 450 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 451 | - $this->_current_page_view_url |
|
| 452 | - ) |
|
| 453 | - : $this->_admin_base_url, |
|
| 454 | - ), |
|
| 455 | - 'help_tabs' => array( |
|
| 456 | - 'edit_category_help_tab' => array( |
|
| 457 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 458 | - 'filename' => 'events_edit_category', |
|
| 459 | - ), |
|
| 460 | - ), |
|
| 461 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 462 | - 'metaboxes' => array('_publish_post_box'), |
|
| 463 | - 'require_nonce' => false, |
|
| 464 | - ), |
|
| 465 | - 'category_list' => array( |
|
| 466 | - 'nav' => array( |
|
| 467 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 468 | - 'order' => 20, |
|
| 469 | - ), |
|
| 470 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 471 | - 'help_tabs' => array( |
|
| 472 | - 'events_categories_help_tab' => array( |
|
| 473 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 474 | - 'filename' => 'events_categories', |
|
| 475 | - ), |
|
| 476 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 477 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 478 | - 'filename' => 'events_categories_table_column_headings', |
|
| 479 | - ), |
|
| 480 | - 'events_categories_view_help_tab' => array( |
|
| 481 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 482 | - 'filename' => 'events_categories_views', |
|
| 483 | - ), |
|
| 484 | - 'events_categories_other_help_tab' => array( |
|
| 485 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 486 | - 'filename' => 'events_categories_other', |
|
| 487 | - ), |
|
| 488 | - ), |
|
| 489 | - 'help_tour' => array( |
|
| 490 | - 'Event_Categories_Help_Tour', |
|
| 491 | - ), |
|
| 492 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 493 | - 'require_nonce' => false, |
|
| 494 | - ), |
|
| 495 | - ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - protected function _add_screen_options() |
|
| 501 | - { |
|
| 502 | - //todo |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - protected function _add_screen_options_default() |
|
| 508 | - { |
|
| 509 | - $this->_per_page_screen_option(); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - protected function _add_screen_options_category_list() |
|
| 515 | - { |
|
| 516 | - $page_title = $this->_admin_page_title; |
|
| 517 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 518 | - $this->_per_page_screen_option(); |
|
| 519 | - $this->_admin_page_title = $page_title; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - protected function _add_feature_pointers() |
|
| 525 | - { |
|
| 526 | - //todo |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - public function load_scripts_styles() |
|
| 532 | - { |
|
| 533 | - wp_register_style( |
|
| 534 | - 'events-admin-css', |
|
| 535 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 536 | - array(), |
|
| 537 | - EVENT_ESPRESSO_VERSION |
|
| 538 | - ); |
|
| 539 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 540 | - wp_enqueue_style('events-admin-css'); |
|
| 541 | - wp_enqueue_style('ee-cat-admin'); |
|
| 542 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 543 | - //registers for all views |
|
| 544 | - //scripts |
|
| 545 | - wp_register_script( |
|
| 546 | - 'event_editor_js', |
|
| 547 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 548 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 549 | - EVENT_ESPRESSO_VERSION, |
|
| 550 | - true |
|
| 551 | - ); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * enqueuing scripts and styles specific to this view |
|
| 558 | - * |
|
| 559 | - * @return void |
|
| 560 | - */ |
|
| 561 | - public function load_scripts_styles_create_new() |
|
| 562 | - { |
|
| 563 | - $this->load_scripts_styles_edit(); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * enqueuing scripts and styles specific to this view |
|
| 570 | - * |
|
| 571 | - * @return void |
|
| 572 | - */ |
|
| 573 | - public function load_scripts_styles_edit() |
|
| 574 | - { |
|
| 575 | - //styles |
|
| 576 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 577 | - wp_register_style( |
|
| 578 | - 'event-editor-css', |
|
| 579 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 580 | - array('ee-admin-css'), |
|
| 581 | - EVENT_ESPRESSO_VERSION |
|
| 582 | - ); |
|
| 583 | - wp_enqueue_style('event-editor-css'); |
|
| 584 | - //scripts |
|
| 585 | - wp_register_script( |
|
| 586 | - 'event-datetime-metabox', |
|
| 587 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 588 | - array('event_editor_js', 'ee-datepicker'), |
|
| 589 | - EVENT_ESPRESSO_VERSION |
|
| 590 | - ); |
|
| 591 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - public function load_scripts_styles_add_category() |
|
| 597 | - { |
|
| 598 | - $this->load_scripts_styles_edit_category(); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - public function load_scripts_styles_edit_category() |
|
| 604 | - { |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - protected function _set_list_table_views_category_list() |
|
| 610 | - { |
|
| 611 | - $this->_views = array( |
|
| 612 | - 'all' => array( |
|
| 613 | - 'slug' => 'all', |
|
| 614 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 615 | - 'count' => 0, |
|
| 616 | - 'bulk_action' => array( |
|
| 617 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 618 | - ), |
|
| 619 | - ), |
|
| 620 | - ); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - public function admin_init() |
|
| 626 | - { |
|
| 627 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 628 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 629 | - 'event_espresso' |
|
| 630 | - ); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - //nothing needed for events with these methods. |
|
| 636 | - public function admin_notices() |
|
| 637 | - { |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - public function admin_footer_scripts() |
|
| 643 | - { |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 650 | - * warning (via EE_Error::add_error()); |
|
| 651 | - * |
|
| 652 | - * @param EE_Event $event Event object |
|
| 653 | - * @access public |
|
| 654 | - * @return void |
|
| 655 | - */ |
|
| 656 | - public function verify_event_edit($event = null) |
|
| 657 | - { |
|
| 658 | - // no event? |
|
| 659 | - if (empty($event)) { |
|
| 660 | - // set event |
|
| 661 | - $event = $this->_cpt_model_obj; |
|
| 662 | - } |
|
| 663 | - // STILL no event? |
|
| 664 | - if (empty ($event)) { |
|
| 665 | - return; |
|
| 666 | - } |
|
| 667 | - $orig_status = $event->status(); |
|
| 668 | - // first check if event is active. |
|
| 669 | - if ( |
|
| 670 | - $orig_status === EEM_Event::cancelled |
|
| 671 | - || $orig_status === EEM_Event::postponed |
|
| 672 | - || $event->is_expired() |
|
| 673 | - || $event->is_inactive() |
|
| 674 | - ) { |
|
| 675 | - return; |
|
| 676 | - } |
|
| 677 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
| 678 | - if ($event->is_sold_out(true)) { |
|
| 679 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 680 | - EE_Error::add_attention( |
|
| 681 | - sprintf( |
|
| 682 | - esc_html__( |
|
| 683 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 684 | - 'event_espresso' |
|
| 685 | - ), |
|
| 686 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 687 | - ) |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - return; |
|
| 691 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
| 692 | - EE_Error::add_attention( |
|
| 693 | - sprintf( |
|
| 694 | - esc_html__( |
|
| 695 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 696 | - 'event_espresso' |
|
| 697 | - ), |
|
| 698 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 699 | - ) |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 703 | - if ( ! $event->tickets_on_sale()) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - //made it here so show warning |
|
| 707 | - $this->_edit_event_warning(); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 714 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 715 | - * |
|
| 716 | - * @access protected |
|
| 717 | - * @return void |
|
| 718 | - */ |
|
| 719 | - protected function _edit_event_warning() |
|
| 720 | - { |
|
| 721 | - // we don't want to add warnings during these requests |
|
| 722 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 723 | - return; |
|
| 724 | - } |
|
| 725 | - EE_Error::add_attention( |
|
| 726 | - esc_html__( |
|
| 727 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 728 | - 'event_espresso' |
|
| 729 | - ) |
|
| 730 | - ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 737 | - * Otherwise, do the normal logic |
|
| 738 | - * |
|
| 739 | - * @return string |
|
| 740 | - * @throws \EE_Error |
|
| 741 | - */ |
|
| 742 | - protected function _create_new_cpt_item() |
|
| 743 | - { |
|
| 744 | - $gmt_offset = get_option('gmt_offset'); |
|
| 745 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 746 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 747 | - EE_Error::add_attention( |
|
| 748 | - sprintf( |
|
| 749 | - __( |
|
| 750 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 751 | - 'event_espresso' |
|
| 752 | - ), |
|
| 753 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 754 | - '</a>' |
|
| 755 | - ), |
|
| 756 | - __FILE__, |
|
| 757 | - __FUNCTION__, |
|
| 758 | - __LINE__ |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - return parent::_create_new_cpt_item(); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - protected function _set_list_table_views_default() |
|
| 767 | - { |
|
| 768 | - $this->_views = array( |
|
| 769 | - 'all' => array( |
|
| 770 | - 'slug' => 'all', |
|
| 771 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 772 | - 'count' => 0, |
|
| 773 | - 'bulk_action' => array( |
|
| 774 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 775 | - ), |
|
| 776 | - ), |
|
| 777 | - 'draft' => array( |
|
| 778 | - 'slug' => 'draft', |
|
| 779 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 780 | - 'count' => 0, |
|
| 781 | - 'bulk_action' => array( |
|
| 782 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 783 | - ), |
|
| 784 | - ), |
|
| 785 | - ); |
|
| 786 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 787 | - $this->_views['trash'] = array( |
|
| 788 | - 'slug' => 'trash', |
|
| 789 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 790 | - 'count' => 0, |
|
| 791 | - 'bulk_action' => array( |
|
| 792 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 793 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 794 | - ), |
|
| 795 | - ); |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * @return array |
|
| 803 | - */ |
|
| 804 | - protected function _event_legend_items() |
|
| 805 | - { |
|
| 806 | - $items = array( |
|
| 807 | - 'view_details' => array( |
|
| 808 | - 'class' => 'dashicons dashicons-search', |
|
| 809 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 810 | - ), |
|
| 811 | - 'edit_event' => array( |
|
| 812 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 813 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 814 | - ), |
|
| 815 | - 'view_attendees' => array( |
|
| 816 | - 'class' => 'dashicons dashicons-groups', |
|
| 817 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 818 | - ), |
|
| 819 | - ); |
|
| 820 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 821 | - $statuses = array( |
|
| 822 | - 'sold_out_status' => array( |
|
| 823 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 824 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 825 | - ), |
|
| 826 | - 'active_status' => array( |
|
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 828 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 829 | - ), |
|
| 830 | - 'upcoming_status' => array( |
|
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 832 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 833 | - ), |
|
| 834 | - 'postponed_status' => array( |
|
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 836 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 837 | - ), |
|
| 838 | - 'cancelled_status' => array( |
|
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 840 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 841 | - ), |
|
| 842 | - 'expired_status' => array( |
|
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 844 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 845 | - ), |
|
| 846 | - 'inactive_status' => array( |
|
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 848 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 849 | - ), |
|
| 850 | - ); |
|
| 851 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 852 | - return array_merge($items, $statuses); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * _event_model |
|
| 859 | - * |
|
| 860 | - * @return EEM_Event |
|
| 861 | - */ |
|
| 862 | - private function _event_model() |
|
| 863 | - { |
|
| 864 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 865 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 866 | - } |
|
| 867 | - return $this->_event_model; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 874 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 875 | - * |
|
| 876 | - * @param string $return the current html |
|
| 877 | - * @param int $id the post id for the page |
|
| 878 | - * @param string $new_title What the title is |
|
| 879 | - * @param string $new_slug what the slug is |
|
| 880 | - * @return string The new html string for the permalink area |
|
| 881 | - */ |
|
| 882 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 883 | - { |
|
| 884 | - //make sure this is only when editing |
|
| 885 | - if ( ! empty($id)) { |
|
| 886 | - $post = get_post($id); |
|
| 887 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 888 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 889 | - . '</a> '; |
|
| 890 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 891 | - . $post->ID |
|
| 892 | - . ']">'; |
|
| 893 | - } |
|
| 894 | - return $return; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * _events_overview_list_table |
|
| 901 | - * This contains the logic for showing the events_overview list |
|
| 902 | - * |
|
| 903 | - * @access protected |
|
| 904 | - * @return void |
|
| 905 | - * @throws \EE_Error |
|
| 906 | - */ |
|
| 907 | - protected function _events_overview_list_table() |
|
| 908 | - { |
|
| 909 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 910 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 911 | - ? (array)$this->_template_args['after_list_table'] |
|
| 912 | - : array(); |
|
| 913 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 914 | - . EEH_Template::get_button_or_link( |
|
| 915 | - get_post_type_archive_link('espresso_events'), |
|
| 916 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 917 | - 'button' |
|
| 918 | - ); |
|
| 919 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 920 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 921 | - 'create_new', |
|
| 922 | - 'add', |
|
| 923 | - array(), |
|
| 924 | - 'add-new-h2' |
|
| 925 | - ); |
|
| 926 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * this allows for extra misc actions in the default WP publish box |
|
| 933 | - * |
|
| 934 | - * @return void |
|
| 935 | - */ |
|
| 936 | - public function extra_misc_actions_publish_box() |
|
| 937 | - { |
|
| 938 | - $this->_generate_publish_box_extra_content(); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 945 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 946 | - * data. |
|
| 947 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 948 | - * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 949 | - * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 950 | - * you handle this accordingly. |
|
| 951 | - * |
|
| 952 | - * @access protected |
|
| 953 | - * @abstract |
|
| 954 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 955 | - * @param object $post The post object of the cpt that was saved. |
|
| 956 | - * @return void |
|
| 957 | - */ |
|
| 958 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 959 | - { |
|
| 960 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 961 | - //get out we're not processing an event save. |
|
| 962 | - return; |
|
| 963 | - } |
|
| 964 | - $event_values = array( |
|
| 965 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 966 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 967 | - 'EVT_additional_limit' => min( |
|
| 968 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 969 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 970 | - ), |
|
| 971 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 972 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 973 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 974 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 975 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 976 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 977 | - ? $this->_req_data['timezone_string'] : null, |
|
| 978 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 979 | - ? $this->_req_data['externalURL'] : null, |
|
| 980 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 981 | - ? $this->_req_data['event_phone'] : null, |
|
| 982 | - ); |
|
| 983 | - //update event |
|
| 984 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 985 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 986 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 987 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 988 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 989 | - $event_update_callbacks = apply_filters( |
|
| 990 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 991 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 992 | - ); |
|
| 993 | - $att_success = true; |
|
| 994 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 995 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 996 | - $att_success = ! $att_success ? $att_success |
|
| 997 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 998 | - } |
|
| 999 | - //any errors? |
|
| 1000 | - if ($success && false === $att_success) { |
|
| 1001 | - EE_Error::add_error( |
|
| 1002 | - esc_html__( |
|
| 1003 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1004 | - 'event_espresso' |
|
| 1005 | - ), |
|
| 1006 | - __FILE__, |
|
| 1007 | - __FUNCTION__, |
|
| 1008 | - __LINE__ |
|
| 1009 | - ); |
|
| 1010 | - } else if ($success === false) { |
|
| 1011 | - EE_Error::add_error( |
|
| 1012 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1013 | - __FILE__, |
|
| 1014 | - __FUNCTION__, |
|
| 1015 | - __LINE__ |
|
| 1016 | - ); |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * @see parent::restore_item() |
|
| 1024 | - * @param int $post_id |
|
| 1025 | - * @param int $revision_id |
|
| 1026 | - */ |
|
| 1027 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1028 | - { |
|
| 1029 | - //copy existing event meta to new post |
|
| 1030 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1031 | - if ($post_evt instanceof EE_Event) { |
|
| 1032 | - //meta revision restore |
|
| 1033 | - $post_evt->restore_revision($revision_id); |
|
| 1034 | - //related objs restore |
|
| 1035 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1036 | - } |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Attach the venue to the Event |
|
| 1043 | - * |
|
| 1044 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1045 | - * @param array $data The request data from the form |
|
| 1046 | - * @return bool Success or fail. |
|
| 1047 | - */ |
|
| 1048 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1049 | - { |
|
| 1050 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1051 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1052 | - $rows_affected = null; |
|
| 1053 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1054 | - // very important. If we don't have a venue name... |
|
| 1055 | - // then we'll get out because not necessary to create empty venue |
|
| 1056 | - if (empty($data['venue_title'])) { |
|
| 1057 | - return false; |
|
| 1058 | - } |
|
| 1059 | - $venue_array = array( |
|
| 1060 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1061 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1062 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1063 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1064 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1065 | - : null, |
|
| 1066 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1067 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1068 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1069 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1070 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1071 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1072 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1073 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1074 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1075 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1076 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1077 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1078 | - 'status' => 'publish', |
|
| 1079 | - ); |
|
| 1080 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1081 | - if ( ! empty($venue_id)) { |
|
| 1082 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1083 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1084 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1085 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1086 | - return $rows_affected > 0 ? true : false; |
|
| 1087 | - } else { |
|
| 1088 | - //we insert the venue |
|
| 1089 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1090 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1091 | - return ! empty($venue_id) ? true : false; |
|
| 1092 | - } |
|
| 1093 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1100 | - * |
|
| 1101 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1102 | - * @param array $data The request data from the form |
|
| 1103 | - * @return array |
|
| 1104 | - */ |
|
| 1105 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1106 | - { |
|
| 1107 | - $success = true; |
|
| 1108 | - $saved_dtt = null; |
|
| 1109 | - $saved_tickets = array(); |
|
| 1110 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1111 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1112 | - //trim all values to ensure any excess whitespace is removed. |
|
| 1113 | - $dtt = array_map('trim', $dtt); |
|
| 1114 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1115 | - : $dtt['DTT_EVT_start']; |
|
| 1116 | - $datetime_values = array( |
|
| 1117 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1118 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1119 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1120 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1121 | - 'DTT_order' => $row, |
|
| 1122 | - ); |
|
| 1123 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1124 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 1125 | - $DTM = EE_Registry::instance() |
|
| 1126 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1127 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1128 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1129 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1130 | - foreach ($datetime_values as $field => $value) { |
|
| 1131 | - $DTM->set($field, $value); |
|
| 1132 | - } |
|
| 1133 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1134 | - $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1135 | - } else { |
|
| 1136 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1137 | - 'Datetime', |
|
| 1138 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1139 | - false, |
|
| 1140 | - false |
|
| 1141 | - ); |
|
| 1142 | - foreach ($datetime_values as $field => $value) { |
|
| 1143 | - $DTM->set($field, $value); |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - $DTM->save(); |
|
| 1147 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1148 | - //load DTT helper |
|
| 1149 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1150 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1151 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1152 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1153 | - $DTT->save(); |
|
| 1154 | - } |
|
| 1155 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1156 | - $saved_dtt = $DTT; |
|
| 1157 | - $success = ! $success ? $success : $DTT; |
|
| 1158 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1159 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1160 | - } |
|
| 1161 | - //no dtts get deleted so we don't do any of that logic here. |
|
| 1162 | - //update tickets next |
|
| 1163 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1164 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1165 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1166 | - $update_prices = false; |
|
| 1167 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1168 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1169 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1170 | - $tkt = array_map('trim', $tkt); |
|
| 1171 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1172 | - //let's use now in the set timezone. |
|
| 1173 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1174 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1175 | - } |
|
| 1176 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1177 | - //use the start date of the first datetime |
|
| 1178 | - $dtt = $evtobj->first_datetime(); |
|
| 1179 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1180 | - $incoming_date_formats[0], |
|
| 1181 | - $incoming_date_formats[1] |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - $TKT_values = array( |
|
| 1185 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1186 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1187 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1188 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1189 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1190 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1191 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1192 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1193 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1194 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1195 | - 'TKT_row' => $row, |
|
| 1196 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1197 | - 'TKT_price' => $ticket_price, |
|
| 1198 | - ); |
|
| 1199 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1200 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1201 | - $TKT_values['TKT_ID'] = 0; |
|
| 1202 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1203 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1204 | - $update_prices = true; |
|
| 1205 | - } |
|
| 1206 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1207 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1208 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1209 | - if ( ! empty($tkt['TKT_ID'])) { |
|
| 1210 | - $TKT = EE_Registry::instance() |
|
| 1211 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1212 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1213 | - if ($TKT instanceof EE_Ticket) { |
|
| 1214 | - $ticket_sold = $TKT->count_related( |
|
| 1215 | - 'Registration', |
|
| 1216 | - array( |
|
| 1217 | - array( |
|
| 1218 | - 'STS_ID' => array( |
|
| 1219 | - 'NOT IN', |
|
| 1220 | - array(EEM_Registration::status_id_incomplete), |
|
| 1221 | - ), |
|
| 1222 | - ), |
|
| 1223 | - ) |
|
| 1224 | - ) > 0 ? true : false; |
|
| 1225 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1226 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1227 | - && ! $TKT->get( |
|
| 1228 | - 'TKT_deleted' |
|
| 1229 | - ) ? true : false; |
|
| 1230 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1231 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1232 | - //set new values |
|
| 1233 | - foreach ($TKT_values as $field => $value) { |
|
| 1234 | - if ($field == 'TKT_qty') { |
|
| 1235 | - $TKT->set_qty($value); |
|
| 1236 | - } else { |
|
| 1237 | - $TKT->set($field, $value); |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1241 | - if ($create_new_TKT) { |
|
| 1242 | - //archive the old ticket first |
|
| 1243 | - $TKT->set('TKT_deleted', 1); |
|
| 1244 | - $TKT->save(); |
|
| 1245 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1246 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1247 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1248 | - $TKT = clone $TKT; |
|
| 1249 | - $TKT->set('TKT_ID', 0); |
|
| 1250 | - $TKT->set('TKT_deleted', 0); |
|
| 1251 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1252 | - $TKT->set('TKT_sold', 0); |
|
| 1253 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1254 | - $update_prices = true; |
|
| 1255 | - } |
|
| 1256 | - //make sure price is set if it hasn't been already |
|
| 1257 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1258 | - } |
|
| 1259 | - } else { |
|
| 1260 | - //no TKT_id so a new TKT |
|
| 1261 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1262 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1263 | - if ($TKT instanceof EE_Ticket) { |
|
| 1264 | - //need to reset values to properly account for the date formats |
|
| 1265 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1266 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1267 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1268 | - //set new values |
|
| 1269 | - foreach ($TKT_values as $field => $value) { |
|
| 1270 | - if ($field == 'TKT_qty') { |
|
| 1271 | - $TKT->set_qty($value); |
|
| 1272 | - } else { |
|
| 1273 | - $TKT->set($field, $value); |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - $update_prices = true; |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - // cap ticket qty by datetime reg limits |
|
| 1280 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1281 | - //update ticket. |
|
| 1282 | - $TKT->save(); |
|
| 1283 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1284 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1285 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1286 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1287 | - $TKT->save(); |
|
| 1288 | - } |
|
| 1289 | - //initially let's add the ticket to the dtt |
|
| 1290 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1291 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1292 | - //add prices to ticket |
|
| 1293 | - $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1294 | - } |
|
| 1295 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1296 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1297 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1298 | - foreach ($tickets_removed as $id) { |
|
| 1299 | - $id = absint($id); |
|
| 1300 | - //get the ticket for this id |
|
| 1301 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1302 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1303 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1304 | - foreach ($dtts as $dtt) { |
|
| 1305 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1306 | - } |
|
| 1307 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1308 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1309 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1310 | - $tkt_to_remove->delete_permanently(); |
|
| 1311 | - } |
|
| 1312 | - return array($saved_dtt, $saved_tickets); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * This attaches a list of given prices to a ticket. |
|
| 1319 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1320 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1321 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1322 | - * |
|
| 1323 | - * @access private |
|
| 1324 | - * @param array $prices Array of prices from the form. |
|
| 1325 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1326 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1327 | - * @return void |
|
| 1328 | - */ |
|
| 1329 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1330 | - { |
|
| 1331 | - foreach ($prices as $row => $prc) { |
|
| 1332 | - $PRC_values = array( |
|
| 1333 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1334 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1335 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1336 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1337 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1338 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1339 | - 'PRC_order' => $row, |
|
| 1340 | - ); |
|
| 1341 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1342 | - $PRC_values['PRC_ID'] = 0; |
|
| 1343 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1344 | - } else { |
|
| 1345 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1346 | - //update this price with new values |
|
| 1347 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1348 | - $PRC->set($field, $newprc); |
|
| 1349 | - } |
|
| 1350 | - $PRC->save(); |
|
| 1351 | - } |
|
| 1352 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1353 | - } |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - /** |
|
| 1359 | - * Add in our autosave ajax handlers |
|
| 1360 | - * |
|
| 1361 | - * @return void |
|
| 1362 | - */ |
|
| 1363 | - protected function _ee_autosave_create_new() |
|
| 1364 | - { |
|
| 1365 | - // $this->_ee_autosave_edit(); |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - |
|
| 1370 | - protected function _ee_autosave_edit() |
|
| 1371 | - { |
|
| 1372 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - /** |
|
| 1378 | - * _generate_publish_box_extra_content |
|
| 1379 | - * |
|
| 1380 | - * @access private |
|
| 1381 | - * @return void |
|
| 1382 | - */ |
|
| 1383 | - private function _generate_publish_box_extra_content() |
|
| 1384 | - { |
|
| 1385 | - //load formatter helper |
|
| 1386 | - //args for getting related registrations |
|
| 1387 | - $approved_query_args = array( |
|
| 1388 | - array( |
|
| 1389 | - 'REG_deleted' => 0, |
|
| 1390 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1391 | - ), |
|
| 1392 | - ); |
|
| 1393 | - $not_approved_query_args = array( |
|
| 1394 | - array( |
|
| 1395 | - 'REG_deleted' => 0, |
|
| 1396 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1397 | - ), |
|
| 1398 | - ); |
|
| 1399 | - $pending_payment_query_args = array( |
|
| 1400 | - array( |
|
| 1401 | - 'REG_deleted' => 0, |
|
| 1402 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1403 | - ), |
|
| 1404 | - ); |
|
| 1405 | - // publish box |
|
| 1406 | - $publish_box_extra_args = array( |
|
| 1407 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1408 | - array( |
|
| 1409 | - 'action' => 'default', |
|
| 1410 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1411 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1412 | - ), |
|
| 1413 | - REG_ADMIN_URL |
|
| 1414 | - ), |
|
| 1415 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1416 | - array( |
|
| 1417 | - 'action' => 'default', |
|
| 1418 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1419 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1420 | - ), |
|
| 1421 | - REG_ADMIN_URL |
|
| 1422 | - ), |
|
| 1423 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1424 | - array( |
|
| 1425 | - 'action' => 'default', |
|
| 1426 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1427 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1428 | - ), |
|
| 1429 | - REG_ADMIN_URL |
|
| 1430 | - ), |
|
| 1431 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1432 | - 'Registration', |
|
| 1433 | - $approved_query_args |
|
| 1434 | - ), |
|
| 1435 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | - 'Registration', |
|
| 1437 | - $not_approved_query_args |
|
| 1438 | - ), |
|
| 1439 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | - 'Registration', |
|
| 1441 | - $pending_payment_query_args |
|
| 1442 | - ), |
|
| 1443 | - 'misc_pub_section_class' => apply_filters( |
|
| 1444 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1445 | - 'misc-pub-section' |
|
| 1446 | - ), |
|
| 1447 | - //'email_attendees_url' => add_query_arg( |
|
| 1448 | - // array( |
|
| 1449 | - // 'event_admin_reports' => 'event_newsletter', |
|
| 1450 | - // 'event_id' => $this->_cpt_model_obj->id |
|
| 1451 | - // ), |
|
| 1452 | - // 'admin.php?page=espresso_registrations' |
|
| 1453 | - //), |
|
| 1454 | - ); |
|
| 1455 | - ob_start(); |
|
| 1456 | - do_action( |
|
| 1457 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1458 | - $this->_cpt_model_obj |
|
| 1459 | - ); |
|
| 1460 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1461 | - // load template |
|
| 1462 | - EEH_Template::display_template( |
|
| 1463 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1464 | - $publish_box_extra_args |
|
| 1465 | - ); |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * This just returns whatever is set as the _event object property |
|
| 1472 | - * //todo this will become obsolete once the models are in place |
|
| 1473 | - * |
|
| 1474 | - * @return object |
|
| 1475 | - */ |
|
| 1476 | - public function get_event_object() |
|
| 1477 | - { |
|
| 1478 | - return $this->_cpt_model_obj; |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - |
|
| 1482 | - |
|
| 1483 | - |
|
| 1484 | - /** METABOXES * */ |
|
| 1485 | - /** |
|
| 1486 | - * _register_event_editor_meta_boxes |
|
| 1487 | - * add all metaboxes related to the event_editor |
|
| 1488 | - * |
|
| 1489 | - * @return void |
|
| 1490 | - */ |
|
| 1491 | - protected function _register_event_editor_meta_boxes() |
|
| 1492 | - { |
|
| 1493 | - $this->verify_cpt_object(); |
|
| 1494 | - add_meta_box( |
|
| 1495 | - 'espresso_event_editor_tickets', |
|
| 1496 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1497 | - array($this, 'ticket_metabox'), |
|
| 1498 | - $this->page_slug, |
|
| 1499 | - 'normal', |
|
| 1500 | - 'high' |
|
| 1501 | - ); |
|
| 1502 | - add_meta_box( |
|
| 1503 | - 'espresso_event_editor_event_options', |
|
| 1504 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1505 | - array($this, 'registration_options_meta_box'), |
|
| 1506 | - $this->page_slug, |
|
| 1507 | - 'side', |
|
| 1508 | - 'default' |
|
| 1509 | - ); |
|
| 1510 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1511 | - // where a metabox has a related management page in the admin |
|
| 1512 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1513 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - |
|
| 1517 | - |
|
| 1518 | - public function ticket_metabox() |
|
| 1519 | - { |
|
| 1520 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1521 | - //defaults for template args |
|
| 1522 | - $template_args = array( |
|
| 1523 | - 'existing_datetime_ids' => '', |
|
| 1524 | - 'event_datetime_help_link' => '', |
|
| 1525 | - 'ticket_options_help_link' => '', |
|
| 1526 | - 'time' => null, |
|
| 1527 | - 'ticket_rows' => '', |
|
| 1528 | - 'existing_ticket_ids' => '', |
|
| 1529 | - 'total_ticket_rows' => 1, |
|
| 1530 | - 'ticket_js_structure' => '', |
|
| 1531 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1532 | - 'disabled' => '', |
|
| 1533 | - ); |
|
| 1534 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1535 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1536 | - /** |
|
| 1537 | - * 1. Start with retrieving Datetimes |
|
| 1538 | - * 2. Fore each datetime get related tickets |
|
| 1539 | - * 3. For each ticket get related prices |
|
| 1540 | - */ |
|
| 1541 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1542 | - /** @type EE_Datetime $first_datetime */ |
|
| 1543 | - $first_datetime = reset($times); |
|
| 1544 | - //do we get related tickets? |
|
| 1545 | - if ($first_datetime instanceof EE_Datetime |
|
| 1546 | - && $first_datetime->ID() !== 0 |
|
| 1547 | - ) { |
|
| 1548 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1549 | - $template_args['time'] = $first_datetime; |
|
| 1550 | - $related_tickets = $first_datetime->tickets( |
|
| 1551 | - array( |
|
| 1552 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1553 | - 'default_where_conditions' => 'none', |
|
| 1554 | - ) |
|
| 1555 | - ); |
|
| 1556 | - if ( ! empty($related_tickets)) { |
|
| 1557 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1558 | - $row = 0; |
|
| 1559 | - foreach ($related_tickets as $ticket) { |
|
| 1560 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1561 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1562 | - $row++; |
|
| 1563 | - } |
|
| 1564 | - } else { |
|
| 1565 | - $template_args['total_ticket_rows'] = 1; |
|
| 1566 | - /** @type EE_Ticket $ticket */ |
|
| 1567 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1568 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1569 | - } |
|
| 1570 | - } else { |
|
| 1571 | - $template_args['time'] = $times[0]; |
|
| 1572 | - /** @type EE_Ticket $ticket */ |
|
| 1573 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1574 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1575 | - // NOTE: we're just sending the first default row |
|
| 1576 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1577 | - } |
|
| 1578 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1579 | - 'event_editor_event_datetimes_help_tab' |
|
| 1580 | - ); |
|
| 1581 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1582 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1583 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1584 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1585 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1586 | - true |
|
| 1587 | - ); |
|
| 1588 | - $template = apply_filters( |
|
| 1589 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1590 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1591 | - ); |
|
| 1592 | - EEH_Template::display_template($template, $template_args); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1599 | - * |
|
| 1600 | - * @access private |
|
| 1601 | - * @param EE_Ticket $ticket the ticket object |
|
| 1602 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1603 | - * @param int $row |
|
| 1604 | - * @return string generated html for the ticket row. |
|
| 1605 | - */ |
|
| 1606 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1607 | - { |
|
| 1608 | - $template_args = array( |
|
| 1609 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1610 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1611 | - : '', |
|
| 1612 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1613 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1614 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1615 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1616 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1617 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1618 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1619 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1620 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1621 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1622 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1623 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1624 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1625 | - : ' disabled=disabled', |
|
| 1626 | - ); |
|
| 1627 | - $price = $ticket->ID() !== 0 |
|
| 1628 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1629 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1630 | - $price_args = array( |
|
| 1631 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1632 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1633 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1634 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1635 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1636 | - ); |
|
| 1637 | - //make sure we have default start and end dates if skeleton |
|
| 1638 | - //handle rows that should NOT be empty |
|
| 1639 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1640 | - //if empty then the start date will be now. |
|
| 1641 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1642 | - } |
|
| 1643 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1644 | - //get the earliest datetime (if present); |
|
| 1645 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1646 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1647 | - 'Datetime', |
|
| 1648 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1649 | - ) |
|
| 1650 | - : null; |
|
| 1651 | - if ( ! empty($earliest_dtt)) { |
|
| 1652 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1653 | - } else { |
|
| 1654 | - $template_args['TKT_end_date'] = date( |
|
| 1655 | - 'Y-m-d h:i a', |
|
| 1656 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1657 | - ); |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - $template_args = array_merge($template_args, $price_args); |
|
| 1661 | - $template = apply_filters( |
|
| 1662 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1663 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1664 | - $ticket |
|
| 1665 | - ); |
|
| 1666 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - |
|
| 1670 | - |
|
| 1671 | - public function registration_options_meta_box() |
|
| 1672 | - { |
|
| 1673 | - $yes_no_values = array( |
|
| 1674 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1675 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1676 | - ); |
|
| 1677 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1678 | - array( |
|
| 1679 | - EEM_Registration::status_id_cancelled, |
|
| 1680 | - EEM_Registration::status_id_declined, |
|
| 1681 | - EEM_Registration::status_id_incomplete, |
|
| 1682 | - ), |
|
| 1683 | - true |
|
| 1684 | - ); |
|
| 1685 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1686 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1687 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1688 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1689 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1690 | - 'default_reg_status', |
|
| 1691 | - $default_reg_status_values, |
|
| 1692 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1693 | - ); |
|
| 1694 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1695 | - 'display_desc', |
|
| 1696 | - $yes_no_values, |
|
| 1697 | - $this->_cpt_model_obj->display_description() |
|
| 1698 | - ); |
|
| 1699 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1700 | - 'display_ticket_selector', |
|
| 1701 | - $yes_no_values, |
|
| 1702 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1703 | - '', |
|
| 1704 | - '', |
|
| 1705 | - false |
|
| 1706 | - ); |
|
| 1707 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1708 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1709 | - '', |
|
| 1710 | - $template_args, |
|
| 1711 | - $yes_no_values, |
|
| 1712 | - $default_reg_status_values |
|
| 1713 | - ); |
|
| 1714 | - EEH_Template::display_template( |
|
| 1715 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1716 | - $template_args |
|
| 1717 | - ); |
|
| 1718 | - } |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * _get_events() |
|
| 1724 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1725 | - * |
|
| 1726 | - * @access public |
|
| 1727 | - * @param int $per_page count of items per page (20 default); |
|
| 1728 | - * @param int $current_page what is the current page being viewed. |
|
| 1729 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1730 | - * If FALSE then we return an array of event objects |
|
| 1731 | - * that match the given _view and paging parameters. |
|
| 1732 | - * @return array an array of event objects. |
|
| 1733 | - */ |
|
| 1734 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1735 | - { |
|
| 1736 | - $EEME = $this->_event_model(); |
|
| 1737 | - $offset = ($current_page - 1) * $per_page; |
|
| 1738 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1739 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1740 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1741 | - if (isset($this->_req_data['month_range'])) { |
|
| 1742 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1743 | - //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1744 | - //where PHP doesn't know what to assume for date. |
|
| 1745 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1746 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1747 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1748 | - } |
|
| 1749 | - $where = array(); |
|
| 1750 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1751 | - //determine what post_status our condition will have for the query. |
|
| 1752 | - switch ($status) { |
|
| 1753 | - case 'month' : |
|
| 1754 | - case 'today' : |
|
| 1755 | - case null : |
|
| 1756 | - case 'all' : |
|
| 1757 | - break; |
|
| 1758 | - case 'draft' : |
|
| 1759 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1760 | - break; |
|
| 1761 | - default : |
|
| 1762 | - $where['status'] = $status; |
|
| 1763 | - } |
|
| 1764 | - //categories? |
|
| 1765 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1766 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1767 | - if ( ! empty ($category)) { |
|
| 1768 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1769 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1770 | - } |
|
| 1771 | - //date where conditions |
|
| 1772 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1773 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1774 | - $DateTime = new DateTime( |
|
| 1775 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1776 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1777 | - ); |
|
| 1778 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1779 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1780 | - ->format('t'))->setTime(23, 59, 59) |
|
| 1781 | - ->format(implode(' ', $start_formats)); |
|
| 1782 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1783 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1784 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1785 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1786 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1787 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1788 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1789 | - $now = date('Y-m-01'); |
|
| 1790 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1791 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1792 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1793 | - ->setTime(23, 59, 59) |
|
| 1794 | - ->format(implode(' ', $start_formats)); |
|
| 1795 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1796 | - } |
|
| 1797 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1798 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1799 | - } else { |
|
| 1800 | - if ( ! isset($where['status'])) { |
|
| 1801 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1802 | - $where['OR'] = array( |
|
| 1803 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1804 | - 'AND' => array( |
|
| 1805 | - 'status*inclusive' => array('=', 'private'), |
|
| 1806 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1807 | - ), |
|
| 1808 | - ); |
|
| 1809 | - } |
|
| 1810 | - } |
|
| 1811 | - } |
|
| 1812 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1813 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1814 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1815 | - ) { |
|
| 1816 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1817 | - } |
|
| 1818 | - } |
|
| 1819 | - //search query handling |
|
| 1820 | - if (isset($this->_req_data['s'])) { |
|
| 1821 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1822 | - $where['OR'] = array( |
|
| 1823 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1824 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1825 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1826 | - ); |
|
| 1827 | - } |
|
| 1828 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1829 | - $query_params = apply_filters( |
|
| 1830 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1831 | - array( |
|
| 1832 | - $where, |
|
| 1833 | - 'limit' => $limit, |
|
| 1834 | - 'order_by' => $orderby, |
|
| 1835 | - 'order' => $order, |
|
| 1836 | - 'group_by' => 'EVT_ID', |
|
| 1837 | - ), |
|
| 1838 | - $this->_req_data |
|
| 1839 | - ); |
|
| 1840 | - //let's first check if we have special requests coming in. |
|
| 1841 | - if (isset($this->_req_data['active_status'])) { |
|
| 1842 | - switch ($this->_req_data['active_status']) { |
|
| 1843 | - case 'upcoming' : |
|
| 1844 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1845 | - break; |
|
| 1846 | - case 'expired' : |
|
| 1847 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1848 | - break; |
|
| 1849 | - case 'active' : |
|
| 1850 | - return $EEME->get_active_events($query_params, $count); |
|
| 1851 | - break; |
|
| 1852 | - case 'inactive' : |
|
| 1853 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1854 | - break; |
|
| 1855 | - } |
|
| 1856 | - } |
|
| 1857 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1858 | - return $events; |
|
| 1859 | - } |
|
| 1860 | - |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1865 | - * |
|
| 1866 | - * @param string $post_id |
|
| 1867 | - */ |
|
| 1868 | - public function trash_cpt_item($post_id) |
|
| 1869 | - { |
|
| 1870 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1871 | - $this->_trash_or_restore_event('trash', false); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - |
|
| 1875 | - |
|
| 1876 | - /** |
|
| 1877 | - * @param string $post_id |
|
| 1878 | - */ |
|
| 1879 | - public function restore_cpt_item($post_id) |
|
| 1880 | - { |
|
| 1881 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1882 | - $this->_trash_or_restore_event('draft', false); |
|
| 1883 | - } |
|
| 1884 | - |
|
| 1885 | - |
|
| 1886 | - |
|
| 1887 | - /** |
|
| 1888 | - * @param string $post_id |
|
| 1889 | - */ |
|
| 1890 | - public function delete_cpt_item($post_id) |
|
| 1891 | - { |
|
| 1892 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1893 | - $this->_delete_event(false); |
|
| 1894 | - } |
|
| 1895 | - |
|
| 1896 | - |
|
| 1897 | - |
|
| 1898 | - /** |
|
| 1899 | - * _trash_or_restore_event |
|
| 1900 | - * |
|
| 1901 | - * @access protected |
|
| 1902 | - * @param string $event_status |
|
| 1903 | - * @param bool $redirect_after |
|
| 1904 | - */ |
|
| 1905 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1906 | - { |
|
| 1907 | - //determine the event id and set to array. |
|
| 1908 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1909 | - // loop thru events |
|
| 1910 | - if ($EVT_ID) { |
|
| 1911 | - // clean status |
|
| 1912 | - $event_status = sanitize_key($event_status); |
|
| 1913 | - // grab status |
|
| 1914 | - if ( ! empty($event_status)) { |
|
| 1915 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1916 | - } else { |
|
| 1917 | - $success = false; |
|
| 1918 | - $msg = esc_html__( |
|
| 1919 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1920 | - 'event_espresso' |
|
| 1921 | - ); |
|
| 1922 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1923 | - } |
|
| 1924 | - } else { |
|
| 1925 | - $success = false; |
|
| 1926 | - $msg = esc_html__( |
|
| 1927 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1928 | - 'event_espresso' |
|
| 1929 | - ); |
|
| 1930 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1931 | - } |
|
| 1932 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1933 | - if ($redirect_after) { |
|
| 1934 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1935 | - } |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * _trash_or_restore_events |
|
| 1942 | - * |
|
| 1943 | - * @access protected |
|
| 1944 | - * @param string $event_status |
|
| 1945 | - * @return void |
|
| 1946 | - */ |
|
| 1947 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1948 | - { |
|
| 1949 | - // clean status |
|
| 1950 | - $event_status = sanitize_key($event_status); |
|
| 1951 | - // grab status |
|
| 1952 | - if ( ! empty($event_status)) { |
|
| 1953 | - $success = true; |
|
| 1954 | - //determine the event id and set to array. |
|
| 1955 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1956 | - // loop thru events |
|
| 1957 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 1958 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 1959 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1960 | - $success = $results !== false ? $success : false; |
|
| 1961 | - } else { |
|
| 1962 | - $msg = sprintf( |
|
| 1963 | - esc_html__( |
|
| 1964 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1965 | - 'event_espresso' |
|
| 1966 | - ), |
|
| 1967 | - $EVT_ID |
|
| 1968 | - ); |
|
| 1969 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1970 | - $success = false; |
|
| 1971 | - } |
|
| 1972 | - } |
|
| 1973 | - } else { |
|
| 1974 | - $success = false; |
|
| 1975 | - $msg = esc_html__( |
|
| 1976 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1977 | - 'event_espresso' |
|
| 1978 | - ); |
|
| 1979 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1980 | - } |
|
| 1981 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1982 | - $success = $success ? 2 : false; |
|
| 1983 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1984 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1985 | - } |
|
| 1986 | - |
|
| 1987 | - |
|
| 1988 | - |
|
| 1989 | - /** |
|
| 1990 | - * _trash_or_restore_events |
|
| 1991 | - * |
|
| 1992 | - * @access private |
|
| 1993 | - * @param int $EVT_ID |
|
| 1994 | - * @param string $event_status |
|
| 1995 | - * @return bool |
|
| 1996 | - */ |
|
| 1997 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1998 | - { |
|
| 1999 | - // grab event id |
|
| 2000 | - if ( ! $EVT_ID) { |
|
| 2001 | - $msg = esc_html__( |
|
| 2002 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2003 | - 'event_espresso' |
|
| 2004 | - ); |
|
| 2005 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2006 | - return false; |
|
| 2007 | - } |
|
| 2008 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2009 | - // clean status |
|
| 2010 | - $event_status = sanitize_key($event_status); |
|
| 2011 | - // grab status |
|
| 2012 | - if (empty($event_status)) { |
|
| 2013 | - $msg = esc_html__( |
|
| 2014 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2015 | - 'event_espresso' |
|
| 2016 | - ); |
|
| 2017 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2018 | - return false; |
|
| 2019 | - } |
|
| 2020 | - // was event trashed or restored ? |
|
| 2021 | - switch ($event_status) { |
|
| 2022 | - case 'draft' : |
|
| 2023 | - $action = 'restored from the trash'; |
|
| 2024 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2025 | - break; |
|
| 2026 | - case 'trash' : |
|
| 2027 | - $action = 'moved to the trash'; |
|
| 2028 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2029 | - break; |
|
| 2030 | - default : |
|
| 2031 | - $action = 'updated'; |
|
| 2032 | - $hook = false; |
|
| 2033 | - } |
|
| 2034 | - //use class to change status |
|
| 2035 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2036 | - $success = $this->_cpt_model_obj->save(); |
|
| 2037 | - if ($success === false) { |
|
| 2038 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2039 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2040 | - return false; |
|
| 2041 | - } |
|
| 2042 | - if ($hook) { |
|
| 2043 | - do_action($hook); |
|
| 2044 | - } |
|
| 2045 | - return true; |
|
| 2046 | - } |
|
| 2047 | - |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * _delete_event |
|
| 2052 | - * |
|
| 2053 | - * @access protected |
|
| 2054 | - * @param bool $redirect_after |
|
| 2055 | - */ |
|
| 2056 | - protected function _delete_event($redirect_after = true) |
|
| 2057 | - { |
|
| 2058 | - //determine the event id and set to array. |
|
| 2059 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2060 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2061 | - // loop thru events |
|
| 2062 | - if ($EVT_ID) { |
|
| 2063 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2064 | - // get list of events with no prices |
|
| 2065 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2066 | - // remove this event from the list of events with no prices |
|
| 2067 | - if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2068 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2069 | - } |
|
| 2070 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2071 | - } else { |
|
| 2072 | - $success = false; |
|
| 2073 | - $msg = esc_html__( |
|
| 2074 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2075 | - 'event_espresso' |
|
| 2076 | - ); |
|
| 2077 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2078 | - } |
|
| 2079 | - if ($redirect_after) { |
|
| 2080 | - $this->_redirect_after_action( |
|
| 2081 | - $success, |
|
| 2082 | - 'Event', |
|
| 2083 | - 'deleted', |
|
| 2084 | - array('action' => 'default', 'status' => 'trash') |
|
| 2085 | - ); |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * _delete_events |
|
| 2093 | - * |
|
| 2094 | - * @access protected |
|
| 2095 | - * @return void |
|
| 2096 | - */ |
|
| 2097 | - protected function _delete_events() |
|
| 2098 | - { |
|
| 2099 | - $success = true; |
|
| 2100 | - // get list of events with no prices |
|
| 2101 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2102 | - //determine the event id and set to array. |
|
| 2103 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2104 | - // loop thru events |
|
| 2105 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2106 | - $EVT_ID = absint($EVT_ID); |
|
| 2107 | - if ($EVT_ID) { |
|
| 2108 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2109 | - $success = $results !== false ? $success : false; |
|
| 2110 | - // remove this event from the list of events with no prices |
|
| 2111 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2112 | - } else { |
|
| 2113 | - $success = false; |
|
| 2114 | - $msg = esc_html__( |
|
| 2115 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2116 | - 'event_espresso' |
|
| 2117 | - ); |
|
| 2118 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2122 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2123 | - $success = $success ? 2 : false; |
|
| 2124 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - |
|
| 2128 | - |
|
| 2129 | - /** |
|
| 2130 | - * _permanently_delete_event |
|
| 2131 | - * |
|
| 2132 | - * @access private |
|
| 2133 | - * @param int $EVT_ID |
|
| 2134 | - * @return bool |
|
| 2135 | - */ |
|
| 2136 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2137 | - { |
|
| 2138 | - // grab event id |
|
| 2139 | - if ( ! $EVT_ID) { |
|
| 2140 | - $msg = esc_html__( |
|
| 2141 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2142 | - 'event_espresso' |
|
| 2143 | - ); |
|
| 2144 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2145 | - return false; |
|
| 2146 | - } |
|
| 2147 | - if ( |
|
| 2148 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2149 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2150 | - ) { |
|
| 2151 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2152 | - } |
|
| 2153 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2154 | - return false; |
|
| 2155 | - } |
|
| 2156 | - //need to delete related tickets and prices first. |
|
| 2157 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2158 | - foreach ($datetimes as $datetime) { |
|
| 2159 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2160 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2161 | - foreach ($tickets as $ticket) { |
|
| 2162 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2163 | - $ticket->delete_related_permanently('Price'); |
|
| 2164 | - $ticket->delete_permanently(); |
|
| 2165 | - } |
|
| 2166 | - $datetime->delete(); |
|
| 2167 | - } |
|
| 2168 | - //what about related venues or terms? |
|
| 2169 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2170 | - foreach ($venues as $venue) { |
|
| 2171 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2172 | - } |
|
| 2173 | - //any attached question groups? |
|
| 2174 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2175 | - if ( ! empty($question_groups)) { |
|
| 2176 | - foreach ($question_groups as $question_group) { |
|
| 2177 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2178 | - } |
|
| 2179 | - } |
|
| 2180 | - //Message Template Groups |
|
| 2181 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2182 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2183 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2184 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2185 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2186 | - } |
|
| 2187 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2188 | - // did it all go as planned ? |
|
| 2189 | - if ($success) { |
|
| 2190 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2191 | - EE_Error::add_success($msg); |
|
| 2192 | - } else { |
|
| 2193 | - $msg = sprintf( |
|
| 2194 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2195 | - $EVT_ID |
|
| 2196 | - ); |
|
| 2197 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2198 | - return false; |
|
| 2199 | - } |
|
| 2200 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2201 | - return true; |
|
| 2202 | - } |
|
| 2203 | - |
|
| 2204 | - |
|
| 2205 | - |
|
| 2206 | - /** |
|
| 2207 | - * get total number of events |
|
| 2208 | - * |
|
| 2209 | - * @access public |
|
| 2210 | - * @return int |
|
| 2211 | - */ |
|
| 2212 | - public function total_events() |
|
| 2213 | - { |
|
| 2214 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2215 | - return $count; |
|
| 2216 | - } |
|
| 2217 | - |
|
| 2218 | - |
|
| 2219 | - |
|
| 2220 | - /** |
|
| 2221 | - * get total number of draft events |
|
| 2222 | - * |
|
| 2223 | - * @access public |
|
| 2224 | - * @return int |
|
| 2225 | - */ |
|
| 2226 | - public function total_events_draft() |
|
| 2227 | - { |
|
| 2228 | - $where = array( |
|
| 2229 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2230 | - ); |
|
| 2231 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2232 | - return $count; |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - |
|
| 2236 | - |
|
| 2237 | - /** |
|
| 2238 | - * get total number of trashed events |
|
| 2239 | - * |
|
| 2240 | - * @access public |
|
| 2241 | - * @return int |
|
| 2242 | - */ |
|
| 2243 | - public function total_trashed_events() |
|
| 2244 | - { |
|
| 2245 | - $where = array( |
|
| 2246 | - 'status' => 'trash', |
|
| 2247 | - ); |
|
| 2248 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2249 | - return $count; |
|
| 2250 | - } |
|
| 2251 | - |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * _default_event_settings |
|
| 2256 | - * This generates the Default Settings Tab |
|
| 2257 | - * |
|
| 2258 | - * @return void |
|
| 2259 | - */ |
|
| 2260 | - protected function _default_event_settings() |
|
| 2261 | - { |
|
| 2262 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2263 | - $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2264 | - // exclude array |
|
| 2265 | - array( |
|
| 2266 | - EEM_Registration::status_id_cancelled, |
|
| 2267 | - EEM_Registration::status_id_declined, |
|
| 2268 | - EEM_Registration::status_id_incomplete, |
|
| 2269 | - EEM_Registration::status_id_wait_list, |
|
| 2270 | - ), |
|
| 2271 | - // translated |
|
| 2272 | - true |
|
| 2273 | - ); |
|
| 2274 | - $this->_template_args['default_reg_status'] = isset( |
|
| 2275 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2276 | - ) |
|
| 2277 | - && array_key_exists( |
|
| 2278 | - EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2279 | - $this->_template_args['reg_status_array'] |
|
| 2280 | - ) |
|
| 2281 | - ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2282 | - : EEM_Registration::status_id_pending_payment; |
|
| 2283 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2284 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2285 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2286 | - EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2287 | - $this->_template_args, |
|
| 2288 | - true |
|
| 2289 | - ); |
|
| 2290 | - $this->display_admin_page_with_sidebar(); |
|
| 2291 | - } |
|
| 2292 | - |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - /** |
|
| 2296 | - * _update_default_event_settings |
|
| 2297 | - * |
|
| 2298 | - * @access protected |
|
| 2299 | - * @return void |
|
| 2300 | - */ |
|
| 2301 | - protected function _update_default_event_settings() |
|
| 2302 | - { |
|
| 2303 | - EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2304 | - ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2305 | - : EEM_Registration::status_id_pending_payment; |
|
| 2306 | - $what = 'Default Event Settings'; |
|
| 2307 | - $success = $this->_update_espresso_configuration( |
|
| 2308 | - $what, |
|
| 2309 | - EE_Config::instance(), |
|
| 2310 | - __FILE__, |
|
| 2311 | - __FUNCTION__, |
|
| 2312 | - __LINE__ |
|
| 2313 | - ); |
|
| 2314 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2315 | - } |
|
| 2316 | - |
|
| 2317 | - |
|
| 2318 | - |
|
| 2319 | - /************* Templates *************/ |
|
| 2320 | - protected function _template_settings() |
|
| 2321 | - { |
|
| 2322 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2323 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2324 | - . EVENTS_ASSETS_URL |
|
| 2325 | - . DS |
|
| 2326 | - . 'images' |
|
| 2327 | - . DS |
|
| 2328 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2329 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2330 | - . '" />'; |
|
| 2331 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2332 | - 'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2333 | - 'event_espresso' |
|
| 2334 | - ) . '</strong>'; |
|
| 2335 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2336 | - } |
|
| 2337 | - |
|
| 2338 | - |
|
| 2339 | - /** Event Category Stuff **/ |
|
| 2340 | - /** |
|
| 2341 | - * set the _category property with the category object for the loaded page. |
|
| 2342 | - * |
|
| 2343 | - * @access private |
|
| 2344 | - * @return void |
|
| 2345 | - */ |
|
| 2346 | - private function _set_category_object() |
|
| 2347 | - { |
|
| 2348 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2349 | - return; |
|
| 2350 | - } //already have the category object so get out. |
|
| 2351 | - //set default category object |
|
| 2352 | - $this->_set_empty_category_object(); |
|
| 2353 | - //only set if we've got an id |
|
| 2354 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2355 | - return; |
|
| 2356 | - } |
|
| 2357 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2358 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2359 | - if ( ! empty($term)) { |
|
| 2360 | - $this->_category->category_name = $term->name; |
|
| 2361 | - $this->_category->category_identifier = $term->slug; |
|
| 2362 | - $this->_category->category_desc = $term->description; |
|
| 2363 | - $this->_category->id = $term->term_id; |
|
| 2364 | - $this->_category->parent = $term->parent; |
|
| 2365 | - } |
|
| 2366 | - } |
|
| 2367 | - |
|
| 2368 | - |
|
| 2369 | - |
|
| 2370 | - private function _set_empty_category_object() |
|
| 2371 | - { |
|
| 2372 | - $this->_category = new stdClass(); |
|
| 2373 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2374 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2375 | - } |
|
| 2376 | - |
|
| 2377 | - |
|
| 2378 | - |
|
| 2379 | - protected function _category_list_table() |
|
| 2380 | - { |
|
| 2381 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2382 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2383 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2384 | - 'add_category', |
|
| 2385 | - 'add_category', |
|
| 2386 | - array(), |
|
| 2387 | - 'add-new-h2' |
|
| 2388 | - ); |
|
| 2389 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2390 | - } |
|
| 2391 | - |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - /** |
|
| 2395 | - * @param $view |
|
| 2396 | - */ |
|
| 2397 | - protected function _category_details($view) |
|
| 2398 | - { |
|
| 2399 | - //load formatter helper |
|
| 2400 | - //load field generator helper |
|
| 2401 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2402 | - $this->_set_add_edit_form_tags($route); |
|
| 2403 | - $this->_set_category_object(); |
|
| 2404 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2405 | - $delete_action = 'delete_category'; |
|
| 2406 | - //custom redirect |
|
| 2407 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2408 | - array('action' => 'category_list'), |
|
| 2409 | - $this->_admin_base_url |
|
| 2410 | - ); |
|
| 2411 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2412 | - //take care of contents |
|
| 2413 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2414 | - $this->display_admin_page_with_sidebar(); |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - /** |
|
| 2420 | - * @return mixed |
|
| 2421 | - */ |
|
| 2422 | - protected function _category_details_content() |
|
| 2423 | - { |
|
| 2424 | - $editor_args['category_desc'] = array( |
|
| 2425 | - 'type' => 'wp_editor', |
|
| 2426 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2427 | - 'class' => 'my_editor_custom', |
|
| 2428 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2429 | - ); |
|
| 2430 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2431 | - $all_terms = get_terms( |
|
| 2432 | - array('espresso_event_categories'), |
|
| 2433 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2434 | - ); |
|
| 2435 | - //setup category select for term parents. |
|
| 2436 | - $category_select_values[] = array( |
|
| 2437 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2438 | - 'id' => 0, |
|
| 2439 | - ); |
|
| 2440 | - foreach ($all_terms as $term) { |
|
| 2441 | - $category_select_values[] = array( |
|
| 2442 | - 'text' => $term->name, |
|
| 2443 | - 'id' => $term->term_id, |
|
| 2444 | - ); |
|
| 2445 | - } |
|
| 2446 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2447 | - 'category_parent', |
|
| 2448 | - $category_select_values, |
|
| 2449 | - $this->_category->parent |
|
| 2450 | - ); |
|
| 2451 | - $template_args = array( |
|
| 2452 | - 'category' => $this->_category, |
|
| 2453 | - 'category_select' => $category_select, |
|
| 2454 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2455 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2456 | - 'disable' => '', |
|
| 2457 | - 'disabled_message' => false, |
|
| 2458 | - ); |
|
| 2459 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2460 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2461 | - } |
|
| 2462 | - |
|
| 2463 | - |
|
| 2464 | - |
|
| 2465 | - protected function _delete_categories() |
|
| 2466 | - { |
|
| 2467 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2468 | - : (array)$this->_req_data['category_id']; |
|
| 2469 | - foreach ($cat_ids as $cat_id) { |
|
| 2470 | - $this->_delete_category($cat_id); |
|
| 2471 | - } |
|
| 2472 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2473 | - $query_args = array( |
|
| 2474 | - 'action' => 'category_list', |
|
| 2475 | - ); |
|
| 2476 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - |
|
| 2480 | - |
|
| 2481 | - /** |
|
| 2482 | - * @param $cat_id |
|
| 2483 | - */ |
|
| 2484 | - protected function _delete_category($cat_id) |
|
| 2485 | - { |
|
| 2486 | - $cat_id = absint($cat_id); |
|
| 2487 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * @param $new_category |
|
| 2494 | - */ |
|
| 2495 | - protected function _insert_or_update_category($new_category) |
|
| 2496 | - { |
|
| 2497 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2498 | - $success = 0; //we already have a success message so lets not send another. |
|
| 2499 | - if ($cat_id) { |
|
| 2500 | - $query_args = array( |
|
| 2501 | - 'action' => 'edit_category', |
|
| 2502 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2503 | - ); |
|
| 2504 | - } else { |
|
| 2505 | - $query_args = array('action' => 'add_category'); |
|
| 2506 | - } |
|
| 2507 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2508 | - } |
|
| 2509 | - |
|
| 2510 | - |
|
| 2511 | - |
|
| 2512 | - /** |
|
| 2513 | - * @param bool $update |
|
| 2514 | - * @return bool|mixed|string |
|
| 2515 | - */ |
|
| 2516 | - private function _insert_category($update = false) |
|
| 2517 | - { |
|
| 2518 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2519 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2520 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2521 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2522 | - if (empty($category_name)) { |
|
| 2523 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2524 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2525 | - return false; |
|
| 2526 | - } |
|
| 2527 | - $term_args = array( |
|
| 2528 | - 'name' => $category_name, |
|
| 2529 | - 'description' => $category_desc, |
|
| 2530 | - 'parent' => $category_parent, |
|
| 2531 | - ); |
|
| 2532 | - //was the category_identifier input disabled? |
|
| 2533 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2534 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2535 | - } |
|
| 2536 | - $insert_ids = $update |
|
| 2537 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2538 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2539 | - if ( ! is_array($insert_ids)) { |
|
| 2540 | - $msg = esc_html__( |
|
| 2541 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2542 | - 'event_espresso' |
|
| 2543 | - ); |
|
| 2544 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2545 | - } else { |
|
| 2546 | - $cat_id = $insert_ids['term_id']; |
|
| 2547 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2548 | - EE_Error::add_success($msg); |
|
| 2549 | - } |
|
| 2550 | - return $cat_id; |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - |
|
| 2554 | - |
|
| 2555 | - /** |
|
| 2556 | - * @param int $per_page |
|
| 2557 | - * @param int $current_page |
|
| 2558 | - * @param bool $count |
|
| 2559 | - * @return \EE_Base_Class[]|int |
|
| 2560 | - */ |
|
| 2561 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2562 | - { |
|
| 2563 | - //testing term stuff |
|
| 2564 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2565 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2566 | - $limit = ($current_page - 1) * $per_page; |
|
| 2567 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2568 | - if (isset($this->_req_data['s'])) { |
|
| 2569 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2570 | - $where['OR'] = array( |
|
| 2571 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2572 | - 'description' => array('LIKE', $sstr), |
|
| 2573 | - ); |
|
| 2574 | - } |
|
| 2575 | - $query_params = array( |
|
| 2576 | - $where, |
|
| 2577 | - 'order_by' => array($orderby => $order), |
|
| 2578 | - 'limit' => $limit . ',' . $per_page, |
|
| 2579 | - 'force_join' => array('Term'), |
|
| 2580 | - ); |
|
| 2581 | - $categories = $count |
|
| 2582 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2583 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2584 | - return $categories; |
|
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - |
|
| 2588 | - |
|
| 2589 | - /* end category stuff */ |
|
| 2590 | - /**************/ |
|
| 385 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | + 'require_nonce' => false, |
|
| 387 | + ), |
|
| 388 | + 'default_event_settings' => array( |
|
| 389 | + 'nav' => array( |
|
| 390 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | + 'order' => 40, |
|
| 392 | + ), |
|
| 393 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | + 'labels' => array( |
|
| 395 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | + ), |
|
| 397 | + 'help_tabs' => array( |
|
| 398 | + 'default_settings_help_tab' => array( |
|
| 399 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | + 'filename' => 'events_default_settings', |
|
| 401 | + ), |
|
| 402 | + 'default_settings_status_help_tab' => array( |
|
| 403 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | + 'filename' => 'events_default_settings_status', |
|
| 405 | + ), |
|
| 406 | + ), |
|
| 407 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 408 | + 'require_nonce' => false, |
|
| 409 | + ), |
|
| 410 | + //template settings |
|
| 411 | + 'template_settings' => array( |
|
| 412 | + 'nav' => array( |
|
| 413 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 414 | + 'order' => 30, |
|
| 415 | + ), |
|
| 416 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 417 | + 'help_tabs' => array( |
|
| 418 | + 'general_settings_templates_help_tab' => array( |
|
| 419 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 420 | + 'filename' => 'general_settings_templates', |
|
| 421 | + ), |
|
| 422 | + ), |
|
| 423 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 424 | + 'require_nonce' => false, |
|
| 425 | + ), |
|
| 426 | + //event category stuff |
|
| 427 | + 'add_category' => array( |
|
| 428 | + 'nav' => array( |
|
| 429 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 430 | + 'order' => 15, |
|
| 431 | + 'persistent' => false, |
|
| 432 | + ), |
|
| 433 | + 'help_tabs' => array( |
|
| 434 | + 'add_category_help_tab' => array( |
|
| 435 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 436 | + 'filename' => 'events_add_category', |
|
| 437 | + ), |
|
| 438 | + ), |
|
| 439 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 440 | + 'metaboxes' => array('_publish_post_box'), |
|
| 441 | + 'require_nonce' => false, |
|
| 442 | + ), |
|
| 443 | + 'edit_category' => array( |
|
| 444 | + 'nav' => array( |
|
| 445 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 446 | + 'order' => 15, |
|
| 447 | + 'persistent' => false, |
|
| 448 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 449 | + ? add_query_arg( |
|
| 450 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 451 | + $this->_current_page_view_url |
|
| 452 | + ) |
|
| 453 | + : $this->_admin_base_url, |
|
| 454 | + ), |
|
| 455 | + 'help_tabs' => array( |
|
| 456 | + 'edit_category_help_tab' => array( |
|
| 457 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 458 | + 'filename' => 'events_edit_category', |
|
| 459 | + ), |
|
| 460 | + ), |
|
| 461 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 462 | + 'metaboxes' => array('_publish_post_box'), |
|
| 463 | + 'require_nonce' => false, |
|
| 464 | + ), |
|
| 465 | + 'category_list' => array( |
|
| 466 | + 'nav' => array( |
|
| 467 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 468 | + 'order' => 20, |
|
| 469 | + ), |
|
| 470 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 471 | + 'help_tabs' => array( |
|
| 472 | + 'events_categories_help_tab' => array( |
|
| 473 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 474 | + 'filename' => 'events_categories', |
|
| 475 | + ), |
|
| 476 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 477 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 478 | + 'filename' => 'events_categories_table_column_headings', |
|
| 479 | + ), |
|
| 480 | + 'events_categories_view_help_tab' => array( |
|
| 481 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 482 | + 'filename' => 'events_categories_views', |
|
| 483 | + ), |
|
| 484 | + 'events_categories_other_help_tab' => array( |
|
| 485 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 486 | + 'filename' => 'events_categories_other', |
|
| 487 | + ), |
|
| 488 | + ), |
|
| 489 | + 'help_tour' => array( |
|
| 490 | + 'Event_Categories_Help_Tour', |
|
| 491 | + ), |
|
| 492 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 493 | + 'require_nonce' => false, |
|
| 494 | + ), |
|
| 495 | + ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + protected function _add_screen_options() |
|
| 501 | + { |
|
| 502 | + //todo |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + protected function _add_screen_options_default() |
|
| 508 | + { |
|
| 509 | + $this->_per_page_screen_option(); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + protected function _add_screen_options_category_list() |
|
| 515 | + { |
|
| 516 | + $page_title = $this->_admin_page_title; |
|
| 517 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 518 | + $this->_per_page_screen_option(); |
|
| 519 | + $this->_admin_page_title = $page_title; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + protected function _add_feature_pointers() |
|
| 525 | + { |
|
| 526 | + //todo |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + public function load_scripts_styles() |
|
| 532 | + { |
|
| 533 | + wp_register_style( |
|
| 534 | + 'events-admin-css', |
|
| 535 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 536 | + array(), |
|
| 537 | + EVENT_ESPRESSO_VERSION |
|
| 538 | + ); |
|
| 539 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 540 | + wp_enqueue_style('events-admin-css'); |
|
| 541 | + wp_enqueue_style('ee-cat-admin'); |
|
| 542 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 543 | + //registers for all views |
|
| 544 | + //scripts |
|
| 545 | + wp_register_script( |
|
| 546 | + 'event_editor_js', |
|
| 547 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 548 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 549 | + EVENT_ESPRESSO_VERSION, |
|
| 550 | + true |
|
| 551 | + ); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * enqueuing scripts and styles specific to this view |
|
| 558 | + * |
|
| 559 | + * @return void |
|
| 560 | + */ |
|
| 561 | + public function load_scripts_styles_create_new() |
|
| 562 | + { |
|
| 563 | + $this->load_scripts_styles_edit(); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * enqueuing scripts and styles specific to this view |
|
| 570 | + * |
|
| 571 | + * @return void |
|
| 572 | + */ |
|
| 573 | + public function load_scripts_styles_edit() |
|
| 574 | + { |
|
| 575 | + //styles |
|
| 576 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 577 | + wp_register_style( |
|
| 578 | + 'event-editor-css', |
|
| 579 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 580 | + array('ee-admin-css'), |
|
| 581 | + EVENT_ESPRESSO_VERSION |
|
| 582 | + ); |
|
| 583 | + wp_enqueue_style('event-editor-css'); |
|
| 584 | + //scripts |
|
| 585 | + wp_register_script( |
|
| 586 | + 'event-datetime-metabox', |
|
| 587 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 588 | + array('event_editor_js', 'ee-datepicker'), |
|
| 589 | + EVENT_ESPRESSO_VERSION |
|
| 590 | + ); |
|
| 591 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + public function load_scripts_styles_add_category() |
|
| 597 | + { |
|
| 598 | + $this->load_scripts_styles_edit_category(); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + public function load_scripts_styles_edit_category() |
|
| 604 | + { |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + protected function _set_list_table_views_category_list() |
|
| 610 | + { |
|
| 611 | + $this->_views = array( |
|
| 612 | + 'all' => array( |
|
| 613 | + 'slug' => 'all', |
|
| 614 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 615 | + 'count' => 0, |
|
| 616 | + 'bulk_action' => array( |
|
| 617 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 618 | + ), |
|
| 619 | + ), |
|
| 620 | + ); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + public function admin_init() |
|
| 626 | + { |
|
| 627 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 628 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 629 | + 'event_espresso' |
|
| 630 | + ); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + //nothing needed for events with these methods. |
|
| 636 | + public function admin_notices() |
|
| 637 | + { |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + public function admin_footer_scripts() |
|
| 643 | + { |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 650 | + * warning (via EE_Error::add_error()); |
|
| 651 | + * |
|
| 652 | + * @param EE_Event $event Event object |
|
| 653 | + * @access public |
|
| 654 | + * @return void |
|
| 655 | + */ |
|
| 656 | + public function verify_event_edit($event = null) |
|
| 657 | + { |
|
| 658 | + // no event? |
|
| 659 | + if (empty($event)) { |
|
| 660 | + // set event |
|
| 661 | + $event = $this->_cpt_model_obj; |
|
| 662 | + } |
|
| 663 | + // STILL no event? |
|
| 664 | + if (empty ($event)) { |
|
| 665 | + return; |
|
| 666 | + } |
|
| 667 | + $orig_status = $event->status(); |
|
| 668 | + // first check if event is active. |
|
| 669 | + if ( |
|
| 670 | + $orig_status === EEM_Event::cancelled |
|
| 671 | + || $orig_status === EEM_Event::postponed |
|
| 672 | + || $event->is_expired() |
|
| 673 | + || $event->is_inactive() |
|
| 674 | + ) { |
|
| 675 | + return; |
|
| 676 | + } |
|
| 677 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
| 678 | + if ($event->is_sold_out(true)) { |
|
| 679 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 680 | + EE_Error::add_attention( |
|
| 681 | + sprintf( |
|
| 682 | + esc_html__( |
|
| 683 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 684 | + 'event_espresso' |
|
| 685 | + ), |
|
| 686 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 687 | + ) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + return; |
|
| 691 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
| 692 | + EE_Error::add_attention( |
|
| 693 | + sprintf( |
|
| 694 | + esc_html__( |
|
| 695 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 696 | + 'event_espresso' |
|
| 697 | + ), |
|
| 698 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 699 | + ) |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 703 | + if ( ! $event->tickets_on_sale()) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + //made it here so show warning |
|
| 707 | + $this->_edit_event_warning(); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 714 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 715 | + * |
|
| 716 | + * @access protected |
|
| 717 | + * @return void |
|
| 718 | + */ |
|
| 719 | + protected function _edit_event_warning() |
|
| 720 | + { |
|
| 721 | + // we don't want to add warnings during these requests |
|
| 722 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 723 | + return; |
|
| 724 | + } |
|
| 725 | + EE_Error::add_attention( |
|
| 726 | + esc_html__( |
|
| 727 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 728 | + 'event_espresso' |
|
| 729 | + ) |
|
| 730 | + ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 737 | + * Otherwise, do the normal logic |
|
| 738 | + * |
|
| 739 | + * @return string |
|
| 740 | + * @throws \EE_Error |
|
| 741 | + */ |
|
| 742 | + protected function _create_new_cpt_item() |
|
| 743 | + { |
|
| 744 | + $gmt_offset = get_option('gmt_offset'); |
|
| 745 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 746 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 747 | + EE_Error::add_attention( |
|
| 748 | + sprintf( |
|
| 749 | + __( |
|
| 750 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 751 | + 'event_espresso' |
|
| 752 | + ), |
|
| 753 | + '<a href="' . admin_url('options-general.php') . '">', |
|
| 754 | + '</a>' |
|
| 755 | + ), |
|
| 756 | + __FILE__, |
|
| 757 | + __FUNCTION__, |
|
| 758 | + __LINE__ |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + return parent::_create_new_cpt_item(); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + protected function _set_list_table_views_default() |
|
| 767 | + { |
|
| 768 | + $this->_views = array( |
|
| 769 | + 'all' => array( |
|
| 770 | + 'slug' => 'all', |
|
| 771 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 772 | + 'count' => 0, |
|
| 773 | + 'bulk_action' => array( |
|
| 774 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 775 | + ), |
|
| 776 | + ), |
|
| 777 | + 'draft' => array( |
|
| 778 | + 'slug' => 'draft', |
|
| 779 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 780 | + 'count' => 0, |
|
| 781 | + 'bulk_action' => array( |
|
| 782 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 783 | + ), |
|
| 784 | + ), |
|
| 785 | + ); |
|
| 786 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 787 | + $this->_views['trash'] = array( |
|
| 788 | + 'slug' => 'trash', |
|
| 789 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 790 | + 'count' => 0, |
|
| 791 | + 'bulk_action' => array( |
|
| 792 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 793 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 794 | + ), |
|
| 795 | + ); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * @return array |
|
| 803 | + */ |
|
| 804 | + protected function _event_legend_items() |
|
| 805 | + { |
|
| 806 | + $items = array( |
|
| 807 | + 'view_details' => array( |
|
| 808 | + 'class' => 'dashicons dashicons-search', |
|
| 809 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 810 | + ), |
|
| 811 | + 'edit_event' => array( |
|
| 812 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 813 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 814 | + ), |
|
| 815 | + 'view_attendees' => array( |
|
| 816 | + 'class' => 'dashicons dashicons-groups', |
|
| 817 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 818 | + ), |
|
| 819 | + ); |
|
| 820 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 821 | + $statuses = array( |
|
| 822 | + 'sold_out_status' => array( |
|
| 823 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 824 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 825 | + ), |
|
| 826 | + 'active_status' => array( |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 828 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 829 | + ), |
|
| 830 | + 'upcoming_status' => array( |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 832 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 833 | + ), |
|
| 834 | + 'postponed_status' => array( |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 836 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 837 | + ), |
|
| 838 | + 'cancelled_status' => array( |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 840 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 841 | + ), |
|
| 842 | + 'expired_status' => array( |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 844 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 845 | + ), |
|
| 846 | + 'inactive_status' => array( |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 848 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 849 | + ), |
|
| 850 | + ); |
|
| 851 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 852 | + return array_merge($items, $statuses); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * _event_model |
|
| 859 | + * |
|
| 860 | + * @return EEM_Event |
|
| 861 | + */ |
|
| 862 | + private function _event_model() |
|
| 863 | + { |
|
| 864 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 865 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 866 | + } |
|
| 867 | + return $this->_event_model; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 874 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 875 | + * |
|
| 876 | + * @param string $return the current html |
|
| 877 | + * @param int $id the post id for the page |
|
| 878 | + * @param string $new_title What the title is |
|
| 879 | + * @param string $new_slug what the slug is |
|
| 880 | + * @return string The new html string for the permalink area |
|
| 881 | + */ |
|
| 882 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 883 | + { |
|
| 884 | + //make sure this is only when editing |
|
| 885 | + if ( ! empty($id)) { |
|
| 886 | + $post = get_post($id); |
|
| 887 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 888 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 889 | + . '</a> '; |
|
| 890 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 891 | + . $post->ID |
|
| 892 | + . ']">'; |
|
| 893 | + } |
|
| 894 | + return $return; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * _events_overview_list_table |
|
| 901 | + * This contains the logic for showing the events_overview list |
|
| 902 | + * |
|
| 903 | + * @access protected |
|
| 904 | + * @return void |
|
| 905 | + * @throws \EE_Error |
|
| 906 | + */ |
|
| 907 | + protected function _events_overview_list_table() |
|
| 908 | + { |
|
| 909 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 910 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 911 | + ? (array)$this->_template_args['after_list_table'] |
|
| 912 | + : array(); |
|
| 913 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 914 | + . EEH_Template::get_button_or_link( |
|
| 915 | + get_post_type_archive_link('espresso_events'), |
|
| 916 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 917 | + 'button' |
|
| 918 | + ); |
|
| 919 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 920 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 921 | + 'create_new', |
|
| 922 | + 'add', |
|
| 923 | + array(), |
|
| 924 | + 'add-new-h2' |
|
| 925 | + ); |
|
| 926 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * this allows for extra misc actions in the default WP publish box |
|
| 933 | + * |
|
| 934 | + * @return void |
|
| 935 | + */ |
|
| 936 | + public function extra_misc_actions_publish_box() |
|
| 937 | + { |
|
| 938 | + $this->_generate_publish_box_extra_content(); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 945 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 946 | + * data. |
|
| 947 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 948 | + * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 949 | + * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 950 | + * you handle this accordingly. |
|
| 951 | + * |
|
| 952 | + * @access protected |
|
| 953 | + * @abstract |
|
| 954 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 955 | + * @param object $post The post object of the cpt that was saved. |
|
| 956 | + * @return void |
|
| 957 | + */ |
|
| 958 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 959 | + { |
|
| 960 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 961 | + //get out we're not processing an event save. |
|
| 962 | + return; |
|
| 963 | + } |
|
| 964 | + $event_values = array( |
|
| 965 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 966 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 967 | + 'EVT_additional_limit' => min( |
|
| 968 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 969 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 970 | + ), |
|
| 971 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 972 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 973 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 974 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 975 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 976 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 977 | + ? $this->_req_data['timezone_string'] : null, |
|
| 978 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 979 | + ? $this->_req_data['externalURL'] : null, |
|
| 980 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 981 | + ? $this->_req_data['event_phone'] : null, |
|
| 982 | + ); |
|
| 983 | + //update event |
|
| 984 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 985 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 986 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 987 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 988 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 989 | + $event_update_callbacks = apply_filters( |
|
| 990 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 991 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 992 | + ); |
|
| 993 | + $att_success = true; |
|
| 994 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 995 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 996 | + $att_success = ! $att_success ? $att_success |
|
| 997 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 998 | + } |
|
| 999 | + //any errors? |
|
| 1000 | + if ($success && false === $att_success) { |
|
| 1001 | + EE_Error::add_error( |
|
| 1002 | + esc_html__( |
|
| 1003 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1004 | + 'event_espresso' |
|
| 1005 | + ), |
|
| 1006 | + __FILE__, |
|
| 1007 | + __FUNCTION__, |
|
| 1008 | + __LINE__ |
|
| 1009 | + ); |
|
| 1010 | + } else if ($success === false) { |
|
| 1011 | + EE_Error::add_error( |
|
| 1012 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1013 | + __FILE__, |
|
| 1014 | + __FUNCTION__, |
|
| 1015 | + __LINE__ |
|
| 1016 | + ); |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * @see parent::restore_item() |
|
| 1024 | + * @param int $post_id |
|
| 1025 | + * @param int $revision_id |
|
| 1026 | + */ |
|
| 1027 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1028 | + { |
|
| 1029 | + //copy existing event meta to new post |
|
| 1030 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1031 | + if ($post_evt instanceof EE_Event) { |
|
| 1032 | + //meta revision restore |
|
| 1033 | + $post_evt->restore_revision($revision_id); |
|
| 1034 | + //related objs restore |
|
| 1035 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1036 | + } |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Attach the venue to the Event |
|
| 1043 | + * |
|
| 1044 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1045 | + * @param array $data The request data from the form |
|
| 1046 | + * @return bool Success or fail. |
|
| 1047 | + */ |
|
| 1048 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1049 | + { |
|
| 1050 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1051 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1052 | + $rows_affected = null; |
|
| 1053 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1054 | + // very important. If we don't have a venue name... |
|
| 1055 | + // then we'll get out because not necessary to create empty venue |
|
| 1056 | + if (empty($data['venue_title'])) { |
|
| 1057 | + return false; |
|
| 1058 | + } |
|
| 1059 | + $venue_array = array( |
|
| 1060 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1061 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1062 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1063 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1064 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1065 | + : null, |
|
| 1066 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1067 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1068 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1069 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1070 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1071 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1072 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1073 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1074 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1075 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1076 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1077 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1078 | + 'status' => 'publish', |
|
| 1079 | + ); |
|
| 1080 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1081 | + if ( ! empty($venue_id)) { |
|
| 1082 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1083 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1084 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1085 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1086 | + return $rows_affected > 0 ? true : false; |
|
| 1087 | + } else { |
|
| 1088 | + //we insert the venue |
|
| 1089 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1090 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1091 | + return ! empty($venue_id) ? true : false; |
|
| 1092 | + } |
|
| 1093 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1100 | + * |
|
| 1101 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1102 | + * @param array $data The request data from the form |
|
| 1103 | + * @return array |
|
| 1104 | + */ |
|
| 1105 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1106 | + { |
|
| 1107 | + $success = true; |
|
| 1108 | + $saved_dtt = null; |
|
| 1109 | + $saved_tickets = array(); |
|
| 1110 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1111 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1112 | + //trim all values to ensure any excess whitespace is removed. |
|
| 1113 | + $dtt = array_map('trim', $dtt); |
|
| 1114 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1115 | + : $dtt['DTT_EVT_start']; |
|
| 1116 | + $datetime_values = array( |
|
| 1117 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1118 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1119 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1120 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1121 | + 'DTT_order' => $row, |
|
| 1122 | + ); |
|
| 1123 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1124 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1125 | + $DTM = EE_Registry::instance() |
|
| 1126 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1127 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1128 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1129 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1130 | + foreach ($datetime_values as $field => $value) { |
|
| 1131 | + $DTM->set($field, $value); |
|
| 1132 | + } |
|
| 1133 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1134 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1135 | + } else { |
|
| 1136 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1137 | + 'Datetime', |
|
| 1138 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1139 | + false, |
|
| 1140 | + false |
|
| 1141 | + ); |
|
| 1142 | + foreach ($datetime_values as $field => $value) { |
|
| 1143 | + $DTM->set($field, $value); |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + $DTM->save(); |
|
| 1147 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1148 | + //load DTT helper |
|
| 1149 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1150 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1151 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1152 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1153 | + $DTT->save(); |
|
| 1154 | + } |
|
| 1155 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1156 | + $saved_dtt = $DTT; |
|
| 1157 | + $success = ! $success ? $success : $DTT; |
|
| 1158 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1159 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1160 | + } |
|
| 1161 | + //no dtts get deleted so we don't do any of that logic here. |
|
| 1162 | + //update tickets next |
|
| 1163 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1164 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1165 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1166 | + $update_prices = false; |
|
| 1167 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1168 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1169 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1170 | + $tkt = array_map('trim', $tkt); |
|
| 1171 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1172 | + //let's use now in the set timezone. |
|
| 1173 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1174 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1175 | + } |
|
| 1176 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1177 | + //use the start date of the first datetime |
|
| 1178 | + $dtt = $evtobj->first_datetime(); |
|
| 1179 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1180 | + $incoming_date_formats[0], |
|
| 1181 | + $incoming_date_formats[1] |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + $TKT_values = array( |
|
| 1185 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1186 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1187 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1188 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1189 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1190 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1191 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1192 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1193 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1194 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1195 | + 'TKT_row' => $row, |
|
| 1196 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1197 | + 'TKT_price' => $ticket_price, |
|
| 1198 | + ); |
|
| 1199 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1200 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1201 | + $TKT_values['TKT_ID'] = 0; |
|
| 1202 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1203 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1204 | + $update_prices = true; |
|
| 1205 | + } |
|
| 1206 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1207 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1208 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1209 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1210 | + $TKT = EE_Registry::instance() |
|
| 1211 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1212 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1213 | + if ($TKT instanceof EE_Ticket) { |
|
| 1214 | + $ticket_sold = $TKT->count_related( |
|
| 1215 | + 'Registration', |
|
| 1216 | + array( |
|
| 1217 | + array( |
|
| 1218 | + 'STS_ID' => array( |
|
| 1219 | + 'NOT IN', |
|
| 1220 | + array(EEM_Registration::status_id_incomplete), |
|
| 1221 | + ), |
|
| 1222 | + ), |
|
| 1223 | + ) |
|
| 1224 | + ) > 0 ? true : false; |
|
| 1225 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1226 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1227 | + && ! $TKT->get( |
|
| 1228 | + 'TKT_deleted' |
|
| 1229 | + ) ? true : false; |
|
| 1230 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1231 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1232 | + //set new values |
|
| 1233 | + foreach ($TKT_values as $field => $value) { |
|
| 1234 | + if ($field == 'TKT_qty') { |
|
| 1235 | + $TKT->set_qty($value); |
|
| 1236 | + } else { |
|
| 1237 | + $TKT->set($field, $value); |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1241 | + if ($create_new_TKT) { |
|
| 1242 | + //archive the old ticket first |
|
| 1243 | + $TKT->set('TKT_deleted', 1); |
|
| 1244 | + $TKT->save(); |
|
| 1245 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1246 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1247 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1248 | + $TKT = clone $TKT; |
|
| 1249 | + $TKT->set('TKT_ID', 0); |
|
| 1250 | + $TKT->set('TKT_deleted', 0); |
|
| 1251 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1252 | + $TKT->set('TKT_sold', 0); |
|
| 1253 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1254 | + $update_prices = true; |
|
| 1255 | + } |
|
| 1256 | + //make sure price is set if it hasn't been already |
|
| 1257 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1258 | + } |
|
| 1259 | + } else { |
|
| 1260 | + //no TKT_id so a new TKT |
|
| 1261 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1262 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1263 | + if ($TKT instanceof EE_Ticket) { |
|
| 1264 | + //need to reset values to properly account for the date formats |
|
| 1265 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1266 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1267 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1268 | + //set new values |
|
| 1269 | + foreach ($TKT_values as $field => $value) { |
|
| 1270 | + if ($field == 'TKT_qty') { |
|
| 1271 | + $TKT->set_qty($value); |
|
| 1272 | + } else { |
|
| 1273 | + $TKT->set($field, $value); |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + $update_prices = true; |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + // cap ticket qty by datetime reg limits |
|
| 1280 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1281 | + //update ticket. |
|
| 1282 | + $TKT->save(); |
|
| 1283 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1284 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1285 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1286 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1287 | + $TKT->save(); |
|
| 1288 | + } |
|
| 1289 | + //initially let's add the ticket to the dtt |
|
| 1290 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1291 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1292 | + //add prices to ticket |
|
| 1293 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1294 | + } |
|
| 1295 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1296 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1297 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1298 | + foreach ($tickets_removed as $id) { |
|
| 1299 | + $id = absint($id); |
|
| 1300 | + //get the ticket for this id |
|
| 1301 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1302 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1303 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1304 | + foreach ($dtts as $dtt) { |
|
| 1305 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1306 | + } |
|
| 1307 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1308 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1309 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1310 | + $tkt_to_remove->delete_permanently(); |
|
| 1311 | + } |
|
| 1312 | + return array($saved_dtt, $saved_tickets); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * This attaches a list of given prices to a ticket. |
|
| 1319 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1320 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1321 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1322 | + * |
|
| 1323 | + * @access private |
|
| 1324 | + * @param array $prices Array of prices from the form. |
|
| 1325 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1326 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1327 | + * @return void |
|
| 1328 | + */ |
|
| 1329 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1330 | + { |
|
| 1331 | + foreach ($prices as $row => $prc) { |
|
| 1332 | + $PRC_values = array( |
|
| 1333 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1334 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1335 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1336 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1337 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1338 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1339 | + 'PRC_order' => $row, |
|
| 1340 | + ); |
|
| 1341 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1342 | + $PRC_values['PRC_ID'] = 0; |
|
| 1343 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1344 | + } else { |
|
| 1345 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1346 | + //update this price with new values |
|
| 1347 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1348 | + $PRC->set($field, $newprc); |
|
| 1349 | + } |
|
| 1350 | + $PRC->save(); |
|
| 1351 | + } |
|
| 1352 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1353 | + } |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + /** |
|
| 1359 | + * Add in our autosave ajax handlers |
|
| 1360 | + * |
|
| 1361 | + * @return void |
|
| 1362 | + */ |
|
| 1363 | + protected function _ee_autosave_create_new() |
|
| 1364 | + { |
|
| 1365 | + // $this->_ee_autosave_edit(); |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + |
|
| 1370 | + protected function _ee_autosave_edit() |
|
| 1371 | + { |
|
| 1372 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + /** |
|
| 1378 | + * _generate_publish_box_extra_content |
|
| 1379 | + * |
|
| 1380 | + * @access private |
|
| 1381 | + * @return void |
|
| 1382 | + */ |
|
| 1383 | + private function _generate_publish_box_extra_content() |
|
| 1384 | + { |
|
| 1385 | + //load formatter helper |
|
| 1386 | + //args for getting related registrations |
|
| 1387 | + $approved_query_args = array( |
|
| 1388 | + array( |
|
| 1389 | + 'REG_deleted' => 0, |
|
| 1390 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1391 | + ), |
|
| 1392 | + ); |
|
| 1393 | + $not_approved_query_args = array( |
|
| 1394 | + array( |
|
| 1395 | + 'REG_deleted' => 0, |
|
| 1396 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1397 | + ), |
|
| 1398 | + ); |
|
| 1399 | + $pending_payment_query_args = array( |
|
| 1400 | + array( |
|
| 1401 | + 'REG_deleted' => 0, |
|
| 1402 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1403 | + ), |
|
| 1404 | + ); |
|
| 1405 | + // publish box |
|
| 1406 | + $publish_box_extra_args = array( |
|
| 1407 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1408 | + array( |
|
| 1409 | + 'action' => 'default', |
|
| 1410 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1411 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1412 | + ), |
|
| 1413 | + REG_ADMIN_URL |
|
| 1414 | + ), |
|
| 1415 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1416 | + array( |
|
| 1417 | + 'action' => 'default', |
|
| 1418 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1419 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1420 | + ), |
|
| 1421 | + REG_ADMIN_URL |
|
| 1422 | + ), |
|
| 1423 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1424 | + array( |
|
| 1425 | + 'action' => 'default', |
|
| 1426 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1427 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1428 | + ), |
|
| 1429 | + REG_ADMIN_URL |
|
| 1430 | + ), |
|
| 1431 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1432 | + 'Registration', |
|
| 1433 | + $approved_query_args |
|
| 1434 | + ), |
|
| 1435 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | + 'Registration', |
|
| 1437 | + $not_approved_query_args |
|
| 1438 | + ), |
|
| 1439 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | + 'Registration', |
|
| 1441 | + $pending_payment_query_args |
|
| 1442 | + ), |
|
| 1443 | + 'misc_pub_section_class' => apply_filters( |
|
| 1444 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1445 | + 'misc-pub-section' |
|
| 1446 | + ), |
|
| 1447 | + //'email_attendees_url' => add_query_arg( |
|
| 1448 | + // array( |
|
| 1449 | + // 'event_admin_reports' => 'event_newsletter', |
|
| 1450 | + // 'event_id' => $this->_cpt_model_obj->id |
|
| 1451 | + // ), |
|
| 1452 | + // 'admin.php?page=espresso_registrations' |
|
| 1453 | + //), |
|
| 1454 | + ); |
|
| 1455 | + ob_start(); |
|
| 1456 | + do_action( |
|
| 1457 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1458 | + $this->_cpt_model_obj |
|
| 1459 | + ); |
|
| 1460 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1461 | + // load template |
|
| 1462 | + EEH_Template::display_template( |
|
| 1463 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1464 | + $publish_box_extra_args |
|
| 1465 | + ); |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * This just returns whatever is set as the _event object property |
|
| 1472 | + * //todo this will become obsolete once the models are in place |
|
| 1473 | + * |
|
| 1474 | + * @return object |
|
| 1475 | + */ |
|
| 1476 | + public function get_event_object() |
|
| 1477 | + { |
|
| 1478 | + return $this->_cpt_model_obj; |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + |
|
| 1482 | + |
|
| 1483 | + |
|
| 1484 | + /** METABOXES * */ |
|
| 1485 | + /** |
|
| 1486 | + * _register_event_editor_meta_boxes |
|
| 1487 | + * add all metaboxes related to the event_editor |
|
| 1488 | + * |
|
| 1489 | + * @return void |
|
| 1490 | + */ |
|
| 1491 | + protected function _register_event_editor_meta_boxes() |
|
| 1492 | + { |
|
| 1493 | + $this->verify_cpt_object(); |
|
| 1494 | + add_meta_box( |
|
| 1495 | + 'espresso_event_editor_tickets', |
|
| 1496 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1497 | + array($this, 'ticket_metabox'), |
|
| 1498 | + $this->page_slug, |
|
| 1499 | + 'normal', |
|
| 1500 | + 'high' |
|
| 1501 | + ); |
|
| 1502 | + add_meta_box( |
|
| 1503 | + 'espresso_event_editor_event_options', |
|
| 1504 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1505 | + array($this, 'registration_options_meta_box'), |
|
| 1506 | + $this->page_slug, |
|
| 1507 | + 'side', |
|
| 1508 | + 'default' |
|
| 1509 | + ); |
|
| 1510 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1511 | + // where a metabox has a related management page in the admin |
|
| 1512 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1513 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + |
|
| 1517 | + |
|
| 1518 | + public function ticket_metabox() |
|
| 1519 | + { |
|
| 1520 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1521 | + //defaults for template args |
|
| 1522 | + $template_args = array( |
|
| 1523 | + 'existing_datetime_ids' => '', |
|
| 1524 | + 'event_datetime_help_link' => '', |
|
| 1525 | + 'ticket_options_help_link' => '', |
|
| 1526 | + 'time' => null, |
|
| 1527 | + 'ticket_rows' => '', |
|
| 1528 | + 'existing_ticket_ids' => '', |
|
| 1529 | + 'total_ticket_rows' => 1, |
|
| 1530 | + 'ticket_js_structure' => '', |
|
| 1531 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1532 | + 'disabled' => '', |
|
| 1533 | + ); |
|
| 1534 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1535 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1536 | + /** |
|
| 1537 | + * 1. Start with retrieving Datetimes |
|
| 1538 | + * 2. Fore each datetime get related tickets |
|
| 1539 | + * 3. For each ticket get related prices |
|
| 1540 | + */ |
|
| 1541 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1542 | + /** @type EE_Datetime $first_datetime */ |
|
| 1543 | + $first_datetime = reset($times); |
|
| 1544 | + //do we get related tickets? |
|
| 1545 | + if ($first_datetime instanceof EE_Datetime |
|
| 1546 | + && $first_datetime->ID() !== 0 |
|
| 1547 | + ) { |
|
| 1548 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1549 | + $template_args['time'] = $first_datetime; |
|
| 1550 | + $related_tickets = $first_datetime->tickets( |
|
| 1551 | + array( |
|
| 1552 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1553 | + 'default_where_conditions' => 'none', |
|
| 1554 | + ) |
|
| 1555 | + ); |
|
| 1556 | + if ( ! empty($related_tickets)) { |
|
| 1557 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1558 | + $row = 0; |
|
| 1559 | + foreach ($related_tickets as $ticket) { |
|
| 1560 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1561 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1562 | + $row++; |
|
| 1563 | + } |
|
| 1564 | + } else { |
|
| 1565 | + $template_args['total_ticket_rows'] = 1; |
|
| 1566 | + /** @type EE_Ticket $ticket */ |
|
| 1567 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1568 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1569 | + } |
|
| 1570 | + } else { |
|
| 1571 | + $template_args['time'] = $times[0]; |
|
| 1572 | + /** @type EE_Ticket $ticket */ |
|
| 1573 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1574 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1575 | + // NOTE: we're just sending the first default row |
|
| 1576 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1577 | + } |
|
| 1578 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1579 | + 'event_editor_event_datetimes_help_tab' |
|
| 1580 | + ); |
|
| 1581 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1582 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1583 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1584 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1585 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1586 | + true |
|
| 1587 | + ); |
|
| 1588 | + $template = apply_filters( |
|
| 1589 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1590 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1591 | + ); |
|
| 1592 | + EEH_Template::display_template($template, $template_args); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1599 | + * |
|
| 1600 | + * @access private |
|
| 1601 | + * @param EE_Ticket $ticket the ticket object |
|
| 1602 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1603 | + * @param int $row |
|
| 1604 | + * @return string generated html for the ticket row. |
|
| 1605 | + */ |
|
| 1606 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1607 | + { |
|
| 1608 | + $template_args = array( |
|
| 1609 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1610 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1611 | + : '', |
|
| 1612 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1613 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1614 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1615 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1616 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1617 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1618 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1619 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1620 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1621 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1622 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1623 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1624 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1625 | + : ' disabled=disabled', |
|
| 1626 | + ); |
|
| 1627 | + $price = $ticket->ID() !== 0 |
|
| 1628 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1629 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1630 | + $price_args = array( |
|
| 1631 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1632 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1633 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1634 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1635 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1636 | + ); |
|
| 1637 | + //make sure we have default start and end dates if skeleton |
|
| 1638 | + //handle rows that should NOT be empty |
|
| 1639 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1640 | + //if empty then the start date will be now. |
|
| 1641 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1642 | + } |
|
| 1643 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1644 | + //get the earliest datetime (if present); |
|
| 1645 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1646 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1647 | + 'Datetime', |
|
| 1648 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1649 | + ) |
|
| 1650 | + : null; |
|
| 1651 | + if ( ! empty($earliest_dtt)) { |
|
| 1652 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1653 | + } else { |
|
| 1654 | + $template_args['TKT_end_date'] = date( |
|
| 1655 | + 'Y-m-d h:i a', |
|
| 1656 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1657 | + ); |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + $template_args = array_merge($template_args, $price_args); |
|
| 1661 | + $template = apply_filters( |
|
| 1662 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1663 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1664 | + $ticket |
|
| 1665 | + ); |
|
| 1666 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + |
|
| 1670 | + |
|
| 1671 | + public function registration_options_meta_box() |
|
| 1672 | + { |
|
| 1673 | + $yes_no_values = array( |
|
| 1674 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1675 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1676 | + ); |
|
| 1677 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1678 | + array( |
|
| 1679 | + EEM_Registration::status_id_cancelled, |
|
| 1680 | + EEM_Registration::status_id_declined, |
|
| 1681 | + EEM_Registration::status_id_incomplete, |
|
| 1682 | + ), |
|
| 1683 | + true |
|
| 1684 | + ); |
|
| 1685 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1686 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1687 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1688 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1689 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1690 | + 'default_reg_status', |
|
| 1691 | + $default_reg_status_values, |
|
| 1692 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1693 | + ); |
|
| 1694 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1695 | + 'display_desc', |
|
| 1696 | + $yes_no_values, |
|
| 1697 | + $this->_cpt_model_obj->display_description() |
|
| 1698 | + ); |
|
| 1699 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1700 | + 'display_ticket_selector', |
|
| 1701 | + $yes_no_values, |
|
| 1702 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1703 | + '', |
|
| 1704 | + '', |
|
| 1705 | + false |
|
| 1706 | + ); |
|
| 1707 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1708 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1709 | + '', |
|
| 1710 | + $template_args, |
|
| 1711 | + $yes_no_values, |
|
| 1712 | + $default_reg_status_values |
|
| 1713 | + ); |
|
| 1714 | + EEH_Template::display_template( |
|
| 1715 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1716 | + $template_args |
|
| 1717 | + ); |
|
| 1718 | + } |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * _get_events() |
|
| 1724 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1725 | + * |
|
| 1726 | + * @access public |
|
| 1727 | + * @param int $per_page count of items per page (20 default); |
|
| 1728 | + * @param int $current_page what is the current page being viewed. |
|
| 1729 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1730 | + * If FALSE then we return an array of event objects |
|
| 1731 | + * that match the given _view and paging parameters. |
|
| 1732 | + * @return array an array of event objects. |
|
| 1733 | + */ |
|
| 1734 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1735 | + { |
|
| 1736 | + $EEME = $this->_event_model(); |
|
| 1737 | + $offset = ($current_page - 1) * $per_page; |
|
| 1738 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1739 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1740 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1741 | + if (isset($this->_req_data['month_range'])) { |
|
| 1742 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1743 | + //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1744 | + //where PHP doesn't know what to assume for date. |
|
| 1745 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1746 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1747 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1748 | + } |
|
| 1749 | + $where = array(); |
|
| 1750 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1751 | + //determine what post_status our condition will have for the query. |
|
| 1752 | + switch ($status) { |
|
| 1753 | + case 'month' : |
|
| 1754 | + case 'today' : |
|
| 1755 | + case null : |
|
| 1756 | + case 'all' : |
|
| 1757 | + break; |
|
| 1758 | + case 'draft' : |
|
| 1759 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1760 | + break; |
|
| 1761 | + default : |
|
| 1762 | + $where['status'] = $status; |
|
| 1763 | + } |
|
| 1764 | + //categories? |
|
| 1765 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1766 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1767 | + if ( ! empty ($category)) { |
|
| 1768 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1769 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1770 | + } |
|
| 1771 | + //date where conditions |
|
| 1772 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1773 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1774 | + $DateTime = new DateTime( |
|
| 1775 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1776 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1777 | + ); |
|
| 1778 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1779 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1780 | + ->format('t'))->setTime(23, 59, 59) |
|
| 1781 | + ->format(implode(' ', $start_formats)); |
|
| 1782 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1783 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1784 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1785 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1786 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1787 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1788 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1789 | + $now = date('Y-m-01'); |
|
| 1790 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1791 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1792 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1793 | + ->setTime(23, 59, 59) |
|
| 1794 | + ->format(implode(' ', $start_formats)); |
|
| 1795 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1796 | + } |
|
| 1797 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1798 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1799 | + } else { |
|
| 1800 | + if ( ! isset($where['status'])) { |
|
| 1801 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1802 | + $where['OR'] = array( |
|
| 1803 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1804 | + 'AND' => array( |
|
| 1805 | + 'status*inclusive' => array('=', 'private'), |
|
| 1806 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1807 | + ), |
|
| 1808 | + ); |
|
| 1809 | + } |
|
| 1810 | + } |
|
| 1811 | + } |
|
| 1812 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1813 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1814 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1815 | + ) { |
|
| 1816 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1817 | + } |
|
| 1818 | + } |
|
| 1819 | + //search query handling |
|
| 1820 | + if (isset($this->_req_data['s'])) { |
|
| 1821 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1822 | + $where['OR'] = array( |
|
| 1823 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1824 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1825 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1826 | + ); |
|
| 1827 | + } |
|
| 1828 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1829 | + $query_params = apply_filters( |
|
| 1830 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1831 | + array( |
|
| 1832 | + $where, |
|
| 1833 | + 'limit' => $limit, |
|
| 1834 | + 'order_by' => $orderby, |
|
| 1835 | + 'order' => $order, |
|
| 1836 | + 'group_by' => 'EVT_ID', |
|
| 1837 | + ), |
|
| 1838 | + $this->_req_data |
|
| 1839 | + ); |
|
| 1840 | + //let's first check if we have special requests coming in. |
|
| 1841 | + if (isset($this->_req_data['active_status'])) { |
|
| 1842 | + switch ($this->_req_data['active_status']) { |
|
| 1843 | + case 'upcoming' : |
|
| 1844 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1845 | + break; |
|
| 1846 | + case 'expired' : |
|
| 1847 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1848 | + break; |
|
| 1849 | + case 'active' : |
|
| 1850 | + return $EEME->get_active_events($query_params, $count); |
|
| 1851 | + break; |
|
| 1852 | + case 'inactive' : |
|
| 1853 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1854 | + break; |
|
| 1855 | + } |
|
| 1856 | + } |
|
| 1857 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1858 | + return $events; |
|
| 1859 | + } |
|
| 1860 | + |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1865 | + * |
|
| 1866 | + * @param string $post_id |
|
| 1867 | + */ |
|
| 1868 | + public function trash_cpt_item($post_id) |
|
| 1869 | + { |
|
| 1870 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1871 | + $this->_trash_or_restore_event('trash', false); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + |
|
| 1875 | + |
|
| 1876 | + /** |
|
| 1877 | + * @param string $post_id |
|
| 1878 | + */ |
|
| 1879 | + public function restore_cpt_item($post_id) |
|
| 1880 | + { |
|
| 1881 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1882 | + $this->_trash_or_restore_event('draft', false); |
|
| 1883 | + } |
|
| 1884 | + |
|
| 1885 | + |
|
| 1886 | + |
|
| 1887 | + /** |
|
| 1888 | + * @param string $post_id |
|
| 1889 | + */ |
|
| 1890 | + public function delete_cpt_item($post_id) |
|
| 1891 | + { |
|
| 1892 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1893 | + $this->_delete_event(false); |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + |
|
| 1897 | + |
|
| 1898 | + /** |
|
| 1899 | + * _trash_or_restore_event |
|
| 1900 | + * |
|
| 1901 | + * @access protected |
|
| 1902 | + * @param string $event_status |
|
| 1903 | + * @param bool $redirect_after |
|
| 1904 | + */ |
|
| 1905 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1906 | + { |
|
| 1907 | + //determine the event id and set to array. |
|
| 1908 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1909 | + // loop thru events |
|
| 1910 | + if ($EVT_ID) { |
|
| 1911 | + // clean status |
|
| 1912 | + $event_status = sanitize_key($event_status); |
|
| 1913 | + // grab status |
|
| 1914 | + if ( ! empty($event_status)) { |
|
| 1915 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1916 | + } else { |
|
| 1917 | + $success = false; |
|
| 1918 | + $msg = esc_html__( |
|
| 1919 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1920 | + 'event_espresso' |
|
| 1921 | + ); |
|
| 1922 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1923 | + } |
|
| 1924 | + } else { |
|
| 1925 | + $success = false; |
|
| 1926 | + $msg = esc_html__( |
|
| 1927 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1928 | + 'event_espresso' |
|
| 1929 | + ); |
|
| 1930 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1931 | + } |
|
| 1932 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1933 | + if ($redirect_after) { |
|
| 1934 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * _trash_or_restore_events |
|
| 1942 | + * |
|
| 1943 | + * @access protected |
|
| 1944 | + * @param string $event_status |
|
| 1945 | + * @return void |
|
| 1946 | + */ |
|
| 1947 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1948 | + { |
|
| 1949 | + // clean status |
|
| 1950 | + $event_status = sanitize_key($event_status); |
|
| 1951 | + // grab status |
|
| 1952 | + if ( ! empty($event_status)) { |
|
| 1953 | + $success = true; |
|
| 1954 | + //determine the event id and set to array. |
|
| 1955 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1956 | + // loop thru events |
|
| 1957 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 1958 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 1959 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1960 | + $success = $results !== false ? $success : false; |
|
| 1961 | + } else { |
|
| 1962 | + $msg = sprintf( |
|
| 1963 | + esc_html__( |
|
| 1964 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1965 | + 'event_espresso' |
|
| 1966 | + ), |
|
| 1967 | + $EVT_ID |
|
| 1968 | + ); |
|
| 1969 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1970 | + $success = false; |
|
| 1971 | + } |
|
| 1972 | + } |
|
| 1973 | + } else { |
|
| 1974 | + $success = false; |
|
| 1975 | + $msg = esc_html__( |
|
| 1976 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1977 | + 'event_espresso' |
|
| 1978 | + ); |
|
| 1979 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1980 | + } |
|
| 1981 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1982 | + $success = $success ? 2 : false; |
|
| 1983 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1984 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1985 | + } |
|
| 1986 | + |
|
| 1987 | + |
|
| 1988 | + |
|
| 1989 | + /** |
|
| 1990 | + * _trash_or_restore_events |
|
| 1991 | + * |
|
| 1992 | + * @access private |
|
| 1993 | + * @param int $EVT_ID |
|
| 1994 | + * @param string $event_status |
|
| 1995 | + * @return bool |
|
| 1996 | + */ |
|
| 1997 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1998 | + { |
|
| 1999 | + // grab event id |
|
| 2000 | + if ( ! $EVT_ID) { |
|
| 2001 | + $msg = esc_html__( |
|
| 2002 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2003 | + 'event_espresso' |
|
| 2004 | + ); |
|
| 2005 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2006 | + return false; |
|
| 2007 | + } |
|
| 2008 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2009 | + // clean status |
|
| 2010 | + $event_status = sanitize_key($event_status); |
|
| 2011 | + // grab status |
|
| 2012 | + if (empty($event_status)) { |
|
| 2013 | + $msg = esc_html__( |
|
| 2014 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2015 | + 'event_espresso' |
|
| 2016 | + ); |
|
| 2017 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2018 | + return false; |
|
| 2019 | + } |
|
| 2020 | + // was event trashed or restored ? |
|
| 2021 | + switch ($event_status) { |
|
| 2022 | + case 'draft' : |
|
| 2023 | + $action = 'restored from the trash'; |
|
| 2024 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2025 | + break; |
|
| 2026 | + case 'trash' : |
|
| 2027 | + $action = 'moved to the trash'; |
|
| 2028 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2029 | + break; |
|
| 2030 | + default : |
|
| 2031 | + $action = 'updated'; |
|
| 2032 | + $hook = false; |
|
| 2033 | + } |
|
| 2034 | + //use class to change status |
|
| 2035 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2036 | + $success = $this->_cpt_model_obj->save(); |
|
| 2037 | + if ($success === false) { |
|
| 2038 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2039 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2040 | + return false; |
|
| 2041 | + } |
|
| 2042 | + if ($hook) { |
|
| 2043 | + do_action($hook); |
|
| 2044 | + } |
|
| 2045 | + return true; |
|
| 2046 | + } |
|
| 2047 | + |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * _delete_event |
|
| 2052 | + * |
|
| 2053 | + * @access protected |
|
| 2054 | + * @param bool $redirect_after |
|
| 2055 | + */ |
|
| 2056 | + protected function _delete_event($redirect_after = true) |
|
| 2057 | + { |
|
| 2058 | + //determine the event id and set to array. |
|
| 2059 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2060 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2061 | + // loop thru events |
|
| 2062 | + if ($EVT_ID) { |
|
| 2063 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2064 | + // get list of events with no prices |
|
| 2065 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2066 | + // remove this event from the list of events with no prices |
|
| 2067 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2068 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2069 | + } |
|
| 2070 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2071 | + } else { |
|
| 2072 | + $success = false; |
|
| 2073 | + $msg = esc_html__( |
|
| 2074 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2075 | + 'event_espresso' |
|
| 2076 | + ); |
|
| 2077 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2078 | + } |
|
| 2079 | + if ($redirect_after) { |
|
| 2080 | + $this->_redirect_after_action( |
|
| 2081 | + $success, |
|
| 2082 | + 'Event', |
|
| 2083 | + 'deleted', |
|
| 2084 | + array('action' => 'default', 'status' => 'trash') |
|
| 2085 | + ); |
|
| 2086 | + } |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * _delete_events |
|
| 2093 | + * |
|
| 2094 | + * @access protected |
|
| 2095 | + * @return void |
|
| 2096 | + */ |
|
| 2097 | + protected function _delete_events() |
|
| 2098 | + { |
|
| 2099 | + $success = true; |
|
| 2100 | + // get list of events with no prices |
|
| 2101 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2102 | + //determine the event id and set to array. |
|
| 2103 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2104 | + // loop thru events |
|
| 2105 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2106 | + $EVT_ID = absint($EVT_ID); |
|
| 2107 | + if ($EVT_ID) { |
|
| 2108 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2109 | + $success = $results !== false ? $success : false; |
|
| 2110 | + // remove this event from the list of events with no prices |
|
| 2111 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2112 | + } else { |
|
| 2113 | + $success = false; |
|
| 2114 | + $msg = esc_html__( |
|
| 2115 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2116 | + 'event_espresso' |
|
| 2117 | + ); |
|
| 2118 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2122 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2123 | + $success = $success ? 2 : false; |
|
| 2124 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + |
|
| 2128 | + |
|
| 2129 | + /** |
|
| 2130 | + * _permanently_delete_event |
|
| 2131 | + * |
|
| 2132 | + * @access private |
|
| 2133 | + * @param int $EVT_ID |
|
| 2134 | + * @return bool |
|
| 2135 | + */ |
|
| 2136 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2137 | + { |
|
| 2138 | + // grab event id |
|
| 2139 | + if ( ! $EVT_ID) { |
|
| 2140 | + $msg = esc_html__( |
|
| 2141 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2142 | + 'event_espresso' |
|
| 2143 | + ); |
|
| 2144 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2145 | + return false; |
|
| 2146 | + } |
|
| 2147 | + if ( |
|
| 2148 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2149 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2150 | + ) { |
|
| 2151 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2152 | + } |
|
| 2153 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2154 | + return false; |
|
| 2155 | + } |
|
| 2156 | + //need to delete related tickets and prices first. |
|
| 2157 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2158 | + foreach ($datetimes as $datetime) { |
|
| 2159 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2160 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2161 | + foreach ($tickets as $ticket) { |
|
| 2162 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2163 | + $ticket->delete_related_permanently('Price'); |
|
| 2164 | + $ticket->delete_permanently(); |
|
| 2165 | + } |
|
| 2166 | + $datetime->delete(); |
|
| 2167 | + } |
|
| 2168 | + //what about related venues or terms? |
|
| 2169 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2170 | + foreach ($venues as $venue) { |
|
| 2171 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2172 | + } |
|
| 2173 | + //any attached question groups? |
|
| 2174 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2175 | + if ( ! empty($question_groups)) { |
|
| 2176 | + foreach ($question_groups as $question_group) { |
|
| 2177 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2178 | + } |
|
| 2179 | + } |
|
| 2180 | + //Message Template Groups |
|
| 2181 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2182 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2183 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2184 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2185 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2186 | + } |
|
| 2187 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2188 | + // did it all go as planned ? |
|
| 2189 | + if ($success) { |
|
| 2190 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2191 | + EE_Error::add_success($msg); |
|
| 2192 | + } else { |
|
| 2193 | + $msg = sprintf( |
|
| 2194 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2195 | + $EVT_ID |
|
| 2196 | + ); |
|
| 2197 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2198 | + return false; |
|
| 2199 | + } |
|
| 2200 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2201 | + return true; |
|
| 2202 | + } |
|
| 2203 | + |
|
| 2204 | + |
|
| 2205 | + |
|
| 2206 | + /** |
|
| 2207 | + * get total number of events |
|
| 2208 | + * |
|
| 2209 | + * @access public |
|
| 2210 | + * @return int |
|
| 2211 | + */ |
|
| 2212 | + public function total_events() |
|
| 2213 | + { |
|
| 2214 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2215 | + return $count; |
|
| 2216 | + } |
|
| 2217 | + |
|
| 2218 | + |
|
| 2219 | + |
|
| 2220 | + /** |
|
| 2221 | + * get total number of draft events |
|
| 2222 | + * |
|
| 2223 | + * @access public |
|
| 2224 | + * @return int |
|
| 2225 | + */ |
|
| 2226 | + public function total_events_draft() |
|
| 2227 | + { |
|
| 2228 | + $where = array( |
|
| 2229 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2230 | + ); |
|
| 2231 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2232 | + return $count; |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + |
|
| 2236 | + |
|
| 2237 | + /** |
|
| 2238 | + * get total number of trashed events |
|
| 2239 | + * |
|
| 2240 | + * @access public |
|
| 2241 | + * @return int |
|
| 2242 | + */ |
|
| 2243 | + public function total_trashed_events() |
|
| 2244 | + { |
|
| 2245 | + $where = array( |
|
| 2246 | + 'status' => 'trash', |
|
| 2247 | + ); |
|
| 2248 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2249 | + return $count; |
|
| 2250 | + } |
|
| 2251 | + |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * _default_event_settings |
|
| 2256 | + * This generates the Default Settings Tab |
|
| 2257 | + * |
|
| 2258 | + * @return void |
|
| 2259 | + */ |
|
| 2260 | + protected function _default_event_settings() |
|
| 2261 | + { |
|
| 2262 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2263 | + $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2264 | + // exclude array |
|
| 2265 | + array( |
|
| 2266 | + EEM_Registration::status_id_cancelled, |
|
| 2267 | + EEM_Registration::status_id_declined, |
|
| 2268 | + EEM_Registration::status_id_incomplete, |
|
| 2269 | + EEM_Registration::status_id_wait_list, |
|
| 2270 | + ), |
|
| 2271 | + // translated |
|
| 2272 | + true |
|
| 2273 | + ); |
|
| 2274 | + $this->_template_args['default_reg_status'] = isset( |
|
| 2275 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2276 | + ) |
|
| 2277 | + && array_key_exists( |
|
| 2278 | + EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2279 | + $this->_template_args['reg_status_array'] |
|
| 2280 | + ) |
|
| 2281 | + ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2282 | + : EEM_Registration::status_id_pending_payment; |
|
| 2283 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2284 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2285 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2286 | + EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2287 | + $this->_template_args, |
|
| 2288 | + true |
|
| 2289 | + ); |
|
| 2290 | + $this->display_admin_page_with_sidebar(); |
|
| 2291 | + } |
|
| 2292 | + |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + /** |
|
| 2296 | + * _update_default_event_settings |
|
| 2297 | + * |
|
| 2298 | + * @access protected |
|
| 2299 | + * @return void |
|
| 2300 | + */ |
|
| 2301 | + protected function _update_default_event_settings() |
|
| 2302 | + { |
|
| 2303 | + EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2304 | + ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2305 | + : EEM_Registration::status_id_pending_payment; |
|
| 2306 | + $what = 'Default Event Settings'; |
|
| 2307 | + $success = $this->_update_espresso_configuration( |
|
| 2308 | + $what, |
|
| 2309 | + EE_Config::instance(), |
|
| 2310 | + __FILE__, |
|
| 2311 | + __FUNCTION__, |
|
| 2312 | + __LINE__ |
|
| 2313 | + ); |
|
| 2314 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2315 | + } |
|
| 2316 | + |
|
| 2317 | + |
|
| 2318 | + |
|
| 2319 | + /************* Templates *************/ |
|
| 2320 | + protected function _template_settings() |
|
| 2321 | + { |
|
| 2322 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2323 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2324 | + . EVENTS_ASSETS_URL |
|
| 2325 | + . DS |
|
| 2326 | + . 'images' |
|
| 2327 | + . DS |
|
| 2328 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2329 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2330 | + . '" />'; |
|
| 2331 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2332 | + 'Template Settings 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. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2333 | + 'event_espresso' |
|
| 2334 | + ) . '</strong>'; |
|
| 2335 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2336 | + } |
|
| 2337 | + |
|
| 2338 | + |
|
| 2339 | + /** Event Category Stuff **/ |
|
| 2340 | + /** |
|
| 2341 | + * set the _category property with the category object for the loaded page. |
|
| 2342 | + * |
|
| 2343 | + * @access private |
|
| 2344 | + * @return void |
|
| 2345 | + */ |
|
| 2346 | + private function _set_category_object() |
|
| 2347 | + { |
|
| 2348 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2349 | + return; |
|
| 2350 | + } //already have the category object so get out. |
|
| 2351 | + //set default category object |
|
| 2352 | + $this->_set_empty_category_object(); |
|
| 2353 | + //only set if we've got an id |
|
| 2354 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2355 | + return; |
|
| 2356 | + } |
|
| 2357 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2358 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2359 | + if ( ! empty($term)) { |
|
| 2360 | + $this->_category->category_name = $term->name; |
|
| 2361 | + $this->_category->category_identifier = $term->slug; |
|
| 2362 | + $this->_category->category_desc = $term->description; |
|
| 2363 | + $this->_category->id = $term->term_id; |
|
| 2364 | + $this->_category->parent = $term->parent; |
|
| 2365 | + } |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + |
|
| 2369 | + |
|
| 2370 | + private function _set_empty_category_object() |
|
| 2371 | + { |
|
| 2372 | + $this->_category = new stdClass(); |
|
| 2373 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2374 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2375 | + } |
|
| 2376 | + |
|
| 2377 | + |
|
| 2378 | + |
|
| 2379 | + protected function _category_list_table() |
|
| 2380 | + { |
|
| 2381 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2382 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2383 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2384 | + 'add_category', |
|
| 2385 | + 'add_category', |
|
| 2386 | + array(), |
|
| 2387 | + 'add-new-h2' |
|
| 2388 | + ); |
|
| 2389 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2390 | + } |
|
| 2391 | + |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * @param $view |
|
| 2396 | + */ |
|
| 2397 | + protected function _category_details($view) |
|
| 2398 | + { |
|
| 2399 | + //load formatter helper |
|
| 2400 | + //load field generator helper |
|
| 2401 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2402 | + $this->_set_add_edit_form_tags($route); |
|
| 2403 | + $this->_set_category_object(); |
|
| 2404 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2405 | + $delete_action = 'delete_category'; |
|
| 2406 | + //custom redirect |
|
| 2407 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2408 | + array('action' => 'category_list'), |
|
| 2409 | + $this->_admin_base_url |
|
| 2410 | + ); |
|
| 2411 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2412 | + //take care of contents |
|
| 2413 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2414 | + $this->display_admin_page_with_sidebar(); |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * @return mixed |
|
| 2421 | + */ |
|
| 2422 | + protected function _category_details_content() |
|
| 2423 | + { |
|
| 2424 | + $editor_args['category_desc'] = array( |
|
| 2425 | + 'type' => 'wp_editor', |
|
| 2426 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2427 | + 'class' => 'my_editor_custom', |
|
| 2428 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2429 | + ); |
|
| 2430 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2431 | + $all_terms = get_terms( |
|
| 2432 | + array('espresso_event_categories'), |
|
| 2433 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2434 | + ); |
|
| 2435 | + //setup category select for term parents. |
|
| 2436 | + $category_select_values[] = array( |
|
| 2437 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2438 | + 'id' => 0, |
|
| 2439 | + ); |
|
| 2440 | + foreach ($all_terms as $term) { |
|
| 2441 | + $category_select_values[] = array( |
|
| 2442 | + 'text' => $term->name, |
|
| 2443 | + 'id' => $term->term_id, |
|
| 2444 | + ); |
|
| 2445 | + } |
|
| 2446 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2447 | + 'category_parent', |
|
| 2448 | + $category_select_values, |
|
| 2449 | + $this->_category->parent |
|
| 2450 | + ); |
|
| 2451 | + $template_args = array( |
|
| 2452 | + 'category' => $this->_category, |
|
| 2453 | + 'category_select' => $category_select, |
|
| 2454 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2455 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2456 | + 'disable' => '', |
|
| 2457 | + 'disabled_message' => false, |
|
| 2458 | + ); |
|
| 2459 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2460 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + |
|
| 2464 | + |
|
| 2465 | + protected function _delete_categories() |
|
| 2466 | + { |
|
| 2467 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2468 | + : (array)$this->_req_data['category_id']; |
|
| 2469 | + foreach ($cat_ids as $cat_id) { |
|
| 2470 | + $this->_delete_category($cat_id); |
|
| 2471 | + } |
|
| 2472 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2473 | + $query_args = array( |
|
| 2474 | + 'action' => 'category_list', |
|
| 2475 | + ); |
|
| 2476 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + |
|
| 2480 | + |
|
| 2481 | + /** |
|
| 2482 | + * @param $cat_id |
|
| 2483 | + */ |
|
| 2484 | + protected function _delete_category($cat_id) |
|
| 2485 | + { |
|
| 2486 | + $cat_id = absint($cat_id); |
|
| 2487 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * @param $new_category |
|
| 2494 | + */ |
|
| 2495 | + protected function _insert_or_update_category($new_category) |
|
| 2496 | + { |
|
| 2497 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2498 | + $success = 0; //we already have a success message so lets not send another. |
|
| 2499 | + if ($cat_id) { |
|
| 2500 | + $query_args = array( |
|
| 2501 | + 'action' => 'edit_category', |
|
| 2502 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2503 | + ); |
|
| 2504 | + } else { |
|
| 2505 | + $query_args = array('action' => 'add_category'); |
|
| 2506 | + } |
|
| 2507 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2508 | + } |
|
| 2509 | + |
|
| 2510 | + |
|
| 2511 | + |
|
| 2512 | + /** |
|
| 2513 | + * @param bool $update |
|
| 2514 | + * @return bool|mixed|string |
|
| 2515 | + */ |
|
| 2516 | + private function _insert_category($update = false) |
|
| 2517 | + { |
|
| 2518 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2519 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2520 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2521 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2522 | + if (empty($category_name)) { |
|
| 2523 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2524 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2525 | + return false; |
|
| 2526 | + } |
|
| 2527 | + $term_args = array( |
|
| 2528 | + 'name' => $category_name, |
|
| 2529 | + 'description' => $category_desc, |
|
| 2530 | + 'parent' => $category_parent, |
|
| 2531 | + ); |
|
| 2532 | + //was the category_identifier input disabled? |
|
| 2533 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2534 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2535 | + } |
|
| 2536 | + $insert_ids = $update |
|
| 2537 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2538 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2539 | + if ( ! is_array($insert_ids)) { |
|
| 2540 | + $msg = esc_html__( |
|
| 2541 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2542 | + 'event_espresso' |
|
| 2543 | + ); |
|
| 2544 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2545 | + } else { |
|
| 2546 | + $cat_id = $insert_ids['term_id']; |
|
| 2547 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2548 | + EE_Error::add_success($msg); |
|
| 2549 | + } |
|
| 2550 | + return $cat_id; |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + |
|
| 2554 | + |
|
| 2555 | + /** |
|
| 2556 | + * @param int $per_page |
|
| 2557 | + * @param int $current_page |
|
| 2558 | + * @param bool $count |
|
| 2559 | + * @return \EE_Base_Class[]|int |
|
| 2560 | + */ |
|
| 2561 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2562 | + { |
|
| 2563 | + //testing term stuff |
|
| 2564 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2565 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2566 | + $limit = ($current_page - 1) * $per_page; |
|
| 2567 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2568 | + if (isset($this->_req_data['s'])) { |
|
| 2569 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2570 | + $where['OR'] = array( |
|
| 2571 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2572 | + 'description' => array('LIKE', $sstr), |
|
| 2573 | + ); |
|
| 2574 | + } |
|
| 2575 | + $query_params = array( |
|
| 2576 | + $where, |
|
| 2577 | + 'order_by' => array($orderby => $order), |
|
| 2578 | + 'limit' => $limit . ',' . $per_page, |
|
| 2579 | + 'force_join' => array('Term'), |
|
| 2580 | + ); |
|
| 2581 | + $categories = $count |
|
| 2582 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2583 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2584 | + return $categories; |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + |
|
| 2588 | + |
|
| 2589 | + /* end category stuff */ |
|
| 2590 | + /**************/ |
|
| 2591 | 2591 | } |
| 2592 | 2592 | //end class Events_Admin_Page |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | // grab attributes and merge with defaults, then extract |
| 105 | 105 | $attributes = array_merge( (array) $default_espresso_events_shortcode_atts, (array) $attributes ); |
| 106 | 106 | $attributes = \EES_Shortcode::sanitize_attributes( |
| 107 | - $attributes, |
|
| 108 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
| 109 | - array( |
|
| 110 | - 'category_slug' => 'skip_sanitization', |
|
| 111 | - 'show_expired' => 'skip_sanitization', |
|
| 112 | - 'order_by' => 'skip_sanitization', |
|
| 113 | - 'month' => 'skip_sanitization', |
|
| 114 | - 'sort' => 'skip_sanitization', |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 107 | + $attributes, |
|
| 108 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
| 109 | + array( |
|
| 110 | + 'category_slug' => 'skip_sanitization', |
|
| 111 | + 'show_expired' => 'skip_sanitization', |
|
| 112 | + 'order_by' => 'skip_sanitization', |
|
| 113 | + 'month' => 'skip_sanitization', |
|
| 114 | + 'sort' => 'skip_sanitization', |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | 117 | // make sure we use the_excerpt() |
| 118 | 118 | add_filter( 'FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true' ); |
| 119 | 119 | // apply query filters |
@@ -232,9 +232,9 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | - * event_list_css |
|
| 236 | - * |
|
| 237 | - * @param string $event_list_css |
|
| 235 | + * event_list_css |
|
| 236 | + * |
|
| 237 | + * @param string $event_list_css |
|
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | public function event_list_css( $event_list_css = '' ) { |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | * @param WP $WP |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - public function run( WP $WP ) { |
|
| 54 | - if ( did_action( 'pre_get_posts' ) && did_action( 'send_headers' ) ) { |
|
| 53 | + public function run(WP $WP) { |
|
| 54 | + if (did_action('pre_get_posts') && did_action('send_headers')) { |
|
| 55 | 55 | EED_Events_Archive::instance()->event_list(); |
| 56 | 56 | } else { |
| 57 | 57 | // this will trigger the EED_Events_Archive module's event_list() method during the pre_get_posts hook point, |
| 58 | 58 | // this allows us to initialize things, enqueue assets, etc, |
| 59 | 59 | // as well, this saves an instantiation of the module in an array using 'espresso_events' as the key, so that we can retrieve it |
| 60 | - add_action( 'pre_get_posts', array( EED_Events_Archive::instance(), 'event_list' ) ); |
|
| 60 | + add_action('pre_get_posts', array(EED_Events_Archive::instance(), 'event_list')); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * @param array $attributes |
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | - public function process_shortcode( $attributes = array() ) { |
|
| 82 | + public function process_shortcode($attributes = array()) { |
|
| 83 | 83 | // make sure EED_Events_Archive is setup properly |
| 84 | - if ( apply_filters( 'FHEE__fallback_shortcode_processor__EES_Espresso_Events', FALSE )) { |
|
| 84 | + if (apply_filters('FHEE__fallback_shortcode_processor__EES_Espresso_Events', FALSE)) { |
|
| 85 | 85 | EED_Events_Archive::instance()->event_list(); |
| 86 | 86 | } |
| 87 | 87 | //set default attributes |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $default_espresso_events_shortcode_atts |
| 103 | 103 | ); |
| 104 | 104 | // grab attributes and merge with defaults, then extract |
| 105 | - $attributes = array_merge( (array) $default_espresso_events_shortcode_atts, (array) $attributes ); |
|
| 105 | + $attributes = array_merge((array) $default_espresso_events_shortcode_atts, (array) $attributes); |
|
| 106 | 106 | $attributes = \EES_Shortcode::sanitize_attributes( |
| 107 | 107 | $attributes, |
| 108 | 108 | // the following get sanitized/whitelisted in EEH_Event_Query |
@@ -115,22 +115,22 @@ discard block |
||
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | 117 | // make sure we use the_excerpt() |
| 118 | - add_filter( 'FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true' ); |
|
| 118 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
| 119 | 119 | // apply query filters |
| 120 | - add_filter( 'FHEE__EEH_Event_Query__apply_query_filters', '__return_true' ); |
|
| 120 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 121 | 121 | // run the query |
| 122 | 122 | global $wp_query; |
| 123 | - $wp_query = new EE_Event_List_Query( $attributes ); |
|
| 123 | + $wp_query = new EE_Event_List_Query($attributes); |
|
| 124 | 124 | // check what template is loaded and load filters accordingly |
| 125 | - EED_Events_Archive::instance()->template_include( 'loop-espresso_events.php' ); |
|
| 125 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
| 126 | 126 | // load our template |
| 127 | - $event_list = EEH_Template::locate_template( 'loop-espresso_events.php', array(), TRUE, TRUE ); |
|
| 127 | + $event_list = EEH_Template::locate_template('loop-espresso_events.php', array(), TRUE, TRUE); |
|
| 128 | 128 | // now reset the query and postdata |
| 129 | 129 | wp_reset_query(); |
| 130 | 130 | wp_reset_postdata(); |
| 131 | 131 | EED_Events_Archive::remove_all_events_archive_filters(); |
| 132 | 132 | // remove query filters |
| 133 | - remove_filter( 'FHEE__EEH_Event_Query__apply_query_filters', '__return_true' ); |
|
| 133 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 134 | 134 | // pull our content from the output buffer and return it |
| 135 | 135 | return $event_list; |
| 136 | 136 | } |
@@ -174,43 +174,43 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @param array $args |
| 176 | 176 | */ |
| 177 | - public function __construct( $args = array() ) { |
|
| 177 | + public function __construct($args = array()) { |
|
| 178 | 178 | // incoming args could be a mix of WP query args + EE shortcode args |
| 179 | - foreach ( $args as $key =>$value ) { |
|
| 180 | - $property = '_' . $key; |
|
| 179 | + foreach ($args as $key =>$value) { |
|
| 180 | + $property = '_'.$key; |
|
| 181 | 181 | // if the arg is a property of this class, then it's an EE shortcode arg |
| 182 | - if ( property_exists( $this, $property )) { |
|
| 182 | + if (property_exists($this, $property)) { |
|
| 183 | 183 | // set the property value |
| 184 | 184 | $this->{$property} = $value; |
| 185 | 185 | // then remove it from the array of args that will later be passed to WP_Query() |
| 186 | - unset( $args[ $key ] ); |
|
| 186 | + unset($args[$key]); |
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | //add query filters |
| 190 | 190 | EEH_Event_Query::add_query_filters(); |
| 191 | 191 | // set params that will get used by the filters |
| 192 | - EEH_Event_Query::set_query_params( $this->_month, $this->_category_slug, $this->_show_expired, $this->_order_by, $this->_sort ); |
|
| 192 | + EEH_Event_Query::set_query_params($this->_month, $this->_category_slug, $this->_show_expired, $this->_order_by, $this->_sort); |
|
| 193 | 193 | // first off, let's remove any filters from previous queries |
| 194 | - remove_filter( 'FHEE__archive_espresso_events_template__upcoming_events_h1', array( $this, 'event_list_title' )); |
|
| 195 | - remove_all_filters( 'FHEE__content_espresso_events__event_class' ); |
|
| 194 | + remove_filter('FHEE__archive_espresso_events_template__upcoming_events_h1', array($this, 'event_list_title')); |
|
| 195 | + remove_all_filters('FHEE__content_espresso_events__event_class'); |
|
| 196 | 196 | // Event List Title ? |
| 197 | - add_filter( 'FHEE__archive_espresso_events_template__upcoming_events_h1', array( $this, 'event_list_title' ), 10, 1 ); |
|
| 197 | + add_filter('FHEE__archive_espresso_events_template__upcoming_events_h1', array($this, 'event_list_title'), 10, 1); |
|
| 198 | 198 | // add the css class |
| 199 | - add_filter( 'FHEE__content_espresso_events__event_class', array( $this, 'event_list_css' ), 10, 1 ); |
|
| 199 | + add_filter('FHEE__content_espresso_events__event_class', array($this, 'event_list_css'), 10, 1); |
|
| 200 | 200 | // the current "page" we are viewing |
| 201 | - $paged = max( 1, get_query_var( 'paged' )); |
|
| 201 | + $paged = max(1, get_query_var('paged')); |
|
| 202 | 202 | // Force these args |
| 203 | - $args = array_merge( $args, array( |
|
| 203 | + $args = array_merge($args, array( |
|
| 204 | 204 | 'post_type' => 'espresso_events', |
| 205 | 205 | 'posts_per_page' => $this->_limit, |
| 206 | 206 | 'update_post_term_cache' => FALSE, |
| 207 | 207 | 'update_post_meta_cache' => FALSE, |
| 208 | 208 | 'paged' => $paged, |
| 209 | - 'offset' => ( $paged - 1 ) * $this->_limit |
|
| 209 | + 'offset' => ($paged - 1) * $this->_limit |
|
| 210 | 210 | )); |
| 211 | 211 | |
| 212 | 212 | // run the query |
| 213 | - parent::__construct( $args ); |
|
| 213 | + parent::__construct($args); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -222,8 +222,8 @@ discard block |
||
| 222 | 222 | * @param string $event_list_title |
| 223 | 223 | * @return string |
| 224 | 224 | */ |
| 225 | - public function event_list_title( $event_list_title = '' ) { |
|
| 226 | - if ( ! empty( $this->_title )) { |
|
| 225 | + public function event_list_title($event_list_title = '') { |
|
| 226 | + if ( ! empty($this->_title)) { |
|
| 227 | 227 | return $this->_title; |
| 228 | 228 | } |
| 229 | 229 | return $event_list_title; |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | * @param string $event_list_css |
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | - public function event_list_css( $event_list_css = '' ) { |
|
| 241 | - $event_list_css .= ! empty( $event_list_css ) ? ' ' : ''; |
|
| 242 | - $event_list_css .= ! empty( $this->_css_class ) ? $this->_css_class : ''; |
|
| 243 | - $event_list_css .= ! empty( $event_list_css ) ? ' ' : ''; |
|
| 244 | - $event_list_css .= ! empty( $this->_category_slug ) ? $this->_category_slug : ''; |
|
| 240 | + public function event_list_css($event_list_css = '') { |
|
| 241 | + $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
| 242 | + $event_list_css .= ! empty($this->_css_class) ? $this->_css_class : ''; |
|
| 243 | + $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
| 244 | + $event_list_css .= ! empty($this->_category_slug) ? $this->_category_slug : ''; |
|
| 245 | 245 | return $event_list_css; |
| 246 | 246 | } |
| 247 | 247 | |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public static function apply_query_filters( WP_Query $WP_Query ) { |
| 93 | 93 | return ( |
| 94 | - isset( $WP_Query->query, $WP_Query->query['post_type'] ) |
|
| 95 | - && $WP_Query->query['post_type'] === 'espresso_events' |
|
| 96 | - ) || apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ; |
|
| 94 | + isset( $WP_Query->query, $WP_Query->query['post_type'] ) |
|
| 95 | + && $WP_Query->query['post_type'] === 'espresso_events' |
|
| 96 | + ) || apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public static function filter_query_parts( WP_Query $WP_Query ) { |
| 106 | 106 | // ONLY add our filters if this isn't the main wp_query, |
| 107 | - // because if this is the main wp_query we already have |
|
| 108 | - // our cpt strategies take care of adding things in. |
|
| 107 | + // because if this is the main wp_query we already have |
|
| 108 | + // our cpt strategies take care of adding things in. |
|
| 109 | 109 | if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) { |
| 110 | 110 | // build event list query |
| 111 | 111 | add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 ); |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | * @param string $orderby |
| 128 | 128 | * @param string $sort |
| 129 | 129 | */ |
| 130 | - public static function set_query_params( |
|
| 131 | - $month = '', |
|
| 132 | - $category = '', |
|
| 133 | - $show_expired = false, |
|
| 134 | - $orderby = 'start_date', |
|
| 135 | - $sort = 'ASC' |
|
| 136 | - ) { |
|
| 130 | + public static function set_query_params( |
|
| 131 | + $month = '', |
|
| 132 | + $category = '', |
|
| 133 | + $show_expired = false, |
|
| 134 | + $orderby = 'start_date', |
|
| 135 | + $sort = 'ASC' |
|
| 136 | + ) { |
|
| 137 | 137 | self::$_query_params = array(); |
| 138 | 138 | EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month ); |
| 139 | 139 | EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category ); |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | 153 | private static function _display_month( $month = '' ) { |
| 154 | - return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
| 155 | - } |
|
| 154 | + return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | private static function _show_expired( $show_expired = false ) { |
| 178 | 178 | // override default expired option if set via filter |
| 179 | 179 | return filter_var( |
| 180 | - EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
| 181 | - FILTER_VALIDATE_BOOLEAN |
|
| 182 | - ); |
|
| 180 | + EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
| 181 | + FILTER_VALIDATE_BOOLEAN |
|
| 182 | + ); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | private static function _orderby( $orderby = 'start_date' ) { |
| 194 | 194 | $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
| 195 | 195 | $event_query_orderby = is_array( $event_query_orderby ) |
| 196 | - ? $event_query_orderby |
|
| 197 | - : explode( ',', $event_query_orderby ); |
|
| 196 | + ? $event_query_orderby |
|
| 197 | + : explode( ',', $event_query_orderby ); |
|
| 198 | 198 | $event_query_orderby = array_map( 'trim', $event_query_orderby ); |
| 199 | 199 | $event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby ); |
| 200 | 200 | return $event_query_orderby; |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | private static function _sort( $sort = 'ASC' ) { |
| 212 | 212 | $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
| 213 | 213 | return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true) |
| 214 | - ? strtoupper( $sort ) |
|
| 215 | - : 'ASC'; |
|
| 214 | + ? strtoupper( $sort ) |
|
| 215 | + : 'ASC'; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * posts_fields |
|
| 240 | - * |
|
| 241 | - * @param $SQL |
|
| 242 | - * @param WP_Query $wp_query |
|
| 243 | - * @return string |
|
| 244 | - * @throws \EE_Error |
|
| 245 | - */ |
|
| 238 | + /** |
|
| 239 | + * posts_fields |
|
| 240 | + * |
|
| 241 | + * @param $SQL |
|
| 242 | + * @param WP_Query $wp_query |
|
| 243 | + * @return string |
|
| 244 | + * @throws \EE_Error |
|
| 245 | + */ |
|
| 246 | 246 | public static function posts_fields( $SQL, WP_Query $wp_query ) { |
| 247 | 247 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 248 | 248 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
@@ -253,13 +253,13 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * posts_join_sql_for_terms |
|
| 258 | - * |
|
| 259 | - * @param array $orderby_params |
|
| 260 | - * @return string |
|
| 261 | - * @throws \EE_Error |
|
| 262 | - */ |
|
| 256 | + /** |
|
| 257 | + * posts_join_sql_for_terms |
|
| 258 | + * |
|
| 259 | + * @param array $orderby_params |
|
| 260 | + * @return string |
|
| 261 | + * @throws \EE_Error |
|
| 262 | + */ |
|
| 263 | 263 | public static function posts_fields_sql_for_orderby( $orderby_params = array() ) { |
| 264 | 264 | $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ; |
| 265 | 265 | foreach( (array)$orderby_params as $orderby ) { |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * posts_join |
|
| 297 | - * |
|
| 298 | - * @param string $SQL |
|
| 299 | - * @param WP_Query $wp_query |
|
| 300 | - * @return string |
|
| 301 | - * @throws \EE_Error |
|
| 302 | - */ |
|
| 295 | + /** |
|
| 296 | + * posts_join |
|
| 297 | + * |
|
| 298 | + * @param string $SQL |
|
| 299 | + * @param WP_Query $wp_query |
|
| 300 | + * @return string |
|
| 301 | + * @throws \EE_Error |
|
| 302 | + */ |
|
| 303 | 303 | public static function posts_join( $SQL = '', WP_Query $wp_query ) { |
| 304 | 304 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 305 | 305 | // Category |
@@ -312,14 +312,14 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * posts_join_sql_for_terms |
|
| 317 | - * |
|
| 318 | - * @param string $SQL |
|
| 319 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
| 320 | - * @return string |
|
| 321 | - * @throws \EE_Error |
|
| 322 | - */ |
|
| 315 | + /** |
|
| 316 | + * posts_join_sql_for_terms |
|
| 317 | + * |
|
| 318 | + * @param string $SQL |
|
| 319 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
| 320 | + * @return string |
|
| 321 | + * @throws \EE_Error |
|
| 322 | + */ |
|
| 323 | 323 | public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) { |
| 324 | 324 | if ( ! $show_expired ) { |
| 325 | 325 | $join = EEM_Event::instance()->table() . '.ID = '; |
@@ -353,24 +353,24 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * posts_join_for_orderby |
|
| 358 | - * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
| 359 | - * |
|
| 360 | - * @param string $SQL |
|
| 361 | - * @param array $orderby_params |
|
| 362 | - * @return string |
|
| 363 | - * @throws \EE_Error |
|
| 364 | - */ |
|
| 356 | + /** |
|
| 357 | + * posts_join_for_orderby |
|
| 358 | + * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
| 359 | + * |
|
| 360 | + * @param string $SQL |
|
| 361 | + * @param array $orderby_params |
|
| 362 | + * @return string |
|
| 363 | + * @throws \EE_Error |
|
| 364 | + */ |
|
| 365 | 365 | public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) { |
| 366 | 366 | foreach ( (array)$orderby_params as $orderby ) { |
| 367 | 367 | switch ( $orderby ) { |
| 368 | 368 | case 'ticket_start' : |
| 369 | 369 | case 'ticket_end' : |
| 370 | 370 | $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
| 371 | - $SQL, |
|
| 372 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
| 373 | - ); |
|
| 371 | + $SQL, |
|
| 372 | + EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
| 373 | + ); |
|
| 374 | 374 | $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
| 375 | 375 | $SQL .= ' ON ('; |
| 376 | 376 | $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
@@ -398,14 +398,14 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | |
| 400 | 400 | |
| 401 | - /** |
|
| 402 | - * _posts_join_for_datetime |
|
| 403 | - * |
|
| 404 | - * @param string $SQL |
|
| 405 | - * @param string $join |
|
| 406 | - * @return string |
|
| 407 | - * @throws \EE_Error |
|
| 408 | - */ |
|
| 401 | + /** |
|
| 402 | + * _posts_join_for_datetime |
|
| 403 | + * |
|
| 404 | + * @param string $SQL |
|
| 405 | + * @param string $join |
|
| 406 | + * @return string |
|
| 407 | + * @throws \EE_Error |
|
| 408 | + */ |
|
| 409 | 409 | protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) { |
| 410 | 410 | if ( ! empty( $join )) { |
| 411 | 411 | $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
@@ -418,13 +418,13 @@ discard block |
||
| 418 | 418 | |
| 419 | 419 | |
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * _posts_join_for_event_venue |
|
| 423 | - * |
|
| 424 | - * @param string $SQL |
|
| 425 | - * @return string |
|
| 426 | - * @throws \EE_Error |
|
| 427 | - */ |
|
| 421 | + /** |
|
| 422 | + * _posts_join_for_event_venue |
|
| 423 | + * |
|
| 424 | + * @param string $SQL |
|
| 425 | + * @return string |
|
| 426 | + * @throws \EE_Error |
|
| 427 | + */ |
|
| 428 | 428 | protected static function _posts_join_for_event_venue( $SQL = '' ) { |
| 429 | 429 | // Event Venue table name |
| 430 | 430 | $event_venue_table = EEM_Event_Venue::instance()->table(); |
@@ -454,13 +454,13 @@ discard block |
||
| 454 | 454 | |
| 455 | 455 | |
| 456 | 456 | |
| 457 | - /** |
|
| 458 | - * _posts_join_for_venue_state |
|
| 459 | - * |
|
| 460 | - * @param string $SQL |
|
| 461 | - * @return string |
|
| 462 | - * @throws \EE_Error |
|
| 463 | - */ |
|
| 457 | + /** |
|
| 458 | + * _posts_join_for_venue_state |
|
| 459 | + * |
|
| 460 | + * @param string $SQL |
|
| 461 | + * @return string |
|
| 462 | + * @throws \EE_Error |
|
| 463 | + */ |
|
| 464 | 464 | protected static function _posts_join_for_venue_state( $SQL = '' ) { |
| 465 | 465 | // Venue Meta table name |
| 466 | 466 | $venue_meta_table = EEM_Venue::instance()->second_table(); |
@@ -484,14 +484,14 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | |
| 486 | 486 | |
| 487 | - /** |
|
| 488 | - * posts_where |
|
| 489 | - * |
|
| 490 | - * @param string $SQL |
|
| 491 | - * @param WP_Query $wp_query |
|
| 492 | - * @return string |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 487 | + /** |
|
| 488 | + * posts_where |
|
| 489 | + * |
|
| 490 | + * @param string $SQL |
|
| 491 | + * @param WP_Query $wp_query |
|
| 492 | + * @return string |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | 495 | public static function posts_where( $SQL = '', WP_Query $wp_query ) { |
| 496 | 496 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 497 | 497 | // Show Expired ? |
@@ -506,17 +506,17 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | |
| 508 | 508 | |
| 509 | - /** |
|
| 510 | - * posts_where_sql_for_show_expired |
|
| 511 | - * |
|
| 512 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
| 513 | - * @return string |
|
| 514 | - * @throws \EE_Error |
|
| 515 | - */ |
|
| 509 | + /** |
|
| 510 | + * posts_where_sql_for_show_expired |
|
| 511 | + * |
|
| 512 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
| 513 | + * @return string |
|
| 514 | + * @throws \EE_Error |
|
| 515 | + */ |
|
| 516 | 516 | public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
| 517 | 517 | return ! $show_expired |
| 518 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' ' |
|
| 519 | - : ''; |
|
| 518 | + ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' ' |
|
| 519 | + : ''; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | |
@@ -531,19 +531,19 @@ discard block |
||
| 531 | 531 | global $wpdb; |
| 532 | 532 | $event_category_slug = esc_sql($event_category_slug); |
| 533 | 533 | return ! empty( $event_category_slug ) |
| 534 | - ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' " |
|
| 535 | - : ''; |
|
| 534 | + ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' " |
|
| 535 | + : ''; |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
| 539 | 539 | |
| 540 | - /** |
|
| 541 | - * posts_where_sql_for_event_list_month |
|
| 542 | - * |
|
| 543 | - * @param boolean $month |
|
| 544 | - * @return string |
|
| 545 | - * @throws \EE_Error |
|
| 546 | - */ |
|
| 540 | + /** |
|
| 541 | + * posts_where_sql_for_event_list_month |
|
| 542 | + * |
|
| 543 | + * @param boolean $month |
|
| 544 | + * @return string |
|
| 545 | + * @throws \EE_Error |
|
| 546 | + */ |
|
| 547 | 547 | public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
| 548 | 548 | $SQL = ''; |
| 549 | 549 | if ( ! empty( $month ) ) { |
@@ -558,55 +558,55 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | |
| 560 | 560 | |
| 561 | - /** |
|
| 562 | - * posts_orderby |
|
| 563 | - * |
|
| 564 | - * @param string $SQL |
|
| 565 | - * @param WP_Query $wp_query |
|
| 566 | - * @return string |
|
| 567 | - * @throws \EE_Error |
|
| 568 | - */ |
|
| 561 | + /** |
|
| 562 | + * posts_orderby |
|
| 563 | + * |
|
| 564 | + * @param string $SQL |
|
| 565 | + * @param WP_Query $wp_query |
|
| 566 | + * @return string |
|
| 567 | + * @throws \EE_Error |
|
| 568 | + */ |
|
| 569 | 569 | public static function posts_orderby( $SQL = '', WP_Query $wp_query ) { |
| 570 | 570 | if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
| 571 | 571 | $SQL = EEH_Event_Query::posts_orderby_sql( |
| 572 | - EEH_Event_Query::$_event_query_orderby, |
|
| 573 | - EEH_Event_Query::$_event_query_sort |
|
| 574 | - ); |
|
| 572 | + EEH_Event_Query::$_event_query_orderby, |
|
| 573 | + EEH_Event_Query::$_event_query_sort |
|
| 574 | + ); |
|
| 575 | 575 | } |
| 576 | 576 | return $SQL; |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | |
| 580 | 580 | |
| 581 | - /** |
|
| 582 | - * posts_orderby_sql |
|
| 583 | - * possible parameters: |
|
| 584 | - * ID |
|
| 585 | - * start_date |
|
| 586 | - * end_date |
|
| 587 | - * event_name |
|
| 588 | - * category_slug |
|
| 589 | - * ticket_start |
|
| 590 | - * ticket_end |
|
| 591 | - * venue_title |
|
| 592 | - * city |
|
| 593 | - * state |
|
| 594 | - * **IMPORTANT** |
|
| 595 | - * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
| 596 | - * or else some of the table references below will result in MySQL errors |
|
| 597 | - * |
|
| 598 | - * @param array|bool $orderby_params |
|
| 599 | - * @param string $sort |
|
| 600 | - * @return string |
|
| 601 | - * @throws \EE_Error |
|
| 602 | - */ |
|
| 581 | + /** |
|
| 582 | + * posts_orderby_sql |
|
| 583 | + * possible parameters: |
|
| 584 | + * ID |
|
| 585 | + * start_date |
|
| 586 | + * end_date |
|
| 587 | + * event_name |
|
| 588 | + * category_slug |
|
| 589 | + * ticket_start |
|
| 590 | + * ticket_end |
|
| 591 | + * venue_title |
|
| 592 | + * city |
|
| 593 | + * state |
|
| 594 | + * **IMPORTANT** |
|
| 595 | + * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
| 596 | + * or else some of the table references below will result in MySQL errors |
|
| 597 | + * |
|
| 598 | + * @param array|bool $orderby_params |
|
| 599 | + * @param string $sort |
|
| 600 | + * @return string |
|
| 601 | + * @throws \EE_Error |
|
| 602 | + */ |
|
| 603 | 603 | public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
| 604 | 604 | global $wpdb; |
| 605 | 605 | $SQL = ''; |
| 606 | 606 | $counter = 0; |
| 607 | 607 | $sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
| 608 | - ? strtoupper($sort) |
|
| 609 | - : 'ASC'; |
|
| 608 | + ? strtoupper($sort) |
|
| 609 | + : 'ASC'; |
|
| 610 | 610 | //make sure 'orderby' is set in query params |
| 611 | 611 | if ( ! isset( self::$_query_params['orderby'] )) { |
| 612 | 612 | self::$_query_params['orderby'] = array(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public static function add_query_filters() { |
| 80 | 80 | //add query filters |
| 81 | - add_action( 'pre_get_posts', array( 'EEH_Event_Query', 'filter_query_parts' ), 10, 1 ); |
|
| 81 | + add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
@@ -89,11 +89,11 @@ discard block |
||
| 89 | 89 | * @param \WP_Query $WP_Query |
| 90 | 90 | * @return bool |
| 91 | 91 | */ |
| 92 | - public static function apply_query_filters( WP_Query $WP_Query ) { |
|
| 92 | + public static function apply_query_filters(WP_Query $WP_Query) { |
|
| 93 | 93 | return ( |
| 94 | - isset( $WP_Query->query, $WP_Query->query['post_type'] ) |
|
| 94 | + isset($WP_Query->query, $WP_Query->query['post_type']) |
|
| 95 | 95 | && $WP_Query->query['post_type'] === 'espresso_events' |
| 96 | - ) || apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ; |
|
| 96 | + ) || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @param \WP_Query $WP_Query |
| 104 | 104 | */ |
| 105 | - public static function filter_query_parts( WP_Query $WP_Query ) { |
|
| 105 | + public static function filter_query_parts(WP_Query $WP_Query) { |
|
| 106 | 106 | // ONLY add our filters if this isn't the main wp_query, |
| 107 | 107 | // because if this is the main wp_query we already have |
| 108 | 108 | // our cpt strategies take care of adding things in. |
| 109 | - if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) { |
|
| 109 | + if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) { |
|
| 110 | 110 | // build event list query |
| 111 | - add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 ); |
|
| 112 | - add_filter( 'posts_join', array( 'EEH_Event_Query', 'posts_join' ), 10, 2 ); |
|
| 113 | - add_filter( 'posts_where', array( 'EEH_Event_Query', 'posts_where' ), 10, 2 ); |
|
| 114 | - add_filter( 'posts_orderby', array( 'EEH_Event_Query', 'posts_orderby' ), 10, 2 ); |
|
| 115 | - add_filter( 'posts_clauses_request', array( 'EEH_Event_Query', 'posts_clauses' ), 10, 2 ); |
|
| 111 | + add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2); |
|
| 112 | + add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2); |
|
| 113 | + add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2); |
|
| 114 | + add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2); |
|
| 115 | + add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | $sort = 'ASC' |
| 136 | 136 | ) { |
| 137 | 137 | self::$_query_params = array(); |
| 138 | - EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month ); |
|
| 139 | - EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category ); |
|
| 140 | - EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired( $show_expired ); |
|
| 141 | - EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby( $orderby ); |
|
| 142 | - EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort( $sort ); |
|
| 138 | + EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month); |
|
| 139 | + EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category); |
|
| 140 | + EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired); |
|
| 141 | + EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby); |
|
| 142 | + EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $month |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - private static function _display_month( $month = '' ) { |
|
| 153 | + private static function _display_month($month = '') { |
|
| 154 | 154 | return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param string $category |
| 163 | 163 | * @return string |
| 164 | 164 | */ |
| 165 | - private static function _event_category_slug( $category = '' ) { |
|
| 165 | + private static function _event_category_slug($category = '') { |
|
| 166 | 166 | return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category)); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param bool $show_expired |
| 175 | 175 | * @return boolean |
| 176 | 176 | */ |
| 177 | - private static function _show_expired( $show_expired = false ) { |
|
| 177 | + private static function _show_expired($show_expired = false) { |
|
| 178 | 178 | // override default expired option if set via filter |
| 179 | 179 | return filter_var( |
| 180 | 180 | EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | * @param string $orderby |
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | - private static function _orderby( $orderby = 'start_date' ) { |
|
| 193 | + private static function _orderby($orderby = 'start_date') { |
|
| 194 | 194 | $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
| 195 | - $event_query_orderby = is_array( $event_query_orderby ) |
|
| 195 | + $event_query_orderby = is_array($event_query_orderby) |
|
| 196 | 196 | ? $event_query_orderby |
| 197 | - : explode( ',', $event_query_orderby ); |
|
| 198 | - $event_query_orderby = array_map( 'trim', $event_query_orderby ); |
|
| 199 | - $event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby ); |
|
| 197 | + : explode(',', $event_query_orderby); |
|
| 198 | + $event_query_orderby = array_map('trim', $event_query_orderby); |
|
| 199 | + $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby); |
|
| 200 | 200 | return $event_query_orderby; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | * @param string $sort |
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | - private static function _sort( $sort = 'ASC' ) { |
|
| 211 | + private static function _sort($sort = 'ASC') { |
|
| 212 | 212 | $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
| 213 | - return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true) |
|
| 214 | - ? strtoupper( $sort ) |
|
| 213 | + return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
| 214 | + ? strtoupper($sort) |
|
| 215 | 215 | : 'ASC'; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -225,10 +225,10 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @return array array of clauses |
| 227 | 227 | */ |
| 228 | - public static function posts_clauses( $clauses, WP_Query $wp_query ) { |
|
| 229 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 228 | + public static function posts_clauses($clauses, WP_Query $wp_query) { |
|
| 229 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 230 | 230 | global $wpdb; |
| 231 | - $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
| 231 | + $clauses['groupby'] = $wpdb->posts.'.ID '; |
|
| 232 | 232 | } |
| 233 | 233 | return $clauses; |
| 234 | 234 | } |
@@ -243,10 +243,10 @@ discard block |
||
| 243 | 243 | * @return string |
| 244 | 244 | * @throws \EE_Error |
| 245 | 245 | */ |
| 246 | - public static function posts_fields( $SQL, WP_Query $wp_query ) { |
|
| 247 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 246 | + public static function posts_fields($SQL, WP_Query $wp_query) { |
|
| 247 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 248 | 248 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
| 249 | - $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby( EEH_Event_Query::$_event_query_orderby ); |
|
| 249 | + $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby); |
|
| 250 | 250 | } |
| 251 | 251 | return $SQL; |
| 252 | 252 | } |
@@ -260,29 +260,29 @@ discard block |
||
| 260 | 260 | * @return string |
| 261 | 261 | * @throws \EE_Error |
| 262 | 262 | */ |
| 263 | - public static function posts_fields_sql_for_orderby( $orderby_params = array() ) { |
|
| 264 | - $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ; |
|
| 265 | - foreach( (array)$orderby_params as $orderby ) { |
|
| 266 | - switch ( $orderby ) { |
|
| 263 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) { |
|
| 264 | + $SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
| 265 | + foreach ((array) $orderby_params as $orderby) { |
|
| 266 | + switch ($orderby) { |
|
| 267 | 267 | |
| 268 | 268 | case 'ticket_start' : |
| 269 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date' ; |
|
| 269 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date'; |
|
| 270 | 270 | break; |
| 271 | 271 | |
| 272 | 272 | case 'ticket_end' : |
| 273 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date' ; |
|
| 273 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date'; |
|
| 274 | 274 | break; |
| 275 | 275 | |
| 276 | 276 | case 'venue_title' : |
| 277 | - $SQL .= ', Venue.post_title AS venue_title' ; |
|
| 277 | + $SQL .= ', Venue.post_title AS venue_title'; |
|
| 278 | 278 | break; |
| 279 | 279 | |
| 280 | 280 | case 'city' : |
| 281 | - $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city' ; |
|
| 281 | + $SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city'; |
|
| 282 | 282 | break; |
| 283 | 283 | |
| 284 | 284 | case 'state' : |
| 285 | - $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name' ; |
|
| 285 | + $SQL .= ', '.EEM_State::instance()->table().'.STA_name'; |
|
| 286 | 286 | break; |
| 287 | 287 | |
| 288 | 288 | } |
@@ -300,12 +300,12 @@ discard block |
||
| 300 | 300 | * @return string |
| 301 | 301 | * @throws \EE_Error |
| 302 | 302 | */ |
| 303 | - public static function posts_join( $SQL = '', WP_Query $wp_query ) { |
|
| 304 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 303 | + public static function posts_join($SQL = '', WP_Query $wp_query) { |
|
| 304 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 305 | 305 | // Category |
| 306 | - $SQL = EEH_Event_Query::posts_join_sql_for_show_expired( $SQL, EEH_Event_Query::$_event_query_show_expired ); |
|
| 307 | - $SQL = EEH_Event_Query::posts_join_sql_for_terms( $SQL, EEH_Event_Query::$_event_query_category ); |
|
| 308 | - $SQL = EEH_Event_Query::posts_join_for_orderby( $SQL, EEH_Event_Query::$_event_query_orderby ); |
|
| 306 | + $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired); |
|
| 307 | + $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category); |
|
| 308 | + $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby); |
|
| 309 | 309 | } |
| 310 | 310 | return $SQL; |
| 311 | 311 | } |
@@ -320,13 +320,13 @@ discard block |
||
| 320 | 320 | * @return string |
| 321 | 321 | * @throws \EE_Error |
| 322 | 322 | */ |
| 323 | - public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) { |
|
| 324 | - if ( ! $show_expired ) { |
|
| 325 | - $join = EEM_Event::instance()->table() . '.ID = '; |
|
| 326 | - $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
| 323 | + public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = FALSE) { |
|
| 324 | + if ( ! $show_expired) { |
|
| 325 | + $join = EEM_Event::instance()->table().'.ID = '; |
|
| 326 | + $join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
| 327 | 327 | // don't add if this is already in the SQL |
| 328 | - if ( strpos( $SQL, $join ) === FALSE ) { |
|
| 329 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
| 328 | + if (strpos($SQL, $join) === FALSE) { |
|
| 329 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) '; |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | return $SQL; |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | * @param string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet |
| 342 | 342 | * @return string |
| 343 | 343 | */ |
| 344 | - public static function posts_join_sql_for_terms( $SQL = '', $join_terms = '' ) { |
|
| 345 | - if ( ! empty( $join_terms ) ) { |
|
| 344 | + public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') { |
|
| 345 | + if ( ! empty($join_terms)) { |
|
| 346 | 346 | global $wpdb; |
| 347 | 347 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
| 348 | 348 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -362,33 +362,33 @@ discard block |
||
| 362 | 362 | * @return string |
| 363 | 363 | * @throws \EE_Error |
| 364 | 364 | */ |
| 365 | - public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) { |
|
| 366 | - foreach ( (array)$orderby_params as $orderby ) { |
|
| 367 | - switch ( $orderby ) { |
|
| 365 | + public static function posts_join_for_orderby($SQL = '', $orderby_params = array()) { |
|
| 366 | + foreach ((array) $orderby_params as $orderby) { |
|
| 367 | + switch ($orderby) { |
|
| 368 | 368 | case 'ticket_start' : |
| 369 | 369 | case 'ticket_end' : |
| 370 | 370 | $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
| 371 | 371 | $SQL, |
| 372 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
| 372 | + EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name() |
|
| 373 | 373 | ); |
| 374 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
| 374 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table(); |
|
| 375 | 375 | $SQL .= ' ON ('; |
| 376 | - $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
| 376 | + $SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
| 377 | 377 | $SQL .= ' = '; |
| 378 | - $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
| 379 | - $SQL .= ' )'; |
|
| 378 | + $SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
| 379 | + $SQL .= ' )'; |
|
| 380 | 380 | break; |
| 381 | 381 | case 'venue_title' : |
| 382 | 382 | case 'city' : |
| 383 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL ); |
|
| 383 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
| 384 | 384 | break; |
| 385 | 385 | case 'state' : |
| 386 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL ); |
|
| 387 | - $SQL .= EEH_Event_Query::_posts_join_for_venue_state( $SQL ); |
|
| 386 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
| 387 | + $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL); |
|
| 388 | 388 | break; |
| 389 | 389 | case 'start_date' : |
| 390 | 390 | default : |
| 391 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime( $SQL, EEM_Event::instance()->table() . '.ID' ); |
|
| 391 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID'); |
|
| 392 | 392 | break; |
| 393 | 393 | |
| 394 | 394 | } |
@@ -406,11 +406,11 @@ discard block |
||
| 406 | 406 | * @return string |
| 407 | 407 | * @throws \EE_Error |
| 408 | 408 | */ |
| 409 | - protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) { |
|
| 410 | - if ( ! empty( $join )) { |
|
| 411 | - $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
| 412 | - if ( strpos( $SQL, $join ) === FALSE ) { |
|
| 413 | - return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
| 409 | + protected static function _posts_join_for_datetime($SQL = '', $join = '') { |
|
| 410 | + if ( ! empty($join)) { |
|
| 411 | + $join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
| 412 | + if (strpos($SQL, $join) === FALSE) { |
|
| 413 | + return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )'; |
|
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | return ''; |
@@ -425,14 +425,14 @@ discard block |
||
| 425 | 425 | * @return string |
| 426 | 426 | * @throws \EE_Error |
| 427 | 427 | */ |
| 428 | - protected static function _posts_join_for_event_venue( $SQL = '' ) { |
|
| 428 | + protected static function _posts_join_for_event_venue($SQL = '') { |
|
| 429 | 429 | // Event Venue table name |
| 430 | 430 | $event_venue_table = EEM_Event_Venue::instance()->table(); |
| 431 | 431 | // generate conditions for: Event <=> Event Venue JOIN clause |
| 432 | - $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
| 433 | - $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
| 432 | + $event_to_event_venue_join = EEM_Event::instance()->table().'.ID = '; |
|
| 433 | + $event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name(); |
|
| 434 | 434 | // don't add joins if they have already been added |
| 435 | - if ( strpos( $SQL, $event_to_event_venue_join ) === FALSE ) { |
|
| 435 | + if (strpos($SQL, $event_to_event_venue_join) === FALSE) { |
|
| 436 | 436 | // Venue table name |
| 437 | 437 | $venue_table = EEM_Venue::instance()->table(); |
| 438 | 438 | // Venue table pk |
@@ -445,10 +445,10 @@ discard block |
||
| 445 | 445 | $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )"; |
| 446 | 446 | // generate JOIN clause for: Venue <=> Venue Meta |
| 447 | 447 | $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )"; |
| 448 | - unset( $event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table ); |
|
| 448 | + unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table); |
|
| 449 | 449 | return $venue_SQL; |
| 450 | 450 | } |
| 451 | - unset( $event_venue_table, $event_to_event_venue_join ); |
|
| 451 | + unset($event_venue_table, $event_to_event_venue_join); |
|
| 452 | 452 | return ''; |
| 453 | 453 | } |
| 454 | 454 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @return string |
| 462 | 462 | * @throws \EE_Error |
| 463 | 463 | */ |
| 464 | - protected static function _posts_join_for_venue_state( $SQL = '' ) { |
|
| 464 | + protected static function _posts_join_for_venue_state($SQL = '') { |
|
| 465 | 465 | // Venue Meta table name |
| 466 | 466 | $venue_meta_table = EEM_Venue::instance()->second_table(); |
| 467 | 467 | // State table name |
@@ -469,16 +469,16 @@ discard block |
||
| 469 | 469 | // State table pk |
| 470 | 470 | $state_table_pk = EEM_State::instance()->primary_key_name(); |
| 471 | 471 | // verify vars |
| 472 | - if ( $venue_meta_table && $state_table && $state_table_pk ) { |
|
| 472 | + if ($venue_meta_table && $state_table && $state_table_pk) { |
|
| 473 | 473 | // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID |
| 474 | 474 | $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk"; |
| 475 | 475 | // don't add join if it has already been added |
| 476 | - if ( strpos( $SQL, $join ) === FALSE ) { |
|
| 477 | - unset( $state_table_pk, $venue_meta_table, $venue_table_pk ); |
|
| 476 | + if (strpos($SQL, $join) === FALSE) { |
|
| 477 | + unset($state_table_pk, $venue_meta_table, $venue_table_pk); |
|
| 478 | 478 | return " LEFT JOIN $state_table ON ( $join )"; |
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | - unset( $join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk ); |
|
| 481 | + unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk); |
|
| 482 | 482 | return ''; |
| 483 | 483 | } |
| 484 | 484 | |
@@ -492,14 +492,14 @@ discard block |
||
| 492 | 492 | * @return string |
| 493 | 493 | * @throws \EE_Error |
| 494 | 494 | */ |
| 495 | - public static function posts_where( $SQL = '', WP_Query $wp_query ) { |
|
| 496 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 495 | + public static function posts_where($SQL = '', WP_Query $wp_query) { |
|
| 496 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 497 | 497 | // Show Expired ? |
| 498 | - $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired( EEH_Event_Query::$_event_query_show_expired ); |
|
| 498 | + $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired); |
|
| 499 | 499 | // Category |
| 500 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug( EEH_Event_Query::$_event_query_category ); |
|
| 500 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category); |
|
| 501 | 501 | // Start Date |
| 502 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month( EEH_Event_Query::$_event_query_month ); |
|
| 502 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month); |
|
| 503 | 503 | } |
| 504 | 504 | return $SQL; |
| 505 | 505 | } |
@@ -513,9 +513,9 @@ discard block |
||
| 513 | 513 | * @return string |
| 514 | 514 | * @throws \EE_Error |
| 515 | 515 | */ |
| 516 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
| 516 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
| 517 | 517 | return ! $show_expired |
| 518 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' ' |
|
| 518 | + ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', TRUE).'\' ' |
|
| 519 | 519 | : ''; |
| 520 | 520 | } |
| 521 | 521 | |
@@ -527,10 +527,10 @@ discard block |
||
| 527 | 527 | * @param boolean $event_category_slug |
| 528 | 528 | * @return string |
| 529 | 529 | */ |
| 530 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
| 530 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
| 531 | 531 | global $wpdb; |
| 532 | 532 | $event_category_slug = esc_sql($event_category_slug); |
| 533 | - return ! empty( $event_category_slug ) |
|
| 533 | + return ! empty($event_category_slug) |
|
| 534 | 534 | ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' " |
| 535 | 535 | : ''; |
| 536 | 536 | } |
@@ -544,16 +544,16 @@ discard block |
||
| 544 | 544 | * @return string |
| 545 | 545 | * @throws \EE_Error |
| 546 | 546 | */ |
| 547 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
| 547 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
| 548 | 548 | $SQL = ''; |
| 549 | - if ( ! empty( $month ) ) { |
|
| 549 | + if ( ! empty($month)) { |
|
| 550 | 550 | $datetime_table = EEM_Datetime::instance()->table(); |
| 551 | 551 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
| 552 | 552 | $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
| 553 | - $SQL .= date( 'Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
| 553 | + $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'"; |
|
| 554 | 554 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
| 555 | 555 | $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
| 556 | - $SQL .= date( 'Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
| 556 | + $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' "; |
|
| 557 | 557 | } |
| 558 | 558 | return $SQL; |
| 559 | 559 | } |
@@ -568,8 +568,8 @@ discard block |
||
| 568 | 568 | * @return string |
| 569 | 569 | * @throws \EE_Error |
| 570 | 570 | */ |
| 571 | - public static function posts_orderby( $SQL = '', WP_Query $wp_query ) { |
|
| 572 | - if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) { |
|
| 571 | + public static function posts_orderby($SQL = '', WP_Query $wp_query) { |
|
| 572 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
| 573 | 573 | $SQL = EEH_Event_Query::posts_orderby_sql( |
| 574 | 574 | EEH_Event_Query::$_event_query_orderby, |
| 575 | 575 | EEH_Event_Query::$_event_query_sort |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @return string |
| 603 | 603 | * @throws \EE_Error |
| 604 | 604 | */ |
| 605 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
| 605 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
| 606 | 606 | global $wpdb; |
| 607 | 607 | $SQL = ''; |
| 608 | 608 | $counter = 0; |
@@ -610,58 +610,58 @@ discard block |
||
| 610 | 610 | ? strtoupper($sort) |
| 611 | 611 | : 'ASC'; |
| 612 | 612 | //make sure 'orderby' is set in query params |
| 613 | - if ( ! isset( self::$_query_params['orderby'] )) { |
|
| 613 | + if ( ! isset(self::$_query_params['orderby'])) { |
|
| 614 | 614 | self::$_query_params['orderby'] = array(); |
| 615 | 615 | } |
| 616 | 616 | // loop thru $orderby_params (type cast as array) |
| 617 | - foreach ( (array)$orderby_params as $orderby ) { |
|
| 617 | + foreach ((array) $orderby_params as $orderby) { |
|
| 618 | 618 | // check if we have already added this param |
| 619 | - if ( isset( self::$_query_params['orderby'][ $orderby ] )) { |
|
| 619 | + if (isset(self::$_query_params['orderby'][$orderby])) { |
|
| 620 | 620 | // if so then remove from the $orderby_params so that the count() method below is accurate |
| 621 | - unset( $orderby_params[ $orderby ] ); |
|
| 621 | + unset($orderby_params[$orderby]); |
|
| 622 | 622 | // then bump ahead to the next param |
| 623 | 623 | continue; |
| 624 | 624 | } |
| 625 | 625 | // this will ad a comma depending on whether this is the first or last param |
| 626 | - $glue = $counter === 0 || $counter === count( $orderby_params ) ? ' ' : ', '; |
|
| 626 | + $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', '; |
|
| 627 | 627 | // ok what's we dealing with? |
| 628 | - switch ( $orderby ) { |
|
| 628 | + switch ($orderby) { |
|
| 629 | 629 | case 'id' : |
| 630 | 630 | case 'ID' : |
| 631 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
| 631 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
| 632 | 632 | break; |
| 633 | 633 | case 'end_date' : |
| 634 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
| 634 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
| 635 | 635 | break; |
| 636 | 636 | case 'event_name' : |
| 637 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
| 637 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
| 638 | 638 | break; |
| 639 | 639 | case 'category_slug' : |
| 640 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
| 640 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
| 641 | 641 | break; |
| 642 | 642 | case 'ticket_start' : |
| 643 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
| 643 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
| 644 | 644 | break; |
| 645 | 645 | case 'ticket_end' : |
| 646 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
| 646 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
| 647 | 647 | break; |
| 648 | 648 | case 'venue_title' : |
| 649 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
| 649 | + $SQL .= $glue.'venue_title '.$sort; |
|
| 650 | 650 | break; |
| 651 | 651 | case 'city' : |
| 652 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
| 652 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
| 653 | 653 | break; |
| 654 | 654 | case 'state' : |
| 655 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
| 655 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
| 656 | 656 | break; |
| 657 | 657 | case 'start_date' : |
| 658 | 658 | default : |
| 659 | - $SQL .= $glue . ' event_start_date ' . $sort; |
|
| 659 | + $SQL .= $glue.' event_start_date '.$sort; |
|
| 660 | 660 | break; |
| 661 | 661 | } |
| 662 | 662 | // add to array of orderby params that have been added |
| 663 | - self::$_query_params['orderby'][ $orderby ] = TRUE; |
|
| 664 | - $counter ++; |
|
| 663 | + self::$_query_params['orderby'][$orderby] = TRUE; |
|
| 664 | + $counter++; |
|
| 665 | 665 | } |
| 666 | 666 | return $SQL; |
| 667 | 667 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param WP $WP |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public abstract function run( WP $WP ); |
|
| 45 | + public abstract function run(WP $WP); |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param array $attributes |
| 55 | 55 | * @return mixed |
| 56 | 56 | */ |
| 57 | - public abstract function process_shortcode( $attributes = array() ); |
|
| 57 | + public abstract function process_shortcode($attributes = array()); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | * @param string $shortcode_class |
| 66 | 66 | * @return \EES_Shortcode |
| 67 | 67 | */ |
| 68 | - final public static function instance( $shortcode_class = null ) { |
|
| 69 | - $shortcode_class = ! empty( $shortcode_class ) ? $shortcode_class : get_called_class(); |
|
| 70 | - if ( $shortcode_class === 'EES_Shortcode' || empty( $shortcode_class )) { |
|
| 68 | + final public static function instance($shortcode_class = null) { |
|
| 69 | + $shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class(); |
|
| 70 | + if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) { |
|
| 71 | 71 | return null; |
| 72 | 72 | } |
| 73 | - $shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class )); |
|
| 74 | - $shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} ) |
|
| 73 | + $shortcode = str_replace('EES_', '', strtoupper($shortcode_class)); |
|
| 74 | + $shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode} ) |
|
| 75 | 75 | ? EE_Registry::instance()->shortcodes->{$shortcode} |
| 76 | 76 | : null; |
| 77 | 77 | return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self' |
@@ -90,23 +90,23 @@ discard block |
||
| 90 | 90 | * @param $attributes |
| 91 | 91 | * @return mixed |
| 92 | 92 | */ |
| 93 | - final public static function fallback_shortcode_processor( $attributes ) { |
|
| 94 | - if ( EE_Maintenance_Mode::disable_frontend_for_maintenance() ) { |
|
| 93 | + final public static function fallback_shortcode_processor($attributes) { |
|
| 94 | + if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) { |
|
| 95 | 95 | return null; |
| 96 | 96 | } |
| 97 | 97 | // what shortcode was actually parsed ? |
| 98 | 98 | $shortcode_class = get_called_class(); |
| 99 | 99 | // notify rest of system that fallback processor was triggered |
| 100 | - add_filter( 'FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true' ); |
|
| 100 | + add_filter('FHEE__fallback_shortcode_processor__'.$shortcode_class, '__return_true'); |
|
| 101 | 101 | // get instance of actual shortcode |
| 102 | - $shortcode_obj = self::instance( $shortcode_class ); |
|
| 102 | + $shortcode_obj = self::instance($shortcode_class); |
|
| 103 | 103 | // verify class |
| 104 | - if ( $shortcode_obj instanceof EES_Shortcode ) { |
|
| 104 | + if ($shortcode_obj instanceof EES_Shortcode) { |
|
| 105 | 105 | global $wp; |
| 106 | - $shortcode_obj->run( $wp ); |
|
| 106 | + $shortcode_obj->run($wp); |
|
| 107 | 107 | // set attributes and run the shortcode |
| 108 | - $shortcode_obj->_attributes = (array)$attributes; |
|
| 109 | - return $shortcode_obj->process_shortcode( $shortcode_obj->_attributes ); |
|
| 108 | + $shortcode_obj->_attributes = (array) $attributes; |
|
| 109 | + return $shortcode_obj->process_shortcode($shortcode_obj->_attributes); |
|
| 110 | 110 | } else { |
| 111 | 111 | return null; |
| 112 | 112 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param $attributes |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | - final public static function invalid_shortcode_processor( $attributes ) { |
|
| 125 | + final public static function invalid_shortcode_processor($attributes) { |
|
| 126 | 126 | return ''; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | final public function __construct() { |
| 135 | 135 | // get classname, remove EES_prefix, and convert to UPPERCASE |
| 136 | - $shortcode = strtoupper( str_replace( 'EES_', '', get_class( $this ))); |
|
| 136 | + $shortcode = strtoupper(str_replace('EES_', '', get_class($this))); |
|
| 137 | 137 | // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier |
| 138 | - add_shortcode( $shortcode, array( $this, 'process_shortcode' )); |
|
| 138 | + add_shortcode($shortcode, array($this, 'process_shortcode')); |
|
| 139 | 139 | // make sure system knows this is an EE page |
| 140 | - EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
|
| 140 | + EE_Registry::instance()->REQ->set_espresso_page(TRUE); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | foreach ($attributes as $key => $value) { |
| 153 | 153 | // is a custom sanitization callback specified ? |
| 154 | - if ( isset($custom_sanitization[$key])) { |
|
| 154 | + if (isset($custom_sanitization[$key])) { |
|
| 155 | 155 | $callback = $custom_sanitization[$key]; |
| 156 | 156 | if ($callback === 'skip_sanitization') { |
| 157 | 157 | $attributes[$key] = $value; |
| 158 | 158 | continue; |
| 159 | - } else if (function_exists($callback)){ |
|
| 159 | + } else if (function_exists($callback)) { |
|
| 160 | 160 | $attributes[$key] = $callback($value); |
| 161 | 161 | continue; |
| 162 | 162 | } |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | $shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class )); |
| 74 | 74 | $shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} ) |
| 75 | - ? EE_Registry::instance()->shortcodes->{$shortcode} |
|
| 76 | - : null; |
|
| 75 | + ? EE_Registry::instance()->shortcodes->{$shortcode} |
|
| 76 | + : null; |
|
| 77 | 77 | return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self' |
| 78 | - ? $shortcode_obj |
|
| 79 | - : new $shortcode_class(); |
|
| 78 | + ? $shortcode_obj |
|
| 79 | + : new $shortcode_class(); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -142,59 +142,59 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Performs basic sanitization on shortcode attributes |
|
| 147 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
| 148 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
| 149 | - * This can be overridden by supplying an array for the $custom_sanitization param, |
|
| 150 | - * where keys match keys in your attributes array, |
|
| 151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | - * So for example, if you had an integer attribute named "event_id" |
|
| 153 | - * that you wanted to be sanitized using absint(), |
|
| 154 | - * then you would pass the following for your $custom_sanitization array: |
|
| 155 | - * array('event_id' => 'absint') |
|
| 156 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
| 157 | - * |
|
| 158 | - * @param array $attributes |
|
| 159 | - * @param array $custom_sanitization |
|
| 160 | - * @return array |
|
| 161 | - */ |
|
| 162 | - public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
| 163 | - { |
|
| 164 | - foreach ($attributes as $key => $value) { |
|
| 165 | - // is a custom sanitization callback specified ? |
|
| 166 | - if ( isset($custom_sanitization[$key])) { |
|
| 167 | - $callback = $custom_sanitization[$key]; |
|
| 168 | - if ($callback === 'skip_sanitization') { |
|
| 169 | - $attributes[$key] = $value; |
|
| 170 | - continue; |
|
| 171 | - } else if (function_exists($callback)){ |
|
| 172 | - $attributes[$key] = $callback($value); |
|
| 173 | - continue; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - switch (true) { |
|
| 177 | - case $value === null : |
|
| 178 | - case is_int($value) : |
|
| 179 | - case is_float($value) : |
|
| 180 | - // typical booleans |
|
| 181 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
| 182 | - $attributes[$key] = $value; |
|
| 183 | - break; |
|
| 184 | - case is_string($value) : |
|
| 185 | - $attributes[$key] = sanitize_text_field($value); |
|
| 186 | - break; |
|
| 187 | - case is_array($value) : |
|
| 188 | - $attributes[$key] = \EES_Shortcode::sanitize_attributes($value); |
|
| 189 | - break; |
|
| 190 | - default : |
|
| 191 | - // only remaining data types are Object and Resource |
|
| 192 | - // which are not allowed as shortcode attributes |
|
| 193 | - $attributes[$key] = null; |
|
| 194 | - break; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - return $attributes; |
|
| 145 | + /** |
|
| 146 | + * Performs basic sanitization on shortcode attributes |
|
| 147 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
| 148 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
| 149 | + * This can be overridden by supplying an array for the $custom_sanitization param, |
|
| 150 | + * where keys match keys in your attributes array, |
|
| 151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | + * So for example, if you had an integer attribute named "event_id" |
|
| 153 | + * that you wanted to be sanitized using absint(), |
|
| 154 | + * then you would pass the following for your $custom_sanitization array: |
|
| 155 | + * array('event_id' => 'absint') |
|
| 156 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
| 157 | + * |
|
| 158 | + * @param array $attributes |
|
| 159 | + * @param array $custom_sanitization |
|
| 160 | + * @return array |
|
| 161 | + */ |
|
| 162 | + public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
| 163 | + { |
|
| 164 | + foreach ($attributes as $key => $value) { |
|
| 165 | + // is a custom sanitization callback specified ? |
|
| 166 | + if ( isset($custom_sanitization[$key])) { |
|
| 167 | + $callback = $custom_sanitization[$key]; |
|
| 168 | + if ($callback === 'skip_sanitization') { |
|
| 169 | + $attributes[$key] = $value; |
|
| 170 | + continue; |
|
| 171 | + } else if (function_exists($callback)){ |
|
| 172 | + $attributes[$key] = $callback($value); |
|
| 173 | + continue; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + switch (true) { |
|
| 177 | + case $value === null : |
|
| 178 | + case is_int($value) : |
|
| 179 | + case is_float($value) : |
|
| 180 | + // typical booleans |
|
| 181 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
| 182 | + $attributes[$key] = $value; |
|
| 183 | + break; |
|
| 184 | + case is_string($value) : |
|
| 185 | + $attributes[$key] = sanitize_text_field($value); |
|
| 186 | + break; |
|
| 187 | + case is_array($value) : |
|
| 188 | + $attributes[$key] = \EES_Shortcode::sanitize_attributes($value); |
|
| 189 | + break; |
|
| 190 | + default : |
|
| 191 | + // only remaining data types are Object and Resource |
|
| 192 | + // which are not allowed as shortcode attributes |
|
| 193 | + $attributes[$key] = null; |
|
| 194 | + break; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + return $attributes; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,244 +14,244 @@ discard block |
||
| 14 | 14 | class EEH_Activation |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * constant used to indicate a cron task is no longer in use |
|
| 19 | - */ |
|
| 20 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * option name that will indicate whether or not we still |
|
| 24 | - * need to create EE's folders in the uploads directory |
|
| 25 | - * (because if EE was installed without file system access, |
|
| 26 | - * we need to request credentials before we can create them) |
|
| 27 | - */ |
|
| 28 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * WP_User->ID |
|
| 32 | - * |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - private static $_default_creator_id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | - * This prevents doing that for EVERY single addon. |
|
| 43 | - * |
|
| 44 | - * @var boolean |
|
| 45 | - */ |
|
| 46 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | - */ |
|
| 51 | - private static $table_analysis; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | - */ |
|
| 56 | - private static $table_manager; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | - */ |
|
| 62 | - public static function getTableAnalysis() |
|
| 63 | - { |
|
| 64 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | - } |
|
| 67 | - return self::$table_analysis; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | - */ |
|
| 74 | - public static function getTableManager() |
|
| 75 | - { |
|
| 76 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | - } |
|
| 79 | - return self::$table_manager; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ensure_table_name_has_prefix |
|
| 85 | - * |
|
| 86 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | - * @access public |
|
| 88 | - * @static |
|
| 89 | - * @param $table_name |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | - { |
|
| 94 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * system_initialization |
|
| 100 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @static |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public static function system_initialization() |
|
| 108 | - { |
|
| 109 | - EEH_Activation::reset_and_update_config(); |
|
| 110 | - //which is fired BEFORE activation of plugin anyways |
|
| 111 | - EEH_Activation::verify_default_pages_exist(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Sets the database schema and creates folders. This should |
|
| 117 | - * be called on plugin activation and reactivation |
|
| 118 | - * |
|
| 119 | - * @return boolean success, whether the database and folders are setup properly |
|
| 120 | - * @throws \EE_Error |
|
| 121 | - */ |
|
| 122 | - public static function initialize_db_and_folders() |
|
| 123 | - { |
|
| 124 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | - $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | - return $good_filesystem && $good_db; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | - * with default and initial data. This should be called |
|
| 133 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | - * of running migration scripts |
|
| 135 | - * |
|
| 136 | - * @throws \EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function initialize_db_content() |
|
| 139 | - { |
|
| 140 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | - |
|
| 146 | - EEH_Activation::initialize_system_questions(); |
|
| 147 | - EEH_Activation::insert_default_status_codes(); |
|
| 148 | - EEH_Activation::generate_default_message_templates(); |
|
| 149 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | - |
|
| 152 | - EEH_Activation::validate_messages_system(); |
|
| 153 | - EEH_Activation::insert_default_payment_methods(); |
|
| 154 | - //in case we've |
|
| 155 | - EEH_Activation::remove_cron_tasks(); |
|
| 156 | - EEH_Activation::create_cron_tasks(); |
|
| 157 | - // remove all TXN locks since that is being done via extra meta now |
|
| 158 | - delete_option('ee_locked_transactions'); |
|
| 159 | - //also, check for CAF default db content |
|
| 160 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | - //which users really won't care about on initial activation |
|
| 163 | - EE_Error::overwrite_success(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | - * (null) |
|
| 172 | - * |
|
| 173 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | - * @return array |
|
| 176 | - * @throws \EE_Error |
|
| 177 | - */ |
|
| 178 | - public static function get_cron_tasks($which_to_include) |
|
| 179 | - { |
|
| 180 | - $cron_tasks = apply_filters( |
|
| 181 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | - array( |
|
| 183 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 17 | + /** |
|
| 18 | + * constant used to indicate a cron task is no longer in use |
|
| 19 | + */ |
|
| 20 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * option name that will indicate whether or not we still |
|
| 24 | + * need to create EE's folders in the uploads directory |
|
| 25 | + * (because if EE was installed without file system access, |
|
| 26 | + * we need to request credentials before we can create them) |
|
| 27 | + */ |
|
| 28 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * WP_User->ID |
|
| 32 | + * |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + private static $_default_creator_id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | + * This prevents doing that for EVERY single addon. |
|
| 43 | + * |
|
| 44 | + * @var boolean |
|
| 45 | + */ |
|
| 46 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | + */ |
|
| 51 | + private static $table_analysis; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | + */ |
|
| 56 | + private static $table_manager; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | + */ |
|
| 62 | + public static function getTableAnalysis() |
|
| 63 | + { |
|
| 64 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | + } |
|
| 67 | + return self::$table_analysis; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | + */ |
|
| 74 | + public static function getTableManager() |
|
| 75 | + { |
|
| 76 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | + } |
|
| 79 | + return self::$table_manager; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ensure_table_name_has_prefix |
|
| 85 | + * |
|
| 86 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | + * @access public |
|
| 88 | + * @static |
|
| 89 | + * @param $table_name |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | + { |
|
| 94 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * system_initialization |
|
| 100 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @static |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public static function system_initialization() |
|
| 108 | + { |
|
| 109 | + EEH_Activation::reset_and_update_config(); |
|
| 110 | + //which is fired BEFORE activation of plugin anyways |
|
| 111 | + EEH_Activation::verify_default_pages_exist(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Sets the database schema and creates folders. This should |
|
| 117 | + * be called on plugin activation and reactivation |
|
| 118 | + * |
|
| 119 | + * @return boolean success, whether the database and folders are setup properly |
|
| 120 | + * @throws \EE_Error |
|
| 121 | + */ |
|
| 122 | + public static function initialize_db_and_folders() |
|
| 123 | + { |
|
| 124 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | + $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | + return $good_filesystem && $good_db; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | + * with default and initial data. This should be called |
|
| 133 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | + * of running migration scripts |
|
| 135 | + * |
|
| 136 | + * @throws \EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function initialize_db_content() |
|
| 139 | + { |
|
| 140 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | + |
|
| 146 | + EEH_Activation::initialize_system_questions(); |
|
| 147 | + EEH_Activation::insert_default_status_codes(); |
|
| 148 | + EEH_Activation::generate_default_message_templates(); |
|
| 149 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | + |
|
| 152 | + EEH_Activation::validate_messages_system(); |
|
| 153 | + EEH_Activation::insert_default_payment_methods(); |
|
| 154 | + //in case we've |
|
| 155 | + EEH_Activation::remove_cron_tasks(); |
|
| 156 | + EEH_Activation::create_cron_tasks(); |
|
| 157 | + // remove all TXN locks since that is being done via extra meta now |
|
| 158 | + delete_option('ee_locked_transactions'); |
|
| 159 | + //also, check for CAF default db content |
|
| 160 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | + //which users really won't care about on initial activation |
|
| 163 | + EE_Error::overwrite_success(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | + * (null) |
|
| 172 | + * |
|
| 173 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | + * @return array |
|
| 176 | + * @throws \EE_Error |
|
| 177 | + */ |
|
| 178 | + public static function get_cron_tasks($which_to_include) |
|
| 179 | + { |
|
| 180 | + $cron_tasks = apply_filters( |
|
| 181 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | + array( |
|
| 183 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 184 | 184 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
| 185 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 188 | - ) |
|
| 189 | - ); |
|
| 190 | - if ($which_to_include === 'old') { |
|
| 191 | - $cron_tasks = array_filter( |
|
| 192 | - $cron_tasks, |
|
| 193 | - function ($value) { |
|
| 194 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 195 | - } |
|
| 196 | - ); |
|
| 197 | - } elseif ($which_to_include === 'current') { |
|
| 198 | - $cron_tasks = array_filter($cron_tasks); |
|
| 199 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 200 | - throw new EE_Error( |
|
| 201 | - sprintf( |
|
| 202 | - __( |
|
| 203 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ), |
|
| 206 | - $which_to_include |
|
| 207 | - ) |
|
| 208 | - ); |
|
| 209 | - } |
|
| 210 | - return $cron_tasks; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 216 | - * |
|
| 217 | - * @throws \EE_Error |
|
| 218 | - */ |
|
| 219 | - public static function create_cron_tasks() |
|
| 220 | - { |
|
| 221 | - |
|
| 222 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 223 | - if (! wp_next_scheduled($hook_name)) { |
|
| 224 | - /** |
|
| 225 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 226 | - */ |
|
| 227 | - if (is_array($frequency) |
|
| 228 | - && count($frequency) === 2 |
|
| 229 | - && isset($frequency[0], $frequency[1]) |
|
| 230 | - ) { |
|
| 231 | - $start_timestamp = $frequency[0]; |
|
| 232 | - $frequency = $frequency[1]; |
|
| 233 | - } else { |
|
| 234 | - $start_timestamp = time(); |
|
| 235 | - } |
|
| 236 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 245 | - * |
|
| 246 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 247 | - * @throws \EE_Error |
|
| 248 | - */ |
|
| 249 | - public static function remove_cron_tasks($remove_all = true) |
|
| 250 | - { |
|
| 251 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 252 | - $crons = _get_cron_array(); |
|
| 253 | - $crons = is_array($crons) ? $crons : array(); |
|
| 254 | - /* reminder of what $crons look like: |
|
| 185 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 188 | + ) |
|
| 189 | + ); |
|
| 190 | + if ($which_to_include === 'old') { |
|
| 191 | + $cron_tasks = array_filter( |
|
| 192 | + $cron_tasks, |
|
| 193 | + function ($value) { |
|
| 194 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 195 | + } |
|
| 196 | + ); |
|
| 197 | + } elseif ($which_to_include === 'current') { |
|
| 198 | + $cron_tasks = array_filter($cron_tasks); |
|
| 199 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 200 | + throw new EE_Error( |
|
| 201 | + sprintf( |
|
| 202 | + __( |
|
| 203 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ), |
|
| 206 | + $which_to_include |
|
| 207 | + ) |
|
| 208 | + ); |
|
| 209 | + } |
|
| 210 | + return $cron_tasks; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 216 | + * |
|
| 217 | + * @throws \EE_Error |
|
| 218 | + */ |
|
| 219 | + public static function create_cron_tasks() |
|
| 220 | + { |
|
| 221 | + |
|
| 222 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 223 | + if (! wp_next_scheduled($hook_name)) { |
|
| 224 | + /** |
|
| 225 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 226 | + */ |
|
| 227 | + if (is_array($frequency) |
|
| 228 | + && count($frequency) === 2 |
|
| 229 | + && isset($frequency[0], $frequency[1]) |
|
| 230 | + ) { |
|
| 231 | + $start_timestamp = $frequency[0]; |
|
| 232 | + $frequency = $frequency[1]; |
|
| 233 | + } else { |
|
| 234 | + $start_timestamp = time(); |
|
| 235 | + } |
|
| 236 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 245 | + * |
|
| 246 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 247 | + * @throws \EE_Error |
|
| 248 | + */ |
|
| 249 | + public static function remove_cron_tasks($remove_all = true) |
|
| 250 | + { |
|
| 251 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 252 | + $crons = _get_cron_array(); |
|
| 253 | + $crons = is_array($crons) ? $crons : array(); |
|
| 254 | + /* reminder of what $crons look like: |
|
| 255 | 255 | * Top-level keys are timestamps, and their values are arrays. |
| 256 | 256 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 257 | 257 | * and their values are arrays. |
@@ -268,971 +268,971 @@ discard block |
||
| 268 | 268 | * ... |
| 269 | 269 | * ... |
| 270 | 270 | */ |
| 271 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 272 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 273 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 274 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 275 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 277 | - ) { |
|
| 278 | - unset($crons[$timestamp][$hook_name]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - //also take care of any empty cron timestamps. |
|
| 282 | - if (empty($hooks_to_fire_at_time)) { |
|
| 283 | - unset($crons[$timestamp]); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - _set_cron_array($crons); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * CPT_initialization |
|
| 293 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 294 | - * |
|
| 295 | - * @access public |
|
| 296 | - * @static |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function CPT_initialization() |
|
| 300 | - { |
|
| 301 | - // register Custom Post Types |
|
| 302 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 303 | - flush_rewrite_rules(); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * reset_and_update_config |
|
| 310 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 311 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 312 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @static |
|
| 316 | - * @return void |
|
| 317 | - */ |
|
| 318 | - public static function reset_and_update_config() |
|
| 319 | - { |
|
| 320 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 321 | - add_filter( |
|
| 322 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 323 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 324 | - 10, |
|
| 325 | - 3 |
|
| 326 | - ); |
|
| 327 | - //EE_Config::reset(); |
|
| 328 | - if (! EE_Config::logging_enabled()) { |
|
| 329 | - delete_option(EE_Config::LOG_NAME); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * load_calendar_config |
|
| 336 | - * |
|
| 337 | - * @access public |
|
| 338 | - * @return void |
|
| 339 | - */ |
|
| 340 | - public static function load_calendar_config() |
|
| 341 | - { |
|
| 342 | - // grab array of all plugin folders and loop thru it |
|
| 343 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 344 | - if (empty($plugins)) { |
|
| 345 | - return; |
|
| 346 | - } |
|
| 347 | - foreach ($plugins as $plugin_path) { |
|
| 348 | - // grab plugin folder name from path |
|
| 349 | - $plugin = basename($plugin_path); |
|
| 350 | - // drill down to Espresso plugins |
|
| 351 | - // then to calendar related plugins |
|
| 352 | - if ( |
|
| 353 | - strpos($plugin, 'espresso') !== false |
|
| 354 | - || strpos($plugin, 'Espresso') !== false |
|
| 355 | - || strpos($plugin, 'ee4') !== false |
|
| 356 | - || strpos($plugin, 'EE4') !== false |
|
| 357 | - || strpos($plugin, 'calendar') !== false |
|
| 358 | - ) { |
|
| 359 | - // this is what we are looking for |
|
| 360 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 361 | - // does it exist in this folder ? |
|
| 362 | - if (is_readable($calendar_config)) { |
|
| 363 | - // YEAH! let's load it |
|
| 364 | - require_once($calendar_config); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * _migrate_old_config_data |
|
| 374 | - * |
|
| 375 | - * @access public |
|
| 376 | - * @param array|stdClass $settings |
|
| 377 | - * @param string $config |
|
| 378 | - * @param \EE_Config $EE_Config |
|
| 379 | - * @return \stdClass |
|
| 380 | - */ |
|
| 381 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 382 | - { |
|
| 383 | - $convert_from_array = array('addons'); |
|
| 384 | - // in case old settings were saved as an array |
|
| 385 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 386 | - // convert existing settings to an object |
|
| 387 | - $config_array = $settings; |
|
| 388 | - $settings = new stdClass(); |
|
| 389 | - foreach ($config_array as $key => $value) { |
|
| 390 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 391 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 392 | - } else { |
|
| 393 | - $settings->{$key} = $value; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 397 | - } |
|
| 398 | - return $settings; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * deactivate_event_espresso |
|
| 404 | - * |
|
| 405 | - * @access public |
|
| 406 | - * @static |
|
| 407 | - * @return void |
|
| 408 | - */ |
|
| 409 | - public static function deactivate_event_espresso() |
|
| 410 | - { |
|
| 411 | - // check permissions |
|
| 412 | - if (current_user_can('activate_plugins')) { |
|
| 413 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * verify_default_pages_exist |
|
| 423 | - * |
|
| 424 | - * @access public |
|
| 425 | - * @static |
|
| 426 | - * @return void |
|
| 427 | - */ |
|
| 428 | - public static function verify_default_pages_exist() |
|
| 429 | - { |
|
| 430 | - $critical_page_problem = false; |
|
| 431 | - $critical_pages = array( |
|
| 432 | - array( |
|
| 433 | - 'id' => 'reg_page_id', |
|
| 434 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 435 | - 'post' => null, |
|
| 436 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 437 | - ), |
|
| 438 | - array( |
|
| 439 | - 'id' => 'txn_page_id', |
|
| 440 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 441 | - 'post' => null, |
|
| 442 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 443 | - ), |
|
| 444 | - array( |
|
| 445 | - 'id' => 'thank_you_page_id', |
|
| 446 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 447 | - 'post' => null, |
|
| 448 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 449 | - ), |
|
| 450 | - array( |
|
| 451 | - 'id' => 'cancel_page_id', |
|
| 452 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 453 | - 'post' => null, |
|
| 454 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 455 | - ), |
|
| 456 | - ); |
|
| 457 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 458 | - foreach ($critical_pages as $critical_page) { |
|
| 459 | - // is critical page ID set in config ? |
|
| 460 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 461 | - // attempt to find post by ID |
|
| 462 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 463 | - } |
|
| 464 | - // no dice? |
|
| 465 | - if ($critical_page['post'] === null) { |
|
| 466 | - // attempt to find post by title |
|
| 467 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 468 | - // still nothing? |
|
| 469 | - if ($critical_page['post'] === null) { |
|
| 470 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 471 | - // REALLY? Still nothing ??!?!? |
|
| 472 | - if ($critical_page['post'] === null) { |
|
| 473 | - $msg = __( |
|
| 474 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 475 | - 'event_espresso' |
|
| 476 | - ); |
|
| 477 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | - break; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - // track post_shortcodes |
|
| 483 | - if ($critical_page['post']) { |
|
| 484 | - EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 485 | - } |
|
| 486 | - // check that Post ID matches critical page ID in config |
|
| 487 | - if ( |
|
| 488 | - isset($critical_page['post']->ID) |
|
| 489 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 490 | - ) { |
|
| 491 | - //update Config with post ID |
|
| 492 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 493 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 494 | - $msg = __( |
|
| 495 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 496 | - 'event_espresso' |
|
| 497 | - ); |
|
| 498 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - $critical_page_problem = |
|
| 502 | - ! isset($critical_page['post']->post_status) |
|
| 503 | - || $critical_page['post']->post_status !== 'publish' |
|
| 504 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 505 | - ? true |
|
| 506 | - : $critical_page_problem; |
|
| 507 | - } |
|
| 508 | - if ($critical_page_problem) { |
|
| 509 | - $msg = sprintf( |
|
| 510 | - __( |
|
| 511 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ), |
|
| 514 | - '<a href="' |
|
| 515 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 516 | - . '">' |
|
| 517 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 518 | - . '</a>' |
|
| 519 | - ); |
|
| 520 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 521 | - } |
|
| 522 | - if (EE_Error::has_notices()) { |
|
| 523 | - EE_Error::get_notices(false, true, true); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Returns the first post which uses the specified shortcode |
|
| 531 | - * |
|
| 532 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 533 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 534 | - * "[ESPRESSO_THANK_YOU" |
|
| 535 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 536 | - * parameter to the shortcode |
|
| 537 | - * @return WP_Post or NULl |
|
| 538 | - */ |
|
| 539 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 540 | - { |
|
| 541 | - global $wpdb; |
|
| 542 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 543 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 544 | - if ($post_id) { |
|
| 545 | - return get_post($post_id); |
|
| 546 | - } else { |
|
| 547 | - return null; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * This function generates a post for critical espresso pages |
|
| 554 | - * |
|
| 555 | - * @access public |
|
| 556 | - * @static |
|
| 557 | - * @param array $critical_page |
|
| 558 | - * @return array |
|
| 559 | - */ |
|
| 560 | - public static function create_critical_page($critical_page) |
|
| 561 | - { |
|
| 562 | - |
|
| 563 | - $post_args = array( |
|
| 564 | - 'post_title' => $critical_page['name'], |
|
| 565 | - 'post_status' => 'publish', |
|
| 566 | - 'post_type' => 'page', |
|
| 567 | - 'comment_status' => 'closed', |
|
| 568 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 569 | - ); |
|
| 570 | - |
|
| 571 | - $post_id = wp_insert_post($post_args); |
|
| 572 | - if (! $post_id) { |
|
| 573 | - $msg = sprintf( |
|
| 574 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 575 | - $critical_page['name'] |
|
| 576 | - ); |
|
| 577 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 578 | - return $critical_page; |
|
| 579 | - } |
|
| 580 | - // get newly created post's details |
|
| 581 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 582 | - $msg = sprintf( |
|
| 583 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 584 | - $critical_page['name'] |
|
| 585 | - ); |
|
| 586 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $critical_page; |
|
| 590 | - |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * This function adds a critical page's shortcode to the post_shortcodes array |
|
| 599 | - * |
|
| 600 | - * @access private |
|
| 601 | - * @static |
|
| 602 | - * @param array $critical_page |
|
| 603 | - * @return void |
|
| 604 | - */ |
|
| 605 | - private static function _track_critical_page_post_shortcodes($critical_page = array()) |
|
| 606 | - { |
|
| 607 | - // check the goods |
|
| 608 | - if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 609 | - $msg = sprintf( |
|
| 610 | - __( |
|
| 611 | - 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', |
|
| 612 | - 'event_espresso' |
|
| 613 | - ), |
|
| 614 | - $critical_page['name'] |
|
| 615 | - ); |
|
| 616 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | - return; |
|
| 618 | - } |
|
| 619 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 620 | - // map shortcode to post |
|
| 621 | - $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 622 | - // and make sure it's NOT added to the WP "Posts Page" |
|
| 623 | - // name of the WP Posts Page |
|
| 624 | - $posts_page = EE_Config::get_page_for_posts(); |
|
| 625 | - if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 626 | - unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 627 | - } |
|
| 628 | - if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 629 | - unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 630 | - } |
|
| 631 | - // update post_shortcode CFG |
|
| 632 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 633 | - // verify that saved ID in the config matches the ID for the post the shortcode is on |
|
| 634 | - if ( |
|
| 635 | - EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] |
|
| 636 | - !== $critical_page['post']->ID |
|
| 637 | - ) { |
|
| 638 | - $msg = sprintf( |
|
| 639 | - __( |
|
| 640 | - 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', |
|
| 641 | - 'event_espresso' |
|
| 642 | - ), |
|
| 643 | - $critical_page['name'] |
|
| 644 | - ); |
|
| 645 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 653 | - * The role being used to check is filterable. |
|
| 654 | - * |
|
| 655 | - * @since 4.6.0 |
|
| 656 | - * @global WPDB $wpdb |
|
| 657 | - * @return mixed null|int WP_user ID or NULL |
|
| 658 | - */ |
|
| 659 | - public static function get_default_creator_id() |
|
| 660 | - { |
|
| 661 | - global $wpdb; |
|
| 662 | - if ( ! empty(self::$_default_creator_id)) { |
|
| 663 | - return self::$_default_creator_id; |
|
| 664 | - }/**/ |
|
| 665 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 666 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 667 | - $pre_filtered_id = apply_filters( |
|
| 668 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 669 | - false, |
|
| 670 | - $role_to_check |
|
| 671 | - ); |
|
| 672 | - if ($pre_filtered_id !== false) { |
|
| 673 | - return (int)$pre_filtered_id; |
|
| 674 | - } |
|
| 675 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 676 | - $query = $wpdb->prepare( |
|
| 677 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 678 | - '%' . $role_to_check . '%' |
|
| 679 | - ); |
|
| 680 | - $user_id = $wpdb->get_var($query); |
|
| 681 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 682 | - if ($user_id && (int)$user_id) { |
|
| 683 | - self::$_default_creator_id = (int)$user_id; |
|
| 684 | - return self::$_default_creator_id; |
|
| 685 | - } else { |
|
| 686 | - return null; |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 694 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 695 | - * but includes extra logic regarding activations. |
|
| 696 | - * |
|
| 697 | - * @access public |
|
| 698 | - * @static |
|
| 699 | - * @param string $table_name without the $wpdb->prefix |
|
| 700 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 701 | - * table query) |
|
| 702 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 703 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 704 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 705 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 706 | - * you just want to verify the table exists and matches this definition |
|
| 707 | - * (and if it HAS data in it you want to leave it be) |
|
| 708 | - * @return void |
|
| 709 | - * @throws EE_Error if there are database errors |
|
| 710 | - */ |
|
| 711 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 712 | - { |
|
| 713 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 714 | - return; |
|
| 715 | - } |
|
| 716 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 717 | - if ( ! function_exists('dbDelta')) { |
|
| 718 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 719 | - } |
|
| 720 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 721 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 722 | - // do we need to first delete an existing version of this table ? |
|
| 723 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 724 | - // ok, delete the table... but ONLY if it's empty |
|
| 725 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 726 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 727 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 728 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 729 | - } else if ( ! $deleted_safely) { |
|
| 730 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 731 | - error_log( |
|
| 732 | - sprintf( |
|
| 733 | - __( |
|
| 734 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 735 | - 'event_espresso' |
|
| 736 | - ), |
|
| 737 | - $wp_table_name, |
|
| 738 | - '<br/>', |
|
| 739 | - 'espresso_db_update' |
|
| 740 | - ) |
|
| 741 | - ); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 745 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * add_column_if_it_doesn't_exist |
|
| 752 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 753 | - * |
|
| 754 | - * @access public |
|
| 755 | - * @static |
|
| 756 | - * @deprecated instead use TableManager::addColumn() |
|
| 757 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 758 | - * @param string $column_name |
|
| 759 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 760 | - * 'VARCHAR(10)' |
|
| 761 | - * @return bool|int |
|
| 762 | - */ |
|
| 763 | - public static function add_column_if_it_doesnt_exist( |
|
| 764 | - $table_name, |
|
| 765 | - $column_name, |
|
| 766 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 767 | - ) { |
|
| 768 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * get_fields_on_table |
|
| 774 | - * Gets all the fields on the database table. |
|
| 775 | - * |
|
| 776 | - * @access public |
|
| 777 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 778 | - * @static |
|
| 779 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 780 | - * @return array of database column names |
|
| 781 | - */ |
|
| 782 | - public static function get_fields_on_table($table_name = null) |
|
| 783 | - { |
|
| 784 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * db_table_is_empty |
|
| 790 | - * |
|
| 791 | - * @access public\ |
|
| 792 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 793 | - * @static |
|
| 794 | - * @param string $table_name |
|
| 795 | - * @return bool |
|
| 796 | - */ |
|
| 797 | - public static function db_table_is_empty($table_name) |
|
| 798 | - { |
|
| 799 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * delete_db_table_if_empty |
|
| 805 | - * |
|
| 806 | - * @access public |
|
| 807 | - * @static |
|
| 808 | - * @param string $table_name |
|
| 809 | - * @return bool | int |
|
| 810 | - */ |
|
| 811 | - public static function delete_db_table_if_empty($table_name) |
|
| 812 | - { |
|
| 813 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 814 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 815 | - } |
|
| 816 | - return false; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * delete_unused_db_table |
|
| 822 | - * |
|
| 823 | - * @access public |
|
| 824 | - * @static |
|
| 825 | - * @deprecated instead use TableManager::dropTable() |
|
| 826 | - * @param string $table_name |
|
| 827 | - * @return bool | int |
|
| 828 | - */ |
|
| 829 | - public static function delete_unused_db_table($table_name) |
|
| 830 | - { |
|
| 831 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * drop_index |
|
| 837 | - * |
|
| 838 | - * @access public |
|
| 839 | - * @static |
|
| 840 | - * @deprecated instead use TableManager::dropIndex() |
|
| 841 | - * @param string $table_name |
|
| 842 | - * @param string $index_name |
|
| 843 | - * @return bool | int |
|
| 844 | - */ |
|
| 845 | - public static function drop_index($table_name, $index_name) |
|
| 846 | - { |
|
| 847 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * create_database_tables |
|
| 854 | - * |
|
| 855 | - * @access public |
|
| 856 | - * @static |
|
| 857 | - * @throws EE_Error |
|
| 858 | - * @return boolean success (whether database is setup properly or not) |
|
| 859 | - */ |
|
| 860 | - public static function create_database_tables() |
|
| 861 | - { |
|
| 862 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 863 | - //find the migration script that sets the database to be compatible with the code |
|
| 864 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 865 | - if ($dms_name) { |
|
| 866 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 867 | - $current_data_migration_script->set_migrating(false); |
|
| 868 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 869 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 870 | - if ($current_data_migration_script->get_errors()) { |
|
| 871 | - if (WP_DEBUG) { |
|
| 872 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 873 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 874 | - } |
|
| 875 | - } else { |
|
| 876 | - EE_Error::add_error( |
|
| 877 | - __( |
|
| 878 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 271 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 272 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 273 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 274 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 275 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 277 | + ) { |
|
| 278 | + unset($crons[$timestamp][$hook_name]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + //also take care of any empty cron timestamps. |
|
| 282 | + if (empty($hooks_to_fire_at_time)) { |
|
| 283 | + unset($crons[$timestamp]); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + _set_cron_array($crons); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * CPT_initialization |
|
| 293 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 294 | + * |
|
| 295 | + * @access public |
|
| 296 | + * @static |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function CPT_initialization() |
|
| 300 | + { |
|
| 301 | + // register Custom Post Types |
|
| 302 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 303 | + flush_rewrite_rules(); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * reset_and_update_config |
|
| 310 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 311 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 312 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @static |
|
| 316 | + * @return void |
|
| 317 | + */ |
|
| 318 | + public static function reset_and_update_config() |
|
| 319 | + { |
|
| 320 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 321 | + add_filter( |
|
| 322 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 323 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 324 | + 10, |
|
| 325 | + 3 |
|
| 326 | + ); |
|
| 327 | + //EE_Config::reset(); |
|
| 328 | + if (! EE_Config::logging_enabled()) { |
|
| 329 | + delete_option(EE_Config::LOG_NAME); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * load_calendar_config |
|
| 336 | + * |
|
| 337 | + * @access public |
|
| 338 | + * @return void |
|
| 339 | + */ |
|
| 340 | + public static function load_calendar_config() |
|
| 341 | + { |
|
| 342 | + // grab array of all plugin folders and loop thru it |
|
| 343 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 344 | + if (empty($plugins)) { |
|
| 345 | + return; |
|
| 346 | + } |
|
| 347 | + foreach ($plugins as $plugin_path) { |
|
| 348 | + // grab plugin folder name from path |
|
| 349 | + $plugin = basename($plugin_path); |
|
| 350 | + // drill down to Espresso plugins |
|
| 351 | + // then to calendar related plugins |
|
| 352 | + if ( |
|
| 353 | + strpos($plugin, 'espresso') !== false |
|
| 354 | + || strpos($plugin, 'Espresso') !== false |
|
| 355 | + || strpos($plugin, 'ee4') !== false |
|
| 356 | + || strpos($plugin, 'EE4') !== false |
|
| 357 | + || strpos($plugin, 'calendar') !== false |
|
| 358 | + ) { |
|
| 359 | + // this is what we are looking for |
|
| 360 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 361 | + // does it exist in this folder ? |
|
| 362 | + if (is_readable($calendar_config)) { |
|
| 363 | + // YEAH! let's load it |
|
| 364 | + require_once($calendar_config); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * _migrate_old_config_data |
|
| 374 | + * |
|
| 375 | + * @access public |
|
| 376 | + * @param array|stdClass $settings |
|
| 377 | + * @param string $config |
|
| 378 | + * @param \EE_Config $EE_Config |
|
| 379 | + * @return \stdClass |
|
| 380 | + */ |
|
| 381 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 382 | + { |
|
| 383 | + $convert_from_array = array('addons'); |
|
| 384 | + // in case old settings were saved as an array |
|
| 385 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 386 | + // convert existing settings to an object |
|
| 387 | + $config_array = $settings; |
|
| 388 | + $settings = new stdClass(); |
|
| 389 | + foreach ($config_array as $key => $value) { |
|
| 390 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 391 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 392 | + } else { |
|
| 393 | + $settings->{$key} = $value; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 397 | + } |
|
| 398 | + return $settings; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * deactivate_event_espresso |
|
| 404 | + * |
|
| 405 | + * @access public |
|
| 406 | + * @static |
|
| 407 | + * @return void |
|
| 408 | + */ |
|
| 409 | + public static function deactivate_event_espresso() |
|
| 410 | + { |
|
| 411 | + // check permissions |
|
| 412 | + if (current_user_can('activate_plugins')) { |
|
| 413 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * verify_default_pages_exist |
|
| 423 | + * |
|
| 424 | + * @access public |
|
| 425 | + * @static |
|
| 426 | + * @return void |
|
| 427 | + */ |
|
| 428 | + public static function verify_default_pages_exist() |
|
| 429 | + { |
|
| 430 | + $critical_page_problem = false; |
|
| 431 | + $critical_pages = array( |
|
| 432 | + array( |
|
| 433 | + 'id' => 'reg_page_id', |
|
| 434 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 435 | + 'post' => null, |
|
| 436 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 437 | + ), |
|
| 438 | + array( |
|
| 439 | + 'id' => 'txn_page_id', |
|
| 440 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 441 | + 'post' => null, |
|
| 442 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 443 | + ), |
|
| 444 | + array( |
|
| 445 | + 'id' => 'thank_you_page_id', |
|
| 446 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 447 | + 'post' => null, |
|
| 448 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 449 | + ), |
|
| 450 | + array( |
|
| 451 | + 'id' => 'cancel_page_id', |
|
| 452 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 453 | + 'post' => null, |
|
| 454 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 455 | + ), |
|
| 456 | + ); |
|
| 457 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 458 | + foreach ($critical_pages as $critical_page) { |
|
| 459 | + // is critical page ID set in config ? |
|
| 460 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 461 | + // attempt to find post by ID |
|
| 462 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 463 | + } |
|
| 464 | + // no dice? |
|
| 465 | + if ($critical_page['post'] === null) { |
|
| 466 | + // attempt to find post by title |
|
| 467 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 468 | + // still nothing? |
|
| 469 | + if ($critical_page['post'] === null) { |
|
| 470 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 471 | + // REALLY? Still nothing ??!?!? |
|
| 472 | + if ($critical_page['post'] === null) { |
|
| 473 | + $msg = __( |
|
| 474 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 475 | + 'event_espresso' |
|
| 476 | + ); |
|
| 477 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | + break; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + // track post_shortcodes |
|
| 483 | + if ($critical_page['post']) { |
|
| 484 | + EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 485 | + } |
|
| 486 | + // check that Post ID matches critical page ID in config |
|
| 487 | + if ( |
|
| 488 | + isset($critical_page['post']->ID) |
|
| 489 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 490 | + ) { |
|
| 491 | + //update Config with post ID |
|
| 492 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 493 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 494 | + $msg = __( |
|
| 495 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 496 | + 'event_espresso' |
|
| 497 | + ); |
|
| 498 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + $critical_page_problem = |
|
| 502 | + ! isset($critical_page['post']->post_status) |
|
| 503 | + || $critical_page['post']->post_status !== 'publish' |
|
| 504 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 505 | + ? true |
|
| 506 | + : $critical_page_problem; |
|
| 507 | + } |
|
| 508 | + if ($critical_page_problem) { |
|
| 509 | + $msg = sprintf( |
|
| 510 | + __( |
|
| 511 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ), |
|
| 514 | + '<a href="' |
|
| 515 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 516 | + . '">' |
|
| 517 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 518 | + . '</a>' |
|
| 519 | + ); |
|
| 520 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 521 | + } |
|
| 522 | + if (EE_Error::has_notices()) { |
|
| 523 | + EE_Error::get_notices(false, true, true); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Returns the first post which uses the specified shortcode |
|
| 531 | + * |
|
| 532 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 533 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 534 | + * "[ESPRESSO_THANK_YOU" |
|
| 535 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 536 | + * parameter to the shortcode |
|
| 537 | + * @return WP_Post or NULl |
|
| 538 | + */ |
|
| 539 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 540 | + { |
|
| 541 | + global $wpdb; |
|
| 542 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 543 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 544 | + if ($post_id) { |
|
| 545 | + return get_post($post_id); |
|
| 546 | + } else { |
|
| 547 | + return null; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * This function generates a post for critical espresso pages |
|
| 554 | + * |
|
| 555 | + * @access public |
|
| 556 | + * @static |
|
| 557 | + * @param array $critical_page |
|
| 558 | + * @return array |
|
| 559 | + */ |
|
| 560 | + public static function create_critical_page($critical_page) |
|
| 561 | + { |
|
| 562 | + |
|
| 563 | + $post_args = array( |
|
| 564 | + 'post_title' => $critical_page['name'], |
|
| 565 | + 'post_status' => 'publish', |
|
| 566 | + 'post_type' => 'page', |
|
| 567 | + 'comment_status' => 'closed', |
|
| 568 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 569 | + ); |
|
| 570 | + |
|
| 571 | + $post_id = wp_insert_post($post_args); |
|
| 572 | + if (! $post_id) { |
|
| 573 | + $msg = sprintf( |
|
| 574 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 575 | + $critical_page['name'] |
|
| 576 | + ); |
|
| 577 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 578 | + return $critical_page; |
|
| 579 | + } |
|
| 580 | + // get newly created post's details |
|
| 581 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 582 | + $msg = sprintf( |
|
| 583 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 584 | + $critical_page['name'] |
|
| 585 | + ); |
|
| 586 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $critical_page; |
|
| 590 | + |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * This function adds a critical page's shortcode to the post_shortcodes array |
|
| 599 | + * |
|
| 600 | + * @access private |
|
| 601 | + * @static |
|
| 602 | + * @param array $critical_page |
|
| 603 | + * @return void |
|
| 604 | + */ |
|
| 605 | + private static function _track_critical_page_post_shortcodes($critical_page = array()) |
|
| 606 | + { |
|
| 607 | + // check the goods |
|
| 608 | + if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 609 | + $msg = sprintf( |
|
| 610 | + __( |
|
| 611 | + 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', |
|
| 612 | + 'event_espresso' |
|
| 613 | + ), |
|
| 614 | + $critical_page['name'] |
|
| 615 | + ); |
|
| 616 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | + return; |
|
| 618 | + } |
|
| 619 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 620 | + // map shortcode to post |
|
| 621 | + $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 622 | + // and make sure it's NOT added to the WP "Posts Page" |
|
| 623 | + // name of the WP Posts Page |
|
| 624 | + $posts_page = EE_Config::get_page_for_posts(); |
|
| 625 | + if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 626 | + unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 627 | + } |
|
| 628 | + if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 629 | + unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 630 | + } |
|
| 631 | + // update post_shortcode CFG |
|
| 632 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 633 | + // verify that saved ID in the config matches the ID for the post the shortcode is on |
|
| 634 | + if ( |
|
| 635 | + EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] |
|
| 636 | + !== $critical_page['post']->ID |
|
| 637 | + ) { |
|
| 638 | + $msg = sprintf( |
|
| 639 | + __( |
|
| 640 | + 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', |
|
| 641 | + 'event_espresso' |
|
| 642 | + ), |
|
| 643 | + $critical_page['name'] |
|
| 644 | + ); |
|
| 645 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 653 | + * The role being used to check is filterable. |
|
| 654 | + * |
|
| 655 | + * @since 4.6.0 |
|
| 656 | + * @global WPDB $wpdb |
|
| 657 | + * @return mixed null|int WP_user ID or NULL |
|
| 658 | + */ |
|
| 659 | + public static function get_default_creator_id() |
|
| 660 | + { |
|
| 661 | + global $wpdb; |
|
| 662 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 663 | + return self::$_default_creator_id; |
|
| 664 | + }/**/ |
|
| 665 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 666 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 667 | + $pre_filtered_id = apply_filters( |
|
| 668 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 669 | + false, |
|
| 670 | + $role_to_check |
|
| 671 | + ); |
|
| 672 | + if ($pre_filtered_id !== false) { |
|
| 673 | + return (int)$pre_filtered_id; |
|
| 674 | + } |
|
| 675 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 676 | + $query = $wpdb->prepare( |
|
| 677 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 678 | + '%' . $role_to_check . '%' |
|
| 679 | + ); |
|
| 680 | + $user_id = $wpdb->get_var($query); |
|
| 681 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 682 | + if ($user_id && (int)$user_id) { |
|
| 683 | + self::$_default_creator_id = (int)$user_id; |
|
| 684 | + return self::$_default_creator_id; |
|
| 685 | + } else { |
|
| 686 | + return null; |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 694 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 695 | + * but includes extra logic regarding activations. |
|
| 696 | + * |
|
| 697 | + * @access public |
|
| 698 | + * @static |
|
| 699 | + * @param string $table_name without the $wpdb->prefix |
|
| 700 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 701 | + * table query) |
|
| 702 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 703 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 704 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 705 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 706 | + * you just want to verify the table exists and matches this definition |
|
| 707 | + * (and if it HAS data in it you want to leave it be) |
|
| 708 | + * @return void |
|
| 709 | + * @throws EE_Error if there are database errors |
|
| 710 | + */ |
|
| 711 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 712 | + { |
|
| 713 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 714 | + return; |
|
| 715 | + } |
|
| 716 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 717 | + if ( ! function_exists('dbDelta')) { |
|
| 718 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 719 | + } |
|
| 720 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 721 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 722 | + // do we need to first delete an existing version of this table ? |
|
| 723 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 724 | + // ok, delete the table... but ONLY if it's empty |
|
| 725 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 726 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 727 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 728 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 729 | + } else if ( ! $deleted_safely) { |
|
| 730 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 731 | + error_log( |
|
| 732 | + sprintf( |
|
| 733 | + __( |
|
| 734 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 735 | + 'event_espresso' |
|
| 736 | + ), |
|
| 737 | + $wp_table_name, |
|
| 738 | + '<br/>', |
|
| 739 | + 'espresso_db_update' |
|
| 740 | + ) |
|
| 741 | + ); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 745 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * add_column_if_it_doesn't_exist |
|
| 752 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 753 | + * |
|
| 754 | + * @access public |
|
| 755 | + * @static |
|
| 756 | + * @deprecated instead use TableManager::addColumn() |
|
| 757 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 758 | + * @param string $column_name |
|
| 759 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 760 | + * 'VARCHAR(10)' |
|
| 761 | + * @return bool|int |
|
| 762 | + */ |
|
| 763 | + public static function add_column_if_it_doesnt_exist( |
|
| 764 | + $table_name, |
|
| 765 | + $column_name, |
|
| 766 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 767 | + ) { |
|
| 768 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * get_fields_on_table |
|
| 774 | + * Gets all the fields on the database table. |
|
| 775 | + * |
|
| 776 | + * @access public |
|
| 777 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 778 | + * @static |
|
| 779 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 780 | + * @return array of database column names |
|
| 781 | + */ |
|
| 782 | + public static function get_fields_on_table($table_name = null) |
|
| 783 | + { |
|
| 784 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * db_table_is_empty |
|
| 790 | + * |
|
| 791 | + * @access public\ |
|
| 792 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 793 | + * @static |
|
| 794 | + * @param string $table_name |
|
| 795 | + * @return bool |
|
| 796 | + */ |
|
| 797 | + public static function db_table_is_empty($table_name) |
|
| 798 | + { |
|
| 799 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * delete_db_table_if_empty |
|
| 805 | + * |
|
| 806 | + * @access public |
|
| 807 | + * @static |
|
| 808 | + * @param string $table_name |
|
| 809 | + * @return bool | int |
|
| 810 | + */ |
|
| 811 | + public static function delete_db_table_if_empty($table_name) |
|
| 812 | + { |
|
| 813 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 814 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 815 | + } |
|
| 816 | + return false; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * delete_unused_db_table |
|
| 822 | + * |
|
| 823 | + * @access public |
|
| 824 | + * @static |
|
| 825 | + * @deprecated instead use TableManager::dropTable() |
|
| 826 | + * @param string $table_name |
|
| 827 | + * @return bool | int |
|
| 828 | + */ |
|
| 829 | + public static function delete_unused_db_table($table_name) |
|
| 830 | + { |
|
| 831 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * drop_index |
|
| 837 | + * |
|
| 838 | + * @access public |
|
| 839 | + * @static |
|
| 840 | + * @deprecated instead use TableManager::dropIndex() |
|
| 841 | + * @param string $table_name |
|
| 842 | + * @param string $index_name |
|
| 843 | + * @return bool | int |
|
| 844 | + */ |
|
| 845 | + public static function drop_index($table_name, $index_name) |
|
| 846 | + { |
|
| 847 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * create_database_tables |
|
| 854 | + * |
|
| 855 | + * @access public |
|
| 856 | + * @static |
|
| 857 | + * @throws EE_Error |
|
| 858 | + * @return boolean success (whether database is setup properly or not) |
|
| 859 | + */ |
|
| 860 | + public static function create_database_tables() |
|
| 861 | + { |
|
| 862 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 863 | + //find the migration script that sets the database to be compatible with the code |
|
| 864 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 865 | + if ($dms_name) { |
|
| 866 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 867 | + $current_data_migration_script->set_migrating(false); |
|
| 868 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 869 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 870 | + if ($current_data_migration_script->get_errors()) { |
|
| 871 | + if (WP_DEBUG) { |
|
| 872 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 873 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 874 | + } |
|
| 875 | + } else { |
|
| 876 | + EE_Error::add_error( |
|
| 877 | + __( |
|
| 878 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 879 | 879 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 880 | - 'event_espresso' |
|
| 881 | - ) |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - return false; |
|
| 885 | - } |
|
| 886 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 887 | - } else { |
|
| 888 | - EE_Error::add_error( |
|
| 889 | - __( |
|
| 890 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 880 | + 'event_espresso' |
|
| 881 | + ) |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + return false; |
|
| 885 | + } |
|
| 886 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 887 | + } else { |
|
| 888 | + EE_Error::add_error( |
|
| 889 | + __( |
|
| 890 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 891 | 891 | structure. So database is probably not setup properly', |
| 892 | - 'event_espresso' |
|
| 893 | - ), |
|
| 894 | - __FILE__, |
|
| 895 | - __FUNCTION__, |
|
| 896 | - __LINE__ |
|
| 897 | - ); |
|
| 898 | - return false; |
|
| 899 | - } |
|
| 900 | - return true; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * initialize_system_questions |
|
| 907 | - * |
|
| 908 | - * @access public |
|
| 909 | - * @static |
|
| 910 | - * @return void |
|
| 911 | - */ |
|
| 912 | - public static function initialize_system_questions() |
|
| 913 | - { |
|
| 914 | - // QUESTION GROUPS |
|
| 915 | - global $wpdb; |
|
| 916 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 917 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 918 | - // what we have |
|
| 919 | - $question_groups = $wpdb->get_col($SQL); |
|
| 920 | - // check the response |
|
| 921 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 922 | - // what we should have |
|
| 923 | - $QSG_systems = array(1, 2); |
|
| 924 | - // loop thru what we should have and compare to what we have |
|
| 925 | - foreach ($QSG_systems as $QSG_system) { |
|
| 926 | - // reset values array |
|
| 927 | - $QSG_values = array(); |
|
| 928 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 929 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 930 | - // add it |
|
| 931 | - switch ($QSG_system) { |
|
| 932 | - case 1: |
|
| 933 | - $QSG_values = array( |
|
| 934 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 935 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 936 | - 'QSG_desc' => '', |
|
| 937 | - 'QSG_order' => 1, |
|
| 938 | - 'QSG_show_group_name' => 1, |
|
| 939 | - 'QSG_show_group_desc' => 1, |
|
| 940 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 941 | - 'QSG_deleted' => 0, |
|
| 942 | - ); |
|
| 943 | - break; |
|
| 944 | - case 2: |
|
| 945 | - $QSG_values = array( |
|
| 946 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 947 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 948 | - 'QSG_desc' => '', |
|
| 949 | - 'QSG_order' => 2, |
|
| 950 | - 'QSG_show_group_name' => 1, |
|
| 951 | - 'QSG_show_group_desc' => 1, |
|
| 952 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 953 | - 'QSG_deleted' => 0, |
|
| 954 | - ); |
|
| 955 | - break; |
|
| 956 | - } |
|
| 957 | - // make sure we have some values before inserting them |
|
| 958 | - if (! empty($QSG_values)) { |
|
| 959 | - // insert system question |
|
| 960 | - $wpdb->insert( |
|
| 961 | - $table_name, |
|
| 962 | - $QSG_values, |
|
| 963 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 964 | - ); |
|
| 965 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - // QUESTIONS |
|
| 970 | - global $wpdb; |
|
| 971 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 972 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 973 | - // what we have |
|
| 974 | - $questions = $wpdb->get_col($SQL); |
|
| 975 | - // what we should have |
|
| 976 | - $QST_systems = array( |
|
| 977 | - 'fname', |
|
| 978 | - 'lname', |
|
| 979 | - 'email', |
|
| 980 | - 'address', |
|
| 981 | - 'address2', |
|
| 982 | - 'city', |
|
| 983 | - 'country', |
|
| 984 | - 'state', |
|
| 985 | - 'zip', |
|
| 986 | - 'phone', |
|
| 987 | - ); |
|
| 988 | - $order_for_group_1 = 1; |
|
| 989 | - $order_for_group_2 = 1; |
|
| 990 | - // loop thru what we should have and compare to what we have |
|
| 991 | - foreach ($QST_systems as $QST_system) { |
|
| 992 | - // reset values array |
|
| 993 | - $QST_values = array(); |
|
| 994 | - // if we don't have what we should have |
|
| 995 | - if (! in_array($QST_system, $questions)) { |
|
| 996 | - // add it |
|
| 997 | - switch ($QST_system) { |
|
| 998 | - case 'fname': |
|
| 999 | - $QST_values = array( |
|
| 1000 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 1001 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 1002 | - 'QST_system' => 'fname', |
|
| 1003 | - 'QST_type' => 'TEXT', |
|
| 1004 | - 'QST_required' => 1, |
|
| 1005 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1006 | - 'QST_order' => 1, |
|
| 1007 | - 'QST_admin_only' => 0, |
|
| 1008 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1009 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1010 | - 'QST_deleted' => 0, |
|
| 1011 | - ); |
|
| 1012 | - break; |
|
| 1013 | - case 'lname': |
|
| 1014 | - $QST_values = array( |
|
| 1015 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 1016 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 1017 | - 'QST_system' => 'lname', |
|
| 1018 | - 'QST_type' => 'TEXT', |
|
| 1019 | - 'QST_required' => 1, |
|
| 1020 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1021 | - 'QST_order' => 2, |
|
| 1022 | - 'QST_admin_only' => 0, |
|
| 1023 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1024 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1025 | - 'QST_deleted' => 0, |
|
| 1026 | - ); |
|
| 1027 | - break; |
|
| 1028 | - case 'email': |
|
| 1029 | - $QST_values = array( |
|
| 1030 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 1031 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 1032 | - 'QST_system' => 'email', |
|
| 1033 | - 'QST_type' => 'EMAIL', |
|
| 1034 | - 'QST_required' => 1, |
|
| 1035 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1036 | - 'QST_order' => 3, |
|
| 1037 | - 'QST_admin_only' => 0, |
|
| 1038 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1039 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1040 | - 'QST_deleted' => 0, |
|
| 1041 | - ); |
|
| 1042 | - break; |
|
| 1043 | - case 'address': |
|
| 1044 | - $QST_values = array( |
|
| 1045 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 1046 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 1047 | - 'QST_system' => 'address', |
|
| 1048 | - 'QST_type' => 'TEXT', |
|
| 1049 | - 'QST_required' => 0, |
|
| 1050 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1051 | - 'QST_order' => 4, |
|
| 1052 | - 'QST_admin_only' => 0, |
|
| 1053 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1054 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1055 | - 'QST_deleted' => 0, |
|
| 1056 | - ); |
|
| 1057 | - break; |
|
| 1058 | - case 'address2': |
|
| 1059 | - $QST_values = array( |
|
| 1060 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1061 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1062 | - 'QST_system' => 'address2', |
|
| 1063 | - 'QST_type' => 'TEXT', |
|
| 1064 | - 'QST_required' => 0, |
|
| 1065 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1066 | - 'QST_order' => 5, |
|
| 1067 | - 'QST_admin_only' => 0, |
|
| 1068 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1069 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1070 | - 'QST_deleted' => 0, |
|
| 1071 | - ); |
|
| 1072 | - break; |
|
| 1073 | - case 'city': |
|
| 1074 | - $QST_values = array( |
|
| 1075 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1076 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1077 | - 'QST_system' => 'city', |
|
| 1078 | - 'QST_type' => 'TEXT', |
|
| 1079 | - 'QST_required' => 0, |
|
| 1080 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1081 | - 'QST_order' => 6, |
|
| 1082 | - 'QST_admin_only' => 0, |
|
| 1083 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1084 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1085 | - 'QST_deleted' => 0, |
|
| 1086 | - ); |
|
| 1087 | - break; |
|
| 1088 | - case 'country': |
|
| 1089 | - $QST_values = array( |
|
| 1090 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1091 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1092 | - 'QST_system' => 'country', |
|
| 1093 | - 'QST_type' => 'COUNTRY', |
|
| 1094 | - 'QST_required' => 0, |
|
| 1095 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1096 | - 'QST_order' => 7, |
|
| 1097 | - 'QST_admin_only' => 0, |
|
| 1098 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1099 | - 'QST_deleted' => 0, |
|
| 1100 | - ); |
|
| 1101 | - break; |
|
| 1102 | - case 'state': |
|
| 1103 | - $QST_values = array( |
|
| 1104 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1105 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1106 | - 'QST_system' => 'state', |
|
| 1107 | - 'QST_type' => 'STATE', |
|
| 1108 | - 'QST_required' => 0, |
|
| 1109 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1110 | - 'QST_order' => 8, |
|
| 1111 | - 'QST_admin_only' => 0, |
|
| 1112 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1113 | - 'QST_deleted' => 0, |
|
| 1114 | - ); |
|
| 1115 | - break; |
|
| 1116 | - case 'zip': |
|
| 1117 | - $QST_values = array( |
|
| 1118 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1119 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1120 | - 'QST_system' => 'zip', |
|
| 1121 | - 'QST_type' => 'TEXT', |
|
| 1122 | - 'QST_required' => 0, |
|
| 1123 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1124 | - 'QST_order' => 9, |
|
| 1125 | - 'QST_admin_only' => 0, |
|
| 1126 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1127 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1128 | - 'QST_deleted' => 0, |
|
| 1129 | - ); |
|
| 1130 | - break; |
|
| 1131 | - case 'phone': |
|
| 1132 | - $QST_values = array( |
|
| 1133 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1134 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1135 | - 'QST_system' => 'phone', |
|
| 1136 | - 'QST_type' => 'TEXT', |
|
| 1137 | - 'QST_required' => 0, |
|
| 1138 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1139 | - 'QST_order' => 10, |
|
| 1140 | - 'QST_admin_only' => 0, |
|
| 1141 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1142 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1143 | - 'QST_deleted' => 0, |
|
| 1144 | - ); |
|
| 1145 | - break; |
|
| 1146 | - } |
|
| 1147 | - if (! empty($QST_values)) { |
|
| 1148 | - // insert system question |
|
| 1149 | - $wpdb->insert( |
|
| 1150 | - $table_name, |
|
| 1151 | - $QST_values, |
|
| 1152 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1153 | - ); |
|
| 1154 | - $QST_ID = $wpdb->insert_id; |
|
| 1155 | - // QUESTION GROUP QUESTIONS |
|
| 1156 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1157 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1158 | - } else { |
|
| 1159 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1160 | - } |
|
| 1161 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1162 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1163 | - } else { |
|
| 1164 | - $id_col = EEM_Question_Group::instance() |
|
| 1165 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1166 | - if (is_array($id_col)) { |
|
| 1167 | - $QSG_ID = reset($id_col); |
|
| 1168 | - } else { |
|
| 1169 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1170 | - EE_Log::instance()->log( |
|
| 1171 | - __FILE__, |
|
| 1172 | - __FUNCTION__, |
|
| 1173 | - sprintf( |
|
| 1174 | - __( |
|
| 1175 | - 'Could not associate question %1$s to a question group because no system question |
|
| 892 | + 'event_espresso' |
|
| 893 | + ), |
|
| 894 | + __FILE__, |
|
| 895 | + __FUNCTION__, |
|
| 896 | + __LINE__ |
|
| 897 | + ); |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 900 | + return true; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * initialize_system_questions |
|
| 907 | + * |
|
| 908 | + * @access public |
|
| 909 | + * @static |
|
| 910 | + * @return void |
|
| 911 | + */ |
|
| 912 | + public static function initialize_system_questions() |
|
| 913 | + { |
|
| 914 | + // QUESTION GROUPS |
|
| 915 | + global $wpdb; |
|
| 916 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 917 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 918 | + // what we have |
|
| 919 | + $question_groups = $wpdb->get_col($SQL); |
|
| 920 | + // check the response |
|
| 921 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 922 | + // what we should have |
|
| 923 | + $QSG_systems = array(1, 2); |
|
| 924 | + // loop thru what we should have and compare to what we have |
|
| 925 | + foreach ($QSG_systems as $QSG_system) { |
|
| 926 | + // reset values array |
|
| 927 | + $QSG_values = array(); |
|
| 928 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 929 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 930 | + // add it |
|
| 931 | + switch ($QSG_system) { |
|
| 932 | + case 1: |
|
| 933 | + $QSG_values = array( |
|
| 934 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 935 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 936 | + 'QSG_desc' => '', |
|
| 937 | + 'QSG_order' => 1, |
|
| 938 | + 'QSG_show_group_name' => 1, |
|
| 939 | + 'QSG_show_group_desc' => 1, |
|
| 940 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 941 | + 'QSG_deleted' => 0, |
|
| 942 | + ); |
|
| 943 | + break; |
|
| 944 | + case 2: |
|
| 945 | + $QSG_values = array( |
|
| 946 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 947 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 948 | + 'QSG_desc' => '', |
|
| 949 | + 'QSG_order' => 2, |
|
| 950 | + 'QSG_show_group_name' => 1, |
|
| 951 | + 'QSG_show_group_desc' => 1, |
|
| 952 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 953 | + 'QSG_deleted' => 0, |
|
| 954 | + ); |
|
| 955 | + break; |
|
| 956 | + } |
|
| 957 | + // make sure we have some values before inserting them |
|
| 958 | + if (! empty($QSG_values)) { |
|
| 959 | + // insert system question |
|
| 960 | + $wpdb->insert( |
|
| 961 | + $table_name, |
|
| 962 | + $QSG_values, |
|
| 963 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 964 | + ); |
|
| 965 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + // QUESTIONS |
|
| 970 | + global $wpdb; |
|
| 971 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 972 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 973 | + // what we have |
|
| 974 | + $questions = $wpdb->get_col($SQL); |
|
| 975 | + // what we should have |
|
| 976 | + $QST_systems = array( |
|
| 977 | + 'fname', |
|
| 978 | + 'lname', |
|
| 979 | + 'email', |
|
| 980 | + 'address', |
|
| 981 | + 'address2', |
|
| 982 | + 'city', |
|
| 983 | + 'country', |
|
| 984 | + 'state', |
|
| 985 | + 'zip', |
|
| 986 | + 'phone', |
|
| 987 | + ); |
|
| 988 | + $order_for_group_1 = 1; |
|
| 989 | + $order_for_group_2 = 1; |
|
| 990 | + // loop thru what we should have and compare to what we have |
|
| 991 | + foreach ($QST_systems as $QST_system) { |
|
| 992 | + // reset values array |
|
| 993 | + $QST_values = array(); |
|
| 994 | + // if we don't have what we should have |
|
| 995 | + if (! in_array($QST_system, $questions)) { |
|
| 996 | + // add it |
|
| 997 | + switch ($QST_system) { |
|
| 998 | + case 'fname': |
|
| 999 | + $QST_values = array( |
|
| 1000 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 1001 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 1002 | + 'QST_system' => 'fname', |
|
| 1003 | + 'QST_type' => 'TEXT', |
|
| 1004 | + 'QST_required' => 1, |
|
| 1005 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1006 | + 'QST_order' => 1, |
|
| 1007 | + 'QST_admin_only' => 0, |
|
| 1008 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1009 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1010 | + 'QST_deleted' => 0, |
|
| 1011 | + ); |
|
| 1012 | + break; |
|
| 1013 | + case 'lname': |
|
| 1014 | + $QST_values = array( |
|
| 1015 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 1016 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 1017 | + 'QST_system' => 'lname', |
|
| 1018 | + 'QST_type' => 'TEXT', |
|
| 1019 | + 'QST_required' => 1, |
|
| 1020 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1021 | + 'QST_order' => 2, |
|
| 1022 | + 'QST_admin_only' => 0, |
|
| 1023 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1024 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1025 | + 'QST_deleted' => 0, |
|
| 1026 | + ); |
|
| 1027 | + break; |
|
| 1028 | + case 'email': |
|
| 1029 | + $QST_values = array( |
|
| 1030 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 1031 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 1032 | + 'QST_system' => 'email', |
|
| 1033 | + 'QST_type' => 'EMAIL', |
|
| 1034 | + 'QST_required' => 1, |
|
| 1035 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1036 | + 'QST_order' => 3, |
|
| 1037 | + 'QST_admin_only' => 0, |
|
| 1038 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1039 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1040 | + 'QST_deleted' => 0, |
|
| 1041 | + ); |
|
| 1042 | + break; |
|
| 1043 | + case 'address': |
|
| 1044 | + $QST_values = array( |
|
| 1045 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 1046 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 1047 | + 'QST_system' => 'address', |
|
| 1048 | + 'QST_type' => 'TEXT', |
|
| 1049 | + 'QST_required' => 0, |
|
| 1050 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1051 | + 'QST_order' => 4, |
|
| 1052 | + 'QST_admin_only' => 0, |
|
| 1053 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1054 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1055 | + 'QST_deleted' => 0, |
|
| 1056 | + ); |
|
| 1057 | + break; |
|
| 1058 | + case 'address2': |
|
| 1059 | + $QST_values = array( |
|
| 1060 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1061 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1062 | + 'QST_system' => 'address2', |
|
| 1063 | + 'QST_type' => 'TEXT', |
|
| 1064 | + 'QST_required' => 0, |
|
| 1065 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1066 | + 'QST_order' => 5, |
|
| 1067 | + 'QST_admin_only' => 0, |
|
| 1068 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1069 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1070 | + 'QST_deleted' => 0, |
|
| 1071 | + ); |
|
| 1072 | + break; |
|
| 1073 | + case 'city': |
|
| 1074 | + $QST_values = array( |
|
| 1075 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1076 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1077 | + 'QST_system' => 'city', |
|
| 1078 | + 'QST_type' => 'TEXT', |
|
| 1079 | + 'QST_required' => 0, |
|
| 1080 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1081 | + 'QST_order' => 6, |
|
| 1082 | + 'QST_admin_only' => 0, |
|
| 1083 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1084 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1085 | + 'QST_deleted' => 0, |
|
| 1086 | + ); |
|
| 1087 | + break; |
|
| 1088 | + case 'country': |
|
| 1089 | + $QST_values = array( |
|
| 1090 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1091 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1092 | + 'QST_system' => 'country', |
|
| 1093 | + 'QST_type' => 'COUNTRY', |
|
| 1094 | + 'QST_required' => 0, |
|
| 1095 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1096 | + 'QST_order' => 7, |
|
| 1097 | + 'QST_admin_only' => 0, |
|
| 1098 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1099 | + 'QST_deleted' => 0, |
|
| 1100 | + ); |
|
| 1101 | + break; |
|
| 1102 | + case 'state': |
|
| 1103 | + $QST_values = array( |
|
| 1104 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1105 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1106 | + 'QST_system' => 'state', |
|
| 1107 | + 'QST_type' => 'STATE', |
|
| 1108 | + 'QST_required' => 0, |
|
| 1109 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1110 | + 'QST_order' => 8, |
|
| 1111 | + 'QST_admin_only' => 0, |
|
| 1112 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1113 | + 'QST_deleted' => 0, |
|
| 1114 | + ); |
|
| 1115 | + break; |
|
| 1116 | + case 'zip': |
|
| 1117 | + $QST_values = array( |
|
| 1118 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1119 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1120 | + 'QST_system' => 'zip', |
|
| 1121 | + 'QST_type' => 'TEXT', |
|
| 1122 | + 'QST_required' => 0, |
|
| 1123 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1124 | + 'QST_order' => 9, |
|
| 1125 | + 'QST_admin_only' => 0, |
|
| 1126 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1127 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1128 | + 'QST_deleted' => 0, |
|
| 1129 | + ); |
|
| 1130 | + break; |
|
| 1131 | + case 'phone': |
|
| 1132 | + $QST_values = array( |
|
| 1133 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1134 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1135 | + 'QST_system' => 'phone', |
|
| 1136 | + 'QST_type' => 'TEXT', |
|
| 1137 | + 'QST_required' => 0, |
|
| 1138 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1139 | + 'QST_order' => 10, |
|
| 1140 | + 'QST_admin_only' => 0, |
|
| 1141 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1142 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1143 | + 'QST_deleted' => 0, |
|
| 1144 | + ); |
|
| 1145 | + break; |
|
| 1146 | + } |
|
| 1147 | + if (! empty($QST_values)) { |
|
| 1148 | + // insert system question |
|
| 1149 | + $wpdb->insert( |
|
| 1150 | + $table_name, |
|
| 1151 | + $QST_values, |
|
| 1152 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1153 | + ); |
|
| 1154 | + $QST_ID = $wpdb->insert_id; |
|
| 1155 | + // QUESTION GROUP QUESTIONS |
|
| 1156 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1157 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1158 | + } else { |
|
| 1159 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1160 | + } |
|
| 1161 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1162 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1163 | + } else { |
|
| 1164 | + $id_col = EEM_Question_Group::instance() |
|
| 1165 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1166 | + if (is_array($id_col)) { |
|
| 1167 | + $QSG_ID = reset($id_col); |
|
| 1168 | + } else { |
|
| 1169 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1170 | + EE_Log::instance()->log( |
|
| 1171 | + __FILE__, |
|
| 1172 | + __FUNCTION__, |
|
| 1173 | + sprintf( |
|
| 1174 | + __( |
|
| 1175 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1176 | 1176 | group existed', |
| 1177 | - 'event_espresso' |
|
| 1178 | - ), |
|
| 1179 | - $QST_ID), |
|
| 1180 | - 'error'); |
|
| 1181 | - continue; |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - // add system questions to groups |
|
| 1185 | - $wpdb->insert( |
|
| 1186 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1187 | - array( |
|
| 1188 | - 'QSG_ID' => $QSG_ID, |
|
| 1189 | - 'QST_ID' => $QST_ID, |
|
| 1190 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1191 | - ), |
|
| 1192 | - array('%d', '%d', '%d') |
|
| 1193 | - ); |
|
| 1194 | - } |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1202 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1203 | - * |
|
| 1204 | - * @throws \EE_Error |
|
| 1205 | - */ |
|
| 1206 | - public static function insert_default_payment_methods() |
|
| 1207 | - { |
|
| 1208 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1209 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1210 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1211 | - } else { |
|
| 1212 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * insert_default_status_codes |
|
| 1218 | - * |
|
| 1219 | - * @access public |
|
| 1220 | - * @static |
|
| 1221 | - * @return void |
|
| 1222 | - */ |
|
| 1223 | - public static function insert_default_status_codes() |
|
| 1224 | - { |
|
| 1225 | - |
|
| 1226 | - global $wpdb; |
|
| 1227 | - |
|
| 1228 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1229 | - |
|
| 1230 | - $table_name = EEM_Status::instance()->table(); |
|
| 1231 | - |
|
| 1232 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1233 | - $wpdb->query($SQL); |
|
| 1234 | - |
|
| 1235 | - $SQL = "INSERT INTO $table_name |
|
| 1177 | + 'event_espresso' |
|
| 1178 | + ), |
|
| 1179 | + $QST_ID), |
|
| 1180 | + 'error'); |
|
| 1181 | + continue; |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + // add system questions to groups |
|
| 1185 | + $wpdb->insert( |
|
| 1186 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1187 | + array( |
|
| 1188 | + 'QSG_ID' => $QSG_ID, |
|
| 1189 | + 'QST_ID' => $QST_ID, |
|
| 1190 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1191 | + ), |
|
| 1192 | + array('%d', '%d', '%d') |
|
| 1193 | + ); |
|
| 1194 | + } |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1202 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1203 | + * |
|
| 1204 | + * @throws \EE_Error |
|
| 1205 | + */ |
|
| 1206 | + public static function insert_default_payment_methods() |
|
| 1207 | + { |
|
| 1208 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1209 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1210 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1211 | + } else { |
|
| 1212 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * insert_default_status_codes |
|
| 1218 | + * |
|
| 1219 | + * @access public |
|
| 1220 | + * @static |
|
| 1221 | + * @return void |
|
| 1222 | + */ |
|
| 1223 | + public static function insert_default_status_codes() |
|
| 1224 | + { |
|
| 1225 | + |
|
| 1226 | + global $wpdb; |
|
| 1227 | + |
|
| 1228 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1229 | + |
|
| 1230 | + $table_name = EEM_Status::instance()->table(); |
|
| 1231 | + |
|
| 1232 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1233 | + $wpdb->query($SQL); |
|
| 1234 | + |
|
| 1235 | + $SQL = "INSERT INTO $table_name |
|
| 1236 | 1236 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1237 | 1237 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1238 | 1238 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1272,521 +1272,521 @@ discard block |
||
| 1272 | 1272 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1273 | 1273 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1274 | 1274 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1275 | - $wpdb->query($SQL); |
|
| 1276 | - |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * create_upload_directories |
|
| 1284 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1285 | - * |
|
| 1286 | - * @access public |
|
| 1287 | - * @static |
|
| 1288 | - * @return boolean success of verifying upload directories exist |
|
| 1289 | - */ |
|
| 1290 | - public static function create_upload_directories() |
|
| 1291 | - { |
|
| 1292 | - // Create the required folders |
|
| 1293 | - $folders = array( |
|
| 1294 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1295 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1296 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1297 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1298 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1299 | - ); |
|
| 1300 | - foreach ($folders as $folder) { |
|
| 1301 | - try { |
|
| 1302 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1303 | - @ chmod($folder, 0755); |
|
| 1304 | - } catch (EE_Error $e) { |
|
| 1305 | - EE_Error::add_error( |
|
| 1306 | - sprintf( |
|
| 1307 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1308 | - $folder, |
|
| 1309 | - '<br />' . $e->getMessage() |
|
| 1310 | - ), |
|
| 1311 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1312 | - ); |
|
| 1313 | - //indicate we'll need to fix this later |
|
| 1314 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1315 | - return false; |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1319 | - //is disabled, there might be activation errors recorded in there |
|
| 1320 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1321 | - //remember EE's folders are all good |
|
| 1322 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1323 | - return true; |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - /** |
|
| 1327 | - * Whether the upload directories need to be fixed or not. |
|
| 1328 | - * If EE is installed but filesystem access isn't initially available, |
|
| 1329 | - * we need to get the user's filesystem credentials and THEN create them, |
|
| 1330 | - * so there might be period of time when EE is installed but its |
|
| 1331 | - * upload directories aren't available. This indicates such a state |
|
| 1332 | - * |
|
| 1333 | - * @return boolean |
|
| 1334 | - */ |
|
| 1335 | - public static function upload_directories_incomplete() |
|
| 1336 | - { |
|
| 1337 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * generate_default_message_templates |
|
| 1343 | - * |
|
| 1344 | - * @static |
|
| 1345 | - * @throws EE_Error |
|
| 1346 | - * @return bool true means new templates were created. |
|
| 1347 | - * false means no templates were created. |
|
| 1348 | - * This is NOT an error flag. To check for errors you will want |
|
| 1349 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1350 | - */ |
|
| 1351 | - public static function generate_default_message_templates() |
|
| 1352 | - { |
|
| 1353 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1354 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1355 | - /* |
|
| 1275 | + $wpdb->query($SQL); |
|
| 1276 | + |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * create_upload_directories |
|
| 1284 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1285 | + * |
|
| 1286 | + * @access public |
|
| 1287 | + * @static |
|
| 1288 | + * @return boolean success of verifying upload directories exist |
|
| 1289 | + */ |
|
| 1290 | + public static function create_upload_directories() |
|
| 1291 | + { |
|
| 1292 | + // Create the required folders |
|
| 1293 | + $folders = array( |
|
| 1294 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1295 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1296 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1297 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1298 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1299 | + ); |
|
| 1300 | + foreach ($folders as $folder) { |
|
| 1301 | + try { |
|
| 1302 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1303 | + @ chmod($folder, 0755); |
|
| 1304 | + } catch (EE_Error $e) { |
|
| 1305 | + EE_Error::add_error( |
|
| 1306 | + sprintf( |
|
| 1307 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1308 | + $folder, |
|
| 1309 | + '<br />' . $e->getMessage() |
|
| 1310 | + ), |
|
| 1311 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1312 | + ); |
|
| 1313 | + //indicate we'll need to fix this later |
|
| 1314 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1315 | + return false; |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1319 | + //is disabled, there might be activation errors recorded in there |
|
| 1320 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1321 | + //remember EE's folders are all good |
|
| 1322 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1323 | + return true; |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + /** |
|
| 1327 | + * Whether the upload directories need to be fixed or not. |
|
| 1328 | + * If EE is installed but filesystem access isn't initially available, |
|
| 1329 | + * we need to get the user's filesystem credentials and THEN create them, |
|
| 1330 | + * so there might be period of time when EE is installed but its |
|
| 1331 | + * upload directories aren't available. This indicates such a state |
|
| 1332 | + * |
|
| 1333 | + * @return boolean |
|
| 1334 | + */ |
|
| 1335 | + public static function upload_directories_incomplete() |
|
| 1336 | + { |
|
| 1337 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * generate_default_message_templates |
|
| 1343 | + * |
|
| 1344 | + * @static |
|
| 1345 | + * @throws EE_Error |
|
| 1346 | + * @return bool true means new templates were created. |
|
| 1347 | + * false means no templates were created. |
|
| 1348 | + * This is NOT an error flag. To check for errors you will want |
|
| 1349 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1350 | + */ |
|
| 1351 | + public static function generate_default_message_templates() |
|
| 1352 | + { |
|
| 1353 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1354 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1355 | + /* |
|
| 1356 | 1356 | * This first method is taking care of ensuring any default messengers |
| 1357 | 1357 | * that should be made active and have templates generated are done. |
| 1358 | 1358 | */ |
| 1359 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1360 | - $message_resource_manager |
|
| 1361 | - ); |
|
| 1362 | - /** |
|
| 1363 | - * This method is verifying there are no NEW default message types |
|
| 1364 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1365 | - */ |
|
| 1366 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1367 | - $message_resource_manager |
|
| 1368 | - ); |
|
| 1369 | - //after all is done, let's persist these changes to the db. |
|
| 1370 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1371 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1372 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1373 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1380 | - * @return array|bool |
|
| 1381 | - * @throws \EE_Error |
|
| 1382 | - */ |
|
| 1383 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1384 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1385 | - ) { |
|
| 1386 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1387 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1388 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1389 | - $templates_created = false; |
|
| 1390 | - foreach ($active_messengers as $active_messenger) { |
|
| 1391 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1392 | - $default_message_type_names_to_activate = array(); |
|
| 1393 | - // looping through each default message type reported by the messenger |
|
| 1394 | - // and setup the actual message types to activate. |
|
| 1395 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1396 | - // if already active or has already been activated before we skip |
|
| 1397 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1398 | - // we also skip if the message type is not installed. |
|
| 1399 | - if ( |
|
| 1400 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1401 | - $default_message_type_name_for_messenger, |
|
| 1402 | - $active_messenger->name |
|
| 1403 | - ) |
|
| 1404 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1405 | - $active_messenger->name, |
|
| 1406 | - $default_message_type_name_for_messenger |
|
| 1407 | - ) |
|
| 1408 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1409 | - ) { |
|
| 1410 | - continue; |
|
| 1411 | - } |
|
| 1412 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1413 | - } |
|
| 1414 | - //let's activate! |
|
| 1415 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1416 | - $default_message_type_names_to_activate, |
|
| 1417 | - $active_messenger->name, |
|
| 1418 | - false |
|
| 1419 | - ); |
|
| 1420 | - //activate the templates for these message types |
|
| 1421 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1422 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1423 | - $active_messenger->name, |
|
| 1424 | - $default_message_type_names_for_messenger, |
|
| 1425 | - '', |
|
| 1426 | - true |
|
| 1427 | - ); |
|
| 1428 | - } |
|
| 1429 | - } |
|
| 1430 | - return $templates_created; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1437 | - * |
|
| 1438 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1439 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1440 | - * False means that there were no templates generated |
|
| 1441 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1442 | - * @throws EE_Error |
|
| 1443 | - */ |
|
| 1444 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1445 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1446 | - ) { |
|
| 1447 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1448 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1449 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1450 | - $templates_generated = false; |
|
| 1451 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1452 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1453 | - //verify the default message types match an installed message type. |
|
| 1454 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1455 | - if ( |
|
| 1456 | - ! isset($installed_message_types[$name]) |
|
| 1457 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1458 | - $name, |
|
| 1459 | - $messenger_to_generate->name |
|
| 1460 | - ) |
|
| 1461 | - ) { |
|
| 1462 | - unset($default_message_type_names_for_messenger[$key]); |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - // in previous iterations, the active_messengers option in the db |
|
| 1466 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1467 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1468 | - // passing off to create templates (after the refactor is done). |
|
| 1469 | - // @todo remove this comment when determined not necessary. |
|
| 1470 | - $message_resource_manager->activate_messenger( |
|
| 1471 | - $messenger_to_generate->name, |
|
| 1472 | - $default_message_type_names_for_messenger, |
|
| 1473 | - false |
|
| 1474 | - ); |
|
| 1475 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1476 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1477 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1478 | - $messenger_to_generate->name, |
|
| 1479 | - $default_message_type_names_for_messenger, |
|
| 1480 | - '', |
|
| 1481 | - true |
|
| 1482 | - ); |
|
| 1483 | - } |
|
| 1484 | - } |
|
| 1485 | - return $templates_generated; |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1491 | - * It considers: |
|
| 1492 | - * - whether a messenger is already active in the db. |
|
| 1493 | - * - whether a messenger has been made active at any time in the past. |
|
| 1494 | - * |
|
| 1495 | - * @static |
|
| 1496 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1497 | - * @return EE_messenger[] |
|
| 1498 | - */ |
|
| 1499 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1500 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1501 | - ) { |
|
| 1502 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1503 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1504 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1505 | - |
|
| 1506 | - $messengers_to_generate = array(); |
|
| 1507 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1508 | - //if installed messenger is a messenger that should be activated on install |
|
| 1509 | - //and is not already active |
|
| 1510 | - //and has never been activated |
|
| 1511 | - if ( |
|
| 1512 | - ! $installed_messenger->activate_on_install |
|
| 1513 | - || isset($active_messengers[$installed_messenger->name]) |
|
| 1514 | - || isset($has_activated[$installed_messenger->name]) |
|
| 1515 | - ) { |
|
| 1516 | - continue; |
|
| 1517 | - } |
|
| 1518 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1519 | - } |
|
| 1520 | - return $messengers_to_generate; |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - |
|
| 1524 | - /** |
|
| 1525 | - * This simply validates active message types to ensure they actually match installed |
|
| 1526 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1527 | - * rows are set inactive. |
|
| 1528 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1529 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1530 | - * are still handled in here. |
|
| 1531 | - * |
|
| 1532 | - * @since 4.3.1 |
|
| 1533 | - * @return void |
|
| 1534 | - */ |
|
| 1535 | - public static function validate_messages_system() |
|
| 1536 | - { |
|
| 1537 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1538 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1539 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1540 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - |
|
| 1544 | - /** |
|
| 1545 | - * create_no_ticket_prices_array |
|
| 1546 | - * |
|
| 1547 | - * @access public |
|
| 1548 | - * @static |
|
| 1549 | - * @return void |
|
| 1550 | - */ |
|
| 1551 | - public static function create_no_ticket_prices_array() |
|
| 1552 | - { |
|
| 1553 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1554 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1555 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1556 | - if (! $espresso_no_ticket_prices) { |
|
| 1557 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1558 | - } |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - |
|
| 1562 | - /** |
|
| 1563 | - * plugin_deactivation |
|
| 1564 | - * |
|
| 1565 | - * @access public |
|
| 1566 | - * @static |
|
| 1567 | - * @return void |
|
| 1568 | - */ |
|
| 1569 | - public static function plugin_deactivation() |
|
| 1570 | - { |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - |
|
| 1574 | - /** |
|
| 1575 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1576 | - * (like post meta or term relations) |
|
| 1577 | - * |
|
| 1578 | - * @global wpdb $wpdb |
|
| 1579 | - * @throws \EE_Error |
|
| 1580 | - */ |
|
| 1581 | - public static function delete_all_espresso_cpt_data() |
|
| 1582 | - { |
|
| 1583 | - global $wpdb; |
|
| 1584 | - //get all the CPT post_types |
|
| 1585 | - $ee_post_types = array(); |
|
| 1586 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1587 | - if (method_exists($model_name, 'instance')) { |
|
| 1588 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1589 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1590 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1591 | - } |
|
| 1592 | - } |
|
| 1593 | - } |
|
| 1594 | - //get all our CPTs |
|
| 1595 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1596 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1597 | - //delete each post meta and term relations too |
|
| 1598 | - foreach ($cpt_ids as $post_id) { |
|
| 1599 | - wp_delete_post($post_id, true); |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * Deletes all EE custom tables |
|
| 1605 | - * |
|
| 1606 | - * @return array |
|
| 1607 | - */ |
|
| 1608 | - public static function drop_espresso_tables() |
|
| 1609 | - { |
|
| 1610 | - $tables = array(); |
|
| 1611 | - // load registry |
|
| 1612 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1613 | - if (method_exists($model_name, 'instance')) { |
|
| 1614 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1615 | - if ($model_obj instanceof EEM_Base) { |
|
| 1616 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1617 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1618 | - && |
|
| 1619 | - ( |
|
| 1620 | - is_main_site()//main site? nuke them all |
|
| 1621 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1622 | - ) |
|
| 1623 | - ) { |
|
| 1624 | - $tables[] = $table->get_table_name(); |
|
| 1625 | - } |
|
| 1626 | - } |
|
| 1627 | - } |
|
| 1628 | - } |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - //there are some tables whose models were removed. |
|
| 1632 | - //they should be removed when removing all EE core's data |
|
| 1633 | - $tables_without_models = array( |
|
| 1634 | - 'esp_promotion', |
|
| 1635 | - 'esp_promotion_applied', |
|
| 1636 | - 'esp_promotion_object', |
|
| 1637 | - 'esp_promotion_rule', |
|
| 1638 | - 'esp_rule', |
|
| 1639 | - ); |
|
| 1640 | - foreach ($tables_without_models as $table) { |
|
| 1641 | - $tables[] = $table; |
|
| 1642 | - } |
|
| 1643 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1650 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1651 | - * Returns the list actually deleted |
|
| 1652 | - * |
|
| 1653 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1654 | - * @global WPDB $wpdb |
|
| 1655 | - * @param array $table_names |
|
| 1656 | - * @return array of table names which we deleted |
|
| 1657 | - */ |
|
| 1658 | - public static function drop_tables($table_names) |
|
| 1659 | - { |
|
| 1660 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * plugin_uninstall |
|
| 1667 | - * |
|
| 1668 | - * @access public |
|
| 1669 | - * @static |
|
| 1670 | - * @param bool $remove_all |
|
| 1671 | - * @return void |
|
| 1672 | - */ |
|
| 1673 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1674 | - { |
|
| 1675 | - global $wpdb; |
|
| 1676 | - self::drop_espresso_tables(); |
|
| 1677 | - $wp_options_to_delete = array( |
|
| 1678 | - 'ee_no_ticket_prices' => true, |
|
| 1679 | - 'ee_active_messengers' => true, |
|
| 1680 | - 'ee_has_activated_messenger' => true, |
|
| 1681 | - 'ee_flush_rewrite_rules' => true, |
|
| 1682 | - 'ee_config' => false, |
|
| 1683 | - 'ee_data_migration_current_db_state' => true, |
|
| 1684 | - 'ee_data_migration_mapping_' => false, |
|
| 1685 | - 'ee_data_migration_script_' => false, |
|
| 1686 | - 'ee_data_migrations' => true, |
|
| 1687 | - 'ee_dms_map' => false, |
|
| 1688 | - 'ee_notices' => true, |
|
| 1689 | - 'lang_file_check_' => false, |
|
| 1690 | - 'ee_maintenance_mode' => true, |
|
| 1691 | - 'ee_ueip_optin' => true, |
|
| 1692 | - 'ee_ueip_has_notified' => true, |
|
| 1693 | - 'ee_plugin_activation_errors' => true, |
|
| 1694 | - 'ee_id_mapping_from' => false, |
|
| 1695 | - 'espresso_persistent_admin_notices' => true, |
|
| 1696 | - 'ee_encryption_key' => true, |
|
| 1697 | - 'pue_force_upgrade_' => false, |
|
| 1698 | - 'pue_json_error_' => false, |
|
| 1699 | - 'pue_install_key_' => false, |
|
| 1700 | - 'pue_verification_error_' => false, |
|
| 1701 | - 'pu_dismissed_upgrade_' => false, |
|
| 1702 | - 'external_updates-' => false, |
|
| 1703 | - 'ee_extra_data' => true, |
|
| 1704 | - 'ee_ssn_' => false, |
|
| 1705 | - 'ee_rss_' => false, |
|
| 1706 | - 'ee_rte_n_tx_' => false, |
|
| 1707 | - 'ee_pers_admin_notices' => true, |
|
| 1708 | - 'ee_job_parameters_' => false, |
|
| 1709 | - 'ee_upload_directories_incomplete' => true, |
|
| 1710 | - 'ee_verified_db_collations' => true, |
|
| 1711 | - ); |
|
| 1712 | - if (is_main_site()) { |
|
| 1713 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1714 | - } |
|
| 1715 | - $undeleted_options = array(); |
|
| 1716 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1717 | - if ($no_wildcard) { |
|
| 1718 | - if ( ! delete_option($option_name)) { |
|
| 1719 | - $undeleted_options[] = $option_name; |
|
| 1720 | - } |
|
| 1721 | - } else { |
|
| 1722 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1723 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1724 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1725 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - } |
|
| 1730 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1731 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1732 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1733 | - $db_update_sans_ee4 = array(); |
|
| 1734 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1735 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1736 | - $db_update_sans_ee4[$version] = $times_activated; |
|
| 1737 | - } |
|
| 1738 | - } |
|
| 1739 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1740 | - } |
|
| 1741 | - $errors = ''; |
|
| 1742 | - if ( ! empty($undeleted_options)) { |
|
| 1743 | - $errors .= sprintf( |
|
| 1744 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1745 | - '<br/>', |
|
| 1746 | - implode(',<br/>', $undeleted_options) |
|
| 1747 | - ); |
|
| 1748 | - } |
|
| 1749 | - if ( ! empty($errors)) { |
|
| 1750 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1751 | - } |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - /** |
|
| 1755 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1756 | - * |
|
| 1757 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1758 | - */ |
|
| 1759 | - public static function last_wpdb_error_code() |
|
| 1760 | - { |
|
| 1761 | - global $wpdb; |
|
| 1762 | - if ($wpdb->use_mysqli) { |
|
| 1763 | - return mysqli_errno($wpdb->dbh); |
|
| 1764 | - } else { |
|
| 1765 | - return mysql_errno($wpdb->dbh); |
|
| 1766 | - } |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1771 | - * |
|
| 1772 | - * @global wpdb $wpdb |
|
| 1773 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1774 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1775 | - * @return boolean |
|
| 1776 | - */ |
|
| 1777 | - public static function table_exists($table_name) |
|
| 1778 | - { |
|
| 1779 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - /** |
|
| 1783 | - * Resets the cache on EEH_Activation |
|
| 1784 | - */ |
|
| 1785 | - public static function reset() |
|
| 1786 | - { |
|
| 1787 | - self::$_default_creator_id = null; |
|
| 1788 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1789 | - } |
|
| 1359 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1360 | + $message_resource_manager |
|
| 1361 | + ); |
|
| 1362 | + /** |
|
| 1363 | + * This method is verifying there are no NEW default message types |
|
| 1364 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1365 | + */ |
|
| 1366 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1367 | + $message_resource_manager |
|
| 1368 | + ); |
|
| 1369 | + //after all is done, let's persist these changes to the db. |
|
| 1370 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1371 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1372 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1373 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1380 | + * @return array|bool |
|
| 1381 | + * @throws \EE_Error |
|
| 1382 | + */ |
|
| 1383 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1384 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1385 | + ) { |
|
| 1386 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1387 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1388 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1389 | + $templates_created = false; |
|
| 1390 | + foreach ($active_messengers as $active_messenger) { |
|
| 1391 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1392 | + $default_message_type_names_to_activate = array(); |
|
| 1393 | + // looping through each default message type reported by the messenger |
|
| 1394 | + // and setup the actual message types to activate. |
|
| 1395 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1396 | + // if already active or has already been activated before we skip |
|
| 1397 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1398 | + // we also skip if the message type is not installed. |
|
| 1399 | + if ( |
|
| 1400 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1401 | + $default_message_type_name_for_messenger, |
|
| 1402 | + $active_messenger->name |
|
| 1403 | + ) |
|
| 1404 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1405 | + $active_messenger->name, |
|
| 1406 | + $default_message_type_name_for_messenger |
|
| 1407 | + ) |
|
| 1408 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1409 | + ) { |
|
| 1410 | + continue; |
|
| 1411 | + } |
|
| 1412 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1413 | + } |
|
| 1414 | + //let's activate! |
|
| 1415 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1416 | + $default_message_type_names_to_activate, |
|
| 1417 | + $active_messenger->name, |
|
| 1418 | + false |
|
| 1419 | + ); |
|
| 1420 | + //activate the templates for these message types |
|
| 1421 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1422 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1423 | + $active_messenger->name, |
|
| 1424 | + $default_message_type_names_for_messenger, |
|
| 1425 | + '', |
|
| 1426 | + true |
|
| 1427 | + ); |
|
| 1428 | + } |
|
| 1429 | + } |
|
| 1430 | + return $templates_created; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1437 | + * |
|
| 1438 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1439 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1440 | + * False means that there were no templates generated |
|
| 1441 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1442 | + * @throws EE_Error |
|
| 1443 | + */ |
|
| 1444 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1445 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1446 | + ) { |
|
| 1447 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1448 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1449 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1450 | + $templates_generated = false; |
|
| 1451 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1452 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1453 | + //verify the default message types match an installed message type. |
|
| 1454 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1455 | + if ( |
|
| 1456 | + ! isset($installed_message_types[$name]) |
|
| 1457 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1458 | + $name, |
|
| 1459 | + $messenger_to_generate->name |
|
| 1460 | + ) |
|
| 1461 | + ) { |
|
| 1462 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + // in previous iterations, the active_messengers option in the db |
|
| 1466 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1467 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1468 | + // passing off to create templates (after the refactor is done). |
|
| 1469 | + // @todo remove this comment when determined not necessary. |
|
| 1470 | + $message_resource_manager->activate_messenger( |
|
| 1471 | + $messenger_to_generate->name, |
|
| 1472 | + $default_message_type_names_for_messenger, |
|
| 1473 | + false |
|
| 1474 | + ); |
|
| 1475 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1476 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1477 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1478 | + $messenger_to_generate->name, |
|
| 1479 | + $default_message_type_names_for_messenger, |
|
| 1480 | + '', |
|
| 1481 | + true |
|
| 1482 | + ); |
|
| 1483 | + } |
|
| 1484 | + } |
|
| 1485 | + return $templates_generated; |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1491 | + * It considers: |
|
| 1492 | + * - whether a messenger is already active in the db. |
|
| 1493 | + * - whether a messenger has been made active at any time in the past. |
|
| 1494 | + * |
|
| 1495 | + * @static |
|
| 1496 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1497 | + * @return EE_messenger[] |
|
| 1498 | + */ |
|
| 1499 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1500 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1501 | + ) { |
|
| 1502 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1503 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1504 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1505 | + |
|
| 1506 | + $messengers_to_generate = array(); |
|
| 1507 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1508 | + //if installed messenger is a messenger that should be activated on install |
|
| 1509 | + //and is not already active |
|
| 1510 | + //and has never been activated |
|
| 1511 | + if ( |
|
| 1512 | + ! $installed_messenger->activate_on_install |
|
| 1513 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1514 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1515 | + ) { |
|
| 1516 | + continue; |
|
| 1517 | + } |
|
| 1518 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1519 | + } |
|
| 1520 | + return $messengers_to_generate; |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + |
|
| 1524 | + /** |
|
| 1525 | + * This simply validates active message types to ensure they actually match installed |
|
| 1526 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1527 | + * rows are set inactive. |
|
| 1528 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1529 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1530 | + * are still handled in here. |
|
| 1531 | + * |
|
| 1532 | + * @since 4.3.1 |
|
| 1533 | + * @return void |
|
| 1534 | + */ |
|
| 1535 | + public static function validate_messages_system() |
|
| 1536 | + { |
|
| 1537 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1538 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1539 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1540 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1541 | + } |
|
| 1542 | + |
|
| 1543 | + |
|
| 1544 | + /** |
|
| 1545 | + * create_no_ticket_prices_array |
|
| 1546 | + * |
|
| 1547 | + * @access public |
|
| 1548 | + * @static |
|
| 1549 | + * @return void |
|
| 1550 | + */ |
|
| 1551 | + public static function create_no_ticket_prices_array() |
|
| 1552 | + { |
|
| 1553 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1554 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1555 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1556 | + if (! $espresso_no_ticket_prices) { |
|
| 1557 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1558 | + } |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + |
|
| 1562 | + /** |
|
| 1563 | + * plugin_deactivation |
|
| 1564 | + * |
|
| 1565 | + * @access public |
|
| 1566 | + * @static |
|
| 1567 | + * @return void |
|
| 1568 | + */ |
|
| 1569 | + public static function plugin_deactivation() |
|
| 1570 | + { |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + |
|
| 1574 | + /** |
|
| 1575 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1576 | + * (like post meta or term relations) |
|
| 1577 | + * |
|
| 1578 | + * @global wpdb $wpdb |
|
| 1579 | + * @throws \EE_Error |
|
| 1580 | + */ |
|
| 1581 | + public static function delete_all_espresso_cpt_data() |
|
| 1582 | + { |
|
| 1583 | + global $wpdb; |
|
| 1584 | + //get all the CPT post_types |
|
| 1585 | + $ee_post_types = array(); |
|
| 1586 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1587 | + if (method_exists($model_name, 'instance')) { |
|
| 1588 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1589 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1590 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1591 | + } |
|
| 1592 | + } |
|
| 1593 | + } |
|
| 1594 | + //get all our CPTs |
|
| 1595 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1596 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1597 | + //delete each post meta and term relations too |
|
| 1598 | + foreach ($cpt_ids as $post_id) { |
|
| 1599 | + wp_delete_post($post_id, true); |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * Deletes all EE custom tables |
|
| 1605 | + * |
|
| 1606 | + * @return array |
|
| 1607 | + */ |
|
| 1608 | + public static function drop_espresso_tables() |
|
| 1609 | + { |
|
| 1610 | + $tables = array(); |
|
| 1611 | + // load registry |
|
| 1612 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1613 | + if (method_exists($model_name, 'instance')) { |
|
| 1614 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1615 | + if ($model_obj instanceof EEM_Base) { |
|
| 1616 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1617 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1618 | + && |
|
| 1619 | + ( |
|
| 1620 | + is_main_site()//main site? nuke them all |
|
| 1621 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1622 | + ) |
|
| 1623 | + ) { |
|
| 1624 | + $tables[] = $table->get_table_name(); |
|
| 1625 | + } |
|
| 1626 | + } |
|
| 1627 | + } |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + //there are some tables whose models were removed. |
|
| 1632 | + //they should be removed when removing all EE core's data |
|
| 1633 | + $tables_without_models = array( |
|
| 1634 | + 'esp_promotion', |
|
| 1635 | + 'esp_promotion_applied', |
|
| 1636 | + 'esp_promotion_object', |
|
| 1637 | + 'esp_promotion_rule', |
|
| 1638 | + 'esp_rule', |
|
| 1639 | + ); |
|
| 1640 | + foreach ($tables_without_models as $table) { |
|
| 1641 | + $tables[] = $table; |
|
| 1642 | + } |
|
| 1643 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1650 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1651 | + * Returns the list actually deleted |
|
| 1652 | + * |
|
| 1653 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1654 | + * @global WPDB $wpdb |
|
| 1655 | + * @param array $table_names |
|
| 1656 | + * @return array of table names which we deleted |
|
| 1657 | + */ |
|
| 1658 | + public static function drop_tables($table_names) |
|
| 1659 | + { |
|
| 1660 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * plugin_uninstall |
|
| 1667 | + * |
|
| 1668 | + * @access public |
|
| 1669 | + * @static |
|
| 1670 | + * @param bool $remove_all |
|
| 1671 | + * @return void |
|
| 1672 | + */ |
|
| 1673 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1674 | + { |
|
| 1675 | + global $wpdb; |
|
| 1676 | + self::drop_espresso_tables(); |
|
| 1677 | + $wp_options_to_delete = array( |
|
| 1678 | + 'ee_no_ticket_prices' => true, |
|
| 1679 | + 'ee_active_messengers' => true, |
|
| 1680 | + 'ee_has_activated_messenger' => true, |
|
| 1681 | + 'ee_flush_rewrite_rules' => true, |
|
| 1682 | + 'ee_config' => false, |
|
| 1683 | + 'ee_data_migration_current_db_state' => true, |
|
| 1684 | + 'ee_data_migration_mapping_' => false, |
|
| 1685 | + 'ee_data_migration_script_' => false, |
|
| 1686 | + 'ee_data_migrations' => true, |
|
| 1687 | + 'ee_dms_map' => false, |
|
| 1688 | + 'ee_notices' => true, |
|
| 1689 | + 'lang_file_check_' => false, |
|
| 1690 | + 'ee_maintenance_mode' => true, |
|
| 1691 | + 'ee_ueip_optin' => true, |
|
| 1692 | + 'ee_ueip_has_notified' => true, |
|
| 1693 | + 'ee_plugin_activation_errors' => true, |
|
| 1694 | + 'ee_id_mapping_from' => false, |
|
| 1695 | + 'espresso_persistent_admin_notices' => true, |
|
| 1696 | + 'ee_encryption_key' => true, |
|
| 1697 | + 'pue_force_upgrade_' => false, |
|
| 1698 | + 'pue_json_error_' => false, |
|
| 1699 | + 'pue_install_key_' => false, |
|
| 1700 | + 'pue_verification_error_' => false, |
|
| 1701 | + 'pu_dismissed_upgrade_' => false, |
|
| 1702 | + 'external_updates-' => false, |
|
| 1703 | + 'ee_extra_data' => true, |
|
| 1704 | + 'ee_ssn_' => false, |
|
| 1705 | + 'ee_rss_' => false, |
|
| 1706 | + 'ee_rte_n_tx_' => false, |
|
| 1707 | + 'ee_pers_admin_notices' => true, |
|
| 1708 | + 'ee_job_parameters_' => false, |
|
| 1709 | + 'ee_upload_directories_incomplete' => true, |
|
| 1710 | + 'ee_verified_db_collations' => true, |
|
| 1711 | + ); |
|
| 1712 | + if (is_main_site()) { |
|
| 1713 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1714 | + } |
|
| 1715 | + $undeleted_options = array(); |
|
| 1716 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1717 | + if ($no_wildcard) { |
|
| 1718 | + if ( ! delete_option($option_name)) { |
|
| 1719 | + $undeleted_options[] = $option_name; |
|
| 1720 | + } |
|
| 1721 | + } else { |
|
| 1722 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1723 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1724 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1725 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + } |
|
| 1730 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1731 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1732 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1733 | + $db_update_sans_ee4 = array(); |
|
| 1734 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1735 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1736 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1740 | + } |
|
| 1741 | + $errors = ''; |
|
| 1742 | + if ( ! empty($undeleted_options)) { |
|
| 1743 | + $errors .= sprintf( |
|
| 1744 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1745 | + '<br/>', |
|
| 1746 | + implode(',<br/>', $undeleted_options) |
|
| 1747 | + ); |
|
| 1748 | + } |
|
| 1749 | + if ( ! empty($errors)) { |
|
| 1750 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1751 | + } |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + /** |
|
| 1755 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1756 | + * |
|
| 1757 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1758 | + */ |
|
| 1759 | + public static function last_wpdb_error_code() |
|
| 1760 | + { |
|
| 1761 | + global $wpdb; |
|
| 1762 | + if ($wpdb->use_mysqli) { |
|
| 1763 | + return mysqli_errno($wpdb->dbh); |
|
| 1764 | + } else { |
|
| 1765 | + return mysql_errno($wpdb->dbh); |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1771 | + * |
|
| 1772 | + * @global wpdb $wpdb |
|
| 1773 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1774 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1775 | + * @return boolean |
|
| 1776 | + */ |
|
| 1777 | + public static function table_exists($table_name) |
|
| 1778 | + { |
|
| 1779 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + /** |
|
| 1783 | + * Resets the cache on EEH_Activation |
|
| 1784 | + */ |
|
| 1785 | + public static function reset() |
|
| 1786 | + { |
|
| 1787 | + self::$_default_creator_id = null; |
|
| 1788 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1789 | + } |
|
| 1790 | 1790 | } |
| 1791 | 1791 | // End of file EEH_Activation.helper.php |
| 1792 | 1792 | // Location: /helpers/EEH_Activation.core.php |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | /** |
| 82 | 82 | * Checks if that value is the one selected |
| 83 | 83 | * @param string|int $value unnormalized value option (string) |
| 84 | - * @return string |
|
| 84 | + * @return boolean |
|
| 85 | 85 | */ |
| 86 | 86 | protected function _check_if_option_selected( $value ){ |
| 87 | 87 | return $this->_input->raw_value() === $value ? TRUE : FALSE; |
@@ -11,49 +11,49 @@ discard block |
||
| 11 | 11 | * @since $VID:$ |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{ |
|
| 14 | +class EE_Select_Display_Strategy extends EE_Display_Strategy_Base { |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * |
| 18 | 18 | * @throws EE_Error |
| 19 | 19 | * @return string of html to display the field |
| 20 | 20 | */ |
| 21 | - function display(){ |
|
| 22 | - if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){ |
|
| 23 | - throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' ))); |
|
| 21 | + function display() { |
|
| 22 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
| 23 | + throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - $html = EEH_HTML::nl( 0, 'select' ); |
|
| 26 | + $html = EEH_HTML::nl(0, 'select'); |
|
| 27 | 27 | $html .= '<select'; |
| 28 | - $html .= ' id="' . $this->_input->html_id() . '"'; |
|
| 29 | - $html .= ' name="' . $this->_input->html_name() . '"'; |
|
| 30 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
| 31 | - $html .= ' class="' . $class . '"'; |
|
| 28 | + $html .= ' id="'.$this->_input->html_id().'"'; |
|
| 29 | + $html .= ' name="'.$this->_input->html_name().'"'; |
|
| 30 | + $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class(); |
|
| 31 | + $html .= ' class="'.$class.'"'; |
|
| 32 | 32 | // add html5 required |
| 33 | 33 | $html .= $this->_input->required() ? ' required' : ''; |
| 34 | - $html .= ' style="' . $this->_input->html_style() . '"'; |
|
| 35 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 34 | + $html .= ' style="'.$this->_input->html_style().'"'; |
|
| 35 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
| 36 | 36 | $html .= '>'; |
| 37 | 37 | |
| 38 | - if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
|
| 39 | - EEH_HTML::indent( 1, 'optgroup' ); |
|
| 40 | - foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
|
| 38 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
| 39 | + EEH_HTML::indent(1, 'optgroup'); |
|
| 40 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
| 41 | 41 | if ( ! empty($opt_group_label)) { |
| 42 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
| 42 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
| 43 | 43 | } |
| 44 | - EEH_HTML::indent( 1, 'option' ); |
|
| 45 | - $html .= $this->_display_options( $opt_group ); |
|
| 44 | + EEH_HTML::indent(1, 'option'); |
|
| 45 | + $html .= $this->_display_options($opt_group); |
|
| 46 | 46 | EEH_HTML::indent( -1, 'option' ); |
| 47 | 47 | if ( ! empty($opt_group_label)) { |
| 48 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
| 48 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | EEH_HTML::indent( -1, 'optgroup' ); |
| 52 | 52 | } else { |
| 53 | - $html.=$this->_display_options( $this->_input->options() ); |
|
| 53 | + $html .= $this->_display_options($this->_input->options()); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $html.= EEH_HTML::nl( 0, 'select' ) . '</select>'; |
|
| 56 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
| 57 | 57 | return $html; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | * @param array $options |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | - protected function _display_options($options){ |
|
| 67 | + protected function _display_options($options) { |
|
| 68 | 68 | $html = ''; |
| 69 | - EEH_HTML::indent( 1, 'option' ); |
|
| 70 | - foreach( $options as $value => $display_text ){ |
|
| 71 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
| 72 | - $selected = $this->_check_if_option_selected( $unnormalized_value ) ? ' selected="selected"' : ''; |
|
| 73 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr( $unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
| 69 | + EEH_HTML::indent(1, 'option'); |
|
| 70 | + foreach ($options as $value => $display_text) { |
|
| 71 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
| 72 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
| 73 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
| 74 | 74 | } |
| 75 | 75 | EEH_HTML::indent( -1, 'option' ); |
| 76 | 76 | return $html; |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string|int $value unnormalized value option (string) |
| 84 | 84 | * @return string |
| 85 | 85 | */ |
| 86 | - protected function _check_if_option_selected( $value ){ |
|
| 86 | + protected function _check_if_option_selected($value) { |
|
| 87 | 87 | return $this->_input->raw_value() === $value ? TRUE : FALSE; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | //does question have any answers? cause if it does then we have to disable type |
| 16 | 16 | $has_answers = $question->has_answers(); |
| 17 | 17 | |
| 18 | -if ( $QST_system === 'country' ) { |
|
| 18 | +if ($QST_system === 'country') { |
|
| 19 | 19 | echo EEH_HTML::div( |
| 20 | - EEH_HTML::h4( '<span class="dashicons dashicons-info"></span>' . esc_html__( 'Did you know...', 'event_espresso' ) ) . |
|
| 20 | + EEH_HTML::h4('<span class="dashicons dashicons-info"></span>'.esc_html__('Did you know...', 'event_espresso')). |
|
| 21 | 21 | EEH_HTML::p( |
| 22 | 22 | esc_html__( |
| 23 | 23 | 'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.', |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | <tbody> |
| 35 | 35 | <tr> |
| 36 | 36 | <th> |
| 37 | - <label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info');?> |
|
| 37 | + <label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info'); ?> |
|
| 38 | 38 | </th> |
| 39 | 39 | <td> |
| 40 | 40 | <input type="text" class="regular-text" id="QST_display_text" name="QST_display_text" value="<?php $question->f('QST_display_text')?>"/> |
@@ -44,23 +44,23 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | <tr> |
| 46 | 46 | <th> |
| 47 | - <label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info');?> |
|
| 47 | + <label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info'); ?> |
|
| 48 | 48 | </th> |
| 49 | 49 | <td> |
| 50 | 50 | <?php |
| 51 | - $disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : ''; |
|
| 52 | - $id = ! empty( $QST_system ) ? '_disabled' : ''; |
|
| 51 | + $disabled = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 52 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 53 | 53 | ?> |
| 54 | 54 | <input type="text" class="regular-text" id="QST_admin_label<?php echo $id?>" name="QST_admin_label<?php echo $id?>" value="<?php $question->f('QST_admin_label')?>"<?php echo $disabled?>/> |
| 55 | 55 | <input class="QST_order" type="hidden" id="QST_order<?php echo $id; ?>" name = "QST_order<?php echo $id; ?>" value="<?php echo $question->get('QST_order'); ?>" /> |
| 56 | - <?php if ( ! empty( $QST_system )) { ?> |
|
| 56 | + <?php if ( ! empty($QST_system)) { ?> |
|
| 57 | 57 | <input type="hidden" id="QST_admin_label" name="QST_admin_label" value="<?php echo $question->admin_label()?>"/> |
| 58 | 58 | <?php } ?> |
| 59 | 59 | <br/> |
| 60 | 60 | <p class="description"> |
| 61 | - <?php if ( ! empty( $QST_system )) { ?> |
|
| 61 | + <?php if ( ! empty($QST_system)) { ?> |
|
| 62 | 62 | <span class="description" style="color:#D54E21;"> |
| 63 | - <?php esc_html_e('System question! This field cannot be changed.','event_espresso')?> |
|
| 63 | + <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?> |
|
| 64 | 64 | </span> |
| 65 | 65 | <?php } ?> |
| 66 | 66 | |
@@ -70,21 +70,21 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | <tr> |
| 72 | 72 | <th> |
| 73 | - <label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info');?> |
|
| 73 | + <label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info'); ?> |
|
| 74 | 74 | </th> |
| 75 | 75 | <td> |
| 76 | 76 | <?php |
| 77 | - $disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : ''; |
|
| 78 | - $id = ! empty( $QST_system ) ? '_disabled' : ''; |
|
| 77 | + $disabled = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 78 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 79 | 79 | $admin_only = $question->get('QST_admin_only'); |
| 80 | - $checked = !empty( $admin_only ) ? ' checked="checked"' : ''; |
|
| 80 | + $checked = ! empty($admin_only) ? ' checked="checked"' : ''; |
|
| 81 | 81 | ?> |
| 82 | 82 | <input class="QST_admin_only" type="checkbox" id="QST_admin_only<?php echo $id; ?>" name = "QST_admin_only<?php echo $id; ?>" value="1"<?php echo $disabled; echo $checked; ?>/> |
| 83 | 83 | <br/> |
| 84 | 84 | <p class="description"> |
| 85 | - <?php if ( ! empty( $QST_system )) { ?> |
|
| 85 | + <?php if ( ! empty($QST_system)) { ?> |
|
| 86 | 86 | <span class="description" style="color:#D54E21;"> |
| 87 | - <?php esc_html_e('System question! This field cannot be changed.','event_espresso')?> |
|
| 87 | + <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?> |
|
| 88 | 88 | </span> |
| 89 | 89 | <?php } ?> |
| 90 | 90 | |
@@ -94,21 +94,21 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | <tr> |
| 96 | 96 | <th> |
| 97 | - <label for="QST_type"><?php echo $fields['QST_type']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info');?> |
|
| 97 | + <label for="QST_type"><?php echo $fields['QST_type']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info'); ?> |
|
| 98 | 98 | </th> |
| 99 | 99 | <td> |
| 100 | 100 | <?php |
| 101 | - $disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : ''; |
|
| 102 | - $id = ! empty( $QST_system ) ? '_disabled' : ''; |
|
| 103 | - echo EEH_Form_Fields::select_input( 'QST_type' . $id, $question_types, $question->type(), 'id="QST_type' . $id . '"' . $disabled ); |
|
| 104 | - if( ! empty( $QST_system ) ) { ?> |
|
| 101 | + $disabled = ! empty($QST_system) ? ' disabled="disabled"' : ''; |
|
| 102 | + $id = ! empty($QST_system) ? '_disabled' : ''; |
|
| 103 | + echo EEH_Form_Fields::select_input('QST_type'.$id, $question_types, $question->type(), 'id="QST_type'.$id.'"'.$disabled); |
|
| 104 | + if ( ! empty($QST_system)) { ?> |
|
| 105 | 105 | <input type="hidden" id="QST_type" name="QST_type" value="<?php echo $question->type()?>"/> |
| 106 | 106 | <?php |
| 107 | - $explanatory_text = esc_html__('System question! This field cannot be changed.','event_espresso'); |
|
| 108 | - }else{ |
|
| 109 | - $explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.','event_espresso'); |
|
| 107 | + $explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso'); |
|
| 108 | + } else { |
|
| 109 | + $explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', 'event_espresso'); |
|
| 110 | 110 | } |
| 111 | - if ( ! empty( $QST_system ) || $has_answers ) { ?> |
|
| 111 | + if ( ! empty($QST_system) || $has_answers) { ?> |
|
| 112 | 112 | <p><span class="description" style="color:#D54E21;"> |
| 113 | 113 | <?php echo $explanatory_text; ?> |
| 114 | 114 | </span></p> |
@@ -121,22 +121,22 @@ discard block |
||
| 121 | 121 | <tr id="text_input_question_options"> |
| 122 | 122 | <th> |
| 123 | 123 | <label> |
| 124 | - <?php esc_html_e( 'Maximum Allowed Response Size', 'event_espresso' );?> |
|
| 124 | + <?php esc_html_e('Maximum Allowed Response Size', 'event_espresso'); ?> |
|
| 125 | 125 | </label> |
| 126 | 126 | </th> |
| 127 | 127 | <td> |
| 128 | - <input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' : "max='$max_max'";?> value="<?php $question->f( 'QST_max' );?>" min="1"> |
|
| 128 | + <input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1"> |
|
| 129 | 129 | <p> |
| 130 | 130 | <span class="description"> |
| 131 | - <?php esc_html_e( 'Maximum number of characters allowed when answering this question', 'event_espresso' );?> |
|
| 131 | + <?php esc_html_e('Maximum number of characters allowed when answering this question', 'event_espresso'); ?> |
|
| 132 | 132 | </span> |
| 133 | 133 | </p> |
| 134 | - <?php if ( $QST_system ) { ?> |
|
| 134 | + <?php if ($QST_system) { ?> |
|
| 135 | 135 | <p> |
| 136 | 136 | <span class="description" style="color:#D54E21;"> |
| 137 | 137 | <?php printf( |
| 138 | - esc_html__( 'System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso' ), |
|
| 139 | - $max_max );?> |
|
| 138 | + esc_html__('System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso'), |
|
| 139 | + $max_max ); ?> |
|
| 140 | 140 | </span> |
| 141 | 141 | </p> |
| 142 | 142 | <?php } ?> |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | <tr id="question_options"> |
| 146 | 146 | <th> |
| 147 | 147 | <label> |
| 148 | - <?php esc_html_e('Answer Options','event_espresso')?> |
|
| 148 | + <?php esc_html_e('Answer Options', 'event_espresso')?> |
|
| 149 | 149 | </label> |
| 150 | 150 | </th> |
| 151 | 151 | <td> |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | <thead> |
| 155 | 155 | <tr> |
| 156 | 156 | <th class="option-value-header"> |
| 157 | - <?php esc_html_e('Value','event_espresso')?> |
|
| 157 | + <?php esc_html_e('Value', 'event_espresso')?> |
|
| 158 | 158 | </th> |
| 159 | 159 | <th class="option-desc-header"> |
| 160 | - <?php esc_html_e('Description (optional, only shown on registration form)','event_espresso')?> |
|
| 160 | + <?php esc_html_e('Description (optional, only shown on registration form)', 'event_espresso')?> |
|
| 161 | 161 | </th> |
| 162 | 162 | <th> |
| 163 | 163 | </th> |
@@ -180,17 +180,17 @@ discard block |
||
| 180 | 180 | </tr> |
| 181 | 181 | |
| 182 | 182 | <?php |
| 183 | - $count=0; |
|
| 183 | + $count = 0; |
|
| 184 | 184 | $question_options = $question->options(); |
| 185 | - if ( ! empty( $question_options )) { |
|
| 186 | - foreach( $question_options as $option_id => $option ) { |
|
| 187 | - $disabled = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
|
| 185 | + if ( ! empty($question_options)) { |
|
| 186 | + foreach ($question_options as $option_id => $option) { |
|
| 187 | + $disabled = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : ''; |
|
| 188 | 188 | ?> |
| 189 | 189 | <tr class="question-option ee-options-sortable"> |
| 190 | 190 | <td class="option-value-cell"> |
| 191 | 191 | <input type="hidden" class="QSO_order" name="question_options[<?php echo $count; ?>][QSO_order]" value="<?php echo $count; ?>"> |
| 192 | 192 | <input type="text" class="option-value regular-text" name="question_options[<?php echo $count?>][QSO_value]" value="<?php $option->f('QSO_value')?>"<?php echo $disabled; ?>> |
| 193 | - <?php if ( $has_answers ) : ?> |
|
| 193 | + <?php if ($has_answers) : ?> |
|
| 194 | 194 | <input type="hidden" name="question_options[<?php echo $count; ?>][QSO_value]" value="<?php echo $option->f('QSO_value'); ?>" > |
| 195 | 195 | <?php endif; ?> |
| 196 | 196 | </td> |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | <input type="text" class="option-desc regular-text" name="question_options[<?php echo $count?>][QSO_desc]" value="<?php $option->f('QSO_desc')?>"> |
| 199 | 199 | </td> |
| 200 | 200 | <td> |
| 201 | - <?php if ( ! $option->system() ) { ?> |
|
| 201 | + <?php if ( ! $option->system()) { ?> |
|
| 202 | 202 | <span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"></span> |
| 203 | 203 | <?php } ?> |
| 204 | 204 | <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span> |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | </table> |
| 238 | 238 | |
| 239 | 239 | <a id="new-question-option" class="button" style="margin:0 0 1em 3px;"> |
| 240 | - <?php esc_html_e('Add Another Answer Option','event_espresso')?> |
|
| 240 | + <?php esc_html_e('Add Another Answer Option', 'event_espresso')?> |
|
| 241 | 241 | </a><br/> |
| 242 | 242 | |
| 243 | 243 | <p class="description"> |
| 244 | - <?php esc_html_e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.','event_espresso')?> |
|
| 244 | + <?php esc_html_e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', 'event_espresso')?> |
|
| 245 | 245 | </p> |
| 246 | - <?php if ( $has_answers ) : ?> |
|
| 246 | + <?php if ($has_answers) : ?> |
|
| 247 | 247 | <p class="description" style="color:#D54E21;"> |
| 248 | 248 | <?php esc_html_e('Answer values that are uneditable are this way because there are registrations in the database that have answers for this question. If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes. This will ensure that the existing registrations that chose the original answer will preserve that answer.', 'event_espresso'); ?> |
| 249 | 249 | </p> |
@@ -254,32 +254,32 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | <tr> |
| 256 | 256 | <th> |
| 257 | - <label for="QST_required"><?php echo $fields['QST_required']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info');?> |
|
| 257 | + <label for="QST_required"><?php echo $fields['QST_required']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info'); ?> |
|
| 258 | 258 | </th> |
| 259 | 259 | <td> |
| 260 | 260 | <?php |
| 261 | - $system_required = array( 'fname', 'email' ); |
|
| 262 | - $disabled = in_array( $QST_system, $system_required ) ? ' disabled="disabled"' : ''; |
|
| 261 | + $system_required = array('fname', 'email'); |
|
| 262 | + $disabled = in_array($QST_system, $system_required) ? ' disabled="disabled"' : ''; |
|
| 263 | 263 | $required_on = $question->get('QST_admin_only'); |
| 264 | 264 | $show_required_msg = $required_on ? '' : ' display:none;'; |
| 265 | - $disabled = $required_on || ! empty( $disabled ) ? ' disabled="disabled"' : ''; |
|
| 266 | - $id = ! empty( $disabled ) && in_array( $QST_system, $system_required) ? '_disabled' : ''; |
|
| 267 | - $requiredOptions=array( |
|
| 268 | - array( 'text'=> esc_html__( 'Optional', 'event_espresso' ), 'id'=>0 ), |
|
| 269 | - array( 'text'=> esc_html__( 'Required', 'event_espresso' ), 'id'=>1 ) |
|
| 265 | + $disabled = $required_on || ! empty($disabled) ? ' disabled="disabled"' : ''; |
|
| 266 | + $id = ! empty($disabled) && in_array($QST_system, $system_required) ? '_disabled' : ''; |
|
| 267 | + $requiredOptions = array( |
|
| 268 | + array('text'=> esc_html__('Optional', 'event_espresso'), 'id'=>0), |
|
| 269 | + array('text'=> esc_html__('Required', 'event_espresso'), 'id'=>1) |
|
| 270 | 270 | ); |
| 271 | - echo EEH_Form_Fields::select_input('QST_required' . $id, $requiredOptions, $question->required(), 'id="QST_required' . $id . '"' . $disabled ); |
|
| 271 | + echo EEH_Form_Fields::select_input('QST_required'.$id, $requiredOptions, $question->required(), 'id="QST_required'.$id.'"'.$disabled); |
|
| 272 | 272 | ?> |
| 273 | 273 | <p><span id="required_toggled_on" class="description" style="color:#D54E21;<?php echo $show_required_msg; ?>"> |
| 274 | - <?php esc_html_e('Required is set to optional, and this field is disabled, because the question is Admin-Only.','event_espresso')?> |
|
| 274 | + <?php esc_html_e('Required is set to optional, and this field is disabled, because the question is Admin-Only.', 'event_espresso')?> |
|
| 275 | 275 | </span></p> |
| 276 | 276 | <p><span id="required_toggled_off" class="description" style="color:#D54E21; display: none;"> |
| 277 | - <?php esc_html_e('Required option field is no longer disabled because the question is not Admin-Only','event_espresso')?> |
|
| 277 | + <?php esc_html_e('Required option field is no longer disabled because the question is not Admin-Only', 'event_espresso')?> |
|
| 278 | 278 | </span></p> |
| 279 | - <?php if ( ! empty( $disabled ) && in_array( $QST_system, $system_required ) ) { ?> |
|
| 279 | + <?php if ( ! empty($disabled) && in_array($QST_system, $system_required)) { ?> |
|
| 280 | 280 | <input type="hidden" id="QST_required" name="QST_required" value="1"/> |
| 281 | 281 | <p><span class="description" style="color:#D54E21;"> |
| 282 | - <?php esc_html_e('System question! This field cannot be changed.','event_espresso')?> |
|
| 282 | + <?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?> |
|
| 283 | 283 | </span></p> |
| 284 | 284 | <?php } ?> |
| 285 | 285 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | <tr> |
| 290 | 290 | <th> |
| 291 | - <label for="QST_required_text"><?php esc_html_e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info');?> |
|
| 291 | + <label for="QST_required_text"><?php esc_html_e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?> |
|
| 292 | 292 | </th> |
| 293 | 293 | <td> |
| 294 | 294 | <input type="text" maxlength="100" class="regular-text" id="QST_required_text" name="QST_required_text" value="<?php $question->f('QST_required_text')?>"/> |