MyBB Source

Full Version: Catalog System
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I have an idea in my head for a Catalog system/plugin but I don't know where to start...Here is what I want it to do:
  • Add Items from the game Animal Crossing to users profile.
  • 3 categories (since their are 3 AC games)
  • Once you click a category it shows the items
  • Then you click 1 of 2 buttons (Want or Own)

Does that make sense? XD

I really want to learn to create plugins/mods and again I just don't know where to start :(
I would say you should start by gaining a knowledge of PHP. If you have that, then I suggest browsing through different plugins and see how they work.
Ok Thanks and I know some of the basics of PHP XD
Sorry to double post but is this right?

I am a complete newb at the Mybb plugin creation xP

PHP Code:
<?
/**
 *    Plugin Copyright
 *    TomNook08 of MyBBSource  
 */
 
if(!defined("IN_MYBB")) {
    die(
"This file cannot be accessed directly.");
}
//Add Your Hooks
$plugins->add_hook("HOOK NAME""FUNCTION_NAME");

//REQUIRED
function catalog_info()
{
    return array(
        
'name'            => 'Item Catalog',
        
'description'    => 'Adds Items from the Animal Crossing games to the users profile.',
        
'website'        => 'http://www.mybbsource.com',
        
'author'        => 'TomNook08',
        
'authorsite'    => 'http://www.animalcrossingcentral.com',
        
'version'        => '1.0',
    );
}

function 
catalog_activate() {
   global 
$db;
   
   require 
MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("header"'#'.preg_quote('</li>').'#''<li>hi</li></ul>');
//stuff to do on activation of the plugin
}
function 
catalog_deactive()
{
global 
$db;

    require 
MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("header"'#'.preg_quote('<li>hi</li></ul>').'#''</ul>'0);
}

function 
FUNCTION_NAME() {
    global 
$mybb,$db,$lang;
//DO SOMETHING WHEN THE HOOK IS CALLED
}


?>
(03-12-2009 08:43 AM)TomNook08 Wrote: [ -> ]Sorry to double post but is this right?

I am a complete newb at the Mybb plugin creation xP

PHP Code:
<?
/**
 *    Plugin Copyright
 *    TomNook08 of MyBBSource  
 */
 
if(!defined("IN_MYBB")) {
    die(
"This file cannot be accessed directly.");
}
//Add Your Hooks
$plugins->add_hook("HOOK NAME""FUNCTION_NAME");

//REQUIRED
function catalog_info()
{
    return array(
        
'name'            => 'Item Catalog',
        
'description'    => 'Adds Items from the Animal Crossing games to the users profile.',
        
'website'        => 'http://www.mybbsource.com',
        
'author'        => 'TomNook08',
        
'authorsite'    => 'http://www.animalcrossingcentral.com',
        
'version'        => '1.0',
    );
}

function 
catalog_activate() {
   global 
$db;
   
   require 
MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("header"'#'.preg_quote('</li>').'#''<li>hi</li></ul>');
//stuff to do on activation of the plugin
}
function 
catalog_deactive()
{
global 
$db;

    require 
MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("header"'#'.preg_quote('<li>hi</li></ul>').'#''</ul>'0);
}

function 
FUNCTION_NAME() {
    global 
$mybb,$db,$lang;
//DO SOMETHING WHEN THE HOOK IS CALLED
}


?>
Looks about right. Are you getting any issues or something?
Quote:Looks about right. Are you getting any issues or something?

No but what do I put where it says hook name and function name
PHP Code:
$plugins->add_hook("HOOK NAME""FUNCTION_NAME"); 

I have studied plugins over and over...I am just really new at this and its my first plugin :P
(03-12-2009 12:44 PM)TomNook08 Wrote: [ -> ]
Quote:Looks about right. Are you getting any issues or something?

No but what do I put where it says hook name and function name
PHP Code:
$plugins->add_hook("HOOK NAME""FUNCTION_NAME"); 

I have studied plugins over and over...I am just really new at this and its my first plugin :P

HOOK NAME is the hook found where you want to run your function. So if you want your plugin to run on every page, you might want to use global_end. FUNCTION_NAME is your own custom function.
Oh ok Thank you so much :)
I just got my very first error
I attached a picture and here is the code...

PHP Code:
<?php
/**
 *    Plugin Copyright
 *    TomNook08 of MyBBSource  
 */

