MyBB Community Forums

Full Version: Plugin Coding Questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It would be nice to have all the mybb globals and their methods/properties listed in a single thread.

Also, how do I do soe of the following things:
1) Query what forum the user is currently browsing.
2) Query who created a cetain post.
3) How to automatically issue warnings for certain actions (ex: warn if a user reports an admin post).

One plugin (that I want t create myself with a little bit of assistance) is a plugin that will automatically warn users that arent admin if he/she reports an admin's post.
If all these questions are concerning your warning plugin:
1. Hook to report_do_report_start
2. Open report.php and you'll notice that $forum and $post variables contain informations required in 1) and 2)
3. Check whether $post['usergroup'] and $post['additionalgroups'] contain admin groups, if yes - issue a warning (open warnings.php to see how it's done - do_warn action specifically), show an error and exit

The documentation has everything you need to know, in my opinion. The rest is a matter of spending some time to read the code and trying.
Thanks, ill try it, though, i want the report to still be sent just in case it is a legitimte report -- it is just a way to decrease the number of people who like to abuse the report system for no reason.

Okay, im working first with my basic install, activate, deactivate, and uninstall functions.

Here's the error:


Error Type: Catchable Fatal Error (4096l
Error Message: Object f class mysqli_result could not be converted to string
Location: %mybb_root%/inc/plugins/warnonadminreport.php Line: 148
Code:
145.  $gid = $db->write_query("SELECT gid FROM '".TABLE_PREFIX."settinggroups' WHERE 'name' = 'warnonadminreport';");
146. // Comment
147. $condition = "gid = ";
148. $condition .= $gid
149.
150. // Comment
151.  $db->delete_query("settinggroups",$condition);

Backtrace:
File | Line | Function
%mybb_root%/inc/class_error.php | 208 | errorHandler->output_error
%mybb_root%/inc/plugins/warnonadminreport.php | 148 | errorHandler->error warnonadminreport_deactivate
%mybb_root%/admin/modules/config/plugins.php | 413 | call_user_func
%mybb_root%/admin/index.php | 576 | require
---------------------------
Please contact the MyBB Group for support.



Can you please explain what is 1) Wrong with my code, and 2) What does this error mean and how should i avoid it?
Basically $gid is a MySQLi object that can't be just appended to a string. It must be "converted" using the $db class:

$query = $db->simple_select('settinggroups', 'gid', "name = 'warnonadminreport'");
$gid = $db->fetch_field($query, 'gid');

$db->delete_query('settinggroups', "gid = {$gid}");
Also, you waste a query this way. Why not simply use:
$db->delete_query('settinggroups', "name = 'warnonadminreport'");
?
(2014-07-05, 03:54 PM)Destroy666 Wrote: [ -> ]If all these questions are concerning your warning plugin:
1. Hook to report_do_report_start
2. Open report.php and you'll notice that $forum and $post variables contain informations required in 1) and 2)
3. Check whether $post['usergroup'] and $post['additionalgroups'] contain admin groups, if yes - issue a warning (open warnings.php to see how it's done - do_warn action specifically), show an error and exit

The documentation has everything you need to know, in my opinion. The rest is a matter of spending some time to read the code and trying.

oh yeah, do i have to declare those as global variables?

(2014-07-05, 07:57 PM)Destroy666 Wrote: [ -> ]Also, you waste a query this way. Why not simply use:
$db->delete_query('settinggroups', "name = 'warnonadminreport'");
?

Thats what I ended up doing.