in the side panel I have a plugin for user statistics, etc., I added to it a condition that checks if we have an unread message and now a question how to add another condition that will change the color of notification when the number will be greater than zero
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
Are you able to share the code? It would be much easier. It would be something like:
$message = '';
if ($variable >= 1) {
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\" style=\"color: green\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
} else {
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
}
(2018-07-17, 06:00 PM)Wires Wrote: [ -> ]Are you able to share the code? It would be much easier. It would be something like:
$message = '';
if ($variable >= 1) {
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\" style=\"color: green\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
} else {
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
}
And you'll tell me how to add color only for a number, I try this way but it does not work
$message = '';
if ($variable >= 1) {
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> <span style=\"color: green\">{$mybb->user['pms_unread']}</span></a>";
} else {
$message = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
}
Of course it's not going to work. I need to see the code you're using...
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("index_start", "statsuserindex");
function statsuserindex_info()
{
//info
$website = "https://mybboard.pl";
return array(
"name" => "Statystyki użytkownika na stronie głównej",
"description" => "---",
"website" => "{$website}",
"author" => "Snake_",
"authorsite" => "{$website}/uzytkownik-snake_19523",
"version" => "0.1",
);
}
function statsuserindex_activate(){ // Aktywacja pluginu
global $db, $mybb; // Używanie bazy danych i MyBB
$insert_array22 = array(
'title' => 'statsuserindex',
'template' => $db->escape_string('<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" style="width: 100%;
border-left: 1px solid #393939;
border-right: 1px solid #393939;
border-bottom: 1px solid #393939;">
<tr>
<td class="tcat"><strong>
{$tekst_wyswietlany_w_thead}
</strong></td>
</tr>
<tr>
<td class="trow1">
<div style="text-align: center;">
{$nick_usera}
<br />
{$avatar_usera}
<br />
{$wiadomosc} {$alerts}
</div>
<br />
<div>
<div class="staty_author"><div class="staty_left_a">Grupa:</div><div class="staty_right_a"> {$grupa_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Reputacja:</div><div class="staty_right_a"> {$reputacja_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Liczba postów:</div><div class="staty_right_a"> {$postow_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">E-mail:</div><div class="staty_right_a"> {$email_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Moje IP:</div><div class="staty_right_a"> {$ip}</div></div>
<div class="staty_author"><div class="staty_left_a">Ostatnia wizyta:</div><div class="staty_right_a"> {$lastvisit}</div></div>
<div class="staty_author"><div class="staty_left_a">Ostrzeżenia:</div><div class="staty_right_a"> {$warn_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Rejestracja:</div><div class="staty_right_a"> {$rejestracja}</div></div>
<div class="staty_author"><div class="staty_left_a">Tytuł:</div><div class="staty_right_a"> {$tytul_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Tytuł:</div><div class="staty_right_a"> {$stopka}</div></div>
</div>
</td>
</tr>
</table>'),
'sid' => '-1',
'version' => '',
'dateline' => time()
);
$db->insert_query('templates', $insert_array22);
}
function statsuserindex_deactivate() { // Dezaktywacja pluginu
global $db, $mybb; // Używanie bazy danych i MyBB
$db->delete_query("templates", "title = 'statsuserindex'");
require MYBB_ROOT."/inc/adminfunctions_templates.php"; // Tym plikiem możemy bawić się w szablonie, np. usuwać zmienną
find_replace_templatesets('index', '#(\n?){\$statsuserindex}#', '', 0); // Zabawa w szablonie: index, usuwamy zmienną: {$statsuserindex}
} // Zamykamy dezaktywację pluginu
function statsuserindex()
{
global $mybb, $cache, $theme, $groupscache, $lastvisit, $statsuserindex, $templates;
//ogolna funkcja
if($mybb->user['uid']) {
$stopka = " Powered by Mybboard.pl Edit by OneFrag.pl"
$tekst_wyswietlany_w_thead = "Statystyki użytkownika {$mybb->user['username']}.";
$nick_usera = build_profile_link(format_name($mybb->user['username'], $mybb->user['usergroup'], $mybb->user['displaygroup']), $mybb->user['uid']);
$nick_usera = "<span style=\"font-size: 20px;\">{$nick_usera}</span>";
$avatar_usera = '<img src="' . (empty($mybb->user['avatar']) ? 'images/default_avatar.png' : $mybb->user['avatar']) . '" title="' . $mybb->user['username'] . '" class="avatar_usera"/>';
$reputacja_usera = $mybb->user['reputation'];
$email_usera = "<a href=\"mailto:{$mybb->user['email']}\">{$mybb->user['email']}</a>";
$postow_usera = $mybb->user['postnum'];
$warn_usera = $mybb->user['warningpoints'];
$tytul_usera = $mybb->user['usertitle'];
$rejestracja = date('d.m.Y', $mybb->user['regdate']);
$alerts = "<a href=\"{$mybb->settings['bburl']}/alerts.php\" class=\"myalerts\" onclick=\"MyBB.popupWindow('/alerts.php?modal=1&ret_link={$myalerts_return_link}', { fadeDuration: 250, zIndex: (typeof modal_zindex !== 'undefined' ? modal_zindex : 9999) }); return false;\"><i class=\"far fa-bell\"></i> {$mybb->user['unreadAlerts']}</a>";
if ($variable >= 1) {
$wiadomosc = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> <span style=\"color: green\">{$mybb->user['pms_unread']}</span></a>";
}
else {
$wiadomosc = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
}
}
else {
$tekst_wyswietlany_w_thead = "Twoje statystyki";
$nick_usera = "";
$avatar_usera = '<img src="images/default_avatar.png" class="avatar_usera" />';
$reputacja_usera = 0;
$email_usera = "<i>Nie zidentyfikowano</i>";
$postow_usera = 0;
$warn_usera = 0;
$tytul_usera = "Gość";
$rejestracja = "Nie zarejestrowany";
}
if(!is_array($groupscache))
$groupscache = $cache->read("usergroups");
$grupa_usera = $groupscache[$mybb->user['usergroup']]['title'];
$ostatnio_tu_bylem = $mybb->user['lastvisit'];
$ip = $_SERVER['REMOTE_ADDR'];
eval("\$statsuserindex = \"".$templates->get("statsuserindex")."\";");
}
?>
So to clarify, if a user has more than 1 unread private message, change the color?
In general, the counter will change color when a message appears which will be marked as unread
Sorry but my English is weak
Try something like this:
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("index_start", "statsuserindex");
function statsuserindex_info()
{
//info
$website = "https://mybboard.pl";
return array(
"name" => "Statystyki użytkownika na stronie głównej",
"description" => "---",
"website" => "{$website}",
"author" => "Snake_",
"authorsite" => "{$website}/uzytkownik-snake_19523",
"version" => "0.1",
);
}
function statsuserindex_activate(){ // Aktywacja pluginu
global $db, $mybb; // Używanie bazy danych i MyBB
$insert_array22 = array(
'title' => 'statsuserindex',
'template' => $db->escape_string('<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" style="width: 100%;
border-left: 1px solid #393939;
border-right: 1px solid #393939;
border-bottom: 1px solid #393939;">
<tr>
<td class="tcat"><strong>
{$tekst_wyswietlany_w_thead}
</strong></td>
</tr>
<tr>
<td class="trow1">
<div style="text-align: center;">
{$nick_usera}
<br />
{$avatar_usera}
<br />
{$wiadomosc} {$alerts}
</div>
<br />
<div>
<div class="staty_author"><div class="staty_left_a">Grupa:</div><div class="staty_right_a"> {$grupa_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Reputacja:</div><div class="staty_right_a"> {$reputacja_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Liczba postów:</div><div class="staty_right_a"> {$postow_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">E-mail:</div><div class="staty_right_a"> {$email_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Moje IP:</div><div class="staty_right_a"> {$ip}</div></div>
<div class="staty_author"><div class="staty_left_a">Ostatnia wizyta:</div><div class="staty_right_a"> {$lastvisit}</div></div>
<div class="staty_author"><div class="staty_left_a">Ostrzeżenia:</div><div class="staty_right_a"> {$warn_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Rejestracja:</div><div class="staty_right_a"> {$rejestracja}</div></div>
<div class="staty_author"><div class="staty_left_a">Tytuł:</div><div class="staty_right_a"> {$tytul_usera}</div></div>
<div class="staty_author"><div class="staty_left_a">Tytuł:</div><div class="staty_right_a"> {$stopka}</div></div>
</div>
</td>
</tr>
</table>'),
'sid' => '-1',
'version' => '',
'dateline' => time()
);
$db->insert_query('templates', $insert_array22);
}
function statsuserindex_deactivate() { // Dezaktywacja pluginu
global $db, $mybb; // Używanie bazy danych i MyBB
$db->delete_query("templates", "title = 'statsuserindex'");
require MYBB_ROOT."/inc/adminfunctions_templates.php"; // Tym plikiem możemy bawić się w szablonie, np. usuwać zmienną
find_replace_templatesets('index', '#(\n?){\$statsuserindex}#', '', 0); // Zabawa w szablonie: index, usuwamy zmienną: {$statsuserindex}
} // Zamykamy dezaktywację pluginu
function statsuserindex()
{
global $mybb, $cache, $theme, $groupscache, $lastvisit, $statsuserindex, $templates;
//ogolna funkcja
if($mybb->user['uid']) {
$stopka = " Powered by Mybboard.pl Edit by OneFrag.pl"
$tekst_wyswietlany_w_thead = "Statystyki użytkownika {$mybb->user['username']}.";
$nick_usera = build_profile_link(format_name($mybb->user['username'], $mybb->user['usergroup'], $mybb->user['displaygroup']), $mybb->user['uid']);
$nick_usera = "<span style=\"font-size: 20px;\">{$nick_usera}</span>";
$avatar_usera = '<img src="' . (empty($mybb->user['avatar']) ? 'images/default_avatar.png' : $mybb->user['avatar']) . '" title="' . $mybb->user['username'] . '" class="avatar_usera"/>';
$reputacja_usera = $mybb->user['reputation'];
$email_usera = "<a href=\"mailto:{$mybb->user['email']}\">{$mybb->user['email']}</a>";
$postow_usera = $mybb->user['postnum'];
$warn_usera = $mybb->user['warningpoints'];
$tytul_usera = $mybb->user['usertitle'];
$rejestracja = date('d.m.Y', $mybb->user['regdate']);
$alerts = "<a href=\"{$mybb->settings['bburl']}/alerts.php\" class=\"myalerts\" onclick=\"MyBB.popupWindow('/alerts.php?modal=1&ret_link={$myalerts_return_link}', { fadeDuration: 250, zIndex: (typeof modal_zindex !== 'undefined' ? modal_zindex : 9999) }); return false;\"><i class=\"far fa-bell\"></i> {$mybb->user['unreadAlerts']}</a>";
if ($mybb->user['pms_unread'] >= 1) {
$wiadomosc = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> <span style=\"color: green\">{$mybb->user['pms_unread']}</span></a>";
}
else {
$wiadomosc = "<a href=\"{$mybb->settings['bburl']}/private.php\"><i class=\"far fa-envelope-open\"></i> {$mybb->user['pms_unread']}</a>";
}
}
else {
$tekst_wyswietlany_w_thead = "Twoje statystyki";
$nick_usera = "";
$avatar_usera = '<img src="images/default_avatar.png" class="avatar_usera" />';
$reputacja_usera = 0;
$email_usera = "<i>Nie zidentyfikowano</i>";
$postow_usera = 0;
$warn_usera = 0;
$tytul_usera = "Gość";
$rejestracja = "Nie zarejestrowany";
}
if(!is_array($groupscache))
$groupscache = $cache->read("usergroups");
$grupa_usera = $groupscache[$mybb->user['usergroup']]['title'];
$ostatnio_tu_bylem = $mybb->user['lastvisit'];
$ip = $_SERVER['REMOTE_ADDR'];
eval("\$statsuserindex = \"".$templates->get("statsuserindex")."\";");
}
?>
What have you tried so far? What are you trying to make a different color?