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)
{
    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.º 2
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.º 3
0
 /**
  * Output Pod Page Content
  *
  * @param bool $return Whether to return or not (default is to echo)
  *
  * @return string
  */
 public static function content($return = false, $pods_page = false)
 {
     if (empty($pods_page)) {
         $pods_page = self::$exists;
     }
     $content = false;
     if ($pods_page == self::$exists && self::$content_called) {
         return $content;
     }
     if (!empty($pods_page)) {
         /**
          * @var $pods \Pods
          */
         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 (0 < strlen(trim($pods_page['code']))) {
             $content = trim($pods_page['code']);
         }
         ob_start();
         do_action('pods_content_pre', $pods_page, $content);
         if (0 < strlen($content)) {
             if (false !== strpos($content, '<?') && (!defined('PODS_DISABLE_EVAL') || !PODS_DISABLE_EVAL)) {
                 pods_deprecated('Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1');
                 eval("?>{$content}");
             } elseif (is_object($pods) && !empty($pods->id)) {
                 echo $pods->do_magic_tags($content);
             } else {
                 echo $content;
             }
         }
         do_action('pods_content_post', $pods_page, $content);
         $content = ob_get_clean();
         if ($pods_page == self::$exists) {
             self::$content_called = true;
         }
     }
     $content = apply_filters('pods_content', $content, $pods_page);
     if ($return) {
         return $content;
     }
     echo $content;
 }