MyBB-Plugins Forums

Full Version: Newpoints plugin basics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I can't even get my plugin to show "Test" on the page where I'm working on. I do know PHP, I know how to search functions so I can do what I want. What I can't do it look up all the MyBB specific hooks and variables, which I have posted about earlier, in the coding help section.

Don't yell at me because I don't know MyBB hooks, I've been trying for 4 hours and yet the only things I've been able to are:
  • Break my website, make all pages show the $vip_bit
  • Get an entire white website
  • Get a white page when action=vipstatus
  • Show what I want on all pages, but the one I need it on

Why isn't there a tutorial to create newpoints plugins and such? I've looked up the "Hello" plugin. This basically shows how to print stuff on ALL pages, which is not what I want. After reading the "Important info for developers" in the newpoints plugin section, I added the tab to the menu.

I also read the developers.html and this didn't help me with what I need. Small tip for this: Make it more clear what is what. right now you have lines like:
@param integer the id of the user

Why don't you format it a little more, looking like:
@param | integer | The ID of the user

Then, I also tried to read the lottery, subscriptions and buynametitle plugins, but even after reading that and trying out a lot of hooks, I still haven't been able to get this to work. Mostly because I'm not working with templates I think, because I want to have everything easy without having to place variables in a template such as {$amount} or anything similar. Could I please get some proper explained post and not "look in there or else get the hell out", even if I want to learn, I'd like to have some easier examples, for some people it's really annoying to read the code of someone else.
(11-30-2012, 04:19 AM)Cyberuben Wrote: [ -> ]Why isn't there a tutorial to create newpoints plugins and such?
Because I didn't have the time to write one yet or when I did, I preferred to something else.

(11-30-2012, 04:19 AM)Cyberuben Wrote: [ -> ]I've looked up the "Hello" plugin. This basically shows how to print stuff on ALL pages, which is not what I want.
Yes, that plugin uses the global_end or global_start hook if I remember correctly.
You want to use a different hook.

(11-30-2012, 04:19 AM)Cyberuben Wrote: [ -> ]Small tip for this: Make it more clear what is what. right now you have lines like:
@param integer the id of the user

Why don't you format it a little more, looking like:
@param | integer | The ID of the user

I try to stick to PHPDoc's format: http://manual.phpdoc.org/HTMLSmartyConve...m.pkg.html

(11-30-2012, 04:19 AM)Cyberuben Wrote: [ -> ]Could I please get some proper explained post and not "look in there or else get the hell out", even if I want to learn, I'd like to have some easier examples, for some people it's really annoying to read the code of someone else.

What do you want me to explain? How NewPoints Plugins work? Is that it?


PS. Regarding hooks, I believe there's no easier example than the one Sama34 posted here: http://forums.mybb-plugins.com/Thread-Ho...6#pid53146

This is what a hook does:
a) MyBB loads plugins (using require_once ) and obviously every bit of global code is executed, including every $plugins->add_hook("hookname", "myfunction");
b) Then, once MyBB executes $plugins->run_hook("hookname"), all functions which have been added to that hook (in our case above, myfunction() ) will be executed. It's as simple as that.
c) Then it's just as if you were calling myfunction() from the same place as $plugins->run_hook("hookname"); You treat global variables as global variables, local variables as global variables, etc.
I just can't seem to find out how to get the correct hooks to get my page to output in this area:
http://puu.sh/1vGCl

This is basically the only problem I've got problems with.
You can alter the $page variable by using this hook newpoints_buynametitle_end but you should edit the template when installing/activating your plugin instead.
No I don't want to add anything to that page, but what I'm trying to say is that I want to have the exact same page, but with my own content in the specified box, that is the thing I can't seem to get working.

Methods I'm looking for (just as example):
$page = "<html>";
$page .= "<head>";

or with just including it in one $page, but I'm not familiar with templates and language files yet, and I just want to start with creating some plugins for my own forum, then I'm going to add more "functionality" so I can release it one day.

Short: I do want to alter a page, but I don't really get how I'd have to do that.

Actually, I don't mind using languagefiles and templates, but I'd like to have some explanation how to use them and such.
If you look at the Buy Username and Usertitle plugin, you'll see that it adds two hooks:
PHP Code:
    // show plugin in the menu
    
$plugins->add_hook("newpoints_default_menu""newpoints_buynametitle_menu");
    
    
// page
    
$plugins->add_hook("newpoints_start""newpoints_buynametitle_page"); 

The first is to run a function to add an entry to the menu. The second is the actual page code which ends up outputting a template. Though you could set $page to something else, instead of eval'ing it.
Yes, but that's the thing that I can't get in my head.

Right now, I have the following code:
PHP Code:
$plugins->add_hook("newpoints_start""newpoints_vipstatus");
$plugins->add_hook("newpoints_default_menu""newpoints_vipstatus_menu");

