PluginProbe
Powerkit – Supercharge your WordPress Site / 2.4.4
Powerkit – Supercharge your WordPress Site v2.4.4
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / admin / class-admin-powerkit-manager.php

class-admin-powerkit-manager.php in Powerkit – Supercharge your WordPress Site 2.4.4, at admin/class-admin-powerkit-manager.php

380 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Manager
4 *
5 * @package Powerkit
6 * @subpackage Admin
7 */
8
9 /**
10 * Admin manager class.
11 */
12 class Admin_Powerkit_Manager {
13
14 /**
15 * The message output.
16 *
17 * @var string $msg The message output.
18 */
19 public $msg;
20
21 /**
22 * The slug name to refer to this menu by.
23 *
24 * @var string $menu_slug The menu slug.
25 */
26 public $menu_slug = 'manager';
27
28 /**
29 * Constructor.
30 */
31 public function __construct() {
32 $self = $this;
33 add_action( 'init', function () use ( $self ) {
34 $self->handler_actions();
35
36 add_action( 'admin_head', array( $self, 'manager_styles' ) );
37 add_action( 'admin_menu', array( $self, 'add_menu_page' ) );
38 add_action( 'plugin_action_links_powerkit/powerkit.php', array( $self, 'action_links' ) );
39 } );
40 }
41
42 /**
43 * Register a callback for our specific plugin's actions
44 *
45 * @param array $actions An array of plugin action links.
46 */
47 public function action_links( $actions ) {
48 $actions[] = sprintf( '<a href="%s">%s</a>', powerkit_get_page_url( $this->menu_slug ), esc_html__( 'Settings', 'powerkit' ) );
49
50 return $actions;
51 }
52
53 /**
54 * Add menu page
55 */
56 public function add_menu_page() {
57
58 $svg = '<svg width="18px" height="18px" viewBox="0 0 18 18" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g fill="#81878B"><path d="M6.78872178,17.7263347 L7.27177123,13.7724855 L8.84170382,13.7724855 C11.0605419,13.7724855 12.7351366,13.2073097 13.6980286,12.160688 C14.6399882,11.1349987 14.7865152,9.87905267 14.7865152,8.87429582 C14.7865152,7.9532687 14.6609206,6.69732264 13.6142989,5.67163335 C12.5676771,4.64594406 11.1442716,4.43661972 9.55340659,4.43661972 L4.88547371,4.43661972 L3.45307884,16.0879292 C1.35084819,14.4404374 5.68434189e-14,11.8779725 5.68434189e-14,9 C5.68434189e-14,4.02943725 4.02943725,0 9,0 C13.9705627,0 18,4.02943725 18,9 C18,13.9705627 13.9705627,18 9,18 C8.23700819,18 7.49619203,17.9050548 6.78872178,17.7263347 Z M9.05102816,7.36716054 C9.55340659,7.36716054 10.3069742,7.3462281 10.7674878,7.8276741 C10.9768121,8.03699844 11.165204,8.41378226 11.165204,9.02082286 C11.165204,9.33480937 11.1233392,9.85812024 10.7256229,10.2558365 C10.1813796,10.8000798 9.2603525,10.8419447 8.75797408,10.8419447 L7.64855505,10.8419447 L8.06720374,7.36716054 L9.05102816,7.36716054 Z" id="Powerkit"></path></g></svg>';
59
60 $svg = 'data:image/svg+xml;base64,' . base64_encode( $svg );
61
62 add_menu_page( esc_html__( 'Powerkit', 'powerkit' ), esc_html__( 'Powerkit', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->menu_slug ), array( $this, 'settings_page' ), $svg );
63 }
64
65 /**
66 * Manager styles
67 */
68 public function manager_styles() {
69 ?>
70 <style>
71 .powerkit-manager .wp-list-table th,
72 .powerkit-manager .wp-list-table td {
73 padding-top: 16px;
74 padding-bottom: 16px;
75 }
76 .powerkit-manager .dashicons.status {
77 width: auto;
78 }
79 .powerkit-manager .dashicons.status:before{
80 background-color: transparent;
81 box-shadow: none;
82 font-size: initial;
83 }
84 .powerkit-manager .spinner {
85 background-size: 16px 16px;
86 float: none;
87 width: 16px;
88 height: 16px;
89 margin: 3px 4px;
90 }
91 </style>
92 <?php
93 }
94
95 /**
96 * Settings
97 */
98 public function settings_page() {
99
100 $modules = powerkit_get_modules();
101
102 $page_link = powerkit_get_page_url( $this->menu_slug, 'admin' );
103
104 // Check _wpnonce.
105 wp_verify_nonce( null );
106
107 // Filter modules.
108 if ( isset( $_GET['filter'] ) ) { // Input var ok.
109 $filter = sanitize_key( $_GET['filter'] ); // Input var ok.
110 }
111
112 // Output Message.
113 if ( $this->msg ) {
114 echo wp_kses( $this->msg, 'post' );
115 }
116 ?>
117 <div class="wrap powerkit-manager">
118 <h1><?php esc_html_e( 'Powerkit Modules', 'powerkit' ); ?></h1>
119
120 <div id="poststuff">
121 <div id="post-body" class="metabox-holder">
122 <div id="post-body-content">
123 <div class="meta-box-sortables ui-sortable">
124 <form method="post">
125 <div class="tablenav">
126 <div class="alignleft">
127 <?php
128 $active_link = add_query_arg( array(
129 '_wpnonce' => wp_create_nonce(),
130 'filter' => 'active',
131 ), $page_link );
132
133 $inactive_link = add_query_arg( array(
134 '_wpnonce' => wp_create_nonce(),
135 'filter' => 'inactive',
136 ), $page_link );
137
138 $num_modules = 0;
139 $num_active_modules = 0;
140 $num_inactive_modules = 0;
141
142 if ( $modules ) {
143 foreach ( $modules as $key => $module ) {
144 if ( ! $module['public'] ) {
145 continue;
146 }
147 $num_modules++;
148 if ( powerkit_module_enabled( $module['slug'] ) ) {
149 $num_active_modules++;
150 } else {
151 $num_inactive_modules++;
152 }
153 }
154 }
155 ?>
156 <ul class="subsubsub">
157 <li class="all"><a href="<?php echo esc_url( $page_link ); ?>" class="<?php echo esc_attr( ( ! isset( $filter ) ) ? 'current' : '' ); ?>"><?php esc_html_e( 'All', 'powerkit' ); ?> <span class="count">(<?php echo esc_attr( $num_modules ); ?>)</span></a> |</li>
158 <li class="active"><a href="<?php echo esc_url( $active_link ); ?>" class="<?php echo esc_attr( ( isset( $filter ) && 'active' === $filter ) ? 'current' : '' ); ?>"><?php esc_html_e( 'Active', 'powerkit' ); ?> <span class="count">(<?php echo esc_attr( $num_active_modules ); ?>)</span></a> |</li>
159 <li class="inactive"><a href="<?php echo esc_url( $inactive_link ); ?>" class="<?php echo esc_attr( ( isset( $filter ) && 'inactive' === $filter ) ? 'current' : '' ); ?>"><?php esc_html_e( 'Inactive', 'powerkit' ); ?> <span class="count">(<?php echo esc_attr( $num_inactive_modules ); ?>)</span></a></li>
160 </ul>
161 </div>
162 <div class="tablenav top">
163 <div class="alignleft actions bulkactions">
164 <label for="bulk-action-selector-top" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'powerkit' ); ?></label>
165 <select name="action" id="bulk-action-selector-top">
166 <option value="-1"><?php esc_html_e( 'Bulk Actions', 'powerkit' ); ?></option>
167 <option value="activate-selected"><?php esc_html_e( 'Activate', 'powerkit' ); ?></option>
168 <option value="deactivate-selected"><?php esc_html_e( 'Deactivate', 'powerkit' ); ?></option>
169 </select>
170 <input type="submit" id="doaction" class="button action" value="Apply">
171 </div>
172
173 <div class="tablenav-pages one-page">
174 <span class="displaying-num"><?php echo esc_attr( $num_modules ); ?> <?php esc_html_e( 'items', 'powerkit' ); ?></span>
175 </div>
176 </div>
177 </div>
178 <table class="wp-list-table widefat plugins">
179 <thead>
180 <tr>
181 <th id="cb" class="manage-column column-cb check-column">
182 <input id="cb-select-all-1" type="checkbox">
183 </th>
184 <th scope="col" class="manage-column column-name column-primary"><?php esc_html_e( 'Module', 'powerkit' ); ?></th>
185 <th scope="col" class="manage-column column-description"><?php esc_html_e( 'Description', 'powerkit' ); ?></th>
186 <th scope="col" class="manage-column"></th>
187 </tr>
188 </thead>
189 <tbody id="the-list">
190 <?php
191 $counter = 0;
192 // Loop modules.
193 if ( $modules ) {
194 foreach ( $modules as $key => $module ) {
195 // Public module.
196 if ( ! $module['public'] ) {
197 continue;
198 }
199
200 // Check module enabled.
201 $module_enabled = powerkit_module_enabled( $module['slug'] );
202
203 // Filter list.
204 if ( isset( $filter ) ) {
205 if ( 'active' === $filter && ! $module_enabled ) {
206 continue;
207 }
208 if ( 'inactive' === $filter && $module_enabled ) {
209 continue;
210 }
211 }
212
213 $activate_link = add_query_arg( array(
214 '_wpnonce' => wp_create_nonce(),
215 'slug' => $module['slug'],
216 'action' => 'activate',
217 ), $page_link );
218
219 $deactivate_link = add_query_arg( array(
220 '_wpnonce' => wp_create_nonce(),
221 'slug' => $module['slug'],
222 'action' => 'deactivate',
223 ), $page_link );
224
225 $counter++;
226 ?>
227 <tr class="<?php echo esc_attr( $module_enabled ? 'active' : 'inactive' ); ?>">
228 <th scope="row" class="check-column">
229 <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $module['slug'] ); ?>">
230 </th>
231 <td scope="col" class="plugin-title column-primary">
232 <strong><?php echo esc_html( $module['name'] ); ?></strong>
233
234 <div class="actions">
235 <?php if ( 'default' === $module['type'] ) { ?>
236 <?php if ( $module_enabled ) { ?>
237 <span class="edit">
238 <a href="<?php echo esc_url( $deactivate_link ); ?>" role="button"><?php esc_html_e( 'Deactivate', 'powerkit' ); ?></a>
239 </span>
240 <?php } else { ?>
241 <span class="edit">
242 <a href="<?php echo esc_url( $activate_link ); ?>" role="button"><?php esc_html_e( 'Activate', 'powerkit' ); ?></a>
243 </span>
244 <?php } ?>
245 <?php } ?>
246 </div>
247 </td>
248 <td scope="col" class="column-description desc">
249 <div class="plugin-description">
250 <p><?php echo (string) $module['desc']; // XSS. ?></p>
251 </div>
252
253 <?php
254 if ( $module_enabled && $module['links'] ) {
255 $counter = 0;
256 foreach ( $module['links'] as $link ) {
257 $counter++;
258 if ( ! isset( $link['name'] ) ) {
259 continue;
260 }
261
262 // Target of link.
263 $target = isset( $link['target'] ) ? $link['target'] : '_self';
264
265 // Output separator.
266 echo 1 < $counter ? '|' : '';
267 ?>
268 <span class="edit">
269 <a target="<?php echo esc_attr( $target ); ?>" href="<?php echo esc_url( isset( $link['url'] ) ? $link['url'] : '' ); ?>" role="button">
270 <?php echo esc_html( $link['name'] ); ?>
271 </a>
272 </span>
273 <?php
274 }
275 }
276 ?>
277 </td>
278 <td scope="col" class="manage-column">
279 <?php if ( $module['badge'] ) { ?>
280 <div class="pk-badge pk-badge-primary"><?php echo esc_attr( $module['badge'] ); ?></div>
281 <?php } ?>
282 </td>
283 </tr>
284 <?php
285 }
286 }
287
288 if ( ! $counter ) {
289 ?>
290 <tr>
291 <td scope="col" colspan="4"><?php esc_html_e( 'No modules avaliable.', 'powerkit' ); ?></td>
292 </tr>
293 <?php
294 }
295 ?>
296 </tbody>
297 </table>
298 <?php wp_nonce_field(); ?>
299 </form>
300
301 <script>
302 if ( window.history.replaceState ) {
303 if ( window.location.href.indexOf( 'action=' ) >= 0 ) {
304 window.history.pushState( null, '', '<?php echo esc_url( $page_link ); ?>' );
305 }
306 }
307 </script>
308 </div>
309 </div>
310 </div>
311 </div>
312 </div>
313 <?php
314 }
315
316 /**
317 * Handler actions.
318 */
319 public function handler_actions() {
320
321 // Check wpnonce.
322 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
323 return;
324 }
325
326 if ( ! isset( $_REQUEST['action'] ) ) { // Input var ok; sanitization ok.
327 return;
328 }
329
330 $action = sanitize_title( $_REQUEST['action'] ); // Input var ok; sanitization ok.
331
332 // Bulk Actions.
333 if ( isset( $_REQUEST['checked'] ) && is_array( $_REQUEST['checked'] ) ) { // Input var ok; sanitization ok.
334 $checked = $_REQUEST['checked']; // Input var ok; sanitization ok.
335
336 foreach ( $checked as $slug ) {
337 if ( 'activate-selected' === $action ) {
338 $this->set_module_state( $slug, 1 );
339 } elseif ( 'deactivate-selected' === $action ) {
340 $this->set_module_state( $slug, 0 );
341 }
342 }
343 }
344
345 if ( ! isset( $_REQUEST['slug'] ) ) { // Input var ok.
346 return;
347 }
348
349 $slug = sanitize_key( $_REQUEST['slug'] ); // Input var ok.
350
351 // Activate module.
352 if ( 'activate' === $action && $slug ) {
353 $this->set_module_state( $slug, 1 );
354 }
355
356 // Deactivate module.
357 if ( 'deactivate' === $action && $slug ) {
358 $this->set_module_state( $slug, 0 );
359 }
360 }
361
362 /**
363 * Set state module.
364 *
365 * @param string $slug The slug module.
366 * @param bool $state The state module.
367 */
368 public function set_module_state( $slug, $state ) {
369 update_option( sprintf( 'powerkit_enabled_%s', $slug ), $state );
370
371 if ( $state ) {
372 $this->msg = sprintf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Module activated.', 'powerkit' ) );
373 } else {
374 $this->msg = sprintf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Module deactivated.', 'powerkit' ) );
375 }
376 }
377 }
378
379 new Admin_Powerkit_Manager();
380