Permalink
Browse files

2.0-bleeding

  • Loading branch information...
1 parent 4c93c8d commit cd3a338778ea998dbd9584f45a0027c9dfc633b5 @sc0ttkclark sc0ttkclark committed Sep 2, 2011
View
173 classes/PodsArray.php
@@ -0,0 +1,173 @@
+<?php
+class PodsArray implements ArrayAccess {
+ private $__container = array();
+
+ /**
+ * Alternative to get_object_vars to access an object as an array with simple functionality and accepts arrays to
+ * add additional functionality. Additional functionality includes validation and setting default data.
+ *
+ * @param mixed $container Object (or existing Array)
+ * @license http://www.gnu.org/licenses/gpl-2.0.html
+ * @since 2.0.0
+ */
+ public function __construct ($container) {
+ if (is_array($container) || is_object($container))
+ $this->__container = &$container;
+ }
+
+ /**
+ * Set value from array usage $object['offset'] = 'value';
+ *
+ * @param mixed $offset Used to set index of Array or Variable name on Object
+ * @param mixed $value Value to be set
+ * @since 2.0.0
+ */
+ public function offsetSet ($offset, $value) {
+ if (is_array($this->__container))
+ $this->__container[$offset] = $value;
+ else
+ $this->__container->$offset = $value;
+ }
+
+ /**
+ * Get value from array usage $object['offset'];
+ *
+ * @param mixed $offset Used to get value of Array or Variable on Object
+ * @since 2.0.0
+ */
+ public function offsetGet ($offset) {
+ if (is_array($this->__container)) {
+ if (isset($this->__container[$offset]))
+ return $this->__container[$offset];
+ return null;
+ }
+ if (isset($this->__container->$offset))
+ return $this->__container->$offset;
+ return null;
+ }
+
+ /**
+ * Get value from array usage $object['offset'];
+ *
+ * @param mixed $offset Used to get value of Array or Variable on Object
+ * @since 2.0.0
+ */
+ public function offsetExists ($offset) {
+ if (is_array($this->__container))
+ return isset($this->__container[$offset]);
+ return isset($this->__container->$offset);
+ }
+
+ /**
+ * Get value from array usage $object['offset'];
+ *
+ * @param mixed $offset Used to unset index of Array or Variable on Object
+ * @since 2.0.0
+ */
+ public function offsetUnset ($offset) {
+ if (is_array($this->__container))
+ unset($this->__container[$offset]);
+ else
+ unset($this->__container->$offset);
+ }
+
+ /**
+ * Validate value on a specific type and set default (if empty)
+ *
+ * @param mixed $offset Used to get value of Array or Variable on Object
+ * @param mixed $default Used to set default value if it doesn't exist
+ * @param string $type Used to force a specific type of variable (allowed: array, object, integer, absint, boolean)
+ * @param mixed $extra Used in advanced types of variables
+ * @since 2.0.0
+ */
+ public function validate ($offset, $default = null, $type = null, $extra = null) {
+ if (!$this->offsetExists($offset))
+ $this->offsetSet($offset, $default);
+ $value = $this->offsetGet($offset);
+ if (empty($value) && null !== $default)
+ $value = $default;
+ if ('array' == $type || 'array_merge' == $type) {
+ if (!is_array($value))
+ $value = explode(',', $value);
+ if ('array_merge' == $type && $value !== $default)
+ $value = array_merge($default, $value);
+ }
+ if ('object' == $type || 'object_merge' == $type) {
+ if (!is_object($value)) {
+ if (!is_array($value))
+ $value = explode(',', $value);
+ $value = (object) $value;
+ }
+ if ('object_merge' == $type && $value !== $default)
+ $value = (object) array_merge((array) $default, (array) $value);
+ }
+ if ('integer' == $type || 'absint' == $type) {
+ if (!is_numeric(trim($value)))
+ $value = 0;
+ else
+ $value = intval($value);
+ if ('absint' == $type)
+ $value = abs($value);
+ }
+ if ('boolean' == $type)
+ $value = (bool) $value;
+ if ('in_array' == $type && is_array($default)) {
+ if (is_array($value)) {
+ foreach ($value as $k => $v) {
+ if (!in_array($v, $extra))
+ unset($value[$k]);
+ }
+ }
+ elseif (!in_array($value, $extra))
+ $value = $default;
+ }
+ $this->offsetSet($offset, $value);
+ return $value;
+ }
+
+ /**
+ *
+ * @since 2.0.0
+ */
+ public function dump () {
+ if (is_array($this->__container))
+ return $this->__container;
+ return get_object_vars($this->__container);
+ }
+
+ /**
+ * Mapping >> offsetSet
+ *
+ * @since 2.0.0
+ */
+ public function __set ($offset, $value) {
+ return $this->offsetSet($offset, $value);
+ }
+
+ /**
+ * Mapping >> offsetGet
+ *
+ * @since 2.0.0
+ */
+ public function __get ($offset) {
+ return $this->offsetGet($offset);
+ }
+
+ /**
+ * Mapping >> offsetExists
+ *
+ * @since 2.0.0
+ */
+ public function __isset ($offset) {
+ return $this->offsetExists($offset);
+ }
+
+ /**
+ * Mapping >> offsetUnset
+ *
+ * @since 2.0.0
+ */
+ public function __unset ($offset) {
+ $this->offsetUnset($offset);
+ }
+}
View
968 classes/PodsData.php
@@ -0,0 +1,968 @@
+<?php
+class PodsData
+{
+ // base
+ private $prefix = 'pods_';
+ private $field_types = array();
+ public $display_errors = true;
+
+ // pods
+ public $pod = null;
+ public $pod_data = null;
+ public $id = 0;
+
+ // data
+ public $row_number = -1;
+ public $data;
+ public $row;
+ public $insert_id;
+ public $total;
+
+ /**
+ * Data Abstraction Class for Pods
+ *
+ * @param string $pod Pod name
+ * @param integer $id Pod Item ID
+ * @license http://www.gnu.org/licenses/gpl-2.0.html
+ * @since 2.0.0
+ */
+ public function __construct ($pod = null, $id = 0) {
+ if (0 < strlen($pod)) {
+ $pod_id = pods_absint($pod);
+ $where = $this->prepare('name = %s', $pod);
+ if (0 < $pod_id)
+ $where = $this->prepare('id = %d', $pod_id);
+ $pod_data = $this->select(array('table' => '@wp_pods',
+ 'where' => $where,
+ 'limit' => 1));
+ if (is_array($pod_data) && !empty($pod_data)) {
+ $this->pod_data = $pod_data[0];
+ $this->pod_data->options = @json_decode($this->pod_data->options, true);
+ if (empty($this->pod_data->options))
+ $this->pod_data->options = array();
+ $field_data = $this->select(array('table' => '@wp_pods_fields',
+ 'where' => "pod_id = {$this->data->id}",
+ 'limit' => 1));
+ $fields = array();
+ if (is_array($field_data) && !empty($field_data)) {
+ foreach ($field_data as $field) {
+ $fields[$field->name] = $field;
+ $fields[$field->name]->options = @json_decode($fields[$field->name]->options, true);
+ if (empty($fields[$field->name]->options))
+ $fields[$field->name]->options = array();
+ }
+ }
+ $this->pod_data->fields = $fields;
+ $this->pod = $this->pod_data->name;
+ if ('pod' == $this->pod_data->type)
+ $this->pod_data->table = 'tbl_' . $this->pod;
+ $id = pods_absint($id);
+ if (0 < $id)
+ $this->id = $id;
+ }
+ }
+ }
+
+ public function insert ($table, $data, $format = null) {
+ global $wpdb;
+ if (strlen($table) < 1 || empty($data) || !is_array($data))
+ return false;
+ if (empty($format)) {
+ $format = array();
+ foreach ($data as $field) {
+ if (isset($this->field_types[$field]))
+ $format[] = $this->field_types[$field];
+ elseif (isset($wpdb->field_types[$field]))
+ $format[] = $wpdb->field_types[$field];
+ else
+ break;
+ }
+ }
+ list($table, $data, $format) = $this->do_hook('insert', array($table, $data, $format));
+ return $wpdb->insert($table, $data, $format);
+ }
+
+ public function update ($table, $data, $where, $format = null, $where_format = null) {
+ global $wpdb;
+ if (strlen($table) < 1 || empty($data) || !is_array($data))
+ return false;
+ if (empty($format)) {
+ $format = array();
+ foreach ($data as $field) {
+ if (isset($this->field_types[$field]))
+ $form = $this->field_types[$field];
+ elseif (isset($wpdb->field_types[$field]))
+ $form = $wpdb->field_types[$field];
+ else
+ $form = '%s';
+ $format[] = $form;
+ }
+ }
+ if (empty($where_format)) {
+ $where_format = array();
+ foreach ((array) array_keys($where) as $field) {
+ if (isset($this->field_types[$field]))
+ $form = $this->field_types[$field];
+ elseif (isset($wpdb->field_types[$field]))
+ $form = $wpdb->field_types[$field];
+ else
+ $form = '%s';
+ $where_format[] = $form;
+ }
+ }
+ list($table, $data, $where, $format, $where_format) = $this->do_hook('update', array($table, $data, $where, $format, $where_format));
+ return $wpdb->update($table, $data, $where, $format, $where_format);
+ }
+
+ public function delete ($table, $where, $where_format = null) {
+ global $wpdb;
+ if (strlen($table) < 1 || empty($where) || !is_array($where))
+ return false;
+ $wheres = array();
+ $where_formats = $where_format = (array) $where_format;
+ foreach ((array) array_keys($where) as $field) {
+ if (!empty($where_format))
+ $form = ($form = array_shift($where_formats)) ? $form : $where_format[0];
+ elseif (isset($this->field_types[$field]))
+ $form = $this->field_types[$field];
+ elseif (isset($wpdb->field_types[$field]))
+ $form = $wpdb->field_types[$field];
+ else
+ $form = '%s';
+ $wheres[] = "`{$field}` = {$form}";
+ }
+ $sql = "DELETE FROM `$table` WHERE " . implode(' AND ', $wheres);
+ list($sql, $where) = $this->do_hook('insert', array($sql, array_values($where)), $table, $where, $where_format, $wheres);
+ return $this->query($this->prepare($sql, $where));
+ }
+
+ public function select ($params) {
+ /*
+ * sql params:
+ *
+ * select
+ * table
+ * join
+ * where
+ * groupby
+ * having
+ * orderby
+ * limit
+ *
+ * build params:
+ *
+ * page
+ * search
+ * filters
+ * sort
+ *
+ * return:
+ *
+ * array of objects
+ */
+ $defaults = array('select' => '*',
+ 'table' => null,
+ 'join' => null,
+ 'where' => null,
+ 'groupby' => null,
+ 'having' => null,
+ 'orderby' => null,
+ 'limit' => -1,
+ 'identifier' => 'id',
+ 'index' => 'name',
+ 'page' => 1,
+ 'search' => null,
+ 'filters' => null,
+ 'sort' => null,
+ 'fields' => null,
+ 'sql' => null);
+ $params = (object) array_merge($defaults, (array) $params);
+ $params->page = pods_absint($params->page);
+ if (0 == $params->page)
+ $params->page = 1;
+ $params->limit = pods_absint($params->limit);
+ if (0 == $params->limit)
+ $params->limit = -1;
+ if (empty($params->fields) || !is_array($params->fields) && isset($this->pod_data->fields) && !empty($this->pod_data->fields))
+ $params->fields = $this->pod_data->fields;
+
+ $where = (array) $params->where;
+ if (empty($where))
+ $where = array();
+ $having = (array) $params->having;
+ if (empty($having))
+ $having = array();
+ if (false !== $this->search_query && 0 < strlen($this->search_query)) {
+ foreach ($params->fields as $key => $field) {
+ $attributes = $field;
+ if (!is_array($attributes))
+ $attributes = array();
+ if (false === $attributes['search'])
+ continue;
+ if (in_array($attributes['type'], array('date', 'time', 'datetime')))
+ continue;
+ if (is_array($field))
+ $field = $key;
+ if (!isset($this->filters[$field]))
+ continue;
+ $fieldfield = '`' . $field . '`';
+ if (isset($selects[$field]))
+ $fieldfield = '`' . $selects[$field] . '`';
+ if (false !== $attributes['real_name'])
+ $fieldfield = $attributes['real_name'];
+ if (false !== $attributes['group_related'])
+ $having[] = "$fieldfield LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ else
+ $where[] = "$fieldfield LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ }
+ if (!empty($where)) {
+ $where = array('(' . implode(' OR ', $where) . ')');
+ }
+ if (!empty($having)) {
+ $having = array('(' . implode(' OR ', $having) . ')');
+ }
+ }
+ foreach ($this->filters as $filter) {
+ if (!isset($this->search_fields[$filter]))
+ continue;
+ $filterfield = '`' . $filter . '`';
+ if (isset($selects[$filter]))
+ $filterfield = '`' . $selects[$filter] . '`';
+ if (false !== $this->search_fields[$filter]['real_name'])
+ $filterfield = $this->search_fields[$filter]['real_name'];
+ if (in_array($this->search_fields[$filter]['type'], array('date', 'datetime'))) {
+ $start = date('Y-m-d') . ('datetime' == $this->search_fields[$filter]['type']) ? ' 00:00:00' : '';
+ $end = date('Y-m-d') . ('datetime' == $this->search_fields[$filter]['type']) ? ' 23:59:59' : '';
+ if (strlen($this->get_var('filter_' . $filter . '_start', false)) < 1 && strlen($this->get_var('filter_' . $filter . '_end', false)) < 1)
+ continue;
+ if (0 < strlen($this->get_var('filter_' . $filter . '_start', false)))
+ $start = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_start', false))) . ('datetime' == $this->search_fields[$filter]['type']) ? ' 00:00:00' : '';
+ if (0 < strlen($this->get_var('filter_' . $filter . '_end', false)))
+ $end = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_end', false))) . ('datetime' == $this->search_fields[$filter]['type']) ? ' 23:59:59' : '';
+ if (false !== $this->search_fields[$filter]['date_ongoing']) {
+ $date_ongoing = $this->search_fields[$filter]['date_ongoing'];
+ if (isset($selects[$date_ongoing]))
+ $date_ongoing = $selects[$date_ongoing];
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having[] = "(($filterfield <= '$start' OR ($filterfield >= '$start' AND $filterfield <= '$end')) AND ($date_ongoing >= '$start' OR ($date_ongoing >= '$start' AND $date_ongoing <= '$end')))";
+ else
+ $where[] = "(($filterfield <= '$start' OR ($filterfield >= '$start' AND $filterfield <= '$end')) AND ($date_ongoing >= '$start' OR ($date_ongoing >= '$start' AND $date_ongoing <= '$end')))";
+ }
+ else {
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having[] = "($filterfield BETWEEN '$start' AND '$end')";
+ else
+ $where[] = "($filterfield BETWEEN '$start' AND '$end')";
+ }
+ }
+ elseif (0 < strlen($this->get_var('filter_' . $filter, false))) {
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having[] = "$filterfield LIKE '%" . PodsUI::sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ else
+ $where[] = "$filterfield LIKE '%" . PodsUI::sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ }
+ }
+ if (null !== $params->sql)
+ $params->sql = $this->build($params);
+ else {
+
+ }
+ }
+
+ public function build ($params) {
+ $defaults = array('select' => '*',
+ 'join' => null,
+ 'where' => null,
+ 'groupby' => null,
+ 'having' => null,
+ 'orderby' => null,
+ 'limit' => -1,
+ 'page' => 1,
+ 'sql' => null);
+ $params = (object) array_merge($defaults, (array) $params);
+ $params->page = pods_absint($params->page);
+ if (0 == $params->page)
+ $params->page = 1;
+ $params->limit = pods_absint($params->limit);
+ if (0 == $params->limit)
+ $params->limit = -1;
+ if (empty($params->sql))
+ return false;
+
+ // build SQL based off of sql query
+ global $wpdb;
+ if (false === $this->sql) {
+ $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM $this->table";
+ if (false !== $this->search && !empty($this->search_fields)) {
+ $whered = false;
+ if (false !== $this->search_query && 0 < strlen($this->search_query)) {
+ $sql .= " WHERE ";
+ $whered = true;
+ $where_sql = array();
+ foreach ($this->search_fields as $key => $field) {
+ if (false === $field['search'])
+ continue;
+ if (in_array($field['type'], array('date', 'time', 'datetime')))
+ continue;
+ if (is_array($field))
+ $field = $key;
+ $where_sql[] = "`$field` LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ }
+ if (!empty($where_sql))
+ $sql .= '(' . implode(' OR ', $where_sql) . ')';
+ }
+ $where_sql = array();
+ foreach ($this->filters as $filter) {
+ if (!isset($this->search_fields[$filter]))
+ continue;
+ if (in_array($this->search_fields[$filter]['type'], array('date', 'datetime'))) {
+ $start = date('Y-m-d') . ' 00:00:00';
+ $end = date('Y-m-d') . ' 23:59:59';
+ if (strlen($this->get_var('filter_' . $filter . '_start', false)) < 1 && strlen($this->get_var('filter_' . $filter . '_end', false)) < 1)
+ continue;
+ if (0 < strlen($this->get_var('filter_' . $filter . '_start', false)))
+ $start = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_start', false))) . ' 00:00:00';
+ if (0 < strlen($this->get_var('filter_' . $filter . '_end', false)))
+ $end = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_end', false))) . ' 23:59:59';
+ if (false !== $this->search_fields[$filter]['date_ongoing'])
+ $where_sql[] = "((`$filter` <= '$start' OR `$filter` <= '$end') AND (`" . $this->search_fields[$filter]['date_ongoing'] . "` >= '$end' OR `" . $this->search_fields[$filter]['date_ongoing'] . "` >= '$start'))";
+ else
+ $where_sql[] = "(`$filter` BETWEEN '$start' AND '$end')";
+ }
+ elseif (0 < strlen($this->get_var('filter_' . $filter, false)))
+ $where_sql[] = "`$filter` LIKE '%" . $this->sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ }
+ if (!empty($where_sql)) {
+ if (false === $whered)
+ $sql .= " WHERE ";
+ else
+ $sql .= " AND ";
+ $sql .= implode(' AND ', $where_sql);
+ }
+ }
+ $sql .= ' ORDER BY ';
+ if (false !== $this->sort && (false === $this->reorder || 'reorder' != $this->action))
+ $sql .= $this->sort . ' ' . $this->sort_dir;
+ elseif (false !== $this->reorder && 'reorder' == $this->action)
+ $sql .= $this->reorder_sort . ' ' . $this->reorder_sort_dir;
+ else
+ $sql .= $this->identifier;
+ if (false !== $this->pagination) {
+ $start = ($this->page - 1) * $this->limit;
+ $end = ($this->page - 1) * $this->limit + $this->limit;
+ $sql .= " LIMIT $start, $end";
+ }
+ }
+ else {
+ $sql = str_replace(array("\n", "\r"), ' ', ' ' . $this->sql);
+ $sql = str_ireplace(' SELECT ', ' SELECT SQL_CALC_FOUND_ROWS ', str_ireplace(' SELECT SQL_CALC_FOUND_ROWS ', ' SELECT ', $sql));
+ $wheresql = $havingsql = $ordersql = $limitsql = '';
+ $where_sql = $having_sql = array();
+ preg_match('/SELECT SQL_CALC_FOUND_ROWS (.*) FROM/i', $sql, $selectmatches);
+ $selects = array();
+ if (isset($selectmatches[1]) && !empty($selectmatches[1]) && false !== stripos($selectmatches[1], ' AS ')) {
+ $theselects = explode(', ', $selectmatches[1]);
+ if (empty($theselects))
+ $theselects = explode(',', $selectmatches[1]);
+ foreach ($theselects as $selected) {
+ $selectfield = explode(' AS ', $selected);
+ if (2 == count($selectfield)) {
+ $field = trim(trim($selectfield[1]), '`');
+ $real_field = trim(trim($selectfield[0]), '`');
+ $selects[$field] = $real_field;
+ }
+ }
+ }
+ if (false !== $this->search && !empty($this->search_fields)) {
+ if (false !== $this->search_query && 0 < strlen($this->search_query)) {
+ foreach ($this->search_fields as $key => $field) {
+ $attributes = $field;
+ if (!is_array($attributes))
+ $attributes = array();
+ if (false === $attributes['search'])
+ continue;
+ if (in_array($attributes['type'], array('date', 'time', 'datetime')))
+ continue;
+ if (is_array($field))
+ $field = $key;
+ if (!isset($this->filters[$field]))
+ continue;
+ $fieldfield = '`' . $field . '`';
+ if (isset($selects[$field]))
+ $fieldfield = '`' . $selects[$field] . '`';
+ if (false !== $attributes['real_name'])
+ $fieldfield = $attributes['real_name'];
+ if (false !== $attributes['group_related'])
+ $having_sql[] = "$fieldfield LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ else
+ $where_sql[] = "$fieldfield LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ }
+ if (!empty($where_sql)) {
+ $where_sql = array('(' . implode(' OR ', $where_sql) . ')');
+ }
+ if (!empty($having_sql)) {
+ $having_sql = array('(' . implode(' OR ', $having_sql) . ')');
+ }
+ }
+ foreach ($this->filters as $filter) {
+ if (!isset($this->search_fields[$filter]))
+ continue;
+ $filterfield = '`' . $filter . '`';
+ if (isset($selects[$filter]))
+ $filterfield = '`' . $selects[$filter] . '`';
+ if (false !== $this->search_fields[$filter]['real_name'])
+ $filterfield = $this->search_fields[$filter]['real_name'];
+ if (in_array($this->search_fields[$filter]['type'], array('date', 'datetime'))) {
+ $start = date('Y-m-d') . ('datetime' == $this->search_fields[$filter]['type']) ? ' 00:00:00' : '';
+ $end = date('Y-m-d') . ('datetime' == $this->search_fields[$filter]['type']) ? ' 23:59:59' : '';
+ if (strlen($this->get_var('filter_' . $filter . '_start', false)) < 1 && strlen($this->get_var('filter_' . $filter . '_end', false)) < 1)
+ continue;
+ if (0 < strlen($this->get_var('filter_' . $filter . '_start', false)))
+ $start = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_start', false))) . ('datetime' == $this->search_fields[$filter]['type']) ? ' 00:00:00' : '';
+ if (0 < strlen($this->get_var('filter_' . $filter . '_end', false)))
+ $end = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_end', false))) . ('datetime' == $this->search_fields[$filter]['type']) ? ' 23:59:59' : '';
+ if (false !== $this->search_fields[$filter]['date_ongoing']) {
+ $date_ongoing = $this->search_fields[$filter]['date_ongoing'];
+ if (isset($selects[$date_ongoing]))
+ $date_ongoing = $selects[$date_ongoing];
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having_sql[] = "(($filterfield <= '$start' OR ($filterfield >= '$start' AND $filterfield <= '$end')) AND ($date_ongoing >= '$start' OR ($date_ongoing >= '$start' AND $date_ongoing <= '$end')))";
+ else
+ $where_sql[] = "(($filterfield <= '$start' OR ($filterfield >= '$start' AND $filterfield <= '$end')) AND ($date_ongoing >= '$start' OR ($date_ongoing >= '$start' AND $date_ongoing <= '$end')))";
+ }
+ else {
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having_sql[] = "($filterfield BETWEEN '$start' AND '$end')";
+ else
+ $where_sql[] = "($filterfield BETWEEN '$start' AND '$end')";
+ }
+ }
+ elseif (0 < strlen($this->get_var('filter_' . $filter, false))) {
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having_sql[] = "$filterfield LIKE '%" . PodsUI::sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ else
+ $where_sql[] = "$filterfield LIKE '%" . PodsUI::sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ }
+ }
+ if (!empty($where_sql)) {
+ if (false === stripos($sql, ' WHERE '))
+ $wheresql .= ' WHERE (' . implode(' AND ', $where_sql) . ')';
+ elseif (empty($wheresql))
+ $wheresql .= ' AND (' . implode(' AND ', $where_sql) . ')';
+ else
+ $wheresql .= '(' . implode(' AND ', $where_sql) . ') AND ';
+ }
+ if (!empty($having_sql)) {
+ if (false === stripos($sql, ' HAVING '))
+ $havingsql .= ' HAVING (' . implode(' AND ', $having_sql) . ')';
+ elseif (empty($havingsql))
+ $havingsql .= ' AND (' . implode(' AND ', $having_sql) . ')';
+ else
+ $havingsql .= '(' . implode(' AND ', $having_sql) . ') AND ';
+ }
+ }
+ if (false !== $this->sort && (false === $this->reorder || 'reorder' != $this->action))
+ $ordersql = trim($this->sort . ' ' . $this->sort_dir);
+ elseif (false !== $this->reorder && 'reorder' == $this->action)
+ $ordersql = trim($this->reorder_sort . ' ' . $this->reorder_sort_dir);
+ elseif (false === stripos($sql, ' ORDER BY '))
+ $ordersql = trim($this->identifier);
+ if (!empty($ordersql)) {
+ if (false === stripos($sql, ' ORDER BY '))
+ $ordersql = ' ORDER BY ' . $ordersql;
+ else
+ $ordersql = $ordersql . ', ';
+ }
+ if (false !== $this->pagination && false === stripos($sql, ' LIMIT ')) {
+ $start = ($this->page - 1) * $this->limit;
+ $end = ($this->page - 1) * $this->limit + $this->limit;
+ $limitsql .= " LIMIT $start, $end";
+ }
+ $sql = str_replace(' WHERE ', ' WHERE %%WHERE%% ', $sql);
+ $sql = str_replace(' HAVING ', ' HAVING %%HAVING%% ', $sql);
+ $sql = str_replace(' ORDER BY ', ' ORDER BY %%ORDERBY%% ', $sql);
+ if (false === stripos($sql, '%%WHERE%%') && false === stripos($sql, ' WHERE ')) {
+ if (false !== stripos($sql, ' GROUP BY '))
+ $sql = str_replace(' GROUP BY ', ' %%WHERE%% GROUP BY ', $sql);
+ elseif (false !== stripos($sql, ' ORDER BY '))
+ $sql = str_replace(' ORDER BY ', ' %%WHERE%% ORDER BY ', $sql);
+ elseif (false !== stripos($sql, ' LIMIT '))
+ $sql = str_replace(' LIMIT ', ' %%WHERE%% LIMIT ', $sql);
+ else
+ $sql .= ' %%WHERE%% ';
+ }
+ if (false === stripos($sql, '%%HAVING%%') && false === stripos($sql, ' HAVING ')) {
+ if (false !== stripos($sql, ' ORDER BY '))
+ $sql = str_replace(' ORDER BY ', ' %%HAVING%% ORDER BY ', $sql);
+ elseif (false !== stripos($sql, ' LIMIT '))
+ $sql = str_replace(' LIMIT ', ' %%HAVING%% LIMIT ', $sql);
+ else
+ $sql .= ' %%HAVING%% ';
+ }
+ if (false === stripos($sql, '%%ORDERBY%%') && false === stripos($sql, ' ORDER BY ')) {
+ if (false !== stripos($sql, ' LIMIT '))
+ $sql = str_replace(' LIMIT ', ' %%ORDERBY%% LIMIT ', $sql);
+ else
+ $sql .= ' %%ORDERBY%% ';
+ }
+ if (false === stripos($sql, '%%LIMIT%%') && false === stripos($sql, ' LIMIT '))
+ $sql .= ' %%LIMIT%%';
+ $sql = str_replace('%%WHERE%%', $wheresql, $sql);
+ $sql = str_replace('%%HAVING%%', $havingsql, $sql);
+ $sql = str_replace('%%ORDERBY%%', $ordersql, $sql);
+ $sql = str_replace('%%LIMIT%%', $limitsql, $sql);
+ $sql = str_replace('``', '`', $sql);
+ $sql = str_replace(' ', ' ', $sql);
+ //echo "<textarea cols='130' rows='30'>$sql</textarea>";
+ }
+ $results = $wpdb->get_results($sql, array_A);
+ $results = $this->do_hook('get_data', $results);
+ $this->data = $results;
+ if (empty($this->fields) && !empty($this->data)) {
+ $data = current($this->data);
+ foreach ($data as $data_key => $data_value) {
+ $this->fields[$data_key] = array('label' => ucwords(str_replace('-', ' ', str_replace('_', ' ', $data_key))));
+ }
+ $this->export_fields = $this->fields;
+ }
+ $total = @current($wpdb->get_col("SELECT FOUND_ROWS()"));
+ $total = $this->do_hook('get_data_total', $total);
+ if (is_numeric($total))
+ $this->total = $total;
+ return $results;
+ }
+
+ public static function table_create ($table, $fields, $if_not_exists = false) {
+ global $wpdb;
+ $sql = "CREATE TABLE";
+ if (true === $if_not_exists)
+ $sql .= " IF NOT EXISTS";
+ $sql .= " `{$wpdb->prefix}" . self::prefix . "{$table}` ({$fields})";
+ if (!empty($wpdb->charset))
+ $sql .= " DEFAULT CHARACTER SET {$wpdb->charset}";
+ if (!empty($wpdb->collate))
+ $sql .= " COLLATE {$wpdb->collate}";
+ return self::query($sql);
+ }
+
+ public static function table_alter ($table, $changes) {
+ global $wpdb;
+ $sql = "ALTER TABLE `{$wpdb->prefix}" . self::prefix . "{$table}` {$changes}";
+ return self::query($sql);
+ }
+
+ public static function table_truncate ($table) {
+ global $wpdb;
+ $sql = "TRUNCATE TABLE `{$wpdb->prefix}" . self::prefix . "{$table}`";
+ return self::query($sql);
+ }
+
+ public static function table_drop ($table) {
+ global $wpdb;
+ $sql = "DROP TABLE `{$wpdb->prefix}" . self::prefix . "{$table}`";
+ return self::query($sql);
+ }
+
+ public function reorder ($table, $weight_field, $id_field, $ids) {
+ $success = false;
+ $ids = (array) $ids;
+ list($table, $weight_field, $id_field, $ids) = $this->do_hook('reorder', array($table, $weight_field, $id_field, $ids));
+ if (!empty($ids)) {
+ $success = true;
+ foreach ($ids as $weight => $id) {
+ $updated = $this->update($table, array($weight_field => $weight), array($id_field => $id), array('%d'), array('%d'));
+ if (false === $updated)
+ $success = false;
+ }
+ }
+ return $success;
+ }
+
+ function get_row ($id = false) {
+ if (isset($this->actions_custom['row']) && function_exists("{$this->actions_custom['row']}"))
+ return $this->actions_custom['row']($id, &$this);
+ if (false !== $this->ui['pod'] && is_object($this->ui['pod'])) {
+ if (false === $id) {
+ $this->ui['pod']->fetch();
+ $row = $this->ui['pod']->data;
+ $row = $this->do_hook('get_row', $row, $id);
+ $this->row = $row;
+ return $row;
+ }
+ else {
+ foreach ($this->ui['pod']->result as $row) {
+ if (!empty($row) && $id === $row[$this->identified]) {
+ $row = $this->do_hook('get_row', $row, $id);
+ $this->row = $row;
+ return $row;
+ }
+ }
+ }
+ }
+ if (false === $this->table && false === $this->sql)
+ return $this->error(__('<strong>Error:</strong> Invalid Configuration - Missing "table" definition.', 'pods'));
+ if (false === $this->id && false === $id)
+ return $this->error(__('<strong>Error:</strong> Invalid Configuration - Missing "id" definition.', 'pods'));
+ if (false === $id)
+ $id = $this->id;
+ global $wpdb;
+ $sql = "SELECT * FROM `{$this->table}` WHERE `id` = " . $this->sanitize($id);
+ $row = @current($wpdb->get_results($sql, array_A));
+ $row = $this->do_hook('get_row', $row, $id);
+ if (!empty($row))
+ $this->row = $row;
+ return $row;
+ }
+
+ function get_data ($full = false) {
+ if (isset($this->actions_custom['data']) && function_exists("{$this->actions_custom['data']}"))
+ return $this->actions_custom['data']($full, &$this);
+ if (false !== $this->ui['pod'] && is_object($this->ui['pod'])) {
+ if (false !== $this->sort && (false === $this->reorder || 'reorder' != $this->action))
+ $sort = $this->sort . ' ' . $this->sort_dir;
+ elseif (false !== $this->reorder && 'reorder' == $this->action)
+ $sort = $this->reorder_sort . ' ' . $this->reorder_sort_dir;
+ $params = array('limit' => $this->limit, 'orderby' => $sort, 'search_var' => 'search_query' . $this->num, 'page_var' => 'pg' . $this->num);
+ if (false !== $full)
+ $params['limit'] = -1;
+ $this->ui['pod']->find($params);
+ $results = $this->ui['pod']->results;
+ $results = $this->do_hook('get_data', $results, $full);
+ return $results;
+ }
+ if (false === $this->table && false === $this->sql)
+ return $this->error(__('<strong>Error:</strong> Invalid Configuration - Missing "table" definition.', 'pods'));
+ global $wpdb;
+ if (false === $this->sql) {
+ $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM $this->table";
+ if (false !== $this->search && !empty($this->search_fields)) {
+ $whered = false;
+ if (false !== $this->search_query && 0 < strlen($this->search_query)) {
+ $sql .= " WHERE ";
+ $whered = true;
+ $where_sql = array();
+ foreach ($this->search_fields as $key => $field) {
+ if (false === $field['search'])
+ continue;
+ if (in_array($field['type'], array('date', 'time', 'datetime')))
+ continue;
+ if (is_array($field))
+ $field = $key;
+ $where_sql[] = "`$field` LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ }
+ if (!empty($where_sql))
+ $sql .= '(' . implode(' OR ', $where_sql) . ')';
+ }
+ $where_sql = array();
+ foreach ($this->filters as $filter) {
+ if (!isset($this->search_fields[$filter]))
+ continue;
+ if (in_array($this->search_fields[$filter]['type'], array('date', 'datetime'))) {
+ $start = date('Y-m-d') . ' 00:00:00';
+ $end = date('Y-m-d') . ' 23:59:59';
+ if (strlen($this->get_var('filter_' . $filter . '_start', false)) < 1 && strlen($this->get_var('filter_' . $filter . '_end', false)) < 1)
+ continue;
+ if (0 < strlen($this->get_var('filter_' . $filter . '_start', false)))
+ $start = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_start', false))) . ' 00:00:00';
+ if (0 < strlen($this->get_var('filter_' . $filter . '_end', false)))
+ $end = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_end', false))) . ' 23:59:59';
+ if (false !== $this->search_fields[$filter]['date_ongoing'])
+ $where_sql[] = "((`$filter` <= '$start' OR `$filter` <= '$end') AND (`" . $this->search_fields[$filter]['date_ongoing'] . "` >= '$end' OR `" . $this->search_fields[$filter]['date_ongoing'] . "` >= '$start'))";
+ else
+ $where_sql[] = "(`$filter` BETWEEN '$start' AND '$end')";
+ }
+ elseif (0 < strlen($this->get_var('filter_' . $filter, false)))
+ $where_sql[] = "`$filter` LIKE '%" . $this->sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ }
+ if (!empty($where_sql)) {
+ if (false === $whered)
+ $sql .= " WHERE ";
+ else
+ $sql .= " AND ";
+ $sql .= implode(' AND ', $where_sql);
+ }
+ }
+ $sql .= ' ORDER BY ';
+ if (false !== $this->sort && (false === $this->reorder || 'reorder' != $this->action))
+ $sql .= $this->sort . ' ' . $this->sort_dir;
+ elseif (false !== $this->reorder && 'reorder' == $this->action)
+ $sql .= $this->reorder_sort . ' ' . $this->reorder_sort_dir;
+ else
+ $sql .= $this->identifier;
+ if (false !== $this->pagination && !$full) {
+ $start = ($this->page - 1) * $this->limit;
+ $end = ($this->page - 1) * $this->limit + $this->limit;
+ $sql .= " LIMIT $start, $end";
+ }
+ }
+ else {
+ $sql = str_replace(array("\n", "\r"), ' ', ' ' . $this->sql);
+ $sql = str_ireplace(' SELECT ', ' SELECT SQL_CALC_FOUND_ROWS ', str_ireplace(' SELECT SQL_CALC_FOUND_ROWS ', ' SELECT ', $sql));
+ $wheresql = $havingsql = $ordersql = $limitsql = '';
+ $where_sql = $having_sql = array();
+ preg_match('/SELECT SQL_CALC_FOUND_ROWS (.*) FROM/i', $sql, $selectmatches);
+ $selects = array();
+ if (isset($selectmatches[1]) && !empty($selectmatches[1]) && false !== stripos($selectmatches[1], ' AS ')) {
+ $theselects = explode(', ', $selectmatches[1]);
+ if (empty($theselects))
+ $theselects = explode(',', $selectmatches[1]);
+ foreach ($theselects as $selected) {
+ $selectfield = explode(' AS ', $selected);
+ if (2 == count($selectfield)) {
+ $field = trim(trim($selectfield[1]), '`');
+ $real_field = trim(trim($selectfield[0]), '`');
+ $selects[$field] = $real_field;
+ }
+ }
+ }
+ if (false !== $this->search && !empty($this->search_fields)) {
+ if (false !== $this->search_query && 0 < strlen($this->search_query)) {
+ foreach ($this->search_fields as $key => $field) {
+ $attributes = $field;
+ if (!is_array($attributes))
+ $attributes = array();
+ if (false === $attributes['search'])
+ continue;
+ if (in_array($attributes['type'], array('date', 'time', 'datetime')))
+ continue;
+ if (is_array($field))
+ $field = $key;
+ if (!isset($this->filters[$field]))
+ continue;
+ $fieldfield = '`' . $field . '`';
+ if (isset($selects[$field]))
+ $fieldfield = '`' . $selects[$field] . '`';
+ if (false !== $attributes['real_name'])
+ $fieldfield = $attributes['real_name'];
+ if (false !== $attributes['group_related'])
+ $having_sql[] = "$fieldfield LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ else
+ $where_sql[] = "$fieldfield LIKE '%" . $this->sanitize($this->search_query) . "%'";
+ }
+ if (!empty($where_sql)) {
+ $where_sql = array('(' . implode(' OR ', $where_sql) . ')');
+ }
+ if (!empty($having_sql)) {
+ $having_sql = array('(' . implode(' OR ', $having_sql) . ')');
+ }
+ }
+ foreach ($this->filters as $filter) {
+ if (!isset($this->search_fields[$filter]))
+ continue;
+ $filterfield = '`' . $filter . '`';
+ if (isset($selects[$filter]))
+ $filterfield = '`' . $selects[$filter] . '`';
+ if (false !== $this->search_fields[$filter]['real_name'])
+ $filterfield = $this->search_fields[$filter]['real_name'];
+ if (in_array($this->search_fields[$filter]['type'], array('date', 'datetime'))) {
+ $start = date('Y-m-d') . ('datetime' == $this->search_fields[$filter]['type']) ? ' 00:00:00' : '';
+ $end = date('Y-m-d') . ('datetime' == $this->search_fields[$filter]['type']) ? ' 23:59:59' : '';
+ if (strlen($this->get_var('filter_' . $filter . '_start', false)) < 1 && strlen($this->get_var('filter_' . $filter . '_end', false)) < 1)
+ continue;
+ if (0 < strlen($this->get_var('filter_' . $filter . '_start', false)))
+ $start = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_start', false))) . ('datetime' == $this->search_fields[$filter]['type']) ? ' 00:00:00' : '';
+ if (0 < strlen($this->get_var('filter_' . $filter . '_end', false)))
+ $end = date('Y-m-d', strtotime($this->get_var('filter_' . $filter . '_end', false))) . ('datetime' == $this->search_fields[$filter]['type']) ? ' 23:59:59' : '';
+ if (false !== $this->search_fields[$filter]['date_ongoing']) {
+ $date_ongoing = $this->search_fields[$filter]['date_ongoing'];
+ if (isset($selects[$date_ongoing]))
+ $date_ongoing = $selects[$date_ongoing];
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having_sql[] = "(($filterfield <= '$start' OR ($filterfield >= '$start' AND $filterfield <= '$end')) AND ($date_ongoing >= '$start' OR ($date_ongoing >= '$start' AND $date_ongoing <= '$end')))";
+ else
+ $where_sql[] = "(($filterfield <= '$start' OR ($filterfield >= '$start' AND $filterfield <= '$end')) AND ($date_ongoing >= '$start' OR ($date_ongoing >= '$start' AND $date_ongoing <= '$end')))";
+ }
+ else {
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having_sql[] = "($filterfield BETWEEN '$start' AND '$end')";
+ else
+ $where_sql[] = "($filterfield BETWEEN '$start' AND '$end')";
+ }
+ }
+ elseif (0 < strlen($this->get_var('filter_' . $filter, false))) {
+ if (false !== $this->search_fields[$filter]['group_related'])
+ $having_sql[] = "$filterfield LIKE '%" . PodsUI::sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ else
+ $where_sql[] = "$filterfield LIKE '%" . PodsUI::sanitize($this->get_var('filter_' . $filter, false)) . "%'";
+ }
+ }
+ if (!empty($where_sql)) {
+ if (false === stripos($sql, ' WHERE '))
+ $wheresql .= ' WHERE (' . implode(' AND ', $where_sql) . ')';
+ elseif (empty($wheresql))
+ $wheresql .= ' AND (' . implode(' AND ', $where_sql) . ')';
+ else
+ $wheresql .= '(' . implode(' AND ', $where_sql) . ') AND ';
+ }
+ if (!empty($having_sql)) {
+ if (false === stripos($sql, ' HAVING '))
+ $havingsql .= ' HAVING (' . implode(' AND ', $having_sql) . ')';
+ elseif (empty($havingsql))
+ $havingsql .= ' AND (' . implode(' AND ', $having_sql) . ')';
+ else
+ $havingsql .= '(' . implode(' AND ', $having_sql) . ') AND ';
+ }
+ }
+ if (false !== $this->sort && (false === $this->reorder || 'reorder' != $this->action))
+ $ordersql = trim($this->sort . ' ' . $this->sort_dir);
+ elseif (false !== $this->reorder && 'reorder' == $this->action)
+ $ordersql = trim($this->reorder_sort . ' ' . $this->reorder_sort_dir);
+ elseif (false === stripos($sql, ' ORDER BY '))
+ $ordersql = trim($this->identifier);
+ if (!empty($ordersql)) {
+ if (false === stripos($sql, ' ORDER BY '))
+ $ordersql = ' ORDER BY ' . $ordersql;
+ else
+ $ordersql = $ordersql . ', ';
+ }
+ if (false !== $this->pagination && !$full && false === stripos($sql, ' LIMIT ')) {
+ $start = ($this->page - 1) * $this->limit;
+ $end = ($this->page - 1) * $this->limit + $this->limit;
+ $limitsql .= " LIMIT $start, $end";
+ }
+ $sql = str_replace(' WHERE ', ' WHERE %%WHERE%% ', $sql);
+ $sql = str_replace(' HAVING ', ' HAVING %%HAVING%% ', $sql);
+ $sql = str_replace(' ORDER BY ', ' ORDER BY %%ORDERBY%% ', $sql);
+ if (false === stripos($sql, '%%WHERE%%') && false === stripos($sql, ' WHERE ')) {
+ if (false !== stripos($sql, ' GROUP BY '))
+ $sql = str_replace(' GROUP BY ', ' %%WHERE%% GROUP BY ', $sql);
+ elseif (false !== stripos($sql, ' ORDER BY '))
+ $sql = str_replace(' ORDER BY ', ' %%WHERE%% ORDER BY ', $sql);
+ elseif (false !== stripos($sql, ' LIMIT '))
+ $sql = str_replace(' LIMIT ', ' %%WHERE%% LIMIT ', $sql);
+ else
+ $sql .= ' %%WHERE%% ';
+ }
+ if (false === stripos($sql, '%%HAVING%%') && false === stripos($sql, ' HAVING ')) {
+ if (false !== stripos($sql, ' ORDER BY '))
+ $sql = str_replace(' ORDER BY ', ' %%HAVING%% ORDER BY ', $sql);
+ elseif (false !== stripos($sql, ' LIMIT '))
+ $sql = str_replace(' LIMIT ', ' %%HAVING%% LIMIT ', $sql);
+ else
+ $sql .= ' %%HAVING%% ';
+ }
+ if (false === stripos($sql, '%%ORDERBY%%') && false === stripos($sql, ' ORDER BY ')) {
+ if (false !== stripos($sql, ' LIMIT '))
+ $sql = str_replace(' LIMIT ', ' %%ORDERBY%% LIMIT ', $sql);
+ else
+ $sql .= ' %%ORDERBY%% ';
+ }
+ if (false === stripos($sql, '%%LIMIT%%') && false === stripos($sql, ' LIMIT '))
+ $sql .= ' %%LIMIT%%';
+ $sql = str_replace('%%WHERE%%', $wheresql, $sql);
+ $sql = str_replace('%%HAVING%%', $havingsql, $sql);
+ $sql = str_replace('%%ORDERBY%%', $ordersql, $sql);
+ $sql = str_replace('%%LIMIT%%', $limitsql, $sql);
+ $sql = str_replace('``', '`', $sql);
+ $sql = str_replace(' ', ' ', $sql);
+ //echo "<textarea cols='130' rows='30'>$sql</textarea>";
+ }
+ $results = $wpdb->get_results($sql, array_A);
+ $results = $this->do_hook('get_data', $results, $full);
+ if ($full)
+ $this->full_data = $results;
+ else
+ $this->data = $results;
+ if ($full) {
+ if (empty($this->fields) && !empty($this->full_data)) {
+ $data = current($this->full_data);
+ foreach ($data as $data_key => $data_value) {
+ $this->fields[$data_key] = array('label' => ucwords(str_replace('-', ' ', str_replace('_', ' ', $data_key))));
+ }
+ $this->export_fields = $this->fields;
+ }
+ return;
+ }
+ else {
+ if (empty($this->fields) && !empty($this->data)) {
+ $data = current($this->data);
+ foreach ($data as $data_key => $data_value) {
+ $this->fields[$data_key] = array('label' => ucwords(str_replace('-', ' ', str_replace('_', ' ', $data_key))));
+ }
+ $this->export_fields = $this->fields;
+ }
+ }
+ $total = @current($wpdb->get_col("SELECT FOUND_ROWS()"));
+ $total = $this->do_hook('get_data_total', $total, $full);
+ if (is_numeric($total))
+ $this->total = $total;
+ return $results;
+ }
+
+ public static function query ($sql, $error = 'Database Error', $results_error = null, $no_results_error = null) {
+ global $wpdb;
+
+ if ($wpdb->show_errors)
+ self::$display_errors = true;
+
+ $display_errors = self::$display_errors;
+ if (is_object($error)) {
+ if (isset($error->display_errors) && false === $error->display_errors) {
+ $display_errors = false;
+ }
+ $error = 'Database Error';
+ }
+ elseif (is_bool($error)) {
+ $display_errors = $error;
+ $error = 'Database Error';
+ }
+
+ $params = array('sql' => $sql,
+ 'error' => $error,
+ 'results_error' => $results_error,
+ 'no_results_error' => $no_results_error,
+ 'display_errors' => $display_errors);
+ if (is_array($sql))
+ $params = array_merge($params, $sql);
+
+ $params->sql = trim($params->sql);
+ $params->sql = str_replace('@wp_users', $wpdb->users, $params->sql);
+ $params->sql = str_replace('@wp_', $wpdb->prefix, $params->sql);
+ $params->sql = str_replace('{prefix}', '@wp_', $params->sql);
+
+ // Run Query
+ $params->sql = self::do_hook('query', $params->sql, $params);
+ $result = $wpdb->query($sql);
+ $result = self::do_hook('query_result', $result, $params);
+
+ if (false === $result && !empty($params->error) && !empty($wpdb->last_error))
+ return pods_error("{$params->error}; SQL: {$params->sql}; Response: {$wpdb->last_error}", $params->display_errors);
+ if ('INSERT' == substr($params->sql, 0, 6))
+ $result = $wpdb->insert_id;
+ elseif ('SELECT' == substr($params->sql, 0, 6)) {
+ $result = (array) $wpdb->last_result;
+ if (!empty($result) && !empty($params->results_error))
+ return pods_error("{$params->results_error}", $params->display_errors);
+ elseif (empty($result) && !empty($params->no_results_error))
+ return pods_error("{$params->no_results_error}", $params->display_errors);
+ }
+ return $result;
+ }
+
+ public static function prepare ($sql, $data) {
+ global $wpdb;
+ list($sql, $data) = self::do_hook('prepare', array($sql, $data));
+ return $wpdb->prepare($sql, $data);
+ }
+
+ public static function switch_site ($new_blog, $validate = true) {
+ $new_blog = self::do_hook('switch_site', $new_blog, $validate);
+ $new_blog = pods_absint($new_blog);
+ if (0 < $new_blog)
+ return switch_to_blog($new_blog, $validate);
+ return false;
+ }
+
+ public static function restore_site () {
+ self::do_hook('restore_site');
+ return restore_current_blog();
+ }
+
+ private function do_hook () {
+ $args = func_get_args();
+ if (empty($args))
+ return false;
+ $name = array_shift($args);
+ return pods_do_hook("data", $name, $args, &$this);
+ }
+}
View
203 classes/PodsFormUI.php
@@ -0,0 +1,203 @@
+<?php
+class PodsFormUI {
+ /**
+ * Generate UI for a Form and it's Fields
+ *
+ * @license http://www.gnu.org/licenses/gpl-2.0.html
+ * @since 2.0.0
+ */
+ private function __construct () {
+ return false;
+ }
+
+ /**
+ * Output a field
+ *
+ * @since 2.0.0
+ */
+ public static function field ($name, $value, $type = 'text', $options = null) {
+ ob_start();
+ if (method_exists(get_called_class(), "field_{$type}")) {
+ $field = 'field_' . $type;
+ get_called_class()::$field($name, $value, $options);
+ }
+ elseif (method_exists(__CLASS__, "field_{$type}")) {
+ $field = 'field_' . $type;
+ __CLASS__::$field($name, $value, $options);
+ }
+ else
+ do_action('pods_form_ui_field_' . $type, $name, $value, $options);
+ return apply_filters('pods_form_ui_field', ob_get_clean(), $name, $value, $type, $options);
+ }
+
+ /**
+ * Output a field's attributes
+ *
+ * @since 2.0.0
+ */
+ public static function attributes ($attributes) {
+ foreach ($attributes as $attribute => $value) {
+ if (null === $value)
+ continue;
+ echo ' ' . esc_attr($attribute) . '="' . esc_attr($value) . '"';
+ }
+ }
+
+ /**
+ * Output field type 'text'
+ *
+ * @since 2.0.0
+ */
+ protected function field_text ($name, $value = null, $options = null) {
+ $type = 'text';
+ $attributes = array();
+ $attributes['type'] = 'text';
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ $attributes['class'] = 'pods_form_ui_field_' . $type;
+ $attributes['value'] = $value;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($attributes['value']) < 1)
+ $attributes['value'] = $options['default'];
+?>
+ <input<?php self::attributes($attributes); ?> />
+<?php
+ }
+
+ /**
+ * Output field type 'textarea'
+ *
+ * @since 2.0.0
+ */
+ protected function field_textarea ($name, $value = null, $options = null) {
+ $type = 'textarea';
+ $attributes = array();
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ $attributes['class'] = 'pods_form_ui_field_' . $type;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($value) < 1)
+ $value = $options['default'];
+ $value = apply_filters('pods_form_ui_field_' . $type . '_value', $value, $name, $attributes, $options);
+?>
+ <textarea<?php self::attributes($attributes); ?>><?php echo esc_html($value); ?></textarea>
+<?php
+ }
+
+ /**
+ * Output field type 'tinymce'
+ *
+ * @since 2.0.0
+ */
+ protected function field_tinymce ($name, $value = null, $options = null) {
+
+ $type = 'tinymce';
+ $attributes = array();
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($value) < 1)
+ $value = $options['default'];
+ $value = apply_filters('pods_form_ui_field_' . $type . '_value', $value, $name, $attributes, $options);
+ $settings = null;
+ if (isset($options['settings']))
+ $settings = $options['settings'];
+ require_once PODS_DIR . "/ui/wp-editor/wp-editor.php";
+ global $wp_editor;
+ $wp_editor->editor($value, $attributes['id'], $settings);
+ }
+
+ /**
+ * Output field type 'number'
+ *
+ * @since 2.0.0
+ */
+ protected function field_number ($name, $value = null, $options = null) {
+ $type = 'number';
+ $attributes = array();
+ $attributes['type'] = 'text';
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ $attributes['class'] = 'pods_form_ui_field_' . $type;
+ $attributes['value'] = $value;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($attributes['value']) < 1)
+ $attributes['value'] = $options['default'];
+ $attributes['value'] = number_format_i18n($attributes['value'], 0);
+ $attributes['value'] = apply_filters('pods_form_ui_field_' . $type . '_value', $attributes['value'], $name, $attributes, $options);
+?>
+ <input<?php self::attributes($attributes); ?> />
+<?php
+ }
+
+ /**
+ * Output field type 'decimal'
+ *
+ * @since 2.0.0
+ */
+ protected function field_decimal ($name, $value = null, $options = null) {
+ $type = 'number';
+ $decimals = 2;
+ if (isset($options['decimals']))
+ $decimals = $options['decimals'];
+ $attributes = array();
+ $attributes['type'] = 'text';
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ $attributes['class'] = 'pods_form_ui_field_' . $type;
+ $attributes['value'] = $value;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($attributes['value']) < 1)
+ $attributes['value'] = $options['default'];
+ $attributes['value'] = number_format_i18n($attributes['value'], $decimals);
+ $attributes['value'] = apply_filters('pods_form_ui_field_' . $type . '_value', $attributes['value'], $name, $attributes, $options);
+?>
+ <input<?php self::attributes($attributes); ?> />
+<?php
+ }
+
+ /**
+ * Output field type 'password'
+ *
+ * @since 2.0.0
+ */
+ protected function field_password ($name, $value = null, $options = null) {
+ $type = 'password';
+ $attributes = array();
+ $attributes['type'] = 'password';
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ $attributes['class'] = 'pods_form_ui_field_' . $type;
+ $attributes['value'] = $value;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($attributes['value']) < 1)
+ $attributes['value'] = $options['default'];
+ $attributes['value'] = apply_filters('pods_form_ui_field_' . $type . '_value', $attributes['value'], $name, $attributes, $options);
+?>
+ <input<?php self::attributes($attributes); ?> />
+<?php
+ }
+
+ /**
+ * Output field type 'boolean'
+ *
+ * @since 2.0.0
+ */
+ protected function field_boolean ($name, $value = null, $options = null) {
+ $type = 'boolean';
+ $attributes = array();
+ $attributes['type'] = 'checkbox';
+ $attributes['id'] = 'pods_form_ui_' . $name;
+ $attributes['class'] = 'pods_form_ui_field_' . $type;
+ $attributes['value'] = 1;
+ $attributes['checked'] = (1 == $value || true === $value) ? 'CHECKED' : null;
+ if (isset($options['attributes']))
+ $attributes = array_merge($attributes, $options['attributes']);
+ if (isset($options['default']) && strlen($attributes['value']) < 1)
+ $attributes['value'] = $options['default'];
+ $attributes['value'] = apply_filters('pods_form_ui_field_' . $type . '_value', $attributes['value'], $name, $attributes, $options);
+?>
+ <input<?php self::attributes($attributes); ?> />
+<?php
+ }
+}
View
1,866 classes/PodsUI.php
@@ -0,0 +1,1866 @@
+<?php
+class PodsUI
+{
+ // internal
+ private $pods_data = null;
+ private $actions = array('manage',
+ 'add',
+ 'edit',
+ 'duplicate',
+ 'save',
+ 'view',
+ 'delete',
+ 'reorder',
+ 'export');
+ private $ui_page = array();
+ private $unique_identifier = null;
+
+ // base
+ public $pod;
+ public $id = 0;
+ public $num = ''; // allows multiple co-existing PodsUI instances with separate functionality in URL
+ static $excluded = array('do',
+ 'id',
+ 'pg',
+ 'search',
+ 'orderby',
+ 'orderby_dir',
+ 'limit',
+ 'action',
+ 'export',
+ 'export_type',
+ 'export_delimiter',
+ 'remove_export',
+ 'updated',
+ 'duplicate'); // used in var_update
+
+ // ui
+ public $item; // to be set with localized string
+ public $items; // to be set with localized string
+ public $heading; // to be set with localized string array
+ public $label; // to be set with localized string array
+ public $icon = false;
+ public $css = false; // set to a URL of stylesheet to include
+ public $wpcss = false; // set to true to include WP Admin stylesheets
+ public $fields = array('manage' => array(),
+ 'search' => array(),
+ 'form' => array(),
+ 'add' => array(),
+ 'edit' => array(),
+ 'duplicate' => array(),
+ 'view' => array(),
+ 'reorder' => array(),
+ 'export' => array());
+ public $searchable = true;
+ public $sortable = true;
+ public $pagination = true;
+ public $export = array('on' => false,
+ 'formats' => array('csv' => ',',
+ 'tsv' => "\t",
+ 'xml' => false,
+ 'json' => false),
+ 'url' => false,
+ 'type' => false);
+ public $reorder = array('on' => false,
+ 'limit' => 250,
+ 'orderby' => false,
+ 'orderby_dir' => 'ASC',
+ 'sql' => null);
+ public $screen_options = array(); // set to 'page' => 'Text'; false hides link
+ public $help = array(); // set to 'page' => 'Text'; 'page' => array('link' => 'yourhelplink'); false hides link
+
+ // data
+ public $search = false;
+ public $filters = array();
+ public $search_across = true;
+ public $search_across_picks = false;
+ public $where = array('manage' => null,
+ 'edit' => null,
+ 'duplicate' => null,
+ 'delete' => null,
+ 'reorder' => null);
+ public $orderby = false;
+ public $orderby_dir = 'DESC';
+ public $limit = 25;
+ public $page = 1;
+ public $total = 0;
+ public $session = array('search',
+ 'filters'); // allowed: search, filters, show_per_page, orderby (priority over usermeta)
+ public $usermeta = array('show_per_page',
+ 'orderby'); // allowed: search, filters, show_per_page, orderby (priority under session)
+
+ // advanced data
+ public $sql = array('table' => null,
+ 'identifier' => 'id',
+ 'index' => 'name',
+ 'select' => null,
+ 'sql' => null);
+
+ // actions
+ public $action = 'manage';
+ public $action_after = array('add' => 'edit',
+ 'edit' => 'edit',
+ 'duplicate' => 'edit'); // set action to 'manage'
+ public $do = false;
+ public $action_links = array('add' => null,
+ 'edit' => null,
+ 'duplicate' => null,
+ 'view' => null,
+ 'delete' => null,
+ 'reorder' => null,
+ 'export' => null); // custom links (callable allowed)
+ public $actions_disabled = array('view',
+ 'reorder',
+ 'export'); // disable actions
+ public $actions_hidden = array(); // hide actions to not show them but allow them
+ public $actions_custom = array(); // overwrite existing actions or add your own
+
+ /**
+ * Generate UI for Data Management
+ *
+ * @param mixed $options Object, Array, or String containing Pod or Options to be used
+ * @param bool $deprecated Set to true to support old options array from Pods UI plugin
+ *
+ * @license http://www.gnu.org/licenses/gpl-2.0.html
+ * @since 2.0.0
+ */
+ public function __construct ($options, $deprecated = false) {
+ $object = null;
+ if (is_object($options)) {
+ $object = $options;
+ $options = array();
+ if (isset($object->ui)) {
+ $options = $object->ui;
+ unset($object->ui);
+ }
+ if (isset($object->pod))
+ $this->pod = &$object;
+ }
+ if (!is_array($options)) {
+ parse_str($options, $options);
+ // need to come back to this and allow for multi-dimensional strings
+ // like: option=value&option2=value2&option3=key[val],key2[val2]&option4=this,that,another
+ }
+ if (!is_object($object) && isset($options['pod'])) {
+ if (isset($options['id']))
+ $object = pods($options['pod'], $options['id']);
+ else
+ $object = pods($options['pod']);
+ $this->pod = &$object;
+ unset($options['pod']);
+ }
+ if (false !== $deprecated)
+ $options = $this->setup_deprecated($options);
+ $options = $this->do_hook('pre_init', $options);
+ $this->setup($options);
+ if ((!is_object($this->pod) || !isset($this->pod->pod)) && false === $this->table) {
+ echo $this->error(__('<strong>Error:</strong> Pods UI needs a Pods object or a Table definition to run from, see the User Guide for more information.', 'pods'));
+ return false;
+ }
+ $this->pods_data = pods_data();
+ }
+
+ public function setup_deprecated ($deprecated_options) {
+ $options = array();
+ if (isset($deprecated_options['id']))
+ $options['id'] = $deprecated_options['id'];
+ if (isset($deprecated_options['action']))
+ $options['action'] = $deprecated_options['action'];
+ if (isset($deprecated_options['num']))
+ $options['num'] = $deprecated_options['num'];
+
+ if (isset($deprecated_options['title']))
+ $options['items'] = $deprecated_options['title'];
+ if (isset($deprecated_options['item']))
+ $options['item'] = $deprecated_options['item'];
+
+ if (isset($deprecated_options['label']))
+ $options['label'] = array('add' => $deprecated_options['label'],
+ 'edit' => $deprecated_options['label'],
+ 'duplicate' => $deprecated_options['label']);
+ if (isset($deprecated_options['label_add'])) {
+ if (isset($options['label']))
+ $options['label']['add'] = $deprecated_options['label_add'];
+ else
+ $options['label'] = array('add' => $deprecated_options['label_add']);
+ }
+ if (isset($deprecated_options['label_edit'])) {
+ if (isset($options['label']))
+ $options['label']['edit'] = $deprecated_options['label_edit'];
+ else
+ $options['label'] = array('edit' => $deprecated_options['label_edit']);
+ }
+ if (isset($deprecated_options['label_duplicate'])) {
+ if (isset($options['label']))
+ $options['label']['duplicate'] = $deprecated_options['label_duplicate'];
+ else
+ $options['label'] = array('duplicate' => $deprecated_options['label_duplicate']);
+ }
+
+ if (isset($deprecated_options['icon']))
+ $options['icon'] = $deprecated_options['icon'];
+
+ if (isset($deprecated_options['columns']))
+ $options['fields'] = array('manage' => $deprecated_options['columns']);
+ if (isset($deprecated_options['reorder_columns'])) {
+ if (isset($options['fields']))
+ $options['fields']['reorder'] = $deprecated_options['reorder_columns'];
+ else
+ $options['fields'] = array('reorder' => $deprecated_options['reorder_columns']);
+ }
+ if (isset($deprecated_options['add_fields'])) {
+ if (isset($options['fields'])) {
+ if (!isset($options['fields']['add']))
+ $options['fields']['add'] = $deprecated_options['add_fields'];
+ if (!isset($options['fields']['edit']))
+ $options['fields']['edit'] = $deprecated_options['add_fields'];
+ if (!isset($options['fields']['duplicate']))
+ $options['fields']['duplicate'] = $deprecated_options['add_fields'];
+ }
+ else
+ $options['fields'] = array('add' => $deprecated_options['add_fields'],
+ 'edit' => $deprecated_options['add_fields'],
+ 'duplicate' => $deprecated_options['add_fields']);
+ }
+ if (isset($deprecated_options['edit_fields'])) {
+ if (isset($options['fields'])) {
+ if (!isset($options['fields']['add']))
+ $options['fields']['add'] = $deprecated_options['edit_fields'];
+ if (!isset($options['fields']['edit']))
+ $options['fields']['edit'] = $deprecated_options['edit_fields'];
+ if (!isset($options['fields']['duplicate']))
+ $options['fields']['duplicate'] = $deprecated_options['edit_fields'];
+ }
+ else
+ $options['fields'] = array('add' => $deprecated_options['edit_fields'],
+ 'edit' => $deprecated_options['edit_fields'],
+ 'duplicate' => $deprecated_options['edit_fields']);
+ }
+ if (isset($deprecated_options['duplicate_fields'])) {
+ if (isset($options['fields']))
+ $options['fields']['duplicate'] = $deprecated_options['duplicate_fields'];
+ else
+ $options['fields'] = array('duplicate' => $deprecated_options['duplicate_fields']);
+ }
+
+ if (isset($deprecated_options['session_filters']) && false === $deprecated_options['session_filters'])
+ $options['session'] = false;
+ if (isset($deprecated_options['user_per_page'])) {
+ if (isset($options['usermeta']) && !empty($options['usermeta']))
+ $options['usermeta'] = array('orderby');
+ else
+ $options['usermeta'] = false;
+ }
+ if (isset($deprecated_options['user_sort'])) {
+ if (isset($options['usermeta']) && !empty($options['usermeta']))
+ $options['usermeta'] = array('show_per_page');
+ else
+ $options['usermeta'] = false;
+ }
+
+ if (isset($deprecated_options['custom_list'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['manage'] = $deprecated_options['custom_list'];
+ else
+ $options['actions_custom'] = array('manage' => $deprecated_options['custom_list']);
+ }
+ if (isset($deprecated_options['custom_reorder'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['reorder'] = $deprecated_options['custom_reorder'];
+ else
+ $options['actions_custom'] = array('reorder' => $deprecated_options['custom_reorder']);
+ }
+ if (isset($deprecated_options['custom_add'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['add'] = $deprecated_options['custom_add'];
+ else
+ $options['actions_custom'] = array('add' => $deprecated_options['custom_add']);
+ }
+ if (isset($deprecated_options['custom_edit'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['edit'] = $deprecated_options['custom_edit'];
+ else
+ $options['actions_custom'] = array('edit' => $deprecated_options['custom_edit']);
+ }
+ if (isset($deprecated_options['custom_duplicate'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['duplicate'] = $deprecated_options['custom_duplicate'];
+ else
+ $options['actions_custom'] = array('duplicate' => $deprecated_options['custom_duplicate']);
+ }
+ if (isset($deprecated_options['custom_delete'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['delete'] = $deprecated_options['custom_delete'];
+ else
+ $options['actions_custom'] = array('delete' => $deprecated_options['custom_delete']);
+ }
+ if (isset($deprecated_options['custom_save'])) {
+ if (isset($options['actions_custom']))
+ $options['actions_custom']['save'] = $deprecated_options['custom_save'];
+ else
+ $options['actions_custom'] = array('save' => $deprecated_options['custom_save']);
+ }
+
+ if (isset($deprecated_options['custom_actions']))
+ $options['actions_custom'] = $deprecated_options['custom_actions'];
+ if (isset($deprecated_options['action_after_save']))
+ $options['action_after'] = array('add' => $deprecated_options['action_after_save'],
+ 'edit' => $deprecated_options['action_after_save'],
+ 'duplicate' => $deprecated_options['action_after_save']);
+ if (isset($deprecated_options['edit_link'])) {
+ if (isset($options['action_links']))
+ $options['action_links']['edit'] = $deprecated_options['edit_link'];
+ else
+ $options['action_links'] = array('edit' => $deprecated_options['edit_link']);
+ }
+ if (isset($deprecated_options['view_link'])) {
+ if (isset($options['action_links']))
+ $options['action_links']['view'] = $deprecated_options['view_link'];
+ else
+ $options['action_links'] = array('view' => $deprecated_options['view_link']);
+ }
+ if (isset($deprecated_options['duplicate_link'])) {
+ if (isset($options['action_links']))
+ $options['action_links']['duplicate'] = $deprecated_options['duplicate_link'];
+ else
+ $options['action_links'] = array('duplicate' => $deprecated_options['duplicate_link']);
+ }
+
+ if (isset($deprecated_options['reorder']))
+ $options['reorder'] = array('on' => $deprecated_options['reorder'],
+ 'orderby' => $deprecated_options['reorder']);
+ if (isset($deprecated_options['reorder_sort']) && isset($options['reorder']))
+ $options['reorder']['orderby'] = $deprecated_options['reorder_sort'];
+ if (isset($deprecated_options['reorder_limit']) && isset($options['reorder']))
+ $options['reorder']['limit'] = $deprecated_options['reorder_limit'];
+ if (isset($deprecated_options['reorder_sql']) && isset($options['reorder']))
+ $options['reorder']['sql'] = $deprecated_options['reorder_sql'];
+
+ if (isset($deprecated_options['sort']))
+ $options['orderby'] = $deprecated_options['sort'];
+ if (isset($deprecated_options['sortable']))
+ $options['sortable'] = $deprecated_options['sortable'];
+ if (isset($deprecated_options['limit']))
+ $options['limit'] = $deprecated_options['limit'];
+
+ if (isset($deprecated_options['where'])) {
+ if (isset($options['where']))
+ $options['where']['manage'] = $deprecated_options['where'];
+ else
+ $options['where'] = array('manage' => $deprecated_options['where']);
+ }
+ if (isset($deprecated_options['edit_where'])) {
+ if (isset($options['where']))
+ $options['where']['edit'] = $deprecated_options['edit_where'];
+ else
+ $options['where'] = array('edit' => $deprecated_options['edit_where']);
+ }
+ if (isset($deprecated_options['duplicate_where'])) {
+ if (isset($options['where']))
+ $options['where']['duplicate'] = $deprecated_options['duplicate_where'];
+ else
+ $options['where'] = array('duplicate' => $deprecated_options['duplicate_where']);
+ }
+ if (isset($deprecated_options['delete_where'])) {
+ if (isset($options['where']))
+ $options['where']['delete'] = $deprecated_options['delete_where'];
+ else
+ $options['where'] = array('delete' => $deprecated_options['delete_where']);
+ }
+ if (isset($deprecated_options['reorder_where'])) {
+ if (isset($options['where']))
+ $options['where']['reorder'] = $deprecated_options['reorder_where'];
+ else
+ $options['where'] = array('reorder' => $deprecated_options['reorder_where']);
+ }
+
+ if (isset($deprecated_options['sql']))
+ $options['sql'] = array('sql' => $deprecated_options['sql']);
+
+ if (isset($deprecated_options['search']))
+ $options['searchable'] = $deprecated_options['search'];
+ if (isset($deprecated_options['search_across']))
+ $options['search_across'] = $deprecated_options['search_across'];
+ if (isset($deprecated_options['search_across_picks']))
+ $options['search_across_picks'] = $deprecated_options['search_across_picks'];
+ if (isset($deprecated_options['filters']))
+ $options['filters'] = $deprecated_options['filters'];
+ if (isset($deprecated_options['custom_filters'])) {
+ if (is_callable($deprecated_options['custom_filters']))
+ add_filter('pods_ui_filters', $deprecated_options['custom_filters']);
+ else {
+ global $pods_ui_custom_filters;
+ $pods_ui_custom_filters = $deprecated_options['custom_filters'];
+ add_filter('pods_ui_filters', function () { global $pods_ui_custom_filters; echo $pods_ui_custom_filters; });
+ }
+ }
+
+ if (isset($deprecated_options['disable_actions']))
+ $options['actions_disabled'] = $deprecated_options['disable_actions'];
+ if (isset($deprecated_options['hide_actions']))
+ $options['actions_hidden'] = $deprecated_options['hide_actions'];
+
+ if (isset($deprecated_options['wpcss']))
+ $options['wpcss'] = $deprecated_options['wpcss'];
+
+ return $options;
+ }
+
+ public function setup ($options) {
+ $options = pods_array($options);
+ $options->validate('num', '', 'absint');
+ $options->validate('id