/**
         * Output something at the start of the table form
         *
         * @param object $form Form class
         * @param bool $results
         */
        function _start_table_edit($form, $results = true)
        {
            $api = pods_api();
            $all_pods = $api->load_pods(array('names' => true));
            $pod_types = array();
            foreach ($all_pods as $pod_name => $pod_label) {
                $pod_types[$pod_name] = $pod_label . ' (' . $pod_name . ')';
            }
            ?>
    <tr>
        <td valign="top">
            <label for="pod_type"><?php 
            _e('Pod', 'pods');
            ?>
</label>
        </td>
        <td>
            <?php 
            if (0 < count($all_pods)) {
                $form->add_drop_down('pod_type', $pod_types);
            } else {
                echo '<strong class="red">' . __('None Found', 'pods') . '</strong>';
            }
            ?>
        </td>
    </tr>
    <tr>
        <td valign="top">
            <label for="slug"><?php 
            _e('Slug or ID', 'pods');
            ?>
</label>
        </td>
        <td>
            <?php 
            $form->add_text_box('slug');
            ?>
        </td>
    </tr>
    <tr>
        <td valign="top">
            <label for="field"><?php 
            _e('Field', 'pods');
            ?>
</label>
        </td>
        <td>
            <?php 
            $form->add_text_box('field');
            ?>
        </td>
    </tr>
<?php 
        }
Exemple #2
0
 public static function build_menu()
 {
     $PodsAPI = pods_api();
     $registered_pods = $PodsAPI->load_pods();
     $role = get_role("administrator");
     foreach ($registered_pods as $pod_info) {
         if (pods_related::is_dms_pod($pod_info["name"])) {
             continue;
         }
         // Add Custom DMS Capabilities
         $role->add_cap("pods_read_others_" . $pod_info["name"]);
         $role->add_cap("pods_read_bygroup_" . $pod_info["name"]);
         $role->add_cap("pods_read_" . $pod_info["name"]);
         $role->add_cap("pods_edit_bygroup_" . $pod_info["name"]);
         $role->add_cap("pods_delete_sealed_" . $pod_info["name"]);
         $role->add_cap("pods_edit_sealed_" . $pod_info["name"]);
         $role->add_cap("pods_unseal_" . $pod_info["name"]);
         $role->add_cap("jomiz_dms_front_settings");
         $role->add_cap("show_reports_in_menu");
     }
     if (!is_user_logged_in()) {
         return "";
     }
     $menu = '<div id="menu-expanded" class="list-group hidden-xs">';
     $navbar_menu = "";
     foreach ($registered_pods as $pod_info) {
         // don't show in the main menu
         if (pods_related::is_dms_pod($pod_info["name"]) || $pod_info['options']['show_in_menu'] == 0) {
             continue;
         }
         if (dms_security::is_allowed($pod_info["name"], array("read_others", "read", "read_bygroup"))) {
             $pod_label = $pod_info["label"];
             $pod_link = pods_related::get_pod_url($pod_info["name"], "list");
             $active_class = "";
             if (isset($_GET['type']) && $_GET['type'] == $pod_info["name"]) {
                 $active_class = "active";
             }
             $listing_link = "<a class='list-group-item {$active_class}' href='{$pod_link}' title='View {$pod_label}'>{$pod_label}</a>";
             $navbar_menu .= "<li class='{$active_class}'><a href='{$pod_link}'>{$pod_label}</a></li>";
             $menu .= $listing_link;
         }
     }
     //Reports Link
     if (dms_security::is_allowed_cap("show_reports_in_menu")) {
         $reports_link = home_url("/reports/");
         $navbar_menu .= "<li class='divider'></li><li class=''><a href='{$reports_link}'>Reports</a></li>";
         $menu .= "<a href='{$reports_link}' class='list-group-item'>Reports</a>";
     }
     $menu .= "<a href='#' id='meunitem-showhide' onclick='showhide_mainmenu()' class='list-group-item'><span class='glyphicon glyphicon-pushpin'></span></a>";
     $menu .= "</div>";
     return array("navbar-menu" => $navbar_menu, "vertical-menu" => $menu);
 }
 /**
  * Gets relationships
  *
  * @since 0.2.0
  *
  * @return bool
  */
 public static function get_relationships()
 {
     $relationships = false;
     $api = pods_api();
     $pods = $api->load_pods();
     foreach ($pods as $pod) {
         $pod_name = pods_v('name', $pod);
         if (!is_null($local_fields = pods_v('fields', $pod))) {
             foreach ($local_fields as $field_name => $field) {
                 if ('' !== ($sister_id = pods_v('sister_id', $field))) {
                     $relationships[pods_v('name', $field)] = array('from' => array('pod_name' => $pod_name, 'field_name' => pods_v('name', $field)), 'to' => self::find_by_id($sister_id, $pods));
                 }
             }
         }
     }
     return $relationships;
 }
 public static function is_dw_pods_page($id)
 {
     if (function_exists('pods_api')) {
         $pod_page = pods_api()->load_page(array('id' => $id));
         $pod_page_name = !empty($pod_page) ? $pod_page['name'] : '';
         if (!empty($pod_page_name) && is_pod_page($pod_page_name)) {
             return TRUE;
         }
     } else {
         global $pod_page_exists;
         if (is_int($id)) {
             $id = array($id);
         }
         if (in_array($pod_page_exists['id'], $id)) {
             return TRUE;
         }
     }
     return FALSE;
 }
Exemple #5
0
 function baldrick_pods_endpoint()
 {
     if (defined('PODS_VERSION') && defined('PODS_JSON_API_VERSION')) {
         //add the basic pods endpoints
         $endpoints['pods'] = json_url('pods');
         $endpoints['pods-api'] = json_url('pods-api');
         //get name of all registered Pods
         $pods = pods_api()->load_pods(array('names' => true));
         //add end point foreach if there are registered Pods
         if (is_array($pods) && !empty($pods)) {
             $endpoint_types = array('pods', 'pods_api');
             foreach ($pods as $pod) {
                 foreach ($endpoint_types as $type) {
                     $endpoints = array_merge($endpoints, array("{$type}/{$pod}" => json_url("{$type}/{$pod}")));
                 }
             }
         }
         return $endpoints;
     }
 }
/**
 * Basic breadcrumbs for custom post type Pod, using load_pod to get Pod labels.
 *
 * Someone should add handling for posts and pages as well as ACTs to this. Possibly make a plugin.
 */
function slug_post_type_breadcrumb($divider = '&gt;&gt;')
{
    $front = slug_link(site_url(), 'Home');
    if (is_home() || is_front_page()) {
        return $front;
    }
    if (is_post_type_archive() || is_singular() && get_post_type() !== false) {
        $post_type = get_post_type();
        $pod = pods_api()->load_pod($post_type);
        if (!is_string($pod)) {
            $single = $pod->options['single_label'];
            $plural = slug_link(get_post_type_archive($post_type), $pod->label, 'All ' . $single);
            if (is_post_type_archive()) {
                return $front . $divider . $plural;
            }
            global $post;
            $single = slug_link(get_permalink($post->ID), get_the__title($post->ID), 'View ' . $single);
            return $front . $divider . $single;
        } else {
            return;
        }
    }
}
<?php

if (!empty($_POST)) {
    if (isset($_POST['clearcache'])) {
        $api = pods_api();
        $api->cache_flush_pods();
        if (defined('PODS_PRELOAD_CONFIG_AFTER_FLUSH') && PODS_PRELOAD_CONFIG_AFTER_FLUSH) {
            $api->load_pods();
        }
        pods_redirect(pods_query_arg(array('pods_clearcache' => 1), array('page', 'tab')));
    }
} elseif (1 == pods_var('pods_clearcache')) {
    pods_message('Pods transients and cache have been cleared.');
}
?>

<h3><?php 
_e('Clear Pods Cache', 'pods');
?>
</h3>

<p><?php 
_e('This tool will clear all of the transients/cache that are used by Pods. ', 'pods');
?>
</p>

<p class="submit">
    <input type="submit" class="button button-primary" name="clearcache" value="<?php 
