PodsUI::manage PHP Method

manage() public method

public manage ( boolean $reorder = false ) : mixed | null
$reorder boolean
return mixed | null
    public function manage($reorder = false)
    {
        if (false !== $this->callback_action('manage', $reorder)) {
            return null;
        }
        if (!empty($this->action_bulk) && !empty($this->actions_bulk) && isset($this->actions_bulk[$this->action_bulk]) && !in_array($this->action_bulk, $this->actions_disabled) && !empty($this->bulk)) {
            if (empty($_REQUEST['_wpnonce' . $this->num]) || false === wp_verify_nonce($_REQUEST['_wpnonce' . $this->num], 'pods-ui-action-bulk')) {
                pods_message(__('Invalid bulk request, please try again.', 'pods'));
            } elseif (false !== $this->callback_bulk($this->action_bulk, $this->bulk)) {
                return null;
            } elseif ('delete' == $this->action_bulk) {
                return $this->delete_bulk();
            }
        }
        $this->screen_meta();
        if (true === $reorder) {
            wp_enqueue_script('jquery-ui-sortable');
        }
        ?>
    <div class="wrap pods-admin pods-ui">
        <div id="icon-edit-pages" class="icon32"<?php 
        if (false !== $this->icon) {
            ?>
 style="background-position:0 0;background-size:100%;background-image:url(<?php 
            echo esc_url($this->icon);
            ?>
);"<?php 
        }
        ?>
