Ejemplo n.º 1
0
/**
 * Shortcode support for use anywhere that support WP Shortcodes
 *
 * @param array $tags An associative array of shortcode properties
 * @param string $content A string that represents a template override
 *
 * @return string
 * @since 1.6.7
 */
function pods_shortcode($tags, $content = null)
{
    $defaults = array('name' => null, 'id' => null, 'slug' => null, 'select' => null, 'order' => null, 'orderby' => null, 'limit' => null, 'where' => null, 'having' => null, 'groupby' => null, 'search' => true, 'pagination' => false, 'page' => null, 'filters' => false, 'filters_label' => null, 'filters_location' => 'before', 'pagination_label' => null, 'pagination_location' => 'after', 'field' => null, 'col' => null, 'template' => null, 'pods_page' => null, 'helper' => null, 'form' => null, 'fields' => null, 'label' => null, 'thank_you' => null, 'view' => null, 'cache_mode' => 'none', 'expires' => 0, 'shortcodes' => false);
    if (!empty($tags)) {
        $tags = array_merge($defaults, $tags);
    } else {
        $tags = $defaults;
    }
    $tags = apply_filters('pods_shortcode', $tags);
    if (empty($content)) {
        $content = null;
    }
    if (0 < strlen($tags['view'])) {
        $return = pods_view($tags['view'], null, (int) $tags['expires'], $tags['cache_mode']);
        if ($tags['shortcodes']) {
            $return = do_shortcode($return);
        }
        return $return;
    }
    if (empty($tags['name'])) {
        if (in_the_loop() || is_singular()) {
            $pod = pods(get_post_type(), get_the_ID(), false);
            if (!empty($pod)) {
                $tags['name'] = get_post_type();
                $id = $tags['id'] = get_the_ID();
            }
        }
        if (empty($tags['name'])) {
            return '<p>Please provide a Pod name</p>';
        }
    }
    if (!empty($tags['col'])) {
        $tags['field'] = $tags['col'];
        unset($tags['col']);
    }
    if (!empty($tags['order'])) {
        $tags['orderby'] = $tags['order'];
        unset($tags['order']);
    }
    if (empty($content) && empty($tags['pods_page']) && empty($tags['template']) && empty($tags['field']) && empty($tags['form'])) {
        return '<p>Please provide either a template or field name</p>';
    }
    if (!isset($id)) {
        // id > slug (if both exist)
        $id = empty($tags['slug']) ? null : pods_evaluate_tags($tags['slug']);
        if (!empty($tags['id'])) {
            $id = $tags['id'];
            if (is_numeric($id)) {
                $id = absint($id);
            }
        }
    }
    if (!isset($pod)) {
        $pod = pods($tags['name'], $id);
    }
    if (empty($pod)) {
        return '<p>Pod not found</p>';
    }
    $found = 0;
    if (!empty($tags['form'])) {
        return $pod->form($tags['fields'], $tags['label'], $tags['thank_you']);
    } elseif (empty($id)) {
        $params = array();
        if (0 < strlen($tags['orderby'])) {
            $params['orderby'] = $tags['orderby'];
        }
        if (!empty($tags['limit'])) {
            $params['limit'] = $tags['limit'];
        }
        if (0 < strlen($tags['where'])) {
            $params['where'] = pods_evaluate_tags($tags['where']);
        }
        if (0 < strlen($tags['having'])) {
            $params['having'] = pods_evaluate_tags($tags['having']);
        }
        if (0 < strlen($tags['groupby'])) {
            $params['groupby'] = $tags['groupby'];
        }
        if (0 < strlen($tags['select'])) {
            $params['select'] = $tags['select'];
        }
        if (empty($tags['search'])) {
            $params['search'] = false;
        }
        if (0 < absint($tags['page'])) {
            $params['page'] = absint($tags['page']);
        }
        if (empty($tags['pagination'])) {
            $params['pagination'] = false;
        }
        if (!empty($tags['cache_mode']) && 'none' != $tags['cache_mode']) {
            $params['cache_mode'] = $tags['cache_mode'];
            $params['expires'] = (int) $tags['expires'];
        }
        $params = apply_filters('pods_shortcode_findrecords_params', $params);
        $pod->find($params);
        $found = $pod->total();
    } elseif (!empty($tags['field'])) {
        if (empty($tags['helper'])) {
            $return = $pod->display($tags['field']);
        } else {
            $return = $pod->helper($tags['helper'], $pod->field($tags['field']), $tags['field']);
        }
        if ($tags['shortcodes']) {
            $return = do_shortcode($return);
        }
        return $return;
    } elseif (!empty($tags['pods_page']) && class_exists('Pods_Pages')) {
        $pods_page = Pods_Pages::exists($tags['pods_page']);
        if (empty($pods_page)) {
            return '<p>Pods Page not found</p>';
        }
        $return = Pods_Pages::content(true, $pods_page);
        if ($tags['shortcodes']) {
            $return = do_shortcode($return);
        }
        return $return;
    }
    ob_start();
    if (empty($id) && false !== $tags['filters'] && 'before' == $tags['filters_location']) {
        echo $pod->filters($tags['filters'], $tags['filters_label']);
    }
    if (empty($id) && 0 < $found && false !== $tags['pagination'] && in_array($tags['pagination_location'], array('before', 'both'))) {
        echo $pod->pagination($tags['pagination_label']);
    }
    echo $pod->template($tags['template'], $content);
    if (empty($id) && 0 < $found && false !== $tags['pagination'] && in_array($tags['pagination_location'], array('after', 'both'))) {
        echo $pod->pagination($tags['pagination_label']);
    }
    if (empty($id) && false !== $tags['filters'] && 'after' == $tags['filters_location']) {
        echo $pod->filters($tags['filters'], $tags['filters_label']);
    }
    $return = ob_get_clean();
    if ($tags['shortcodes']) {
        $return = do_shortcode($return);
    }
    return $return;
}
Ejemplo n.º 2
0
 /**
  * Parse the default the value
  *
  * @since 2.0
  */
 public static function default_value($value, $type = 'text', $name = null, $options = null, $pod = null, $id = null)
 {
     $default_value = pods_v('default_value', $options);
     if ('' === $default_value || null === $default_value) {
         $default_value = $value;
     }
     $default = pods_v('default', $options, $default_value, true);
     $default_value = str_replace(array('{@', '}'), '', trim($default));
     if ($default != $default_value && 1 == (int) pods_v('default_evaluate_tags', $options, 1)) {
         $default = pods_evaluate_tags($default);
     }
     $default = pods_var_raw(pods_v('default_value_parameter', $options), 'request', $default, null, true);
     if ($default != $value) {
         $value = $default;
     }
     if (is_array($value)) {
         $value = pods_serial_comma($value);
     }
     return apply_filters('pods_form_field_default_value', $value, $default, $type, $options, $pod, $id);
 }
Ejemplo n.º 3
0
 /**
  * Create PodsUI content for the settings administration pages
  */
 public function admin_content_settings()
 {
     $pod_name = str_replace('pods-settings-', '', $_GET['page']);
     $pod = pods($pod_name);
     if ('custom' != pods_var('ui_style', $pod->pod_data['options'], 'settings', null, true)) {
         $actions_disabled = array('manage' => 'manage', 'add' => 'add', 'delete' => 'delete', 'duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export');
         $_GET['action'] = 'edit';
         $page_title = pods_var_raw('label', $pod->pod_data, ucwords(str_replace('_', ' ', $pod->pod_data['name'])), null, true);
         $ui = array('pod' => $pod, 'fields' => array('edit' => $pod->pod_data['fields']), 'header' => array('edit' => $page_title), 'label' => array('edit' => __('Save Changes', 'pods')), 'style' => pods_var('ui_style', $pod->pod_data['options'], 'settings', null, true), 'icon' => pods_evaluate_tags(pods_var_raw('menu_icon', $pod->pod_data['options']), true), 'actions_disabled' => $actions_disabled);
         $ui = apply_filters('pods_admin_ui_' . $pod->pod, apply_filters('pods_admin_ui', $ui, $pod->pod, $pod), $pod->pod, $pod);
         // Force disabled actions, do not pass go, do not collect $two_hundred
         $ui['actions_disabled'] = $actions_disabled;
         pods_ui($ui);
     } else {
         do_action('pods_admin_ui_custom', $pod);
         do_action('pods_admin_ui_custom_' . $pod->pod, $pod);
     }
 }
