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

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