><br /></div>
        <h2>
            <?php 
        if (true === $reorder) {
            echo $this->header['reorder'];
            $link = pods_query_arg(array('action' . $this->num => 'manage', 'id' . $this->num => ''), self::$allowed, $this->exclusion());
            if (!empty($this->action_links['manage'])) {
                $link = $this->action_links['manage'];
            }
            ?>
                <small>(<a href="<?php 
            echo esc_url($link);
            ?>
">&laquo; <?php 
            echo sprintf(__('Back to %s', 'pods'), $this->heading['manage']);
            ?>
</a>)</small>
                <?php 
        } else {
            echo $this->header['manage'];
        }
        if (!in_array('add', $this->actions_disabled) && !in_array('add', $this->actions_hidden)) {
            $link = pods_query_arg(array('action' . $this->num => 'add', 'id' . $this->num => '', 'do' . $this->num => ''), self::$allowed, $this->exclusion());
            if (!empty($this->action_links['add'])) {
                $link = $this->action_links['add'];
            }
            ?>
                <a href="<?php 
            echo esc_url($link);
            ?>
" class="add-new-h2"><?php 
            echo $this->label['add_new'];
            ?>
</a>
                <?php 
        }
        if (!in_array('reorder', $this->actions_disabled) && !in_array('reorder', $this->actions_hidden) && false !== $this->reorder['on']) {
            $link = pods_query_arg(array('action' . $this->num => 'reorder'), self::$allowed, $this->exclusion());
            if (!empty($this->action_links['reorder'])) {
                $link = $this->action_links['reorder'];
            }
            ?>
                <a href="<?php 
            echo esc_url($link);
            ?>
" class="add-new-h2"><?php 
            echo $this->label['reorder'];
            ?>
</a>
                <?php 
        }
        ?>
        </h2>

		<form id="posts-filter" action="" method="get">
        	<?php 
        $excluded_filters = array('search' . $this->num, 'pg' . $this->num, 'action' . $this->num, 'action_bulk' . $this->num, 'action_bulk_ids' . $this->num, '_wpnonce' . $this->num);
        $filters = $this->filters;
        foreach ($filters as $k => $filter) {
            if (isset($this->pod->fields[$filter])) {
                $filter_field = $this->pod->fields[$filter];
            } elseif (isset($this->fields['manage'][$filter])) {
                $filter_field = $this->fields['manage'][$filter];
            } else {
                unset($filters[$k]);
                continue;
            }
            if (in_array($filter_field['type'], array('date', 'datetime', 'time'))) {
                if ('' == pods_var_raw('filter_' . $filter . '_start', 'get', '', null, true) && '' == pods_var_raw('filter_' . $filter . '_end', 'get', '', null, true)) {
                    unset($filters[$k]);
                    continue;
                }
            } elseif ('' === pods_var_raw('filter_' . $filter, 'get', '')) {
                unset($filters[$k]);
                continue;
            }
            $excluded_filters[] = 'filter_' . $filter . '_start';
            $excluded_filters[] = 'filter_' . $filter . '_end';
            $excluded_filters[] = 'filter_' . $filter;
        }
        $get = $_GET;
        foreach ($get as $k => $v) {
            if (is_array($v) || in_array($k, $excluded_filters) || strlen($v) < 1) {
                continue;
            }
            ?>
				<input type="hidden" name="<?php 
            echo esc_attr($k);
            ?>
" value="<?php 
            echo esc_attr($v);
            ?>
" />
			<?php 
        }
        if (false !== $this->callback('header', $reorder)) {
            return null;
        }
        if (false === $this->data) {
            $this->get_data();
        } elseif ($this->sortable) {
            // we have the data already as an array
            $this->sort_data();
        }
        if (!in_array('export', $this->actions_disabled) && 'export' == $this->action) {
            $this->export();
        }
        if ((!empty($this->data) || false !== $this->search || $this->filters_enhanced && !empty($this->views)) && ($this->filters_enhanced && !empty($this->views) || false !== $this->searchable)) {
            if ($this->filters_enhanced) {
                $this->filters();
            } else {
                ?>
                <p class="search-box" align="right">
                    <?php 
                $excluded_filters = array('search' . $this->num, 'pg' . $this->num);
                foreach ($this->filters as $filter) {
                    $excluded_filters[] = 'filter_' . $filter . '_start';
                    $excluded_filters[] = 'filter_' . $filter . '_end';
                    $excluded_filters[] = 'filter_' . $filter;
                }
                $this->hidden_vars($excluded_filters);
                foreach ($this->filters as $filter) {
                    if (isset($this->pod->fields[$filter])) {
                        $filter_field = $this->pod->fields[$filter];
                    } elseif (isset($this->fields['manage'][$filter])) {
                        $filter_field = $this->fields['manage'][$filter];
                    } else {
                        continue;
                    }
                    if (in_array($filter_field['type'], array('date', 'datetime', 'time'))) {
                        $start = pods_var_raw('filter_' . $filter . '_start', 'get', pods_var_raw('filter_default', $filter_field, '', null, true), null, true);
                        $end = pods_var_raw('filter_' . $filter . '_end', 'get', pods_var_raw('filter_ongoing_default', $filter_field, '', null, true), null, true);
                        // override default value
                        $filter_field['options']['default_value'] = '';
                        $filter_field['options'][$filter_field['type'] . '_allow_empty'] = 1;
                        if (!empty($start) && !in_array($start, array('0000-00-00', '0000-00-00 00:00:00', '00:00:00'))) {
                            $start = PodsForm::field_method($filter_field['type'], 'convert_date', $start, 'n/j/Y');
                        }
                        if (!empty($end) && !in_array($end, array('0000-00-00', '0000-00-00 00:00:00', '00:00:00'))) {
                            $end = PodsForm::field_method($filter_field['type'], 'convert_date', $end, 'n/j/Y');
                        }
                        ?>
                        <label for="pods-form-ui-filter-<?php 
                        echo esc_attr($filter);
                        ?>
_start">
                            <?php 
                        echo $filter_field['label'];
                        ?>
                        </label>
                        <?php 
                        echo PodsForm::field('filter_' . $filter . '_start', $start, $filter_field['type'], $filter_field);
                        ?>

                        <label for="pods-form-ui-filter-<?php 
                        echo esc_attr($filter);
                        ?>
_end">
                            to
                        </label>
                    <?php 
                        echo PodsForm::field('filter_' . $filter . '_end', $end, $filter_field['type'], $filter_field);
                    } elseif ('pick' == $filter_field['type']) {
                        $value = pods_var_raw('filter_' . $filter, 'get');
                        if (strlen($value) < 1) {
                            $value = pods_var_raw('filter_default', $filter_field);
                        }
                        // override default value
                        $filter_field['options']['default_value'] = '';
                        $filter_field['options']['pick_format_type'] = 'single';
                        $filter_field['options']['pick_format_single'] = 'dropdown';
                        $filter_field['options']['input_helper'] = pods_var_raw('ui_input_helper', pods_var_raw('options', pods_var_raw($filter, $this->fields['search'], array(), null, true), array(), null, true), '', null, true);
                        $filter_field['options']['input_helper'] = pods_var_raw('ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true);
                        $options = array_merge($filter_field, $filter_field['options']);
                        ?>
                        <label for="pods-form-ui-filter-<?php 
                        echo esc_attr($filter);
                        ?>
">
                            <?php 
                        echo $filter_field['label'];
                        ?>
                        </label>
                    <?php 
                        echo PodsForm::field('filter_' . $filter, $value, 'pick', $options);
                    } elseif ('boolean' == $filter_field['type']) {
                        $value = pods_var_raw('filter_' . $filter, 'get', '');
                        if (strlen($value) < 1) {
                            $value = pods_var_raw('filter_default', $filter_field);
                        }
                        // override default value
                        $filter_field['options']['default_value'] = '';
                        $filter_field['options']['pick_format_type'] = 'single';
                        $filter_field['options']['pick_format_single'] = 'dropdown';
                        $filter_field['options']['pick_object'] = 'custom-simple';
                        $filter_field['options']['pick_custom'] = array('1' => pods_var_raw('boolean_yes_label', $filter_field['options'], __('Yes', 'pods'), null, true), '0' => pods_var_raw('boolean_no_label', $filter_field['options'], __('No', 'pods'), null, true));
                        $filter_field['options']['input_helper'] = pods_var_raw('ui_input_helper', pods_var_raw('options', pods_var_raw($filter, $this->fields['search'], array(), null, true), array(), null, true), '', null, true);
                        $filter_field['options']['input_helper'] = pods_var_raw('ui_input_helper', $filter_field['options'], $filter_field['options']['input_helper'], null, true);
                        $options = array_merge($filter_field, $filter_field['options']);
                        ?>
                        <label for="pods-form-ui-filter-<?php 
                        echo esc_attr($filter);
                        ?>
">
                            <?php 
                        echo $filter_field['label'];
                        ?>
                        </label>
                    <?php 
                        echo PodsForm::field('filter_' . $filter, $value, 'pick', $options);
                    } else {
                        $value = pods_var_raw('filter_' . $filter, 'get');
                        if (strlen($value) < 1) {
                            $value = pods_var_raw('filter_default', $filter_field);
                        }
                        // override default value
                        $filter_field['options']['default_value'] = '';
                        $options = array();
                        $options['input_helper'] = pods_var_raw('ui_input_helper', pods_var_raw('options', pods_var_raw($filter, $this->fields['search'], array(), null, true), array(), null, true), '', null, true);
                        $options['input_helper'] = pods_var_raw('ui_input_helper', $options, $options['input_helper'], null, true);
                        ?>
                        <label for="pods-form-ui-filter-<?php 
                        echo esc_attr($filter);
                        ?>
">
                            <?php 
                        echo $filter_field['label'];
                        ?>
                        </label>
                    <?php 
                        echo PodsForm::field('filter_' . $filter, $value, 'text', $options);
                    }
                }
                if (false !== $this->do_hook('filters_show_search', true)) {
                    ?>
						&nbsp;&nbsp; <label<?php 
                    echo empty($this->filters) ? ' class="screen-reader-text"' : '';
                    ?>
 for="page-search<?php 
                    echo esc_attr($this->num);
                    ?>
-input"><?php 
                    _e('Search', 'pods');
                    ?>
:</label>
						<?php 
                    echo PodsForm::field('search' . $this->num, $this->search, 'text', array('attributes' => array('id' => 'page-search' . $this->num . '-input')));
                    ?>
					<?php 
                } else {
                    echo PodsForm::field('search' . $this->num, '', 'hidden');
                }
                ?>
                    <?php 
                echo PodsForm::submit_button($this->header['search'], 'button', false, false, array('id' => 'search' . $this->num . '-submit'));
                ?>
                    <?php 
                if (0 < strlen($this->search)) {
                    $clear_filters = array('search' . $this->num => false);
                    foreach ($this->filters as $filter) {
                        $clear_filters['filter_' . $filter . '_start'] = false;
                        $clear_filters['filter_' . $filter . '_end'] = false;
                        $clear_filters['filter_' . $filter] = false;
                    }
                    ?>
                        <br class="clear" />
                        <small>[<a href="<?php 
                    echo esc_url(pods_query_arg($clear_filters, array('orderby' . $this->num, 'orderby_dir' . $this->num, 'limit' . $this->num, 'page'), $this->exclusion()));
                    ?>
"><?php 
                    _e('Reset Filters', 'pods');
                    ?>
</a>]</small>
                        <br class="clear" />
                        <?php 
                }
                ?>
                </p>
                <?php 
            }
        } else {
            ?>
                <br class="clear" />
                <?php 
        }
        if (!empty($this->data) && (false !== $this->pagination_total || false !== $this->pagination || true === $reorder) || !in_array('export', $this->actions_disabled) && !in_array('export', $this->actions_hidden) || !empty($this->actions_disabled)) {
            ?>
                <div class="tablenav">
                    <?php 
            if (!empty($this->data) && !empty($this->actions_bulk)) {
                ?>
                    <div class="alignleft actions">
	                    <?php 
                wp_nonce_field('pods-ui-action-bulk', '_wpnonce' . $this->num, false);
                ?>

                        <select name="action_bulk<?php 
                echo esc_attr($this->num);
                ?>
">
                            <option value="-1" selected="selected"><?php 
                _e('Bulk Actions', 'pods');
                ?>
</option>

                            <?php 
                foreach ($this->actions_bulk as $action => $action_data) {
                    if (in_array($action, $this->actions_hidden) || in_array($action, $this->actions_hidden)) {
                        continue;
                    }
                    if (!isset($action_data['label'])) {
                        $action_data['label'] = ucwords(str_replace('_', ' ', $action));
                    }
                    ?>
                                <option value="<?php 
                    echo esc_attr($action);
                    ?>
"><?php 
                    echo esc_html($action_data['label']);
                    ?>
</option>
                            <?php 
                }
                ?>
                        </select>

                        <input type="submit" id="doaction_bulk<?php 
                echo esc_attr($this->num);
                ?>
" class="button-secondary action" value="<?php 
                esc_attr_e('Apply', 'pods');
                ?>
">
                    </div>
                <?php 
            }
            if (true !== $reorder && (false !== $this->pagination_total || false !== $this->pagination)) {
                ?>
                        <div class="tablenav-pages<?php 
                echo esc_attr($this->limit < $this->total_found || 1 < $this->page ? '' : ' one-page');
                ?>
">
                            <?php 
                $this->pagination(1);
                ?>
                        </div>
                        <?php 
            }
            if (true === $reorder) {
                $link = pods_query_arg(array('action' . $this->num => 'manage', 'id' . $this->num => ''), self::$allowed, $this->exclusion());
                if (!empty($this->action_links['manage'])) {
                    $link = $this->action_links['manage'];
                }
                ?>
                        <input type="button" value="<?php 
                esc_attr_e('Update Order', 'pods');
                ?>
" class="button" onclick="jQuery('form.admin_ui_reorder_form').submit();" />
                        <input type="button" value="<?php 
                esc_attr_e('Cancel', 'pods');
                ?>
" class="button" onclick="document.location='<?php 
                echo esc_js($link);
                ?>
';" />
                    </form>
				<?php 
            } elseif (!in_array('export', $this->actions_disabled) && !in_array('export', $this->actions_hidden)) {
                ?>
                        <div class="alignleft actions">
                            <strong><?php 
                _e('Export', 'pods');
                ?>
:</strong>
                            <?php 
                foreach ($this->export['formats'] as $format => $separator) {
                    ?>
                                <input type="button" value=" <?php 
                    echo esc_attr(strtoupper($format));
                    ?>
 " class="button" onclick="document.location='<?php 
                    echo pods_slash(pods_query_arg(array('action' . $this->num => 'export', 'export_type' . $this->num => $format, '_wpnonce' => wp_create_nonce('pods-ui-action-export')), self::$allowed, $this->exclusion()));
                    ?>
';" />
                                <?php 
                }
                ?>
                        </div>
                        <?php 
            }
            ?>
                    <br class="clear" />
                </div>
                <?php 
        } else {
            ?>
                <br class="clear" />
                <?php 
        }
        ?>
            <div class="clear"></div>
            <?php 
        if (empty($this->data) && false !== $this->default_none && false === $this->search) {
            ?>
                <p><?php 
            _e('Please use the search filter(s) above to display data', 'pods');
            if ($this->export) {
                ?>
, <?php 
                _e('or click on an Export to download a full copy of the data', 'pods');
            }
            ?>
.</p>
                <?php 
        } else {
            $this->table($reorder);
        }
        if (!empty($this->data)) {
            if (true !== $reorder && (false !== $this->pagination_total || false !== $this->pagination)) {
                ?>
                    <div class="tablenav">
                        <div class="tablenav-pages<?php 
                echo esc_attr($this->limit < $this->total_found || 1 < $this->page ? '' : ' one-page');
                ?>
">
                            <?php 
                $this->pagination(0);
                ?>
                            <br class="clear" />
                        </div>
                    </div>
                    <?php 
            }
        }
        ?>
        </form>
    </div>
    <?php 
        if ($this->filters_enhanced) {
            $this->filters_popup();
        }
    }

