| @@ -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' ) ) { die( 'Forbidden' ); } |
| @@ -61,15 +61,38 @@ | ||
| 61 | 61 | } else { |
| 62 | 62 | $this->resource = fopen( $path, $mode, $options ); |
| 63 | 63 | } |
| 64 | 64 | self::start(); |
| 65 | - if ( in_array( $mode, ['rb', 'rt', 'r']) && "{$path[-4]}{$path[-3]}{$path[-2]}{$path[-1]}" == '.php') { | |
| 66 | - $this->script = 1; | |
| 65 | + | |
| 66 | + if ( version_compare( PHP_VERSION, '8.0', '<') ) { | |
| 67 | + if ( in_array( $mode, ['rb', 'rt', 'r']) && | |
| 68 | + "{$path[-4]}{$path[-3]}{$path[-2]}{$path[-1]}" == '.php') { | |
| 69 | + | |
| 70 | + $this->script = $this->check_exclusions( $path ); | |
| 71 | + } | |
| 72 | + } else { | |
| 73 | + if ( str_ends_with( $path, '.php') && in_array( $mode, ['rb', 'rt', 'r']) ) { | |
| 74 | + $this->script = $this->check_exclusions( $path ); | |
| 75 | + } | |
| 67 | 76 | } |
| 77 | + | |
| 68 | 78 | return $this->resource !== false; |
| 69 | 79 | } |
| 70 | 80 | |
| 71 | 81 | /** |
| 82 | + * Check file and folder exclusions. | |
| 83 | + */ | |
| 84 | + private function check_exclusions( $path ) { | |
| 85 | + | |
| 86 | + foreach( CodeProfiler_Profiler::$exclusions as $item ) { | |
| 87 | + if ( $item && strpos( $path, $item ) !== false ) { | |
| 88 | + return; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + return 1; | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 72 | 95 | * Close a resource |
| 73 | 96 | */ |
| 74 | 97 | public function stream_close() { |
| 75 | 98 | self::$io_stats['close']++; |
| @@ -316,14 +339,18 @@ | ||
| 316 | 339 | if ( ftell( $this->resource ) == 0 ) { |
| 317 | 340 | self::start(); |
| 318 | 341 | $read = fread( $this->resource, $count - CODE_PROFILER_LENGTH ); |
| 319 | 342 | self::$io_read += strlen( $read ); |
| 320 | - return preg_replace( | |
| 321 | - '/<\?php/i', | |
| 322 | - '<?php declare(ticks='. CODE_PROFILER_TICKS .');', | |
| 323 | - $read, | |
| 324 | - 1 | |
| 325 | - ); | |
| 343 | + $pos = stripos( $read, '<?php' ); | |
| 344 | + if ( $pos !== false ) { | |
| 345 | + return substr_replace( | |
| 346 | + $read, | |
| 347 | + '<?php declare(ticks='. CODE_PROFILER_TICKS .');', | |
| 348 | + $pos, | |
| 349 | + 5 | |
| 350 | + ); | |
| 351 | + } | |
| 352 | + return $read; | |
| 326 | 353 | } |
| 327 | 354 | self::start(); |
| 328 | 355 | } |
| 329 | 356 | $read = fread( $this->resource, $count ); |