Skip to content

Commit

Permalink
Work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev4press committed Nov 5, 2023
1 parent cb84fda commit ba298b2
Show file tree
Hide file tree
Showing 24 changed files with 392 additions and 81 deletions.
108 changes: 86 additions & 22 deletions core/display/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,87 +165,151 @@ public function debugger_content() {

public function prepare_tabs() {
$this->tabs = array(
'basics' => __( "Basics", "debugpress" ),
'basics' => array(
'label' => __( "Basics", "debugpress" ),
'icon' => 'gear',
),
);

if ( debugpress_plugin()->get( 'panel_request' ) ) {
$this->tabs['request'] = __( "Request", "debugpress" );
$this->tabs['request'] = array(
'label' => __( "Request", "debugpress" ),
'icon' => 'globe',
);
}

if ( ! is_admin() ) {
$this->tabs['query'] = __( "Query", "debugpress" );
$this->tabs['query'] = array(
'label' => __( "Query", "debugpress" ),
'icon' => 'brackets-curly',
);
}

if ( debugpress_plugin()->get( 'panel_content' ) ) {
$this->tabs['content'] = __( "Content", "debugpress" );
$this->tabs['content'] = array(
'label' => __( "Content", "debugpress" ),
'icon' => 'folder',
);
}

if ( debugpress_plugin()->get( 'panel_rewriter' ) ) {
$this->tabs['rewriter'] = __( "Rewriter", "debugpress" );
$this->tabs['rewriter'] = array(
'label' => __( "Rewriter", "debugpress" ),
'icon' => 'link-simple',
);
}

if ( debugpress_plugin()->get( 'panel_roles' ) ) {
$this->tabs['roles'] = __( "Roles", "debugpress" );
$this->tabs['roles'] = array(
'label' => __( "Roles", "debugpress" ),
'icon' => 'folder-user',
);
}

if ( debugpress_plugin()->get( 'panel_constants' ) ) {
$this->tabs['constants'] = __( "Constants", "debugpress" );
$this->tabs['constants'] = array(
'label' => __( "Constants", "debugpress" ),
'icon' => 'brackets-square',
);
}

if ( debugpress_plugin()->get( 'panel_hooks' ) ) {
$this->tabs['hooks'] = __( "Hooks", "debugpress" );
$this->tabs['hooks'] = array(
'label' => __( "Hooks", "debugpress" ),
'icon' => 'diagram-project',
);
}

if ( ! empty( debugpress_db()->wpdb()->queries ) ) {
$this->tabs['queries'] = __( "SQL Queries", "debugpress" );
$this->tabs['queries'] = array(
'label' => __( "SQL Queries", "debugpress" ),
'icon' => 'database',
);
}

if ( is_user_logged_in() && debugpress_plugin()->get( 'panel_user' ) ) {
$this->tabs['user'] = __( "User", "debugpress" );
$this->tabs['user'] = array(
'label' => __( "User", "debugpress" ),
'icon' => 'id-card-clip',
);
}

if ( debugpress_plugin()->get( 'panel_enqueue' ) ) {
$this->tabs['enqueue'] = __( "Enqueue", "debugpress" );
$this->tabs['enqueue'] = array(
'label' => __( "Enqueue", "debugpress" ),
'icon' => 'files',
);
}

if ( debugpress_plugin()->get( 'panel_php' ) ) {
$this->tabs['php'] = __( "PHP", "debugpress" );
$this->tabs['php'] = array(
'label' => __( "PHP", "debugpress" ),
'icon' => 'php',
);
}

if ( debugpress_plugin()->get( 'panel_system' ) ) {
$this->tabs['server'] = __( "System", "debugpress" );
$this->tabs['server'] = array(
'label' => __( "System", "debugpress" ),
'icon' => 'server',
);
}

if ( debugpress_plugin()->get( 'panel_bbpress' ) && debugpress_has_bbpress() && is_bbpress() ) {
$this->tabs['bbpress'] = __( "bbPress", "debugpress" );
$this->tabs['bbpress'] = array(
'label' => __( "bbPress", "debugpress" ),
'icon' => 'bbpress',
);
}

if ( ! empty( debugpress_tracker()->plugins ) ) {
$this->tabs['plugins'] = __( "Plugins", "debugpress" );
$this->tabs['plugins'] = array(
'label' => __( "Plugins", "debugpress" ),
'icon' => 'plug',
);
}

if ( debugpress_plugin()->get( 'panel_http' ) && ! empty( debugpress_tracker()->httpapi ) ) {
$this->tabs['http'] = __( "HTTP", "debugpress" ) . ' (' . count( debugpress_tracker()->httpapi ) . ')';
$this->tabs['http'] = array(
'label' => __( "HTTP", "debugpress" ) . ' (' . count( debugpress_tracker()->httpapi ) . ')',
'icon' => 'diagram-project',
);
}

if ( debugpress_plugin()->get( 'ajax' ) ) {
$this->tabs['ajax'] = __( "AJAX", "debugpress" ) . ' (<span>0</span>)';
$this->tabs['ajax'] = array(
'label' => __( "AJAX", "debugpress" ) . '',
'counter' => true,
'icon' => 'code',
);
}

if ( ! empty( debugpress_tracker()->logged ) ) {
$this->tabs['store'] = __( "Store", "debugpress" ) . ' (' . count( debugpress_tracker()->logged ) . ')';
$this->tabs['store'] = array(
'label' => __( "Store", "debugpress" ) . ' (' . count( debugpress_tracker()->logged ) . ')',
'icon' => 'clipboard',
);
}

if ( ! empty( debugpress_tracker()->deprecated ) ) {
$this->tabs['deprecated'] = __( "Deprecated", "debugpress" ) . ' (' . debugpress_tracker()->counts['deprecated'] . ')';
$this->tabs['deprecated'] = array(
'label' => __( "Deprecated", "debugpress" ) . ' (' . debugpress_tracker()->counts['deprecated'] . ')',
'icon' => 'octagon-exclamation',
);
}

if ( ! empty( debugpress_tracker()->doingitwrong ) ) {
$this->tabs['doingitwrong'] = __( "Doing It Wrong", "debugpress" ) . ' (' . debugpress_tracker()->counts['doingitwrong'] . ')';
$this->tabs['doingitwrong'] = array(
'label' => __( "Doing It Wrong", "debugpress" ) . ' (' . debugpress_tracker()->counts['doingitwrong'] . ')',
'icon' => 'square-exclamation',
);
}

if ( ! empty( debugpress_tracker()->errors ) ) {
$this->tabs['errors'] = __( "Errors", "debugpress" ) . ' (' . debugpress_tracker()->counts['errors'] . ')';
if ( empty( debugpress_tracker()->errors ) ) {
$this->tabs['errors'] = array(
'label' => __( "Errors", "debugpress" ) . ' (' . ( debugpress_tracker()->counts['errors'] + 1 ) . ')',
'icon' => 'triangle-exclamation',
);
}

$this->tabs['layout'] = array(
Expand Down
9 changes: 9 additions & 0 deletions core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ function debugpress_has_bbpress() : bool {
}
}

/**
* Check if the coreActivity plugin is currently installed and active.
*
* @return bool TRUE: if the coreActivity is active, FALSE: if it is not active
*/
function debugpress_has_coreactivity() : bool {
return defined( 'COREACTIVITY_VERSION' ) && function_exists( 'coreactivity' ) && class_exists( '\Dev4Press\Plugin\CoreActivity\Basic\Plugin' );
}

/**
* Check if the currently running CMS is ClassicPress, and not the WordPress.
*
Expand Down
4 changes: 4 additions & 0 deletions core/panel/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function single() {
$this->add_column( __( "Request", "debugpress" ) );
$this->add_column( __( "Response", "debugpress" ) );
$this->add_column( __( "Time", "debugpress" ) );
$this->add_column( __( "Caller", "debugpress" ) );
$this->table_head();
foreach ( debugpress_tracker()->httpapi as $request ) {
$this->render_request( $request );
Expand All @@ -40,6 +41,7 @@ public function render_request( $request ) {
}

$_req = array(
__( "Timestamp", "debugpress" ) => $request['timers']['start'] ?? '',
__( "Transport", "debugpress" ) => $request['transport'],
__( "Method", "debugpress" ) => $request['args']['method'] ?? 'N/A',
__( "User Agent", "debugpress" ) => $request['args']['user-agent'] ?? 'N/A',
Expand All @@ -59,6 +61,7 @@ public function render_request( $request ) {
}

$_res = array(
__( "Timestamp", "debugpress" ) => $request['timers']['end'] ?? '',
__( "Code", "debugpress" ) => $request['info']['http_code'] ?? 'N/A',
__( "Content Type", "debugpress" ) => $request['info']['content_type'] ?? 'N/A',
__( "IP and Port", "debugpress" ) => $_ip,
Expand All @@ -77,6 +80,7 @@ public function render_request( $request ) {
$this->list_plain_pairs( $_req ),
$this->list_plain_pairs( $_res ),
$this->list_plain_pairs( $_tme ),
$this->list_plain_pairs( $request['trace'] ),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion core/panel/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function process_origin( $origins ) {
}

public function left() {
echo '<h4 class="debugpress-querie-sidebar-control"><span data-state="open"><i class="debugpress-icon debugpress-icon-caret-left"></i></span></h4>';
echo '<h4 class="debugpress-query-sidebar-control"><span data-state="open"><i class="debugpress-icon debugpress-icon-caret-left"></i></span></h4>';

$this->title( __( "Hooks Control", "debugpress" ), true, false, 'hooks-control' );
$this->block_header();
Expand Down
2 changes: 1 addition & 1 deletion core/panel/Queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct() {
}

public function left() {
echo '<h4 class="debugpress-querie-sidebar-control"><span data-state="open"><i class="debugpress-icon debugpress-icon-caret-left"></i></span></h4>';
echo '<h4 class="debugpress-query-sidebar-control"><span data-state="open"><i class="debugpress-icon debugpress-icon-caret-left"></i></span></h4>';

$this->title( __( "Basic Statistics", "debugpress" ), true, false, 'basic-statistics' );
$this->block_header();
Expand Down
16 changes: 16 additions & 0 deletions core/panel/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public function left() {
}

public function middle() {
$this->title( 'coreActivity', true, true );
echo '<p>' . esc_html__( "coreActivity is free and powerful plugin for logging activities in WordPress for later review and analysis, supporting over 120 events, more than 10 plugins, with notifications, live logs and more. And, it has 9 events for DebugPress plugin.", "debugpress" ) . '</p>';

$this->block_header();
if ( debugpress_has_coreactivity() ) {
$this->sub_title( __( "Events and Logs", "debugpress" ) );
echo '<p>' . esc_html__( "Configure available events and check out what is logged.", "debugpress" ) . '</p>';
echo '<a target="_blank" href="' . network_admin_url( 'admin.php?page=coreactivity-events&filter-component=coreactivity/debugpress' ) . '" class="debugpress-button-action">' . esc_html__( "DebugPress Events", "debugpress" ) . '</a>';
echo '<a target="_blank" href="' . network_admin_url( 'admin.php?page=coreactivity-logs&view=component&filter-component=coreactivity/debugpress' ) . '" class="debugpress-button-action">' . esc_html__( "DebugPress Log", "debugpress" ) . '</a>';
} else {
$this->sub_title( __( "Install the Plugin", "debugpress" ) );
echo '<p>' . esc_html__( "Find plugin in the repository, install and activate it.", "debugpress" ) . '</p>';
echo '<a target="_blank" href="' . network_admin_url( 'plugin-install.php?s=coreactivity&tab=search&type=term' ) . '" class="debugpress-button-action">' . esc_html__( "Find and Install the plugin", "debugpress" ) . '</a>';
}
$this->block_footer();

$this->title( __( "WordPress Important Tools", "debugpress" ), true, true );

if ( current_user_can( 'manage_options' ) ) {
Expand Down
6 changes: 5 additions & 1 deletion core/track/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public function release() {
debugpress_tracker()->end();

if ( ! headers_sent() ) {
foreach ( $this->data() as $key => $value ) {
$data = $this->data();

do_action( 'debugpress-tracker-admin-ajax-logged', $data );

foreach ( $data as $key => $value ) {
$formatted = is_scalar( $value ) ? $value : json_encode( $value );
$header = sprintf( 'X-DEBUGPRESS-%s: %s', $key, $formatted );

Expand Down
46 changes: 34 additions & 12 deletions core/track/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Tracker {

private $_http_transport = null;
private $_http_info = null;
private $_http_spawn_cron = false;

public function __construct() {
global $timestart;
Expand Down Expand Up @@ -173,14 +174,13 @@ public function http_request_args( $args, $url ) {

$args['_debugpress_key_'] = md5( microtime( true ) . '-' . $url ) . '-' . microtime( true );

if ( ! empty( $url ) ) {
$this->httpapi[ $args['_debugpress_key_'] ] = array(
'url' => $url,
'args' => $args,
'start' => $start,
'trace' => $trace,
);
}
$this->httpapi[ $args['_debugpress_key_'] ] = array(
'url' => $url,
'args' => $args,
'start' => $start,
'trace' => $trace,
'spawn' => $this->_http_spawn_cron,
);

return $args;
}
Expand Down Expand Up @@ -645,12 +645,13 @@ private function _strip_abspath( $path ) : string {
}

private function _get_caller( $function_target = '', $use_previous_call_actual = false ) : array {
$_abspath = str_replace( '\\', '/', ABSPATH );
$this->_http_spawn_cron = false;

$filters = array( 'do_action', 'apply_filter', 'do_action_ref_array', 'call_user_func_array' );

$trace = array_reverse( debug_backtrace() );
$caller = array();
$trace = array_reverse( debug_backtrace() );
$caller = array();

$this->_actual_file = '';
$this->_actual_line = 0;

Expand Down Expand Up @@ -688,7 +689,11 @@ private function _get_caller( $function_target = '', $use_previous_call_actual =
}
}

$value = isset( $call["class"] ) ? "{$call["class"]}->{$call["function"]}" : $call["function"];
if ( $call['function'] == 'spawn_cron' ) {
$this->_http_spawn_cron = true;
}

$value = isset( $call['class'] ) ? "{$call['class']}->{$call['function']}" : $call['function'];

$file = '';
if ( isset( $call['file'] ) && isset( $call['line'] ) ) {
Expand Down Expand Up @@ -750,9 +755,19 @@ private function _log_http_api_call( $response, $args, $url ) {
$this->httpapi[ $key_original ]['response'] = new WP_Error( 'http_request_not_executed', sprintf( __( "Request not executed because of the filter on %s.", "debugpress" ), 'pre_http_request' ) );
}

if ( isset( $this->httpapi[ $key ] ) ) {
$log['start'] = $this->httpapi[ $key ]['start'] ?? 0;
$log['trace'] = $this->httpapi[ $key ]['trace'] ?? array();
$log['spawn'] = $this->httpapi[ $key ]['spawn'] ?? false;
}

$this->_http_info = null;
$this->_http_transport = null;

if ( ! $log['spawn'] ) {
do_action( 'debugpress-tracker-http-request-call-logged', $log );
}

$this->httpapi[ $key ] = $log;
}

Expand All @@ -762,7 +777,13 @@ private function _prepare_http_api_logs() {
$log = array(
'transport' => $raw['transport'],
'info' => $raw['info'],
'trace' => $raw['trace'] ?? array(),
'timers' => array(
'start' => $raw['start'] ?? 0,
'end' => $raw['end'] ?? 0,
),
'args' => array(),
'spawn' => $raw['spawn'] ?? false,
);

foreach ( $raw['args'] as $key => $val ) {
Expand All @@ -786,6 +807,7 @@ private function _prepare_http_api_logs() {

$raw = $log;
}
debugpress_error_log( $this->httpapi );
}
}
}
Loading

0 comments on commit ba298b2

Please sign in to comment.