function pods_markdown_output($value, $name, $options, $pod, $id, $traverse) { if (1 == pods_var($options['type'] . '_allow_markdown', $options)) { $value = Markdown($value); } return $value; }
/** * Change the way the value of the field is displayed with Pods::get * * @param mixed $value * @param string $name * @param array $options * @param array $fields * @param array $pod * @param int $id * * @since 2.0 */ public function display($value = null, $name = null, $options = null, $pod = null, $id = null) { if (1 == pods_var(self::$type . '_allow_shortcode', $options, 0)) { $value = do_shortcode($value); } return $value; }
/** * Build admin area * * @param $options * @param $component * * @return void * @since 2.0 */ public function admin($options, $component) { global $wp_roles; // Hook into Gravity Forms roles (since it only adds filter if Members plugin itself is activated if (class_exists('RGForms') && !has_filter('members_get_capabilities', array('RGForms', 'members_get_capabilities'))) { add_filter('members_get_capabilities', array('RGForms', 'members_get_capabilities')); } $default_role = get_option('default_role'); $roles = array(); foreach ($wp_roles->role_objects as $key => $role) { $count = $this->count_users($key); $roles[$key] = array('id' => $key, 'label' => $wp_roles->role_names[$key], 'name' => $key, 'capabilities' => count((array) $role->capabilities), 'users' => sprintf(_n('%s User', '%s Users', $count, 'pods'), $count)); if ($default_role == $key) { $roles[$key]['label'] .= ' (site default)'; } if (0 < $count && pods_is_admin(array('list_users'))) { $roles[$key]['users'] .= '<br /><a href="' . admin_url(esc_url('users.php?role=' . $key)) . '">' . __('View Users', 'pods') . '</a>'; } } $ui = array('component' => $component, 'data' => $roles, 'total' => count($roles), 'total_found' => count($roles), 'icon' => PODS_URL . 'ui/images/icon32.png', 'items' => 'Roles', 'item' => 'Role', 'fields' => array('manage' => array('label' => array('label' => __('Label', 'pods')), 'name' => array('label' => __('Name', 'pods')), 'capabilities' => array('label' => __('Capabilities', 'pods')), 'users' => array('label' => __('Users', 'pods'), 'type' => 'text', 'options' => array('text_allow_html' => 1, 'text_allowed_html_tags' => '')))), 'actions_disabled' => array('duplicate', 'view', 'export'), 'actions_custom' => array('add' => array($this, 'admin_add'), 'edit' => array($this, 'admin_edit'), 'delete' => array($this, 'admin_delete')), 'search' => false, 'searchable' => false, 'sortable' => false, 'pagination' => false); if (isset($roles[pods_var('id', 'get', -1)])) { $ui['row'] = $roles[pods_var('id', 'get', -1)]; } if (!pods_is_admin(array('pods_roles_add'))) { $ui['actions_disabled'][] = 'add'; } if (!pods_is_admin(array('pods_roles_edit'))) { $ui['actions_disabled'][] = 'edit'; } if (count($roles) < 2 || !pods_is_admin(array('pods_roles_delete'))) { $ui['actions_disabled'][] = 'delete'; } pods_ui($ui); }
/** * @return string */ public function migrate_relationships() { if (true === $this->check_progress(__FUNCTION__)) { return '1'; } $migration_limit = (int) apply_filters('pods_upgrade_item_limit', 1500); $migration_limit = max($migration_limit, 100); $last_id = (int) $this->check_progress(__FUNCTION__); $relationship_fields = $this->api->load_fields(array('type' => array('pick', 'file'))); foreach ($relationship_fields as $field) { $pod = $this->api->load_pod(array('pod' => $field['pod'])); // Only target pods that are meta-enabled if (!in_array($pod['type'], array('post_type', 'media', 'user', 'comment'))) { continue; } // Only target multi-select relationships $single_multi = pods_var($field['type'] . '_format_type', $field['options'], 'single'); if ('multi' == $single_multi) { $limit = (int) pods_var($field['type'] . '_limit', $field['options'], 0); } else { $limit = 1; } if ($limit <= 1) { continue; } // Get and loop through relationship meta $sql = "\n\n "; // if serialized (or array), save as individual meta items and save new order meta key } $last_id = true; $rel = array(); $this->update_progress(__FUNCTION__, $last_id); if ($migration_limit == count($rel)) { return '-2'; } else { return '1'; } }
echo $indent; ?> > <input<?php PodsForm::attributes($attributes, $name, $form_field_type, $options); ?> /> <?php if (0 < strlen($label)) { $help = pods_var_raw('help', $options); if (1 == pods_var('grouped', $options, 0, null, true) || empty($help)) { $help = ''; } echo PodsForm::label($attributes['id'], $label, $help); } ?> </div> <?php if (1 == pods_var('grouped', $options, 0, null, true)) { ?> </li> <?php } $counter++; } if (1 == pods_var('grouped', $options, 0, null, true)) { ?> </ul> </div> <?php }
/** * @param $params * * @return mixed|string|void */ public function migrate_pod($params) { /** * @var $wpdb WPDB */ global $wpdb; if (!isset($params->pod)) { return pods_error(__('Invalid Pod.', 'pods')); } $pod = pods_sanitize(pods_clean_name($params->pod)); if (!in_array("{$wpdb->prefix}pod_tbl_{$pod}", $this->tables)) { return pods_error(__('Table not found, items cannot be migrated', 'pods')); } if (!in_array("{$wpdb->prefix}pods_{$pod}", $this->tables)) { return pods_error(__('New table not found, items cannot be migrated', 'pods')); } if (!in_array("{$wpdb->prefix}pod_types", $this->tables)) { return pods_error(__('Pod Types table not found, items cannot be migrated', 'pods')); } if (!in_array("{$wpdb->prefix}pod", $this->tables)) { return pods_error(__('Pod table not found, items cannot be migrated', 'pods')); } if (true === $this->check_progress(__FUNCTION__, $pod)) { return '1'; } $pod_data = $this->api->load_pod(array('name' => $pod), false); if (empty($pod_data)) { return pods_error(sprintf(__('Pod <strong>%s</strong> not found, items cannot be migrated', 'pods'), $pod)); } $columns = array(); $old_columns = array(); foreach ($pod_data['fields'] as $field) { if (!in_array($field['name'], array('created', 'modified', 'author')) && !in_array($field['type'], array('file', 'pick'))) { $columns[] = pods_sanitize($field['name']); $old_columns[] = pods_var('_pods_1x_field_name', $field['options'], $field['name'], null, false); } } $into = '`id`'; $select = '`t`.`id`'; if (!empty($columns)) { $into .= ', `' . implode('`, `', $columns) . '`'; $select .= ', `t`.`' . implode('`, `t`.`', $old_columns) . '`'; } // Copy content from the old table into the new $sql = "\n REPLACE INTO `@wp_pods_{$pod}`\n ( {$into} )\n ( SELECT {$select}\n FROM `@wp_pod_tbl_{$pod}` AS `t` )\n "; pods_query($sql); // Copy index data from the old index table into the new individual table $sql = "\n UPDATE `@wp_pods_{$pod}` AS `t`\n LEFT JOIN `@wp_pod_types` AS `x` ON `x`.`name` = '{$pod}'\n LEFT JOIN `@wp_pod` AS `p` ON `p`.`datatype` = `x`.`id` AND `p`.`tbl_row_id` = `t`.`id`\n SET `t`.`created` = `p`.`created`, `t`.`modified` = `p`.`modified`\n WHERE `x`.`id` IS NOT NULL AND `p`.`id` IS NOT NULL\n "; pods_query($sql); // Copy name data from the old index table into the new individual table (if name empty in indiv table) $sql = "\n UPDATE `@wp_pods_{$pod}` AS `t`\n LEFT JOIN `@wp_pod_types` AS `x` ON `x`.`name` = '{$pod}'\n LEFT JOIN `@wp_pod` AS `p` ON `p`.`datatype` = `x`.`id` AND `p`.`tbl_row_id` = `t`.`id`\n SET `t`.`name` = `p`.`name`\n WHERE ( `t`.`name` IS NULL OR `t`.`name` = '' ) AND `x`.`id` IS NOT NULL AND `p`.`id` IS NOT NULL\n "; pods_query($sql); $this->update_progress(__FUNCTION__, true, $pod); return '1'; }
/** * Get options for a field and setup defaults * * * @param null $fields * @param null $core_defaults * @param bool $single * * @return array|null * * @static * @since 2.0 */ public static function fields_setup($fields = null, $core_defaults = null, $single = false) { if (empty($core_defaults)) { $core_defaults = array('id' => 0, 'name' => '', 'label' => '', 'description' => '', 'help' => '', 'default' => null, 'attributes' => array(), 'class' => '', 'type' => 'text', 'group' => 0, 'grouped' => 0, 'developer_mode' => false, 'dependency' => false, 'depends-on' => array(), 'excludes-on' => array(), 'options' => array()); } if ($single) { $fields = array($fields); } foreach ($fields as $f => $field) { $fields[$f] = self::field_setup($field, $core_defaults, pods_var('type', $field, 'text')); if (!$single && strlen($fields[$f]['name']) < 1) { $fields[$f]['name'] = $f; } } if ($single) { $fields = $fields[0]; } return $fields; }
<?php $type = 'textarea'; $attributes = array(); $attributes['tabindex'] = 2; $attributes = PodsForm::merge_attributes($attributes, $name, $form_field_type, $options); if (pods_var('readonly', $options, false)) { $attributes['readonly'] = 'READONLY'; $attributes['class'] .= ' pods-form-ui-read-only'; } ?> <textarea<?php PodsForm::attributes($attributes, $name, $form_field_type, $options); ?> ><?php echo esc_textarea($value); ?> </textarea> <?php PodsForm::regex($form_field_type, $options);
if (isset($_POST['cleanup_1x'])) { pods_upgrade('2.0.0')->cleanup(); pods_redirect(pods_var_update(array('pods_cleanup_1x' => 1), array('page', 'tab'))); } elseif (isset($_POST['reset'])) { $pods_init->reset(); $pods_init->setup(); pods_redirect(pods_var_update(array('pods_reset' => 1), array('page', 'tab'))); } elseif (isset($_POST['reset_deactivate'])) { $pods_init->reset(); deactivate_plugins(PODS_DIR . 'init.php'); pods_redirect('index.php'); } elseif (1 == pods_var('pods_reset')) { pods_message('Pods 2.x settings and data have been reset.'); } elseif (1 == pods_var('pods_cleanup_1x')) { pods_message('Pods 1.x data has been deleted.'); } elseif (pods_var('reset_weekend', 'post', pods_var('reset_weekend', 'get', 0, null, true), null, true)) { if ($monday_mode) { $html = '<br /><br /><iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/QH2-TGUlwu4?autoplay=1" frameborder="0" allowfullscreen></iframe>'; pods_message('The weekend has been reset and you have been sent back to Friday night. Unfortunately due to a tear in the fabric of time, you slipped back to Monday. We took video of the whole process and you can see it below..' . $html); } else { $html = '<br /><br /><iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/xhrBDcQq2DM?autoplay=1" frameborder="0" allowfullscreen></iframe>'; pods_message('Oops, sorry! You can only reset the weekend on a Monday before the end of the work day. Somebody call the Waaambulance!' . $html, 'error'); } } $old_version = get_option('pods_version'); if (!empty($old_version)) { ?> <h3><?php _e('Delete Pods 1.x data', 'pods'); ?> </h3>
/** * Check if permissions are restricted * * @param array $options * * @return bool Whether the permissions are restricted * * @since 2.3.4 */ function pods_has_permissions($options) { $permission = false; if (isset($options['options'])) { $options = $options['options']; } if (1 == pods_var('restrict_role', $options, 0) || 1 == pods_var('restrict_capability', $options, 0) || 1 == pods_var('admin_only', $options, 0)) { return true; } return false; }
$field = $pod; include PODS_DIR . 'ui/admin/field-option.php'; ?> </div> <?php } if (isset($tabs['extra-fields'])) { ?> <div id="pods-extra-fields" class="pods-nav-tab"> <p><?php _e('Taxonomies do not support extra fields natively, but Pods can add this feature for you easily. Table based storage will operate in a way where each field you create for your content type becomes a field in a table.', 'pods'); ?> </p> <p><?php echo sprintf(__('Enabling extra fields for this taxonomy will add a custom table into your database as <em>%s</em>.', 'pods'), $wpdb->prefix . 'pods_' . pods_var('name', $pod)); ?> </p> <p><a href="http://pods.io/docs/comparisons/compare-storage-types/" target="_blank"><?php _e('Find out more', 'pods'); ?> »</a></p> <p class="submit"> <a href="<?php echo esc_url(pods_query_arg(array('enable_extra_fields' => 1))); ?> " class="button-primary"><?php _e('Enable Extra Fields', 'pods'); ?>
/** * Build date/time format string based on options * * @param $options * * @return string * @since 2.0 */ public function format($options) { $date_format = array('mdy' => 'm/d/Y', 'mdy_dash' => 'm-d-Y', 'mdy_dot' => 'm.d.Y', 'dmy' => 'd/m/Y', 'dmy_dash' => 'd-m-Y', 'dmy_dot' => 'd.m.Y', 'ymd_slash' => 'Y/m/d', 'ymd_dash' => 'Y-m-d', 'ymd_dot' => 'Y.m.d', 'dMy' => 'd/M/Y', 'dMy_dash' => 'd-M-Y', 'fjy' => 'F j, Y', 'fjsy' => 'F jS, Y', 'c' => 'c'); $time_format = array('h_mm_A' => 'g:i A', 'h_mm_ss_A' => 'g:i:s A', 'hh_mm_A' => 'h:i A', 'hh_mm_ss_A' => 'h:i:s A', 'h_mma' => 'g:ia', 'hh_mma' => 'h:ia', 'h_mm' => 'g:i', 'h_mm_ss' => 'g:i:s', 'hh_mm' => 'h:i', 'hh_mm_ss' => 'h:i:s'); $format_value = pods_var(self::$type . '_format', $options, 'ymd_dash', null, true); $format = $date_format[$format_value]; if ('c' != $format_value) { if (12 == pods_var(self::$type . '_time_type', $options)) { $format .= ' ' . $time_format[pods_var(self::$type . '_time_format', $options, 'hh_mm', null, true)]; } else { $format .= ' ' . str_replace(array('h:', 'g:'), 'H:', $time_format[pods_var(self::$type . '_time_format', $options, 'hh_mm', null, true)]); } } return $format; }
<?php /* Template Name: Edit A Project Template */ $projectID = pods_var(-1, 'url'); $podForm = pods('project'); get_header(); ?> <div class="content clearfix"> <div class="header"> <h1>Edit your project</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> </div> <div class="start-project clearfix"> <?php if (is_user_logged_in()) { // Only show the 'name', 'description', and 'other' fields. $fields = array('name', 'timeframe', 'budget', 'image', 'description', 'region'); // Output a form with specific fields echo pods('project', $projectID)->form($fields); } else { ?> <h1>Please Login or Register to start a project.</h1> <?php }
/** * Handle autocomplete AJAX * * @since 2.3 */ public function admin_ajax_relationship() { pods_session_start(); // Sanitize input $params = pods_unslash((array) $_POST); foreach ($params as $key => $value) { if ('action' == $key) { continue; } unset($params[$key]); $params[str_replace('_podsfix_', '', $key)] = $value; } $params = (object) $params; $uid = @session_id(); if (is_user_logged_in()) { $uid = 'user_' . get_current_user_id(); } $nonce_check = 'pods_relationship_' . (int) $params->pod . '_' . $uid . '_' . $params->uri . '_' . (int) $params->field; if (!isset($params->_wpnonce) || false === wp_verify_nonce($params->_wpnonce, $nonce_check)) { pods_error(__('Unauthorized request', 'pods'), PodsInit::$admin); } $api = pods_api(); $pod = $api->load_pod(array('id' => (int) $params->pod)); $field = $api->load_field(array('id' => (int) $params->field, 'table_info' => true)); $id = (int) $params->id; $limit = 15; if (isset($params->limit)) { $limit = (int) $params->limit; } $page = 1; if (isset($params->page)) { $page = (int) $params->page; } if (!isset($params->query) || strlen(trim($params->query)) < 1) { pods_error(__('Invalid field request', 'pods'), PodsInit::$admin); } elseif (empty($pod) || empty($field) || $pod['id'] != $field['pod_id'] || !isset($pod['fields'][$field['name']])) { pods_error(__('Invalid field request', 'pods'), PodsInit::$admin); } elseif ('pick' != $field['type'] || empty($field['table_info'])) { pods_error(__('Invalid field', 'pods'), PodsInit::$admin); } elseif ('single' == pods_var(self::$type . '_format_type', $field) && 'autocomplete' == pods_var(self::$type . '_format_single', $field)) { pods_error(__('Invalid field', 'pods'), PodsInit::$admin); } elseif ('multi' == pods_var(self::$type . '_format_type', $field) && 'autocomplete' == pods_var(self::$type . '_format_multi', $field)) { pods_error(__('Invalid field', 'pods'), PodsInit::$admin); } $object_params = array('name' => $field['name'], 'value' => null, 'options' => array_merge($field, $field['options']), 'pod' => $pod, 'id' => $id, 'context' => 'admin_ajax_relationship', 'data_params' => $params, 'page' => $page, 'limit' => $limit); $pick_data = apply_filters('pods_field_pick_data_ajax', null, $field['name'], null, $field, $pod, $id); if (null !== $pick_data) { $items = $pick_data; } else { $items = $this->get_object_data($object_params); } if (!empty($items) && isset($items[0]) && !is_array($items[0])) { $new_items = array(); foreach ($items as $id => $text) { $new_items[] = array('id' => $id, 'text' => $text, 'image' => ''); } $items = $new_items; } $items = apply_filters('pods_field_pick_data_ajax_items', $items, $field['name'], null, $field, $pod, $id); $items = array('results' => $items); wp_send_json($items); die; // KBAI! }
/** * 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); } } }
$limit_types = 'txt,rtx,csv,tsv'; } elseif ('any' == $limit_file_type) { $limit_types = ''; } else { $limit_types = pods_var($form_field_type . '_allowed_extensions', $options, ''); } $limit_types = str_replace(' ', '', $limit_types); $tab = pods_var($form_field_type . '_attachment_tab', $options, 'type', null, true); if ('upload' == $tab) { $tab = 'type'; } elseif ('browse' == $tab) { $tab = 'library'; } $file_limit = 1; if ('multi' == pods_var($form_field_type . '_format_type', $options, 'single')) { $file_limit = (int) pods_var($form_field_type . '_limit', $options, 0); } $data = array('limit-types' => $limit_types, 'limit-files' => $file_limit); $the_post_id = ''; if (is_admin() && !empty($post_ID)) { $the_post_id = '&post_id=' . (int) $post_ID; } if (empty($value)) { $value = array(); } else { $value = (array) $value; } ?> <div<?php PodsForm::attributes(array('class' => $attributes['class'], 'id' => $attributes['id']), $name, $form_field_type, $options); ?>
public function delete_object($type, $id, $name = null) { if (empty($name)) { $name = $type; } $object = $this->object_get($type, $name); if (!empty($object)) { $params = array('pod' => pods_var('name', $object), 'pod_id' => pods_var('id', $object), 'id' => $id); return pods_api()->delete_pod_item($params, false); } else { return pods_api()->delete_object_from_relationships($id, $type, $name); } }
public function restricted($action = 'edit', $row = null) { $restricted = false; $restrict = array(); if (isset($this->restrict[$action])) { $restrict = (array) $this->restrict[$action]; } // @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query /*if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) { $where = pods_var_raw( $action, $this->where, null, null, true ); if ( !empty( $where ) ) { $restricted = true; $old_where = $this->where[ $action ]; $id = $this->row[ $this->sql[ 'field_id' ] ]; if ( is_array( $where ) ) { if ( 'OR' == pods_var( 'relation', $where ) ) $where = array( $where ); $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id; } else $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id; $this->where[ $action ] = $where; $data = false; //$data = $this->get_data(); $this->where[ $action ] = $old_where; if ( empty( $data ) ) $restricted = true; } }*/ $author_restrict = false; if (!empty($this->restrict['author_restrict']) && $restrict === $this->restrict['author_restrict']) { $restricted = false; $author_restrict = true; if (is_object($this->pod)) { $restricted = true; if ('settings' == $this->pod->pod_data['type'] && 'add' == $action) { $action = 'edit'; } if (pods_is_admin(array('pods', 'pods_content'))) { $restricted = false; } elseif ('manage' == $action) { if (!in_array('edit', $this->actions_disabled) && current_user_can('pods_edit_' . $this->pod->pod) && current_user_can('pods_edit_others_' . $this->pod->pod)) { $restricted = false; } elseif (!in_array('delete', $this->actions_disabled) && current_user_can('pods_delete_' . $this->pod->pod) && current_user_can('pods_delete_others_' . $this->pod->pod)) { $restricted = false; } elseif (current_user_can('pods_' . $action . '_' . $this->pod->pod) && current_user_can('pods_' . $action . '_others_' . $this->pod->pod)) { $restricted = false; } } elseif (current_user_can('pods_' . $action . '_' . $this->pod->pod) && current_user_can('pods_' . $action . '_others_' . $this->pod->pod)) { $restricted = false; } } /* @todo determine proper logic for non-pods capabilities else { $restricted = true; if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) $restricted = false; elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) ) $restricted = false; }*/ } if ($restricted && !empty($restrict)) { $relation = strtoupper(trim(pods_var('relation', $restrict, 'AND', null, true))); if ('AND' != $relation) { $relation = 'OR'; } $okay = true; foreach ($restrict as $field => $match) { if ('relation' == $field) { continue; } if (is_array($match)) { $match_okay = true; $match_relation = strtoupper(trim(pods_var('relation', $match, 'OR', null, true))); if ('AND' != $match_relation) { $match_relation = 'OR'; } foreach ($match as $the_field => $the_match) { if ('relation' == $the_field) { continue; } $value = null; if (is_object($this->pod)) { $value = $this->pod->field($the_match, true); } else { if (empty($row)) { $row = $this->row; } if (isset($row[$the_match])) { if (is_array($row[$the_match])) { if (false !== strpos($the_match, '.')) { $the_matches = explode('.', $the_match); $value = $row[$the_match]; foreach ($the_matches as $m) { if (is_array($value) && isset($value[$m])) { $value = $value[$m]; } else { $value = null; break; } } } } else { $value = $row[$the_match]; } } } if (is_array($value)) { if (!in_array($the_match, $value)) { $match_okay = false; } elseif ('OR' == $match_relation) { $match_okay = true; break; } } elseif ($value == $the_match) { $match_okay = false; } elseif ('OR' == $match_relation) { $match_okay = true; break; } } if (!$match_okay) { $okay = false; } if ('OR' == $relation) { $okay = true; break; } } else { $value = null; if (is_object($this->pod)) { $value = $this->pod->field($match, true); } else { if (empty($row)) { $row = $this->row; } if (isset($row[$match])) { if (is_array($row[$match])) { if (false !== strpos($match, '.')) { $matches = explode('.', $match); $value = $row[$match]; foreach ($matches as $m) { if (is_array($value) && isset($value[$m])) { $value = $value[$m]; } else { $value = null; break; } } } } else { $value = $row[$match]; } } } if (is_array($value)) { if (!in_array($match, $value)) { $okay = false; } elseif ('OR' == $relation) { $okay = true; break; } } elseif ($value != $match) { $okay = false; } elseif ('OR' == $relation) { $okay = true; break; } } } if (!empty($author_restrict)) { if (is_object($this->pod) && 'manage' == $action) { if (!in_array('edit', $this->actions_disabled) && !current_user_can('pods_edit_' . $this->pod->pod) && !in_array('delete', $this->actions_disabled) && !current_user_can('pods_delete_' . $this->pod->pod)) { $okay = false; } } if (is_object($this->pod) && !current_user_can('pods_' . $action . '_' . $this->pod->pod)) { $okay = false; } /* @todo determine proper logic for non-pods capabilities elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) ) $okay = false;*/ if (!$okay && !empty($row)) { foreach ($this->restrict['author_restrict'] as $key => $val) { $author_restricted = $this->get_field($key); if (!empty($author_restricted)) { if (!is_array($author_restricted)) { $author_restricted = (array) $author_restricted; } if (is_array($val)) { foreach ($val as $v) { if (in_array($v, $author_restricted)) { $okay = true; } } } elseif (in_array($val, $author_restricted)) { $okay = true; } } } } } if ($okay) { $restricted = false; } } if (isset($this->actions_custom[$action]) && is_array($this->actions_custom[$action]) && isset($this->actions_custom[$action]['restrict_callback']) && is_callable($this->actions_custom[$action]['restrict_callback'])) { $restricted = call_user_func($this->actions_custom[$action]['restrict_callback'], $restricted, $restrict, $action, $row, $this); } $restricted = $this->do_hook('restricted_' . $action, $restricted, $restrict, $action, $row); return $restricted; }
/** * Process a Pod-based form * * @param mixed $params * @param object $obj Pod object * @param array $fields Fields being submitted in form ( key => settings ) * @param string $thank_you URL to send to upon success * * @return mixed * * @since 2.0 */ public function process_form($params, $obj = null, $fields = null, $thank_you = null) { $this->display_errors = false; $form = null; $nonce = pods_var('_pods_nonce', $params); $pod = pods_var('_pods_pod', $params); $id = pods_var('_pods_id', $params); $uri = pods_var('_pods_uri', $params); $form = pods_var('_pods_form', $params); $location = pods_var('_pods_location', $params); if (is_object($obj)) { $pod = $obj->pod; $id = $obj->id(); } if (!empty($fields)) { $fields = array_keys($fields); $form = implode(',', $fields); } else { $fields = explode(',', $form); } if (empty($nonce) || empty($pod) || empty($uri) || empty($fields)) { return pods_error(__('Invalid submission', 'pods'), $this); } $uid = @session_id(); if (is_user_logged_in()) { $uid = 'user_' . get_current_user_id(); } $field_hash = wp_create_nonce('pods_fields_' . $form); $action = 'pods_form_' . $pod . '_' . $uid . '_' . $id . '_' . $uri . '_' . $field_hash; if (empty($uid)) { return pods_error(__('Access denied for your session, please refresh and try again.', 'pods'), $this); } if (false === wp_verify_nonce($nonce, $action)) { return pods_error(__('Access denied, please refresh and try again.', 'pods'), $this); } $data = array(); foreach ($fields as $field) { $data[$field] = pods_var_raw('pods_field_' . $field, $params, ''); } $params = array('pod' => $pod, 'id' => $id, 'data' => $data, 'from' => 'process_form', 'location' => $location); $id = $this->save_pod_item($params); if (0 < $id && !empty($thank_you)) { $thank_you = str_replace('X_ID_X', $id, $thank_you); pods_redirect($thank_you); } return $id; }
/** * Change the value or perform actions after validation but before saving to the DB * * @param mixed $value * @param int $id * @param string $name * @param array $options * @param array $fields * @param array $pod * @param object $params * * @return mixed|string * @since 2.0 */ public function pre_save($value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null) { $length = (int) pods_var(self::$type . '_max_length', $options, 255); if (0 < $length && $length < pods_mb_strlen($value)) { $value = pods_mb_substr($value, 0, $length); } return $value; }
} $plupload_init = array('runtimes' => 'html5,silverlight,flash,html4', 'container' => $css_id, 'browse_button' => $css_id . '-upload', 'url' => admin_url('admin-ajax.php', 'relative') . '?pods_ajax=1', 'file_data_name' => 'Filedata', 'multiple_queues' => false, 'max_file_size' => wp_max_upload_size() . 'b', 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => __('Allowed Files', 'pods'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, 'multipart_params' => array('_wpnonce' => $field_nonce, 'action' => 'pods_upload', 'method' => 'upload', 'pod' => !is_object($pod) ? '0' : $pod->pod_id, 'field' => $options['id'], 'uri' => $uri_hash)); $limit_file_type = pods_var($form_field_type . '_type', $options, 'images'); $title_editable = pods_var($form_field_type . '_edit_title', $options, 0); if ('images' == $limit_file_type) { $limit_types = 'jpg,jpeg,png,gif'; } elseif ('video' == $limit_file_type) { $limit_types = 'mpg,mov,flv,mp4'; } elseif ('audio' == $limit_file_type) { $limit_types = 'mp3,m4a,wav,wma'; } elseif ('text' == $limit_file_type) { $limit_types = 'txt,rtx,csv,tsv'; } elseif ('any' == $limit_file_type) { $limit_types = ''; } else { $limit_types = pods_var($form_field_type . '_allowed_extensions', $options, '', null, true); } $limit_types = trim(str_replace(array(' ', '.', "\n", "\t", ';'), array('', ',', ',', ','), $limit_types), ','); if (pods_version_check('wp', '3.5')) { $mime_types = wp_get_mime_types(); if (in_array($limit_file_type, array('images', 'audio', 'video'))) { $new_limit_types = array(); foreach ($mime_types as $type => $mime) { if (0 === strpos($mime, $limit_file_type)) { $type = explode('|', $type); $new_limit_types = array_merge($new_limit_types, $type); } } if (!empty($new_limit_types)) { $limit_types = implode(',', $new_limit_types); }
return data; } }, formatResult : <?php echo esc_js(pods_js_name($attributes['id'])); ?> _podsFormatResult, formatSelection : <?php echo esc_js(pods_js_name($attributes['id'])); ?> _podsFormatSelection, minimumInputLength : 1 <?php } ?> } ); <?php if ('multi' == pods_var($form_field_type . '_format_type', $options) && 1 != $pick_limit) { ?> $element.select2( 'container' ).find( 'ul.select2-choices' ).sortable( { containment: 'parent', start: function() { $element.select2( 'onSortStart' ); }, update: function() { $element.select2( 'onSortEnd' ); } } ); <?php } ?> } ); </script>
/** * Validate a value before it's saved * * @param mixed $value * @param string $name * @param array $options * @param array $fields * @param array $pod * @param int $id * @param null $params * * @return array|bool * @since 2.0 */ public function validate($value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null) { $errors = array(); $check = $this->pre_save($value, $id, $name, $options, $fields, $pod, $params); if (is_array($check)) { $errors = $check; } else { if (0 < strlen($value) && strlen($check) < 1) { if (1 == pods_var('required', $options)) { $errors[] = __('This field is required.', 'pods'); } } } if (!empty($errors)) { return $errors; } return true; }
<!-- /#side-sortables --> </div> <!-- /#side-info-column --> <div id="post-body"> <div id="post-body-content"> <?php $more = false; if ($pod->pod_data['field_index'] != $pod->pod_data['field_id']) { foreach ($fields as $k => $field) { if ($pod->pod_data['field_index'] != $field['name'] || 'text' != $field['type']) { continue; } $more = true; $extra = ''; $max_length = (int) pods_var('maxlength', $field['options'], pods_var($field['type'] . '_max_length', $field['options'], 0), null, true); if (0 < $max_length) { $extra .= ' maxlength="' . $max_length . '"'; } ?> <div id="titlediv"> <div id="titlewrap"> <label class="hide-if-no-js" style="visibility:hidden" id="title-prompt-text" for="title"><?php echo apply_filters('pods_enter_name_here', __('Enter name here', 'pods'), $pod, $fields); ?> </label> <input type="text" name="pods_field_<?php echo $pod->pod_data['field_index']; ?> " data-name-clean="pods-field-<?php echo $pod->pod_data['field_index'];
/** * Add pods specific capabilities. * * @param $capabilities List of extra capabilities to add * * @return array */ public function admin_capabilities($capabilities) { foreach ($this->components as $component => $component_data) { if (!empty($component_data['Hide'])) { continue; } if (true === (bool) pods_var('DeveloperMode', $component_data, false) && !pods_developer()) { continue; } if (true === (bool) pods_var('TablelessMode', $component_data, false) && !pods_developer()) { continue; } if (empty($component_data['MenuPage']) && (!isset($component_data['object']) || !method_exists($component_data['object'], 'admin'))) { continue; } $capability = 'pods_component_' . str_replace('-', '_', sanitize_title(str_replace(' and ', ' ', strip_tags($component_data['Name'])))); if (0 < strlen($component_data['Capability'])) { $capability = $component_data['Capability']; } if (!in_array($capability, $capabilities)) { $capabilities[] = $capability; } } return $capabilities; }
/** * Delete the value from the DB * * @param string $type * @param int $id * @param string $name * @param array $options * @param array $pod * * @static * * @since 2.3 */ public static function delete($type, $id = null, $name = null, $options = null, $pod = null) { self::field_loader($type); $deleted = null; if (1 == pods_var('field_delete', $options, 1) && method_exists(self::$loaded[$type], 'delete')) { $deleted = self::$loaded[$type]->delete($id, $name, $options, $pod); } return $deleted; }
<?php if (!empty($_POST)) { if (isset($_POST['clearcache'])) { $api = pods_api(); $api->cache_flush_pods(); if (defined('PODS_PRELOAD_CONFIG_AFTER_FLUSH') && PODS_PRELOAD_CONFIG_AFTER_FLUSH) { $api->load_pods(); } pods_redirect(pods_query_arg(array('pods_clearcache' => 1), array('page', 'tab'))); } } elseif (1 == pods_var('pods_clearcache')) { pods_message('Pods transients and cache have been cleared.'); } ?> <h3><?php _e('Clear Pods Cache', 'pods'); ?> </h3> <p><?php _e('This tool will clear all of the transients/cache that are used by Pods. ', 'pods'); ?> </p> <p class="submit"> <input type="submit" class="button button-primary" name="clearcache" value="<?php esc_attr_e('Clear Pods Cache', 'pods'); ?> " />
/** * Add pods specific capabilities. * * @param $capabilities List of extra capabilities to add * * @return array */ public function admin_capabilities($capabilities) { $pods = pods_api()->load_pods(array('type' => array('pod', 'table', 'post_type', 'taxonomy', 'settings'))); $capabilities[] = 'pods'; $capabilities[] = 'pods_content'; $capabilities[] = 'pods_settings'; $capabilities[] = 'pods_components'; foreach ($pods as $pod) { if ('settings' == $pod['type']) { $capabilities[] = 'pods_edit_' . $pod['name']; } elseif ('post_type' == $pod['type']) { $capability_type = pods_var('capability_type_custom', $pod['options'], pods_var_raw('name', $pod)); if ('custom' == pods_var('capability_type', $pod['options']) && 0 < strlen($capability_type)) { $capabilities[] = 'read_' . $capability_type; $capabilities[] = 'edit_' . $capability_type; $capabilities[] = 'delete_' . $capability_type; if (1 == pods_var('capability_type_extra', $pod['options'], 1)) { $capabilities[] = 'read_private_' . $capability_type . 's'; $capabilities[] = 'edit_' . $capability_type . 's'; $capabilities[] = 'edit_others_' . $capability_type . 's'; $capabilities[] = 'edit_private_' . $capability_type . 's'; $capabilities[] = 'edit_published_' . $capability_type . 's'; $capabilities[] = 'publish_' . $capability_type . 's'; $capabilities[] = 'delete_' . $capability_type . 's'; $capabilities[] = 'delete_private_' . $capability_type . 's'; $capabilities[] = 'delete_published_' . $capability_type . 's'; $capabilities[] = 'delete_others_' . $capability_type . 's'; } } } elseif ('taxonomy' == $pod['type']) { if (1 == pods_var('capabilities', $pod['options'], 0)) { $capability_type = pods_var('capability_type_custom', $pod['options'], pods_var_raw('name', $pod) . 's'); $capabilities[] = 'manage_' . $capability_type; $capabilities[] = 'edit_' . $capability_type; $capabilities[] = 'delete_' . $capability_type; $capabilities[] = 'assign_' . $capability_type; } } else { $capabilities[] = 'pods_add_' . $pod['name']; $capabilities[] = 'pods_edit_' . $pod['name']; if (isset($pod['fields']['author']) && 'pick' == $pod['fields']['author']['type'] && 'user' == $pod['fields']['author']['pick_object']) { $capabilities[] = 'pods_edit_others_' . $pod['name']; } $capabilities[] = 'pods_delete_' . $pod['name']; if (isset($pod['fields']['author']) && 'pick' == $pod['fields']['author']['type'] && 'user' == $pod['fields']['author']['pick_object']) { $capabilities[] = 'pods_delete_others_' . $pod['name']; } $actions_enabled = pods_var_raw('ui_actions_enabled', $pod['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } if (!in_array('export', $actions_disabled)) { $capabilities[] = 'pods_export_' . $pod['name']; } if (!in_array('reorder', $actions_disabled)) { $capabilities[] = 'pods_reorder_' . $pod['name']; } } elseif (1 == pods_var('ui_export', $pod['options'], 0)) { $capabilities[] = 'pods_export_' . $pod['name']; } } } return $capabilities; }
/** * Validate a value before it's saved * * @param mixed $value * @param string $name * @param array $options * @param array $fields * @param array $pod * @param int $id * @param null $params * * @return array|bool * @since 2.0 */ public function validate($value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null) { $errors = array(); $check = $this->pre_save($value, $id, $name, $options, $fields, $pod, $params); if (is_array($check)) { $errors = $check; } else { if (0 < strlen($value) && strlen($check) < 1) { $label = pods_var('label', $options, ucwords(str_replace('_', ' ', $name))); if (1 == pods_var('required', $options)) { $errors[] = sprintf(__('%s is required', 'pods'), $label); } else { $errors[] = sprintf(__('Invalid e-mail provided for %s', 'pods'), $label); } } } if (!empty($errors)) { return $errors; } return true; }
/** * Validate a value before it's saved * * @param mixed $value * @param string $name * @param array $options * @param array $fields * @param array $pod * @param int $id * @param array $params * * @return array|bool * @since 2.0 */ public function validate($value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null) { $errors = array(); $check = $this->pre_save($value, $id, $name, $options, $fields, $pod, $params); if (is_array($check)) { $errors = $check; } else { $color = str_replace('#', '', $check); if (0 < strlen($value) && strlen($check) < 1) { if (1 == pods_var('required', $options)) { $errors[] = __('This field is required.', 'pods'); } else { // @todo Ask for a specific format in error message $errors[] = __('Invalid value provided for this field.', 'pods'); } } elseif (3 != strlen($color) && 6 != strlen($color) && 1 != empty($color)) { $errors[] = __('Invalid Hex Color value provided for this field.', 'pods'); } } if (!empty($errors)) { return $errors; } return true; }