/** * Widget Form */ public function form($instance) { $title = pods_var_raw('title', $instance, ''); $pod_type = pods_var_raw('pod_type', $instance, ''); $slug = pods_var_raw('slug', $instance, ''); $field = pods_var_raw('field', $instance, ''); require PODS_DIR . 'ui/admin/widgets/field.php'; }
/** * Widget Form */ public function form($instance) { $title = pods_var_raw('title', $instance, ''); $view = pods_var_raw('view', $instance, ''); $expires = (int) pods_var_raw('expires', $instance, 60 * 5); $cache_mode = pods_var_raw('cache_mode', $instance, 'none', null, true); require PODS_DIR . 'ui/admin/widgets/view.php'; }
/** * Widget Form */ public function form($instance) { $title = pods_var_raw('title', $instance, ''); $slug = pods_var_raw('slug', $instance, ''); $pod_type = pods_var_raw('pod_type', $instance, ''); $template = pods_var_raw('template', $instance, ''); $template_custom = pods_var_raw('template_custom', $instance, ''); require PODS_DIR . 'ui/admin/widgets/single.php'; }
public function form($instance) { $title = pods_var_raw('title', $instance, ''); $pod_type = pods_var_raw('pod_type', $instance, ''); $slug = pods_var_raw('slug', $instance, ''); $fields = pods_var_raw('fields', $instance, ''); $label = pods_var_raw('label', $instance, __('Submit', 'pods'), null, true); $thank_you = pods_var_raw('thank_you', $instance, ''); require PODS_DIR . 'ui/admin/widgets/form.php'; }
/** * Widget Form */ public function form($instance) { $title = pods_var_raw('title', $instance, ''); $pod_type = pods_var_raw('pod_type', $instance, ''); $template = pods_var_raw('template', $instance, ''); $template_custom = pods_var_raw('template_custom', $instance, ''); $limit = (int) pods_var_raw('limit', $instance, 15, null, true); $orderby = pods_var_raw('orderby', $instance, ''); $where = pods_var_raw('where', $instance, ''); $expires = (int) pods_var_raw('expires', $instance, 60 * 5); $cache_mode = pods_var_raw('cache_mode', $instance, 'none'); require PODS_DIR . 'ui/admin/widgets/list.php'; }
/** * @static * * @param string $view Path of the view file * @param array|null $data (optional) Data to pass on to the template * @param bool|int|array $expires (optional) Time in seconds for the cache to expire, if 0 caching is disabled. * @param string $cache_mode (optional) Decides the caching method to use for the view. * * @return bool|mixed|null|string|void * * @since 2.0 */ public static function view($view, $data = null, $expires = false, $cache_mode = 'cache') { // Different $expires if user is anonymous or logged in or specific capability if (is_array($expires)) { $anon = pods_var_raw(0, $expires, false); $user = pods_var_raw(1, $expires, false); $capability = pods_var_raw(2, $expires, null, null, true); $expires = pods_var_user($anon, $user, $capability); } if ('none' == $cache_mode) { $expires = false; } if (false !== $expires && empty($expires)) { $expires = 0; } if (!in_array($cache_mode, self::$cache_modes)) { $cache_mode = 'cache'; } $view = apply_filters('pods_view_inc', $view, $data, $expires, $cache_mode); $view_key = $view; if (is_array($view_key)) { $view_key = implode('-', $view_key) . '.php'; } $view_key = realpath($view_key); $pods_ui_dir = realpath(PODS_DIR . 'ui/'); $pods_components_dir = realpath(PODS_DIR . 'components/'); $content_dir = realpath(WP_CONTENT_DIR); $plugins_dir = realpath(WP_PLUGIN_DIR); $abspath_dir = realpath(ABSPATH); $cache_key = sanitize_title(pods_str_replace(array($pods_ui_dir, $pods_components_dir, $content_dir, $plugins_dir, $abspath_dir, '.php', '/'), array('ui-', 'ui-', 'custom-', 'custom-', 'custom-', '', '_'), $view_key, 1)); $output = false; if (false !== $expires && false === strpos($view_key, $pods_ui_dir) && false === strpos($view_key, $pods_components_dir) && false === strpos($view_key, $content_dir) && false === strpos($view_key, $plugins_dir) && false === strpos($view_key, $abspath_dir)) { $output = self::get('pods-view-' . $cache_key, $cache_mode, 'pods_view'); } if (false === $output || null === $output) { $output = self::get_template_part($view, $data); } if (false !== $output && false !== $expires) { self::set('pods-view-' . $cache_key, $output, $expires, $cache_mode, 'pods_view'); } $output = apply_filters('pods_view_output_' . $cache_key, $output, $view, $data, $expires, $cache_mode); $output = apply_filters('pods_view_output', $output, $view, $data, $expires, $cache_mode); return $output; }
<div class="clear"></div> </div> <!-- /#major-publishing-actions --> </div> <!-- /#submitpost --> </div> <!-- /.inside --> </div> <!-- /#submitdiv --><!-- END PUBLISH DIV --><!-- TODO: minor column fields --> <?php if (pods_var_raw('action') == 'edit' && !$duplicate && !in_array('navigate', $obj->actions_disabled) && !in_array('navigate', $obj->actions_hidden)) { if (!isset($singular_label)) { $singular_label = ucwords(str_replace('_', ' ', $pod->pod_data['name'])); } $singular_label = pods_var_raw('label', $pod->pod_data['options'], $singular_label, null, true); $singular_label = pods_var_raw('label_singular', $pod->pod_data['options'], $singular_label, null, true); $prev = $pod->prev_id(); $next = $pod->next_id(); if (0 < $prev || 0 < $next) { ?> <div id="navigatediv" class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span><?php _e('Navigate', 'pods'); ?> </span></h3> <div class="inside"> <div class="pods-admin" id="navigatebox"> <div id="navigation-actions"> <?php
$attributes['value'] = $value; $attributes['data-field-type'] = 'select2'; $attributes['tabindex'] = 2; $attributes = PodsForm::merge_attributes($attributes, $name, $form_field_type, $options); $attributes['class'] .= ' pods-form-ui-field-type-select2'; $uri_hash = wp_create_nonce('pods_uri_' . $_SERVER['REQUEST_URI']); $uid = @session_id(); if (is_user_logged_in()) { $uid = 'user_' . get_current_user_id(); } $field_nonce = wp_create_nonce('pods_relationship_' . (!is_object($pod) ? '0' : $pod->pod_id) . '_' . $uid . '_' . $uri_hash . '_' . $options['id']); $pick_limit = (int) pods_var($form_field_type . '_limit', $options, 0); if ('multi' == pods_var($form_field_type . '_format_type', $options) && 1 != $pick_limit) { wp_enqueue_script('jquery-ui-sortable'); } $options['data'] = (array) pods_var_raw('data', $options, array(), null, true); ?> <div class="pods-select2"> <input<?php PodsForm::attributes($attributes, $name, $form_field_type, $options); ?> /> </div> <script type="text/javascript"> jQuery( function ( $ ) { if ( 'undefined' == typeof ajaxurl ) { var ajaxurl = '<?php echo pods_slash(admin_url('admin-ajax.php')); ?> ';
/** * * 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); }
/** * Get data from relationship objects * * @param array $object_params Object data parameters * * @return array|bool Object data */ public function get_object_data($object_params = null) { global $wpdb, $polylang, $sitepress, $icl_adjust_id_url_filter_off; $current_language = false; // 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'); } $object_params = array_merge(array('name' => '', 'value' => '', 'options' => array(), 'pod' => '', 'id' => '', 'context' => '', 'data_params' => array('query' => ''), 'page' => 1, 'limit' => 0), $object_params); $name = $object_params['name']; $value = $object_params['value']; $options = $object_params['options'] = (array) $object_params['options']; $pod = $object_params['pod']; $id = $object_params['id']; $context = $object_params['context']; $data_params = $object_params['data_params'] = (array) $object_params['data_params']; $page = min(1, (int) $object_params['page']); $limit = (int) $object_params['limit']; if (isset($options['options'])) { $options = array_merge($options, $options['options']); unset($options['options']); } $data = apply_filters('pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params); $items = array(); if (!isset($options[self::$type . '_object'])) { $data = pods_var_raw('data', $options, array(), null, true); } $simple = false; if (null === $data) { $data = array(); if ('custom-simple' == $options[self::$type . '_object']) { $custom = pods_var_raw(self::$type . '_custom', $options, ''); $custom = apply_filters('pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params); if (!empty($custom)) { if (!is_array($custom)) { $data = array(); $custom = explode("\n", trim($custom)); foreach ($custom as $custom_value) { $custom_label = explode('|', $custom_value); if (empty($custom_label)) { continue; } if (1 == count($custom_label)) { $custom_label = $custom_value; } else { $custom_value = $custom_label[0]; $custom_label = $custom_label[1]; } $custom_value = trim((string) $custom_value); $custom_label = trim((string) $custom_label); $data[$custom_value] = $custom_label; } } else { $data = $custom; } $simple = true; } } elseif (isset(self::$related_objects[$options[self::$type . '_object']]) && isset(self::$related_objects[$options[self::$type . '_object']]['data']) && !empty(self::$related_objects[$options[self::$type . '_object']]['data'])) { $data = self::$related_objects[$options[self::$type . '_object']]['data']; $simple = true; } elseif (isset(self::$related_objects[$options[self::$type . '_object']]) && isset(self::$related_objects[$options[self::$type . '_object']]['data_callback']) && is_callable(self::$related_objects[$options[self::$type . '_object']]['data_callback'])) { $data = call_user_func_array(self::$related_objects[$options[self::$type . '_object']]['data_callback'], array($name, $value, $options, $pod, $id)); $simple = true; // Cache data from callback if (!empty($data)) { self::$related_objects[$options[self::$type . '_object']]['data'] = $data; } } elseif ('simple_value' != $context) { $pick_val = pods_var(self::$type . '_val', $options); if ('table' == pods_var(self::$type . '_object', $options)) { $pick_val = pods_var(self::$type . '_table', $options, $pick_val, null, true); } if ('__current__' == $pick_val) { if (is_object($pod)) { $pick_val = $pod->pod; } elseif (is_array($pod)) { $pick_val = $pod['name']; } elseif (0 < strlen($pod)) { $pick_val = $pod; } } $options['table_info'] = pods_api()->get_table_info(pods_var(self::$type . '_object', $options), $pick_val, null, null, $options); $search_data = pods_data(); $search_data->table($options['table_info']); if (isset($options['table_info']['pod']) && !empty($options['table_info']['pod']) && isset($options['table_info']['pod']['name'])) { $search_data->pod = $options['table_info']['pod']['name']; $search_data->fields = $options['table_info']['pod']['fields']; } $params = array('select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`", 'table' => $search_data->table, 'where' => pods_var_raw(self::$type . '_where', $options, (array) $options['table_info']['where_default'], null, true), 'orderby' => pods_var_raw(self::$type . '_orderby', $options, null, null, true), 'groupby' => pods_var_raw(self::$type . '_groupby', $options, null, null, true), 'pagination' => false, 'search' => false); if (in_array($options[self::$type . '_object'], array('site', 'network'))) { $params['select'] .= ', `t`.`path`'; } if (!empty($params['where']) && (array) $options['table_info']['where_default'] != $params['where']) { $params['where'] = pods_evaluate_tags($params['where'], true); } if (empty($params['where']) || !is_array($params['where']) && strlen(trim($params['where'])) < 1) { $params['where'] = array(); } elseif (!is_array($params['where'])) { $params['where'] = (array) $params['where']; } if ('value_to_label' == $context) { $params['where'][] = "`t`.`{$search_data->field_id}` = " . number_format($value, 0, '', ''); } /* not needed yet if ( !empty( $params[ 'orderby' ] ) ) $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true ); if ( !empty( $params[ 'groupby' ] ) ) $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/ $display = trim(pods_var(self::$type . '_display', $options), ' {@}'); if (0 < strlen($display)) { if (isset($options['table_info']['pod']) && !empty($options['table_info']['pod'])) { if (isset($options['table_info']['pod']['object_fields']) && isset($options['table_info']['pod']['object_fields'][$display])) { $search_data->field_index = $display; $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; } elseif (isset($options['table_info']['pod']['fields'][$display])) { $search_data->field_index = $display; if ('table' == $options['table_info']['pod']['storage'] && !in_array($options['table_info']['pod']['type'], array('pod', 'table'))) { $params['select'] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`"; } elseif ('meta' == $options['table_info']['pod']['storage']) { $params['select'] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}"; } else { $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; } } } elseif (isset($options['table_info']['object_fields']) && isset($options['table_info']['object_fields'][$display])) { $search_data->field_index = $display; $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`"; } } $autocomplete = false; if ('single' == pods_var(self::$type . '_format_type', $options, 'single') && 'autocomplete' == pods_var(self::$type . '_format_single', $options, 'dropdown')) { $autocomplete = true; } elseif ('multi' == pods_var(self::$type . '_format_type', $options, 'single') && 'autocomplete' == pods_var(self::$type . '_format_multi', $options, 'checkbox')) { $autocomplete = true; } $hierarchy = false; if ('data' == $context && !$autocomplete) { if ('single' == pods_var(self::$type . '_format_type', $options, 'single') && in_array(pods_var(self::$type . '_format_single', $options, 'dropdown'), array('dropdown', 'radio'))) { $hierarchy = true; } elseif ('multi' == pods_var(self::$type . '_format_type', $options, 'single') && in_array(pods_var(self::$type . '_format_multi', $options, 'checkbox'), array('multiselect', 'checkbox'))) { $hierarchy = true; } } if ($hierarchy && $options['table_info']['object_hierarchical'] && !empty($options['table_info']['field_parent'])) { $params['select'] .= ', ' . $options['table_info']['field_parent_select']; } if ($autocomplete) { if (0 == $limit) { $limit = 30; } $params['limit'] = apply_filters('pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params); if (is_array($value) && $params['limit'] < count($value)) { $params['limit'] = count($value); } $params['page'] = $page; if ('admin_ajax_relationship' == $context) { $lookup_where = array($search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"); // @todo Hook into WPML for each table if ($wpdb->users == $search_data->table) { $lookup_where['display_name'] = "`t`.`display_name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['user_login'] = "******" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['user_email'] = "`t`.`user_email` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } elseif ($wpdb->posts == $search_data->table) { $lookup_where['post_title'] = "`t`.`post_title` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['post_name'] = "`t`.`post_name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['post_content'] = "`t`.`post_content` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['post_excerpt'] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } elseif ($wpdb->terms == $search_data->table) { $lookup_where['name'] = "`t`.`name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['slug'] = "`t`.`slug` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } elseif ($wpdb->comments == $search_data->table) { $lookup_where['comment_content'] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['comment_author'] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; $lookup_where['comment_author_email'] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'"; } $lookup_where = apply_filters('pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params['query'], $name, $value, $options, $pod, $id, $object_params, $search_data); if (!empty($lookup_where)) { $params['where'][] = implode(' OR ', $lookup_where); } $orderby = array(); $orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like($data_params['query']) . "%' ) DESC"; $pick_orderby = pods_var_raw(self::$type . '_orderby', $options, null, null, true); if (0 < strlen($pick_orderby)) { $orderby[] = $pick_orderby; } $orderby[] = "`t`.`{$search_data->field_index}`"; $orderby[] = "`t`.`{$search_data->field_id}`"; $params['orderby'] = $orderby; } } elseif (0 < $limit) { $params['limit'] = $limit; $params['page'] = $page; } $extra = ''; if ($wpdb->posts == $search_data->table) { $extra = ', `t`.`post_type`'; } elseif ($wpdb->terms == $search_data->table) { $extra = ', `tt`.`taxonomy`'; } elseif ($wpdb->comments == $search_data->table) { $extra = ', `t`.`comment_type`'; } $params['select'] .= $extra; if ('user' == pods_var(self::$type . '_object', $options)) { $roles = pods_var(self::$type . '_user_role', $options); if (!empty($roles)) { $where = array(); foreach ((array) $roles as $role) { if (empty($role) || pods_clean_name($role) != $role && sanitize_title($role) != $role) { continue; } $where[] = $wpdb->base_prefix . (is_multisite() && !is_main_site() ? get_current_blog_id() . '_' : '') . 'capabilities.meta_value LIKE "%\\"' . pods_sanitize_like($role) . '\\"%"'; } if (!empty($where)) { $params['where'][] = implode(' OR ', $where); } } } $results = $search_data->select($params); if ($autocomplete && $params['limit'] < $search_data->total_found()) { if (!empty($value)) { $ids = $value; if (is_array($ids) && isset($ids[0]) && is_array($ids[0])) { $ids = wp_list_pluck($ids, $search_data->field_id); } if (is_array($ids)) { $ids = implode(', ', $ids); } if (is_array($params['where'])) { $params['where'] = implode(' AND ', $params['where']); } if (!empty($params['where'])) { $params['where'] .= ' AND '; } $params['where'] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )"; $results = $search_data->select($params); } } else { $autocomplete = false; } if ('data' == $context) { self::$field_data = array('field' => $name, 'id' => $options['id'], 'autocomplete' => $autocomplete); } if ($hierarchy && !$autocomplete && !empty($results) && $options['table_info']['object_hierarchical'] && !empty($options['table_info']['field_parent'])) { $args = array('id' => $options['table_info']['field_id'], 'index' => $options['table_info']['field_index'], 'parent' => $options['table_info']['field_parent']); $results = pods_hierarchical_select($results, $args); } $ids = array(); if (!empty($results)) { $display_filter = pods_var('display_filter', pods_var_raw('options', pods_var_raw($search_data->field_index, $search_data->pod_data['object_fields']))); foreach ($results as $result) { $result = get_object_vars($result); if (!isset($result[$search_data->field_id]) || !isset($result[$search_data->field_index])) { continue; } $result[$search_data->field_index] = trim($result[$search_data->field_index]); $object = $object_type = ''; if ($wpdb->posts == $search_data->table && isset($result['post_type'])) { $object = $result['post_type']; $object_type = 'post_type'; } elseif ($wpdb->terms == $search_data->table && isset($result['taxonomy'])) { $object = $result['taxonomy']; $object_type = 'taxonomy'; } // WPML integration for Post Types and Taxonomies if (is_object($sitepress) && in_array($object_type, array('post_type', 'taxonomy'))) { $translated = false; if ('post_type' == $object_type && $sitepress->is_translated_post_type($object)) { $translated = true; } elseif ('taxonomy' == $object_type && $sitepress->is_translated_taxonomy($object)) { $translated = true; } if ($translated) { $object_id = icl_object_id($result[$search_data->field_id], $object, false, $current_language); if (0 < $object_id && !in_array($object_id, $ids)) { $text = $result[$search_data->field_index]; if ($result[$search_data->field_id] != $object_id) { if ($wpdb->posts == $search_data->table) { $text = trim(get_the_title($object_id)); } elseif ($wpdb->terms == $search_data->table) { $text = trim(get_term($object_id, $object)->name); } } $result[$search_data->field_id] = $object_id; $result[$search_data->field_index] = $text; } else { continue; } } } elseif (is_object($polylang) && in_array($object_type, array('post_type', 'taxonomy')) && method_exists($polylang, 'get_translation')) { $translated = false; if ('post_type' == $object_type && pll_is_translated_post_type($object)) { $translated = true; } elseif ('taxonomy' == $object_type && pll_is_translated_taxonomy($object)) { $translated = true; } if ($translated) { $object_id = $polylang->get_translation($object, $result[$search_data->field_id], $current_language); if (0 < $object_id && !in_array($object_id, $ids)) { $text = $result[$search_data->field_index]; if ($result[$search_data->field_id] != $object_id) { if ($wpdb->posts == $search_data->table) { $text = trim(get_the_title($object_id)); } elseif ($wpdb->terms == $search_data->table) { $text = trim(get_term($object_id, $object)->name); } } $result[$search_data->field_id] = $object_id; $result[$search_data->field_index] = $text; } else { continue; } } } if (0 < strlen($display_filter)) { $display_filter_args = pods_var('display_filter_args', pods_var_raw('options', pods_var_raw($search_data->field_index, $search_data->pod_data['object_fields']))); $args = array($display_filter, $result[$search_data->field_index]); if (!empty($display_filter_args)) { foreach ((array) $display_filter_args as $display_filter_arg) { if (isset($result[$display_filter_arg])) { $args[] = $result[$display_filter_arg]; } } } $result[$search_data->field_index] = call_user_func_array('apply_filters', $args); } if (in_array($options[self::$type . '_object'], array('site', 'network'))) { $result[$search_data->field_index] = $result[$search_data->field_index] . $result['path']; } elseif (strlen($result[$search_data->field_index]) < 1) { $result[$search_data->field_index] = '(No Title)'; } if ('admin_ajax_relationship' == $context) { $items[] = array('id' => $result[$search_data->field_id], 'text' => $result[$search_data->field_index], 'image' => ''); } else { $data[$result[$search_data->field_id]] = $result[$search_data->field_index]; } $ids[] = $result[$search_data->field_id]; } } } if ($simple && 'admin_ajax_relationship' == $context) { $found_data = array(); foreach ($data as $k => $v) { if (false !== stripos($v, $data_params['query']) || false !== stripos($k, $data_params['query'])) { $found_data[$k] = $v; } } $data = $found_data; } } if ('admin_ajax_relationship' == $context) { if (empty($items) && !empty($data)) { foreach ($data as $k => $v) { $items[] = array('id' => $k, 'text' => $v, 'image' => ''); } } return $items; } return $data; }
/** * Customize the Pods UI manage table column output * * @param int $id * @param mixed $value * @param string $name * @param array $options * @param array $fields * @param array $pod * * @since 2.0 */ public function ui($id, $value, $name = null, $options = null, $fields = null, $pod = null) { $yesno = array(1 => pods_var_raw(self::$type . '_yes_label', $options, __('Yes', 'pods'), null, true), 0 => pods_var_raw(self::$type . '_no_label', $options, __('No', 'pods'), null, true)); if (isset($yesno[(int) $value])) { $value = strip_tags($yesno[(int) $value], '<strong><a><em><span><img>'); } return $value; }
/** * Process a Pod-based form * * @param mixed $params * @param object $obj Pod object * @param array $fields Fields being submitted in form ( key => settings ) * @param string $thank_you URL to send to upon success * * @return mixed * * @since 2.0 */ public function process_form($params, $obj = null, $fields = null, $thank_you = null) { $this->display_errors = false; $form = null; $nonce = pods_var('_pods_nonce', $params); $pod = pods_var('_pods_pod', $params); $id = pods_var('_pods_id', $params); $uri = pods_var('_pods_uri', $params); $form = pods_var('_pods_form', $params); $location = pods_var('_pods_location', $params); if (is_object($obj)) { $pod = $obj->pod; $id = $obj->id(); } if (!empty($fields)) { $fields = array_keys($fields); $form = implode(',', $fields); } else { $fields = explode(',', $form); } if (empty($nonce) || empty($pod) || empty($uri) || empty($fields)) { return pods_error(__('Invalid submission', 'pods'), $this); } $uid = @session_id(); if (is_user_logged_in()) { $uid = 'user_' . get_current_user_id(); } $field_hash = wp_create_nonce('pods_fields_' . $form); $action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash; if (empty($uid)) { return pods_error(__('Access denied for your session, please refresh and try again.', 'pods'), $this); } if (false === wp_verify_nonce($nonce, $action)) { return pods_error(__('Access denied, please refresh and try again.', 'pods'), $this); } $data = array(); foreach ($fields as $field) { $data[$field] = pods_var_raw('pods_field_' . $field, $params, ''); } $params = array('pod' => $pod, 'id' => $id, 'data' => $data, 'from' => 'process_form', 'location' => $location); $id = $this->save_pod_item($params); if (0 < $id && !empty($thank_you)) { $thank_you = str_replace('X_ID_X', $id, $thank_you); pods_redirect($thank_you); } return $id; }
} $thumb = wp_get_attachment_image_src($val, 'thumbnail', true); $title = $attachment->post_title; if (0 == $title_editable) { $title = basename($attachment->guid); } echo $field_file->markup($attributes, $file_limit, $title_editable, $val, $thumb[0], $title); } ?> </ul> <a class="button pods-file-add pods-media-add" id="<?php echo $css_id; ?> -upload" href="#" tabindex="2"><?php echo pods_var_raw($form_field_type . '_add_button', $options, __('Add File', 'pods')); ?> </a> <ul class="pods-files pods-files-queue"></ul> </div> <script type="text/x-handlebars" id="<?php echo $css_id; ?> -handlebars"> <?php echo $field_file->markup($attributes, $file_limit, $title_editable); ?> </script>
/** * Add pods specific capabilities. * * @param $capabilities List of extra capabilities to add * * @return array */ public function admin_capabilities($capabilities) { $pods = pods_api()->load_pods(array('type' => array('pod', 'table', 'post_type', 'taxonomy', 'settings'))); $capabilities[] = 'pods'; $capabilities[] = 'pods_content'; $capabilities[] = 'pods_settings'; $capabilities[] = 'pods_components'; foreach ($pods as $pod) { if ('settings' == $pod['type']) { $capabilities[] = 'pods_edit_' . $pod['name']; } elseif ('post_type' == $pod['type']) { $capability_type = pods_var('capability_type_custom', $pod['options'], pods_var_raw('name', $pod)); if ('custom' == pods_var('capability_type', $pod['options']) && 0 < strlen($capability_type)) { $capabilities[] = 'read_' . $capability_type; $capabilities[] = 'edit_' . $capability_type; $capabilities[] = 'delete_' . $capability_type; if (1 == pods_var('capability_type_extra', $pod['options'], 1)) { $capabilities[] = 'read_private_' . $capability_type . 's'; $capabilities[] = 'edit_' . $capability_type . 's'; $capabilities[] = 'edit_others_' . $capability_type . 's'; $capabilities[] = 'edit_private_' . $capability_type . 's'; $capabilities[] = 'edit_published_' . $capability_type . 's'; $capabilities[] = 'publish_' . $capability_type . 's'; $capabilities[] = 'delete_' . $capability_type . 's'; $capabilities[] = 'delete_private_' . $capability_type . 's'; $capabilities[] = 'delete_published_' . $capability_type . 's'; $capabilities[] = 'delete_others_' . $capability_type . 's'; } } } elseif ('taxonomy' == $pod['type']) { if (1 == pods_var('capabilities', $pod['options'], 0)) { $capability_type = pods_var('capability_type_custom', $pod['options'], pods_var_raw('name', $pod) . 's'); $capabilities[] = 'manage_' . $capability_type; $capabilities[] = 'edit_' . $capability_type; $capabilities[] = 'delete_' . $capability_type; $capabilities[] = 'assign_' . $capability_type; } } else { $capabilities[] = 'pods_add_' . $pod['name']; $capabilities[] = 'pods_edit_' . $pod['name']; if (isset($pod['fields']['author']) && 'pick' == $pod['fields']['author']['type'] && 'user' == $pod['fields']['author']['pick_object']) { $capabilities[] = 'pods_edit_others_' . $pod['name']; } $capabilities[] = 'pods_delete_' . $pod['name']; if (isset($pod['fields']['author']) && 'pick' == $pod['fields']['author']['type'] && 'user' == $pod['fields']['author']['pick_object']) { $capabilities[] = 'pods_delete_others_' . $pod['name']; } $actions_enabled = pods_var_raw('ui_actions_enabled', $pod['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; } } if (!in_array('export', $actions_disabled)) { $capabilities[] = 'pods_export_' . $pod['name']; } if (!in_array('reorder', $actions_disabled)) { $capabilities[] = 'pods_reorder_' . $pod['name']; } } elseif (1 == pods_var('ui_export', $pod['options'], 0)) { $capabilities[] = 'pods_export_' . $pod['name']; } } } return $capabilities; }
/** * @param bool $reorder * * @return bool|mixed */ public function table($reorder = false) { if (false !== $this->callback('table', $reorder)) { return null; } if (empty($this->data)) { ?> <p><?php echo sprintf(__('No %s found', 'pods'), $this->items); ?> </p> <?php return false; } if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { ?> <style type="text/css"> table.widefat.fixed tbody.reorderable tr { height: 50px; } .dragme { background: url(<?php echo esc_url(PODS_URL); ?> /ui/images/handle.gif) no-repeat; background-position: 8px 8px; cursor: pointer; } .dragme strong { margin-left: 30px; } </style> <form action="<?php echo esc_url(pods_query_arg(array('action' . $this->num => 'reorder', 'do' . $this->num => 'save', 'page' => pods_var_raw('page')), self::$allowed, $this->exclusion())); ?> " method="post" class="admin_ui_reorder_form"> <?php } $table_fields = $this->fields['manage']; if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { $table_fields = $this->fields['reorder']; } if (false === $table_fields || empty($table_fields)) { return $this->error(__('<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods')); } ?> <table class="widefat page fixed wp-list-table" cellspacing="0"<?php echo 1 == $reorder && $this->reorder ? ' id="admin_ui_reorder"' : ''; ?> > <thead> <tr> <?php if (!empty($this->actions_bulk)) { ?> <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th> <?php } $name_field = false; $fields = array(); if (!empty($table_fields)) { foreach ($table_fields as $field => $attributes) { if (false === $attributes['display']) { continue; } if (false === $name_field) { $id = 'title'; } else { $id = ''; } if ('other' == $attributes['type']) { $id = ''; } if (in_array($attributes['type'], array('date', 'datetime', 'time'))) { $id = 'date'; } if (false === $name_field && 'title' == $id) { $name_field = true; } $fields[$field] = $attributes; $fields[$field]['field_id'] = $id; $dir = 'DESC'; $current_sort = ' asc'; if (isset($this->orderby['default']) && $field == $this->orderby['default']) { if ('DESC' == $this->orderby_dir) { $dir = 'ASC'; $current_sort = ' desc'; } } $att_id = ''; if (!empty($id)) { $att_id = ' id="' . esc_attr($id) . '"'; } $width = ''; if (isset($attributes['width']) && !empty($attributes['width'])) { $width = ' style="width: ' . esc_attr($attributes['width']) . '"'; } if ($fields[$field]['sortable']) { ?> <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr($id); ?> sortable<?php echo esc_attr($current_sort); ?> "<?php echo $width; ?> > <a href="<?php echo esc_url_raw(pods_query_arg(array('orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir), array('limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page'), $this->exclusion())); ?> "> <span><?php echo $attributes['label']; ?> </span> <span class="sorting-indicator"></span> </a> </th> <?php } else { ?> <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr($id); ?> "<?php echo $width; ?> ><?php echo $attributes['label']; ?> </th> <?php } } } ?> </tr> </thead> <?php if (6 < $this->total_found) { ?> <tfoot> <tr> <?php if (!empty($this->actions_bulk)) { ?> <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th> <?php } if (!empty($fields)) { foreach ($fields as $field => $attributes) { $dir = 'ASC'; if ($field == $this->orderby) { $current_sort = 'desc'; if ('ASC' == $this->orderby_dir) { $dir = 'DESC'; $current_sort = 'asc'; } } $width = ''; if (isset($attributes['width']) && !empty($attributes['width'])) { $width = ' style="width: ' . esc_attr($attributes['width']) . '"'; } if ($fields[$field]['sortable']) { ?> <th scope="col" class="manage-column column-<?php echo esc_attr($id); ?> sortable <?php echo esc_attr($current_sort); ?> "<?php echo $width; ?> ><a href="<?php echo esc_url_raw(pods_query_arg(array('orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir), array('limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page'), $this->exclusion())); ?> "><span><?php echo $attributes['label']; ?> </span><span class="sorting-indicator"></span></a></th> <?php } else { ?> <th scope="col" class="manage-column column-<?php echo esc_attr($id); ?> "<?php echo $width; ?> ><?php echo $attributes['label']; ?> </th> <?php } } } ?> </tr> </tfoot> <?php } ?> <tbody id="the-list"<?php echo true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on'] ? ' class="reorderable"' : ''; ?> > <?php if (!empty($this->data) && is_array($this->data)) { $counter = 0; while ($row = $this->get_row($counter, 'table')) { if (is_object($row)) { $row = get_object_vars((object) $row); } $toggle_class = ''; if (is_array($this->actions_custom) && isset($this->actions_custom['toggle'])) { $toggle_class = ' pods-toggled-on'; if (!isset($row['toggle']) || empty($row['toggle'])) { $toggle_class = ' pods-toggled-off'; } } ?> <tr id="item-<?php echo esc_attr($row[$this->sql['field_id']]); ?> " class="iedit<?php echo esc_attr($toggle_class); ?> "> <?php if (!empty($this->actions_bulk)) { ?> <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php echo esc_attr($this->num); ?> []" value="<?php echo esc_attr($row[$this->sql['field_id']]); ?> "></th> <?php } foreach ($fields as $field => $attributes) { if (false === $attributes['display']) { continue; } if (!isset($row[$field])) { $row[$field] = $this->get_field($field); } $row_value = $row[$field]; if (!empty($attributes['custom_display'])) { if (is_callable($attributes['custom_display'])) { $row_value = call_user_func_array($attributes['custom_display'], array($row, &$this, $row_value, $field, $attributes)); } elseif (is_object($this->pod) && class_exists('Pods_Helpers')) { $row_value = $this->pod->helper($attributes['custom_display'], $row_value, $field); } } else { ob_start(); $field_value = PodsForm::field_method($attributes['type'], 'ui', $this->id, $row_value, $field, array_merge($attributes, pods_var_raw('options', $attributes, array(), null, true)), $fields, $this->pod); $field_output = trim((string) ob_get_clean()); if (false === $field_value) { $row_value = ''; } elseif (0 < strlen(trim((string) $field_value))) { $row_value = trim((string) $field_value); } elseif (0 < strlen($field_output)) { $row_value = $field_output; } } if (false !== $attributes['custom_relate']) { global $wpdb; $table = $attributes['custom_relate']; $on = $this->sql['field_id']; $is = $row[$this->sql['field_id']]; $what = array('name'); if (is_array($table)) { if (isset($table['on'])) { $on = pods_sanitize($table['on']); } if (isset($table['is']) && isset($row[$table['is']])) { $is = pods_sanitize($row[$table['is']]); } if (isset($table['what'])) { $what = array(); if (is_array($table['what'])) { foreach ($table['what'] as $wha) { $what[] = pods_sanitize($wha); } } else { $what[] = pods_sanitize($table['what']); } } if (isset($table['table'])) { $table = $table['table']; } } $table = pods_sanitize($table); $wha = implode(',', $what); $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'"; $value = @current($wpdb->get_results($sql, ARRAY_A)); if (!empty($value)) { $val = array(); foreach ($what as $wha) { if (isset($value[$wha])) { $val[] = $value[$wha]; } } if (!empty($val)) { $row_value = implode(' ', $val); } } } $css_classes = ' pods-ui-col-field-' . sanitize_title($field); if ($attributes['css_values']) { $css_field_value = $row[$field]; if (is_object($css_field_value)) { $css_field_value = get_object_vars($css_field_value); } if (is_array($css_field_value)) { foreach ($css_field_value as $css_field_val) { if (is_object($css_field_val)) { $css_field_val = get_object_vars($css_field_val); } if (is_array($css_field_val)) { foreach ($css_field_val as $css_field_v) { if (is_object($css_field_v)) { $css_field_v = get_object_vars($css_field_v); } $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_v))); } } else { $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_val))); } } } else { $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_value))); } } if (is_object($this->pod)) { $row_value = $this->do_hook($this->pod->pod . '_field_value', $row_value, $field, $attributes, $row); } $row_value = $this->do_hook('field_value', $row_value, $field, $attributes, $row); if ('title' == $attributes['field_id']) { $default_action = $this->do_hook('default_action', 'edit', $row); if (!in_array('edit', $this->actions_disabled) && !in_array('edit', $this->actions_hidden) && (false === $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) && 'edit' == $default_action) { $link = pods_query_arg(array('action' . $this->num => 'edit', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['edit'])) { $link = $this->do_template($this->action_links['edit'], $row); } ?> <td class="post-title page-title column-title<?php echo esc_attr($css_classes); ?> "><strong><a class="row-title" href="<?php echo esc_url_raw($link); ?> " title="<?php esc_attr_e('Edit this item', 'pods'); ?> "><?php echo $row_value; ?> </a></strong> <?php } elseif (!in_array('view', $this->actions_disabled) && !in_array('view', $this->actions_hidden) && (false === $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) && 'view' == $default_action) { $link = pods_query_arg(array('action' . $this->num => 'view', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['view'])) { $link = $this->do_template($this->action_links['view'], $row); } ?> <td class="post-title page-title column-title<?php echo esc_attr($css_classes); ?> "><strong><a class="row-title" href="<?php echo esc_url_raw($link); ?> " title="<?php esc_attr_e('View this item', 'pods'); ?> "><?php echo $row_value; ?> </a></strong> <?php } else { ?> <td class="post-title page-title column-title<?php echo esc_attr($css_classes); echo esc_attr(1 == $reorder && $this->reorder ? ' dragme' : ''); ?> "><strong><?php echo $row_value; ?> </strong> <?php } if (true !== $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) { $toggle = false; $actions = array(); if (!in_array('view', $this->actions_disabled) && !in_array('view', $this->actions_hidden)) { $link = pods_query_arg(array('action' . $this->num => 'view', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['view'])) { $link = $this->do_template($this->action_links['view'], $row); } $actions['view'] = '<span class="view"><a href="' . esc_url($link) . '" title="' . esc_attr__('View this item', 'pods') . '">' . __('View', 'pods') . '</a></span>'; } if (!in_array('edit', $this->actions_disabled) && !in_array('edit', $this->actions_hidden) && !$this->restricted('edit', $row)) { $link = pods_query_arg(array('action' . $this->num => 'edit', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['edit'])) { $link = $this->do_template($this->action_links['edit'], $row); } $actions['edit'] = '<span class="edit"><a href="' . esc_url($link) . '" title="' . esc_attr__('Edit this item', 'pods') . '">' . __('Edit', 'pods') . '</a></span>'; } if (!in_array('duplicate', $this->actions_disabled) && !in_array('duplicate', $this->actions_hidden) && !$this->restricted('edit', $row)) { $link = pods_query_arg(array('action' . $this->num => 'duplicate', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['duplicate'])) { $link = $this->do_template($this->action_links['duplicate'], $row); } $actions['duplicate'] = '<span class="edit"><a href="' . esc_url($link) . '" title="' . esc_attr__('Duplicate this item', 'pods') . '">' . __('Duplicate', 'pods') . '</a></span>'; } if (!in_array('delete', $this->actions_disabled) && !in_array('delete', $this->actions_hidden) && !$this->restricted('delete', $row)) { $link = pods_query_arg(array('action' . $this->num => 'delete', 'id' . $this->num => $row[$this->sql['field_id']], '_wpnonce' => wp_create_nonce('pods-ui-action-delete')), self::$allowed, $this->exclusion()); if (!empty($this->action_links['delete'])) { $link = add_query_arg(array('_wpnonce' => wp_create_nonce('pods-ui-action-delete')), $this->do_template($this->action_links['delete'], $row)); } $actions['delete'] = '<span class="delete"><a href="' . esc_url($link) . '" title="' . esc_attr__('Delete this item', 'pods') . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__('You are about to permanently delete this item\\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods') . '\')){return true;}return false;">' . __('Delete', 'pods') . '</a></span>'; } if (is_array($this->actions_custom)) { foreach ($this->actions_custom as $custom_action => $custom_data) { if ('add' != $custom_action && is_array($custom_data) && (isset($custom_data['link']) || isset($custom_data['callback'])) && !in_array($custom_action, $this->actions_disabled) && !in_array($custom_action, $this->actions_hidden)) { if (!in_array($custom_action, array('add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table'))) { if ('toggle' == $custom_action) { $toggle = true; $toggle_labels = array(__('Enable', 'pods'), __('Disable', 'pods')); $custom_data['label'] = $row['toggle'] ? $toggle_labels[1] : $toggle_labels[0]; } if (!isset($custom_data['label'])) { $custom_data['label'] = ucwords(str_replace('_', ' ', $custom_action)); } if (!isset($custom_data['link'])) { $vars = array('action' => $custom_action, 'id' => $row[$this->sql['field_id']], '_wpnonce' => wp_create_nonce('pods-ui-action-' . $custom_action)); if ('toggle' == $custom_action) { $vars['toggle'] = (int) (!$row['toggle']); $vars['toggled'] = 1; } $custom_data['link'] = pods_query_arg($vars, self::$allowed, $this->exclusion()); if (isset($this->action_links[$custom_action]) && !empty($this->action_links[$custom_action])) { $custom_data['link'] = add_query_arg(array('_wpnonce' => wp_create_nonce('pods-ui-action-' . $custom_action)), $this->do_template($this->action_links[$custom_action], $row)); } } $confirm = ''; if (isset($custom_data['confirm'])) { $confirm = ' onclick="if(confirm(\'' . esc_js($custom_data['confirm']) . '\')){return true;}return false;"'; } if ($this->restricted($custom_action, $row)) { continue; } $actions[$custom_action] = '<span class="edit action-' . esc_attr($custom_action) . '"><a href="' . esc_url($this->do_template($custom_data['link'], $row)) . '" title="' . esc_attr($custom_data['label']) . ' this item"' . $confirm . '>' . $custom_data['label'] . '</a></span>'; } } } } $actions = $this->do_hook('row_actions', $actions, $row[$this->sql['field_id']]); if (!empty($actions)) { ?> <div class="row-actions<?php echo esc_attr($toggle ? ' row-actions-toggle' : ''); ?> "> <?php $this->callback('actions_start', $row, $actions); echo implode(' | ', $actions); $this->callback('actions_end', $row, $actions); ?> </div> <?php } } else { ?> <input type="hidden" name="order[]" value="<?php echo esc_attr($row[$this->sql['field_id']]); ?> " /> <?php } ?> </td> <?php } elseif ('date' == $attributes['type']) { ?> <td class="date column-date<?php echo esc_attr($css_classes); ?> "><abbr title="<?php echo esc_attr($row_value); ?> "><?php echo $row_value; ?> </abbr></td> <?php } else { ?> <td class="author<?php echo esc_attr($css_classes); ?> "><span><?php echo $row_value; ?> </span></td> <?php } } ?> </tr> <?php } } ?> </tbody> </table> <?php if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { ?> </form> <?php } ?> <script type="text/javascript"> jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' ); <?php if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { ?> jQuery( document ).ready( function () { jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} ); jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) { jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' ); jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' ); } ); } ); <?php } ?> </script> <?php }
/** * Validate a value before it's saved * * @param mixed $value * @param string $name * @param array $options * @param array $fields * @param array $pod * @param int $id * * @since 2.0 */ public function validate($value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null) { $errors = array(); $label = strip_tags(pods_var_raw('label', $options, ucwords(str_replace('_', ' ', $name)))); $check = $this->pre_save($value, $id, $name, $options, $fields, $pod, $params); if (is_array($check)) { $errors = $check; } else { if (0 < strlen($value) && strlen($check) < 1) { if (1 == pods_var('required', $options)) { $errors[] = sprintf(__('The %s field is required.', 'pods'), $label); } else { $errors[] = sprintf(__('Invalid phone number provided for the field %s.', 'pods'), $label); } } } if (!empty($errors)) { return $errors; } return true; }
foreach ($field_option['group'] as $field_group_name => $field_group_option) { $field_group_option = (array) $field_group_option; if ('boolean' != $field_group_option['type']) { continue; } $field_group_option['boolean_yes_label'] = $field_group_option['label']; $depends_option = PodsForm::dependencies($field_group_option, !isset($pods_tab_form) ? 'field-data-' : ''); $row_name = $field_group_name; if (!isset($pods_tab_form)) { $row_name = 'field_data[' . $pods_i . '][' . $field_group_name . ']'; } $value = $field_group_option['default']; if (isset($field_group_option['value']) && 0 < strlen($field_group_option['value'])) { $value = $field_group_option['value']; } else { $value = pods_var_raw($field_group_name, $field, $value); } ?> <li class="<?php echo esc_attr($depends_option); ?> "> <?php echo PodsForm::field($row_name, $value, $field_group_option['type'], $field_group_option); ?> </li> <?php } ?> </ul> </div>
<p><?php _e('Packages allow you to import/export your Pods, Fields, and other settings between any Pods sites.', 'pods'); ?> </p> </div> <div class="stuffbox"> <h3><label for="link_name"><?php _e('Paste the Package Code', 'pods'); ?> </label></h3> <div class="inside pods-manage-field pods-dependency"> <div class="pods-field-option"> <?php echo PodsForm::field('import_package', pods_var_raw('import_package', 'post'), 'paragraph', array('attributes' => array('style' => 'width: 94%; max-width: 94%; height: 300px;'))); ?> </div> </div> </div> </div> <div class="pods-wizard-option-content" id="pods-wizard-export"> <div class="pods-wizard-content"> <p><?php _e('Packages allow you to import/export your Pods, Fields, and other settings between any Pods sites.', 'pods'); ?> </p> </div> <?php
<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> <?php } ?> </ul> </td> </tr>
/** * @param array $data Array of data * @param string $delimiter Delimiter for export type 'sv' * * @return bool */ public function build_sv($data = null, $delimiter = null) { if (!empty($data)) { $this->set_data($data); } if (!empty($delimiter)) { $this->delimiter = $delimiter; } if (empty($this->data) || !is_array($this->data)) { return false; } $head = $lines = ''; foreach ($this->data['columns'] as $column => $label) { $head .= '"' . $label . '"' . $this->delimiter; } $head = substr($head, 0, -1); foreach ($this->data['items'] as $item) { $line = ''; foreach ($this->data['columns'] as $column => $label) { if (is_numeric($column) && (is_object($item) && !isset($item->{$column}) || is_array($item) && !isset($item[$column]))) { $column = $label; } $value = ''; if (is_object($item)) { if (!isset($item->{$column})) { $item->{$column} = ''; } $value = $item->{$column}; } elseif (is_array($item)) { if (!isset($item[$column])) { $item[$column] = ''; } $value = $item[$column]; } if (is_array($value) || is_object($value)) { $value = pods_serial_comma($value, array('field' => $column, 'fields' => pods_var_raw($column, $this->data['fields']), 'and' => '')); } $value = str_replace(array('"', "\r\n", "\r", "\n"), array('\\"', "\n", "\n", '\\n'), $value); $line .= '"' . $value . '"' . $this->delimiter; } $lines .= substr($line, 0, -1) . "\n"; } if (!empty($lines)) { $lines = "\n" . substr($lines, 0, -1); } $this->built = $head . $lines; return $this->built; }
?> <li> <?php } ?> <div class="pods-field pods-boolean"<?php echo $indent; ?> > <input<?php PodsForm::attributes($attributes, $name, $form_field_type, $options); ?> /> <?php if (0 < strlen($label)) { $help = pods_var_raw('help', $options); if (1 == pods_var('grouped', $options, 0, null, true) || empty($help)) { $help = ''; } echo PodsForm::label($attributes['id'], $label, $help); } ?> </div> <?php if (1 == pods_var('grouped', $options, 0, null, true)) { ?> </li> <?php } $counter++; }
/** * Export a Package * * $params['pods'] string|array|bool Pod IDs to export, or set to true to export all * $params['templates'] string|array|bool Template IDs to export, or set to true to export all * $params['pages'] string|array|bool Page IDs to export, or set to true to export all * $params['helpers'] string|array|bool Helper IDs to export, or set to true to export all * * @param array $params Array of things to export * * @return array|bool * * @static * @since 2.0.5 */ public static function export($params) { $export = array('meta' => array('version' => PODS_VERSION, 'build' => time())); if (is_object($params)) { $params = get_object_vars($params); } $api = pods_api(); $pod_ids = pods_var_raw('pods', $params); $template_ids = pods_var_raw('templates', $params); $page_ids = pods_var_raw('pages', $params); $helper_ids = pods_var_raw('helpers', $params); if (!empty($pod_ids)) { $api_params = array('export' => true); if (true !== $pod_ids) { $api_params['ids'] = (array) $pod_ids; } $export['pods'] = $api->load_pods($api_params); $options_ignore = array('pod_id', 'old_name', 'object_type', 'object_name', 'object_hierarchical', 'table', 'meta_table', 'pod_table', 'field_id', 'field_index', 'field_slug', 'field_type', 'field_parent', 'field_parent_select', 'meta_field_id', 'meta_field_index', 'meta_field_value', 'pod_field_id', 'pod_field_index', 'object_fields', 'join', 'where', 'where_default', 'orderby', 'pod', 'recurse', 'table_info', 'attributes', 'group', 'grouped', 'developer_mode', 'dependency', 'depends-on', 'excludes-on'); $field_types = PodsForm::field_types(); $field_type_options = array(); foreach ($field_types as $type => $field_type_data) { $field_type_options[$type] = PodsForm::ui_options($type); } foreach ($export['pods'] as &$pod) { if (isset($pod['options'])) { $pod = array_merge($pod, $pod['options']); unset($pod['options']); } foreach ($pod as $option => $option_value) { if (in_array($option, $options_ignore) || null === $option_value) { unset($pod[$option]); } } if (!empty($pod['fields'])) { foreach ($pod['fields'] as &$field) { if (isset($field['options'])) { $field = array_merge($field, $field['options']); unset($field['options']); } foreach ($field as $option => $option_value) { if (in_array($option, $options_ignore) || null === $option_value) { unset($field[$option]); } } foreach ($field_type_options as $type => $options) { if ($type == pods_var('type', $field)) { continue; } foreach ($options as $option_data) { if (isset($option_data['group']) && is_array($option_data['group']) && !empty($option_data['group'])) { if (isset($field[$option_data['name']])) { unset($field[$option_data['name']]); } foreach ($option_data['group'] as $group_option_data) { if (isset($field[$group_option_data['name']])) { unset($field[$group_option_data['name']]); } } } elseif (isset($field[$option_data['name']])) { unset($field[$option_data['name']]); } } } } } } } if (!empty($template_ids)) { $api_params = array(); if (true !== $template_ids) { $api_params['ids'] = (array) $template_ids; } $export['templates'] = $api->load_templates($api_params); } if (!empty($page_ids)) { $api_params = array(); if (true !== $page_ids) { $api_params['ids'] = (array) $page_ids; } $export['pages'] = $api->load_pages($api_params); } if (!empty($helper_ids)) { $api_params = array(); if (true !== $helper_ids) { $api_params['ids'] = (array) $helper_ids; } $export['helpers'] = $api->load_helpers($api_params); } $export = apply_filters('pods_packages_export', $export, $params); if (1 == count($export)) { return false; } $export = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($export, JSON_UNESCAPED_UNICODE) : json_encode($export); return $export; }
<?php if (!pods_tableless() && apply_filters('pods_admin_setup_add_extend_storage', false)) { ?> <div class="pods-depends-on pods-depends-on-extend-pod-type pods-depends-on-extend-pod-type-post-type pods-depends-on-extend-pod-type-media pods-depends-on-extend-pod-type-user pods-depends-on-extend-pod-type-comment"> <p><a href="#pods-advanced" class="pods-advanced-toggle"><?php _e('Advanced', 'pods'); ?> +</a></p> <div class="pods-advanced"> <div class="pods-field-option"> <?php echo PodsForm::label('extend_storage', __('Storage Type', 'pods'), array(__('<h6>Storage Types</h6> Table based storage will operate in a way where each field you create for your content type becomes a field in a table. Meta based storage relies upon the WordPress meta storage table for all field data.', 'pods'), 'http://pods.io/docs/comparisons/compare-storage-types/')); $data = array('meta' => __('Meta Based (WP Default)', 'pods'), 'table' => __('Table Based', 'pods')); echo PodsForm::field('extend_storage', pods_var_raw('extend_storage', 'post'), 'pick', array('data' => $data)); ?> </div> </div> </div> <?php } ?> </div> </div> </div> </div> <div id="pods-wizard-actions"> <div id="pods-wizard-toolbar"> <a href="#start" id="pods-wizard-start" class="button button-secondary"><?php
/** * Add Admin Bar links */ public function admin_bar_links() { global $wp_admin_bar, $pods; if (!is_user_logged_in() || !is_admin_bar_showing()) { return; } $all_pods = pods_api()->load_pods(array('type' => 'pod', 'fields' => false)); // Add New item links for all pods foreach ($all_pods as $pod) { if (0 == $pod['options']['show_in_menu']) { continue; } if (!pods_is_admin(array('pods', 'pods_content', 'pods_add_' . $pod['name']))) { continue; } $singular_label = pods_var_raw('label_singular', $pod['options'], pods_var_raw('label', $pod, ucwords(str_replace('_', ' ', $pod['name'])), null, true), null, true); $wp_admin_bar->add_node(array('id' => 'new-pod-' . $pod['name'], 'title' => $singular_label, 'parent' => 'new-content', 'href' => admin_url('admin.php?page=pods-manage-' . $pod['name'] . '&action=add'))); } // Add edit link if we're on a pods page if (is_object($pods) && !is_wp_error($pods) && !empty($pods->id) && isset($pods->pod_data) && !empty($pods->pod_data) && 'pod' == $pods->pod_data['type']) { $pod = $pods->pod_data; if (pods_is_admin(array('pods', 'pods_content', 'pods_edit_' . $pod['name']))) { $singular_label = pods_var_raw('label_singular', $pod['options'], pods_var_raw('label', $pod, ucwords(str_replace('_', ' ', $pod['name'])), null, true), null, true); $wp_admin_bar->add_node(array('title' => sprintf(__('Edit %s', 'pods'), $singular_label), 'id' => 'edit-pod', 'href' => admin_url('admin.php?page=pods-manage-' . $pod['name'] . '&action=edit&id=' . $pods->id()))); } } }
} var pods_sister_field_going = { }; var pods_sister_field = function ( $el ) { var id = $el.closest( 'tr.pods-manage-row' ).data( 'row' ); if ( 'undefined' != typeof pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] && true == pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] ) return; pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = true; var default_select = '<?php echo str_replace(array("\n", "\r"), ' ', PodsForm::field('field_data[--1][sister_id]', '', 'pick', array('data' => pods_var_raw('sister_id', $field_settings)))); ?> '; default_select = default_select.replace( /\-\-1/g, id ); var related_pod_name = jQuery( '#pods-form-ui-field-data-' + id + '-pick-object' ).val(); if ( 0 != related_pod_name.indexOf( 'pod-' ) && 0 != related_pod_name.indexOf( 'post_type-' ) && 0 != related_pod_name.indexOf( 'taxonomy-' ) && 0 != related_pod_name.indexOf( 'user' ) && 0 != related_pod_name.indexOf( 'media' ) && 0 != related_pod_name.indexOf( 'comment' ) ) { pods_sister_field_going[ id + '_' + $el.prop( 'id' ) ] = false; return; } var selected_value = jQuery( '#pods-form-ui-field-data-' + id + '-sister-id' ).val(); var select_container = default_select.match( /<select[^<]*>/g );
/** * 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; }
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'; }
/** * Advanced $expires handling * * @param array|bool|int $expires * @param string $cache_mode * * @return bool|int * * @since 3.0 * @static */ public static function expires($expires, $cache_mode = 'cache') { // Different $expires if user is anonymous or logged in or specific capability if (is_array($expires)) { if ((isset($expires['anonymous']) || isset($expires['user_with_access'])) && isset($expires['user'])) { if (isset($expires['user_with_access'])) { $expires = array(pods_var_raw('anonymous', $expires, false), pods_var_raw('user', $expires, false), pods_var_raw('user_with_access', $expires, false), pods_var_raw('capability', $expires, null, null, true)); } elseif (isset($expires['anonymous'])) { $expires = array(pods_var_raw('anonymous', $expires, false), pods_var_raw('user', $expires, false), pods_var_raw('capability', $expires, null, null, true)); } } else { $expires = array_values($expires); } if (4 == count($expires)) { if (!is_user_logged_in()) { $expires = pods_var_raw(0, $expires, false); } else { $user_no_access = pods_var_raw(1, $expires, false); $user_with_access = pods_var_raw(2, $expires, false); $capability = pods_var_raw(3, $expires, null, null, true); $expires = pods_var_user($user_no_access, $user_with_access, $capability); } } else { $anon = pods_var_raw(0, $expires, false); $user = pods_var_raw(1, $expires, false); $capability = pods_var_raw(2, $expires, null, null, true); $expires = pods_var_user($anon, $user, $capability); } } if ('none' == $cache_mode) { $expires = false; } elseif (false !== $expires) { $expires = (int) $expires; if ($expires < 1) { $expires = 0; } } return $expires; }
/** * Parse the default the value * * @since 2.0 */ public static function default_value($value, $type = 'text', $name = null, $options = null, $pod = null, $id = null) { $default_value = pods_v('default_value', $options); if ('' === $default_value || null === $default_value) { $default_value = $value; } $default = pods_v('default', $options, $default_value, true); $default_value = str_replace(array('{@', '}'), '', trim($default)); if ($default != $default_value && 1 == (int) pods_v('default_evaluate_tags', $options, 1)) { $default = pods_evaluate_tags($default); } $default = pods_var_raw(pods_v('default_value_parameter', $options), 'request', $default, null, true); if ($default != $value) { $value = $default; } if (is_array($value)) { $value = pods_serial_comma($value); } return apply_filters('pods_form_field_default_value', $value, $default, $type, $options, $pod, $id); }
/** * Run any precode for current Pod Page */ public function precode() { global $pods; // Fix any global confusion wherever this runs if (isset($pods) && !isset($GLOBALS['pods'])) { $GLOBALS['pods'] =& $pods; } elseif (!isset($pods) && isset($GLOBALS['pods'])) { $pods =& $GLOBALS['pods']; } if (false !== self::$exists) { $permission = pods_permission(self::$exists['options']); $permission = (bool) apply_filters('pods_pages_permission', $permission, self::$exists); if ($permission) { $content = false; if (!is_object($pods) && 404 != $pods && 0 < strlen(pods_var('pod', self::$exists['options']))) { $slug = pods_var_raw('pod_slug', self::$exists['options'], null, null, true); // Handle special magic tags if (0 < strlen($slug)) { $slug = pods_evaluate_tags($slug, true); } $pods = pods(pods_var('pod', self::$exists['options']), $slug); // Auto 404 handling if item doesn't exist if (0 < strlen($slug) && !$pods->exists() && apply_filters('pods_pages_auto_404', true, $slug, $pods, self::$exists)) { $pods = 404; } } if (0 < strlen(trim(self::$exists['precode']))) { $content = self::$exists['precode']; } if (false !== $content && (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL)) { pods_deprecated('Pod Page Precode has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1'); eval("?>{$content}"); } do_action('pods_page_precode', self::$exists, $pods, $content); } elseif (self::$exists['options']['restrict_redirect']) { $redirect_url = ''; if (self::$exists['options']['restrict_redirect_login']) { $redirect_url = wp_login_url(pods_current_url()); } elseif (!empty(self::$exists['options']['restrict_redirect_url'])) { $redirect_url = self::$exists['options']['restrict_redirect_url']; } if (!empty($redirect_url)) { wp_redirect($redirect_url); die; } } if (!$permission || !is_object($pods) && (404 == $pods || is_wp_error($pods))) { remove_action('template_redirect', array($this, 'template_redirect')); remove_action('wp_head', array($this, 'wp_head')); remove_filter('redirect_canonical', '__return_false'); remove_filter('wp_title', array($this, 'wp_title')); remove_filter('body_class', array($this, 'body_class')); remove_filter('status_header', array($this, 'status_header')); remove_action('wp', array($this, 'silence_404'), 1); } } }