Hello There, Guest!
View New Posts  |  View Recent Posts
Video Tutorial - Create a simple MyBB Plugin

  • 0 Vote(s) - 0 Average


12-22-2012, 01:42 PM #1
KoBE
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,743 Threads:466 Joined: Jun 2011 Reputation: 64

Video Tutorial - Create a simple MyBB Plugin
Hey guys,

Here is the video I promised.. :D Below it, is the full source code.
Here is a list of MyBB Hooks that will help you if you are wanting to create plugins for other things in MyBB:
http://docs.mybb.com/MyBB_Plugin_Hooks.html





PHP Code:
<?php
/***************************************************************************
 *
 *  Referrer Log plugin (/inc/plugins/ReferralPlugin.php)
 *  Author: KoBE
 *  
 *  Website: http://tech.reboot.pro
 *  License: Free to use. Free to modify. Keep the credits.
 *
 *  If you like this, please support TechLifeForum by
 *    joining today.
 *
 ***************************************************************************/

// Hooks
$plugins->add_hook("member_profile_start","ReferralPlugin");
$plugins->add_hook('misc_start','ReferralPlugin_ShowReferrals');

function 
ReferralPlugin_info(){
    return array(
        
"name"            => "Referrer Log",
        
"description"    => "This plugin displays a log of referrals for each user.",
        
"website"        => "http://tech.reboot.pro",
        
"author"        => "TechLifeForum",
        
"authorsite"    => "http://tech.reboot.pro/member.php?action=profile&uid=2",
        
"guid"            => "5aad1ff545a194ff41c98b2b0605dc00",
        
"version"        => "1.0"
    
);
}

function 
ReferralPlugin_activate(){
    global 
$db;
    
    
// create a setting group to house our setting
    
$ReferralPlugin = array(
        
"name"            => "ReferralPlugin",
        
"title"         => "Referral Plugin",
        
"description"    => "Enable or disable the referrer plugin.",
        
"disporder"        => "0",
        
"isdefault"        => "no",
    );
    
    
// insert the setting group into the database
    
$db->insert_query("settinggroups"$ReferralPlugin);
    
    
// grab insert ID of the setting group
    
$gid intval($db->insert_id());
    
    
// we're only going to insert 1 setting
    
$setting = array(
        
"name"            => "ReferralPlugin_enabled",
        
"title"            => "Enabled",
        
"description"    => "Determine if you want to enable this plugin",
        
"optionscode"    => "yesno",
        
"value"            => "1",
        
"disporder"        => 1,
        
"gid"            => $gid
        
);
    
    
$db->insert_query("settings"$setting);
    
rebuildsettings();
    
    
$template = array(
        
"tid"        => NULL,
        
"title"        => "ReferralPlugin_log",
        
"template"    => '
<html>
    <head>
        <title>Referrals</title>
        {$headerinclude}
    </head>
    <body>
        {$header}
        <h2>Referral Log for: KoBE</h2>
        <br />
        <table class="tborder">
            <tr class="thead">
                <th><strong>Referral Username:</strong></th>
                <th><strong>Date Referred:</strong></th>
            </tr>
            {$referrals}
        </table>
        {$footer}
    </body>
</html>'
,
        
"sid"        => "-1"
    
);
    
    
// insert template into the database
    
$db->insert_query("templates"$template);
    
    
// require the file that has the function needed to make a template edit
    
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    
    
// go to the template member_profile_referrals, and replace
    // the text {$memprofile['referrals']} with {$memprofile['referrals']}{$details}
    
find_replace_templatesets("member_profile_referrals""#".preg_quote('{$memprofile[\'referrals\']}')."#i"'{$memprofile[\'referrals\']}{$details}');
}

function 
ReferralPlugin_deactivate(){
    global 
$db;
    
    
// delete our setting/setting group/template
    
$db->delete_query("settings","name LIKE 'ReferralPlugin_%'");
    
$db->delete_query("settinggroups","name LIKE 'ReferralPlugin'");
    
$db->delete_query("templates""title LIKE 'ReferralPlugin_%'");
    
    
// require the file that has the function needed to make a template edit
    
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    
find_replace_templatesets("member_profile_referrals""#".preg_quote('{$details}')."#i"'');
}

