/** * Retrieve member list * Ideal to offer a multi-page member list * * @param array $data Contains data affecting the member query - List of Array keys below * - orderby: What table column will the member list be sorted by? * - orderdir: Ascending or Descending order direction * - perpage: Amount of members to fetch (set 0 for all members) * - letter: Beginning character of member name * - username: Searching for a matching username * - username_match: Set this to "begins" when username shall being with given token - otherwise it goes or "contains" * - website: String contained in website * - aim: Search for an AIM * - icq: Search for an ICQ number * - msn: Search for a MSN ID * - yahoo: Search for a Yahoo ID * - page: Which page of the list will we be retrieving * @return array */ function getMembers($data = array()) { /** * Make sure we have initial values in the data array */ $data['orderby'] = !isset($data['orderby']) ? 'u.`username`' : $data['orderby']; $data['orderdir'] = !isset($data['orderdir']) ? 'ASC' : strtoupper($data['orderdir']); $data['orderdir'] = $data['orderdir'] == 'ASC' ? 'ASC' : 'DESC'; $data['perpage'] = !isset($data['perpage']) ? (int) $this->mybb->settings['membersperpage'] : (int) $data['perpage']; $data['letter'] = !isset($data['letter']) ? '' : $data['letter']; $data['username'] = !isset($data['username']) ? '' : $data['username']; $data['username_match'] = !isset($data['username_match']) ? 'begins' : $data['username_match']; $data['website'] = !isset($data['website']) ? '' : $data['website']; $data['aim'] = !isset($data['aim']) ? '' : $data['aim']; $data['icq'] = !isset($data['icq']) ? '' : $data['icq']; $data['msn'] = !isset($data['msn']) ? '' : $data['msn']; $data['yahoo'] = !isset($data['yahoo']) ? '' : $data['yahoo']; $data['page'] = !isset($data['page']) ? 1 : (int) $data['page']; /** * Let's build the DB query now! */ $sql_where = 'WHERE 1 = 1'; // Username begins with a letter or number if (strlen($data['letter']) == 1) { $data['letter'] = chr(ord($data['letter'])); // Letter is 0: Shall start with number if ($data['letter'] == '0') { $sql_where .= " AND u.`username` NOT REGEXP('[a-zA-Z]')"; } else { $sql_where .= " AND u.`username` LIKE '" . $this->db->escape_string($data['letter']) . "%'"; } } // Search for matching username if (strlen($data['username']) > 0) { $data['username'] = htmlspecialchars_uni($data['username']); if ($data['username_match'] == 'begins') { $sql_where .= " AND u.`username` LIKE '" . $this->db->escape_string_like($data['username']) . "%'"; } else { $sql_where .= " AND u.`username` LIKE '%" . $this->db->escape_string_like($data['username']) . "%'"; } } // Search for website if (strlen($data['website']) > 0) { $data['website'] = trim(htmlspecialchars_uni($data['website'])); $sql_where .= " AND u.`website` LIKE '%" . $this->db->escape_string_like($data['website']) . "%'"; } // Search for AIM if (strlen($data['aim']) > 0) { $sql_where .= " AND u.`aim` LIKE '%" . $this->db->escape_string_like($data['aim']) . "%'"; } // Search for ICQ if (strlen($data['icq']) > 0) { $sql_where .= " AND u.`icq` LIKE '%" . $this->db->escape_string_like($data['icq']) . "%'"; } // Search for MSN if (strlen($data['msn']) > 0) { $sql_where .= " AND u.`msn` LIKE '%" . $this->db->escape_string_like($data['msn']) . "%'"; } // Search for Yahoo if (strlen($data['yahoo']) > 0) { $sql_where .= " AND u.`yahoo` LIKE '%" . $this->db->escape_string_like($data['yahoo']) . "%'"; } // Build the LIMIT-part of the query here if ($data['perpage'] == 0) { $limit_string = ''; } else { if ($data['page'] > 0) { $limit_string = 'LIMIT ' . ($data['page'] - 1) * $data['perpage'] . ', ' . $data['perpage']; } else { $limit_string = 'LIMIT ' . $data['perpage']; } } $sql .= ' SELECT u.*, f.* FROM ' . TABLE_PREFIX . 'users u LEFT JOIN ' . TABLE_PREFIX . 'userfields f ON f.`ufid` = u.`uid` ' . $sql_where . ' ORDER BY ' . $data['orderby'] . ' ' . $data['orderdir'] . ' ' . $limit_string . ' '; $query = $this->db->query($sql); $arr = array(); while ($member = $this->db->fetch_array($query)) { $arr[] = $member; } return $arr; }
/** * Returns the popular tags * pass searchStr in the parameters to narrow the tags * * @param array $params * searchStr string -- return only tags that contain this string * @param object $db -- the database object * @param bool $check_only --whether we run the query, or just validate that we can run it. * * @return vB_dB_Result -- The query result */ function getPopularTags($params, $db, $check_only = false) { if ($check_only) { return isset($params[vB_dB_Query::PARAM_LIMIT]) and isset($params['offset']); } $params = vB::getCleaner()->cleanArray($params, array('searchStr' => vB_Cleaner::TYPE_STR, vB_dB_Query::PARAM_LIMIT => vB_Cleaner::TYPE_UINT, 'offset' => vB_Cleaner::TYPE_UINT)); $where = false; if (!empty($params['searchStr'])) { $where = " WHERE tag.tagtext LIKE '" . $db->escape_string_like($params['searchStr']) . "%'"; } $sql = "\n\t\t\tSELECT tag.tagtext, tagnode.userid, tag.tagid, count(tag.tagid) AS nr\n\t\t\tFROM " . TABLE_PREFIX . "tag AS tag\n\t\t\t\tJOIN " . TABLE_PREFIX . "tagnode AS tagnode ON (tag.tagid = tagnode.tagid)\n\t\t\t{$where}\n\t\t\tGROUP BY tag.tagid\n\t\t\tORDER BY nr DESC, tag.tagtext ASC\n\t\t\tLIMIT " . $params[vB_dB_Query::PARAM_LIMIT] . " OFFSET " . $params['offset'] . "\n\t\t\t/** getPopularTags " . (defined('THIS_SCRIPT') ? '- ' . THIS_SCRIPT : '') . "**/"; $resultclass = 'vB_dB_' . $this->db_type . '_result'; $config = vB::getConfig(); if (isset($config['Misc']['debug_sql']) and $config['Misc']['debug_sql']) { echo "sql: {$sql}<br />\n"; } $result = new $resultclass($db, $sql); return $result; }