function get($max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $exclude = false, $in = false) { global $nxtdb, $bp; // Select conditions $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name"; $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$nxtdb->users} u ON a.user_id = u.ID"; // Where conditions $where_conditions = array(); // Searching if ($search_terms) { $search_terms = $nxtdb->escape($search_terms); $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape($search_terms) . "%%'"; } // Filtering if ($filter && ($filter_sql = BP_Activity_Activity::get_filter_sql($filter))) { $where_conditions['filter_sql'] = $filter_sql; } // Sorting if ($sort != 'ASC' && $sort != 'DESC') { $sort = 'DESC'; } // Hide Hidden Items? if (!$show_hidden) { $where_conditions['hidden_sql'] = "a.hide_sitewide = 0"; } // Exclude specified items if (!empty($exclude)) { $exclude = implode(',', nxt_parse_id_list($exclude)); $where_conditions['exclude'] = "a.id NOT IN ({$exclude})"; } // The specific ids to which you want to limit the query if (!empty($in)) { $in = implode(',', nxt_parse_id_list($in)); $where_conditions['in'] = "a.id IN ({$in})"; } // Alter the query based on whether we want to show activity item // comments in the stream like normal comments or threaded below // the activity. if (false === $display_comments || 'threaded' === $display_comments) { $where_conditions[] = "a.type != 'activity_comment'"; } $where_sql = 'WHERE ' . join(' AND ', $where_conditions); if (!empty($per_page) && !empty($page)) { // Make sure page values are absolute integers $page = absint($page); $per_page = absint($per_page); $pag_sql = $nxtdb->prepare("LIMIT %d, %d", absint(($page - 1) * $per_page), $per_page); $activities = $nxtdb->get_results(apply_filters('bp_activity_get_user_join_filter', $nxtdb->prepare("{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}"), $select_sql, $from_sql, $where_sql, $sort, $pag_sql)); } else { $activities = $nxtdb->get_results(apply_filters('bp_activity_get_user_join_filter', $nxtdb->prepare("{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}"), $select_sql, $from_sql, $where_sql, $sort)); } $total_activities_sql = apply_filters('bp_activity_total_activities_sql', $nxtdb->prepare("SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}"), $where_sql, $sort); $total_activities = $nxtdb->get_var($total_activities_sql); // Get the fullnames of users so we don't have to query in the loop if (bp_is_active('xprofile') && $activities) { foreach ((array) $activities as $activity) { if ((int) $activity->user_id) { $activity_user_ids[] = $activity->user_id; } } $activity_user_ids = implode(',', array_unique((array) $activity_user_ids)); if (!empty($activity_user_ids)) { if ($names = $nxtdb->get_results($nxtdb->prepare("SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})"))) { foreach ((array) $names as $name) { $tmp_names[$name->user_id] = $name->user_fullname; } foreach ((array) $activities as $i => $activity) { if (!empty($tmp_names[$activity->user_id])) { $activities[$i]->user_fullname = $tmp_names[$activity->user_id]; } } unset($names); unset($tmp_names); } } } if ($activities && $display_comments) { $activities = BP_Activity_Activity::append_comments($activities); } // If $max is set, only return up to the max results if (!empty($max)) { if ((int) $total_activities > (int) $max) { $total_activities = $max; } } return array('activities' => $activities, 'total' => (int) $total_activities); }
/** * Retrieve the terms in a given taxonomy or list of taxonomies. * * You can fully inject any customizations to the query before it is sent, as * well as control the output with a filter. * * The 'get_terms' filter will be called when the cache has the term and will * pass the found term along with the array of $taxonomies and array of $args. * This filter is also called before the array of terms is passed and will pass * the array of terms, along with the $taxonomies and $args. * * The 'list_terms_exclusions' filter passes the compiled exclusions along with * the $args. * * The 'get_terms_orderby' filter passes the ORDER BY clause for the query * along with the $args array. * * The 'get_terms_fields' filter passes the fields for the SELECT query * along with the $args array. * * The list of arguments that $args can contain, which will overwrite the defaults: * * orderby - Default is 'name'. Can be name, count, term_group, slug or nothing * (will use term_id), Passing a custom value other than these will cause it to * order based on the custom value. * * order - Default is ASC. Can use DESC. * * hide_empty - Default is true. Will not return empty terms, which means * terms whose count is 0 according to the given taxonomy. * * exclude - Default is an empty array. An array, comma- or space-delimited string * of term ids to exclude from the return array. If 'include' is non-empty, * 'exclude' is ignored. * * exclude_tree - Default is an empty array. An array, comma- or space-delimited * string of term ids to exclude from the return array, along with all of their * descendant terms according to the primary taxonomy. If 'include' is non-empty, * 'exclude_tree' is ignored. * * include - Default is an empty array. An array, comma- or space-delimited string * of term ids to include in the return array. * * number - The maximum number of terms to return. Default is to return them all. * * offset - The number by which to offset the terms query. * * fields - Default is 'all', which returns an array of term objects. * If 'fields' is 'ids' or 'names', returns an array of * integers or strings, respectively. * * slug - Returns terms whose "slug" matches this value. Default is empty string. * * hierarchical - Whether to include terms that have non-empty descendants * (even if 'hide_empty' is set to true). * * search - Returned terms' names will contain the value of 'search', * case-insensitive. Default is an empty string. * * name__like - Returned terms' names will begin with the value of 'name__like', * case-insensitive. Default is empty string. * * The argument 'pad_counts', if set to true will include the quantity of a term's * children in the quantity of each term's "count" object variable. * * The 'get' argument, if set to 'all' instead of its default empty string, * returns terms regardless of ancestry or whether the terms are empty. * * The 'child_of' argument, when used, should be set to the integer of a term ID. Its default * is 0. If set to a non-zero value, all returned terms will be descendants * of that term according to the given taxonomy. Hence 'child_of' is set to 0 * if more than one taxonomy is passed in $taxonomies, because multiple taxonomies * make term ancestry ambiguous. * * The 'parent' argument, when used, should be set to the integer of a term ID. Its default is * the empty string '', which has a different meaning from the integer 0. * If set to an integer value, all returned terms will have as an immediate * ancestor the term whose ID is specified by that integer according to the given taxonomy. * The 'parent' argument is different from 'child_of' in that a term X is considered a 'parent' * of term Y only if term X is the father of term Y, not its grandfather or great-grandfather, etc. * * The 'cache_domain' argument enables a unique cache key to be produced when this query is stored * in object cache. For instance, if you are using one of this function's filters to modify the * query (such as 'terms_clauses'), setting 'cache_domain' to a unique value will not overwrite * the cache for similar queries. Default value is 'core'. * * @package NXTClass * @subpackage Taxonomy * @since 2.3.0 * * @uses $nxtdb * @uses nxt_parse_args() Merges the defaults with those defined by $args and allows for strings. * * @param string|array $taxonomies Taxonomy name or list of Taxonomy names * @param string|array $args The values of what to search for when returning terms * @return array|nxt_Error List of Term Objects and their children. Will return nxt_Error, if any of $taxonomies do not exist. */ function &get_terms($taxonomies, $args = '') { global $nxtdb; $empty_array = array(); $single_taxonomy = false; if (!is_array($taxonomies)) { $single_taxonomy = true; $taxonomies = array($taxonomies); } foreach ($taxonomies as $taxonomy) { if (!taxonomy_exists($taxonomy)) { $error = new nxt_Error('invalid_taxonomy', __('Invalid Taxonomy')); return $error; } } $defaults = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core'); $args = nxt_parse_args($args, $defaults); $args['number'] = absint($args['number']); $args['offset'] = absint($args['offset']); if (!$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) || '' !== $args['parent']) { $args['child_of'] = 0; $args['hierarchical'] = false; $args['pad_counts'] = false; } if ('all' == $args['get']) { $args['child_of'] = 0; $args['hide_empty'] = 0; $args['hierarchical'] = false; $args['pad_counts'] = false; } $args = apply_filters('get_terms_args', $args, $taxonomies); extract($args, EXTR_SKIP); if ($child_of) { $hierarchy = _get_term_hierarchy($taxonomies[0]); if (!isset($hierarchy[$child_of])) { return $empty_array; } } if ($parent) { $hierarchy = _get_term_hierarchy($taxonomies[0]); if (!isset($hierarchy[$parent])) { return $empty_array; } } // $args can be whatever, only use the args defined in defaults to compute the key $filter_key = has_filter('list_terms_exclusions') ? serialize($GLOBALS['nxt_filter']['list_terms_exclusions']) : ''; $key = md5(serialize(compact(array_keys($defaults))) . serialize($taxonomies) . $filter_key); $last_changed = nxt_cache_get('last_changed', 'terms'); if (!$last_changed) { $last_changed = time(); nxt_cache_set('last_changed', $last_changed, 'terms'); } $cache_key = "get_terms:{$key}:{$last_changed}"; $cache = nxt_cache_get($cache_key, 'terms'); if (false !== $cache) { $cache = apply_filters('get_terms', $cache, $taxonomies, $args); return $cache; } $_orderby = strtolower($orderby); if ('count' == $_orderby) { $orderby = 'tt.count'; } else { if ('name' == $_orderby) { $orderby = 't.name'; } else { if ('slug' == $_orderby) { $orderby = 't.slug'; } else { if ('term_group' == $_orderby) { $orderby = 't.term_group'; } else { if ('none' == $_orderby) { $orderby = ''; } elseif (empty($_orderby) || 'id' == $_orderby) { $orderby = 't.term_id'; } else { $orderby = 't.name'; } } } } } $orderby = apply_filters('get_terms_orderby', $orderby, $args); if (!empty($orderby)) { $orderby = "ORDER BY {$orderby}"; } else { $order = ''; } $order = strtoupper($order); if ('' !== $order && !in_array($order, array('ASC', 'DESC'))) { $order = 'ASC'; } $where = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')"; $inclusions = ''; if (!empty($include)) { $exclude = ''; $exclude_tree = ''; $interms = nxt_parse_id_list($include); foreach ($interms as $interm) { if (empty($inclusions)) { $inclusions = ' AND ( t.term_id = ' . intval($interm) . ' '; } else { $inclusions .= ' OR t.term_id = ' . intval($interm) . ' '; } } } if (!empty($inclusions)) { $inclusions .= ')'; } $where .= $inclusions; $exclusions = ''; if (!empty($exclude_tree)) { $excluded_trunks = nxt_parse_id_list($exclude_tree); foreach ($excluded_trunks as $extrunk) { $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids', 'hide_empty' => 0)); $excluded_children[] = $extrunk; foreach ($excluded_children as $exterm) { if (empty($exclusions)) { $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; } else { $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; } } } } if (!empty($exclude)) { $exterms = nxt_parse_id_list($exclude); foreach ($exterms as $exterm) { if (empty($exclusions)) { $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' '; } else { $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' '; } } } if (!empty($exclusions)) { $exclusions .= ')'; } $exclusions = apply_filters('list_terms_exclusions', $exclusions, $args); $where .= $exclusions; if (!empty($slug)) { $slug = sanitize_title($slug); $where .= " AND t.slug = '{$slug}'"; } if (!empty($name__like)) { $name__like = like_escape($name__like); $where .= $nxtdb->prepare(" AND t.name LIKE %s", $name__like . '%'); } if ('' !== $parent) { $parent = (int) $parent; $where .= " AND tt.parent = '{$parent}'"; } if ($hide_empty && !$hierarchical) { $where .= ' AND tt.count > 0'; } // don't limit the query results when we have to descend the family tree if (!empty($number) && !$hierarchical && empty($child_of) && '' === $parent) { if ($offset) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } else { $limits = ''; } if (!empty($search)) { $search = like_escape($search); $where .= $nxtdb->prepare(" AND (t.name LIKE %s)", '%' . $search . '%'); } $selects = array(); switch ($fields) { case 'all': $selects = array('t.*', 'tt.*'); break; case 'ids': case 'id=>parent': $selects = array('t.term_id', 'tt.parent', 'tt.count'); break; case 'names': $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name'); break; case 'count': $orderby = ''; $order = ''; $selects = array('COUNT(*)'); } $_fields = $fields; $fields = implode(', ', apply_filters('get_terms_fields', $selects, $args)); $join = "INNER JOIN {$nxtdb->term_taxonomy} AS tt ON t.term_id = tt.term_id"; $pieces = array('fields', 'join', 'where', 'orderby', 'order', 'limits'); $clauses = apply_filters('terms_clauses', compact($pieces), $taxonomies, $args); foreach ($pieces as $piece) { ${$piece} = isset($clauses[$piece]) ? $clauses[$piece] : ''; } $query = "SELECT {$fields} FROM {$nxtdb->terms} AS t {$join} WHERE {$where} {$orderby} {$order} {$limits}"; $fields = $_fields; if ('count' == $fields) { $term_count = $nxtdb->get_var($query); return $term_count; } $terms = $nxtdb->get_results($query); if ('all' == $fields) { update_term_cache($terms); } if (empty($terms)) { nxt_cache_add($cache_key, array(), 'terms', 86400); // one day $terms = apply_filters('get_terms', array(), $taxonomies, $args); return $terms; } if ($child_of) { $children = _get_term_hierarchy($taxonomies[0]); if (!empty($children)) { $terms =& _get_term_children($child_of, $terms, $taxonomies[0]); } } // Update term counts to include children. if ($pad_counts && 'all' == $fields) { _pad_term_counts($terms, $taxonomies[0]); } // Make sure we show empty categories that have children. if ($hierarchical && $hide_empty && is_array($terms)) { foreach ($terms as $k => $term) { if (!$term->count) { $children = _get_term_children($term->term_id, $terms, $taxonomies[0]); if (is_array($children)) { foreach ($children as $child) { if ($child->count) { continue 2; } } } // It really is empty unset($terms[$k]); } } } reset($terms); $_terms = array(); if ('id=>parent' == $fields) { while ($term = array_shift($terms)) { $_terms[$term->term_id] = $term->parent; } $terms = $_terms; } elseif ('ids' == $fields) { while ($term = array_shift($terms)) { $_terms[] = $term->term_id; } $terms = $_terms; } elseif ('names' == $fields) { while ($term = array_shift($terms)) { $_terms[] = $term->name; } $terms = $_terms; } if (0 < $number && intval(@count($terms)) > $number) { $terms = array_slice($terms, $offset, $number); } nxt_cache_add($cache_key, $terms, 'terms', 86400); // one day $terms = apply_filters('get_terms', $terms, $taxonomies, $args); return $terms; }
/** * Retrieve a list of pages. * * The defaults that can be overridden are the following: 'child_of', * 'sort_order', 'sort_column', 'post_title', 'hierarchical', 'exclude', * 'include', 'meta_key', 'meta_value','authors', 'number', and 'offset'. * * @since 1.5.0 * @uses $nxtdb * * @param mixed $args Optional. Array or string of options that overrides defaults. * @return array List of pages matching defaults or $args */ function &get_pages($args = '') { global $nxtdb; $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish'); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); $number = (int) $number; $offset = (int) $offset; // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types(array('hierarchical' => true)); if (!in_array($post_type, $hierarchical_post_types)) { return false; } // Make sure we have a valid post status if (!is_array($post_status)) { $post_status = explode(',', $post_status); } if (array_diff($post_status, get_post_stati())) { return false; } $cache = array(); $key = md5(serialize(compact(array_keys($defaults)))); if ($cache = nxt_cache_get('get_pages', 'posts')) { if (is_array($cache) && isset($cache[$key])) { $pages = apply_filters('get_pages', $cache[$key], $r); return $pages; } } if (!is_array($cache)) { $cache = array(); } $inclusions = ''; if (!empty($include)) { $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include $parent = -1; $exclude = ''; $meta_key = ''; $meta_value = ''; $hierarchical = false; $incpages = nxt_parse_id_list($include); if (!empty($incpages)) { foreach ($incpages as $incpage) { if (empty($inclusions)) { $inclusions = $nxtdb->prepare(' AND ( ID = %d ', $incpage); } else { $inclusions .= $nxtdb->prepare(' OR ID = %d ', $incpage); } } } } if (!empty($inclusions)) { $inclusions .= ')'; } $exclusions = ''; if (!empty($exclude)) { $expages = nxt_parse_id_list($exclude); if (!empty($expages)) { foreach ($expages as $expage) { if (empty($exclusions)) { $exclusions = $nxtdb->prepare(' AND ( ID <> %d ', $expage); } else { $exclusions .= $nxtdb->prepare(' AND ID <> %d ', $expage); } } } } if (!empty($exclusions)) { $exclusions .= ')'; } $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\\s,]+/', $authors); if (!empty($post_authors)) { foreach ($post_authors as $post_author) { //Do we have an author id or an author login? if (0 == intval($post_author)) { $post_author = get_user_by('login', $post_author); if (empty($post_author)) { continue; } if (empty($post_author->ID)) { continue; } $post_author = $post_author->ID; } if ('' == $author_query) { $author_query = $nxtdb->prepare(' post_author = %d ', $post_author); } else { $author_query .= $nxtdb->prepare(' OR post_author = %d ', $post_author); } } if ('' != $author_query) { $author_query = " AND ({$author_query})"; } } } $join = ''; $where = "{$exclusions} {$inclusions} "; if (!empty($meta_key) || !empty($meta_value)) { $join = " LEFT JOIN {$nxtdb->postmeta} ON ( {$nxtdb->posts}.ID = {$nxtdb->postmeta}.post_id )"; // meta_key and meta_value might be slashed $meta_key = stripslashes($meta_key); $meta_value = stripslashes($meta_value); if (!empty($meta_key)) { $where .= $nxtdb->prepare(" AND {$nxtdb->postmeta}.meta_key = %s", $meta_key); } if (!empty($meta_value)) { $where .= $nxtdb->prepare(" AND {$nxtdb->postmeta}.meta_value = %s", $meta_value); } } if ($parent >= 0) { $where .= $nxtdb->prepare(' AND post_parent = %d ', $parent); } if (1 == count($post_status)) { $where_post_type = $nxtdb->prepare("post_type = %s AND post_status = %s", $post_type, array_shift($post_status)); } else { $post_status = implode("', '", $post_status); $where_post_type = $nxtdb->prepare("post_type = %s AND post_status IN ('{$post_status}')", $post_type); } $orderby_array = array(); $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', 'ID', 'rand', 'comment_count'); foreach (explode(',', $sort_column) as $orderby) { $orderby = trim($orderby); if (!in_array($orderby, $allowed_keys)) { continue; } switch ($orderby) { case 'menu_order': break; case 'ID': $orderby = "{$nxtdb->posts}.ID"; break; case 'rand': $orderby = 'RAND()'; break; case 'comment_count': $orderby = "{$nxtdb->posts}.comment_count"; break; default: if (0 === strpos($orderby, 'post_')) { $orderby = "{$nxtdb->posts}." . $orderby; } else { $orderby = "{$nxtdb->posts}.post_" . $orderby; } } $orderby_array[] = $orderby; } $sort_column = !empty($orderby_array) ? implode(',', $orderby_array) : "{$nxtdb->posts}.post_title"; $sort_order = strtoupper($sort_order); if ('' !== $sort_order && !in_array($sort_order, array('ASC', 'DESC'))) { $sort_order = 'ASC'; } $query = "SELECT * FROM {$nxtdb->posts} {$join} WHERE ({$where_post_type}) {$where} "; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order; if (!empty($number)) { $query .= ' LIMIT ' . $offset . ',' . $number; } $pages = $nxtdb->get_results($query); if (empty($pages)) { $pages = apply_filters('get_pages', array(), $r); return $pages; } // Sanitize before caching so it'll only get done once $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { $pages[$i] = sanitize_post($pages[$i], 'raw'); } // Update cache. update_page_cache($pages); if ($child_of || $hierarchical) { $pages =& get_page_children($child_of, $pages); } if (!empty($exclude_tree)) { $exclude = (int) $exclude_tree; $children = get_page_children($exclude, $pages); $excludes = array(); foreach ($children as $child) { $excludes[] = $child->ID; } $excludes[] = $exclude; $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { if (in_array($pages[$i]->ID, $excludes)) { unset($pages[$i]); } } } $cache[$key] = $pages; nxt_cache_set('get_pages', $cache, 'posts'); $pages = apply_filters('get_pages', $pages, $r); return $pages; }
/** * Prepare the query variables * * @since 3.1.0 * @access private */ function prepare_query() { global $nxtdb; $qv =& $this->query_vars; if (is_array($qv['fields'])) { $qv['fields'] = array_unique($qv['fields']); $this->query_fields = array(); foreach ($qv['fields'] as $field) { $this->query_fields[] = $nxtdb->users . '.' . esc_sql($field); } $this->query_fields = implode(',', $this->query_fields); } elseif ('all' == $qv['fields']) { $this->query_fields = "{$nxtdb->users}.*"; } else { $this->query_fields = "{$nxtdb->users}.ID"; } if ($this->query_vars['count_total']) { $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; } $this->query_from = "FROM {$nxtdb->users}"; $this->query_where = "WHERE 1=1"; // sorting if (in_array($qv['orderby'], array('nicename', 'email', 'url', 'registered'))) { $orderby = 'user_' . $qv['orderby']; } elseif (in_array($qv['orderby'], array('user_nicename', 'user_email', 'user_url', 'user_registered'))) { $orderby = $qv['orderby']; } elseif ('name' == $qv['orderby'] || 'display_name' == $qv['orderby']) { $orderby = 'display_name'; } elseif ('post_count' == $qv['orderby']) { // todo: avoid the JOIN $where = get_posts_by_author_sql('post'); $this->query_from .= " LEFT OUTER JOIN (\n\t\t\t\tSELECT post_author, COUNT(*) as post_count\n\t\t\t\tFROM {$nxtdb->posts}\n\t\t\t\t{$where}\n\t\t\t\tGROUP BY post_author\n\t\t\t) p ON ({$nxtdb->users}.ID = p.post_author)\n\t\t\t"; $orderby = 'post_count'; } elseif ('ID' == $qv['orderby'] || 'id' == $qv['orderby']) { $orderby = 'ID'; } else { $orderby = 'user_login'; } $qv['order'] = strtoupper($qv['order']); if ('ASC' == $qv['order']) { $order = 'ASC'; } else { $order = 'DESC'; } $this->query_orderby = "ORDER BY {$orderby} {$order}"; // limit if ($qv['number']) { if ($qv['offset']) { $this->query_limit = $nxtdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']); } else { $this->query_limit = $nxtdb->prepare("LIMIT %d", $qv['number']); } } $search = trim($qv['search']); if ($search) { $leading_wild = ltrim($search, '*') != $search; $trailing_wild = rtrim($search, '*') != $search; if ($leading_wild && $trailing_wild) { $wild = 'both'; } elseif ($leading_wild) { $wild = 'leading'; } elseif ($trailing_wild) { $wild = 'trailing'; } else { $wild = false; } if ($wild) { $search = trim($search, '*'); } if (false !== strpos($search, '@')) { $search_columns = array('user_email'); } elseif (is_numeric($search)) { $search_columns = array('user_login', 'ID'); } elseif (preg_match('|^https?://|', $search)) { $search_columns = array('user_url'); } else { $search_columns = array('user_login', 'user_nicename'); } $this->query_where .= $this->get_search_sql($search, $search_columns, $wild); } $blog_id = absint($qv['blog_id']); if ('authors' == $qv['who'] && $blog_id) { $qv['meta_key'] = $nxtdb->get_blog_prefix($blog_id) . 'user_level'; $qv['meta_value'] = 0; $qv['meta_compare'] = '!='; $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query } $role = trim($qv['role']); if ($blog_id && ($role || is_multisite())) { $cap_meta_query = array(); $cap_meta_query['key'] = $nxtdb->get_blog_prefix($blog_id) . 'capabilities'; if ($role) { $cap_meta_query['value'] = '"' . $role . '"'; $cap_meta_query['compare'] = 'like'; } $qv['meta_query'][] = $cap_meta_query; } $meta_query = new nxt_Meta_Query(); $meta_query->parse_query_vars($qv); if (!empty($meta_query->queries)) { $clauses = $meta_query->get_sql('user', $nxtdb->users, 'ID', $this); $this->query_from .= $clauses['join']; $this->query_where .= $clauses['where']; if ('OR' == $meta_query->relation) { $this->query_fields = 'DISTINCT ' . $this->query_fields; } } if (!empty($qv['include'])) { $ids = implode(',', nxt_parse_id_list($qv['include'])); $this->query_where .= " AND {$nxtdb->users}.ID IN ({$ids})"; } elseif (!empty($qv['exclude'])) { $ids = implode(',', nxt_parse_id_list($qv['exclude'])); $this->query_where .= " AND {$nxtdb->users}.ID NOT IN ({$ids})"; } do_action_ref_array('pre_user_query', array(&$this)); }