PluginProbe
Plugin Load Filter / 2.4.1
Plugin Load Filter v2.4.1
trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.3.1 2.4.0 2.4.1 2.5.1 3.3.0 4.0.6 4.1.1 4.2.0 4.3.0 4.3.1 4.4.0
plugin-load-filter / plugin-load-filter.php

plugin-load-filter.php in Plugin Load Filter 2.4.1, at plugin-load-filter.php

834 lines 42.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: plugin load filter
4 Description: Dynamically activate the selected plugins for each page. Response will be faster by filtering plugins.
5 Version: 2.4.1
6 Plugin URI: http://celtislab.net/wp_plugin_load_filter
7 Author: enomoto@celtislab
8 Author URI: http://celtislab.net/
9 License: GPLv2
10 Text Domain: plf
11 Domain Path: /languages
12 */
13 defined( 'ABSPATH' ) || exit;
14
15 /***************************************************************************
16 * plugin activation / deactivation / uninstall
17 **************************************************************************/
18 if(is_admin()){
19 function plugin_load_filter_activation( $network_wide ) {
20 //plf-filter must-use plagin activete check
21 if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
22 if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
23 @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
24 }
25 else {
26 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
27 $dp = get_plugin_data( WPMU_PLUGIN_DIR . "/plf-filter.php", false, false );
28 $sp = get_plugin_data( __DIR__ . '/mu-plugins/plf-filter.php', false, false );
29 if(version_compare( $dp['Version'], $sp['Version'], '!=')){
30 @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
31 }
32 }
33 }
34 }
35 register_activation_hook( __FILE__, 'plugin_load_filter_activation' );
36
37 //deactivation
38 function plugin_load_filter_deactivation( $network_deactivating ) {
39 $act = false;
40 if (is_multisite()) {
41 if(! $network_deactivating){
42 global $wpdb;
43 $current_blog_id = get_current_blog_id();
44 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
45 foreach ( $blog_ids as $blog_id ) {
46 if($blog_id == $current_blog_id){
47 //current site
48 }
49 else {
50 //other site active check
51 switch_to_blog( $blog_id );
52 if ( is_plugin_active( plugin_basename( __FILE__ )))
53 $act = true;
54 }
55 }
56 switch_to_blog( $current_blog_id );
57 }
58 }
59 if($act === false){
60 flush_rewrite_rules(); //options data 'rewrite_rules' clear for remake.
61 if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
62 @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
63 }
64 }
65 }
66 register_deactivation_hook( __FILE__, 'plugin_load_filter_deactivation' );
67
68 //uninstall
69 function plugin_load_filter_uninstall() {
70
71 if ( !is_multisite()) {
72 delete_option('plf_queryvars');
73 delete_option('plf_option' );
74 } else {
75 global $wpdb;
76 $current_blog_id = get_current_blog_id();
77 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
78 foreach ( $blog_ids as $blog_id ) {
79 switch_to_blog( $blog_id );
80 delete_option('plf_queryvars');
81 delete_option('plf_option' );
82 }
83 switch_to_blog( $current_blog_id );
84 }
85 if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
86 @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
87 }
88 }
89 register_uninstall_hook(__FILE__, 'plugin_load_filter_uninstall');
90
91 }
92
93 $Plf_setting = new Plf_setting();
94
95 class Plf_setting {
96
97 private $plugins_inf = ''; //active plugin/module infomation
98 private $filter = array(); //filter option data
99 private $tab_num = 0;
100
101 /***************************************************************************
102 * Style Sheet
103 **************************************************************************/
104 function plf_css() { ?>
105 <style type="text/css">
106 #activation-table { margin-top: 10px; border: 1px solid #eee;}
107 #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
108 thead .plugins-name { background-color: aliceblue;}
109 thead .device-type { background-color: oldlace;}
110 thead .plugins-name, tbody .plugins-name { min-width: 172px; max-width: 172px;}
111 thead .device-type, tbody .device-type { min-width: 36px; max-width: 36px; padding: 0;}
112 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
113 .device-type label { color: whitesmoke; margin-left: -28px; }
114 .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
115 </style>
116 <?php }
117
118 function jquery_tab_css() { ?>
119 <style type="text/css">
120 .ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.5; text-decoration: none; font-size: 100%; list-style: none; }
121 .ui-helper-clearfix:before, .ui-helper-clearfix:after { content: ""; display: table; }
122 .ui-helper-clearfix:after { clear: both; }
123 .ui-helper-clearfix { zoom: 1; }
124 .ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */
125 .ui-tabs .ui-tabs-nav { margin: 1px 8px; padding: .2em .2em; }
126 .ui-tabs .ui-tabs-nav li { list-style: none; float: left; position: relative; top: 0; margin: 1px .3em 0 0; border-bottom: 0; padding: 0; white-space: nowrap; }
127 .ui-tabs .ui-tabs-nav li a { float: left; text-decoration: none; }
128 .ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: -1px; padding-bottom: 1px; }
129 .ui-tabs .ui-tabs-panel { display: block; border-width: 0; background: none; }
130 .ui-tabs .ui-tabs-nav a { margin: 8px 10px; }
131 .ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #dddddd; background-color: #f4f4f4; font-weight: bold; color: #0073ea; }
132 .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #0073ea; text-decoration: none; }
133 .ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus { border: 1px solid #0073ea; background-color: #0073ea; font-weight: bold; color: #ffffff; }
134 .ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #dddddd; background-color: #0073ea; font-weight: bold; color: #ffffff; }
135 .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; }
136 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
137
138 #wrap_registration-table, #wrap_activation-table { overflow-x:auto;}
139 #registration-table input[type=radio], #activation-table input[type=checkbox] { height: 25px; width: 25px; opacity: 0;}
140 thead, tbody { display: block;}
141 .plugins-table-body { overflow-y:scroll; height:500px; }
142 .widefat td, .widefat th { padding: 8px 4px;}
143 thead .filter-plugins-name, thead .plugins-name { background-color: aliceblue;}
144 .filter-none, .filter-admin, .filter-tmpl { background-color: oldlace;}
145 thead .device-type { background-color: oldlace;}
146 thead .tmpl-type { background-color: lavender;}
147 thead .pformat { background-color: honeydew;}
148 thead .tmpl-embed { background-color: lightyellow;}
149 thead .tmpl-custom { background-color: lavenderblush;}
150 thead .filter-plugins-name, tbody .filter-plugins-name { min-width: 260px; max-width: 260px;}
151 thead .plugins-name, tbody .plugins-name { min-width: 180px; max-width: 180px;}
152 thead .filter-type, tbody .filter-type { min-width: 100px; max-width: 100px;}
153 thead .device-type, tbody .device-type, thead .tmpl-type, tbody .tmpl-type { min-width: 40px; max-width: 40px; }
154 .filter-description { padding: 0 10px 20px 10px;}
155 .exclude-pformat { padding: 16px 0 20px}
156 .exclude-pformat label { white-space:nowrap;}
157 .exclude-pformat span { margin-right: 12px; }
158 .dashicons:before { font-size: 24px; }
159 .radio-green label, .radio-red label, .tmpl-type label { color: #ddd; margin-left: -28px; }
160 .radio-green input[type="radio"]:checked + label { color: #339966; }
161 .radio-red input[type="radio"]:checked + label { color: #ff0000; }
162 .tmpl-type input[type="checkbox"]:checked + label { color: #339966; }
163 .dashicons-yes:before { font-size: 20px; border: 1px solid #eee; background-color: whitesmoke;}
164 .device-type label { color: whitesmoke; margin-left: -28px; }
165 .device-type input[type="checkbox"]:checked + label .dashicons-yes:before { background-color: yellowgreen; }
166 </style>
167 <?php }
168
169 /***************************************************************************
170 * Plugin Load Filter Option Setting
171 **************************************************************************/
172
173 public function __construct() {
174
175 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
176
177 $this->filter = get_option('plf_option');
178 //v2.3.0 option change
179 if(empty($this->filter['optver']) || $this->filter['optver'] < '2'){
180 $this->filter['optver'] = '2';
181
182 if(empty($this->filter['group']['desktop']) && empty($this->filter['group']['mobile'])){
183 //For ver2.2.0 compatibility, set '_pagefilter' data to 'desktop' and 'mobile'
184 if(!empty($this->filter['_pagefilter'])){
185 $this->filter['group']['desktop'] = $this->filter['_pagefilter'];
186 $this->filter['group']['mobile'] = $this->filter['_pagefilter'];
187 }
188 if(!empty($this->filter['_desktop'])){
189 $this->filter['_desktop'] = null;
190 }
191 if(!empty($this->filter['_mobile'])){
192 $this->filter['_mobile'] = null;
193 }
194 }
195 }
196
197 if(is_admin()) {
198 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
199 add_action( 'admin_init', array(&$this, 'action_posts'));
200 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
201 }
202 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
203 }
204
205 //Plugin Load Filter admin setting start
206 public function plf_admin_start() {
207 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
208
209 $this->plugins_inf = get_plugins();
210 $packplug = array();
211 foreach ( $this->plugins_inf as $plugin_key => $a_plugin ) {
212 if(is_plugin_inactive( $plugin_key )){
213 unset($this->plugins_inf[$plugin_key]);
214 }
215 }
216 //jetpack active module
217 if(method_exists('Jetpack', 'get_module')){
218 $modules = Jetpack::get_active_modules();
219 $modules = array_diff( $modules, array( 'vaultpress' ) );
220 foreach ( $modules as $key => $module_name ) {
221 if(!empty($module_name)){
222 $module = Jetpack::get_module( $module_name );
223 if(!empty($module))
224 $this->plugins_inf['jetpack_module/' . $module_name] = $module;
225 }
226 }
227 }
228 //celtispack active module
229 if(method_exists('Celtispack', 'get_module')){
230 $modules = Celtispack::get_active_modules();
231 foreach ( $modules as $key => $module_name ) {
232 if(!empty($module_name)){
233 $this->plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
234 }
235 }
236 }
237 if ( empty( $this->plugins_inf ) )
238 return;
239
240 add_action('admin_menu', array(&$this, 'plf_option_menu'));
241 }
242
243 //Plugins sub menu add
244 public function plf_option_menu() {
245 $page = add_plugins_page( 'Plugin Load Filter', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this,'plf_option_page'));
246 add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts'));
247 }
248
249 //Plugin Load Filter setting page script
250 function plf_scripts() {
251 wp_enqueue_script( 'jquery' );
252 wp_enqueue_script( 'jquery-ui-core' );
253 wp_enqueue_script( 'jquery-ui-widget' );
254 wp_enqueue_script( 'jquery-ui-tabs' );
255 add_action( 'admin_head', array(&$this, 'plf_css' ));
256 add_action( 'admin_head', array(&$this, 'jquery_tab_css' ));
257 add_action( 'admin_footer', array(&$this, 'activetab_script' ));
258 }
259
260 //plugin filter option action request (add, update, delete)
261 function action_posts() {
262 if (current_user_can( 'activate_plugins' )) {
263 if( isset($_POST['edit_regist_filter']) ) {
264 if(isset($_POST['plfregist'])){
265 check_admin_referer('plugin_load_filter');
266 foreach( array('_admin', '_pagefilter') as $item){
267 $plugins = array();
268 foreach ( $_POST['plfregist'] as $p_key => $val ) {
269 if($val == $item)
270 $plugins[$p_key] = $val;
271 }
272 if($item == '_pagefilter'){
273 //If all modules is specified filter, in some cases you want to deactivate plugin itself.
274 $jbase = $cbase = '';
275 $jall = $call = true;
276 foreach ( $_POST['plfregist'] as $p_key => $val ) {
277 if(strpos($p_key, 'jetpack/') !== false)
278 $jbase = $p_key;
279 else if(strpos($p_key, 'celtispack/') !== false)
280 $cbase = $p_key;
281 else if(strpos($p_key, 'jetpack_module/') !== false){
282 if($val != '_pagefilter' && $val != '_admin'){
283 $jall = false;
284 }
285 }
286 else if(strpos($p_key, 'celtispack_module/') !== false){
287 if($val != '_pagefilter' && $val != '_admin')
288 $call = false;
289 }
290 }
291 if(!empty($jbase) && $jall === false)
292 unset($plugins[$jbase]);
293 if(!empty($cbase) && $call === false)
294 unset($plugins[$cbase]);
295 }
296 $option["plugins"] = implode(",", array_keys($plugins));
297 $this->filter[$item] = $option;
298 }
299 if(isset($_POST['plf_option']['exclude'])){
300 $exclude = array();
301 foreach ( $_POST['plf_option']['exclude'] as $ft => $v ) {
302 if(!empty($v))
303 $exclude[$ft] = true;
304 }
305 $this->filter['exclude'] = $exclude;
306 }
307 else {
308 $this->filter['exclude'] = '';
309 }
310 update_option('plf_option', $this->filter );
311 }
312 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
313 exit;
314 }
315 elseif( isset($_POST['clear_regist_filter']) ) {
316 check_admin_referer('plugin_load_filter');
317 foreach( array('_admin', '_pagefilter') as $item){
318 $this->filter[$item] = '';
319 }
320 $this->filter['exclude'] = '';
321 update_option('plf_option', $this->filter );
322 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
323 exit;
324 }
325 else if(isset($_POST['edit_activate_page_filter']) ) {
326 if(isset($_POST['plfactive'])){
327 check_admin_referer('plugin_load_filter');
328 $group = array_keys($_POST['plfactive']);
329 foreach( $group as $item){
330 $plugins = array();
331 foreach ( $_POST['plfactive'][$item] as $p_key => $val ) {
332 if($val == '1')
333 $plugins[] = $p_key;
334 }
335 $option["plugins"] = implode(",", $plugins);
336 $this->filter['group'][$item] = $option;
337 }
338 update_option('plf_option', $this->filter );
339 }
340 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
341 exit;
342 }
343 elseif( isset($_POST['clear_activate_page_filter']) ) {
344 check_admin_referer('plugin_load_filter');
345 $group = array_keys($_POST['plfactive']);
346 foreach( $group as $item){
347 $this->filter['group'][$item] = '';
348 }
349 update_option('plf_option', $this->filter );
350 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
351 exit;
352 }
353 if(!empty($_GET['action']) && $_GET['action']=='tab_1') {
354 $this->tab_num = 1;
355 }
356 }
357 }
358
359 //Plugin or Module key to name
360 // $type : list/smart/tree
361 public function pluginkey_to_name( $infkey, $type='list') {
362
363 $name = '';
364 if(strpos($infkey, 'jetpack_module/') !== false){
365 if(!empty($this->plugins_inf[$infkey]['name'])){
366 $m_mark = ($type !== 'list')? '-' : 'Jetpack-';
367 if($type === 'smart') {
368 if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'jetpack/') === false)
369 $name = $m_mark . $this->plugins_inf[$infkey]['name'];
370 }
371 else
372 $name = $m_mark . $this->plugins_inf[$infkey]['name'];
373 }
374 }
375 elseif(strpos($infkey, 'celtispack_module/') !== false){
376 if(!empty($this->plugins_inf[$infkey]['Name'])){
377 $m_mark = ($type !== 'list')? '-' : 'Celtispack-';
378 if($type === 'smart') {
379 if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'celtispack/') === false)
380 $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
381 }
382 else
383 $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
384 }
385 }
386 else {
387 if(!empty($this->plugins_inf[$infkey]['Name']))
388 $name = $this->plugins_inf[$infkey]['Name'];
389 }
390 return($name);
391 }
392
393 //Checkbox
394 static function checkbox($name, $value, $label = '') {
395 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
396 }
397 static function altcheckbox($name, $value, $label = '') {
398 return "<input type='hidden' name='$name' value='0'><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/><label> $label</label>";
399 }
400
401 public function plfregist_item($key, $val) {
402 $p_name = $this->pluginkey_to_name($key);
403 $opt_name = "plfregist[$key]";
404 ?>
405 <tr id="plfregist_<?php echo $key; ?>">
406 <td class="filter-plugins-name"><?php echo $p_name; ?></td>
407 <td class="radio-green filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value='' <?php checked('', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
408 <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_admin" <?php checked('_admin', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
409 <td class="radio-red filter-type"><input type="radio" name="<?php echo $opt_name; ?>" value="_pagefilter" <?php checked('_pagefilter', $val); ?>/><label><span class="dashicons dashicons-admin-plugins"></span></label></td>
410 </tr>
411 <?php
412 }
413
414 //Filterring plugins select
415 public function plfregist_table($plugins, $filter) {
416 ?>
417 <div id="wrap_registration-table">
418 <table id="registration-table" class="widefat">
419 <thead>
420 <tr><th class="filter-plugins-name"><?php _e('Plugins'); ?></th>
421 <th class="filter-type filter-none"><?php _e('Normal Load', 'plf'); ?></th>
422 <th class="filter-type filter-admin"><?php _e('Admin Filter', 'plf'); ?></th>
423 <th class="filter-type filter-tmpl"><?php _e('Page Filter', 'plf'); ?></th>
424 </tr>
425 </thead>
426 <tbody class="plugins-table-body">
427 <?php
428 //plugins filter registoration table
429 $plist = array();
430 foreach ( $plugins as $p_key => $val ) {
431 $name = $this->pluginkey_to_name($p_key);
432 if(!empty($name))
433 $plist[$p_key] = '';
434 }
435 foreach( array('_admin', '_pagefilter') as $item){
436 $parr = (!empty($filter[$item]['plugins'])) ? array_map("trim", explode(',', $filter[$item]['plugins'])) : array();
437 foreach ( $plist as $p_key => $val ) {
438 if(empty($val) && in_array($p_key, $parr))
439 $plist[$p_key] = $item;
440 }
441 }
442 $jlist = $clist = array();
443 foreach ( $plist as $p_key => $val ) {
444 if(strpos($p_key, 'jetpack_module/') !== false){
445 $jlist[$p_key] = $plist[$p_key];
446 unset($plist[$p_key]);
447 }
448 else if(strpos($p_key, 'celtispack_module/') !== false){
449 $clist[$p_key] = $plist[$p_key];
450 unset($plist[$p_key]);
451 }
452 }
453 foreach ( $plist as $p_key => $val ) {
454 $modules = array();
455 if(strpos($p_key, 'jetpack/') !== false)
456 $modules = $jlist;
457 else if(strpos($p_key, 'celtispack/') !== false)
458 $modules = $clist;
459 else
460 $this->plfregist_item($p_key, $val);
461 if(!empty($modules)){
462 echo "<input type='hidden' name='plfregist[$p_key]' value='_pagefilter'>";
463 foreach ( $modules as $m_key => $val) {
464 $this->plfregist_item($m_key, $val);
465 }
466 }
467 }
468 ?>
469 </tbody>
470 </table>
471 <br />
472 <p><strong>[ Admin Filter ]</strong></p>
473 <div class="filter-description"><?php _e('Plugins to be used only in admin mode.', 'plf'); ?></div>
474 <p><strong>[ Page Filter ]</strong></p>
475 <div class="filter-description">
476 <?php _e('Plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
477 <?php _e('Selected page filter plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?>
478 <div class="exclude-pformat">
479 <p><strong><?php _e( 'Exclude Post Format Type', 'plf' ); ?></strong><br />
480 <?php _e('Choose Post Format Type you are not using. To exclude from Page Filter item subject.', 'plf'); ?>
481 </p>
482 <?php
483 $html = '<div>';
484 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
485 foreach ( $pformat as $type ) {
486 $checked = (!empty($this->filter['exclude'][$type]))? $this->filter['exclude'][$type] : false;
487 $label = "<span>$type</span>";
488 $html .= self::checkbox("plf_option[exclude][$type]", $checked, $label);
489 }
490 $html .= '</div>';
491 echo $html;
492 ?>
493 </div>
494 </div>
495 </div>
496 <?php
497 }
498
499 //Activate plugins select from Page Filter
500 public function _plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter) {
501
502 $selplugins = array_map("trim", explode(',', $select_cvplugins));
503 $devlist = array('desktop','mobile');
504 if(in_array( $p_key, $selplugins )){
505 $p_name = $this->pluginkey_to_name($p_key);
506 echo "<tr><td class='plugins-name'>$p_name</td>";
507 foreach($devlist as $devtype){
508 $checked = (empty($filter['group'][$devtype]['plugins']) || false === strpos($filter['group'][$devtype]['plugins'], $p_key))? false : true;
509 echo '<td class="device-type">' . self::altcheckbox("plfactive[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
510 }
511 foreach($chklist as $pgtype){
512 $checked = (empty($filter['group'][$pgtype]['plugins']) || false === strpos($filter['group'][$pgtype]['plugins'], $p_key))? false : true;
513 echo '<td class="tmpl-type">' . self::altcheckbox("plfactive[$pgtype][$p_key]", $checked, '<span class="dashicons dashicons-admin-plugins"></span>') . '</td>';
514 }
515 echo "</tr>";
516 }
517 }
518
519 public function plfactive_table($plugins, $select_cvplugins, $filter) {
520 if(empty($select_cvplugins))
521 return;
522
523 ?>
524 <div id="wrap_activation-table">
525 <table id="activation-table" class="widefat">
526 <thead>
527 <tr><th class="plugins-name"><?php _e('Plugins'); ?></th>
528 <th class="device-type"><span title="<?php _e('Desktop Device', 'plf'); ?>" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>
529 <th class="device-type"><span title="<?php _e('Mobile Device', 'plf'); ?>" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>
530 <th class="tmpl-type"><span title="<?php _e('Home/Front-page', 'plf'); ?>" class="dashicons dashicons-admin-home"></span><br /><span style="font-size:xx-small">Home</span></th>
531 <th class="tmpl-type"><span title="<?php _e('Archive page', 'plf'); ?>" class="dashicons dashicons-list-view"></span><br /><span style="font-size:xx-small">Archive</span></th>
532 <th class="tmpl-type"><span title="<?php _e('Search page', 'plf'); ?>" class="dashicons dashicons-search"></span><br /><span style="font-size:xx-small">Search</span></th>
533 <th class="tmpl-type"><span title="<?php _e('Attachment page', 'plf'); ?>" class="dashicons dashicons-media-default"></span><br /><span style="font-size:xx-small">Attach</span></th>
534 <th class="tmpl-type"><span title="<?php _e('Page', 'plf'); ?>" class="dashicons dashicons-admin-page"></span><br /><span style="font-size:xx-small">Page</span></th>
535 <th class="tmpl-type pformat"><span title="<?php _e('Post : ', 'plf'); _e('Standard', 'plf'); ?>" class="dashicons dashicons-admin-post"></span><br /><span style="font-size:xx-small">Post</span></th>
536 <?php
537 $pformat = array('image', 'gallery', 'video', 'audio', 'aside', 'status', 'quote', 'link', 'chat' );
538 $exclude = array();
539 if(!empty($filter['exclude'])){
540 foreach ( $filter['exclude'] as $type => $v) {
541 if(!empty($v)){
542 $exclude[] = $type;
543 }
544 }
545 }
546 foreach ( $pformat as $type) {
547 if(!in_array($type, $exclude)){
548 $title = __('Post : ', 'plf') . $type;
549 $icon = ($type === "link")? "dashicons-admin-links" : "dashicons-format-$type";
550 echo '<th class="tmpl-type pformat"><span title="' . $title . '" class="dashicons ' . $icon .'"></span><br /><span style="font-size:xx-small">' . $type .'</span></th>';
551 }
552 }
553 if(function_exists('is_embed')){
554 $title = __('WordPress Embed Content Card (API)', 'plf');
555 echo "<th class='tmpl-type tmpl-embed'><span title='$title' style='font-size:xx-small'>Embed Content</span></th>";
556 }
557 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
558 foreach ( $post_types as $post_type ) {
559 if(!empty($post_type)){
560 $title = __('Custom Post : ', 'plf') . $post_type;
561 echo "<th class='tmpl-type tmpl-custom'><span title='$title' style='font-size:xx-small'>$post_type</span></th>";
562 }
563 }
564 ?>
565 </tr>
566 </thead>
567 <tbody class="plugins-table-body">
568 <?php
569 $nplugins = $jmodules = $cmodules = $allmodule = array();
570 foreach ( $plugins as $p_key => $p_data ) {
571 $p_name = $this->pluginkey_to_name($p_key);
572 if(empty($p_name))
573 continue;
574 if(strpos($p_key, 'jetpack_module/') !== false)
575 $jmodules[] = $p_key;
576 else if(strpos($p_key, 'celtispack_module/') !== false)
577 $cmodules[] = $p_key;
578 else
579 $nplugins[] = $p_key;
580 }
581 $chklist = array('home', 'archive', 'search', 'attachment', 'page', 'post');
582 foreach ( $pformat as $type) {
583 if(!in_array($type, $exclude)){
584 $chklist[] = "post-$type";
585 }
586 }
587 if(function_exists('is_embed')){
588 $chklist[] = 'content-card';
589 }
590 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
591 foreach ( $post_types as $post_type ) {
592 $chklist[] = $post_type;
593 }
594 foreach ( $nplugins as $p_key ) {
595 if(strpos($p_key, 'jetpack/') !== false){
596 foreach ( $jmodules as $p_key ) {
597 $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
598 }
599 }
600 else if(strpos($p_key, 'celtispack/') !== false){
601 foreach ( $cmodules as $p_key ) {
602 $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
603 }
604 }
605 else {
606 $this->_plfactive_checkbox_row($p_key, $select_cvplugins, $chklist, $filter);
607 }
608 }
609 ?>
610 </tbody>
611 </table>
612 </div>
613 <?php
614 }
615
616 //Option Setting Form Display
617 public function plf_option_page() {
618 ?>
619 <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2>
620 <p></p>
621 <div id="plf-setting-tabs">
622 <ul>
623 <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
624 <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
625 </ul>
626 <form method="post" autocomplete="off">
627 <?php wp_nonce_field( 'plugin_load_filter'); ?>
628 <div id="plf-registration-tab" style="display : none;">
629 <?php $this->plfregist_table($this->plugins_inf, $this->filter); ?>
630 <p class="submit">
631 <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
632 <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Filter Entry &raquo;', 'plf'); ?>" />
633 </p>
634 </div>
635 <div id="plf-activation-tab" style="display : none;">
636 <?php
637 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
638 if(!empty($pgfilter)){
639 $this->plfactive_table($this->plugins_inf, $pgfilter, $this->filter);
640 ?>
641 <br />
642 <p><?php _e('Select plugins to be activated for each page type by clicking on <span class="dashicons dashicons-admin-plugins"></span> mark from "page filter" registered plugins.', 'plf') ?><br />
643 <?php _e('You can also select plugins to activate from Post/Page content editing screen.', 'plf') ?>
644 </p>
645 <p class="submit">
646 <input type="submit" class="button-primary" name="clear_activate_page_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
647 <input type="submit" class="button-primary" name="edit_activate_page_filter" value="<?php _e('Activate Plugin Entry &raquo;', 'plf'); ?>" />
648 </p>
649 <?php
650 }
651 else {
652 ?>
653 <br />
654 <p><span style="color: #ff0000;"><?php _e('Page Filter is not registered', 'plf') ?></span></p>
655 <?php
656 }
657 ?>
658 </div>
659 </form>
660 </div>
661 <?php
662 }
663
664 /***************************************************************************
665 * Meta box
666 * Individual of the plug-in filter meta box for Post/Page/CustomPost
667 **************************************************************************/
668 function load_meta_boxes( $post_type, $post ) {
669 if ( current_user_can('activate_plugins', $post->ID) ) {
670 add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
671 add_action( 'admin_head', array(&$this, 'plf_css' ));
672 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
673 }
674 }
675
676 //Plugin pagefilter Selected Checkbox (plugin and modules list)
677 // $p_key
678 // $select_cvplugins : csv string : pagefilter selected plugins
679 // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
680 function _pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins ) {
681
682 $html = '';
683 $selplugins = array_map("trim", explode(',', $select_cvplugins));
684 $device['desktop'] = $checked_arcvplugins['desktop'];
685 $device['mobile'] = $checked_arcvplugins['mobile'];
686 $devlist = array('desktop','mobile');
687 if(in_array( $p_key, $selplugins )){
688 $p_name = $this->pluginkey_to_name($p_key);
689 $html .= "<tr><td class='plugins-name'>$p_name</td>";
690 foreach($devlist as $devtype){
691 $checked = (empty($device[$devtype]) || false === strpos($device[$devtype], $p_key))? false : true;
692 $html .= "<td class='device-type $devtype'>" . self::altcheckbox("plf_option[$devtype][$p_key]", $checked, '<span class="dashicons dashicons-yes"></span>') . '</td>';
693 }
694 $html .= "</tr>";
695 }
696 return $html;
697 }
698
699 //Plugin pagefilter Selected Checkbox (plugin and modules list)
700 // $plugins : array : all active plugins
701 // $select_cvplugins : csv string : pagefilter selected plugins
702 // $checked_arcvplugins : array csv string : ['desktop']=desktop enable plugins, ['mobile']=mobile enable plugins
703 function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_arcvplugins ) {
704
705 if(empty($select_cvplugins))
706 return __('Page Filter is not registered', 'plf');
707
708 $html = '<table id="activation-table">';
709 $html .= '<thead>';
710 $html .= '<tr><th class="plugins-name">'. __('Plugins') . '</th>';
711 $html .= '<th class="device-type"><span title="'. __('Desktop Device', 'plf'). '" class="dashicons dashicons-desktop"></span><br /><span style="font-size:xx-small">Desktop</span></th>';
712 $html .= '<th class="device-type"><span title="'. __('Mobile Device', 'plf'). '" class="dashicons dashicons-smartphone"></span><br /><span style="font-size:xx-small">Mobile</span></th>';
713 $html .= '</tr>';
714 $html .= '</thead>';
715 $html .= '<tbody class="plugins-table-body meta-boxes-plugins-table">';
716 $nplugins = $jmodules = $cmodules = array();
717 foreach ( $plugins as $p_key => $p_data ) {
718 $p_name = $this->pluginkey_to_name($p_key);
719 if(empty($p_name))
720 continue;
721 if(strpos($p_key, 'jetpack_module/') !== false)
722 $jmodules[] = $p_key;
723 else if(strpos($p_key, 'celtispack_module/') !== false)
724 $cmodules[] = $p_key;
725 else
726 $nplugins[] = $p_key;
727 }
728
729 foreach ( $nplugins as $p_key ) {
730 if(strpos($p_key, 'jetpack/') !== false){
731 foreach ( $jmodules as $p_key ) {
732 $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
733 }
734 }
735 else if(strpos($p_key, 'celtispack/') !== false){
736 foreach ( $cmodules as $p_key ) {
737 $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
738 }
739 }
740 else {
741 $html .= $this->_pagefilter_plugins_checklist( $p_key, $select_cvplugins, $checked_arcvplugins );
742 }
743 }
744 $html .= '</tbody>';
745 $html .= '</table>';
746 return $html;
747 }
748
749 function plf_meta_box( $post, $box ) {
750 if(is_object($post)){
751 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
752 //ver2.2.0 for compatibility, set 'plugins' data to 'desktop' and 'mobile'
753 if(!empty($myfilter['plugins'])){
754 $myfilter['desktop'] = $myfilter['plugins'];
755 $myfilter['mobile'] = $myfilter['plugins'];
756 unset($myfilter['plugins']);
757 }
758 $default = array( 'filter' => 'default', 'desktop' => '', 'mobile' => '');
759 $option = (!empty($myfilter))? $myfilter : $default;
760 $option = wp_parse_args( $option, $default);
761 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
762 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
763 ?>
764 <div id="plugin-filter-select">
765 <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
766 <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label>
767 <div id="page-filter-stat">
768 <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option ); ?>
769 </div>
770 <?php echo '<p class="hide-if-no-js"><a id="plugin-filter-submit" class="button" href="#pluginfilterdiv" onclick="WPAddPagePluginLoadFilter(\'' . $ajax_nonce . '\');return false;" >'. __('Save') .'</a></p>'; ?>
771 </div>
772 <?php
773 }
774 }
775
776 //wp_ajax_plugin_load_filter called function
777 function plf_ajax_postidfilter() {
778 if ( isset($_POST['post_id']) ) {
779 $pid = (int) $_POST['post_id'];
780 if ( !current_user_can( 'activate_plugins', $pid ) )
781 wp_die( -1 );
782 check_ajax_referer( "plugin_load_filter-$pid" );
783
784 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
785 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
786 if('default' == $option["filter"]){
787 delete_post_meta( $pid, '_plugin_load_filter');
788 }
789 else {
790 $plugins = array();
791 if( preg_match_all('/plf_option\[desktop\]\[(.+?)\]/u', $_POST['desktop'], $matches)){
792 if(!empty($matches[1])){
793 foreach ($matches[1] as $plugin){
794 $plugins[] = $plugin;
795 }
796 $option["desktop"] = implode(",", $plugins);
797 }
798 }
799 $plugins = array();
800 if( preg_match_all('/plf_option\[mobile\]\[(.+?)\]/u', $_POST['mobile'], $matches)){
801 if(!empty($matches[1])){
802 foreach ($matches[1] as $plugin){
803 $plugins[] = $plugin;
804 }
805 $option["mobile"] = implode(",", $plugins);
806 }
807 }
808 update_post_meta( $pid, '_plugin_load_filter', $option );
809 }
810
811 $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option );
812 wp_send_json_success($html);
813 }
814 wp_die( 0 );
815 }
816
817 /***************************************************************************
818 * Javascript
819 **************************************************************************/
820 function activetab_script() { ?>
821 <script type='text/javascript' >
822 /* <![CDATA[ */
823 var plf_activetab = <?php echo $this->tab_num; ?>
824 /* ]]> */
825 jQuery(document).ready(function ($) { plf_setting_tabs(); function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }});
826 </script>
827 <?php }
828
829 function plf_meta_script() { ?>
830 <script type='text/javascript' >
831 WPAddPagePluginLoadFilter = function(nonce){ jQuery.ajax({ type: 'POST', url: ajaxurl, data: { action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), desktop: jQuery('.meta-boxes-plugins-table td.desktop input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), mobile: jQuery('.meta-boxes-plugins-table td.mobile input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','),}, dataType: 'json', success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }}); return false; };
832 </script>
833 <?php }
834 }