PluginProbe
Powerkit – Supercharge your WordPress Site / 2.7.4
Powerkit – Supercharge your WordPress Site v2.7.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.7.4, at admin/class-admin-powerkit-manager.php

386 lines 13.2 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
97 /**
98 * Settings
99 */
100 public function settings_page() {
101
102 powerkit_uuid_hash();
103
104 $modules = powerkit_get_modules();
105
106 $page_link = powerkit_get_page_url( $this->menu_slug, 'admin' );
107
108 // Check wpnonce.
109 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
110 return;
111 }
112
113 // Filter modules.
114 if ( isset( $_REQUEST['filter'] ) ) { // Input var ok.
115 $filter = sanitize_key( $_REQUEST['filter'] ); // Input var ok.
116 }
117
118 // Output Message.
119 if ( $this->msg ) {
120 echo wp_kses( $this->msg, 'post' );
121 }
122 ?>
123 <div class="wrap powerkit-manager">
124 <h1><?php esc_html_e( 'Powerkit Modules', 'powerkit' ); ?></h1>
125
126 <div id="poststuff">
127 <div id="post-body" class="metabox-holder">
128 <div id="post-body-content">
129 <div class="meta-box-sortables ui-sortable">
130 <form method="post">
131 <div class="tablenav">
132 <div class="alignleft">
133 <?php
134 $active_link = add_query_arg( array(
135 '_wpnonce' => wp_create_nonce(),
136 'filter' => 'active',
137 ), $page_link );
138
139 $inactive_link = add_query_arg( array(
140 '_wpnonce' => wp_create_nonce(),
141 'filter' => 'inactive',
142 ), $page_link );
143
144 $num_modules = 0;
145 $num_active_modules = 0;
146 $num_inactive_modules = 0;
147
148 if ( $modules ) {
149 foreach ( $modules as $key => $module ) {
150 if ( ! $module['public'] ) {
151 continue;
152 }
153 $num_modules++;
154 if ( powerkit_module_enabled( $module['slug'] ) ) {
155 $num_active_modules++;
156 } else {
157 $num_inactive_modules++;
158 }
159 }
160 }
161 ?>
162 <ul class="subsubsub">
163 <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>
164 <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>
165 <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>
166 </ul>
167 </div>
168 <div class="tablenav top">
169 <div class="alignleft actions bulkactions">
170 <label for="bulk-action-selector-top" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'powerkit' ); ?></label>
171 <select name="action" id="bulk-action-selector-top">
172 <option value="-1"><?php esc_html_e( 'Bulk Actions', 'powerkit' ); ?></option>
173 <option value="activate-selected"><?php esc_html_e( 'Activate', 'powerkit' ); ?></option>
174 <option value="deactivate-selected"><?php esc_html_e( 'Deactivate', 'powerkit' ); ?></option>
175 </select>
176 <input type="submit" id="doaction" class="button action" value="Apply">
177 </div>
178
179 <div class="tablenav-pages one-page">
180 <span class="displaying-num"><?php echo esc_attr( $num_modules ); ?> <?php esc_html_e( 'items', 'powerkit' ); ?></span>
181 </div>
182 </div>
183 </div>
184 <table class="wp-list-table widefat plugins">
185 <thead>
186 <tr>
187 <th id="cb" class="manage-column column-cb check-column">
188 <input id="cb-select-all-1" type="checkbox">
189 </th>
190 <th scope="col" class="manage-column column-name column-primary"><?php esc_html_e( 'Module', 'powerkit' ); ?></th>
191 <th scope="col" class="manage-column column-description"><?php esc_html_e( 'Description', 'powerkit' ); ?></th>
192 <th scope="col" class="manage-column"></th>
193 </tr>
194 </thead>
195 <tbody id="the-list">
196 <?php
197 $counter = 0;
198 // Loop modules.
199 if ( $modules ) {
200 foreach ( $modules as $key => $module ) {
201 // Public module.
202 if ( ! $module['public'] ) {
203 continue;
204 }
205
206 // Check module enabled.
207 $module_enabled = powerkit_module_enabled( $module['slug'] );
208
209 // Filter list.
210 if ( isset( $filter ) ) {
211 if ( 'active' === $filter && ! $module_enabled ) {
212 continue;
213 }
214 if ( 'inactive' === $filter && $module_enabled ) {
215 continue;
216 }
217 }
218
219 $activate_link = add_query_arg( array(
220 '_wpnonce' => wp_create_nonce(),
221 'slug' => $module['slug'],
222 'action' => 'activate',
223 ), $page_link );
224
225 $deactivate_link = add_query_arg( array(
226 '_wpnonce' => wp_create_nonce(),
227 'slug' => $module['slug'],
228 'action' => 'deactivate',
229 ), $page_link );
230
231 $counter++;
232 ?>
233 <tr class="<?php echo esc_attr( $module_enabled ? 'active' : 'inactive' ); ?>">
234 <th scope="row" class="check-column">
235 <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $module['slug'] ); ?>">
236 </th>
237 <td scope="col" class="plugin-title column-primary">
238 <strong><?php echo esc_html( $module['name'] ); ?></strong>
239
240 <div class="actions">
241 <?php if ( 'default' === $module['type'] ) { ?>
242 <?php if ( $module_enabled ) { ?>
243 <span class="edit">
244 <a href="<?php echo esc_url( $deactivate_link ); ?>" role="button"><?php esc_html_e( 'Deactivate', 'powerkit' ); ?></a>
245 </span>
246 <?php } else { ?>
247 <span class="edit">
248 <a href="<?php echo esc_url( $activate_link ); ?>" role="button"><?php esc_html_e( 'Activate', 'powerkit' ); ?></a>
249 </span>
250 <?php } ?>
251 <?php } ?>
252 </div>
253 </td>
254 <td scope="col" class="column-description desc">
255 <div class="plugin-description">
256 <p><?php echo esc_html( $module['desc'] ); ?></p>
257 </div>
258
259 <?php
260 if ( $module_enabled && $module['links'] ) {
261 $counter = 0;
262 foreach ( $module['links'] as $link ) {
263 $counter++;
264 if ( ! isset( $link['name'] ) ) {
265 continue;
266 }
267
268 // Target of link.
269 $target = isset( $link['target'] ) ? $link['target'] : '_self';
270
271 // Output separator.
272 echo 1 < $counter ? '|' : '';
273 ?>
274 <span class="edit">
275 <a target="<?php echo esc_attr( $target ); ?>" href="<?php echo esc_url( isset( $link['url'] ) ? $link['url'] : '' ); ?>" role="button">
276 <?php echo esc_html( $link['name'] ); ?>
277 </a>
278 </span>
279 <?php
280 }
281 }
282 ?>
283 </td>
284 <td scope="col" class="manage-column">
285 <?php if ( $module['badge'] ) { ?>
286 <div class="pk-badge pk-badge-primary"><?php echo esc_attr( $module['badge'] ); ?></div>
287 <?php } ?>
288 </td>
289 </tr>
290 <?php
291 }
292 }
293
294 if ( ! $counter ) {
295 ?>
296 <tr>
297 <td scope="col" colspan="4"><?php esc_html_e( 'No modules avaliable.', 'powerkit' ); ?></td>
298 </tr>
299 <?php
300 }
301 ?>
302 </tbody>
303 </table>
304 <?php wp_nonce_field(); ?>
305 </form>
306
307 <script>
308 if ( window.history.replaceState ) {
309 if ( window.location.href.indexOf( 'action=' ) >= 0 ) {
310 window.history.pushState( null, '', '<?php echo esc_url( $page_link ); ?>' );
311 }
312 }
313 </script>
314 </div>
315 </div>
316 </div>
317 </div>
318 </div>
319 <?php
320 }
321
322 /**
323 * Handler actions.
324 */
325 public function handler_actions() {
326
327 // Check wpnonce.
328 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
329 return;
330 }
331
332 if ( ! isset( $_REQUEST['action'] ) ) { // Input var ok; sanitization ok.
333 return;
334 }
335
336 $action = sanitize_title( $_REQUEST['action'] ); // Input var ok; sanitization ok.
337
338 // Bulk Actions.
339 if ( isset( $_REQUEST['checked'] ) && is_array( $_REQUEST['checked'] ) ) { // Input var ok; sanitization ok.
340 $checked = array_map( 'sanitize_key', $_REQUEST['checked'] ); // Input var ok; sanitization ok.
341
342 foreach ( $checked as $slug ) {
343 if ( 'activate-selected' === $action ) {
344 $this->set_module_state( $slug, 1 );
345 } elseif ( 'deactivate-selected' === $action ) {
346 $this->set_module_state( $slug, 0 );
347 }
348 }
349 }
350
351 if ( ! isset( $_REQUEST['slug'] ) ) { // Input var ok.
352 return;
353 }
354
355 $slug = sanitize_key( $_REQUEST['slug'] ); // Input var ok.
356
357 // Activate module.
358 if ( 'activate' === $action && $slug ) {
359 $this->set_module_state( $slug, 1 );
360 }
361
362 // Deactivate module.
363 if ( 'deactivate' === $action && $slug ) {
364 $this->set_module_state( $slug, 0 );
365 }
366 }
367
368 /**
369 * Set state module.
370 *
371 * @param string $slug The slug module.
372 * @param bool $state The state module.
373 */
374 public function set_module_state( $slug, $state ) {
375 update_option( sprintf( 'powerkit_enabled_%s', $slug ), $state );
376
377 if ( $state ) {
378 $this->msg = sprintf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Module activated.', 'powerkit' ) );
379 } else {
380 $this->msg = sprintf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Module deactivated.', 'powerkit' ) );
381 }
382 }
383 }
384
385 new Admin_Powerkit_Manager();
386