MyBB Community Forums
Private Message title in dropdown of header_welcomeblock_member? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Private Message title in dropdown of header_welcomeblock_member? (/thread-182241.html)

Pages: 1 2


Private Message title in dropdown of header_welcomeblock_member? - niere8 - 2015-10-02

Hi, I would like add in a dropdown the title of private message received, like this (it's only an example edited, don't look to numbers etc Big Grin ):

[Image: gZL0q0H.png]

I tried to add in header_welcomeblock_member this:

<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
    Private Messages
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
    <li>{$pm_notice}</li>
  </ul>
</li>

or

<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" title="I tuoi messaggi privati">
    Private Messages
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
    <li>{$privatemessage_text}</li>
  </ul>
</li>

But nothing, I think I need edit in core something but I don't know what. Is there some tutorial for this? Because I saw this edit in a MyBB forum, so it's possible make it.

Thank you in advance


RE: Private Message title in dropdown of header_welcomeblock_member? - SentoWeb - 2015-10-02

You will need more than template changes to make this possible. You will need to select the user's last 5 unread PMs and put it in a template variable.

You can ask for a custom plugin using the plugin request subforum. If you are at least somewhat experienced in PHP I can help you put together such plugin.


RE: Private Message title in dropdown of header_welcomeblock_member? - niere8 - 2015-10-02

Hi, I tried with this code in global.php but nothing:

