Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -81,8 +81,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function init() {
add_action('wp_ajax_wu_handle_view_logs', array($this, 'handle_view_logs'));
} // end init;
}
/**
* Registers extra scripts needed for this page.
@ -96,17 +95,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
\WP_Ultimo\Scripts::get_instance()->register_script('wu-view-log', wu_get_asset('view-logs.js', 'js'), array('jquery'));
wp_localize_script('wu-view-log', 'wu_view_logs', array(
'i18n' => array(
'copied' => __('Copied!', 'wp-ultimo'),
),
));
wp_localize_script(
'wu-view-log',
'wu_view_logs',
array(
'i18n' => array(
'copied' => __('Copied!', 'wp-ultimo'),
),
)
);
wp_enqueue_script('wu-view-log');
wp_enqueue_script('clipboard');
} // end register_scripts;
}
/**
* Returns the title of the page.
@ -117,8 +119,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return __('View Log', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -129,8 +130,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('View Log', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Handles the actions for the logs and system info.
@ -141,17 +141,19 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
*/
public function handle_view_logs() {
$logs_list = list_files(Logger::get_logs_folder(), 2, array(
'index.html',
));
$logs_list = list_files(
Logger::get_logs_folder(),
2,
array(
'index.html',
)
);
$logs_list = array_combine(array_values($logs_list), array_map(fn($file) => str_replace(Logger::get_logs_folder(), '', (string) $file), $logs_list));
if (empty($logs_list)) {
$logs_list[''] = __('No log files found', 'wp-ultimo');
} // end if;
}
$file = wu_request('file');
@ -160,17 +162,13 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
$contents = '';
// Security check
if ($file && !stristr((string) $file, Logger::get_logs_folder())) {
if ($file && ! stristr((string) $file, Logger::get_logs_folder())) {
wp_die(__('You can see files that are not WP Multisite WaaS\'s logs', 'wp-ultimo'));
}
} // end if;
if (!$file && !empty($logs_list)) {
$file = !$file && !empty($logs_list) ? current(array_keys($logs_list)) : false;
} // end if;
if ( ! $file && ! empty($logs_list)) {
$file = ! $file && ! empty($logs_list) ? current(array_keys($logs_list)) : false;
}
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file);
@ -186,16 +184,11 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
);
if (wp_doing_ajax()) {
wp_send_json_success($response);
} else {
return $response;
} // end if;
} // end handle_view_logs;
}
}
/**
* Allow child classes to register widgets, if they need them.
@ -209,41 +202,46 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
add_meta_box('wp-ultimo-log-contents', __('Log Contents', 'wp-ultimo'), array($this, 'output_default_widget_payload'), get_current_screen()->id, 'normal', null, $info);
$this->add_fields_widget('file-selector', array(
'title' => __('Log Files', 'wp-ultimo'),
'fields' => array(
'log_file' => array(
'type' => 'select',
'title' => __('Select Log File', 'wp-ultimo'),
'placeholder' => __('Select Log File', 'wp-ultimo'),
'value' => wu_request('file'),
'tooltip' => '',
'options' => $info['logs_list'],
$this->add_fields_widget(
'file-selector',
array(
'title' => __('Log Files', 'wp-ultimo'),
'fields' => array(
'log_file' => array(
'type' => 'select',
'title' => __('Select Log File', 'wp-ultimo'),
'placeholder' => __('Select Log File', 'wp-ultimo'),
'value' => wu_request('file'),
'tooltip' => '',
'options' => $info['logs_list'],
),
'download' => array(
'type' => 'submit',
'title' => __('Download Log', 'wp-ultimo'),
'value' => 'download',
'classes' => 'button button-primary wu-w-full',
),
),
'download' => array(
'type' => 'submit',
'title' => __('Download Log', 'wp-ultimo'),
'value' => 'download',
'classes' => 'button button-primary wu-w-full',
)
);
$this->add_fields_widget(
'info',
array(
'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side',
'fields' => array(
'date_modified' => array(
'title' => __('Last Modified at', 'wp-ultimo'),
'type' => 'text-edit',
'date' => true,
'value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
'display_value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
),
),
),
));
$this->add_fields_widget('info', array(
'title' => __('Timestamps', 'wp-ultimo'),
'position' => 'side',
'fields' => array(
'date_modified' => array(
'title' => __('Last Modified at', 'wp-ultimo'),
'type' => 'text-edit',
'date' => true,
'value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
'display_value' => date_i18n('Y-m-d H:i:s', filemtime($info['file'])),
)
),
));
} // end register_widgets;
)
);
}
/**
* Outputs the pre block that shows the content.
@ -256,13 +254,15 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
*/
public function output_default_widget_payload($unused, $data) {
wu_get_template('events/widget-payload', array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $data['args']['contents'],
));
} // end output_default_widget_payload;
wu_get_template(
'events/widget-payload',
array(
'title' => __('Event Payload', 'wp-ultimo'),
'loading_text' => __('Loading Payload', 'wp-ultimo'),
'payload' => $data['args']['contents'],
)
);
}
/**
* Returns the labels to be used on the admin page.
@ -280,8 +280,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Log File', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Returns the object being edit at the moment.
@ -292,8 +291,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
public function get_object() {
return array();
} // end get_object;
}
/**
* Register additional hooks to page load such as the action links and the save processing.
@ -312,8 +310,7 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
* Process save, if necessary
*/
$this->process_save();
} // end page_loaded;
}
/**
* Should implement the processes necessary to save the changes made to the object.
@ -326,25 +323,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
$action = wu_request('submit_button', 'none');
if ($action === 'none') {
WP_Ultimo()->notices->add(__('Something wrong happened', 'wp-ultimo'), 'error', 'network-admin');
return;
} // end if;
}
$file = wu_request('log_file', false);
if (!file_exists($file)) {
if ( ! file_exists($file)) {
WP_Ultimo()->notices->add(__('File not found', 'wp-ultimo'), 'error', 'network-admin');
return;
} // end if;
}
if ($action === 'download') {
$file_name = str_replace(Logger::get_logs_folder(), '', (string) $file);
header('Content-Type: application/octet-stream');
@ -354,27 +346,20 @@ class View_Logs_Admin_Page extends Edit_Admin_Page {
readfile($file);
exit;
} elseif ($action === 'delete') {
$status = unlink($file);
if (!$status) {
if ( ! $status) {
WP_Ultimo()->notices->add(__('We were unable to delete file', 'wp-ultimo'), 'error', 'network-admin');
return;
} // end if;
} // end if;
}
}
$url = remove_query_arg('log_file');
wp_redirect(add_query_arg('deleted', 1, $url));
exit;
} // end handle_save;
} // end class View_Logs_Admin_Page;
}
}