function 
ReferralPlugin(){
    global 
$templates$mybb$details;
    
    
// if the plugin setting isn't enabled then exit
    
if($mybb->settings['ReferralPlugin_enabled'] != 1)
        return;
    
    
$details " <a href=\"misc.php?action=referrals&uid=".$mybb->input['uid']."\">[Details]</a>";
    eval(
"\$referrals = \"".$templates->get("member_profile_referrals")."\";");
    
}

function 
ReferralPlugin_ShowReferrals(){
    global 
$mybb$db$headerinclude$header$footer$templates;
    
    
// check if the user viewing the page is logged in
    
if ($mybb->user['uid']){

        
// Since this page is the misc.php check to see if
        // they are here because of our plugin
        // p.s. - mybb sanitizes the input for you
        
if($mybb->input['action']== "referrals" && $mybb->input['uid']){
            
            
// if the plugin setting isn't enabled then exit
            
if($mybb->settings['ReferralPlugin_enabled'] != 1)
                return;
                
            
// get the uid of the profile we want
            
$grabuser $db->simple_select("users""username""uid = ".$mybb->input['uid']);
            
            
// grab an array of the record for that user
            
$user $db->fetch_array($grabuser);
            
            
// $username is holding a place in our template
            
$username $user['username'];
            
            
// grab every record from the users table who
            // has this user UID as their referrer
            
$query $db->simple_select("users""username,uid,regdate""referrer = ".$mybb->input['uid']);
            
            
// $referrals holds a place in our template
            
$referrals '';
            
            
// loop through each row in the database that 
            // matches our query and create a table row to display it
            
while($row $db->fetch_array($query)){
                
$referrals=$referrals."<tr class='trow1'><td><a href=\"member.php?action=profile&uid=".$row['uid']."\">".$row['username']."</a></td>
                <td>"
.my_date($mybb->settings['dateformat'], $row['regdate'])."  ".my_date($mybb->settings['timeformat'], $row['regdate'])."</td>
                </tr>"
;
            }
            
            
// grab our template
            
$template=$templates->get("ReferralPlugin_log");
            
            
// eval will fill replace the variables
            // in our template, with the values from above
            
eval("\$page=\"".$template."\";");
            
output_page($page);
        }
    }
}
?>
This post was last modified: 12-22-2012, 02:05 PM by KoBE.

12-22-2012, 02:32 PM #2
Epixors
(づ。◕‿‿◕。)づ・。*。✧・゜゜・。
*****
TLF Coders
Posts: 419 Threads:58 Joined: Aug 2012 Reputation: 6

RE: Video Tutorial - Create a simple MyBB Plugin
Nice video, I like it :) Also this was funny to see:


12-22-2012, 02:37 PM #3
KoBE
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,743 Threads:466 Joined: Jun 2011 Reputation: 64

RE: Video Tutorial - Create a simple MyBB Plugin
Haha, where did "and they're working on my feet" come from?

12-22-2012, 02:39 PM #4
Epixors
(づ。◕‿‿◕。)づ・。*。✧・゜゜・。
*****
TLF Coders
Posts: 419 Threads:58 Joined: Aug 2012 Reputation: 6

RE: Video Tutorial - Create a simple MyBB Plugin
It's the automatic sub thingy, it fails big time. It is hilarious though, turns out MyBB = Money.




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
  [JavaScript] Simple IRC Bot Louis 1 383 12-15-2014, 10:33 AM
Last Post: AZERTY9
  Funny Video - Java vs. .NET AceInfinity 5 1,755 05-21-2014, 06:45 PM
Last Post: ByteBlast
Exclamation Twitch.tv Bot Help or create Urgent! zapmaster14 5 1,923 05-30-2013, 05:43 PM
Last Post: AceInfinity
  [JavaScript/Node.js] Video Information Louis 5 1,874 04-01-2013, 12:30 AM
Last Post: Louis
  How should I store video files in DB? Shintaro 3 1,370 01-25-2013, 01:37 PM
Last Post: Adriana


Users browsing this thread: 1 Guest(s)