/classes/PodsUI.php
PHP | 3523 lines | 2764 code | 410 blank | 349 comment | 773 complexity | 5983e2663f1640e9d8f68e03953b2a6b MD5 | raw file
Possible License(s): AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @package Pods
- */
- class PodsUI {
- // internal
- /**
- * @var bool|PodsData
- */
- private $pods_data = false;
- /**
- * @var array
- */
- private $actions = array(
- 'manage',
- 'add',
- 'edit',
- 'duplicate',
- 'save',
- 'view',
- 'delete',
- 'reorder',
- 'export'
- );
- /**
- * @var array
- */
- private $ui_page = array();
- /**
- * @var bool
- */
- private $unique_identifier = false;
- // base
- public $x = array();
- /**
- * @var array|bool|mixed|null|Pods
- */
- public $pod = false;
- /**
- * @var int
- */
- public $id = 0;
- /**
- * @var string
- */
- public $num = ''; // allows multiple co-existing PodsUI instances with separate functionality in URL
- /**
- * @var array
- */
- static $excluded = array(
- 'do',
- 'id',
- 'pg',
- 'search',
- 'filter_*',
- 'orderby',
- 'orderby_dir',
- 'limit',
- 'action',
- 'action_bulk',
- 'action_bulk_ids',
- 'view',
- 'export',
- 'export_type',
- 'export_delimiter',
- 'remove_export',
- 'updated',
- 'duplicate'
- ); // used in var_update
- // ui
- /**
- * @var bool
- */
- public $item = false; // to be set with localized string
- /**
- * @var bool
- */
- public $items = false; // to be set with localized string
- /**
- * @var bool
- */
- public $heading = false; // to be set with localized string array
- /**
- * @var bool
- */
- public $header = false; // to be set with localized string array
- /**
- * @var bool
- */
- public $label = false; // to be set with localized string array
- /**
- * @var bool
- */
- public $icon = false;
- /**
- * @var bool
- */
- public $css = false; // set to a URL of stylesheet to include
- /**
- * @var bool
- */
- public $wpcss = false; // set to true to include WP Admin stylesheets
- /**
- * @var array
- */
- public $fields = array(
- 'manage' => array(),
- 'search' => array(),
- 'form' => array(),
- 'add' => array(),
- 'edit' => array(),
- 'duplicate' => array(),
- 'view' => array(),
- 'reorder' => array(),
- 'export' => array()
- );
- /**
- * @var bool
- */
- public $searchable = true;
- /**
- * @var bool
- */
- public $sortable = true;
- /**
- * @var bool
- */
- public $pagination = true;
- /**
- * @var bool
- */
- public $pagination_total = true;
- /**
- * @var array
- */
- public $export = array(
- 'on' => false,
- 'formats' => array(
- 'csv' => ',',
- 'tsv' => "\t",
- 'xml' => false,
- 'json' => false
- ),
- 'url' => false,
- 'type' => false
- );
- /**
- * @var array
- */
- public $reorder = array(
- 'on' => false,
- 'limit' => 250,
- 'orderby' => false,
- 'orderby_dir' => 'ASC',
- 'sql' => null
- );
- /**
- * @var array
- */
- public $screen_options = array(); // set to 'page' => 'Text'; false hides link
- /**
- * @var array
- */
- public $help = array(); // set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link
- // data
- /**
- * @var bool
- */
- public $search = false;
- /**
- * @var bool
- */
- public $filters_enhanced = false;
- /**
- * @var array
- */
- public $filters = array();
- /**
- * @var string
- */
- public $view = false;
- /**
- * @var array
- */
- public $views = array();
- /**
- * @var bool
- */
- public $search_across = true;
- /**
- * @var bool
- */
- public $search_across_picks = false;
- /**
- * @var bool
- */
- public $default_none = false;
- /**
- * @var array
- */
- public $where = array(
- 'manage' => null,
- 'edit' => null,
- 'duplicate' => null,
- 'delete' => null,
- 'reorder' => null
- );
- /**
- * @var bool
- */
- public $orderby = false;
- /**
- * @var string
- */
- public $orderby_dir = 'DESC';
- /**
- * @var int
- */
- public $limit = 25;
- /**
- * @var int
- */
- public $page = 1;
- /**
- * @var int
- */
- public $total = 0;
- /**
- * @var int
- */
- public $total_found = 0;
- /**
- * @var array
- */
- public $session = array(
- 'search',
- 'filters'
- ); // allowed: search, filters, show_per_page, orderby (priority over usermeta)
- /**
- * @var array
- */
- public $user = array(
- 'show_per_page',
- 'orderby'
- ); // allowed: search, filters, show_per_page, orderby (priority under session)
- // advanced data
- /**
- * @var array
- */
- public $sql = array(
- 'table' => null,
- 'field_id' => 'id',
- 'field_index' => 'name',
- 'select' => null,
- 'sql' => null
- );
- /**
- * @var array
- */
- public $params = array();
- /**
- * @var bool|array
- */
- public $data = false;
- /**
- * @var bool|array
- */
- public $data_full = false;
- /**
- * @var array
- */
- public $data_keys = array();
- /**
- * @var array
- */
- public $row = array();
- // actions
- /**
- * @var string
- */
- public $action = 'manage';
- /**
- * @var string
- */
- public $action_bulk = false;
- /**
- * @var array
- */
- public $bulk = array();
- /**
- * @var array
- */
- public $action_after = array(
- 'add' => 'edit',
- 'edit' => 'edit',
- 'duplicate' => 'edit'
- ); // set action to 'manage'
- /**
- * @var bool
- */
- public $do = false;
- /**
- * @var array
- */
- public $action_links = array(
- 'add' => null,
- 'edit' => null,
- 'duplicate' => null,
- 'view' => null,
- 'delete' => null,
- 'reorder' => null,
- 'export' => null
- ); // custom links (callable allowed)
- /**
- * @var array
- */
- public $actions_disabled = array(
- 'view',
- 'export'
- ); // disable actions
- /**
- * @var array
- */
- public $actions_hidden = array(); // hide actions to not show them but allow them
- /**
- * @var array
- */
- public $actions_custom = array(); // overwrite existing actions or add your own
- /**
- * @var array
- */
- public $actions_bulk = array(); // enabled bulk actions
- /**
- * @var bool|string
- */
- public $restrict = array(
- 'manage' => null,
- 'edit' => null,
- 'duplicate' => null,
- 'delete' => null,
- 'reorder' => null,
- 'author_restrict' => null
- );
- /**
- * @var bool
- */
- public $save = false; // Allow custom save handling for tables that aren't Pod-based
- /**
- * Generate UI for Data Management
- *
- * @param mixed $options Object, Array, or String containing Pod or Options to be used
- * @param bool $deprecated Set to true to support old options array from Pods UI plugin
- *
- * @license http://www.gnu.org/licenses/gpl-2.0.html
- * @since 2.0.0
- */
- public function __construct ( $options, $deprecated = false ) {
- $object = null;
- if ( is_object( $options ) ) {
- $object = $options;
- $options = array();
- if ( isset( $object->ui ) ) {
- $options = (array) $object->ui;
- unset( $object->ui );
- }
- if ( is_object( $object ) && ( 'Pods' == get_class( $object ) || 'Pod' == get_class( $object ) ) )
- $this->pod = &$object;
- }
- if ( !is_array( $options ) ) {
- // @todo need to come back to this and allow for multi-dimensional strings
- // like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
- if ( false !== strpos( $options, '=' ) || false !== strpos( $options, '&' ) )
- parse_str( $options, $options );
- else
- $options = array( 'pod' => $options );
- }
- if ( !is_object( $object ) && isset( $options[ 'pod' ] ) ) {
- if ( is_object( $options[ 'pod' ] ) )
- $this->pod = $options[ 'pod' ];
- elseif ( isset( $options[ 'id' ] ) )
- $this->pod = pods( $options[ 'pod' ], $options[ 'id' ] );
- else
- $this->pod = pods( $options[ 'pod' ] );
- unset( $options[ 'pod' ] );
- }
- elseif ( is_object( $object ) )
- $this->pod = $object;
- if ( false !== $deprecated || ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) ) )
- $options = $this->setup_deprecated( $options );
- if ( is_object( $this->pod ) && 'Pod' == get_class( $this->pod ) && is_object( $this->pod->_data ) )
- $this->pods_data =& $this->pod->_data;
- elseif ( is_object( $this->pod ) && 'Pods' == get_class( $this->pod ) && is_object( $this->pod->data ) )
- $this->pods_data =& $this->pod->data;
- elseif ( is_object( $this->pod ) )
- $this->pods_data = pods_data( $this->pod->pod );
- elseif ( !is_object( $this->pod ) )
- $this->pods_data = pods_data( $this->pod );
- $options = $this->do_hook( 'pre_init', $options );
- $this->setup( $options );
- if ( is_object( $this->pods_data ) && is_object( $this->pod ) && 0 < $this->id && $this->id != $this->pods_data->id )
- $this->row = $this->pods_data->fetch( $this->id );
- if ( ( !is_object( $this->pod ) || 'Pods' != get_class( $this->pod ) ) && false === $this->sql[ 'table' ] && false === $this->data ) {
- echo $this->error( __( '<strong>Error:</strong> Pods UI needs a Pods object or a Table definition to run from, see the User Guide for more information.', 'pods' ) );
- return false;
- }
- $this->go();
- }
- /**
- * @param $deprecated_options
- *
- * @return array
- */
- public function setup_deprecated ( $deprecated_options ) {
- $options = array();
- if ( isset( $deprecated_options[ 'id' ] ) )
- $options[ 'id' ] = $deprecated_options[ 'id' ];
- if ( isset( $deprecated_options[ 'action' ] ) )
- $options[ 'action' ] = $deprecated_options[ 'action' ];
- if ( isset( $deprecated_options[ 'num' ] ) )
- $options[ 'num' ] = $deprecated_options[ 'num' ];
- if ( isset( $deprecated_options[ 'title' ] ) )
- $options[ 'items' ] = $deprecated_options[ 'title' ];
- if ( isset( $deprecated_options[ 'item' ] ) )
- $options[ 'item' ] = $deprecated_options[ 'item' ];
- if ( isset( $deprecated_options[ 'label' ] ) )
- $options[ 'label' ] = array(
- 'add' => $deprecated_options[ 'label' ],
- 'edit' => $deprecated_options[ 'label' ],
- 'duplicate' => $deprecated_options[ 'label' ]
- );
- if ( isset( $deprecated_options[ 'label_add' ] ) ) {
- if ( isset( $options[ 'label' ] ) )
- $options[ 'label' ][ 'add' ] = $deprecated_options[ 'label_add' ];
- else
- $options[ 'label' ] = array( 'add' => $deprecated_options[ 'label_add' ] );
- }
- if ( isset( $deprecated_options[ 'label_edit' ] ) ) {
- if ( isset( $options[ 'label' ] ) )
- $options[ 'label' ][ 'edit' ] = $deprecated_options[ 'label_edit' ];
- else
- $options[ 'label' ] = array( 'edit' => $deprecated_options[ 'label_edit' ] );
- }
- if ( isset( $deprecated_options[ 'label_duplicate' ] ) ) {
- if ( isset( $options[ 'label' ] ) )
- $options[ 'label' ][ 'duplicate' ] = $deprecated_options[ 'label_duplicate' ];
- else
- $options[ 'label' ] = array( 'duplicate' => $deprecated_options[ 'label_duplicate' ] );
- }
- if ( isset( $deprecated_options[ 'icon' ] ) )
- $options[ 'icon' ] = $deprecated_options[ 'icon' ];
- if ( isset( $deprecated_options[ 'columns' ] ) )
- $options[ 'fields' ] = array( 'manage' => $deprecated_options[ 'columns' ] );
- if ( isset( $deprecated_options[ 'reorder_columns' ] ) ) {
- if ( isset( $options[ 'fields' ] ) )
- $options[ 'fields' ][ 'reorder' ] = $deprecated_options[ 'reorder_columns' ];
- else
- $options[ 'fields' ] = array( 'reorder' => $deprecated_options[ 'reorder_columns' ] );
- }
- if ( isset( $deprecated_options[ 'add_fields' ] ) ) {
- if ( isset( $options[ 'fields' ] ) ) {
- if ( !isset( $options[ 'fields' ][ 'add' ] ) )
- $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'add_fields' ];
- if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
- $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'add_fields' ];
- if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
- $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'add_fields' ];
- }
- else
- $options[ 'fields' ] = array(
- 'add' => $deprecated_options[ 'add_fields' ],
- 'edit' => $deprecated_options[ 'add_fields' ],
- 'duplicate' => $deprecated_options[ 'add_fields' ]
- );
- }
- if ( isset( $deprecated_options[ 'edit_fields' ] ) ) {
- if ( isset( $options[ 'fields' ] ) ) {
- if ( !isset( $options[ 'fields' ][ 'add' ] ) )
- $options[ 'fields' ][ 'add' ] = $deprecated_options[ 'edit_fields' ];
- if ( !isset( $options[ 'fields' ][ 'edit' ] ) )
- $options[ 'fields' ][ 'edit' ] = $deprecated_options[ 'edit_fields' ];
- if ( !isset( $options[ 'fields' ][ 'duplicate' ] ) )
- $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'edit_fields' ];
- }
- else
- $options[ 'fields' ] = array(
- 'add' => $deprecated_options[ 'edit_fields' ],
- 'edit' => $deprecated_options[ 'edit_fields' ],
- 'duplicate' => $deprecated_options[ 'edit_fields' ]
- );
- }
- if ( isset( $deprecated_options[ 'duplicate_fields' ] ) ) {
- if ( isset( $options[ 'fields' ] ) )
- $options[ 'fields' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_fields' ];
- else
- $options[ 'fields' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_fields' ] );
- }
- if ( isset( $deprecated_options[ 'session_filters' ] ) && false === $deprecated_options[ 'session_filters' ] )
- $options[ 'session' ] = false;
- if ( isset( $deprecated_options[ 'user_per_page' ] ) ) {
- if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
- $options[ 'user' ] = array( 'orderby' );
- else
- $options[ 'user' ] = false;
- }
- if ( isset( $deprecated_options[ 'user_sort' ] ) ) {
- if ( isset( $options[ 'user' ] ) && !empty( $options[ 'user' ] ) )
- $options[ 'user' ] = array( 'show_per_page' );
- else
- $options[ 'user' ] = false;
- }
- if ( isset( $deprecated_options[ 'custom_list' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'manage' ] = $deprecated_options[ 'custom_list' ];
- else
- $options[ 'actions_custom' ] = array( 'manage' => $deprecated_options[ 'custom_list' ] );
- }
- if ( isset( $deprecated_options[ 'custom_reorder' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'reorder' ] = $deprecated_options[ 'custom_reorder' ];
- else
- $options[ 'actions_custom' ] = array( 'reorder' => $deprecated_options[ 'custom_reorder' ] );
- }
- if ( isset( $deprecated_options[ 'custom_add' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'add' ] = $deprecated_options[ 'custom_add' ];
- else
- $options[ 'actions_custom' ] = array( 'add' => $deprecated_options[ 'custom_add' ] );
- }
- if ( isset( $deprecated_options[ 'custom_edit' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'edit' ] = $deprecated_options[ 'custom_edit' ];
- else
- $options[ 'actions_custom' ] = array( 'edit' => $deprecated_options[ 'custom_edit' ] );
- }
- if ( isset( $deprecated_options[ 'custom_duplicate' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'duplicate' ] = $deprecated_options[ 'custom_duplicate' ];
- else
- $options[ 'actions_custom' ] = array( 'duplicate' => $deprecated_options[ 'custom_duplicate' ] );
- }
- if ( isset( $deprecated_options[ 'custom_delete' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'delete' ] = $deprecated_options[ 'custom_delete' ];
- else
- $options[ 'actions_custom' ] = array( 'delete' => $deprecated_options[ 'custom_delete' ] );
- }
- if ( isset( $deprecated_options[ 'custom_save' ] ) ) {
- if ( isset( $options[ 'actions_custom' ] ) )
- $options[ 'actions_custom' ][ 'save' ] = $deprecated_options[ 'custom_save' ];
- else
- $options[ 'actions_custom' ] = array( 'save' => $deprecated_options[ 'custom_save' ] );
- }
- if ( isset( $deprecated_options[ 'custom_actions' ] ) )
- $options[ 'actions_custom' ] = $deprecated_options[ 'custom_actions' ];
- if ( isset( $deprecated_options[ 'action_after_save' ] ) )
- $options[ 'action_after' ] = array(
- 'add' => $deprecated_options[ 'action_after_save' ],
- 'edit' => $deprecated_options[ 'action_after_save' ],
- 'duplicate' => $deprecated_options[ 'action_after_save' ]
- );
- if ( isset( $deprecated_options[ 'edit_link' ] ) ) {
- if ( isset( $options[ 'action_links' ] ) )
- $options[ 'action_links' ][ 'edit' ] = $deprecated_options[ 'edit_link' ];
- else
- $options[ 'action_links' ] = array( 'edit' => $deprecated_options[ 'edit_link' ] );
- }
- if ( isset( $deprecated_options[ 'view_link' ] ) ) {
- if ( isset( $options[ 'action_links' ] ) )
- $options[ 'action_links' ][ 'view' ] = $deprecated_options[ 'view_link' ];
- else
- $options[ 'action_links' ] = array( 'view' => $deprecated_options[ 'view_link' ] );
- }
- if ( isset( $deprecated_options[ 'duplicate_link' ] ) ) {
- if ( isset( $options[ 'action_links' ] ) )
- $options[ 'action_links' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_link' ];
- else
- $options[ 'action_links' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_link' ] );
- }
- if ( isset( $deprecated_options[ 'reorder' ] ) )
- $options[ 'reorder' ] = array(
- 'on' => $deprecated_options[ 'reorder' ],
- 'orderby' => $deprecated_options[ 'reorder' ]
- );
- if ( isset( $deprecated_options[ 'reorder_sort' ] ) && isset( $options[ 'reorder' ] ) )
- $options[ 'reorder' ][ 'orderby' ] = $deprecated_options[ 'reorder_sort' ];
- if ( isset( $deprecated_options[ 'reorder_limit' ] ) && isset( $options[ 'reorder' ] ) )
- $options[ 'reorder' ][ 'limit' ] = $deprecated_options[ 'reorder_limit' ];
- if ( isset( $deprecated_options[ 'reorder_sql' ] ) && isset( $options[ 'reorder' ] ) )
- $options[ 'reorder' ][ 'sql' ] = $deprecated_options[ 'reorder_sql' ];
- if ( isset( $deprecated_options[ 'sort' ] ) )
- $options[ 'orderby' ] = $deprecated_options[ 'sort' ];
- if ( isset( $deprecated_options[ 'sortable' ] ) )
- $options[ 'sortable' ] = $deprecated_options[ 'sortable' ];
- if ( isset( $deprecated_options[ 'limit' ] ) )
- $options[ 'limit' ] = $deprecated_options[ 'limit' ];
- if ( isset( $deprecated_options[ 'where' ] ) ) {
- if ( isset( $options[ 'where' ] ) )
- $options[ 'where' ][ 'manage' ] = $deprecated_options[ 'where' ];
- else
- $options[ 'where' ] = array( 'manage' => $deprecated_options[ 'where' ] );
- }
- if ( isset( $deprecated_options[ 'edit_where' ] ) ) {
- if ( isset( $options[ 'where' ] ) )
- $options[ 'where' ][ 'edit' ] = $deprecated_options[ 'edit_where' ];
- else
- $options[ 'where' ] = array( 'edit' => $deprecated_options[ 'edit_where' ] );
- if ( isset( $options[ 'restrict' ] ) )
- $options[ 'restrict' ][ 'edit' ] = (array) $deprecated_options[ 'edit_where' ];
- else
- $options[ 'restrict' ] = array( 'edit' => (array) $deprecated_options[ 'edit_where' ] );
- }
- if ( isset( $deprecated_options[ 'duplicate_where' ] ) ) {
- if ( isset( $options[ 'where' ] ) )
- $options[ 'where' ][ 'duplicate' ] = $deprecated_options[ 'duplicate_where' ];
- else
- $options[ 'where' ] = array( 'duplicate' => $deprecated_options[ 'duplicate_where' ] );
- if ( isset( $options[ 'restrict' ] ) )
- $options[ 'restrict' ][ 'duplicate' ] = (array) $deprecated_options[ 'duplicate_where' ];
- else
- $options[ 'restrict' ] = array( 'duplicate' => (array) $deprecated_options[ 'duplicate_where' ] );
- }
- if ( isset( $deprecated_options[ 'delete_where' ] ) ) {
- if ( isset( $options[ 'where' ] ) )
- $options[ 'where' ][ 'delete' ] = $deprecated_options[ 'delete_where' ];
- else
- $options[ 'where' ] = array( 'delete' => $deprecated_options[ 'delete_where' ] );
- if ( isset( $options[ 'restrict' ] ) )
- $options[ 'restrict' ][ 'delete' ] = (array) $deprecated_options[ 'delete_where' ];
- else
- $options[ 'restrict' ] = array( 'delete' => (array) $deprecated_options[ 'delete_where' ] );
- }
- if ( isset( $deprecated_options[ 'reorder_where' ] ) ) {
- if ( isset( $options[ 'where' ] ) )
- $options[ 'where' ][ 'reorder' ] = $deprecated_options[ 'reorder_where' ];
- else
- $options[ 'where' ] = array( 'reorder' => $deprecated_options[ 'reorder_where' ] );
- }
- if ( isset( $deprecated_options[ 'sql' ] ) )
- $options[ 'sql' ] = array( 'sql' => $deprecated_options[ 'sql' ] );
- if ( isset( $deprecated_options[ 'search' ] ) )
- $options[ 'searchable' ] = $deprecated_options[ 'search' ];
- if ( isset( $deprecated_options[ 'search_across' ] ) )
- $options[ 'search_across' ] = $deprecated_options[ 'search_across' ];
- if ( isset( $deprecated_options[ 'search_across_picks' ] ) )
- $options[ 'search_across_picks' ] = $deprecated_options[ 'search_across_picks' ];
- if ( isset( $deprecated_options[ 'filters' ] ) )
- $options[ 'filters' ] = $deprecated_options[ 'filters' ];
- if ( isset( $deprecated_options[ 'custom_filters' ] ) ) {
- if ( is_callable( $deprecated_options[ 'custom_filters' ] ) )
- add_filter( 'pods_ui_filters', $deprecated_options[ 'custom_filters' ] );
- else {
- global $pods_ui_custom_filters;
- $pods_ui_custom_filters = $deprecated_options[ 'custom_filters' ];
- add_filter( 'pods_ui_filters', array( $this, 'deprecated_filters' ) );
- }
- }
- if ( isset( $deprecated_options[ 'disable_actions' ] ) )
- $options[ 'actions_disabled' ] = $deprecated_options[ 'disable_actions' ];
- if ( isset( $deprecated_options[ 'hide_actions' ] ) )
- $options[ 'actions_hidden' ] = $deprecated_options[ 'hide_actions' ];
- if ( isset( $deprecated_options[ 'wpcss' ] ) )
- $options[ 'wpcss' ] = $deprecated_options[ 'wpcss' ];
- $remaining_options = array_diff_assoc( $options, $deprecated_options );
- foreach ( $remaining_options as $option => $value ) {
- if ( isset( $deprecated_options[ $option ] ) && isset( $this->$option ) )
- $options[ $option ] = $value;
- }
- return $options;
- }
- /**
- *
- */
- public function deprecated_filters () {
- global $pods_ui_custom_filters;
- echo $pods_ui_custom_filters;
- }
- /**
- * @param $options
- *
- * @return array|bool|mixed|null|PodsArray
- */
- public function setup ( $options ) {
- $options = pods_array( $options );
- $options->validate( 'num', '', 'absint' );
- if ( empty( $options->num ) )
- $options->num = '';
- $options->validate( 'id', pods_var( 'id' . $options->num, 'get', $this->id ) );
- $options->validate( 'do', pods_var( 'do' . $options->num, 'get', $this->do ), 'in_array', array(
- 'save',
- 'create'
- ) );
- $options->validate( 'excluded', self::$excluded, 'array_merge' );
- $options->validate( 'action', pods_var( 'action' . $options->num, 'get', $this->action, null, true ), 'in_array', $this->actions );
- $options->validate( 'actions_bulk', $this->actions_bulk, 'array_merge' );
- $options->validate( 'action_bulk', pods_var( 'action_bulk' . $options->num, 'get', $this->action_bulk, null, true ), 'isset', $this->actions_bulk );
- $options->validate( 'bulk', pods_var( 'action_bulk_ids' . $options->num, 'get', array(), null, true ), 'array_merge', $this->bulk );
- $options->validate( 'views', $this->views, 'array' );
- $options->validate( 'view', pods_var( 'view' . $options->num, 'get', $this->view, null, true ), 'isset', $this->views );
- $options->validate( 'searchable', $this->searchable, 'boolean' );
- $options->validate( 'search', pods_var( 'search' . $options->num, 'get' ) );
- $options->validate( 'search_across', $this->search_across, 'boolean' );
- $options->validate( 'search_across_picks', $this->search_across_picks, 'boolean' );
- $options->validate( 'filters', $this->filters, 'array' );
- $options->validate( 'filters_enhanced', $this->filters_enhanced, 'boolean' );
- $options->validate( 'where', $this->where, 'array_merge' );
- $options->validate( 'pagination', $this->pagination, 'boolean' );
- $options->validate( 'page', pods_var( 'pg' . $options->num, 'get', $this->page ), 'absint' );
- $options->validate( 'limit', pods_var( 'limit' . $options->num, 'get', $this->limit ), 'int' );
- if ( isset( $this->pods_data ) && is_object( $this->pods_data ) ) {
- $this->sql = array(
- 'table' => $this->pods_data->table,
- 'field_id' => $this->pods_data->field_id,
- 'field_index' => $this->pods_data->field_index
- );
- }
- $options->validate( 'sql', $this->sql, 'array_merge' );
- $options->validate( 'orderby_dir', strtoupper( pods_var_raw( 'orderby_dir' . $options[ 'num' ], 'get', $this->orderby_dir, null, true ) ), 'in_array', array( 'ASC', 'DESC' ) );
- $orderby = pods_var_raw( 'orderby' . $options->num, 'get', $this->orderby, null, true );
- if ( !empty( $orderby ) ) {
- $orderby = array(
- 'default' => $orderby
- );
- }
- else
- $orderby = array();
- $options->validate( 'orderby', $orderby, 'array_merge' );
- $options->validate( 'sortable', $this->sortable, 'boolean' );
- $options->validate( 'params', $this->params, 'array' );
- $options->validate( 'restrict', $this->restrict, 'array_merge' );
- // handle author restrictions
- if ( !empty( $options[ 'restrict' ][ 'author_restrict' ] ) ) {
- if ( !is_array( $options[ 'restrict' ][ 'author_restrict' ] ) )
- $options->restrict[ 'author_restrict' ] = array( $options[ 'restrict' ][ 'author_restrict' ] => get_current_user_id() );
- if ( null === $options[ 'restrict' ][ 'edit' ] )
- $options->restrict[ 'edit' ] = $options[ 'restrict' ][ 'author_restrict' ];
- }
- if ( null !== $options[ 'restrict' ][ 'edit' ] ) {
- if ( null === $options[ 'restrict' ][ 'duplicate' ] )
- $options->restrict[ 'duplicate' ] = $options[ 'restrict' ][ 'edit' ];
- if ( null === $options[ 'restrict' ][ 'delete' ] )
- $options->restrict[ 'delete' ] = $options[ 'restrict' ][ 'edit' ];
- if ( null === $options[ 'restrict' ][ 'manage' ] )
- $options->restrict[ 'manage' ] = $options[ 'restrict' ][ 'edit' ];
- if ( null === $options[ 'restrict' ][ 'reorder' ] )
- $options->restrict[ 'reorder' ] = $options[ 'restrict' ][ 'edit' ];
- }
- $item = __( 'Item', 'pods' );
- $items = __( 'Items', 'pods' );
- if ( is_object( $this->pod ) ) {
- $item = pods_var_raw( 'label_singular', $this->pod->pod_data[ 'options' ], pods_var_raw( 'label', $this->pod->pod_data, $item, null, true ), null, true );
- $items = pods_var_raw( 'label', $this->pod->pod_data, $items, null, true );
- }
- $options->validate( 'item', $item );
- $options->validate( 'items', $items );
- $options->validate( 'heading', array(
- 'manage' => __( 'Manage', 'pods' ),
- 'add' => __( 'Add New', 'pods' ),
- 'edit' => __( 'Edit', 'pods' ),
- 'duplicate' => __( 'Duplicate', 'pods' ),
- 'view' => __( 'View', 'pods' ),
- 'reorder' => __( 'Reorder', 'pods' ),
- 'search' => __( 'Search', 'pods' ),
- 'views' => __( 'View', 'pods' )
- ), 'array_merge' );
- $options->validate( 'header', array(
- 'manage' => $options->items,
- 'add' => $options->heading[ 'add' ] . " {$options->item}",
- 'edit' => $options->heading[ 'edit' ] . " {$options->item}",
- 'duplicate' => $options->heading[ 'duplicate' ] . " {$options->item}",
- 'view' => $options->heading[ 'view' ] . " {$options->item}",
- 'reorder' => $options->heading[ 'reorder' ] . " {$options->items}",
- 'search' => $options->heading[ 'search' ] . " {$options->items}"
- ), 'array_merge' );
- $options->validate( 'label', array(
- 'add' => __( 'Save New', 'pods' ) . " {$options->item}",
- 'add_new' => __( 'Add New', 'pods' ),
- 'edit' => __( 'Save', 'pods' ) . " {$options->item}",
- 'duplicate' => __( 'Save New', 'pods' ) . " {$options->item}",
- 'delete' => __( 'Delete this', 'pods' ) . " {$options->item}",
- 'view' => __( 'View', 'pods' ) . " {$options->item}",
- 'reorder' => __( 'Reorder', 'pods' ) . " {$options->items}"
- ), 'array_merge' );
- $options->validate( 'fields', array(
- 'manage' => array(
- $options->sql[ 'field_index' ] => array( 'label' => __( 'Name', 'pods' ) )
- )
- ), 'array' );
- $options->validate( 'export', $this->export, 'array_merge' );
- $options->validate( 'reorder', $this->reorder, 'array_merge' );
- $options->validate( 'screen_options', $this->screen_options, 'array_merge' );
- $options->validate( 'session', $this->session, 'in_array', array(
- 'search',
- 'filters',
- 'show_per_page',
- 'orderby'
- ) );
- $options->validate( 'user', $this->user, 'in_array', array(
- 'search',
- 'filters',
- 'show_per_page',
- 'orderby'
- ) );
- $options->validate( 'action_after', $this->action_after, 'array_merge' );
- $options->validate( 'action_links', $this->action_links, 'array_merge' );
- $options->validate( 'actions_disabled', $this->actions_disabled, 'array' );
- $options->validate( 'actions_hidden', $this->actions_hidden, 'array_merge' );
- $options->validate( 'actions_custom', $this->actions_custom, 'array_merge' );
- $options->validate( 'icon', $this->icon );
- $options->validate( 'css', $this->css );
- $options->validate( 'wpcss', $this->wpcss, 'boolean' );
- if ( true === $options[ 'wpcss' ] ) {
- global $user_ID;
- get_currentuserinfo();
- $color = get_user_meta( $user_ID, 'admin_color', true );
- if ( strlen( $color ) < 1 )
- $color = 'fresh';
- $this->wpcss = "colors-{$color}";
- }
- $options = $options->dump();
- $options = $this->do_hook( 'setup_options', $options );
- if ( false !== $options && !empty( $options ) ) {
- foreach ( $options as $option => $value ) {
- if ( isset( $this->{$option} ) )
- $this->{$option} = $value;
- else
- $this->x[ $option ] = $value;
- }
- }
- $unique_identifier = pods_var( 'page', 'get' ); // wp-admin page
- if ( is_object( $this->pod ) && isset( $this->pod->pod ) )
- $unique_identifier = '_' . $this->pod->pod;
- elseif ( 0 < strlen( $this->sql[ 'table' ] ) )
- $unique_identifier = '_' . $this->sql[ 'table' ];
- $unique_identifier .= '_' . $this->page;
- if ( 0 < strlen( $this->num ) )
- $unique_identifier .= '_' . $this->num;
- $this->unique_identifier = 'pods_ui_' . md5( $unique_identifier );
- $this->setup_fields();
- return $options;
- }
- /**
- * @param null $fields
- * @param string $which
- *
- * @return array|bool|mixed|null
- */
- public function setup_fields ( $fields = null, $which = 'fields' ) {
- $init = false;
- if ( null === $fields ) {
- if ( isset( $this->fields[ $which ] ) )
- $fields = (array) $this->fields[ $which ];
- elseif ( isset( $this->fields[ 'manage' ] ) )
- $fields = (array) $this->fields[ 'manage' ];
- else
- $fields = array();
- if ( 'fields' == $which )
- $init = true;
- }
- if ( !empty( $fields ) ) {
- // Available Attributes
- // type = field type
- // type = date (data validation as date)
- // type = time (data validation as time)
- // type = datetime (data validation as datetime)
- // date_touch = use current timestamp when saving (even if readonly, if type is date-related)
- // date_touch_on_create = use current timestamp when saving ONLY on create (even if readonly, if type is date-related)
- // date_ongoing = use this additional field to search between as if the first is the "start" and the date_ongoing is the "end" for filter
- // type = text / other (single line text box)
- // type = desc (textarea)
- // type = number (data validation as int float)
- // type = decimal (data validation as decimal)
- // type = password (single line password box)
- // type = bool (checkbox)
- // type = related (select box)
- // related = table to relate to (if type=related) OR custom array of (key => label or comma separated values) items
- // related_field = field name on table to show (if type=related) - default "name"
- // related_multiple = true (ability to select multiple values if type=related)
- // related_sql = custom where / order by SQL (if type=related)
- // readonly = true (shows as text)
- // display = false (doesn't show on form, but can be saved)
- // search = this field is searchable
- // filter = this field will be independently searchable (by default, searchable fields are searched by the primary search box)
- // comments = comments to show for field
- // comments_top = true (shows comments above field instead of below)
- // real_name = the real name of the field (if using an alias for 'name')
- // group_related = true (uses HAVING instead of WHERE for filtering field)
- $new_fields = array();
- $filterable = false;
- if ( empty( $this->filters ) && ( empty( $this->fields[ 'search' ] ) || 'search' == $which ) && false !== $this->searchable ) {
- $filterable = true;
- $this->filters = array();
- }
- foreach ( $fields as $field => $attributes ) {
- if ( !is_array( $attributes ) ) {
- if ( is_int( $field ) ) {
- $field = $attributes;
- $attributes = array();
- }
- else
- $attributes = array( 'label' => $attributes );
- }
- if ( !isset( $attributes[ 'real_name' ] ) )
- $attributes[ 'real_name' ] = pods_var( 'name', $attributes, $field );
- if ( is_object( $this->pod ) && isset( $this->pod->fields ) && isset( $this->pod->fields[ $attributes[ 'real_name' ] ] ) )
- $attributes = array_merge( $this->pod->fields[ $attributes[ 'real_name' ] ], $attributes );
- if ( !isset( $attributes[ 'options' ] ) )
- $attributes[ 'options' ] = array();
- if ( !isset( $attributes[ 'id' ] ) )
- $attributes[ 'id' ] = '';
- if ( !isset( $attributes[ 'label' ] ) )
- $attributes[ 'label' ] = ucwords( str_replace( '_', ' ', $field ) );
- if ( !isset( $attributes[ 'type' ] ) )
- $attributes[ 'type' ] = 'text';
- if ( !isset( $attributes[ 'options' ][ 'date_format_type' ] ) )
- $attributes[ 'options' ][ 'date_format_type' ] = 'date';
- if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related' ] ) )
- $attributes[ 'related' ] = false;
- if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_id' ] ) )
- $attributes[ 'related_id' ] = 'id';
- if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_field' ] ) )
- $attributes[ 'related_field' ] = 'name';
- if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_multiple' ] ) )
- $attributes[ 'related_multiple' ] = false;
- if ( 'related' != $attributes[ 'type' ] || !isset( $attributes[ 'related_sql' ] ) )
- $attributes[ 'related_sql' ] = false;
- if ( 'related' == $attributes[ 'type' ] && ( is_array( $attributes[ 'related' ] ) || strpos( $attributes[ 'related' ], ',' ) ) ) {
- if ( !is_array( $attributes[ 'related' ] ) ) {
- $attributes[ 'related' ] = @explode( ',', $attributes[ 'related' ] );
- $related_items = array();
- foreach ( $attributes[ 'related' ] as $key => $label ) {
- if ( is_numeric( $key ) ) {
- $key = $label;
- $label = ucwords( str_replace( '_', ' ', $label ) );
- }
- $related_items[ $key ] = $label;
- }
- $attributes[ 'related' ] = $related_items;
- }
- if ( empty( $attributes[ 'related' ] ) )
- $attributes[ 'related' ] = false;
- }
- if ( !isset( $attributes[ 'readonly' ] ) )
- $attributes[ 'readonly' ] = false;
- if ( !isset( $attributes[ 'date_touch' ] ) || 'date' != $attributes[ 'type' ] )
- $attributes[ 'date_touch' ] = false;
- if ( !isset( $attributes[ 'date_touch_on_create' ] ) || 'date' != $attributes[ 'type' ] )
- $attributes[ 'date_touch_on_create' ] = false;
- if ( !isset( $attributes[ 'display' ] ) )
- $attributes[ 'display' ] = true;
- if ( !isset( $attributes[ 'hidden' ] ) )
- $attributes[ 'hidden' ] = false;
- if ( !isset( $attributes[ 'sortable' ] ) || false === $this->sortable )
- $attributes[ 'sortable' ] = $this->sortable;
- if ( !isset( $attributes[ 'options' ][ 'search' ] ) || false === $this->searchable )
- $attributes[ 'options' ][ 'search' ] = $this->searchable;
- if ( !isset( $attributes[ 'options' ][ 'filter' ] ) || false === $this->searchable )
- $attributes[ 'options' ][ 'filter' ] = $this->searchable;
- /*if ( false !== $attributes[ 'options' ][ 'filter' ] && false !== $filterable )
- $this->filters[] = $field;*/
- if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_label' ] ) || !in_array( $field, $this->filters ) )
- $attributes[ 'filter_label' ] = $attributes[ 'label' ];
- if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'filter_default' ] ) || !in_array( $field, $this->filters ) )
- $attributes[ 'filter_default' ] = false;
- if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !in_array( $field, $this->filters ) )
- $attributes[ 'date_ongoing' ] = false;
- if ( false === $attributes[ 'options' ][ 'filter' ] || !isset( $attributes[ 'date_ongoing' ] ) || 'date' != $attributes[ 'type' ] || !isset( $attributes[ 'date_ongoing_default' ] ) || !in_array( $field, $this->filters ) )
- $attributes[ 'date_ongoing_default' ] = false;
- if ( !isset( $attributes[ 'export' ] ) )
- $attributes[ 'export' ] = true;
- if ( !isset( $attributes[ 'group_related' ] ) )
- $attributes[ 'group_related' ] = false;
- if ( !isset( $attributes[ 'comments' ] ) )
- $attributes[ 'comments' ] = '';
- if ( !isset( $attributes[ 'comments_top' ] ) )
- $attributes[ 'comments_top' ] = false;
- if ( !isset( $attributes[ 'custom_view' ] ) )
- $attributes[ 'custom_view' ] = false;
- if ( !isset( $attributes[ 'custom_input' ] ) )
- $attributes[ 'custom_input' ] = false;
- if ( isset( $attributes[ 'display_helper' ] ) ) // pods ui backward compatibility
- $attributes[ 'custom_display' ] = $attributes[ 'display_helper' ];
- if ( !isset( $attributes[ 'custom_display' ] ) )
- $attributes[ 'custom_display' ] = false;
- if ( !isset( $attributes[ 'custom_relate' ] ) )
- $attributes[ 'custom_relate' ] = false;
- if ( !isset( $attributes[ 'custom_form_display' ] ) )
- $attributes[ 'custom_form_display' ] = false;
- if ( 'search_columns' == $which && !$attributes[ 'options' ][ 'search' ] )
- continue;
- $attributes = PodsForm::field_setup( $attributes, null, $attributes[ 'type' ] );
- $new_fields[ $field ] = $attributes;
- }
- $fields = $new_fields;
- }
- if ( false !== $init ) {
- if ( 'fields' != $which && !empty( $this->fields ) )
- $this->fields = $this->setup_fields( $this->fields, 'fields' );
- else
- $this->fields[ 'manage' ] = $fields;
- if ( !in_array( 'add', $this->actions_disabled ) || !in_array( 'edit', $this->actions_disabled ) || !in_array( 'duplicate', $this->actions_disabled ) ) {
- if ( 'form' != $which && isset( $this->fields[ 'form' ] ) && is_array( $this->fields[ 'form' ] ) )
- $this->fields[ 'form' ] = $this->setup_fields( $this->fields[ 'form' ], 'form' );
- else
- $this->fields[ 'form' ] = $fields;
- if ( !in_array( 'add', $this->actions_disabled ) ) {
- if ( 'add' != $which && isset( $this->fields[ 'add' ] ) && is_array( $this->fields[ 'add' ] ) )
- $this->fields[ 'add' ] = $this->setup_fields( $this->fields[ 'add' ], 'add' );
- }
- if ( !in_array( 'edit', $this->actions_disabled ) ) {
- if ( 'edit' != $which && isset( $this->fields[ 'edit' ] ) && is_array( $this->fields[ 'edit' ] ) )
- $this->fields[ 'edit' ] = $this->setup_fields( $this->fields[ 'edit' ], 'edit' );
- }
- if ( !in_array( 'duplicate', $this->actions_disabled ) ) {
- if ( 'duplicate' != $which && isset( $this->fields[ 'duplicate' ] ) && is_array( $this->fields[ 'duplicate' ] ) )
- $this->fields[ 'duplicate' ] = $this->setup_fields( $this->fields[ 'duplicate' ], 'duplicate' );
- }
- }
- if ( false !== $this->searchable ) {
- if ( 'search' != $which && isset( $this->fields[ 'search' ] ) &&!empty( $this->fields[ 'search' ] ) )
- $this->fields[ 'search' ] = $this->setup_fields( $this->fields[ 'search' ], 'search' );
- else
- $this->fields[ 'search' ] = $fields;
- }
- else
- $this->fields[ 'search' ] = false;
- if ( !in_array( 'export', $this->actions_disabled ) ) {
- if ( 'export' != $which && isset( $this->fields[ 'export' ] ) &&!empty( $this->fields[ 'export' ] ) )
- $this->fields[ 'export' ] = $this->setup_fields( $this->fields[ 'export' ], 'export' );
- }
- if ( !in_array( 'reorder', $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
- if ( 'reorder' != $which && isset( $this->fields[ 'reorder' ] ) &&!empty( $this->fields[ 'reorder' ] ) )
- $this->fields[ 'reorder' ] = $this->setup_fields( $this->fields[ 'reorder' ], 'reorder' );
- else
- $this->fields[ 'reorder' ] = $fields;
- }
- }
- return $this->do_hook( 'setup_fields', $fields, $which, $init );
- }
- /**
- * @param $msg
- * @param bool $error
- */
- public function message ( $msg, $error = false ) {
- $msg = $this->do_hook( ( $error ) ? 'error' : 'message', $msg );
- ?>
- <div id="message" class="<?php echo ( $error ) ? 'error' : 'updated'; ?> fade"><p><?php echo $msg; ?></p></div>
- <?php
- }
- /**
- * @param $msg
- *
- * @return bool
- */
- public function error ( $msg ) {
- $this->message( $msg, true );
- return false;
- }
- /**
- * @return mixed
- */
- public function go () {
- $this->do_hook( 'go' );
- $_GET = pods_unsanitize( $_GET ); // fix wp sanitization
- $_POST = pods_unsanitize( $_POST ); // fix wp sanitization
- if ( false !== $this->css ) {
- ?>
- <link type="text/css" rel="stylesheet" href="<?php echo $this->css; ?>" />
- <?php
- }
- if ( false !== $this->wpcss ) {
- $stylesheets = array( 'global', 'wp-admin', $this->wpcss );
- foreach ( $stylesheets as $style ) {
- if ( !wp_style_is( $style, 'queue' ) && !wp_style_is( $style, 'to_do' ) && !wp_style_is( $style, 'done' ) )
- wp_enqueue_style( $style );
- }
- }
- $this->ui_page = array( $this->action );
- if ( 'add' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
- $this->ui_page[] = 'form';
- if ( 'create' == $this->do && $this->save && !in_array( $this->do, $this->actions_disabled ) && !empty( $_POST ) ) {
- $this->ui_page[] = $this->do;
- $this->save( true );
- $this->manage();
- }
- else
- $this->add();
- }
- elseif ( ( 'edit' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) || ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ) {
- $this->ui_page[] = 'form';
- if ( 'save' == $this->do && $this->save && !empty( $_POST ) )
- $this->save();
- $this->edit( ( 'duplicate' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) ? 1 : 0 );
- }
- elseif ( 'delete' == $this->action && !in_array( $this->action, $this->actions_disabled ) ) {
- $this->delete( $this->id );
- $this->manage();
- }
- elseif ( 'reorder' == $this->action && !in_array( $this->action, $this->actions_disabled ) && false !== $this->reorder[ 'on' ] ) {
- if ( 's…
Large files files are truncated, but you can click here to view the full file