MyBB Community Forums

Full Version: RPG Searchable Face Claim Listing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Face Claim Listing
Tutorial Created By: isoldehn
Tutorial Permissions: Please do not re-post this tutorial else where, instead link someone to this thread.
- Additionally, you are NOT required to credit me if you use these codes on your board BUT I do wish for you to share this with those that ask about it if they ever do (share the knowledge, be kind).
Tutorial Needs: Overall, the ability to copy and paste.
- FTP/File Access To Web Space

I will at some point be attempting to make this an actual plugin, I just haven't gotten that far yet, so for now I will just share the templates/file.

Step One
Create the face claim file. Open your FTP client or file manager/file area of your web space. In your MyBB directory (usually located directly in public_html) create a new file called faceclaims.php and insert the following code.
<?php
// *********************************************************
// * Face Claim Listing by Isoldehn Affairs 2018.          *
// * Free for for general public usage and change!         *
// * Please do not claim as your own nor charge money to   *
// *  install this for others.                             *
// * If any issues contact isoldehn#4139 on Discord or     *
// *  visit https://isoaff.com/ for other contact options. *
// *********************************************************

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'faceclaims.php');
$templatelist = "faceclaims,faceclaims_entry,faceclaims_empty";
require "./global.php";
add_breadcrumb("Face Claim Listing", "faceclaims.php");


$query = $db->query("
SELECT *
FROM ".TABLE_PREFIX."users 
LEFT JOIN ".TABLE_PREFIX."userfields 
ON ".TABLE_PREFIX."users.uid = ".TABLE_PREFIX."userfields.ufid 
WHERE ".TABLE_PREFIX."users.usergroup IN (#,#,#,#)
ORDER BY username ASC
");
// WHERE ".TABLE_PREFIX."users.usergroup IN (#,#,#,#)
// ^ # = group id for usergroups you want to show on this listing, if only one group just put a number with no commas
// ORDER BY fid# ASC
// ^ if you don't want to order by username, # = field id for face claim profile field


while($users=$db->fetch_array($query)) {
    $users['avatar'] = $users['avatar'];
    $users['profilelink'] = $users['uid'];
    $users['username'] = format_name($users['username'], $users['usergroup'], $users['displaygroup']);
$users['faceclaim'] = $users['fid#'];
// fid# = # = field id for face claim profile field
if(!$users['faceclaim']) {
    }
else {
    eval("\$directory .= \"".$templates->get("faceclaims_entry")."\";");
}
}
if(!$directory) {
    eval("\$directory .= \"".$templates->get("faceclaims_empty")."\";");
}

eval("\$faceclaims = \"".$templates->get("faceclaims")."\";");
output_page($faceclaims);
?>
NOTE(S):
  • Be sure you change all traces of # to the correct ids needed. The file contains // notes for you to follow along to. Please find the notes and edit as suggested.
Step Two
Create new templates for our listing. Navigate to Admin CP --> Templates & Style --> Templates --> Global Templates --> Add New Template (for each one).

Template Name: faceclaims
<html>
	<head>
		<title>{$mybb->settings['bbname']} - Face Claim Listing</title>
		{$headerinclude}
	</head>
	<body>
		{$header}
		
		<table width ="100%" border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}">
			<tr>
				<td colspan="2" class="thead"><strong>Face Claim Listing</strong><input type="text" id="faceSearch" onkeyup="myFunction()" placeholder="Search for a face..." class="float_right" style="box-sizing: border-box; padding: 5px;"></td>
			</tr>
			<tr>
				<td class="tcat" width="50%">Character</td>
				<td class="tcat" width="50%">Face Claim</td>
			</tr>
		</table>
		<table width ="100%" border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" id="faceTable">
			{$directory}
		</table>
		
		{$footer}
		<script>
			function myFunction() {
			var input, filter, table, tr, td, i;
			input = document.getElementById("faceSearch");
			filter = input.value.toUpperCase();
			table = document.getElementById("faceTable");
			tr = table.getElementsByTagName("tr");
			for (i = 0; i < tr.length; i++) {
				td = tr[i].getElementsByTagName("td")[2];
				if (td) {
					if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
						tr[i].style.display = "";
						}
					else {
						tr[i].style.display = "none";
						}
					}       
				}
			}
		</script>
		<!--
				FILTER TABLE SCRIPT BY W3SCHOOLS
				https://www.w3schools.com/howto/howto_js_filter_table.asp
		-->
	</body>
</html>

Template Name: faceclaims_entry
<tr>
	<td class="trow1" width="50px">
		<a href="{$users['profilelink']}">
			<img src="{$users['avatar']}" onerror="this.onerror=null;this.src='/images/default_avatar.png';" width="50px" height="50px" style="border-radius: 50%;" />
		</a>
		<!-- You may have to change the default avatar file name/type. Depending on your default avatar URL. -->
	</td>
	<td class="trow1">
		<a href="/member.php?action=profile&amp;uid={$users['profilelink']}">
			{$users['username']}
		</a>
	</td>
	<td class="trow1" width="50%">
		{$users['faceclaim']}
	</td>
</tr>

Template Name: faceclaims_empty
<tr>
	<td class="trow1" colspan="2" align="center">
		<i>There are currently no characters with face claims applicable. Please check back at a later date.</i>
	</td>
</tr>