/** * Load a Pod and all of its fields * * $params['id'] int The Pod ID * $params['name'] string The Pod name * $params['fields'] bool Whether to load fields (default is true) * * @param array|object $params An associative array of parameters or pod name as a string * @param bool $strict Makes sure the pod exists, throws an error if it doesn't work * * @return array|bool|mixed|void * @since 1.7.9 */ public function load_pod($params, $strict = true) { /** * @var $sitepress SitePress * @var $wpdb wpdb */ global $sitepress, $icl_adjust_id_url_filter_off, $wpdb; $current_language = false; $load_fields = true; // WPML support if (is_object($sitepress) && !$icl_adjust_id_url_filter_off) { $current_language = pods_sanitize(ICL_LANGUAGE_CODE); } elseif (function_exists('pll_current_language')) { $current_language = pll_current_language('slug'); } if (!is_array($params) && !is_object($params)) { $params = array('name' => $params, 'table_info' => false, 'fields' => true); } if (is_object($params) && isset($params->fields) && !$params->fields) { $load_fields = false; } elseif (is_array($params) && isset($params['fields']) && !$params['fields']) { $load_fields = false; } $table_info = false; if (is_object($params) && !empty($params->table_info)) { $table_info = true; } elseif (is_array($params) && !empty($params['table_info'])) { $table_info = true; } $transient = 'pods_' . $wpdb->prefix . '_pod'; if (!empty($current_language)) { $transient .= '_' . $current_language; } if (!$load_fields) { $transient .= '_nofields'; } if ($table_info) { $transient .= '_tableinfo'; } if (is_object($params) && isset($params->post_name)) { $pod = false; if (pods_api_cache()) { $pod = pods_transient_get($transient . '_' . $params->post_name); } if (false !== $pod && (!$table_info || isset($pod['table']))) { if (in_array($pod['type'], array('post_type', 'taxonomy')) && is_object($sitepress) && !$icl_adjust_id_url_filter_off) { $pod = array_merge($pod, $this->get_table_info($pod['type'], $pod['object'], $pod['name'], $pod)); } return $pod; } $_pod = get_object_vars($params); } else { $params = (object) pods_sanitize($params); if ((!isset($params->id) || empty($params->id)) && (!isset($params->name) || empty($params->name))) { if ($strict) { return pods_error('Either Pod ID or Name are required', $this); } return false; } if (isset($params->name)) { $pod = false; if ('_pods_pod' == $params->name) { $pod = array('id' => 0, 'name' => $params->name, 'label' => __('Pods', 'pods'), 'type' => 'post_type', 'storage' => 'meta', 'options' => array('label_singular' => __('Pod', 'pods')), 'fields' => array()); } elseif ('_pods_field' == $params->name) { $pod = array('id' => 0, 'name' => $params->name, 'label' => __('Pod Fields', 'pods'), 'type' => 'post_type', 'storage' => 'meta', 'options' => array('label_singular' => __('Pod Field', 'pods')), 'fields' => array()); } elseif (pods_api_cache()) { $pod = pods_transient_get($transient . '_' . $params->name); } if (false !== $pod && (!$table_info || isset($pod['table']))) { if (in_array($pod['type'], array('post_type', 'taxonomy')) && is_object($sitepress) && !$icl_adjust_id_url_filter_off) { $pod = array_merge($pod, $this->get_table_info($pod['type'], $pod['object'], $pod['name'], $pod)); } return $pod; } } if (!isset($params->name)) { $pod = get_post($dummy = (int) $params->id); } else { $pod = get_posts(array('name' => $params->name, 'post_type' => '_pods_pod', 'posts_per_page' => 1)); } if (empty($pod)) { if ($strict) { return pods_error(__('Pod not found', 'pods'), $this); } return false; } if (is_array($pod)) { $pod = $pod[0]; } $_pod = get_object_vars($pod); } $pod = false; if (pods_api_cache()) { $pod = pods_transient_get($transient . '_' . $_pod['post_name']); } if (false !== $pod && (!$table_info || isset($pod['table']))) { if (in_array($pod['type'], array('post_type', 'taxonomy')) && is_object($sitepress) && !$icl_adjust_id_url_filter_off) { $pod = array_merge($pod, $this->get_table_info($pod['type'], $pod['object'], $pod['name'], $pod)); } return $pod; } $pod = array('id' => $_pod['ID'], 'name' => $_pod['post_name'], 'label' => $_pod['post_title'], 'description' => $_pod['post_content']); if (strlen($pod['label']) < 1) { $pod['label'] = $pod['name']; } // @todo update with a method to put all options in $defaults = array('show_in_menu' => 1, 'type' => 'post_type', 'storage' => 'meta', 'object' => '', 'alias' => ''); $pod['options'] = get_post_meta($pod['id']); foreach ($pod['options'] as $option => $value) { if (is_array($value)) { foreach ($value as $k => $v) { if (!is_array($v)) { $value[$k] = maybe_unserialize($v); } } if (1 == count($value)) { $value = current($value); } } else { $value = maybe_unserialize($value); } $pod['options'][$option] = $value; } $pod['options'] = array_merge($defaults, $pod['options']); $pod['type'] = $pod['options']['type']; $pod['storage'] = $pod['options']['storage']; $pod['object'] = $pod['options']['object']; $pod['alias'] = $pod['options']['alias']; unset($pod['options']['type']); unset($pod['options']['storage']); unset($pod['options']['object']); unset($pod['options']['alias']); if ($table_info) { $pod = array_merge($this->get_table_info($pod['type'], $pod['object'], $pod['name'], $pod), $pod); } if (isset($pod['pod'])) { unset($pod['pod']); } $pod['fields'] = array(); $pod['object_fields'] = array(); if ('pod' != $pod['type']) { $pod['object_fields'] = $this->get_wp_object_fields($pod['type'], $pod); } $fields = get_posts(array('post_type' => '_pods_field', 'posts_per_page' => -1, 'nopaging' => true, 'post_parent' => $pod['id'], 'orderby' => 'menu_order', 'order' => 'ASC')); if (!empty($fields)) { foreach ($fields as $field) { $field->pod = $pod['name']; $field->table_info = $table_info; if ($load_fields) { $field = $this->load_field($field); $field = PodsForm::field_setup($field, null, $field['type']); } else { $field = array('id' => $field->ID, 'name' => $field->post_name, 'label' => $field->post_title, 'type' => get_post_meta($field->ID, 'type', true)); } $pod['fields'][$field['name']] = $field; } } if (did_action('init') && pods_api_cache()) { pods_transient_set($transient . '_' . $pod['name'], $pod); } return $pod; }
public function admin_ajax_settings($component, $params) { if (!isset($this->components[$component])) { wp_die('Invalid Component'); } elseif (!method_exists($this->components[$component]['object'], 'options')) { pods_error('Component options method does not exist', $this); } $options = $this->components[$component]['object']->options($this->settings['components'][$component]); if (empty($this->settings['components'][$component])) { $this->settings['components'][$component] = array(); } foreach ($options as $field_name => $field_option) { $field_option = PodsForm::field_setup($field_option, null, $field_option['type']); if (!is_array($field_option['group'])) { $field_value = pods_var_raw('pods_setting_' . $field_name, $params); $this->settings['components'][$component][$field_name] = $field_value; } else { foreach ($field_option['group'] as $field_group_name => $field_group_option) { $field_value = pods_var_raw('pods_setting_' . $field_group_name, $params); $this->settings['components'][$component][$field_group_name] = $field_value; } } } $settings = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($this->settings, JSON_UNESCAPED_UNICODE) : json_encode($this->settings); update_option('pods_component_settings', $settings); return '1'; }
/** * @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 (!isset($attributes['css_values'])) { $attributes['css_values'] = true; } 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); }
/** * Recursively join tables based on fields * * @param array $traverse_recurse Array of traversal options * * @return array Array of table joins * * @since 2.0 */ function traverse_recurse($traverse_recurse) { global $wpdb; $defaults = array('pod' => null, 'fields' => array(), 'joined' => 't', 'depth' => 0, 'joined_id' => 'id', 'joined_index' => 'id', 'params' => new stdClass(), 'last_table_info' => array()); $traverse_recurse = array_merge($defaults, $traverse_recurse); $joins = array(); if (0 == $traverse_recurse['depth'] && !empty($traverse_recurse['pod']) && !empty($traverse_recurse['last_table_info']) && isset($traverse_recurse['last_table_info']['id'])) { $pod_data = $traverse_recurse['last_table_info']; } elseif (empty($traverse_recurse['pod'])) { if (!empty($traverse_recurse['params']) && !empty($traverse_recurse['params']->table) && 0 === strpos($traverse_recurse['params']->table, $wpdb->prefix)) { if ($wpdb->posts == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'post_type'; } elseif ($wpdb->terms == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'taxonomy'; } elseif ($wpdb->users == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'user'; } elseif ($wpdb->comments == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'comment'; } else { return $joins; } $pod_data = array(); if (in_array($traverse_recurse['pod'], array('user', 'comment'))) { $pod = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true)); if (!empty($pod) && $pod['type'] == $pod) { $pod_data = $pod; } } if (empty($pod_data)) { $pod_data = array('id' => 0, 'name' => '_table_' . $traverse_recurse['pod'], 'type' => $traverse_recurse['pod'], 'storage' => 'taxonomy' == $traverse_recurse['pod'] ? 'none' : 'meta', 'fields' => array(), 'object_fields' => $this->api->get_wp_object_fields($traverse_recurse['pod'])); $pod_data = array_merge($this->api->get_table_info($traverse_recurse['pod'], ''), $pod_data); } $traverse_recurse['pod'] = $pod_data['name']; } else { return $joins; } } else { $pod_data = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true), false); if (empty($pod_data)) { return $joins; } } if (isset($pod_data['object_fields'])) { $pod_data['fields'] = array_merge($pod_data['fields'], $pod_data['object_fields']); } $tableless_field_types = PodsForm::tableless_field_types(); $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects'); $file_field_types = PodsForm::file_field_types(); if (!isset($this->traversal[$traverse_recurse['pod']])) { $this->traversal[$traverse_recurse['pod']] = array(); } if ((empty($pod_data['meta_table']) || $pod_data['meta_table'] == $pod_data['table']) && (empty($traverse_recurse['fields']) || !isset($traverse_recurse['fields'][$traverse_recurse['depth']]) || empty($traverse_recurse['fields'][$traverse_recurse['depth']]))) { return $joins; } $field = $traverse_recurse['fields'][$traverse_recurse['depth']]; $ignore_aliases = array('wpml_languages', 'polylang_languages'); $ignore_aliases = $this->do_hook('traverse_recurse_ignore_aliases', $ignore_aliases, $field, $traverse_recurse); if (in_array($field, $ignore_aliases)) { return $joins; } $meta_data_table = false; if (!isset($pod_data['fields'][$field]) && 'd' == $field && isset($traverse_recurse['fields'][$traverse_recurse['depth'] - 1])) { $field = $traverse_recurse['fields'][$traverse_recurse['depth'] - 1]; $field_type = 'pick'; if (isset($traverse_recurse['last_table_info']['pod']['fields'][$field])) { $field_type = $traverse_recurse['last_table_info']['pod']['fields'][$field]['type']; } elseif (isset($traverse_recurse['last_table_info']['pod']['object_fields'][$field])) { $field_type = $traverse_recurse['last_table_info']['pod']['object_fields'][$field]['type']; } $pod_data['fields'][$field] = array('id' => 0, 'name' => $field, 'type' => $field_type, 'pick_object' => $traverse_recurse['last_table_info']['pod']['type'], 'pick_val' => $traverse_recurse['last_table_info']['pod']['name']); $meta_data_table = true; } // Fallback to meta table if the pod type supports it if (!isset($pod_data['fields'][$field])) { $last = end($traverse_recurse['fields']); if ('post_type' == $pod_data['type'] && !isset($pod_data['object_fields'])) { $pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data); } if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) { $pod_data['fields'][$field] = $pod_data['object_fields'][$field]; } elseif (in_array($pod_data['type'], array('post_type', 'media', 'user', 'comment')) && 'meta_value' == $last) { $pod_data['fields'][$field] = PodsForm::field_setup(array('name' => $field)); } else { if ('post_type' == $pod_data['type']) { $pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data, true); if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) { $pod_data['fields'][$field] = $pod_data['object_fields'][$field]; } else { return $joins; } } else { return $joins; } } } $traverse = $pod_data['fields'][$field]; if ('taxonomy' == $traverse['type']) { $traverse['table_info'] = $this->api->get_table_info($traverse['type'], $traverse['name']); } elseif (in_array($traverse['type'], $file_field_types)) { $traverse['table_info'] = $this->api->get_table_info('post_type', 'attachment'); } elseif (!in_array($traverse['type'], $tableless_field_types)) { $traverse['table_info'] = $this->api->get_table_info($pod_data['type'], $pod_data['name'], $pod_data['name'], $pod_data); } elseif (empty($traverse['table_info']) || in_array($traverse['pick_object'], $simple_tableless_objects) && !empty($traverse_recurse['last_table_info'])) { if (in_array($traverse['pick_object'], $simple_tableless_objects) && !empty($traverse_recurse['last_table_info'])) { $traverse['table_info'] = $traverse_recurse['last_table_info']; if (!empty($traverse['table_info']['meta_table'])) { $meta_data_table = true; } } elseif (!in_array($traverse['type'], $tableless_field_types) && isset($traverse_recurse['last_table_info']) && !empty($traverse_recurse['last_table_info']) && 0 == $traverse_recurse['depth']) { $traverse['table_info'] = $traverse_recurse['last_table_info']; } else { $traverse['table_info'] = $this->api->get_table_info($traverse['pick_object'], $traverse['pick_val'], null, $traverse['pod'], $traverse); } } if (isset($this->traversal[$traverse_recurse['pod']][$traverse['name']])) { $traverse = array_merge($traverse, (array) $this->traversal[$traverse_recurse['pod']][$traverse['name']]); } $traverse = $this->do_hook('traverse', $traverse, compact('pod', 'fields', 'joined', 'depth', 'joined_id', 'params')); if (empty($traverse)) { return $joins; } $traverse = pods_sanitize($traverse); $traverse['id'] = (int) $traverse['id']; if (empty($traverse['id'])) { $traverse['id'] = $field; } $table_info = $traverse['table_info']; $this->traversal[$traverse_recurse['pod']][$field] = $traverse; $field_joined = $field; if (0 < $traverse_recurse['depth'] && 't' != $traverse_recurse['joined']) { if ($meta_data_table && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects))) { $field_joined = $traverse_recurse['joined'] . '_d'; } else { $field_joined = $traverse_recurse['joined'] . '_' . $field; } } $rel_alias = 'rel_' . $field_joined; if (pods_var('search', $traverse_recurse['params'], false) && empty($traverse_recurse['params']->filters)) { if (0 < strlen(pods_var('filter_' . $field_joined, 'get'))) { $val = absint(pods_var('filter_' . $field_joined, 'get')); $search = "`{$field_joined}`.`{$table_info['field_id']}` = {$val}"; if ('text' == $this->search_mode) { $val = pods_var('filter_' . $field_joined, 'get'); $search = "`{$field_joined}`.`{$traverse['name']}` = '{$val}'"; } elseif ('text_like' == $this->search_mode) { $val = pods_sanitize(pods_sanitize_like(pods_var_raw('filter_' . $field_joined))); $search = "`{$field_joined}`.`{$traverse['name']}` LIKE '%{$val}%'"; } $this->search_where[] = " {$search} "; } } $the_join = null; $joined_id = $table_info['field_id']; $joined_index = $table_info['field_index']; if ('taxonomy' == $traverse['type']) { $rel_tt_alias = 'rel_tt_' . $field_joined; if ($meta_data_table) { $the_join = "\n LEFT JOIN `{$table_info['pod_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['pod_field_id']}` = `{$traverse_recurse['rel_alias']}`.`{$traverse_recurse['joined_id']}`\n "; } else { $the_join = "\n LEFT JOIN `{$wpdb->term_relationships}` AS `{$rel_alias}` ON\n `{$rel_alias}`.`object_id` = `{$traverse_recurse['joined']}`.`ID`\n\n LEFT JOIN `{$wpdb->term_taxonomy}` AS `{$rel_tt_alias}` ON\n `{$rel_tt_alias}`.`taxonomy` = '{$traverse['name']}'\n AND `{$rel_tt_alias}`.`term_taxonomy_id` = `{$rel_alias}`.`term_taxonomy_id`\n\n LEFT JOIN `{$table_info['table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['field_id']}` = `{$rel_tt_alias}`.`{$table_info['field_id']}`\n "; // Override $rel_alias $rel_alias = $field_joined; $joined_id = $table_info['field_id']; $joined_index = $table_info['field_index']; } } elseif (in_array($traverse['type'], $tableless_field_types) && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects))) { if (pods_tableless()) { $the_join = "\n LEFT JOIN `{$table_info['meta_table']}` AS `{$rel_alias}` ON\n `{$rel_alias}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$rel_alias}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n\n LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$field_joined}`.`{$table_info['meta_field_id']}` = CONVERT( `{$rel_alias}`.`{$table_info['meta_field_value']}`, SIGNED )\n "; $joined_id = $table_info['meta_field_id']; $joined_index = $table_info['meta_field_index']; } elseif ($meta_data_table) { $the_join = "\n LEFT JOIN `{$table_info['pod_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['pod_field_id']}` = `{$traverse_recurse['rel_alias']}`.`{$traverse_recurse['joined_id']}`\n "; } else { $the_join = "\n LEFT JOIN `@wp_podsrel` AS `{$rel_alias}` ON\n `{$rel_alias}`.`field_id` = {$traverse['id']}\n AND `{$rel_alias}`.`item_id` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n\n LEFT JOIN `{$table_info['table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['field_id']}` = `{$rel_alias}`.`related_item_id`\n "; } } elseif ('meta' == $pod_data['storage']) { if ($traverse_recurse['depth'] + 2 == count($traverse_recurse['fields']) && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects)) && $table_info['meta_field_value'] == $traverse_recurse['fields'][$traverse_recurse['depth'] + 1]) { $the_join = "\n LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$field_joined}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n "; $table_info['recurse'] = false; } else { $the_join = "\n LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$field_joined}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n "; $joined_id = $table_info['meta_field_id']; $joined_index = $table_info['meta_field_index']; } } $traverse_recursive = array('pod' => pods_var_raw('name', pods_var_raw('pod', $table_info)), 'fields' => $traverse_recurse['fields'], 'joined' => $field_joined, 'depth' => $traverse_recurse['depth'] + 1, 'joined_id' => $joined_id, 'joined_index' => $joined_index, 'params' => $traverse_recurse['params'], 'rel_alias' => $rel_alias, 'last_table_info' => $table_info); $the_join = $this->do_hook('traverse_the_join', $the_join, $traverse_recurse, $traverse_recursive); if (empty($the_join)) { return $joins; } $joins[$traverse_recurse['pod'] . '_' . $traverse_recurse['depth'] . '_' . $traverse['id']] = $the_join; if ($traverse_recurse['depth'] + 1 < count($traverse_recurse['fields']) && !empty($traverse_recurse['pod']) && false !== $table_info['recurse']) { $joins = array_merge($joins, $this->traverse_recurse($traverse_recursive)); } return $joins; }
} else { ?> <tr valign="top" class="pods-field-option-group" id="pods-setting-<?php echo $field_name; ?> "> <th class="pods-field-option-group-label"> <?php echo $field_option['label']; ?> </th> <td class="pods-pick-values pods-pick-checkbox"> <ul> <?php foreach ($field_option['group'] as $field_group_name => $field_group_option) { $field_group_option = PodsForm::field_setup($field_group_option, null, $field_group_option['type']); if ('boolean' != $field_group_option['type']) { continue; } $field_group_option['boolean_yes_label'] = $field_group_option['label']; $depends_option = PodsForm::dependencies($field_group_option); $value = pods_var_raw($field_group_name, $settings, $field_group_option['default']); ?> <li class="<?php echo $depends_option; ?> "> <?php echo PodsForm::field('pods_setting_' . $field_group_name, $value, $field_group_option['type'], $field_group_option); ?> </li>
/** * * Generate UI for Data Management * * @param mixed $options Array or String containing Pod or Options to be used * @param bool $amend Whether to amend the default UI options or replace entirely * * @return PodsUI|void UI object or void if custom UI used * * @since 2.3.10 */ public function ui($options = null, $amend = false) { $num = ''; if (empty($options)) { $options = array(); } else { $num = pods_var('num', $options, ''); if (empty($num)) { $num = ''; } } if ($this->id() != pods_var('id' . $num, 'get', null, null, true)) { $this->fetch(pods_var('id' . $num, 'get', null, null, true)); } if (!empty($options) && !$amend) { $this->ui = $options; return pods_ui($this); } elseif (!empty($options) || 'custom' != pods_var('ui_style', $this->pod_data['options'], 'post_type', null, true)) { $actions_enabled = pods_var_raw('ui_actions_enabled', $this->pod_data['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } } else { $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export'); if (1 == pods_var('ui_export', $this->pod_data['options'], 0)) { unset($actions_disabled['export']); } } if (empty($options)) { $author_restrict = false; if (isset($this->fields['author']) && 'pick' == $this->fields['author']['type'] && 'user' == $this->fields['author']['pick_object']) { $author_restrict = 'author.ID'; } if (!pods_is_admin(array('pods', 'pods_content'))) { if (!current_user_can('pods_add_' . $this->pod)) { $actions_disabled['add'] = 'add'; if ('add' == pods_var('action' . $num, 'get')) { $_GET['action' . $num] = 'manage'; } } if (!$author_restrict && !current_user_can('pods_edit_' . $this->pod) && !current_user_can('pods_edit_others_' . $this->pod)) { $actions_disabled['edit'] = 'edit'; } if (!$author_restrict && !current_user_can('pods_delete_' . $this->pod) && !current_user_can('pods_delete_others_' . $this->pod)) { $actions_disabled['delete'] = 'delete'; } if (!current_user_can('pods_reorder_' . $this->pod)) { $actions_disabled['reorder'] = 'reorder'; } if (!current_user_can('pods_export_' . $this->pod)) { $actions_disabled['export'] = 'export'; } } } $_GET['action' . $num] = pods_var('action' . $num, 'get', pods_var('action', $options, 'manage')); $index = $this->pod_data['field_id']; $label = __('ID', 'pods'); if (isset($this->pod_data['fields'][$this->pod_data['field_index']])) { $index = $this->pod_data['field_index']; $label = $this->pod_data['fields'][$this->pod_data['field_index']]; } $manage = array($index => $label); if (isset($this->pod_data['fields']['modified'])) { $manage['modified'] = $this->pod_data['fields']['modified']['label']; } $manage_fields = pods_var_raw('ui_fields_manage', $this->pod_data['options']); if (!empty($manage_fields)) { $manage_new = array(); foreach ($manage_fields as $manage_field) { if (isset($this->pod_data['fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['fields'][$manage_field]; } elseif (isset($this->pod_data['object_fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['object_fields'][$manage_field]; } elseif ($manage_field == $this->pod_data['field_id']) { $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%'); $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']); } } if (!empty($manage_new)) { $manage = $manage_new; } } $manage = apply_filters('pods_admin_ui_fields_' . $this->pod, apply_filters('pods_admin_ui_fields', $manage, $this->pod, $this), $this->pod, $this); $icon = pods_var_raw('ui_icon', $this->pod_data['options']); if (!empty($icon)) { $icon = pods_image_url($icon, '32x32'); } $filters = pods_var_raw('ui_filters', $this->pod_data['options']); if (!empty($filters)) { $filters_new = array(); foreach ($filters as $filter_field) { if (isset($this->pod_data['fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['fields'][$filter_field]; } elseif (isset($this->pod_data['object_fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['object_fields'][$filter_field]; } } $filters = $filters_new; } $ui = array('fields' => array('manage' => $manage, 'add' => $this->pod_data['fields'], 'edit' => $this->pod_data['fields'], 'duplicate' => $this->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled); if (!empty($filters)) { $ui['fields']['search'] = $filters; $ui['filters'] = array_keys($filters); $ui['filters_enhanced'] = true; } $reorder_field = pods_var_raw('ui_reorder_field', $this->pod_data['options']); if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($this->pod_data['object_fields']) && isset($this->pod_data['object_fields'][$reorder_field]) || isset($this->pod_data['fields'][$reorder_field]))) { $ui['reorder'] = array('on' => $reorder_field); $ui['orderby'] = $reorder_field; $ui['orderby_dir'] = 'ASC'; } if (!empty($author_restrict)) { $ui['restrict'] = array('author_restrict' => $author_restrict); } if (!in_array('delete', $ui['actions_disabled'])) { $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods'))); } $detail_url = pods_var('detail_url', $this->pod_data['options']); if (0 < strlen($detail_url)) { $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . $detail_url)); } // @todo Customize the Add New / Manage links to point to their correct menu items $ui = apply_filters('pods_admin_ui_' . $this->pod, apply_filters('pods_admin_ui', $ui, $this->pod, $this), $this->pod, $this); // Override UI options foreach ($options as $option => $value) { $ui[$option] = $value; } $this->ui = $ui; return pods_ui($this); } do_action('pods_admin_ui_custom', $this); do_action('pods_admin_ui_custom_' . $this->pod, $this); }
/** * Create PodsUI content for the administration pages */ public function admin_content() { $pod_name = str_replace(array('pods-manage-', 'pods-add-new-'), '', $_GET['page']); $pod = pods($pod_name, pods_var('id', 'get', null, null, true)); $default = 'manage'; if (false !== strpos($_GET['page'], 'pods-add-new-')) { $default = 'add'; } $actions_enabled = pods_var_raw('ui_actions_enabled', $pod->pod_data['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } } else { $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export'); if (1 == pods_var('ui_export', $pod->pod_data['options'], 0)) { unset($actions_disabled['export']); } } $author_restrict = false; if (isset($pod->fields['author']) && 'pick' == $pod->fields['author']['type'] && 'user' == $pod->fields['author']['pick_object']) { $author_restrict = 'author.ID'; } if (!pods_is_admin(array('pods', 'pods_content'))) { if (!current_user_can('pods_add_' . $pod_name)) { $actions_disabled['add'] = 'add'; $default = 'manage'; } if (!$author_restrict && !current_user_can('pods_edit_' . $pod_name) && !current_user_can('pods_edit_others_' . $pod_name)) { $actions_disabled['edit'] = 'edit'; } if (!$author_restrict && !current_user_can('pods_delete_' . $pod_name) && !current_user_can('pods_delete_others_' . $pod_name)) { $actions_disabled['delete'] = 'delete'; } if (!current_user_can('pods_reorder_' . $pod_name)) { $actions_disabled['reorder'] = 'reorder'; } if (!current_user_can('pods_export_' . $pod_name)) { $actions_disabled['export'] = 'export'; } } $_GET['action'] = pods_var('action', 'get', $default); $index = $pod->pod_data['field_id']; $label = __('ID', 'pods'); if (isset($pod->pod_data['fields'][$pod->pod_data['field_index']])) { $index = $pod->pod_data['field_index']; $label = $pod->pod_data['fields'][$pod->pod_data['field_index']]; } $manage = array($index => $label); if (isset($pod->pod_data['fields']['modified'])) { $manage['modified'] = $pod->pod_data['fields']['modified']['label']; } $manage_fields = pods_var_raw('ui_fields_manage', $pod->pod_data['options']); if (!empty($manage_fields)) { $manage_new = array(); foreach ($manage_fields as $manage_field) { if (isset($pod->pod_data['fields'][$manage_field])) { $manage_new[$manage_field] = $pod->pod_data['fields'][$manage_field]; } elseif (isset($pod->pod_data['object_fields'][$manage_field])) { $manage_new[$manage_field] = $pod->pod_data['object_fields'][$manage_field]; } elseif ($manage_field == $pod->pod_data['field_id']) { $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%'); $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']); } } if (!empty($manage_new)) { $manage = $manage_new; } } $manage = apply_filters('pods_admin_ui_fields_' . $pod->pod, apply_filters('pods_admin_ui_fields', $manage, $pod->pod, $pod), $pod->pod, $pod); $icon = pods_var_raw('ui_icon', $pod->pod_data['options']); if (!empty($icon)) { $icon = pods_image_url($icon, '32x32'); } $filters = pods_var_raw('ui_filters', $pod->pod_data['options']); if (!empty($filters)) { $filters_new = array(); foreach ($filters as $filter_field) { if (isset($pod->pod_data['fields'][$filter_field])) { $filters_new[$filter_field] = $pod->pod_data['fields'][$filter_field]; } elseif (isset($pod->pod_data['object_fields'][$filter_field])) { $filters_new[$filter_field] = $pod->pod_data['object_fields'][$filter_field]; } } $filters = $filters_new; } $ui = array('pod' => $pod, 'fields' => array('manage' => $manage, 'add' => $pod->pod_data['fields'], 'edit' => $pod->pod_data['fields'], 'duplicate' => $pod->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled); if (!empty($filters)) { $ui['fields']['search'] = $filters; $ui['filters'] = array_keys($filters); $ui['filters_enhanced'] = true; } $reorder_field = pods_var_raw('ui_reorder_field', $pod->pod_data['options']); if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($pod->pod_data['object_fields']) && isset($pod->pod_data['object_fields'][$reorder_field]) || isset($pod->pod_data['fields'][$reorder_field]))) { $ui['reorder'] = array('on' => $reorder_field); $ui['orderby'] = $reorder_field; $ui['orderby_dir'] = 'ASC'; } if (!empty($author_restrict)) { $ui['restrict'] = array('author_restrict' => $author_restrict); } if (!in_array('delete', $ui['actions_disabled'])) { $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods'))); } if (strlen(pods_var('detail_url', $pod->pod_data)) < 1) { $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . pods_var('detail_url', $pod->pod_data['options']))); } // @todo Customize the Add New / Manage links to point to their correct menu items $ui = apply_filters('pods_admin_ui_' . $pod->pod, apply_filters('pods_admin_ui', $ui, $pod->pod, $pod), $pod->pod, $pod); pods_ui($ui); }