public function get_field_value($id) { $field = null; if (is_numeric($id)) { $field = wpbdp_get_form_field($id); } else { $field = wpbdp_get_form_fields(array('association' => $id, 'unique' => true)); } return $field ? $field->html_value($this->id) : ''; }
private function sanitize_and_validate_row($data) { global $wpbdp; $errors = array(); $categories = array(); $fields = array(); $images = array(); $expires_on = array(); $meta = array(); $meta['sequence_id'] = 0; $meta['username'] = ''; $meta['featured_level'] = ''; foreach ($this->header as $i => $col_info) { $column = $col_info['short_name']; $field = $col_info['field_id'] ? wpbdp_get_form_field($col_info['field_id']) : null; $value = stripslashes(trim(isset($data[$i]) ? $data[$i] : '')); switch ($column) { case 'image': case 'images': $file_names = explode($this->settings['images-separator'], $value); foreach ($file_names as $f) { $f = trim($f); if ($f) { $images[] = $f; } } break; case 'username': if ($this->settings['assign-listings-to-user']) { if (!$value && $this->settings['default-user']) { $value = $this->settings['default-user']; } if (!username_exists($value)) { $errors[] = sprintf(_x('Username "%s" does not exist', 'admin csv-import', 'WPBDM'), $value); } else { $meta['username'] = $value; } } break; case 'featured_level': $meta['featured_level'] = $value; break; case 'expires_on': $dates = explode('/', $value); foreach ($dates as $d) { $expires_on[] = $d; } break; case 'sequence_id': $meta['sequence_id'] = absint($value); break; default: if (!$field) { break; } if ($field->is_required() && $field->is_empty_value($value)) { $errors[] = sprintf(_x('Missing required field: %s', 'admin csv-import', 'WPBDM'), $column); break; } if ('category' == $field->get_association()) { $csv_categories = array_map('trim', explode($this->settings['category-separator'], $value)); foreach ($csv_categories as $csv_category_) { $csv_category = $csv_category_; $csv_category = strip_tags(str_replace("\n", "-", $csv_category)); $csv_category = str_replace(array('"', "'"), '', $csv_category); $csv_category = str_replace('&', '&', $csv_category); if (!$csv_category) { continue; } if ($term = term_exists($csv_category, WPBDP_CATEGORY_TAX)) { $categories[] = array('name' => $csv_category, 'term_id' => $term['term_id'], 'expires_on' => ''); } else { if (!$this->settings['create-missing-categories']) { $errors[] = sprintf(_x('Listing category "%s" does not exist', 'admin csv-import', 'WPBDM'), $csv_category); continue; } if ($this->settings['test-import']) { continue; } $categories[] = array('name' => $csv_category, 'term_id' => 0, 'expires_on' => ''); } } } else { $fields[$field->get_id()] = $field->convert_csv_input($value, $this->settings); } break; } } if ($categories && $expires_on) { foreach ($categories as $i => &$category_data) { if (!empty($expires_on[$i])) { $category_data['expires_on'] = $expires_on[$i]; } } } return array(compact('categories', 'fields', 'images', 'meta'), $errors); }
public function sortbar_orderby($orderby) { global $wpdb; $sort = wpbdp_get_current_sort_option(); if (!$sort || !in_array(str_replace('field-', '', $sort->option), wpbdp_get_option('listings-sortbar-fields'))) { return $orderby; } $sname = str_replace('field-', '', $sort->option); $qn = ''; switch ($sname) { case 'user_login': case 'user_registered': $qn = $sname; break; case 'date': case 'modified': $qn = "{$wpdb->posts}.post_{$sname}"; break; default: $field = wpbdp_get_form_field($sname); if (!$field) { break; } switch ($field->get_association()) { case 'title': case 'excerpt': case 'content': $qn = "{$wpdb->posts}.post_" . $field->get_association(); break; case 'meta': $qn = "field_{$sname}"; break; } break; } if ($qn) { return $orderby . ', ' . $qn . ' ' . $sort->order; } else { return $orderby; } }
public static function &from_state($state) { $export = new self($state['settings'], trailingslashit($state['workingdir']), (array) $state['listings']); $export->exported = abs(intval($state['exported'])); // Setup columns. $shortnames = wpbdp_formfields_api()->get_short_names(); foreach ($state['columns'] as $fshortname) { if (in_array($fshortname, array('images', 'username', 'featured_level', 'expires_on', 'sequence_id'))) { $export->columns[$fshortname] = $fshortname; continue; } $field_id = array_search($fshortname, $shortnames); if ($field_id === FALSE) { throw new Exception('Invalid field shortname.'); } $export->columns[$fshortname] = wpbdp_get_form_field($field_id); } return $export; }