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

674 lines 33.7 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.0.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 $editem = false;
20 private $filter = array(); //filter option data
21 private $tab_num = 0;
22
23 /***************************************************************************
24 * Style Sheet
25 **************************************************************************/
26 function plf_css() { ?>
27 <style type="text/css">
28 .plugins-list { max-width : 480px; min-height: 80px; max-height: 320px; overflow: auto; border: 1px solid #CEE1EF; padding:0.5em 0.5em;}
29 ul.plugins-list ul { margin-left: 20px; }
30 ul.plugins-list li { margin: 0; padding: 0; line-height: 22px; word-wrap: break-word;}
31 </style>
32 <?php }
33
34 function jquery_tab_css() { ?>
35 <style type="text/css">
36 .ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.5; text-decoration: none; font-size: 100%; list-style: none; }
37 .ui-helper-clearfix:before, .ui-helper-clearfix:after { content: ""; display: table; }
38 .ui-helper-clearfix:after { clear: both; }
39 .ui-helper-clearfix { zoom: 1; }
40 .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") */
41 .ui-tabs .ui-tabs-nav { margin: 1px 8px; padding: .2em .2em; }
42 .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; }
43 .ui-tabs .ui-tabs-nav li a { float: left; text-decoration: none; }
44 .ui-tabs .ui-tabs-nav li.ui-tabs-active { margin-bottom: -1px; padding-bottom: 1px; }
45 .ui-tabs .ui-tabs-panel { display: block; border-width: 0; background: none; }
46 .ui-tabs .ui-tabs-nav a { margin: 8px 10px; }
47 .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; }
48 .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #0073ea; text-decoration: none; }
49 .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; }
50 .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; }
51 .ui-state-hover a, .ui-state-hover a:hover, .ui-state-hover a:link, .ui-state-hover a:visited { color: #ffffff; text-decoration: none; }
52 .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #ffffff; text-decoration: none; }
53 </style>
54 <?php }
55
56 /***************************************************************************
57 * Plugin Load Filter Option Setting
58 **************************************************************************/
59
60 public function __construct() {
61
62 load_plugin_textdomain('plf', false, basename( dirname( __FILE__ ) ).'/languages' );
63
64 $this->filter = get_option('plf_option');
65 if(is_admin()) {
66 add_action( 'plugins_loaded', array(&$this, 'plf_admin_start'), 9999 );
67 add_action( 'update_option_plf_option', array(&$this, 'plf_transient_clear') );
68 add_action( 'update_option_active_plugins', array(&$this, 'plf_transient_clear') );
69 add_action( 'update_option_jetpack_active_modules', array(&$this, 'plf_transient_clear') );
70 add_action( 'update_option_celtispack_active_modules', array(&$this, 'plf_transient_clear') );
71 add_action( 'add_meta_boxes', array(&$this, 'load_meta_boxes'), 10, 2 );
72 //plf-filter must-use plagin activete check
73 if(wp_mkdir_p( WPMU_PLUGIN_DIR )){
74 if ( !file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
75 @copy(__DIR__ . '/mu-plugins/plf-filter.php', WPMU_PLUGIN_DIR . '/plf-filter.php');
76 }
77 }
78 register_deactivation_hook( __FILE__, 'Plf_setting::deactivation' );
79 register_uninstall_hook(__FILE__, 'Plf_setting::uninstall');
80 }
81 add_action( 'save_post', array(&$this, 'plf_transient_clear') );
82 add_action( 'deleted_post', array(&$this, 'plf_transient_clear') );
83 add_action( 'wp_ajax_plugin_load_filter', array(&$this, 'plf_ajax_postidfilter'));
84 }
85
86 //Plugin Deactivate
87 public static function deactivation() {
88 if ( file_exists( WPMU_PLUGIN_DIR . "/plf-filter.php" )) {
89 @unlink( WPMU_PLUGIN_DIR . '/plf-filter.php' );
90 }
91 }
92 //Plugin Uninstall
93 public static function uninstall() {
94 delete_option('plf_queryvars');
95 delete_option('plf_option' );
96 }
97
98 //Disable the transient cache by changing the update time
99 public function plf_transient_clear() {
100 $this->filter['updated'] = strtotime("now");
101 update_option('plf_option', $this->filter );
102 }
103
104 //Plugin Load Filter admin setting start
105 public function plf_admin_start() {
106 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
107
108 $this->plugins_inf = get_plugins();
109 $packplug = array();
110 foreach ( $this->plugins_inf as $plugin_key => $a_plugin ) {
111 if(is_plugin_inactive( $plugin_key )){
112 unset($this->plugins_inf[$plugin_key]);
113 }
114 }
115 //jetpack active module
116 if(method_exists('Jetpack', 'get_module')){
117 $modules = Jetpack::get_active_modules();
118 $modules = array_diff( $modules, array( 'vaultpress' ) );
119 foreach ( $modules as $key => $module_name ) {
120 if(!empty($module_name)){
121 $module = Jetpack::get_module( $module_name );
122 if(!empty($module))
123 $this->plugins_inf['jetpack_module/' . $module_name] = $module;
124 }
125 }
126 }
127 //celtispack active module
128 if(method_exists('Celtispack', 'get_module')){
129 $modules = Celtispack::get_active_modules();
130 foreach ( $modules as $key => $module_name ) {
131 if(!empty($module_name)){
132 $this->plugins_inf['celtispack_module/' . $module_name] = Celtispack::get_module( $module_name );
133 }
134 }
135 }
136 if ( empty( $this->plugins_inf ) )
137 return;
138
139 $this->action_posts(); //POST, GET Request Action
140 add_action('admin_menu', array(&$this, 'plf_option_menu'));
141 }
142
143 //Plugins sub menu add
144 public function plf_option_menu() {
145 $page = add_plugins_page( 'Plugin Load Filter', __('Plugin Load Filter', 'plf'), 'manage_options', 'plugin_load_filter_admin_manage_page', array(&$this,'plf_option_page'));
146 add_action('admin_print_scripts-'.$page, array(&$this, 'plf_scripts'));
147 }
148
149 //Plugin Load Filter setting page script
150 function plf_scripts() {
151 wp_enqueue_script( 'jquery' );
152 wp_enqueue_script( 'jquery-ui-core' );
153 wp_enqueue_script( 'jquery-ui-widget' );
154 wp_enqueue_script( 'jquery-ui-tabs' );
155 add_action( 'admin_head', array(&$this, 'plf_css' ));
156 add_action( 'admin_head', array(&$this, 'jquery_tab_css' ));
157 add_action( 'admin_footer', array(&$this, 'activetab_script' ));
158 }
159
160 //plugin filter option action request (add, update, delete)
161 function action_posts() {
162 if (current_user_can( 'edit_plugins' )) {
163 if( isset($_POST['edit_regist_filter']) ) {
164 if(isset($_POST['plf_option']['_tag'])){
165 check_admin_referer('plugin_load_filter');
166 $option["plugins"] = '';
167 if(isset($_POST['plf_option']['plugins'])){
168 $plugins = array();
169 foreach($_POST['plf_option']['plugins'] as $plugin => $val) {
170 $plugins[] = $plugin;
171 }
172 $option["plugins"] = implode(",", $plugins);
173 }
174 $this->filter[$_POST['plf_option']['_tag']] = $option;
175 $this->filter['updated'] = strtotime("now");
176 update_option('plf_option', $this->filter );
177 }
178 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
179 exit;
180 }
181 elseif( isset($_POST['clear_regist_filter']) ) {
182 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'));
183 exit;
184 }
185 else if( isset($_POST['new_page_filter']) || isset($_POST['edit_page_filter']) ) {
186 if(isset($_POST['plf_option']['tag'])){
187 check_admin_referer('plugin_load_filter');
188 $option["plugins"] = '';
189 if(isset($_POST['plf_option']['plugins'])){
190 $plugins = array();
191 foreach($_POST['plf_option']['plugins'] as $plugin => $val) {
192 $plugins[] = $plugin;
193 }
194 $option["plugins"] = implode(",", $plugins);
195 }
196 $this->filter['group'][$_POST['plf_option']['tag']] = $option;
197 $this->filter['updated'] = strtotime("now");
198 update_option('plf_option', $this->filter );
199 }
200 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
201 exit;
202 }
203 elseif( isset($_POST['clear_page_filter']) ) {
204 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page&action=tab_1'));
205 exit;
206 }
207 else if (!empty($_GET['action'])) {
208 if( $_GET['action']=='edit_filter_table') {
209 $this->editem = $_GET['item'];
210 $this->tab_num = (0 === strpos($_GET['item'], '_'))? 0 : 1;
211 }
212 elseif( $_GET['action']=='del_filter_table') {
213 if( !empty( $_GET['item'])){
214 check_admin_referer( 'plugin_load_filter' );
215 $tab_action = '';
216 if(0 === strpos($_GET['item'], '_')){
217 unset($this->filter[$_GET['item']]);
218 }
219 else {
220 unset($this->filter['group'][$_GET['item']]);
221 $tab_action = '&action=tab_1';
222 }
223 $this->filter['updated'] = strtotime("now");
224 update_option('plf_option', $this->filter );
225 }
226 header('Location: ' . admin_url('plugins.php?page=plugin_load_filter_admin_manage_page'.$tab_action));
227 exit;
228 }
229 elseif( $_GET['action']=='tab_1') {
230 $this->tab_num = 1;
231 }
232 }
233 }
234 }
235
236 public function filter_stat( $sw, $stat) {
237 if( $sw === 'exclude') {
238 if(empty($stat))
239 $str = '<span style="color: #339966;">"Page filter plugins Activate"</span>';
240 else
241 $str = '<span style="color: #ff0000;">' . $stat. '</span>';
242 }
243 elseif( $sw === 'include') {
244 if(empty($stat))
245 $str = '<span style="color: #ff0000;">"Page filter plugins Deactivate"</span>';
246 else
247 $str = '<span style="color: #339966;">' . $stat. '</span>';
248 }
249 else
250 $str = $stat;
251 return $str;
252 }
253
254 //Plugin or Module key to name
255 // $type : smart/csv/list/tree
256 public function pluginkey_to_name( $infkey, $type='smart') {
257
258 $name = '';
259 if(strpos($infkey, 'jetpack_module/') !== false){
260 if(!empty($this->plugins_inf[$infkey]['name'])){
261 $m_mark = ($type !== 'list')? '-' : 'Jetpack-';
262 if($type === 'smart') {
263 if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'jetpack/') === false)
264 $name = $m_mark . $this->plugins_inf[$infkey]['name'];
265 }
266 else
267 $name = $m_mark . $this->plugins_inf[$infkey]['name'];
268 }
269 }
270 elseif(strpos($infkey, 'celtispack_module/') !== false){
271 if(!empty($this->plugins_inf[$infkey]['Name'])){
272 $m_mark = ($type !== 'list')? '-' : 'Celtispack-';
273 if($type === 'smart') {
274 if(empty($this->filter['_pagefilter']['plugins']) || strpos($this->filter['_pagefilter']['plugins'], 'celtispack/') === false)
275 $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
276 }
277 else
278 $name = $m_mark . $this->plugins_inf[$infkey]['Name'];
279 }
280 }
281 else {
282 if(!empty($this->plugins_inf[$infkey]['Name']))
283 $name = $this->plugins_inf[$infkey]['Name'];
284 }
285 return($name);
286 }
287
288 //Checkbox
289 static function checkbox($name, $value, $label = '') {
290 return "<label><input type='checkbox' name='$name' value='1' " . checked( $value, 1, false ). "/> $label</label>";
291 }
292 //DropdownList
293 static function dropdown($name, $items, $selected, $args=null) {
294 $defaults = array( 'id' => $name, 'class' => "", 'multiple' => false );
295 foreach($items as $key => &$value) {
296 if (is_array($value))
297 $value = array_shift($value);
298 }
299 $opt = wp_parse_args($args, $defaults);
300 $name = ($name) ? "name='$name'" : "";
301 $id = ($opt['id']) ? "id='${opt['id']}'" : "";
302 $class = ($opt['class']) ? "class='${opt['class']}'" : "";
303 $multiple = ($opt['multiple']) ? "multiple='multiple'" : "";
304
305 $html = "<select $name $id $class $multiple >";
306 foreach ((array)$items as $key => $label) {
307 $key = esc_attr($key);
308 $label = esc_attr($label);
309 $html .= "<option value='$key' " . selected($selected, $key, false) . ">$label</option>";
310 }
311 $html .= "</select>";
312 return $html;
313 }
314
315 //Plugin Select Checkbox (plugin-modules tree)
316 // $plugins : array : all active plugins
317 // $checked_cvplugins : csv string : checked plugins
318 function plugins_checklist( $plugins, $checked_cvplugins ) {
319
320 $nplugins = $jmodules = $cmodules = array();
321 $type = 'tree';
322 foreach ( $plugins as $p_key => $p_data ) {
323 $p_name = $this->pluginkey_to_name($p_key, $type);
324 if(empty($p_name))
325 continue;
326 if(strpos($p_key, 'jetpack_module/') !== false)
327 $jmodules[] = $p_key;
328 else if(strpos($p_key, 'celtispack_module/') !== false)
329 $cmodules[] = $p_key;
330 else
331 $nplugins[] = $p_key;
332 }
333 $chkplugins = array_map("trim", explode(',', $checked_cvplugins));
334 $html = '<ul class="plugins-list">';
335 foreach ( $nplugins as $p_key ) {
336 $p_name = $this->pluginkey_to_name($p_key, $type);
337 $checked = in_array( $p_key, $chkplugins ) ? true : false;
338 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
339
340 $modules = array();
341 if(strpos($p_key, 'jetpack/') !== false)
342 $modules = $jmodules;
343 else if(strpos($p_key, 'celtispack/') !== false)
344 $modules = $cmodules;
345 if(!empty($modules)){
346 $html .= '<ul class="modules-list">';
347 foreach ( $modules as $m_key ) {
348 $m_name = $this->pluginkey_to_name($m_key, $type);
349 $mchecked = ($checked || in_array( $m_key, $chkplugins )) ? true : false;
350 $html .= '<li>' . self::checkbox("plf_option[plugins][$m_key]", $mchecked, esc_attr($m_name)) . '</li>';
351 }
352 $html .= '</ul>';
353 }
354 }
355 $html .= '</ul>';
356 return $html;
357 }
358
359 //Plugin pagefilter Selected Checkbox (plugin and modules list)
360 // $plugins : array : all active plugins
361 // $select_cvplugins : csv string : pagefilter selected plugins
362 // $checked_cvplugins : csv string : checked plugins
363 function pagefilter_plugins_checklist( $plugins, $select_cvplugins, $checked_cvplugins ) {
364
365 if(empty($select_cvplugins))
366 return __('Page Filter is not registered', 'plf');
367
368 $nplugins = $jmodules = $cmodules = $allmodule = array();
369 $type = 'list';
370 foreach ( $plugins as $p_key => $p_data ) {
371 $p_name = $this->pluginkey_to_name($p_key, $type);
372 if(empty($p_name))
373 continue;
374 if(strpos($p_key, 'jetpack_module/') !== false)
375 $jmodules[] = $p_key;
376 else if(strpos($p_key, 'celtispack_module/') !== false)
377 $cmodules[] = $p_key;
378 else {
379 if(strpos($p_key, 'jetpack/') !== false && strpos($select_cvplugins, $p_key) !== false)
380 $allmodule['jetpack'] = $p_key;
381 else if(strpos($p_key, 'celtispack/') !== false && strpos($select_cvplugins, $p_key) !== false)
382 $allmodule['celtispack'] = $p_key;
383 else
384 $nplugins[] = $p_key;
385 }
386 }
387 $selplugins = array_map("trim", explode(',', $select_cvplugins));
388 $chkplugins = array_map("trim", explode(',', $checked_cvplugins));
389 $html = '<ul class="plugins-list">';
390 foreach ( $nplugins as $p_key ) {
391 if(in_array( $p_key, $selplugins )) {
392 $p_name = $this->pluginkey_to_name($p_key, $type);
393 $checked = in_array( $p_key, $chkplugins ) ? true : false;
394 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
395 }
396 }
397 foreach ( $jmodules as $p_key ) {
398 if(!empty($allmodule['jetpack']) || in_array( $p_key, $selplugins )){
399 $p_name = $this->pluginkey_to_name($p_key, $type);
400 $checked = in_array( $p_key, $chkplugins ) ? true : false;
401 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
402 }
403 }
404 foreach ( $cmodules as $p_key ) {
405 if(!empty($allmodule['celtispack']) || in_array( $p_key, $selplugins )){
406 $p_name = $this->pluginkey_to_name($p_key, $type);
407 $checked = in_array( $p_key, $chkplugins ) ? true : false;
408 $html .= '<li>' . self::checkbox("plf_option[plugins][$p_key]", $checked, esc_attr($p_name)) . '</li>';
409 }
410 }
411 $html .= '</ul>';
412 return $html;
413 }
414
415 //Plugin Filter Table
416 public function plf_table($tags, $default) {
417 ?>
418 <table class="widefat">
419 <thead>
420 <tr><th width="12%"><?php _e('Type'); ?></th><th width="76%"><?php _e('Plugins'); ?></th><th width="12%" colspan="2">&nbsp;</th></tr>
421 </thead>
422 <tbody>
423 <?php
424 if(!empty($tags)){
425 foreach( $tags as $ptag => $val ) {
426 $opt = wp_parse_args( $val, $default);
427 $plugins = array_map("trim", explode(',', $opt['plugins']));
428 $plist = '';
429 $type = ($ptag == '_pagefilter')? 'smart' : 'csv';
430 foreach ( $plugins as $p_key ) {
431 $p_name = $this->pluginkey_to_name($p_key, $type);
432 if(!empty($p_name)){
433 $sep = (empty($plist))? '' : ', ';
434 $plist .= $sep . esc_attr($p_name);
435 }
436 }
437 if(!empty($ptag)){
438 echo '<tr id="plf_filter_' .$ptag. '">';
439 echo '<td>'.$ptag.'</td>';
440 echo '<td>'. $this->filter_stat($opt['filter'], $plist).'</td>';
441 echo '<td><a class="view" href="'. wp_nonce_url("plugins.php?page=plugin_load_filter_admin_manage_page&amp;action=edit_filter_table&amp;item=$ptag", "plugin_load_filter") . '">' . __( 'Edit' ) . '</a></td>';
442 echo '<td><a class="delete" href="'. wp_nonce_url("plugins.php?page=plugin_load_filter_admin_manage_page&amp;action=del_filter_table&amp;item=$ptag", "plugin_load_filter") . '">' . __( 'Delete' ) . '</a></td>';
443 echo '</tr>';
444 }
445 }
446 }
447 ?>
448 </tbody>
449 </table>
450 <?php
451 }
452
453 //Option Setting Form Display
454 public function plf_option_page() {
455 ?>
456 <h2><?php _e('Plugin Load Filter Settings', 'plf'); ?></h2>
457 <p></p>
458 <div id="plf-setting-tabs">
459 <ul>
460 <li><a href="#plf-registration-tab" ><?php _e('Filter Registration', 'plf'); ?></a></li>
461 <li><a href="#plf-activation-tab" ><?php _e('Page Filter Activation', 'plf'); ?></a></li>
462 </ul>
463 <form method="post" >
464 <?php wp_nonce_field( 'plugin_load_filter'); ?>
465 <div id="plf-registration-tab" >
466 <?php
467 $default = array( 'filter' => 'exclude', 'plugins' => '');
468 $base = array();
469 foreach($this->filter as $item => $val){
470 if(0 === strpos($item, '_'))
471 $base[$item] = $this->filter[$item];
472 }
473 $this->plf_table($base, $default);
474
475 $itemtag = '';
476 $option = $default;
477 if( !empty($this->editem) ) {
478 $itemtag = $this->editem;
479 $option = $this->filter[$itemtag];
480 }
481 $option = wp_parse_args( $option, $default);
482 ?>
483 <br />
484 <p><strong>[ Admin Filter ]</strong><br />
485 <?php _e('Register the plugins to be used only in admin mode.', 'plf'); ?><br />
486 </p>
487 <p><strong>[ Desktop/Mobile Filter ]</strong><br />
488 <?php _e('Register the plugins to be used only in desktop/moble device. (wp_is_mobile function use)', 'plf'); ?><br />
489 </p>
490 <p><strong>[ Page Filter ]</strong><br />
491 <?php _e('Register the plugins for selecting whether to activate each Page type or Post.', 'plf'); ?><br />
492 <?php _e('Page Filter registration plugins are once blocked, but is activated by "Page filter Activation" setting.', 'plf'); ?><br />
493 </p>
494 <p><?php _e('<strong>[Note]</strong> Running condition is unknown plugin, please do not register. Unregistered plugins are usually loaded.', 'plf') ?></p>
495 <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
496 <tbody>
497 <tr>
498 <th valign="top" scope="row"><label for="plugin"><?php _e('Filter Type', 'plf'); ?>:</label></th>
499 <td>
500 <label><input type="radio" name="plf_option[_tag]" value="_admin" <?php checked('_admin', $itemtag); ?>/><?php _e('Admin', 'plf'); ?></label>
501 <label><input type="radio" name="plf_option[_tag]" value="_desktop" <?php checked('_desktop', $itemtag); ?>/><?php _e('Desktop', 'plf'); ?></label>
502 <label><input type="radio" name="plf_option[_tag]" value="_mobile" <?php checked('_mobile', $itemtag); ?>/><?php _e('Mobile', 'plf'); ?></label>
503 <label><input type="radio" name="plf_option[_tag]" value="_pagefilter" <?php checked('_pagefilter', $itemtag); ?>/><?php _e('Page Filter', 'plf'); ?></label>
504 <br />
505 <?php echo $this->plugins_checklist( $this->plugins_inf, $option['plugins'] ); ?>
506 </td>
507 </tr>
508 <tr>
509 </tr>
510 </tbody>
511 </table>
512 <p class="submit">
513 <input type="submit" class="button-primary" name="clear_regist_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
514 <input type="submit" class="button-primary" name="edit_regist_filter" value="<?php _e('Entry &raquo;', 'plf'); ?>" />
515 </p>
516 </div>
517 <div id="plf-activation-tab" >
518 <?php
519 $default = array( 'filter' => 'include', 'plugins' => '');
520 $cgroup = (!empty($this->filter['group']))? $this->filter['group'] : array();
521 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
522 $this->plf_table( $cgroup, $default);
523 $itemtag = '';
524 $option = $default;
525 $action = 'new_page_filter';
526 if( !empty($this->editem) ) {
527 $itemtag = $this->editem;
528 $option = $cgroup[$itemtag];
529 $action = 'edit_page_filter';
530 }
531 $option = wp_parse_args( $option, $default);
532 ?>
533 <br />
534 <p><?php _e('Select the plugin from "Page Filter" registration to activate in each Page type.', 'plf') ?><br />
535 <?php _e('Can be selected plugins to activate from Post content editing screen.', 'plf') ?>
536 </p>
537 <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
538 <tbody>
539 <tr>
540 <th valign="top" scope="row"><label for="plugintag"><?php _e( 'Page type', 'plf'); ?></label></th>
541 <td><?php
542 $slist = array('home' => __('Home/Front-page', 'plf'),
543 'archive' => __('Archive page', 'plf'),
544 'search' => __('Search page', 'plf'),
545 'attachment' => __('Attachment page', 'plf'),
546 'page' => __('Page', 'plf'),
547 'post' => __('Post : Standard', 'plf'),
548 'post-aside' => __('Post : Aside', 'plf'),
549 'post-image' => __('Post : Image', 'plf'),
550 'post-video' => __('Post : Video', 'plf'),
551 'post-quote' => __('Post : Quote', 'plf'),
552 'post-link' => __('Post : Link', 'plf'),
553 'post-gallery'=> __('Post : Gallery', 'plf'),
554 'post-status' => __('Post : Status', 'plf'),
555 'post-audio' => __('Post : Audio', 'plf'),
556 'post-chat' => __('Post : Chat', 'plf'));
557 $post_types = get_post_types( array('public' => true, '_builtin' => false) );
558 foreach ( $post_types as $post_type ) {
559 if(!empty($post_type))
560 $slist[$post_type] = __('Custom Post : ', 'plf') . $post_type;
561 }
562 echo self::dropdown('plf_option[tag]', $slist, $itemtag );
563 ?>
564 </td>
565 </tr>
566 <tr>
567 <th valign="top" scope="row"><label for="plugin"><?php _e('Activate Plugins', 'plf'); ?>:</label></th>
568 <td>
569 <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?>
570 </td>
571 </tr>
572 </tbody>
573 </table>
574 <p class="submit">
575 <input type="submit" class="button-primary" name="clear_page_filter" value="<?php _e('Clear', 'plf'); ?>" />&nbsp;&nbsp;&nbsp;
576 <input type="submit" class="button-primary" name="<?php echo $action ?>" value="<?php _e('Entry &raquo;', 'plf'); ?>" />
577 </p>
578 </div>
579 </form>
580 </div>
581 <?php
582 }
583
584 /***************************************************************************
585 * Meta box
586 * Individual of the plug-in filter meta box for Post/Page/CustomPost
587 **************************************************************************/
588 function load_meta_boxes( $post_type, $post ) {
589 if ( current_user_can('edit_plugins', $post->ID) ) {
590 add_meta_box( 'pluginfilterdiv', __( 'Page Filter Plugin', 'plf' ), array(&$this, 'plf_meta_box'), null, 'side' );
591 add_action( 'admin_head', array(&$this, 'plf_css' ));
592 add_action( 'admin_footer', array(&$this, 'plf_meta_script' ));
593 }
594 }
595
596 function plf_meta_box( $post, $box ) {
597 if(is_object($post)){
598 $default = array( 'filter' => 'default', 'plugins' => '');
599 $myfilter = get_post_meta( $post->ID, '_plugin_load_filter', true );
600 $option = (!empty($myfilter))? $myfilter : $default;
601 $option = wp_parse_args( $option, $default);
602 $ajax_nonce = wp_create_nonce( 'plugin_load_filter-' . $post->ID );
603 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
604 ?>
605 <div id="plugin-filter-select">
606 <label><input type="radio" name="pagefilter" value="default" <?php checked('default', $option['filter']); ?>/><?php _e('Not Use', 'plf' ); ?></label>
607 <label><input type="radio" name="pagefilter" value="include" <?php checked('include', $option['filter']); ?>/><?php _e('Activate Plugins', 'plf'); ?></label>
608 <br />
609 <div id="page-filter-stat">
610 <?php echo $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] ); ?>
611 </div>
612 <?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>'; ?>
613 </div>
614 <?php
615 }
616 }
617
618 //wp_ajax_plugin_load_filter called function
619 function plf_ajax_postidfilter() {
620 if ( isset($_POST['post_id']) ) {
621 $pid = (int) $_POST['post_id'];
622 if ( !current_user_can( 'edit_plugins', $pid ) )
623 wp_die( -1 );
624 check_ajax_referer( "plugin_load_filter-$pid" );
625
626 $option["filter"] = (empty($_POST['filter']))? 'default' : $_POST['filter'];
627 $option["plugins"] = '';
628 if('default' == $option["filter"])
629 delete_post_meta( $pid, '_plugin_load_filter');
630 else {
631 $plugins = array();
632 if( preg_match_all('/plf_option\[plugins\]\[(.+?)\]/u', $_POST['plugins'], $matches)){
633 if(!empty($matches[1])){
634 foreach ($matches[1] as $plugin){
635 $plugins[] = $plugin;
636 }
637 $option["plugins"] = implode(",", $plugins);
638 }
639 }
640 update_post_meta( $pid, '_plugin_load_filter', $option );
641 }
642 //transient cache clear
643 $this->plf_transient_clear();
644
645 $pgfilter = (!empty($this->filter['_pagefilter']['plugins']))? $this->filter['_pagefilter']['plugins'] : array();
646 $html = $this->pagefilter_plugins_checklist( $this->plugins_inf, $pgfilter, $option['plugins'] );
647 wp_send_json_success($html);
648 }
649 wp_die( 0 );
650 }
651
652 /***************************************************************************
653 * Javascript
654 **************************************************************************/
655 function activetab_script() { ?>
656 <script type='text/javascript' >
657 /* <![CDATA[ */
658 var plf_activetab = <?php echo $this->tab_num; ?>
659 /* ]]> */
660 jQuery(document).ready(function ($) { plf_setting_tabs(); function plf_setting_tabs(){ $('#plf-setting-tabs').tabs({ active:plf_activetab, }); }});
661 </script>
662 <?php }
663
664 function plf_meta_script() { ?>
665 <script type='text/javascript' >
666 WPAddPagePluginLoadFilter = function(nonce){
667 jQuery.ajax({ type: 'POST', url: ajaxurl,
668 data: {action: "plugin_load_filter", post_id : jQuery( '#post_ID' ).val(), _ajax_nonce: nonce, filter: jQuery("input[name='pagefilter']:checked").val(), plugins: jQuery('.plugins-list li input:checked').map(function(){ return jQuery(this).attr("name"); }).get().join(','), }, dataType: 'json',
669 success: function(response, dataType) { jQuery('#page-filter-stat').html(response.data); }
670 });
671 return false; };
672 </script>
673 <?php }
674 }