/** * Standardize queries and error reporting * * @param string $query The SQL query * @param string $error (optional) The failure message * @param string $results_error (optional) Throw an error if a records are found * @param string $no_results_error (optional) Throw an error if no records are found * @since 1.2.0 */ function pod_query($sql, $error = 'SQL failed', $results_error = null, $no_results_error = null) { global $wpdb; $sql = trim($sql); // Using @wp_users is deprecated! use $wpdb->users instead! $sql = str_replace('@wp_users', $wpdb->users, $sql); $sql = str_replace('@wp_', $wpdb->prefix, $sql); $sql = str_replace('{prefix}', '@wp_', $sql); $sql = apply_filters('pod_query', $sql, $error, $results_error, $no_results_error); // Return cached resultset if ('SELECT' == substr($sql, 0, 6)) { $cache = PodCache::instance(); if ($cache->cache_enabled && isset($cache->results[$sql])) { $result = $cache->results[$sql]; if (0 < mysql_num_rows($result)) { mysql_data_seek($result, 0); } $result = apply_filters('pod_query_return', $result, $sql, $error, $results_error, $no_results_error); return $result; } } if (false !== $error) { $result = mysql_query($sql, $wpdb->dbh) or die("<e>{$error}; SQL: {$sql}; Response: " . mysql_error($wpdb->dbh)); } else { $result = @mysql_query($sql, $wpdb->dbh); } if (0 < @mysql_num_rows($result)) { if (!empty($results_error)) { die("<e>{$results_error}"); } } elseif (!empty($no_results_error)) { die("<e>{$no_results_error}"); } if ('INSERT' == substr($sql, 0, 6)) { $result = mysql_insert_id($wpdb->dbh); } elseif ('SELECT' == substr($sql, 0, 6)) { if ('SELECT FOUND_ROWS()' != $sql) { $cache->results[$sql] = $result; } } $result = apply_filters('pod_query_return', $result, $sql, $error, $results_error, $no_results_error); return $result; }
<?php $cache = PodCache::instance(); $form_count = $cache->form_count; global $coltype_exists; $name = $field['name']; $label = $field['label']; $comment = $field['comment']; $coltype = $field['coltype']; $input_helper = $field['input_helper']; $hidden = empty($field['hidden']) ? '' : ' hidden'; $value = is_array($this->data[$name]) ? $this->data[$name] : stripslashes($this->data[$name]); $css_id = 'pods_form' . $form_count . '_' . $name; // The first 3 CSS classes will be DEPRECATED in 2.0.0 $css_classes = "form {$coltype} {$name} pods_field pods_field_{$name} pods_coltype_{$coltype}"; if (1 > $field['multiple']) { $css_classes = str_replace(' pick ', ' pick1 ', $css_classes); } //pre-field hooks do_action('pods_pre_input_field', $field, $css_id, $css_classes, $value, $this); do_action("pods_pre_input_field_{$name}", $field, $css_id, $css_classes, $value, $this); do_action("pods_pre_input_field_type_{$coltype}", $field, $css_id, $css_classes, $value, $this); ?> <div class="leftside <?php echo esc_attr($name . $hidden); ?> "> <label for="<?php echo esc_attr($css_id); ?> "><?php
define('PODS_DIR', rtrim(plugin_dir_path(__FILE__), '/')); // non-trailing slash being deprecated in 2.0 define('WP_INC_URL', rtrim(includes_url(), '/')); // non-trailing slash being deprecated in 2.0 require_once PODS_DIR . '/functions.php'; require_once PODS_DIR . '/classes/PodInit.php'; require_once PODS_DIR . '/classes/Pod.php'; require_once PODS_DIR . '/classes/PodAPI.php'; require_once PODS_DIR . '/classes/PodCache.php'; require_once PODS_DIR . '/pods-ui.php'; global $pods_cache, $cache, $pods_init; if (false !== pods_compatible() && (!defined('SHORTINIT') || !SHORTINIT)) { // JSON support if (!function_exists('json_encode')) { require_once ABSPATH . '/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php'; function json_encode($str) { $json = new Moxiecode_JSON(); return $json->encode($str); } function json_decode($str) { $json = new Moxiecode_JSON(); return $json->decode($str); } } $pods_cache = PodCache::instance(); $cache =& $pods_cache; // DEPRECATED IN 2.0 $pods_init = new PodInit(); }
/** * Display HTML for all datatype fields */ function showform($pod_id = null, $public_columns = null, $label = 'Save changes') { if (empty($this->datatype_id)) { echo "<e>Error: Pod name invalid</e>"; return null; } $pod_id = absint($pod_id); $cache = PodCache::instance(); $datatype = $this->datatype; $datatype_id = (int) $this->datatype_id; $this->data['pod_id'] = $pod_id = (int) $pod_id; $where = ''; if (!empty($public_columns)) { foreach ($public_columns as $key => $val) { if (is_array($public_columns[$key])) { $where[] = $key; $attributes[$key] = $val; } else { $where[] = $val; $attributes[$val] = array(); } } $where = "AND name IN ('" . implode("','", $where) . "')"; } $result = pod_query("SELECT * FROM @wp_pod_fields WHERE datatype = {$datatype_id} {$where} ORDER BY weight ASC"); $public_columns = array(); while ($row = mysql_fetch_assoc($result)) { $fields[$row['name']] = $row; $public_columns[] = $row['name']; } // Re-order the fields if a public form if (!empty($attributes)) { $tmp = $fields; $fields = array(); foreach ($attributes as $key => $val) { if (isset($tmp[$key])) { $fields[$key] = $tmp[$key]; } } unset($tmp); } // Edit an existing item if (!empty($pod_id)) { $sql = "\n SELECT\n `t`.*\n FROM\n @wp_pod `p`\n INNER JOIN\n `@wp_pod_tbl_{$datatype}` AS `t` ON `t`.`id` = `p`.`tbl_row_id`\n WHERE\n `p`.`id` = {$pod_id}\n LIMIT\n 1\n "; $result = pod_query($sql); if (0 < mysql_num_rows($result)) { $tbl_cols = mysql_fetch_assoc($result); } } $uri_hash = wp_hash($_SERVER['REQUEST_URI']); do_action('pods_showform_pre', $pod_id, $public_columns, $label, $this); foreach ($fields as $key => $field) { // Replace field attributes with public form attributes if (!empty($attributes) && is_array($attributes[$key])) { $field = array_merge($field, $attributes[$key]); } if (empty($field['label'])) { $field['label'] = ucwords($key); } if (1 == $field['required']) { $field['label'] .= ' <span class="red">*</span>'; } if (!empty($field['pickval'])) { $val = array(); $tbl_row_ids = array(); $table = $field['pickval']; $result = pod_query("SELECT `id` FROM `@wp_pod_fields` WHERE `datatype` = {$datatype_id} AND `name` = '{$key}' LIMIT 1"); $field_id = (int) mysql_result($result, 0); $result = pod_query("SELECT `tbl_row_id` FROM `@wp_pod_rel` WHERE `field_id` = {$field_id} AND `pod_id` = {$pod_id}"); while ($row = mysql_fetch_assoc($result)) { $tbl_row_ids[] = (int) $row['tbl_row_id']; } // Use default values for public forms if (empty($tbl_row_ids) && !empty($field['default'])) { $tbl_row_ids = $field['default']; if (!is_array($field['default'])) { $tbl_row_ids = explode(',', $tbl_row_ids); foreach ($tbl_row_ids as $row_key => $row_val) { $tbl_row_ids[$row_key] = (int) trim($row_val); } } } // If the PICK column is unique, get values already chosen $unique_vals = false; if (1 == $field['unique']) { $exclude = empty($pod_id) ? '' : "AND `pod_id` != {$pod_id}"; $result = pod_query("SELECT `tbl_row_id` FROM `@wp_pod_rel` WHERE `field_id` = {$field_id} {$exclude}"); if (0 < mysql_num_rows($result)) { $unique_vals = array(); while ($row = mysql_fetch_assoc($result)) { $unique_vals[] = (int) $row['tbl_row_id']; } $unique_vals = implode(',', $unique_vals); } } $params = array('table' => $table, 'field_name' => null, 'tbl_row_ids' => $tbl_row_ids, 'unique_vals' => $unique_vals, 'pick_filter' => $field['pick_filter'], 'pick_orderby' => $field['pick_orderby']); $this->data[$key] = $this->get_dropdown_values($params); } else { // Set a default value if no value is entered if (!isset($this->data[$key]) && !empty($field['default'])) { $this->data[$key] = $field['default']; } else { $this->data[$key] = isset($tbl_cols[$key]) && $this->is_val($tbl_cols[$key]) ? $tbl_cols[$key] : null; } } $this->build_field_html($field); } $uri_hash = wp_hash($_SERVER['REQUEST_URI']); $save_button_atts = array('type' => 'button', 'class' => 'button btn_save', 'value' => $label, 'onclick' => "saveForm({$cache->form_count})"); $save_button_atts = apply_filters('pods_showform_save_button_atts', $save_button_atts, $this); $atts = ''; foreach ($save_button_atts as $att => $value) { $atts .= $att . '="' . $value . '" '; } $save_button = '<input ' . $atts . '/>'; ?> <div> <input type="hidden" class="form num pod_id" value="<?php echo $pod_id; ?> " /> <input type="hidden" class="form num tbl_row_id" value="<?php echo !empty($tbl_cols) ? $tbl_cols['id'] : 0; ?> " /> <input type="hidden" class="form txt datatype" value="<?php echo $datatype; ?> " /> <input type="hidden" class="form txt form_count" value="<?php echo $cache->form_count; ?> " /> <input type="hidden" class="form txt token" value="<?php echo pods_generate_key($datatype, $uri_hash, $public_columns, $cache->form_count); ?> " /> <input type="hidden" class="form txt uri_hash" value="<?php echo $uri_hash; ?> " /> <?php echo apply_filters('pods_showform_save_button', $save_button, $save_button_atts, $this); ?> </div> <?php do_action('pods_showform_post', $pod_id, $public_columns, $label, $this); }