How do I print a 'send private message' link into profile along with other fields? I have my custom user-profile.tpl, is there any available variable that I can use to print this?

Please advice. Thanks.

CommentFileSizeAuthor
#13 pm.gif7.95 KBliliplanet

Comments

michelle’s picture

Status: Active » Fixed

Check this file for how it's done for Author Pane. You can use the same thing. Or you can just use Author Pane and have it done for you. :)

Michelle

halloffame’s picture

I'm a newbie so apologize for this question...

If am going to install the Author Pane Module any variables available in author-pane-block.tpl or author-pane.tpl is directly available to me via my user-profile.tpl? Is this correct?

Thanks.

michelle’s picture

No, the entire Author Pane will be available as one variable if you call its theme function. So if you don't need the whole thing, just grab the code out of that file I linked you to for getting the privatemsg link and put it in your user profile preprocess.

Michelle

halloffame’s picture

Thanks Michelle for pointing me to the right direction. I was able to figure this thing out and the preprocess function I need to implement in case I don't want to use AP Module.

I decided to use AP module instead because of its integration with some of the modules I'm already using.

I still have one more question though... The 'send private message' and 'add a relationship' link only displays to authenticated users and disappears on anonymous users. But I want this link to be visible to anyone who's viewing the profile including the none authenticated ones.

Thanks.

berdir’s picture

You can't, because anonymous users can't write private messages nor can they create relationships. However, you can of course display your own link which then links to the user registration form, for example "Register to write a private message" or whatever you want.

halloffame’s picture

I'm trying to figure out how to set conditional php to show $privatemsg_link for auth users and my custom link (as you suggested) for anonymous users. I can't seem to figure it out.

Any hint?

liliplanet’s picture

Replace 'yourrole1' and 'yourrole2' with your roles ..

<?php
global $user;
    $approved_roles = array('yourrole1', 'yourrole2');
    $user_roles = $user->roles;
?>
<?php
global $user;
if (user_access('write privatemsg') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
    $profileuser = arg(1);
    if (arg(0) == 'user' && is_numeric(arg(1))) {
            print l(' ' .theme_image(path_to_theme() .
              "/send_a_private_message.png"), 'messages/new/'. $profileuser);
      }
    }
?>

<?php if (count(array_intersect($user_roles, $approved_roles)) > 0) { ?>
<?php } else { ?>
if they do not belong to the above roles, print this ..
<?php } ?>

Still trying to figure out how to print an image in the link, but this code will restrict users by role.

Hope this helps,
Lilian

halloffame’s picture

Thank you Lilian. But where am I supposed to put this code?

I'm actually looking for something simpler... Something like...

 if ($user->uid == 0) print the 'send pm' link linking to user register
but if the user is logged in print the $privatemsg_link variable from the author pane module. 

I'm sorry cuz I feel like its more of an Author Pane issue than Privatemsg. I'm trying to achieve this via author-pane.tpl.

liliplanet’s picture

evilgenius, it is in your custom template for users (my case with http://drupal.org/project/content_profile is the content_profile-display-view.tpl.php) but I'm sure you should be able to use it on any user profile page.

The code restricts PM's by role : which enable to send a private message to that specific user, if they are not in that role, cannot send a PM.

michelle’s picture

The if test is already in the template... Just add an else:

      <?php /* Private message */ ?>
      <?php if (!empty($privatemsg_link)): ?>
        <div class="author-pane-line author-privatemsg">
          <?php print $privatemsg_link; ?>
        </div>
      <?php else: ?>
          <?php print l('Register to send pm', 'user/register'); ?>
      <?php endif; ?>

Michelle

liliplanet’s picture

Michelle Hi!

Sorry to hijack this thread, but have been trying all afternoon to add an image to my link:

global $user;
if (user_access('write privatemsg') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
    $profileuser = arg(1);
    if (arg(0) == 'user' && is_numeric(arg(1))) {
            print l(' ' .theme_image(path_to_theme() .
              "/send_a_private_message.png"), 'messages/new/'. $profileuser);
      }
    }

Would like the 'send_a_private_message.png' to replace the text. Currently I just see the link ..

Please, would you be so kind to guide me in the right direction :)

Thank you so much :)
Lilian

michelle’s picture

It looks ok to me... If the image isn't showing up, maybe you've got the path wrong. path_to_theme() isn't always your site's theme. It can be the path to the current template, too.

Michelle

liliplanet’s picture

StatusFileSize
new7.95 KB

Hi Michelle,

Thank you so much for your reply. Michelle, my template and the image is in the same folder. It's on a localhost, so unable to show you at this moment.

<div><?php
global $user;
if (user_access('write privatemsg') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
    $profileuser = arg(1);
    if (arg(0) == 'user' && is_numeric(arg(1))) {
            print l(' ' .theme_image(path_to_theme() .
              "/send_a_private_message.png"), 'messages/new/'. $profileuser);
      }
    }
?></div>

When I change the path, the link disappears so it seems not to load the image. I'm quite happy to make it an absolute url instead of path_to_theme, so please how would I change the print l( to an absolute url?

I'm attaching the screenshot of the problem.

So appreciate the amazing work you are doing on Drupal :)

All the best,
Lilian

michelle’s picture

Oh! That screenshot makes it clearer. It's printing out the HTML because you're missing a paramater to l(). Try:

print l(' ' .theme_image(path_to_theme() .
              "/send_a_private_message.png"), 'messages/new/'. $profileuser, array('html' => TRUE));

I just got up and am barely awake so not 100% sure I got that right. See http://api.drupal.org/api/function/l/6

Michelle

PS: I'm not on IRC at 4am. ;)

liliplanet’s picture

Michelle, you are a super-star! Thank you so much for your kind help, most most appreciated :)

Saw you online on irc, did not know that you are seen when unavailable, sorry.

michelle’s picture

Did it work?

I'm always connected to IRC unless my computer is off. Most people just leave it connected all the time.

Michelle

halloffame’s picture

Yes Michelle thanks so much too! You're such a super (duper) star indeed.

michelle’s picture

LOL! Thanks. *blush*

Michelle

Status: Fixed » Closed (fixed)

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