| 1 |
<?php |
| 2 |
/** |
| 3 |
* CartFlows Log status. |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace CartflowsAdmin\AdminCore\Inc; |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Class LogStatus. |
| 17 |
* |
| 18 |
* Reads the log directory for the debug UI. The download/delete handlers live in |
| 19 |
* ajax/debugger.php, which resolves the filename through get_log_files() and adds a |
| 20 |
* realpath containment check; the unreferenced copies that used to sit here took |
| 21 |
* $_REQUEST['handle'] straight onto the log path and were removed. |
| 22 |
*/ |
| 23 |
class LogStatus { |
| 24 |
|
| 25 |
/** |
| 26 |
* Instance |
| 27 |
* |
| 28 |
* @access private |
| 29 |
* @var object Class object. |
| 30 |
* @since 1.0.0 |
| 31 |
*/ |
| 32 |
private static $instance; |
| 33 |
|
| 34 |
/** |
| 35 |
* Initiator |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* @return object initialized object of class. |
| 39 |
*/ |
| 40 |
public static function get_instance() { |
| 41 |
if ( ! isset( self::$instance ) ) { |
| 42 |
self::$instance = new self(); |
| 43 |
} |
| 44 |
return self::$instance; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Constructor |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
*/ |
| 52 |
public function __construct() { |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get all log files in the log directory. |
| 57 |
* |
| 58 |
* @return array |
| 59 |
*/ |
| 60 |
public function get_log_files() { |
| 61 |
// Condition for multisite instances: |
| 62 |
// Return empty array if log directory doesn't exist yet or is not readable. |
| 63 |
if ( ! is_dir( CARTFLOWS_LOG_DIR ) || ! is_readable( CARTFLOWS_LOG_DIR ) ) { |
| 64 |
return array(); |
| 65 |
} |
| 66 |
|
| 67 |
$files = scandir( CARTFLOWS_LOG_DIR ); |
| 68 |
$result = array(); |
| 69 |
|
| 70 |
if ( ! empty( $files ) ) { |
| 71 |
foreach ( $files as $key => $file ) { |
| 72 |
if ( ! is_dir( $file ) && strstr( $file, '.log' ) ) { |
| 73 |
$result[ pathinfo( $file, PATHINFO_FILENAME ) ] = $file; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return $result; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
LogStatus::get_instance(); |
| 83 |
|