esc_attr_e('Clear Pods Cache', 'pods');
?>
" />
Exemple #8
0
 /**
  * Add or edit a single pod item
  *
  * $params['pod'] string The Pod name (pod or pod_id is required)
  * $params['pod_id'] string The Pod ID (pod or pod_id is required)
  * $params['id'] int The item ID
  * $params['data'] array (optional) Associative array of field names + values
  * $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers
  * $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
  *
  * @param array|object $params An associative array of parameters
  *
  * @return int The item ID
  *
  * @since 1.7.9
  */
 public function save_pod_item($params)
 {
     global $wpdb;
     $params = (object) pods_str_replace('@wp_', '{prefix}', $params);
     $tableless_field_types = PodsForm::tableless_field_types();
     $repeatable_field_types = PodsForm::repeatable_field_types();
     $simple_tableless_objects = PodsForm::simple_tableless_objects();
     // @deprecated 2.0
     if (isset($params->datatype)) {
         pods_deprecated('$params->pod instead of $params->datatype', '2.0');
         $params->pod = $params->datatype;
         unset($params->datatype);
         if (isset($params->pod_id)) {
             pods_deprecated('$params->id instead of $params->pod_id', '2.0');
             $params->id = $params->pod_id;
             unset($params->pod_id);
         }
         if (isset($params->data) && !empty($params->data) && is_array($params->data)) {
             $check = current($params->data);
             if (is_array($check)) {
                 pods_deprecated('PodsAPI::save_pod_items', '2.0');
                 return $this->save_pod_items($params, $params->data);
             }
         }
     }
     // @deprecated 2.0
     if (isset($params->tbl_row_id)) {
         pods_deprecated('$params->id instead of $params->tbl_row_id', '2.0');
         $params->id = $params->tbl_row_id;
         unset($params->tbl_row_id);
     }
     // @deprecated 2.0
     if (isset($params->columns)) {
         pods_deprecated('$params->data instead of $params->columns', '2.0');
         $params->data = $params->columns;
         unset($params->columns);
     }
     if (!isset($params->pod)) {
         $params->pod = false;
     }
     if (isset($params->pod_id)) {
         $params->pod_id = pods_absint($params->pod_id);
     } else {
         $params->pod_id = 0;
     }
     if (isset($params->id)) {
         $params->id = pods_absint($params->id);
     } else {
         $params->id = 0;
     }
     if (!isset($params->from)) {
         $params->from = 'save';
     }
     if (!isset($params->location)) {
         $params->location = null;
     }
     if (!isset($params->track_changed_fields)) {
         $params->track_changed_fields = false;
     }
     /**
      * Override $params['track_changed_fields']
      *
      * Use for globally setting field change tracking.
      *
      * @param bool
      *
      * @since 2.3.19
      */
     $track_changed_fields = apply_filters('pods_api_save_pod_item_track_changed_fields_' . $params->pod, (bool) $params->track_changed_fields, $params);
     $changed_fields = array();
     if (!isset($params->clear_slug_cache)) {
         $params->clear_slug_cache = true;
     }
     // Support for bulk edit
     if (isset($params->id) && !empty($params->id) && is_array($params->id)) {
         $ids = array();
         $new_params = $params;
         foreach ($params->id as $id) {
             $new_params->id = $id;
             $ids[] = $this->save_pod_item($new_params);
         }
         return $ids;
     }
     // Allow Helpers to know what's going on, are we adding or saving?
     $is_new_item = false;
     if (empty($params->id)) {
         $is_new_item = true;
     }
     if (isset($params->is_new_item)) {
         $is_new_item = (bool) $params->is_new_item;
     }
     // Allow Helpers to bypass subsequent helpers in recursive save_pod_item calls
     $bypass_helpers = false;
     if (isset($params->bypass_helpers) && false !== $params->bypass_helpers) {
         $bypass_helpers = true;
     }
     // Allow Custom Fields not defined by Pods to be saved
     $allow_custom_fields = false;
     if (isset($params->allow_custom_fields) && false !== $params->allow_custom_fields) {
         $allow_custom_fields = true;
     }
     // Get array of Pods
     $pod = $this->load_pod(array('id' => $params->pod_id, 'name' => $params->pod, 'table_info' => true));
     if (false === $pod) {
         return pods_error(__('Pod not found', 'pods'), $this);
     }
     $params->pod = $pod['name'];
     $params->pod_id = $pod['id'];
     if ('settings' == $pod['type']) {
         $params->id = $pod['id'];
     }
     $fields = $pod['fields'];
     $object_fields = (array) pods_var_raw('object_fields', $pod, array(), null, true);
     $fields_active = array();
     $custom_data = array();
     // Find the active fields (loop through $params->data to retain order)
     if (!empty($params->data) && is_array($params->data)) {
         $custom_fields = array();
         foreach ($params->data as $field => $value) {
             if (isset($object_fields[$field])) {
                 $object_fields[$field]['value'] = $value;
                 $fields_active[] = $field;
             } elseif (isset($fields[$field])) {
                 if ('save' == $params->from || true === PodsForm::permission($fields[$field]['type'], $field, $fields[$field], $fields, $pod, $params->id, $params)) {
                     $fields[$field]['value'] = $value;
                     $fields_active[] = $field;
                 } elseif (!pods_has_permissions($fields[$field]['options']) && pods_var('hidden', $fields[$field]['options'], false)) {
                     $fields[$field]['value'] = $value;
                     $fields_active[] = $field;
                 }
             } else {
                 $found = false;
                 foreach ($object_fields as $object_field => $object_field_opt) {
                     if (in_array($field, $object_field_opt['alias'])) {
                         $object_fields[$object_field]['value'] = $value;
                         $fields_active[] = $object_field;
                         $found = true;
                         break;
                     }
                 }
                 if ($allow_custom_fields && !$found) {
                     $custom_fields[] = $field;
                 }
             }
         }
         if ($allow_custom_fields && !empty($custom_fields)) {
             foreach ($custom_fields as $field) {
                 $custom_data[$field] = $params->data[$field];
             }
         }
         if ($pod['type'] === 'taxonomy' && isset($params->data) && !empty($params->data)) {
             $term_data = $params->data;
         }
         unset($params->data);
     }
     if (empty($params->id) && !in_array('created', $fields_active) && isset($fields['created']) && in_array($fields['created']['type'], array('date', 'datetime'))) {
         $fields['created']['value'] = current_time('mysql');
         $fields_active[] = 'created';
     }
     if (!in_array('modified', $fields_active) && isset($fields['modified']) && in_array($fields['modified']['type'], array('date', 'datetime'))) {
         $fields['modified']['value'] = current_time('mysql');
         $fields_active[] = 'modified';
     }
     if (in_array($pod['type'], array('pod', 'table')) && empty($params->id) && !empty($pod['pod_field_index']) && in_array($pod['pod_field_index'], $fields_active) && !in_array($pod['pod_field_slug'], $fields_active) && isset($fields[$pod['pod_field_slug']])) {
         $fields[$pod['pod_field_slug']]['value'] = '';
         // this will get picked up by slug pre_save method
         $fields_active[] = $pod['pod_field_slug'];
     }
     // Handle hidden fields
     if (empty($params->id)) {
         foreach ($fields as $field => $field_data) {
             if (in_array($field, $fields_active)) {
                 continue;
             }
             if (in_array($params->from, array('save', 'process_form')) || true === PodsForm::permission($fields[$field]['type'], $field, $fields[$field], $fields, $pod, $params->id, $params)) {
                 $value = PodsForm::default_value(pods_var_raw($field, 'post'), $field_data['type'], $field, pods_var_raw('options', $field_data, $field_data, null, true), $pod, $params->id);
                 if (null !== $value && '' !== $value && false !== $value) {
                     $fields[$field]['value'] = $value;
                     $fields_active[] = $field;
                 }
             }
         }
         // Set default field values for object fields
         if (!empty($object_fields)) {
             foreach ($object_fields as $field => $field_data) {
                 if (in_array($field, $fields_active)) {
                     continue;
                 } elseif (!isset($field_data['default']) || strlen($field_data['default']) < 1) {
                     continue;
                 }
                 $value = PodsForm::default_value(pods_var_raw($field, 'post'), $field_data['type'], $field, pods_var_raw('options', $field_data, $field_data, null, true), $pod, $params->id);
                 if (null !== $value && '' !== $value && false !== $value) {
                     $object_fields[$field]['value'] = $value;
                     $fields_active[] = $field;
                 }
             }
         }
         // Set default field values for Pod fields
         foreach ($fields as $field => $field_data) {
             if (in_array($field, $fields_active)) {
                 continue;
             } elseif (!isset($field_data['default']) || strlen($field_data['default']) < 1) {
                 continue;
             }
             $value = PodsForm::default_value(pods_var_raw($field, 'post'), $field_data['type'], $field, pods_var_raw('options', $field_data, $field_data, null, true), $pod, $params->id);
             if (null !== $value && '' !== $value && false !== $value) {
                 $fields[$field]['value'] = $value;
                 $fields_active[] = $field;
             }
         }
     }
     $columns =& $fields;
     // @deprecated 2.0
     $active_columns =& $fields_active;
     // @deprecated 2.0
     $params->tbl_row_id =& $params->id;
     // @deprecated 2.0
     $pre_save_helpers = $post_save_helpers = array();
     $pieces = array('fields', 'params', 'pod', 'fields_active', 'object_fields', 'custom_fields', 'custom_data', 'track_changed_fields', 'changed_fields');
     if (false === $bypass_helpers) {
         // Plugin hooks
         $hooked = $this->do_hook('pre_save_pod_item', compact($pieces), $is_new_item, $params->id);
         if (is_array($hooked) && !empty($hooked)) {
             extract($hooked);
         }
         $hooked = $this->do_hook("pre_save_pod_item_{$params->pod}", compact($pieces), $is_new_item, $params->id);
         if (is_array($hooked) && !empty($hooked)) {
             extract($hooked);
         }
         if ($is_new_item) {
             $hooked = $this->do_hook('pre_create_pod_item', compact($pieces));
             if (is_array($hooked) && !empty($hooked)) {
                 extract($hooked);
             }
             $hooked = $this->do_hook("pre_create_pod_item_{$params->pod}", compact($pieces));
             if (is_array($hooked) && !empty($hooked)) {
                 extract($hooked);
             }
         } else {
             $hooked = $this->do_hook('pre_edit_pod_item', compact($pieces), $params->id);
             if (is_array($hooked) && !empty($hooked)) {
                 extract($hooked);
             }
             $hooked = $this->do_hook("pre_edit_pod_item_{$params->pod}", compact($pieces), $params->id);
             if (is_array($hooked) && !empty($hooked)) {
                 extract($hooked);
             }
         }
         // Call any pre-save helpers (if not bypassed)
         if (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL) {
             if (!empty($pod['options']) && is_array($pod['options'])) {
                 $helpers = array('pre_save_helpers', 'post_save_helpers');
                 foreach ($helpers as $helper) {
                     if (isset($pod['options'][$helper]) && !empty($pod['options'][$helper])) {
                         ${$helper} = explode(',', $pod['options'][$helper]);
                     }
                 }
             }
             if (!empty($pre_save_helpers)) {
                 pods_deprecated(sprintf(__('Pre-save helpers are deprecated, use the action pods_pre_save_pod_item_%s instead', 'pods'), $params->pod), '2.0');
                 foreach ($pre_save_helpers as $helper) {
                     $helper = $this->load_helper(array('name' => $helper));
                     if (false !== $helper) {
                         eval('?>' . $helper['code']);
                     }
                 }
             }
         }
     }
     if ($track_changed_fields) {
         $changed_fields = $this->get_changed_fields(compact($pieces));
     }
     $table_data = $table_formats = $update_values = $rel_fields = $rel_field_ids = array();
     $object_type = $pod['type'];
     $object_ID = 'ID';
     if ('comment' == $object_type) {
         $object_ID = 'comment_ID';
     }
     $object_data = $object_meta = $post_term_data = array();
     if ('settings' == $object_type) {
         $object_data['option_id'] = $pod['name'];
     } elseif (!empty($params->id)) {
         $object_data[$object_ID] = $params->id;
     }
     $fields_active = array_unique($fields_active);
     // Loop through each active field, validating and preparing the table data
     foreach ($fields_active as $field) {
         if (isset($object_fields[$field])) {
             $field_data = $object_fields[$field];
         } elseif (isset($fields[$field])) {
             $field_data = $fields[$field];
         } else {
             continue;
         }
         $value = $field_data['value'];
         $type = $field_data['type'];
         $options = pods_var('options', $field_data, array());
         // WPML AJAX compatibility
         if (is_admin() && isset($_GET['page']) && false !== strpos($_GET['page'], '/menu/languages.php') && isset($_POST['icl_ajx_action']) && isset($_POST['_icl_nonce']) && wp_verify_nonce($_POST['_icl_nonce'], $_POST['icl_ajx_action'] . '_nonce')) {
             $options['unique'] = $fields[$field]['options']['unique'] = $options['required'] = $fields[$field]['options']['required'] = 0;
         } else {
             // Validate value
             $validate = $this->handle_field_validation($value, $field, $object_fields, $fields, $pod, $params);
             if (false === $validate) {
                 $validate = sprintf(__('There was an issue validating the field %s', 'pods'), $field_data['label']);
             } elseif (true !== $validate) {
                 $validate = (array) $validate;
             }
             if (!is_bool($validate) && !empty($validate)) {
                 return pods_error($validate, $this);
             }
         }
         $value = PodsForm::pre_save($field_data['type'], $value, $params->id, $field, array_merge($field_data, $options), array_merge($fields, $object_fields), $pod, $params);
         $field_data['value'] = $value;
         if (isset($object_fields[$field])) {
             if ('taxonomy' == $object_fields[$field]['type']) {
                 $post_term_data[$field] = $value;
             } else {
                 $object_data[$field] = $value;
             }
         } else {
             $simple = 'pick' == $type && in_array(pods_var('pick_object', $field_data), $simple_tableless_objects);
             $simple = (bool) $this->do_hook('tableless_custom', $simple, $field_data, $field, $fields, $pod, $params);
             // Handle Simple Relationships
             if ($simple) {
                 if (!is_array($value)) {
                     $value = explode(',', $value);
                 }
                 $pick_limit = (int) pods_var_raw('pick_limit', $options, 0);
                 if ('single' == pods_var_raw('pick_format_type', $options)) {
                     $pick_limit = 1;
                 }
                 if ('custom-simple' == pods_var('pick_object', $field_data)) {
                     $custom = pods_var_raw('pick_custom', $options, '');
                     $custom = apply_filters('pods_form_ui_field_pick_custom_values', $custom, $field_data['name'], $value, array_merge($field_data, $options), $pod, $params->id);
                     if (empty($value) || empty($custom)) {
                         $value = '';
                     } elseif (!empty($custom)) {
                         if (!is_array($custom)) {
                             $custom = explode("\n", $custom);
                             $custom_values = array();
                             foreach ($custom as $c => $cv) {
                                 if (0 < strlen($cv)) {
                                     $custom_label = explode('|', $cv);
                                     if (!isset($custom_label[1])) {
                                         $custom_label[1] = $custom_label[0];
                                     }
                                     $custom_label[0] = trim((string) $custom_label[0]);
                                     $custom_label[1] = trim((string) $custom_label[1]);
                                     $custom_values[$custom_label[0]] = $custom_label[1];
                                 }
                             }
                         } else {
                             $custom_values = $custom;
                         }
                         $values = array();
                         foreach ($value as $k => $v) {
                             $v = pods_unsanitize($v);
                             if (isset($custom_values[$v])) {
                                 $values[$k] = $v;
                             }
                         }
                         $value = $values;
                     }
                 }
                 if (0 < $pick_limit && !empty($value)) {
                     $value = array_slice($value, 0, $pick_limit);
                 }
                 // Don't save an empty array, just make it an empty string
                 if (empty($value)) {
                     $value = '';
                 } elseif (is_array($value)) {
                     // If there's just one item, don't save as an array, save the string
                     if (1 == $pick_limit || 1 == count($value)) {
                         $value = implode('', $value);
                     } elseif ('table' == pods_var('storage', $pod)) {
                         $value = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($value, JSON_UNESCAPED_UNICODE) : json_encode($value);
                     }
                 }
             }
             // Prepare all table / meta data
             if (!in_array($type, $tableless_field_types) || $simple) {
                 if (in_array($type, $repeatable_field_types) && 1 == pods_var($type . '_repeatable', $field_data, 0)) {
                     // Don't save an empty array, just make it an empty string
                     if (empty($value)) {
                         $value = '';
                     } elseif (is_array($value)) {
                         // If there's just one item, don't save as an array, save the string
                         if (1 == count($value)) {
                             $value = implode('', $value);
                         } elseif ('table' == pods_var('storage', $pod)) {
                             $value = version_compare(PHP_VERSION, '5.4.0', '>=') ? json_encode($value, JSON_UNESCAPED_UNICODE) : json_encode($value);
                         }
                     }
                 }
                 $table_data[$field] = str_replace(array('{prefix}', '@wp_'), array('{/prefix/}', '{prefix}'), $value);
                 // Fix for pods_query
                 $table_formats[] = PodsForm::prepare($type, $options);
                 $object_meta[$field] = $value;
             } else {
                 // Convert values from a comma-separated string into an array
                 if (!is_array($value)) {
                     $value = explode(',', $value);
                 }
                 $rel_fields[$type][$field] = $value;
                 $rel_field_ids[] = $field_data['id'];
             }
         }
     }
     if ('post_type' == $pod['type']) {
         $post_type = $pod['name'];
         if (!empty($pod['object'])) {
             $post_type = $pod['object'];
         }
         $object_data['post_type'] = $post_type;
     }
     if (('meta' == $pod['storage'] || 'settings' == $pod['type']) && !in_array($pod['type'], array('taxonomy', 'pod', 'table', ''))) {
         if ($allow_custom_fields && !empty($custom_data)) {
             $object_meta = array_merge($custom_data, $object_meta);
         }
         $fields_to_send = array_flip(array_keys($object_meta));
         foreach ($fields_to_send as $field => $field_data) {
             if (isset($object_fields[$field])) {
                 $field_data = $object_fields[$field];
             } elseif (isset($fields[$field])) {
                 $field_data = $fields[$field];
             } else {
                 unset($fields_to_send[$field]);
             }
             $fields_to_send[$field] = $field_data;
         }
         $params->id = $this->save_wp_object($object_type, $object_data, $object_meta, false, true, $fields_to_send);
         if (!empty($params->id) && 'settings' == $object_type) {
             $params->id = $pod['id'];
         }
     } else {
         if (!in_array($pod['type'], array('taxonomy', 'pod', 'table', ''))) {
             $params->id = $this->save_wp_object($object_type, $object_data, array(), false, true);
         } elseif ('taxonomy' == $pod['type']) {
             $term = pods_v($object_fields['name']['name'], $object_data, '', null, true);
             if (!isset($term_data)) {
                 $term_data = array();
             }
             if (empty($params->id) || !empty($term_data)) {
                 $taxonomy = $pod['name'];
                 if (!empty($pod['object'])) {
                     $taxonomy = $pod['object'];
                 }
                 $params->id = $this->save_term($params->id, $term, $taxonomy, $term_data, true);
             }
         }
         if ('table' == $pod['storage']) {
             // Every row should have an id set here, otherwise Pods with nothing
             // but relationship fields won't get properly ID'd
             if (empty($params->id)) {
                 $params->id = 0;
             }
             $table_data = array('id' => $params->id) + $table_data;
             array_unshift($table_formats, '%d');
             if (!empty($table_data)) {
                 $sql = pods_data()->insert_on_duplicate("@wp_pods_{$params->pod}", $table_data, $table_formats);
                 $id = pods_query($sql, 'Cannot add/save table row');
                 if (empty($params->id)) {
                     $params->id = $id;
                 }
             }
         }
     }
     $params->id = (int) $params->id;
     // Save terms for taxonomies associated to a post type
     if (0 < $params->id && 'post_type' == $pod['type'] && !empty($post_term_data)) {
         foreach ($post_term_data as $post_taxonomy => $post_terms) {
             $post_terms = (array) $post_terms;
             foreach ($post_terms as $k => $v) {
                 if (!preg_match('/[^0-9]/', $v)) {
                     $v = (int) $v;
                 }
                 $post_terms[$k] = $v;
             }
             wp_set_object_terms($params->id, $post_terms, $post_taxonomy);
         }
     }
     $no_conflict = pods_no_conflict_check($pod['type']);
     if (!$no_conflict) {
         pods_no_conflict_on($pod['type']);
     }
     // Save relationship / file data
     if (!empty($rel_fields)) {
         foreach ($rel_fields as $type => $data) {
             // Only handle tableless fields
             if (!in_array($type, $tableless_field_types)) {
                 continue;
             }
             foreach ($data as $field => $values) {
                 $pick_val = pods_var('pick_val', $fields[$field]);
                 if ('table' == pods_var('pick_object', $fields[$field])) {
                     $pick_val = pods_var('pick_table', $fields[$field]['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;
                     }
                 }
                 $fields[$field]['options']['table_info'] = pods_api()->get_table_info(pods_var('pick_object', $fields[$field]), $pick_val, null, null, $fields[$field]['options']);
                 if (isset($fields[$field]['options']['table_info']['pod']) && !empty($fields[$field]['options']['table_info']['pod']) && isset($fields[$field]['options']['table_info']['pod']['name'])) {
                     $search_data = pods($fields[$field]['options']['table_info']['pod']['name']);
                     $data_mode = 'pods';
                 } else {
                     $search_data = pods_data();
                     $search_data->table($fields[$field]['options']['table_info']);
                     $data_mode = 'data';
                 }
                 $find_rel_params = array('select' => "`t`.`{$search_data->field_id}`", 'where' => "`t`.`{$search_data->field_slug}` = %s OR `t`.`{$search_data->field_index}` = %s", 'limit' => 1, 'pagination' => false, 'search' => false);
                 if (empty($search_data->field_slug) && !empty($search_data->field_index)) {
                     $find_rel_params['where'] = "`t`.`{$search_data->field_index}` = %s";
                 } elseif (empty($search_data->field_slug) && empty($search_data->field_index)) {
                     $find_rel_params = false;
                 }
                 $related_limit = (int) pods_var_raw($type . '_limit', $fields[$field]['options'], 0);
                 if ('single' == pods_var_raw($type . '_format_type', $fields[$field]['options'])) {
                     $related_limit = 1;
                 }
                 // Enforce integers / unique values for IDs
                 $value_ids = array();
                 $is_file_field = in_array($type, PodsForm::file_field_types());
                 $is_taggable = in_array($type, PodsForm::tableless_field_types()) && 1 == pods_v($type . '_taggable', $fields[$field]['options']);
                 // @todo Handle simple relationships eventually
                 foreach ($values as $v) {
                     if (!empty($v)) {
                         if (!is_array($v)) {
                             if (!preg_match('/[^0-9]/', $v)) {
                                 $v = (int) $v;
                             } elseif ($is_file_field) {
                                 // Get ID from GUID
                                 $v = pods_image_id_from_field($v);
                                 // If file not found, add it
                                 if (empty($v)) {
                                     $v = pods_attachment_import($v);
                                 }
                             } else {
                                 $v_data = false;
                                 if (false !== $find_rel_params) {
                                     $rel_params = $find_rel_params;
                                     $rel_params['where'] = $wpdb->prepare($rel_params['where'], array($v, $v));
                                     $search_data->select($rel_params);
                                     $v_data = $search_data->fetch($v);
                                 }
                                 if (!empty($v_data) && isset($v_data[$search_data->field_id])) {
                                     $v = (int) $v_data[$search_data->field_id];
                                 } elseif ($is_taggable && 'pods' == $data_mode) {
                                     $tag_data = array($search_data->field_index => $v);
                                     if ('post_type' == $search_data->pod_data['type']) {
                                         $tag_data['post_status'] = 'publish';
                                     }
                                     /**
                                      * Filter for changing tag before adding new item.
                                      *
                                      * @param array $tag_data Fields for creating new item.
                                      * @param int $v Field ID of tag.
                                      * @param obj $search_data Search object for tag.
                                      * @param string $field Table info for field.
                                      * @param array	$pieces Field array.
                                      *
                                      * @since 2.3.19
                                      */
                                     $tag_data = apply_filters('pods_api_save_pod_item_taggable_data', $tag_data, $v, $search_data, $field, compact($pieces));
                                     // Save $v to a new item on related object
                                     $v = $search_data->add($tag_data);
                                     // @todo Support non-Pods for tagging
                                 }
                             }
                         } elseif ($is_file_field && isset($v['id'])) {
                             $v = (int) $v['id'];
                         } else {
                             continue;
                         }
                         if (!empty($v) && !in_array($v, $value_ids)) {
                             $value_ids[] = $v;
                         }
                     }
                 }
                 $value_ids = array_unique(array_filter($value_ids));
                 // Limit values
                 if (0 < $related_limit && !empty($value_ids)) {
                     $value_ids = array_slice($value_ids, 0, $related_limit);
                 }
                 // Get current values
                 if ('pick' == $type && isset(PodsField_Pick::$related_data[$fields[$field]['id']]) && isset(PodsField_Pick::$related_data[$fields[$field]['id']]['current_ids'])) {
                     $related_ids = PodsField_Pick::$related_data[$fields[$field]['id']]['current_ids'];
                 } else {
                     $related_ids = $this->lookup_related_items($fields[$field]['id'], $pod['id'], $params->id, $fields[$field], $pod);
                 }
                 // Get ids to remove
                 $remove_ids = array_diff($related_ids, $value_ids);
                 // Delete relationships
                 if (!empty($remove_ids)) {
                     $this->delete_relationships($params->id, $remove_ids, $pod, $fields[$field]);
                 }
                 // Save relationships
                 if (!empty($value_ids)) {
                     $this->save_relationships($params->id, $value_ids, $pod, $fields[$field]);
                 }
                 // Run save function for field type (where needed)
                 PodsForm::save($type, $values, $params->id, $field, array_merge($fields[$field], $fields[$field]['options']), array_merge($fields, $object_fields), $pod, $params);
             }
             // Unset data no longer needed
             if ('pick' == $type) {
                 foreach ($data as $field => $values) {
                     if (isset(PodsField_Pick::$related_data[$fields[$field]['id']])) {
                         unset(PodsField_Pick::$related_data[PodsField_Pick::$related_data[$fields[$field]['id']]['related_field']['id']]);
                         unset(PodsField_Pick::$related_data[$fields[$field]['id']]);
                     }
                 }
             }
         }
     }
     if (!$no_conflict) {
         pods_no_conflict_off($pod['type']);
     }
     if (false === $bypass_helpers) {
         $pieces = compact($pieces);
         // Plugin hooks
         $this->do_hook('post_save_pod_item', $pieces, $is_new_item, $params->id);
         $this->do_hook("post_save_pod_item_{$params->pod}", $pieces, $is_new_item, $params->id);
         if ($is_new_item) {
             $this->do_hook('post_create_pod_item', $pieces, $params->id);
             $this->do_hook("post_create_pod_item_{$params->pod}", $pieces, $params->id);
         } else {
             $this->do_hook('post_edit_pod_item', $pieces, $params->id);
             $this->do_hook("post_edit_pod_item_{$params->pod}", $pieces, $params->id);
         }
         // Call any post-save helpers (if not bypassed)
         if (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL) {
             if (!empty($post_save_helpers)) {
                 pods_deprecated(sprintf(__('Post-save helpers are deprecated, use the action pods_post_save_pod_item_%s instead', 'pods'), $params->pod), '2.0');
                 foreach ($post_save_helpers as $helper) {
                     $helper = $this->load_helper(array('name' => $helper));
                     if (false !== $helper && (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL)) {
                         eval('?>' . $helper['code']);
                     }
                 }
             }
         }
     }
     // Clear cache
     pods_cache_clear($params->id, 'pods_items_' . $pod['name']);
     if ($params->clear_slug_cache && !empty($pod['field_slug'])) {
         $slug = pods($pod['name'], $params->id)->field($pod['field_slug']);
         if (0 < strlen($slug)) {
             pods_cache_clear($slug, 'pods_items_' . $pod['name']);
         }
     }
     // Clear WP meta cache
     if (in_array($pod['type'], array('post_type', 'taxonomy', 'user', 'comment'))) {
         $meta_type = $pod['type'];
         if ('post_type' == $meta_type) {
             $meta_type = 'post';
         }
         wp_cache_delete($params->id, $meta_type . '_meta');
         wp_cache_delete($params->id, 'pods_' . $meta_type . '_meta');
     }
     // Success! Return the id
     return $params->id;
 }
 /**
  * Reorder data
  */
 public function reorder()
 {
     // loop through order
     $order = (array) pods_var_raw('order', 'post', array(), null, true);
     $params = array('pod' => $this->pod->pod, 'field' => $this->reorder['on'], 'order' => $order);
     $reorder = pods_api()->reorder_pod_item($params);
     if ($reorder) {
         $this->message(sprintf(__("<strong>Success!</strong> %s reordered successfully.", 'pods'), $this->items));
     } else {
         $this->error(sprintf(__("<strong>Error:</strong> %s has not been reordered.", 'pods'), $this->items));
     }
 }
Exemple #10
0
 /**
  * Add meta boxes to the page
  *
  * @since 2.0
  */
 public function add_meta_boxes()
 {
     $pod = array('name' => $this->object_type, 'type' => 'post_type');
     if (isset(PodsMeta::$post_types[$pod['name']])) {
         return;
     }
     if (!function_exists('get_page_templates')) {
         include_once ABSPATH . 'wp-admin/includes/theme.php';
     }
     $page_templates = apply_filters('pods_page_templates', get_page_templates());
     $page_templates[__('-- Page Template --', 'pods')] = '';
     $page_templates[__('Custom (uses only Pod Page content)', 'pods')] = '_custom';
     if (!in_array('pods.php', $page_templates) && locate_template(array('pods.php', false))) {
         $page_templates[__('Pods (Pods Default)', 'pods')] = 'pods.php';
     }
     if (!in_array('page.php', $page_templates) && locate_template(array('page.php', false))) {
         $page_templates[__('Page (WP Default)', 'pods')] = 'page.php';
     }
     if (!in_array('index.php', $page_templates) && locate_template(array('index.php', false))) {
         $page_templates[__('Index (WP Fallback)', 'pods')] = 'index.php';
     }
     ksort($page_templates);
     $page_templates = array_flip($page_templates);
     $fields = array(array('name' => 'page_title', 'label' => __('Page Title', 'pods'), 'type' => 'text'), array('name' => 'code', 'label' => __('Page Code', 'pods'), 'type' => 'code', 'attributes' => array('id' => 'content'), 'label_options' => array('attributes' => array('for' => 'content'))), array('name' => 'precode', 'label' => __('Page Precode', 'pods'), 'type' => 'code', 'help' => __('Precode will run before your theme outputs the page. It is expected that this value will be a block of PHP. You must open the PHP tag here, as we do not open it for you by default.', 'pods')), array('name' => 'page_template', 'label' => __('Page Template', 'pods'), 'type' => 'pick', 'data' => $page_templates));
     pods_group_add($pod, __('Page', 'pods'), $fields, 'normal', 'high');
     $associated_pods = array(0 => __('-- Select a Pod --', 'pods'));
     $all_pods = pods_api()->load_pods(array('names' => true));
     if (!empty($all_pods)) {
         foreach ($all_pods as $pod_name => $pod_label) {
             $associated_pods[$pod_name] = $pod_label . ' (' . $pod_name . ')';
         }
     } else {
         $associated_pods[0] = __('None Found', 'pods');
     }
     $fields = array(array('name' => 'pod', 'label' => __('Associated Pod', 'pods'), 'default' => 0, 'type' => 'pick', 'data' => $associated_pods, 'dependency' => true), array('name' => 'pod_slug', 'label' => __('Wildcard Slug', 'pods'), 'help' => __('Setting the Wildcard Slug is an easy way to setup a detail page. You can use the special tag {@url.2} to match the *third* level of the URL of a Pod Page named "first/second/*" part of the pod page. This is functionally the same as using pods_var( 2, "url" ) in PHP.', 'pods'), 'type' => 'text', 'excludes-on' => array('pod' => 0)));
     pods_group_add($pod, __('Pod Association', 'pods'), $fields, 'normal', 'high');
     $fields = array(array('name' => 'admin_only', 'label' => __('Restrict access to Admins?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'restrict_role', 'label' => __('Restrict access by Role?', 'pods'), 'help' => array(__('<h6>Roles</h6> Roles are assigned to users to provide them access to specific functionality in WordPress. Please see the Roles and Capabilities component in Pods for an easy tool to add your own roles and edit existing ones.', 'pods'), 'http://codex.wordpress.org/Roles_and_Capabilities'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'roles_allowed', 'label' => __('Role(s) Allowed', 'pods'), 'type' => 'pick', 'pick_object' => 'role', 'pick_format_type' => 'multi', 'pick_format_multi' => 'autocomplete', 'pick_ajax' => false, 'default' => '', 'depends-on' => array('restrict_role' => true)), array('name' => 'restrict_capability', 'label' => __('Restrict access by Capability?', 'pods'), 'help' => array(__('<h6>Capabilities</h6> Capabilities denote access to specific functionality in WordPress, and are assigned to specific User Roles. Please see the Roles and Capabilities component in Pods for an easy tool to add your own capabilities and roles.', 'pods'), 'http://codex.wordpress.org/Roles_and_Capabilities'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'capability_allowed', 'label' => __('Capability Allowed', 'pods'), 'type' => 'pick', 'pick_object' => 'capability', 'pick_format_type' => 'multi', 'pick_format_multi' => 'autocomplete', 'pick_ajax' => false, 'default' => '', 'depends-on' => array('restrict_capability' => true)), array('name' => 'restrict_redirect', 'label' => __('Redirect if Restricted?', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true), array('name' => 'restrict_redirect_login', 'label' => __('Redirect to WP Login page', 'pods'), 'default' => 0, 'type' => 'boolean', 'dependency' => true, 'depends-on' => array('restrict_redirect' => true)), array('name' => 'restrict_redirect_url', 'label' => __('Redirect to a Custom URL', 'pods'), 'default' => '', 'type' => 'text', 'depends-on' => array('restrict_redirect' => true, 'restrict_redirect_login' => false)));
     pods_group_add($pod, __('Restrict Access', 'pods'), $fields, 'normal', 'high');
 }
<?php

$all_pods = pods_api()->load_pods();
// or $api = pods_api(); and then $api->load_pods();
foreach ($all_pods as $pod) {
    echo '<p>' . $pod['name '] . ' is awesome</p>' . "\n";
}
 /**
  * Get titles of all Pods Templates
  *
  * @return string[] Array of template names
  *
  * @since 2.4.5
  */
 public function get_template_titles()
 {
     static $template_titles;
     if (empty($template_titles)) {
         $all_templates = (array) pods_api()->load_templates(array());
         $template_titles = array();
         foreach ($all_templates as $template) {
             $template_titles[] = $template['name'];
         }
     }
     return $template_titles;
 }
Exemple #13
0
 /**
  * @param $import
  * @param bool $output
  */
 public function heres_the_beef($import, $output = true)
 {
     global $wpdb;
     $api = pods_api();
     for ($i = 0; $i < 40000; $i++) {
         echo "  \t";
         // extra spaces
     }
     $default_data = array('pod' => null, 'table' => null, 'reset' => null, 'update_on' => null, 'where' => null, 'fields' => array(), 'row_filter' => null, 'pre_save' => null, 'post_save' => null, 'sql' => null, 'sort' => null, 'limit' => null, 'page' => null, 'output' => null, 'page_var' => 'ipg', 'bypass_helpers' => false);
     $default_field_data = array('field' => null, 'filter' => null);
     if (!is_array($import)) {
         $import = array($import);
     } elseif (empty($import)) {
         die('<h1 style="color:red;font-weight:bold;">ERROR: No imports configured</h1>');
     }
     $import_counter = 0;
     $total_imports = count($import);
     $paginated = false;
     $avg_time = -1;
     $total_time = 0;
     $counter = 0;
     $avg_unit = 100;
     $avg_counter = 0;
     foreach ($import as $datatype => $data) {
         $import_counter++;
         flush();
         @ob_end_flush();
         usleep(50000);
         if (!is_array($data)) {
             $datatype = $data;
             $data = array('table' => $data);
         }
         if (isset($data[0])) {
             $data = array('table' => $data[0]);
         }
         $data = array_merge($default_data, $data);
         if (null === $data['pod']) {
             $data['pod'] = array('name' => $datatype);
         }
         if (false !== $output) {
             echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <em>" . $data['pod']['name'] . "</em> - <strong>Loading Pod: " . $data['pod']['name'] . "</strong>\n";
         }
         if (2 > count($data['pod'])) {
             $data['pod'] = $api->load_pod(array('name' => $data['pod']['name']));
         }
         if (empty($data['pod']['fields'])) {
             continue;
         }
         if (null === $data['table']) {
             $data['table'] = $data['pod']['name'];
         }
         if ($data['reset'] === true) {
             if (false !== $output) {
                 echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong style='color:blue;'>Resetting Pod: " . $data['pod']['name'] . "</strong>\n";
             }
             $api->reset_pod(array('id' => $data['pod']['id'], 'name' => $data['pod']['name']));
         }
         if (null === $data['sort'] && null !== $data['update_on'] && isset($data['fields'][$data['update_on']])) {
             if (isset($data['fields'][$data['update_on']]['field'])) {
                 $data['sort'] = $data['fields'][$data['update_on']]['field'];
             } else {
                 $data['sort'] = $data['update_on'];
             }
         }
         $page = 1;
         if (false !== $data['page_var'] && isset($_GET[$data['page_var']])) {
             $page = absval($_GET[$data['page_var']]);
         }
         if (null === $data['sql']) {
             $data['sql'] = "SELECT * FROM {$data['table']}" . (null !== $data['where'] ? " WHERE {$data['where']}" : '') . (null !== $data['sort'] ? " ORDER BY {$data['sort']}" : '') . (null !== $data['limit'] ? " LIMIT " . (1 < $page ? ($page - 1) * $data['limit'] . ',' : '') . "{$data['limit']}" : '');
         }
         if (false !== $output) {
             echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Getting Results: " . $data['pod']['name'] . "\n";
         }
         if (false !== $output) {
             echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Using Query: <small><code>" . $data['sql'] . "</code></small>\n";
         }
         $result = $wpdb->get_results($data['sql'], ARRAY_A);
         if (false !== $output) {
             echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Results Found: " . count($result) . "\n";
         }
         $avg_time = -1;
         $total_time = 0;
         $counter = 0;
         $avg_unit = 100;
         $avg_counter = 0;
         $result_count = count($result);
         $paginated = false;
         if (false !== $data['page_var'] && $result_count == $data['limit']) {
             $paginated = "<input type=\"button\" onclick=\"document.location=\\'" . pods_ui_var_update(array($data['page_var'] => $page + 1), false, false) . "\\';\" value=\"  Continue Import &raquo;  \" />";
         }
         if ($result_count < $avg_unit && 5 < $result_count) {
             $avg_unit = number_format($result_count / 5, 0, '', '');
         } elseif (2000 < $result_count && 10 < count($data['pod']['fields'])) {
             $avg_unit = 40;
         }
         $data['count'] = $result_count;
         timer_start();
         if (false !== $output && 1 == $import_counter) {
             echo "<div style='width:50%;background-color:navy;padding:10px 10px 30px 10px;color:#FFF;position:absolute;top:10px;left:25%;text-align:center;'><p id='progress_status' align='center'>" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Running Importer..</p><br /><small>This will automatically update every " . $avg_unit . " rows</small></div>\n";
         }
         foreach ($result as $k => $row) {
             flush();
             @ob_end_flush();
             usleep(50000);
             if (false !== $output) {
                 echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Processing Row #" . ($k + 1) . "\n";
             }
             if (null !== $data['row_filter'] && function_exists($data['row_filter'])) {
                 if (false !== $output) {
                     echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Filtering <strong>" . $data['row_filter'] . "</strong> on Row #" . ($k + 1) . "\n";
                 }
                 $row = $data['row_filter']($row, $data);
             }
             if (!is_array($row)) {
                 continue;
             }
             $params = array('datatype' => $data['pod']['name'], 'columns' => array(), 'bypass_helpers' => $data['bypass_helpers']);
             foreach ($data['pod']['fields'] as $fk => $field_info) {
                 $field = $field_info['name'];
                 if (!empty($data['fields']) && !isset($data['fields'][$field]) && !in_array($field, $data['fields'])) {
                     continue;
                 }
                 if (isset($data['fields'][$field])) {
                     if (is_array($data['fields'][$field])) {
                         $field_data = $data['fields'][$field];
                     } else {
                         $field_data = array('field' => $data['fields'][$field]);
                     }
                 } else {
                     $field_data = array();
                 }
                 if (!is_array($field_data)) {
                     $field = $field_data;
                     $field_data = array();
                 }
                 $field_data = array_merge($default_field_data, $field_data);
                 if (null === $field_data['field']) {
                     $field_data['field'] = $field;
                 }
                 $data['fields'][$field] = $field_data;
                 $value = '';
                 if (isset($row[$field_data['field']])) {
                     $value = $row[$field_data['field']];
                 }
                 if (null !== $field_data['filter']) {
                     if (function_exists($field_data['filter'])) {
                         if (false !== $output) {
                             echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Filtering <strong>" . $field_data['filter'] . "</strong> on Field: " . $field . "\n";
                         }
                         $value = $field_data['filter']($value, $row, $data);
                     } else {
                         $value = '';
                     }
                 }
                 if (1 > strlen($value) && 1 == $field_info['required']) {
                     die('<h1 style="color:red;font-weight:bold;">ERROR: Field Required for <strong>' . $field . '</strong></h1>');
                 }
                 $params['columns'][$field] = $value;
                 unset($value);
                 unset($field_data);
                 unset($field_info);
                 unset($fk);
             }
             if (empty($params['columns'])) {
                 continue;
             }
             $params['columns'] = pods_sanitize($params['columns']);
             if (null !== $data['update_on'] && isset($params['columns'][$data['update_on']])) {
                 if (false !== $output) {
                     echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Checking for Existing Item\n";
                 }
                 $check = new Pod($data['pod']['name']);
                 $check->findRecords(array('orderby' => 't.id', 'limit' => 1, 'where' => "t.{$data['update_on']} = '{$params['columns'][$data['update_on']]}'", 'search' => false, 'page' => 1));
                 if (0 < $check->getTotalRows()) {
                     $check->fetchRecord();
                     $params['tbl_row_id'] = $check->get_field('id');
                     $params['pod_id'] = $check->get_pod_id();
                     if (false !== $output) {
                         echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Found Existing Item w/ ID: " . $params['tbl_row_id'] . "\n";
                     }
                     unset($check);
                 }
                 if (!isset($params['tbl_row_id']) && false !== $output) {
                     echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Existing item not found - Creating New\n";
                 }
             }
             if (null !== $data['pre_save'] && function_exists($data['pre_save'])) {
                 if (false !== $output) {
                     echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Running Pre Save <strong>" . $data['pre_save'] . "</strong> on " . $data['pod']['name'] . "\n";
                 }
                 $params = $data['pre_save']($params, $row, $data);
             }
             $id = $api->save_pod_item($params);
             if (false !== $output) {
                 echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong>Saved Row #" . ($k + 1) . " w/ ID: " . $id . "</strong>\n";
             }
             $params['tbl_row_id'] = $id;
             if (null !== $data['post_save'] && function_exists($data['post_save'])) {
                 if (false !== $output) {
                     echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Running Post Save <strong>" . $data['post_save'] . "</strong> on " . $data['pod']['name'] . "\n";
                 }
                 $data['post_save']($params, $row, $data);
             }
             unset($params);
             unset($result[$k]);
             unset($row);
             wp_cache_flush();
             $wpdb->queries = array();
             $avg_counter++;
             $counter++;
             if ($avg_counter == $avg_unit && false !== $output) {
                 $avg_counter = 0;
                 $avg_time = timer_stop(0, 10);
                 $total_time += $avg_time;
                 $rows_left = $result_count - $counter;
                 $estimated_time_left = $total_time / $counter * $rows_left / 60;
                 $percent_complete = 100 - $rows_left * 100 / $result_count;
                 echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em><br /><strong>" . $percent_complete . "% Complete</strong><br /><strong>Estimated Time Left:</strong> " . $estimated_time_left . " minute(s) or " . $estimated_time_left / 60 . " hours(s)<br /><strong>Time Spent:</strong> " . $total_time / 60 . " minute(s)<br /><strong>Rows Done:</strong> " . ($result_count - $rows_left) . "/" . $result_count . "<br /><strong>Rows Left:</strong> " . $rows_left . "';</script>\n";
                 echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong>Updated Status:</strong> " . $percent_complete . "% Complete</strong>\n";
             }
         }
         if (false !== $output) {
             $avg_counter = 0;
             $avg_time = timer_stop(0, 10);
             $total_time += $avg_time;
             $rows_left = $result_count - $counter;
             $estimated_time_left = $total_time / $counter * $rows_left / 60;
             $percent_complete = 100 - $rows_left * 100 / $result_count;
             echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em><br /><strong style=\\'color:green;\\'>100% Complete</strong><br /><br /><strong>Time Spent:</strong> " . $total_time / 60 . " minute(s)<br /><strong>Rows Imported:</strong> " . $result_count . (false !== $paginated ? "<br /><br />" . $paginated : '') . "';</script>\n";
             echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong style='color:green;'>Done Importing: " . $data['pod']['name'] . "</strong>\n";
         }
         unset($result);
         unset($import[$datatype]);
         unset($datatype);
         unset($data);
         wp_cache_flush();
         $wpdb->queries = array();
     }
     if (false !== $output) {
         $avg_counter = 0;
         $avg_time = timer_stop(0, 10);
         $total_time += $avg_time;
         $rows_left = $result_count - $counter;
         echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date('Y-m-d h:i:sa') . " - <strong style=\\'color:green;\\'>Import Complete</strong><br /><br /><strong>Time Spent:</strong> " . $total_time / 60 . " minute(s)<br /><strong>Rows Imported:</strong> " . $result_count . (false !== $paginated ? "<br /><br />" . $paginated : '') . "';</script>\n";
         echo "<br />" . date('Y-m-d h:i:sa') . " - <strong style='color:green;'>Import Complete</strong>\n";
     }
 }
Exemple #14
0
 /**
  * Handle plupload AJAX
  *
  * @since 2.3
  */
 public function admin_ajax_upload()
 {
     if (false === headers_sent()) {
         if ('' == session_id()) {
             @session_start();
         }
     }
     // Sanitize input
     $params = stripslashes_deep((array) $_POST);
     foreach ($params as $key => $value) {
         if ('action' == $key) {
             continue;
         }
         unset($params[$key]);
         $params[str_replace('_podsfix_', '', $key)] = $value;
     }
     $params = (object) $params;
     $methods = array('upload');
     if (!isset($params->method) || !in_array($params->method, $methods) || !isset($params->pod) || !isset($params->field) || !isset($params->uri) || empty($params->uri)) {
         pods_error('Invalid AJAX request', PodsInit::$admin);
     } elseif (!empty($params->pod) && empty($params->field)) {
         pods_error('Invalid AJAX request', PodsInit::$admin);
     } elseif (empty($params->pod) && !current_user_can('upload_files')) {
         pods_error('Invalid AJAX request', PodsInit::$admin);
     }
     // Flash often fails to send cookies with the POST or upload, so we need to pass it in GET or POST instead
     if (is_ssl() && empty($_COOKIE[SECURE_AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) {
         $_COOKIE[SECURE_AUTH_COOKIE] = $_REQUEST['auth_cookie'];
     } elseif (empty($_COOKIE[AUTH_COOKIE]) && !empty($_REQUEST['auth_cookie'])) {
         $_COOKIE[AUTH_COOKIE] = $_REQUEST['auth_cookie'];
     }
     if (empty($_COOKIE[LOGGED_IN_COOKIE]) && !empty($_REQUEST['logged_in_cookie'])) {
         $_COOKIE[LOGGED_IN_COOKIE] = $_REQUEST['logged_in_cookie'];
     }
     global $current_user;
     unset($current_user);
     /**
      * Access Checking
      */
     $upload_disabled = false;
     if (defined('PODS_DISABLE_FILE_UPLOAD') && true === PODS_DISABLE_FILE_UPLOAD) {
         $upload_disabled = true;
     } elseif (defined('PODS_UPLOAD_REQUIRE_LOGIN') && is_bool(PODS_UPLOAD_REQUIRE_LOGIN) && true === PODS_UPLOAD_REQUIRE_LOGIN && !is_user_logged_in()) {
         $upload_disabled = true;
     } elseif (defined('PODS_UPLOAD_REQUIRE_LOGIN') && !is_bool(PODS_UPLOAD_REQUIRE_LOGIN) && (!is_user_logged_in() || !current_user_can(PODS_UPLOAD_REQUIRE_LOGIN))) {
         $upload_disabled = true;
     }
     $uid = @session_id();
     if (is_user_logged_in()) {
         $uid = 'user_' . get_current_user_id();
     }
     $nonce_check = 'pods_upload_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
     if (true === $upload_disabled || !isset($params->_wpnonce) || false === wp_verify_nonce($params->_wpnonce, $nonce_check)) {
         pods_error(__('Unauthorized request', 'pods'), PodsInit::$admin);
     }
     $pod = array();
     $field = array('type' => 'file', 'options' => array());
     $api = pods_api();
     if (!empty($params->pod)) {
         $pod = $api->load_pod(array('id' => (int) $params->pod));
         $field = $api->load_field(array('id' => (int) $params->field));
         if (empty($pod) || empty($field) || $pod['id'] != $field['pod_id'] || !isset($pod['fields'][$field['name']])) {
             pods_error(__('Invalid field request', 'pods'), PodsInit::$admin);
         }
         if (!in_array($field['type'], PodsForm::file_field_types())) {
             pods_error(__('Invalid field', 'pods'), PodsInit::$admin);
         }
     }
     $method = $params->method;
     // Cleaning up $params
     unset($params->action);
     unset($params->method);
     unset($params->_wpnonce);
     $params->post_id = pods_var('post_id', $params, 0, null, true);
     /**
      * Upload a new file (advanced - returns URL and ID)
      */
     if ('upload' == $method) {
         $file = $_FILES['Filedata'];
         $limit_size = pods_var($field['type'] . '_restrict_filesize', $field['options']);
         if (!empty($limit_size)) {
             if (false !== stripos($limit_size, 'MB')) {
                 $limit_size = (double) trim(str_ireplace('MB', '', $limit_size));
                 $limit_size = $limit_size * 1025 * 1025;
                 // convert to KB to B
             } elseif (false !== stripos($limit_size, 'KB')) {
                 $limit_size = (double) trim(str_ireplace('KB', '', $limit_size));
                 $limit_size = $limit_size * 1025 * 1025;
                 // convert to B
             } elseif (false !== stripos($limit_size, 'GB')) {
                 $limit_size = (double) trim(str_ireplace('GB', '', $limit_size));
                 $limit_size = $limit_size * 1025 * 1025 * 1025;
                 // convert to MB to KB to B
             } elseif (false !== stripos($limit_size, 'B')) {
                 $limit_size = (double) trim(str_ireplace('B', '', $limit_size));
             } else {
                 $limit_size = wp_max_upload_size();
             }
             if (0 < $limit_size && $limit_size < $file['size']) {
                 $error = __('File size too large, max size is %s', 'pods');
                 $error = sprintf($error, pods_var($field['type'] . '_restrict_filesize', $field['options']));
                 pods_error('<div style="color:#FF0000">Error: ' . $error . '</div>');
             }
         }
         $limit_file_type = pods_var($field['type'] . '_type', $field['options'], 'images');
         if ('images' == $limit_file_type) {
             $limit_types = 'jpg,png,gif';
         } elseif ('video' == $limit_file_type) {
             $limit_types = 'mpg,mov,flv,mp4';
         } elseif ('audio' == $limit_file_type) {
             $limit_types = 'mp3,m4a,wav,wma';
         } elseif ('text' == $limit_file_type) {
             $limit_types = 'txt,rtx,csv,tsv';
         } elseif ('any' == $limit_file_type) {
             $limit_types = '';
         } else {
             $limit_types = pods_var($field['type'] . '_allowed_extensions', $field['options'], '', null, true);
         }
         $limit_types = trim(str_replace(array(' ', '.', "\n", "\t", ';'), array('', ',', ',', ','), $limit_types), ',');
         if (pods_version_check('wp', '3.5')) {
             $mime_types = wp_get_mime_types();
             if (in_array($limit_file_type, array('images', 'audio', 'video'))) {
                 $new_limit_types = array();
                 foreach ($mime_types as $type => $mime) {
                     if (0 === strpos($mime, $limit_file_type)) {
                         $type = explode('|', $type);
                         $new_limit_types = array_merge($new_limit_types, $type);
                     }
                 }
                 if (!empty($new_limit_types)) {
                     $limit_types = implode(',', $new_limit_types);
                 }
             } elseif ('any' != $limit_file_type) {
                 $new_limit_types = array();
                 $limit_types = explode(',', $limit_types);
                 foreach ($limit_types as $k => $limit_type) {
                     $found = false;
                     foreach ($mime_types as $type => $mime) {
                         if (0 === strpos($mime, $limit_type)) {
                             $type = explode('|', $type);
                             foreach ($type as $t) {
                                 if (!in_array($t, $new_limit_types)) {
                                     $new_limit_types[] = $t;
                                 }
                             }
                             $found = true;
                         }
                     }
                     if (!$found) {
                         $new_limit_types[] = $limit_type;
                     }
                 }
                 if (!empty($new_limit_types)) {
                     $limit_types = implode(',', $new_limit_types);
                 }
             }
         }
         $limit_types = explode(',', $limit_types);
         $limit_types = array_filter(array_unique($limit_types));
         if (!empty($limit_types)) {
             $ok = false;
             foreach ($limit_types as $limit_type) {
                 $limit_type = '.' . trim($limit_type, ' .');
                 $pos = strlen($file['name']) - strlen($limit_type);
                 if ($pos === stripos($file['name'], $limit_type)) {
                     $ok = true;
                     break;
                 }
             }
             if (false === $ok) {
                 $error = __('File type not allowed, please use one of the following: %s', 'pods');
                 $error = sprintf($error, '.' . implode(', .', $limit_types));
                 pods_error('<div style="color:#FF0000">Error: ' . $error . '</div>');
             }
         }
         $custom_handler = apply_filters('pods_upload_handle', null, 'Filedata', $params->post_id, $params);
         if (null === $custom_handler) {
             $attachment_id = media_handle_upload('Filedata', $params->post_id);
             if (is_object($attachment_id)) {
                 $errors = array();
                 foreach ($attachment_id->errors['upload_error'] as $error_code => $error_message) {
                     $errors[] = '[' . $error_code . '] ' . $error_message;
                 }
                 pods_error('<div style="color:#FF0000">Error: ' . implode('</div><div>', $errors) . '</div>');
             } else {
                 $attachment = get_post($attachment_id, ARRAY_A);
                 $attachment['filename'] = basename($attachment['guid']);
                 $thumb = wp_get_attachment_image_src($attachment['ID'], 'thumbnail', true);
                 $attachment['thumbnail'] = $thumb[0];
                 $attachment = apply_filters('pods_upload_attachment', $attachment, $params->post_id);
                 wp_send_json($attachment);
             }
         }
     }
     die;
     // KBAI!
 }
Exemple #15
0
 /**
  * Constructor - Pods Framework core
  *
  * @param string $pod The pod name
  * @param mixed $id (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
  *
  * @return \Pods
  *
  * @license http://www.gnu.org/licenses/gpl-2.0.html
  * @since 1.0.0
  * @link http://pods.io/docs/pods/
  */
 public function __construct($pod = null, $id = null)
 {
     if (null === $pod) {
         $queried_object = get_queried_object();
         if ($queried_object) {
             $id_lookup = true;
             // Post Type Singular
             if (isset($queried_object->post_type)) {
                 $pod = $queried_object->post_type;
             } elseif (isset($queried_object->taxonomy)) {
                 $pod = $queried_object->taxonomy;
             } elseif (isset($queried_object->user_login)) {
                 $pod = 'user';
             } elseif (isset($queried_object->public) && isset($queried_object->name)) {
                 $pod = $queried_object->name;
                 $id_lookup = false;
             }
             if (null === $id && $id_lookup) {
                 $id = get_queried_object_id();
             }
         }
     }
     $this->api = pods_api($pod);
     $this->api->display_errors =& $this->display_errors;
     $this->data = pods_data($this->api, $id, false);
     PodsData::$display_errors =& $this->display_errors;
     // Set up page variable
     if (pods_strict(false)) {
         $this->page = 1;
         $this->pagination = false;
         $this->search = false;
     } else {
         // Get the page variable
         $this->page = pods_var($this->page_var, 'get');
         $this->page = empty($this->page) ? 1 : max(pods_absint($this->page), 1);
     }
     // Set default pagination handling to on/off
     if (defined('PODS_GLOBAL_POD_PAGINATION')) {
         if (!PODS_GLOBAL_POD_PAGINATION) {
             $this->page = 1;
             $this->pagination = false;
         } else {
             $this->pagination = true;
         }
     }
     // Set default search to on/off
     if (defined('PODS_GLOBAL_POD_SEARCH')) {
         if (PODS_GLOBAL_POD_SEARCH) {
             $this->search = true;
         } else {
             $this->search = false;
         }
     }
     // Set default search mode
     $allowed_search_modes = array('int', 'text', 'text_like');
     if (defined('PODS_GLOBAL_POD_SEARCH_MODE') && in_array(PODS_GLOBAL_POD_SEARCH_MODE, $allowed_search_modes)) {
         $this->search_mode = PODS_GLOBAL_POD_SEARCH_MODE;
     }
     // Sync Settings
     $this->data->page =& $this->page;
     $this->data->limit =& $this->limit;
     $this->data->pagination =& $this->pagination;
     $this->data->search =& $this->search;
     $this->data->search_mode =& $this->search_mode;
     // Sync Pod Data
     $this->api->pod_data =& $this->data->pod_data;
     $this->pod_data =& $this->api->pod_data;
     $this->api->pod_id =& $this->data->pod_id;
     $this->pod_id =& $this->api->pod_id;
     $this->datatype_id =& $this->pod_id;
     $this->api->pod =& $this->data->pod;
     $this->pod =& $this->api->pod;
     $this->datatype =& $this->pod;
     $this->api->fields =& $this->data->fields;
     $this->fields =& $this->api->fields;
     $this->detail_page =& $this->data->detail_page;
     $this->id =& $this->data->id;
     $this->row =& $this->data->row;
     $this->rows =& $this->data->data;
     $this->row_number =& $this->data->row_number;
     $this->sql =& $this->data->sql;
     if (is_array($id) || is_object($id)) {
         $this->find($id);
     }
 }
/**
 * Split an array into human readable text (Item, Item, and Item)
 *
 * @param array $value
 * @param string $field
 * @param array $fields
 * @param string $and
 * @param string $field_index
 *
 * @return string
 *
 * @since 2.0
 */
function pods_serial_comma($value, $field = null, $fields = null, $and = null, $field_index = null)
{
    if (is_object($value)) {
        $value = get_object_vars($value);
    }
    $defaults = array('field' => $field, 'fields' => $fields, 'and' => $and, 'field_index' => $field_index, 'separator' => ',', 'serial' => true);
    if (is_array($field)) {
        $defaults['field'] = null;
        $params = array_merge($defaults, $field);
    } else {
        $params = $defaults;
    }
    $params = (object) $params;
    $simple = false;
    if (!empty($params->fields) && is_array($params->fields) && isset($params->fields[$params->field])) {
        $params->field = $params->fields[$params->field];
        $simple_tableless_objects = PodsForm::simple_tableless_objects();
        if (!empty($params->field) && is_array($params->field) && in_array($params->field['type'], PodsForm::tableless_field_types())) {
            if (in_array($params->field['type'], PodsForm::file_field_types())) {
                if (null === $params->field_index) {
                    $params->field_index = 'guid';
                }
            } elseif (in_array($params->field['pick_object'], $simple_tableless_objects)) {
                $simple = true;
            } else {
                $table = pods_api()->get_table_info($params->field['pick_object'], $params->field['pick_val'], null, null, $params->field);
                if (!empty($table)) {
                    if (null === $params->field_index) {
                        $params->field_index = $table['field_index'];
                    }
                }
            }
        }
    } else {
        $params->field = null;
    }
    if ($simple && is_array($params->field) && !is_array($value) && '' !== $value && null !== $value) {
        $value = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $value, $params->field);
    }
    if (!is_array($value)) {
        return $value;
    }
    if (null === $params->and) {
        $params->and = ' ' . __('and', 'pods') . ' ';
    }
    $last = '';
    $original_value = $value;
    if (!empty($value)) {
        $last = array_pop($value);
    }
    if ($simple && is_array($params->field) && !is_array($last) && '' !== $last && null !== $last) {
        $last = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $last, $params->field);
    }
    if (is_array($last)) {
        if (null !== $params->field_index && isset($last[$params->field_index])) {
            $last = $last[$params->field_index];
        } elseif (isset($last[0])) {
            $last = $last[0];
        } elseif ($simple) {
            $last = current($last);
        } else {
            $last = '';
        }
    }
    if (!empty($value)) {
        if (null !== $params->field_index && isset($original_value[$params->field_index])) {
            return $original_value[$params->field_index];
        } elseif (null !== $params->field_index && isset($value[$params->field_index])) {
            return $value[$params->field_index];
        } elseif (!isset($value[0])) {
            $value = array($value);
        }
        foreach ($value as $k => $v) {
            if ($simple && is_array($params->field) && !is_array($v) && '' !== $v && null !== $v) {
                $v = PodsForm::field_method('pick', 'simple_value', $params->field['name'], $v, $params->field);
            }
            if (is_array($v)) {
                if (null !== $params->field_index && isset($v[$params->field_index])) {
                    $v = $v[$params->field_index];
                } elseif ($simple) {
                    $v = trim(implode($params->separator . ' ', $v), $params->separator . ' ');
                } else {
                    unset($value[$k]);
                    continue;
                }
            }
            $value[$k] = $v;
        }
        if (1 == count($value) || !$params->serial) {
            $value = trim(implode($params->separator . ' ', $value), $params->separator . ' ');
        } else {
            $value = trim(implode($params->separator . ' ', $value), $params->separator . ' ') . apply_filters('pods_serial_comma', $params->separator . ' ', $value, $original_value, $params);
        }
        $value = trim($value);
        $last = trim($last);
        if (0 < strlen($value) && 0 < strlen($last)) {
            $value = $value . $params->and . $last;
        } elseif (0 < strlen($last)) {
            $value = $last;
        } else {
            $value = '';
        }
    } else {
        $value = $last;
    }
    $value = trim($value, $params->separator . ' ');
    $value = apply_filters('pods_serial_comma_value', $value, $original_value, $params);
    return (string) $value;
}
<?php

// Get the API object for 'event' Pod
$api = pods_api('event');
// Setup the data to import
$data = array(0 => array('name' => 'My first event', 'start_date' => '2009-10-30 08:24:30', 'attendees' => array('Bill Gates', 'Steve Jobs', 'Mario Andretti')), 1 => array('name' => 'My second event', 'start_date' => '2012-12-25 06:45:00', 'attendees' => array('Al Gore', 'Bill Clinton')), 2 => array('name' => 'My third event', 'start_date' => '2010-01-20 11:59:99', 'attendees' => array('Rick Astley')));
// Run the import
$api->import($data);
// Get CSV data
$data = file_get_contents('path/to/events.csv');
// Run the import and set the format to CSV
$api->import($data, false, 'csv');
Exemple #18
0
 function __construct($type = null, $format = null)
 {
     pods_deprecated('PodAPI (class)', '2.0', 'pods_api (function)');
     $this->new = pods_api($type, $format);
 }
Exemple #19
0
 public function delete_object($type, $id, $name = null)
 {
     if (empty($name)) {
         $name = $type;
     }
     $object = $this->object_get($type, $name);
     if (!empty($object)) {
         $params = array('pod' => pods_var('name', $object), 'pod_id' => pods_var('id', $object), 'id' => $id);
         return pods_api()->delete_pod_item($params, false);
     } else {
         return pods_api()->delete_object_from_relationships($id, $type, $name);
     }
 }
Exemple #20
0
 /**
  * Add REST API support to post type and taxonomy objects.
  *
  * @uses "init"
  *
  * @since 2.5.6
  */
 public function add_rest_support()
 {
     static $rest_support_added;
     if (!function_exists('register_rest_field')) {
         return;
     }
     include_once PODS_DIR . 'classes/PodsRESTFields.php';
     include_once PODS_DIR . 'classes/PodsRESTHandlers.php';
     $rest_bases = pods_transient_get('pods_rest_bases');
     if (empty($rest_bases)) {
         $pods = pods_api()->load_pods();
         $rest_bases = array();
         if (!empty($pods) && is_array($pods)) {
             foreach ($pods as $pod) {
                 $type = $pod['type'];
                 if (in_array($type, array('post_type', 'taxonomy'))) {
                     if ($pod && PodsRESTHandlers::pod_extends_core_route($pod)) {
                         $rest_bases[$pod['name']] = array('type' => $type, 'base' => sanitize_title(pods_v('rest_base', $pod['options'], $pod['name'])));
                     }
                 }
             }
         }
         if (empty($rest_bases)) {
             $rest_bases = 'none';
         }
         pods_transient_set('pods_rest_bases', $rest_bases);
     }
     if (empty($rest_support_added) && !empty($rest_bases) && 'none' !== $rest_bases) {
         foreach ($rest_bases as $pod_name => $pod_info) {
             $pod_type = $pod_info['type'];
             $rest_base = $pod_info['base'];
             if ('post_type' == $pod_type) {
                 PodsRESTHandlers::post_type_rest_support($pod_name, $rest_base);
             } elseif ('taxonomy' == $pod_type) {
                 PodsRESTHandlers::taxonomy_rest_support($pod_name, $rest_base);
             }
             new PodsRESTFields($pod_name);
         }
         $rest_support_added = true;
     }
 }
 /**
  * Handle autocomplete AJAX
  *
  * @since 2.3
  */
 public function admin_ajax_relationship()
 {
     pods_session_start();
     // Sanitize input
     $params = pods_unslash((array) $_POST);
     foreach ($params as $key => $value) {
         if ('action' == $key) {
             continue;
         }
         unset($params[$key]);
         $params[str_replace('_podsfix_', '', $key)] = $value;
     }
     $params = (object) $params;
     $uid = @session_id();
     if (is_user_logged_in()) {
         $uid = 'user_' . get_current_user_id();
     }
     $nonce_check = 'pods_relationship_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field;
     if (!isset($params->_wpnonce) || false === wp_verify_nonce($params->_wpnonce, $nonce_check)) {
         pods_error(__('Unauthorized request', 'pods'), PodsInit::$admin);
     }
     $api = pods_api();
     $pod = $api->load_pod(array('id' => (int) $params->pod));
     $field = $api->load_field(array('id' => (int) $params->field, 'table_info' => true));
     $id = (int) $params->id;
     $limit = 15;
     if (isset($params->limit)) {
         $limit = (int) $params->limit;
     }
     $page = 1;
     if (isset($params->page)) {
         $page = (int) $params->page;
     }
     if (!isset($params->query) || strlen(trim($params->query)) < 1) {
         pods_error(__('Invalid field request', 'pods'), PodsInit::$admin);
     } elseif (empty($pod) || empty($field) || $pod['id'] != $field['pod_id'] || !isset($pod['fields'][$field['name']])) {
         pods_error(__('Invalid field request', 'pods'), PodsInit::$admin);
     } elseif ('pick' != $field['type'] || empty($field['table_info'])) {
         pods_error(__('Invalid field', 'pods'), PodsInit::$admin);
     } elseif ('single' == pods_var(self::$type . '_format_type', $field) && 'autocomplete' == pods_var(self::$type . '_format_single', $field)) {
         pods_error(__('Invalid field', 'pods'), PodsInit::$admin);
     } elseif ('multi' == pods_var(self::$type . '_format_type', $field) && 'autocomplete' == pods_var(self::$type . '_format_multi', $field)) {
         pods_error(__('Invalid field', 'pods'), PodsInit::$admin);
     }
     $object_params = array('name' => $field['name'], 'value' => null, 'options' => array_merge($field, $field['options']), 'pod' => $pod, 'id' => $id, 'context' => 'admin_ajax_relationship', 'data_params' => $params, 'page' => $page, 'limit' => $limit);
     $pick_data = apply_filters('pods_field_pick_data_ajax', null, $field['name'], null, $field, $pod, $id);
     if (null !== $pick_data) {
         $items = $pick_data;
     } else {
         $items = $this->get_object_data($object_params);
     }
     if (!empty($items) && isset($items[0]) && !is_array($items[0])) {
         $new_items = array();
         foreach ($items as $id => $text) {
             $new_items[] = array('id' => $id, 'text' => $text, 'image' => '');
         }
         $items = $new_items;
     }
     $items = apply_filters('pods_field_pick_data_ajax_items', $items, $field['name'], null, $field, $pod, $id);
     $items = array('results' => $items);
     wp_send_json($items);
     die;
     // KBAI!
 }
 /**
  * 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;
 }
Exemple #23
0
 /**
  * Profiles the Pods configuration
  *
  * @param null|string|array $pod. Optional. Which Pod(s) to get configuration for. Can be a the name of one Pod, or an array of names of Pods, or null, which is the default, to profile all Pods.
  * @param bool $full_field_info Optional. If true all info about each field is returned. If false, which is the default only name and type, will be returned.
  *
  * @return array
  *
  * @since 3.0.0
  */
 function configuration($pod = null, $full_field_info = false)
 {
     $api = pods_api();
     if (is_null($pod)) {
         $the_pods = $api->load_pods();
     } elseif (is_array($pod)) {
         foreach ($pod as $p) {
             $the_pods[] = $api->load_pod($p);
         }
     } else {
         $the_pods[] = $api->load_pod($pod);
     }
     foreach ($the_pods as $pod) {
         $configuration[$pod['name']] = array('name' => $pod['name'], 'ID' => $pod['id'], 'storage' => $pod['storage'], 'fields' => $pod['fields']);
     }
     if (!$full_field_info) {
         foreach ($the_pods as $pod) {
             $fields = $configuration[$pod['name']]['fields'];
             unset($configuration[$pod['name']]['fields']);
             foreach ($fields as $field) {
                 $info = array('name' => $field['name'], 'type' => $field['type']);
                 if ($info['type'] === 'pick') {
                     $info['pick_object'] = $field['pick_object'];
                     if (isset($field['pick_val']) && $field['pick_val'] !== '') {
                         $info['pick_val'] = $field['pick_val'];
                     }
                 }
                 if (is_array($info)) {
                     $configuration[$pod['name']]['fields'][$field['name']] = $info;
                 }
                 unset($info);
             }
         }
     }
     if (is_array($configuration)) {
         return $configuration;
     }
 }
 /**
  * Get all Pods with auto template enable and its settings
  *
  * @return array With info about auto template settings per post type
  *
  * @since 2.4.5
  */
 function auto_pods()
 {
     /**
      * Filter to override all settings for which templates are used.
      *
      * Note: If this filter does not return null, all back-end settings are ignored. To add to settings with a filter, use 'pods_pfat_auto_pods';
      *
      * @param array $auto_pods Array of parameters to use instead of those from settings.
      *
      * @return array Settings arrays for each post type.
      *
      * @since 2.4.5
      */
     $auto_pods = apply_filters('pods_pfat_auto_pods_override', null);
     if (!is_null($auto_pods)) {
         return $auto_pods;
     }
     //try to get cached results of this method
     $key = '_pods_pfat_auto_pods';
     $auto_pods = pods_transient_get($key);
     //check if we already have the results cached & use it if we can.
     if ($auto_pods === false) {
         //get possible pods
         $the_pods = $this->the_pods();
         //start output array empty
         $auto_pods = array();
         //get pods api class
         $api = pods_api();
         //loop through each to see if auto templates is enabled
         foreach ($the_pods as $the_pod => $the_pod_label) {
             //get this Pods' data.
             $pod_data = $api->load_pod(array('name' => $the_pod));
             //if auto template is enabled add info about Pod to array
             if (1 == pods_v('pfat_enable', $pod_data['options'])) {
                 //check if pfat_single and pfat_archive are set
                 $single = pods_v('pfat_single', $pod_data['options'], false, true);
                 $archive = pods_v('pfat_archive', $pod_data['options'], false, true);
                 $single_append = pods_v('pfat_append_single', $pod_data['options'], true, true);
                 $archive_append = pods_v('pfat_append_archive', $pod_data['options'], true, true);
                 $single_filter = pods_v('pfat_filter_single', $pod_data['options'], 'the_content', true);
                 $archive_filter = pods_v('pfat_filter_archive', $pod_data['options'], 'the_content', true);
                 $type = pods_v('type', $pod_data, false, true);
                 //check if it's a post type that has an arhive
                 if ($type === 'post_type' && $the_pod !== 'post' || $the_pod !== 'page') {
                     $has_archive = pods_v('has_archive', $pod_data['options'], false, true);
                 } else {
                     $has_archive = true;
                 }
                 if (empty($single_filter)) {
                     $single_filter = 'the_content';
                 }
                 if (empty($archive_filter)) {
                     $archive_filter = 'the_content';
                 }
                 //build output array
                 $auto_pods[$the_pod] = array('name' => $the_pod, 'label' => $the_pod_label, 'single' => $single, 'archive' => $archive, 'single_append' => $single_append, 'archive_append' => $archive_append, 'has_archive' => $has_archive, 'single_filter' => $single_filter, 'archive_filter' => $archive_filter, 'type' => $type);
             }
         }
         //endforeach
         //cache the results
         pods_transient_set($key, $auto_pods);
     }
     /**
      * Add to or change settings.
      *
      * Use this filter to change or add to the settings set in the back-end for this plugin. Has no effect if 'pods_pfat_auto_pods_override' filter is being used.
      *
      * @param array $auto_pods Array of parameters to use instead of those from settings.
      *
      * @return array Settings arrays for each post type.
      *
      * @since 2.4.5
      */
     $auto_pods = apply_filters('pods_pfat_auto_pods', $auto_pods);
     return $auto_pods;
 }
Exemple #25
0
    <div id="icon-pods" class="icon32"><br /></div>

    <form action="" method="post" class="pods-submittable">
        <div class="pods-submittable-fields">
            <input type="hidden" name="action" value="pods_admin" />
            <input type="hidden" name="method" value="add_pod" />
            <input type="hidden" name="_wpnonce" value="<?php 
echo esc_attr(wp_create_nonce('pods-add_pod'));
?>
" />
            <input type="hidden" name="create_extend" id="pods_create_extend" value="create" />

            <h2 class="italicized">
                <?php 
_e('Add New Pod', 'pods');
$all_pods = pods_api()->load_pods(array('key_names' => true));
if (!empty($all_pods)) {
    $link = pods_query_arg(array('page' => 'pods', 'action' . $obj->num => 'manage'));
    ?>
                    <a href="<?php 
    echo esc_url($link);
    ?>
" class="add-new-h2">&laquo; <?php 
    _e('Back to Manage', 'pods');
    ?>
</a>
                <?php 
}
?>
            </h2>
Exemple #26
0
 /**
  * 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())));
         }
     }
 }
Exemple #27
0
/**
 * Find out if the current page has a valid $pods
 *
 * @param object $object The Pod Object currently checking (optional)
 *
 * @return bool
 * @since 2.0
 */
function is_pod($object = null)
{
    global $pods, $post;
    if (is_object($object) && isset($object->pod) && !empty($object->pod)) {
        return true;
    } elseif (is_object($pods) && isset($pods->pod) && !empty($pods->pod)) {
        return true;
    } elseif (is_object($post) && isset($post->post_type) && pods_api()->pod_exists($post->post_type, 'post_type')) {
        return true;
    }
    return false;
}
<?php

/**
 * Add a Pod and a field programmatically.
 *
 * In this case, a custom post type using table storage and a text field is being added.
 */
//set name of Pods
$pod_name = 'frogs';
//Set up the Pod.
//You probably want to set an array of labels
//For Custom Post Types you can choose meta or table storage.
//The latter option requires the table storage componenet.
$params = array('storage' => 'table', 'type' => 'post_type', 'name' => $pod_name);
//return ID of new Pod into a variable.
$pod_id = pods_api()->save_pod($params);
//now add a field if it didn't return false.
if ($pod_id) {
    //set up field params for a text field. Setting pod name and ID with variables we already populated.
    $params = array('pod_id' => $pod_id, 'pod' => $pod_name, 'name' => 'latin_name', 'type' => 'text');
    $field_id = pods_api()->save_field($params);
}
Exemple #29
0
 /**
  * Output a field
  *
  * @param string $name Field name
  * @param mixed $value Field value
  * @param string $type Field type
  * @param array $options Field options
  * @param array $pod Pod data
  * @param int $id Item ID
  *
  * @return string Field HTML
  *
  * @since 2.0
  */
 public static function field($name, $value, $type = 'text', $options = null, $pod = null, $id = null)
 {
     // Take a field array
     if (is_array($name) || is_object($name)) {
         $options = $name;
         if (is_object($type)) {
             $pod = $type;
             $id = $options;
         }
         $name = pods_v('name', $options);
         $type = pods_v('type', $options);
     }
     $options = self::options($type, $options);
     if (null === $value || '' === $value && 'boolean' == $type || !empty($pod) && empty($id)) {
         $value = self::default_value($value, $type, $name, $options, $pod, $id);
     }
     if (false === self::permission($type, $name, $options, null, $pod, $id)) {
         return false;
     }
     $value = apply_filters('pods_form_ui_field_' . $type . '_value', $value, $name, $options, $pod, $id);
     $form_field_type = self::$field_type;
     ob_start();
     $helper = false;
     if (0 < strlen(pods_v('input_helper', $options))) {
         $helper = pods_api()->load_helper(array('name' => $options['input_helper']));
     }
     if ((!isset($options['data']) || empty($options['data'])) && is_object(self::$loaded[$type]) && method_exists(self::$loaded[$type], 'data')) {
         $data = $options['data'] = self::$loaded[$type]->data($name, $value, $options, $pod, $id, true);
     }
     if (true === apply_filters('pods_form_ui_field_' . $type . '_override', false, $name, $value, $options, $pod, $id)) {
         do_action('pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id);
     } elseif (!empty($helper) && 0 < strlen(pods_v('code', $helper)) && false === strpos($helper['code'], '$this->') && (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL)) {
         eval('?>' . $helper['code']);
     } elseif (method_exists(get_class(), 'field_' . $type)) {
         echo call_user_func(array(get_class(), 'field_' . $type), $name, $value, $options);
     } elseif (is_object(self::$loaded[$type]) && method_exists(self::$loaded[$type], 'input')) {
         self::$loaded[$type]->input($name, $value, $options, $pod, $id);
     } else {
         do_action('pods_form_ui_field_' . $type, $name, $value, $options, $pod, $id);
     }
     $output = ob_get_clean();
     return apply_filters('pods_form_ui_field_' . $type, $output, $name, $value, $options, $pod, $id);
 }
Exemple #30
0
 /**
  * Get the string to use in a query for matching, uses WP_Query meta_query arguments
  *
  * @param string|int $field Field name or array index
  * @param array|string $q Query array (meta_query) or string for matching
  * @param array $pod Related Pod
  * @param object $params Parameters passed from select()
  *
  * @return string|null Query field string
  *
  * @see PodsData::query_fields
  * @static
  * @since 2.3
  */
 public static function query_field($field, $q, $pod = null, &$params = null)
 {
     global $wpdb;
     $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects');
     $field_query = null;
     // Plain queries
     if (is_numeric($field) && !is_array($q)) {
         return $q;
     } elseif (!is_numeric($field) && (!is_array($q) || !isset($q['key']) && !isset($q['field']))) {
         $new_q = array('field' => $field, 'compare' => pods_var_raw('compare', $q, '=', null, true), 'value' => pods_var_raw('value', $q, $q, null, true), 'sanitize' => pods_var_raw('sanitize', $q, true), 'sanitize_format' => pods_var_raw('sanitize_format', $q), 'cast' => pods_var_raw('cast', $q));
         if (is_array($new_q['value'])) {
             if ('=' == $new_q['compare']) {
                 $new_q['compare'] = 'IN';
             }
             if (isset($new_q['value']['compare'])) {
                 unset($new_q['value']['compare']);
             }
         }
         $q = $new_q;
     }
     $field_name = trim(pods_var_raw('field', $q, pods_var_raw('key', $q, $field, null, true), null, true));
     $field_type = strtoupper(trim(pods_var_raw('type', $q, 'CHAR', null, true)));
     $field_value = pods_var_raw('value', $q);
     $field_compare = strtoupper(trim(pods_var_raw('compare', $q, is_array($field_value ? 'IN' : '='), null, true)));
     $field_sanitize = (bool) pods_var('sanitize', $q, true);
     $field_sanitize_format = pods_var_raw('sanitize_format', $q, null, null, true);
     $field_cast = pods_var_raw('cast', $q, null, null, true);
     if (is_object($params)) {
         $params->meta_query_syntax = true;
         $params->query_fields[] = $field_name;
     }
     // Deprecated WP type
     if ('NUMERIC' == $field_type) {
         $field_type = 'SIGNED';
     } elseif (!in_array($field_type, array('BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'))) {
         $field_type = 'CHAR';
     }
     // Alias / Casting
     if (empty($field_cast)) {
         // Setup field casting from field name
         if (false === strpos($field_name, '`') && false === strpos($field_name, '(') && false === strpos($field_name, ' ')) {
             // Handle field naming if Pod-based
             if (!empty($pod) && false === strpos($field_name, '.')) {
                 $field_cast = '';
                 $tableless_field_types = PodsForm::tableless_field_types();
                 if (isset($pod['fields'][$field_name]) && in_array($pod['fields'][$field_name]['type'], $tableless_field_types)) {
                     if (in_array($pod['fields'][$field_name]['pick_object'], $simple_tableless_objects)) {
                         if ('table' == $pod['storage']) {
                             $field_cast = "`t`.`{$field_name}`";
                         } else {
                             $field_cast = "`{$field_name}`.`meta_value`";
                         }
                     } else {
                         $table = pods_api()->get_table_info($pod['fields'][$field_name]['pick_object'], $pod['fields'][$field_name]['pick_val']);
                         if (!empty($table)) {
                             $field_cast = "`{$field_name}`.`" . $table['field_index'] . '`';
                         }
                     }
                 }
                 if (empty($field_cast)) {
                     if (!in_array($pod['type'], array('pod', 'table'))) {
                         if (isset($pod['object_fields'][$field_name])) {
                             $field_cast = "`t`.`{$field_name}`";
                         } elseif (isset($pod['fields'][$field_name])) {
                             if ('table' == $pod['storage']) {
                                 $field_cast = "`d`.`{$field_name}`";
                             } else {
                                 $field_cast = "`{$field_name}`.`meta_value`";
                             }
                         } else {
                             foreach ($pod['object_fields'] as $object_field => $object_field_opt) {
                                 if ($object_field == $field_name || in_array($field_name, $object_field_opt['alias'])) {
                                     $field_cast = "`t`.`{$object_field}`";
                                     break;
                                 }
                             }
                         }
                     } elseif (isset($pod['fields'][$field_name])) {
                         if ('table' == $pod['storage']) {
                             $field_cast = "`t`.`{$field_name}`";
                         } else {
                             $field_cast = "`{$field_name}`.`meta_value`";
                         }
                     }
                     if (empty($field_cast)) {
                         $field_cast = "`{$field_name}`";
                     }
                 }
             } else {
                 $field_cast = '`' . str_replace('.', '`.`', $field_name) . '`';
             }
         } else {
             $field_cast = $field_name;
         }
         // Cast field if needed
         if ('CHAR' != $field_type) {
             $field_cast = 'CAST( ' . $field_cast . ' AS ' . $field_type . ' )';
         }
     }
     // Setup string sanitizing for $wpdb->prepare()
     if (empty($field_sanitize_format)) {
         // Sanitize as string
         $field_sanitize_format = '%s';
         // Sanitize as integer if needed
         if (in_array($field_type, array('UNSIGNED', 'SIGNED'))) {
             $field_sanitize_format = '%d';
         }
     }
     // Restrict to supported comparisons
     if (!in_array($field_compare, array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS', 'NOT EXISTS', 'REGEXP', 'NOT REGEXP', 'RLIKE'))) {
         $field_compare = '=';
     }
     // Restrict to supported array comparisons
     if (is_array($field_value) && !in_array($field_compare, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'))) {
         if (in_array($field_compare, array('!=', 'NOT LIKE'))) {
             $field_compare = 'NOT IN';
         } else {
             $field_compare = 'IN';
         }
     } elseif (!is_array($field_value) && in_array($field_compare, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'))) {
         $check_value = preg_split('/[,\\s]+/', $field_value);
         if (1 < count($check_value)) {
             $field_value = $check_value;
         } elseif (in_array($field_compare, array('NOT IN', 'NOT BETWEEN'))) {
             $field_compare = '!=';
         } else {
             $field_compare = '=';
         }
     }
     // Restrict to two values, force = and != if only one value provided
     if (in_array($field_compare, array('BETWEEN', 'NOT BETWEEN'))) {
         $field_value = array_values(array_slice($field_value, 0, 2));
         if (1 == count($field_value)) {
             if ('NOT IN' == $field_compare) {
                 $field_compare = '!=';
             } else {
                 $field_compare = '=';
             }
         }
     }
     // Empty array handling
     if (in_array($field_compare, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN')) && empty($field_value)) {
         $field_compare = 'EXISTS';
     }
     // Rebuild $q
     $q = array('field' => $field_name, 'type' => $field_type, 'value' => $field_value, 'compare' => $field_compare, 'sanitize' => $field_sanitize, 'sanitize_format' => $field_sanitize_format, 'cast' => $field_cast);
     // Make the query
     if (in_array($field_compare, array('=', '!=', '>', '>=', '<', '<=', 'REGEXP', 'NOT REGEXP', 'RLIKE'))) {
         if ($field_sanitize) {
             $field_query = $wpdb->prepare($field_cast . ' ' . $field_compare . ' ' . $field_sanitize_format, $field_value);
         } else {
             $field_query = $field_cast . ' ' . $field_compare . ' "' . $field_value . '"';
         }
     } elseif (in_array($field_compare, array('LIKE', 'NOT LIKE'))) {
         if ($field_sanitize) {
             $field_query = $field_cast . ' ' . $field_compare . ' "%' . pods_sanitize_like($field_value) . '%"';
         } else {
             $field_query = $field_cast . ' ' . $field_compare . ' "' . $field_value . '"';
         }
     } elseif (in_array($field_compare, array('IN', 'NOT IN'))) {
         if ($field_sanitize) {
             $field_query = $wpdb->prepare($field_cast . ' ' . $field_compare . ' ( ' . substr(str_repeat(', ' . $field_sanitize_format, count($field_value)), 1) . ' )', $field_value);
         } else {
             $field_query = $field_cast . ' ' . $field_compare . ' ( "' . implode('", "', $field_value) . '" )';
         }
     } elseif (in_array($field_compare, array('BETWEEN', 'NOT BETWEEN'))) {
         if ($field_sanitize) {
             $field_query = $wpdb->prepare($field_cast . ' ' . $field_compare . ' ' . $field_sanitize_format . ' AND ' . $field_sanitize_format, $field_value);
         } else {
             $field_query = $field_cast . ' ' . $field_compare . ' "' . $field_value[0] . '" AND "' . $field_value[1] . '"';
         }
     } elseif ('EXISTS' == $field_compare) {
         $field_query = $field_cast . ' IS NOT NULL';
     } elseif ('NOT EXISTS' == $field_compare) {
         $field_query = $field_cast . ' IS NULL';
     }
     $field_query = apply_filters('pods_data_field_query', $field_query, $q);
     return $field_query;
 }