Usage Example

示例#1
0
 /**
  * Toggle a component on or off
  *
  * @param PodsUI $ui
  *
  * @return bool
  */
 public function admin_components_toggle(PodsUI $ui)
 {
     $component = $_GET['id'];
     if (!empty(PodsInit::$components->components[$component]['PluginDependency'])) {
         $dependency = explode('|', PodsInit::$components->components[$component]['PluginDependency']);
         if (!pods_is_plugin_active($dependency[1])) {
             $website = 'http://wordpress.org/extend/plugins/' . dirname($dependency[1]) . '/';
             if (isset($dependency[2])) {
                 $website = $dependency[2];
             }
             if (!empty($website)) {
                 $website = ' ' . sprintf(__('You can find it at %s', 'pods'), '<a href="' . $website . '" target="_blank">' . $website . '</a>');
             }
             $message = sprintf(__('The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods'), PodsInit::$components->components[$component]['Name'], $dependency[0]) . $website;
             $ui->error($message);
             $ui->manage();
             return;
         }
     }
     if (!empty(PodsInit::$components->components[$component]['ThemeDependency'])) {
         $dependency = explode('|', PodsInit::$components->components[$component]['ThemeDependency']);
         if (strtolower($dependency[1]) != strtolower(get_template()) && strtolower($dependency[1]) != strtolower(get_stylesheet())) {
             $website = '';
             if (isset($dependency[2])) {
                 $website = ' ' . sprintf(__('You can find it at %s', 'pods'), '<a href="' . $dependency[2] . '" target="_blank">' . $dependency[2] . '</a>');
             }
             $message = sprintf(__('The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods'), PodsInit::$components->components[$component]['Name'], $dependency[0]) . $website;
             $ui->error($message);
             $ui->manage();
             return;
         }
     }
     if (!empty(PodsInit::$components->components[$component]['MustUse'])) {
         $message = sprintf(__('The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods'), PodsInit::$components->components[$component]['Name']);
         $ui->error($message);
         $ui->manage();
         return;
     }
     if (1 == pods_var('toggled')) {
         $toggle = PodsInit::$components->toggle($component);
         if (true === $toggle) {
             $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component enabled', 'pods'));
         } elseif (false === $toggle) {
             $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component disabled', 'pods'));
         }
         $components = PodsInit::$components->components;
         foreach ($components as $component => &$component_data) {
             $toggle = 0;
             if (isset(PodsInit::$components->settings['components'][$component_data['ID']])) {
                 if (0 != PodsInit::$components->settings['components'][$component_data['ID']]) {
                     $toggle = 1;
                 }
             }
             if (true === $component_data['DeveloperMode']) {
                 if (!pods_developer()) {
                     unset($components[$component]);
                     continue;
                 }
             }
             $component_data = array('id' => $component_data['ID'], 'name' => $component_data['Name'], 'description' => make_clickable($component_data['Description']), 'version' => $component_data['Version'], 'author' => $component_data['Author'], 'toggle' => $toggle);
         }
         $ui->data = $components;
         pods_transient_clear('pods_components');
         $url = pods_var_update(array('toggled' => null));
         pods_redirect($url);
     } elseif (1 == pods_var('toggle')) {
         $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component enabled', 'pods'));
     } else {
         $ui->message(PodsInit::$components->components[$component]['Name'] . ' ' . __('Component disabled', 'pods'));
     }
     $ui->manage();
 }
All Usage Examples Of PodsUI::manage