if(!defined("IN_MYBB")) {
    die(
"This file cannot be accessed directly.");
}
//Add Your Hooks
$plugins->add_hook("member_profile_end""Show_Catalog");

//REQUIRED
function catalog_info()
{
    return array(
        
'name'            => 'Item Catalog',
        
'description'    => 'Adds Items from the Animal Crossing games to the users profile.',
        
'website'        => 'http://www.mybbsource.com',
        
'author'        => 'TomNook08',
        
'authorsite'    => 'mailto:[email protected]',
        
'version'        => '1.0',
        
'compatibility'     =>    '14*',

    );
}

function 
catalog_activate() {
   global 
$db;
       
    
$catalog_admin = array(
        
'gid'            => 'NULL',
        
'name'            => 'catalogadmin',
        
'title'            => 'Catalog Admin',
        
'description'    => 'Settings For The Catalog System.',
        
'disporder'        => $rows+1,
        
'isdefault'        => 'no',
    );

    
$db->insert_query('settinggroups'$catalog_admin);
    
$gid $db->insert_id();

    
$catalog_setting_1 = array(
        
'sid'            => 'NULL',
        
'name'            => 'enablecatalog',
        
'title'            => 'Enable Catalog System?',
        
'description'    => 'If set to off, no one will get a catalog',
        
'optionscode'    => 'onoff',
        
'value'            => 'on',
        
'disporder'        => 1,
        
'gid'            => intval($gid),
    );

    
$catalog_setting_2 = array(
        
'sid'            => 'NULL',
        
'name'            => 'showwhichgames',
        
'title'            => 'Show Which Game',
        
'description'    => 'Set to 1 to show only ACGC items, 2 to show only ACWW items, 3 to show ACCF/LGTTC items, or 0 for all 3 games',
        
'optionscode'    => 'text',
        
'value'            => '0',
        
'disporder'        => 2,
        
'gid'            => intval($gid),
    );
    
$catalog_setting_3 = array(

        
'sid'            => 'NULL',
        
'name'            => 'adminitems',
        
'title'            => 'Admin Remove Items?',
        
'description'    => 'Do you want admins to be able to remove items?',
        
'optionscode'    => 'onoff',
        
'value'            => 'off',
        
'disporder'        => 3,
        
'gid'            => intval($gid),
    );
    
$db->query("CREATE TABLE `".TABLE_PREFIX."catalog` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`memberid` INT NOT NULL)"
);
    
$db->insert_query('settings'$catalog_setting_1);
    
$db->insert_query('settings'$catalog_setting_2);
    
$db->insert_query('settings'$catalog_setting_3);
    require 
MYBB_ROOT."/inc/adminfunctions_templates.php";
    
find_replace_templatesets("member_profile"'#{\$signature}#'"{\$signature}\n{\$catalog}");
    
$template = array(
        
"title"        => "catalog",
        
"template"    => "<head>
<title>{\$mybb->settings[\'bbname\']} - Catalog</title>
{\$headerinclude}
</head>
<body>
    {\$header}
    <table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder\" style=\"clear: both;\">
        <tr>
            <td class=\"thead\"><strong>My Catalog</strong></td>
        </tr>
        <tr>
            <td class=\"trow1\"><br />
</td>
        </tr>
    </table>
    {\$footer}
</body>
</html>
"
,
        
"sid"        => -1
    
);
    
$db->insert_query("templates"$template);
//stuff to do on activation of the plugin
}
function 
catalog_deactive()
{
global 
$db;
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='catalogadmin'");
    
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN(
        'enablecatalog',
        'showwhichgames',
        'adminitems',
    )"
);
    
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='catalog'");
    
$db->query("DROP TABLE ".TABLE_PREFIX."catalog");
    require 
MYBB_ROOT."/inc/adminfunctions_templates.php";
    
find_replace_templatesets("member_profile"'#{\$catalog}(\r?)(\n?)#'''0);
}

function 
Show_Catalog() {
    global 
$memprofile,$mybb,$theme,$db,$lang,$templates;
    
//DO SOMETHING WHEN THE HOOK IS CALLED
}


?>
[attachment=225]

Oh perfect it stretched the page XD
Try changing 'NULL' to just NULL without the single quotes in the whole code.
Pages: 1 2 3
Reference URL's