/** * 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); } } }
/** * Set a variable * * @param mixed $value The value to be set * @param mixed $var The variable name, or URI segment position / query var name (if $type is 'url') * @param string|array|object $type (optional) Super globals, url/url-relative, constants, globals, user data, Pod field values * * @return mixed Updated URL (if $type is 'url'), $value (if $type is 'constant'), Item ID (if $type is 'pods'), $type, or false if not set * @since 2.3.10 */ function pods_v_set($value, $var, $type = 'get') { $ret = false; if (null === $var || '' === $var) { // Invalid $var } elseif (null === $type || '' === $type) { // Invalid $type } elseif (is_array($type)) { $type[$var] = $value; $ret = $type; } elseif (is_object($type)) { $type->{$var} = $value; $ret = $type; } else { $type = strtolower($type); if ('get' == $type) { $_GET[$var] = $value; $ret = $_GET; } elseif ('post' == $type) { $_POST[$var] = $value; $ret = $_POST; } elseif ('request' == $type) { $_REQUEST[$var] = $value; $ret = $_REQUEST; } elseif ('url' == $type) { if (is_numeric($var) && function_exists('http_build_url')) { $url = parse_url(pods_current_url()); $uri = trim($url['path'], '/'); $uri = array_filter(explode('/', $uri)); if ('first' == $var) { $var = 0; } elseif ('last' == $var) { $var = -1; } if ($var < 0) { $uri[count($uri) + $var] = $value; } else { $uri[$var] = $value; } $url['path'] = '/' . implode('/', $uri) . '/'; $url['path'] = trim($url['path'], '/'); $ret = http_build_url($url); } else { $ret = add_query_arg(array($var => $value)); } } elseif ('server' == $type) { $_SERVER[$var] = $value; $ret = $_SERVER; } elseif (in_array($type, array('global', 'globals'))) { $GLOBALS[$var] = $value; $ret = $GLOBALS; } elseif ('session' == $type) { // Session start pods_session_start(); $_SESSION[$var] = $value; $ret = $_SESSION; } elseif ('cookie' == $type && !headers_sent()) { setcookie($var, $value, time() + 10 * DAY_IN_SECONDS, COOKIEPATH); $ret = $_COOKIE; } elseif ('constant' == $type && !defined($var) && (is_scalar($value) || null === $value)) { define($var, $value); $ret = constant($var); } elseif ('user' == $type && is_user_logged_in()) { $user = get_userdata(get_current_user_id()); if (!pods_version_check('wp', '3.5')) { $user_data = get_object_vars($user->data); } else { $user_data = $user->to_array(); } // Role if ('role' == $var) { $user->set_role($value); } elseif (isset($user_data[$var])) { wp_update_user(array('ID' => $user->ID, $var => $value)); } else { update_user_meta($user->ID, $var, $value); } $ret = get_userdata($user->ID); } elseif ('pods' == $type) { /** * @var $pods Pods */ global $pods; if (is_object($pods) && 'Pods' == get_class($pods) && $pods->exists()) { $ret = $pods->save($var, $value); } } else { $ret = apply_filters('pods_var_set_' . $type, $value, $var); } } return $ret; }
/** * @return mixed|void */ function get_current_url() { $url = pods_current_url(); return apply_filters('get_current_url', $url); }
<?php // Include with Cache Key using Current URL // Loop content on a page cached based on Current URL pods_view('loop-content.php?url=' . pods_current_url(), null, DAY_IN_SECONDS); // Include with Cache Key using User Role // Restricted content cached based on current role of User global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); pods_view('restricted-content.php?role=' . $user_role, null, DAY_IN_SECONDS); // Include with Cache Key using Special Magic Tag // See: http://pods.io/docs/build/special-magic-tags/ // Show related posts cached based on current post ID pods_view('related-posts.php?ID={globals.post_ID}', null, DAY_IN_SECONDS);
/** * Check to see if Pod Page exists and return data * * $uri not required, if NULL then returns REQUEST_URI matching Pod Page * * @param string $uri The Pod Page URI to check if exists * * @return array|bool */ public static function exists($uri = null) { if (null === $uri) { $uri = parse_url(pods_current_url()); $uri = $uri['path']; } else { $uri = explode('?', $uri); $uri = explode('#', $uri[0]); $uri = $uri[0]; } $home = parse_url(get_home_url()); if (!empty($home) && isset($home['path']) && '/' != $home['path']) { $uri = substr($uri, strlen($home['path'])); } $uri = trim($uri, '/'); $uri_depth = count(array_filter(explode('/', $uri))) - 1; $pods_page_exclusions = array('wp-admin', 'wp-content', 'wp-includes', 'index.php', 'wp-login.php', 'wp-signup.php'); $pods_page_exclusions = apply_filters('pods_page_exclusions', $pods_page_exclusions); if (is_admin() || empty($uri)) { return false; } foreach ($pods_page_exclusions as $exclusion) { if (0 === strpos($uri, $exclusion)) { return false; } } $object = false; if (false === strpos($uri, '*') && !apply_filters('pods_page_regex_matching', false)) { $object = pods_by_title($uri, ARRAY_A, '_pods_page', 'publish'); } $wildcard = false; if (empty($object)) { if (false === strpos($uri, '*')) { $object = pods_cache_get($uri, 'pods_object_page_wildcard'); if (!empty($object)) { return $object; } } $pod_page_rewrites = pods_transient_get('pods_object_page_rewrites'); if (empty($pod_page_rewrites)) { $pod_page_rewrites = self::flush_rewrites(); } else { $pod_page_rewrites = array_flip($pod_page_rewrites); } $found_rewrite_page_id = 0; if (!empty($pod_page_rewrites)) { foreach ($pod_page_rewrites as $pod_page => $pod_page_id) { if (!apply_filters('pods_page_regex_matching', false)) { if (false === strpos($pod_page, '*')) { continue; } $depth_check = strlen($pod_page) - strlen(str_replace('/', '', $pod_page)); $pod_page = preg_quote($pod_page, '/'); $pod_page = str_replace('\\*', '(.*)', $pod_page); if ($uri_depth == $depth_check && preg_match('/^' . $pod_page . '$/', $uri)) { $found_rewrite_page_id = $pod_page_id; break; } } elseif (preg_match('/^' . str_replace('/', '\\/', $pod_page) . '$/', $uri)) { $found_rewrite_page_id = $pod_page_id; break; } } if (!empty($found_rewrite_page_id)) { $object = get_post($found_rewrite_page_id, ARRAY_A); if (empty($object) || '_pods_page' != $object['post_type']) { $object = false; } } } $wildcard = true; } if (!empty($object)) { $object = array('id' => $object['ID'], 'uri' => $object['post_title'], 'code' => $object['post_content'], 'phpcode' => $object['post_content'], 'precode' => get_post_meta($object['ID'], 'precode', true), 'page_template' => get_post_meta($object['ID'], 'page_template', true), 'title' => get_post_meta($object['ID'], 'page_title', true), 'options' => array('admin_only' => (bool) get_post_meta($object['ID'], 'admin_only', true), 'restrict_role' => (bool) get_post_meta($object['ID'], 'restrict_role', true), 'restrict_capability' => (bool) get_post_meta($object['ID'], 'restrict_capability', true), 'roles_allowed' => get_post_meta($object['ID'], 'roles_allowed', true), 'capability_allowed' => get_post_meta($object['ID'], 'capability_allowed', true), 'pod' => get_post_meta($object['ID'], 'pod', true), 'pod_slug' => get_post_meta($object['ID'], 'pod_slug', true))); if ($wildcard) { pods_cache_set($uri, $object, 'pods_object_page_wildcard', 3600); } return $object; } return false; }
/** * Set a variable * * @param mixed $value The value to be set * @param mixed $key The variable name or URI segment position * @param string $type (optional) "url", "get", "post", "request", "server", "session", "cookie", "constant", or "user" * * @return mixed $value (if set), $type (if $type is array or object), or $url (if $type is 'url') * @since 1.10.6 */ function pods_var_set($value, $key = 'last', $type = 'url') { $type = strtolower($type); $ret = false; if (is_array($type)) { $type[$key] = $value; $ret = $type; } elseif (is_object($type)) { $type->{$key} = $value; $ret = $type; } elseif ('url' == $type) { $url = parse_url(pods_current_url()); $uri = trim($url['path'], '/'); $uri = array_filter(explode('/', $uri)); if ('first' == $key) { $key = 0; } elseif ('last' == $key) { $key = -1; } if (is_numeric($key)) { if ($key < 0) { $uri[count($uri) + $key] = $value; } else { $uri[$key] = $value; } } $url['path'] = '/' . implode('/', $uri) . '/'; $url['path'] = trim($url['path'], '/'); $ret = http_build_url($url); } elseif ('get' == $type) { $ret = $_GET[$key] = $value; } elseif ('post' == $type) { $ret = $_POST[$key] = $value; } elseif ('request' == $type) { $ret = $_REQUEST[$key] = $value; } elseif ('server' == $type) { $ret = $_SERVER[$key] = $value; } elseif ('session' == $type) { $ret = $_SESSION[$key] = $value; } elseif ('cookie' == $type) { $ret = $_COOKIE[$key] = $value; } elseif ('constant' == $type && !defined($key)) { define($key, $value); $ret = constant($key); } elseif ('user' == $type && is_user_logged_in()) { global $user_ID; get_currentuserinfo(); update_user_meta($user_ID, $key, $value); $ret = $value; } return apply_filters('pods_var_set', $ret, $value, $key, $type); }