| @@ -6,15 +6,17 @@ | ||
| 6 | 6 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| 7 | 7 | | | |__| (_) | (_| | __/ | __/| | | (_) | _| | | __/ | | |
| 8 | 8 | | \____\___/ \__,_|\___| |_| |_| \___/|_| |_|_|\___|_| | |
| 9 | 9 | | | |
| 10 | - | (c) Jerome Bruandet ~ https://code-profiler.com/ | | |
| 10 | + | (c) Jerome Bruandet ~ https://nintechnet.com/codeprofiler/ | | |
| 11 | 11 | +=====================================================================+ |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (! defined('ABSPATH') ) { die('Forbidden'); } | |
| 14 | +if (! defined('ABSPATH') ) { | |
| 15 | + die('Forbidden'); | |
| 16 | +} | |
| 15 | 17 | |
| 16 | -// ===================================================================== | |
| 18 | +// ===================================================================== 2023-11-17 | |
| 17 | 19 | // Display Plugins & Theme stats. |
| 18 | 20 | |
| 19 | 21 | $buffer = code_profiler_get_profile_data( $profile_path, 'slugs'); |
| 20 | 22 | if ( isset( $buffer['error'] ) ) { |
| @@ -24,33 +26,36 @@ | ||
| 24 | 26 | // Fetch options |
| 25 | 27 | $cp_options = get_option('code-profiler'); |
| 26 | 28 | |
| 27 | 29 | // Name vs slug |
| 28 | -if ( empty( $cp_options['display_name'] ) || ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) { | |
| 30 | +if ( empty( $cp_options['display_name'] ) || | |
| 31 | + ! in_array( $cp_options['display_name'], ['full', 'slug' ] ) ) { | |
| 32 | + | |
| 29 | 33 | $cp_options['display_name'] = 'full'; |
| 30 | 34 | } |
| 31 | 35 | // Truncate name |
| 32 | -if ( empty( $cp_options['truncate_name'] ) || ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) { | |
| 36 | +if ( empty( $cp_options['truncate_name'] ) || | |
| 37 | + ! preg_match('/^\d+$/', ( $cp_options['truncate_name'] ) ) ) { | |
| 38 | + | |
| 33 | 39 | $cp_options['truncate_name'] = 30; |
| 34 | 40 | } |
| 35 | 41 | // Horizontal vs vertical chart |
| 36 | -if ( empty( $cp_options['chart_type'] ) || ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) { | |
| 42 | +if ( empty( $cp_options['chart_type'] ) || | |
| 43 | + ! in_array( $cp_options['chart_type'], ['x', 'y' ] ) ) { | |
| 44 | + | |
| 37 | 45 | $axis = 'x'; |
| 38 | 46 | } else { |
| 39 | 47 | $axis = $cp_options['chart_type']; |
| 40 | 48 | } |
| 41 | 49 | // Max plugins to display |
| 42 | -if ( empty( $cp_options['chart_max_plugins'] ) || ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) { | |
| 50 | +if ( empty( $cp_options['chart_max_plugins'] ) || | |
| 51 | + ! preg_match('/^\d+$/', ( $cp_options['chart_max_plugins'] ) ) ) { | |
| 52 | + | |
| 43 | 53 | $chart_max_plugins = 25; |
| 44 | 54 | } else { |
| 45 | 55 | $chart_max_plugins = $cp_options['chart_max_plugins']; |
| 46 | 56 | } |
| 47 | 57 | |
| 48 | -// Check if we should warn about composer | |
| 49 | -if (! empty( $cp_options['warn_composer'] ) ) { | |
| 50 | - $composer_warning = code_profiler_composer_warning( $profile_path, $cp_options['display_name'] ); | |
| 51 | -} | |
| 52 | - | |
| 53 | 58 | $label = []; |
| 54 | 59 | $data = ''; |
| 55 | 60 | $theme = esc_attr__('theme', 'code-profiler'); |
| 56 | 61 | $total_time = 0; |
| @@ -111,9 +116,9 @@ | ||
| 111 | 116 | 'use strict'; |
| 112 | 117 | cpjs_plugins_chart( |
| 113 | 118 | '<?php echo esc_js( $axis ) ?>', [<?php |
| 114 | 119 | for( $i = 0; $i < $count; $i++ ) { |
| 115 | - echo "'". addslashes( $label[ $i ] ) ."',"; | |
| 120 | + echo "'". esc_js( $label[ $i ] ) ."',"; | |
| 116 | 121 | } |
| 117 | 122 | echo "'". esc_js( $label[ $i ] ) ."'"; |
| 118 | 123 | ?>], |
| 119 | 124 | [<?php echo esc_js( $data ) ?>], <?php echo esc_js( number_format( $total_time, 4 ) ) ?> |
| @@ -135,9 +140,10 @@ | ||
| 135 | 140 | $sr_data[ $i ] = 0; |
| 136 | 141 | } |
| 137 | 142 | echo "\t<tr>\n\t\t<td>". esc_html( $label[ $i ] ) ."</td>". |
| 138 | 143 | "<td>". esc_html( number_format( $sr_data[ $i ], 3 ) ) ."</td>". |
| 139 | - "<td>". esc_html( number_format( ( $sr_data[ $i ] / $total_time ) * 100 ) ) ."%</td>\n\t</tr>\n"; | |
| 144 | + "<td>". esc_html( number_format( ( $sr_data[ $i ] / $total_time ) * 100 ) ) . | |
| 145 | + "%</td>\n\t</tr>\n"; | |
| 140 | 146 | } |
| 141 | 147 | echo "</table>\n"; |
| 142 | 148 | ?> |
| 143 | 149 | </div> |
| @@ -148,51 +154,6 @@ | ||
| 148 | 154 | $save_png = 1; |
| 149 | 155 | $rotate_img = 1; |
| 150 | 156 | $type = 'slugs'; |
| 151 | 157 | |
| 152 | -// ===================================================================== | |
| 153 | -// Warn if multiple plugins are using composer | |
| 154 | - | |
| 155 | -function code_profiler_composer_warning( $profile_path, $display_name ) { | |
| 156 | - | |
| 157 | - if (! file_exists( "$profile_path.composer.profile" ) ) { | |
| 158 | - return; | |
| 159 | - } | |
| 160 | - $res = json_decode( file_get_contents( "$profile_path.composer.profile" ), true ); | |
| 161 | - // Make sure there are at least two items (free version only) | |
| 162 | - if ( $res === false || count( $res ) < 2 ) { | |
| 163 | - return; | |
| 164 | - } | |
| 165 | - | |
| 166 | - $list = ''; | |
| 167 | - $first = ''; | |
| 168 | - $count = 1; | |
| 169 | - foreach( $res as $slug => $name ) { | |
| 170 | - if ( $display_name == 'full') { | |
| 171 | - $list .= "$count: <strong>". esc_html( $name ) .'</strong>, '; | |
| 172 | - if ( empty( $first ) ) { | |
| 173 | - $first = '<strong>'. esc_html( $name ) .'</strong>'; | |
| 174 | - } | |
| 175 | - } else { | |
| 176 | - $list .= "$count: <strong>". esc_html( $slug ) .'</strong>, '; | |
| 177 | - if ( empty( $first ) ) { | |
| 178 | - $first = '<strong>'. esc_html( $slug ) .'</strong>'; | |
| 179 | - } | |
| 180 | - } | |
| 181 | - $count++; | |
| 182 | - } | |
| 183 | - $list = rtrim( $list, ', ') .'.'; | |
| 184 | - | |
| 185 | - $msg = esc_html__('Code Profiler has detected that the following components, sorted by execution order, are using Composer dependency manager:', 'code-profiler') . "<br />$list<br />". | |
| 186 | - sprintf( | |
| 187 | - esc_html__('As that may increase the execution time of %s, make sure to consult the following FAQ: %s%s%s', 'code-profiler'), | |
| 188 | - $first, | |
| 189 | - '<a href="?page=code-profiler&cptab=faq#composerwarning" target="_blank" rel="noopener noreferrer">', | |
| 190 | - esc_html__('Why does Code Profiler warn me that I have multiple plugins using Composer?', 'code-profiler'), | |
| 191 | - '</a>' | |
| 192 | - ); | |
| 193 | - | |
| 194 | - return '<div class="cp-notice cp-notice-orange"><p>'. $msg .'</p></div>'; | |
| 195 | - | |
| 196 | -} | |
| 197 | 158 | // ===================================================================== |
| 198 | 159 | // EOF |