MyBB Community Forums

Full Version: Help creating Plugins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I am working on creating my first plugin, and I must say I'm absolutely stumped. The plugin I'm trying to create is a plugin that will allow users to "claim" posts of their own. The reason for this is that to friend of mine had his IPB forum crash, and had to switch to MyBB with a modified transfer script. However, all posts show up as having been done by guests, so I want users to be able to claim the posts they wrote. However, as I said before, I'm stumped. Here are the problems I'm facing:

1. What are all the plugin hooks for? I can only find the list of them, but I have no idea what they all do, and therefore which one to use.
2. How do I use the pluginname_activate function to add a button to the template that will allow for claiming a post?
3. How do I have that button then submit to the plugin so the user can claim their post?

With that info under my belt, I think I might be able to manage it. So can anyone help me out with these?
so are you missing the user table/info or the post table is missing poster info? what data do you have from the IPB forum? there may be other options to recovering the data. a plugin is not your best option either. a new page to handle the 'claim' would be better. install the page-manager plugin and use that to create a new page (using one the examples) that will handle the claim and update the posts and threads tables.

as for your questions:

1) plugin hooks allow your plugin to run a specific function at the time the plugin hook is called. so the global_start hook will check all the plugins and run any function in them that reference the global_start hook.

2) if it is just for your own use, its easier to simply manually add/remove the code to the template. at least that is my opinion as I can not a fan of the find/replace function. especially if it is a simple link you need to add to the postbit template

3) this is the template edit you would need to make to the postbit. i would suggest a simple button or text link to a new page to process the 'claim'
(2010-10-05, 06:10 PM)pavemen Wrote: [ -> ]so are you missing the user table/info or the post table is missing poster info? what data do you have from the IPB forum? there may be other options to recovering the data. a plugin is not your best option either. a new page to handle the 'claim' would be better. install the page-manager plugin and use that to create a new page (using one the examples) that will handle the claim and update the posts and threads tables.

The users are intact (though the passwords are lost so everyone is using the recover password feature). It is just that the posts have no user data attached to them.

Anyway, I know how hooks work, I just don't know what they all do, and therefore which one to use.
you don't need a plugin for what you want to do. as i suggested, you need a whole page to process in incoming http request from the postbit link you add. a plugin is designed to be run inline with the forum script. you need external processing.

create that new page with mybb integration. the simplest method is to install the page-manager plugin and use that to create a new page with php enabled.

in the page, test that the user is a mybb user and not a guest ($mybb->user['uid'] >=1) and if so, update the posts and threads table based as needed.

then just edit the postbit template to add a link to a new page you created.

no plugin needed to 'claim' the thread/post
Yeah, that's what I'm working on right now. However, I'm using a completely independent page, and I'm trying to figure out how to get a hold of either the user id or the username, since the page is not actually attached to MyBB. Remember, this isn't my forum. I want to suggest a fairly quick and easy way to my friend. I don't want to have to have him install a new plugin. So how can I access the uid or username? I'm looking at the postbit on my forum, and have figured out how to get hold of the post ID, it's just the user id or name that's lacking.
like i said, install the page-manger plugin. there are examples fo how to implement a php page using that plugin and its fully integrated with mybb

otherwise you need to include global.php and then you can use the $mybb variable. Current user is in the $mybb->user array. You can do a

echo "<pre>";
 print_r($mybb);
echo "</pre>";

to see all the $mybb variable settings and values. including global.php should include all the functionality you need to access the posts and threads tables
OK, thanks a lot. One more little wrinkle, however. The "claim post" button should only show on posts that were supposedly written by guests. How is this possible with the template?
its not, but if your standalone page tests the current post owner, you can catch the error that way.

otherwise you do need to create a plugin, but in my opinion that is too much work for what you need to do.

if you want to do it, you need to insert {$claimlink} into the template where you want it to show, then create a plugin that grabs the 'postbit' hook (as called from the functions_post.php build_postbit() function). The function in your plugin simply needs to create/update a global variable called $clamlink if the post owner is guest
So basically you're saying I should let the button show on all posts, since otherwise I have to make a plugin? Oh well, it will have to be that way then. I'm not even sure my friend will want to set up a "claim" system. The only thing that makes me think he will want it is because this is a Post2Host hosting site, where every post counts. When everyone loses their posts, that's not good.

BTW, for the claim button, does anyone know what the font is for the postbit buttons?
OK, so I tried requiring global.php, but I get the IN_MYBB not defined error, and the script dies. What now?
define("IN_MYBB", 1);
Pages: 1 2 3