Dec 21, 2011 11:24 PM
Branching from this thread:
https://hackforums.net/showthread.php?tid=2033878
I ended making a userscript tutorial earlier ( https://hackforums.net/showthread.php?tid=2034312 ) and now I am following up with a simple MyBB plugin tutorial. I try to assume that you know something about PHP, but I still explain as much as possible. This tutorial is split into two ~14 minute segments.
Enjoy :)
Part 1:
Part 2:
Entire code:
Spoiler (Click to View)
https://hackforums.net/showthread.php?tid=2033878
I ended making a userscript tutorial earlier ( https://hackforums.net/showthread.php?tid=2034312 ) and now I am following up with a simple MyBB plugin tutorial. I try to assume that you know something about PHP, but I still explain as much as possible. This tutorial is split into two ~14 minute segments.
Enjoy :)
Part 1:
Part 2:
Entire code:
Spoiler (Click to View)
PHP Code
<?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("misc_start", "showreferals_view");
function showreferals_info()
{
return array(
'name' => 'Show Referals',
'description' => 'This plugin will let you see who members referred.',
'website' => 'http://www.xerotic.net',
'author' => 'Xerotic',
'authorsite' => 'http://www.xerotic.net',
'version' => '1.0',
"guid" => "",
"compatibility" => "16*"
);
}
function showreferals_activate()
{
require "../inc/adminfunctions_templates.php";
find_replace_templatesets("usercp_referrals", '#<br />#', ' <span class="smalltext">[<a href="misc.php?action=referrals">WARNING: Potential SPAM or INFECTED LINK</a>]</span><br />');
find_replace_templatesets("member_profile_referrals", '#'.preg_quote('{$memprofile[\'referrals\']}').'#', '<a href="misc.php?action=referrals&uid={$memprofile[\'uid\']}">{$memprofile[\'referrals\']}</a>');
}
function showreferals_deactivate()
{
require "../inc/adminfunctions_templates.php";
find_replace_templatesets("usercp_referrals", '#'.preg_quote(' <span class="smalltext">[<a href="misc.php?action=referrals">WARNING: Potential SPAM or INFECTED LINK</a>]</span>').'#', '',0);
find_replace_templatesets("member_profile_referrals", '#'.preg_quote('<a href="misc.php?action=referrals&uid={$memprofile[\'uid\']}">{$memprofile[\'referrals\']}</a>').'#', '{$memprofile[\'referrals\']}',0);
}
function showreferals_view()
{
global $mybb, $db, $lang;
if(!$mybb->user['uid']){
error_no_permission();
}
if($mybb->input['action'] != "referrals"){
return;
}
if($mybb->input['uid']){
$uid = intval($mybb->input['uid']);
} else {
$uid = $mybb->user['uid'];
}
$referral_html = '<table border="0" cellspacing="1" cellpadding="4" class="tborder">
<tr>
<td class="tcat" align="center"><strong>User</strong></td>';
if($mybb->usergroup['canmodcp']){
$referral_html .= '<td class="tcat" align="center"><strong>Last Known IP</strong></td>';
}
$referral_html .= '</tr>';
$query = $db->simple_select("users", "uid,username,usergroup,displaygroup,timeonline",
"referrer='$uid'", array("order_by" => 'uid',
"order_dir" => 'DESC'));
while($results = $db->fetch_array($query)){
$trow = alt_trow();
$referral_html .= '<tr>
<td class="'.$trow.'">' . build_profile_link(format_name($results['username'], $results['usergroup'], $results['displaygroup']), $results['uid']) . '</td>';
if($mybb->usergroup['canmodcp']){
$referral_html .= '<td class="'.$trow.'">' . $results['timeonline'] . '</td>';
}
$referral_html .= '</tr>';
}
$referral_html .= '</table>';
$query = $db->simple_select("users", "username",
"uid='$uid'");
$referrer_username = $db->fetch_field($query, "username");
$lang->error = "Referrals";
error($referral_html, "{$referrer_username}'s Referrals");
}
?>![[Image: DE93-ABEA-2-E28-4-F9-D-9-BB6-312-B3328937-E.png]](https://i.ibb.co/BcJWkqN/DE93-ABEA-2-E28-4-F9-D-9-BB6-312-B3328937-E.png)

