4 Tutorials in one thread! - Nasyr - Dec 27, 2014
------
MyBB Help Desk
------
4 Simple tutorials that relate to MyBB.
------
Show Groups
Firstly create a new file in your root folder named 'showgroups.php'
Edit the file and add the following code and save it.
Code <?php
define('IN_MYBB', 1); require "./global.php";
add_breadcrumb("Custom Usergroups", "showgroups.php");
eval("\$html = \"".$templates->get("showgroups")."\";");
output_page($html);
?>
Now go to your Admin Control Panel > Themes > Templates > Global Templates > and add a new template titled 'showgroups'.
In that template add the following code and save it.
Code </style>
<html>
<head>
<title>Current Usergroups</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="1" cellpadding="4" class="tborder">
<tr>
<td class="thead"><span class="smalltext"><strong>Current Custom Usergroups</strong></span></td>
</tr>
<tr>
<td class="trow1">
<div style="width: 48%; min-height:120px; border: 1px #0E8104 solid; margin: 4px; padding: 2px; border-radius: 5px; float:left;">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr class="trow1">
<td width="75%" border="0">
<span><b>Usergroup</b></span><br />
<span class="smalltext"><b>Leaders: </b>
<a href="profile.php"><span style="color: white;">Add username(s) here</span></a><br /><a href="usercp.php?action=usergroups&joingroup=8&my_post_key={$mybb->post_code}">(Join Group)</a><br /><br />Description.</span>
</td>
<td width="25%" align="right" valign="middle">
<img src="http://resources.mybb.com/images/badges/oct_13/support.png" /><br />
</td>
</tr>
</table>
</div>
<div style="width: 48%; min-height:120px; border: 1px #0E8104 solid; margin: 4px; padding: 2px; border-radius: 5px; float:left;">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr class="trow1">
<td width="75%" border="0">
<span><b>Usergroup</b></span><br />
<span class="smalltext"><b>Leaders: </b>
<a href="profile.php"><span style="color: white;">Add username(s) here</span></a><br /><a href="usercp.php?action=usergroups&joingroup=8&my_post_key={$mybb->post_code}">(Join Group)</a><br /><br />Description.</span>
</td>
<td width="25%" align="right" valign="middle">
<img src="http://resources.mybb.com/images/badges/oct_13/support.png" /><br />
</td>
</tr>
</table>
</div>
<br>
<div style="width: 48%; min-height:120px; border: 1px #0E8104 solid; margin: 4px; padding: 2px; border-radius: 5px; float:left;">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr class="trow1">
<td width="75%" border="0">
<span><b>Usergroup</b></span><br />
<span class="smalltext"><b>Leaders: </b>
<a href="profile.php"><span style="color: white;">Add username(s) here</span></a><br /><a href="usercp.php?action=usergroups&joingroup=8&my_post_key={$mybb->post_code}">(Join Group)</a><br /><br />Description.</span>
</td>
<td width="25%" align="right" valign="middle">
<img src="http://resources.mybb.com/images/badges/oct_13/support.png" /><br />
</td>
</tr>
</table>
</div>
<div style="width: 48%; min-height:120px; border: 1px #0E8104 solid; margin: 4px; padding: 2px; border-radius: 5px; float:left;">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr class="trow1">
<td width="75%" border="0">
<span><b>Usergroup</b></span><br />
<span class="smalltext"><b>Leaders: </b>
<a href="profile.php"><span style="color: white;">Add username(s) here</span></a><br /><a href="usercp.php?action=usergroups&joingroup=8&my_post_key={$mybb->post_code}">(Join Group)</a><br /><br />Description.</span>
</td>
<td width="25%" align="right" valign="middle">
<img src="http://resources.mybb.com/images/badges/oct_13/support.png" /><br />
</td>
</tr>
</table>
</div>
<br>
<div style="width: 48%; min-height:120px; border: 1px #0E8104 solid; margin: 4px; padding: 2px; border-radius: 5px; float:left;">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr class="trow1">
<td width="75%" border="0">
<span><b>Usergroup</b></span><br />
<span class="smalltext"><b>Leaders: </b>
<a href="profile.php"><span style="color: white;">Add username(s) here</span></a><br /><a href="usercp.php?action=usergroups&joingroup=8&my_post_key={$mybb->post_code}">(Join Group)</a><br /><br />Description.</span>
</td>
<td width="25%" align="right" valign="middle">
<img src="http://resources.mybb.com/images/badges/oct_13/support.png" /><br />
</td>
</tr>
</table>
</div>
<div style="width: 48%; min-height:120px; border: 1px #0E8104 solid; margin: 4px; padding: 2px; border-radius: 5px; float:left;">
<table width="100%" cellspacing="0" cellpadding="5" border="0">
<tr class="trow1">
<td width="75%" border="0">
<span><b>Usergroup</b></span><br />
<span class="smalltext"><b>Leaders: </b>
<a href="profile.php"><span style="color: white;">Add username(s) here</span></a><br /><a href="usercp.php?action=usergroups&joingroup=8&my_post_key={$mybb->post_code}">(Join Group)</a><br /><br />Description.</span>
</td>
<td width="25%" align="right" valign="middle">
<img src="http://resources.mybb.com/images/badges/oct_13/support.png" /><br />
</td>
</tr>
</table>
</div>
<br>
</td></tr></table>
{$footer}
</body>
</html>
Then you can edit the code to the appropriate images, users and so on for each of your groups.
Alert AdBlock users about adblock extension
This short method will tell members using AdBlock to deactivate the extension in their browser.
Go to the Admin Control Panel > Themes > Templates > Theme Name > Header > Select who views it.
And then put this code in and save it.
Code <div class="YOUR_CLASS">Alerts! </div> // - You can remove this
<script>
(function() {
var message = "Your Message to AdBlock Users!";
var tryMessage = function() {
setTimeout(function() {
if(!document.getElementsByClassName) return;
var ads = document.getElementsByClassName('YOUR_CLASS'),
ad = ads[ads.length - 1];
if(!ad
|| ad.innerHTML.length == 0
|| ad.clientHeight === 0) {
alert(message);
//window.location.href = 'http://comunidade.bf4brasil.com.br/member.php?action=register'; "//" Redirect users to where you want - You need to remove "//"
} else {
ad.style.display = 'none';
}
}, 1800);
}
if(window.addEventListener) {
window.addEventListener('load', tryMessage, false);
} else {
window.attachEvent('onload', tryMessage);
}
})();
</script>
Limit Signature Image Size in kilobyte
Go to your Root > Inc > Plugins > create a file named 'limitsign.php' and save it.
Then edit that file and add the following code.
Code <?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
// Plugin info
function limitsign_info ()
{
return array(
"name" => "limitsign",
"description" => "limitsign",
"website" => "limitsign",
"author" => "limitsign",
"authorsite" => "limitsign",
"version" => "limitsign",
"guid" => "limitsign",
"compatibility" => "16*"
);
}
$plugins->add_hook('usercp_start', 'signsize');
function signsize()
{
global $mybb, $error;
preg_match_all("/\[img(.*?)\](.*?)\[\/img\]/i", $mybb->input['signature'], $matches, PREG_SET_ORDER);
$kbsizetot = 0;
foreach ($matches as $img)
{
$kbsize = strlen(@file_get_contents($img[2]));
$kbsizetot += $kbsize;
}
if (($kbsizetot > 350000) && ($mybb->input['action'] == "do_editsig")) {
$error = inline_error("The sum of the size of the images exceeds the allowed limit of 350kb.");
}
}
?>
Change the value (currently 350000) to whatever you want it to be.
Additionally enter the error message you want and then save it.
Usergroups legend without using plugins
To begin with go to this template: Admin Control Panel > Templates & Style > Templates > theme of choice > Index Page Templates > index_boardstats.
Find {$whosonline} and replace with the following but filled in with your groups.
Code <tr>
<td class="tcat"><span class="smalltext"><strong>Usergroup Legend</strong></span></td>
</tr>
<tr>
<td class="trow1"><span class="smalltext">ADD YOUR USERGROUPS HERE</span></td>
</tr>
If you are having issues with whos online, readd the code for it which is > {$whosonline}
* - holyshit - Jan 13, 2015
Yes but how to make showgroups page automatic...
* - Sakuto - Jan 13, 2015
You should remove the center tag on the code tag, it make the code unreadable. Good job for this tutorial though.
* - Nasyr - Jan 13, 2015
(Jan 13, 2015 06:33 PM)Sakuto Wrote: You should remove the center tag on the code tag, it make the code unreadable. Good job for this tutorial though.
It's not really a big deal is it really?
* - Sakuto - Jan 13, 2015
I love reading code when I see tutorial, the fact that center tag destroy the indentation make the code so disagreeable to read that, in 90% of case, I just leave the thread without finishing my lecture. I don't know if it's the same for everybody, but I find that very unpalatable.
|