PluginProbe
Email Log / 2.63
Email Log v2.63
2.63 2.4.8 2.4.9 2.6 2.61 2.62 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.9 0.9.1 0.9.2 1.1 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 61 releases
email-log / include / Core / UI / Page / LogListPage.php

LogListPage.php in Email Log 2.63, at include/Core/UI/Page/LogListPage.php

225 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace EmailLog\Core\UI\Page;
2
3 use EmailLog\Core\DB\TableManager;
4 use EmailLog\Core\UI\ListTable\LogListTable;
5
6 /**
7 * Log List Page.
8 *
9 * @since 2.0
10 */
11 class LogListPage extends BasePage {
12 /**
13 * @var LogListTable
14 */
15 protected $log_list_table;
16
17 /**
18 * Page slug.
19 */
20 const PAGE_SLUG = 'email-log';
21
22 /**
23 * Nonce Field.
24 */
25 const LOG_LIST_ACTION_NONCE_FIELD = 'el-log-list-nonce-field';
26
27 /**
28 * Nonce name.
29 */
30 const LOG_LIST_ACTION_NONCE = 'el-log-list-nonce';
31
32 /**
33 * Capability to manage email logs.
34 *
35 * @since 2.1.0
36 */
37 const CAPABILITY = 'manage_email_logs';
38
39 /**
40 * Setup hooks.
41 */
42 public function load() {
43 parent::load();
44
45 add_filter( 'set-screen-option', array( $this, 'save_screen_options' ), 10, 3 );
46
47 add_action( 'admin_enqueue_scripts', array( $this, 'load_view_logs_assets' ), 1 );
48 }
49
50 /**
51 * Register page.
52 *
53 * @inheritdoc
54 */
55 public function register_page() {
56 add_menu_page(
57 __( 'Email Log', 'email-log' ),
58 __( 'Email Log', 'email-log' ),
59 self::CAPABILITY,
60 self::PAGE_SLUG,
61 array( $this, 'render_page' ),
62 'dashicons-email-alt',
63 26
64 );
65
66 $this->page = add_submenu_page(
67 self::PAGE_SLUG,
68 __( 'View Logs', 'email-log'),
69 __( 'View Logs', 'email-log'),
70 self::CAPABILITY,
71 self::PAGE_SLUG,
72 array( $this, 'render_page' )
73 );
74
75 add_action( "load-{$this->page}", array( $this, 'load_page' ) );
76
77 /**
78 * Fires before loading log list page.
79 *
80 * @since 2.0
81 *
82 * @param string $page Page slug.
83 */
84 do_action( 'el_load_log_list_page', $this->page );
85 }
86
87 /**
88 * Render page.
89 */
90 public function render_page() {
91 if ( ! current_user_can( self::CAPABILITY ) ) {
92 return;
93 }
94
95 add_thickbox();
96
97 $this->log_list_table->prepare_items();
98 ?>
99 <div class="wrap">
100 <h2><img class="el-logo" src="<?php echo esc_url(EMAIL_LOG_URL . 'assets/img/logo-64x64.png'); ?>" /><?php esc_html_e( 'Email Log', 'email-log' ); ?></h2>
101 <?php settings_errors(); ?>
102 <div class="email-log-body-wrapper">
103 <form id="email-logs-list" method="get">
104 <input type="hidden" name="page" value="<?php echo esc_attr( self::PAGE_SLUG ); ?>">
105 <?php $this->log_list_table->search_box( __( 'Search Logs', 'email-log' ), 'search_id' ); ?>
106
107 <?php
108 // Disable the output of referrer hidden field, since it will be generated by the log list table.
109 wp_nonce_field( self::LOG_LIST_ACTION_NONCE, self::LOG_LIST_ACTION_NONCE_FIELD, false );
110 $this->log_list_table->display();
111 ?>
112 </form>
113 </div>
114 <div class="email-log-sidebar-wrapper">
115 <?php \EmailLog\Core\EmailLog::wp_kses_wf($this->sidebar()); ?>
116 </div>
117 </div>
118 <?php
119 $this->render_page_footer();
120 }
121
122 /**
123 * Load page.
124 */
125 public function load_page() {
126 // Add screen options
127 $this->get_screen()->add_option(
128 'per_page',
129 array(
130 'label' => __( 'Entries per page', 'email-log' ),
131 'default' => 20,
132 'option' => 'per_page',
133 )
134 );
135
136 $this->log_list_table = new LogListTable( $this );
137 }
138
139 /**
140 * Gets the per page option.
141 *
142 * @return int Number of logs a user wanted to be displayed in a page.
143 */
144 public function get_per_page() {
145 $screen = get_current_screen();
146 $option = $screen->get_option( 'per_page', 'option' );
147
148 $per_page = get_user_meta( get_current_user_id(), $option, true );
149
150 if ( empty( $per_page ) || $per_page < 1 ) {
151 $per_page = $screen->get_option( 'per_page', 'default' );
152 }
153
154 return $per_page;
155 }
156
157 /**
158 * Get nonce args.
159 *
160 * @return array Nonce args.
161 */
162 public function get_nonce_args() {
163 return array(
164 self::LOG_LIST_ACTION_NONCE_FIELD => wp_create_nonce( self::LOG_LIST_ACTION_NONCE ),
165 );
166 }
167
168 /**
169 * Get TableManager instance.
170 *
171 * @return TableManager TableManager instance.
172 */
173 public function get_table_manager() {
174 $email_log = email_log();
175
176 return $email_log->table_manager;
177 }
178
179 /**
180 * Saves Screen options.
181 *
182 * @since Genesis
183 *
184 * @param bool|int $status Screen option value. Default false to skip.
185 * @param string $option The option name.
186 * @param int $value The number of rows to use.
187 *
188 * @return bool|int
189 */
190 public function save_screen_options( $status, $option, $value ) {
191 if ( 'per_page' == $option ) {
192 return $value;
193 } else {
194 return $status;
195 }
196 }
197
198 /**
199 * Loads assets on the Log List page.
200 *
201 * @since 2.0.0
202 *
203 * @param string $hook The current admin page.
204 */
205 public function load_view_logs_assets( $hook ) {
206 // Don't load assets if not View Logs page.
207 if ( 'toplevel_page_email-log' !== $hook && 'email-log_page_email-log-settings' !== $hook) {
208 return;
209 }
210
211 $email_log = email_log();
212
213 wp_register_script('insertionQ', EMAIL_LOG_URL . 'assets/js/insQ.min.js', array( 'jquery' ), '1.0.4', true );
214 wp_enqueue_script('jquery-ui-position');
215 wp_enqueue_script('jquery-effects-core');
216 wp_enqueue_script("jquery-effects-blind");
217 wp_enqueue_script('jquery-ui-accordion');
218 wp_enqueue_script('jquery-ui-dialog');
219 wp_enqueue_script( 'el-view-logs', EMAIL_LOG_URL . 'assets/js/view-logs.js', array( 'insertionQ', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-tooltip', 'jquery-ui-tabs' ), $email_log->get_version(), true );
220 wp_enqueue_style('el-jquery-ui-css', EMAIL_LOG_URL . 'assets/css/email-log-jquery-ui.min.css', array());
221 wp_enqueue_style('wp-jquery-ui-dialog');
222
223 }
224 }
225