JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace WPForms\Logger;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use WP_List_Table;
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
* Class ListTable.
*
* @since 1.6.3
*/
class ListTable extends WP_List_Table {
/**
* Record Query.
*
* @since 1.6.3
*
* @var Repository
*/
private $repository;
/**
* ListTable constructor.
*
* @since 1.6.3
*
* @param Repository $repository Repository.
*/
public function __construct( $repository ) {
$this->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(
'<a href="#" class="js-single-log-target" data-log-id="%1$d"><strong>%2$s</strong></a>',
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() {
?>
<div class="wpforms-admin-content-header">
<h4 class="wp-heading-inline"><?php esc_html_e( 'View Logs', 'wpforms-lite' ); ?>
<?php if ( $this->get_request_search_query() ) { ?>
<span class="subtitle">
<?php
printf( /* translators: %s - search query. */
esc_html__( 'Search results for "%s"', 'wpforms-lite' ),
esc_html( $this->get_request_search_query() )
);
?>
</span>
<?php } ?>
</h4>
<?php
$this->hidden_fields();
$this->search_box( esc_html__( 'Search Logs', 'wpforms-lite' ), 'plugin' );
?>
</div>
<?php
}
/**
* Generate the table navigation above or below the table.
*
* @since 1.6.3
*
* @param string $which Which position.
*/
protected function display_tablenav( $which ) {
?>
<div class="tablenav <?php echo esc_attr( $which ); ?>">
<?php
if ( $which === 'top' ) {
$this->extra_tablenav( $which );
}
$this->pagination( $which );
?>
<br class="clear" />
</div>
<?php
}
/**
* Table list actions.
*
* @since 1.6.3
*
* @param string $which Position of navigation (top or bottom).
*/
protected function extra_tablenav( $which ) {
if ( ! $this->get_total() ) {
return;
}
$this->log_type_select();
$this->clear_all();
}
/**
* Clear all log records.
*
* @since 1.6.3
*/
private function clear_all() {
?>
<button name="clear-all" type="submit" class="button" value="1"><?php esc_html_e( 'Delete All Logs', 'wpforms-lite' ); ?></button>
<?php
}
/**
* Update URL when table showing.
* _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter.
*
* @since 1.6.3
*/
public function process_admin_ui() {
$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
if ( ! wp_verify_nonce( $nonce, 'wpforms-table-' . $this->_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 '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" />';
}
}
/**
* 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'] ) ) : '';
?>
<select name="log_type">
<option value=""><?php esc_html_e( 'All Logs', 'wpforms-lite' ); ?></option>
<?php foreach ( Log::get_log_types() as $type_slug => $type ) { ?>
<option
value="<?php echo esc_attr( $type_slug ); ?>"
<?php selected( $type_slug, $current_type ); ?>>
<?php echo esc_html( $type ); ?>
</option>
<?php } ?>
</select>
<input type="submit" class="button" value="<?php esc_attr_e( 'Apply', 'wpforms-lite' ); ?>">
<?php
}
/**
* Popup view.
*
* @since 1.6.3
*/
public function popup_template() {
?>
<script type="text/html" id="tmpl-wpforms-log-record">
<div class="wpforms-log-popup">
<div class="wpforms-log-popup-block">
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Log Title', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-title">{{{ data.title }}}</div>
</div>
<div class="wpforms-log-popup-block">
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Message', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-message">{{{ data.message }}}</div>
</div>
<div class="wpforms-log-popup-flex wpforms-log-popup-flex-column-2">
<div>
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Date', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-create-at">{{ data.create_at }}</div>
</div>
<div>
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Types', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-types">{{ data.types }}</div>
</div>
</div>
<div class="wpforms-log-popup-flex wpforms-log-popup-flex-column-4">
<div>
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Log ID', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-id">{{ data.ID }}</div>
</div>
<div>
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Form ID', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-form-id">
<# if ( data.form_id ) { #>
<a href="{{ data.form_url }}">
<# } #>
{{ data.form_id }}
<# if ( data.form_id ) { #>
</a>
<# } #>
</div>
</div>
<div>
<div class="wpforms-log-popup-label"><?php esc_html_e( 'Entry ID', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-entry-id">
<# if ( data.entry_id ) { #>
<a href="{{ data.entry_url }}">
<# } #>
{{ data.entry_id }}
<# if ( data.entry_id ) { #>
</a>
<# } #>
</div>
</div>
<div>
<div class="wpforms-log-popup-label"><?php esc_html_e( 'User ID', 'wpforms-lite' ); ?></div>
<div class="wpforms-log-popup-user-id">
<# if ( data.user_id ) { #>
<a href="{{ data.user_url }}">
<# } #>
{{ data.user_id }}
<# if ( data.user_id ) { #>
</a>
<# } #>
</div>
</div>
</div>
</div>
</script>
<?php
}
/**
* Display list table page.
*
* @since 1.6.3
*/
public function display_page() {
$this->prepare_column_headers();
$this->prepare_items();
$slug = $this->_args['plural'];
echo '<div class="wpforms-list-table wpforms-list-table--logs">';
echo '<form id="' . esc_attr( $slug ) . '-filter" method="get">';
wp_nonce_field( 'wpforms-table-' . $slug );
$this->header();
$this->display();
echo '</form>';
echo '</div>';
}
/**
* 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';
}
}