/** * @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'; }
<?php ob_start(); require_once preg_replace("/wp-content.*/", "wp-load.php", __FILE__); ob_end_clean(); if (false === headers_sent()) { if ('' == session_id()) { @session_start(); } header('Content-Type: text/html; charset=' . get_bloginfo('charset')); } // Sanitize input $params = stripslashes_deep($_POST); if (!defined('PODS_STRICT_MODE') || !PODS_STRICT_MODE) { foreach ($params as $key => $val) { $params[$key] = pods_sanitize(trim($val)); } } $methods = array('save_pod' => array('priv' => 'manage_pods', 'format' => 'json'), 'save_column' => array('priv' => 'manage_pods'), 'save_template' => array('priv' => 'manage_templates'), 'save_page' => array('priv' => 'manage_pod_pages'), 'save_helper' => array('priv' => 'manage_helpers'), 'save_roles' => array('priv' => 'manage_roles'), 'save_pod_item' => array('processor' => 'process_save_pod_item'), 'reorder_pod_item' => array('access_pod_specific' => true), 'drop_pod' => array('priv' => 'manage_pods'), 'drop_column' => array('priv' => 'manage_pods'), 'drop_template' => array('priv' => 'manage_templates'), 'drop_page' => array('priv' => 'manage_pod_pages'), 'drop_helper' => array('priv' => 'manage_helpers'), 'drop_pod_item' => array('access_pod_specific' => true), 'load_pod' => array('priv' => 'manage_pods', 'format' => 'json'), 'load_column' => array('priv' => 'manage_pods', 'format' => 'json'), 'load_template' => array('priv' => 'manage_templates', 'format' => 'json'), 'load_page' => array('priv' => 'manage_pod_pages', 'format' => 'json'), 'load_helper' => array('priv' => 'manage_helpers', 'format' => 'json'), 'load_sister_fields' => array('priv' => 'manage_pods', 'format' => 'json'), 'load_pod_item' => array(), 'load_files' => array(), 'export_package' => array('priv' => 'manage_packages', 'format' => 'json', 'safe' => true), 'import_package' => array('priv' => 'manage_packages'), 'validate_package' => array('priv' => 'manage_packages'), 'replace_package' => array('priv' => 'manage_packages'), 'security_settings' => array('priv' => 'manage_settings'), 'pod_page_settings' => array('priv' => 'manage_settings'), 'fix_wp_pod' => array('priv' => 'manage_settings')); $api = new PodAPI(); $params = (object) $params; $action = $params->action; if (isset($methods[$action])) { $priv = isset($methods[$action]['priv']) ? $methods[$action]['priv'] : null; $format = isset($methods[$action]['format']) ? $methods[$action]['format'] : null; $processor = isset($methods[$action]['processor']) ? (string) $methods[$action]['processor'] : null; $safe = isset($methods[$action]['safe']) ? $methods[$action]['safe'] : null; $access_pod_specific = isset($methods[$action]['access_pod_specific']) ? $methods[$action]['access_pod_specific'] : null; if ('save_pod_item' == $action) { if (isset($params->_wpnonce) && false === wp_verify_nonce($params->_wpnonce, 'pods-' . $action)) { die('<e>Access denied');
/** * Recursively join tables based on fields * * @param array $traverse_recurse Array of traversal options * * @return array Array of table joins * * @since 2.0 */ function traverse_recurse($traverse_recurse) { global $wpdb; $defaults = array('pod' => null, 'fields' => array(), 'joined' => 't', 'depth' => 0, 'joined_id' => 'id', 'joined_index' => 'id', 'params' => new stdClass(), 'last_table_info' => array()); $traverse_recurse = array_merge($defaults, $traverse_recurse); $joins = array(); if (0 == $traverse_recurse['depth'] && !empty($traverse_recurse['pod']) && !empty($traverse_recurse['last_table_info']) && isset($traverse_recurse['last_table_info']['id'])) { $pod_data = $traverse_recurse['last_table_info']; } elseif (empty($traverse_recurse['pod'])) { if (!empty($traverse_recurse['params']) && !empty($traverse_recurse['params']->table) && 0 === strpos($traverse_recurse['params']->table, $wpdb->prefix)) { if ($wpdb->posts == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'post_type'; } elseif ($wpdb->terms == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'taxonomy'; } elseif ($wpdb->users == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'user'; } elseif ($wpdb->comments == $traverse_recurse['params']->table) { $traverse_recurse['pod'] = 'comment'; } else { return $joins; } $pod_data = array(); if (in_array($traverse_recurse['pod'], array('user', 'comment'))) { $pod = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true)); if (!empty($pod) && $pod['type'] == $pod) { $pod_data = $pod; } } if (empty($pod_data)) { $pod_data = array('id' => 0, 'name' => '_table_' . $traverse_recurse['pod'], 'type' => $traverse_recurse['pod'], 'storage' => 'taxonomy' == $traverse_recurse['pod'] ? 'none' : 'meta', 'fields' => array(), 'object_fields' => $this->api->get_wp_object_fields($traverse_recurse['pod'])); $pod_data = array_merge($this->api->get_table_info($traverse_recurse['pod'], ''), $pod_data); } $traverse_recurse['pod'] = $pod_data['name']; } else { return $joins; } } else { $pod_data = $this->api->load_pod(array('name' => $traverse_recurse['pod'], 'table_info' => true), false); if (empty($pod_data)) { return $joins; } } if (isset($pod_data['object_fields'])) { $pod_data['fields'] = array_merge($pod_data['fields'], $pod_data['object_fields']); } $tableless_field_types = PodsForm::tableless_field_types(); $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects'); $file_field_types = PodsForm::file_field_types(); if (!isset($this->traversal[$traverse_recurse['pod']])) { $this->traversal[$traverse_recurse['pod']] = array(); } if ((empty($pod_data['meta_table']) || $pod_data['meta_table'] == $pod_data['table']) && (empty($traverse_recurse['fields']) || !isset($traverse_recurse['fields'][$traverse_recurse['depth']]) || empty($traverse_recurse['fields'][$traverse_recurse['depth']]))) { return $joins; } $field = $traverse_recurse['fields'][$traverse_recurse['depth']]; $ignore_aliases = array('wpml_languages', 'polylang_languages'); $ignore_aliases = $this->do_hook('traverse_recurse_ignore_aliases', $ignore_aliases, $field, $traverse_recurse); if (in_array($field, $ignore_aliases)) { return $joins; } $meta_data_table = false; if (!isset($pod_data['fields'][$field]) && 'd' == $field && isset($traverse_recurse['fields'][$traverse_recurse['depth'] - 1])) { $field = $traverse_recurse['fields'][$traverse_recurse['depth'] - 1]; $field_type = 'pick'; if (isset($traverse_recurse['last_table_info']['pod']['fields'][$field])) { $field_type = $traverse_recurse['last_table_info']['pod']['fields'][$field]['type']; } elseif (isset($traverse_recurse['last_table_info']['pod']['object_fields'][$field])) { $field_type = $traverse_recurse['last_table_info']['pod']['object_fields'][$field]['type']; } $pod_data['fields'][$field] = array('id' => 0, 'name' => $field, 'type' => $field_type, 'pick_object' => $traverse_recurse['last_table_info']['pod']['type'], 'pick_val' => $traverse_recurse['last_table_info']['pod']['name']); $meta_data_table = true; } // Fallback to meta table if the pod type supports it if (!isset($pod_data['fields'][$field])) { $last = end($traverse_recurse['fields']); if ('post_type' == $pod_data['type'] && !isset($pod_data['object_fields'])) { $pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data); } if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) { $pod_data['fields'][$field] = $pod_data['object_fields'][$field]; } elseif (in_array($pod_data['type'], array('post_type', 'media', 'user', 'comment')) && 'meta_value' == $last) { $pod_data['fields'][$field] = PodsForm::field_setup(array('name' => $field)); } else { if ('post_type' == $pod_data['type']) { $pod_data['object_fields'] = $this->api->get_wp_object_fields('post_type', $pod_data, true); if ('post_type' == $pod_data['type'] && isset($pod_data['object_fields'][$field]) && in_array($pod_data['object_fields'][$field]['type'], $tableless_field_types)) { $pod_data['fields'][$field] = $pod_data['object_fields'][$field]; } else { return $joins; } } else { return $joins; } } } $traverse = $pod_data['fields'][$field]; if ('taxonomy' == $traverse['type']) { $traverse['table_info'] = $this->api->get_table_info($traverse['type'], $traverse['name']); } elseif (in_array($traverse['type'], $file_field_types)) { $traverse['table_info'] = $this->api->get_table_info('post_type', 'attachment'); } elseif (!in_array($traverse['type'], $tableless_field_types)) { $traverse['table_info'] = $this->api->get_table_info($pod_data['type'], $pod_data['name'], $pod_data['name'], $pod_data); } elseif (empty($traverse['table_info']) || in_array($traverse['pick_object'], $simple_tableless_objects) && !empty($traverse_recurse['last_table_info'])) { if (in_array($traverse['pick_object'], $simple_tableless_objects) && !empty($traverse_recurse['last_table_info'])) { $traverse['table_info'] = $traverse_recurse['last_table_info']; if (!empty($traverse['table_info']['meta_table'])) { $meta_data_table = true; } } elseif (!in_array($traverse['type'], $tableless_field_types) && isset($traverse_recurse['last_table_info']) && !empty($traverse_recurse['last_table_info']) && 0 == $traverse_recurse['depth']) { $traverse['table_info'] = $traverse_recurse['last_table_info']; } else { $traverse['table_info'] = $this->api->get_table_info($traverse['pick_object'], $traverse['pick_val'], null, $traverse['pod'], $traverse); } } if (isset($this->traversal[$traverse_recurse['pod']][$traverse['name']])) { $traverse = array_merge($traverse, (array) $this->traversal[$traverse_recurse['pod']][$traverse['name']]); } $traverse = $this->do_hook('traverse', $traverse, compact('pod', 'fields', 'joined', 'depth', 'joined_id', 'params')); if (empty($traverse)) { return $joins; } $traverse = pods_sanitize($traverse); $traverse['id'] = (int) $traverse['id']; if (empty($traverse['id'])) { $traverse['id'] = $field; } $table_info = $traverse['table_info']; $this->traversal[$traverse_recurse['pod']][$field] = $traverse; $field_joined = $field; if (0 < $traverse_recurse['depth'] && 't' != $traverse_recurse['joined']) { if ($meta_data_table && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects))) { $field_joined = $traverse_recurse['joined'] . '_d'; } else { $field_joined = $traverse_recurse['joined'] . '_' . $field; } } $rel_alias = 'rel_' . $field_joined; if (pods_var('search', $traverse_recurse['params'], false) && empty($traverse_recurse['params']->filters)) { if (0 < strlen(pods_var('filter_' . $field_joined, 'get'))) { $val = absint(pods_var('filter_' . $field_joined, 'get')); $search = "`{$field_joined}`.`{$table_info['field_id']}` = {$val}"; if ('text' == $this->search_mode) { $val = pods_var('filter_' . $field_joined, 'get'); $search = "`{$field_joined}`.`{$traverse['name']}` = '{$val}'"; } elseif ('text_like' == $this->search_mode) { $val = pods_sanitize(pods_sanitize_like(pods_var_raw('filter_' . $field_joined))); $search = "`{$field_joined}`.`{$traverse['name']}` LIKE '%{$val}%'"; } $this->search_where[] = " {$search} "; } } $the_join = null; $joined_id = $table_info['field_id']; $joined_index = $table_info['field_index']; if ('taxonomy' == $traverse['type']) { $rel_tt_alias = 'rel_tt_' . $field_joined; if ($meta_data_table) { $the_join = "\n LEFT JOIN `{$table_info['pod_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['pod_field_id']}` = `{$traverse_recurse['rel_alias']}`.`{$traverse_recurse['joined_id']}`\n "; } else { $the_join = "\n LEFT JOIN `{$wpdb->term_relationships}` AS `{$rel_alias}` ON\n `{$rel_alias}`.`object_id` = `{$traverse_recurse['joined']}`.`ID`\n\n LEFT JOIN `{$wpdb->term_taxonomy}` AS `{$rel_tt_alias}` ON\n `{$rel_tt_alias}`.`taxonomy` = '{$traverse['name']}'\n AND `{$rel_tt_alias}`.`term_taxonomy_id` = `{$rel_alias}`.`term_taxonomy_id`\n\n LEFT JOIN `{$table_info['table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['field_id']}` = `{$rel_tt_alias}`.`{$table_info['field_id']}`\n "; // Override $rel_alias $rel_alias = $field_joined; $joined_id = $table_info['field_id']; $joined_index = $table_info['field_index']; } } elseif (in_array($traverse['type'], $tableless_field_types) && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects))) { if (pods_tableless()) { $the_join = "\n LEFT JOIN `{$table_info['meta_table']}` AS `{$rel_alias}` ON\n `{$rel_alias}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$rel_alias}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n\n LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$field_joined}`.`{$table_info['meta_field_id']}` = CONVERT( `{$rel_alias}`.`{$table_info['meta_field_value']}`, SIGNED )\n "; $joined_id = $table_info['meta_field_id']; $joined_index = $table_info['meta_field_index']; } elseif ($meta_data_table) { $the_join = "\n LEFT JOIN `{$table_info['pod_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['pod_field_id']}` = `{$traverse_recurse['rel_alias']}`.`{$traverse_recurse['joined_id']}`\n "; } else { $the_join = "\n LEFT JOIN `@wp_podsrel` AS `{$rel_alias}` ON\n `{$rel_alias}`.`field_id` = {$traverse['id']}\n AND `{$rel_alias}`.`item_id` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n\n LEFT JOIN `{$table_info['table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['field_id']}` = `{$rel_alias}`.`related_item_id`\n "; } } elseif ('meta' == $pod_data['storage']) { if ($traverse_recurse['depth'] + 2 == count($traverse_recurse['fields']) && ('pick' != $traverse['type'] || !in_array(pods_var('pick_object', $traverse), $simple_tableless_objects)) && $table_info['meta_field_value'] == $traverse_recurse['fields'][$traverse_recurse['depth'] + 1]) { $the_join = "\n LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$field_joined}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n "; $table_info['recurse'] = false; } else { $the_join = "\n LEFT JOIN `{$table_info['meta_table']}` AS `{$field_joined}` ON\n `{$field_joined}`.`{$table_info['meta_field_index']}` = '{$traverse['name']}'\n AND `{$field_joined}`.`{$table_info['meta_field_id']}` = `{$traverse_recurse['joined']}`.`{$traverse_recurse['joined_id']}`\n "; $joined_id = $table_info['meta_field_id']; $joined_index = $table_info['meta_field_index']; } } $traverse_recursive = array('pod' => pods_var_raw('name', pods_var_raw('pod', $table_info)), 'fields' => $traverse_recurse['fields'], 'joined' => $field_joined, 'depth' => $traverse_recurse['depth'] + 1, 'joined_id' => $joined_id, 'joined_index' => $joined_index, 'params' => $traverse_recurse['params'], 'rel_alias' => $rel_alias, 'last_table_info' => $table_info); $the_join = $this->do_hook('traverse_the_join', $the_join, $traverse_recurse, $traverse_recursive); if (empty($the_join)) { return $joins; } $joins[$traverse_recurse['pod'] . '_' . $traverse_recurse['depth'] . '_' . $traverse['id']] = $the_join; if ($traverse_recurse['depth'] + 1 < count($traverse_recurse['fields']) && !empty($traverse_recurse['pod']) && false !== $table_info['recurse']) { $joins = array_merge($joins, $this->traverse_recurse($traverse_recursive)); } return $joins; }
/** * Evaluate tag like magic tag but mapped through pods_v * * @param string|array $tag * @param bool $sanitize Whether to sanitize tags * * @return string * * @version 2.1 */ function pods_evaluate_tag($tag, $sanitize = false) { global $wpdb; // Handle pods_evaluate_tags if (is_array($tag)) { if (!isset($tag[2]) && strlen(trim($tag[2])) < 1) { return ''; } $tag = $tag[2]; } $tag = trim($tag, ' {@}'); $tag = explode('.', $tag); if (empty($tag) || !isset($tag[0]) || strlen(trim($tag[0])) < 1) { return ''; } // Fix formatting that may be after the first . if (2 < count($tag)) { $first_tag = $tag[0]; unset($tag[0]); $tag = array($first_tag, implode('.', $tag)); } foreach ($tag as $k => $v) { $tag[$k] = trim($v); } $value = ''; $single_supported = array('template-url', 'stylesheet-url', 'site-url', 'home-url', 'admin-url', 'includes-url', 'content-url', 'plugins-url', 'network-site-url', 'network-home-url', 'network-admin-url', 'user-admin-url', 'prefix'); if (in_array($tag[0], $single_supported)) { $value = pods_v('', $tag[0], '', true); } elseif (1 == count($tag)) { $value = pods_v($tag[0], 'get', '', true); } elseif (2 == count($tag)) { $value = pods_v($tag[1], $tag[0], '', true); } $value = apply_filters('pods_evaluate_tag', $value, $tag); if (is_array($value) && 1 == count($value)) { $value = current($value); } if (is_array($value)) { $value = pods_serial_comma($value); } if ($sanitize) { $value = pods_sanitize($value); } return $value; }
/** * Import data from an array or a CSV file. * * @param mixed $import_data PHP associative array or CSV input * @param bool $numeric_mode Use IDs instead of the name field when matching * @param string $format Format of import data, options are php or csv * * @return array IDs of imported items * * @since 1.7.1 * @todo This needs some love and use of table_info etc for relationships */ public function import($import_data, $numeric_mode = false, $format = null) { /** * @var $wpdb wpdb */ global $wpdb; if (null === $format && null !== $this->format) { $format = $this->format; } if ('csv' == $format && !is_array($import_data)) { $data = pods_migrate('sv', ',')->parse($import_data); $import_data = $data['items']; } pods_query("SET NAMES utf8"); pods_query("SET CHARACTER SET utf8"); // Loop through the array of items $ids = array(); // Test to see if it's an array of arrays if (!is_array(@current($import_data))) { $import_data = array($import_data); } $pod = $this->load_pod(array('name' => $this->pod)); if (false === $pod) { return pods_error(__('Pod not found', 'pods'), $this); } $fields = array_merge($pod['fields'], $pod['object_fields']); $simple_tableless_objects = PodsForm::simple_tableless_objects(); foreach ($import_data as $key => $data_row) { $data = array(); // Loop through each field (use $fields so only valid fields get parsed) foreach ($fields as $field_name => $field_data) { if (!isset($data_row[$field_name]) && !isset($data_row[$field_data['label']])) { continue; } $field_id = $field_data['id']; $type = $field_data['type']; $pick_object = isset($field_data['pick_object']) ? $field_data['pick_object'] : ''; $pick_val = isset($field_data['pick_val']) ? $field_data['pick_val'] : ''; if (isset($data_row[$field_name])) { $field_value = $data_row[$field_name]; } else { $field_value = $data_row[$field_data['label']]; } if (null !== $field_value && false !== $field_value && '' !== $field_value) { if ('pick' == $type || in_array($type, PodsForm::file_field_types())) { $field_values = is_array($field_value) ? $field_value : array($field_value); $pick_values = array(); foreach ($field_values as $pick_value) { if (in_array($type, PodsForm::file_field_types()) || 'media' == $pick_object) { $where = "`guid` = '" . pods_sanitize($pick_value) . "'"; if (0 < pods_absint($pick_value) && false !== $numeric_mode) { $where = "`ID` = " . pods_absint($pick_value); } $result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = 'attachment' AND {$where} ORDER BY `ID`", $this); if (!empty($result)) { $pick_values[] = $result[0]->id; } } elseif ('pick' == $type) { $related_pod = false; if ('pod' == $pick_object) { $related_pod = $this->load_pod(array('name' => $pick_val, 'table_info' => true), false); } if (empty($related_pod)) { $related_pod = array('id' => 0, 'type' => $pick_object); } if (in_array('taxonomy', array($pick_object, $related_pod['type']))) { $where = "`t`.`name` = '" . pods_sanitize($pick_value) . "'"; if (0 < pods_absint($pick_value) && false !== $numeric_mode) { $where = "`tt`.`term_id` = " . pods_absint($pick_value); } $result = pods_query("SELECT `t`.`term_id` AS `id` FROM `{$wpdb->term_taxonomy}` AS `tt` LEFT JOIN `{$wpdb->terms}` AS `t` ON `t`.`term_id` = `tt`.`term_id` WHERE `taxonomy` = '{$pick_val}' AND {$where} ORDER BY `t`.`term_id`", $this); if (!empty($result)) { $pick_values[] = $result[0]->id; } } elseif (in_array('post_type', array($pick_object, $related_pod['type'])) || in_array('media', array($pick_object, $related_pod['type']))) { $where = "`post_title` = '" . pods_sanitize($pick_value) . "'"; if (0 < pods_absint($pick_value) && false !== $numeric_mode) { $where = "`ID` = " . pods_absint($pick_value); } $result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->posts}` WHERE `post_type` = '{$pick_val}' AND {$where} ORDER BY `ID`", $this); if (!empty($result)) { $pick_values[] = $result[0]->id; } } elseif (in_array('user', array($pick_object, $related_pod['type']))) { $where = "`user_login` = '" . pods_sanitize($pick_value) . "'"; if (0 < pods_absint($pick_value) && false !== $numeric_mode) { $where = "`ID` = " . pods_absint($pick_value); } $result = pods_query("SELECT `ID` AS `id` FROM `{$wpdb->users}` WHERE {$where} ORDER BY `ID`", $this); if (!empty($result)) { $pick_values[] = $result[0]->id; } } elseif (in_array('comment', array($pick_object, $related_pod['type']))) { $where = "`comment_ID` = " . pods_absint($pick_value); $result = pods_query("SELECT `comment_ID` AS `id` FROM `{$wpdb->comments}` WHERE {$where} ORDER BY `ID`", $this); if (!empty($result)) { $pick_values[] = $result[0]->id; } } elseif (in_array($pick_object, $simple_tableless_objects)) { $pick_values[] = $pick_value; } elseif (!empty($related_pod['id'])) { $where = "`" . $related_pod['field_index'] . "` = '" . pods_sanitize($pick_value) . "'"; if (0 < pods_absint($pick_value) && false !== $numeric_mode) { $where = "`" . $related_pod['field_id'] . "` = " . pods_absint($pick_value); } $result = pods_query("SELECT `" . $related_pod['field_id'] . "` AS `id` FROM `" . $related_pod['table'] . "` WHERE {$where} ORDER BY `" . $related_pod['field_id'] . "`", $this); if (!empty($result)) { $pick_values[] = $result[0]->id; } } } } $field_value = implode(',', $pick_values); } $data[$field_name] = $field_value; } } if (!empty($data)) { $params = array('pod' => $this->pod, 'data' => $data); $ids[] = $this->save_pod_item($params); } } return $ids; }
add_option('pods_files_require_login_cap', 'upload_files'); add_option('pods_disable_file_upload', 0); add_option('pods_upload_require_login', 0); add_option('pods_upload_require_login_cap', 'upload_files'); update_option('pods_version', '196'); } if (version_compare($old_version, '1.9.7', '<')) { pods_query("ALTER TABLE `@wp_pod` CHANGE `id` `id` BIGINT(15) UNSIGNED NOT NULL AUTO_INCREMENT"); pods_query("ALTER TABLE `@wp_pod` CHANGE `tbl_row_id` `tbl_row_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pods_query("ALTER TABLE `@wp_pod` CHANGE `author_id` `author_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pods_query("ALTER TABLE `@wp_pod_rel` CHANGE `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT"); pods_query("ALTER TABLE `@wp_pod_rel` CHANGE `pod_id` `pod_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pods_query("ALTER TABLE `@wp_pod_rel` CHANGE `sister_pod_id` `sister_pod_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pods_query("ALTER TABLE `@wp_pod_rel` CHANGE `tbl_row_id` `tbl_row_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pods_query("ALTER TABLE `@wp_pod_rel` CHANGE `weight` `weight` INT(10) UNSIGNED NULL DEFAULT '0'"); update_option('pods_version', '197'); } if (version_compare($old_version, '1.11', '<')) { pods_query("ALTER TABLE `@wp_pod` CHANGE `datatype` `datatype` INT(10) UNSIGNED NULL DEFAULT NULL"); pods_query("ALTER TABLE `@wp_pod` DROP INDEX `datatype_idx`", false); pods_query("ALTER TABLE `@wp_pod` ADD INDEX `datatype_row_idx` (`datatype`, `tbl_row_id`)", false); pods_query("ALTER TABLE `@wp_pod_rel` DROP INDEX `field_id_idx`", false); pods_query("ALTER TABLE `@wp_pod_rel` ADD INDEX `field_pod_idx` (`field_id`, `pod_id`)", false); pods_query("ALTER TABLE `@wp_pod_fields` CHANGE `datatype` `datatype` INT(10) UNSIGNED NULL DEFAULT NULL"); $result = pods_query("SELECT id, name FROM @wp_pod_types"); foreach ($result as $row) { $pod = pods_sanitize($row->name); pods_query("ALTER TABLE `@wp_pod_tbl_{$pod}` CHANGE `id` `id` BIGINT(15) UNSIGNED NOT NULL AUTO_INCREMENT"); } update_option('pods_version', '001011000'); }
add_option('pods_upload_require_login', 0); add_option('pods_upload_require_login_cap', 'upload_files'); update_option('pods_version', '196'); } if (version_compare($installed, '1.9.7', '<')) { pod_query("ALTER TABLE `@wp_pod` CHANGE `id` `id` BIGINT(15) UNSIGNED NOT NULL AUTO_INCREMENT"); pod_query("ALTER TABLE `@wp_pod` CHANGE `tbl_row_id` `tbl_row_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pod_query("ALTER TABLE `@wp_pod` CHANGE `author_id` `author_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pod_query("ALTER TABLE `@wp_pod_rel` CHANGE `id` `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT"); pod_query("ALTER TABLE `@wp_pod_rel` CHANGE `pod_id` `pod_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pod_query("ALTER TABLE `@wp_pod_rel` CHANGE `sister_pod_id` `sister_pod_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pod_query("ALTER TABLE `@wp_pod_rel` CHANGE `tbl_row_id` `tbl_row_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL"); pod_query("ALTER TABLE `@wp_pod_rel` CHANGE `weight` `weight` INT(10) UNSIGNED NULL DEFAULT '0'"); update_option('pods_version', '197'); } if (version_compare($installed, '1.11', '<')) { pod_query("ALTER TABLE `@wp_pod` CHANGE `datatype` `datatype` INT(10) UNSIGNED NULL DEFAULT NULL"); pod_query("ALTER TABLE `@wp_pod` DROP INDEX `datatype_idx`", false); pod_query("ALTER TABLE `@wp_pod` ADD INDEX `datatype_row_idx` (`datatype`, `tbl_row_id`)", false); pod_query("ALTER TABLE `@wp_pod_rel` DROP INDEX `field_id_idx`", false); pod_query("ALTER TABLE `@wp_pod_rel` ADD INDEX `field_pod_idx` (`field_id`, `pod_id`)", false); pod_query("ALTER TABLE `@wp_pod_fields` CHANGE `datatype` `datatype` INT(10) UNSIGNED NULL DEFAULT NULL"); $result = pod_query("SELECT id, name FROM @wp_pod_types"); while ($row = mysql_fetch_assoc($result)) { $pod = pods_sanitize($row['name']); pod_query("ALTER TABLE `@wp_pod_tbl_{$pod}` CHANGE `id` `id` BIGINT(15) UNSIGNED NOT NULL AUTO_INCREMENT"); } update_option('pods_version', '001011000'); } // Save this version update_option('pods_version', PODS_VERSION);
/** * @param bool $reorder * * @return bool|mixed */ public function table($reorder = false) { if (false !== $this->callback('table', $reorder)) { return null; } if (empty($this->data)) { ?> <p><?php echo sprintf(__('No %s found', 'pods'), $this->items); ?> </p> <?php return false; } if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { ?> <style type="text/css"> table.widefat.fixed tbody.reorderable tr { height: 50px; } .dragme { background: url(<?php echo esc_url(PODS_URL); ?> /ui/images/handle.gif) no-repeat; background-position: 8px 8px; cursor: pointer; } .dragme strong { margin-left: 30px; } </style> <form action="<?php echo esc_url(pods_query_arg(array('action' . $this->num => 'reorder', 'do' . $this->num => 'save', 'page' => pods_var_raw('page')), self::$allowed, $this->exclusion())); ?> " method="post" class="admin_ui_reorder_form"> <?php } $table_fields = $this->fields['manage']; if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { $table_fields = $this->fields['reorder']; } if (false === $table_fields || empty($table_fields)) { return $this->error(__('<strong>Error:</strong> Invalid Configuration - Missing "fields" definition.', 'pods')); } ?> <table class="widefat page fixed wp-list-table" cellspacing="0"<?php echo 1 == $reorder && $this->reorder ? ' id="admin_ui_reorder"' : ''; ?> > <thead> <tr> <?php if (!empty($this->actions_bulk)) { ?> <th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox" /></th> <?php } $name_field = false; $fields = array(); if (!empty($table_fields)) { foreach ($table_fields as $field => $attributes) { if (false === $attributes['display']) { continue; } if (false === $name_field) { $id = 'title'; } else { $id = ''; } if ('other' == $attributes['type']) { $id = ''; } if (in_array($attributes['type'], array('date', 'datetime', 'time'))) { $id = 'date'; } if (false === $name_field && 'title' == $id) { $name_field = true; } $fields[$field] = $attributes; $fields[$field]['field_id'] = $id; $dir = 'DESC'; $current_sort = ' asc'; if (isset($this->orderby['default']) && $field == $this->orderby['default']) { if ('DESC' == $this->orderby_dir) { $dir = 'ASC'; $current_sort = ' desc'; } } $att_id = ''; if (!empty($id)) { $att_id = ' id="' . esc_attr($id) . '"'; } $width = ''; if (isset($attributes['width']) && !empty($attributes['width'])) { $width = ' style="width: ' . esc_attr($attributes['width']) . '"'; } if ($fields[$field]['sortable']) { ?> <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr($id); ?> sortable<?php echo esc_attr($current_sort); ?> "<?php echo $width; ?> > <a href="<?php echo esc_url_raw(pods_query_arg(array('orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir), array('limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page'), $this->exclusion())); ?> "> <span><?php echo $attributes['label']; ?> </span> <span class="sorting-indicator"></span> </a> </th> <?php } else { ?> <th scope="col"<?php echo $att_id; ?> class="manage-column column-<?php echo esc_attr($id); ?> "<?php echo $width; ?> ><?php echo $attributes['label']; ?> </th> <?php } } } ?> </tr> </thead> <?php if (6 < $this->total_found) { ?> <tfoot> <tr> <?php if (!empty($this->actions_bulk)) { ?> <th scope="col" class="manage-column column-cb check-column"><input type="checkbox" /></th> <?php } if (!empty($fields)) { foreach ($fields as $field => $attributes) { $dir = 'ASC'; if ($field == $this->orderby) { $current_sort = 'desc'; if ('ASC' == $this->orderby_dir) { $dir = 'DESC'; $current_sort = 'asc'; } } $width = ''; if (isset($attributes['width']) && !empty($attributes['width'])) { $width = ' style="width: ' . esc_attr($attributes['width']) . '"'; } if ($fields[$field]['sortable']) { ?> <th scope="col" class="manage-column column-<?php echo esc_attr($id); ?> sortable <?php echo esc_attr($current_sort); ?> "<?php echo $width; ?> ><a href="<?php echo esc_url_raw(pods_query_arg(array('orderby' . $this->num => $field, 'orderby_dir' . $this->num => $dir), array('limit' . $this->num, 'search' . $this->num, 'pg' . $this->num, 'page'), $this->exclusion())); ?> "><span><?php echo $attributes['label']; ?> </span><span class="sorting-indicator"></span></a></th> <?php } else { ?> <th scope="col" class="manage-column column-<?php echo esc_attr($id); ?> "<?php echo $width; ?> ><?php echo $attributes['label']; ?> </th> <?php } } } ?> </tr> </tfoot> <?php } ?> <tbody id="the-list"<?php echo true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on'] ? ' class="reorderable"' : ''; ?> > <?php if (!empty($this->data) && is_array($this->data)) { $counter = 0; while ($row = $this->get_row($counter, 'table')) { if (is_object($row)) { $row = get_object_vars((object) $row); } $toggle_class = ''; if (is_array($this->actions_custom) && isset($this->actions_custom['toggle'])) { $toggle_class = ' pods-toggled-on'; if (!isset($row['toggle']) || empty($row['toggle'])) { $toggle_class = ' pods-toggled-off'; } } ?> <tr id="item-<?php echo esc_attr($row[$this->sql['field_id']]); ?> " class="iedit<?php echo esc_attr($toggle_class); ?> "> <?php if (!empty($this->actions_bulk)) { ?> <th scope="row" class="check-column"><input type="checkbox" name="action_bulk_ids<?php echo esc_attr($this->num); ?> []" value="<?php echo esc_attr($row[$this->sql['field_id']]); ?> "></th> <?php } foreach ($fields as $field => $attributes) { if (false === $attributes['display']) { continue; } if (!isset($row[$field])) { $row[$field] = $this->get_field($field); } $row_value = $row[$field]; if (!empty($attributes['custom_display'])) { if (is_callable($attributes['custom_display'])) { $row_value = call_user_func_array($attributes['custom_display'], array($row, &$this, $row_value, $field, $attributes)); } elseif (is_object($this->pod) && class_exists('Pods_Helpers')) { $row_value = $this->pod->helper($attributes['custom_display'], $row_value, $field); } } else { ob_start(); $field_value = PodsForm::field_method($attributes['type'], 'ui', $this->id, $row_value, $field, array_merge($attributes, pods_var_raw('options', $attributes, array(), null, true)), $fields, $this->pod); $field_output = trim((string) ob_get_clean()); if (false === $field_value) { $row_value = ''; } elseif (0 < strlen(trim((string) $field_value))) { $row_value = trim((string) $field_value); } elseif (0 < strlen($field_output)) { $row_value = $field_output; } } if (false !== $attributes['custom_relate']) { global $wpdb; $table = $attributes['custom_relate']; $on = $this->sql['field_id']; $is = $row[$this->sql['field_id']]; $what = array('name'); if (is_array($table)) { if (isset($table['on'])) { $on = pods_sanitize($table['on']); } if (isset($table['is']) && isset($row[$table['is']])) { $is = pods_sanitize($row[$table['is']]); } if (isset($table['what'])) { $what = array(); if (is_array($table['what'])) { foreach ($table['what'] as $wha) { $what[] = pods_sanitize($wha); } } else { $what[] = pods_sanitize($table['what']); } } if (isset($table['table'])) { $table = $table['table']; } } $table = pods_sanitize($table); $wha = implode(',', $what); $sql = "SELECT {$wha} FROM {$table} WHERE `{$on}`='{$is}'"; $value = @current($wpdb->get_results($sql, ARRAY_A)); if (!empty($value)) { $val = array(); foreach ($what as $wha) { if (isset($value[$wha])) { $val[] = $value[$wha]; } } if (!empty($val)) { $row_value = implode(' ', $val); } } } $css_classes = ' pods-ui-col-field-' . sanitize_title($field); if ($attributes['css_values']) { $css_field_value = $row[$field]; if (is_object($css_field_value)) { $css_field_value = get_object_vars($css_field_value); } if (is_array($css_field_value)) { foreach ($css_field_value as $css_field_val) { if (is_object($css_field_val)) { $css_field_val = get_object_vars($css_field_val); } if (is_array($css_field_val)) { foreach ($css_field_val as $css_field_v) { if (is_object($css_field_v)) { $css_field_v = get_object_vars($css_field_v); } $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_v))); } } else { $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_val))); } } } else { $css_classes .= ' pods-ui-css-value-' . sanitize_title(str_replace(array("\n", "\r"), ' ', strip_tags((string) $css_field_value))); } } if (is_object($this->pod)) { $row_value = $this->do_hook($this->pod->pod . '_field_value', $row_value, $field, $attributes, $row); } $row_value = $this->do_hook('field_value', $row_value, $field, $attributes, $row); if ('title' == $attributes['field_id']) { $default_action = $this->do_hook('default_action', 'edit', $row); if (!in_array('edit', $this->actions_disabled) && !in_array('edit', $this->actions_hidden) && (false === $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) && 'edit' == $default_action) { $link = pods_query_arg(array('action' . $this->num => 'edit', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['edit'])) { $link = $this->do_template($this->action_links['edit'], $row); } ?> <td class="post-title page-title column-title<?php echo esc_attr($css_classes); ?> "><strong><a class="row-title" href="<?php echo esc_url_raw($link); ?> " title="<?php esc_attr_e('Edit this item', 'pods'); ?> "><?php echo $row_value; ?> </a></strong> <?php } elseif (!in_array('view', $this->actions_disabled) && !in_array('view', $this->actions_hidden) && (false === $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) && 'view' == $default_action) { $link = pods_query_arg(array('action' . $this->num => 'view', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['view'])) { $link = $this->do_template($this->action_links['view'], $row); } ?> <td class="post-title page-title column-title<?php echo esc_attr($css_classes); ?> "><strong><a class="row-title" href="<?php echo esc_url_raw($link); ?> " title="<?php esc_attr_e('View this item', 'pods'); ?> "><?php echo $row_value; ?> </a></strong> <?php } else { ?> <td class="post-title page-title column-title<?php echo esc_attr($css_classes); echo esc_attr(1 == $reorder && $this->reorder ? ' dragme' : ''); ?> "><strong><?php echo $row_value; ?> </strong> <?php } if (true !== $reorder || in_array('reorder', $this->actions_disabled) || false === $this->reorder['on']) { $toggle = false; $actions = array(); if (!in_array('view', $this->actions_disabled) && !in_array('view', $this->actions_hidden)) { $link = pods_query_arg(array('action' . $this->num => 'view', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['view'])) { $link = $this->do_template($this->action_links['view'], $row); } $actions['view'] = '<span class="view"><a href="' . esc_url($link) . '" title="' . esc_attr__('View this item', 'pods') . '">' . __('View', 'pods') . '</a></span>'; } if (!in_array('edit', $this->actions_disabled) && !in_array('edit', $this->actions_hidden) && !$this->restricted('edit', $row)) { $link = pods_query_arg(array('action' . $this->num => 'edit', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['edit'])) { $link = $this->do_template($this->action_links['edit'], $row); } $actions['edit'] = '<span class="edit"><a href="' . esc_url($link) . '" title="' . esc_attr__('Edit this item', 'pods') . '">' . __('Edit', 'pods') . '</a></span>'; } if (!in_array('duplicate', $this->actions_disabled) && !in_array('duplicate', $this->actions_hidden) && !$this->restricted('edit', $row)) { $link = pods_query_arg(array('action' . $this->num => 'duplicate', 'id' . $this->num => $row[$this->sql['field_id']]), self::$allowed, $this->exclusion()); if (!empty($this->action_links['duplicate'])) { $link = $this->do_template($this->action_links['duplicate'], $row); } $actions['duplicate'] = '<span class="edit"><a href="' . esc_url($link) . '" title="' . esc_attr__('Duplicate this item', 'pods') . '">' . __('Duplicate', 'pods') . '</a></span>'; } if (!in_array('delete', $this->actions_disabled) && !in_array('delete', $this->actions_hidden) && !$this->restricted('delete', $row)) { $link = pods_query_arg(array('action' . $this->num => 'delete', 'id' . $this->num => $row[$this->sql['field_id']], '_wpnonce' => wp_create_nonce('pods-ui-action-delete')), self::$allowed, $this->exclusion()); if (!empty($this->action_links['delete'])) { $link = add_query_arg(array('_wpnonce' => wp_create_nonce('pods-ui-action-delete')), $this->do_template($this->action_links['delete'], $row)); } $actions['delete'] = '<span class="delete"><a href="' . esc_url($link) . '" title="' . esc_attr__('Delete this item', 'pods') . '" class="submitdelete" onclick="if(confirm(\'' . esc_attr__('You are about to permanently delete this item\\n Choose \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', 'pods') . '\')){return true;}return false;">' . __('Delete', 'pods') . '</a></span>'; } if (is_array($this->actions_custom)) { foreach ($this->actions_custom as $custom_action => $custom_data) { if ('add' != $custom_action && is_array($custom_data) && (isset($custom_data['link']) || isset($custom_data['callback'])) && !in_array($custom_action, $this->actions_disabled) && !in_array($custom_action, $this->actions_hidden)) { if (!in_array($custom_action, array('add', 'view', 'edit', 'duplicate', 'delete', 'save', 'export', 'reorder', 'manage', 'table'))) { if ('toggle' == $custom_action) { $toggle = true; $toggle_labels = array(__('Enable', 'pods'), __('Disable', 'pods')); $custom_data['label'] = $row['toggle'] ? $toggle_labels[1] : $toggle_labels[0]; } if (!isset($custom_data['label'])) { $custom_data['label'] = ucwords(str_replace('_', ' ', $custom_action)); } if (!isset($custom_data['link'])) { $vars = array('action' => $custom_action, 'id' => $row[$this->sql['field_id']], '_wpnonce' => wp_create_nonce('pods-ui-action-' . $custom_action)); if ('toggle' == $custom_action) { $vars['toggle'] = (int) (!$row['toggle']); $vars['toggled'] = 1; } $custom_data['link'] = pods_query_arg($vars, self::$allowed, $this->exclusion()); if (isset($this->action_links[$custom_action]) && !empty($this->action_links[$custom_action])) { $custom_data['link'] = add_query_arg(array('_wpnonce' => wp_create_nonce('pods-ui-action-' . $custom_action)), $this->do_template($this->action_links[$custom_action], $row)); } } $confirm = ''; if (isset($custom_data['confirm'])) { $confirm = ' onclick="if(confirm(\'' . esc_js($custom_data['confirm']) . '\')){return true;}return false;"'; } if ($this->restricted($custom_action, $row)) { continue; } $actions[$custom_action] = '<span class="edit action-' . esc_attr($custom_action) . '"><a href="' . esc_url($this->do_template($custom_data['link'], $row)) . '" title="' . esc_attr($custom_data['label']) . ' this item"' . $confirm . '>' . $custom_data['label'] . '</a></span>'; } } } } $actions = $this->do_hook('row_actions', $actions, $row[$this->sql['field_id']]); if (!empty($actions)) { ?> <div class="row-actions<?php echo esc_attr($toggle ? ' row-actions-toggle' : ''); ?> "> <?php $this->callback('actions_start', $row, $actions); echo implode(' | ', $actions); $this->callback('actions_end', $row, $actions); ?> </div> <?php } } else { ?> <input type="hidden" name="order[]" value="<?php echo esc_attr($row[$this->sql['field_id']]); ?> " /> <?php } ?> </td> <?php } elseif ('date' == $attributes['type']) { ?> <td class="date column-date<?php echo esc_attr($css_classes); ?> "><abbr title="<?php echo esc_attr($row_value); ?> "><?php echo $row_value; ?> </abbr></td> <?php } else { ?> <td class="author<?php echo esc_attr($css_classes); ?> "><span><?php echo $row_value; ?> </span></td> <?php } } ?> </tr> <?php } } ?> </tbody> </table> <?php if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { ?> </form> <?php } ?> <script type="text/javascript"> jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' ); <?php if (true === $reorder && !in_array('reorder', $this->actions_disabled) && false !== $this->reorder['on']) { ?> jQuery( document ).ready( function () { jQuery( ".reorderable" ).sortable( {axis : "y", handle : ".dragme"} ); jQuery( ".reorderable" ).bind( 'sortupdate', function ( event, ui ) { jQuery( 'table.widefat tbody tr' ).removeClass( 'alternate' ); jQuery( 'table.widefat tbody tr:even' ).addClass( 'alternate' ); } ); } ); <?php } ?> </script> <?php }
/** * Save the fields * * @param $_null * @param int $post_ID * @param string $meta_key * @param null $meta_value * * @return bool|int|null */ public function save_meta($_null, $post_ID = null, $meta_key = null, $meta_value = null) { if ('code' == $meta_key) { $post = get_post($post_ID); if (is_object($post) && $this->object_type == $post->post_type) { $postdata = array('ID' => $post_ID, 'post_content' => pods_sanitize($meta_value)); remove_filter(current_filter(), array($this, __FUNCTION__), 10); $revisions = false; if (has_action('pre_post_update', 'wp_save_post_revision')) { remove_action('pre_post_update', 'wp_save_post_revision'); $revisions = true; } wp_update_post($postdata); if ($revisions) { add_action('pre_post_update', 'wp_save_post_revision'); } return true; } } return $_null; }
/** * Build a unique slug * * @todo Simplify this function - get rid of the pod_id crap * @param string $value The slug value * @param string $column_name The column name * @param string $datatype The datatype name * @param int $datatype_id The datatype ID * @param int $pod_id The item's ID in the wp_pod table * @return string The unique slug name * @since 1.7.2 */ function pods_unique_slug($value, $column_name, $datatype, $datatype_id = 0, $pod_id = 0) { $value = sanitize_title($value); $slug = pods_sanitize($value); $tbl_row_id = 0; if (is_object($datatype)) { if (isset($datatype->tbl_row_id)) { $tbl_row_id = $datatype->tbl_row_id; } if (isset($datatype->pod_id)) { $pod_id = $datatype->pod_id; } if (isset($datatype->datatype_id)) { $datatype_id = $datatype->datatype_id; } if (isset($datatype->datatype)) { $datatype = $datatype->datatype; } else { $datatype = ''; } } $datatype_id = absint($datatype_id); $tbl_row_id = absint($tbl_row_id); $pod_id = absint($pod_id); $sql = "\r\n SELECT DISTINCT\r\n t.`{$column_name}` AS slug\r\n FROM\r\n `@wp_pod_tbl_{$datatype}` t\r\n WHERE\r\n t.`{$column_name}` = '{$value}'\r\n "; if (0 < $tbl_row_id) { $sql = "\r\n SELECT DISTINCT\r\n t.`{$column_name}` AS slug\r\n FROM\r\n `@wp_pod_tbl_{$datatype}` t\r\n WHERE\r\n t.`{$column_name}` = '{$value}' AND t.id != {$tbl_row_id}\r\n "; } elseif (0 < $pod_id) { $sql = "\r\n SELECT DISTINCT\r\n t.`{$column_name}` AS slug\r\n FROM\r\n @wp_pod p\r\n INNER JOIN\r\n `@wp_pod_tbl_{$datatype}` t ON t.id = p.tbl_row_id\r\n WHERE\r\n t.`{$column_name}` = '{$slug}' AND p.datatype = {$datatype_id} AND p.id != {$pod_id}\r\n "; } $result = pod_query($sql); if (0 < mysql_num_rows($result)) { $unique_num = 0; $unique_found = false; while (!$unique_found) { $unique_num++; $test_slug = pods_sanitize($value . '-' . $unique_num); $result = pod_query(str_replace("t.`{$column_name}` = '{$slug}'", "t.`{$column_name}` = '{$test_slug}'", $sql)); if (0 < mysql_num_rows($result)) { continue; } $value = $test_slug; $unique_found = true; } } $value = apply_filters('pods_unique_slug', $value, $column_name, $datatype, $datatype_id, $pod_id); return $value; }
/** * Get current language information from Multilingual plugins * * @since 2.6.6 * * @return array */ public static function get_current_language() { /** * @var $sitepress SitePress object * @var $polylang object */ /* * @todo wpml-comp Remove global object usage */ global $sitepress, $polylang; $lang_data = false; $translator = false; $current_language = false; // Multilingual support if (did_action('wpml_loaded') && apply_filters('wpml_setting', true, 'auto_adjust_ids')) { // WPML support $translator = 'WPML'; // Get the global current language (if set) $wpml_language = apply_filters('wpml_current_language', null); $current_language = $wpml_language != 'all' ? $wpml_language : ''; } elseif ((function_exists('PLL') || is_object($polylang)) && function_exists('pll_current_language')) { // Polylang support $translator = 'PLL'; // Get the global current language (if set) $current_language = pll_current_language('slug'); } /** * Admin functions that overwrite the current language * * @since 2.6.6 */ if (is_admin() && !empty($translator)) { if ($translator == 'PLL') { /** * Polylang support * Get the current user's perferred language. * This is a user meta setting that will overwrite the language returned from pll_current_language() * @see polylang/admin/admin-base.php -> init_user() */ $current_language = get_user_meta(get_current_user_id(), 'pll_filter_content', true); } // Get current language based on the object language if available if (function_exists('get_current_screen')) { $current_screen = get_current_screen(); /** * Overwrite the current language if needed for post types */ if (isset($current_screen->base) && ($current_screen->base == 'post' || $current_screen->base == 'edit')) { if (!empty($_GET['post'])) { /** * WPML support * In WPML the current language is always set to default on an edit screen * We need to overwrite this when the current object is not-translatable to enable relationships with different languages */ if ($translator == 'WPML' && !apply_filters('wpml_is_translated_post_type', false, get_post_type($_GET['post']))) { // Overwrite the current language to nothing if this is a NOT-translatable post_type $current_language = ''; } /** * Polylang support (1.5.4+) * In polylang the preferred language could be anything. * We only want the related objects if they are not translatable OR the same language as the current object */ if ($translator == 'PLL' && function_exists('pll_get_post_language') && pll_is_translated_post_type(get_post_type($_GET['post']))) { // Overwrite the current language if this is a translateable post_type $current_language = pll_get_post_language((int) $_GET['post']); } } /** * Polylang support (1.0.1+) * In polylang the preferred language could be anything. * When we're adding a new object and language is set we only want the related objects if they are not translatable OR the same language */ if ($translator == 'PLL' && !empty($_GET['new_lang']) && !empty($_GET['post_type']) && pll_is_translated_post_type(sanitize_text_field($_GET['post_type']))) { $current_language = $_GET['new_lang']; } /** * Overwrite the current language if needed for taxonomies */ } elseif (isset($current_screen->base) && ($current_screen->base == 'term' || $current_screen->base == 'edit-tags')) { // @todo MAYBE: Similar function like get_post_type for taxonomies so we don't need to check for $_GET['taxonomy'] if (!empty($_GET['taxonomy'])) { /* * @todo wpml-comp API call for taxonomy needed! * Suggested API call: * add_filter( 'wpml_is_translated_taxonomy', $_GET['taxonomy'], 10, 2 ); */ /** * WPML support * In WPML the current language is always set to default on an edit screen * We need to overwrite this when the current object is not-translatable to enable relationships with different languages */ if ($translator == 'WPML' && method_exists($sitepress, 'is_translated_taxonomy') && !$sitepress->is_translated_taxonomy($_GET['taxonomy'])) { // Overwrite the current language to nothing if this is a NOT-translatable taxonomy $current_language = ''; } /** * Polylang support (1.5.4+) * In polylang the preferred language could be anything. * We only want the related objects if they are not translatable OR the same language as the current object */ if ($translator == 'PLL' && !empty($_GET['tag_ID']) && function_exists('pll_get_term_language') && pll_is_translated_taxonomy(sanitize_text_field($_GET['taxonomy']))) { // Overwrite the current language if this is a translatable taxonomy $current_language = pll_get_term_language((int) $_GET['tag_ID']); } } /** * Polylang support (1.0.1+) * In polylang the preferred language could be anything. * When we're adding a new object and language is set we only want the related objects if they are not translatable OR the same language */ if ($translator == 'PLL' && !empty($_GET['new_lang']) && !empty($_GET['taxonomy']) && pll_is_translated_taxonomy(sanitize_text_field($_GET['taxonomy']))) { $current_language = $_GET['new_lang']; } } } } $current_language = pods_sanitize(sanitize_text_field($current_language)); if (!empty($current_language)) { // We need to return language data $lang_data = array('language' => $current_language, 't_id' => 0, 'tt_id' => 0, 'term' => null); /** * Polylang support * Get the language taxonomy object for the current language */ if ($translator == 'PLL') { $current_language_t = false; // Get the language term object if (function_exists('PLL') && isset(PLL()->model) && method_exists(PLL()->model, 'get_language')) { // Polylang 1.8 and newer $current_language_t = PLL()->model->get_language($current_language); } elseif (is_object($polylang) && isset($polylang->model) && method_exists($polylang->model, 'get_language')) { // Polylang 1.2 - 1.7.x $current_language_t = $polylang->model->get_language($current_language); } elseif (is_object($polylang) && method_exists($polylang, 'get_language')) { // Polylang 1.1.x and older $current_language_t = $polylang->get_language($current_language); } // If the language object exists, add it! if ($current_language_t && !empty($current_language_t->term_id)) { $lang_data['t_id'] = (int) $current_language_t->term_id; $lang_data['tt_id'] = (int) $current_language_t->term_taxonomy_id; $lang_data['term'] = $current_language_t; } } } /** * Override language data used by Pods. * * @since 2.6.6 * * @param array|false $lang_data { * Language data * * @type string $language Language slug * @type int $t_id Language term_id * @type int $tt_id Language term_taxonomy_id * @type WP_Term $term Language term object * } * @param string|boolean $translator Language plugin used */ $lang_data = apply_filters('pods_get_current_language', $lang_data, $translator); return $lang_data; }
$geoinfo = file_get_contents($geourl); // get the geocoded info back in json format into the variable you could use curl for better performance but this is more compatible $decoded = json_decode($geoinfo); // decode json geoinfo into an object // make sure value is returned and allow manual change if ($decoded->status == "OK") { $event_data['latitude'] = $decoded->results[0]->geometry->location->lat; // copy lat into the field called lat in your pod $event_data['longitude'] = $decoded->results[0]->geometry->location->lng; // copy long into the field called long in your pod } } // all clear to save the data to the database $api = new PodAPI(); // safety cleansing pods_sanitize($event_data); if ($eid == 'new') { // since we are saving a new event, these fields need initializing this one time only $event_data['vendor'] = get_active_user_id(); $event_data['approved'] = '1'; $event_data['event_type'] = '1'; $a['approved'] = '1'; $params = array('datatype' => 'events', 'columns' => $event_data); // create the item $api->save_pod_item($params); $success = true; } else { // SCREW PODSCMS... just do a plain ole SQL update $sql = "UPDATE wp_pod_tbl_events SET "; $sql_fields = array(); foreach ($event_data as $key => $val) {
$geoinfo = file_get_contents($geourl); // get the geocoded info back in json format into the variable you could use curl for better performance but this is more compatible $decoded = json_decode($geoinfo); // decode json geoinfo into an object // make sure value is returned and allow manual change if ($decoded->status == "OK") { $profile_data['latitude'] = $decoded->results[0]->geometry->location->lat; // copy lat into the field called lat in your pod $profile_data['longitude'] = $decoded->results[0]->geometry->location->lng; // copy long into the field called long in your pod } } // all clear to save the data to the database $api = new PodAPI(); // safety cleansing pods_sanitize($profile_data); if ($pid == 'new') { // since we are saving a new profile, these fields need initializing this one time only $profile_data['vendor'] = get_active_user_id(); $profile_data['active'] = '0'; $profile_data['profile_type'] = 'Free'; $profile_data['expiration_date'] = '0000-00-00 00:00:00'; $profile_data['payment_plan'] = 'NA'; $profile_data['payment_amount'] = '0'; $params = array('datatype' => 'vendor_profiles', 'columns' => $profile_data); // create the item $api->save_pod_item($params); $success = true; } else { // SCREW PODSCMS... just do a plain ole SQL update $sql = "UPDATE wp_pod_tbl_vendor_profiles SET ";
/** * 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; }
/** * Display the page template */ function showTemplate($template, $code = null) { ob_start(); //pre-template hooks do_action('pods_pre_showtemplate', $template, $code, $this); do_action("pods_pre_showtemplate_{$template}", $template, $code, $this); if (!empty($code)) { $function_or_file = false; } else { $function_or_file = $template; $check_function = false; $check_file = null; if ((!defined('PODS_STRICT_MODE') || !PODS_STRICT_MODE) && (!defined('PODS_TEMPLATE_FILES') || !PODS_TEMPLATE_FILES)) { $check_file = false; } if (false !== $check_function && false !== $check_file) { $function_or_file = pods_function_or_file($function_or_file, $check_function, 'template', $check_file); } else { $function_or_file = false; } if (!$function_or_file) { $api = new PodAPI(); $params = array('name' => $template); if (!defined('PODS_STRICT_MODE') || !PODS_STRICT_MODE) { $params = pods_sanitize($params); } $code = $api->load_template($params); if (false !== $code && 0 < strlen(trim($code['code']))) { $code = $code['code']; } else { $code = false; } } } if (empty($code) && false !== $function_or_file && isset($function_or_file['file'])) { // Only detail templates need $this->id if (empty($this->id)) { while ($this->fetchRecord()) { locate_template($function_or_file['file'], true, true); } } else { locate_template($function_or_file['file'], true, true); } } elseif (!empty($code)) { // Only detail templates need $this->id if (empty($this->id)) { while ($this->fetchRecord()) { echo $this->parse_template_string($code); } } else { echo $this->parse_template_string($code); } } //post-template hooks do_action('pods_post_showtemplate', $template, $code, $this); do_action("pods_post_showtemplate_{$template}", $template, $code, $this); return apply_filters('pods_showtemplate', ob_get_clean(), $template, $code, $this); }
$headers = 'From: "Occasions Magazine" <*****@*****.**>' . "\r\n" . 'Reply-To: "Occasions Magazine" <*****@*****.**>' . "\r\n" . 'X-Mailer: AO3/PHP/' . phpversion(); $msg = 'The following review of ' . $a['name'] . ' was submitted:' . "\r\n\r\n" . 'Name: ' . $txt_name . "\r\n" . 'Email: ' . $txt_email . "\r\n" . 'Rating: ' . $rdo_rating . "\r\n" . 'Review: ' . "\r\n\r\n" . $txt_comments . "\r\n\r\n\r\n" . '------------------------------------------------------------' . "\r\n" . 'SENT TO : ' . $a['emai'] . "\r\n" . 'SENT AT : ' . date("D F j, Y, g:i a") . "\r\n" . 'FROM IP : ' . get_real_ip() . "\r\n" . '------------------------------------------------------------' . "\r\n"; mail($to, $subject, $msg, $headers); mail(AO_ADMIN_EMAIL, $subject, $msg, $headers); mail(AO_TECH_EMAIL, $subject, $msg, $headers); // all clear to save the data to the database $api = new PodAPI(); // since we are saving a new profile, these fields need initializing this one time only $comment_data['vendor'] = $a['id']; $comment_data['name'] = $txt_name; $comment_data['email'] = $txt_email; $comment_data['rating'] = $rdo_rating; $comment_data['comment'] = $txt_comments; $comment_data['comment_date'] = date("Y-m-d H:i:s"); // safety cleansing pods_sanitize($comment_data); $params = array('datatype' => 'comments', 'columns' => $comment_data); // create the item $api->save_pod_item($params); // set these to NULL so the fields will not be pre-filled below. $txt_name = NULL; $txt_email = NULL; $txt_comments = NULL; $rdo_rating = NULL; // now recalc the average rating... pod_query("UPDATE wp_pod_tbl_vendor_profiles SET rating = (SELECT AVG(rating) FROM wp_pod_tbl_comments WHERE vendor='" . $a['id'] . "') WHERE id = " . $a['id']); $err[] = "Your review has been submitted."; } } get_header(); $s = <<<HEREDOC
/** * @param $import * @param bool $output */ public function heres_the_beef($import, $output = true) { global $wpdb; $api = pods_api(); for ($i = 0; $i < 40000; $i++) { echo " \t"; // extra spaces } $default_data = array('pod' => null, 'table' => null, 'reset' => null, 'update_on' => null, 'where' => null, 'fields' => array(), 'row_filter' => null, 'pre_save' => null, 'post_save' => null, 'sql' => null, 'sort' => null, 'limit' => null, 'page' => null, 'output' => null, 'page_var' => 'ipg', 'bypass_helpers' => false); $default_field_data = array('field' => null, 'filter' => null); if (!is_array($import)) { $import = array($import); } elseif (empty($import)) { die('<h1 style="color:red;font-weight:bold;">ERROR: No imports configured</h1>'); } $import_counter = 0; $total_imports = count($import); $paginated = false; $avg_time = -1; $total_time = 0; $counter = 0; $avg_unit = 100; $avg_counter = 0; foreach ($import as $datatype => $data) { $import_counter++; flush(); @ob_end_flush(); usleep(50000); if (!is_array($data)) { $datatype = $data; $data = array('table' => $data); } if (isset($data[0])) { $data = array('table' => $data[0]); } $data = array_merge($default_data, $data); if (null === $data['pod']) { $data['pod'] = array('name' => $datatype); } if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <em>" . $data['pod']['name'] . "</em> - <strong>Loading Pod: " . $data['pod']['name'] . "</strong>\n"; } if (2 > count($data['pod'])) { $data['pod'] = $api->load_pod(array('name' => $data['pod']['name'])); } if (empty($data['pod']['fields'])) { continue; } if (null === $data['table']) { $data['table'] = $data['pod']['name']; } if ($data['reset'] === true) { if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong style='color:blue;'>Resetting Pod: " . $data['pod']['name'] . "</strong>\n"; } $api->reset_pod(array('id' => $data['pod']['id'], 'name' => $data['pod']['name'])); } if (null === $data['sort'] && null !== $data['update_on'] && isset($data['fields'][$data['update_on']])) { if (isset($data['fields'][$data['update_on']]['field'])) { $data['sort'] = $data['fields'][$data['update_on']]['field']; } else { $data['sort'] = $data['update_on']; } } $page = 1; if (false !== $data['page_var'] && isset($_GET[$data['page_var']])) { $page = absval($_GET[$data['page_var']]); } if (null === $data['sql']) { $data['sql'] = "SELECT * FROM {$data['table']}" . (null !== $data['where'] ? " WHERE {$data['where']}" : '') . (null !== $data['sort'] ? " ORDER BY {$data['sort']}" : '') . (null !== $data['limit'] ? " LIMIT " . (1 < $page ? ($page - 1) * $data['limit'] . ',' : '') . "{$data['limit']}" : ''); } if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Getting Results: " . $data['pod']['name'] . "\n"; } if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Using Query: <small><code>" . $data['sql'] . "</code></small>\n"; } $result = $wpdb->get_results($data['sql'], ARRAY_A); if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Results Found: " . count($result) . "\n"; } $avg_time = -1; $total_time = 0; $counter = 0; $avg_unit = 100; $avg_counter = 0; $result_count = count($result); $paginated = false; if (false !== $data['page_var'] && $result_count == $data['limit']) { $paginated = "<input type=\"button\" onclick=\"document.location=\\'" . pods_ui_var_update(array($data['page_var'] => $page + 1), false, false) . "\\';\" value=\" Continue Import » \" />"; } if ($result_count < $avg_unit && 5 < $result_count) { $avg_unit = number_format($result_count / 5, 0, '', ''); } elseif (2000 < $result_count && 10 < count($data['pod']['fields'])) { $avg_unit = 40; } $data['count'] = $result_count; timer_start(); if (false !== $output && 1 == $import_counter) { echo "<div style='width:50%;background-color:navy;padding:10px 10px 30px 10px;color:#FFF;position:absolute;top:10px;left:25%;text-align:center;'><p id='progress_status' align='center'>" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Running Importer..</p><br /><small>This will automatically update every " . $avg_unit . " rows</small></div>\n"; } foreach ($result as $k => $row) { flush(); @ob_end_flush(); usleep(50000); if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Processing Row #" . ($k + 1) . "\n"; } if (null !== $data['row_filter'] && function_exists($data['row_filter'])) { if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Filtering <strong>" . $data['row_filter'] . "</strong> on Row #" . ($k + 1) . "\n"; } $row = $data['row_filter']($row, $data); } if (!is_array($row)) { continue; } $params = array('datatype' => $data['pod']['name'], 'columns' => array(), 'bypass_helpers' => $data['bypass_helpers']); foreach ($data['pod']['fields'] as $fk => $field_info) { $field = $field_info['name']; if (!empty($data['fields']) && !isset($data['fields'][$field]) && !in_array($field, $data['fields'])) { continue; } if (isset($data['fields'][$field])) { if (is_array($data['fields'][$field])) { $field_data = $data['fields'][$field]; } else { $field_data = array('field' => $data['fields'][$field]); } } else { $field_data = array(); } if (!is_array($field_data)) { $field = $field_data; $field_data = array(); } $field_data = array_merge($default_field_data, $field_data); if (null === $field_data['field']) { $field_data['field'] = $field; } $data['fields'][$field] = $field_data; $value = ''; if (isset($row[$field_data['field']])) { $value = $row[$field_data['field']]; } if (null !== $field_data['filter']) { if (function_exists($field_data['filter'])) { if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Filtering <strong>" . $field_data['filter'] . "</strong> on Field: " . $field . "\n"; } $value = $field_data['filter']($value, $row, $data); } else { $value = ''; } } if (1 > strlen($value) && 1 == $field_info['required']) { die('<h1 style="color:red;font-weight:bold;">ERROR: Field Required for <strong>' . $field . '</strong></h1>'); } $params['columns'][$field] = $value; unset($value); unset($field_data); unset($field_info); unset($fk); } if (empty($params['columns'])) { continue; } $params['columns'] = pods_sanitize($params['columns']); if (null !== $data['update_on'] && isset($params['columns'][$data['update_on']])) { if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Checking for Existing Item\n"; } $check = new Pod($data['pod']['name']); $check->findRecords(array('orderby' => 't.id', 'limit' => 1, 'where' => "t.{$data['update_on']} = '{$params['columns'][$data['update_on']]}'", 'search' => false, 'page' => 1)); if (0 < $check->getTotalRows()) { $check->fetchRecord(); $params['tbl_row_id'] = $check->get_field('id'); $params['pod_id'] = $check->get_pod_id(); if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Found Existing Item w/ ID: " . $params['tbl_row_id'] . "\n"; } unset($check); } if (!isset($params['tbl_row_id']) && false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Existing item not found - Creating New\n"; } } if (null !== $data['pre_save'] && function_exists($data['pre_save'])) { if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Running Pre Save <strong>" . $data['pre_save'] . "</strong> on " . $data['pod']['name'] . "\n"; } $params = $data['pre_save']($params, $row, $data); } $id = $api->save_pod_item($params); if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong>Saved Row #" . ($k + 1) . " w/ ID: " . $id . "</strong>\n"; } $params['tbl_row_id'] = $id; if (null !== $data['post_save'] && function_exists($data['post_save'])) { if (false !== $output) { echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - Running Post Save <strong>" . $data['post_save'] . "</strong> on " . $data['pod']['name'] . "\n"; } $data['post_save']($params, $row, $data); } unset($params); unset($result[$k]); unset($row); wp_cache_flush(); $wpdb->queries = array(); $avg_counter++; $counter++; if ($avg_counter == $avg_unit && false !== $output) { $avg_counter = 0; $avg_time = timer_stop(0, 10); $total_time += $avg_time; $rows_left = $result_count - $counter; $estimated_time_left = $total_time / $counter * $rows_left / 60; $percent_complete = 100 - $rows_left * 100 / $result_count; echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em><br /><strong>" . $percent_complete . "% Complete</strong><br /><strong>Estimated Time Left:</strong> " . $estimated_time_left . " minute(s) or " . $estimated_time_left / 60 . " hours(s)<br /><strong>Time Spent:</strong> " . $total_time / 60 . " minute(s)<br /><strong>Rows Done:</strong> " . ($result_count - $rows_left) . "/" . $result_count . "<br /><strong>Rows Left:</strong> " . $rows_left . "';</script>\n"; echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong>Updated Status:</strong> " . $percent_complete . "% Complete</strong>\n"; } } if (false !== $output) { $avg_counter = 0; $avg_time = timer_stop(0, 10); $total_time += $avg_time; $rows_left = $result_count - $counter; $estimated_time_left = $total_time / $counter * $rows_left / 60; $percent_complete = 100 - $rows_left * 100 / $result_count; echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em><br /><strong style=\\'color:green;\\'>100% Complete</strong><br /><br /><strong>Time Spent:</strong> " . $total_time / 60 . " minute(s)<br /><strong>Rows Imported:</strong> " . $result_count . (false !== $paginated ? "<br /><br />" . $paginated : '') . "';</script>\n"; echo "<br />" . date('Y-m-d h:i:sa') . " - <em>" . $data['pod']['name'] . "</em> - <strong style='color:green;'>Done Importing: " . $data['pod']['name'] . "</strong>\n"; } unset($result); unset($import[$datatype]); unset($datatype); unset($data); wp_cache_flush(); $wpdb->queries = array(); } if (false !== $output) { $avg_counter = 0; $avg_time = timer_stop(0, 10); $total_time += $avg_time; $rows_left = $result_count - $counter; echo "<script type='text/javascript'>document.getElementById('progress_status').innerHTML = '" . date('Y-m-d h:i:sa') . " - <strong style=\\'color:green;\\'>Import Complete</strong><br /><br /><strong>Time Spent:</strong> " . $total_time / 60 . " minute(s)<br /><strong>Rows Imported:</strong> " . $result_count . (false !== $paginated ? "<br /><br />" . $paginated : '') . "';</script>\n"; echo "<br />" . date('Y-m-d h:i:sa') . " - <strong style='color:green;'>Import Complete</strong>\n"; } }
// check and validate recaptcha $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $missing_fields = true; $missing_error .= '<p style="font-weight: bold; color: red;">Image Verification failed! (reCAPTCHA said: ' . $resp->error . ')</p>'; } } } if ($_POST['submitted'] == "1" && !$missing_fields) { // ************************************************************************ // SAVING DATA // ************************************************************************ $api = new PodAPI(); // all of the values to save and options to use $reg_data = array('name' => addslashes($txt_name), 'email' => addslashes($txt_email), 'address' => addslashes($txt_address), 'city' => addslashes($txt_city), 'state' => strtoupper(addslashes($txt_state)), 'zipcode' => addslashes($txt_zip), 'phone' => addslashes($txt_phone), 'event_date' => addslashes($txt_date), 'interests' => addslashes($txt_service_interest), 'interest_weddings' => $txt_interest_weddings, 'interest_social' => $txt_interest_social, 'interest_corporate' => $txt_interest_corporate, 'interest_mitzvahs' => $txt_interest_mitzvahs, 'interest_parties' => $txt_interest_parties, 'referral' => addslashes($txt_referral), 'notes' => addslashes($txt_comments), 'inquire_date' => date("Y-m-d H:i:s")); pods_sanitize($reg_data); $params = array('datatype' => 'user_profiles', 'columns' => $reg_data); // create the item $api->save_pod_item($params); // ************************************************************************ // MAILCHIMP INSERTION // ************************************************************************ // grab an API Key from http://admin.mailchimp.com/account/api/ $api = new MCAPI('e7c8035acf9e6541b2a1e0c27ccd2dfd-us1'); // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/ // Click the "settings" link for the list - the Unique Id is at the bottom of that page. $list_id = 'da7db994ec'; if ($api->listSubscribe($list_id, $txt_email, '', '', false) === true) { // It worked! $mailchimp = 'Their email address was successfully added to MailChimp.'; } else {
} $check_file = null; if ((!defined('PODS_STRICT_MODE') || !PODS_STRICT_MODE) && (!defined('PODS_HELPER_FILES') || !PODS_HELPER_FILES)) { $check_file = false; } if (false !== $check_function && false !== $check_file) { $function_or_file = pods_function_or_file($function_or_file, $check_function, 'helper', $check_file); } else { $function_or_file = false; } $content = false; if (!$function_or_file) { $api = new PodAPI(); $params = array('name' => $input_helper, 'type' => 'input'); if (!defined('PODS_STRICT_MODE') || !PODS_STRICT_MODE) { $params = pods_sanitize($params); } $content = $api->load_helper($params); if (false !== $content && 0 < strlen(trim($content['phpcode']))) { $content = $content['phpcode']; } else { $content = false; } } if (false === $content && false !== $function_or_file && isset($function_or_file['function'])) { echo $function_or_file['function']($coltype, $field, $css_id, $css_classes, $value, $this); } elseif (false === $content && false !== $function_or_file && isset($function_or_file['file'])) { locate_template($function_or_file['file'], true, true); } elseif (false !== $content) { if (!defined('PODS_DISABLE_EVAL') || PODS_DISABLE_EVAL) { eval("?>{$content}");
/** * Resync wp_pod and wp_pod_tbl_* tables * * wp_pod_tbl_* is assumed the primary source * (if not found there, it'll get deleted from wp_pod) * * This might take a bit! * * @since 1.10.1 */ function fix_wp_pod() { $result = pod_query("SELECT id, name FROM @wp_pod_types ORDER BY name"); while ($row = mysql_fetch_array($result)) { $id = (int) $row['id']; $name = pods_sanitize($row['name']); pod_query("DELETE p FROM `@wp_pod` AS p LEFT JOIN `@wp_pod_tbl_{$name}` AS t ON t.id = p.tbl_row_id WHERE p.datatype = {$id} AND t.id IS NULL"); pod_query("INSERT INTO `@wp_pod` (tbl_row_id, name, datatype, created, modified, author_id) SELECT t.id AS tbl_row_id, t.name AS name, {$id} AS datatype, '" . current_time('mysql') . "' AS created, '" . current_time('mysql') . "' AS modified, 0 AS author_id FROM `@wp_pod_tbl_{$name}` AS t LEFT JOIN `@wp_pod` AS p ON p.datatype = {$id} AND p.tbl_row_id = t.id WHERE p.id IS NULL"); } }
/** * Evaluate tag like magic tag but through pods_var_raw * * @param string|array $tag * @param bool $sanitize Whether to sanitize tags * * @return string * @version 2.1 */ function pods_evaluate_tag($tag, $sanitize = false) { // Handle pods_evaluate_tags if (is_array($tag)) { if (!isset($tag[2]) && strlen(trim($tag[2])) < 1) { return; } $tag = $tag[2]; } $tag = trim($tag, ' {@}'); $tag = explode('.', $tag); if (empty($tag) || !isset($tag[0]) || strlen(trim($tag[0])) < 1) { return; } // Fix formatting that may be after the first . if (2 < count($tag)) { $first_tag = $tag[0]; unset($tag[0]); $tag = array($first_tag, implode('.', $tag)); } foreach ($tag as $k => $v) { $tag[$k] = trim($v); } $value = ''; if (1 == count($tag)) { $value = pods_var_raw($tag[0], 'get', '', null, true); } elseif (2 == count($tag)) { $value = pods_var_raw($tag[1], $tag[0], '', null, true); } $value = apply_filters('pods_evaluate_tag', $value, $tag); if ($sanitize) { $value = pods_sanitize($value); } return $value; }