/** * @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') { // Different $expires if user is anonymous or logged in or specific capability if (is_array($expires)) { $anon = pods_var_raw(0, $expires, false); $user = pods_var_raw(1, $expires, false); $capability = pods_var_raw(2, $expires, null, null, true); $expires = pods_var_user($anon, $user, $capability); } if ('none' == $cache_mode) { $expires = false; } if (false !== $expires && empty($expires)) { $expires = 0; } if (!in_array($cache_mode, self::$cache_modes)) { $cache_mode = 'cache'; } $view = apply_filters('pods_view_inc', $view, $data, $expires, $cache_mode); $view_key = $view; if (is_array($view_key)) { $view_key = implode('-', $view_key) . '.php'; } $view_key = realpath($view_key); $pods_ui_dir = realpath(PODS_DIR . 'ui/'); $pods_components_dir = realpath(PODS_DIR . 'components/'); $content_dir = realpath(WP_CONTENT_DIR); $plugins_dir = realpath(WP_PLUGIN_DIR); $muplugins_dir = realpath(WPMU_PLUGIN_DIR); $abspath_dir = realpath(ABSPATH); $cache_key = sanitize_title(pods_str_replace(array($pods_ui_dir, $pods_components_dir, $content_dir, $plugins_dir, $abspath_dir, '.php', '/'), array('ui-', 'ui-', 'custom-', 'custom-', 'custom-', '', '_'), $view_key, 1)); $output = false; if (false !== $expires && false === strpos($view_key, $pods_ui_dir) && false === strpos($view_key, $pods_components_dir) && false === strpos($view_key, $content_dir) && false === strpos($view_key, $plugins_dir) && false === strpos($view_key, $muplugins_dir) && false === strpos($view_key, $abspath_dir)) { $output = self::get('pods-view-' . $cache_key, $cache_mode, 'pods_view'); } if (false === $output || null === $output) { $output = self::get_template_part($view, $data); } if (false !== $output && false !== $expires) { self::set('pods-view-' . $cache_key, $output, $expires, $cache_mode, 'pods_view'); } $output = apply_filters('pods_view_output_' . $cache_key, $output, $view, $data, $expires, $cache_mode); $output = apply_filters('pods_view_output', $output, $view, $data, $expires, $cache_mode); return $output; }
/** * See if the current user has a certain privilege * * @param mixed $privs The privilege name or names (array if multiple) * @param string $method The access method ("AND", "OR") * * @return bool * @since 1.2.0 */ function pods_access($privs, $method = 'OR') { // Convert $privs to an array $privs = (array) $privs; // Convert $method to uppercase $method = strtoupper($method); $check = apply_filters('pods_access', null, $privs, $method); if (null !== $check && is_bool($check)) { return $check; } if (!is_user_logged_in()) { return false; } if (pods_is_admin(array('pods', 'pods_content'))) { return true; } // Store approved privs when using "AND" $approved_privs = array(); // Loop through the user's roles foreach ($privs as $priv) { if (0 === strpos($priv, 'pod_')) { $priv = pods_str_replace('pod_', 'pods_edit_', $priv, 1); } if (0 === strpos($priv, 'manage_')) { $priv = pods_str_replace('manage_', 'pods_', $priv, 1); } if (current_user_can($priv)) { if ('OR' == $method) { return true; } $approved_privs[$priv] = true; } } if ('AND' == strtoupper($method)) { foreach ($privs as $priv) { if (0 === strpos($priv, 'pod_')) { $priv = pods_str_replace('pod_', 'pods_edit_', $priv, 1); } if (0 === strpos($priv, 'manage_')) { $priv = pods_str_replace('manage_', 'pods_', $priv, 1); } if (isset($approved_privs[$priv])) { return false; } } return true; } return false; }
<?php echo PodsForm::field('update_count_callback', pods_var_raw('update_count_callback', $pod), 'text'); ?> </div> <div class="pods-field-option-group"> <p class="pods-field-option-group-label"> <?php _e('Associated Post Types', 'pods'); ?> </p> <div class="pods-pick-values pods-pick-checkbox"> <ul> <?php foreach ((array) $field_settings['pick_object'][__('Post Types', 'pods')] as $post_type => $label) { $post_type = pods_str_replace('post_type-', '', $post_type, 1); $label = str_replace(array('(', ')'), array('<small>(', ')</small>'), $label); ?> <li> <div class="pods-field pods-boolean"> <?php echo PodsForm::field('built_in_post_types_' . $post_type, pods_var_raw('built_in_post_types_' . $post_type, $pod, false), 'boolean', array('boolean_yes_label' => $label)); ?> </div> </li> <?php } ?> <?php if (pods_version_check('wp', '3.5')) {
/** * Load potential sister fields for a specific field * * $params['pod'] int The Pod name * $params['related_pod'] string The related Pod name * * @param array $params An associative array of parameters * @param array $pod (optional) Array of Pod data to use (to avoid lookup) * * @return array|bool * * @since 1.7.9 * * @uses PodsAPI::load_pod */ public function load_sister_fields($params, $pod = null) { $params = (object) pods_sanitize($params); if (empty($pod)) { $pod = $this->load_pod(array('name' => $params->pod, 'table_info' => false), false); if (false === $pod) { return pods_error(__('Pod not found', 'pods'), $this); } } $params->pod_id = $pod['id']; $params->pod = $pod['name']; $type = false; if (0 === strpos($params->related_pod, 'pod-')) { $params->related_pod = pods_str_replace('pod-', '', $params->related_pod, 1); $type = 'pod'; } elseif (0 === strpos($params->related_pod, 'post_type-')) { $params->related_pod = pods_str_replace('post_type-', '', $params->related_pod, 1); $type = 'post_type'; } elseif (0 === strpos($params->related_pod, 'taxonomy-')) { $params->related_pod = pods_str_replace('taxonomy-', '', $params->related_pod, 1); $type = 'taxonomy'; } $related_pod = $this->load_pod(array('name' => $params->related_pod, 'table_info' => false), false); if (false === $related_pod || false !== $type && 'pod' != $type && $type != $related_pod['type']) { return pods_error(__('Related Pod not found', 'pods'), $this); } $params->related_pod_id = $related_pod['id']; $params->related_pod = $related_pod['name']; $sister_fields = array(); foreach ($related_pod['fields'] as $field) { if ('pick' == $field['type'] && in_array($field['pick_object'], array($pod['type'], 'pod')) && ($params->pod == $field['pick_object'] || $params->pod == $field['pick_val'])) { $sister_fields[$field['id']] = esc_html($field['label'] . ' (' . $field['name'] . ')'); } } return $sister_fields; }
/** * @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; }
/** * @return string */ public function migrate_roles() { if (true === $this->check_progress(__FUNCTION__)) { return '1'; } /** * @var $wpdb WPDB */ global $wpdb; $wp_roles = get_option("{$wpdb->prefix}user_roles"); $old_roles = get_option('pods_roles'); if (!is_array($old_roles) && !empty($old_roles)) { $old_roles = @unserialize($old_roles); } if (!is_array($old_roles)) { $old_roles = array(); } if (!empty($old_roles)) { foreach ($old_roles as $role => $data) { if ($role == '_wpnonce') { continue; } if (!isset($wp_roles[$role])) { continue; } $caps = $wp_roles[$role]['capabilities']; foreach ($data as $cap) { if (0 === strpos('manage_', $cap)) { if (in_array($cap, array('manage_roles'))) { continue; } $cap = pods_str_replace('manage_', 'pods_', $cap, 1); $cap = pods_str_replace('pod_pages', 'pages', $cap, 1); $caps[$cap] = true; } elseif (0 === strpos('pod_', $cap)) { $keys = array(pods_str_replace('pod_', 'pods_new_', $cap, 1), pods_str_replace('pod_', 'pods_edit_', $cap, 1), pods_str_replace('pod_', 'pods_delete_', $cap, 1)); foreach ($keys as $key) { $caps[$key] = true; } } } $wp_roles[$role]['capabilities'] = $caps; } } update_option("{$wpdb->prefix}user_roles", $wp_roles); $this->update_progress(__FUNCTION__, true); return '1'; }
/** * Functions like str_replace except it will restrict $occurrences * * @param mixed $find * @param mixed $replace * @param string $string * @param int $occurrences (optional) * * @return mixed * @version 2.0 */ function pods_str_replace($find, $replace, $string, $occurrences = -1) { if (is_array($string)) { foreach ($string as $k => $v) { $string[$k] = pods_str_replace($find, $replace, $v, $occurrences); } return $string; } elseif (is_object($string)) { $string = get_object_vars($string); foreach ($string as $k => $v) { $string[$k] = pods_str_replace($find, $replace, $v, $occurrences); } return (object) $string; } if (is_array($find)) { foreach ($find as &$f) { $f = '/' . preg_quote($f, '/') . '/'; } } else { $find = '/' . preg_quote($find, '/') . '/'; } return preg_replace($find, $replace, $string, $occurrences); }