@@ -15,327 +15,327 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Benchmark |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var string $output |
|
| 20 | - */ |
|
| 21 | - private static $output; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var array $start_times array containing the start time for the timers |
|
| 25 | - */ |
|
| 26 | - private static $start_times; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var array $times array containing all the timer'd times, which can be outputted via show_times() |
|
| 30 | - */ |
|
| 31 | - private static $times = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array $memory_usage |
|
| 35 | - */ |
|
| 36 | - protected static $memory_usage = array(); |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param string $output |
|
| 41 | - * @param bool $formatted |
|
| 42 | - */ |
|
| 43 | - public static function addOutput($output, $formatted = true) |
|
| 44 | - { |
|
| 45 | - Benchmark::$output .= $formatted |
|
| 46 | - ? "<br />{$output}" |
|
| 47 | - : "\n{$output}"; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return void |
|
| 53 | - */ |
|
| 54 | - public static function resetOutput() |
|
| 55 | - { |
|
| 56 | - Benchmark::$output = ''; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * whether to benchmark code or not |
|
| 61 | - */ |
|
| 62 | - public static function doNotRun() |
|
| 63 | - { |
|
| 64 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * resetTimes |
|
| 70 | - */ |
|
| 71 | - public static function resetTimes() |
|
| 72 | - { |
|
| 73 | - Benchmark::$times = array(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 79 | - * |
|
| 80 | - * @param null $timer_name |
|
| 81 | - */ |
|
| 82 | - public static function startTimer($timer_name = null) |
|
| 83 | - { |
|
| 84 | - if (Benchmark::doNotRun()) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 88 | - Benchmark::$start_times[ $timer_name ] = microtime(true); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 94 | - * |
|
| 95 | - * @param string $timer_name |
|
| 96 | - */ |
|
| 97 | - public static function stopTimer($timer_name = '') |
|
| 98 | - { |
|
| 99 | - if (Benchmark::doNotRun()) { |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 103 | - if (isset(Benchmark::$start_times[ $timer_name ])) { |
|
| 104 | - $start_time = Benchmark::$start_times[ $timer_name ]; |
|
| 105 | - unset(Benchmark::$start_times[ $timer_name ]); |
|
| 106 | - } else { |
|
| 107 | - $start_time = array_pop(Benchmark::$start_times); |
|
| 108 | - } |
|
| 109 | - Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Measure the memory usage by PHP so far. |
|
| 115 | - * |
|
| 116 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 117 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 118 | - * @param bool $formatted |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
| 122 | - { |
|
| 123 | - if (Benchmark::doNotRun()) { |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 127 | - Benchmark::$memory_usage[ $label ] = $memory_used; |
|
| 128 | - if ($output_now) { |
|
| 129 | - echo wp_kses( |
|
| 130 | - $formatted |
|
| 131 | - ? "<br>{$label} : {$memory_used}" |
|
| 132 | - : "\n {$label} : {$memory_used}", |
|
| 133 | - AllowedTags::getAllowedTags() |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * will display the benchmarking results at shutdown |
|
| 141 | - * |
|
| 142 | - * @param bool $formatted |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public static function displayResultsAtShutdown($formatted = true) |
|
| 146 | - { |
|
| 147 | - Benchmark::resetOutput(); |
|
| 148 | - add_action( |
|
| 149 | - 'shutdown', |
|
| 150 | - function () use ($formatted) { |
|
| 151 | - Benchmark::displayResults(true, $formatted); |
|
| 152 | - }, |
|
| 153 | - 999999 |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * will display the benchmarking results at shutdown |
|
| 160 | - * |
|
| 161 | - * @param string $filepath |
|
| 162 | - * @param bool $formatted |
|
| 163 | - * @param bool $append |
|
| 164 | - * @return void |
|
| 165 | - */ |
|
| 166 | - public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
| 167 | - { |
|
| 168 | - Benchmark::resetOutput(); |
|
| 169 | - add_action( |
|
| 170 | - 'shutdown', |
|
| 171 | - function () use ($filepath, $formatted, $append) { |
|
| 172 | - Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
| 173 | - }, |
|
| 174 | - 999999 |
|
| 175 | - ); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @param bool $formatted |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - private static function generateResults($formatted = true) |
|
| 184 | - { |
|
| 185 | - if (Benchmark::doNotRun()) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - if (! empty(Benchmark::$times)) { |
|
| 189 | - $total = 0; |
|
| 190 | - Benchmark::$output .= $formatted |
|
| 191 | - ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
| 192 | - : ''; |
|
| 193 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 194 | - Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
| 195 | - Benchmark::$output .= $formatted ? '<br />' : "\n"; |
|
| 196 | - $total += $total_time; |
|
| 197 | - } |
|
| 198 | - if ($formatted) { |
|
| 199 | - Benchmark::$output .= '<br />'; |
|
| 200 | - Benchmark::$output .= '<h4>TOTAL TIME</h4>'; |
|
| 201 | - Benchmark::$output .= Benchmark::formatTime('', $total, $formatted); |
|
| 202 | - Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 203 | - Benchmark::$output .= '<br />'; |
|
| 204 | - Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 205 | - Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 206 | - Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 207 | - Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 208 | - Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 209 | - Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 210 | - Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 214 | - Benchmark::$output .= $formatted |
|
| 215 | - ? '<h5>Memory</h5>' |
|
| 216 | - : "\nMemory"; |
|
| 217 | - foreach (Benchmark::$memory_usage as $label => $memory_usage) { |
|
| 218 | - Benchmark::$output .= $formatted |
|
| 219 | - ? "<br />{$memory_usage} : {$label}" |
|
| 220 | - : "\n{$memory_usage} : {$label}"; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - if (empty(Benchmark::$output)) { |
|
| 224 | - return ''; |
|
| 225 | - } |
|
| 226 | - Benchmark::$output = $formatted |
|
| 227 | - ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 228 | - . (is_admin() |
|
| 229 | - ? ' margin:2em 2em 2em 180px;' |
|
| 230 | - : ' margin:2em;') |
|
| 231 | - . ' padding:2em;">' |
|
| 232 | - . '<h4>BENCHMARKING</h4>' |
|
| 233 | - . Benchmark::$output |
|
| 234 | - . '</div>' |
|
| 235 | - : Benchmark::$output; |
|
| 236 | - return Benchmark::$output; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param bool $echo |
|
| 242 | - * @param bool $formatted |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public static function displayResults($echo = true, $formatted = true) |
|
| 246 | - { |
|
| 247 | - $results = Benchmark::generateResults($formatted); |
|
| 248 | - if ($echo) { |
|
| 249 | - echo wp_kses($results, AllowedTags::getWithFormTags()); |
|
| 250 | - return ''; |
|
| 251 | - } |
|
| 252 | - return $results; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param string $filepath |
|
| 258 | - * @param bool $formatted |
|
| 259 | - * @param bool $append |
|
| 260 | - * @throws EE_Error |
|
| 261 | - */ |
|
| 262 | - public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
| 263 | - { |
|
| 264 | - $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
| 265 | - ? $filepath |
|
| 266 | - : ''; |
|
| 267 | - if (empty($filepath)) { |
|
| 268 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 269 | - } |
|
| 270 | - EEH_File::ensure_file_exists_and_is_writable($filepath); |
|
| 271 | - file_put_contents( |
|
| 272 | - $filepath, |
|
| 273 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 274 | - $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 281 | - * |
|
| 282 | - * @param int $size |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public static function convert($size) |
|
| 286 | - { |
|
| 287 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 288 | - return round( |
|
| 289 | - $size / pow(1024, $i = floor(log($size, 1024))), |
|
| 290 | - 2 |
|
| 291 | - ) . ' ' . $unit[ absint($i) ]; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @param string $timer_name |
|
| 297 | - * @param float $total_time |
|
| 298 | - * @param bool $formatted |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - public static function formatTime($timer_name, $total_time, $formatted = true) |
|
| 302 | - { |
|
| 303 | - $total_time *= 1000; |
|
| 304 | - switch ($total_time) { |
|
| 305 | - case $total_time > 12500: |
|
| 306 | - $color = 'red'; |
|
| 307 | - $bold = 'bold'; |
|
| 308 | - break; |
|
| 309 | - case $total_time > 2500: |
|
| 310 | - $color = 'darkorange'; |
|
| 311 | - $bold = 'bold'; |
|
| 312 | - break; |
|
| 313 | - case $total_time > 500: |
|
| 314 | - $color = 'gold'; |
|
| 315 | - $bold = 'bold'; |
|
| 316 | - break; |
|
| 317 | - case $total_time > 100: |
|
| 318 | - $color = 'limegreen'; |
|
| 319 | - $bold = 'normal'; |
|
| 320 | - break; |
|
| 321 | - case $total_time > 20: |
|
| 322 | - $color = 'deepskyblue'; |
|
| 323 | - $bold = 'normal'; |
|
| 324 | - break; |
|
| 325 | - default: |
|
| 326 | - $color = 'mediumpurple'; |
|
| 327 | - $bold = 'normal'; |
|
| 328 | - break; |
|
| 329 | - } |
|
| 330 | - return $formatted |
|
| 331 | - ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 332 | - . $color |
|
| 333 | - . '; font-weight:' |
|
| 334 | - . $bold |
|
| 335 | - . '; font-size:1.2em;">' |
|
| 336 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 337 | - . '</span> ' |
|
| 338 | - . $timer_name |
|
| 339 | - : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
| 340 | - } |
|
| 18 | + /** |
|
| 19 | + * @var string $output |
|
| 20 | + */ |
|
| 21 | + private static $output; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var array $start_times array containing the start time for the timers |
|
| 25 | + */ |
|
| 26 | + private static $start_times; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var array $times array containing all the timer'd times, which can be outputted via show_times() |
|
| 30 | + */ |
|
| 31 | + private static $times = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array $memory_usage |
|
| 35 | + */ |
|
| 36 | + protected static $memory_usage = array(); |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param string $output |
|
| 41 | + * @param bool $formatted |
|
| 42 | + */ |
|
| 43 | + public static function addOutput($output, $formatted = true) |
|
| 44 | + { |
|
| 45 | + Benchmark::$output .= $formatted |
|
| 46 | + ? "<br />{$output}" |
|
| 47 | + : "\n{$output}"; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return void |
|
| 53 | + */ |
|
| 54 | + public static function resetOutput() |
|
| 55 | + { |
|
| 56 | + Benchmark::$output = ''; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * whether to benchmark code or not |
|
| 61 | + */ |
|
| 62 | + public static function doNotRun() |
|
| 63 | + { |
|
| 64 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * resetTimes |
|
| 70 | + */ |
|
| 71 | + public static function resetTimes() |
|
| 72 | + { |
|
| 73 | + Benchmark::$times = array(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 79 | + * |
|
| 80 | + * @param null $timer_name |
|
| 81 | + */ |
|
| 82 | + public static function startTimer($timer_name = null) |
|
| 83 | + { |
|
| 84 | + if (Benchmark::doNotRun()) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 88 | + Benchmark::$start_times[ $timer_name ] = microtime(true); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 94 | + * |
|
| 95 | + * @param string $timer_name |
|
| 96 | + */ |
|
| 97 | + public static function stopTimer($timer_name = '') |
|
| 98 | + { |
|
| 99 | + if (Benchmark::doNotRun()) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 103 | + if (isset(Benchmark::$start_times[ $timer_name ])) { |
|
| 104 | + $start_time = Benchmark::$start_times[ $timer_name ]; |
|
| 105 | + unset(Benchmark::$start_times[ $timer_name ]); |
|
| 106 | + } else { |
|
| 107 | + $start_time = array_pop(Benchmark::$start_times); |
|
| 108 | + } |
|
| 109 | + Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Measure the memory usage by PHP so far. |
|
| 115 | + * |
|
| 116 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 117 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 118 | + * @param bool $formatted |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
| 122 | + { |
|
| 123 | + if (Benchmark::doNotRun()) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 127 | + Benchmark::$memory_usage[ $label ] = $memory_used; |
|
| 128 | + if ($output_now) { |
|
| 129 | + echo wp_kses( |
|
| 130 | + $formatted |
|
| 131 | + ? "<br>{$label} : {$memory_used}" |
|
| 132 | + : "\n {$label} : {$memory_used}", |
|
| 133 | + AllowedTags::getAllowedTags() |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * will display the benchmarking results at shutdown |
|
| 141 | + * |
|
| 142 | + * @param bool $formatted |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public static function displayResultsAtShutdown($formatted = true) |
|
| 146 | + { |
|
| 147 | + Benchmark::resetOutput(); |
|
| 148 | + add_action( |
|
| 149 | + 'shutdown', |
|
| 150 | + function () use ($formatted) { |
|
| 151 | + Benchmark::displayResults(true, $formatted); |
|
| 152 | + }, |
|
| 153 | + 999999 |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * will display the benchmarking results at shutdown |
|
| 160 | + * |
|
| 161 | + * @param string $filepath |
|
| 162 | + * @param bool $formatted |
|
| 163 | + * @param bool $append |
|
| 164 | + * @return void |
|
| 165 | + */ |
|
| 166 | + public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
| 167 | + { |
|
| 168 | + Benchmark::resetOutput(); |
|
| 169 | + add_action( |
|
| 170 | + 'shutdown', |
|
| 171 | + function () use ($filepath, $formatted, $append) { |
|
| 172 | + Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
| 173 | + }, |
|
| 174 | + 999999 |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @param bool $formatted |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + private static function generateResults($formatted = true) |
|
| 184 | + { |
|
| 185 | + if (Benchmark::doNotRun()) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + if (! empty(Benchmark::$times)) { |
|
| 189 | + $total = 0; |
|
| 190 | + Benchmark::$output .= $formatted |
|
| 191 | + ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
| 192 | + : ''; |
|
| 193 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 194 | + Benchmark::$output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
| 195 | + Benchmark::$output .= $formatted ? '<br />' : "\n"; |
|
| 196 | + $total += $total_time; |
|
| 197 | + } |
|
| 198 | + if ($formatted) { |
|
| 199 | + Benchmark::$output .= '<br />'; |
|
| 200 | + Benchmark::$output .= '<h4>TOTAL TIME</h4>'; |
|
| 201 | + Benchmark::$output .= Benchmark::formatTime('', $total, $formatted); |
|
| 202 | + Benchmark::$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 203 | + Benchmark::$output .= '<br />'; |
|
| 204 | + Benchmark::$output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 205 | + Benchmark::$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 206 | + Benchmark::$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 207 | + Benchmark::$output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 208 | + Benchmark::$output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 209 | + Benchmark::$output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 210 | + Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + if (! empty(Benchmark::$memory_usage)) { |
|
| 214 | + Benchmark::$output .= $formatted |
|
| 215 | + ? '<h5>Memory</h5>' |
|
| 216 | + : "\nMemory"; |
|
| 217 | + foreach (Benchmark::$memory_usage as $label => $memory_usage) { |
|
| 218 | + Benchmark::$output .= $formatted |
|
| 219 | + ? "<br />{$memory_usage} : {$label}" |
|
| 220 | + : "\n{$memory_usage} : {$label}"; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + if (empty(Benchmark::$output)) { |
|
| 224 | + return ''; |
|
| 225 | + } |
|
| 226 | + Benchmark::$output = $formatted |
|
| 227 | + ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 228 | + . (is_admin() |
|
| 229 | + ? ' margin:2em 2em 2em 180px;' |
|
| 230 | + : ' margin:2em;') |
|
| 231 | + . ' padding:2em;">' |
|
| 232 | + . '<h4>BENCHMARKING</h4>' |
|
| 233 | + . Benchmark::$output |
|
| 234 | + . '</div>' |
|
| 235 | + : Benchmark::$output; |
|
| 236 | + return Benchmark::$output; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param bool $echo |
|
| 242 | + * @param bool $formatted |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public static function displayResults($echo = true, $formatted = true) |
|
| 246 | + { |
|
| 247 | + $results = Benchmark::generateResults($formatted); |
|
| 248 | + if ($echo) { |
|
| 249 | + echo wp_kses($results, AllowedTags::getWithFormTags()); |
|
| 250 | + return ''; |
|
| 251 | + } |
|
| 252 | + return $results; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param string $filepath |
|
| 258 | + * @param bool $formatted |
|
| 259 | + * @param bool $append |
|
| 260 | + * @throws EE_Error |
|
| 261 | + */ |
|
| 262 | + public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
| 263 | + { |
|
| 264 | + $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
| 265 | + ? $filepath |
|
| 266 | + : ''; |
|
| 267 | + if (empty($filepath)) { |
|
| 268 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 269 | + } |
|
| 270 | + EEH_File::ensure_file_exists_and_is_writable($filepath); |
|
| 271 | + file_put_contents( |
|
| 272 | + $filepath, |
|
| 273 | + "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 274 | + $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 281 | + * |
|
| 282 | + * @param int $size |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public static function convert($size) |
|
| 286 | + { |
|
| 287 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 288 | + return round( |
|
| 289 | + $size / pow(1024, $i = floor(log($size, 1024))), |
|
| 290 | + 2 |
|
| 291 | + ) . ' ' . $unit[ absint($i) ]; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @param string $timer_name |
|
| 297 | + * @param float $total_time |
|
| 298 | + * @param bool $formatted |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + public static function formatTime($timer_name, $total_time, $formatted = true) |
|
| 302 | + { |
|
| 303 | + $total_time *= 1000; |
|
| 304 | + switch ($total_time) { |
|
| 305 | + case $total_time > 12500: |
|
| 306 | + $color = 'red'; |
|
| 307 | + $bold = 'bold'; |
|
| 308 | + break; |
|
| 309 | + case $total_time > 2500: |
|
| 310 | + $color = 'darkorange'; |
|
| 311 | + $bold = 'bold'; |
|
| 312 | + break; |
|
| 313 | + case $total_time > 500: |
|
| 314 | + $color = 'gold'; |
|
| 315 | + $bold = 'bold'; |
|
| 316 | + break; |
|
| 317 | + case $total_time > 100: |
|
| 318 | + $color = 'limegreen'; |
|
| 319 | + $bold = 'normal'; |
|
| 320 | + break; |
|
| 321 | + case $total_time > 20: |
|
| 322 | + $color = 'deepskyblue'; |
|
| 323 | + $bold = 'normal'; |
|
| 324 | + break; |
|
| 325 | + default: |
|
| 326 | + $color = 'mediumpurple'; |
|
| 327 | + $bold = 'normal'; |
|
| 328 | + break; |
|
| 329 | + } |
|
| 330 | + return $formatted |
|
| 331 | + ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 332 | + . $color |
|
| 333 | + . '; font-weight:' |
|
| 334 | + . $bold |
|
| 335 | + . '; font-size:1.2em;">' |
|
| 336 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 337 | + . '</span> ' |
|
| 338 | + . $timer_name |
|
| 339 | + : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
| 340 | + } |
|
| 341 | 341 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | 87 | $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
| 88 | - Benchmark::$start_times[ $timer_name ] = microtime(true); |
|
| 88 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
| 103 | - if (isset(Benchmark::$start_times[ $timer_name ])) { |
|
| 104 | - $start_time = Benchmark::$start_times[ $timer_name ]; |
|
| 105 | - unset(Benchmark::$start_times[ $timer_name ]); |
|
| 103 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
| 104 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
| 105 | + unset(Benchmark::$start_times[$timer_name]); |
|
| 106 | 106 | } else { |
| 107 | 107 | $start_time = array_pop(Benchmark::$start_times); |
| 108 | 108 | } |
| 109 | - Benchmark::$times[ $timer_name ] = number_format(microtime(true) - $start_time, 8); |
|
| 109 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | $memory_used = Benchmark::convert(memory_get_usage(true)); |
| 127 | - Benchmark::$memory_usage[ $label ] = $memory_used; |
|
| 127 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
| 128 | 128 | if ($output_now) { |
| 129 | 129 | echo wp_kses( |
| 130 | 130 | $formatted |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | Benchmark::resetOutput(); |
| 148 | 148 | add_action( |
| 149 | 149 | 'shutdown', |
| 150 | - function () use ($formatted) { |
|
| 150 | + function() use ($formatted) { |
|
| 151 | 151 | Benchmark::displayResults(true, $formatted); |
| 152 | 152 | }, |
| 153 | 153 | 999999 |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | Benchmark::resetOutput(); |
| 169 | 169 | add_action( |
| 170 | 170 | 'shutdown', |
| 171 | - function () use ($filepath, $formatted, $append) { |
|
| 171 | + function() use ($filepath, $formatted, $append) { |
|
| 172 | 172 | Benchmark::writeResultsToFile($filepath, $formatted, $append); |
| 173 | 173 | }, |
| 174 | 174 | 999999 |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (Benchmark::doNotRun()) { |
| 186 | 186 | return ''; |
| 187 | 187 | } |
| 188 | - if (! empty(Benchmark::$times)) { |
|
| 188 | + if ( ! empty(Benchmark::$times)) { |
|
| 189 | 189 | $total = 0; |
| 190 | 190 | Benchmark::$output .= $formatted |
| 191 | 191 | ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | Benchmark::$output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 213 | + if ( ! empty(Benchmark::$memory_usage)) { |
|
| 214 | 214 | Benchmark::$output .= $formatted |
| 215 | 215 | ? '<h5>Memory</h5>' |
| 216 | 216 | : "\nMemory"; |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | ? $filepath |
| 266 | 266 | : ''; |
| 267 | 267 | if (empty($filepath)) { |
| 268 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 268 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html'; |
|
| 269 | 269 | } |
| 270 | 270 | EEH_File::ensure_file_exists_and_is_writable($filepath); |
| 271 | 271 | file_put_contents( |
| 272 | 272 | $filepath, |
| 273 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 273 | + "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted), |
|
| 274 | 274 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
| 275 | 275 | ); |
| 276 | 276 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | return round( |
| 289 | 289 | $size / pow(1024, $i = floor(log($size, 1024))), |
| 290 | 290 | 2 |
| 291 | - ) . ' ' . $unit[ absint($i) ]; |
|
| 291 | + ).' '.$unit[absint($i)]; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | |
@@ -24,123 +24,123 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class BootstrapDependencyInjectionContainer |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * @var EE_Dependency_Map $dependency_map |
|
| 29 | - */ |
|
| 30 | - protected $dependency_map; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type LoaderInterface $loader |
|
| 34 | - */ |
|
| 35 | - protected $loader; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var EE_Registry $registry |
|
| 39 | - */ |
|
| 40 | - protected $registry; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var ClassInterfaceCache $class_cache |
|
| 44 | - */ |
|
| 45 | - private $class_cache; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var Mirror |
|
| 49 | - */ |
|
| 50 | - private $mirror; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var ObjectIdentifier |
|
| 54 | - */ |
|
| 55 | - private $object_identifier; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Can't use this just yet until we exorcise some more of our singleton usage from core |
|
| 60 | - */ |
|
| 61 | - public function buildDependencyInjectionContainer() |
|
| 62 | - { |
|
| 63 | - // build DI container |
|
| 64 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
| 65 | - // $OpenCoffeeShop->addRecipes(); |
|
| 66 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Setups EE_Registry and EE_Dependency_Map |
|
| 72 | - * |
|
| 73 | - * @throws EE_Error |
|
| 74 | - */ |
|
| 75 | - public function buildLegacyDependencyInjectionContainer() |
|
| 76 | - { |
|
| 77 | - $this->class_cache = new ClassInterfaceCache(); |
|
| 78 | - $this->object_identifier = new ObjectIdentifier($this->class_cache); |
|
| 79 | - $this->mirror = new Mirror(); |
|
| 80 | - // EE_Dependency_Map: info about how to load classes required by other classes |
|
| 81 | - espresso_load_required( |
|
| 82 | - 'EE_Dependency_Map', |
|
| 83 | - EE_CORE . 'EE_Dependency_Map.core.php' |
|
| 84 | - ); |
|
| 85 | - $this->dependency_map = EE_Dependency_Map::instance($this->class_cache); |
|
| 86 | - // EE_Registry: central repository for classes (legacy) |
|
| 87 | - espresso_load_required( |
|
| 88 | - 'EE_Registry', |
|
| 89 | - EE_CORE . 'EE_Registry.core.php' |
|
| 90 | - ); |
|
| 91 | - $this->registry = EE_Registry::instance( |
|
| 92 | - $this->dependency_map, |
|
| 93 | - $this->mirror, |
|
| 94 | - $this->class_cache, |
|
| 95 | - $this->object_identifier |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Performs initial setup for the generic Loader |
|
| 102 | - * |
|
| 103 | - * @throws InvalidDataTypeException |
|
| 104 | - * @throws InvalidInterfaceException |
|
| 105 | - * @throws InvalidArgumentException |
|
| 106 | - */ |
|
| 107 | - public function buildLoader() |
|
| 108 | - { |
|
| 109 | - $this->loader = LoaderFactory::getLoader( |
|
| 110 | - $this->registry, |
|
| 111 | - $this->class_cache, |
|
| 112 | - $this->object_identifier |
|
| 113 | - ); |
|
| 114 | - $this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache); |
|
| 115 | - $this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier); |
|
| 116 | - $this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror); |
|
| 117 | - $this->dependency_map->setLoader($this->loader); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return EE_Dependency_Map |
|
| 123 | - */ |
|
| 124 | - public function getDependencyMap(): EE_Dependency_Map |
|
| 125 | - { |
|
| 126 | - return $this->dependency_map; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return EE_Registry |
|
| 132 | - */ |
|
| 133 | - public function getRegistry(): EE_Registry |
|
| 134 | - { |
|
| 135 | - return $this->registry; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return LoaderInterface |
|
| 141 | - */ |
|
| 142 | - public function getLoader(): LoaderInterface |
|
| 143 | - { |
|
| 144 | - return $this->loader; |
|
| 145 | - } |
|
| 27 | + /** |
|
| 28 | + * @var EE_Dependency_Map $dependency_map |
|
| 29 | + */ |
|
| 30 | + protected $dependency_map; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type LoaderInterface $loader |
|
| 34 | + */ |
|
| 35 | + protected $loader; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var EE_Registry $registry |
|
| 39 | + */ |
|
| 40 | + protected $registry; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var ClassInterfaceCache $class_cache |
|
| 44 | + */ |
|
| 45 | + private $class_cache; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var Mirror |
|
| 49 | + */ |
|
| 50 | + private $mirror; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var ObjectIdentifier |
|
| 54 | + */ |
|
| 55 | + private $object_identifier; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Can't use this just yet until we exorcise some more of our singleton usage from core |
|
| 60 | + */ |
|
| 61 | + public function buildDependencyInjectionContainer() |
|
| 62 | + { |
|
| 63 | + // build DI container |
|
| 64 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
| 65 | + // $OpenCoffeeShop->addRecipes(); |
|
| 66 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Setups EE_Registry and EE_Dependency_Map |
|
| 72 | + * |
|
| 73 | + * @throws EE_Error |
|
| 74 | + */ |
|
| 75 | + public function buildLegacyDependencyInjectionContainer() |
|
| 76 | + { |
|
| 77 | + $this->class_cache = new ClassInterfaceCache(); |
|
| 78 | + $this->object_identifier = new ObjectIdentifier($this->class_cache); |
|
| 79 | + $this->mirror = new Mirror(); |
|
| 80 | + // EE_Dependency_Map: info about how to load classes required by other classes |
|
| 81 | + espresso_load_required( |
|
| 82 | + 'EE_Dependency_Map', |
|
| 83 | + EE_CORE . 'EE_Dependency_Map.core.php' |
|
| 84 | + ); |
|
| 85 | + $this->dependency_map = EE_Dependency_Map::instance($this->class_cache); |
|
| 86 | + // EE_Registry: central repository for classes (legacy) |
|
| 87 | + espresso_load_required( |
|
| 88 | + 'EE_Registry', |
|
| 89 | + EE_CORE . 'EE_Registry.core.php' |
|
| 90 | + ); |
|
| 91 | + $this->registry = EE_Registry::instance( |
|
| 92 | + $this->dependency_map, |
|
| 93 | + $this->mirror, |
|
| 94 | + $this->class_cache, |
|
| 95 | + $this->object_identifier |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Performs initial setup for the generic Loader |
|
| 102 | + * |
|
| 103 | + * @throws InvalidDataTypeException |
|
| 104 | + * @throws InvalidInterfaceException |
|
| 105 | + * @throws InvalidArgumentException |
|
| 106 | + */ |
|
| 107 | + public function buildLoader() |
|
| 108 | + { |
|
| 109 | + $this->loader = LoaderFactory::getLoader( |
|
| 110 | + $this->registry, |
|
| 111 | + $this->class_cache, |
|
| 112 | + $this->object_identifier |
|
| 113 | + ); |
|
| 114 | + $this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache); |
|
| 115 | + $this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier); |
|
| 116 | + $this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror); |
|
| 117 | + $this->dependency_map->setLoader($this->loader); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return EE_Dependency_Map |
|
| 123 | + */ |
|
| 124 | + public function getDependencyMap(): EE_Dependency_Map |
|
| 125 | + { |
|
| 126 | + return $this->dependency_map; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return EE_Registry |
|
| 132 | + */ |
|
| 133 | + public function getRegistry(): EE_Registry |
|
| 134 | + { |
|
| 135 | + return $this->registry; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return LoaderInterface |
|
| 141 | + */ |
|
| 142 | + public function getLoader(): LoaderInterface |
|
| 143 | + { |
|
| 144 | + return $this->loader; |
|
| 145 | + } |
|
| 146 | 146 | } |
@@ -10,41 +10,41 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | interface AddressInterface |
| 12 | 12 | { |
| 13 | - public function address(): string; |
|
| 13 | + public function address(): string; |
|
| 14 | 14 | |
| 15 | 15 | |
| 16 | - public function address2(): string; |
|
| 16 | + public function address2(): string; |
|
| 17 | 17 | |
| 18 | 18 | |
| 19 | - public function city(): string; |
|
| 19 | + public function city(): string; |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - public function state_obj(): EE_State; |
|
| 22 | + public function state_obj(): EE_State; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - public function state_ID(): int; |
|
| 25 | + public function state_ID(): int; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - public function state_name(): string; |
|
| 28 | + public function state_name(): string; |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - public function state_abbrev(): string; |
|
| 31 | + public function state_abbrev(): string; |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - public function state(): string; |
|
| 34 | + public function state(): string; |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - public function country_obj(): EE_Country; |
|
| 37 | + public function country_obj(): EE_Country; |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - public function country_ID(): string; |
|
| 40 | + public function country_ID(): string; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - public function country_name(): string; |
|
| 43 | + public function country_name(): string; |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - public function country(): string; |
|
| 46 | + public function country(): string; |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - public function zip(): string; |
|
| 49 | + public function zip(): string; |
|
| 50 | 50 | } |
@@ -4,23 +4,23 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface AddressFormatterInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @param string $address |
|
| 9 | - * @param string $address2 |
|
| 10 | - * @param string $city |
|
| 11 | - * @param string $state |
|
| 12 | - * @param string $zip |
|
| 13 | - * @param string $country |
|
| 14 | - * @param string $CNT_ISO |
|
| 15 | - * @return string|null |
|
| 16 | - */ |
|
| 17 | - public function format( |
|
| 18 | - string $address, |
|
| 19 | - string $address2, |
|
| 20 | - string $city, |
|
| 21 | - string $state, |
|
| 22 | - string $zip, |
|
| 23 | - string $country, |
|
| 24 | - string $CNT_ISO |
|
| 25 | - ): ?string; |
|
| 7 | + /** |
|
| 8 | + * @param string $address |
|
| 9 | + * @param string $address2 |
|
| 10 | + * @param string $city |
|
| 11 | + * @param string $state |
|
| 12 | + * @param string $zip |
|
| 13 | + * @param string $country |
|
| 14 | + * @param string $CNT_ISO |
|
| 15 | + * @return string|null |
|
| 16 | + */ |
|
| 17 | + public function format( |
|
| 18 | + string $address, |
|
| 19 | + string $address2, |
|
| 20 | + string $city, |
|
| 21 | + string $state, |
|
| 22 | + string $zip, |
|
| 23 | + string $country, |
|
| 24 | + string $CNT_ISO |
|
| 25 | + ): ?string; |
|
| 26 | 26 | } |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class NullAddressFormatter implements AddressFormatterInterface |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @param string $address |
|
| 17 | - * @param string $address2 |
|
| 18 | - * @param string $city |
|
| 19 | - * @param string $state |
|
| 20 | - * @param string $zip |
|
| 21 | - * @param string $country |
|
| 22 | - * @param string $CNT_ISO |
|
| 23 | - * @return string|null |
|
| 24 | - */ |
|
| 25 | - public function format( |
|
| 26 | - string $address, |
|
| 27 | - string $address2, |
|
| 28 | - string $city, |
|
| 29 | - string $state, |
|
| 30 | - string $zip, |
|
| 31 | - string $country, |
|
| 32 | - string $CNT_ISO |
|
| 33 | - ): ?string { |
|
| 34 | - return null; |
|
| 35 | - } |
|
| 15 | + /** |
|
| 16 | + * @param string $address |
|
| 17 | + * @param string $address2 |
|
| 18 | + * @param string $city |
|
| 19 | + * @param string $state |
|
| 20 | + * @param string $zip |
|
| 21 | + * @param string $country |
|
| 22 | + * @param string $CNT_ISO |
|
| 23 | + * @return string|null |
|
| 24 | + */ |
|
| 25 | + public function format( |
|
| 26 | + string $address, |
|
| 27 | + string $address2, |
|
| 28 | + string $city, |
|
| 29 | + string $state, |
|
| 30 | + string $zip, |
|
| 31 | + string $country, |
|
| 32 | + string $CNT_ISO |
|
| 33 | + ): ?string { |
|
| 34 | + return null; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -19,240 +19,240 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class GenericAddress implements AddressInterface |
| 21 | 21 | { |
| 22 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - private $_address; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private $_address2; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - private $_city; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var int |
|
| 40 | - */ |
|
| 41 | - private $_state_ID = 0; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_State |
|
| 45 | - */ |
|
| 46 | - private $_state_obj; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - private $_zip; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - private $_country_ID = ''; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var EE_Country |
|
| 60 | - */ |
|
| 61 | - private $_country_obj; |
|
| 62 | - // phpcs:enable |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 66 | - /** |
|
| 67 | - * @param string $address |
|
| 68 | - * @param string $address2 |
|
| 69 | - * @param string $city |
|
| 70 | - * @param EE_State|int $state |
|
| 71 | - * @param string $zip |
|
| 72 | - * @param EE_Country|string $country |
|
| 73 | - * @throws EE_Error |
|
| 74 | - * @throws ReflectionException |
|
| 75 | - */ |
|
| 76 | - public function __construct(string $address, string $address2, string $city, $state, string $zip, $country) |
|
| 77 | - { |
|
| 78 | - $this->_address = $address; |
|
| 79 | - $this->_address2 = $address2; |
|
| 80 | - $this->_city = $city; |
|
| 81 | - if ($state instanceof EE_State) { |
|
| 82 | - $this->_state_obj = $state; |
|
| 83 | - } else { |
|
| 84 | - $this->_state_ID = $state; |
|
| 85 | - $this->_state_obj = $this->_get_state_obj(); |
|
| 86 | - } |
|
| 87 | - $this->_zip = $zip; |
|
| 88 | - if ($country instanceof EE_Country) { |
|
| 89 | - $this->_country_obj = $country; |
|
| 90 | - } else { |
|
| 91 | - $this->_country_ID = $country; |
|
| 92 | - $this->_country_obj = $this->_get_country_obj(); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 100 | - public function address(): string |
|
| 101 | - { |
|
| 102 | - return $this->_address; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function address2(): string |
|
| 110 | - { |
|
| 111 | - return $this->_address2; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 118 | - public function city(): string |
|
| 119 | - { |
|
| 120 | - return $this->_city; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @return EE_State |
|
| 128 | - * @throws EE_Error |
|
| 129 | - * @throws ReflectionException |
|
| 130 | - */ |
|
| 131 | - private function _get_state_obj(): EE_State |
|
| 132 | - { |
|
| 133 | - return $this->_state_obj instanceof EE_State |
|
| 134 | - ? $this->_state_obj |
|
| 135 | - : EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return int |
|
| 141 | - */ |
|
| 142 | - public function state_ID(): int |
|
| 143 | - { |
|
| 144 | - return $this->_state_ID; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - public function state_abbrev(): string |
|
| 152 | - { |
|
| 153 | - return $this->state_obj() instanceof EE_State |
|
| 154 | - ? $this->state_obj()->abbrev() |
|
| 155 | - : ''; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function state_name(): string |
|
| 163 | - { |
|
| 164 | - return $this->state_obj() instanceof EE_State |
|
| 165 | - ? $this->state_obj()->name() |
|
| 166 | - : ''; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return EE_State |
|
| 172 | - */ |
|
| 173 | - public function state_obj(): EE_State |
|
| 174 | - { |
|
| 175 | - return $this->_state_obj; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function state(): string |
|
| 183 | - { |
|
| 184 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 185 | - return $this->state_obj()->abbrev(); |
|
| 186 | - } else { |
|
| 187 | - return $this->state_name(); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @return EE_Country |
|
| 194 | - * @throws EE_Error |
|
| 195 | - * @throws ReflectionException |
|
| 196 | - */ |
|
| 197 | - private function _get_country_obj(): EE_Country |
|
| 198 | - { |
|
| 199 | - return $this->_country_obj instanceof EE_Country |
|
| 200 | - ? $this->_country_obj |
|
| 201 | - : EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function country_ID(): string |
|
| 209 | - { |
|
| 210 | - return $this->_country_ID; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @return string |
|
| 216 | - * @throws EE_Error |
|
| 217 | - * @throws ReflectionException |
|
| 218 | - */ |
|
| 219 | - public function country_name(): string |
|
| 220 | - { |
|
| 221 | - return $this->country_obj() instanceof EE_Country |
|
| 222 | - ? $this->country_obj()->name() |
|
| 223 | - : ''; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return EE_Country |
|
| 229 | - */ |
|
| 230 | - public function country_obj(): EE_Country |
|
| 231 | - { |
|
| 232 | - return $this->_country_obj; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @return string |
|
| 238 | - * @throws EE_Error |
|
| 239 | - * @throws ReflectionException |
|
| 240 | - */ |
|
| 241 | - public function country(): string |
|
| 242 | - { |
|
| 243 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 244 | - return $this->country_ID(); |
|
| 245 | - } else { |
|
| 246 | - return $this->country_name(); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - public function zip(): string |
|
| 255 | - { |
|
| 256 | - return $this->_zip; |
|
| 257 | - } |
|
| 22 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + private $_address; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private $_address2; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + private $_city; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var int |
|
| 40 | + */ |
|
| 41 | + private $_state_ID = 0; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_State |
|
| 45 | + */ |
|
| 46 | + private $_state_obj; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + private $_zip; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + private $_country_ID = ''; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var EE_Country |
|
| 60 | + */ |
|
| 61 | + private $_country_obj; |
|
| 62 | + // phpcs:enable |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 66 | + /** |
|
| 67 | + * @param string $address |
|
| 68 | + * @param string $address2 |
|
| 69 | + * @param string $city |
|
| 70 | + * @param EE_State|int $state |
|
| 71 | + * @param string $zip |
|
| 72 | + * @param EE_Country|string $country |
|
| 73 | + * @throws EE_Error |
|
| 74 | + * @throws ReflectionException |
|
| 75 | + */ |
|
| 76 | + public function __construct(string $address, string $address2, string $city, $state, string $zip, $country) |
|
| 77 | + { |
|
| 78 | + $this->_address = $address; |
|
| 79 | + $this->_address2 = $address2; |
|
| 80 | + $this->_city = $city; |
|
| 81 | + if ($state instanceof EE_State) { |
|
| 82 | + $this->_state_obj = $state; |
|
| 83 | + } else { |
|
| 84 | + $this->_state_ID = $state; |
|
| 85 | + $this->_state_obj = $this->_get_state_obj(); |
|
| 86 | + } |
|
| 87 | + $this->_zip = $zip; |
|
| 88 | + if ($country instanceof EE_Country) { |
|
| 89 | + $this->_country_obj = $country; |
|
| 90 | + } else { |
|
| 91 | + $this->_country_ID = $country; |
|
| 92 | + $this->_country_obj = $this->_get_country_obj(); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | + public function address(): string |
|
| 101 | + { |
|
| 102 | + return $this->_address; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function address2(): string |
|
| 110 | + { |
|
| 111 | + return $this->_address2; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | + public function city(): string |
|
| 119 | + { |
|
| 120 | + return $this->_city; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @return EE_State |
|
| 128 | + * @throws EE_Error |
|
| 129 | + * @throws ReflectionException |
|
| 130 | + */ |
|
| 131 | + private function _get_state_obj(): EE_State |
|
| 132 | + { |
|
| 133 | + return $this->_state_obj instanceof EE_State |
|
| 134 | + ? $this->_state_obj |
|
| 135 | + : EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return int |
|
| 141 | + */ |
|
| 142 | + public function state_ID(): int |
|
| 143 | + { |
|
| 144 | + return $this->_state_ID; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + public function state_abbrev(): string |
|
| 152 | + { |
|
| 153 | + return $this->state_obj() instanceof EE_State |
|
| 154 | + ? $this->state_obj()->abbrev() |
|
| 155 | + : ''; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function state_name(): string |
|
| 163 | + { |
|
| 164 | + return $this->state_obj() instanceof EE_State |
|
| 165 | + ? $this->state_obj()->name() |
|
| 166 | + : ''; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return EE_State |
|
| 172 | + */ |
|
| 173 | + public function state_obj(): EE_State |
|
| 174 | + { |
|
| 175 | + return $this->_state_obj; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function state(): string |
|
| 183 | + { |
|
| 184 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 185 | + return $this->state_obj()->abbrev(); |
|
| 186 | + } else { |
|
| 187 | + return $this->state_name(); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @return EE_Country |
|
| 194 | + * @throws EE_Error |
|
| 195 | + * @throws ReflectionException |
|
| 196 | + */ |
|
| 197 | + private function _get_country_obj(): EE_Country |
|
| 198 | + { |
|
| 199 | + return $this->_country_obj instanceof EE_Country |
|
| 200 | + ? $this->_country_obj |
|
| 201 | + : EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function country_ID(): string |
|
| 209 | + { |
|
| 210 | + return $this->_country_ID; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @return string |
|
| 216 | + * @throws EE_Error |
|
| 217 | + * @throws ReflectionException |
|
| 218 | + */ |
|
| 219 | + public function country_name(): string |
|
| 220 | + { |
|
| 221 | + return $this->country_obj() instanceof EE_Country |
|
| 222 | + ? $this->country_obj()->name() |
|
| 223 | + : ''; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return EE_Country |
|
| 229 | + */ |
|
| 230 | + public function country_obj(): EE_Country |
|
| 231 | + { |
|
| 232 | + return $this->_country_obj; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @return string |
|
| 238 | + * @throws EE_Error |
|
| 239 | + * @throws ReflectionException |
|
| 240 | + */ |
|
| 241 | + public function country(): string |
|
| 242 | + { |
|
| 243 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 244 | + return $this->country_ID(); |
|
| 245 | + } else { |
|
| 246 | + return $this->country_name(); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + public function zip(): string |
|
| 255 | + { |
|
| 256 | + return $this->_zip; |
|
| 257 | + } |
|
| 258 | 258 | } |
@@ -12,549 +12,549 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_Html_messenger extends EE_messenger |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * The following are the properties that this messenger requires for displaying the html |
|
| 17 | - */ |
|
| 18 | - /** |
|
| 19 | - * This is the html body generated by the template via the message type. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $_content = ''; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
| 27 | - * equivalent to the "subject" of the page. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected $_subject = ''; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * EE_Html_messenger constructor. |
|
| 36 | - */ |
|
| 37 | - public function __construct() |
|
| 38 | - { |
|
| 39 | - // set properties |
|
| 40 | - $this->name = 'html'; |
|
| 41 | - $this->description = esc_html__( |
|
| 42 | - 'This messenger outputs a message to a browser for display.', |
|
| 43 | - 'event_espresso' |
|
| 44 | - ); |
|
| 45 | - $this->label = [ |
|
| 46 | - 'singular' => esc_html__('html', 'event_espresso'), |
|
| 47 | - 'plural' => esc_html__('html', 'event_espresso'), |
|
| 48 | - ]; |
|
| 49 | - $this->activate_on_install = true; |
|
| 50 | - // add the "powered by EE" credit link to the HTML receipt and invoice |
|
| 51 | - add_filter( |
|
| 52 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
| 53 | - [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
| 54 | - 10, |
|
| 55 | - 3 |
|
| 56 | - ); |
|
| 57 | - parent::__construct(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * HTML Messenger desires execution immediately. |
|
| 63 | - * |
|
| 64 | - * @return bool |
|
| 65 | - * @since 4.9.0 |
|
| 66 | - * @see parent::send_now() for documentation. |
|
| 67 | - */ |
|
| 68 | - public function send_now(): bool |
|
| 69 | - { |
|
| 70 | - return true; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * HTML Messenger allows an empty to field. |
|
| 76 | - * |
|
| 77 | - * @return bool |
|
| 78 | - * @since 4.9.0 |
|
| 79 | - * @see parent::allow_empty_to_field() for documentation |
|
| 80 | - */ |
|
| 81 | - public function allow_empty_to_field(): bool |
|
| 82 | - { |
|
| 83 | - return true; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @see abstract declaration in EE_messenger for details. |
|
| 89 | - */ |
|
| 90 | - protected function _set_admin_pages() |
|
| 91 | - { |
|
| 92 | - $this->admin_registered_pages = ['events_edit' => true]; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @see abstract declaration in EE_messenger for details. |
|
| 98 | - */ |
|
| 99 | - protected function _set_valid_shortcodes() |
|
| 100 | - { |
|
| 101 | - $this->_valid_shortcodes = []; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @see abstract declaration in EE_messenger for details. |
|
| 107 | - */ |
|
| 108 | - protected function _set_validator_config() |
|
| 109 | - { |
|
| 110 | - $this->_validator_config = [ |
|
| 111 | - 'subject' => [ |
|
| 112 | - 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
| 113 | - ], |
|
| 114 | - 'content' => [ |
|
| 115 | - 'shortcodes' => [ |
|
| 116 | - 'organization', |
|
| 117 | - 'primary_registration_list', |
|
| 118 | - 'primary_registration_details', |
|
| 119 | - 'email', |
|
| 120 | - 'transaction', |
|
| 121 | - 'event_list', |
|
| 122 | - 'payment_list', |
|
| 123 | - 'venue', |
|
| 124 | - 'line_item_list', |
|
| 125 | - 'messenger', |
|
| 126 | - 'ticket_list', |
|
| 127 | - ], |
|
| 128 | - ], |
|
| 129 | - 'event_list' => [ |
|
| 130 | - 'shortcodes' => [ |
|
| 131 | - 'event', |
|
| 132 | - 'ticket_list', |
|
| 133 | - 'venue', |
|
| 134 | - 'primary_registration_details', |
|
| 135 | - 'primary_registration_list', |
|
| 136 | - 'event_author', |
|
| 137 | - ], |
|
| 138 | - 'required' => ['[EVENT_LIST]'], |
|
| 139 | - ], |
|
| 140 | - 'ticket_list' => [ |
|
| 141 | - 'shortcodes' => [ |
|
| 142 | - 'attendee_list', |
|
| 143 | - 'ticket', |
|
| 144 | - 'datetime_list', |
|
| 145 | - 'primary_registration_details', |
|
| 146 | - 'line_item_list', |
|
| 147 | - 'venue', |
|
| 148 | - ], |
|
| 149 | - 'required' => ['[TICKET_LIST]'], |
|
| 150 | - ], |
|
| 151 | - 'ticket_line_item_no_pms' => [ |
|
| 152 | - 'shortcodes' => ['line_item', 'ticket'], |
|
| 153 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 154 | - ], |
|
| 155 | - 'ticket_line_item_pms' => [ |
|
| 156 | - 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
| 157 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 158 | - ], |
|
| 159 | - 'price_modifier_line_item_list' => [ |
|
| 160 | - 'shortcodes' => ['line_item'], |
|
| 161 | - 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
| 162 | - ], |
|
| 163 | - 'datetime_list' => [ |
|
| 164 | - 'shortcodes' => ['datetime'], |
|
| 165 | - 'required' => ['[DATETIME_LIST]'], |
|
| 166 | - ], |
|
| 167 | - 'attendee_list' => [ |
|
| 168 | - 'shortcodes' => ['attendee'], |
|
| 169 | - 'required' => ['[ATTENDEE_LIST]'], |
|
| 170 | - ], |
|
| 171 | - 'tax_line_item_list' => [ |
|
| 172 | - 'shortcodes' => ['line_item'], |
|
| 173 | - 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
| 174 | - ], |
|
| 175 | - 'additional_line_item_list' => [ |
|
| 176 | - 'shortcodes' => ['line_item'], |
|
| 177 | - 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
| 178 | - ], |
|
| 179 | - 'payment_list' => [ |
|
| 180 | - 'shortcodes' => ['payment'], |
|
| 181 | - 'required' => ['[PAYMENT_LIST_*]'], |
|
| 182 | - ], |
|
| 183 | - ]; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
| 189 | - * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
| 190 | - * (i.e. swap out css files or something else). |
|
| 191 | - * |
|
| 192 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
| 193 | - * @return void |
|
| 194 | - * @since 4.5.0 |
|
| 195 | - */ |
|
| 196 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
| 197 | - { |
|
| 198 | - if ($sending_messenger_name === 'pdf') { |
|
| 199 | - add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * @param $variation_path |
|
| 206 | - * @param EE_Messages_Template_Pack $template_pack |
|
| 207 | - * @param $messenger_name |
|
| 208 | - * @param $message_type_name |
|
| 209 | - * @param $url |
|
| 210 | - * @param $type |
|
| 211 | - * @param $variation |
|
| 212 | - * @param $skip_filters |
|
| 213 | - * @return string |
|
| 214 | - */ |
|
| 215 | - public function add_html_css( |
|
| 216 | - $variation_path, |
|
| 217 | - EE_Messages_Template_Pack $template_pack, |
|
| 218 | - $messenger_name, |
|
| 219 | - $message_type_name, |
|
| 220 | - $url, |
|
| 221 | - $type, |
|
| 222 | - $variation, |
|
| 223 | - $skip_filters |
|
| 224 | - ): string { |
|
| 225 | - return $template_pack->get_variation( |
|
| 226 | - $this->name, |
|
| 227 | - $message_type_name, |
|
| 228 | - $type, |
|
| 229 | - $variation, |
|
| 230 | - $url, |
|
| 231 | - '.css', |
|
| 232 | - $skip_filters |
|
| 233 | - ); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
| 239 | - * messenger can add their own js. |
|
| 240 | - * |
|
| 241 | - * @return void. |
|
| 242 | - */ |
|
| 243 | - public function enqueue_scripts_styles() |
|
| 244 | - { |
|
| 245 | - parent::enqueue_scripts_styles(); |
|
| 246 | - do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * _set_template_fields |
|
| 252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
| 253 | - * |
|
| 254 | - * @access protected |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - protected function _set_template_fields() |
|
| 258 | - { |
|
| 259 | - // any extra template fields that are NOT used by the messenger |
|
| 260 | - // but will get used by a messenger field for shortcode replacement |
|
| 261 | - // get added to the 'extra' key in an associated array |
|
| 262 | - // indexed by the messenger field they relate to. |
|
| 263 | - // This is important for the Messages_admin to know what fields to display to the user. |
|
| 264 | - // Also, notice that the "values" are equal to the field type |
|
| 265 | - // that messages admin will use to know what kind of field to display. |
|
| 266 | - // The values ALSO have one index labeled "shortcode". |
|
| 267 | - // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
| 268 | - // is required in order for this extra field to be displayed. |
|
| 269 | - // If the required shortcode isn't part of the shortcodes array |
|
| 270 | - // then the field is not needed and will not be displayed/parsed. |
|
| 271 | - $this->_template_fields = [ |
|
| 272 | - 'subject' => [ |
|
| 273 | - 'input' => 'text', |
|
| 274 | - 'label' => esc_html__('Page Title', 'event_espresso'), |
|
| 275 | - 'type' => 'string', |
|
| 276 | - 'required' => true, |
|
| 277 | - 'validation' => true, |
|
| 278 | - 'css_class' => 'large-text', |
|
| 279 | - 'format' => '%s', |
|
| 280 | - ], |
|
| 281 | - 'content' => '', |
|
| 282 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
| 283 | - 'extra' => [ |
|
| 284 | - 'content' => [ |
|
| 285 | - 'main' => [ |
|
| 286 | - 'input' => 'wp_editor', |
|
| 287 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
| 288 | - 'type' => 'string', |
|
| 289 | - 'required' => true, |
|
| 290 | - 'validation' => true, |
|
| 291 | - 'format' => '%s', |
|
| 292 | - 'rows' => '15', |
|
| 293 | - ], |
|
| 294 | - 'event_list' => [ |
|
| 295 | - 'input' => 'wp_editor', |
|
| 296 | - 'label' => '[EVENT_LIST]', |
|
| 297 | - 'type' => 'string', |
|
| 298 | - 'required' => true, |
|
| 299 | - 'validation' => true, |
|
| 300 | - 'format' => '%s', |
|
| 301 | - 'rows' => '15', |
|
| 302 | - 'shortcodes_required' => ['[EVENT_LIST]'], |
|
| 303 | - ], |
|
| 304 | - 'ticket_list' => [ |
|
| 305 | - 'input' => 'textarea', |
|
| 306 | - 'label' => '[TICKET_LIST]', |
|
| 307 | - 'type' => 'string', |
|
| 308 | - 'required' => true, |
|
| 309 | - 'validation' => true, |
|
| 310 | - 'format' => '%s', |
|
| 311 | - 'css_class' => 'large-text', |
|
| 312 | - 'rows' => '10', |
|
| 313 | - 'shortcodes_required' => ['[TICKET_LIST]'], |
|
| 314 | - ], |
|
| 315 | - 'ticket_line_item_no_pms' => [ |
|
| 316 | - 'input' => 'textarea', |
|
| 317 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
| 318 | - 'Ticket Line Item List with no Price Modifiers', |
|
| 319 | - 'event_espresso' |
|
| 320 | - ), |
|
| 321 | - 'type' => 'string', |
|
| 322 | - 'required' => false, |
|
| 323 | - 'validation' => true, |
|
| 324 | - 'format' => '%s', |
|
| 325 | - 'css_class' => 'large-text', |
|
| 326 | - 'rows' => '5', |
|
| 327 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 328 | - ], |
|
| 329 | - 'ticket_line_item_pms' => [ |
|
| 330 | - 'input' => 'textarea', |
|
| 331 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
| 332 | - 'Ticket Line Item List with Price Modifiers', |
|
| 333 | - 'event_espresso' |
|
| 334 | - ), |
|
| 335 | - 'type' => 'string', |
|
| 336 | - 'required' => false, |
|
| 337 | - 'validation' => true, |
|
| 338 | - 'format' => '%s', |
|
| 339 | - 'css_class' => 'large-text', |
|
| 340 | - 'rows' => '5', |
|
| 341 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 342 | - ], |
|
| 343 | - 'price_modifier_line_item_list' => [ |
|
| 344 | - 'input' => 'textarea', |
|
| 345 | - 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
| 346 | - 'type' => 'string', |
|
| 347 | - 'required' => false, |
|
| 348 | - 'validation' => true, |
|
| 349 | - 'format' => '%s', |
|
| 350 | - 'css_class' => 'large-text', |
|
| 351 | - 'rows' => '5', |
|
| 352 | - 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
| 353 | - ], |
|
| 354 | - 'datetime_list' => [ |
|
| 355 | - 'input' => 'textarea', |
|
| 356 | - 'label' => '[DATETIME_LIST]', |
|
| 357 | - 'type' => 'string', |
|
| 358 | - 'required' => true, |
|
| 359 | - 'validation' => true, |
|
| 360 | - 'format' => '%s', |
|
| 361 | - 'css_class' => 'large-text', |
|
| 362 | - 'rows' => '5', |
|
| 363 | - 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
| 364 | - ], |
|
| 365 | - 'attendee_list' => [ |
|
| 366 | - 'input' => 'textarea', |
|
| 367 | - 'label' => '[ATTENDEE_LIST]', |
|
| 368 | - 'type' => 'string', |
|
| 369 | - 'required' => true, |
|
| 370 | - 'validation' => true, |
|
| 371 | - 'format' => '%s', |
|
| 372 | - 'css_class' => 'large-text', |
|
| 373 | - 'rows' => '5', |
|
| 374 | - 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
| 375 | - ], |
|
| 376 | - 'tax_line_item_list' => [ |
|
| 377 | - 'input' => 'textarea', |
|
| 378 | - 'label' => '[TAX_LINE_ITEM_LIST]', |
|
| 379 | - 'type' => 'string', |
|
| 380 | - 'required' => false, |
|
| 381 | - 'validation' => true, |
|
| 382 | - 'format' => '%s', |
|
| 383 | - 'css_class' => 'large-text', |
|
| 384 | - 'rows' => '5', |
|
| 385 | - 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
| 386 | - ], |
|
| 387 | - 'additional_line_item_list' => [ |
|
| 388 | - 'input' => 'textarea', |
|
| 389 | - 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
| 390 | - 'type' => 'string', |
|
| 391 | - 'required' => false, |
|
| 392 | - 'validation' => true, |
|
| 393 | - 'format' => '%s', |
|
| 394 | - 'css_class' => 'large-text', |
|
| 395 | - 'rows' => '5', |
|
| 396 | - 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
| 397 | - ], |
|
| 398 | - 'payment_list' => [ |
|
| 399 | - 'input' => 'textarea', |
|
| 400 | - 'label' => '[PAYMENT_LIST]', |
|
| 401 | - 'type' => 'string', |
|
| 402 | - 'required' => true, |
|
| 403 | - 'validation' => true, |
|
| 404 | - 'format' => '%s', |
|
| 405 | - 'css_class' => 'large-text', |
|
| 406 | - 'rows' => '5', |
|
| 407 | - 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
| 408 | - ], |
|
| 409 | - ], |
|
| 410 | - ], |
|
| 411 | - ]; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @see definition of this method in parent |
|
| 417 | - * @since 4.5.0 |
|
| 418 | - */ |
|
| 419 | - protected function _set_default_message_types() |
|
| 420 | - { |
|
| 421 | - $this->_default_message_types = ['receipt', 'invoice']; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @see definition of this method in parent |
|
| 427 | - * @since 4.5.0 |
|
| 428 | - */ |
|
| 429 | - protected function _set_valid_message_types() |
|
| 430 | - { |
|
| 431 | - $this->_valid_message_types = ['receipt', 'invoice']; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Displays the message in the browser. |
|
| 437 | - * |
|
| 438 | - * @return void. |
|
| 439 | - * @since 4.5.0 |
|
| 440 | - */ |
|
| 441 | - protected function _send_message() |
|
| 442 | - { |
|
| 443 | - $this->_template_args = [ |
|
| 444 | - 'page_title' => $this->_subject, |
|
| 445 | - 'base_css' => $this->get_variation( |
|
| 446 | - $this->_tmp_pack, |
|
| 447 | - $this->_incoming_message_type->name, |
|
| 448 | - true, |
|
| 449 | - 'base', |
|
| 450 | - $this->_variation |
|
| 451 | - ), |
|
| 452 | - 'print_css' => $this->get_variation( |
|
| 453 | - $this->_tmp_pack, |
|
| 454 | - $this->_incoming_message_type->name, |
|
| 455 | - true, |
|
| 456 | - 'print', |
|
| 457 | - $this->_variation |
|
| 458 | - ), |
|
| 459 | - 'main_css' => $this->get_variation( |
|
| 460 | - $this->_tmp_pack, |
|
| 461 | - $this->_incoming_message_type->name, |
|
| 462 | - true, |
|
| 463 | - 'main', |
|
| 464 | - $this->_variation |
|
| 465 | - ), |
|
| 466 | - 'main_body' => wpautop( |
|
| 467 | - apply_filters( |
|
| 468 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
| 469 | - $this->_content, |
|
| 470 | - $this->_content, |
|
| 471 | - $this->_incoming_message_type |
|
| 472 | - ) |
|
| 473 | - ), |
|
| 474 | - ]; |
|
| 475 | - $this->_deregister_wp_hooks(); |
|
| 476 | - add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
| 477 | - echo '<!doctype html>'.wp_kses($this->_get_main_template(), AllowedTags::getWithFullTags()); |
|
| 478 | - exit(); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
| 484 | - * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
| 485 | - * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
| 486 | - * |
|
| 487 | - * @return void |
|
| 488 | - * @since 4.5.0 |
|
| 489 | - */ |
|
| 490 | - protected function _deregister_wp_hooks() |
|
| 491 | - { |
|
| 492 | - remove_all_actions('wp_head'); |
|
| 493 | - remove_all_actions('wp_footer'); |
|
| 494 | - remove_all_actions('wp_print_footer_scripts'); |
|
| 495 | - remove_all_actions('wp_enqueue_scripts'); |
|
| 496 | - global $wp_scripts, $wp_styles; |
|
| 497 | - $wp_scripts = $wp_styles = []; |
|
| 498 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
| 499 | - add_action('wp_footer', 'wp_print_footer_scripts'); |
|
| 500 | - add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
| 501 | - add_action('wp_head', 'wp_enqueue_scripts'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Overwrite parent _get_main_template for display_html purposes. |
|
| 507 | - * |
|
| 508 | - * @param bool $preview |
|
| 509 | - * @return string |
|
| 510 | - * @since 4.5.0 |
|
| 511 | - */ |
|
| 512 | - protected function _get_main_template($preview = false): string |
|
| 513 | - { |
|
| 514 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
| 515 | - // include message type as a template arg |
|
| 516 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
| 517 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @return void |
|
| 523 | - */ |
|
| 524 | - protected function _preview() |
|
| 525 | - { |
|
| 526 | - $this->_send_message(); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - protected function _set_admin_settings_fields() |
|
| 531 | - { |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * add the "powered by EE" credit link to the HTML receipt and invoice |
|
| 537 | - * |
|
| 538 | - * @param string $content |
|
| 539 | - * @param string $content_again |
|
| 540 | - * @param EE_message_type $incoming_message_type |
|
| 541 | - * @return string |
|
| 542 | - */ |
|
| 543 | - public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
| 544 | - string $content, |
|
| 545 | - string $content_again, |
|
| 546 | - EE_message_type $incoming_message_type |
|
| 547 | - ): string { |
|
| 548 | - if ( |
|
| 549 | - ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
| 550 | - && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
| 551 | - ) { |
|
| 552 | - $content .= EEH_Template::powered_by_event_espresso( |
|
| 553 | - 'aln-cntr', |
|
| 554 | - '', |
|
| 555 | - ['utm_content' => 'messages_system'] |
|
| 556 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
| 557 | - } |
|
| 558 | - return $content; |
|
| 559 | - } |
|
| 15 | + /** |
|
| 16 | + * The following are the properties that this messenger requires for displaying the html |
|
| 17 | + */ |
|
| 18 | + /** |
|
| 19 | + * This is the html body generated by the template via the message type. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $_content = ''; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
| 27 | + * equivalent to the "subject" of the page. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected $_subject = ''; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * EE_Html_messenger constructor. |
|
| 36 | + */ |
|
| 37 | + public function __construct() |
|
| 38 | + { |
|
| 39 | + // set properties |
|
| 40 | + $this->name = 'html'; |
|
| 41 | + $this->description = esc_html__( |
|
| 42 | + 'This messenger outputs a message to a browser for display.', |
|
| 43 | + 'event_espresso' |
|
| 44 | + ); |
|
| 45 | + $this->label = [ |
|
| 46 | + 'singular' => esc_html__('html', 'event_espresso'), |
|
| 47 | + 'plural' => esc_html__('html', 'event_espresso'), |
|
| 48 | + ]; |
|
| 49 | + $this->activate_on_install = true; |
|
| 50 | + // add the "powered by EE" credit link to the HTML receipt and invoice |
|
| 51 | + add_filter( |
|
| 52 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
| 53 | + [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
| 54 | + 10, |
|
| 55 | + 3 |
|
| 56 | + ); |
|
| 57 | + parent::__construct(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * HTML Messenger desires execution immediately. |
|
| 63 | + * |
|
| 64 | + * @return bool |
|
| 65 | + * @since 4.9.0 |
|
| 66 | + * @see parent::send_now() for documentation. |
|
| 67 | + */ |
|
| 68 | + public function send_now(): bool |
|
| 69 | + { |
|
| 70 | + return true; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * HTML Messenger allows an empty to field. |
|
| 76 | + * |
|
| 77 | + * @return bool |
|
| 78 | + * @since 4.9.0 |
|
| 79 | + * @see parent::allow_empty_to_field() for documentation |
|
| 80 | + */ |
|
| 81 | + public function allow_empty_to_field(): bool |
|
| 82 | + { |
|
| 83 | + return true; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @see abstract declaration in EE_messenger for details. |
|
| 89 | + */ |
|
| 90 | + protected function _set_admin_pages() |
|
| 91 | + { |
|
| 92 | + $this->admin_registered_pages = ['events_edit' => true]; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @see abstract declaration in EE_messenger for details. |
|
| 98 | + */ |
|
| 99 | + protected function _set_valid_shortcodes() |
|
| 100 | + { |
|
| 101 | + $this->_valid_shortcodes = []; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @see abstract declaration in EE_messenger for details. |
|
| 107 | + */ |
|
| 108 | + protected function _set_validator_config() |
|
| 109 | + { |
|
| 110 | + $this->_validator_config = [ |
|
| 111 | + 'subject' => [ |
|
| 112 | + 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
| 113 | + ], |
|
| 114 | + 'content' => [ |
|
| 115 | + 'shortcodes' => [ |
|
| 116 | + 'organization', |
|
| 117 | + 'primary_registration_list', |
|
| 118 | + 'primary_registration_details', |
|
| 119 | + 'email', |
|
| 120 | + 'transaction', |
|
| 121 | + 'event_list', |
|
| 122 | + 'payment_list', |
|
| 123 | + 'venue', |
|
| 124 | + 'line_item_list', |
|
| 125 | + 'messenger', |
|
| 126 | + 'ticket_list', |
|
| 127 | + ], |
|
| 128 | + ], |
|
| 129 | + 'event_list' => [ |
|
| 130 | + 'shortcodes' => [ |
|
| 131 | + 'event', |
|
| 132 | + 'ticket_list', |
|
| 133 | + 'venue', |
|
| 134 | + 'primary_registration_details', |
|
| 135 | + 'primary_registration_list', |
|
| 136 | + 'event_author', |
|
| 137 | + ], |
|
| 138 | + 'required' => ['[EVENT_LIST]'], |
|
| 139 | + ], |
|
| 140 | + 'ticket_list' => [ |
|
| 141 | + 'shortcodes' => [ |
|
| 142 | + 'attendee_list', |
|
| 143 | + 'ticket', |
|
| 144 | + 'datetime_list', |
|
| 145 | + 'primary_registration_details', |
|
| 146 | + 'line_item_list', |
|
| 147 | + 'venue', |
|
| 148 | + ], |
|
| 149 | + 'required' => ['[TICKET_LIST]'], |
|
| 150 | + ], |
|
| 151 | + 'ticket_line_item_no_pms' => [ |
|
| 152 | + 'shortcodes' => ['line_item', 'ticket'], |
|
| 153 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 154 | + ], |
|
| 155 | + 'ticket_line_item_pms' => [ |
|
| 156 | + 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
| 157 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 158 | + ], |
|
| 159 | + 'price_modifier_line_item_list' => [ |
|
| 160 | + 'shortcodes' => ['line_item'], |
|
| 161 | + 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
| 162 | + ], |
|
| 163 | + 'datetime_list' => [ |
|
| 164 | + 'shortcodes' => ['datetime'], |
|
| 165 | + 'required' => ['[DATETIME_LIST]'], |
|
| 166 | + ], |
|
| 167 | + 'attendee_list' => [ |
|
| 168 | + 'shortcodes' => ['attendee'], |
|
| 169 | + 'required' => ['[ATTENDEE_LIST]'], |
|
| 170 | + ], |
|
| 171 | + 'tax_line_item_list' => [ |
|
| 172 | + 'shortcodes' => ['line_item'], |
|
| 173 | + 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
| 174 | + ], |
|
| 175 | + 'additional_line_item_list' => [ |
|
| 176 | + 'shortcodes' => ['line_item'], |
|
| 177 | + 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
| 178 | + ], |
|
| 179 | + 'payment_list' => [ |
|
| 180 | + 'shortcodes' => ['payment'], |
|
| 181 | + 'required' => ['[PAYMENT_LIST_*]'], |
|
| 182 | + ], |
|
| 183 | + ]; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
| 189 | + * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
| 190 | + * (i.e. swap out css files or something else). |
|
| 191 | + * |
|
| 192 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
| 193 | + * @return void |
|
| 194 | + * @since 4.5.0 |
|
| 195 | + */ |
|
| 196 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
| 197 | + { |
|
| 198 | + if ($sending_messenger_name === 'pdf') { |
|
| 199 | + add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * @param $variation_path |
|
| 206 | + * @param EE_Messages_Template_Pack $template_pack |
|
| 207 | + * @param $messenger_name |
|
| 208 | + * @param $message_type_name |
|
| 209 | + * @param $url |
|
| 210 | + * @param $type |
|
| 211 | + * @param $variation |
|
| 212 | + * @param $skip_filters |
|
| 213 | + * @return string |
|
| 214 | + */ |
|
| 215 | + public function add_html_css( |
|
| 216 | + $variation_path, |
|
| 217 | + EE_Messages_Template_Pack $template_pack, |
|
| 218 | + $messenger_name, |
|
| 219 | + $message_type_name, |
|
| 220 | + $url, |
|
| 221 | + $type, |
|
| 222 | + $variation, |
|
| 223 | + $skip_filters |
|
| 224 | + ): string { |
|
| 225 | + return $template_pack->get_variation( |
|
| 226 | + $this->name, |
|
| 227 | + $message_type_name, |
|
| 228 | + $type, |
|
| 229 | + $variation, |
|
| 230 | + $url, |
|
| 231 | + '.css', |
|
| 232 | + $skip_filters |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
| 239 | + * messenger can add their own js. |
|
| 240 | + * |
|
| 241 | + * @return void. |
|
| 242 | + */ |
|
| 243 | + public function enqueue_scripts_styles() |
|
| 244 | + { |
|
| 245 | + parent::enqueue_scripts_styles(); |
|
| 246 | + do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * _set_template_fields |
|
| 252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
| 253 | + * |
|
| 254 | + * @access protected |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + protected function _set_template_fields() |
|
| 258 | + { |
|
| 259 | + // any extra template fields that are NOT used by the messenger |
|
| 260 | + // but will get used by a messenger field for shortcode replacement |
|
| 261 | + // get added to the 'extra' key in an associated array |
|
| 262 | + // indexed by the messenger field they relate to. |
|
| 263 | + // This is important for the Messages_admin to know what fields to display to the user. |
|
| 264 | + // Also, notice that the "values" are equal to the field type |
|
| 265 | + // that messages admin will use to know what kind of field to display. |
|
| 266 | + // The values ALSO have one index labeled "shortcode". |
|
| 267 | + // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
| 268 | + // is required in order for this extra field to be displayed. |
|
| 269 | + // If the required shortcode isn't part of the shortcodes array |
|
| 270 | + // then the field is not needed and will not be displayed/parsed. |
|
| 271 | + $this->_template_fields = [ |
|
| 272 | + 'subject' => [ |
|
| 273 | + 'input' => 'text', |
|
| 274 | + 'label' => esc_html__('Page Title', 'event_espresso'), |
|
| 275 | + 'type' => 'string', |
|
| 276 | + 'required' => true, |
|
| 277 | + 'validation' => true, |
|
| 278 | + 'css_class' => 'large-text', |
|
| 279 | + 'format' => '%s', |
|
| 280 | + ], |
|
| 281 | + 'content' => '', |
|
| 282 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
| 283 | + 'extra' => [ |
|
| 284 | + 'content' => [ |
|
| 285 | + 'main' => [ |
|
| 286 | + 'input' => 'wp_editor', |
|
| 287 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
| 288 | + 'type' => 'string', |
|
| 289 | + 'required' => true, |
|
| 290 | + 'validation' => true, |
|
| 291 | + 'format' => '%s', |
|
| 292 | + 'rows' => '15', |
|
| 293 | + ], |
|
| 294 | + 'event_list' => [ |
|
| 295 | + 'input' => 'wp_editor', |
|
| 296 | + 'label' => '[EVENT_LIST]', |
|
| 297 | + 'type' => 'string', |
|
| 298 | + 'required' => true, |
|
| 299 | + 'validation' => true, |
|
| 300 | + 'format' => '%s', |
|
| 301 | + 'rows' => '15', |
|
| 302 | + 'shortcodes_required' => ['[EVENT_LIST]'], |
|
| 303 | + ], |
|
| 304 | + 'ticket_list' => [ |
|
| 305 | + 'input' => 'textarea', |
|
| 306 | + 'label' => '[TICKET_LIST]', |
|
| 307 | + 'type' => 'string', |
|
| 308 | + 'required' => true, |
|
| 309 | + 'validation' => true, |
|
| 310 | + 'format' => '%s', |
|
| 311 | + 'css_class' => 'large-text', |
|
| 312 | + 'rows' => '10', |
|
| 313 | + 'shortcodes_required' => ['[TICKET_LIST]'], |
|
| 314 | + ], |
|
| 315 | + 'ticket_line_item_no_pms' => [ |
|
| 316 | + 'input' => 'textarea', |
|
| 317 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
| 318 | + 'Ticket Line Item List with no Price Modifiers', |
|
| 319 | + 'event_espresso' |
|
| 320 | + ), |
|
| 321 | + 'type' => 'string', |
|
| 322 | + 'required' => false, |
|
| 323 | + 'validation' => true, |
|
| 324 | + 'format' => '%s', |
|
| 325 | + 'css_class' => 'large-text', |
|
| 326 | + 'rows' => '5', |
|
| 327 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 328 | + ], |
|
| 329 | + 'ticket_line_item_pms' => [ |
|
| 330 | + 'input' => 'textarea', |
|
| 331 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
| 332 | + 'Ticket Line Item List with Price Modifiers', |
|
| 333 | + 'event_espresso' |
|
| 334 | + ), |
|
| 335 | + 'type' => 'string', |
|
| 336 | + 'required' => false, |
|
| 337 | + 'validation' => true, |
|
| 338 | + 'format' => '%s', |
|
| 339 | + 'css_class' => 'large-text', |
|
| 340 | + 'rows' => '5', |
|
| 341 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
| 342 | + ], |
|
| 343 | + 'price_modifier_line_item_list' => [ |
|
| 344 | + 'input' => 'textarea', |
|
| 345 | + 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
| 346 | + 'type' => 'string', |
|
| 347 | + 'required' => false, |
|
| 348 | + 'validation' => true, |
|
| 349 | + 'format' => '%s', |
|
| 350 | + 'css_class' => 'large-text', |
|
| 351 | + 'rows' => '5', |
|
| 352 | + 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
| 353 | + ], |
|
| 354 | + 'datetime_list' => [ |
|
| 355 | + 'input' => 'textarea', |
|
| 356 | + 'label' => '[DATETIME_LIST]', |
|
| 357 | + 'type' => 'string', |
|
| 358 | + 'required' => true, |
|
| 359 | + 'validation' => true, |
|
| 360 | + 'format' => '%s', |
|
| 361 | + 'css_class' => 'large-text', |
|
| 362 | + 'rows' => '5', |
|
| 363 | + 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
| 364 | + ], |
|
| 365 | + 'attendee_list' => [ |
|
| 366 | + 'input' => 'textarea', |
|
| 367 | + 'label' => '[ATTENDEE_LIST]', |
|
| 368 | + 'type' => 'string', |
|
| 369 | + 'required' => true, |
|
| 370 | + 'validation' => true, |
|
| 371 | + 'format' => '%s', |
|
| 372 | + 'css_class' => 'large-text', |
|
| 373 | + 'rows' => '5', |
|
| 374 | + 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
| 375 | + ], |
|
| 376 | + 'tax_line_item_list' => [ |
|
| 377 | + 'input' => 'textarea', |
|
| 378 | + 'label' => '[TAX_LINE_ITEM_LIST]', |
|
| 379 | + 'type' => 'string', |
|
| 380 | + 'required' => false, |
|
| 381 | + 'validation' => true, |
|
| 382 | + 'format' => '%s', |
|
| 383 | + 'css_class' => 'large-text', |
|
| 384 | + 'rows' => '5', |
|
| 385 | + 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
| 386 | + ], |
|
| 387 | + 'additional_line_item_list' => [ |
|
| 388 | + 'input' => 'textarea', |
|
| 389 | + 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
| 390 | + 'type' => 'string', |
|
| 391 | + 'required' => false, |
|
| 392 | + 'validation' => true, |
|
| 393 | + 'format' => '%s', |
|
| 394 | + 'css_class' => 'large-text', |
|
| 395 | + 'rows' => '5', |
|
| 396 | + 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
| 397 | + ], |
|
| 398 | + 'payment_list' => [ |
|
| 399 | + 'input' => 'textarea', |
|
| 400 | + 'label' => '[PAYMENT_LIST]', |
|
| 401 | + 'type' => 'string', |
|
| 402 | + 'required' => true, |
|
| 403 | + 'validation' => true, |
|
| 404 | + 'format' => '%s', |
|
| 405 | + 'css_class' => 'large-text', |
|
| 406 | + 'rows' => '5', |
|
| 407 | + 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
| 408 | + ], |
|
| 409 | + ], |
|
| 410 | + ], |
|
| 411 | + ]; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @see definition of this method in parent |
|
| 417 | + * @since 4.5.0 |
|
| 418 | + */ |
|
| 419 | + protected function _set_default_message_types() |
|
| 420 | + { |
|
| 421 | + $this->_default_message_types = ['receipt', 'invoice']; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @see definition of this method in parent |
|
| 427 | + * @since 4.5.0 |
|
| 428 | + */ |
|
| 429 | + protected function _set_valid_message_types() |
|
| 430 | + { |
|
| 431 | + $this->_valid_message_types = ['receipt', 'invoice']; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Displays the message in the browser. |
|
| 437 | + * |
|
| 438 | + * @return void. |
|
| 439 | + * @since 4.5.0 |
|
| 440 | + */ |
|
| 441 | + protected function _send_message() |
|
| 442 | + { |
|
| 443 | + $this->_template_args = [ |
|
| 444 | + 'page_title' => $this->_subject, |
|
| 445 | + 'base_css' => $this->get_variation( |
|
| 446 | + $this->_tmp_pack, |
|
| 447 | + $this->_incoming_message_type->name, |
|
| 448 | + true, |
|
| 449 | + 'base', |
|
| 450 | + $this->_variation |
|
| 451 | + ), |
|
| 452 | + 'print_css' => $this->get_variation( |
|
| 453 | + $this->_tmp_pack, |
|
| 454 | + $this->_incoming_message_type->name, |
|
| 455 | + true, |
|
| 456 | + 'print', |
|
| 457 | + $this->_variation |
|
| 458 | + ), |
|
| 459 | + 'main_css' => $this->get_variation( |
|
| 460 | + $this->_tmp_pack, |
|
| 461 | + $this->_incoming_message_type->name, |
|
| 462 | + true, |
|
| 463 | + 'main', |
|
| 464 | + $this->_variation |
|
| 465 | + ), |
|
| 466 | + 'main_body' => wpautop( |
|
| 467 | + apply_filters( |
|
| 468 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
| 469 | + $this->_content, |
|
| 470 | + $this->_content, |
|
| 471 | + $this->_incoming_message_type |
|
| 472 | + ) |
|
| 473 | + ), |
|
| 474 | + ]; |
|
| 475 | + $this->_deregister_wp_hooks(); |
|
| 476 | + add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
| 477 | + echo '<!doctype html>'.wp_kses($this->_get_main_template(), AllowedTags::getWithFullTags()); |
|
| 478 | + exit(); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
| 484 | + * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
| 485 | + * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
| 486 | + * |
|
| 487 | + * @return void |
|
| 488 | + * @since 4.5.0 |
|
| 489 | + */ |
|
| 490 | + protected function _deregister_wp_hooks() |
|
| 491 | + { |
|
| 492 | + remove_all_actions('wp_head'); |
|
| 493 | + remove_all_actions('wp_footer'); |
|
| 494 | + remove_all_actions('wp_print_footer_scripts'); |
|
| 495 | + remove_all_actions('wp_enqueue_scripts'); |
|
| 496 | + global $wp_scripts, $wp_styles; |
|
| 497 | + $wp_scripts = $wp_styles = []; |
|
| 498 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
| 499 | + add_action('wp_footer', 'wp_print_footer_scripts'); |
|
| 500 | + add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
| 501 | + add_action('wp_head', 'wp_enqueue_scripts'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Overwrite parent _get_main_template for display_html purposes. |
|
| 507 | + * |
|
| 508 | + * @param bool $preview |
|
| 509 | + * @return string |
|
| 510 | + * @since 4.5.0 |
|
| 511 | + */ |
|
| 512 | + protected function _get_main_template($preview = false): string |
|
| 513 | + { |
|
| 514 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
| 515 | + // include message type as a template arg |
|
| 516 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
| 517 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @return void |
|
| 523 | + */ |
|
| 524 | + protected function _preview() |
|
| 525 | + { |
|
| 526 | + $this->_send_message(); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + protected function _set_admin_settings_fields() |
|
| 531 | + { |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * add the "powered by EE" credit link to the HTML receipt and invoice |
|
| 537 | + * |
|
| 538 | + * @param string $content |
|
| 539 | + * @param string $content_again |
|
| 540 | + * @param EE_message_type $incoming_message_type |
|
| 541 | + * @return string |
|
| 542 | + */ |
|
| 543 | + public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
| 544 | + string $content, |
|
| 545 | + string $content_again, |
|
| 546 | + EE_message_type $incoming_message_type |
|
| 547 | + ): string { |
|
| 548 | + if ( |
|
| 549 | + ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
| 550 | + && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
| 551 | + ) { |
|
| 552 | + $content .= EEH_Template::powered_by_event_espresso( |
|
| 553 | + 'aln-cntr', |
|
| 554 | + '', |
|
| 555 | + ['utm_content' => 'messages_system'] |
|
| 556 | + ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
| 557 | + } |
|
| 558 | + return $content; |
|
| 559 | + } |
|
| 560 | 560 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | <?php echo esc_js($eei18n); ?> |
| 37 | 37 | </script> |
| 38 | 38 | <?php foreach ($header_js as $key => $url) :?> |
| 39 | - <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?> |
|
| 39 | + <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?> |
|
| 40 | 40 | <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($header_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script> |
| 41 | 41 | <?php endforeach; ?> |
| 42 | 42 | <?php endif; ?> |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | <?php echo wp_kses($content, AllowedTags::getWithFullTags()); ?> |
| 48 | 48 | </div> |
| 49 | 49 | <?php foreach ($footer_js as $key => $url) : ?> |
| 50 | - <?php $footer_attributes = isset($footer_js_attributes[ $key ]) ? $footer_js_attributes[ $key ] : ''; ?> |
|
| 50 | + <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?> |
|
| 51 | 51 | <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($footer_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script> |
| 52 | 52 | <?php endforeach; ?> |
| 53 | 53 | <?php if ($enqueue_wp_assets) : ?> |
@@ -28,9 +28,12 @@ |
||
| 28 | 28 | <title><?php echo wp_strip_all_tags($title); ?></title> |
| 29 | 29 | <?php if ($enqueue_wp_assets) : ?> |
| 30 | 30 | <?php wp_head(); ?> |
| 31 | - <?php else : ?> |
|
| 31 | + <?php else { |
|
| 32 | + : ?> |
|
| 32 | 33 | <?php foreach ($css as $url) :?> |
| 33 | - <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url); ?>"> |
|
| 34 | + <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url); |
|
| 35 | +} |
|
| 36 | +?>"> |
|
| 34 | 37 | <?php endforeach; ?> |
| 35 | 38 | <script type="text/javascript"> |
| 36 | 39 | <?php echo esc_js($eei18n); ?> |
@@ -8,5 +8,5 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | $gateway_response = $payment->gateway_response(); |
| 10 | 10 | if (! empty($gateway_response)) { |
| 11 | - echo '<span class="error payment-problem">' . esc_html($gateway_response) . '</span>'; |
|
| 11 | + echo '<span class="error payment-problem">' . esc_html($gateway_response) . '</span>'; |
|
| 12 | 12 | } |
@@ -7,6 +7,6 @@ |
||
| 7 | 7 | * @var EE_Payment_Method $payment_method |
| 8 | 8 | */ |
| 9 | 9 | $gateway_response = $payment->gateway_response(); |
| 10 | -if (! empty($gateway_response)) { |
|
| 11 | - echo '<span class="error payment-problem">' . esc_html($gateway_response) . '</span>'; |
|
| 10 | +if ( ! empty($gateway_response)) { |
|
| 11 | + echo '<span class="error payment-problem">'.esc_html($gateway_response).'</span>'; |
|
| 12 | 12 | } |