/** * Get list of components available * * @since 2.0 */ public function get_components() { $components = pods_transient_get('pods_components'); if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) { $components = array(); } if (PodsInit::$version != PODS_VERSION || !is_array($components) || empty($components) || is_admin() && isset($_GET['page']) && 'pods-components' == $_GET['page'] && 1 !== pods_transient_get('pods_components_refresh')) { do_action('pods_components_get'); $component_dir = @opendir(untrailingslashit($this->components_dir)); $component_files = array(); if (false !== $component_dir) { while (false !== ($file = readdir($component_dir))) { if ('.' == substr($file, 0, 1)) { continue; } elseif (is_dir($this->components_dir . $file)) { $component_subdir = @opendir($this->components_dir . $file); if ($component_subdir) { while (false !== ($subfile = readdir($component_subdir))) { if ('.' == substr($subfile, 0, 1)) { continue; } elseif ('.php' == substr($subfile, -4)) { $component_files[] = str_replace('\\', '/', $file . '/' . $subfile); } } closedir($component_subdir); } } elseif ('.php' == substr($file, -4)) { $component_files[] = $file; } } closedir($component_dir); } $default_headers = array('ID' => 'ID', 'Name' => 'Name', 'ShortName' => 'Short Name', 'PluginName' => 'Plugin Name', 'ComponentName' => 'Component Name', 'URI' => 'URI', 'MenuName' => 'Menu Name', 'MenuPage' => 'Menu Page', 'MenuAddPage' => 'Menu Add Page', 'MustUse' => 'Must Use', 'Description' => 'Description', 'Version' => 'Version', 'Category' => 'Category', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Class' => 'Class', 'Hide' => 'Hide', 'PluginDependency' => 'Plugin Dependency', 'ThemeDependency' => 'Theme Dependency', 'DeveloperMode' => 'Developer Mode', 'TablelessMode' => 'Tableless Mode', 'Capability' => 'Capability', 'Plugin' => 'Plugin'); $component_files = apply_filters('pods_components_register', $component_files); $components = array(); foreach ($component_files as $component_file) { $external = false; if (is_array($component_file) && isset($component_file['File'])) { $component = $component_file = $component_file['File']; $external = true; } else { $component = $this->components_dir . $component_file; } if (!is_readable($component)) { continue; } $component_data = get_file_data($component, $default_headers, 'pods_component'); if (empty($component_data['Name']) && empty($component_data['ComponentName']) && empty($component_data['PluginName']) || 'yes' == $component_data['Hide']) { continue; } if (isset($component_data['Plugin']) && pods_is_plugin_active($component_data['Plugin'])) { continue; } if (empty($component_data['Name'])) { if (!empty($component_data['ComponentName'])) { $component_data['Name'] = $component_data['ComponentName']; } elseif (!empty($component_data['PluginName'])) { $component_data['Name'] = $component_data['PluginName']; } } if (empty($component_data['ShortName'])) { $component_data['ShortName'] = $component_data['Name']; } if (empty($component_data['MenuName'])) { $component_data['MenuName'] = $component_data['Name']; } if (empty($component_data['Class'])) { $component_data['Class'] = 'Pods_' . pods_clean_name(basename($component, '.php'), false); } if (empty($component_data['ID'])) { $component_data['ID'] = $component_data['Name']; } $component_data['ID'] = sanitize_title($component_data['ID']); if ('on' == strtolower($component_data['DeveloperMode']) || 1 == $component_data['DeveloperMode']) { $component_data['DeveloperMode'] = true; } else { $component_data['DeveloperMode'] = false; } if ('on' == strtolower($component_data['TablelessMode']) || 1 == $component_data['TablelessMode']) { $component_data['TablelessMode'] = true; } else { $component_data['TablelessMode'] = false; } $component_data['External'] = (bool) $external; if ('on' == strtolower($component_data['MustUse']) || '1' == $component_data['MustUse']) { $component_data['MustUse'] = true; } elseif ('off' == strtolower($component_data['MustUse']) || '0' == $component_data['MustUse']) { $component_data['MustUse'] = false; } else { $component_data['MustUse'] = $component_data['External']; } $component_data['File'] = $component_file; $components[$component_data['ID']] = $component_data; } ksort($components); pods_transient_set('pods_components_refresh', 1, 60 * 60 * 12); pods_transient_set('pods_components', $components); } if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($components); } $this->components = $components; return $this->components; }
/** * Get find() params based on current UI action * * @param null|array $params * @param null|string $action */ public function get_params($params = null, $action = null) { if (null === $action) { $action = $this->action; } $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => ''); if (!empty($params) && is_array($params)) { $params = (object) array_merge($defaults, $params); } else { $params = (object) $defaults; } if (!in_array($action, array('manage', 'reorder'))) { $action = 'manage'; } $params_override = false; $orderby = array(); $limit = $this->limit; $sql = null; if ('reorder' == $this->action) { if (!empty($this->reorder['orderby'])) { $orderby[$this->reorder['orderby']] = $this->reorder['orderby_dir']; } else { $orderby[$this->reorder['on']] = $this->reorder['orderby_dir']; } if (!empty($this->reorder['limit'])) { $limit = $this->reorder['limit']; } if (!empty($this->reorder['sql'])) { $sql = $this->reorder['sql']; } } if (!empty($this->orderby)) { $this->orderby = (array) $this->orderby; foreach ($this->orderby as $order) { if (false !== strpos($order, ' ')) { $orderby[] = $order; } elseif (!isset($orderby[$order])) { $orderby[$order] = $this->orderby_dir; } } } if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) { $find_params = array('where' => pods_v($action, $this->where, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'search_across' => $this->search_across, 'search_across_picks' => $this->search_across_picks, 'filters' => $this->filters, 'sql' => $sql); $params_override = true; } else { $find_params = array('table' => $this->sql['table'], 'id' => $this->sql['field_id'], 'index' => $this->sql['field_index'], 'where' => pods_v($action, $this->where, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'fields' => $this->fields['search'], 'sql' => $sql); if (!empty($this->sql['select'])) { $find_params['select'] = $this->sql['select']; } } if (empty($find_params['where']) && $this->restricted($this->action)) { $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null); } if ($params_override) { $find_params = array_merge($find_params, (array) $this->params); } if ($params->full) { $find_params['limit'] = -1; } // Debug purposes if (1 == pods_v('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($find_params); } return $find_params; }
/** * @param bool $full Whether to get ALL data or use pagination * * @return bool */ public function get_data($params = null) { $action = $this->action; $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => ''); if (!empty($params) && is_array($params)) { $params = (object) array_merge($defaults, $params); } else { $params = (object) $defaults; } if (!in_array($action, array('manage', 'reorder'))) { $action = 'manage'; } if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) { $orderby = array(); $limit = $this->limit; $sql = null; if ('reorder' == $this->action) { if (!empty($this->reorder['orderby'])) { $orderby[$this->reorder['orderby']] = $this->reorder['orderby_dir']; } else { $orderby[$this->reorder['on']] = $this->reorder['orderby_dir']; } if (!empty($this->reorder['limit'])) { $limit = $this->reorder['limit']; } if (!empty($this->reorder['sql'])) { $sql = $this->reorder['sql']; } } if (!empty($this->orderby)) { $this->orderby = (array) $this->orderby; foreach ($this->orderby as $order) { if (false === strpos(' ', $order) && !isset($orderby[$order])) { $orderby[$order] = $this->orderby_dir; } } } $find_params = array('where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'search_across' => $this->search_across, 'search_across_picks' => $this->search_across_picks, 'filters' => $this->filters, 'sql' => $sql); if (empty($find_params['where']) && $this->restricted($this->action)) { $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null); } if ($params->full) { $find_params['limit'] = -1; } $find_params = array_merge($find_params, (array) $this->params); // Debug purposes if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($find_params); } $this->pod->find($find_params); if (!$params->full) { $data = $this->pod->data(); $this->data = $data; if (!empty($this->data)) { $this->data_keys = array_keys($this->data); } $this->total = $this->pod->total(); $this->total_found = $this->pod->total_found(); } else { $this->data_full = array(); $export_params = array('fields' => $params->fields, 'flatten' => true); if (in_array($params->type, array('json', 'xml'))) { $export_params['flatten'] = false; } $export_params = $this->do_hook('export_options', $export_params, $params); while ($this->pod->fetch()) { $this->data_full[$this->pod->id()] = $this->pod->export($export_params); } $this->pod->reset(); return $this->data_full; } } else { if (!empty($this->data)) { return $this->data; } if (empty($this->sql['table'])) { return $this->data; } $orderby = ''; if (!empty($this->orderby)) { $orderby = '`' . $this->orderby . '` ' . (false === strpos($this->orderby, ' ') ? strtoupper($this->orderby_dir) : ''); } $find_params = array('table' => $this->sql['table'], 'where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $this->limit, 'search' => $this->searchable, 'search_query' => $this->search, 'fields' => $this->fields['search']); if (empty($find_params['where']) && $this->restricted($this->action)) { $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null); } if ($params->full) { $find_params['limit'] = -1; } // Debug purposes if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($find_params); } $this->pods_data->select($find_params); if (!$params->full) { $this->data = $this->pods_data->data; if (!empty($this->data)) { $this->data_keys = array_keys($this->data); } $this->total = $this->pods_data->total(); $this->total_found = $this->pods_data->total_found(); } else { $this->data_full = $this->pods_data->data; return $this->data_full; } } return $this->data; }
/** * Build/Rewrite dynamic SQL and handle search/filter/sort * * @param array $params * * @return bool|mixed|string * @since 2.0 */ public function build($params) { $simple_tableless_objects = PodsForm::field_method('pick', 'simple_objects'); $defaults = array('select' => '*', 'calc_rows' => false, 'distinct' => true, 'table' => null, 'join' => null, 'where' => null, 'groupby' => null, 'having' => null, 'orderby' => null, 'limit' => -1, 'offset' => null, 'id' => null, 'index' => null, 'page' => 1, 'pagination' => $this->pagination, 'search' => $this->search, 'search_query' => null, 'search_mode' => null, 'search_across' => false, 'search_across_picks' => false, 'search_across_files' => false, 'filters' => array(), 'fields' => array(), 'object_fields' => array(), 'pod_table_prefix' => null, 'traverse' => array(), 'sql' => null, 'strict' => false); $params = (object) array_merge($defaults, (array) $params); if (0 < strlen($params->sql)) { return $params->sql; } $pod = false; if (is_array($this->pod_data)) { $pod = $this->pod_data; } // Validate $params->page = pods_absint($params->page); $params->pagination = (bool) $params->pagination; if (0 == $params->page || !$params->pagination) { $params->page = 1; } $params->limit = (int) $params->limit; if (0 == $params->limit) { $params->limit = -1; } $this->limit = $params->limit; $offset = $params->limit * ($params->page - 1); if (0 < (int) $params->offset) { $params->offset += $offset; } else { $params->offset = $offset; } if (!$params->pagination || -1 == $params->limit) { $params->page = 1; $params->offset = 0; } if ((empty($params->fields) || !is_array($params->fields)) && !empty($pod) && isset($this->fields) && !empty($this->fields)) { $params->fields = $this->fields; } if ((empty($params->object_fields) || !is_array($params->object_fields)) && !empty($pod) && isset($pod['object_fields']) && !empty($pod['object_fields'])) { $params->object_fields = $pod['object_fields']; } if (empty($params->filters) && $params->search) { $params->filters = array_keys($params->fields); } elseif (empty($params->filters)) { $params->filters = array(); } if (empty($params->index)) { $params->index = $this->field_index; } if (empty($params->id)) { $params->id = $this->field_id; } if (empty($params->table) && !empty($pod) && isset($this->table) && !empty($this->table)) { $params->table = $this->table; } if (empty($params->pod_table_prefix)) { $params->pod_table_prefix = 't'; } if (!empty($pod) && !in_array($pod['type'], array('pod', 'table')) && 'table' == $pod['storage']) { $params->pod_table_prefix = 'd'; } $params->meta_fields = false; if (!empty($pod) && !in_array($pod['type'], array('pod', 'table', 'taxonomy')) && 'meta' == $pod['storage']) { $params->meta_fields = true; } if (empty($params->table)) { return false; } if (false === strpos($params->table, '(') && false === strpos($params->table, '`')) { $params->table = '`' . $params->table . '`'; } if (!empty($params->join)) { $params->join = array_merge((array) $this->join, (array) $params->join); } elseif (false === $params->strict) { $params->join = $this->join; } $params->where_defaulted = false; $params->where_default = $this->where_default; if (false === $params->strict) { // Set default where if (!empty($this->where_default) && empty($params->where)) { $params->where = array_values((array) $this->where_default); $params->where_defaulted = true; } if (!empty($this->where)) { if (is_array($params->where) && isset($params->where['relation']) && 'OR' == strtoupper($params->where['relation'])) { $params->where = array_merge(array($params->where), array_values((array) $this->where)); } else { $params->where = array_merge((array) $params->where, array_values((array) $this->where)); } } } // Allow where array ( 'field' => 'value' ) and WP_Query meta_query syntax $params->where = $this->query_fields((array) $params->where, $pod, $params); if (empty($params->where)) { $params->where = array(); } else { $params->where = (array) $params->where; } // Allow having array ( 'field' => 'value' ) and WP_Query meta_query syntax $params->having = $this->query_fields((array) $params->having, $pod); if (empty($params->having)) { $params->having = array(); } else { $params->having = (array) $params->having; } if (!empty($params->orderby)) { $params->orderby = (array) $params->orderby; } else { $params->orderby = array(); } if (false === $params->strict && !empty($this->orderby)) { $params->orderby = array_merge($params->orderby, (array) $this->orderby); } if (!empty($params->traverse)) { $this->traverse = $params->traverse; } $allowed_search_modes = array('int', 'text', 'text_like'); if (!empty($params->search_mode) && in_array($params->search_mode, $allowed_search_modes)) { $this->search_mode = $params->search_mode; } $params->search = (bool) $params->search; if (1 == pods_var('pods_debug_params_all', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($params); } $params->field_table_alias = 't'; // Get Aliases for future reference $selectsfound = ''; if (!empty($params->select)) { if (is_array($params->select)) { $selectsfound = implode(', ', $params->select); } else { $selectsfound = $params->select; } } // Pull Aliases from SQL query too if (null !== $params->sql) { $temp_sql = ' ' . trim(str_replace(array("\n", "\r"), ' ', $params->sql)); $temp_sql = preg_replace(array('/\\sSELECT\\sSQL_CALC_FOUND_ROWS\\s/i', '/\\sSELECT\\s/i'), array(' SELECT ', ' SELECT SQL_CALC_FOUND_ROWS '), $temp_sql); preg_match('/\\sSELECT SQL_CALC_FOUND_ROWS\\s(.*)\\sFROM/i', $temp_sql, $selectmatches); if (isset($selectmatches[1]) && !empty($selectmatches[1]) && false !== stripos($selectmatches[1], ' AS ')) { $selectsfound .= (!empty($selectsfound) ? ', ' : '') . $selectmatches[1]; } } // Build Alias list $this->aliases = array(); if (!empty($selectsfound) && false !== stripos($selectsfound, ' AS ')) { $theselects = array_filter(explode(', ', $selectsfound)); if (empty($theselects)) { $theselects = array_filter(explode(',', $selectsfound)); } foreach ($theselects as $selected) { $selected = trim($selected); if (strlen($selected) < 1) { continue; } $selectfield = explode(' AS ', str_replace(' as ', ' AS ', $selected)); if (2 == count($selectfield)) { $field = trim(trim($selectfield[1]), '`'); $real_field = trim(trim($selectfield[0]), '`'); $this->aliases[$field] = $real_field; } } } // Search if (!empty($params->search) && !empty($params->fields)) { if (false !== $params->search_query && 0 < strlen($params->search_query)) { $where = $having = array(); if (false !== $params->search_across) { foreach ($params->fields as $key => $field) { if (is_array($field)) { $attributes = $field; $field = pods_var('name', $field, $key, null, true); } else { $attributes = array('type' => '', 'options' => array()); } if (isset($attributes['options']['search']) && !$attributes['options']['search']) { continue; } if (in_array($attributes['type'], array('date', 'time', 'datetime', 'number', 'decimal', 'currency', 'phone', 'password', 'boolean'))) { continue; } $fieldfield = '`' . $field . '`'; if ('pick' == $attributes['type'] && !in_array(pods_var('pick_object', $attributes), $simple_tableless_objects)) { if (false === $params->search_across_picks) { continue; } else { if (!isset($attributes['table_info']) || empty($attributes['table_info'])) { $attributes['table_info'] = $this->api->get_table_info(pods_var('pick_object', $attributes), pods_var('pick_val', $attributes)); } if (empty($attributes['table_info']['field_index'])) { continue; } $fieldfield = $fieldfield . '.`' . $attributes['table_info']['field_index'] . '`'; } } elseif (in_array($attributes['type'], PodsForm::file_field_types())) { if (false === $params->search_across_files) { continue; } else { $fieldfield = $fieldfield . '.`post_title`'; } } elseif (isset($params->fields[$field])) { if ($params->meta_fields) { $fieldfield = $fieldfield . '.`' . $params->pod_table_prefix . '`'; } else { $fieldfield = '`' . $params->pod_table_prefix . '`.' . $fieldfield; } } elseif (!empty($params->object_fields) && !isset($params->object_fields[$field])) { $fieldfield = $fieldfield . '.`meta_value`'; } else { $fieldfield = '`t`.' . $fieldfield; } if (isset($this->aliases[$field])) { $fieldfield = '`' . $this->aliases[$field] . '`'; } if (isset($attributes['real_name']) && !empty($attributes['real_name'])) { $fieldfield = $attributes['real_name']; } if (isset($attributes['group_related']) && false !== $attributes['group_related']) { $having[] = "{$fieldfield} LIKE '%" . pods_sanitize_like($params->search_query) . "%'"; } else { $where[] = "{$fieldfield} LIKE '%" . pods_sanitize_like($params->search_query) . "%'"; } } } elseif (!empty($params->index)) { $attributes = array(); $fieldfield = '`t`.`' . $params->index . '`'; if (isset($params->fields[$params->index])) { if ($params->meta_fields) { $fieldfield = '`' . $params->index . '`.`' . $params->pod_table_prefix . '`'; } else { $fieldfield = '`' . $params->pod_table_prefix . '`.`' . $params->index . '`'; } } elseif (!empty($params->object_fields) && !isset($params->object_fields[$params->index])) { $fieldfield = '`' . $params->index . '`.`meta_value`'; } if (isset($attributes['real_name']) && false !== $attributes['real_name'] && !empty($attributes['real_name'])) { $fieldfield = $attributes['real_name']; } if (isset($attributes['group_related']) && false !== $attributes['group_related']) { $having[] = "{$fieldfield} LIKE '%" . pods_sanitize_like($params->search_query) . "%'"; } else { $where[] = "{$fieldfield} LIKE '%" . pods_sanitize_like($params->search_query) . "%'"; } } if (!empty($where)) { $params->where[] = implode(' OR ', $where); } if (!empty($having)) { $params->having[] = implode(' OR ', $where); } } // Filter foreach ($params->filters as $filter) { $where = $having = array(); if (!isset($params->fields[$filter])) { continue; } $attributes = $params->fields[$filter]; $field = pods_var('name', $attributes, $filter, null, true); $filterfield = '`' . $field . '`'; if ('pick' == $attributes['type'] && !in_array(pods_var('pick_object', $attributes), $simple_tableless_objects)) { if (!isset($attributes['table_info']) || empty($attributes['table_info'])) { $attributes['table_info'] = $this->api->get_table_info(pods_var('pick_object', $attributes), pods_var('pick_val', $attributes)); } if (empty($attributes['table_info']['field_index'])) { continue; } $filterfield = $filterfield . '.`' . $attributes['table_info']['field_index'] . '`'; } elseif (in_array($attributes['type'], PodsForm::file_field_types())) { $filterfield = $filterfield . '.`post_title`'; } elseif (isset($params->fields[$field])) { if ($params->meta_fields) { $filterfield = $filterfield . '.`meta_value`'; } else { $filterfield = '`' . $params->pod_table_prefix . '`.' . $filterfield; } } elseif (!empty($params->object_fields) && !isset($params->object_fields[$field])) { $filterfield = $filterfield . '.`meta_value`'; } else { $filterfield = '`t`.' . $filterfield; } if (isset($this->aliases[$field])) { $filterfield = '`' . $this->aliases[$field] . '`'; } if (isset($attributes['real_name']) && false !== $attributes['real_name'] && !empty($attributes['real_name'])) { $filterfield = $attributes['real_name']; } if ('pick' == $attributes['type']) { $filter_value = pods_var_raw('filter_' . $field, 'get'); if (!is_array($filter_value)) { $filter_value = (array) $filter_value; } foreach ($filter_value as $filter_v) { if (in_array(pods_var('pick_object', $attributes), $simple_tableless_objects)) { if (strlen($filter_v) < 1) { continue; } if (isset($attributes['group_related']) && false !== $attributes['group_related']) { $having[] = "( {$filterfield} = '" . pods_sanitize($filter_v) . "'" . " OR {$filterfield} LIKE '%\"" . pods_sanitize_like($filter_v) . "\"%' )"; } else { $where[] = "( {$filterfield} = '" . pods_sanitize($filter_v) . "'" . " OR {$filterfield} LIKE '%\"" . pods_sanitize_like($filter_v) . "\"%' )"; } } else { $filter_v = (int) $filter_v; if (empty($filter_v) || empty($attributes['table_info']) || empty($attributes['table_info']['field_id'])) { continue; } $filterfield = '`' . $field . '`.`' . $attributes['table_info']['field_id'] . '`'; if (isset($attributes['group_related']) && false !== $attributes['group_related']) { $having[] = "{$filterfield} = " . $filter_v; } else { $where[] = "{$filterfield} = " . $filter_v; } } } } elseif (in_array($attributes['type'], array('date', 'datetime'))) { $start = date_i18n('Y-m-d') . ('datetime' == $attributes['type']) ? ' 00:00:00' : ''; $end = date_i18n('Y-m-d') . ('datetime' == $attributes['type']) ? ' 23:59:59' : ''; $start_value = pods_var('filter_' . $field . '_start', 'get', false); $end_value = pods_var('filter_' . $field . '_end', 'get', false); if (empty($start_value) && empty($end_value)) { continue; } if (!empty($start_value)) { $start = date_i18n('Y-m-d', strtotime($start_value)) . ('datetime' == $attributes['type'] ? ' 00:00:00' : ''); } if (!empty($end_value)) { $end = date_i18n('Y-m-d', strtotime($end_value)) . ('datetime' == $attributes['type'] ? ' 23:59:59' : ''); } if (isset($attributes['date_ongoing']) && true === $attributes['date_ongoing']) { $date_ongoing = '`' . $attributes['date_ongoing'] . '`'; if (isset($this->aliases[$date_ongoing])) { $date_ongoing = '`' . $this->aliases[$date_ongoing] . '`'; } if (isset($attributes['group_related']) && false !== $attributes['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 (isset($attributes['group_related']) && false !== $attributes['group_related']) { $having[] = "({$filterfield} BETWEEN '{$start}' AND '{$end}')"; } else { $where[] = "({$filterfield} BETWEEN '{$start}' AND '{$end}')"; } } } else { $filter_value = pods_var_raw('filter_' . $field, 'get', ''); if (strlen($filter_value) < 1) { continue; } if (isset($attributes['group_related']) && false !== $attributes['group_related']) { $having[] = "{$filterfield} LIKE '%" . pods_sanitize_like($filter_value) . "%'"; } else { $where[] = "{$filterfield} LIKE '%" . pods_sanitize_like($filter_value) . "%'"; } } if (!empty($where)) { $params->where[] = implode(' AND ', $where); } if (!empty($having)) { $params->having[] = implode(' AND ', $having); } } } // Traverse the Rabbit Hole if (!empty($this->pod)) { $haystack = implode(' ', (array) $params->select) . ' ' . implode(' ', (array) $params->where) . ' ' . implode(' ', (array) $params->groupby) . ' ' . implode(' ', (array) $params->having) . ' ' . implode(' ', (array) $params->orderby); $haystack = preg_replace('/\\s/', ' ', $haystack); $haystack = preg_replace('/\\w\\(/', ' ', $haystack); $haystack = str_replace(array('(', ')', ' ', '\\\'', "\\\""), ' ', $haystack); preg_match_all('/`?[\\w]+`?(?:\\.`?[\\w]+`?)+(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/', $haystack, $found, PREG_PATTERN_ORDER); $found = (array) @current($found); $find = $replace = $traverse = array(); foreach ($found as $key => $value) { $value = str_replace('`', '', $value); $value = explode('.', $value); $dot = $last_value = array_pop($value); if ('t' == $value[0] || in_array('/\\b' . trim($found[$key], '`') . '\\b(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/', $find)) { continue; } elseif (1 == count($value) && '' == preg_replace('/[0-9]*/', '', $value[0]) && '' == preg_replace('/[0-9]*/', '', $last_value)) { continue; } $find[$key] = '/\\b' . trim($found[$key], '`') . '\\b(?=[^"\']*(?:"[^"]*"[^"]*|\'[^\']*\'[^\']*)*$)/'; $esc_start = $esc_end = '`'; if (strlen(ltrim($found[$key], '`')) < strlen($found[$key])) { $esc_start = ''; } if (strlen(rtrim($found[$key], '`')) < strlen($found[$key])) { $esc_end = ''; } if ('*' != $dot) { $dot = '`' . $dot . $esc_end; } $replace[$key] = $esc_start . implode('_', $value) . '`.' . $dot; $value[] = $last_value; if (!in_array($value, $traverse)) { $traverse[$key] = $value; } } if (!empty($this->traverse)) { foreach ((array) $this->traverse as $key => $traverse) { $traverse = str_replace('`', '', $traverse); $already_found = false; foreach ($traverse as $traversal) { if (is_array($traversal)) { $traversal = implode('.', $traversal); } if ($traversal == $traverse) { $already_found = true; break; } } if (!$already_found) { $traverse['traverse_' . $key] = explode('.', $traverse); } } } $joins = array(); if (!empty($find)) { $params->select = preg_replace($find, $replace, $params->select); $params->where = preg_replace($find, $replace, $params->where); $params->groupby = preg_replace($find, $replace, $params->groupby); $params->having = preg_replace($find, $replace, $params->having); $params->orderby = preg_replace($find, $replace, $params->orderby); if (!empty($traverse)) { $joins = $this->traverse($traverse, $params->fields, $params); } elseif (false !== $params->search) { $joins = $this->traverse(null, $params->fields, $params); } } } // Traversal Search if (!empty($params->search) && !empty($this->search_where)) { $params->where = array_merge((array) $this->search_where, $params->where); } if (!empty($params->join) && !empty($joins)) { $params->join = array_merge($joins, (array) $params->join); } elseif (!empty($joins)) { $params->join = $joins; } // Build if (null === $params->sql) { $sql = "\n SELECT\n " . ($params->calc_rows ? 'SQL_CALC_FOUND_ROWS' : '') . "\n " . ($params->distinct ? 'DISTINCT' : '') . "\n " . (!empty($params->select) ? is_array($params->select) ? implode(', ', $params->select) : $params->select : '*') . "\n FROM {$params->table} AS `t`\n " . (!empty($params->join) ? is_array($params->join) ? implode("\n ", $params->join) : $params->join : '') . "\n " . (!empty($params->where) ? 'WHERE ' . (is_array($params->where) ? implode(' AND ', $params->where) : $params->where) : '') . "\n " . (!empty($params->groupby) ? 'GROUP BY ' . (is_array($params->groupby) ? implode(', ', $params->groupby) : $params->groupby) : '') . "\n " . (!empty($params->having) ? 'HAVING ' . (is_array($params->having) ? implode(' AND ', $params->having) : $params->having) : '') . "\n " . (!empty($params->orderby) ? 'ORDER BY ' . (is_array($params->orderby) ? implode(', ', $params->orderby) : $params->orderby) : '') . "\n " . (0 < $params->page && 0 < $params->limit ? 'LIMIT ' . $params->offset . ', ' . $params->limit : '') . "\n "; if (!$params->calc_rows) { $this->total_sql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\tCOUNT( " . ($params->distinct ? 'DISTINCT `t`.`' . $params->id . '`' : '*') . " )\n\t\t\t\t\tFROM {$params->table} AS `t`\n\t\t\t\t\t" . (!empty($params->join) ? is_array($params->join) ? implode("\n ", $params->join) : $params->join : '') . "\n\t\t\t\t\t" . (!empty($params->where) ? 'WHERE ' . (is_array($params->where) ? implode(' AND ', $params->where) : $params->where) : '') . "\n\t\t\t\t\t" . (!empty($params->groupby) ? 'GROUP BY ' . (is_array($params->groupby) ? implode(', ', $params->groupby) : $params->groupby) : '') . "\n\t\t\t\t\t" . (!empty($params->having) ? 'HAVING ' . (is_array($params->having) ? implode(' AND ', $params->having) : $params->having) : '') . "\n\t\t\t\t"; } } else { $sql = ' ' . trim(str_replace(array("\n", "\r"), ' ', $params->sql)); $sql = preg_replace(array('/\\sSELECT\\sSQL_CALC_FOUND_ROWS\\s/i', '/\\sSELECT\\s/i'), array(' SELECT ', ' SELECT SQL_CALC_FOUND_ROWS '), $sql); // Insert variables based on existing statements if (false === stripos($sql, '%%SELECT%%')) { $sql = preg_replace('/\\sSELECT\\sSQL_CALC_FOUND_ROWS\\s/i', ' SELECT SQL_CALC_FOUND_ROWS %%SELECT%% ', $sql); } if (false === stripos($sql, '%%WHERE%%')) { $sql = preg_replace('/\\sWHERE\\s(?!.*\\sWHERE\\s)/i', ' WHERE %%WHERE%% ', $sql); } if (false === stripos($sql, '%%GROUPBY%%')) { $sql = preg_replace('/\\sGROUP BY\\s(?!.*\\sGROUP BY\\s)/i', ' GROUP BY %%GROUPBY%% ', $sql); } if (false === stripos($sql, '%%HAVING%%')) { $sql = preg_replace('/\\sHAVING\\s(?!.*\\sHAVING\\s)/i', ' HAVING %%HAVING%% ', $sql); } if (false === stripos($sql, '%%ORDERBY%%')) { $sql = preg_replace('/\\sORDER BY\\s(?!.*\\sORDER BY\\s)/i', ' ORDER BY %%ORDERBY%% ', $sql); } // Insert variables based on other existing statements if (false === stripos($sql, '%%JOIN%%')) { if (false !== stripos($sql, ' WHERE ')) { $sql = preg_replace('/\\sWHERE\\s(?!.*\\sWHERE\\s)/i', ' %%JOIN%% WHERE ', $sql); } elseif (false !== stripos($sql, ' GROUP BY ')) { $sql = preg_replace('/\\sGROUP BY\\s(?!.*\\sGROUP BY\\s)/i', ' %%WHERE%% GROUP BY ', $sql); } elseif (false !== stripos($sql, ' ORDER BY ')) { $sql = preg_replace('/\\ORDER BY\\s(?!.*\\ORDER BY\\s)/i', ' %%WHERE%% ORDER BY ', $sql); } else { $sql .= ' %%JOIN%% '; } } if (false === stripos($sql, '%%WHERE%%')) { if (false !== stripos($sql, ' GROUP BY ')) { $sql = preg_replace('/\\sGROUP BY\\s(?!.*\\sGROUP BY\\s)/i', ' %%WHERE%% GROUP BY ', $sql); } elseif (false !== stripos($sql, ' ORDER BY ')) { $sql = preg_replace('/\\ORDER BY\\s(?!.*\\ORDER BY\\s)/i', ' %%WHERE%% ORDER BY ', $sql); } else { $sql .= ' %%WHERE%% '; } } if (false === stripos($sql, '%%GROUPBY%%')) { if (false !== stripos($sql, ' HAVING ')) { $sql = preg_replace('/\\sHAVING\\s(?!.*\\sHAVING\\s)/i', ' %%GROUPBY%% HAVING ', $sql); } elseif (false !== stripos($sql, ' ORDER BY ')) { $sql = preg_replace('/\\ORDER BY\\s(?!.*\\ORDER BY\\s)/i', ' %%GROUPBY%% ORDER BY ', $sql); } else { $sql .= ' %%GROUPBY%% '; } } if (false === stripos($sql, '%%HAVING%%')) { if (false !== stripos($sql, ' ORDER BY ')) { $sql = preg_replace('/\\ORDER BY\\s(?!.*\\ORDER BY\\s)/i', ' %%HAVING%% ORDER BY ', $sql); } else { $sql .= ' %%HAVING%% '; } } if (false === stripos($sql, '%%ORDERBY%%')) { $sql .= ' %%ORDERBY%% '; } if (false === stripos($sql, '%%LIMIT%%')) { $sql .= ' %%LIMIT%% '; } // Replace variables if (0 < strlen($params->select)) { if (false === stripos($sql, '%%SELECT%% FROM ')) { $sql = str_ireplace('%%SELECT%%', $params->select . ', ', $sql); } else { $sql = str_ireplace('%%SELECT%%', $params->select, $sql); } } if (0 < strlen($params->join)) { $sql = str_ireplace('%%JOIN%%', $params->join, $sql); } if (0 < strlen($params->where)) { if (false !== stripos($sql, ' WHERE ')) { if (false !== stripos($sql, ' WHERE %%WHERE%% ')) { $sql = str_ireplace('%%WHERE%%', $params->where . ' AND ', $sql); } else { $sql = str_ireplace('%%WHERE%%', ' AND ' . $params->where, $sql); } } else { $sql = str_ireplace('%%WHERE%%', ' WHERE ' . $params->where, $sql); } } if (0 < strlen($params->groupby)) { if (false !== stripos($sql, ' GROUP BY ')) { if (false !== stripos($sql, ' GROUP BY %%GROUPBY%% ')) { $sql = str_ireplace('%%GROUPBY%%', $params->groupby . ', ', $sql); } else { $sql = str_ireplace('%%GROUPBY%%', ', ' . $params->groupby, $sql); } } else { $sql = str_ireplace('%%GROUPBY%%', ' GROUP BY ' . $params->groupby, $sql); } } if (0 < strlen($params->having) && false !== stripos($sql, ' GROUP BY ')) { if (false !== stripos($sql, ' HAVING ')) { if (false !== stripos($sql, ' HAVING %%HAVING%% ')) { $sql = str_ireplace('%%HAVING%%', $params->having . ' AND ', $sql); } else { $sql = str_ireplace('%%HAVING%%', ' AND ' . $params->having, $sql); } } else { $sql = str_ireplace('%%HAVING%%', ' HAVING ' . $params->having, $sql); } } if (0 < strlen($params->orderby)) { if (false !== stripos($sql, ' ORDER BY ')) { if (false !== stripos($sql, ' ORDER BY %%ORDERBY%% ')) { $sql = str_ireplace('%%ORDERBY%%', $params->groupby . ', ', $sql); } else { $sql = str_ireplace('%%ORDERBY%%', ', ' . $params->groupby, $sql); } } else { $sql = str_ireplace('%%ORDERBY%%', ' ORDER BY ' . $params->groupby, $sql); } } if (0 < $params->page && 0 < $params->limit) { $start = ($params->page - 1) * $params->limit; $end = $start + $params->limit; $sql .= 'LIMIT ' . (int) $start . ', ' . (int) $end; } // Clear any unused variables $sql = str_ireplace(array('%%SELECT%%', '%%JOIN%%', '%%WHERE%%', '%%GROUPBY%%', '%%HAVING%%', '%%ORDERBY%%', '%%LIMIT%%'), '', $sql); $sql = str_replace(array('``', '`'), array(' ', ' '), $sql); } return $sql; }
/** * Register Post Types and Taxonomies */ public function setup_content_types($force = false) { $post_types = PodsMeta::$post_types; $taxonomies = PodsMeta::$taxonomies; $existing_post_types = get_post_types(); $existing_taxonomies = get_taxonomies(); $pods_cpt_ct = pods_transient_get('pods_wp_cpt_ct'); $cpt_positions = array(); if (empty($pods_cpt_ct) && (!empty($post_types) || !empty($taxonomies))) { $force = true; } elseif (!empty($pods_cpt_ct) && empty($pods_cpt_ct['post_types']) && !empty($post_types)) { $force = true; } elseif (!empty($pods_cpt_ct) && empty($pods_cpt_ct['taxonomies']) && !empty($taxonomies)) { $force = true; } if (false === $pods_cpt_ct || $force) { $pods_cpt_ct = array('post_types' => array(), 'taxonomies' => array()); $pods_post_types = $pods_taxonomies = array(); $supported_post_types = $supported_taxonomies = array(); foreach ($post_types as $post_type) { // Post Type exists already if (isset($pods_cpt_ct['post_types'][$post_type['name']])) { continue; } elseif (!empty($post_type['object']) && isset($existing_post_types[$post_type['object']])) { continue; } elseif (!$force && isset($existing_post_types[$post_type['name']])) { continue; } $post_type['options']['name'] = $post_type['name']; $post_type = array_merge($post_type, (array) $post_type['options']); // Labels $cpt_label = esc_html(pods_var_raw('label', $post_type, ucwords(str_replace('_', ' ', pods_var_raw('name', $post_type))), null, true)); $cpt_singular = esc_html(pods_var_raw('label_singular', $post_type, ucwords(str_replace('_', ' ', pods_var_raw('label', $post_type, pods_var('name', $post_type), null, true))), null, true)); $cpt_labels = array(); $cpt_labels['name'] = $cpt_label; $cpt_labels['singular_name'] = $cpt_singular; $cpt_labels['menu_name'] = pods_var_raw('menu_name', $post_type, '', null, true); $cpt_labels['add_new'] = pods_var_raw('label_add_new', $post_type, '', null, true); $cpt_labels['add_new_item'] = pods_var_raw('label_add_new_item', $post_type, '', null, true); $cpt_labels['new_item'] = pods_var_raw('label_new_item', $post_type, '', null, true); $cpt_labels['edit'] = pods_var_raw('label_edit', $post_type, '', null, true); $cpt_labels['edit_item'] = pods_var_raw('label_edit_item', $post_type, '', null, true); $cpt_labels['view'] = pods_var_raw('label_view', $post_type, '', null, true); $cpt_labels['view_item'] = pods_var_raw('label_view_item', $post_type, '', null, true); $cpt_labels['all_items'] = pods_var_raw('label_all_items', $post_type, '', null, true); $cpt_labels['search_items'] = pods_var_raw('label_search_items', $post_type, '', null, true); $cpt_labels['not_found'] = pods_var_raw('label_not_found', $post_type, '', null, true); $cpt_labels['not_found_in_trash'] = pods_var_raw('label_not_found_in_trash', $post_type, '', null, true); $cpt_labels['parent'] = pods_var_raw('label_parent', $post_type, '', null, true); $cpt_labels['parent_item_colon'] = pods_var_raw('label_parent_item_colon', $post_type, '', null, true); // Supported $cpt_supported = array('title' => (bool) pods_var('supports_title', $post_type, false), 'editor' => (bool) pods_var('supports_editor', $post_type, false), 'author' => (bool) pods_var('supports_author', $post_type, false), 'thumbnail' => (bool) pods_var('supports_thumbnail', $post_type, false), 'excerpt' => (bool) pods_var('supports_excerpt', $post_type, false), 'trackbacks' => (bool) pods_var('supports_trackbacks', $post_type, false), 'custom-fields' => (bool) pods_var('supports_custom_fields', $post_type, false), 'comments' => (bool) pods_var('supports_comments', $post_type, false), 'revisions' => (bool) pods_var('supports_revisions', $post_type, false), 'page-attributes' => (bool) pods_var('supports_page_attributes', $post_type, false), 'post-formats' => (bool) pods_var('supports_post_formats', $post_type, false)); // Custom Supported $cpt_supported_custom = pods_var('supports_custom', $post_type, ''); if (!empty($cpt_supported_custom)) { $cpt_supported_custom = explode(',', $cpt_supported_custom); $cpt_supported_custom = array_filter(array_unique($cpt_supported_custom)); foreach ($cpt_supported_custom as $cpt_support) { $cpt_supported[$cpt_support] = true; } } // Genesis Support if (function_exists('genesis')) { $cpt_supported['genesis-seo'] = (bool) pods_var('supports_genesis_seo', $post_type, false); $cpt_supported['genesis-layouts'] = (bool) pods_var('supports_genesis_layouts', $post_type, false); $cpt_supported['genesis-simple-sidebars'] = (bool) pods_var('supports_genesis_simple_sidebars', $post_type, false); } // WP needs something, if this was empty and none were enabled, it would show title+editor pre 3.5 :( $cpt_supports = array(); if (!pods_version_check('wp', '3.5')) { $cpt_supports = array('_bug_fix_pre_35'); } foreach ($cpt_supported as $cpt_support => $supported) { if (true === $supported) { $cpt_supports[] = $cpt_support; } } if (empty($cpt_supports) && pods_version_check('wp', '3.5')) { $cpt_supports = false; } // Rewrite $cpt_rewrite = (bool) pods_var('rewrite', $post_type, true); $cpt_rewrite_array = array('slug' => pods_var('rewrite_custom_slug', $post_type, str_replace('_', '-', pods_var('name', $post_type)), null, true), 'with_front' => (bool) pods_var('rewrite_with_front', $post_type, true), 'feeds' => (bool) pods_var('rewrite_feeds', $post_type, (bool) pods_var('has_archive', $post_type, false)), 'pages' => (bool) pods_var('rewrite_pages', $post_type, true)); if (false !== $cpt_rewrite) { $cpt_rewrite = $cpt_rewrite_array; } $capability_type = pods_var('capability_type', $post_type, 'post'); if ('custom' == $capability_type) { $capability_type = pods_var('capability_type_custom', $post_type, 'post'); } $show_in_menu = (bool) pods_var('show_in_menu', $post_type, true); if ($show_in_menu && 0 < strlen(pods_var_raw('menu_location_custom', $post_type))) { $show_in_menu = pods_var_raw('menu_location_custom', $post_type); } // Register Post Type $pods_post_types[pods_var('name', $post_type)] = array('label' => $cpt_label, 'labels' => $cpt_labels, 'description' => esc_html(pods_var_raw('description', $post_type)), 'public' => (bool) pods_var('public', $post_type, true), 'publicly_queryable' => (bool) pods_var('publicly_queryable', $post_type, (bool) pods_var('public', $post_type, true)), 'exclude_from_search' => (bool) pods_var('exclude_from_search', $post_type, (bool) pods_var('public', $post_type, true) ? false : true), 'show_ui' => (bool) pods_var('show_ui', $post_type, (bool) pods_var('public', $post_type, true)), 'show_in_menu' => $show_in_menu, 'show_in_admin_bar' => (bool) pods_var('show_in_admin_bar', $post_type, (bool) pods_var('show_in_menu', $post_type, true)), 'menu_position' => (int) pods_var('menu_position', $post_type, 0, null, true), 'menu_icon' => pods_var('menu_icon', $post_type, null, null, true), 'capability_type' => $capability_type, 'map_meta_cap' => (bool) pods_var('capability_type_extra', $post_type, true), 'hierarchical' => (bool) pods_var('hierarchical', $post_type, false), 'supports' => $cpt_supports, 'has_archive' => (bool) pods_var('has_archive', $post_type, false), 'rewrite' => $cpt_rewrite, 'query_var' => false !== (bool) pods_var('query_var', $post_type, true) ? pods_var('query_var_string', $post_type, pods_var('name', $post_type), null, true) : false, 'can_export' => (bool) pods_var('can_export', $post_type, true), 'show_in_nav_menus' => (bool) pods_var('show_in_nav_menus', $post_type, (bool) pods_var('public', $post_type, true))); if (25 == $pods_post_types[pods_var('name', $post_type)]['menu_position']) { $pods_post_types[pods_var('name', $post_type)]['menu_position']++; } if ($pods_post_types[pods_var('name', $post_type)]['menu_position'] < 1 || in_array($pods_post_types[pods_var('name', $post_type)]['menu_position'], $cpt_positions)) { unset($pods_post_types[pods_var('name', $post_type)]['menu_position']); } else { $cpt_positions[] = $pods_post_types[pods_var('name', $post_type)]['menu_position']; // This would be nice if WP supported floats in menu_position // $pods_post_types[ pods_var( 'name', $post_type ) ][ 'menu_position' ] = $pods_post_types[ pods_var( 'name', $post_type ) ][ 'menu_position' ] . '.1'; } // Taxonomies $cpt_taxonomies = array(); $_taxonomies = get_taxonomies(); $_taxonomies = array_merge_recursive($_taxonomies, $pods_taxonomies); $ignore = array('nav_menu', 'link_category', 'post_format'); foreach ($_taxonomies as $taxonomy => $label) { if (in_array($taxonomy, $ignore)) { continue; } if (false !== (bool) pods_var('built_in_taxonomies_' . $taxonomy, $post_type, false)) { $cpt_taxonomies[] = $taxonomy; if (isset($supported_post_types[$taxonomy]) && !in_array(pods_var('name', $post_type), $supported_post_types[$taxonomy])) { $supported_post_types[$taxonomy][] = pods_var('name', $post_type); } } } if (isset($supported_taxonomies[pods_var('name', $post_type)])) { $supported_taxonomies[pods_var('name', $post_type)] = array_merge((array) $supported_taxonomies[pods_var('name', $post_type)], $cpt_taxonomies); } else { $supported_taxonomies[pods_var('name', $post_type)] = $cpt_taxonomies; } } foreach ($taxonomies as $taxonomy) { // Taxonomy Type exists already if (isset($pods_cpt_ct['taxonomies'][$taxonomy['name']])) { continue; } elseif (!empty($taxonomy['object']) && isset($existing_taxonomies[$taxonomy['object']])) { continue; } elseif (!$force && isset($existing_taxonomies[$taxonomy['name']])) { continue; } $taxonomy['options']['name'] = $taxonomy['name']; $taxonomy = array_merge($taxonomy, (array) $taxonomy['options']); // Labels $ct_label = esc_html(pods_var_raw('label', $taxonomy, ucwords(str_replace('_', ' ', pods_var_raw('name', $taxonomy))), null, true)); $ct_singular = esc_html(pods_var_raw('label_singular', $taxonomy, ucwords(str_replace('_', ' ', pods_var_raw('label', $taxonomy, pods_var_raw('name', $taxonomy), null, true))), null, true)); $ct_labels = array(); $ct_labels['name'] = $ct_label; $ct_labels['singular_name'] = $ct_singular; $ct_labels['menu_name'] = pods_var_raw('menu_name', $taxonomy, '', null, true); $ct_labels['search_items'] = pods_var_raw('label_search_items', $taxonomy, '', null, true); $ct_labels['popular_items'] = pods_var_raw('label_popular_items', $taxonomy, '', null, true); $ct_labels['all_items'] = pods_var_raw('label_all_items', $taxonomy, '', null, true); $ct_labels['parent_item'] = pods_var_raw('label_parent_item', $taxonomy, '', null, true); $ct_labels['parent_item_colon'] = pods_var_raw('label_parent_item_colon', $taxonomy, '', null, true); $ct_labels['edit_item'] = pods_var_raw('label_edit_item', $taxonomy, '', null, true); $ct_labels['update_item'] = pods_var_raw('label_update_item', $taxonomy, '', null, true); $ct_labels['add_new_item'] = pods_var_raw('label_add_new_item', $taxonomy, '', null, true); $ct_labels['new_item_name'] = pods_var_raw('label_new_item_name', $taxonomy, '', null, true); $ct_labels['separate_items_with_commas'] = pods_var_raw('label_separate_items_with_commas', $taxonomy, '', null, true); $ct_labels['add_or_remove_items'] = pods_var_raw('label_add_or_remove_items', $taxonomy, '', null, true); $ct_labels['choose_from_most_used'] = pods_var_raw('label_choose_from_the_most_used', $taxonomy, '', null, true); // Rewrite $ct_rewrite = (bool) pods_var('rewrite', $taxonomy, true); $ct_rewrite_array = array('slug' => pods_var('rewrite_custom_slug', $taxonomy, str_replace('_', '-', pods_var('name', $taxonomy)), null, true), 'with_front' => (bool) pods_var('rewrite_with_front', $taxonomy, true), 'hierarchical' => (bool) pods_var('rewrite_hierarchical', $taxonomy, (bool) pods_var('hierarchical', $taxonomy, false))); if (false !== $ct_rewrite) { $ct_rewrite = $ct_rewrite_array; } // Register Taxonomy $pods_taxonomies[pods_var('name', $taxonomy)] = array('label' => $ct_label, 'labels' => $ct_labels, 'public' => (bool) pods_var('public', $taxonomy, true), 'show_in_nav_menus' => (bool) pods_var('show_in_nav_menus', $taxonomy, (bool) pods_var('public', $taxonomy, true)), 'show_ui' => (bool) pods_var('show_ui', $taxonomy, (bool) pods_var('public', $taxonomy, true)), 'show_tagcloud' => (bool) pods_var('show_tagcloud', $taxonomy, (bool) pods_var('show_ui', $taxonomy, (bool) pods_var('public', $taxonomy, true))), 'hierarchical' => (bool) pods_var('hierarchical', $taxonomy, false), 'update_count_callback' => pods_var('update_count_callback', $taxonomy, null, null, true), 'query_var' => false !== (bool) pods_var('query_var', $taxonomy, true) ? pods_var('query_var_string', $taxonomy, pods_var('name', $taxonomy), null, true) : false, 'rewrite' => $ct_rewrite, 'show_admin_column' => (bool) pods_var('show_admin_column', $taxonomy, false), 'sort' => (bool) pods_var('sort', $taxonomy, false)); if (is_array($ct_rewrite) && !$pods_taxonomies[pods_var('name', $taxonomy)]['query_var']) { $pods_taxonomies[pods_var('name', $taxonomy)]['query_var'] = pods_var('query_var_string', $taxonomy, pods_var('name', $taxonomy), null, true); } // Post Types $ct_post_types = array(); $_post_types = get_post_types(); $_post_types = array_merge_recursive($_post_types, $pods_post_types); $ignore = array('revision', 'nav_menu_item'); foreach ($_post_types as $post_type => $options) { if (in_array($post_type, $ignore)) { continue; } if (false !== (bool) pods_var('built_in_post_types_' . $post_type, $taxonomy, false)) { $ct_post_types[] = $post_type; if (isset($supported_taxonomies[$post_type]) && !in_array(pods_var('name', $taxonomy), $supported_taxonomies[$post_type])) { $supported_taxonomies[$post_type][] = pods_var('name', $taxonomy); } } } if (isset($supported_post_types[pods_var('name', $taxonomy)])) { $supported_post_types[pods_var('name', $taxonomy)] = array_merge($supported_post_types[pods_var('name', $taxonomy)], $ct_post_types); } else { $supported_post_types[pods_var('name', $taxonomy)] = $ct_post_types; } } $pods_post_types = apply_filters('pods_wp_post_types', $pods_post_types); $pods_taxonomies = apply_filters('pods_wp_taxonomies', $pods_taxonomies); $supported_post_types = apply_filters('pods_wp_supported_post_types', $supported_post_types); $supported_taxonomies = apply_filters('pods_wp_supported_taxonomies', $supported_taxonomies); foreach ($pods_taxonomies as $taxonomy => $options) { $ct_post_types = null; if (isset($supported_post_types[$taxonomy]) && !empty($supported_post_types[$taxonomy])) { $ct_post_types = $supported_post_types[$taxonomy]; } $pods_cpt_ct['taxonomies'][$taxonomy] = array('post_types' => $ct_post_types, 'options' => $options); } foreach ($pods_post_types as $post_type => $options) { if (isset($supported_taxonomies[$post_type]) && !empty($supported_taxonomies[$post_type])) { $options['taxonomies'] = $supported_taxonomies[$post_type]; } $pods_cpt_ct['post_types'][$post_type] = $options; } pods_transient_set('pods_wp_cpt_ct', $pods_cpt_ct); } foreach ($pods_cpt_ct['taxonomies'] as $taxonomy => $options) { if (isset(self::$content_types_registered['taxonomies']) && in_array($taxonomy, self::$content_types_registered['taxonomies'])) { continue; } $ct_post_types = $options['post_types']; $options = $options['options']; $options = apply_filters('pods_register_taxonomy_' . $taxonomy, $options); $options = self::object_label_fix($options, 'taxonomy'); // Max length for taxonomies are 32 characters $taxonomy = substr($taxonomy, 0, 32); // i18n compatibility for plugins that override it if (is_array($options['rewrite']) && isset($options['rewrite']['slug']) && !empty($options['rewrite']['slug'])) { $options['rewrite']['slug'] = _x($options['rewrite']['slug'], 'URL taxonomy slug', 'pods'); } if (1 == pods_var('pods_debug_register', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug(array($taxonomy, $ct_post_types, $options)); } register_taxonomy($taxonomy, $ct_post_types, $options); if (!isset(self::$content_types_registered['taxonomies'])) { self::$content_types_registered['taxonomies'] = array(); } self::$content_types_registered['taxonomies'][] = $taxonomy; } foreach ($pods_cpt_ct['post_types'] as $post_type => $options) { if (isset(self::$content_types_registered['post_types']) && in_array($post_type, self::$content_types_registered['post_types'])) { continue; } $options = apply_filters('pods_register_post_type_' . $post_type, $options); $options = self::object_label_fix($options, 'post_type'); // Max length for post types are 20 characters $post_type = substr($post_type, 0, 20); // i18n compatibility for plugins that override it if (is_array($options['rewrite']) && isset($options['rewrite']['slug']) && !empty($options['rewrite']['slug'])) { $options['rewrite']['slug'] = _x($options['rewrite']['slug'], 'URL slug', 'pods'); } if (1 == pods_var('pods_debug_register', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug(array($post_type, $options)); } register_post_type($post_type, $options); if (!isset(self::$content_types_registered['post_types'])) { self::$content_types_registered['post_types'] = array(); } self::$content_types_registered['post_types'][] = $post_type; } $flush = pods_transient_get('pods_flush_rewrites'); if (1 == $flush) { global $wp_rewrite; $wp_rewrite->flush_rules(); $wp_rewrite->init(); pods_transient_set('pods_flush_rewrites', 0); } }
/** * @param bool $full Whether to get ALL data or use pagination * * @return bool */ public function get_data($params = null) { $action = $this->action; $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => ''); if (!empty($params) && is_array($params)) { $params = (object) array_merge($defaults, $params); } else { $params = (object) $defaults; } if (!in_array($action, array('manage', 'reorder'))) { $action = 'manage'; } if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) { $orderby = array(); $limit = $this->limit; $sql = null; if ('reorder' == $this->action) { if (!empty($this->reorder['orderby'])) { $orderby[$this->reorder['orderby']] = $this->reorder['orderby_dir']; } else { $orderby[$this->reorder['on']] = $this->reorder['orderby_dir']; } if (!empty($this->reorder['limit'])) { $limit = $this->reorder['limit']; } if (!empty($this->reorder['sql'])) { $sql = $this->reorder['sql']; } } if (!empty($this->orderby)) { $this->orderby = (array) $this->orderby; foreach ($this->orderby as $order) { if (false === strpos(' ', $order) && !isset($orderby[$order])) { $orderby[$order] = $this->orderby_dir; } } } $find_params = array('where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'search_across' => $this->search_across, 'search_across_picks' => $this->search_across_picks, 'filters' => $this->filters, 'sql' => $sql); if (empty($find_params['where']) && $this->restricted($this->action)) { $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null); } if ($params->full) { $find_params['limit'] = -1; } $find_params = array_merge($find_params, (array) $this->params); // Debug purposes if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($find_params); } $this->pod->find($find_params); if (!$params->full) { $data = $this->pod->data(); $this->data = $data; if (!empty($this->data)) { $this->data_keys = array_keys($this->data); } $this->total = $this->pod->total(); $this->total_found = $this->pod->total_found(); } else { $this->data_full = array(); $export_params = array('fields' => $params->fields, 'flatten' => true); if (in_array($params->type, array('json', 'xml'))) { $export_params['flatten'] = false; } $export_params = $this->do_hook('export_options', $export_params, $params); while ($this->pod->fetch()) { $this->data_full[$this->pod->id()] = $this->pod->export($export_params); } $this->pod->reset(); return $this->data_full; } } else { if (!empty($this->data)) { return $this->data; } if (empty($this->sql['table'])) { return $this->data; } $orderby = array(); if (!empty($this->orderby)) { $this->orderby = (array) $this->orderby; foreach ($this->orderby as $k => $order) { if (false === strpos($order, ' ')) { if (in_array(strtoupper($order), array('ASC', 'DESC'))) { $orderby[$k] = $order; } elseif (!isset($orderby[$order])) { $orderby[$order] = $this->orderby_dir; } } else { $orderby[] = $order; } } } // Allow orderby array ( 'field' => 'asc|desc' ) if (!empty($orderby) && is_array($orderby)) { foreach ($orderby as $k => &$orderby_value) { if (!is_numeric($k)) { $order = 'ASC'; if ('DESC' == strtoupper($orderby_value)) { $order = 'DESC'; } if (false !== strpos($k, '.')) { $key = $k; if (false === strpos($key, ' ') && false === strpos($key, '`')) { $key = '`' . str_replace('.', '`.`', $key) . '`'; } } else { $key = "`t`.`{$k}`"; } $orderby_value = $key; if (false === strpos($orderby_value, ' ')) { $orderby_value .= ' ' . $order; } } } } // Add prefix to $orderby if needed if (!empty($orderby)) { if (!is_array($orderby)) { $orderby = array($orderby); } foreach ($orderby as &$prefix_orderby) { if (false === strpos($prefix_orderby, ',') && false === strpos($prefix_orderby, '(') && false === stripos($prefix_orderby, ' AS ') && false === strpos($prefix_orderby, '`') && false === strpos($prefix_orderby, '.')) { if (false !== stripos($prefix_orderby, ' DESC')) { $k = trim(str_ireplace(array('`', ' DESC'), '', $prefix_orderby)); $dir = 'DESC'; } else { $k = trim(str_ireplace(array('`', ' ASC'), '', $prefix_orderby)); $dir = 'ASC'; } $key = "`t`.`{$k}`"; $prefix_orderby = "{$key} {$dir}"; } } } $find_params = array('table' => $this->sql['table'], 'id' => $this->sql['field_id'], 'index' => $this->sql['field_index'], 'where' => pods_var_raw($action, $this->where, null, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $this->limit, 'search' => $this->searchable, 'search_query' => $this->search, 'fields' => $this->fields['search']); if (empty($find_params['where']) && $this->restricted($this->action)) { $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null); } if ($params->full) { $find_params['limit'] = -1; } // Debug purposes if (1 == pods_var('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($find_params); } $this->pods_data->select($find_params); if (!$params->full) { $this->data = $this->pods_data->data; if (!empty($this->data)) { $this->data_keys = array_keys($this->data); } $this->total = $this->pods_data->total(); $this->total_found = $this->pods_data->total_found(); } else { $this->data_full = $this->pods_data->data; if (!empty($this->data_full)) { $this->data_keys = array_keys($this->data_full); } return $this->data_full; } } return $this->data; }