MyBB Community Forums
My first Plugin: Help! - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Support (https://community.mybb.com/forum-72.html)
+---- Thread: My first Plugin: Help! (/thread-6513.html)

Pages: 1 2


My first Plugin: Help! - .Lou - 2006-02-04

My first plugin. I would like to implement the following inside a plugin:

Michael83 Wrote:A nicer solution (far less queries): Insert into global.php
## Update Usergroup ##
// Usergroup-ID Group 1 (old group)
$gid1 = "2";

// Usergroup-ID Group 2 (new group)
$gid2 = "4";

// Minimal number of posts
$minposts = "5";

// Update user
if ($mybb->user['postnum'] == $minposts)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
}
## Update Usergroup ##
When you use this method, you have to run the following query via phpmyadmin to update all users that already have more than x posts:
UPDATE mybb_users SET usergroup = 'x', displaygroup = 'x' WHERE postnum >= 'y' AND usergroup = 'z'
x = new goup id
y = minimal post number
z = old group id


I would also like to make it so in the options when you set a certain number of posts to change from usergroup, you can chose what group to change to, and what group they must be in for this change to take affect. Also, I would like to be able to automatically switch current users to this group using a checkbox.

So example:
Add new Changer: http://www.louhabs.com/mybbmods/usergroupchanger/index.htm
Manage Current Changers: http://www.louhabs.com/mybbmods/usergroupchanger/groups.htm

[Manage Changers is just so you know what I want there. There is no example]

Anyone willing to help me make this?


RE: Auto Usergroup change mod: Help - ShawnZ - 2006-02-04

<?php
$plugins->add_hook("newreply_start", "auto_update_usergroup");

function autoupdate_info()
{
return array(
"name" => "Auto Update Usergroup",
"description" => "Automatically updates someone's usergroup",
"website" => "http://community.mybboard.net/",
"author" => "shawnz",
"authorsite" => "http://community.mybboard.net/",
"version" => "1.0",
);
}

function autoupdate_activate()
{
}

function autoupdate_deactivate()
{
}

function auto_update_usergroup()
{


## Update Usergroup ##
// Usergroup-ID Group 1 (old group)
$gid1 = "2";

// Usergroup-ID Group 2 (new group)
$gid2 = "4";

// Minimal number of posts
$minposts = "5";

// Update user
if ($mybb->user['postnum'] == $minposts)
{
// Update usergroup
$update_group = $db->query("UPDATE ".TABLE_PREFIX."users SET usergroup = '".$gid2."', displaygroup = '".$gid2."' WHERE uid = '".$mybb->user['uid']."' AND usergroup = '".$gid1."'");
}
## Update Usergroup ##


}
?>

dunno, ripped off hello.php =p


RE: My first Plugin: Help! - .Lou - 2006-02-04

That's a basic thing...will work probably but won't do exactly what I wanted since I wanted:

http://www.louhabs.com/mybbmods/usergroupchanger/index.htm
and
http://www.louhabs.com/mybbmods/usergroupchanger/groups.htm



RE: My first Plugin: Help! - laie_techie - 2006-02-04

You bump a thread after 3 measley hours? Since we have a life outside MyBB and live in different timezones, you should wait at least 1 business day.

As far as the auto group promotions, you may want to change your logic a bit. You want to promote to the new group if the user has at least the minimum number of posts (Shawn's code tests for exact equality). It would also be prudent to check additionalgroups to see if the base group is listed there.

Your plugin could register a few settings in the ACP (such as how many posts are required for each promotion).



RE: My first Plugin: Help! - .Lou - 2006-02-05

See, I never made a plugin. Which is why I would like someone to explain to me step by step everything I got to do, so I understand it for future. I'm asking alot, but it would be useful as a tutorial tbh.


RE: My first Plugin: Help! - decswxaqz - 2006-02-05

I don't get the plugin.
I think it's talking about promoting someone from a usergroup to another usergroup based on their post count?


RE: My first Plugin: Help! - .Lou - 2006-02-05

Exactly it.


RE: My first Plugin: Help! - Smethead - 2006-02-05

I don't think it has te be done as a plugin. It's more like a new page in the AdminCP. It would be very easy doing it as a new page.
Let the script list all the usergroups
$query = $db->query("SELECT gid, title FROM ".TABLE_PREFIX."usergroups");
Then let the script make two drop-down selections.
echo "<form method=\"post\" action=\"page.php\">From Group:<select name=\"from_group\">";
while($group = $db->fetch_array($query)){
echo "<option value=\"".$group['gid']."\">".$group['title']."</option>";
}
echo "</select> to group: <select name=\"to_group\">";
while($group = $db->fetch_array($query)){
echo "<option value=\"".$group['gid']."\">".$group['title']."</option>";
}
echo "</select><br>postcount:";
and add all the things you want just in there. It shouldn't be that hard.
remeber to escape the "s (replacing them with \")
Also remember to add require "./global.php"; at the top of the page.

But if you want to make it work automatically, I'd suggest to wait till eMods is released. (http://mods.mybboard.com/forum/showthread.php?tid=488)


RE: My first Plugin: Help! - decswxaqz - 2006-02-05

Well you will probably want to use the handle "newthread_do_newthread_end". Maybe something like

<?php
$plugins->add_hook("newreply_do_newreply_end", "auto_update_newUsergroup");

function autoupdate_info()
{
return array(
"name" => "Auto Update Usergroup",
"description" => "Automatically updates someone's usergroup",
"website" => "http://community.mybboard.net/",
"author" => "shawnz",
"authorsite" => "http://community.mybboard.net/",
"version" => "1.0",
);
}

function autoupdate_activate()
{
}

function autoupdate_deactivate()
{
}

function auto_update_newUsergroup(){
   global $db, $mybb;
   $row = $db->fetch_array($db->query("SELECT postnum FROM ".TABLE_PREFIX."users WHERE uid = " . $mybb->user['uid']));
   if($row['postnum'] > $usergroup['postnum']){
      //Update usergroups here
   }
}
?>
Of course you will need some way of knowing the post counts for the usergroups. Perhaps storing them in the usergroup table along with the other information or your own table?
But I think it's better to use the handle I have because it happens after the post has been inserted. Whch means that the post count has been updated and that the post is 'legit' - not too short, not too many images etc.

EDIT:
(Was contructing the above reply whilst smethead responded. Didn't see his reply)
Reply to smethead.

I thought eMods was to install Admin panels automatically rather than execute code? Although I guess by definition it might do this? Have to wait and see.

If you want it to automatically update usergroups when a user posts then you will need to use plugin handles, like the one I mentioned. If it's going to be a manual process (ie admin goes to admin cp), then you can use smetheads' reply.



RE: My first Plugin: Help! - .Lou - 2006-02-05

Smethead Wrote:But if you want to make it work automatically, I'd suggest to wait till eMods is released. (http://mods.mybboard.com/forum/showthread.php?tid=488)
I'm a beta testerToungue

Edit: I want it automatic. The code I provided in my first post explains this.