2010-03-26, 03:15 PM
Hi,
this is a hack for Advanced Memberlist Search. By default it is not possible to filter the search result with the help custom profile fields. But with this simple code modification it becomes possible!
Known limitations:
*If you really need to search in textareas just ask for it and I will provide the code modification.
*There exist no hooks, so it's not possible to make it as a plugin. Of course you can copy the whole code of memberlist.php into a plugin file and use the memberlist_start hook, but this would be a crappy way...
If you are not able to do the hack yourself you can use the attached memberlist.php (wow, we are at MyBB 1.4.11 and this file wasn't modified since 2009-01-31 ). But you still have to add the variable {$customfields} to the template.
License: GPL
this is a hack for Advanced Memberlist Search. By default it is not possible to filter the search result with the help custom profile fields. But with this simple code modification it becomes possible!
- Open file memberlist.php in an appropriate file editor.
- Find:
// Showing advanced search page? if($mybb->input['action'] == "search") { eval("\$search_page = \"".$templates->get("memberlist_search")."\";"); $plugins->run_hooks("memberlist_search"); output_page($search_page); }
- Replace with:
// Showing advanced search page? if($mybb->input['action'] == "search") { $altbg = "trow2"; $query = $db->simple_select("profilefields", "*", "type!='checkbox' AND type!='multiselect' AND type!='textarea' AND editable=1 AND hidden=0", array('order_by' => 'disporder')); while($profilefield = $db->fetch_array($query)) { $profilefield['type'] = htmlspecialchars_uni($profilefield['type']); $thing = explode("\n", $profilefield['type'], "2"); $type = $thing[0]; $options = $thing[1]; $field = "fid{$profilefield['fid']}"; $select = '<option value=""></option>'; $userfield = $user[$field]; if($type == "select") { $expoptions = explode("\n", $options); if(is_array($expoptions)) { foreach($expoptions as $key => $val) { $val = trim($val); $val = str_replace("\n", "\\n", $val); $select .= "<option value=\"{$val}\">{$val}</option>"; } if(!$profilefield['length']) { $profilefield['length'] = 1; } $code = "<select id=\"{$field}\" name=\"{$field}\" size=\"{$profilefield['length']}\">{$select}</select>"; } } elseif($type == "radio") { $expoptions = explode("\n", $options); if(is_array($expoptions)) { foreach($expoptions as $key => $val) { $code .= "<input type=\"radio\" class=\"radio\" name=\"{$field}\" value=\"{$val}\" /> <span class=\"smalltext\">{$val}</span><br />"; } } } else { $maxlength = ""; if($profilefield['maxlength'] > 0) { $maxlength = " maxlength=\"{$profilefield['maxlength']}\""; } $code = "<input id=\"{$field}\" type=\"text\" name=\"{$field}\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"\" />"; } if($type != "radio") { $profilefield['name']="<label for=\"{$field}\">{$profilefield['name']}</label>"; } $customfields.="<tr><td class=\"{$altbg}\"><strong>{$profilefield['name']}</strong></td><td class=\"{$altbg}\">{$code}</td></tr>"; $altbg = alt_trow(); $code = ""; $select = ""; $val = ""; $options = ""; $expoptions = ""; } eval("\$search_page = \"".$templates->get("memberlist_search")."\";"); $plugins->run_hooks("memberlist_search"); output_page($search_page); }
- Find:
$query = $db->simple_select("users u", "COUNT(*) AS users", "{$search_query}");
- Replace with:
$query = $db->query(" SHOW FULL COLUMNS FROM ".TABLE_PREFIX."userfields "); $columns = 1; while($rows = $db->fetch_array($query)) { if(trim($mybb->input['fid'.$columns])) { $search_query .= " AND f.fid".$columns." LIKE '%".$db->escape_string_like($mybb->input['fid'.$columns])."%'"; $search_url .= "&fid".$columns."=".urlencode($mybb->input['fid'.$columns]); } $columns++; } $query = $db->query(" SELECT COUNT(*) AS users FROM ".TABLE_PREFIX."users u LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid) WHERE {$search_query} ");
- Find:
- Go into your ACP and open the template memberlist_search.
- Find:
<tr> <td class="trow1" style="vertical-align: top;" width="20%"><strong><label for="username">{$lang->username}</label></strong></td> <td class="trow1"> <select name="username_match"> <option value="begins">{$lang->begins_with}</option> <option value="contains">{$lang->username_contains}</option> </select> <input type="text" class="textbox" name="username" id="username" /> </td> </tr> <tr> <td class="trow2" width="20%"><strong><label for="website">{$lang->search_website}</label></strong></td> <td class="trow2"> <input type="text" class="textbox" name="website" id="website" /> </td> </tr>
- Replace with:
(or add the variable {$customfields} wherever you want)<tr> <td class="trow1" style="vertical-align: top;" width="20%"><strong><label for="username">{$lang->username}</label></strong></td> <td class="trow1"> <select name="username_match"> <option value="begins">{$lang->begins_with}</option> <option value="contains">{$lang->username_contains}</option> </select> <input type="text" class="textbox" name="username" id="username" /> </td> </tr> {$customfields} <tr> <td class="trow2" width="20%"><strong><label for="website">{$lang->search_website}</label></strong></td> <td class="trow2"> <input type="text" class="textbox" name="website" id="website" /> </td> </tr>
- Find:
Known limitations:
- Multi value fields are not supported
- Textareas are not supported (because I think it's pointless to search within a textarea)*
- It's not a plugin*
*If you really need to search in textareas just ask for it and I will provide the code modification.
*There exist no hooks, so it's not possible to make it as a plugin. Of course you can copy the whole code of memberlist.php into a plugin file and use the memberlist_start hook, but this would be a crappy way...
If you are not able to do the hack yourself you can use the attached memberlist.php (wow, we are at MyBB 1.4.11 and this file wasn't modified since 2009-01-31 ). But you still have to add the variable {$customfields} to the template.
License: GPL