// Dropdown mp
	$query = $db->query("
		SELECT pm.subject, pm.pmid, fu.username AS fromusername, fu.uid AS fromuid
		FROM ".TABLE_PREFIX."privatemessages pm
		LEFT JOIN ".TABLE_PREFIX."users fu on (fu.uid=pm.fromid)
		WHERE pm.folder = '1' AND pm.uid = '{$mybb->user['uid']}' AND pm.status = '0'
		ORDER BY pm.dateline DESC
		LIMIT 5
	");
	
	while($private_dropdown = $db->fetch_array($query))
	{
		$private_dropdown_subject = htmlspecialchars_uni($private_dropdown['subject']);
		$private_dropdown_fromuser = htmlspecialchars_uni($private_dropdown['fromusername']);

	eval("\$private_dropdown_template_template .= \"".$templates->get("private_dropdown_template_template")."\";");
	}
	
eval("\$private_dropdown_template = \"".$templates->get("private_dropdown_template")."\";");

and in "private_dropdown_template" template only added, to test, {$private_dropdown_subject} and {$private_dropdown_fromuser} but it doesn't appear in header_welcomeblock_member..

<ul class="dropdown-menu">
 <li>{$private_dropdown_template}</li>
</ul>

Sad


RE: Private Message title in dropdown of header_welcomeblock_member? - niere8 - 2015-10-12

Bump  Blush if some good soul can give me advice

I need only move the text "You have one unread private message from" from header to headermenu member..but doesn't work..


RE: Private Message title in dropdown of header_welcomeblock_member? - RateU - 2015-10-12

Add the code before the header_welcomeblock_member defined.
Can be achieved by a plugin though.


RE: Private Message title in dropdown of header_welcomeblock_member? - niere8 - 2015-10-13

Thank you RateU!!! Big Grin It works


So:


In global.php BEFORE of this line:

// Load appropriate welcome block for the current logged in user

(Thank you Leefish for the place Big Grin )


I added this code:

// Dropdown PM
	$query = $db->query("
		SELECT pm.subject, pm.pmid, pm.status, pm.dateline, fu.username AS fromusername, fu.uid AS fromuid
		FROM ".TABLE_PREFIX."privatemessages pm
		LEFT JOIN ".TABLE_PREFIX."users fu on (fu.uid=pm.fromid)
		WHERE pm.folder = '1' AND pm.uid = '{$mybb->user['uid']}'
		ORDER BY pm.dateline DESC
		LIMIT 5
	");
	$private_dropdown_dateline = my_date($mybb->settings['dateformat'], $private_dropdown['dateline']);
		
	while($private_dropdown = $db->fetch_array($query))
	{
		$private_dropdown_link = htmlspecialchars_uni($private_dropdown['pmid']);
		$private_dropdown_status = htmlspecialchars_uni($private_dropdown['status']);
		$private_dropdown_subject = htmlspecialchars_uni($private_dropdown['subject']);
		$private_dropdown_fromuser = htmlspecialchars_uni($private_dropdown['fromusername']);
		$private_dropdown_dateline = my_date($mybb->settings['dateformat'], $private_dropdown['dateline']);
			
	eval("\$private_dropdown_template_template .= \"".$templates->get("private_dropdown_template_template")."\";");
	}
eval("\$private_dropdown_template = \"".$templates->get("private_dropdown_template")."\";");


Created a new template called "private_dropdown_template" with inside only this variable:

{$private_dropdown_template_template}


And created a new template called "private_dropdown_template_template" with status PM (unread/read), date, from user, subject, link to PM:

<if ($private_dropdown['status'] == 0) then>

<a href="private.php?action=read&amp;pmid={$private_dropdown['pmid']}">
<strong>{$private_dropdown_subject} from {$private_dropdown_fromuser}, <span class="icon-stopwatch"></span> <?=my_date($mybb->settings['dateformat'], $private_dropdown['dateline'])?> <?=my_date($mybb->settings['timeformat'], $private_dropdown['dateline'])?> Unread
</strong></a>
	
<else>

<a href="private.php?action=read&amp;pmid={$private_dropdown['pmid']}">{$private_dropdown_subject} from {$private_dropdown_fromuser}, <span class="icon-stopwatch"></span> <?=my_date($mybb->settings['dateformat'], $private_dropdown['dateline'])?> <?=my_date($mybb->settings['timeformat'], $private_dropdown['dateline'])?></a>	

</if>


(With PHP and Template Conditionals Plugin)


The result

[Image: 3cuvgAa.png]


I used:

<?=my_date($mybb->settings['dateformat'], $private_dropdown['dateline'])?>
<?=my_date($mybb->settings['timeformat'], $private_dropdown['dateline'])?>

because with {$private_dropdown['dateline']} I had UNIX datetime like "1444702684"



Other thing about PM status. If I used this code:

if($pm['status'] == 0)
	{
		$private_lang_unread = "<span style=\"font-weight: bold;\">Unread !</span>";
	}
if($pm['status'] == 1)
	{
		$private_lang_unread = "Already read";
	}

with {$private_lang_unread} I had always and only "Unread" mark , also on all other PM's already read.


Maybe not 100% perfect but it seems to work Big Grin


Thank you again Smile


RE: Private Message title in dropdown of header_welcomeblock_member? - kylesw555 - 2016-01-24

I've been trying to do exactly this for a while now and this worked great so thanks very much Big Grin.

Could someone please help me with one thing though, I would like a thumbnail of the avatar of the user that the PM is from to display on the left hand side of the PM link. Any help achieving that would be greatly appreciated.

I would also like to achieve the number of unread pm's in a circle as in niere8's image above if anyone could help me achieve that Smile.


RE: Private Message title in dropdown of header_welcomeblock_member? - niere8 - 2016-01-24

For unread pm's in a circle add:

Quote:{$mybb->user['pms_unread']}

This give you the number of unread pm's, then you need only add with CSS the circle and style you want. I use bootstrap but you can easily add style with CSS.

For avatar in PM's dropdown you need add it in the query:

Quote:SELECT pm.subject, pm.pmid, pm.status, pm.dateline, fu.username AS fromusername, fu.uid AS fromuid

but I haven't still tested it


RE: Private Message title in dropdown of header_welcomeblock_member? - kylesw555 - 2016-01-25

Thanks, I have successfully added the number of unread pms and also put it in a 'if/else' code to hide if 0. Unfortunately as I'm still quite new to all of this I wouldn't know where to start with the avatar in the dropdown, if you have the time to help me further with that that would be excellent.

One more bit of help I'm in need of is that for some reason the first link in the dropdown menu is a link to the user cp (no text) and then the list of PMs, is there a way to remove this link?


RE: Private Message title in dropdown of header_welcomeblock_member? - kylesw555 - 2016-03-06

I still need help getting the pm authors avatar to display to the left of the pm in the dropdown menu, anyone able to help with that?