@@ -35,16 +35,16 @@ discard block |
||
| 35 | 35 | </th> |
| 36 | 36 | <td> |
| 37 | 37 | <?php |
| 38 | - if ($payment_log->object() instanceof EE_Transaction) { |
|
| 39 | - esc_html_e('Unknown', 'event_espresso'); |
|
| 40 | - } else { |
|
| 41 | - echo esc_html( |
|
| 42 | - $payment_method |
|
| 43 | - ? $payment_method->admin_name() |
|
| 44 | - : __("No Longer Exists", 'event_espresso') |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - ?> |
|
| 38 | + if ($payment_log->object() instanceof EE_Transaction) { |
|
| 39 | + esc_html_e('Unknown', 'event_espresso'); |
|
| 40 | + } else { |
|
| 41 | + echo esc_html( |
|
| 42 | + $payment_method |
|
| 43 | + ? $payment_method->admin_name() |
|
| 44 | + : __("No Longer Exists", 'event_espresso') |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + ?> |
|
| 48 | 48 | </td> |
| 49 | 49 | </tr> |
| 50 | 50 | <tr> |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | </th> |
| 56 | 56 | <td> |
| 57 | 57 | <?php echo esc_html( |
| 58 | - $transaction |
|
| 59 | - ? absint($transaction->ID()) |
|
| 60 | - : __('Could not be determined', 'event_espresso') |
|
| 61 | - ); ?> |
|
| 58 | + $transaction |
|
| 59 | + ? absint($transaction->ID()) |
|
| 60 | + : __('Could not be determined', 'event_espresso') |
|
| 61 | + ); ?> |
|
| 62 | 62 | </td> |
| 63 | 63 | </tr> |
| 64 | 64 | <tr> |
@@ -19,38 +19,38 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | function ee_recurse_into_array_for_display($data, $depth = 0, $td = true) |
| 21 | 21 | { |
| 22 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 23 | - // is_object($incomplete_class) actually returns false, hence why we check for it |
|
| 24 | - $data = json_decode(json_encode($data), true); |
|
| 25 | - } |
|
| 26 | - if (empty($data)) { |
|
| 27 | - return; |
|
| 28 | - } |
|
| 29 | - if (is_array($data)) { |
|
| 30 | - $depth++; |
|
| 31 | - ksort($data, SORT_NATURAL | SORT_FLAG_CASE); |
|
| 32 | - if (EEH_Array::is_associative_array($data)) { ?> |
|
| 22 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
| 23 | + // is_object($incomplete_class) actually returns false, hence why we check for it |
|
| 24 | + $data = json_decode(json_encode($data), true); |
|
| 25 | + } |
|
| 26 | + if (empty($data)) { |
|
| 27 | + return; |
|
| 28 | + } |
|
| 29 | + if (is_array($data)) { |
|
| 30 | + $depth++; |
|
| 31 | + ksort($data, SORT_NATURAL | SORT_FLAG_CASE); |
|
| 32 | + if (EEH_Array::is_associative_array($data)) { ?> |
|
| 33 | 33 | <table class='ee-system-stati ee-system-stati-<?php echo absint($depth); ?>'> |
| 34 | 34 | <tbody> |
| 35 | 35 | <?php foreach ($data as $data_key => $data_value) { |
| 36 | - // if the value is a single element array with no key, |
|
| 37 | - // and the value is a primitive (not an array, object, etc.) |
|
| 38 | - if ( |
|
| 39 | - is_array($data_value) |
|
| 40 | - && count($data_value) === 1 |
|
| 41 | - && empty(key($data_value)) |
|
| 42 | - && is_scalar(reset($data_value)) |
|
| 43 | - ) { |
|
| 44 | - ?> |
|
| 36 | + // if the value is a single element array with no key, |
|
| 37 | + // and the value is a primitive (not an array, object, etc.) |
|
| 38 | + if ( |
|
| 39 | + is_array($data_value) |
|
| 40 | + && count($data_value) === 1 |
|
| 41 | + && empty(key($data_value)) |
|
| 42 | + && is_scalar(reset($data_value)) |
|
| 43 | + ) { |
|
| 44 | + ?> |
|
| 45 | 45 | <tr> |
| 46 | 46 | <td class="ee-system-stati-value" colspan="2"> |
| 47 | 47 | <?php echo esc_html(reset($data_value)); ?> |
| 48 | 48 | </td> |
| 49 | 49 | </tr> |
| 50 | 50 | <?php |
| 51 | - continue; |
|
| 52 | - } |
|
| 53 | - ?> |
|
| 51 | + continue; |
|
| 52 | + } |
|
| 53 | + ?> |
|
| 54 | 54 | <tr> |
| 55 | 55 | <td class='ee-system-stati-key'> |
| 56 | 56 | <span class="ee-system-stati-label"> |
@@ -65,31 +65,31 @@ discard block |
||
| 65 | 65 | <?php if (is_scalar($data_value)) { ?> |
| 66 | 66 | <?php ee_recurse_into_array_for_display($data_value, $depth); ?> |
| 67 | 67 | <?php } else { |
| 68 | - if (is_array($data_value) && count($data_value) === 1) { |
|
| 69 | - // verify that values have been set |
|
| 70 | - $keys_only = empty( |
|
| 71 | - array_filter( |
|
| 72 | - array_values($data_value), |
|
| 73 | - function ($v) { |
|
| 74 | - return $v !== null && (is_array($v) || trim($v) !== ''); |
|
| 75 | - } |
|
| 76 | - ) |
|
| 77 | - ); |
|
| 78 | - // if the array only consists of keys (no values) |
|
| 79 | - if ($keys_only) { |
|
| 80 | - // then use keys for values |
|
| 81 | - $data_value = array_keys($data_value); |
|
| 82 | - // but if there is only one value now |
|
| 83 | - if (count($data_value) === 1) { |
|
| 84 | - // then pass that single value back into this function |
|
| 85 | - // this prevents extra empty layers of nothing being added to the output |
|
| 86 | - ee_recurse_into_array_for_display(reset($data_value), $depth); |
|
| 87 | - // need to finish the row off though |
|
| 88 | - echo '</tr>'; |
|
| 89 | - continue; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } ?> |
|
| 68 | + if (is_array($data_value) && count($data_value) === 1) { |
|
| 69 | + // verify that values have been set |
|
| 70 | + $keys_only = empty( |
|
| 71 | + array_filter( |
|
| 72 | + array_values($data_value), |
|
| 73 | + function ($v) { |
|
| 74 | + return $v !== null && (is_array($v) || trim($v) !== ''); |
|
| 75 | + } |
|
| 76 | + ) |
|
| 77 | + ); |
|
| 78 | + // if the array only consists of keys (no values) |
|
| 79 | + if ($keys_only) { |
|
| 80 | + // then use keys for values |
|
| 81 | + $data_value = array_keys($data_value); |
|
| 82 | + // but if there is only one value now |
|
| 83 | + if (count($data_value) === 1) { |
|
| 84 | + // then pass that single value back into this function |
|
| 85 | + // this prevents extra empty layers of nothing being added to the output |
|
| 86 | + ee_recurse_into_array_for_display(reset($data_value), $depth); |
|
| 87 | + // need to finish the row off though |
|
| 88 | + echo '</tr>'; |
|
| 89 | + continue; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } ?> |
|
| 93 | 93 | <td class="ee-system-stati-sub-values"> |
| 94 | 94 | <?php ee_recurse_into_array_for_display($data_value, $depth); ?> |
| 95 | 95 | </td> |
@@ -107,19 +107,19 @@ discard block |
||
| 107 | 107 | <?php } ?> |
| 108 | 108 | </ul> |
| 109 | 109 | <?php } else { |
| 110 | - // there's no key (label) and there's only one value, |
|
| 111 | - // so let's just pass that value back into this function, |
|
| 112 | - // but reset the depth back to where it was. |
|
| 113 | - // this prevents extra empty layers of nothing being added to the output |
|
| 114 | - $depth--; |
|
| 115 | - ee_recurse_into_array_for_display(reset($data), $depth, false); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - echo wp_kses($td ? '<td class="ee-system-stati-value">' : '', AllowedTags::getAllowedTags()); |
|
| 119 | - // simple value |
|
| 120 | - echo wp_kses($data, AllowedTags::getAllowedTags()); |
|
| 121 | - echo wp_kses($td ? '</td>' : '', AllowedTags::getAllowedTags()); |
|
| 122 | - } |
|
| 110 | + // there's no key (label) and there's only one value, |
|
| 111 | + // so let's just pass that value back into this function, |
|
| 112 | + // but reset the depth back to where it was. |
|
| 113 | + // this prevents extra empty layers of nothing being added to the output |
|
| 114 | + $depth--; |
|
| 115 | + ee_recurse_into_array_for_display(reset($data), $depth, false); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + echo wp_kses($td ? '<td class="ee-system-stati-value">' : '', AllowedTags::getAllowedTags()); |
|
| 119 | + // simple value |
|
| 120 | + echo wp_kses($data, AllowedTags::getAllowedTags()); |
|
| 121 | + echo wp_kses($td ? '</td>' : '', AllowedTags::getAllowedTags()); |
|
| 122 | + } |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | ?> |
@@ -37,55 +37,55 @@ discard block |
||
| 37 | 37 | <h3 class="espresso-header"> |
| 38 | 38 | <span class="dashicons dashicons-flag ee-icon-size-22"></span> |
| 39 | 39 | <?php |
| 40 | - echo esc_html( |
|
| 41 | - apply_filters( |
|
| 42 | - 'FHEE__ee_migration_page__header', |
|
| 43 | - sprintf( |
|
| 44 | - __("Your Event Espresso data needs to be updated.", "event_espresso"), |
|
| 45 | - $current_db_state, |
|
| 46 | - $next_db_state |
|
| 47 | - ), |
|
| 48 | - $current_db_state, |
|
| 49 | - $next_db_state |
|
| 50 | - ) |
|
| 51 | - ); |
|
| 52 | - ?> |
|
| 40 | + echo esc_html( |
|
| 41 | + apply_filters( |
|
| 42 | + 'FHEE__ee_migration_page__header', |
|
| 43 | + sprintf( |
|
| 44 | + __("Your Event Espresso data needs to be updated.", "event_espresso"), |
|
| 45 | + $current_db_state, |
|
| 46 | + $next_db_state |
|
| 47 | + ), |
|
| 48 | + $current_db_state, |
|
| 49 | + $next_db_state |
|
| 50 | + ) |
|
| 51 | + ); |
|
| 52 | + ?> |
|
| 53 | 53 | </h3> |
| 54 | 54 | <?php } elseif ($show_most_recent_migration) { ?> |
| 55 | 55 | <h3 class="espresso-header"> |
| 56 | 56 | <span class="dashicons dashicons-awards ee-icon-size-22"></span> |
| 57 | 57 | <?php echo esc_html( |
| 58 | - apply_filters( |
|
| 59 | - 'FHEE__ee_migration_page__done_migration_header', |
|
| 60 | - sprintf( |
|
| 61 | - __( |
|
| 62 | - 'Congratulations! Your database is "up-to-date" and you are ready to begin using %s', |
|
| 63 | - "event_espresso" |
|
| 64 | - ), |
|
| 65 | - $ultimate_db_state |
|
| 66 | - ) |
|
| 67 | - ) |
|
| 68 | - ); ?> |
|
| 58 | + apply_filters( |
|
| 59 | + 'FHEE__ee_migration_page__done_migration_header', |
|
| 60 | + sprintf( |
|
| 61 | + __( |
|
| 62 | + 'Congratulations! Your database is "up-to-date" and you are ready to begin using %s', |
|
| 63 | + "event_espresso" |
|
| 64 | + ), |
|
| 65 | + $ultimate_db_state |
|
| 66 | + ) |
|
| 67 | + ) |
|
| 68 | + ); ?> |
|
| 69 | 69 | </h3> |
| 70 | 70 | <p> |
| 71 | 71 | <?php echo esc_html( |
| 72 | - apply_filters( |
|
| 73 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 74 | - sprintf( |
|
| 75 | - __( |
|
| 76 | - "Time to find out about all the great new features %s has to offer.", |
|
| 77 | - "event_espresso" |
|
| 78 | - ), |
|
| 79 | - $ultimate_db_state |
|
| 80 | - ) |
|
| 81 | - ) |
|
| 82 | - ); ?> |
|
| 72 | + apply_filters( |
|
| 73 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
| 74 | + sprintf( |
|
| 75 | + __( |
|
| 76 | + "Time to find out about all the great new features %s has to offer.", |
|
| 77 | + "event_espresso" |
|
| 78 | + ), |
|
| 79 | + $ultimate_db_state |
|
| 80 | + ) |
|
| 81 | + ) |
|
| 82 | + ); ?> |
|
| 83 | 83 | <b> |
| 84 | 84 | <a class="button-primary" |
| 85 | 85 | id='get-started-after-migrate' |
| 86 | 86 | href="<?php |
| 87 | - echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php'))); |
|
| 88 | - ?>" |
|
| 87 | + echo esc_url_raw(add_query_arg(['page' => 'espresso_about'], admin_url('admin.php'))); |
|
| 88 | + ?>" |
|
| 89 | 89 | > |
| 90 | 90 | <?php esc_html_e("Let's Get Started", "event_espresso"); ?> |
| 91 | 91 | <span class="dashicons dashicons-arrow-right ee-icon-size-22" style="margin:0;"></span> |
@@ -96,46 +96,46 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | <?php |
| 99 | - if ($show_backup_db_text) { |
|
| 100 | - echo wp_kses($migration_options_html, AllowedTags::getAllowedTags()); |
|
| 101 | - } ?> |
|
| 99 | + if ($show_backup_db_text) { |
|
| 100 | + echo wp_kses($migration_options_html, AllowedTags::getAllowedTags()); |
|
| 101 | + } ?> |
|
| 102 | 102 | |
| 103 | 103 | <?php |
| 104 | - if ($show_most_recent_migration) { |
|
| 105 | - if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) { |
|
| 106 | - if ($most_recent_migration->can_continue()) { |
|
| 107 | - // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> |
|
| 104 | + if ($show_most_recent_migration) { |
|
| 105 | + if ($most_recent_migration instanceof EE_Data_Migration_Script_Base) { |
|
| 106 | + if ($most_recent_migration->can_continue()) { |
|
| 107 | + // tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?> |
|
| 108 | 108 | <h3 class="espresso-header"> |
| 109 | 109 | <span class="dashicons dashicons-star-half ee-icon-size-22"></span> |
| 110 | 110 | <?php printf( |
| 111 | - esc_html__( |
|
| 112 | - "It appears that your previous Database Update (%s) is incomplete, and should be resumed", |
|
| 113 | - "event_espresso" |
|
| 114 | - ), |
|
| 115 | - $most_recent_migration->pretty_name() |
|
| 116 | - ); ?> |
|
| 111 | + esc_html__( |
|
| 112 | + "It appears that your previous Database Update (%s) is incomplete, and should be resumed", |
|
| 113 | + "event_espresso" |
|
| 114 | + ), |
|
| 115 | + $most_recent_migration->pretty_name() |
|
| 116 | + ); ?> |
|
| 117 | 117 | </h3> |
| 118 | 118 | <?php |
| 119 | - } elseif ($most_recent_migration->is_broken()) { |
|
| 120 | - // tell the user the migration failed, and they should notify EE?> |
|
| 119 | + } elseif ($most_recent_migration->is_broken()) { |
|
| 120 | + // tell the user the migration failed, and they should notify EE?> |
|
| 121 | 121 | <h3 class="espresso-header"> |
| 122 | 122 | <span class="dashicons dashicons-no ee-icon-size-22"></span> |
| 123 | 123 | <?php echo esc_html($most_recent_migration->get_feedback_message()) ?> |
| 124 | 124 | </h3> |
| 125 | 125 | <?php |
| 126 | - } |
|
| 127 | - // display errors or not of the most recent migration ran |
|
| 128 | - if ($most_recent_migration->get_errors()) { |
|
| 129 | - ?> |
|
| 126 | + } |
|
| 127 | + // display errors or not of the most recent migration ran |
|
| 128 | + if ($most_recent_migration->get_errors()) { |
|
| 129 | + ?> |
|
| 130 | 130 | <div class="ee-attention"> |
| 131 | 131 | <strong> |
| 132 | 132 | <?php printf( |
| 133 | - esc_html__( |
|
| 134 | - "Warnings occurred during your last Database Update (%s):", |
|
| 135 | - 'event_espresso' |
|
| 136 | - ), |
|
| 137 | - $most_recent_migration->pretty_name() |
|
| 138 | - ); ?> |
|
| 133 | + esc_html__( |
|
| 134 | + "Warnings occurred during your last Database Update (%s):", |
|
| 135 | + 'event_espresso' |
|
| 136 | + ), |
|
| 137 | + $most_recent_migration->pretty_name() |
|
| 138 | + ); ?> |
|
| 139 | 139 | </strong> |
| 140 | 140 | <a id="show-hide-migration-warnings" class="display-the-hidden"> |
| 141 | 141 | <?php esc_html_e("Show Warnings", 'event_espresso'); ?> |
@@ -147,32 +147,32 @@ discard block |
||
| 147 | 147 | </ul> |
| 148 | 148 | </div> |
| 149 | 149 | <?php |
| 150 | - } else { |
|
| 151 | - // there were no errors during the last migration, just say so?> |
|
| 150 | + } else { |
|
| 151 | + // there were no errors during the last migration, just say so?> |
|
| 152 | 152 | <h2> |
| 153 | 153 | <?php printf( |
| 154 | - esc_html__( |
|
| 155 | - "The last Database Update (%s) ran successfully without errors.", |
|
| 156 | - "event_espresso" |
|
| 157 | - ), |
|
| 158 | - $most_recent_migration->pretty_name() |
|
| 159 | - ); ?> |
|
| 154 | + esc_html__( |
|
| 155 | + "The last Database Update (%s) ran successfully without errors.", |
|
| 156 | + "event_espresso" |
|
| 157 | + ), |
|
| 158 | + $most_recent_migration->pretty_name() |
|
| 159 | + ); ?> |
|
| 160 | 160 | </h2> |
| 161 | 161 | <?php |
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - // end of: if ( $show_most_recent_migration ) |
|
| 166 | - ?> |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + // end of: if ( $show_most_recent_migration ) |
|
| 166 | + ?> |
|
| 167 | 167 | |
| 168 | 168 | </div> |
| 169 | 169 | <!--end of #migration-prep--> |
| 170 | 170 | |
| 171 | 171 | <?php |
| 172 | - if ($show_migration_progress) { ?> |
|
| 172 | + if ($show_migration_progress) { ?> |
|
| 173 | 173 | <div id='migration-monitor' <?php if ($show_backup_db_text) : ?>style="display:none"<?php endif; ?>> |
| 174 | 174 | <?php |
| 175 | - if ($show_backup_db_text) { ?> |
|
| 175 | + if ($show_backup_db_text) { ?> |
|
| 176 | 176 | <p> |
| 177 | 177 | <a class="toggle-migration-monitor small-text" style="cursor: pointer;"> |
| 178 | 178 | <span class="dashicons dashicons-arrow-left-alt2" style="top:0;"></span> |
@@ -182,19 +182,19 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | </p> |
| 184 | 184 | <?php |
| 185 | - } ?> |
|
| 185 | + } ?> |
|
| 186 | 186 | <div id='progress-area'> |
| 187 | 187 | <h3 class="espresso-header"> |
| 188 | 188 | <?php |
| 189 | - echo sprintf( |
|
| 190 | - _n( |
|
| 191 | - "The following task needs to be performed:", |
|
| 192 | - "The following %s tasks need to be performed:", |
|
| 193 | - count($script_names), |
|
| 194 | - "event_espresso" |
|
| 195 | - ), |
|
| 196 | - count($script_names) |
|
| 197 | - ); ?> |
|
| 189 | + echo sprintf( |
|
| 190 | + _n( |
|
| 191 | + "The following task needs to be performed:", |
|
| 192 | + "The following %s tasks need to be performed:", |
|
| 193 | + count($script_names), |
|
| 194 | + "event_espresso" |
|
| 195 | + ), |
|
| 196 | + count($script_names) |
|
| 197 | + ); ?> |
|
| 198 | 198 | </h3> |
| 199 | 199 | <ul style="list-style: inside;"> |
| 200 | 200 | <?php foreach ($script_names as $script_name) { ?> |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | <?php if (count($script_names) > 1) { ?> |
| 206 | 206 | <p> |
| 207 | 207 | <?php esc_html_e( |
| 208 | - "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", |
|
| 209 | - "event_espresso" |
|
| 210 | - ); ?> |
|
| 208 | + "Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.", |
|
| 209 | + "event_espresso" |
|
| 210 | + ); ?> |
|
| 211 | 211 | </p> |
| 212 | 212 | <?php } ?> |
| 213 | 213 | |
@@ -218,19 +218,19 @@ discard block |
||
| 218 | 218 | </span> |
| 219 | 219 | <br /> |
| 220 | 220 | <?php esc_html_e( |
| 221 | - "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", |
|
| 222 | - "event_espresso" |
|
| 223 | - ); ?> |
|
| 221 | + "Depending on the number of events and the complexity of the information in your database, this could take a few minutes.", |
|
| 222 | + "event_espresso" |
|
| 223 | + ); ?> |
|
| 224 | 224 | </p> |
| 225 | 225 | <p> |
| 226 | 226 | <?php printf( |
| 227 | - esc_html__( |
|
| 228 | - "%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.", |
|
| 229 | - "event_espresso" |
|
| 230 | - ), |
|
| 231 | - '<strong>', |
|
| 232 | - '</strong>' |
|
| 233 | - ); ?> |
|
| 227 | + esc_html__( |
|
| 228 | + "%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.", |
|
| 229 | + "event_espresso" |
|
| 230 | + ), |
|
| 231 | + '<strong>', |
|
| 232 | + '</strong>' |
|
| 233 | + ); ?> |
|
| 234 | 234 | </p> |
| 235 | 235 | <p> |
| 236 | 236 | <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?> |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | <button id='start-migration' class='button-primary'> |
| 248 | 248 | <?php echo esc_html( |
| 249 | - $show_continue_current_migration_script |
|
| 250 | - ? __("Continue Database Update", "event_espresso") |
|
| 251 | - : __("Begin Database Update", "event_espresso") |
|
| 252 | - ); ?> |
|
| 249 | + $show_continue_current_migration_script |
|
| 250 | + ? __("Continue Database Update", "event_espresso") |
|
| 251 | + : __("Begin Database Update", "event_espresso") |
|
| 252 | + ); ?> |
|
| 253 | 253 | </button> |
| 254 | 254 | <br class="clear" /> |
| 255 | 255 | |
@@ -265,9 +265,9 @@ discard block |
||
| 265 | 265 | </div> |
| 266 | 266 | |
| 267 | 267 | <?php |
| 268 | - } |
|
| 269 | - if ($show_maintenance_switch) { |
|
| 270 | - ?> |
|
| 268 | + } |
|
| 269 | + if ($show_maintenance_switch) { |
|
| 270 | + ?> |
|
| 271 | 271 | <h2> |
| 272 | 272 | <span class="dashicons dashicons-admin-tools"></span> |
| 273 | 273 | <?php esc_html_e('Set Event Espresso Maintenance Mode', 'event_espresso'); ?> |
@@ -282,11 +282,11 @@ discard block |
||
| 282 | 282 | type='radio' |
| 283 | 283 | value="0" |
| 284 | 284 | <?php echo esc_attr( |
| 285 | - $mMode_level === EE_Maintenance_Mode::level_0_not_in_maintenance |
|
| 286 | - ? 'checked' |
|
| 287 | - : '' |
|
| 288 | - ); |
|
| 289 | - ?> |
|
| 285 | + $mMode_level === EE_Maintenance_Mode::level_0_not_in_maintenance |
|
| 286 | + ? 'checked' |
|
| 287 | + : '' |
|
| 288 | + ); |
|
| 289 | + ?> |
|
| 290 | 290 | /> |
| 291 | 291 | </td> |
| 292 | 292 | <th align="left"> |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | </label> |
| 296 | 296 | <p class='description' style="font-weight: normal;"> |
| 297 | 297 | <?php esc_html_e( |
| 298 | - "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", |
|
| 299 | - "event_espresso" |
|
| 300 | - ); ?> |
|
| 298 | + "This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.", |
|
| 299 | + "event_espresso" |
|
| 300 | + ); ?> |
|
| 301 | 301 | </p> |
| 302 | 302 | </th> |
| 303 | 303 | </tr> |
@@ -308,11 +308,11 @@ discard block |
||
| 308 | 308 | type='radio' |
| 309 | 309 | value="1" |
| 310 | 310 | <?php echo esc_attr( |
| 311 | - $mMode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance |
|
| 312 | - ? 'checked' |
|
| 313 | - : '' |
|
| 314 | - ); |
|
| 315 | - ?> |
|
| 311 | + $mMode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance |
|
| 312 | + ? 'checked' |
|
| 313 | + : '' |
|
| 314 | + ); |
|
| 315 | + ?> |
|
| 316 | 316 | /> |
| 317 | 317 | </td> |
| 318 | 318 | <th align="left"> |
@@ -321,9 +321,9 @@ discard block |
||
| 321 | 321 | </label> |
| 322 | 322 | <p class='description' style="font-weight: normal;"> |
| 323 | 323 | <?php esc_html_e( |
| 324 | - "This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.", |
|
| 325 | - "event_espresso" |
|
| 326 | - ); ?> |
|
| 324 | + "This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.", |
|
| 325 | + "event_espresso" |
|
| 326 | + ); ?> |
|
| 327 | 327 | </p> |
| 328 | 328 | </th> |
| 329 | 329 | </tr> |
@@ -337,6 +337,6 @@ discard block |
||
| 337 | 337 | </p> |
| 338 | 338 | </form> |
| 339 | 339 | <?php |
| 340 | - } ?> |
|
| 340 | + } ?> |
|
| 341 | 341 | |
| 342 | 342 | </div> |
@@ -18,28 +18,28 @@ |
||
| 18 | 18 | <?php esc_html_e('Select from Venue Manager List', 'event_espresso'); ?> |
| 19 | 19 | </label> |
| 20 | 20 | <?php |
| 21 | - echo wp_kses($venue_selector, AllowedTags::getWithFormTags()); |
|
| 22 | - echo wp_kses($new_venue_link, AllowedTags::getWithFormTags()); |
|
| 23 | - foreach ($venues as $venue) : |
|
| 24 | - if (! $venue instanceof EE_Venue) { |
|
| 25 | - continue; |
|
| 26 | - } |
|
| 27 | - $selected = $evt_venue_id === $venue->ID() ? 'ee-venue-selected' : 'ee-venue-not-selected'; |
|
| 28 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 29 | - ['action' => 'edit', 'post' => $venue->ID()], |
|
| 30 | - EE_VENUES_ADMIN_URL |
|
| 31 | - ); |
|
| 32 | - $state_name = is_object($venue->state_obj()) ? $venue->state_obj()->name() : null; |
|
| 33 | - $country_name = is_object($venue->country_obj()) ? $venue->country_obj()->name() : null; |
|
| 34 | - ?> |
|
| 21 | + echo wp_kses($venue_selector, AllowedTags::getWithFormTags()); |
|
| 22 | + echo wp_kses($new_venue_link, AllowedTags::getWithFormTags()); |
|
| 23 | + foreach ($venues as $venue) : |
|
| 24 | + if (! $venue instanceof EE_Venue) { |
|
| 25 | + continue; |
|
| 26 | + } |
|
| 27 | + $selected = $evt_venue_id === $venue->ID() ? 'ee-venue-selected' : 'ee-venue-not-selected'; |
|
| 28 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 29 | + ['action' => 'edit', 'post' => $venue->ID()], |
|
| 30 | + EE_VENUES_ADMIN_URL |
|
| 31 | + ); |
|
| 32 | + $state_name = is_object($venue->state_obj()) ? $venue->state_obj()->name() : null; |
|
| 33 | + $country_name = is_object($venue->country_obj()) ? $venue->country_obj()->name() : null; |
|
| 34 | + ?> |
|
| 35 | 35 | <div class='eebox <?php echo sanitize_html_class($selected); ?>' id="eebox_<?php echo absint($venue->ID()); ?>"> |
| 36 | 36 | <p class='address-view'> |
| 37 | 37 | <span><?php esc_html_e('Address:', 'event_espresso'); ?> </span> |
| 38 | 38 | <?php echo esc_html($venue->address()); ?> |
| 39 | 39 | <?php echo wp_kses( |
| 40 | - $venue->address2() ? '<br />' . $venue->address2() : '', |
|
| 41 | - AllowedTags::getAllowedTags() |
|
| 42 | - ); ?> |
|
| 40 | + $venue->address2() ? '<br />' . $venue->address2() : '', |
|
| 41 | + AllowedTags::getAllowedTags() |
|
| 42 | + ); ?> |
|
| 43 | 43 | <br /> |
| 44 | 44 | <span><?php esc_html_e('City:', 'event_espresso'); ?> </span> |
| 45 | 45 | <?php echo esc_html($venue->city()); ?> |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | echo wp_kses($venue_selector, AllowedTags::getWithFormTags()); |
| 22 | 22 | echo wp_kses($new_venue_link, AllowedTags::getWithFormTags()); |
| 23 | 23 | foreach ($venues as $venue) : |
| 24 | - if (! $venue instanceof EE_Venue) { |
|
| 24 | + if ( ! $venue instanceof EE_Venue) { |
|
| 25 | 25 | continue; |
| 26 | 26 | } |
| 27 | 27 | $selected = $evt_venue_id === $venue->ID() ? 'ee-venue-selected' : 'ee-venue-not-selected'; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | <span><?php esc_html_e('Address:', 'event_espresso'); ?> </span> |
| 38 | 38 | <?php echo esc_html($venue->address()); ?> |
| 39 | 39 | <?php echo wp_kses( |
| 40 | - $venue->address2() ? '<br />' . $venue->address2() : '', |
|
| 40 | + $venue->address2() ? '<br />'.$venue->address2() : '', |
|
| 41 | 41 | AllowedTags::getAllowedTags() |
| 42 | 42 | ); ?> |
| 43 | 43 | <br /> |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | maxlength='245' |
| 81 | 81 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_name]" |
| 82 | 82 | placeholder="<?php |
| 83 | - esc_html_e('Ticket Title', 'event_espresso') ?>" |
|
| 83 | + esc_html_e('Ticket Title', 'event_espresso') ?>" |
|
| 84 | 84 | value="<?php echo esc_attr($TKT_name); ?>" |
| 85 | 85 | /> |
| 86 | 86 | </td> |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); ?>' |
| 327 | 327 | > |
| 328 | 328 | <?php |
| 329 | - esc_html_e('Ticket Uses', 'event_espresso') ?> |
|
| 329 | + esc_html_e('Ticket Uses', 'event_espresso') ?> |
|
| 330 | 330 | </label> |
| 331 | 331 | <input type="text" |
| 332 | 332 | class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | /> |
| 346 | 346 | <label class='screen-reader-text' for='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
| 347 | 347 | <?php |
| 348 | - esc_html_e('Minimum Quantity', 'event_espresso') ?> |
|
| 348 | + esc_html_e('Minimum Quantity', 'event_espresso') ?> |
|
| 349 | 349 | </label> |
| 350 | 350 | <input type="text" disabled |
| 351 | 351 | class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" |
@@ -407,14 +407,14 @@ discard block |
||
| 407 | 407 | id="edit-ticket-TKT_required-<?php echo esc_attr($tkt_row); ?>" |
| 408 | 408 | value="1" |
| 409 | 409 | <?php |
| 410 | - echo esc_attr($TKT_required ? ' checked' : ''); |
|
| 411 | - echo esc_attr($disabled ? ' disabled' : ''); |
|
| 412 | - ?> |
|
| 410 | + echo esc_attr($TKT_required ? ' checked' : ''); |
|
| 411 | + echo esc_attr($disabled ? ' disabled' : ''); |
|
| 412 | + ?> |
|
| 413 | 413 | /> |
| 414 | 414 | <?php esc_html_e( |
| 415 | - 'This ticket is required (will appear first in frontend ticket lists).', |
|
| 416 | - 'event_espresso' |
|
| 417 | - ); ?> |
|
| 415 | + 'This ticket is required (will appear first in frontend ticket lists).', |
|
| 416 | + 'event_espresso' |
|
| 417 | + ); ?> |
|
| 418 | 418 | </label> |
| 419 | 419 | </div> |
| 420 | 420 | <div class="ticket-is-taxable-container"> |
@@ -517,36 +517,36 @@ discard block |
||
| 517 | 517 | <h4 class="tickets-heading"><?php esc_html_e('Event Datetimes', 'event_espresso'); ?></h4> |
| 518 | 518 | <p> |
| 519 | 519 | <?php esc_html_e( |
| 520 | - 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
| 521 | - 'event_espresso' |
|
| 522 | - ); ?> |
|
| 520 | + 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
| 521 | + 'event_espresso' |
|
| 522 | + ); ?> |
|
| 523 | 523 | </p> |
| 524 | 524 | <ul class="datetime-tickets-list"> |
| 525 | 525 | <?php echo wp_kses($ticket_datetimes_list, AllowedTags::getWithFormTags()); ?> |
| 526 | 526 | </ul> |
| 527 | 527 | |
| 528 | 528 | <?php do_action( |
| 529 | - 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
| 530 | - $tkt_row, |
|
| 531 | - $TKT_ID |
|
| 532 | - ); ?> |
|
| 529 | + 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
| 530 | + $tkt_row, |
|
| 531 | + $TKT_ID |
|
| 532 | + ); ?> |
|
| 533 | 533 | <div class="ee-editor-footer-container"> |
| 534 | 534 | <div class="ee-editor-id-container"> |
| 535 | 535 | <span class="ee-item-id"> |
| 536 | 536 | <?php |
| 537 | - echo esc_html( |
|
| 538 | - $TKT_ID |
|
| 539 | - ? sprintf(__('Ticket ID: %d', 'event_espresso'), $TKT_ID) |
|
| 540 | - : '' |
|
| 541 | - ); ?> |
|
| 537 | + echo esc_html( |
|
| 538 | + $TKT_ID |
|
| 539 | + ? sprintf(__('Ticket ID: %d', 'event_espresso'), $TKT_ID) |
|
| 540 | + : '' |
|
| 541 | + ); ?> |
|
| 542 | 542 | </span> |
| 543 | 543 | </div> |
| 544 | 544 | <div class="save-cancel-button-container"> |
| 545 | 545 | <label for="edit-ticket-TKT_is_default_selector-<?php echo esc_attr($tkt_row); ?>"> |
| 546 | 546 | <?php esc_html_e( |
| 547 | - 'use this new ticket as a default ticket for any new events', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ); ?> |
|
| 547 | + 'use this new ticket as a default ticket for any new events', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ); ?> |
|
| 550 | 550 | <input type="checkbox" |
| 551 | 551 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_is_default_selector]" |
| 552 | 552 | class="edit-ticket-TKT_is_default_selector" |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | placeholder="Datetime Description (optional)"><?php echo esc_textarea($DTT_description); ?></textarea> |
| 26 | 26 | </div> |
| 27 | 27 | <?php do_action( |
| 28 | - 'AHEE__event_tickets_datetime_attached_tickets_row_template__advanced_details_after_dtt_description', |
|
| 29 | - $dtt_row, |
|
| 30 | - $DTT_ID |
|
| 31 | - ); ?> |
|
| 28 | + 'AHEE__event_tickets_datetime_attached_tickets_row_template__advanced_details_after_dtt_description', |
|
| 29 | + $dtt_row, |
|
| 30 | + $DTT_ID |
|
| 31 | + ); ?> |
|
| 32 | 32 | <h4 class="datetime-tickets-heading"><?php esc_html_e('Assigned Tickets', 'event_espresso'); ?></h4> |
| 33 | 33 | |
| 34 | 34 | <ul class="datetime-tickets-list"> |
@@ -38,28 +38,28 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | <div class="add-datetime-ticket-container"> |
| 40 | 40 | <h4 class="datetime-tickets-heading"><?php |
| 41 | - esc_html_e( |
|
| 42 | - 'Add New Ticket', |
|
| 43 | - 'event_espresso' |
|
| 44 | - ); ?></h4><?php echo wp_kses($add_new_datetime_ticket_help_link, AllowedTags::getAllowedTags()); ?><br> |
|
| 41 | + esc_html_e( |
|
| 42 | + 'Add New Ticket', |
|
| 43 | + 'event_espresso' |
|
| 44 | + ); ?></h4><?php echo wp_kses($add_new_datetime_ticket_help_link, AllowedTags::getAllowedTags()); ?><br> |
|
| 45 | 45 | <table class="add-new-ticket-table"> |
| 46 | 46 | <thead> |
| 47 | 47 | <tr valign="top"> |
| 48 | 48 | <td><span class="ANT_TKT_name_label"><?php |
| 49 | - esc_html_e( |
|
| 50 | - 'Ticket Name', |
|
| 51 | - 'event_espresso' |
|
| 52 | - ); ?></span></td> |
|
| 49 | + esc_html_e( |
|
| 50 | + 'Ticket Name', |
|
| 51 | + 'event_espresso' |
|
| 52 | + ); ?></span></td> |
|
| 53 | 53 | <td><span class="ANT_TKT_goes_on_sale_label"><?php |
| 54 | - esc_html_e( |
|
| 55 | - 'Sale Starts', |
|
| 56 | - 'event_espresso' |
|
| 57 | - ); ?></span></td> |
|
| 54 | + esc_html_e( |
|
| 55 | + 'Sale Starts', |
|
| 56 | + 'event_espresso' |
|
| 57 | + ); ?></span></td> |
|
| 58 | 58 | <td><span class="ANT_TKT_sell_until_label"><?php |
| 59 | - esc_html_e( |
|
| 60 | - 'Sell Until', |
|
| 61 | - 'event_espresso' |
|
| 62 | - ); ?></span></td> |
|
| 59 | + esc_html_e( |
|
| 60 | + 'Sell Until', |
|
| 61 | + 'event_espresso' |
|
| 62 | + ); ?></span></td> |
|
| 63 | 63 | <td><span class="ANT_TKT_price_label"><?php esc_html_e('Price', 'event_espresso'); ?></span> |
| 64 | 64 | </td> |
| 65 | 65 | <td><span class="ANT_TKT_qty_label"><?php esc_html_e('Qty', 'event_espresso'); ?></span></td> |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | <div class="ee-editor-id-container"> |
| 111 | 111 | <span class="ee-item-id"> |
| 112 | 112 | <?php |
| 113 | - echo esc_html( |
|
| 114 | - $DTT_ID |
|
| 115 | - ? sprintf( |
|
| 116 | - __('Datetime ID: %d', 'event_espresso'), |
|
| 117 | - $DTT_ID |
|
| 118 | - ) |
|
| 119 | - : '' |
|
| 120 | - ); |
|
| 121 | - ?> |
|
| 113 | + echo esc_html( |
|
| 114 | + $DTT_ID |
|
| 115 | + ? sprintf( |
|
| 116 | + __('Datetime ID: %d', 'event_espresso'), |
|
| 117 | + $DTT_ID |
|
| 118 | + ) |
|
| 119 | + : '' |
|
| 120 | + ); |
|
| 121 | + ?> |
|
| 122 | 122 | </span> |
| 123 | 123 | </div> |
| 124 | 124 | <div class="save-cancel-button-container"> |
@@ -12,290 +12,290 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class AllowedTags |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array[] |
|
| 17 | - */ |
|
| 18 | - private static $attributes = [ |
|
| 19 | - 'accept-charset' => 1, |
|
| 20 | - 'action' => 1, |
|
| 21 | - 'alt' => 1, |
|
| 22 | - 'allow' => 1, |
|
| 23 | - 'allowfullscreen' => 1, |
|
| 24 | - 'align' => 1, |
|
| 25 | - 'aria-*' => 1, |
|
| 26 | - 'autocomplete' => 1, |
|
| 27 | - 'bgcolor' => 1, |
|
| 28 | - 'border' => 1, |
|
| 29 | - 'cellpadding' => 1, |
|
| 30 | - 'cellspacing' => 1, |
|
| 31 | - 'checked' => 1, |
|
| 32 | - 'class' => 1, |
|
| 33 | - 'cols' => 1, |
|
| 34 | - 'content' => 1, |
|
| 35 | - 'data-*' => 1, |
|
| 36 | - 'dir' => 1, |
|
| 37 | - 'disabled' => 1, |
|
| 38 | - 'enctype' => 1, |
|
| 39 | - 'extension' => 1, |
|
| 40 | - 'for' => 1, |
|
| 41 | - 'frameborder' => 1, |
|
| 42 | - 'height' => 1, |
|
| 43 | - 'href' => 1, |
|
| 44 | - 'id' => 1, |
|
| 45 | - 'itemprop' => 1, |
|
| 46 | - 'itemscope' => 1, |
|
| 47 | - 'itemtype' => 1, |
|
| 48 | - 'label' => 1, |
|
| 49 | - 'lang' => 1, |
|
| 50 | - 'leftmargin' => 1, |
|
| 51 | - 'marginheight' => 1, |
|
| 52 | - 'marginwidth' => 1, |
|
| 53 | - 'max' => 1, |
|
| 54 | - 'maxlength' => 1, |
|
| 55 | - 'media' => 1, |
|
| 56 | - 'method' => 1, |
|
| 57 | - 'min' => 1, |
|
| 58 | - 'multiple' => 1, |
|
| 59 | - 'name' => 1, |
|
| 60 | - 'novalidate' => 1, |
|
| 61 | - 'onclick' => 1, |
|
| 62 | - 'placeholder' => 1, |
|
| 63 | - 'property' => 1, |
|
| 64 | - 'readonly' => 1, |
|
| 65 | - 'rel' => 1, |
|
| 66 | - 'required' => 1, |
|
| 67 | - 'rows' => 1, |
|
| 68 | - 'selected' => 1, |
|
| 69 | - 'src' => 1, |
|
| 70 | - 'size' => 1, |
|
| 71 | - 'style' => 1, |
|
| 72 | - 'step' => 1, |
|
| 73 | - 'tabindex' => 1, |
|
| 74 | - 'target' => 1, |
|
| 75 | - 'title' => 1, |
|
| 76 | - 'topmargin' => 1, |
|
| 77 | - 'type' => 1, |
|
| 78 | - 'value' => 1, |
|
| 79 | - 'width' => 1, |
|
| 80 | - 'http-equiv' => 1, |
|
| 81 | - ]; |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - private static $tags = [ |
|
| 88 | - 'a', |
|
| 89 | - 'abbr', |
|
| 90 | - 'b', |
|
| 91 | - 'br', |
|
| 92 | - 'code', |
|
| 93 | - 'div', |
|
| 94 | - 'em', |
|
| 95 | - 'h1', |
|
| 96 | - 'h2', |
|
| 97 | - 'h3', |
|
| 98 | - 'h4', |
|
| 99 | - 'h5', |
|
| 100 | - 'h6', |
|
| 101 | - 'hr', |
|
| 102 | - 'i', |
|
| 103 | - 'img', |
|
| 104 | - 'li', |
|
| 105 | - 'ol', |
|
| 106 | - 'p', |
|
| 107 | - 'pre', |
|
| 108 | - 'small', |
|
| 109 | - 'span', |
|
| 110 | - 'strong', |
|
| 111 | - 'table', |
|
| 112 | - 'td', |
|
| 113 | - 'tr', |
|
| 114 | - 'ul', |
|
| 115 | - ]; |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @var array |
|
| 120 | - */ |
|
| 121 | - private static $allowed_tags; |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - private static $allowed_with_embed_tags; |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var array |
|
| 132 | - */ |
|
| 133 | - private static $allowed_with_form_tags; |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @var array |
|
| 138 | - */ |
|
| 139 | - private static $allowed_with_script_and_style_tags; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @var array |
|
| 143 | - */ |
|
| 144 | - private static $allowed_with_full_tags; |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * merges additional tags and attributes into the WP post tags |
|
| 149 | - */ |
|
| 150 | - private static function initializeAllowedTags() |
|
| 151 | - { |
|
| 152 | - $allowed_post_tags = wp_kses_allowed_html('post'); |
|
| 153 | - $allowed_tags = []; |
|
| 154 | - foreach (AllowedTags::$tags as $tag) { |
|
| 155 | - $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
| 156 | - } |
|
| 157 | - AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * merges embed tags and attributes into the EE all tags |
|
| 163 | - */ |
|
| 164 | - private static function initializeWithEmbedTags() |
|
| 165 | - { |
|
| 166 | - $all_tags = AllowedTags::getAllowedTags(); |
|
| 167 | - $embed_tags = [ |
|
| 168 | - 'iframe' => AllowedTags::$attributes |
|
| 169 | - ]; |
|
| 170 | - AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * merges form tags and attributes into the EE all tags |
|
| 176 | - */ |
|
| 177 | - private static function initializeWithFormTags() |
|
| 178 | - { |
|
| 179 | - $all_tags = AllowedTags::getAllowedTags(); |
|
| 180 | - $form_tags = [ |
|
| 181 | - 'form' => AllowedTags::$attributes, |
|
| 182 | - 'label' => AllowedTags::$attributes, |
|
| 183 | - 'input' => AllowedTags::$attributes, |
|
| 184 | - 'select' => AllowedTags::$attributes, |
|
| 185 | - 'option' => AllowedTags::$attributes, |
|
| 186 | - 'optgroup' => AllowedTags::$attributes, |
|
| 187 | - 'textarea' => AllowedTags::$attributes, |
|
| 188 | - 'button' => AllowedTags::$attributes, |
|
| 189 | - 'fieldset' => AllowedTags::$attributes, |
|
| 190 | - 'output' => AllowedTags::$attributes, |
|
| 191 | - ]; |
|
| 192 | - AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * merges form script and style tags and attributes into the EE all tags |
|
| 198 | - */ |
|
| 199 | - private static function initializeWithScriptAndStyleTags() |
|
| 200 | - { |
|
| 201 | - $all_tags = AllowedTags::getAllowedTags(); |
|
| 202 | - $script_and_style_tags = [ |
|
| 203 | - 'script' => AllowedTags::$attributes, |
|
| 204 | - 'style' => AllowedTags::$attributes, |
|
| 205 | - 'link' => AllowedTags::$attributes, |
|
| 206 | - 'noscript' => AllowedTags::$attributes, |
|
| 207 | - ]; |
|
| 208 | - AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * merges all head and body tags and attributes into the EE all tags |
|
| 213 | - */ |
|
| 214 | - private static function initializeWithFullTags() |
|
| 215 | - { |
|
| 216 | - $all_tags = AllowedTags::getAllowedTags(); |
|
| 217 | - $full_tags = [ |
|
| 218 | - 'script' => AllowedTags::$attributes, |
|
| 219 | - 'style' => AllowedTags::$attributes, |
|
| 220 | - 'link' => AllowedTags::$attributes, |
|
| 221 | - 'title' => AllowedTags::$attributes, |
|
| 222 | - 'meta' => AllowedTags::$attributes, |
|
| 223 | - 'iframe' => AllowedTags::$attributes, |
|
| 224 | - 'form' => AllowedTags::$attributes, |
|
| 225 | - 'label' => AllowedTags::$attributes, |
|
| 226 | - 'input' => AllowedTags::$attributes, |
|
| 227 | - 'select' => AllowedTags::$attributes, |
|
| 228 | - 'option' => AllowedTags::$attributes, |
|
| 229 | - 'optgroup' => AllowedTags::$attributes, |
|
| 230 | - 'textarea' => AllowedTags::$attributes, |
|
| 231 | - 'button' => AllowedTags::$attributes, |
|
| 232 | - 'fieldset' => AllowedTags::$attributes, |
|
| 233 | - 'output' => AllowedTags::$attributes, |
|
| 234 | - 'noscript' => AllowedTags::$attributes, |
|
| 235 | - 'html' => AllowedTags::$attributes, |
|
| 236 | - 'body' => AllowedTags::$attributes, |
|
| 237 | - 'head' => AllowedTags::$attributes, |
|
| 238 | - ]; |
|
| 239 | - AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @return array[] |
|
| 245 | - */ |
|
| 246 | - public static function getAllowedTags() |
|
| 247 | - { |
|
| 248 | - if (empty(AllowedTags::$allowed_tags)) { |
|
| 249 | - AllowedTags::initializeAllowedTags(); |
|
| 250 | - } |
|
| 251 | - return AllowedTags::$allowed_tags; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @return array[] |
|
| 257 | - */ |
|
| 258 | - public static function getWithEmbedTags() |
|
| 259 | - { |
|
| 260 | - if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
| 261 | - AllowedTags::initializeWithEmbedTags(); |
|
| 262 | - } |
|
| 263 | - return AllowedTags::$allowed_with_embed_tags; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return array[] |
|
| 269 | - */ |
|
| 270 | - public static function getWithFormTags() |
|
| 271 | - { |
|
| 272 | - if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
| 273 | - AllowedTags::initializeWithFormTags(); |
|
| 274 | - } |
|
| 275 | - return AllowedTags::$allowed_with_form_tags; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return array[] |
|
| 281 | - */ |
|
| 282 | - public static function getWithScriptAndStyleTags() |
|
| 283 | - { |
|
| 284 | - if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
| 285 | - AllowedTags::initializeWithScriptAndStyleTags(); |
|
| 286 | - } |
|
| 287 | - return AllowedTags::$allowed_with_script_and_style_tags; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * @return array[] |
|
| 293 | - */ |
|
| 294 | - public static function getWithFullTags() |
|
| 295 | - { |
|
| 296 | - if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
| 297 | - AllowedTags::initializeWithFullTags(); |
|
| 298 | - } |
|
| 299 | - return AllowedTags::$allowed_with_full_tags; |
|
| 300 | - } |
|
| 15 | + /** |
|
| 16 | + * @var array[] |
|
| 17 | + */ |
|
| 18 | + private static $attributes = [ |
|
| 19 | + 'accept-charset' => 1, |
|
| 20 | + 'action' => 1, |
|
| 21 | + 'alt' => 1, |
|
| 22 | + 'allow' => 1, |
|
| 23 | + 'allowfullscreen' => 1, |
|
| 24 | + 'align' => 1, |
|
| 25 | + 'aria-*' => 1, |
|
| 26 | + 'autocomplete' => 1, |
|
| 27 | + 'bgcolor' => 1, |
|
| 28 | + 'border' => 1, |
|
| 29 | + 'cellpadding' => 1, |
|
| 30 | + 'cellspacing' => 1, |
|
| 31 | + 'checked' => 1, |
|
| 32 | + 'class' => 1, |
|
| 33 | + 'cols' => 1, |
|
| 34 | + 'content' => 1, |
|
| 35 | + 'data-*' => 1, |
|
| 36 | + 'dir' => 1, |
|
| 37 | + 'disabled' => 1, |
|
| 38 | + 'enctype' => 1, |
|
| 39 | + 'extension' => 1, |
|
| 40 | + 'for' => 1, |
|
| 41 | + 'frameborder' => 1, |
|
| 42 | + 'height' => 1, |
|
| 43 | + 'href' => 1, |
|
| 44 | + 'id' => 1, |
|
| 45 | + 'itemprop' => 1, |
|
| 46 | + 'itemscope' => 1, |
|
| 47 | + 'itemtype' => 1, |
|
| 48 | + 'label' => 1, |
|
| 49 | + 'lang' => 1, |
|
| 50 | + 'leftmargin' => 1, |
|
| 51 | + 'marginheight' => 1, |
|
| 52 | + 'marginwidth' => 1, |
|
| 53 | + 'max' => 1, |
|
| 54 | + 'maxlength' => 1, |
|
| 55 | + 'media' => 1, |
|
| 56 | + 'method' => 1, |
|
| 57 | + 'min' => 1, |
|
| 58 | + 'multiple' => 1, |
|
| 59 | + 'name' => 1, |
|
| 60 | + 'novalidate' => 1, |
|
| 61 | + 'onclick' => 1, |
|
| 62 | + 'placeholder' => 1, |
|
| 63 | + 'property' => 1, |
|
| 64 | + 'readonly' => 1, |
|
| 65 | + 'rel' => 1, |
|
| 66 | + 'required' => 1, |
|
| 67 | + 'rows' => 1, |
|
| 68 | + 'selected' => 1, |
|
| 69 | + 'src' => 1, |
|
| 70 | + 'size' => 1, |
|
| 71 | + 'style' => 1, |
|
| 72 | + 'step' => 1, |
|
| 73 | + 'tabindex' => 1, |
|
| 74 | + 'target' => 1, |
|
| 75 | + 'title' => 1, |
|
| 76 | + 'topmargin' => 1, |
|
| 77 | + 'type' => 1, |
|
| 78 | + 'value' => 1, |
|
| 79 | + 'width' => 1, |
|
| 80 | + 'http-equiv' => 1, |
|
| 81 | + ]; |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + private static $tags = [ |
|
| 88 | + 'a', |
|
| 89 | + 'abbr', |
|
| 90 | + 'b', |
|
| 91 | + 'br', |
|
| 92 | + 'code', |
|
| 93 | + 'div', |
|
| 94 | + 'em', |
|
| 95 | + 'h1', |
|
| 96 | + 'h2', |
|
| 97 | + 'h3', |
|
| 98 | + 'h4', |
|
| 99 | + 'h5', |
|
| 100 | + 'h6', |
|
| 101 | + 'hr', |
|
| 102 | + 'i', |
|
| 103 | + 'img', |
|
| 104 | + 'li', |
|
| 105 | + 'ol', |
|
| 106 | + 'p', |
|
| 107 | + 'pre', |
|
| 108 | + 'small', |
|
| 109 | + 'span', |
|
| 110 | + 'strong', |
|
| 111 | + 'table', |
|
| 112 | + 'td', |
|
| 113 | + 'tr', |
|
| 114 | + 'ul', |
|
| 115 | + ]; |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @var array |
|
| 120 | + */ |
|
| 121 | + private static $allowed_tags; |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + private static $allowed_with_embed_tags; |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var array |
|
| 132 | + */ |
|
| 133 | + private static $allowed_with_form_tags; |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @var array |
|
| 138 | + */ |
|
| 139 | + private static $allowed_with_script_and_style_tags; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @var array |
|
| 143 | + */ |
|
| 144 | + private static $allowed_with_full_tags; |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * merges additional tags and attributes into the WP post tags |
|
| 149 | + */ |
|
| 150 | + private static function initializeAllowedTags() |
|
| 151 | + { |
|
| 152 | + $allowed_post_tags = wp_kses_allowed_html('post'); |
|
| 153 | + $allowed_tags = []; |
|
| 154 | + foreach (AllowedTags::$tags as $tag) { |
|
| 155 | + $allowed_tags[ $tag ] = AllowedTags::$attributes; |
|
| 156 | + } |
|
| 157 | + AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * merges embed tags and attributes into the EE all tags |
|
| 163 | + */ |
|
| 164 | + private static function initializeWithEmbedTags() |
|
| 165 | + { |
|
| 166 | + $all_tags = AllowedTags::getAllowedTags(); |
|
| 167 | + $embed_tags = [ |
|
| 168 | + 'iframe' => AllowedTags::$attributes |
|
| 169 | + ]; |
|
| 170 | + AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * merges form tags and attributes into the EE all tags |
|
| 176 | + */ |
|
| 177 | + private static function initializeWithFormTags() |
|
| 178 | + { |
|
| 179 | + $all_tags = AllowedTags::getAllowedTags(); |
|
| 180 | + $form_tags = [ |
|
| 181 | + 'form' => AllowedTags::$attributes, |
|
| 182 | + 'label' => AllowedTags::$attributes, |
|
| 183 | + 'input' => AllowedTags::$attributes, |
|
| 184 | + 'select' => AllowedTags::$attributes, |
|
| 185 | + 'option' => AllowedTags::$attributes, |
|
| 186 | + 'optgroup' => AllowedTags::$attributes, |
|
| 187 | + 'textarea' => AllowedTags::$attributes, |
|
| 188 | + 'button' => AllowedTags::$attributes, |
|
| 189 | + 'fieldset' => AllowedTags::$attributes, |
|
| 190 | + 'output' => AllowedTags::$attributes, |
|
| 191 | + ]; |
|
| 192 | + AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * merges form script and style tags and attributes into the EE all tags |
|
| 198 | + */ |
|
| 199 | + private static function initializeWithScriptAndStyleTags() |
|
| 200 | + { |
|
| 201 | + $all_tags = AllowedTags::getAllowedTags(); |
|
| 202 | + $script_and_style_tags = [ |
|
| 203 | + 'script' => AllowedTags::$attributes, |
|
| 204 | + 'style' => AllowedTags::$attributes, |
|
| 205 | + 'link' => AllowedTags::$attributes, |
|
| 206 | + 'noscript' => AllowedTags::$attributes, |
|
| 207 | + ]; |
|
| 208 | + AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * merges all head and body tags and attributes into the EE all tags |
|
| 213 | + */ |
|
| 214 | + private static function initializeWithFullTags() |
|
| 215 | + { |
|
| 216 | + $all_tags = AllowedTags::getAllowedTags(); |
|
| 217 | + $full_tags = [ |
|
| 218 | + 'script' => AllowedTags::$attributes, |
|
| 219 | + 'style' => AllowedTags::$attributes, |
|
| 220 | + 'link' => AllowedTags::$attributes, |
|
| 221 | + 'title' => AllowedTags::$attributes, |
|
| 222 | + 'meta' => AllowedTags::$attributes, |
|
| 223 | + 'iframe' => AllowedTags::$attributes, |
|
| 224 | + 'form' => AllowedTags::$attributes, |
|
| 225 | + 'label' => AllowedTags::$attributes, |
|
| 226 | + 'input' => AllowedTags::$attributes, |
|
| 227 | + 'select' => AllowedTags::$attributes, |
|
| 228 | + 'option' => AllowedTags::$attributes, |
|
| 229 | + 'optgroup' => AllowedTags::$attributes, |
|
| 230 | + 'textarea' => AllowedTags::$attributes, |
|
| 231 | + 'button' => AllowedTags::$attributes, |
|
| 232 | + 'fieldset' => AllowedTags::$attributes, |
|
| 233 | + 'output' => AllowedTags::$attributes, |
|
| 234 | + 'noscript' => AllowedTags::$attributes, |
|
| 235 | + 'html' => AllowedTags::$attributes, |
|
| 236 | + 'body' => AllowedTags::$attributes, |
|
| 237 | + 'head' => AllowedTags::$attributes, |
|
| 238 | + ]; |
|
| 239 | + AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @return array[] |
|
| 245 | + */ |
|
| 246 | + public static function getAllowedTags() |
|
| 247 | + { |
|
| 248 | + if (empty(AllowedTags::$allowed_tags)) { |
|
| 249 | + AllowedTags::initializeAllowedTags(); |
|
| 250 | + } |
|
| 251 | + return AllowedTags::$allowed_tags; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @return array[] |
|
| 257 | + */ |
|
| 258 | + public static function getWithEmbedTags() |
|
| 259 | + { |
|
| 260 | + if (empty(AllowedTags::$allowed_with_embed_tags)) { |
|
| 261 | + AllowedTags::initializeWithEmbedTags(); |
|
| 262 | + } |
|
| 263 | + return AllowedTags::$allowed_with_embed_tags; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return array[] |
|
| 269 | + */ |
|
| 270 | + public static function getWithFormTags() |
|
| 271 | + { |
|
| 272 | + if (empty(AllowedTags::$allowed_with_form_tags)) { |
|
| 273 | + AllowedTags::initializeWithFormTags(); |
|
| 274 | + } |
|
| 275 | + return AllowedTags::$allowed_with_form_tags; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return array[] |
|
| 281 | + */ |
|
| 282 | + public static function getWithScriptAndStyleTags() |
|
| 283 | + { |
|
| 284 | + if (empty(AllowedTags::$allowed_with_script_and_style_tags)) { |
|
| 285 | + AllowedTags::initializeWithScriptAndStyleTags(); |
|
| 286 | + } |
|
| 287 | + return AllowedTags::$allowed_with_script_and_style_tags; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * @return array[] |
|
| 293 | + */ |
|
| 294 | + public static function getWithFullTags() |
|
| 295 | + { |
|
| 296 | + if (empty(AllowedTags::$allowed_with_full_tags)) { |
|
| 297 | + AllowedTags::initializeWithFullTags(); |
|
| 298 | + } |
|
| 299 | + return AllowedTags::$allowed_with_full_tags; |
|
| 300 | + } |
|
| 301 | 301 | } |
@@ -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 | } |