Saturday, December 17, 2011

MyBB Plugin "Signature settings per group"

On MyBB, the "Signature settings per group" plugin does a great job of letting you control signature settings and grant different settings for different groups of users. One great use is to limit number of images for those who are not advertisers. The problem with the plugin is that smiles count against the number of images and most users like to have a few smilies in their signature.

It was easy to get around this. (applies to MyBB 1.6+)
In the forum install root, find this file: usercp.php
Edit it and search for this:
$plugins->run_hooks("usercp_start");
If you've broken out the more or less proper line breaks, it should be around line 57, but the files come from MyBB without line breaks.

Change this:
if((($mybb->settings['sigimgcode'] == 0 && $mybb->settings['sigsmilies'] != 1) &&
substr_count($parsed_sig, "<img") > 0) ||
(($mybb->settings['sigimgcode'] == 1 || $mybb->settings['sigsmilies'] == 1) &&
substr_count($parsed_sig, "<img") > $mybb->settings['maxsigimages'])
)
To this (focus on the - substr_count images/smilies/):

if((($mybb->settings['sigimgcode'] == 0 && $mybb->settings['sigsmilies'] != 1) &&
substr_count($parsed_sig, "<img") > 0) ||
(($mybb->settings['sigimgcode'] == 1 || $mybb->settings['sigsmilies'] == 1) &&
(substr_count($parsed_sig, "<img") - substr_count($parsed_sig, "images/smilies/")) > $mybb->settings['maxsigimages'])
)
What's going on here is... say you allow one image in a signature. Well a smilie is an image because when it all comes down to the code, there is an "<img" tag. The code counts the images and checks the count against the "maxsigimages" setting. All I am doing is counting the number of instances of "images/smilies/" and then reducing the number of images found by that number before it is compared to the "maxsigimages" setting.

This works because smilies are kept in a specific directory.

It comes down to this:
(substr_count($parsed_sig, "<img") - substr_count($parsed_sig, "images/smilies/")) > $mybb->settings['maxsigimages'])
versus this:
substr_count($parsed_sig, "<img") > $mybb->settings['maxsigimages'])

No comments:

Post a Comment