This is a follow up from a question I asked.

I'd like to see a way to have Friendlist automatically notify the receiver of a friend request, other than email. What I'm looking for is when you have a message waiting to be read, a number appears in the menu block (example: "twoway received (1)").

Private messages does a similar thing. When you have a message waiting to be read, a number appears in the menu (example: "All messages (1)").

Comments

mariusooms’s picture

We can not do it that way currently. However here's a way, but the relationship count will not be in the menu item. Instead you can create a tiny block notifying the user he or she has pending requests. I have not done this myself, but try this.

Create a new block with this code:

<?php
global $user;
$none = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_NONE'); // '1' equals the relationship id.
$send = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_1_TO_2_P');
$received = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_2_TO_1_P');
$accepted = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_BOTH');
?>

<?php if ($user->uid == arg(1)): ?>
<ul>
  <?php if ($none): ?>
  <li>You have no friends yet.</li>
  <?php endif; ?>
  <?php if ($send): ?>
  <li><?php print $send ?> requests send</li>
  <?php endif; ?>
  <?php if ($received): ?>
  <li><?php print $received ?> requests received</li>
  <?php endif; ?>
  <?php if ($both): ?>
  <li><?php print $accpeted ?> current friends</li>
  <?php endif; ?>
</ul>
<?php endif; ?>

This is just a tiny example how you can output the number of statuses for the logged in user. Now that you have this info you can display it in any way you desire. Sorry about the markup clunkyness, but I just wanted to quickly show how to make a block like this. Format the php in any way you think is best for your needs.

Regards,

Marius

wxman’s picture

Thanks. I'm adding this to my ever growing list of things to get caught up on.

mariusooms’s picture

Status: Active » Fixed

Okiedokie

manoz_79’s picture

Status: Fixed » Active

Hi,

I created a new block using the code above and enabled it. But I see no messages in the block, do I need to do something more apart from pasting the code above in the block body, with input format selected as PHP? Is there something else that i need to do/

I am using the latest dev version of Frielndlist.

Thanks.

mariusooms’s picture

I'm so sorry Manoz...that's what you get when you try write some quick code. Try the following code instead. Just stick it in a block with the input filter set to "PHP code" and display it on the user profile.

<?php
global $user; 
$send = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_1_TO_2_P'); // Where '1' equals the relationship id.
$received = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_2_TO_1_P');
$accepted = friendlist_api_db_statuses ('count', $user->uid, NULL, 1, 'TW_BOTH');
?>

<ul>
  <?php if ($send): ?>
    <li><?php print $send ?> requests send</li>
  <?php endif; ?>
  <?php if ($received): ?>
    <li><?php print $received ?> requests received</li>
  <?php endif; ?>
  <?php if ($accepted): ?>
    <li><?php print $accepted ?> current friends</li>
  <?php endif; ?>
  <?php if(!$accepted): ?>
    <li>You have no friends yet.</li>
  <?php endif; ?>
</ul>

Additionally if you wish to only display this on the profile for the logged in user (which I think you do), put the following code in the visibility settings with the radio button checked for "Show if the following PHP code returns TRUE". This code assumes you are using the core profile module. If you use e.g. Content Profile you will need to adjust the argument, since you are viewing a profile as a node.

<?php
global $user;
if (arg(0) == 'user' && $user->uid == arg(1)) {
    return TRUE;
}
?>

Good luck!

Marius

PS.

manoz_79’s picture

Thanks Marius, the code worked perfectly.

mariusooms’s picture

Status: Active » Fixed

Good to hear...this code might even be useful to include as a default block for the module. We'll see...maybe we will just include it as a snippet in the manual.

Regards,

Marius

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

TapSkill’s picture

Very useful snippet, thanks.