function 
newpoints_vipstatus($page)
{
        
    global 
$mybb$db$lang$cache$theme$header$templates$plugins$headerinclude$footer$options$inline_errors;
    
    echo 
"test";


http://casualbananas.com/forums/newpoints.php
Right now, it shows "Test" on all pages, while I only want it to show on the "VIP status" page. Whenever I go there, it'll show me nothing but "test". That's the problem I ran into earlier, forgot to list that.

All the globals were defined because I tried to copy some or your code.
May I ask why are you echoing stuff? Did you see any "echo" in any of the plugins I've already told you to look and that you said you looked at?

You are supposed to output a page. Look at the plugin I mentioned in my previous post. I am extremely sorry, but if you cannot understand that, there is nothing else I can do. I am not going to write you a plugin to what you want because you will probably not understand it either, it will do the same the others do minus something.

If you read and try to understand the code, there's nothing hard about it. When using templates, you're not supposed to echo anything in plugins or even inside the software (the ACP doesn't use templates so things are echo'ed there), you're supposed to "echo" the entire page when it's time (that's why you call output_page(...) ), not just bits. That's why templates are used, so people can edit the templates and therefore change the final output.
(11-30-2012, 06:10 AM)Pirata Nervo Wrote: [ -> ]May I ask why are you echoing stuff? Did you see any "echo" in any of the plugins I've already told you to look and that you said you looked at?

You are supposed to output a page. Look at the plugin I mentioned in my previous post. I am extremely sorry, but if you cannot understand that, there is nothing else I can do. I am not going to write you a plugin to what you want because you will probably not understand it either, it will do the same the others do minus something.

If you read and try to understand the code, there's nothing hard about it. When using templates, you're not supposed to echo anything in plugins or even inside the software (the ACP doesn't use templates so things are echo'ed there), you're supposed to "echo" the entire page when it's time (that's why you call output_page(...) ), not just bits. That's why templates are used, so people can edit the templates and therefore change the final output.

That's quite stupid, I admit. I just tried to see if I could echo anything, but one reason to not use templates, correct me if I'm wrong, is because I've read that http://php.net/manual/en/function.eval.php should always be avoided because of it being harmful.

Then, what doesn't make sense to me, is that I have a file, called "buy.php", a "buy credit plugin" that allows users to purchase points for Newpoints. There, I added some features like a "disclaimer", changed all of the text, added formatting for the numbers, added a tool to move the forum-newpoints to my server, using MySQL, where the users can purchase hats and such with it.

There, they do the following:
Code:
$page="
<html>
<head>
<title>{$mybb->settings[bbname]} - ".$lang->sprintf($lang->buycredit_title, $name)."</title>
{$headerinclude}
<style type=\"text/css\">
#donatenav {
    color: #ffff00;
}
</style>
</head>
<body id=\"donate\">

Just as example.

Now, in my newpoints plugin, I'm trying to do the same:
Code:
function newpoints_vipstatus($page)
{
        
    global $mybb, $db, $lang, $cache, $theme, $header, $templates, $plugins, $headerinclude, $footer, $options, $inline_errors;
    
    $page = '<html>
    <head>
    <title>{$lang->newpoints} - {$lang->newpoints_subscriptions}</title>
    {$headerinclude}
    </head>
    <body>
    {$header}
    <table width="100%" border="0" align="center">
    <tr>
    <td valign="top" width="180">
    <table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
    <tr>
    <td class="thead"><strong>{$lang->newpoints_menu}</strong></td>
    </tr>
    {$options}
    </table>
    </td>
    <td valign="top">
    {$inline_errors}
    Test
    </td>
    </tr>
    </table>
    {$footer}
    </body>
    </html>';
    output_page($page);
}

I copied this code from subscriptions (it's a template-copy, but the buy.php doesn't use templates either and it works there), just to see if it works, but apparently this isn't possible because this is a plugin, and not a page.
I'm getting the following output:
http://puu.sh/1vHEx, and on the page itself: http://puu.sh/1vHEQ

It's just really frustrating that I can't find out how to get it to work. I'm really easy with picking things up such as this, this is how I learnt PHP. Started doing simple tasks my dad gave me and I kept expanding. I can write some decent systems with "security" built in and such, but MyBB is just one blank sheet of paper, there's nothing that makes it clear for me. I don't understand how they accomplished to write a whole system where developers have to find out MyBB's way of doing stuff, without any form of documentation, not looking at the bad snippets on their website where not even a hyperlink works.
I understand that I'm a pain in the ass, but once I get it, it'll be no deal. I just need a push in the right direction.

Sorry for doubleposting, was an accident. Thought post-merge time was a little longer.

EDIT:
Could you help me to set this up? I just need a basic example how to alter the page that's being put out, with the menu on the left. I'm willing to pay you $10 if you can write me a small tutorial, templates would be nice. Even if the output is only "Test".
Pages: 1 2