| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -/* | |
| 2 | +/** | |
| 3 | 3 | +=====================================================================+ |
| 4 | 4 | | ____ _ ____ __ _ _ | |
| 5 | 5 | | / ___|___ __| | ___ | _ \ _ __ ___ / _(_) | ___ _ __ | |
| 6 | 6 | | | | / _ \ / _` |/ _ \ | |_) | '__/ _ \| |_| | |/ _ \ '__| | |
| @@ -6,9 +6,9 @@ | ||
| 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 | 14 | if (! defined('ABSPATH') ) { |
| @@ -29,9 +29,10 @@ | ||
| 29 | 29 | ]; |
| 30 | 30 | private $abspath; |
| 31 | 31 | private $row_count = 0; |
| 32 | 32 | |
| 33 | - /******************************************************************** | |
| 33 | + | |
| 34 | + /** | |
| 34 | 35 | * Initialize |
| 35 | 36 | */ |
| 36 | 37 | function __construct() { |
| 37 | 38 | |
| @@ -36,23 +37,26 @@ | ||
| 36 | 37 | function __construct() { |
| 37 | 38 | |
| 38 | 39 | $this->abspath = rtrim( ABSPATH, '/\\'); |
| 39 | 40 | |
| 40 | - parent::__construct( array( | |
| 41 | + parent::__construct( [ | |
| 41 | 42 | 'singular' => esc_html__('profile', 'code-profiler'), |
| 42 | 43 | 'plural' => esc_html__('profiles', 'code-profiler'), |
| 43 | 44 | 'ajax' => false |
| 44 | - )); | |
| 45 | + ] ); | |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | - /******************************************************************** | |
| 48 | + | |
| 49 | + /** | |
| 48 | 50 | * Empty list |
| 49 | 51 | */ |
| 50 | 52 | function no_items() { |
| 51 | 53 | esc_html_e('No profile found.', 'code-profiler'); |
| 54 | + $this->is_empty = 1; | |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | - /******************************************************************** | |
| 57 | + | |
| 58 | + /** | |
| 55 | 59 | * Default |
| 56 | 60 | */ |
| 57 | 61 | function column_default( $item, $column_name ) { |
| 58 | 62 | |
| @@ -61,9 +65,14 @@ | ||
| 61 | 65 | return $item[ $column_name ]; |
| 62 | 66 | } |
| 63 | 67 | switch( $column_name ) { |
| 64 | 68 | case 'date': |
| 65 | - return date('Y/m/d \@ H:i', $item[ $column_name ] ); | |
| 69 | + return sprintf( | |
| 70 | + /* translators: This is already translated in WordPress core */ | |
| 71 | + __('%1$s at %2$s'), | |
| 72 | + date('Y/m/d', $item[ $column_name ] ) .'<br />', | |
| 73 | + date('g:i a', $item[ $column_name ] ) | |
| 74 | + ); | |
| 66 | 75 | break; |
| 67 | 76 | case 'time': |
| 68 | 77 | return $item[ $column_name ] .' s'; |
| 69 | 78 | break; |
| @@ -79,28 +88,30 @@ | ||
| 79 | 88 | return ''; |
| 80 | 89 | } |
| 81 | 90 | } |
| 82 | 91 | |
| 83 | - /******************************************************************** | |
| 92 | + | |
| 93 | + /** | |
| 84 | 94 | * Sortable columns |
| 85 | 95 | */ |
| 86 | 96 | function get_sortable_columns() { |
| 87 | - return array( | |
| 88 | - 'profile' => array( 'profile', true ), | |
| 89 | - 'date' => array( 'date', true ), | |
| 90 | - 'items' => array( 'items', true ), | |
| 91 | - 'time' => array( 'time', true ), | |
| 92 | - 'mem' => array( 'mem', true ), | |
| 93 | - 'io' => array( 'io', true ), | |
| 94 | - 'queries' => array( 'queries', true ) | |
| 95 | - ); | |
| 97 | + return [ | |
| 98 | + 'profile' => ['profile', true ], | |
| 99 | + 'date' => ['date', true ], | |
| 100 | + 'items' => ['items', true ], | |
| 101 | + 'time' => ['time', true ], | |
| 102 | + 'mem' => ['mem', true ], | |
| 103 | + 'io' => ['io', true ], | |
| 104 | + 'queries' => ['queries', true ] | |
| 105 | + ]; | |
| 96 | 106 | } |
| 97 | 107 | |
| 98 | - /******************************************************************** | |
| 108 | + | |
| 109 | + /** | |
| 99 | 110 | * Columns |
| 100 | 111 | */ |
| 101 | 112 | function get_columns(){ |
| 102 | - return array( | |
| 113 | + return [ | |
| 103 | 114 | 'cb' => '<input type="checkbox" />', |
| 104 | 115 | 'profile' => esc_html__( 'Profile', 'code-profiler' ), |
| 105 | 116 | 'date' => esc_html__( 'Date', 'code-profiler' ), |
| 106 | 117 | 'items' => esc_html__( 'Items', 'code-profiler' ), |
| @@ -107,12 +118,13 @@ | ||
| 107 | 118 | 'time' => esc_html__( 'Time', 'code-profiler' ), |
| 108 | 119 | 'mem' => esc_html__( 'Memory', 'code-profiler' ), |
| 109 | 120 | 'io' => esc_html__( 'File I/O', 'code-profiler' ), |
| 110 | 121 | 'queries' => esc_html__( 'SQL', 'code-profiler' ) |
| 111 | - ); | |
| 122 | + ]; | |
| 112 | 123 | } |
| 113 | 124 | |
| 114 | - /******************************************************************** | |
| 125 | + | |
| 126 | + /** | |
| 115 | 127 | * Sorting |
| 116 | 128 | */ |
| 117 | 129 | function usort_reorder( $a, $b ) { |
| 118 | 130 | // Sort by date by default |
| @@ -121,9 +133,10 @@ | ||
| 121 | 133 | $result = $this->cmp_num_or_string( $a[$orderby], $b[$orderby] ); |
| 122 | 134 | return ( $order === 'asc') ? $result : -$result; |
| 123 | 135 | } |
| 124 | 136 | |
| 125 | - /******************************************************************** | |
| 137 | + | |
| 138 | + /** | |
| 126 | 139 | * Sort string and numeric values differently |
| 127 | 140 | */ |
| 128 | 141 | function cmp_num_or_string( $a, $b ) { |
| 129 | 142 | if ( is_numeric( $a ) && is_numeric( $b ) ) { |
| @@ -133,9 +146,9 @@ | ||
| 133 | 146 | } |
| 134 | 147 | } |
| 135 | 148 | |
| 136 | 149 | |
| 137 | - /******************************************************************** | |
| 150 | + /** | |
| 138 | 151 | * Row action links |
| 139 | 152 | */ |
| 140 | 153 | function column_profile( $item ) { |
| 141 | 154 | |
| @@ -173,11 +186,11 @@ | ||
| 173 | 186 | '<div id="profile_name_%1$s">%2$s</div>'. |
| 174 | 187 | '<div id="profile_div_%1$s" style="display:none">'. |
| 175 | 188 | '<input type="text" id="edit-%1$s" name="edit_%3$s" value="" maxlength="100" />'. |
| 176 | 189 | '<p>'. |
| 177 | - '<input type="button" class="button-primary button button-small" value="%4$s" onClick="cpjs_edit_name(\'%3$s\', \'%1$s\', \'%6$s\', \'%1$s\')"/>'. | |
| 190 | + '<input type="button" class="button button-primary button-small" value="%4$s" onClick="cpjs_edit_name(\'%3$s\', \'%1$s\', \'%6$s\', \'%1$s\')"/>'. | |
| 178 | 191 | ' '. |
| 179 | - '<input type="button" class="button-secondary button button-small" value="%5$s" onClick="cpjs_toggle_name(\'%1$s\')"/>'. | |
| 192 | + '<input type="button" class="button button-secondary button-small" value="%5$s" onClick="cpjs_toggle_name(\'%1$s\')"/>'. | |
| 180 | 193 | ' '. |
| 181 | 194 | '<span id="profile_spinner_%1$s" class="spinner" style="float:none"></span>'. |
| 182 | 195 | '</p>'. |
| 183 | 196 | '</div>', |
| @@ -191,9 +204,10 @@ | ||
| 191 | 204 | |
| 192 | 205 | return sprintf('%1$s %2$s', $profile_name, $this->row_actions( $actions ) ); |
| 193 | 206 | } |
| 194 | 207 | |
| 195 | - /******************************************************************** | |
| 208 | + | |
| 209 | + /** | |
| 196 | 210 | * Bulk action menu (delete) |
| 197 | 211 | */ |
| 198 | 212 | function get_bulk_actions() { |
| 199 | 213 | return [ |
| @@ -200,9 +214,10 @@ | ||
| 200 | 214 | 'delete_profiles' => esc_html__('Delete') |
| 201 | 215 | ]; |
| 202 | 216 | } |
| 203 | 217 | |
| 204 | - /******************************************************************** | |
| 218 | + | |
| 219 | + /** | |
| 205 | 220 | * Checkboxes |
| 206 | 221 | */ |
| 207 | 222 | function column_cb($item) { |
| 208 | 223 | return sprintf( |
| @@ -210,9 +225,10 @@ | ||
| 210 | 225 | esc_attr( $item['ID'] ) |
| 211 | 226 | ); |
| 212 | 227 | } |
| 213 | 228 | |
| 214 | - /******************************************************************** | |
| 229 | + | |
| 230 | + /** | |
| 215 | 231 | * Prepare to display profiles |
| 216 | 232 | */ |
| 217 | 233 | function prepare_items() { |
| 218 | 234 | $columns = $this->get_columns(); |
| @@ -241,15 +257,16 @@ | ||
| 241 | 257 | 'per_page' => $per_page |
| 242 | 258 | )); |
| 243 | 259 | } |
| 244 | 260 | |
| 245 | - /******************************************************************** | |
| 261 | + | |
| 262 | + /** | |
| 246 | 263 | * Retrieve all profiles |
| 247 | 264 | */ |
| 248 | 265 | function fetch_profiles() { |
| 249 | 266 | |
| 250 | 267 | $profiles = []; |
| 251 | - $glob = glob( CODE_PROFILER_UPLOAD_DIR .'/*.slugs.profile'); | |
| 268 | + $glob = code_profiler_glob( CODE_PROFILER_UPLOAD_DIR, '\.slugs\.profile$', true ); | |
| 252 | 269 | |
| 253 | 270 | if ( is_array( $glob ) ) { |
| 254 | 271 | $count = 0; |
| 255 | 272 | foreach( $glob as $path ) { |
| @@ -324,9 +341,10 @@ | ||
| 324 | 341 | } |
| 325 | 342 | return $profiles; |
| 326 | 343 | } |
| 327 | 344 | |
| 328 | - /******************************************************************** | |
| 345 | + | |
| 346 | + /** | |
| 329 | 347 | * Search a profile file for a string. |
| 330 | 348 | */ |
| 331 | 349 | private function search_profile_file( $file, $string ) { |
| 332 | 350 | |
| @@ -352,9 +370,10 @@ | ||
| 352 | 370 | fclose( $fh ); |
| 353 | 371 | return false; |
| 354 | 372 | } |
| 355 | 373 | |
| 356 | - /******************************************************************** | |
| 374 | + | |
| 375 | + /** | |
| 357 | 376 | * Delete one or more profiles. |
| 358 | 377 | */ |
| 359 | 378 | public function delete_profiles( $profiles ) { |
| 360 | 379 | |