PluginProbe
Plugin Load Filter / 2.5.1
Plugin Load Filter v2.5.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.5.1, at plugin-load-filter.php

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