/home/techb158/dev.aleamaralawal.com/wp-content/plugins/wpforms-lite/src/Logger
Edit: /home/techb158/dev.aleamaralawal.com/wp-content/plugins/wpforms-lite/src/Logger/ListTable.php (12761B)
repository = $repository;
parent::__construct(
[
'plural' => esc_html__( 'Logs', 'wpforms-lite' ),
'singular' => esc_html__( 'Log', 'wpforms-lite' ),
]
);
$this->hooks();
add_screen_option(
'per_page',
[ 'default' => $this->get_items_per_page( $this->get_per_page_option_name() ) ]
);
set_screen_options();
}
/**
* Hooks.
*
* @since 1.7.5
*/
private function hooks() {
add_filter(
'set_screen_option_' . $this->get_per_page_option_name(),
[ $this, 'set_items_per_page_option' ],
10,
3
);
}
/**
* Handles setting the items_per_page option for this screen.
*
* @since 1.7.5
*
* @param mixed $status Default false (to skip saving the current option).
* @param string $option Screen option name.
* @param int $value Screen option value.
*
* @return int
* @noinspection PhpUnusedParameterInspection
*/
public function set_items_per_page_option( $status, $option, $value ) {
return $value;
}
/**
* Whether the table has items to display or not.
*
* @since 1.6.3
*
* @return bool
*/
public function has_items() {
// We can't use the empty function because it doesn't work with the Countable object.
return (bool) count( $this->items );
}
/**
* Prepares the list of items for displaying.
*
* @since 1.6.3
*/
public function prepare_items() {
$offset = $this->get_items_offset();
$search = $this->get_request_search_query();
$types = $this->get_items_type();
$per_page = $this->get_items_per_page( $this->get_per_page_option_name() );
$this->items = $this->repository->records( $per_page, $offset, $search, $types );
$total_items = $this->get_total();
$this->set_pagination_args(
[
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => (int) ceil( $total_items / $per_page ),
]
);
}
/**
* Return the type of records.
*
* @since 1.6.3
*
* @return string
*/
private function get_items_type() {
return filter_input( INPUT_GET, 'log_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
}
/**
* Return the number of items to offset/skip for this current view.
*
* @since 1.6.3
*
* @return int
*/
private function get_items_offset() {
return $this->get_items_per_page( $this->get_per_page_option_name() ) * ( $this->get_pagenum() - 1 );
}
/**
* Return the search filter for this request, if any.
*
* @since 1.6.3
*
* @return string
*/
private function get_request_search_query() {
return filter_input( INPUT_GET, 's', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
}
/**
* Column title.
*
* @since 1.6.3
*
* @param Record $item List table item.
*
* @return string
* @noinspection PhpUnused
*/
public function column_log_title( $item ) {
return sprintf(
'
%2$s',
absint( $item->get_id() ),
esc_html( $item->get_title() )
);
}
/**
* Column message.
*
* @since 1.6.3
*
* @param Record $item List table item.
*
* @return string
* @noinspection PhpUnused
*/
public function column_message( $item ) {
$message = $item->get_message();
if ( preg_match( '/\[body].+{"error":"(.+)"}/i', $message, $m ) ) {
$message = $m[1];
}
if ( preg_match( '/\[error] => (.+)/i', $message, $m ) ) {
$message = $m[1];
}
return esc_html( $this->crop_message( $message ) );
}
/**
* Column form ID.
*
* @since 1.6.3
*
* @param Record $item List table item.
*
* @return int
* @noinspection PhpUnused
*/
public function column_form_id( $item ) {
return absint( $item->get_form_id() );
}
/**
* Column types.
*
* @since 1.6.3
*
* @param Record $item List table item.
*
* @return string
* @noinspection PhpUnused
*/
public function column_types( $item ) {
return esc_html( implode( ', ', $item->get_types( 'label' ) ) );
}
/**
* Column date.
*
* @since 1.6.3
*
* @param Record $item List table item.
*
* @return string
* @noinspection PhpUnused
*/
public function column_date( $item ) {
return esc_html( $item->get_date( 'sql-local' ) );
}
/**
* Crop message for preview on list table.
*
* @since 1.6.3
*
* @param string $message Message.
*
* @return string
*/
private function crop_message( $message ) {
return wp_html_excerpt( $message, 97, '...' );
}
/**
* Prepares the _column_headers property which is used by WP_Table_List at rendering.
* It merges the columns and the sortable columns.
*
* @since 1.6.3
*/
private function prepare_column_headers() {
$this->_column_headers = [
$this->get_columns(),
get_hidden_columns( $this->screen ),
[],
];
}
/**
* Return the columns' names for rendering.
*
* @since 1.6.3
*
* @return array
*/
public function get_columns() {
return [
'log_title' => __( 'Log Title', 'wpforms-lite' ),
'message' => __( 'Message', 'wpforms-lite' ),
'form_id' => __( 'Form ID', 'wpforms-lite' ),
'types' => __( 'Types', 'wpforms-lite' ),
'date' => __( 'Date', 'wpforms-lite' ),
];
}
/**
* Header before log table.
*
* @since 1.6.3
*/
private function header() {
?>
extra_tablenav( $which );
}
$this->pagination( $which );
?>
get_total() ) {
return;
}
$this->log_type_select();
$this->clear_all();
}
/**
* Clear all log records.
*
* @since 1.6.3
*/
private function clear_all() {
?>
_args['plural'] ) ) {
return;
}
if ( empty( $_REQUEST['_wp_http_referer'] ) && empty( $_REQUEST['clear-all'] ) ) {
return;
}
if ( ! empty( $_REQUEST['clear-all'] ) ) {
$this->repository->clear_all();
}
$uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
wp_safe_redirect(
remove_query_arg(
[ '_wp_http_referer', '_wpnonce', 'clear-all' ],
$uri
)
);
exit;
}
/**
* Message to be displayed when there are no items.
*
* @since 1.6.3
*/
public function no_items() {
esc_html_e( 'No logs found.', 'wpforms-lite' );
}
/**
* Print all hidden fields.
*
* @since 1.6.3
*/
private function hidden_fields() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
foreach ( $_GET as $key => $value ) {
if ( $key[0] === '_' || $key === 'paged' || $key === 'ID' ) {
continue;
}
echo '
';
}
}
/**
* Select for choose a log type.
*
* @since 1.6.3
*/
private function log_type_select() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$current_type = ! empty( $_GET['log_type'] ) ? sanitize_text_field( wp_unslash( $_GET['log_type'] ) ) : '';
?>
prepare_column_headers();
$this->prepare_items();
$slug = $this->_args['plural'];
echo '
';
echo '
';
echo '';
}
/**
* Get total logs.
*
* @since 1.6.3
*
* @return int
*/
public function get_total() {
return $this->repository->get_total();
}
/**
* Gets the screen per_page option name.
*
* @since 1.7.5
*
* @return string
*/
private function get_per_page_option_name() {
return str_replace( '-', '_', $this->screen->id ) . '_per_page';
}
}