Beispiel #1
0
/**
 * Primary query for the memberlist display, runs the query based on the users
 * sort and start selections.
 *  - Uses printMemberListRows to load the query results in to context
 *
 * @param mixed[] $query_parameters
 * @param string|string[]|null $customJoin
 * @param string $where
 * @param int $limit
 * @return integer
 */
function ml_searchMembers($query_parameters, $customJoin = '', $where = '', $limit = 0)
{
    global $modSettings;
    $db = database();
    // Get the number of results
    $request = $db->query('', '
		SELECT COUNT(*)
		FROM {db_prefix}members AS mem
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' . (empty($customJoin) ? '' : implode('
			', $customJoin)) . '
		WHERE (' . $where . ')
			AND mem.is_activated = {int:is_activated}', $query_parameters);
    list($numResults) = $db->fetch_row($request);
    $db->free_result($request);
    // Select the members from the database.
    $request = $db->query('', '
		SELECT mem.id_member
		FROM {db_prefix}members AS mem
			LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' . (empty($customJoin) ? '' : implode('
			', $customJoin)) . '
		WHERE (' . $where . ')
			AND mem.is_activated = {int:is_activated}
		ORDER BY {raw:sort}
		LIMIT ' . $limit . ', ' . $modSettings['defaultMaxMembers'], $query_parameters);
    // Place everything context so the template can use it
    printMemberListRows($request);
    $db->free_result($request);
    return $numResults;
}
function MLSearch()
{
    global $txt, $scripturl, $context, $user_info, $modSettings, $smcFunc;
    $context['page_title'] = $txt['mlist_search'];
    $context['can_moderate_forum'] = allowedTo('moderate_forum');
    // Can they search custom fields?
    $request = $smcFunc['db_query']('', '
		SELECT col_name, field_name, field_desc
		FROM {db_prefix}custom_fields
		WHERE active = {int:active}
			' . (allowedTo('admin_forum') ? '' : ' AND private < {int:private_level}') . '
			AND can_search = {int:can_search}
			AND (field_type = {string:field_type_text} OR field_type = {string:field_type_textarea})', array('active' => 1, 'can_search' => 1, 'private_level' => 2, 'field_type_text' => 'text', 'field_type_textarea' => 'textarea'));
    $context['custom_search_fields'] = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $context['custom_search_fields'][$row['col_name']] = array('colname' => $row['col_name'], 'name' => $row['field_name'], 'desc' => $row['field_desc']);
    }
    $smcFunc['db_free_result']($request);
    // They're searching..
    if (isset($_REQUEST['search']) && isset($_REQUEST['fields'])) {
        $_POST['search'] = trim(isset($_GET['search']) ? $_GET['search'] : $_POST['search']);
        $_POST['fields'] = isset($_GET['fields']) ? explode(',', $_GET['fields']) : $_POST['fields'];
        $context['old_search'] = $_REQUEST['search'];
        $context['old_search_value'] = urlencode($_REQUEST['search']);
        // No fields?  Use default...
        if (empty($_POST['fields'])) {
            $_POST['fields'] = array('name');
        }
        $query_parameters = array('regular_id_group' => 0, 'is_activated' => 1, 'blank_string' => '', 'search' => '%' . strtr($smcFunc['htmlspecialchars']($_POST['search'], ENT_QUOTES), array('_' => '\\_', '%' => '\\%', '*' => '%')) . '%');
        // Search for a name?
        if (in_array('name', $_POST['fields'])) {
            $fields = array('member_name', 'real_name');
        } else {
            $fields = array();
        }
        // Search for messengers...
        if (in_array('messenger', $_POST['fields']) && (!$user_info['is_guest'] || empty($modSettings['guest_hideContacts']))) {
            $fields += array(3 => 'msn', 'aim', 'icq', 'yim');
        }
        // Search for websites.
        if (in_array('website', $_POST['fields'])) {
            $fields += array(7 => 'website_title', 'website_url');
        }
        // Search for groups.
        if (in_array('group', $_POST['fields'])) {
            $fields += array(9 => 'IFNULL(group_name, {string:blank_string})');
        }
        // Search for an email address?
        if (in_array('email', $_POST['fields'])) {
            $fields += array(2 => allowedTo('moderate_forum') ? 'email_address' : '(hide_email = 0 AND email_address');
            $condition = allowedTo('moderate_forum') ? '' : ')';
        } else {
            $condition = '';
        }
        $customJoin = array();
        $customCount = 10;
        // Any custom fields to search for - these being tricky?
        foreach ($_POST['fields'] as $field) {
            $curField = substr($field, 5);
            if (substr($field, 0, 5) == 'cust_' && isset($context['custom_search_fields'][$curField])) {
                $customJoin[] = 'LEFT JOIN {db_prefix}themes AS t' . $curField . ' ON (t' . $curField . '.variable = {string:t' . $curField . '} AND t' . $curField . '.id_theme = 1 AND t' . $curField . '.id_member = mem.id_member)';
                $query_parameters['t' . $curField] = $curField;
                $fields += array($customCount++ => 'IFNULL(t' . $curField . '.value, {string:blank_string})');
            }
        }
        $query = $_POST['search'] == '' ? '= {string:blank_string}' : 'LIKE {string:search}';
        $request = $smcFunc['db_query']('', '
			SELECT COUNT(*)
			FROM {db_prefix}members AS mem
				LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' . (empty($customJoin) ? '' : implode('
				', $customJoin)) . '
			WHERE (' . implode(' ' . $query . ' OR ', $fields) . ' ' . $query . $condition . ')
				AND mem.is_activated = {int:is_activated}', $query_parameters);
        list($numResults) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        $context['page_index'] = constructPageIndex($scripturl . '?action=mlist;sa=search;search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']), $_REQUEST['start'], $numResults, $modSettings['defaultMaxMembers']);
        // Find the members from the database.
        // !!!SLOW This query is slow.
        $request = $smcFunc['db_query']('', '
			SELECT mem.id_member
			FROM {db_prefix}members AS mem
				LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
				LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' . (empty($customJoin) ? '' : implode('
				', $customJoin)) . '
			WHERE (' . implode(' ' . $query . ' OR ', $fields) . ' ' . $query . $condition . ')
				AND mem.is_activated = {int:is_activated}
			LIMIT ' . $_REQUEST['start'] . ', ' . $modSettings['defaultMaxMembers'], $query_parameters);
        printMemberListRows($request);
        $smcFunc['db_free_result']($request);
    } else {
        // These are all the possible fields.
        $context['search_fields'] = array('name' => $txt['mlist_search_name'], 'email' => $txt['mlist_search_email'], 'messenger' => $txt['mlist_search_messenger'], 'website' => $txt['mlist_search_website'], 'group' => $txt['mlist_search_group']);
        foreach ($context['custom_search_fields'] as $field) {
            $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
        }
        // What do we search for by default?
        $context['search_defaults'] = array('name', 'email');
        $context['sub_template'] = 'search';
        $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? htmlspecialchars($_POST['search']) : '');
    }
    $context['linktree'][] = array('url' => $scripturl . '?action=mlist;sa=search', 'name' => &$context['page_title']);
}
Beispiel #3
0
function MLSearch()
{
    global $txt, $scripturl, $db_prefix, $context, $user_info, $modSettings;
    $context['page_title'] = $txt['mlist_search'];
    // They're searching..
    if (isset($_REQUEST['search']) && isset($_REQUEST['fields'])) {
        $_POST['search'] = trim(isset($_GET['search']) ? $_GET['search'] : $_POST['search']);
        $_POST['fields'] = isset($_GET['fields']) ? explode(',', $_GET['fields']) : $_POST['fields'];
        $context['old_search'] = $_REQUEST['search'];
        $context['old_search_value'] = urlencode($_REQUEST['search']);
        // No fields?  Use default...
        if (empty($_POST['fields'])) {
            $_POST['fields'] = array('name');
        }
        // Search for a name?
        if (in_array('name', $_POST['fields'])) {
            $fields = array('memberName', 'realName');
        } else {
            $fields = array();
        }
        // Search for messengers...
        if (in_array('messenger', $_POST['fields']) && (!$user_info['is_guest'] || empty($modSettings['guest_hideContacts']))) {
            $fields += array(3 => 'MSN', 'AIM', 'ICQ', 'YIM');
        }
        // Search for websites.
        if (in_array('website', $_POST['fields'])) {
            $fields += array(7 => 'websiteTitle', 'websiteUrl');
        }
        // Search for groups.
        if (in_array('group', $_POST['fields'])) {
            $fields += array(9 => 'IFNULL(groupName, \'\')');
        }
        // Search for an email address?
        if (in_array('email', $_POST['fields'])) {
            $fields += array(2 => allowedTo('moderate_forum') ? 'emailAddress' : '(hideEmail = 0 AND emailAddress');
            $condition = allowedTo('moderate_forum') ? '' : ')';
        } else {
            $condition = '';
        }
        $query = $_POST['search'] == '' ? "= ''" : "LIKE '%" . strtr($_POST['search'], array('_' => '\\_', '%' => '\\%', '*' => '%')) . "%'";
        $request = db_query("\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM {$db_prefix}members AS mem\n\t\t\t\tLEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))\n\t\t\tWHERE " . implode(" {$query} OR ", $fields) . " {$query}{$condition}\n\t\t\t\tAND is_activated = 1", __FILE__, __LINE__);
        list($numResults) = mysql_fetch_row($request);
        mysql_free_result($request);
        $context['page_index'] = constructPageIndex($scripturl . '?action=mlist;sa=search;search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']), $_REQUEST['start'], $numResults, $modSettings['defaultMaxMembers']);
        // Find the members from the database.
        // !!!SLOW This query is slow.
        $request = db_query("\n\t\t\tSELECT mem.ID_MEMBER\n\t\t\tFROM {$db_prefix}members AS mem\n\t\t\t\tLEFT JOIN {$db_prefix}log_online AS lo ON (lo.ID_MEMBER = mem.ID_MEMBER)\n\t\t\t\tLEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))\n\t\t\tWHERE " . implode(" {$query} OR ", $fields) . " {$query}{$condition}\n\t\t\t\tAND is_activated = 1\n\t\t\tLIMIT {$_REQUEST['start']}, {$modSettings['defaultMaxMembers']}", __FILE__, __LINE__);
        printMemberListRows($request);
        mysql_free_result($request);
    } else {
        $context['sub_template'] = 'search';
        $context['old_search'] = isset($_REQUEST['search']) ? htmlspecialchars($_REQUEST['search']) : '';
    }
    $context['linktree'][] = array('url' => $scripturl . '?action=mlist;sa=search', 'name' => &$context['page_title']);
}