Ejemplo n.º 4
0
/**
 * Shortcode support for use anywhere that support WP Shortcodes
 *
 * @param array $tags An associative array of shortcode properties
 * @param string $content A string that represents a template override
 *
 * @return string
 * @since 1.6.7
 */
function pods_shortcode($tags, $content = null)
{
    if (defined('PODS_DISABLE_SHORTCODE') && PODS_DISABLE_SHORTCODE) {
        return '';
    }
    // For enforcing pagination parameters when not displaying pagination
    $page = 1;
    $offset = 0;
    if (isset($tags['page'])) {
        $page = (int) $tags['page'];
        $page = max($page, 1);
    }
    if (isset($tags['offset'])) {
        $offset = (int) $tags['offset'];
        $offset = max($offset, 0);
    }
    $defaults = array('use_current' => false, 'name' => null, 'id' => null, 'slug' => null, 'select' => null, 'join' => null, 'order' => null, 'orderby' => null, 'limit' => null, 'where' => null, 'having' => null, 'groupby' => null, 'search' => true, 'pagination' => false, 'page' => null, 'offset' => null, 'filters' => false, 'filters_label' => null, 'filters_location' => 'before', 'pagination_label' => null, 'pagination_location' => 'after', 'field' => null, 'col' => null, 'template' => null, 'pods_page' => null, 'helper' => null, 'form' => null, 'fields' => null, 'label' => null, 'thank_you' => null, 'view' => null, 'cache_mode' => 'none', 'expires' => 0, 'shortcodes' => false);
    if (!empty($tags)) {
        $tags = array_merge($defaults, $tags);
    } else {
        $tags = $defaults;
    }
    $tags = apply_filters('pods_shortcode', $tags);
    $tags['pagination'] = filter_var($tags['pagination'], FILTER_VALIDATE_BOOLEAN);
    $tags['search'] = filter_var($tags['pagination'], FILTER_VALIDATE_BOOLEAN);
    $tags['use_current'] = filter_var($tags['use_current'], FILTER_VALIDATE_BOOLEAN);
    if (empty($content)) {
        $content = null;
    }
    // Allow views only if not targeting a file path (must be within theme)
    if (0 < strlen($tags['view'])) {
        $return = '';
        if (!file_exists($tags['view'])) {
            $return = pods_view($tags['view'], null, (int) $tags['expires'], $tags['cache_mode']);
            if ($tags['shortcodes'] && defined('PODS_SHORTCODE_ALLOW_SUB_SHORTCODES') && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES) {
                $return = do_shortcode($return);
            }
        }
        return $return;
    }
    if (!$tags['use_current'] && empty($tags['name'])) {
        if (in_the_loop() || is_singular()) {
            $pod = pods(get_post_type(), get_the_ID(), false);
            if (!empty($pod)) {
                $tags['name'] = get_post_type();
                $id = $tags['id'] = get_the_ID();
            }
        }
        if (empty($tags['name'])) {
            return '<p>Please provide a Pod name</p>';
        }
    }
    if (!empty($tags['col'])) {
        $tags['field'] = $tags['col'];
        unset($tags['col']);
    }
    if (!empty($tags['order'])) {
        $tags['orderby'] = $tags['order'];
        unset($tags['order']);
    }
    if (empty($content) && empty($tags['pods_page']) && empty($tags['template']) && empty($tags['field']) && empty($tags['form'])) {
        return '<p>Please provide either a template or field name</p>';
    }
    if (!$tags['use_current'] && !isset($id)) {
        // id > slug (if both exist)
        $id = null;
        if (!empty($tags['slug'])) {
            $id = $tags['slug'];
            if (defined('PODS_SHORTCODE_ALLOW_EVALUATE_TAGS') && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS) {
                $id = pods_evaluate_tags($id);
            }
        }
        if (!empty($tags['id'])) {
            $id = $tags['id'];
            if (defined('PODS_SHORTCODE_ALLOW_EVALUATE_TAGS') && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS) {
                $id = pods_evaluate_tags($id);
            }
            if (is_numeric($id)) {
                $id = absint($id);
            }
        }
    }
    if (!isset($pod)) {
        if (!$tags['use_current']) {
            $pod = pods($tags['name'], $id);
        } else {
            $pod = pods();
            $id = $pod->id();
        }
    }
    if (empty($pod) || !$pod->valid()) {
        return '<p>Pod not found</p>';
    }
    $found = 0;
    $is_singular = !empty($id) || $tags['use_current'];
    if (!$is_singular) {
        $params = array();
        if (!defined('PODS_DISABLE_SHORTCODE_SQL') || !PODS_DISABLE_SHORTCODE_SQL) {
            if (0 < strlen($tags['orderby'])) {
                $params['orderby'] = $tags['orderby'];
            }
            if (0 < strlen($tags['where'])) {
                $params['where'] = $tags['where'];
                if (defined('PODS_SHORTCODE_ALLOW_EVALUATE_TAGS') && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS) {
                    $params['where'] = pods_evaluate_tags($params['where']);
                }
            }
            if (0 < strlen($tags['having'])) {
                $params['having'] = $tags['having'];
                if (defined('PODS_SHORTCODE_ALLOW_EVALUATE_TAGS') && PODS_SHORTCODE_ALLOW_EVALUATE_TAGS) {
                    $params['having'] = pods_evaluate_tags($id);
                }
            }
            if (0 < strlen($tags['groupby'])) {
                $params['groupby'] = $tags['groupby'];
            }
            if (0 < strlen($tags['select'])) {
                $params['select'] = $tags['select'];
            }
            if (0 < strlen($tags['join'])) {
                $params['join'] = $tags['join'];
            }
        }
        // Forms require params set
        if (!empty($params) || empty($tags['form'])) {
            if (!empty($tags['limit'])) {
                $params['limit'] = (int) $tags['limit'];
            }
            $params['search'] = $tags['search'];
            $params['pagination'] = $tags['pagination'];
            // If we aren't displaying pagination, we need to enforce page/offset
            if (!$params['pagination']) {
                $params['page'] = $page;
                $params['offset'] = $offset;
                // Force pagination on, we need it and we're enforcing page/offset
                $params['pagination'] = true;
            } else {
                // If we are displaying pagination, allow page/offset override only if *set*
                if (isset($tags['page'])) {
                    $params['page'] = (int) $tags['page'];
                    $params['page'] = max($params['page'], 1);
                }
                if (isset($tags['offset'])) {
                    $params['offset'] = (int) $tags['offset'];
                    $params['offset'] = max($params['offset'], 0);
                }
            }
            if (!empty($tags['cache_mode']) && 'none' != $tags['cache_mode']) {
                $params['cache_mode'] = $tags['cache_mode'];
                $params['expires'] = (int) $tags['expires'];
            }
            $params = apply_filters('pods_shortcode_findrecords_params', $params, $pod, $tags);
            $pod->find($params);
            $found = $pod->total();
        }
    }
    if (!empty($tags['form'])) {
        if ('user' == $pod->pod) {
            // Further hardening of User-based forms
            if (false !== strpos($tags['fields'], '_capabilities') || false !== strpos($tags['fields'], '_user_level')) {
                return '';
            } elseif ($is_singular && (!defined('PODS_SHORTCODE_ALLOW_USER_EDIT') || !PODS_SHORTCODE_ALLOW_USER_EDIT)) {
                return '';
            }
        }
        return $pod->form($tags['fields'], $tags['label'], $tags['thank_you']);
    } elseif (!empty($tags['field'])) {
        if (empty($tags['helper'])) {
            $return = $pod->display($tags['field']);
        } else {
            $return = $pod->helper($tags['helper'], $pod->field($tags['field']), $tags['field']);
        }
        if ($tags['shortcodes'] && defined('PODS_SHORTCODE_ALLOW_SUB_SHORTCODES') && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES) {
            $return = do_shortcode($return);
        }
        return $return;
    } elseif (!empty($tags['pods_page']) && class_exists('Pods_Pages')) {
        $pods_page = Pods_Pages::exists($tags['pods_page']);
        if (empty($pods_page)) {
            return '<p>Pods Page not found</p>';
        }
        $return = Pods_Pages::content(true, $pods_page);
        if ($tags['shortcodes'] && defined('PODS_SHORTCODE_ALLOW_SUB_SHORTCODES') && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES) {
            $return = do_shortcode($return);
        }
        return $return;
    }
    ob_start();
    if (!$is_singular && false !== $tags['filters'] && 'before' == $tags['filters_location']) {
        echo $pod->filters($tags['filters'], $tags['filters_label']);
    }
    if (!$is_singular && 0 < $found && true === $tags['pagination'] && in_array($tags['pagination_location'], array('before', 'both'))) {
        echo $pod->pagination($tags['pagination_label']);
    }
    echo $pod->template($tags['template'], $content);
    if (!$is_singular && 0 < $found && true === $tags['pagination'] && in_array($tags['pagination_location'], array('after', 'both'))) {
        echo $pod->pagination($tags['pagination_label']);
    }
    if (!$is_singular && false !== $tags['filters'] && 'after' == $tags['filters_location']) {
        echo $pod->filters($tags['filters'], $tags['filters_label']);
    }
    $return = ob_get_clean();
    if ($tags['shortcodes'] && defined('PODS_SHORTCODE_ALLOW_SUB_SHORTCODES') && PODS_SHORTCODE_ALLOW_SUB_SHORTCODES) {
        $return = do_shortcode($return);
    }
    return $return;
}
Ejemplo n.º 5
0
 /**
  * Run any precode for current Pod Page
  */
 public function precode()
 {
     global $pods;
     // Fix any global confusion wherever this runs
     if (isset($pods) && !isset($GLOBALS['pods'])) {
         $GLOBALS['pods'] =& $pods;
     } elseif (!isset($pods) && isset($GLOBALS['pods'])) {
         $pods =& $GLOBALS['pods'];
     }
     if (false !== self::$exists) {
         $permission = pods_permission(self::$exists['options']);
         $permission = (bool) apply_filters('pods_pages_permission', $permission, self::$exists);
         if ($permission) {
             $content = false;
             if (!is_object($pods) && 404 != $pods && 0 < strlen(pods_var('pod', self::$exists['options']))) {
                 $slug = pods_var_raw('pod_slug', self::$exists['options'], null, null, true);
                 // Handle special magic tags
                 if (0 < strlen($slug)) {
                     $slug = pods_evaluate_tags($slug, true);
                 }
                 $pods = pods(pods_var('pod', self::$exists['options']), $slug);
                 // Auto 404 handling if item doesn't exist
                 if (0 < strlen($slug) && !$pods->exists() && apply_filters('pods_pages_auto_404', true, $slug, $pods, self::$exists)) {
                     $pods = 404;
                 }
             }
             if (0 < strlen(trim(self::$exists['precode']))) {
                 $content = self::$exists['precode'];
             }
             if (false !== $content && (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL)) {
                 pods_deprecated('Pod Page Precode has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1');
                 eval("?>{$content}");
             }
             do_action('pods_page_precode', self::$exists, $pods, $content);
         } elseif (self::$exists['options']['restrict_redirect']) {
             $redirect_url = '';
             if (self::$exists['options']['restrict_redirect_login']) {
                 $redirect_url = wp_login_url(pods_current_url());
             } elseif (!empty(self::$exists['options']['restrict_redirect_url'])) {
                 $redirect_url = self::$exists['options']['restrict_redirect_url'];
             }
             if (!empty($redirect_url)) {
                 wp_redirect($redirect_url);
                 die;
             }
         }
         if (!$permission || !is_object($pods) && (404 == $pods || is_wp_error($pods))) {
             remove_action('template_redirect', array($this, 'template_redirect'));
             remove_action('wp_head', array($this, 'wp_head'));
             remove_filter('redirect_canonical', '__return_false');
             remove_filter('wp_title', array($this, 'wp_title'));
             remove_filter('body_class', array($this, 'body_class'));
             remove_filter('status_header', array($this, 'status_header'));
             remove_action('wp', array($this, 'silence_404'), 1);
         }
     }
 }
 /**
  * Get data from relationship objects
  *
  * @param array $object_params Object data parameters
  *
  * @return array|bool Object data
  */
 public function get_object_data($object_params = null)
 {
     global $wpdb, $polylang, $sitepress, $icl_adjust_id_url_filter_off;
     $current_language = false;
     // WPML support
     if (is_object($sitepress) && !$icl_adjust_id_url_filter_off) {
         $current_language = pods_sanitize(ICL_LANGUAGE_CODE);
     } elseif (function_exists('pll_current_language')) {
         $current_language = pll_current_language('slug');
     }
     $object_params = array_merge(array('name' => '', 'value' => '', 'options' => array(), 'pod' => '', 'id' => '', 'context' => '', 'data_params' => array('query' => ''), 'page' => 1, 'limit' => 0), $object_params);
     $name = $object_params['name'];
     $value = $object_params['value'];
     $options = $object_params['options'] = (array) $object_params['options'];
     $pod = $object_params['pod'];
     $id = $object_params['id'];
     $context = $object_params['context'];
     $data_params = $object_params['data_params'] = (array) $object_params['data_params'];
     $page = min(1, (int) $object_params['page']);
     $limit = (int) $object_params['limit'];
     if (isset($options['options'])) {
         $options = array_merge($options, $options['options']);
         unset($options['options']);
     }
     $data = apply_filters('pods_field_pick_object_data', null, $name, $value, $options, $pod, $id, $object_params);
     $items = array();
     if (!isset($options[self::$type . '_object'])) {
         $data = pods_var_raw('data', $options, array(), null, true);
     }
     $simple = false;
     if (null === $data) {
         $data = array();
         if ('custom-simple' == $options[self::$type . '_object']) {
             $custom = pods_var_raw(self::$type . '_custom', $options, '');
             $custom = apply_filters('pods_form_ui_field_pick_custom_values', $custom, $name, $value, $options, $pod, $id, $object_params);
             if (!empty($custom)) {
                 if (!is_array($custom)) {
                     $data = array();
                     $custom = explode("\n", trim($custom));
                     foreach ($custom as $custom_value) {
                         $custom_label = explode('|', $custom_value);
                         if (empty($custom_label)) {
                             continue;
                         }
                         if (1 == count($custom_label)) {
                             $custom_label = $custom_value;
                         } else {
                             $custom_value = $custom_label[0];
                             $custom_label = $custom_label[1];
                         }
                         $custom_value = trim((string) $custom_value);
                         $custom_label = trim((string) $custom_label);
                         $data[$custom_value] = $custom_label;
                     }
                 } else {
                     $data = $custom;
                 }
                 $simple = true;
             }
         } elseif (isset(self::$related_objects[$options[self::$type . '_object']]) && isset(self::$related_objects[$options[self::$type . '_object']]['data']) && !empty(self::$related_objects[$options[self::$type . '_object']]['data'])) {
             $data = self::$related_objects[$options[self::$type . '_object']]['data'];
             $simple = true;
         } elseif (isset(self::$related_objects[$options[self::$type . '_object']]) && isset(self::$related_objects[$options[self::$type . '_object']]['data_callback']) && is_callable(self::$related_objects[$options[self::$type . '_object']]['data_callback'])) {
             $data = call_user_func_array(self::$related_objects[$options[self::$type . '_object']]['data_callback'], array($name, $value, $options, $pod, $id));
             $simple = true;
             // Cache data from callback
             if (!empty($data)) {
                 self::$related_objects[$options[self::$type . '_object']]['data'] = $data;
             }
         } elseif ('simple_value' != $context) {
             $pick_val = pods_var(self::$type . '_val', $options);
             if ('table' == pods_var(self::$type . '_object', $options)) {
                 $pick_val = pods_var(self::$type . '_table', $options, $pick_val, null, true);
             }
             if ('__current__' == $pick_val) {
                 if (is_object($pod)) {
                     $pick_val = $pod->pod;
                 } elseif (is_array($pod)) {
                     $pick_val = $pod['name'];
                 } elseif (0 < strlen($pod)) {
                     $pick_val = $pod;
                 }
             }
             $options['table_info'] = pods_api()->get_table_info(pods_var(self::$type . '_object', $options), $pick_val, null, null, $options);
             $search_data = pods_data();
             $search_data->table($options['table_info']);
             if (isset($options['table_info']['pod']) && !empty($options['table_info']['pod']) && isset($options['table_info']['pod']['name'])) {
                 $search_data->pod = $options['table_info']['pod']['name'];
                 $search_data->fields = $options['table_info']['pod']['fields'];
             }
             $params = array('select' => "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`", 'table' => $search_data->table, 'where' => pods_var_raw(self::$type . '_where', $options, (array) $options['table_info']['where_default'], null, true), 'orderby' => pods_var_raw(self::$type . '_orderby', $options, null, null, true), 'groupby' => pods_var_raw(self::$type . '_groupby', $options, null, null, true), 'pagination' => false, 'search' => false);
             if (in_array($options[self::$type . '_object'], array('site', 'network'))) {
                 $params['select'] .= ', `t`.`path`';
             }
             if (!empty($params['where']) && (array) $options['table_info']['where_default'] != $params['where']) {
                 $params['where'] = pods_evaluate_tags($params['where'], true);
             }
             if (empty($params['where']) || !is_array($params['where']) && strlen(trim($params['where'])) < 1) {
                 $params['where'] = array();
             } elseif (!is_array($params['where'])) {
                 $params['where'] = (array) $params['where'];
             }
             if ('value_to_label' == $context) {
                 $params['where'][] = "`t`.`{$search_data->field_id}` = " . number_format($value, 0, '', '');
             }
             /* not needed yet
                             if ( !empty( $params[ 'orderby' ] ) )
                                 $params[ 'orderby' ] = pods_evaluate_tags( $params[ 'orderby' ], true );
             
                             if ( !empty( $params[ 'groupby' ] ) )
                                 $params[ 'groupby' ] = pods_evaluate_tags( $params[ 'groupby' ], true );*/
             $display = trim(pods_var(self::$type . '_display', $options), ' {@}');
             if (0 < strlen($display)) {
                 if (isset($options['table_info']['pod']) && !empty($options['table_info']['pod'])) {
                     if (isset($options['table_info']['pod']['object_fields']) && isset($options['table_info']['pod']['object_fields'][$display])) {
                         $search_data->field_index = $display;
                         $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
                     } elseif (isset($options['table_info']['pod']['fields'][$display])) {
                         $search_data->field_index = $display;
                         if ('table' == $options['table_info']['pod']['storage'] && !in_array($options['table_info']['pod']['type'], array('pod', 'table'))) {
                             $params['select'] = "`t`.`{$search_data->field_id}`, `d`.`{$search_data->field_index}`";
                         } elseif ('meta' == $options['table_info']['pod']['storage']) {
                             $params['select'] = "`t`.`{$search_data->field_id}`, `{$search_data->field_index}`.`meta_value` AS {$search_data->field_index}";
                         } else {
                             $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
                         }
                     }
                 } elseif (isset($options['table_info']['object_fields']) && isset($options['table_info']['object_fields'][$display])) {
                     $search_data->field_index = $display;
                     $params['select'] = "`t`.`{$search_data->field_id}`, `t`.`{$search_data->field_index}`";
                 }
             }
             $autocomplete = false;
             if ('single' == pods_var(self::$type . '_format_type', $options, 'single') && 'autocomplete' == pods_var(self::$type . '_format_single', $options, 'dropdown')) {
                 $autocomplete = true;
             } elseif ('multi' == pods_var(self::$type . '_format_type', $options, 'single') && 'autocomplete' == pods_var(self::$type . '_format_multi', $options, 'checkbox')) {
                 $autocomplete = true;
             }
             $hierarchy = false;
             if ('data' == $context && !$autocomplete) {
                 if ('single' == pods_var(self::$type . '_format_type', $options, 'single') && in_array(pods_var(self::$type . '_format_single', $options, 'dropdown'), array('dropdown', 'radio'))) {
                     $hierarchy = true;
                 } elseif ('multi' == pods_var(self::$type . '_format_type', $options, 'single') && in_array(pods_var(self::$type . '_format_multi', $options, 'checkbox'), array('multiselect', 'checkbox'))) {
                     $hierarchy = true;
                 }
             }
             if ($hierarchy && $options['table_info']['object_hierarchical'] && !empty($options['table_info']['field_parent'])) {
                 $params['select'] .= ', ' . $options['table_info']['field_parent_select'];
             }
             if ($autocomplete) {
                 if (0 == $limit) {
                     $limit = 30;
                 }
                 $params['limit'] = apply_filters('pods_form_ui_field_pick_autocomplete_limit', $limit, $name, $value, $options, $pod, $id, $object_params);
                 if (is_array($value) && $params['limit'] < count($value)) {
                     $params['limit'] = count($value);
                 }
                 $params['page'] = $page;
                 if ('admin_ajax_relationship' == $context) {
                     $lookup_where = array($search_data->field_index => "`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'");
                     // @todo Hook into WPML for each table
                     if ($wpdb->users == $search_data->table) {
                         $lookup_where['display_name'] = "`t`.`display_name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['user_login'] = "******" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['user_email'] = "`t`.`user_email` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                     } elseif ($wpdb->posts == $search_data->table) {
                         $lookup_where['post_title'] = "`t`.`post_title` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['post_name'] = "`t`.`post_name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['post_content'] = "`t`.`post_content` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['post_excerpt'] = "`t`.`post_excerpt` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                     } elseif ($wpdb->terms == $search_data->table) {
                         $lookup_where['name'] = "`t`.`name` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['slug'] = "`t`.`slug` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                     } elseif ($wpdb->comments == $search_data->table) {
                         $lookup_where['comment_content'] = "`t`.`comment_content` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['comment_author'] = "`t`.`comment_author` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                         $lookup_where['comment_author_email'] = "`t`.`comment_author_email` LIKE '%" . pods_sanitize_like($data_params['query']) . "%'";
                     }
                     $lookup_where = apply_filters('pods_form_ui_field_pick_autocomplete_lookup', $lookup_where, $data_params['query'], $name, $value, $options, $pod, $id, $object_params, $search_data);
                     if (!empty($lookup_where)) {
                         $params['where'][] = implode(' OR ', $lookup_where);
                     }
                     $orderby = array();
                     $orderby[] = "(`t`.`{$search_data->field_index}` LIKE '%" . pods_sanitize_like($data_params['query']) . "%' ) DESC";
                     $pick_orderby = pods_var_raw(self::$type . '_orderby', $options, null, null, true);
                     if (0 < strlen($pick_orderby)) {
                         $orderby[] = $pick_orderby;
                     }
                     $orderby[] = "`t`.`{$search_data->field_index}`";
                     $orderby[] = "`t`.`{$search_data->field_id}`";
                     $params['orderby'] = $orderby;
                 }
             } elseif (0 < $limit) {
                 $params['limit'] = $limit;
                 $params['page'] = $page;
             }
             $extra = '';
             if ($wpdb->posts == $search_data->table) {
                 $extra = ', `t`.`post_type`';
             } elseif ($wpdb->terms == $search_data->table) {
                 $extra = ', `tt`.`taxonomy`';
             } elseif ($wpdb->comments == $search_data->table) {
                 $extra = ', `t`.`comment_type`';
             }
             $params['select'] .= $extra;
             if ('user' == pods_var(self::$type . '_object', $options)) {
                 $roles = pods_var(self::$type . '_user_role', $options);
                 if (!empty($roles)) {
                     $where = array();
                     foreach ((array) $roles as $role) {
                         if (empty($role) || pods_clean_name($role) != $role && sanitize_title($role) != $role) {
                             continue;
                         }
                         $where[] = $wpdb->base_prefix . (is_multisite() && !is_main_site() ? get_current_blog_id() . '_' : '') . 'capabilities.meta_value LIKE "%\\"' . pods_sanitize_like($role) . '\\"%"';
                     }
                     if (!empty($where)) {
                         $params['where'][] = implode(' OR ', $where);
                     }
                 }
             }
             $results = $search_data->select($params);
             if ($autocomplete && $params['limit'] < $search_data->total_found()) {
                 if (!empty($value)) {
                     $ids = $value;
                     if (is_array($ids) && isset($ids[0]) && is_array($ids[0])) {
                         $ids = wp_list_pluck($ids, $search_data->field_id);
                     }
                     if (is_array($ids)) {
                         $ids = implode(', ', $ids);
                     }
                     if (is_array($params['where'])) {
                         $params['where'] = implode(' AND ', $params['where']);
                     }
                     if (!empty($params['where'])) {
                         $params['where'] .= ' AND ';
                     }
                     $params['where'] .= "`t`.`{$search_data->field_id}` IN ( " . $ids . " )";
                     $results = $search_data->select($params);
                 }
             } else {
                 $autocomplete = false;
             }
             if ('data' == $context) {
                 self::$field_data = array('field' => $name, 'id' => $options['id'], 'autocomplete' => $autocomplete);
             }
             if ($hierarchy && !$autocomplete && !empty($results) && $options['table_info']['object_hierarchical'] && !empty($options['table_info']['field_parent'])) {
                 $args = array('id' => $options['table_info']['field_id'], 'index' => $options['table_info']['field_index'], 'parent' => $options['table_info']['field_parent']);
                 $results = pods_hierarchical_select($results, $args);
             }
             $ids = array();
             if (!empty($results)) {
                 $display_filter = pods_var('display_filter', pods_var_raw('options', pods_var_raw($search_data->field_index, $search_data->pod_data['object_fields'])));
                 foreach ($results as $result) {
                     $result = get_object_vars($result);
                     if (!isset($result[$search_data->field_id]) || !isset($result[$search_data->field_index])) {
                         continue;
                     }
                     $result[$search_data->field_index] = trim($result[$search_data->field_index]);
                     $object = $object_type = '';
                     if ($wpdb->posts == $search_data->table && isset($result['post_type'])) {
                         $object = $result['post_type'];
                         $object_type = 'post_type';
                     } elseif ($wpdb->terms == $search_data->table && isset($result['taxonomy'])) {
                         $object = $result['taxonomy'];
                         $object_type = 'taxonomy';
                     }
                     // WPML integration for Post Types and Taxonomies
                     if (is_object($sitepress) && in_array($object_type, array('post_type', 'taxonomy'))) {
                         $translated = false;
                         if ('post_type' == $object_type && $sitepress->is_translated_post_type($object)) {
                             $translated = true;
                         } elseif ('taxonomy' == $object_type && $sitepress->is_translated_taxonomy($object)) {
                             $translated = true;
                         }
                         if ($translated) {
                             $object_id = icl_object_id($result[$search_data->field_id], $object, false, $current_language);
                             if (0 < $object_id && !in_array($object_id, $ids)) {
                                 $text = $result[$search_data->field_index];
                                 if ($result[$search_data->field_id] != $object_id) {
                                     if ($wpdb->posts == $search_data->table) {
                                         $text = trim(get_the_title($object_id));
                                     } elseif ($wpdb->terms == $search_data->table) {
                                         $text = trim(get_term($object_id, $object)->name);
                                     }
                                 }
                                 $result[$search_data->field_id] = $object_id;
                                 $result[$search_data->field_index] = $text;
                             } else {
                                 continue;
                             }
                         }
                     } elseif (is_object($polylang) && in_array($object_type, array('post_type', 'taxonomy')) && method_exists($polylang, 'get_translation')) {
                         $translated = false;
                         if ('post_type' == $object_type && pll_is_translated_post_type($object)) {
                             $translated = true;
                         } elseif ('taxonomy' == $object_type && pll_is_translated_taxonomy($object)) {
                             $translated = true;
                         }
                         if ($translated) {
                             $object_id = $polylang->get_translation($object, $result[$search_data->field_id], $current_language);
                             if (0 < $object_id && !in_array($object_id, $ids)) {
                                 $text = $result[$search_data->field_index];
                                 if ($result[$search_data->field_id] != $object_id) {
                                     if ($wpdb->posts == $search_data->table) {
                                         $text = trim(get_the_title($object_id));
                                     } elseif ($wpdb->terms == $search_data->table) {
                                         $text = trim(get_term($object_id, $object)->name);
                                     }
                                 }
                                 $result[$search_data->field_id] = $object_id;
                                 $result[$search_data->field_index] = $text;
                             } else {
                                 continue;
                             }
                         }
                     }
                     if (0 < strlen($display_filter)) {
                         $display_filter_args = pods_var('display_filter_args', pods_var_raw('options', pods_var_raw($search_data->field_index, $search_data->pod_data['object_fields'])));
                         $args = array($display_filter, $result[$search_data->field_index]);
                         if (!empty($display_filter_args)) {
                             foreach ((array) $display_filter_args as $display_filter_arg) {
                                 if (isset($result[$display_filter_arg])) {
                                     $args[] = $result[$display_filter_arg];
                                 }
                             }
                         }
                         $result[$search_data->field_index] = call_user_func_array('apply_filters', $args);
                     }
                     if (in_array($options[self::$type . '_object'], array('site', 'network'))) {
                         $result[$search_data->field_index] = $result[$search_data->field_index] . $result['path'];
                     } elseif (strlen($result[$search_data->field_index]) < 1) {
                         $result[$search_data->field_index] = '(No Title)';
                     }
                     if ('admin_ajax_relationship' == $context) {
                         $items[] = array('id' => $result[$search_data->field_id], 'text' => $result[$search_data->field_index], 'image' => '');
                     } else {
                         $data[$result[$search_data->field_id]] = $result[$search_data->field_index];
                     }
                     $ids[] = $result[$search_data->field_id];
                 }
             }
         }
         if ($simple && 'admin_ajax_relationship' == $context) {
             $found_data = array();
             foreach ($data as $k => $v) {
                 if (false !== stripos($v, $data_params['query']) || false !== stripos($k, $data_params['query'])) {
                     $found_data[$k] = $v;
                 }
             }
             $data = $found_data;
         }
     }
     if ('admin_ajax_relationship' == $context) {
         if (empty($items) && !empty($data)) {
             foreach ($data as $k => $v) {
                 $items[] = array('id' => $k, 'text' => $v, 'image' => '');
             }
         }
         return $items;
     }
     return $data;
 }
Ejemplo n.º 7
0
 /**
  * @static
  *
  * @param string         $view       Path of the view file
  * @param array|null     $data       (optional) Data to pass on to the template
  * @param bool|int|array $expires    (optional) Time in seconds for the cache to expire, if 0 no expiration.
  * @param string         $cache_mode (optional) Decides the caching method to use for the view.
  *
  * @return bool|mixed|null|string|void
  *
  * @since 2.0
  */
 public static function view($view, $data = null, $expires = false, $cache_mode = 'cache')
 {
     /**
      * Override the value of $view. For example, using Pods AJAX View.
      *
      * To use, set first param to true. If that param in not null, this method returns its value.
      *
      * @param null|bool      If          not set to null, this filter overrides the rest of the method.
      * @param string         $view       Path of the view file
      * @param array|null     $data       (optional) Data to pass on to the template
      * @param bool|int|array $expires    (optional) Time in seconds for the cache to expire, if 0 no expiration.
      * @param string         $cache_mode (optional) Decides the caching method to use for the view.
      *
      * @returns The value of the first param.
      *
      * @since 2.4.1
      */
     $filter_check = apply_filters('pods_view_alt_view', null, $view, $data, $expires, $cache_mode);
     if (!is_null($filter_check)) {
         return $filter_check;
     }
     // Advanced $expires handling
     $expires = self::expires($expires, $cache_mode);
     if (!in_array($cache_mode, self::$cache_modes)) {
         $cache_mode = 'cache';
     }
     // Support my-view.php?custom-key=X#hash keying for cache
     $view_id = '';
     if (!is_array($view)) {
         $view_q = explode('?', $view);
         if (1 < count($view_q)) {
             $view_id = '?' . $view_q[1];
             $view = $view_q[0];
         }
         $view_h = explode('#', $view);
         if (1 < count($view_h)) {
             $view_id .= '#' . $view_h[1];
             $view = $view_h[0];
         }
         // Support dynamic tags!
         $view_id = pods_evaluate_tags($view_id);
     }
     $view = apply_filters('pods_view_inc', $view, $data, $expires, $cache_mode);
     $view_key = $view;
     if (is_array($view_key)) {
         $view_key = implode('-', $view_key) . '.php';
     }
     if (false !== realpath($view_key)) {
         $view_key = realpath($view_key);
     }
     $pods_ui_dir = realpath(PODS_DIR . 'ui/');
     $pods_components_dir = realpath(PODS_DIR . 'components/');
     $abspath_dir = realpath(ABSPATH);
     $cache_key = pods_str_replace($abspath_dir, '/', $view_key, 1);
     $output = false;
     $caching = false;
     if (false !== $expires && false === strpos($view_key, $pods_ui_dir) && false === strpos($view_key, $pods_components_dir)) {
         $caching = true;
     }
     if ($caching) {
         $output = self::get('pods-view-' . $cache_key . $view_id, $cache_mode, 'pods_view');
     }
     if (false === $output || null === $output) {
         $output = self::get_template_part($view, $data);
     }
     if (false !== $output && $caching) {
         self::set('pods-view-' . $cache_key . $view_id, $output, $expires, $cache_mode, 'pods_view');
     }
     $output = apply_filters('pods_view_output_' . $cache_key, $output, $view, $data, $expires, $cache_mode);
     $output = apply_filters('pods_view_output', $output, $view, $data, $expires, $cache_mode);
     return $output;
 }
/**
 * Evaluate tags like magic tags but through pods_var
 *
 * @param string|array|object $tags String to be evaluated
 * @param bool $sanitize Whether to sanitize tags
 *
 * @return string
 *
 * @version 2.1
 *
 * @see pods_evaluate_tag
 */
function pods_evaluate_tags($tags, $sanitize = false)
{
    if (is_array($tags)) {
        foreach ($tags as $k => $tag) {
            $tags[$k] = pods_evaluate_tags($tag, $sanitize);
        }
        return $tags;
    } elseif (is_object($tags)) {
        $tags = get_object_vars($tags);
        foreach ($tags as $k => $tag) {
            $tags[$k] = pods_evaluate_tags($tag, $sanitize);
        }
        $tags = (object) $tags;
        return $tags;
    }
    $callback = 'pods_evaluate_tag';
    if (true === $sanitize) {
        $callback = 'pods_evaluate_tag_sanitized';
    }
    return preg_replace_callback('/({@(.*?)})/m', $callback, (string) $tags);
}
Ejemplo n.º 9
0
 /**
  * Register Post Types and Taxonomies
  */
 public function setup_content_types($force = false)
 {
     $post_types = PodsMeta::$post_types;
     $taxonomies = PodsMeta::$taxonomies;
     $existing_post_types = get_post_types();
     $existing_taxonomies = get_taxonomies();
     $pods_cpt_ct = pods_transient_get('pods_wp_cpt_ct');
     $cpt_positions = array();
     if (empty($pods_cpt_ct) && (!empty($post_types) || !empty($taxonomies))) {
         $force = true;
     } elseif (!empty($pods_cpt_ct) && empty($pods_cpt_ct['post_types']) && !empty($post_types)) {
         $force = true;
     } elseif (!empty($pods_cpt_ct) && empty($pods_cpt_ct['taxonomies']) && !empty($taxonomies)) {
         $force = true;
     }
     if (false === $pods_cpt_ct || $force) {
         /**
          * @var WP_Query
          */
         global $wp_query;
         $reserved_query_vars = array('post_type', 'taxonomy', 'output');
         if (is_object($wp_query)) {
             $reserved_query_vars = array_merge($reserved_query_vars, array_keys($wp_query->fill_query_vars(array())));
         }
         $pods_cpt_ct = array('post_types' => array(), 'taxonomies' => array());
         $pods_post_types = $pods_taxonomies = array();
         $supported_post_types = $supported_taxonomies = array();
         foreach ($post_types as $post_type) {
             // Post Type exists already
             if (isset($pods_cpt_ct['post_types'][$post_type['name']])) {
                 continue;
             } elseif (!empty($post_type['object']) && isset($existing_post_types[$post_type['object']])) {
                 continue;
             } elseif (!$force && isset($existing_post_types[$post_type['name']])) {
                 continue;
             }
             $post_type['options']['name'] = $post_type['name'];
             $post_type = array_merge($post_type, (array) $post_type['options']);
             $post_type_name = pods_var('name', $post_type);
             // Labels
             $cpt_label = esc_html(pods_var_raw('label', $post_type, ucwords(str_replace('_', ' ', pods_var_raw('name', $post_type))), null, true));
             $cpt_singular = esc_html(pods_var_raw('label_singular', $post_type, ucwords(str_replace('_', ' ', pods_var_raw('label', $post_type, $post_type_name, null, true))), null, true));
             $cpt_labels = array();
             $cpt_labels['name'] = $cpt_label;
             $cpt_labels['singular_name'] = $cpt_singular;
             $cpt_labels['menu_name'] = pods_var_raw('menu_name', $post_type, '', null, true);
             $cpt_labels['add_new'] = pods_var_raw('label_add_new', $post_type, '', null, true);
             $cpt_labels['add_new_item'] = pods_var_raw('label_add_new_item', $post_type, '', null, true);
             $cpt_labels['new_item'] = pods_var_raw('label_new_item', $post_type, '', null, true);
             $cpt_labels['edit'] = pods_var_raw('label_edit', $post_type, '', null, true);
             $cpt_labels['edit_item'] = pods_var_raw('label_edit_item', $post_type, '', null, true);
             $cpt_labels['view'] = pods_var_raw('label_view', $post_type, '', null, true);
             $cpt_labels['view_item'] = pods_var_raw('label_view_item', $post_type, '', null, true);
             $cpt_labels['all_items'] = pods_var_raw('label_all_items', $post_type, '', null, true);
             $cpt_labels['search_items'] = pods_var_raw('label_search_items', $post_type, '', null, true);
             $cpt_labels['not_found'] = pods_var_raw('label_not_found', $post_type, '', null, true);
             $cpt_labels['not_found_in_trash'] = pods_var_raw('label_not_found_in_trash', $post_type, '', null, true);
             $cpt_labels['parent'] = pods_var_raw('label_parent', $post_type, '', null, true);
             $cpt_labels['parent_item_colon'] = pods_var_raw('label_parent_item_colon', $post_type, '', null, true);
             // Supported
             $cpt_supported = array('title' => (bool) pods_var('supports_title', $post_type, false), 'editor' => (bool) pods_var('supports_editor', $post_type, false), 'author' => (bool) pods_var('supports_author', $post_type, false), 'thumbnail' => (bool) pods_var('supports_thumbnail', $post_type, false), 'excerpt' => (bool) pods_var('supports_excerpt', $post_type, false), 'trackbacks' => (bool) pods_var('supports_trackbacks', $post_type, false), 'custom-fields' => (bool) pods_var('supports_custom_fields', $post_type, false), 'comments' => (bool) pods_var('supports_comments', $post_type, false), 'revisions' => (bool) pods_var('supports_revisions', $post_type, false), 'page-attributes' => (bool) pods_var('supports_page_attributes', $post_type, false), 'post-formats' => (bool) pods_var('supports_post_formats', $post_type, false));
             // Custom Supported
             $cpt_supported_custom = pods_var('supports_custom', $post_type, '');
             if (!empty($cpt_supported_custom)) {
                 $cpt_supported_custom = explode(',', $cpt_supported_custom);
                 $cpt_supported_custom = array_filter(array_unique($cpt_supported_custom));
                 foreach ($cpt_supported_custom as $cpt_support) {
                     $cpt_supported[$cpt_support] = true;
                 }
             }
             // Genesis Support
             if (function_exists('genesis')) {
                 $cpt_supported['genesis-seo'] = (bool) pods_var('supports_genesis_seo', $post_type, false);
                 $cpt_supported['genesis-layouts'] = (bool) pods_var('supports_genesis_layouts', $post_type, false);
                 $cpt_supported['genesis-simple-sidebars'] = (bool) pods_var('supports_genesis_simple_sidebars', $post_type, false);
             }
             // YARPP Support
             if (defined('YARPP_VERSION')) {
                 $cpt_supported['yarpp_support'] = (bool) pods_var('supports_yarpp_support', $post_type, false);
             }
             // Jetpack Support
             if (class_exists('Jetpack')) {
                 $cpt_supported['supports_jetpack_publicize'] = (bool) pods_var('supports_jetpack_publicize', $post_type, false);
                 $cpt_supported['supports_jetpack_markdown'] = (bool) pods_var('supports_jetpack_markdown', $post_type, false);
             }
             // WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :(
             $cpt_supports = array();
             if (!pods_version_check('wp', '3.5')) {
                 $cpt_supports = array('_bug_fix_pre_35');
             }
             foreach ($cpt_supported as $cpt_support => $supported) {
                 if (true === $supported) {
                     $cpt_supports[] = $cpt_support;
                 }
             }
             if (empty($cpt_supports) && pods_version_check('wp', '3.5')) {
                 $cpt_supports = false;
             }
             // Rewrite
             $cpt_rewrite = (bool) pods_var('rewrite', $post_type, true);
             $cpt_rewrite_array = array('slug' => pods_var('rewrite_custom_slug', $post_type, str_replace('_', '-', $post_type_name), null, true), 'with_front' => (bool) pods_var('rewrite_with_front', $post_type, true), 'feeds' => (bool) pods_var('rewrite_feeds', $post_type, (bool) pods_var('has_archive', $post_type, false)), 'pages' => (bool) pods_var('rewrite_pages', $post_type, true));
             if (false !== $cpt_rewrite) {
                 $cpt_rewrite = $cpt_rewrite_array;
             }
             $capability_type = pods_var('capability_type', $post_type, 'post');
             if ('custom' == $capability_type) {
                 $capability_type = pods_var('capability_type_custom', $post_type, 'post');
             }
             $show_in_menu = (bool) pods_var('show_in_menu', $post_type, true);
             if ($show_in_menu && 0 < strlen(pods_var_raw('menu_location_custom', $post_type))) {
                 $show_in_menu = pods_var_raw('menu_location_custom', $post_type);
             }
             $menu_icon = pods_var('menu_icon', $post_type, null, null, true);
             if (!empty($menu_icon)) {
                 $menu_icon = pods_evaluate_tags($menu_icon);
             }
             // Register Post Type
             $pods_post_types[$post_type_name] = array('label' => $cpt_label, 'labels' => $cpt_labels, 'description' => esc_html(pods_var_raw('description', $post_type)), 'public' => (bool) pods_var('public', $post_type, true), 'publicly_queryable' => (bool) pods_var('publicly_queryable', $post_type, (bool) pods_var('public', $post_type, true)), 'exclude_from_search' => (bool) pods_var('exclude_from_search', $post_type, (bool) pods_var('public', $post_type, true) ? false : true), 'show_ui' => (bool) pods_var('show_ui', $post_type, (bool) pods_var('public', $post_type, true)), 'show_in_menu' => $show_in_menu, 'show_in_nav_menus' => (bool) pods_var('show_in_nav_menus', $post_type, (bool) pods_var('public', $post_type, true)), 'show_in_admin_bar' => (bool) pods_var('show_in_admin_bar', $post_type, (bool) pods_var('show_in_menu', $post_type, true)), 'menu_position' => (int) pods_var('menu_position', $post_type, 0, null, true), 'menu_icon' => $menu_icon, 'capability_type' => $capability_type, 'map_meta_cap' => (bool) pods_var('capability_type_extra', $post_type, true), 'hierarchical' => (bool) pods_var('hierarchical', $post_type, false), 'supports' => $cpt_supports, 'has_archive' => pods_v('has_archive_slug', $post_type, (bool) pods_v('has_archive', $post_type, false), true), 'rewrite' => $cpt_rewrite, 'query_var' => false !== (bool) pods_var('query_var', $post_type, true) ? pods_var('query_var_string', $post_type, $post_type_name, null, true) : false, 'can_export' => (bool) pods_var('can_export', $post_type, true));
             // YARPP doesn't use 'supports' array option (yet)
             if (!empty($cpt_supports['yarpp_support'])) {
                 $pods_post_types[$post_type_name]['yarpp_support'] = true;
             }
             // Prevent reserved query_var issues
             if (in_array($pods_post_types[$post_type_name]['query_var'], $reserved_query_vars)) {
                 $pods_post_types[$post_type_name]['query_var'] = 'post_type_' . $pods_post_types[$post_type_name]['query_var'];
             }
             if (25 == $pods_post_types[$post_type_name]['menu_position']) {
                 $pods_post_types[$post_type_name]['menu_position']++;
             }
             if ($pods_post_types[$post_type_name]['menu_position'] < 1 || in_array($pods_post_types[$post_type_name]['menu_position'], $cpt_positions)) {
                 unset($pods_post_types[$post_type_name]['menu_position']);
             } else {
                 $cpt_positions[] = $pods_post_types[$post_type_name]['menu_position'];
                 // This would be nice if WP supported floats in menu_position
                 // $pods_post_types[ $post_type_name ][ 'menu_position' ] = $pods_post_types[ $post_type_name ][ 'menu_position' ] . '.1';
             }
             // Taxonomies
             $cpt_taxonomies = array();
             $_taxonomies = get_taxonomies();
             $_taxonomies = array_merge_recursive($_taxonomies, $pods_taxonomies);
             $ignore = array('nav_menu', 'link_category', 'post_format');
             foreach ($_taxonomies as $taxonomy => $label) {
                 if (in_array($taxonomy, $ignore)) {
                     continue;
                 }
                 if (false !== (bool) pods_var('built_in_taxonomies_' . $taxonomy, $post_type, false)) {
                     $cpt_taxonomies[] = $taxonomy;
                     if (isset($supported_post_types[$taxonomy]) && !in_array($post_type_name, $supported_post_types[$taxonomy])) {
                         $supported_post_types[$taxonomy][] = $post_type_name;
                     }
                 }
             }
             if (isset($supported_taxonomies[$post_type_name])) {
                 $supported_taxonomies[$post_type_name] = array_merge((array) $supported_taxonomies[$post_type_name], $cpt_taxonomies);
             } else {
                 $supported_taxonomies[$post_type_name] = $cpt_taxonomies;
             }
         }
         foreach ($taxonomies as $taxonomy) {
             // Taxonomy Type exists already
             if (isset($pods_cpt_ct['taxonomies'][$taxonomy['name']])) {
                 continue;
             } elseif (!empty($taxonomy['object']) && isset($existing_taxonomies[$taxonomy['object']])) {
                 continue;
             } elseif (!$force && isset($existing_taxonomies[$taxonomy['name']])) {
                 continue;
             }
             $taxonomy['options']['name'] = $taxonomy['name'];
             $taxonomy = array_merge($taxonomy, (array) $taxonomy['options']);
             $taxonomy_name = pods_var('name', $taxonomy);
             // Labels
             $ct_label = esc_html(pods_var_raw('label', $taxonomy, ucwords(str_replace('_', ' ', pods_var_raw('name', $taxonomy))), null, true));
             $ct_singular = esc_html(pods_var_raw('label_singular', $taxonomy, ucwords(str_replace('_', ' ', pods_var_raw('label', $taxonomy, pods_var_raw('name', $taxonomy), null, true))), null, true));
             $ct_labels = array();
             $ct_labels['name'] = $ct_label;
             $ct_labels['singular_name'] = $ct_singular;
             $ct_labels['menu_name'] = pods_var_raw('menu_name', $taxonomy, '', null, true);
             $ct_labels['search_items'] = pods_var_raw('label_search_items', $taxonomy, '', null, true);
             $ct_labels['popular_items'] = pods_var_raw('label_popular_items', $taxonomy, '', null, true);
             $ct_labels['all_items'] = pods_var_raw('label_all_items', $taxonomy, '', null, true);
             $ct_labels['parent_item'] = pods_var_raw('label_parent_item', $taxonomy, '', null, true);
             $ct_labels['parent_item_colon'] = pods_var_raw('label_parent_item_colon', $taxonomy, '', null, true);
             $ct_labels['edit_item'] = pods_var_raw('label_edit_item', $taxonomy, '', null, true);
             $ct_labels['update_item'] = pods_var_raw('label_update_item', $taxonomy, '', null, true);
             $ct_labels['add_new_item'] = pods_var_raw('label_add_new_item', $taxonomy, '', null, true);
             $ct_labels['new_item_name'] = pods_var_raw('label_new_item_name', $taxonomy, '', null, true);
             $ct_labels['separate_items_with_commas'] = pods_var_raw('label_separate_items_with_commas', $taxonomy, '', null, true);
             $ct_labels['add_or_remove_items'] = pods_var_raw('label_add_or_remove_items', $taxonomy, '', null, true);
             $ct_labels['choose_from_most_used'] = pods_var_raw('label_choose_from_the_most_used', $taxonomy, '', null, true);
             // Rewrite
             $ct_rewrite = (bool) pods_var('rewrite', $taxonomy, true);
             $ct_rewrite_array = array('slug' => pods_var('rewrite_custom_slug', $taxonomy, str_replace('_', '-', $taxonomy_name), null, true), 'with_front' => (bool) pods_var('rewrite_with_front', $taxonomy, true), 'hierarchical' => (bool) pods_var('rewrite_hierarchical', $taxonomy, (bool) pods_var('hierarchical', $taxonomy, false)));
             if (false !== $ct_rewrite) {
                 $ct_rewrite = $ct_rewrite_array;
             }
             // Register Taxonomy
             $pods_taxonomies[$taxonomy_name] = array('label' => $ct_label, 'labels' => $ct_labels, 'public' => (bool) pods_var('public', $taxonomy, true), 'show_in_nav_menus' => (bool) pods_var('show_in_nav_menus', $taxonomy, (bool) pods_var('public', $taxonomy, true)), 'show_ui' => (bool) pods_var('show_ui', $taxonomy, (bool) pods_var('public', $taxonomy, true)), 'show_tagcloud' => (bool) pods_var('show_tagcloud', $taxonomy, (bool) pods_var('show_ui', $taxonomy, (bool) pods_var('public', $taxonomy, true))), 'hierarchical' => (bool) pods_var('hierarchical', $taxonomy, false), 'update_count_callback' => pods_var('update_count_callback', $taxonomy, null, null, true), 'query_var' => false !== (bool) pods_var('query_var', $taxonomy, true) ? pods_var('query_var_string', $taxonomy, $taxonomy_name, null, true) : false, 'rewrite' => $ct_rewrite, 'show_admin_column' => (bool) pods_var('show_admin_column', $taxonomy, false), 'sort' => (bool) pods_var('sort', $taxonomy, false));
             if (is_array($ct_rewrite) && !$pods_taxonomies[$taxonomy_name]['query_var']) {
                 $pods_taxonomies[$taxonomy_name]['query_var'] = pods_var('query_var_string', $taxonomy, $taxonomy_name, null, true);
             }
             // Prevent reserved query_var issues
             if (in_array($pods_taxonomies[$taxonomy_name]['query_var'], $reserved_query_vars)) {
                 $pods_taxonomies[$taxonomy_name]['query_var'] = 'taxonomy_' . $pods_taxonomies[$taxonomy_name]['query_var'];
             }
             // Integration for Single Value Taxonomy UI
             if (function_exists('tax_single_value_meta_box')) {
                 $pods_taxonomies[$taxonomy_name]['single_value'] = (bool) pods_var('single_value', $taxonomy, false);
                 $pods_taxonomies[$taxonomy_name]['required'] = (bool) pods_var('single_value_required', $taxonomy, false);
             }
             // Post Types
             $ct_post_types = array();
             $_post_types = get_post_types();
             $_post_types = array_merge_recursive($_post_types, $pods_post_types);
             $ignore = array('revision');
             foreach ($_post_types as $post_type => $options) {
                 if (in_array($post_type, $ignore)) {
                     continue;
                 }
                 if (false !== (bool) pods_var('built_in_post_types_' . $post_type, $taxonomy, false)) {
                     $ct_post_types[] = $post_type;
                     if (isset($supported_taxonomies[$post_type]) && !in_array($taxonomy_name, $supported_taxonomies[$post_type])) {
                         $supported_taxonomies[$post_type][] = $taxonomy_name;
                     }
                 }
             }
             if (isset($supported_post_types[$taxonomy_name])) {
                 $supported_post_types[$taxonomy_name] = array_merge($supported_post_types[$taxonomy_name], $ct_post_types);
             } else {
                 $supported_post_types[$taxonomy_name] = $ct_post_types;
             }
         }
         $pods_post_types = apply_filters('pods_wp_post_types', $pods_post_types);
         $pods_taxonomies = apply_filters('pods_wp_taxonomies', $pods_taxonomies);
         $supported_post_types = apply_filters('pods_wp_supported_post_types', $supported_post_types);
         $supported_taxonomies = apply_filters('pods_wp_supported_taxonomies', $supported_taxonomies);
         foreach ($pods_taxonomies as $taxonomy => $options) {
             $ct_post_types = null;
             if (isset($supported_post_types[$taxonomy]) && !empty($supported_post_types[$taxonomy])) {
                 $ct_post_types = $supported_post_types[$taxonomy];
             }
             $pods_cpt_ct['taxonomies'][$taxonomy] = array('post_types' => $ct_post_types, 'options' => $options);
         }
         foreach ($pods_post_types as $post_type => $options) {
             if (isset($supported_taxonomies[$post_type]) && !empty($supported_taxonomies[$post_type])) {
                 $options['taxonomies'] = $supported_taxonomies[$post_type];
             }
             $pods_cpt_ct['post_types'][$post_type] = $options;
         }
         pods_transient_set('pods_wp_cpt_ct', $pods_cpt_ct);
     }
     foreach ($pods_cpt_ct['taxonomies'] as $taxonomy => $options) {
         if (isset(self::$content_types_registered['taxonomies']) && in_array($taxonomy, self::$content_types_registered['taxonomies'])) {
             continue;
         }
         $ct_post_types = $options['post_types'];
         $options = $options['options'];
         $options = apply_filters('pods_register_taxonomy_' . $taxonomy, $options, $taxonomy);
         $options = apply_filters('pods_register_taxonomy', $options, $taxonomy);
         $options = self::object_label_fix($options, 'taxonomy');
         // Max length for taxonomies are 32 characters
         $taxonomy = substr($taxonomy, 0, 32);
         // i18n compatibility for plugins that override it
         if (is_array($options['rewrite']) && isset($options['rewrite']['slug']) && !empty($options['rewrite']['slug'])) {
             $options['rewrite']['slug'] = _x($options['rewrite']['slug'], 'URL taxonomy slug', 'pods');
         }
         if (1 == pods_var('pods_debug_register', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug(array($taxonomy, $ct_post_types, $options));
         }
         register_taxonomy($taxonomy, $ct_post_types, $options);
         if (!isset(self::$content_types_registered['taxonomies'])) {
             self::$content_types_registered['taxonomies'] = array();
         }
         self::$content_types_registered['taxonomies'][] = $taxonomy;
     }
     foreach ($pods_cpt_ct['post_types'] as $post_type => $options) {
         if (isset(self::$content_types_registered['post_types']) && in_array($post_type, self::$content_types_registered['post_types'])) {
             continue;
         }
         $options = apply_filters('pods_register_post_type_' . $post_type, $options, $post_type);
         $options = apply_filters('pods_register_post_type', $options, $post_type);
         $options = self::object_label_fix($options, 'post_type');
         // Max length for post types are 20 characters
         $post_type = substr($post_type, 0, 20);
         // i18n compatibility for plugins that override it
         if (is_array($options['rewrite']) && isset($options['rewrite']['slug']) && !empty($options['rewrite']['slug'])) {
             $options['rewrite']['slug'] = _x($options['rewrite']['slug'], 'URL slug', 'pods');
         }
         if (1 == pods_var('pods_debug_register', 'get', 0) && pods_is_admin(array('pods'))) {
             pods_debug(array($post_type, $options));
         }
         register_post_type($post_type, $options);
         if (!isset(self::$content_types_registered['post_types'])) {
             self::$content_types_registered['post_types'] = array();
         }
         self::$content_types_registered['post_types'][] = $post_type;
     }
 }
Ejemplo n.º 10
0
 /**
  * Run any precode for current Pod Page
  */
 public function precode()
 {
     global $pods;
     // Fix any global confusion wherever this runs
     if (isset($pods) && !isset($GLOBALS['pods'])) {
         $GLOBALS['pods'] =& $pods;
     } elseif (!isset($pods) && isset($GLOBALS['pods'])) {
         $pods =& $GLOBALS['pods'];
     }
     if (false !== self::$exists) {
         $permission = pods_permission(self::$exists['options']);
         $permission = (bool) apply_filters('pods_pages_permission', $permission, self::$exists);
         if ($permission) {
             $content = false;
             if (!is_object($pods) && 404 != $pods && 0 < strlen(pods_var('pod', self::$exists['options']))) {
                 $pods = pods(pods_var('pod', self::$exists['options']), pods_evaluate_tags(pods_var_raw('pod_slug', self::$exists['options'], null, null, true), true));
             }
             if (0 < strlen(trim(self::$exists['precode']))) {
                 $content = self::$exists['precode'];
             }
             if (false !== $content && (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL)) {
                 pods_deprecated('Use WP Page Templates or hook into the pods_page_precode action instead of using Pod Page Precode', '2.1');
                 eval("?>{$content}");
             }
             do_action('pods_page_precode', self::$exists, $pods, $content);
         }
         if (!$permission || !is_object($pods) && (404 == $pods || is_wp_error($pods))) {
             remove_action('template_redirect', array($this, 'template_redirect'));
             remove_action('wp_head', array($this, 'wp_head'));
             remove_filter('redirect_canonical', '__return_false');
             remove_filter('wp_title', array($this, 'wp_title'));
             remove_filter('body_class', array($this, 'body_class'));
             remove_filter('status_header', array($this, 'status_header'));
             remove_action('wp', array($this, 'silence_404'));
         }
     }
 }
Ejemplo n.º 11
0
/**
 * Evaluate tags like magic tags but through pods_var
 *
 * @param string|array $tags String to be evaluated
 * @param bool $sanitize Whether to sanitize tags
 *
 * @return string
 * @version 2.1
 */
function pods_evaluate_tags($tags, $sanitize = false)
{
    if (is_array($tags)) {
        foreach ($tags as $k => $tag) {
            $tags[$k] = pods_evaluate_tags($tag, $sanitize);
        }
        return $tags;
    }
    if ($sanitize) {
        return preg_replace_callback('/({@(.*?)})/m', 'pods_evaluate_tag_sanitized', (string) $tags);
    } else {
        return preg_replace_callback('/({@(.*?)})/m', 'pods_evaluate_tag', (string) $tags);
    }
}